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
e85d5e54
Commit
e85d5e54
authored
Feb 11, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update root shell preparation
parent
5fb071d8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
31 deletions
+63
-31
Info.kt
app/src/main/java/com/topjohnwu/magisk/core/Info.kt
+7
-8
SplashActivity.kt
...src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt
+7
-21
DTBPatch.kt
...src/main/java/com/topjohnwu/magisk/core/tasks/DTBPatch.kt
+37
-0
RootInit.kt
...src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt
+8
-0
manager.sh
app/src/main/res/raw/manager.sh
+4
-2
No files found.
app/src/main/java/com/topjohnwu/magisk/core/Info.kt
View file @
e85d5e54
...
@@ -8,7 +8,7 @@ import com.topjohnwu.magisk.extensions.subscribeK
...
@@ -8,7 +8,7 @@ import com.topjohnwu.magisk.extensions.subscribeK
import
com.topjohnwu.magisk.utils.CachedValue
import
com.topjohnwu.magisk.utils.CachedValue
import
com.topjohnwu.magisk.utils.KObservableField
import
com.topjohnwu.magisk.utils.KObservableField
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.ShellUtils
import
com.topjohnwu.superuser.ShellUtils
.fastCmd
import
java.io.FileInputStream
import
java.io.FileInputStream
import
java.io.IOException
import
java.io.IOException
...
@@ -56,12 +56,11 @@ object Info {
...
@@ -56,12 +56,11 @@ object Info {
}
}
}
}
private
fun
loadState
()
=
runCatching
{
private
fun
loadState
()
=
Env
(
val
str
=
ShellUtils
.
fastCmd
(
"magisk -v"
).
split
(
":"
.
toRegex
())[
0
]
fastCmd
(
"magisk -v"
).
split
(
":"
.
toRegex
())[
0
],
val
code
=
ShellUtils
.
fastCmd
(
"magisk -V"
).
toInt
()
runCatching
{
fastCmd
(
"magisk -V"
).
toInt
()
}.
getOrDefault
(-
1
),
val
hide
=
Shell
.
su
(
"magiskhide --status"
).
exec
().
isSuccess
Shell
.
su
(
"magiskhide --status"
).
exec
().
isSuccess
Env
(
str
,
code
,
hide
)
)
}.
getOrElse
{
Env
()
}
class
Env
(
class
Env
(
val
magiskVersionString
:
String
=
""
,
val
magiskVersionString
:
String
=
""
,
...
@@ -71,7 +70,7 @@ object Info {
...
@@ -71,7 +70,7 @@ object Info {
val
magiskHide
get
()
=
Config
.
magiskHide
val
magiskHide
get
()
=
Config
.
magiskHide
val
magiskVersionCode
=
when
(
code
)
{
val
magiskVersionCode
=
when
(
code
)
{
in
Int
.
MIN_VALUE
..
Const
.
Version
.
MIN_VERCODE
->
-
1
in
Int
.
MIN_VALUE
..
Const
.
Version
.
MIN_VERCODE
->
-
1
else
->
if
(
Shell
.
rootAccess
())
code
else
-
1
else
->
if
(
Shell
.
rootAccess
())
code
else
-
1
}
}
val
isUnsupported
=
code
>
0
&&
code
<
Const
.
Version
.
MIN_VERCODE
val
isUnsupported
=
code
>
0
&&
code
<
Const
.
Version
.
MIN_VERCODE
val
isActive
=
magiskVersionCode
>=
0
val
isActive
=
magiskVersionCode
>=
0
...
...
app/src/main/java/com/topjohnwu/magisk/core/SplashActivity.kt
View file @
e85d5e54
...
@@ -4,12 +4,12 @@ import android.app.Activity
...
@@ -4,12 +4,12 @@ import android.app.Activity
import
android.content.Context
import
android.content.Context
import
android.os.Bundle
import
android.os.Bundle
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.core.tasks.patchDTB
import
com.topjohnwu.magisk.core.utils.Utils
import
com.topjohnwu.magisk.core.utils.Utils
import
com.topjohnwu.magisk.core.view.Notifications
import
com.topjohnwu.magisk.core.view.Notifications
import
com.topjohnwu.magisk.core.view.Shortcuts
import
com.topjohnwu.magisk.core.view.Shortcuts
import
com.topjohnwu.magisk.model.navigation.Navigation
import
com.topjohnwu.magisk.model.navigation.Navigation
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.ShellUtils
open
class
SplashActivity
:
Activity
()
{
open
class
SplashActivity
:
Activity
()
{
...
@@ -22,7 +22,7 @@ open class SplashActivity : Activity() {
...
@@ -22,7 +22,7 @@ open class SplashActivity : Activity() {
Shell
.
getShell
{
initAndStart
()
}
Shell
.
getShell
{
initAndStart
()
}
}
}
private
fun
initAndStart
()
{
private
fun
handleRepackage
()
{
val
pkg
=
Config
.
suManager
val
pkg
=
Config
.
suManager
if
(
Config
.
suManager
.
isNotEmpty
()
&&
packageName
==
BuildConfig
.
APPLICATION_ID
)
{
if
(
Config
.
suManager
.
isNotEmpty
()
&&
packageName
==
BuildConfig
.
APPLICATION_ID
)
{
Config
.
suManager
=
""
Config
.
suManager
=
""
...
@@ -35,31 +35,17 @@ open class SplashActivity : Activity() {
...
@@ -35,31 +35,17 @@ open class SplashActivity : Activity() {
Shell
.
su
(
"pm uninstall "
+
BuildConfig
.
APPLICATION_ID
).
submit
()
Shell
.
su
(
"pm uninstall "
+
BuildConfig
.
APPLICATION_ID
).
submit
()
}
}
}
}
}
Info
.
keepVerity
=
ShellUtils
.
fastCmd
(
"echo \$KEEPVERITY"
).
toBoolean
()
private
fun
initAndStart
()
{
Info
.
keepEnc
=
ShellUtils
.
fastCmd
(
"echo \$KEEPFORCEENCRYPT"
).
toBoolean
()
Info
.
recovery
=
ShellUtils
.
fastCmd
(
"echo \$RECOVERYMODE"
).
toBoolean
()
// Set default configs
Config
.
initialize
()
Config
.
initialize
()
handleRepackage
()
// Create notification channel on Android O
Notifications
.
setup
(
this
)
Notifications
.
setup
(
this
)
// Schedule periodic update checks
Utils
.
scheduleUpdateCheck
(
this
)
Utils
.
scheduleUpdateCheck
(
this
)
// Setup shortcuts
Shortcuts
.
setup
(
this
)
Shortcuts
.
setup
(
this
)
if
(
Info
.
isNewReboot
)
{
// Patch DTB partitions if needed
val
shell
=
Shell
.
newInstance
()
patchDTB
(
this
)
shell
.
newJob
().
add
(
"mm_patch_dtb"
).
submit
{
if
(
it
.
isSuccess
)
Notifications
.
dtboPatched
(
this
)
shell
.
close
()
}
}
DONE
=
true
DONE
=
true
Navigation
.
start
(
intent
,
this
)
Navigation
.
start
(
intent
,
this
)
...
...
app/src/main/java/com/topjohnwu/magisk/core/tasks/DTBPatch.kt
0 → 100644
View file @
e85d5e54
package
com.topjohnwu.magisk.core.tasks
import
android.content.Context
import
android.content.ContextWrapper
import
android.content.Intent
import
android.content.IntentFilter
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.core.base.BaseReceiver
import
com.topjohnwu.magisk.core.view.Notifications
import
com.topjohnwu.superuser.Shell
import
timber.log.Timber
private
const
val
DTB_PATCH_RESULT
=
"dtb_result"
private
const
val
DTB_PATCH_ACTION
=
"com.topjohnwu.magisk.DTBO_PATCH"
private
class
DTBPatchReceiver
:
BaseReceiver
()
{
override
fun
onReceive
(
context
:
ContextWrapper
,
intent
:
Intent
?)
{
intent
?.
also
{
val
result
=
it
.
getIntExtra
(
DTB_PATCH_RESULT
,
1
)
Timber
.
d
(
"result=[$result]"
)
if
(
result
==
0
)
Notifications
.
dtboPatched
(
context
)
}
context
.
unregisterReceiver
(
this
)
}
}
fun
patchDTB
(
context
:
Context
)
{
if
(
Info
.
isNewReboot
)
{
val
c
=
context
.
applicationContext
c
.
registerReceiver
(
DTBPatchReceiver
(),
IntentFilter
(
DTB_PATCH_ACTION
))
val
broadcastCmd
=
"am broadcast --user ${Const.USER_ID} -p ${c.packageName} "
+
"-a $DTB_PATCH_ACTION --ei $DTB_PATCH_RESULT \$result"
Shell
.
su
(
"mm_patch_dtb '$broadcastCmd'"
).
submit
()
}
}
app/src/main/java/com/topjohnwu/magisk/core/utils/RootInit.kt
View file @
e85d5e54
...
@@ -3,9 +3,11 @@ package com.topjohnwu.magisk.core.utils
...
@@ -3,9 +3,11 @@ package com.topjohnwu.magisk.core.utils
import
android.content.Context
import
android.content.Context
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.Info
import
com.topjohnwu.magisk.core.wrap
import
com.topjohnwu.magisk.core.wrap
import
com.topjohnwu.magisk.extensions.rawResource
import
com.topjohnwu.magisk.extensions.rawResource
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.ShellUtils
import
com.topjohnwu.superuser.io.SuFile
import
com.topjohnwu.superuser.io.SuFile
class
RootInit
:
Shell
.
Initializer
()
{
class
RootInit
:
Shell
.
Initializer
()
{
...
@@ -30,6 +32,12 @@ class RootInit : Shell.Initializer() {
...
@@ -30,6 +32,12 @@ class RootInit : Shell.Initializer() {
"export BOOTMODE=true"
"export BOOTMODE=true"
).
exec
()
).
exec
()
fun
getvar
(
name
:
String
)
=
ShellUtils
.
fastCmd
(
shell
,
"echo \$$name"
).
toBoolean
()
Info
.
keepVerity
=
getvar
(
"KEEPVERITY"
)
Info
.
keepEnc
=
getvar
(
"KEEPFORCEENCRYPT"
)
Info
.
recovery
=
getvar
(
"RECOVERYMODE"
)
return
true
return
true
}
}
}
}
app/src/main/res/raw/manager.sh
View file @
e85d5e54
...
@@ -38,7 +38,7 @@ direct_install() {
...
@@ -38,7 +38,7 @@ direct_install() {
}
}
mm_patch_dtb
()
{
mm_patch_dtb
()
{
local
result
=
1
(
local
result
=
1
local
PATCHED
=
$TMPDIR
/dt.patched
local
PATCHED
=
$TMPDIR
/dt.patched
for
name
in
dtb dtbo
;
do
for
name
in
dtb dtbo
;
do
local
IMAGE
=
`
find_block
$name$SLOT
`
local
IMAGE
=
`
find_block
$name$SLOT
`
...
@@ -55,7 +55,9 @@ mm_patch_dtb() {
...
@@ -55,7 +55,9 @@ mm_patch_dtb() {
fi
fi
fi
fi
done
done
return
$result
# Run broadcast command passed from app
eval
$1
)
&
>
/dev/null 2>&1
}
}
restore_imgs
()
{
restore_imgs
()
{
...
...
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