diff --git a/app/build.gradle.kts b/app/build.gradle.kts index dac758c5c..8d1cb7232 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -104,7 +104,7 @@ dependencies { implementation("androidx.room:room-ktx:${vRoom}") kapt("androidx.room:room-compiler:${vRoom}") - val vNav = "2.7.6" + val vNav = "2.7.7" implementation("androidx.navigation:navigation-fragment-ktx:${vNav}") implementation("androidx.navigation:navigation-ui-ktx:${vNav}") diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt index 16d682574..cae384aeb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -12,7 +12,6 @@ import androidx.core.content.pm.ShortcutManagerCompat import androidx.core.view.forEach import androidx.core.view.isGone import androidx.core.view.isVisible -import androidx.lifecycle.lifecycleScope import androidx.navigation.NavDirections import com.topjohnwu.magisk.MainDirections import com.topjohnwu.magisk.R @@ -24,13 +23,10 @@ import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.isRunningAsStub import com.topjohnwu.magisk.core.model.module.LocalModule -import com.topjohnwu.magisk.core.tasks.HideAPK import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding import com.topjohnwu.magisk.ui.home.HomeFragmentDirections import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.magisk.view.Shortcuts -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import java.io.File class MainViewModel : BaseViewModel() @@ -62,7 +58,6 @@ class MainActivity : SplashActivity() { setContentView() showUnsupportedMessage() askForHomeShortcut() - checkStubComponent() // Ask permission to post notifications for background update check if (Config.checkUpdate) { @@ -231,22 +226,4 @@ class MainActivity : SplashActivity() { }.show() } } - - @SuppressLint("InlinedApi") - private fun checkStubComponent() { - if (intent.component?.className?.contains(HideAPK.PLACEHOLDER) == true) { - // The stub APK was not properly patched, re-apply our changes - withPermission(Manifest.permission.REQUEST_INSTALL_PACKAGES) { granted -> - if (granted) { - lifecycleScope.launch(Dispatchers.IO) { - val apk = File(applicationInfo.sourceDir) - HideAPK.upgrade(this@MainActivity, apk)?.let { - startActivity(it) - } - } - } - } - } - } - } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt index ea694f240..fa1073f1e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt @@ -8,23 +8,30 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.databinding.ViewDataBinding import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope +import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.BuildConfig.APPLICATION_ID import com.topjohnwu.magisk.R import com.topjohnwu.magisk.StubApk import com.topjohnwu.magisk.arch.NavigationActivity import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Const +import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.JobService import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.isRunningAsStub import com.topjohnwu.magisk.core.ktx.toast +import com.topjohnwu.magisk.core.ktx.writeTo import com.topjohnwu.magisk.core.tasks.HideAPK import com.topjohnwu.magisk.core.utils.RootUtils import com.topjohnwu.magisk.ui.theme.Theme import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.magisk.view.Shortcuts import com.topjohnwu.superuser.Shell +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import timber.log.Timber +import java.io.File +import java.io.IOException @SuppressLint("CustomSplashScreen") abstract class SplashActivity : NavigationActivity() { @@ -58,7 +65,7 @@ abstract class SplashActivity : NavigationActivity : NavigationActivity : NavigationActivity/dev/null 2>&1").exec() + } + } else { + if (Config.suManager.isNotEmpty()) + Config.suManager = "" + if (prevPkg != null) { + Shell.cmd("(pm uninstall $prevPkg)& >/dev/null 2>&1").exec() + } + } + if (prevPkg != null) { runOnUiThread { // Relaunch the process after package migration @@ -121,6 +142,31 @@ abstract class SplashActivity : NavigationActivity + if (granted) { + lifecycleScope.launch(Dispatchers.IO) { + val apk = File(cacheDir, "stub.apk") + try { + assets.open("stub.apk").writeTo(apk) + HideAPK.upgrade(this@SplashActivity, apk)?.let { + startActivity(it) + } + } catch (e: IOException) { + Timber.e(e) + } + } + } + } + return + } + JobService.schedule(this) Shortcuts.setupDynamic(this) @@ -144,19 +190,4 @@ abstract class SplashActivity : NavigationActivity/dev/null 2>&1").exec() - } - } else { - if (Config.suManager.isNotEmpty()) - Config.suManager = "" - pkg ?: return - Shell.cmd("(pm uninstall $pkg)& >/dev/null 2>&1").exec() - } - } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 79b4190b2..67ca5efc2 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -18,7 +18,7 @@ gradlePlugin { dependencies { implementation(embeddedKotlin("gradle-plugin")) implementation("com.android.tools.build:gradle:8.2.2") - implementation("androidx.navigation:navigation-safe-args-gradle-plugin:2.7.6") + implementation("androidx.navigation:navigation-safe-args-gradle-plugin:2.7.7") implementation("org.lsposed.lsparanoid:gradle-plugin:0.5.2") implementation("org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r") } diff --git a/buildSrc/src/main/java/Setup.kt b/buildSrc/src/main/java/Setup.kt index df3a6bd45..80c66f452 100644 --- a/buildSrc/src/main/java/Setup.kt +++ b/buildSrc/src/main/java/Setup.kt @@ -166,6 +166,10 @@ private fun Project.setupAppCommon() { } } + defaultConfig { + buildConfigField("int", "STUB_VERSION", Config.stubVersion) + } + buildTypes { signingConfigs["config"].also { debug { diff --git a/stub/build.gradle.kts b/stub/build.gradle.kts index eff37f597..0a270f5e6 100644 --- a/stub/build.gradle.kts +++ b/stub/build.gradle.kts @@ -21,7 +21,6 @@ android { applicationId = "com.topjohnwu.magisk" versionCode = 1 versionName = "1.0" - buildConfigField("int", "STUB_VERSION", Config.stubVersion) buildConfigField("String", "APK_URL", url?.let { "\"$it\"" } ?: "null" ) }