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
67c3f40a
Commit
67c3f40a
authored
May 10, 2019
by
Viktor De Pasquale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed language won't change in certain views unless app restarts
parent
ff7a0ba5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
44 deletions
+50
-44
ApplicationModule.kt
...rc/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
+4
-5
ViewModelsModule.kt
...src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt
+1
-1
MagiskActivity.kt
.../main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt
+1
-1
HomeViewModel.kt
...c/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt
+29
-35
XAndroid.kt
app/src/main/java/com/topjohnwu/magisk/utils/XAndroid.kt
+6
-0
XString.kt
app/src/main/java/com/topjohnwu/magisk/utils/XString.kt
+7
-0
include_update_card.xml
app/src/main/res/layout/include_update_card.xml
+2
-2
No files found.
app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
View file @
67c3f40a
...
...
@@ -9,12 +9,11 @@ import org.koin.dsl.module
val
applicationModule
=
module
{
single
{
RxBus
()
}
single
{
get
<
Context
>().
resources
}
single
{
get
<
Context
>()
as
App
}
single
{
get
<
Context
>().
packageManager
}
factory
{
get
<
Context
>().
resources
}
factory
{
get
<
Context
>()
as
App
}
factory
{
get
<
Context
>().
packageManager
}
single
(
SUTimeout
)
{
get
<
App
>().
protectedContext
.
getSharedPreferences
(
"su_timeout"
,
0
)
get
<
App
>().
protectedContext
.
getSharedPreferences
(
"su_timeout"
,
0
)
}
single
{
PreferenceManager
.
getDefaultSharedPreferences
(
get
<
App
>().
protectedContext
)
}
}
app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt
View file @
67c3f40a
...
...
@@ -15,7 +15,7 @@ import org.koin.dsl.module
val
viewModelModules
=
module
{
viewModel
{
MainViewModel
()
}
viewModel
{
HomeViewModel
(
get
()
,
get
()
)
}
viewModel
{
HomeViewModel
(
get
())
}
viewModel
{
SuperuserViewModel
(
get
(),
get
(),
get
(),
get
())
}
viewModel
{
HideViewModel
(
get
(),
get
())
}
viewModel
{
ModuleViewModel
(
get
(),
get
())
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskActivity.kt
View file @
67c3f40a
...
...
@@ -62,7 +62,7 @@ abstract class MagiskActivity<ViewModel : MagiskViewModel, Binding : ViewDataBin
override
fun
applyOverrideConfiguration
(
config
:
Configuration
?)
{
// Force applying our preferred local
config
!!
.
setLocale
(
LocaleManager
.
locale
)
config
?
.
setLocale
(
LocaleManager
.
locale
)
super
.
applyOverrideConfiguration
(
config
)
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt
View file @
67c3f40a
package
com.topjohnwu.magisk.ui.home
import
android.content.
res.Resources
import
android.content.
Context
import
com.skoumal.teanity.extensions.addOnPropertyChangedCallback
import
com.skoumal.teanity.util.KObservableField
import
com.topjohnwu.magisk.*
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.Config
import
com.topjohnwu.magisk.Const
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.model.events.*
import
com.topjohnwu.magisk.model.observer.Observer
import
com.topjohnwu.magisk.tasks.CheckUpdates
import
com.topjohnwu.magisk.ui.base.MagiskViewModel
import
com.topjohnwu.magisk.utils.Event
import
com.topjohnwu.magisk.utils.ISafetyNetHelper
import
com.topjohnwu.magisk.utils.toggle
import
com.topjohnwu.magisk.utils.*
import
com.topjohnwu.net.Networking
import
com.topjohnwu.superuser.Shell
class
HomeViewModel
(
private
val
resources
:
Resources
,
private
val
app
:
App
private
val
context
:
Context
)
:
MagiskViewModel
()
{
val
isAdvancedExpanded
=
KObservableField
(
false
)
...
...
@@ -29,17 +29,17 @@ class HomeViewModel(
val
magiskStateText
=
Observer
(
magiskState
)
{
when
(
magiskState
.
value
)
{
MagiskState
.
NO_ROOT
->
TODO
()
MagiskState
.
NOT_INSTALLED
->
resources
.
getString
(
R
.
string
.
magisk_version_error
)
MagiskState
.
UP_TO_DATE
->
resources
.
getString
(
R
.
string
.
magisk_up_to_date
)
MagiskState
.
LOADING
->
resources
.
getString
(
R
.
string
.
checking_for_updates
)
MagiskState
.
OBSOLETE
->
resources
.
getString
(
R
.
string
.
magisk_update_title
)
MagiskState
.
NOT_INSTALLED
->
R
.
string
.
magisk_version_error
.
res
(
)
MagiskState
.
UP_TO_DATE
->
R
.
string
.
magisk_up_to_date
.
res
(
)
MagiskState
.
LOADING
->
R
.
string
.
checking_for_updates
.
res
(
)
MagiskState
.
OBSOLETE
->
R
.
string
.
magisk_update_title
.
res
(
)
}
}
val
magiskCurrentVersion
=
KObservableField
(
""
)
val
magiskLatestVersion
=
KObservableField
(
""
)
val
magiskAdditionalInfo
=
Observer
(
magiskState
)
{
if
(
Config
.
get
<
Boolean
>(
Config
.
Key
.
COREONLY
))
resources
.
getString
(
R
.
string
.
core_only_enabled
)
R
.
string
.
core_only_enabled
.
res
(
)
else
""
}
...
...
@@ -48,22 +48,22 @@ class HomeViewModel(
val
managerStateText
=
Observer
(
managerState
)
{
when
(
managerState
.
value
)
{
MagiskState
.
NO_ROOT
->
"wtf"
MagiskState
.
NOT_INSTALLED
->
resources
.
getString
(
R
.
string
.
invalid_update_channel
)
MagiskState
.
UP_TO_DATE
->
resources
.
getString
(
R
.
string
.
manager_up_to_date
)
MagiskState
.
LOADING
->
resources
.
getString
(
R
.
string
.
checking_for_updates
)
MagiskState
.
OBSOLETE
->
resources
.
getString
(
R
.
string
.
manager_update_title
)
MagiskState
.
NOT_INSTALLED
->
R
.
string
.
invalid_update_channel
.
res
(
)
MagiskState
.
UP_TO_DATE
->
R
.
string
.
manager_up_to_date
.
res
(
)
MagiskState
.
LOADING
->
R
.
string
.
checking_for_updates
.
res
(
)
MagiskState
.
OBSOLETE
->
R
.
string
.
manager_update_title
.
res
(
)
}
}
val
managerCurrentVersion
=
KObservableField
(
""
)
val
managerLatestVersion
=
KObservableField
(
""
)
val
managerAdditionalInfo
=
Observer
(
managerState
)
{
if
(
app
.
packageName
!=
BuildConfig
.
APPLICATION_ID
)
"($
{app.packageName}
)"
if
(
packageName
!=
BuildConfig
.
APPLICATION_ID
)
"($
packageName
)"
else
""
}
val
safetyNetTitle
=
KObservableField
(
resources
.
getString
(
R
.
string
.
safetyNet_check_text
))
val
safetyNetTitle
=
KObservableField
(
R
.
string
.
safetyNet_check_text
.
res
(
))
val
ctsState
=
KObservableField
(
SafetyNetState
.
IDLE
)
val
basicIntegrityState
=
KObservableField
(
SafetyNetState
.
IDLE
)
val
safetyNetState
=
Observer
(
ctsState
,
basicIntegrityState
)
{
...
...
@@ -81,8 +81,6 @@ class HomeViewModel(
val
hasRoot
=
KObservableField
(
false
)
private
var
shownDialog
=
false
private
val
current
=
resources
.
getString
(
R
.
string
.
current_installed
)
private
val
latest
=
resources
.
getString
(
R
.
string
.
latest_version
)
init
{
Event
.
register
(
this
)
...
...
@@ -126,7 +124,7 @@ class HomeViewModel(
fun
safetyNetPressed
()
{
ctsState
.
value
=
SafetyNetState
.
LOADING
basicIntegrityState
.
value
=
SafetyNetState
.
LOADING
safetyNetTitle
.
value
=
resources
.
getString
(
R
.
string
.
checking_safetyNet_status
)
safetyNetTitle
.
value
=
R
.
string
.
checking_safetyNet_status
.
res
(
)
UpdateSafetyNetEvent
().
publish
()
}
...
...
@@ -135,7 +133,7 @@ class HomeViewModel(
response
and
0
x0F
==
0
->
{
val
hasCtsPassed
=
response
and
ISafetyNetHelper
.
CTS_PASS
!=
0
val
hasBasicIntegrityPassed
=
response
and
ISafetyNetHelper
.
BASIC_PASS
!=
0
safetyNetTitle
.
value
=
resources
.
getString
(
R
.
string
.
safetyNet_check_success
)
safetyNetTitle
.
value
=
R
.
string
.
safetyNet_check_success
.
res
(
)
ctsState
.
value
=
if
(
hasCtsPassed
)
{
SafetyNetState
.
PASS
}
else
{
...
...
@@ -154,11 +152,10 @@ class HomeViewModel(
else
->
{
ctsState
.
value
=
SafetyNetState
.
IDLE
basicIntegrityState
.
value
=
SafetyNetState
.
IDLE
val
errorString
=
when
(
response
)
{
safetyNetTitle
.
value
=
when
(
response
)
{
ISafetyNetHelper
.
RESPONSE_ERR
->
R
.
string
.
safetyNet_res_invalid
else
->
R
.
string
.
safetyNet_api_error
}
safetyNetTitle
.
value
=
resources
.
getString
(
errorString
)
}.
res
()
}
}
...
...
@@ -172,7 +169,7 @@ class HomeViewModel(
hasRoot
.
value
=
Shell
.
rootAccess
()
if
(
Networking
.
checkNetworkStatus
(
app
))
{
if
(
Networking
.
checkNetworkStatus
(
context
))
{
CheckUpdates
.
check
()
}
else
{
state
=
State
.
LOADING_FAILED
...
...
@@ -187,16 +184,14 @@ class HomeViewModel(
else
->
MagiskState
.
UP_TO_DATE
}
if
(
magiskState
.
value
!=
MagiskState
.
NOT_INSTALLED
)
{
magiskCurrentVersion
.
value
=
version
.
format
(
Config
.
magiskVersionString
,
Config
.
magiskVersionCode
)
.
let
{
current
.
format
(
it
)
}
magiskCurrentVersion
.
value
=
if
(
magiskState
.
value
!=
MagiskState
.
NOT_INSTALLED
)
{
version
.
format
(
Config
.
magiskVersionString
,
Config
.
magiskVersionCode
)
}
else
{
magiskCurrentVersion
.
value
=
""
""
}
magiskLatestVersion
.
value
=
version
.
format
(
Config
.
remoteMagiskVersionString
,
Config
.
remoteMagiskVersionCode
)
.
let
{
latest
.
format
(
it
)
}
managerState
.
value
=
when
(
Config
.
remoteManagerVersionCode
)
{
in
Int
.
MIN_VALUE
until
0
->
MagiskState
.
NOT_INSTALLED
//wrong update channel
...
...
@@ -206,10 +201,9 @@ class HomeViewModel(
managerCurrentVersion
.
value
=
version
.
format
(
BuildConfig
.
VERSION_NAME
,
BuildConfig
.
VERSION_CODE
)
.
let
{
current
.
format
(
it
)
}
managerLatestVersion
.
value
=
version
.
format
(
Config
.
remoteManagerVersionString
,
Config
.
remoteManagerVersionCode
)
.
let
{
latest
.
format
(
it
)
}
}
private
fun
ensureEnv
()
{
...
...
app/src/main/java/com/topjohnwu/magisk/utils/XAndroid.kt
View file @
67c3f40a
...
...
@@ -11,6 +11,12 @@ import android.provider.OpenableColumns
import
com.topjohnwu.magisk.App
import
java.io.FileNotFoundException
val
packageName
:
String
get
()
{
val
app
:
App
by
inject
()
return
app
.
packageName
}
val
PackageInfo
.
processes
get
()
=
activities
?.
processNames
.
orEmpty
()
+
services
?.
processNames
.
orEmpty
()
+
...
...
app/src/main/java/com/topjohnwu/magisk/utils/XString.kt
View file @
67c3f40a
package
com.topjohnwu.magisk.utils
import
android.content.res.Resources
val
specialChars
=
arrayOf
(
'!'
,
'@'
,
'#'
,
'$'
,
'%'
,
'&'
,
'?'
)
fun
String
.
replaceRandomWithSpecial
():
String
{
...
...
@@ -8,4 +10,9 @@ fun String.replaceRandomWithSpecial(): String {
random
=
random
()
}
while
(
random
==
'.'
)
return
replace
(
random
,
specialChars
.
random
())
}
fun
Int
.
res
(
vararg
args
:
Any
):
String
{
val
resources
:
Resources
by
inject
()
return
resources
.
getString
(
this
,
*
args
)
}
\ No newline at end of file
app/src/main/res/layout/include_update_card.xml
View file @
67c3f40a
...
...
@@ -110,7 +110,7 @@
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:maxLines=
"1"
android:text=
"@{state != MagiskState.LOADING ?
currentVersion
: @string/checking_for_updates}"
android:text=
"@{state != MagiskState.LOADING ?
@string/current_installed(currentVersion)
: @string/checking_for_updates}"
app:autoSizeMinTextSize=
"1sp"
app:autoSizeTextType=
"uniform"
app:layout_constraintBottom_toTopOf=
"@+id/latest_version"
...
...
@@ -125,7 +125,7 @@
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:maxLines=
"1"
android:text=
"@{state != MagiskState.LOADING ?
latestVersion
: @string/checking_for_updates}"
android:text=
"@{state != MagiskState.LOADING ?
@string/latest_version(latestVersion)
: @string/checking_for_updates}"
app:autoSizeMinTextSize=
"1sp"
app:autoSizeTextType=
"uniform"
app:layout_constraintBottom_toTopOf=
"@+id/additional"
...
...
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