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
0ad0ef48
Commit
0ad0ef48
authored
Jan 18, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bump min Magisk version to v21.0
Close #5220
parent
7dfe3e53
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
94 deletions
+19
-94
Const.kt
app/src/main/java/com/topjohnwu/magisk/core/Const.kt
+2
-3
Provider.kt
app/src/main/java/com/topjohnwu/magisk/core/Provider.kt
+1
-1
SuCallbackHandler.kt
...in/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt
+1
-31
SuRequestHandler.kt
...ain/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt
+11
-45
SuRequestActivity.kt
...va/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.kt
+4
-14
No files found.
app/src/main/java/com/topjohnwu/magisk/core/Const.kt
View file @
0ad0ef48
...
@@ -25,10 +25,9 @@ object Const {
...
@@ -25,10 +25,9 @@ object Const {
val
APP_IS_CANARY
get
()
=
Version
.
isCanary
(
BuildConfig
.
VERSION_CODE
)
val
APP_IS_CANARY
get
()
=
Version
.
isCanary
(
BuildConfig
.
VERSION_CODE
)
object
Version
{
object
Version
{
const
val
MIN_VERSION
=
"v2
0.4
"
const
val
MIN_VERSION
=
"v2
1.0
"
const
val
MIN_VERCODE
=
2
04
00
const
val
MIN_VERCODE
=
2
10
00
fun
atLeast_21_0
()
=
Info
.
env
.
versionCode
>=
21000
||
isCanary
()
fun
atLeast_21_2
()
=
Info
.
env
.
versionCode
>=
21200
||
isCanary
()
fun
atLeast_21_2
()
=
Info
.
env
.
versionCode
>=
21200
||
isCanary
()
fun
isCanary
()
=
isCanary
(
Info
.
env
.
versionCode
)
fun
isCanary
()
=
isCanary
(
Info
.
env
.
versionCode
)
...
...
app/src/main/java/com/topjohnwu/magisk/core/Provider.kt
View file @
0ad0ef48
...
@@ -19,7 +19,7 @@ class Provider : ContentProvider() {
...
@@ -19,7 +19,7 @@ class Provider : ContentProvider() {
}
}
override
fun
call
(
method
:
String
,
arg
:
String
?,
extras
:
Bundle
?):
Bundle
?
{
override
fun
call
(
method
:
String
,
arg
:
String
?,
extras
:
Bundle
?):
Bundle
?
{
SuCallbackHandler
(
context
!!
,
method
,
extras
)
SuCallbackHandler
.
run
(
context
!!
,
method
,
extras
)
return
Bundle
.
EMPTY
return
Bundle
.
EMPTY
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/core/su/SuCallbackHandler.kt
View file @
0ad0ef48
package
com.topjohnwu.magisk.core.su
package
com.topjohnwu.magisk.core.su
import
android.content.Context
import
android.content.Context
import
android.content.Intent
import
android.os.Build
import
android.os.Bundle
import
android.os.Bundle
import
android.os.Process
import
android.os.Process
import
android.widget.Toast
import
android.widget.Toast
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.intent
import
com.topjohnwu.magisk.core.model.su.SuPolicy
import
com.topjohnwu.magisk.core.model.su.SuPolicy
import
com.topjohnwu.magisk.core.model.su.toLog
import
com.topjohnwu.magisk.core.model.su.toLog
import
com.topjohnwu.magisk.core.model.su.toPolicy
import
com.topjohnwu.magisk.core.model.su.toPolicy
import
com.topjohnwu.magisk.di.ServiceLocator
import
com.topjohnwu.magisk.di.ServiceLocator
import
com.topjohnwu.magisk.ktx.startActivity
import
com.topjohnwu.magisk.ktx.startActivityWithRoot
import
com.topjohnwu.magisk.ui.surequest.SuRequestActivity
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.superuser.Shell
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.launch
import
timber.log.Timber
import
timber.log.Timber
...
@@ -28,9 +21,8 @@ object SuCallbackHandler {
...
@@ -28,9 +21,8 @@ object SuCallbackHandler {
const
val
REQUEST
=
"request"
const
val
REQUEST
=
"request"
const
val
LOG
=
"log"
const
val
LOG
=
"log"
const
val
NOTIFY
=
"notify"
const
val
NOTIFY
=
"notify"
const
val
TEST
=
"test"
operator
fun
invoke
(
context
:
Context
,
action
:
String
?,
data
:
Bundle
?)
{
fun
run
(
context
:
Context
,
action
:
String
?,
data
:
Bundle
?)
{
data
?:
return
data
?:
return
// Debug messages
// Debug messages
...
@@ -44,16 +36,8 @@ object SuCallbackHandler {
...
@@ -44,16 +36,8 @@ object SuCallbackHandler {
}
}
when
(
action
)
{
when
(
action
)
{
REQUEST
->
handleRequest
(
context
,
data
)
LOG
->
handleLogging
(
context
,
data
)
LOG
->
handleLogging
(
context
,
data
)
NOTIFY
->
handleNotify
(
context
,
data
)
NOTIFY
->
handleNotify
(
context
,
data
)
TEST
->
{
val
mode
=
data
.
getInt
(
"mode"
,
2
)
Shell
.
su
(
"magisk --connect-mode $mode"
,
"magisk --use-broadcast"
).
submit
()
}
}
}
}
}
...
@@ -64,20 +48,6 @@ object SuCallbackHandler {
...
@@ -64,20 +48,6 @@ object SuCallbackHandler {
}
}
}
}
private
fun
handleRequest
(
context
:
Context
,
data
:
Bundle
)
{
val
intent
=
context
.
intent
<
SuRequestActivity
>()
.
setAction
(
REQUEST
)
.
putExtras
(
data
)
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
.
addFlags
(
Intent
.
FLAG_ACTIVITY_MULTIPLE_TASK
)
if
(
Build
.
VERSION
.
SDK_INT
>=
29
)
{
// Android Q does not allow starting activity from background
intent
.
startActivityWithRoot
()
}
else
{
intent
.
startActivity
(
context
)
}
}
private
fun
handleLogging
(
context
:
Context
,
data
:
Bundle
)
{
private
fun
handleLogging
(
context
:
Context
,
data
:
Bundle
)
{
val
fromUid
=
data
[
"from.uid"
].
toInt
()
?:
return
val
fromUid
=
data
[
"from.uid"
].
toInt
()
?:
return
if
(
fromUid
==
Process
.
myUid
())
if
(
fromUid
==
Process
.
myUid
())
...
...
app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt
View file @
0ad0ef48
...
@@ -2,9 +2,6 @@ package com.topjohnwu.magisk.core.su
...
@@ -2,9 +2,6 @@ package com.topjohnwu.magisk.core.su
import
android.content.Intent
import
android.content.Intent
import
android.content.pm.PackageManager
import
android.content.pm.PackageManager
import
android.net.LocalSocket
import
android.net.LocalSocketAddress
import
androidx.collection.ArrayMap
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.Config
import
com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.Const
...
@@ -12,11 +9,16 @@ import com.topjohnwu.magisk.core.magiskdb.PolicyDao
...
@@ -12,11 +9,16 @@ import com.topjohnwu.magisk.core.magiskdb.PolicyDao
import
com.topjohnwu.magisk.core.model.su.SuPolicy
import
com.topjohnwu.magisk.core.model.su.SuPolicy
import
com.topjohnwu.magisk.core.model.su.toPolicy
import
com.topjohnwu.magisk.core.model.su.toPolicy
import
com.topjohnwu.magisk.ktx.now
import
com.topjohnwu.magisk.ktx.now
import
kotlinx.coroutines.*
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
timber.log.Timber
import
timber.log.Timber
import
java.io.*
import
java.io.Closeable
import
java.io.DataOutputStream
import
java.io.FileOutputStream
import
java.io.IOException
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.TimeUnit.SECONDS
class
SuRequestHandler
(
class
SuRequestHandler
(
private
val
pm
:
PackageManager
,
private
val
pm
:
PackageManager
,
...
@@ -50,12 +52,6 @@ class SuRequestHandler(
...
@@ -50,12 +52,6 @@ class SuRequestHandler(
return
true
return
true
}
}
private
suspend
fun
<
T
>
Deferred
<
T
>.
timedAwait
()
:
T
?
{
return
withTimeoutOrNull
(
SECONDS
.
toMillis
(
1
))
{
await
()
}
}
@Throws
(
IOException
::
class
)
@Throws
(
IOException
::
class
)
override
fun
close
()
{
override
fun
close
()
{
if
(
::
output
.
isInitialized
)
if
(
::
output
.
isInitialized
)
...
@@ -66,20 +62,9 @@ class SuRequestHandler(
...
@@ -66,20 +62,9 @@ class SuRequestHandler(
private
suspend
fun
init
(
intent
:
Intent
)
=
withContext
(
Dispatchers
.
IO
)
{
private
suspend
fun
init
(
intent
:
Intent
)
=
withContext
(
Dispatchers
.
IO
)
{
try
{
try
{
val
uid
:
Int
if
(
Const
.
Version
.
atLeast_21_0
())
{
val
name
=
intent
.
getStringExtra
(
"fifo"
)
?:
throw
SuRequestError
()
val
name
=
intent
.
getStringExtra
(
"fifo"
)
?:
throw
SuRequestError
()
uid
=
intent
.
getIntExtra
(
"uid"
,
-
1
).
also
{
if
(
it
<
0
)
throw
SuRequestError
()
}
val
uid
=
intent
.
getIntExtra
(
"uid"
,
-
1
).
also
{
if
(
it
<
0
)
throw
SuRequestError
()
}
output
=
DataOutputStream
(
FileOutputStream
(
name
).
buffered
())
output
=
DataOutputStream
(
FileOutputStream
(
name
).
buffered
())
}
else
{
val
name
=
intent
.
getStringExtra
(
"socket"
)
?:
throw
SuRequestError
()
val
socket
=
LocalSocket
()
socket
.
connect
(
LocalSocketAddress
(
name
,
LocalSocketAddress
.
Namespace
.
ABSTRACT
))
output
=
DataOutputStream
(
BufferedOutputStream
(
socket
.
outputStream
))
val
input
=
DataInputStream
(
BufferedInputStream
(
socket
.
inputStream
))
val
map
=
async
{
input
.
readRequest
()
}.
timedAwait
()
?:
throw
SuRequestError
()
uid
=
map
[
"uid"
]
?.
toIntOrNull
()
?:
throw
SuRequestError
()
}
policy
=
uid
.
toPolicy
(
pm
)
policy
=
uid
.
toPolicy
(
pm
)
true
true
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
...
@@ -117,23 +102,4 @@ class SuRequestHandler(
...
@@ -117,23 +102,4 @@ class SuRequestHandler(
}
}
}
}
}
}
@Throws
(
IOException
::
class
)
private
fun
DataInputStream
.
readRequest
():
Map
<
String
,
String
>
{
fun
readString
():
String
{
val
len
=
readInt
()
val
buf
=
ByteArray
(
len
)
readFully
(
buf
)
return
String
(
buf
,
Charsets
.
UTF_8
)
}
val
ret
=
ArrayMap
<
String
,
String
>()
while
(
true
)
{
val
name
=
readString
()
if
(
name
==
"eof"
)
break
ret
[
name
]
=
readString
()
}
return
ret
}
}
}
app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.kt
View file @
0ad0ef48
...
@@ -37,26 +37,16 @@ open class SuRequestActivity : BaseUIActivity<SuRequestViewModel, ActivityReques
...
@@ -37,26 +37,16 @@ open class SuRequestActivity : BaseUIActivity<SuRequestViewModel, ActivityReques
setTheme
(
Theme
.
selected
.
themeRes
)
setTheme
(
Theme
.
selected
.
themeRes
)
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
fun
showRequest
()
{
viewModel
.
handleRequest
(
intent
)
}
fun
runHandler
(
action
:
String
?)
{
SuCallbackHandler
(
this
,
action
,
intent
.
extras
)
finish
()
}
if
(
intent
.
action
==
Intent
.
ACTION_VIEW
)
{
if
(
intent
.
action
==
Intent
.
ACTION_VIEW
)
{
val
action
=
intent
.
getStringExtra
(
"action"
)
val
action
=
intent
.
getStringExtra
(
"action"
)
if
(
action
==
REQUEST
)
{
if
(
action
==
REQUEST
)
{
showRequest
(
)
viewModel
.
handleRequest
(
intent
)
}
else
{
}
else
{
runHandler
(
action
)
SuCallbackHandler
.
run
(
this
,
action
,
intent
.
extras
)
finish
()
}
}
}
else
if
(
intent
.
action
==
REQUEST
)
{
showRequest
()
}
else
{
}
else
{
runHandler
(
intent
.
action
)
finish
(
)
}
}
}
}
...
...
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