Fix: Root Installer Freeze (Again)

Improve: Default Uninstaller moved
This commit is contained in:
LooKeR 2021-10-24 20:06:51 +05:30
parent 2aaec7e022
commit ab703de3cd
3 changed files with 27 additions and 44 deletions

View File

@ -1,15 +1,10 @@
package com.looker.droidify.installer
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.Dispatchers
import kotlinx.coroutines.Job
abstract class BaseInstaller(val context: Context) : InstallationEvents {
companion object {
@ -19,38 +14,4 @@ abstract class BaseInstaller(val context: Context) : InstallationEvents {
private val job = 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()
}
}

View File

@ -21,6 +21,10 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
scope.launch { mDefaultInstaller(cacheFile) }
}
override fun uninstall(packageName: String) {
scope.launch { mDefaultUninstaller(packageName) }
}
private suspend fun mDefaultInstaller(cacheFile: File) {
val (uri, flags) = if (Android.sdk(24)) {
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)
}
}

View File

@ -15,6 +15,7 @@ import android.widget.FrameLayout
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
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.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
companion object {
@ -382,11 +385,13 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
(recyclerView?.adapter as? ProductAdapter)?.setStatus(status)
if (state is DownloadService.State.Success && isResumed) {
state.consume()
AppInstaller
.getInstance(context)?.defaultInstaller?.install(
"",
state.release.cacheFileName
)
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO){
AppInstaller
.getInstance(context)?.defaultInstaller?.install(
"",
state.release.cacheFileName
)
}
}
}