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
3f7f6e61
Commit
3f7f6e61
authored
Aug 23, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use VERSION_CODES instead of raw numbers
parent
c2f96975
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
33 additions
and
26 deletions
+33
-26
StubApk.java
app/shared/src/main/java/com/topjohnwu/magisk/StubApk.java
+3
-2
BaseActivity.kt
.../main/java/com/topjohnwu/magisk/core/base/BaseActivity.kt
+4
-3
DownloadService.kt
...ava/com/topjohnwu/magisk/core/download/DownloadService.kt
+2
-2
MediaStoreUtils.kt
...n/java/com/topjohnwu/magisk/core/utils/MediaStoreUtils.kt
+1
-1
RequestInstall.kt
...in/java/com/topjohnwu/magisk/core/utils/RequestInstall.kt
+1
-1
NetworkObserver.kt
...va/com/topjohnwu/magisk/core/utils/net/NetworkObserver.kt
+1
-1
XAndroid.kt
app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt
+3
-2
AppProcessInfo.kt
.../main/java/com/topjohnwu/magisk/ui/deny/AppProcessInfo.kt
+3
-1
SettingsViewModel.kt
...ava/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
+5
-4
Notifications.kt
app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt
+5
-4
Shortcuts.kt
app/src/main/java/com/topjohnwu/magisk/view/Shortcuts.kt
+2
-2
DownloadActivity.java
.../src/main/java/com/topjohnwu/magisk/DownloadActivity.java
+1
-1
DynLoad.java
stub/src/main/java/com/topjohnwu/magisk/DynLoad.java
+2
-2
No files found.
app/shared/src/main/java/com/topjohnwu/magisk/StubApk.java
View file @
3f7f6e61
...
...
@@ -11,6 +11,7 @@ import android.content.res.AssetManager;
import
android.content.res.Resources
;
import
android.content.res.loader.ResourcesLoader
;
import
android.content.res.loader.ResourcesProvider
;
import
android.os.Build
;
import
android.os.ParcelFileDescriptor
;
import
java.io.File
;
...
...
@@ -28,7 +29,7 @@ public class StubApk {
private
static
File
getDynDir
(
ApplicationInfo
info
)
{
if
(
dynDir
==
null
)
{
final
String
dataDir
;
if
(
SDK_INT
>=
24
)
{
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
// Use device protected path to allow directBootAware
dataDir
=
info
.
deviceProtectedDataDir
;
}
else
{
...
...
@@ -57,7 +58,7 @@ public class StubApk {
}
public
static
void
addAssetPath
(
Resources
res
,
String
path
)
{
if
(
SDK_INT
>=
30
)
{
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
R
)
{
try
(
var
fd
=
ParcelFileDescriptor
.
open
(
new
File
(
path
),
MODE_READ_ONLY
))
{
var
loader
=
new
ResourcesLoader
();
loader
.
addProvider
(
ResourcesProvider
.
loadFromApk
(
fd
));
...
...
app/src/main/java/com/topjohnwu/magisk/core/base/BaseActivity.kt
View file @
3f7f6e61
...
...
@@ -52,7 +52,7 @@ abstract class BaseActivity : AppCompatActivity() {
val
realCallingPackage
:
String
?
get
()
{
callingPackage
?.
let
{
return
it
}
if
(
Build
.
VERSION
.
SDK_INT
>=
22
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP_MR1
)
{
mReferrerField
.
get
(
this
)
?.
let
{
return
it
as
String
}
}
return
null
...
...
@@ -82,8 +82,9 @@ abstract class BaseActivity : AppCompatActivity() {
}
fun
withPermission
(
permission
:
String
,
callback
:
(
Boolean
)
->
Unit
)
{
if
(
permission
==
WRITE_EXTERNAL_STORAGE
&&
Build
.
VERSION
.
SDK_INT
>=
30
)
{
// We do not need external rw on 30+
if
(
permission
==
WRITE_EXTERNAL_STORAGE
&&
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
)
{
// We do not need external rw on R+
callback
(
true
)
return
}
...
...
app/src/main/java/com/topjohnwu/magisk/core/download/DownloadService.kt
View file @
3f7f6e61
...
...
@@ -199,7 +199,7 @@ class DownloadService : NotificationService() {
fun
getPendingIntent
(
context
:
Context
,
subject
:
Subject
):
PendingIntent
{
val
flag
=
FLAG_IMMUTABLE
or
FLAG_UPDATE_CURRENT
or
FLAG_ONE_SHOT
val
intent
=
intent
(
context
,
subject
)
return
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
{
return
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
getForegroundService
(
context
,
REQUEST_CODE
,
intent
,
flag
)
}
else
{
getService
(
context
,
REQUEST_CODE
,
intent
,
flag
)
...
...
@@ -208,7 +208,7 @@ class DownloadService : NotificationService() {
fun
start
(
context
:
Context
,
subject
:
Subject
)
{
val
app
=
context
.
applicationContext
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
app
.
startForegroundService
(
intent
(
app
,
subject
))
}
else
{
app
.
startService
(
intent
(
app
,
subject
))
...
...
app/src/main/java/com/topjohnwu/magisk/core/utils/MediaStoreUtils.kt
View file @
3f7f6e61
...
...
@@ -87,7 +87,7 @@ object MediaStoreUtils {
@Throws
(
IOException
::
class
)
fun
getFile
(
displayName
:
String
,
skipQuery
:
Boolean
=
false
):
UriFile
{
if
(
Build
.
VERSION
.
SDK_INT
<
30
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
R
)
{
// Fallback to file based I/O pre Android 11
val
parent
=
File
(
Environment
.
getExternalStorageDirectory
(),
relativePath
)
parent
.
mkdirs
()
...
...
app/src/main/java/com/topjohnwu/magisk/core/utils/RequestInstall.kt
View file @
3f7f6e61
...
...
@@ -25,7 +25,7 @@ class RequestInstall : ActivityResultContract<Unit, Boolean>() {
context
:
Context
,
input
:
Unit
):
SynchronousResult
<
Boolean
>?
{
if
(
Build
.
VERSION
.
SDK_INT
<
26
)
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
O
)
return
SynchronousResult
(
true
)
if
(
context
.
packageManager
.
canRequestPackageInstalls
())
return
SynchronousResult
(
true
)
...
...
app/src/main/java/com/topjohnwu/magisk/core/utils/net/NetworkObserver.kt
View file @
3f7f6e61
...
...
@@ -20,7 +20,7 @@ abstract class NetworkObserver(
companion
object
{
fun
observe
(
context
:
Context
,
callback
:
ConnectionCallback
):
NetworkObserver
{
val
observer
:
NetworkObserver
=
if
(
Build
.
VERSION
.
SDK_INT
>=
23
)
val
observer
:
NetworkObserver
=
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
)
MarshmallowNetworkObserver
(
context
,
callback
)
else
LollipopNetworkObserver
(
context
,
callback
)
return
observer
.
apply
{
getCurrentState
()
}
...
...
app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt
View file @
3f7f6e61
...
...
@@ -17,6 +17,7 @@ import android.graphics.drawable.AdaptiveIconDrawable
import
android.graphics.drawable.BitmapDrawable
import
android.graphics.drawable.LayerDrawable
import
android.net.Uri
import
android.os.Build
import
android.os.Build.VERSION.SDK_INT
import
android.os.Process
import
android.view.View
...
...
@@ -44,7 +45,7 @@ fun Context.getBitmap(id: Int): Bitmap {
var
drawable
=
AppCompatResources
.
getDrawable
(
this
,
id
)
!!
if
(
drawable
is
BitmapDrawable
)
return
drawable
.
bitmap
if
(
SDK_INT
>=
26
&&
drawable
is
AdaptiveIconDrawable
)
{
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
&&
drawable
is
AdaptiveIconDrawable
)
{
drawable
=
LayerDrawable
(
arrayOf
(
drawable
.
background
,
drawable
.
foreground
))
}
val
bitmap
=
Bitmap
.
createBitmap
(
...
...
@@ -58,7 +59,7 @@ fun Context.getBitmap(id: Int): Bitmap {
}
val
Context
.
deviceProtectedContext
:
Context
get
()
=
if
(
SDK_INT
>=
24
)
{
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
createDeviceProtectedStorageContext
()
}
else
{
this
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/deny/AppProcessInfo.kt
View file @
3f7f6e61
...
...
@@ -7,6 +7,7 @@ import android.content.pm.PackageManager
import
android.content.pm.PackageManager.*
import
android.content.pm.ServiceInfo
import
android.graphics.drawable.Drawable
import
android.os.Build
import
android.os.Build.VERSION.SDK_INT
import
androidx.core.os.ProcessCompat
import
com.topjohnwu.magisk.core.utils.currentLocale
...
...
@@ -67,7 +68,8 @@ class AppProcessInfo(
val
proc
=
info
.
processName
?:
info
.
packageName
createProcess
(
"${proc}_zygote"
)
}
else
{
val
proc
=
if
(
SDK_INT
>=
29
)
"${it.getProcName()}:${it.name}"
else
it
.
getProcName
()
val
proc
=
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
)
"${it.getProcName()}:${it.name}"
else
it
.
getProcName
()
createProcess
(
proc
,
ISOLATED_MAGIC
)
}
}
else
{
...
...
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
View file @
3f7f6e61
...
...
@@ -53,7 +53,8 @@ class SettingsViewModel : BaseViewModel(), BaseSettingsItem.Handler {
AppSettings
,
UpdateChannel
,
UpdateChannelUrl
,
DoHToggle
,
UpdateChecker
,
DownloadPath
))
if
(
Build
.
VERSION
.
SDK_INT
>=
22
&&
Info
.
env
.
isActive
&&
Const
.
USER_ID
==
0
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP_MR1
&&
Info
.
env
.
isActive
&&
Const
.
USER_ID
==
0
)
{
if
(
hidden
)
list
.
add
(
Restore
)
else
list
.
add
(
Hide
)
}
...
...
@@ -75,15 +76,15 @@ class SettingsViewModel : BaseViewModel(), BaseSettingsItem.Handler {
Tapjack
,
Biometrics
,
AccessMode
,
MultiuserMode
,
MountNamespaceMode
,
AutomaticResponse
,
RequestTimeout
,
SUNotification
))
if
(
Build
.
VERSION
.
SDK_INT
<
23
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
M
)
{
// Biometric is only available on 6.0+
list
.
remove
(
Biometrics
)
}
if
(
Build
.
VERSION
.
SDK_INT
<
26
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
O
)
{
// Re-authenticate is not feasible on 8.0+
list
.
add
(
Reauthenticate
)
}
if
(
Build
.
VERSION
.
SDK_INT
>=
31
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
// Can hide overlay windows on 12.0+
list
.
remove
(
Tapjack
)
}
...
...
app/src/main/java/com/topjohnwu/magisk/view/Notifications.kt
View file @
3f7f6e61
...
...
@@ -7,6 +7,7 @@ import android.app.NotificationManager
import
android.app.PendingIntent
import
android.content.Context
import
android.content.Intent
import
android.os.Build
import
android.os.Build.VERSION.SDK_INT
import
androidx.core.content.getSystemService
import
androidx.core.graphics.drawable.toIcon
...
...
@@ -32,7 +33,7 @@ object Notifications {
private
val
nextId
=
AtomicInteger
(
APP_UPDATE_NOTIFICATION_ID
)
fun
setup
(
context
:
Context
)
{
if
(
SDK_INT
>=
26
)
{
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
val
channel
=
NotificationChannel
(
UPDATE_CHANNEL
,
context
.
getString
(
R
.
string
.
update_channel
),
NotificationManager
.
IMPORTANCE_DEFAULT
)
val
channel2
=
NotificationChannel
(
PROGRESS_CHANNEL
,
...
...
@@ -55,7 +56,7 @@ object Notifications {
setup
(
context
)
val
flag
=
PendingIntent
.
FLAG_IMMUTABLE
or
PendingIntent
.
FLAG_UPDATE_CURRENT
val
pending
=
PendingIntent
.
getActivity
(
context
,
0
,
selfLaunchIntent
(
context
),
flag
)
val
builder
=
if
(
SDK_INT
>=
26
)
{
val
builder
=
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
Notification
.
Builder
(
context
,
UPDATED_CHANNEL
)
.
setSmallIcon
(
context
.
getBitmap
(
R
.
drawable
.
ic_magisk_outline
).
toIcon
())
}
else
{
...
...
@@ -73,7 +74,7 @@ object Notifications {
val
intent
=
DownloadService
.
getPendingIntent
(
context
,
Subject
.
App
())
val
bitmap
=
context
.
getBitmap
(
R
.
drawable
.
ic_magisk_outline
)
val
builder
=
if
(
SDK_INT
>=
26
)
{
val
builder
=
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
Notification
.
Builder
(
context
,
UPDATE_CHANNEL
)
.
setSmallIcon
(
bitmap
.
toIcon
())
}
else
{
...
...
@@ -90,7 +91,7 @@ object Notifications {
}
fun
progress
(
context
:
Context
,
title
:
CharSequence
):
Notification
.
Builder
{
val
builder
=
if
(
SDK_INT
>=
26
)
{
val
builder
=
if
(
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
Notification
.
Builder
(
context
,
PROGRESS_CHANNEL
)
}
else
{
Notification
.
Builder
(
context
).
setPriority
(
Notification
.
PRIORITY_LOW
)
...
...
app/src/main/java/com/topjohnwu/magisk/view/Shortcuts.kt
View file @
3f7f6e61
...
...
@@ -19,7 +19,7 @@ import com.topjohnwu.magisk.utils.Utils
object
Shortcuts
{
fun
setupDynamic
(
context
:
Context
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
25
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N_MR1
)
{
val
manager
=
context
.
getSystemService
<
ShortcutManager
>()
?:
return
manager
.
dynamicShortcuts
=
getShortCuts
(
context
)
}
...
...
@@ -36,7 +36,7 @@ object Shortcuts {
}
private
fun
Context
.
getIconCompat
(
id
:
Int
):
IconCompat
{
return
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
return
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
IconCompat
.
createWithAdaptiveBitmap
(
getBitmap
(
id
))
else
IconCompat
.
createWithBitmap
(
getBitmap
(
id
))
...
...
stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java
View file @
3f7f6e61
...
...
@@ -186,7 +186,7 @@ public class DownloadActivity extends Activity {
}
private
void
loadResources
()
throws
Exception
{
if
(
Build
.
VERSION
.
SDK_INT
>=
30
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
R
)
{
var
fd
=
Os
.
memfd_create
(
"res.apk"
,
0
);
try
{
decryptResources
(
new
FileOutputStream
(
fd
));
...
...
stub/src/main/java/com/topjohnwu/magisk/DynLoad.java
View file @
3f7f6e61
...
...
@@ -104,7 +104,7 @@ public class DynLoad {
// Dynamically load APK and create the Application instance from the loaded APK
static
Application
createAndSetupApp
(
Application
context
)
{
// On API >= 29, AppComponentFactory will replace the ClassLoader for us
if
(
Build
.
VERSION
.
SDK_INT
<
29
)
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
Q
)
replaceClassLoader
(
context
);
// noinspection InlinedApi
...
...
@@ -145,7 +145,7 @@ public class DynLoad {
.
newInstance
(
data
.
getObject
());
// Create the receiver component factory
if
(
Build
.
VERSION
.
SDK_INT
>=
28
&&
componentFactory
!=
null
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
P
&&
componentFactory
!=
null
)
{
Object
factory
=
cl
.
loadClass
(
appInfo
.
appComponentFactory
).
newInstance
();
var
delegate
=
(
DelegateComponentFactory
)
componentFactory
;
delegate
.
receiver
=
(
AppComponentFactory
)
factory
;
...
...
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