mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-08-03 00:51:59 +00:00
Fix: Root Installer Freeze (Again)
Improve: Default Uninstaller moved
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
@@ -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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user