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
da159e46
Commit
da159e46
authored
Nov 16, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better environment status detection
parent
7f6a6016
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
47 deletions
+47
-47
Info.kt
app/src/main/java/com/topjohnwu/magisk/Info.kt
+5
-4
MainActivity.kt
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
+6
-12
HomeViewModel.kt
...c/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt
+2
-2
SettingsFragment.kt
...java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt
+28
-20
Utils.kt
app/src/main/java/com/topjohnwu/magisk/utils/Utils.kt
+1
-2
Shortcuts.kt
app/src/main/java/com/topjohnwu/magisk/view/Shortcuts.kt
+2
-4
fragment_magisk.xml
app/src/main/res/layout/fragment_magisk.xml
+3
-3
No files found.
app/src/main/java/com/topjohnwu/magisk/Info.kt
View file @
da159e46
...
@@ -36,20 +36,21 @@ object Info {
...
@@ -36,20 +36,21 @@ object Info {
val
str
=
ShellUtils
.
fastCmd
(
"magisk -v"
).
split
(
":"
.
toRegex
())[
0
]
val
str
=
ShellUtils
.
fastCmd
(
"magisk -v"
).
split
(
":"
.
toRegex
())[
0
]
val
code
=
ShellUtils
.
fastCmd
(
"magisk -V"
).
toInt
()
val
code
=
ShellUtils
.
fastCmd
(
"magisk -V"
).
toInt
()
val
hide
=
Shell
.
su
(
"magiskhide --status"
).
exec
().
isSuccess
val
hide
=
Shell
.
su
(
"magiskhide --status"
).
exec
().
isSuccess
Env
(
code
,
str
,
hide
)
Env
(
str
,
code
,
hide
)
}.
getOrElse
{
Env
()
}
}.
getOrElse
{
Env
()
}
class
Env
(
class
Env
(
code
:
Int
=
-
1
,
val
magiskVersionString
:
String
=
""
,
val
magiskVersionString
:
String
=
""
,
code
:
Int
=
-
1
,
hide
:
Boolean
=
false
hide
:
Boolean
=
false
)
{
)
{
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
->
code
else
->
if
(
Shell
.
rootAccess
())
code
else
-
1
}
}
val
unsupported
=
code
>
0
&&
code
<
Const
.
Version
.
MIN_VERCODE
val
isUnsupported
=
code
>
0
&&
code
<
Const
.
Version
.
MIN_VERCODE
val
isActive
=
magiskVersionCode
>=
0
init
{
init
{
Config
.
magiskHide
=
hide
Config
.
magiskHide
=
hide
...
...
app/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt
View file @
da159e46
...
@@ -31,7 +31,6 @@ import com.topjohnwu.magisk.ui.module.ReposFragment
...
@@ -31,7 +31,6 @@ import com.topjohnwu.magisk.ui.module.ReposFragment
import
com.topjohnwu.magisk.ui.settings.SettingsFragment
import
com.topjohnwu.magisk.ui.settings.SettingsFragment
import
com.topjohnwu.magisk.ui.superuser.SuperuserFragment
import
com.topjohnwu.magisk.ui.superuser.SuperuserFragment
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.superuser.Shell
import
org.koin.androidx.viewmodel.ext.android.viewModel
import
org.koin.androidx.viewmodel.ext.android.viewModel
import
timber.log.Timber
import
timber.log.Timber
import
kotlin.reflect.KClass
import
kotlin.reflect.KClass
...
@@ -68,7 +67,7 @@ open class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Na
...
@@ -68,7 +67,7 @@ open class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Na
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
if
(
Info
.
env
.
u
nsupported
&&
!
viewModel
.
shownUnsupportedDialog
)
{
if
(
Info
.
env
.
isU
nsupported
&&
!
viewModel
.
shownUnsupportedDialog
)
{
viewModel
.
shownUnsupportedDialog
=
true
viewModel
.
shownUnsupportedDialog
=
true
AlertDialog
.
Builder
(
this
)
AlertDialog
.
Builder
(
this
)
.
setTitle
(
R
.
string
.
unsupport_magisk_title
)
.
setTitle
(
R
.
string
.
unsupport_magisk_title
)
...
@@ -164,16 +163,11 @@ open class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Na
...
@@ -164,16 +163,11 @@ open class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Na
private
fun
checkHideSection
()
{
private
fun
checkHideSection
()
{
val
menu
=
binding
.
navView
.
menu
val
menu
=
binding
.
navView
.
menu
menu
.
findItem
(
R
.
id
.
magiskHideFragment
).
isVisible
=
menu
.
findItem
(
R
.
id
.
magiskHideFragment
).
isVisible
=
Info
.
env
.
isActive
&&
Info
.
env
.
magiskHide
Shell
.
rootAccess
()
&&
Info
.
env
.
magiskHide
menu
.
findItem
(
R
.
id
.
modulesFragment
).
isVisible
=
Info
.
env
.
isActive
menu
.
findItem
(
R
.
id
.
modulesFragment
).
isVisible
=
menu
.
findItem
(
R
.
id
.
reposFragment
).
isVisible
=
Info
.
isConnected
.
value
&&
Info
.
env
.
isActive
Shell
.
rootAccess
()
&&
Info
.
env
.
magiskVersionCode
>=
0
menu
.
findItem
(
R
.
id
.
logFragment
).
isVisible
=
Info
.
env
.
isActive
menu
.
findItem
(
R
.
id
.
reposFragment
).
isVisible
=
menu
.
findItem
(
R
.
id
.
superuserFragment
).
isVisible
=
Utils
.
showSuperUser
()
(
viewModel
.
isConnected
.
value
&&
Shell
.
rootAccess
()
&&
Info
.
env
.
magiskVersionCode
>=
0
)
menu
.
findItem
(
R
.
id
.
logFragment
).
isVisible
=
Shell
.
rootAccess
()
menu
.
findItem
(
R
.
id
.
superuserFragment
).
isVisible
=
Utils
.
showSuperUser
()
}
}
private
fun
FragNavTransactionOptions
.
Builder
.
customAnimations
(
options
:
MagiskAnimBuilder
)
=
private
fun
FragNavTransactionOptions
.
Builder
.
customAnimations
(
options
:
MagiskAnimBuilder
)
=
...
...
app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt
View file @
da159e46
...
@@ -92,7 +92,7 @@ class HomeViewModel(
...
@@ -92,7 +92,7 @@ class HomeViewModel(
}
}
}
}
val
hasRoot
=
KObservableField
(
false
)
val
isActive
=
KObservableField
(
false
)
private
var
shownDialog
=
false
private
var
shownDialog
=
false
...
@@ -175,7 +175,7 @@ class HomeViewModel(
...
@@ -175,7 +175,7 @@ class HomeViewModel(
if
(
invalidate
)
if
(
invalidate
)
Info
.
envRef
.
invalidate
()
Info
.
envRef
.
invalidate
()
hasRoot
.
value
=
Shell
.
rootAccess
()
isActive
.
value
=
Info
.
env
.
isActive
val
fetchUpdate
=
if
(
isConnected
.
value
)
val
fetchUpdate
=
if
(
isConnected
.
value
)
magiskRepo
.
fetchUpdate
().
ignoreElement
()
magiskRepo
.
fetchUpdate
().
ignoreElement
()
...
...
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt
View file @
da159e46
...
@@ -61,7 +61,7 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -61,7 +61,7 @@ class SettingsFragment : BasePreferenceFragment() {
nsConfig
=
findPreference
(
Config
.
Key
.
SU_MNT_NS
)
!!
nsConfig
=
findPreference
(
Config
.
Key
.
SU_MNT_NS
)
!!
val
reauth
=
findPreference
<
SwitchPreferenceCompat
>(
Config
.
Key
.
SU_REAUTH
)
!!
val
reauth
=
findPreference
<
SwitchPreferenceCompat
>(
Config
.
Key
.
SU_REAUTH
)
!!
val
biometric
=
findPreference
<
SwitchPreferenceCompat
>(
Config
.
Key
.
SU_BIOMETRIC
)
!!
val
biometric
=
findPreference
<
SwitchPreferenceCompat
>(
Config
.
Key
.
SU_BIOMETRIC
)
!!
val
generalCat
a
gory
=
findPreference
<
PreferenceCategory
>(
"general"
)
!!
val
generalCat
e
gory
=
findPreference
<
PreferenceCategory
>(
"general"
)
!!
val
magiskCategory
=
findPreference
<
PreferenceCategory
>(
"magisk"
)
!!
val
magiskCategory
=
findPreference
<
PreferenceCategory
>(
"magisk"
)
!!
val
suCategory
=
findPreference
<
PreferenceCategory
>(
"superuser"
)
!!
val
suCategory
=
findPreference
<
PreferenceCategory
>(
"superuser"
)
!!
val
hideManager
=
findPreference
<
Preference
>(
"hide"
)
!!
val
hideManager
=
findPreference
<
Preference
>(
"hide"
)
!!
...
@@ -94,9 +94,9 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -94,9 +94,9 @@ class SettingsFragment : BasePreferenceFragment() {
biometric
.
setSummary
(
R
.
string
.
no_biometric
)
biometric
.
setSummary
(
R
.
string
.
no_biometric
)
}
}
if
(
Const
.
USER_ID
==
0
&&
Info
.
isConnected
.
value
&&
Shell
.
rootAccess
()
)
{
if
(
Const
.
USER_ID
==
0
&&
Info
.
isConnected
.
value
&&
Info
.
env
.
isActive
)
{
if
(
activity
.
packageName
==
BuildConfig
.
APPLICATION_ID
)
{
if
(
activity
.
packageName
==
BuildConfig
.
APPLICATION_ID
)
{
generalCat
a
gory
.
removePreference
(
restoreManager
)
generalCat
e
gory
.
removePreference
(
restoreManager
)
hideManager
.
setOnPreferenceClickListener
{
hideManager
.
setOnPreferenceClickListener
{
showManagerNameDialog
{
showManagerNameDialog
{
PatchAPK
.
hideManager
(
requireContext
(),
it
)
PatchAPK
.
hideManager
(
requireContext
(),
it
)
...
@@ -104,7 +104,7 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -104,7 +104,7 @@ class SettingsFragment : BasePreferenceFragment() {
true
true
}
}
}
else
{
}
else
{
generalCat
a
gory
.
removePreference
(
hideManager
)
generalCat
e
gory
.
removePreference
(
hideManager
)
restoreManager
.
setOnPreferenceClickListener
{
restoreManager
.
setOnPreferenceClickListener
{
DownloadService
(
requireContext
())
{
DownloadService
(
requireContext
())
{
subject
=
DownloadSubject
.
Manager
(
Configuration
.
APK
.
Restore
)
subject
=
DownloadSubject
.
Manager
(
Configuration
.
APK
.
Restore
)
...
@@ -114,25 +114,32 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -114,25 +114,32 @@ class SettingsFragment : BasePreferenceFragment() {
}
}
}
else
{
}
else
{
// Remove if not primary user, no connection, or no root
// Remove if not primary user, no connection, or no root
generalCat
a
gory
.
removePreference
(
restoreManager
)
generalCat
e
gory
.
removePreference
(
restoreManager
)
generalCat
a
gory
.
removePreference
(
hideManager
)
generalCat
e
gory
.
removePreference
(
hideManager
)
}
}
if
(!
Utils
.
showSuperUser
())
{
if
(!
Utils
.
showSuperUser
())
{
preferenceScreen
.
removePreference
(
suCategory
)
preferenceScreen
.
removePreference
(
suCategory
)
}
}
if
(!
Shell
.
rootAccess
()
)
{
if
(!
Info
.
env
.
isActive
)
{
preferenceScreen
.
removePreference
(
magiskCategory
)
preferenceScreen
.
removePreference
(
magiskCategory
)
generalCat
a
gory
.
removePreference
(
hideManager
)
generalCat
e
gory
.
removePreference
(
hideManager
)
}
}
findPreference
<
Preference
>(
"clear"
)
?.
setOnPreferenceClickListener
{
findPreference
<
Preference
>(
"clear"
)
?.
also
{
Completable
.
fromAction
{
repoDB
.
clear
()
}.
subscribeK
{
if
(
Info
.
env
.
isActive
)
{
Utils
.
toast
(
R
.
string
.
repo_cache_cleared
,
Toast
.
LENGTH_SHORT
)
it
.
setOnPreferenceClickListener
{
Completable
.
fromAction
{
repoDB
.
clear
()
}.
subscribeK
{
Utils
.
toast
(
R
.
string
.
repo_cache_cleared
,
Toast
.
LENGTH_SHORT
)
}
true
}
}
else
{
generalCategory
.
removePreference
(
it
)
}
}
true
}
}
findPreference
<
Preference
>(
"hosts"
)
?.
setOnPreferenceClickListener
{
findPreference
<
Preference
>(
"hosts"
)
?.
setOnPreferenceClickListener
{
Shell
.
su
(
"add_hosts_module"
).
submit
{
Shell
.
su
(
"add_hosts_module"
).
submit
{
Utils
.
toast
(
R
.
string
.
settings_hosts_toast
,
Toast
.
LENGTH_SHORT
)
Utils
.
toast
(
R
.
string
.
settings_hosts_toast
,
Toast
.
LENGTH_SHORT
)
...
@@ -142,20 +149,21 @@ class SettingsFragment : BasePreferenceFragment() {
...
@@ -142,20 +149,21 @@ class SettingsFragment : BasePreferenceFragment() {
findPreference
<
Preference
>(
Config
.
Key
.
DOWNLOAD_PATH
)
?.
apply
{
findPreference
<
Preference
>(
Config
.
Key
.
DOWNLOAD_PATH
)
?.
apply
{
summary
=
Config
.
downloadPath
summary
=
Config
.
downloadPath
}
?.
setOnPreferenceClickListener
{
preference
->
setOnPreferenceClickListener
{
pref
->
activity
.
withExternalRW
{
activity
.
withExternalRW
{
onSuccess
{
onSuccess
{
showDownloadDialog
{
showDownloadDialog
{
Config
.
downloadPath
=
it
Config
.
downloadPath
=
it
preference
.
summary
=
it
pref
.
summary
=
it
}
}
}
}
}
true
}
}
true
}
}
updateChannel
.
setOnPreferenceChangeListener
{
_
,
value
->
updateChannel
.
setOnPreferenceChangeListener
{
_
,
value
->
val
channel
=
Integer
.
parseInt
(
value
as
String
)
val
channel
=
value
.
toString
().
toInt
(
)
val
previous
=
Config
.
updateChannel
val
previous
=
Config
.
updateChannel
if
(
channel
==
Config
.
Value
.
CUSTOM_CHANNEL
)
{
if
(
channel
==
Config
.
Value
.
CUSTOM_CHANNEL
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Utils.kt
View file @
da159e46
...
@@ -11,7 +11,6 @@ import com.topjohnwu.magisk.*
...
@@ -11,7 +11,6 @@ import com.topjohnwu.magisk.*
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.extensions.get
import
com.topjohnwu.magisk.extensions.get
import
com.topjohnwu.magisk.model.update.UpdateCheckService
import
com.topjohnwu.magisk.model.update.UpdateCheckService
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.concurrent.TimeUnit
import
java.util.concurrent.TimeUnit
...
@@ -34,7 +33,7 @@ object Utils {
...
@@ -34,7 +33,7 @@ object Utils {
}
}
fun
showSuperUser
():
Boolean
{
fun
showSuperUser
():
Boolean
{
return
Shell
.
rootAccess
()
&&
(
Const
.
USER_ID
==
0
return
Info
.
env
.
isActive
&&
(
Const
.
USER_ID
==
0
||
Config
.
suMultiuserMode
!=
Config
.
Value
.
MULTIUSER_MODE_OWNER_MANAGED
)
||
Config
.
suMultiuserMode
!=
Config
.
Value
.
MULTIUSER_MODE_OWNER_MANAGED
)
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/view/Shortcuts.kt
View file @
da159e46
...
@@ -14,7 +14,6 @@ import com.topjohnwu.magisk.*
...
@@ -14,7 +14,6 @@ import com.topjohnwu.magisk.*
import
com.topjohnwu.magisk.extensions.getBitmap
import
com.topjohnwu.magisk.extensions.getBitmap
import
com.topjohnwu.magisk.ui.SplashActivity
import
com.topjohnwu.magisk.ui.SplashActivity
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.magisk.utils.Utils
import
com.topjohnwu.superuser.Shell
object
Shortcuts
{
object
Shortcuts
{
...
@@ -28,7 +27,6 @@ object Shortcuts {
...
@@ -28,7 +27,6 @@ object Shortcuts {
@RequiresApi
(
api
=
25
)
@RequiresApi
(
api
=
25
)
private
fun
getShortCuts
(
context
:
Context
):
List
<
ShortcutInfo
>
{
private
fun
getShortCuts
(
context
:
Context
):
List
<
ShortcutInfo
>
{
val
shortCuts
=
mutableListOf
<
ShortcutInfo
>()
val
shortCuts
=
mutableListOf
<
ShortcutInfo
>()
val
root
=
Shell
.
rootAccess
()
val
intent
=
context
.
intent
<
SplashActivity
>()
val
intent
=
context
.
intent
<
SplashActivity
>()
fun
getIcon
(
id
:
Int
):
Icon
{
fun
getIcon
(
id
:
Int
):
Icon
{
...
@@ -53,7 +51,7 @@ object Shortcuts {
...
@@ -53,7 +51,7 @@ object Shortcuts {
.
build
()
.
build
()
)
)
}
}
if
(
root
&&
Info
.
env
.
magiskHide
)
{
if
(
Info
.
env
.
magiskHide
)
{
shortCuts
.
add
(
shortCuts
.
add
(
ShortcutInfo
.
Builder
(
context
,
"magiskhide"
)
ShortcutInfo
.
Builder
(
context
,
"magiskhide"
)
.
setShortLabel
(
context
.
getString
(
R
.
string
.
magiskhide
))
.
setShortLabel
(
context
.
getString
(
R
.
string
.
magiskhide
))
...
@@ -68,7 +66,7 @@ object Shortcuts {
...
@@ -68,7 +66,7 @@ object Shortcuts {
.
build
()
.
build
()
)
)
}
}
if
(!
Config
.
coreOnly
&&
root
&&
Info
.
env
.
magiskVersionCode
>=
0
)
{
if
(!
Config
.
coreOnly
&&
Info
.
env
.
isActive
)
{
shortCuts
.
add
(
shortCuts
.
add
(
ShortcutInfo
.
Builder
(
context
,
"modules"
)
ShortcutInfo
.
Builder
(
context
,
"modules"
)
.
setShortLabel
(
context
.
getString
(
R
.
string
.
modules
))
.
setShortLabel
(
context
.
getString
(
R
.
string
.
modules
))
...
...
app/src/main/res/layout/fragment_magisk.xml
View file @
da159e46
...
@@ -201,7 +201,7 @@
...
@@ -201,7 +201,7 @@
<View
<View
style=
"@style/Widget.Divider.Horizontal"
style=
"@style/Widget.Divider.Horizontal"
gone=
"@{!viewModel.
hasRoot
|| !viewModel.isConnected}"
gone=
"@{!viewModel.
isActive
|| !viewModel.isConnected}"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_margin=
"@dimen/margin_generic"
/>
android:layout_margin=
"@dimen/margin_generic"
/>
...
@@ -482,13 +482,13 @@
...
@@ -482,13 +482,13 @@
<View
<View
style=
"@style/Widget.Divider.Horizontal"
style=
"@style/Widget.Divider.Horizontal"
gone=
"@{!viewModel.
hasRoot
}"
gone=
"@{!viewModel.
isActive
}"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_margin=
"@dimen/margin_generic"
/>
android:layout_margin=
"@dimen/margin_generic"
/>
<com.google.android.material.button.MaterialButton
<com.google.android.material.button.MaterialButton
style=
"@style/Widget.Button.Text"
style=
"@style/Widget.Button.Text"
gone=
"@{!viewModel.
hasRoot
}"
gone=
"@{!viewModel.
isActive
}"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:onClick=
"@{() -> viewModel.uninstallPressed()}"
android:onClick=
"@{() -> viewModel.uninstallPressed()}"
...
...
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