Fix: Freeze with Root Installer

This commit is contained in:
LooKeR
2021-11-18 11:59:04 +05:30
parent 6c481138e0
commit c2360f492a
4 changed files with 18 additions and 26 deletions

View File

@ -6,7 +6,6 @@ import android.net.Uri
import com.looker.droidify.content.Cache
import com.looker.droidify.utility.extension.android.Android
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
@ -38,13 +37,11 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
// TODO Handle deprecation
@Suppress("DEPRECATION")
withContext(Dispatchers.IO) {
launch {
context.startActivity(
Intent(Intent.ACTION_INSTALL_PACKAGE)
.setDataAndType(uri, "application/vnd.android.package-archive")
.setFlags(flags)
)
}
context.startActivity(
Intent(Intent.ACTION_INSTALL_PACKAGE)
.setDataAndType(uri, "application/vnd.android.package-archive")
.setFlags(flags)
)
}
}
@ -60,6 +57,6 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
withContext(Dispatchers.IO) { launch { context.startActivity(intent) } }
withContext(Dispatchers.IO) { context.startActivity(intent) }
}
}

View File

@ -5,7 +5,6 @@ import android.util.Log
import com.looker.droidify.content.Cache
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
@ -25,7 +24,6 @@ class RootInstaller(context: Context) : BaseInstaller(context) {
override suspend fun uninstall(packageName: String) = mRootUninstaller(packageName)
private suspend fun mRootInstaller(cacheFile: File) {
Log.e("UserID", getCurrentUserState)
val installCommand =
String.format(
ROOT_INSTALL_PACKAGE,
@ -40,18 +38,14 @@ class RootInstaller(context: Context) : BaseInstaller(context) {
cacheFile.absolutePath.quote
)
withContext(Dispatchers.IO) {
launch {
Shell.su(installCommand).submit {
if (it.isSuccess) Shell.su(deleteCommand).submit()
}
}
Shell.su(installCommand).submit { if (it.isSuccess) Shell.su(deleteCommand).submit() }
}
}
private suspend fun mRootUninstaller(packageName: String) {
val uninstallCommand =
String.format(ROOT_UNINSTALL_PACKAGE, getCurrentUserState, packageName)
withContext(Dispatchers.IO) { launch { Shell.su(uninstallCommand).submit() } }
withContext(Dispatchers.IO) { Shell.su(uninstallCommand).submit() }
}
private val getCurrentUserState: String =