Merge pull request #49 from Iamlooker/root-installation-freeze

Fix: Freezing during application installation with root method
This commit is contained in:
LooKeR 2021-10-20 00:43:44 +05:30 committed by GitHub
commit 380faea31e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 6 deletions

View File

@ -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 {
@ -375,8 +378,10 @@ 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() lifecycleScope.launch(Dispatchers.IO) {
screenActivity.startPackageInstaller(state.release.cacheFileName) state.consume()
screenActivity.startPackageInstaller(state.release.cacheFileName)
}
} }
} }

View File

@ -9,6 +9,7 @@ import android.widget.FrameLayout
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import com.looker.droidify.R import com.looker.droidify.R
import com.looker.droidify.content.Preferences import com.looker.droidify.content.Preferences
import com.looker.droidify.database.CursorOwner import com.looker.droidify.database.CursorOwner
@ -16,6 +17,8 @@ import com.looker.droidify.utility.KParcelable
import com.looker.droidify.utility.Utils.startPackageInstaller import com.looker.droidify.utility.Utils.startPackageInstaller
import com.looker.droidify.utility.extension.resources.getDrawableFromAttr import com.looker.droidify.utility.extension.resources.getDrawableFromAttr
import com.looker.droidify.utility.extension.text.nullIfEmpty import com.looker.droidify.utility.extension.text.nullIfEmpty
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
abstract class ScreenActivity : FragmentActivity() { abstract class ScreenActivity : FragmentActivity() {
companion object { companion object {
@ -215,7 +218,9 @@ abstract class ScreenActivity : FragmentActivity() {
is SpecialIntent.Install -> { is SpecialIntent.Install -> {
val packageName = specialIntent.packageName val packageName = specialIntent.packageName
if (!packageName.isNullOrEmpty()) { if (!packageName.isNullOrEmpty()) {
specialIntent.cacheFileName?.let { startPackageInstaller(it) } lifecycleScope.launch(Dispatchers.IO) {
specialIntent.cacheFileName?.let { startPackageInstaller(it) }
}
} }
Unit Unit
} }

View File

@ -25,6 +25,9 @@ import com.looker.droidify.utility.extension.resources.getColorFromAttr
import com.looker.droidify.utility.extension.resources.getDrawableCompat import com.looker.droidify.utility.extension.resources.getDrawableCompat
import com.looker.droidify.utility.extension.text.hex import com.looker.droidify.utility.extension.text.hex
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import java.security.MessageDigest import java.security.MessageDigest
import java.security.cert.Certificate import java.security.cert.Certificate
@ -102,7 +105,7 @@ object Utils {
} }
} }
internal fun Activity.startPackageInstaller(cacheFileName: String) { suspend fun Activity.startPackageInstaller(cacheFileName: String) {
val file = Cache.getReleaseFile(this, cacheFileName) val file = Cache.getReleaseFile(this, cacheFileName)
if (Preferences[Preferences.Key.RootPermission]) { if (Preferences[Preferences.Key.RootPermission]) {
val commandBuilder = StringBuilder() val commandBuilder = StringBuilder()
@ -110,8 +113,16 @@ object Utils {
if (verifyState == "1") commandBuilder.append("settings put global verifier_verify_adb_installs 0 ; ") if (verifyState == "1") commandBuilder.append("settings put global verifier_verify_adb_installs 0 ; ")
commandBuilder.append(getPackageInstallCommand(file)) commandBuilder.append(getPackageInstallCommand(file))
commandBuilder.append(" ; settings put global verifier_verify_adb_installs $verifyState") commandBuilder.append(" ; settings put global verifier_verify_adb_installs $verifyState")
val result = Shell.su(commandBuilder.toString()).exec() withContext(Dispatchers.IO) {
if (result.isSuccess) Shell.su("${getUtilBoxPath()} rm ${quote(file.absolutePath)}") launch {
val result = Shell.su(commandBuilder.toString()).exec()
launch {
if (result.isSuccess) {
Shell.su("${getUtilBoxPath()} rm ${quote(file.absolutePath)}").submit()
}
}
}
}
} else { } else {
val (uri, flags) = if (Android.sdk(24)) { val (uri, flags) = if (Android.sdk(24)) {
Pair( Pair(