From 105b2fc114b069df9c747e5d69db833850b7b366 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 19 Aug 2020 05:18:15 -0700 Subject: [PATCH] Ensure SplashActivity is ran before MainActivity --- .../java/com/topjohnwu/magisk/core/Hacks.kt | 5 +++++ .../topjohnwu/magisk/core/SplashActivity.kt | 14 +----------- .../com/topjohnwu/magisk/ui/MainActivity.kt | 22 +++++++++++++++++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt index 3240554ed..8dd0d3ec1 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt @@ -3,6 +3,7 @@ package com.topjohnwu.magisk.core import android.annotation.SuppressLint +import android.app.Activity import android.app.job.JobInfo import android.app.job.JobScheduler import android.app.job.JobWorkItem @@ -53,6 +54,10 @@ fun Class<*>.cmp(pkg: String): ComponentName { return ComponentName(pkg, Info.stub?.classToComponent?.get(name) ?: name) } +inline fun Activity.redirect() = Intent(intent) + .setComponent(T::class.java.cmp(packageName)) + .setFlags(0) + inline fun Context.intent() = Intent().setComponent(T::class.java.cmp(packageName)) private open class GlobalResContext(base: Context) : ContextWrapper(base) { diff --git a/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt b/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt index 9421e447d..606533c7c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt @@ -2,8 +2,6 @@ package com.topjohnwu.magisk.core import android.app.Activity import android.content.Context -import android.content.Intent -import android.os.Build import android.os.Bundle import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.R @@ -61,21 +59,11 @@ open class SplashActivity : Activity() { DONE = true - val section = if (intent.action == ACTION_APPLICATION_PREFERENCES) Const.Nav.SETTINGS - else intent.getStringExtra(Const.Key.OPEN_SECTION) - - intent() - .putExtra(Const.Key.OPEN_SECTION, section) - .also { startActivity(it) } - + redirect().also { startActivity(it) } finish() } companion object { - private val ACTION_APPLICATION_PREFERENCES get() = - if (Build.VERSION.SDK_INT >= 24) Intent.ACTION_APPLICATION_PREFERENCES - else "???" - var DONE = false } } 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 f2ec6116c..e77464c4f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt @@ -1,5 +1,7 @@ package com.topjohnwu.magisk.ui +import android.content.Intent +import android.os.Build import android.os.Bundle import android.view.MenuItem import android.view.View @@ -18,6 +20,8 @@ import com.topjohnwu.magisk.arch.BaseViewModel import com.topjohnwu.magisk.arch.ReselectionTarget import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info +import com.topjohnwu.magisk.core.SplashActivity +import com.topjohnwu.magisk.core.redirect import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding import com.topjohnwu.magisk.ktx.startAnimations import com.topjohnwu.magisk.ui.home.HomeFragmentDirections @@ -49,6 +53,13 @@ open class MainActivity : BaseUIActivity( override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + // Make sure Splash is always ran before us + if (!SplashActivity.DONE) { + redirect().also { startActivity(it) } + finish() + return + } + if (Info.env.isUnsupported) { MagiskDialog(this) .applyTitle(R.string.unsupport_magisk_title) @@ -97,8 +108,9 @@ open class MainActivity : BaseUIActivity( binding.mainNavigation.viewTreeObserver.addOnGlobalLayoutListener(navObserver) - if (intent.hasExtra(Const.Key.OPEN_SECTION)) - getScreen(intent.getStringExtra(Const.Key.OPEN_SECTION))?.navigate() + val section = if (intent.action == ACTION_APPLICATION_PREFERENCES) Const.Nav.SETTINGS + else intent.getStringExtra(Const.Key.OPEN_SECTION) + getScreen(section)?.navigate() if (savedInstanceState != null) { if (!isRootFragment) { @@ -177,4 +189,10 @@ open class MainActivity : BaseUIActivity( } } + companion object { + private val ACTION_APPLICATION_PREFERENCES get() = + if (Build.VERSION.SDK_INT >= 24) Intent.ACTION_APPLICATION_PREFERENCES + else "???" + } + }