Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
317153c5
Commit
317153c5
authored
Jun 06, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better stub launch flow
parent
fa60daf9
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
38 deletions
+55
-38
UIActivity.kt
app/src/main/java/com/topjohnwu/magisk/arch/UIActivity.kt
+1
-2
BaseActivity.kt
.../main/java/com/topjohnwu/magisk/core/base/BaseActivity.kt
+13
-0
HideAPK.kt
app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt
+1
-2
DarkThemeDialog.kt
...ava/com/topjohnwu/magisk/events/dialog/DarkThemeDialog.kt
+2
-1
MainActivity.kt
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
+1
-2
SplashActivity.kt
app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt
+31
-24
ThemeViewModel.kt
...main/java/com/topjohnwu/magisk/ui/theme/ThemeViewModel.kt
+6
-7
No files found.
app/src/main/java/com/topjohnwu/magisk/arch/UIActivity.kt
View file @
317153c5
...
@@ -27,8 +27,7 @@ abstract class UIActivity<Binding : ViewDataBinding> : BaseActivity(), ViewModel
...
@@ -27,8 +27,7 @@ abstract class UIActivity<Binding : ViewDataBinding> : BaseActivity(), ViewModel
open
val
snackbarAnchorView
:
View
?
get
()
=
null
open
val
snackbarAnchorView
:
View
?
get
()
=
null
init
{
init
{
val
theme
=
Config
.
darkTheme
AppCompatDelegate
.
setDefaultNightMode
(
Config
.
darkTheme
)
AppCompatDelegate
.
setDefaultNightMode
(
theme
)
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
...
...
app/src/main/java/com/topjohnwu/magisk/core/base/BaseActivity.kt
View file @
317153c5
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.core.base
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.core.base
import
android.Manifest.permission.REQUEST_INSTALL_PACKAGES
import
android.Manifest.permission.REQUEST_INSTALL_PACKAGES
import
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import
android.app.Activity
import
android.content.ActivityNotFoundException
import
android.content.ActivityNotFoundException
import
android.content.Context
import
android.content.Context
import
android.content.Intent
import
android.content.Intent
...
@@ -54,6 +55,18 @@ abstract class BaseActivity : AppCompatActivity() {
...
@@ -54,6 +55,18 @@ abstract class BaseActivity : AppCompatActivity() {
uninstallLatch
.
countDown
()
uninstallLatch
.
countDown
()
}
}
private
val
mReferrerField
by
lazy
(
LazyThreadSafetyMode
.
NONE
)
{
Activity
::
class
.
java
.
reflectField
(
"mReferrer"
)
}
val
realCallingPackage
:
String
?
get
()
{
callingPackage
?.
let
{
return
it
}
if
(
Build
.
VERSION
.
SDK_INT
>=
22
)
{
mReferrerField
.
get
(
this
)
?.
let
{
return
it
as
String
}
}
return
null
}
override
fun
attachBaseContext
(
base
:
Context
)
{
override
fun
attachBaseContext
(
base
:
Context
)
{
super
.
attachBaseContext
(
base
.
wrap
())
super
.
attachBaseContext
(
base
.
wrap
())
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt
View file @
317153c5
...
@@ -99,8 +99,7 @@ object HideAPK {
...
@@ -99,8 +99,7 @@ object HideAPK {
val
flag
=
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
val
flag
=
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
activity
.
grantUriPermission
(
pkg
,
Provider
.
preferencesUri
(
self
),
flag
)
activity
.
grantUriPermission
(
pkg
,
Provider
.
preferencesUri
(
self
),
flag
)
intent
.
putExtra
(
Const
.
Key
.
PREV_PKG
,
self
)
intent
.
putExtra
(
Const
.
Key
.
PREV_PKG
,
self
)
intent
.
flags
=
0
activity
.
startActivity
(
intent
)
activity
.
startActivityForResult
(
intent
,
Int
.
MAX_VALUE
)
activity
.
finish
()
activity
.
finish
()
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/events/dialog/DarkThemeDialog.kt
View file @
317153c5
...
@@ -3,6 +3,7 @@ package com.topjohnwu.magisk.events.dialog
...
@@ -3,6 +3,7 @@ package com.topjohnwu.magisk.events.dialog
import
android.app.Activity
import
android.app.Activity
import
androidx.appcompat.app.AppCompatDelegate
import
androidx.appcompat.app.AppCompatDelegate
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.arch.UIActivity
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.view.MagiskDialog
import
com.topjohnwu.magisk.view.MagiskDialog
...
@@ -33,6 +34,6 @@ class DarkThemeDialog : DialogEvent() {
...
@@ -33,6 +34,6 @@ class DarkThemeDialog : DialogEvent() {
private
fun
selectTheme
(
mode
:
Int
,
activity
:
Activity
)
{
private
fun
selectTheme
(
mode
:
Int
,
activity
:
Activity
)
{
Config
.
darkTheme
=
mode
Config
.
darkTheme
=
mode
activity
.
recreate
()
(
activity
as
UIActivity
<*>).
delegate
.
localNightMode
=
mode
}
}
}
}
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
View file @
317153c5
...
@@ -13,7 +13,6 @@ import androidx.core.view.isVisible
...
@@ -13,7 +13,6 @@ import androidx.core.view.isVisible
import
androidx.navigation.NavDirections
import
androidx.navigation.NavDirections
import
com.topjohnwu.magisk.MainDirections
import
com.topjohnwu.magisk.MainDirections
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.arch.BaseMainActivity
import
com.topjohnwu.magisk.arch.BaseViewModel
import
com.topjohnwu.magisk.arch.BaseViewModel
import
com.topjohnwu.magisk.arch.viewModel
import
com.topjohnwu.magisk.arch.viewModel
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.Config
...
@@ -31,7 +30,7 @@ import java.io.File
...
@@ -31,7 +30,7 @@ import java.io.File
class
MainViewModel
:
BaseViewModel
()
class
MainViewModel
:
BaseViewModel
()
class
MainActivity
:
BaseMain
Activity
<
ActivityMainMd2Binding
>()
{
class
MainActivity
:
Splash
Activity
<
ActivityMainMd2Binding
>()
{
override
val
layoutRes
=
R
.
layout
.
activity_main_md2
override
val
layoutRes
=
R
.
layout
.
activity_main_md2
override
val
viewModel
by
viewModel
<
MainViewModel
>()
override
val
viewModel
by
viewModel
<
MainViewModel
>()
...
...
app/src/main/java/com/topjohnwu/magisk/
arch/BaseMain
Activity.kt
→
app/src/main/java/com/topjohnwu/magisk/
ui/Splash
Activity.kt
View file @
317153c5
package
com.topjohnwu.magisk.
arch
package
com.topjohnwu.magisk.
ui
import
android.Manifest.permission.REQUEST_INSTALL_PACKAGES
import
android.Manifest.permission.REQUEST_INSTALL_PACKAGES
import
android.annotation.SuppressLint
import
android.annotation.SuppressLint
...
@@ -9,7 +9,7 @@ import androidx.databinding.ViewDataBinding
...
@@ -9,7 +9,7 @@ import androidx.databinding.ViewDataBinding
import
androidx.lifecycle.lifecycleScope
import
androidx.lifecycle.lifecycleScope
import
com.topjohnwu.magisk.BuildConfig.APPLICATION_ID
import
com.topjohnwu.magisk.BuildConfig.APPLICATION_ID
import
com.topjohnwu.magisk.R
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.Config
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.JobService
import
com.topjohnwu.magisk.core.JobService
...
@@ -25,16 +25,17 @@ import com.topjohnwu.magisk.view.Shortcuts
...
@@ -25,16 +25,17 @@ import com.topjohnwu.magisk.view.Shortcuts
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
abstract
class
BaseMainActivity
<
Binding
:
ViewDataBinding
>
:
NavigationActivity
<
Binding
>()
{
@SuppressLint
(
"CustomSplashScreen"
)
abstract
class
SplashActivity
<
Binding
:
ViewDataBinding
>
:
NavigationActivity
<
Binding
>()
{
companion
object
{
companion
object
{
private
var
doPreload
=
tru
e
private
var
skipSplash
=
fals
e
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
setTheme
(
Theme
.
selected
.
themeRes
)
setTheme
(
Theme
.
selected
.
themeRes
)
if
(
isRunningAsStub
&&
doPreload
)
{
if
(
isRunningAsStub
&&
!
skipSplash
)
{
// Manually apply splash theme for stub
// Manually apply splash theme for stub
theme
.
applyStyle
(
R
.
style
.
StubSplashTheme
,
true
)
theme
.
applyStyle
(
R
.
style
.
StubSplashTheme
,
true
)
}
}
...
@@ -43,28 +44,19 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
...
@@ -43,28 +44,19 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
if
(!
isRunningAsStub
)
{
if
(!
isRunningAsStub
)
{
val
splashScreen
=
installSplashScreen
()
val
splashScreen
=
installSplashScreen
()
splashScreen
.
setKeepOnScreenCondition
{
doPreload
}
splashScreen
.
setKeepOnScreenCondition
{
!
skipSplash
}
}
}
if
(
doPreload
)
{
if
(
skipSplash
)
{
showMainUI
(
savedInstanceState
)
}
else
{
Shell
.
getShell
(
Shell
.
EXECUTOR
)
{
Shell
.
getShell
(
Shell
.
EXECUTOR
)
{
if
(
isRunningAsStub
&&
!
it
.
isRoot
)
{
if
(
isRunningAsStub
&&
!
it
.
isRoot
)
{
showInvalidStateMessage
()
showInvalidStateMessage
()
return
@getShell
return
@getShell
}
}
preLoad
()
preLoad
(
savedInstanceState
)
runOnUiThread
{
doPreload
=
false
if
(
isRunningAsStub
)
{
// Re-launch main activity without splash theme
relaunch
()
}
else
{
showMainUI
(
savedInstanceState
)
}
}
}
}
}
else
{
showMainUI
(
savedInstanceState
)
}
}
}
}
...
@@ -84,7 +76,7 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
...
@@ -84,7 +76,7 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
showInvalidStateMessage
()
showInvalidStateMessage
()
}
else
{
}
else
{
lifecycleScope
.
launch
{
lifecycleScope
.
launch
{
HideAPK
.
restore
(
this
@
BaseMain
Activity
)
HideAPK
.
restore
(
this
@
Splash
Activity
)
}
}
}
}
}
}
...
@@ -95,10 +87,10 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
...
@@ -95,10 +87,10 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
}
}
}
}
private
fun
preLoad
()
{
private
fun
preLoad
(
savedState
:
Bundle
?
)
{
val
prevPkg
=
intent
.
getStringExtra
(
Const
.
Key
.
PREV_PKG
)
?.
let
{
val
prevPkg
=
intent
.
getStringExtra
(
Const
.
Key
.
PREV_PKG
)
?.
let
{
// Make sure the calling package matches (prevent DoS)
// Make sure the calling package matches (prevent DoS)
if
(
it
==
c
allingPackage
)
if
(
it
==
realC
allingPackage
)
it
it
else
else
null
null
...
@@ -106,9 +98,14 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
...
@@ -106,9 +98,14 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
Config
.
load
(
prevPkg
)
Config
.
load
(
prevPkg
)
handleRepackage
(
prevPkg
)
handleRepackage
(
prevPkg
)
if
(
prevPkg
!=
null
)
{
if
(
prevPkg
!=
null
&&
!
isRunningAsStub
)
{
StubApk
.
restartProcess
(
this
)
runOnUiThread
{
// Might have new configuration loaded, relaunch the activity
relaunch
()
}
return
}
}
Notifications
.
setup
(
this
)
Notifications
.
setup
(
this
)
JobService
.
schedule
(
this
)
JobService
.
schedule
(
this
)
Shortcuts
.
setupDynamic
(
this
)
Shortcuts
.
setupDynamic
(
this
)
...
@@ -118,6 +115,16 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
...
@@ -118,6 +115,16 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
// Wait for root service
// Wait for root service
RootUtils
.
Connection
.
await
()
RootUtils
.
Connection
.
await
()
runOnUiThread
{
skipSplash
=
true
if
(
isRunningAsStub
)
{
// Re-launch main activity without splash theme
relaunch
()
}
else
{
showMainUI
(
savedState
)
}
}
}
}
private
fun
handleRepackage
(
pkg
:
String
?)
{
private
fun
handleRepackage
(
pkg
:
String
?)
{
...
...
app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeViewModel.kt
View file @
317153c5
package
com.topjohnwu.magisk.ui.theme
package
com.topjohnwu.magisk.ui.theme
import
com.topjohnwu.magisk.arch.BaseViewModel
import
com.topjohnwu.magisk.arch.BaseViewModel
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.events.RecreateEvent
import
com.topjohnwu.magisk.events.RecreateEvent
import
com.topjohnwu.magisk.events.dialog.DarkThemeDialog
import
com.topjohnwu.magisk.events.dialog.DarkThemeDialog
import
com.topjohnwu.magisk.view.TappableHeadlineItem
import
com.topjohnwu.magisk.view.TappableHeadlineItem
...
@@ -10,15 +11,13 @@ class ThemeViewModel : BaseViewModel(), TappableHeadlineItem.Listener {
...
@@ -10,15 +11,13 @@ class ThemeViewModel : BaseViewModel(), TappableHeadlineItem.Listener {
val
themeHeadline
=
TappableHeadlineItem
.
ThemeMode
val
themeHeadline
=
TappableHeadlineItem
.
ThemeMode
override
fun
onItemPressed
(
item
:
TappableHeadlineItem
)
=
when
(
item
)
{
override
fun
onItemPressed
(
item
:
TappableHeadlineItem
)
=
when
(
item
)
{
is
TappableHeadlineItem
.
ThemeMode
->
darkModePressed
()
is
TappableHeadlineItem
.
ThemeMode
->
DarkThemeDialog
().
publish
()
else
->
Unit
}
}
fun
saveTheme
(
theme
:
Theme
)
{
fun
saveTheme
(
theme
:
Theme
)
{
theme
.
select
()
if
(!
theme
.
isSelected
)
{
RecreateEvent
().
publish
()
Config
.
themeOrdinal
=
theme
.
ordinal
RecreateEvent
().
publish
()
}
}
}
private
fun
darkModePressed
()
=
DarkThemeDialog
().
publish
()
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment