mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 13:35:27 +00:00
Postpone showMainUI
when activity has stopped
Co-authored-by: topjohnwu <topjohnwu@gmail.com>
This commit is contained in:
parent
e14f7b6908
commit
d52ea1b068
@ -6,6 +6,7 @@ import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.databinding.ViewDataBinding
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.topjohnwu.magisk.BuildConfig.APPLICATION_ID
|
||||
import com.topjohnwu.magisk.R
|
||||
@ -29,13 +30,15 @@ import kotlinx.coroutines.launch
|
||||
abstract class SplashActivity<Binding : ViewDataBinding> : NavigationActivity<Binding>() {
|
||||
|
||||
companion object {
|
||||
private var skipSplash = false
|
||||
private var splashShown = false
|
||||
}
|
||||
|
||||
private var needShowMainUI = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(Theme.selected.themeRes)
|
||||
|
||||
if (isRunningAsStub && !skipSplash) {
|
||||
if (isRunningAsStub && !splashShown) {
|
||||
// Manually apply splash theme for stub
|
||||
theme.applyStyle(R.style.StubSplashTheme, true)
|
||||
}
|
||||
@ -44,11 +47,11 @@ abstract class SplashActivity<Binding : ViewDataBinding> : NavigationActivity<Bi
|
||||
|
||||
if (!isRunningAsStub) {
|
||||
val splashScreen = installSplashScreen()
|
||||
splashScreen.setKeepOnScreenCondition { !skipSplash }
|
||||
splashScreen.setKeepOnScreenCondition { !splashShown }
|
||||
}
|
||||
|
||||
if (skipSplash) {
|
||||
showMainUI(savedInstanceState)
|
||||
if (splashShown) {
|
||||
doShowMainUI(savedInstanceState)
|
||||
} else {
|
||||
Shell.getShell(Shell.EXECUTOR) {
|
||||
if (isRunningAsStub && !it.isRoot) {
|
||||
@ -60,6 +63,11 @@ abstract class SplashActivity<Binding : ViewDataBinding> : NavigationActivity<Bi
|
||||
}
|
||||
}
|
||||
|
||||
private fun doShowMainUI(savedInstanceState: Bundle?) {
|
||||
needShowMainUI = false
|
||||
showMainUI(savedInstanceState)
|
||||
}
|
||||
|
||||
abstract fun showMainUI(savedInstanceState: Bundle?)
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
@ -87,6 +95,13 @@ abstract class SplashActivity<Binding : ViewDataBinding> : NavigationActivity<Bi
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (needShowMainUI) {
|
||||
doShowMainUI(null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun preLoad(savedState: Bundle?) {
|
||||
val prevPkg = intent.getStringExtra(Const.Key.PREV_PKG)?.let {
|
||||
// Make sure the calling package matches (prevent DoS)
|
||||
@ -116,12 +131,16 @@ abstract class SplashActivity<Binding : ViewDataBinding> : NavigationActivity<Bi
|
||||
RootUtils.Connection.await()
|
||||
|
||||
runOnUiThread {
|
||||
skipSplash = true
|
||||
splashShown = true
|
||||
if (isRunningAsStub) {
|
||||
// Re-launch main activity without splash theme
|
||||
relaunch()
|
||||
} else {
|
||||
showMainUI(savedState)
|
||||
if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
doShowMainUI(savedState)
|
||||
} else {
|
||||
needShowMainUI = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,5 +159,4 @@ abstract class SplashActivity<Binding : ViewDataBinding> : NavigationActivity<Bi
|
||||
Shell.cmd("(pm uninstall $pkg)& >/dev/null 2>&1").exec()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user