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
5fa452aa
Commit
5fa452aa
authored
Aug 12, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Multiple minor changes
parent
2225ccb1
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
68 additions
and
100 deletions
+68
-100
App.kt
app/src/main/java/com/topjohnwu/magisk/App.kt
+15
-30
PolicyDao.kt
...main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt
+4
-10
MagiskRepository.kt
.../com/topjohnwu/magisk/data/repository/MagiskRepository.kt
+2
-2
ApplicationModule.kt
...rc/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
+8
-3
XAndroid.kt
...src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt
+16
-4
MagiskPolicy.kt
...in/java/com/topjohnwu/magisk/model/entity/MagiskPolicy.kt
+2
-1
GeneralReceiver.kt
...va/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt
+6
-8
SplashActivity.kt
app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt
+1
-1
BasePreferenceFragment.kt
...va/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.kt
+0
-2
SettingsFragment.kt
...java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt
+10
-8
Utils.kt
app/src/main/java/com/topjohnwu/magisk/utils/Utils.kt
+4
-31
No files found.
app/src/main/java/com/topjohnwu/magisk/App.kt
View file @
5fa452aa
...
@@ -3,7 +3,6 @@ package com.topjohnwu.magisk
...
@@ -3,7 +3,6 @@ package com.topjohnwu.magisk
import
android.app.Application
import
android.app.Application
import
android.content.Context
import
android.content.Context
import
android.content.res.Configuration
import
android.content.res.Configuration
import
android.os.Build
import
androidx.appcompat.app.AppCompatDelegate
import
androidx.appcompat.app.AppCompatDelegate
import
androidx.multidex.MultiDex
import
androidx.multidex.MultiDex
import
androidx.room.Room
import
androidx.room.Room
...
@@ -14,9 +13,9 @@ import com.topjohnwu.magisk.data.database.RepoDatabase_Impl
...
@@ -14,9 +13,9 @@ import com.topjohnwu.magisk.data.database.RepoDatabase_Impl
import
com.topjohnwu.magisk.di.ActivityTracker
import
com.topjohnwu.magisk.di.ActivityTracker
import
com.topjohnwu.magisk.di.koinModules
import
com.topjohnwu.magisk.di.koinModules
import
com.topjohnwu.magisk.extensions.get
import
com.topjohnwu.magisk.extensions.get
import
com.topjohnwu.magisk.net.Networking
import
com.topjohnwu.magisk.utils.LocaleManager
import
com.topjohnwu.magisk.utils.LocaleManager
import
com.topjohnwu.magisk.utils.RootUtils
import
com.topjohnwu.magisk.utils.RootUtils
import
com.topjohnwu.magisk.net.Networking
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
org.koin.android.ext.koin.androidContext
import
org.koin.android.ext.koin.androidContext
import
org.koin.core.context.startKoin
import
org.koin.core.context.startKoin
...
@@ -24,7 +23,20 @@ import timber.log.Timber
...
@@ -24,7 +23,20 @@ import timber.log.Timber
open
class
App
:
Application
()
{
open
class
App
:
Application
()
{
lateinit
var
deContext
:
Context
init
{
AppCompatDelegate
.
setCompatVectorFromResourcesEnabled
(
true
)
Shell
.
Config
.
setFlags
(
Shell
.
FLAG_MOUNT_MASTER
or
Shell
.
FLAG_USE_MAGISK_BUSYBOX
)
Shell
.
Config
.
verboseLogging
(
BuildConfig
.
DEBUG
)
Shell
.
Config
.
addInitializers
(
RootUtils
::
class
.
java
)
Shell
.
Config
.
setTimeout
(
2
)
Room
.
setFactory
{
when
(
it
)
{
WorkDatabase
::
class
.
java
->
WorkDatabase_Impl
()
RepoDatabase
::
class
.
java
->
RepoDatabase_Impl
()
else
->
null
}
}
}
override
fun
attachBaseContext
(
base
:
Context
)
{
override
fun
attachBaseContext
(
base
:
Context
)
{
super
.
attachBaseContext
(
base
)
super
.
attachBaseContext
(
base
)
...
@@ -37,13 +49,6 @@ open class App : Application() {
...
@@ -37,13 +49,6 @@ open class App : Application() {
modules
(
koinModules
)
modules
(
koinModules
)
}
}
deContext
=
base
if
(
Build
.
VERSION
.
SDK_INT
>=
24
)
{
deContext
=
base
.
createDeviceProtectedStorageContext
()
deContext
.
moveSharedPreferencesFrom
(
base
,
defaultPrefsName
)
}
registerActivityLifecycleCallbacks
(
get
<
ActivityTracker
>())
registerActivityLifecycleCallbacks
(
get
<
ActivityTracker
>())
Networking
.
init
(
base
)
Networking
.
init
(
base
)
...
@@ -54,24 +59,4 @@ open class App : Application() {
...
@@ -54,24 +59,4 @@ open class App : Application() {
super
.
onConfigurationChanged
(
newConfig
)
super
.
onConfigurationChanged
(
newConfig
)
LocaleManager
.
setLocale
(
this
)
LocaleManager
.
setLocale
(
this
)
}
}
private
val
Context
.
defaultPrefsName
get
()
=
"${packageName}_preferences"
companion
object
{
init
{
AppCompatDelegate
.
setCompatVectorFromResourcesEnabled
(
true
)
Shell
.
Config
.
setFlags
(
Shell
.
FLAG_MOUNT_MASTER
or
Shell
.
FLAG_USE_MAGISK_BUSYBOX
)
Shell
.
Config
.
verboseLogging
(
BuildConfig
.
DEBUG
)
Shell
.
Config
.
addInitializers
(
RootUtils
::
class
.
java
)
Shell
.
Config
.
setTimeout
(
2
)
Room
.
setFactory
{
when
(
it
)
{
WorkDatabase
::
class
.
java
->
WorkDatabase_Impl
()
RepoDatabase
::
class
.
java
->
RepoDatabase_Impl
()
else
->
null
}
}
}
}
}
}
app/src/main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt
View file @
5fa452aa
...
@@ -62,20 +62,14 @@ class PolicyDao(
...
@@ -62,20 +62,14 @@ class PolicyDao(
private
fun
Map
<
String
,
String
>.
toPolicySafe
():
MagiskPolicy
?
{
private
fun
Map
<
String
,
String
>.
toPolicySafe
():
MagiskPolicy
?
{
val
taskResult
=
runCatching
{
toPolicy
(
context
.
packageManager
)
}
return
runCatching
{
toPolicy
(
context
.
packageManager
)
}.
getOrElse
{
val
result
=
taskResult
.
getOrNull
()
Timber
.
e
(
it
)
val
exception
=
taskResult
.
exceptionOrNull
()
if
(
it
is
PackageManager
.
NameNotFoundException
)
{
Timber
.
e
(
exception
)
when
(
exception
)
{
is
PackageManager
.
NameNotFoundException
->
{
val
uid
=
getOrElse
(
"uid"
)
{
null
}
?:
return
null
val
uid
=
getOrElse
(
"uid"
)
{
null
}
?:
return
null
delete
(
uid
).
subscribe
()
delete
(
uid
).
subscribe
()
}
}
null
}
}
return
result
}
}
}
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt
View file @
5fa452aa
...
@@ -5,11 +5,11 @@ import com.topjohnwu.magisk.Config
...
@@ -5,11 +5,11 @@ import com.topjohnwu.magisk.Config
import
com.topjohnwu.magisk.Info
import
com.topjohnwu.magisk.Info
import
com.topjohnwu.magisk.data.database.base.su
import
com.topjohnwu.magisk.data.database.base.su
import
com.topjohnwu.magisk.data.network.GithubRawServices
import
com.topjohnwu.magisk.data.network.GithubRawServices
import
com.topjohnwu.magisk.extensions.getLabel
import
com.topjohnwu.magisk.extensions.packageName
import
com.topjohnwu.magisk.extensions.packageName
import
com.topjohnwu.magisk.extensions.toSingle
import
com.topjohnwu.magisk.extensions.toSingle
import
com.topjohnwu.magisk.model.entity.HideAppInfo
import
com.topjohnwu.magisk.model.entity.HideAppInfo
import
com.topjohnwu.magisk.model.entity.HideTarget
import
com.topjohnwu.magisk.model.entity.HideTarget
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
io.reactivex.Single
import
io.reactivex.Single
...
@@ -43,7 +43,7 @@ class MagiskRepository(
...
@@ -43,7 +43,7 @@ class MagiskRepository(
.
flattenAsFlowable
{
it
}
.
flattenAsFlowable
{
it
}
.
filter
{
it
.
enabled
&&
!
blacklist
.
contains
(
it
.
packageName
)
}
.
filter
{
it
.
enabled
&&
!
blacklist
.
contains
(
it
.
packageName
)
}
.
map
{
.
map
{
val
label
=
Utils
.
getAppLabel
(
it
,
packageManager
)
val
label
=
it
.
getLabel
(
packageManager
)
val
icon
=
it
.
loadIcon
(
packageManager
)
val
icon
=
it
.
loadIcon
(
packageManager
)
HideAppInfo
(
it
,
label
,
icon
)
HideAppInfo
(
it
,
label
,
icon
)
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
View file @
5fa452aa
...
@@ -4,10 +4,10 @@ import android.annotation.SuppressLint
...
@@ -4,10 +4,10 @@ import android.annotation.SuppressLint
import
android.app.Activity
import
android.app.Activity
import
android.app.Application
import
android.app.Application
import
android.content.Context
import
android.content.Context
import
android.os.Build
import
android.os.Bundle
import
android.os.Bundle
import
androidx.preference.PreferenceManager
import
androidx.preference.PreferenceManager
import
com.skoumal.teanity.rxbus.RxBus
import
com.skoumal.teanity.rxbus.RxBus
import
com.topjohnwu.magisk.App
import
org.koin.core.qualifier.named
import
org.koin.core.qualifier.named
import
org.koin.dsl.module
import
org.koin.dsl.module
...
@@ -17,15 +17,20 @@ val Protected = named("protected")
...
@@ -17,15 +17,20 @@ val Protected = named("protected")
val
applicationModule
=
module
{
val
applicationModule
=
module
{
single
{
RxBus
()
}
single
{
RxBus
()
}
factory
{
get
<
Context
>().
resources
}
factory
{
get
<
Context
>().
resources
}
factory
{
get
<
Context
>()
as
App
}
factory
{
get
<
Context
>().
packageManager
}
factory
{
get
<
Context
>().
packageManager
}
factory
(
Protected
)
{
get
<
App
>().
deContext
}
factory
(
Protected
)
{
createDEContext
(
get
())
}
single
(
SUTimeout
)
{
get
<
Context
>(
Protected
).
getSharedPreferences
(
"su_timeout"
,
0
)
}
single
(
SUTimeout
)
{
get
<
Context
>(
Protected
).
getSharedPreferences
(
"su_timeout"
,
0
)
}
single
{
PreferenceManager
.
getDefaultSharedPreferences
(
get
<
Context
>(
Protected
))
}
single
{
PreferenceManager
.
getDefaultSharedPreferences
(
get
<
Context
>(
Protected
))
}
single
{
ActivityTracker
()
}
single
{
ActivityTracker
()
}
factory
{
get
<
ActivityTracker
>().
foreground
?:
NullActivity
}
factory
{
get
<
ActivityTracker
>().
foreground
?:
NullActivity
}
}
}
private
fun
createDEContext
(
context
:
Context
):
Context
{
return
if
(
Build
.
VERSION
.
SDK_INT
>=
24
)
context
.
createDeviceProtectedStorageContext
()
else
context
}
class
ActivityTracker
:
Application
.
ActivityLifecycleCallbacks
{
class
ActivityTracker
:
Application
.
ActivityLifecycleCallbacks
{
@Volatile
@Volatile
...
...
app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt
View file @
5fa452aa
...
@@ -7,10 +7,12 @@ import android.content.pm.ComponentInfo
...
@@ -7,10 +7,12 @@ import android.content.pm.ComponentInfo
import
android.content.pm.PackageInfo
import
android.content.pm.PackageInfo
import
android.content.pm.PackageManager
import
android.content.pm.PackageManager
import
android.content.pm.PackageManager.*
import
android.content.pm.PackageManager.*
import
android.content.res.Configuration
import
android.database.Cursor
import
android.database.Cursor
import
android.net.Uri
import
android.net.Uri
import
android.provider.OpenableColumns
import
android.provider.OpenableColumns
import
com.topjohnwu.magisk.utils.FileProvider
import
com.topjohnwu.magisk.utils.FileProvider
import
com.topjohnwu.magisk.utils.currentLocale
import
java.io.File
import
java.io.File
import
java.io.FileNotFoundException
import
java.io.FileNotFoundException
...
@@ -81,10 +83,6 @@ fun Context.rawResource(id: Int) = resources.openRawResource(id)
...
@@ -81,10 +83,6 @@ fun Context.rawResource(id: Int) = resources.openRawResource(id)
fun
Context
.
readUri
(
uri
:
Uri
)
=
fun
Context
.
readUri
(
uri
:
Uri
)
=
contentResolver
.
openInputStream
(
uri
)
?:
throw
FileNotFoundException
()
contentResolver
.
openInputStream
(
uri
)
?:
throw
FileNotFoundException
()
fun
ApplicationInfo
.
findAppLabel
(
pm
:
PackageManager
):
String
{
return
pm
.
getApplicationLabel
(
this
).
toString
().
orEmpty
()
}
fun
Intent
.
startActivity
(
context
:
Context
)
=
context
.
startActivity
(
this
)
fun
Intent
.
startActivity
(
context
:
Context
)
=
context
.
startActivity
(
this
)
fun
File
.
provide
(
context
:
Context
=
get
()):
Uri
{
fun
File
.
provide
(
context
:
Context
=
get
()):
Uri
{
...
@@ -107,3 +105,17 @@ fun <Result> Cursor.toList(transformer: (Cursor) -> Result): List<Result> {
...
@@ -107,3 +105,17 @@ fun <Result> Cursor.toList(transformer: (Cursor) -> Result): List<Result> {
while
(
moveToNext
())
out
.
add
(
transformer
(
this
))
while
(
moveToNext
())
out
.
add
(
transformer
(
this
))
return
out
return
out
}
}
fun
ApplicationInfo
.
getLabel
(
pm
:
PackageManager
):
String
{
runCatching
{
if
(
labelRes
>
0
)
{
val
res
=
pm
.
getResourcesForApplication
(
this
)
val
config
=
Configuration
()
config
.
setLocale
(
currentLocale
)
res
.
updateConfiguration
(
config
,
res
.
displayMetrics
)
return
res
.
getString
(
labelRes
)
}
}
return
loadLabel
(
pm
).
toString
()
}
app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskPolicy.kt
View file @
5fa452aa
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.model.entity
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.model.entity
import
android.content.pm.ApplicationInfo
import
android.content.pm.ApplicationInfo
import
android.content.pm.PackageManager
import
android.content.pm.PackageManager
import
com.topjohnwu.magisk.extensions.getLabel
import
com.topjohnwu.magisk.model.entity.MagiskPolicy.Companion.INTERACTIVE
import
com.topjohnwu.magisk.model.entity.MagiskPolicy.Companion.INTERACTIVE
...
@@ -50,7 +51,7 @@ fun Map<String, String>.toPolicy(pm: PackageManager): MagiskPolicy {
...
@@ -50,7 +51,7 @@ fun Map<String, String>.toPolicy(pm: PackageManager): MagiskPolicy {
logging
=
get
(
"logging"
)
?.
toIntOrNull
()
!=
0
,
logging
=
get
(
"logging"
)
?.
toIntOrNull
()
!=
0
,
notification
=
get
(
"notification"
)
?.
toIntOrNull
()
!=
0
,
notification
=
get
(
"notification"
)
?.
toIntOrNull
()
!=
0
,
applicationInfo
=
info
,
applicationInfo
=
info
,
appName
=
info
.
loadLabel
(
pm
).
toString
(
)
appName
=
info
.
getLabel
(
pm
)
)
)
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/model/receiver/GeneralReceiver.kt
View file @
5fa452aa
...
@@ -33,20 +33,18 @@ open class GeneralReceiver : BroadcastReceiver() {
...
@@ -33,20 +33,18 @@ open class GeneralReceiver : BroadcastReceiver() {
}
}
private
fun
getPkg
(
intent
:
Intent
):
String
{
private
fun
getPkg
(
intent
:
Intent
):
String
{
return
intent
.
data
?.
encodedSchemeSpecificPart
?:
""
return
intent
.
data
?.
encodedSchemeSpecificPart
.
orEmpty
()
}
}
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
?)
{
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
?)
{
if
(
intent
==
null
)
intent
?:
return
return
when
(
intent
.
action
?:
return
)
{
var
action
:
String
?
=
intent
.
action
?:
return
when
(
action
)
{
Intent
.
ACTION_REBOOT
,
Intent
.
ACTION_BOOT_COMPLETED
->
{
Intent
.
ACTION_REBOOT
,
Intent
.
ACTION_BOOT_COMPLETED
->
{
action
=
intent
.
getStringExtra
(
"action"
)
val
action
=
intent
.
getStringExtra
(
"action"
)
if
(
action
==
null
)
{
if
(
action
==
null
)
{
// Actual boot completed event
// Actual boot completed event
Shell
.
su
(
"mm_patch_dtbo"
).
submit
{
result
->
Shell
.
su
(
"mm_patch_dtbo"
).
submit
{
if
(
resul
t
.
isSuccess
)
if
(
i
t
.
isSuccess
)
Notifications
.
dtboPatched
(
context
)
Notifications
.
dtboPatched
(
context
)
}
}
return
return
...
...
app/src/main/java/com/topjohnwu/magisk/ui/SplashActivity.kt
View file @
5fa452aa
...
@@ -53,7 +53,7 @@ open class SplashActivity : AppCompatActivity() {
...
@@ -53,7 +53,7 @@ open class SplashActivity : AppCompatActivity() {
Notifications
.
setup
(
this
)
Notifications
.
setup
(
this
)
// Schedule periodic update checks
// Schedule periodic update checks
Utils
.
scheduleUpdateCheck
()
Utils
.
scheduleUpdateCheck
(
this
)
// Setup shortcuts
// Setup shortcuts
Shortcuts
.
setup
(
this
)
Shortcuts
.
setup
(
this
)
...
...
app/src/main/java/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.kt
View file @
5fa452aa
...
@@ -11,7 +11,6 @@ import androidx.core.view.children
...
@@ -11,7 +11,6 @@ import androidx.core.view.children
import
androidx.core.view.isVisible
import
androidx.core.view.isVisible
import
androidx.preference.*
import
androidx.preference.*
import
androidx.recyclerview.widget.RecyclerView
import
androidx.recyclerview.widget.RecyclerView
import
com.topjohnwu.magisk.App
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
org.koin.android.ext.android.inject
import
org.koin.android.ext.android.inject
...
@@ -19,7 +18,6 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat(),
...
@@ -19,7 +18,6 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat(),
SharedPreferences
.
OnSharedPreferenceChangeListener
{
SharedPreferences
.
OnSharedPreferenceChangeListener
{
protected
val
prefs
:
SharedPreferences
by
inject
()
protected
val
prefs
:
SharedPreferences
by
inject
()
protected
val
app
:
App
by
inject
()
protected
val
activity
get
()
=
requireActivity
()
as
MagiskActivity
<*,
*>
protected
val
activity
get
()
=
requireActivity
()
as
MagiskActivity
<*,
*>
override
fun
onCreateView
(
override
fun
onCreateView
(
...
...
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt
View file @
5fa452aa
...
@@ -26,10 +26,10 @@ import com.topjohnwu.magisk.model.download.DownloadService
...
@@ -26,10 +26,10 @@ import com.topjohnwu.magisk.model.download.DownloadService
import
com.topjohnwu.magisk.model.entity.internal.Configuration
import
com.topjohnwu.magisk.model.entity.internal.Configuration
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import
com.topjohnwu.magisk.model.observer.Observer
import
com.topjohnwu.magisk.model.observer.Observer
import
com.topjohnwu.magisk.net.Networking
import
com.topjohnwu.magisk.ui.base.BasePreferenceFragment
import
com.topjohnwu.magisk.ui.base.BasePreferenceFragment
import
com.topjohnwu.magisk.utils.*
import
com.topjohnwu.magisk.utils.*
import
com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog
import
com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog
import
com.topjohnwu.magisk.net.Networking
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
io.reactivex.Completable
import
io.reactivex.Completable
import
org.koin.android.ext.android.inject
import
org.koin.android.ext.android.inject
...
@@ -155,7 +155,7 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -155,7 +155,7 @@ class SettingsFragment : BasePreferenceFragment() {
}
}
if
(
Shell
.
rootAccess
()
&&
Const
.
USER_ID
==
0
)
{
if
(
Shell
.
rootAccess
()
&&
Const
.
USER_ID
==
0
)
{
if
(
a
pp
.
packageName
==
BuildConfig
.
APPLICATION_ID
)
{
if
(
a
ctivity
.
packageName
==
BuildConfig
.
APPLICATION_ID
)
{
generalCatagory
.
removePreference
(
restoreManager
)
generalCatagory
.
removePreference
(
restoreManager
)
}
else
{
}
else
{
if
(!
Networking
.
checkNetworkStatus
(
requireContext
()))
{
if
(!
Networking
.
checkNetworkStatus
(
requireContext
()))
{
...
@@ -179,10 +179,12 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -179,10 +179,12 @@ class SettingsFragment : BasePreferenceFragment() {
}
}
override
fun
onSharedPreferenceChanged
(
prefs
:
SharedPreferences
,
key
:
String
)
{
override
fun
onSharedPreferenceChanged
(
prefs
:
SharedPreferences
,
key
:
String
)
{
fun
getStrInt
()
=
prefs
.
getString
(
key
,
null
)
?.
toInt
()
?:
0
when
(
key
)
{
when
(
key
)
{
Config
.
Key
.
ROOT_ACCESS
->
Config
.
rootMode
=
Utils
.
getPrefsInt
(
prefs
,
key
)
Config
.
Key
.
ROOT_ACCESS
->
Config
.
rootMode
=
getStrInt
(
)
Config
.
Key
.
SU_MULTIUSER_MODE
->
Config
.
suMultiuserMode
=
Utils
.
getPrefsInt
(
prefs
,
key
)
Config
.
Key
.
SU_MULTIUSER_MODE
->
Config
.
suMultiuserMode
=
getStrInt
(
)
Config
.
Key
.
SU_MNT_NS
->
Config
.
suMntNamespaceMode
=
Utils
.
getPrefsInt
(
prefs
,
key
)
Config
.
Key
.
SU_MNT_NS
->
Config
.
suMntNamespaceMode
=
getStrInt
(
)
Config
.
Key
.
DARK_THEME
->
requireActivity
().
recreate
()
Config
.
Key
.
DARK_THEME
->
requireActivity
().
recreate
()
Config
.
Key
.
COREONLY
->
{
Config
.
Key
.
COREONLY
->
{
if
(
prefs
.
getBoolean
(
key
,
false
))
{
if
(
prefs
.
getBoolean
(
key
,
false
))
{
...
@@ -200,10 +202,10 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -200,10 +202,10 @@ class SettingsFragment : BasePreferenceFragment() {
Shell
.
su
(
"magiskhide --disable"
).
submit
()
Shell
.
su
(
"magiskhide --disable"
).
submit
()
}
}
Config
.
Key
.
LOCALE
->
{
Config
.
Key
.
LOCALE
->
{
LocaleManager
.
setLocale
(
a
pp
)
LocaleManager
.
setLocale
(
a
ctivity
.
application
)
requireActivity
()
.
recreate
()
activity
.
recreate
()
}
}
Config
.
Key
.
CHECK_UPDATES
->
Utils
.
scheduleUpdateCheck
()
Config
.
Key
.
CHECK_UPDATES
->
Utils
.
scheduleUpdateCheck
(
activity
)
}
}
setSummary
(
key
)
setSummary
(
key
)
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Utils.kt
View file @
5fa452aa
...
@@ -2,10 +2,6 @@ package com.topjohnwu.magisk.utils
...
@@ -2,10 +2,6 @@ package com.topjohnwu.magisk.utils
import
android.content.Context
import
android.content.Context
import
android.content.Intent
import
android.content.Intent
import
android.content.SharedPreferences
import
android.content.pm.ApplicationInfo
import
android.content.pm.PackageManager
import
android.content.res.Configuration
import
android.content.res.Resources
import
android.content.res.Resources
import
android.net.Uri
import
android.net.Uri
import
android.os.Environment
import
android.os.Environment
...
@@ -18,7 +14,6 @@ import com.topjohnwu.magisk.model.update.UpdateCheckService
...
@@ -18,7 +14,6 @@ import com.topjohnwu.magisk.model.update.UpdateCheckService
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.Shell
import
com.topjohnwu.superuser.internal.UiThreadHandler
import
com.topjohnwu.superuser.internal.UiThreadHandler
import
java.io.File
import
java.io.File
import
java.util.*
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.TimeUnit
object
Utils
{
object
Utils
{
...
@@ -33,40 +28,17 @@ object Utils {
...
@@ -33,40 +28,17 @@ object Utils {
UiThreadHandler
.
run
{
Toast
.
makeText
(
get
(),
resId
,
duration
).
show
()
}
UiThreadHandler
.
run
{
Toast
.
makeText
(
get
(),
resId
,
duration
).
show
()
}
}
}
fun
getPrefsInt
(
prefs
:
SharedPreferences
,
key
:
String
,
def
:
Int
=
0
):
Int
{
return
prefs
.
getString
(
key
,
def
.
toString
())
!!
.
toInt
()
}
fun
dpInPx
(
dp
:
Int
):
Int
{
fun
dpInPx
(
dp
:
Int
):
Int
{
val
scale
=
get
<
Resources
>().
displayMetrics
.
density
val
scale
=
get
<
Resources
>().
displayMetrics
.
density
return
(
dp
*
scale
+
0.5
).
toInt
()
return
(
dp
*
scale
+
0.5
).
toInt
()
}
}
fun
fmt
(
fmt
:
String
,
vararg
args
:
Any
):
String
{
return
String
.
format
(
Locale
.
US
,
fmt
,
*
args
)
}
fun
getAppLabel
(
info
:
ApplicationInfo
,
pm
:
PackageManager
):
String
{
try
{
if
(
info
.
labelRes
>
0
)
{
val
res
=
pm
.
getResourcesForApplication
(
info
)
val
config
=
Configuration
()
config
.
setLocale
(
currentLocale
)
res
.
updateConfiguration
(
config
,
res
.
displayMetrics
)
return
res
.
getString
(
info
.
labelRes
)
}
}
catch
(
ignored
:
Exception
)
{
}
return
info
.
loadLabel
(
pm
).
toString
()
}
fun
showSuperUser
():
Boolean
{
fun
showSuperUser
():
Boolean
{
return
Shell
.
rootAccess
()
&&
(
Const
.
USER_ID
==
0
return
Shell
.
rootAccess
()
&&
(
Const
.
USER_ID
==
0
||
Config
.
suMultiuserMode
!=
Config
.
Value
.
MULTIUSER_MODE_OWNER_MANAGED
)
||
Config
.
suMultiuserMode
!=
Config
.
Value
.
MULTIUSER_MODE_OWNER_MANAGED
)
}
}
fun
scheduleUpdateCheck
()
{
fun
scheduleUpdateCheck
(
context
:
Context
)
{
if
(
Config
.
checkUpdate
)
{
if
(
Config
.
checkUpdate
)
{
val
constraints
=
Constraints
.
Builder
()
val
constraints
=
Constraints
.
Builder
()
.
setRequiredNetworkType
(
NetworkType
.
CONNECTED
)
.
setRequiredNetworkType
(
NetworkType
.
CONNECTED
)
...
@@ -76,11 +48,12 @@ object Utils {
...
@@ -76,11 +48,12 @@ object Utils {
.
Builder
(
ClassMap
[
UpdateCheckService
::
class
.
java
],
12
,
TimeUnit
.
HOURS
)
.
Builder
(
ClassMap
[
UpdateCheckService
::
class
.
java
],
12
,
TimeUnit
.
HOURS
)
.
setConstraints
(
constraints
)
.
setConstraints
(
constraints
)
.
build
()
.
build
()
WorkManager
.
getInstance
().
enqueueUniquePeriodicWork
(
WorkManager
.
getInstance
(
context
).
enqueueUniquePeriodicWork
(
Const
.
ID
.
CHECK_MAGISK_UPDATE_WORKER_ID
,
Const
.
ID
.
CHECK_MAGISK_UPDATE_WORKER_ID
,
ExistingPeriodicWorkPolicy
.
REPLACE
,
request
)
ExistingPeriodicWorkPolicy
.
REPLACE
,
request
)
}
else
{
}
else
{
WorkManager
.
getInstance
().
cancelUniqueWork
(
Const
.
ID
.
CHECK_MAGISK_UPDATE_WORKER_ID
)
WorkManager
.
getInstance
(
context
)
.
cancelUniqueWork
(
Const
.
ID
.
CHECK_MAGISK_UPDATE_WORKER_ID
)
}
}
}
}
...
...
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