From 7d9b0dfb3e58ab0959021533e0d19ba362b766a7 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 22 Oct 2026 05:50:49 +0000 Subject: [PATCH] app: Remove dynamic code loading and simplify stub Remove dynamic APK class and resource loading across :app, :shared, and :stub. Consolidate stub resources into :stub and remove stub obfuscation and encryption. - Merge :stub-res into :stub and delete the :stub-res module. - Delete DynLoad, DelegateComponentFactory, ClassLoaders, StubApplication, StubRootService, and dummy component classes. - Delete StubApk, DynamicClassLoader, and CompoundEnumeration from :shared. - Remove lsparanoid, stub component randomization, resource encryption, and Stub.kt from build-logic. - Remove stubVersion and STUB_VERSION tracking. - Simplify DownloadActivity to use direct resources and APKInstall. - Remove isRunningAsStub and stub-specific hooks across :core. Assisted-by: Gemini 4 Argon --- README.MD | 2 +- app/.gitignore | 2 - .../com/topjohnwu/magisk/ui/MainActivity.kt | 2 - app/build-logic/src/main/java/Plugin.kt | 8 - app/build-logic/src/main/java/Setup.kt | 3 +- app/build-logic/src/main/java/Stub.kt | 309 ------------------ app/build.gradle.kts | 1 - app/core/build.gradle.kts | 1 - .../java/com/topjohnwu/magisk/core/App.kt | 21 +- .../com/topjohnwu/magisk/core/AppContext.kt | 15 +- .../java/com/topjohnwu/magisk/core/Hacks.kt | 8 +- .../java/com/topjohnwu/magisk/core/Info.kt | 5 - .../magisk/core/base/SplashScreen.kt | 31 +- .../magisk/core/tasks/MagiskInstaller.kt | 58 +--- .../magisk/core/utils/LocaleSetting.kt | 20 +- .../topjohnwu/magisk/core/utils/ShellInit.kt | 24 +- .../topjohnwu/magisk/core/view/Shortcuts.kt | 13 +- app/core/src/main/res/values-v31/themes.xml | 11 - app/core/src/main/res/values/themes.xml | 1 - app/gradle.properties | 1 - app/gradle/libs.versions.toml | 1 - app/settings.gradle.kts | 2 +- .../java/com/topjohnwu/magisk/StubApk.java | 114 ------- .../magisk/utils/CompoundEnumeration.java | 35 -- .../magisk/utils/DynamicClassLoader.java | 65 ---- app/stub-res/build.gradle.kts | 16 - app/stub-res/src/main/AndroidManifest.xml | 2 - app/stub/build.gradle.kts | 10 +- app/stub/proguard-rules.pro | 9 - app/stub/src/main/AndroidManifest.xml | 12 +- .../com/topjohnwu/magisk/ClassLoaders.java | 68 ---- .../magisk/DelegateComponentFactory.java | 78 ----- .../topjohnwu/magisk/DownloadActivity.java | 113 +------ .../java/com/topjohnwu/magisk/DynLoad.java | 250 -------------- .../com/topjohnwu/magisk/StubApplication.java | 12 - .../com/topjohnwu/magisk/StubRootService.java | 43 --- .../topjohnwu/magisk/dummy/DummyProvider.java | 38 --- .../topjohnwu/magisk/dummy/DummyReceiver.java | 10 - .../topjohnwu/magisk/dummy/DummyService.java | 12 - .../src/main/res/values-ar/strings.xml | 0 .../src/main/res/values-ast/strings.xml | 0 .../src/main/res/values-az/strings.xml | 0 .../src/main/res/values-b+sr+Latn/strings.xml | 0 .../src/main/res/values-be/strings.xml | 0 .../src/main/res/values-bg/strings.xml | 0 .../src/main/res/values-ca/strings.xml | 0 .../src/main/res/values-cs/strings.xml | 0 .../src/main/res/values-de/strings.xml | 0 .../src/main/res/values-el/strings.xml | 0 .../src/main/res/values-es/strings.xml | 0 .../src/main/res/values-et/strings.xml | 0 .../src/main/res/values-fa/strings.xml | 0 .../src/main/res/values-fr/strings.xml | 0 .../src/main/res/values-hi/strings.xml | 0 .../src/main/res/values-hn/strings.xml | 0 .../src/main/res/values-hr/strings.xml | 0 .../src/main/res/values-hu/strings.xml | 0 .../src/main/res/values-in/strings.xml | 0 .../src/main/res/values-it/strings.xml | 0 .../src/main/res/values-iw/strings.xml | 0 .../src/main/res/values-ja/strings.xml | 0 .../src/main/res/values-ka/strings.xml | 0 .../src/main/res/values-kk/strings.xml | 0 .../src/main/res/values-ko/strings.xml | 0 .../src/main/res/values-ku/strings.xml | 0 .../src/main/res/values-lt/strings.xml | 0 .../src/main/res/values-mk/strings.xml | 0 .../src/main/res/values-ml/strings.xml | 0 .../src/main/res/values-nb/strings.xml | 0 .../src/main/res/values-nl/strings.xml | 0 .../src/main/res/values-pa/strings.xml | 0 .../src/main/res/values-pl/strings.xml | 0 .../src/main/res/values-pt-rBR/strings.xml | 0 .../src/main/res/values-pt-rPT/strings.xml | 0 .../src/main/res/values-ro/strings.xml | 0 .../src/main/res/values-ru/strings.xml | 0 .../src/main/res/values-sk/strings.xml | 0 .../src/main/res/values-sq/strings.xml | 0 .../src/main/res/values-sr/strings.xml | 0 .../src/main/res/values-sv/strings.xml | 0 .../src/main/res/values-sw/strings.xml | 0 .../src/main/res/values-ta/strings.xml | 0 .../src/main/res/values-th/strings.xml | 0 .../src/main/res/values-tr/strings.xml | 0 .../src/main/res/values-uk/strings.xml | 0 .../src/main/res/values-vi/strings.xml | 0 .../src/main/res/values-zh-rCN/strings.xml | 0 .../src/main/res/values-zh-rTW/strings.xml | 0 .../src/main/res/values/strings.xml | 0 89 files changed, 59 insertions(+), 1367 deletions(-) delete mode 100644 app/build-logic/src/main/java/Stub.kt delete mode 100644 app/core/src/main/res/values-v31/themes.xml delete mode 100644 app/shared/src/main/java/com/topjohnwu/magisk/StubApk.java delete mode 100644 app/shared/src/main/java/com/topjohnwu/magisk/utils/CompoundEnumeration.java delete mode 100644 app/shared/src/main/java/com/topjohnwu/magisk/utils/DynamicClassLoader.java delete mode 100644 app/stub-res/build.gradle.kts delete mode 100644 app/stub-res/src/main/AndroidManifest.xml delete mode 100644 app/stub/src/main/java/com/topjohnwu/magisk/ClassLoaders.java delete mode 100644 app/stub/src/main/java/com/topjohnwu/magisk/DelegateComponentFactory.java delete mode 100644 app/stub/src/main/java/com/topjohnwu/magisk/DynLoad.java delete mode 100644 app/stub/src/main/java/com/topjohnwu/magisk/StubApplication.java delete mode 100644 app/stub/src/main/java/com/topjohnwu/magisk/StubRootService.java delete mode 100644 app/stub/src/main/java/com/topjohnwu/magisk/dummy/DummyProvider.java delete mode 100644 app/stub/src/main/java/com/topjohnwu/magisk/dummy/DummyReceiver.java delete mode 100644 app/stub/src/main/java/com/topjohnwu/magisk/dummy/DummyService.java rename app/{stub-res => stub}/src/main/res/values-ar/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-ast/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-az/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-b+sr+Latn/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-be/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-bg/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-ca/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-cs/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-de/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-el/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-es/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-et/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-fa/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-fr/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-hi/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-hn/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-hr/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-hu/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-in/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-it/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-iw/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-ja/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-ka/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-kk/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-ko/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-ku/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-lt/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-mk/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-ml/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-nb/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-nl/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-pa/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-pl/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-pt-rBR/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-pt-rPT/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-ro/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-ru/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-sk/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-sq/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-sr/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-sv/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-sw/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-ta/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-th/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-tr/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-uk/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-vi/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-zh-rCN/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values-zh-rTW/strings.xml (100%) rename app/{stub-res => stub}/src/main/res/values/strings.xml (100%) diff --git a/README.MD b/README.MD index 4c2ed6c7f..cf7582c50 100644 --- a/README.MD +++ b/README.MD @@ -38,7 +38,7 @@ For Magisk app crashes, record and upload the logcat when the crash occurs. Default string resources for the Magisk app and its stub APK are located here: - `app/core/src/main/res/values/strings.xml` -- `app/stub-res/src/main/res/values/strings.xml` +- `app/stub/src/main/res/values/strings.xml` Translate each and place them in the respective locations (`[module]/src/main/res/values-[lang]/strings.xml`). diff --git a/app/.gitignore b/app/.gitignore index abb5fdfad..c04ceb918 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,5 +1,3 @@ -/dict.txt - # Gradle .gradle .kotlin diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index 58423e960..96f70db7e 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -238,8 +238,6 @@ class MainActivity : ComponentActivity(), SplashScreenHost { } } - override fun showInvalidStateMessage() {} - private fun showUnsupportedMessage() { val messages = mutableListOf>() diff --git a/app/build-logic/src/main/java/Plugin.kt b/app/build-logic/src/main/java/Plugin.kt index 190d16ee2..c876aea02 100644 --- a/app/build-logic/src/main/java/Plugin.kt +++ b/app/build-logic/src/main/java/Plugin.kt @@ -4,12 +4,6 @@ import org.gradle.api.Project import org.gradle.kotlin.dsl.provideDelegate import java.io.File import java.util.Properties -import java.util.Random - -// Set non-zero value here to fix the random seed for reproducible builds -// CI builds are always reproducible -val RAND_SEED = if (System.getenv("CI") != null) 42 else 0 -lateinit var RANDOM: Random val ABI_SUPPORT_LIST = listOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64", "riscv64") private val props = Properties() @@ -28,7 +22,6 @@ object Config { // Properties from gradle.properties, should always exist val versionCode: Int get() = get("magisk.versionCode")!!.toInt() - val stubVersion: String get() = get("magisk.stubVersion")!! } fun Project.rootFile(path: String): File { @@ -41,7 +34,6 @@ class MagiskPlugin : Plugin { override fun apply(project: Project) = project.applyPlugin() private fun Project.applyPlugin() { - initRandom(rootProject.file("dict.txt")) props.clear() // Get gradle properties relevant to Magisk diff --git a/app/build-logic/src/main/java/Setup.kt b/app/build-logic/src/main/java/Setup.kt index dfd217ef6..19a91c805 100644 --- a/app/build-logic/src/main/java/Setup.kt +++ b/app/build-logic/src/main/java/Setup.kt @@ -262,8 +262,7 @@ fun Project.setupAppCommon() { // Always add a transformation to set comments on the APK this.transformations.add { it.eocdComment = ("version=${Config.version}\n" + - "versionCode=${Config.versionCode}\n" + - "stubVersion=${Config.stubVersion}\n").toByteArray() + "versionCode=${Config.versionCode}\n").toByteArray() } } diff --git a/app/build-logic/src/main/java/Stub.kt b/app/build-logic/src/main/java/Stub.kt deleted file mode 100644 index d64f79075..000000000 --- a/app/build-logic/src/main/java/Stub.kt +++ /dev/null @@ -1,309 +0,0 @@ -import com.android.build.api.artifact.SingleArtifact -import org.gradle.api.DefaultTask -import org.gradle.api.Project -import org.gradle.api.file.DirectoryProperty -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.Property -import org.gradle.api.tasks.CacheableTask -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.PathSensitive -import org.gradle.api.tasks.PathSensitivity -import org.gradle.api.tasks.TaskAction -import org.gradle.kotlin.dsl.assign -import org.gradle.kotlin.dsl.register -import org.gradle.kotlin.dsl.withType -import java.io.ByteArrayInputStream -import java.io.ByteArrayOutputStream -import java.io.File -import java.io.PrintStream -import java.security.SecureRandom -import java.util.Random -import java.util.zip.Deflater -import java.util.zip.DeflaterOutputStream -import java.util.zip.ZipFile -import javax.crypto.Cipher -import javax.crypto.CipherOutputStream -import javax.crypto.spec.IvParameterSpec -import javax.crypto.spec.SecretKeySpec -import kotlin.random.asKotlinRandom - -private val kRANDOM get() = RANDOM.asKotlinRandom() - -private val c1 = mutableListOf() -private val c2 = mutableListOf() -private val c3 = mutableListOf() - -fun initRandom(dict: File) { - RANDOM = if (RAND_SEED != 0) Random(RAND_SEED.toLong()) else SecureRandom() - c1.clear() - c2.clear() - c3.clear() - for (a in chain('a'..'z', 'A'..'Z')) { - if (a != 'a' && a != 'A') { - c1.add("$a") - } - for (b in chain('a'..'z', 'A'..'Z', '0'..'9')) { - c2.add("$a$b") - for (c in chain('a'..'z', 'A'..'Z', '0'..'9')) { - c3.add("$a$b$c") - } - } - } - c1.shuffle(RANDOM) - c2.shuffle(RANDOM) - c3.shuffle(RANDOM) - PrintStream(dict).use { - for (c in chain(c1, c2, c3)) { - it.println(c) - } - } -} - -private fun chain(vararg iters: Iterable) = sequence { - iters.forEach { it.forEach { v -> yield(v) } } -} - -private fun PrintStream.byteField(name: String, bytes: ByteArray) { - println("public static byte[] $name() {") - print("byte[] buf = {") - print(bytes.joinToString(",") { it.toString() }) - println("};") - println("return buf;") - println("}") -} - -@CacheableTask -private abstract class ManifestUpdater: DefaultTask() { - @get:Input - abstract val applicationId: Property - - @get:Input - abstract val factoryClass: Property - - @get:Input - abstract val appClass: Property - - @get:InputFile - @get:PathSensitive(PathSensitivity.RELATIVE) - abstract val mergedManifest: RegularFileProperty - - @get:OutputFile - abstract val outputManifest: RegularFileProperty - - @TaskAction - fun taskAction() { - fun String.ind(level: Int) = replaceIndentByMargin(" ".repeat(level)) - - val cmpList = mutableListOf() - - cmpList.add(""" - |""".ind(2) - ) - - cmpList.add(""" - | - | - | - | - | - | - | - | - | - | - | - |""".ind(2) - ) - - cmpList.add(""" - | - | - | - | - | - |""".ind(2) - ) - - cmpList.add(""" - |""".ind(2) - ) - - cmpList.add(""" - |""".ind(2) - ) - - // Shuffle the order of the components - cmpList.shuffle(RANDOM) - val components = cmpList.joinToString("\n\n") - .replace("\${applicationId}", applicationId.get()) - val manifest = mergedManifest.asFile.get().readText().replace(Regex(".*\\ { - val classNameGenerator = sequence { - fun notJavaKeyword(name: String) = when (name) { - "do", "if", "for", "int", "new", "try" -> false - else -> true - } - - fun List.process() = asSequence() - .filter(::notJavaKeyword) - // Distinct by lower case to support case insensitive file systems - .distinctBy { it.lowercase() } - - val names = mutableListOf() - names.addAll(c1) - names.addAll(c2.process().take(30)) - names.addAll(c3.process().take(30)) - names.shuffle(RANDOM) - - while (true) { - val cls = StringBuilder() - cls.append(names.random(kRANDOM)) - cls.append('.') - cls.append(names.random(kRANDOM)) - // Old Android does not support capitalized package names - // Check Android 7.0.0 PackageParser#buildClassName - yield(cls.toString().replaceFirstChar { it.lowercase() }) - } - }.distinct().iterator() - - fun genClass(type: String, outDir: File): String { - val clzName = classNameGenerator.next() - val (pkg, name) = clzName.split('.') - val pkgDir = File(outDir, pkg) - pkgDir.mkdirs() - PrintStream(File(pkgDir, "$name.java")).use { - it.println("package $pkg;") - it.println("public class $name extends com.topjohnwu.magisk.$type {}") - } - return clzName - } - - val factory = genClass("DelegateComponentFactory", outDir) - val app = genClass("StubApplication", outDir) - return Pair(factory, app) -} - -private fun genEncryptedResources(res: ByteArray, outDir: File) { - val mainPkgDir = File(outDir, "com/topjohnwu/magisk") - mainPkgDir.mkdirs() - - // Generate iv and key - val iv = ByteArray(16) - val key = ByteArray(32) - RANDOM.nextBytes(iv) - RANDOM.nextBytes(key) - - val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding") - cipher.init(Cipher.ENCRYPT_MODE, SecretKeySpec(key, "AES"), IvParameterSpec(iv)) - val bos = ByteArrayOutputStream() - - ByteArrayInputStream(res).use { - CipherOutputStream(bos, cipher).use { os -> - it.transferTo(os) - } - } - - PrintStream(File(mainPkgDir, "Bytes.java")).use { - it.println("package com.topjohnwu.magisk;") - it.println("public final class Bytes {") - - it.byteField("key", key) - it.byteField("iv", iv) - it.byteField("res", bos.toByteArray()) - - it.println("}") - } -} - -private abstract class TaskWithDir : DefaultTask() { - @get:OutputDirectory - abstract val outputFolder: DirectoryProperty -} - -fun Project.setupStubApk() { - setupAppCommon() - - androidAppComponents { - onVariants { variant -> - val variantName = variant.name - val variantCapped = variantName.replaceFirstChar { it.uppercase() } - val variantLowered = variantName.lowercase() - - val componentJavaOutDir = layout.buildDirectory - .dir("generated/${variantLowered}/components").get().asFile - componentJavaOutDir.deleteRecursively() - - val (factory, app) = genStubClasses(componentJavaOutDir) - - val manifestUpdater = - project.tasks.register("${variantName}ManifestProducer", ManifestUpdater::class.java) { - applicationId = variant.applicationId - factoryClass.set(factory) - appClass.set(app) - } - variant.artifacts.use(manifestUpdater) - .wiredWithFiles( - ManifestUpdater::mergedManifest, - ManifestUpdater::outputManifest) - .toTransform(SingleArtifact.MERGED_MANIFEST) - - val resTask = tasks.getByPath(":stub-res:package$variantCapped") - val genResourcesTask = tasks.register("generate${variantCapped}BundledResources", TaskWithDir::class) { - dependsOn(resTask) - outputFolder.set(layout.buildDirectory.dir("generated/${variantLowered}/resources")) - - doLast { - val apk = resTask.outputs.files.asFileTree - .filter { it.name.endsWith(".apk") }.files.first() - - val bos = ByteArrayOutputStream() - ZipFile(apk).use { src -> - DeflaterOutputStream(bos, Deflater(Deflater.BEST_COMPRESSION)).use { - src.getInputStream(src.getEntry("resources.arsc")).transferTo(it) - } - } - genEncryptedResources(bos.toByteArray(), outputFolder.get().asFile) - } - } - - tasks.withType(TransformApkTask::class) { - transformations.add { - // Always delete resources.arsc from the APK - // to ensure that external resources can be loaded - it.get("resources.arsc")?.delete() - } - } - - variant.sources.java?.let { - it.addStaticSourceDirectory(componentJavaOutDir.path) - it.addGeneratedSourceDirectory(genResourcesTask, TaskWithDir::outputFolder) - } - } - } -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cc1e8dc64..1a21ddb68 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -5,7 +5,6 @@ plugins { alias(libs.plugins.ksp) apply false alias(libs.plugins.compose.compiler) apply false alias(libs.plugins.moshix) apply false - alias(libs.plugins.lsparanoid) apply false } tasks.register("clean", Delete::class) { diff --git a/app/core/build.gradle.kts b/app/core/build.gradle.kts index 9364c89a4..aed4e40aa 100644 --- a/app/core/build.gradle.kts +++ b/app/core/build.gradle.kts @@ -23,7 +23,6 @@ android { buildConfigField("String", "APP_PACKAGE_NAME", "\"com.topjohnwu.magisk\"") buildConfigField("int", "APP_VERSION_CODE", "${Config.versionCode}") buildConfigField("String", "APP_VERSION_NAME", "\"${Config.version}\"") - buildConfigField("int", "STUB_VERSION", Config.stubVersion) consumerProguardFile("proguard-rules.pro") } diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/App.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/App.kt index 28aa27844..9f4cc2a13 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/App.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/App.kt @@ -2,26 +2,11 @@ package com.topjohnwu.magisk.core import android.app.Application import android.content.Context -import com.topjohnwu.magisk.StubApk -import com.topjohnwu.magisk.core.utils.RootUtils -open class App() : Application() { - - constructor(o: Any) : this() { - val data = StubApk.Data(o) - // Add the root service name mapping - data.classToComponent[RootUtils::class.java.name] = data.rootService.name - // Send back the actual root service class - data.rootService = RootUtils::class.java - Info.stub = data - } +open class App : Application() { override fun attachBaseContext(context: Context) { - if (context is Application) { - AppContext.attachApplication(context) - } else { - super.attachBaseContext(context) - AppContext.attachApplication(this) - } + super.attachBaseContext(context) + AppContext.attachApplication(this) } } diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/AppContext.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/AppContext.kt index ea026c7d9..73225ff80 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/AppContext.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/AppContext.kt @@ -2,7 +2,6 @@ package com.topjohnwu.magisk.core import android.app.Activity import android.app.Application -import android.app.LocaleManager import android.content.ComponentCallbacks2 import android.content.Context import android.content.ContextWrapper @@ -11,7 +10,6 @@ import android.os.Build.VERSION.SDK_INT import android.os.Bundle import android.system.Os import androidx.profileinstaller.ProfileInstaller -import com.topjohnwu.magisk.StubApk import com.topjohnwu.magisk.core.base.UntrackedActivity import com.topjohnwu.magisk.core.utils.LocaleSetting import com.topjohnwu.magisk.core.utils.NetworkObserver @@ -78,11 +76,7 @@ object AppContext : ContextWrapper(null), app.registerActivityLifecycleCallbacks(this) app.registerComponentCallbacks(this) - AppApkPath = if (isRunningAsStub) { - StubApk.current(base).path - } else { - base.packageResourcePath - } + AppApkPath = base.packageResourcePath resources.patch() val shellBuilder = Shell.Builder.create() @@ -100,13 +94,8 @@ object AppContext : ContextWrapper(null), // Pre-heat the shell ASAP Shell.getShell(null) {} - if (SDK_INT >= 34 && isRunningAsStub) { - // Send over the locale config manually - val lm = getSystemService(LocaleManager::class.java) - lm.overrideLocaleConfig = LocaleSetting.localeConfig - } networkObserver = NetworkObserver.init(this) - if (!BuildConfig.DEBUG && !isRunningAsStub) { + if (!BuildConfig.DEBUG) { @OptIn(kotlinx.coroutines.DelicateCoroutinesApi::class) GlobalScope.launch(Dispatchers.IO) { ProfileInstaller.writeProfile(this@AppContext) diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/Hacks.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/Hacks.kt index 7bcf46aa4..3cae9af78 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/Hacks.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/Hacks.kt @@ -8,15 +8,10 @@ import android.content.ContextWrapper import android.content.Intent import android.content.res.Configuration import android.content.res.Resources -import com.topjohnwu.magisk.StubApk import com.topjohnwu.magisk.core.ktx.unwrap import com.topjohnwu.magisk.core.utils.LocaleSetting -fun Resources.addAssetPath(path: String) = StubApk.addAssetPath(this, path) - fun Resources.patch(): Resources { - if (isRunningAsStub) - addAssetPath(AppApkPath) LocaleSetting.instance.updateResource(this) return this } @@ -36,8 +31,7 @@ fun Context.wrap(): Context { } } -fun Class<*>.cmp(pkg: String) = - ComponentName(pkg, Info.stub?.classToComponent?.get(name) ?: name) +fun Class<*>.cmp(pkg: String) = ComponentName(pkg, name) inline fun Context.intent() = Intent().setComponent(T::class.java.cmp(packageName)) diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/Info.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/Info.kt index 2fcf5bc6b..87144f16e 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/Info.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/Info.kt @@ -3,7 +3,6 @@ package com.topjohnwu.magisk.core import android.app.KeyguardManager import android.os.Build import androidx.lifecycle.MutableLiveData -import com.topjohnwu.magisk.StubApk import com.topjohnwu.magisk.core.ktx.getProperty import com.topjohnwu.magisk.core.model.UpdateInfo import com.topjohnwu.magisk.core.repository.NetworkService @@ -13,12 +12,8 @@ import com.topjohnwu.superuser.ShellUtils.fastCmd import com.topjohnwu.superuser.ShellUtils.fastCmdResult import kotlinx.coroutines.Runnable -val isRunningAsStub get() = Info.stub != null - object Info { - var stub: StubApk.Data? = null - private val EMPTY_UPDATE = UpdateInfo() var update = EMPTY_UPDATE private set diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/base/SplashScreen.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/base/SplashScreen.kt index 7838be153..bec5d6d2d 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/base/SplashScreen.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/base/SplashScreen.kt @@ -6,9 +6,7 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.lifecycle.Lifecycle import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.JobService -import com.topjohnwu.magisk.core.R import com.topjohnwu.magisk.core.di.ServiceLocator -import com.topjohnwu.magisk.core.isRunningAsStub import com.topjohnwu.magisk.core.utils.RootUtils import com.topjohnwu.magisk.view.Notifications import com.topjohnwu.magisk.view.Shortcuts @@ -18,7 +16,6 @@ interface SplashScreenHost : IActivityExtension { val splashController: SplashController<*> fun onCreateUi(savedInstanceState: Bundle?) - fun showInvalidStateMessage() } class SplashController(private val activity: T) @@ -30,39 +27,23 @@ class SplashController(private val activity: T) private var shouldCreateUiOnResume = false - fun preOnCreate() { - if (isRunningAsStub && !splashShown) { - // Manually apply splash theme for stub - activity.theme.applyStyle(R.style.StubSplashTheme, true) - } - } + fun preOnCreate() {} fun onCreate(savedInstanceState: Bundle?) { - if (!isRunningAsStub) { - val splashScreen = activity.installSplashScreen() - splashScreen.setKeepOnScreenCondition { !splashShown } - } + val splashScreen = activity.installSplashScreen() + splashScreen.setKeepOnScreenCondition { !splashShown } if (splashShown) { doCreateUi(savedInstanceState) } else { Shell.getShell(Shell.EXECUTOR) { - if (isRunningAsStub && !it.isRoot) { - activity.showInvalidStateMessage() - return@getShell - } activity.initializeApp() activity.runOnUiThread { splashShown = true - if (isRunningAsStub) { - // Re-launch main activity without splash theme - activity.relaunch() + if (activity.lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { + doCreateUi(savedInstanceState) } else { - if (activity.lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { - doCreateUi(savedInstanceState) - } else { - shouldCreateUiOnResume = true - } + shouldCreateUiOnResume = true } } } diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt index 272efb49c..d06550bc1 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt @@ -6,14 +6,12 @@ import android.os.Process import android.system.Os import androidx.annotation.WorkerThread import androidx.core.os.postDelayed -import com.topjohnwu.magisk.StubApk import com.topjohnwu.magisk.core.AppApkPath import com.topjohnwu.magisk.core.BuildConfig import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.di.ServiceLocator -import com.topjohnwu.magisk.core.isRunningAsStub import com.topjohnwu.magisk.core.ktx.copyAll import com.topjohnwu.magisk.core.ktx.writeTo import com.topjohnwu.magisk.core.utils.DataChannel @@ -32,7 +30,6 @@ import com.topjohnwu.superuser.nio.ExtendedFile import com.topjohnwu.superuser.nio.FileSystemManager import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import org.apache.commons.compress.archivers.zip.ZipFile import timber.log.Timber import java.io.Closeable import java.io.File @@ -126,47 +123,24 @@ abstract class MagiskInstallImpl protected constructor( try { // Extract binaries - if (isRunningAsStub) { - ZipFile.builder().setFile(StubApk.current(context)).get().use { zf -> - zf.entries.asSequence().filter { - !it.isDirectory && it.name.startsWith("lib/${Const.CPU_ABI}/") - }.forEach { - val n = it.name.substring(it.name.lastIndexOf('/') + 1) - val name = n.substring(3, n.length - 3) - val dest = File(installDir, name) - zf.getInputStream(it).writeTo(dest) - dest.setExecutable(true) - } + val info = context.applicationInfo + val libs = File(info.nativeLibraryDir).listFiles { _, name -> + name.startsWith("lib") && name.endsWith(".so") + } ?: emptyArray() - val abi32 = Const.CPU_ABI_32 - if (Process.is64Bit() && abi32 != null) { - val entry = zf.getEntry("lib/$abi32/libmagisk.so") - if (entry != null) { - val magisk32 = File(installDir, "magisk32") - zf.getInputStream(entry).writeTo(magisk32) - } - } - } - } else { - val info = context.applicationInfo - val libs = File(info.nativeLibraryDir).listFiles { _, name -> - name.startsWith("lib") && name.endsWith(".so") - } ?: emptyArray() + for (lib in libs) { + val name = lib.name.substring(3, lib.name.length - 3) + Os.symlink(lib.path, "$installDir/$name") + } - for (lib in libs) { - val name = lib.name.substring(3, lib.name.length - 3) - Os.symlink(lib.path, "$installDir/$name") - } - - // Also extract magisk32 on 64-bit devices that supports 32-bit - val abi32 = Const.CPU_ABI_32 - if (Process.is64Bit() && abi32 != null) { - val name = "lib/$abi32/libmagisk.so" - val entry = javaClass.classLoader!!.getResourceAsStream(name) - if (entry != null) { - val magisk32 = File(installDir, "magisk32") - entry.writeTo(magisk32) - } + // Also extract magisk32 on 64-bit devices that supports 32-bit + val abi32 = Const.CPU_ABI_32 + if (Process.is64Bit() && abi32 != null) { + val name = "lib/$abi32/libmagisk.so" + val entry = javaClass.classLoader!!.getResourceAsStream(name) + if (entry != null) { + val magisk32 = File(installDir, "magisk32") + entry.writeTo(magisk32) } } diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/utils/LocaleSetting.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/utils/LocaleSetting.kt index 50dec4152..9aaf11d54 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/utils/LocaleSetting.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/utils/LocaleSetting.kt @@ -3,7 +3,6 @@ package com.topjohnwu.magisk.core.utils import android.annotation.SuppressLint import android.app.LocaleConfig import android.app.LocaleManager -import android.content.ContextWrapper import android.content.Intent import android.content.res.Resources import android.net.Uri @@ -11,12 +10,10 @@ import android.os.Build import android.os.LocaleList import android.provider.Settings import androidx.annotation.RequiresApi -import com.topjohnwu.magisk.core.AppApkPath import com.topjohnwu.magisk.core.AppContext import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.R import com.topjohnwu.magisk.core.base.relaunch -import com.topjohnwu.magisk.core.isRunningAsStub import org.xmlpull.v1.XmlPullParser import java.util.Locale @@ -91,7 +88,7 @@ interface LocaleSetting { names.add(AppContext.getString(R.string.system_default)) tags.add("") - if ((Build.VERSION.SDK_INT == 34 && !isRunningAsStub) || Build.VERSION.SDK_INT >= 35) { + if (Build.VERSION.SDK_INT >= 34) { // Use platform LocaleConfig parser val config = localeConfig val list = config.supportedLocales ?: LocaleList.getEmptyLocaleList() @@ -124,22 +121,11 @@ interface LocaleSetting { @get:RequiresApi(34) val localeConfig: LocaleConfig by lazy { - val context = if (isRunningAsStub) { - val pkgInfo = AppContext.packageManager.getPackageArchiveInfo(AppApkPath, 0)!! - object : ContextWrapper(AppContext) { - override fun getApplicationInfo() = pkgInfo.applicationInfo - } - } else { - AppContext - } - LocaleConfig.fromContextIgnoringOverride(context) + LocaleConfig.fromContextIgnoringOverride(AppContext) } - private val localeManagerUsable get() = - if (isRunningAsStub) Build.VERSION.SDK_INT >= 35 else Build.VERSION.SDK_INT >= 33 - val useLocaleManager by lazy { - localeManagerUsable && + Build.VERSION.SDK_INT >= 33 && localeSettingsIntent.resolveActivity(AppContext.packageManager) != null } diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt index cfaa9c505..aa527fe2b 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt @@ -1,17 +1,9 @@ package com.topjohnwu.magisk.core.utils import android.content.Context -import com.topjohnwu.magisk.StubApk -import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info -import com.topjohnwu.magisk.core.isRunningAsStub -import com.topjohnwu.magisk.core.ktx.cachedFile -import com.topjohnwu.magisk.core.ktx.writeTo import com.topjohnwu.superuser.Shell -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.runBlocking import java.io.File -import java.util.jar.JarFile class ShellInit : Shell.Initializer() { override fun onInit(context: Context, shell: Shell): Boolean { @@ -23,21 +15,7 @@ class ShellInit : Shell.Initializer() { shell.newJob().apply { add("export ASH_STANDALONE=1") - val localBB: File - if (isRunningAsStub) { - if (!shell.isRoot) - return true - val jar = JarFile(StubApk.current(context)) - val bb = jar.getJarEntry("lib/${Const.CPU_ABI}/libbusybox.so") - localBB = context.createDeviceProtectedStorageContext().cachedFile("busybox") - localBB.delete() - runBlocking { - jar.getInputStream(bb).writeTo(localBB, dispatcher = Dispatchers.Unconfined) - } - localBB.setExecutable(true) - } else { - localBB = File(context.applicationInfo.nativeLibraryDir, "libbusybox.so") - } + val localBB = File(context.applicationInfo.nativeLibraryDir, "libbusybox.so") if (shell.isRoot) { add("export MAGISKTMP=\$(magisk --path)") diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/view/Shortcuts.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/view/Shortcuts.kt index 444c5f211..cffdc67ba 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/view/Shortcuts.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/view/Shortcuts.kt @@ -11,8 +11,6 @@ import androidx.core.content.getSystemService import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.R -import com.topjohnwu.magisk.core.isRunningAsStub -import com.topjohnwu.magisk.core.ktx.getBitmap object Shortcuts { @@ -23,16 +21,7 @@ object Shortcuts { } } - private fun Context.getIcon(id: Int): Icon { - return if (isRunningAsStub) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - Icon.createWithAdaptiveBitmap(getBitmap(id)) - else - Icon.createWithBitmap(getBitmap(id)) - } else { - Icon.createWithResource(this, id) - } - } + private fun Context.getIcon(id: Int): Icon = Icon.createWithResource(this, id) @RequiresApi(api = 25) private fun getShortCuts(context: Context): List { diff --git a/app/core/src/main/res/values-v31/themes.xml b/app/core/src/main/res/values-v31/themes.xml deleted file mode 100644 index a458579bb..000000000 --- a/app/core/src/main/res/values-v31/themes.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - diff --git a/app/core/src/main/res/values/themes.xml b/app/core/src/main/res/values/themes.xml index 0e981f106..cc4be945e 100644 --- a/app/core/src/main/res/values/themes.xml +++ b/app/core/src/main/res/values/themes.xml @@ -4,5 +4,4 @@ @color/splash_background @drawable/ic_magisk_padded -