mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Fix: Root Installer Freeze (Again)
Improve: Default Uninstaller moved
This commit is contained in:
parent
2aaec7e022
commit
ab703de3cd
@ -1,15 +1,10 @@
|
|||||||
package com.looker.droidify.installer
|
package com.looker.droidify.installer
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import android.content.pm.PackageInstaller
|
|
||||||
import android.net.Uri
|
|
||||||
import com.looker.droidify.utility.extension.android.Android
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
|
||||||
|
|
||||||
abstract class BaseInstaller(val context: Context) : InstallationEvents {
|
abstract class BaseInstaller(val context: Context) : InstallationEvents {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@ -19,38 +14,4 @@ abstract class BaseInstaller(val context: Context) : InstallationEvents {
|
|||||||
|
|
||||||
private val job = Job()
|
private val job = Job()
|
||||||
val scope = CoroutineScope(Dispatchers.IO + job)
|
val scope = CoroutineScope(Dispatchers.IO + job)
|
||||||
|
|
||||||
fun getStatusString(context: Context, status: Int): String {
|
|
||||||
return when (status) {
|
|
||||||
PackageInstaller.STATUS_FAILURE -> "context.getString(R.string.installer_status_failure)"
|
|
||||||
PackageInstaller.STATUS_FAILURE_ABORTED -> "context.getString(R.string.installer_status_failure_aborted)"
|
|
||||||
PackageInstaller.STATUS_FAILURE_BLOCKED -> "context.getString(R.string.installer_status_failure_blocked)"
|
|
||||||
PackageInstaller.STATUS_FAILURE_CONFLICT -> "context.getString(R.string.installer_status_failure_conflict)"
|
|
||||||
PackageInstaller.STATUS_FAILURE_INCOMPATIBLE -> "context.getString(R.string.installer_status_failure_incompatible)"
|
|
||||||
PackageInstaller.STATUS_FAILURE_INVALID -> "context.getString(R.string.installer_status_failure_invalid)"
|
|
||||||
PackageInstaller.STATUS_FAILURE_STORAGE -> "context.getString(R.string.installer_status_failure_storage)"
|
|
||||||
PackageInstaller.STATUS_PENDING_USER_ACTION -> "context.getString(R.string.installer_status_user_action)"
|
|
||||||
PackageInstaller.STATUS_SUCCESS -> "context.getString(R.string.installer_status_success)"
|
|
||||||
else -> "context.getString(R.string.installer_status_unknown)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun uninstall(packageName: String) {
|
|
||||||
val uri = Uri.fromParts("package", packageName, null)
|
|
||||||
val intent = Intent()
|
|
||||||
intent.data = uri
|
|
||||||
if (Android.sdk(28)) {
|
|
||||||
intent.action = Intent.ACTION_DELETE
|
|
||||||
} else {
|
|
||||||
intent.action = Intent.ACTION_UNINSTALL_PACKAGE
|
|
||||||
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
|
||||||
}
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
context.startActivity(intent)
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed class Event {
|
|
||||||
object INSTALL : Event()
|
|
||||||
object UNINSTALL : Event()
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -21,6 +21,10 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
|||||||
scope.launch { mDefaultInstaller(cacheFile) }
|
scope.launch { mDefaultInstaller(cacheFile) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun uninstall(packageName: String) {
|
||||||
|
scope.launch { mDefaultUninstaller(packageName) }
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun mDefaultInstaller(cacheFile: File) {
|
private suspend fun mDefaultInstaller(cacheFile: File) {
|
||||||
val (uri, flags) = if (Android.sdk(24)) {
|
val (uri, flags) = if (Android.sdk(24)) {
|
||||||
Pair(
|
Pair(
|
||||||
@ -40,4 +44,17 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun mDefaultUninstaller(packageName: String){
|
||||||
|
val uri = Uri.fromParts("package", packageName, null)
|
||||||
|
val intent = Intent()
|
||||||
|
intent.data = uri
|
||||||
|
if (Android.sdk(28)) {
|
||||||
|
intent.action = Intent.ACTION_DELETE
|
||||||
|
} else {
|
||||||
|
intent.action = Intent.ACTION_UNINSTALL_PACKAGE
|
||||||
|
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
|
||||||
|
}
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
context.startActivity(intent)
|
||||||
|
}
|
||||||
}
|
}
|
@ -15,6 +15,7 @@ import android.widget.FrameLayout
|
|||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@ -34,6 +35,8 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
|||||||
import io.reactivex.rxjava3.core.Observable
|
import io.reactivex.rxjava3.core.Observable
|
||||||
import io.reactivex.rxjava3.disposables.Disposable
|
import io.reactivex.rxjava3.disposables.Disposable
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
||||||
companion object {
|
companion object {
|
||||||
@ -382,11 +385,13 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
|||||||
(recyclerView?.adapter as? ProductAdapter)?.setStatus(status)
|
(recyclerView?.adapter as? ProductAdapter)?.setStatus(status)
|
||||||
if (state is DownloadService.State.Success && isResumed) {
|
if (state is DownloadService.State.Success && isResumed) {
|
||||||
state.consume()
|
state.consume()
|
||||||
AppInstaller
|
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO){
|
||||||
.getInstance(context)?.defaultInstaller?.install(
|
AppInstaller
|
||||||
"",
|
.getInstance(context)?.defaultInstaller?.install(
|
||||||
state.release.cacheFileName
|
"",
|
||||||
)
|
state.release.cacheFileName
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user