mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Fix: Freeze with Root Installer
This commit is contained in:
parent
6c481138e0
commit
c2360f492a
@ -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) }
|
||||
}
|
||||
}
|
@ -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 =
|
||||
|
@ -19,6 +19,7 @@ import com.looker.droidify.R
|
||||
import com.looker.droidify.content.ProductPreferences
|
||||
import com.looker.droidify.database.Database
|
||||
import com.looker.droidify.entity.*
|
||||
import com.looker.droidify.installer.AppInstaller
|
||||
import com.looker.droidify.service.Connection
|
||||
import com.looker.droidify.service.DownloadService
|
||||
import com.looker.droidify.utility.RxUtils
|
||||
@ -50,7 +51,7 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
||||
|
||||
private enum class Action(
|
||||
val id: Int,
|
||||
val adapterAction: ProductAdapter.Action
|
||||
val adapterAction: ProductAdapter.Action,
|
||||
) {
|
||||
INSTALL(1, ProductAdapter.Action.INSTALL),
|
||||
UPDATE(2, ProductAdapter.Action.UPDATE),
|
||||
@ -356,9 +357,9 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
||||
}
|
||||
(recyclerView?.adapter as? ProductAdapter)?.setStatus(status)
|
||||
if (state is DownloadService.State.Success && isResumed) {
|
||||
lifecycleScope.launch(Dispatchers.Default) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
state.consume()
|
||||
screenActivity.defaultInstaller?.install(state.release.cacheFileName)
|
||||
AppInstaller.getInstance(context)?.defaultInstaller?.install(state.release.cacheFileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -405,8 +406,8 @@ class ProductFragment() : ScreenFragment(), ProductAdapter.Callbacks {
|
||||
)
|
||||
}
|
||||
ProductAdapter.Action.UNINSTALL -> {
|
||||
lifecycleScope.launch(Dispatchers.Default) {
|
||||
screenActivity.defaultInstaller?.uninstall(packageName)
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
AppInstaller.getInstance(context)?.defaultInstaller?.uninstall(packageName)
|
||||
}
|
||||
Unit
|
||||
}
|
||||
|
@ -69,8 +69,6 @@ abstract class ScreenActivity : AppCompatActivity() {
|
||||
return supportFragmentManager.findFragmentById(R.id.main_content)
|
||||
}
|
||||
|
||||
val defaultInstaller = AppInstaller.getInstance(this)?.defaultInstaller
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(Preferences[Preferences.Key.Theme].getResId(resources.configuration))
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -220,9 +218,11 @@ abstract class ScreenActivity : AppCompatActivity() {
|
||||
is SpecialIntent.Install -> {
|
||||
val packageName = specialIntent.packageName
|
||||
if (!packageName.isNullOrEmpty()) {
|
||||
lifecycleScope.launch(Dispatchers.Default) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
specialIntent.cacheFileName?.let {
|
||||
defaultInstaller?.install(packageName, it)
|
||||
AppInstaller.getInstance(this@ScreenActivity)?.defaultInstaller?.install(
|
||||
packageName,
|
||||
it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user