mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 07:57:39 +00:00
App migration minor refactoring
This commit is contained in:
parent
fe9ec3bc6d
commit
881d3b5221
@ -14,7 +14,7 @@ import com.topjohnwu.magisk.core.base.relaunch
|
|||||||
import com.topjohnwu.magisk.core.initializeOnSplashScreen
|
import com.topjohnwu.magisk.core.initializeOnSplashScreen
|
||||||
import com.topjohnwu.magisk.core.isRunningAsStub
|
import com.topjohnwu.magisk.core.isRunningAsStub
|
||||||
import com.topjohnwu.magisk.core.ktx.toast
|
import com.topjohnwu.magisk.core.ktx.toast
|
||||||
import com.topjohnwu.magisk.core.tasks.HideAPK
|
import com.topjohnwu.magisk.core.tasks.AppMigration
|
||||||
import com.topjohnwu.magisk.ui.theme.Theme
|
import com.topjohnwu.magisk.ui.theme.Theme
|
||||||
import com.topjohnwu.magisk.view.MagiskDialog
|
import com.topjohnwu.magisk.view.MagiskDialog
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
@ -91,7 +91,7 @@ abstract class SplashActivity<Binding : ViewDataBinding> : NavigationActivity<Bi
|
|||||||
showInvalidStateMessage()
|
showInvalidStateMessage()
|
||||||
} else {
|
} else {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
HideAPK.restore(this@SplashActivity)
|
AppMigration.restore(this@SplashActivity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import com.topjohnwu.magisk.core.Config
|
|||||||
import com.topjohnwu.magisk.core.Const
|
import com.topjohnwu.magisk.core.Const
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.ktx.activity
|
import com.topjohnwu.magisk.core.ktx.activity
|
||||||
import com.topjohnwu.magisk.core.tasks.HideAPK
|
import com.topjohnwu.magisk.core.tasks.AppMigration
|
||||||
import com.topjohnwu.magisk.core.utils.LocaleSetting
|
import com.topjohnwu.magisk.core.utils.LocaleSetting
|
||||||
import com.topjohnwu.magisk.core.utils.MediaStoreUtils
|
import com.topjohnwu.magisk.core.utils.MediaStoreUtils
|
||||||
import com.topjohnwu.magisk.databinding.DialogSettingsAppNameBinding
|
import com.topjohnwu.magisk.databinding.DialogSettingsAppNameBinding
|
||||||
@ -81,7 +81,7 @@ object Hide : BaseSettingsItem.Input() {
|
|||||||
set(value) = set(value, field, { field = it }, BR.result, BR.error)
|
set(value) = set(value, field, { field = it }, BR.result, BR.error)
|
||||||
|
|
||||||
val maxLength
|
val maxLength
|
||||||
get() = HideAPK.MAX_LABEL_LENGTH
|
get() = AppMigration.MAX_LABEL_LENGTH
|
||||||
|
|
||||||
@get:Bindable
|
@get:Bindable
|
||||||
val isError
|
val isError
|
||||||
|
@ -19,7 +19,7 @@ import com.topjohnwu.magisk.core.R
|
|||||||
import com.topjohnwu.magisk.core.isRunningAsStub
|
import com.topjohnwu.magisk.core.isRunningAsStub
|
||||||
import com.topjohnwu.magisk.core.ktx.activity
|
import com.topjohnwu.magisk.core.ktx.activity
|
||||||
import com.topjohnwu.magisk.core.ktx.toast
|
import com.topjohnwu.magisk.core.ktx.toast
|
||||||
import com.topjohnwu.magisk.core.tasks.HideAPK
|
import com.topjohnwu.magisk.core.tasks.AppMigration
|
||||||
import com.topjohnwu.magisk.core.utils.LocaleSetting
|
import com.topjohnwu.magisk.core.utils.LocaleSetting
|
||||||
import com.topjohnwu.magisk.databinding.bindExtra
|
import com.topjohnwu.magisk.databinding.bindExtra
|
||||||
import com.topjohnwu.magisk.events.AddHomeIconEvent
|
import com.topjohnwu.magisk.events.AddHomeIconEvent
|
||||||
@ -105,8 +105,8 @@ class SettingsViewModel : BaseViewModel(), BaseSettingsItem.Handler {
|
|||||||
SystemlessHosts -> createHosts()
|
SystemlessHosts -> createHosts()
|
||||||
DenyListConfig -> SettingsFragmentDirections.actionSettingsFragmentToDenyFragment().navigate()
|
DenyListConfig -> SettingsFragmentDirections.actionSettingsFragmentToDenyFragment().navigate()
|
||||||
UpdateChannel -> openUrlIfNecessary(view)
|
UpdateChannel -> openUrlIfNecessary(view)
|
||||||
is Hide -> viewModelScope.launch { HideAPK.hide(view.activity, item.value) }
|
is Hide -> viewModelScope.launch { AppMigration.hide(view.activity, item.value) }
|
||||||
Restore -> viewModelScope.launch { HideAPK.restore(view.activity) }
|
Restore -> viewModelScope.launch { AppMigration.restore(view.activity) }
|
||||||
Zygisk -> if (Zygisk.mismatch) SnackbarEvent(R.string.reboot_apply_change).publish()
|
Zygisk -> if (Zygisk.mismatch) SnackbarEvent(R.string.reboot_apply_change).publish()
|
||||||
else -> Unit
|
else -> Unit
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import com.topjohnwu.magisk.core.base.UntrackedActivity
|
|||||||
import com.topjohnwu.magisk.core.base.launchPackage
|
import com.topjohnwu.magisk.core.base.launchPackage
|
||||||
import com.topjohnwu.magisk.core.di.ServiceLocator
|
import com.topjohnwu.magisk.core.di.ServiceLocator
|
||||||
import com.topjohnwu.magisk.core.ktx.writeTo
|
import com.topjohnwu.magisk.core.ktx.writeTo
|
||||||
import com.topjohnwu.magisk.core.tasks.HideAPK
|
import com.topjohnwu.magisk.core.tasks.AppMigration
|
||||||
import com.topjohnwu.magisk.core.utils.LocaleSetting
|
import com.topjohnwu.magisk.core.utils.LocaleSetting
|
||||||
import com.topjohnwu.magisk.core.utils.NetworkObserver
|
import com.topjohnwu.magisk.core.utils.NetworkObserver
|
||||||
import com.topjohnwu.magisk.core.utils.ProcessLifecycle
|
import com.topjohnwu.magisk.core.utils.ProcessLifecycle
|
||||||
@ -178,15 +178,15 @@ where T : ComponentActivity, T : IActivityExtension {
|
|||||||
// Version mismatch
|
// Version mismatch
|
||||||
Info.stub!!.version != BuildConfig.STUB_VERSION ||
|
Info.stub!!.version != BuildConfig.STUB_VERSION ||
|
||||||
// Not properly patched
|
// Not properly patched
|
||||||
intent.component!!.className.contains(HideAPK.PLACEHOLDER))
|
intent.component!!.className.contains(AppMigration.PLACEHOLDER))
|
||||||
) {
|
) {
|
||||||
withPermission(REQUEST_INSTALL_PACKAGES) { granted ->
|
withPermission(REQUEST_INSTALL_PACKAGES) { granted ->
|
||||||
if (granted) {
|
if (granted) {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch {
|
||||||
val apk = File(cacheDir, "stub.apk")
|
val apk = File(cacheDir, "stub.apk")
|
||||||
try {
|
try {
|
||||||
assets.open("stub.apk").writeTo(apk)
|
assets.open("stub.apk").writeTo(apk)
|
||||||
HideAPK.upgrade(this@initializeOnSplashScreen, apk)?.let {
|
AppMigration.upgradeStub(this@initializeOnSplashScreen, apk)?.let {
|
||||||
startActivity(it)
|
startActivity(it)
|
||||||
}
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
@ -33,7 +33,7 @@ import com.topjohnwu.magisk.core.ktx.forEach
|
|||||||
import com.topjohnwu.magisk.core.ktx.set
|
import com.topjohnwu.magisk.core.ktx.set
|
||||||
import com.topjohnwu.magisk.core.ktx.withStreams
|
import com.topjohnwu.magisk.core.ktx.withStreams
|
||||||
import com.topjohnwu.magisk.core.ktx.writeTo
|
import com.topjohnwu.magisk.core.ktx.writeTo
|
||||||
import com.topjohnwu.magisk.core.tasks.HideAPK
|
import com.topjohnwu.magisk.core.tasks.AppMigration
|
||||||
import com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream
|
import com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream
|
||||||
import com.topjohnwu.magisk.core.utils.ProgressInputStream
|
import com.topjohnwu.magisk.core.utils.ProgressInputStream
|
||||||
import com.topjohnwu.magisk.utils.APKInstall
|
import com.topjohnwu.magisk.utils.APKInstall
|
||||||
@ -292,7 +292,7 @@ class DownloadEngine(
|
|||||||
zf.close()
|
zf.close()
|
||||||
|
|
||||||
// Patch and install
|
// Patch and install
|
||||||
subject.intent = HideAPK.upgrade(context, apk)
|
subject.intent = AppMigration.upgradeStub(context, apk)
|
||||||
?: throw IOException("HideAPK patch error")
|
?: throw IOException("HideAPK patch error")
|
||||||
apk.delete()
|
apk.delete()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -6,7 +6,6 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.WorkerThread
|
|
||||||
import com.topjohnwu.magisk.StubApk
|
import com.topjohnwu.magisk.StubApk
|
||||||
import com.topjohnwu.magisk.core.BuildConfig.APP_PACKAGE_NAME
|
import com.topjohnwu.magisk.core.BuildConfig.APP_PACKAGE_NAME
|
||||||
import com.topjohnwu.magisk.core.Config
|
import com.topjohnwu.magisk.core.Config
|
||||||
@ -33,7 +32,7 @@ import java.io.OutputStream
|
|||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
import kotlin.random.asKotlinRandom
|
import kotlin.random.asKotlinRandom
|
||||||
|
|
||||||
object HideAPK {
|
object AppMigration {
|
||||||
|
|
||||||
private const val ALPHA = "abcdefghijklmnopqrstuvwxyz"
|
private const val ALPHA = "abcdefghijklmnopqrstuvwxyz"
|
||||||
private const val ALPHADOTS = "$ALPHA....."
|
private const val ALPHADOTS = "$ALPHA....."
|
||||||
@ -258,16 +257,17 @@ object HideAPK {
|
|||||||
if (!success) onFailure.run()
|
if (!success) onFailure.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
suspend fun upgradeStub(context: Context, apk: File): Intent? {
|
||||||
fun upgrade(context: Context, apk: File): Intent? {
|
|
||||||
val label = context.applicationInfo.nonLocalizedLabel
|
val label = context.applicationInfo.nonLocalizedLabel
|
||||||
val pkg = context.packageName
|
val pkg = context.packageName
|
||||||
val session = APKInstall.startSession(context)
|
val session = APKInstall.startSession(context)
|
||||||
session.openStream(context).use {
|
return withContext(Dispatchers.IO) {
|
||||||
if (!patch(context, apk, it, pkg, label)) {
|
session.openStream(context).use {
|
||||||
return null
|
if (!patch(context, apk, it, pkg, label)) {
|
||||||
|
return@withContext null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
session.waitIntent()
|
||||||
}
|
}
|
||||||
return session.waitIntent()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user