mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-05-02 07:24:26 +02:00
Always use root to hide/restore app
This commit is contained in:
parent
dadba44cf9
commit
51cf196bf7
@ -92,7 +92,6 @@ class SettingsViewModel : BaseViewModel(), BaseSettingsItem.Handler {
|
|||||||
DownloadPath -> withExternalRW(doAction)
|
DownloadPath -> withExternalRW(doAction)
|
||||||
UpdateChecker -> withPostNotificationPermission(doAction)
|
UpdateChecker -> withPostNotificationPermission(doAction)
|
||||||
Authentication -> AuthEvent(doAction).publish()
|
Authentication -> AuthEvent(doAction).publish()
|
||||||
Hide, Restore -> withInstallPermission(doAction)
|
|
||||||
else -> doAction()
|
else -> doAction()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import com.topjohnwu.magisk.core.Config
|
|||||||
import com.topjohnwu.magisk.core.Const
|
import com.topjohnwu.magisk.core.Const
|
||||||
import com.topjohnwu.magisk.core.R
|
import com.topjohnwu.magisk.core.R
|
||||||
import com.topjohnwu.magisk.core.ktx.await
|
import com.topjohnwu.magisk.core.ktx.await
|
||||||
import com.topjohnwu.magisk.core.ktx.copyAndClose
|
|
||||||
import com.topjohnwu.magisk.core.ktx.toast
|
import com.topjohnwu.magisk.core.ktx.toast
|
||||||
import com.topjohnwu.magisk.core.ktx.writeTo
|
import com.topjohnwu.magisk.core.ktx.writeTo
|
||||||
import com.topjohnwu.magisk.core.signing.JarMap
|
import com.topjohnwu.magisk.core.signing.JarMap
|
||||||
@ -23,7 +22,6 @@ import com.topjohnwu.magisk.core.utils.Keygen
|
|||||||
import com.topjohnwu.magisk.utils.APKInstall
|
import com.topjohnwu.magisk.utils.APKInstall
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Runnable
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -172,7 +170,7 @@ object AppMigration {
|
|||||||
activity.finish()
|
activity.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun patchAndHide(activity: Activity, label: String, onFailure: Runnable): Boolean {
|
private suspend fun patchAndHide(activity: Activity, label: String): Boolean {
|
||||||
val stub = File(activity.cacheDir, "stub.apk")
|
val stub = File(activity.cacheDir, "stub.apk")
|
||||||
try {
|
try {
|
||||||
activity.assets.open("stub.apk").writeTo(stub)
|
activity.assets.open("stub.apk").writeTo(stub)
|
||||||
@ -190,23 +188,15 @@ object AppMigration {
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
// Install and auto launch app
|
// Install and auto launch app
|
||||||
val session = APKInstall.startSession(activity, pkg, onFailure) {
|
val cmd = "adb_pm_install $repack $pkg"
|
||||||
|
if (Shell.cmd(cmd).exec().isSuccess) {
|
||||||
Config.suManager = pkg
|
Config.suManager = pkg
|
||||||
Shell.cmd("touch $AppApkPath").exec()
|
Shell.cmd("touch $AppApkPath").exec()
|
||||||
launchApp(activity, pkg)
|
launchApp(activity, pkg)
|
||||||
}
|
return true
|
||||||
|
} else {
|
||||||
val cmd = "adb_pm_install $repack $pkg"
|
|
||||||
if (Shell.cmd(cmd).exec().isSuccess) return true
|
|
||||||
|
|
||||||
try {
|
|
||||||
repack.inputStream().copyAndClose(session.openStream(activity))
|
|
||||||
} catch (e: IOException) {
|
|
||||||
Timber.e(e)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
session.waitIntent()?.let { activity.startActivity(it) } ?: return false
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@ -217,14 +207,13 @@ object AppMigration {
|
|||||||
setCancelable(false)
|
setCancelable(false)
|
||||||
show()
|
show()
|
||||||
}
|
}
|
||||||
val onFailure = Runnable {
|
val success = withContext(Dispatchers.IO) {
|
||||||
|
patchAndHide(activity, label)
|
||||||
|
}
|
||||||
|
if (!success) {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
activity.toast(R.string.failure, Toast.LENGTH_LONG)
|
activity.toast(R.string.failure, Toast.LENGTH_LONG)
|
||||||
}
|
}
|
||||||
val success = withContext(Dispatchers.IO) {
|
|
||||||
patchAndHide(activity, label, onFailure)
|
|
||||||
}
|
|
||||||
if (!success) onFailure.run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@ -235,31 +224,17 @@ object AppMigration {
|
|||||||
setCancelable(false)
|
setCancelable(false)
|
||||||
show()
|
show()
|
||||||
}
|
}
|
||||||
val onFailure = Runnable {
|
|
||||||
dialog.dismiss()
|
|
||||||
activity.toast(R.string.failure, Toast.LENGTH_LONG)
|
|
||||||
}
|
|
||||||
val apk = StubApk.current(activity)
|
val apk = StubApk.current(activity)
|
||||||
val session = APKInstall.startSession(activity, APP_PACKAGE_NAME, onFailure) {
|
val cmd = "adb_pm_install $apk $APP_PACKAGE_NAME"
|
||||||
|
if (Shell.cmd(cmd).await().isSuccess) {
|
||||||
Config.suManager = ""
|
Config.suManager = ""
|
||||||
Shell.cmd("touch $AppApkPath").exec()
|
Shell.cmd("touch $AppApkPath").exec()
|
||||||
launchApp(activity, APP_PACKAGE_NAME)
|
launchApp(activity, APP_PACKAGE_NAME)
|
||||||
|
} else {
|
||||||
|
activity.toast(R.string.failure, Toast.LENGTH_LONG)
|
||||||
|
}
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
val cmd = "adb_pm_install $apk $APP_PACKAGE_NAME"
|
|
||||||
if (Shell.cmd(cmd).await().isSuccess) return
|
|
||||||
val success = withContext(Dispatchers.IO) {
|
|
||||||
try {
|
|
||||||
apk.inputStream().copyAndClose(session.openStream(activity))
|
|
||||||
} catch (e: IOException) {
|
|
||||||
Timber.e(e)
|
|
||||||
return@withContext false
|
|
||||||
}
|
|
||||||
session.waitIntent()?.let { activity.startActivity(it) } ?: return@withContext false
|
|
||||||
return@withContext true
|
|
||||||
}
|
|
||||||
if (!success) onFailure.run()
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun upgradeStub(context: Context, apk: File): Intent? {
|
suspend fun upgradeStub(context: Context, apk: File): Intent? {
|
||||||
val label = context.applicationInfo.nonLocalizedLabel
|
val label = context.applicationInfo.nonLocalizedLabel
|
||||||
|
Loading…
x
Reference in New Issue
Block a user