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
f2c15c77
Commit
f2c15c77
authored
Mar 24, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure RootService is launched
parent
e67d0678
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
23 deletions
+102
-23
build.gradle.kts
app/build.gradle.kts
+1
-1
BaseMainActivity.kt
...c/main/java/com/topjohnwu/magisk/arch/BaseMainActivity.kt
+4
-0
App.kt
app/src/main/java/com/topjohnwu/magisk/core/App.kt
+18
-20
RootUtils.kt
...rc/main/java/com/topjohnwu/magisk/core/utils/RootUtils.kt
+77
-0
ShellInit.kt
...rc/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt
+2
-2
No files found.
app/build.gradle.kts
View file @
f2c15c77
...
...
@@ -86,7 +86,7 @@ dependencies {
implementation
(
"${bindingAdapter}:${vBAdapt}"
)
implementation
(
"${bindingAdapter}-recyclerview:${vBAdapt}"
)
val
vLibsu
=
"4.0.
2
"
val
vLibsu
=
"4.0.
3
"
implementation
(
"com.github.topjohnwu.libsu:core:${vLibsu}"
)
implementation
(
"com.github.topjohnwu.libsu:io:${vLibsu}"
)
implementation
(
"com.github.topjohnwu.libsu:service:${vLibsu}"
)
...
...
app/src/main/java/com/topjohnwu/magisk/arch/BaseMainActivity.kt
View file @
f2c15c77
...
...
@@ -14,6 +14,7 @@ import com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.JobService
import
com.topjohnwu.magisk.core.isRunningAsStub
import
com.topjohnwu.magisk.core.tasks.HideAPK
import
com.topjohnwu.magisk.core.utils.RootUtils
import
com.topjohnwu.magisk.di.ServiceLocator
import
com.topjohnwu.magisk.ui.theme.Theme
import
com.topjohnwu.magisk.utils.Utils
...
...
@@ -104,6 +105,9 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
// Pre-fetch network services
ServiceLocator
.
networkService
// Wait for root service
RootUtils
.
Connection
.
await
()
}
private
fun
handleRepackage
(
pkg
:
String
?)
{
...
...
app/src/main/java/com/topjohnwu/magisk/core/App.kt
View file @
f2c15c77
...
...
@@ -8,6 +8,7 @@ import android.content.res.Configuration
import
android.os.Bundle
import
com.topjohnwu.magisk.StubApk
import
com.topjohnwu.magisk.core.utils.*
import
com.topjohnwu.magisk.di.AppContext
import
com.topjohnwu.magisk.di.ServiceLocator
import
com.topjohnwu.magisk.ui.surequest.SuRequestActivity
import
com.topjohnwu.superuser.Shell
...
...
@@ -22,9 +23,9 @@ open class App() : Application() {
constructor
(
o
:
Any
)
:
this
()
{
val
data
=
StubApk
.
Data
(
o
)
// Add the root service name mapping
data
.
classToComponent
[
Root
Registry
::
class
.
java
.
name
]
=
data
.
rootService
.
name
data
.
classToComponent
[
Root
Utils
::
class
.
java
.
name
]
=
data
.
rootService
.
name
// Send back the actual root service class
data
.
rootService
=
Root
Registry
::
class
.
java
data
.
rootService
=
Root
Utils
::
class
.
java
Info
.
stub
=
data
}
...
...
@@ -38,43 +39,40 @@ open class App() : Application() {
}
override
fun
attachBaseContext
(
context
:
Context
)
{
Shell
.
setDefaultBuilder
(
Shell
.
Builder
.
create
()
.
setFlags
(
Shell
.
FLAG_MOUNT_MASTER
)
.
setInitializers
(
ShellInit
::
class
.
java
)
.
setTimeout
(
2
))
Shell
.
EXECUTOR
=
DispatcherExecutor
(
Dispatchers
.
IO
)
// Get the actual ContextImpl
val
app
:
Application
val
base
:
Context
if
(
context
is
Application
)
{
app
=
context
base
=
context
.
baseContext
AppApkPath
=
StubApk
.
current
(
base
).
path
}
else
{
app
=
this
base
=
context
AppApkPath
=
base
.
packageResourcePath
}
super
.
attachBaseContext
(
base
)
ServiceLocator
.
context
=
base
refreshLocale
()
AppApkPath
=
if
(
isRunningAsStub
)
{
StubApk
.
current
(
base
).
path
}
else
{
base
.
packageResourcePath
}
base
.
resources
.
patch
()
app
.
registerActivityLifecycleCallbacks
(
ActivityTracker
)
}
override
fun
onCreate
()
{
super
.
onCreate
()
RootRegistry
.
bindTask
=
RootService
.
bindOrTask
(
intent
<
RootRegistry
>(),
Shell
.
setDefaultBuilder
(
Shell
.
Builder
.
create
()
.
setFlags
(
Shell
.
FLAG_MOUNT_MASTER
)
.
setInitializers
(
ShellInit
::
class
.
java
)
.
setTimeout
(
2
))
Shell
.
EXECUTOR
=
DispatcherExecutor
(
Dispatchers
.
IO
)
RootUtils
.
bindTask
=
RootService
.
bindOrTask
(
intent
<
RootUtils
>(),
UiThreadHandler
.
executor
,
Root
Registry
.
Connection
Root
Utils
.
Connection
)
// Pre-heat the shell ASAP
Shell
.
getShell
(
null
)
{}
refreshLocale
()
AppContext
.
resources
.
patch
()
}
override
fun
onConfigurationChanged
(
newConfig
:
Configuration
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/core/utils/Root
Registry
.kt
→
app/src/main/java/com/topjohnwu/magisk/core/utils/Root
Utils
.kt
View file @
f2c15c77
...
...
@@ -6,49 +6,72 @@ import android.content.ServiceConnection
import
android.os.Binder
import
android.os.IBinder
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.ShellUtils
import
com.topjohnwu.superuser.ipc.RootService
import
timber.log.Timber
import
java.util.concurrent.CountDownLatch
import
kotlin.system.exitProcess
import
java.util.concurrent.locks.AbstractQueuedSynchronizer
class
RootRegistry
(
stub
:
Any
?)
:
RootService
()
{
class
RootUtils
(
stub
:
Any
?)
:
RootService
()
{
private
val
className
:
String
=
stub
?.
javaClass
?.
name
?:
javaClass
.
name
constructor
()
:
this
(
null
)
{
// Always log full stack trace with Timber
Timber
.
plant
(
Timber
.
DebugTree
())
Thread
.
setDefaultUncaughtExceptionHandler
{
_
,
e
->
Timber
.
e
(
e
)
exitProcess
(
1
)
}
}
private
val
className
:
String
?
=
stub
?.
javaClass
?.
name
override
fun
getComponentName
():
ComponentName
{
return
ComponentName
(
packageName
,
className
)
}
override
fun
onBind
(
intent
:
Intent
):
IBinder
{
// TODO: PLACEHOLDER
return
Binder
()
}
override
fun
getComponentName
():
ComponentName
{
return
ComponentName
(
packageName
,
className
?:
javaClass
.
name
)
}
object
Connection
:
AbstractQueuedSynchronizer
(),
ServiceConnection
{
init
{
state
=
1
}
// TODO: PLACEHOLDER
object
Connection
:
CountDownLatch
(
1
),
ServiceConnection
{
override
fun
onServiceConnected
(
name
:
ComponentName
,
service
:
IBinder
)
{
Timber
.
d
(
"onServiceConnected"
)
countDown
()
}
override
fun
onNullBinding
(
name
:
ComponentName
)
{
Timber
.
d
(
"onServiceConnected"
)
countDown
()
obj
=
IRootUtils
.
Stub
.
asInterface
(
service
)
releaseShared
(
1
)
}
override
fun
onServiceDisconnected
(
name
:
ComponentName
)
{
state
=
1
obj
=
null
bind
(
Intent
().
setComponent
(
name
),
this
)
}
override
fun
tryAcquireShared
(
acquires
:
Int
)
=
if
(
state
==
0
)
1
else
-
1
override
fun
tryReleaseShared
(
releases
:
Int
):
Boolean
{
// Decrement count; signal when transition to zero
while
(
true
)
{
val
c
=
state
if
(
c
==
0
)
return
false
val
n
=
c
-
1
if
(
compareAndSetState
(
c
,
n
))
return
n
==
0
}
}
fun
await
()
{
// We cannot await on the main thread
if
(!
ShellUtils
.
onMainThread
())
acquireSharedInterruptibly
(
1
)
}
}
companion
object
{
var
bindTask
:
Shell
.
Task
?
=
null
var
obj
:
IRootUtils
?
=
null
get
()
{
Connection
.
await
()
return
field
}
private
set
}
}
app/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt
View file @
f2c15c77
...
...
@@ -19,8 +19,8 @@ import java.util.jar.JarFile
class
ShellInit
:
Shell
.
Initializer
()
{
override
fun
onInit
(
context
:
Context
,
shell
:
Shell
):
Boolean
{
if
(
shell
.
isRoot
)
{
Root
Registry
.
bindTask
?.
let
{
shell
.
execTask
(
it
)
}
Root
Registry
.
bindTask
=
null
Root
Utils
.
bindTask
?.
let
{
shell
.
execTask
(
it
)
}
Root
Utils
.
bindTask
=
null
}
shell
.
newJob
().
apply
{
add
(
"export ASH_STANDALONE=1"
)
...
...
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