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
a97d278b
Commit
a97d278b
authored
Jul 09, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove RxBus
parent
8647ba47
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
97 deletions
+31
-97
ApplicationModule.kt
...rc/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
+0
-2
ViewModelsModule.kt
...src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt
+1
-1
PolicyRvItem.kt
...om/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt
+2
-3
RxEvents.kt
...c/main/java/com/topjohnwu/magisk/model/events/RxEvents.kt
+0
-15
ViewEvents.kt
...main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt
+7
-6
SafetynetViewModel.kt
...a/com/topjohnwu/magisk/ui/safetynet/SafetynetViewModel.kt
+10
-12
SuperuserViewModel.kt
...a/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
+11
-22
RxBus.kt
app/src/main/java/com/topjohnwu/magisk/utils/RxBus.kt
+0
-36
No files found.
app/src/main/java/com/topjohnwu/magisk/di/ApplicationModule.kt
View file @
a97d278b
...
...
@@ -4,7 +4,6 @@ import android.content.Context
import
android.os.Build
import
androidx.preference.PreferenceManager
import
com.topjohnwu.magisk.core.ResMgr
import
com.topjohnwu.magisk.utils.RxBus
import
org.koin.core.qualifier.named
import
org.koin.dsl.module
...
...
@@ -12,7 +11,6 @@ val SUTimeout = named("su_timeout")
val
Protected
=
named
(
"protected"
)
val
applicationModule
=
module
{
single
{
RxBus
()
}
factory
{
ResMgr
.
resource
}
factory
{
get
<
Context
>().
packageManager
}
factory
(
Protected
)
{
createDEContext
(
get
())
}
...
...
app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt
View file @
a97d278b
...
...
@@ -21,7 +21,7 @@ val viewModelModules = module {
viewModel
{
HomeViewModel
(
get
())
}
viewModel
{
LogViewModel
(
get
())
}
viewModel
{
ModuleViewModel
(
get
(),
get
(),
get
())
}
viewModel
{
SafetynetViewModel
(
get
()
)
}
viewModel
{
SafetynetViewModel
()
}
viewModel
{
SettingsViewModel
(
get
())
}
viewModel
{
SuperuserViewModel
(
get
(),
get
(),
get
())
}
viewModel
{
ThemeViewModel
()
}
...
...
app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt
View file @
a97d278b
...
...
@@ -9,7 +9,6 @@ import com.topjohnwu.magisk.core.model.MagiskPolicy
import
com.topjohnwu.magisk.databinding.ComparableRvItem
import
com.topjohnwu.magisk.extensions.toggle
import
com.topjohnwu.magisk.extensions.value
import
com.topjohnwu.magisk.model.events.PolicyUpdateEvent
import
com.topjohnwu.magisk.ui.superuser.SuperuserViewModel
class
PolicyItem
(
val
item
:
MagiskPolicy
,
val
icon
:
Drawable
)
:
ComparableRvItem
<
PolicyItem
>()
{
...
...
@@ -42,12 +41,12 @@ class PolicyItem(val item: MagiskPolicy, val icon: Drawable) : ComparableRvItem<
fun
toggleNotify
(
viewModel
:
SuperuserViewModel
)
{
shouldNotify
.
toggle
()
viewModel
.
updatePolicy
(
PolicyUpdateEvent
.
Notification
(
updatedPolicy
)
)
viewModel
.
updatePolicy
(
updatedPolicy
,
isLogging
=
false
)
}
fun
toggleLog
(
viewModel
:
SuperuserViewModel
)
{
shouldLog
.
toggle
()
viewModel
.
updatePolicy
(
PolicyUpdateEvent
.
Log
(
updatedPolicy
)
)
viewModel
.
updatePolicy
(
updatedPolicy
,
isLogging
=
true
)
}
override
fun
onBindingBound
(
binding
:
ViewDataBinding
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/model/events/RxEvents.kt
deleted
100644 → 0
View file @
8647ba47
package
com.topjohnwu.magisk.model.events
import
com.topjohnwu.magisk.core.model.MagiskPolicy
import
com.topjohnwu.magisk.utils.RxBus
import
org.json.JSONObject
sealed
class
PolicyUpdateEvent
(
val
item
:
MagiskPolicy
)
:
RxBus
.
Event
{
class
Notification
(
item
:
MagiskPolicy
)
:
PolicyUpdateEvent
(
item
)
class
Log
(
item
:
MagiskPolicy
)
:
PolicyUpdateEvent
(
item
)
}
data class
SafetyNetResult
(
val
response
:
JSONObject
?
=
null
,
val
dismiss
:
Boolean
=
false
)
:
RxBus
.
Event
app/src/main/java/com/topjohnwu/magisk/model/events/ViewEvents.kt
View file @
a97d278b
...
...
@@ -13,7 +13,7 @@ import com.topjohnwu.magisk.extensions.DynamicClassLoader
import
com.topjohnwu.magisk.extensions.OnErrorListener
import
com.topjohnwu.magisk.extensions.subscribeK
import
com.topjohnwu.magisk.extensions.writeTo
import
com.topjohnwu.magisk.u
tils.RxBus
import
com.topjohnwu.magisk.u
i.safetynet.SafetyNetResult
import
com.topjohnwu.magisk.view.MagiskDialog
import
com.topjohnwu.magisk.view.MarkDownWindow
import
com.topjohnwu.superuser.Shell
...
...
@@ -38,10 +38,11 @@ abstract class ViewEvent {
var
handled
=
false
}
class
UpdateSafetyNetEvent
:
ViewEvent
(),
ContextExecutor
,
KoinComponent
,
SafetyNetHelper
.
Callback
{
class
CheckSafetyNetEvent
(
private
val
callback
:
(
SafetyNetResult
)
->
Unit
=
{}
)
:
ViewEvent
(),
ContextExecutor
,
KoinComponent
,
SafetyNetHelper
.
Callback
{
private
val
magiskRepo
by
inject
<
MagiskRepository
>()
private
val
rxBus
by
inject
<
RxBus
>()
private
lateinit
var
apk
:
File
private
lateinit
var
dex
:
File
...
...
@@ -93,7 +94,7 @@ class UpdateSafetyNetEvent : ViewEvent(), ContextExecutor, KoinComponent, Safety
.
map
{
it
.
byteStream
().
writeTo
(
apk
)
}
.
subscribeK
{
attest
(
context
)
{
Timber
.
e
(
it
)
rxBus
.
post
(
SafetyNetResult
())
callback
(
SafetyNetResult
())
}
}
if
(!
askUser
)
{
...
...
@@ -111,13 +112,13 @@ class UpdateSafetyNetEvent : ViewEvent(), ContextExecutor, KoinComponent, Safety
}
.
applyButton
(
MagiskDialog
.
ButtonType
.
NEGATIVE
)
{
titleRes
=
android
.
R
.
string
.
cancel
onClick
{
rxBus
.
post
(
SafetyNetResult
(
dismiss
=
true
))
}
onClick
{
callback
(
SafetyNetResult
(
dismiss
=
true
))
}
}
.
reveal
()
}
override
fun
onResponse
(
response
:
JSONObject
?)
{
rxBus
.
post
(
SafetyNetResult
(
response
))
callback
(
SafetyNetResult
(
response
))
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/ui/safetynet/SafetynetViewModel.kt
View file @
a97d278b
...
...
@@ -4,22 +4,22 @@ import androidx.databinding.Bindable
import
androidx.databinding.ObservableField
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.extensions.subscribeK
import
com.topjohnwu.magisk.extensions.value
import
com.topjohnwu.magisk.model.events.SafetyNetResult
import
com.topjohnwu.magisk.model.events.UpdateSafetyNetEvent
import
com.topjohnwu.magisk.model.events.CheckSafetyNetEvent
import
com.topjohnwu.magisk.ui.base.BaseViewModel
import
com.topjohnwu.magisk.ui.safetynet.SafetyNetState.*
import
com.topjohnwu.magisk.utils.RxBus
import
org.json.JSONObject
enum
class
SafetyNetState
{
LOADING
,
PASS
,
FAILED
,
IDLE
}
class
SafetynetViewModel
(
rxBus
:
RxBus
)
:
BaseViewModel
()
{
data class
SafetyNetResult
(
val
response
:
JSONObject
?
=
null
,
val
dismiss
:
Boolean
=
false
)
class
SafetynetViewModel
:
BaseViewModel
()
{
private
var
currentState
=
IDLE
set
(
value
)
{
...
...
@@ -36,10 +36,6 @@ class SafetynetViewModel(
val
isSuccess
@Bindable
get
()
=
currentState
==
PASS
init
{
rxBus
.
register
<
SafetyNetResult
>()
.
subscribeK
{
resolveResponse
(
it
)
}
.
add
()
cachedResult
?.
also
{
resolveResponse
(
SafetyNetResult
(
it
))
}
?:
attest
()
...
...
@@ -54,7 +50,9 @@ class SafetynetViewModel(
private
fun
attest
()
{
currentState
=
LOADING
UpdateSafetyNetEvent
().
publish
()
CheckSafetyNetEvent
{
resolveResponse
(
it
)
}.
publish
()
}
fun
reset
()
=
attest
()
...
...
app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
View file @
a97d278b
...
...
@@ -15,7 +15,6 @@ import com.topjohnwu.magisk.extensions.toggle
import
com.topjohnwu.magisk.model.entity.recycler.PolicyItem
import
com.topjohnwu.magisk.model.entity.recycler.TappableHeadlineItem
import
com.topjohnwu.magisk.model.entity.recycler.TextItem
import
com.topjohnwu.magisk.model.events.PolicyUpdateEvent
import
com.topjohnwu.magisk.model.events.SnackbarEvent
import
com.topjohnwu.magisk.model.events.dialog.BiometricDialog
import
com.topjohnwu.magisk.model.events.dialog.SuperuserRevokeDialog
...
...
@@ -110,24 +109,19 @@ class SuperuserViewModel(
//---
fun
updatePolicy
(
it
:
PolicyUpdateEvent
)
=
viewModelScope
.
launch
{
val
snackStr
=
when
(
it
)
{
is
PolicyUpdateEvent
.
Notification
->
{
updatePolicy
(
it
.
item
)
when
{
it
.
item
.
notification
->
R
.
string
.
su_snack_notif_on
else
->
R
.
string
.
su_snack_notif_off
}
}
is
PolicyUpdateEvent
.
Log
->
{
updatePolicy
(
it
.
item
)
when
{
it
.
item
.
logging
->
R
.
string
.
su_snack_log_on
fun
updatePolicy
(
policy
:
MagiskPolicy
,
isLogging
:
Boolean
)
=
viewModelScope
.
launch
{
db
.
update
(
policy
)
val
str
=
when
{
isLogging
->
when
{
policy
.
logging
->
R
.
string
.
su_snack_log_on
else
->
R
.
string
.
su_snack_log_off
}
else
->
when
{
policy
.
notification
->
R
.
string
.
su_snack_notif_on
else
->
R
.
string
.
su_snack_notif_off
}
}
SnackbarEvent
(
resources
.
getString
(
s
nackStr
,
it
.
item
.
appName
)).
publish
()
SnackbarEvent
(
resources
.
getString
(
s
tr
,
policy
.
appName
)).
publish
()
}
fun
togglePolicy
(
item
:
PolicyItem
,
enable
:
Boolean
)
{
...
...
@@ -136,7 +130,7 @@ class SuperuserViewModel(
val
app
=
item
.
item
.
copy
(
policy
=
policy
)
viewModelScope
.
launch
{
updatePolicy
(
app
)
db
.
update
(
app
)
val
res
=
if
(
app
.
policy
==
MagiskPolicy
.
ALLOW
)
R
.
string
.
su_snack_grant
else
R
.
string
.
su_snack_deny
SnackbarEvent
(
resources
.
getString
(
res
).
format
(
item
.
item
.
appName
))
...
...
@@ -152,9 +146,4 @@ class SuperuserViewModel(
updateState
()
}
}
//---
private
suspend
fun
updatePolicy
(
policy
:
MagiskPolicy
)
=
db
.
update
(
policy
)
}
app/src/main/java/com/topjohnwu/magisk/utils/RxBus.kt
deleted
100644 → 0
View file @
8647ba47
package
com.topjohnwu.magisk.utils
import
io.reactivex.Observable
import
io.reactivex.subjects.PublishSubject
class
RxBus
{
private
val
_bus
=
PublishSubject
.
create
<
Event
>()
val
bus
:
Observable
<
Event
>
get
()
=
_bus
fun
post
(
event
:
Event
)
{
_bus
.
onNext
(
event
)
}
fun
post
(
event
:
Int
)
{
_bus
.
onNext
(
SimpleEvent
(
event
))
}
inline
fun
<
reified
T
:
Event
>
register
(
noinline
predicate
:
(
T
)
->
Boolean
=
{
true
}):
Observable
<
T
>
{
return
bus
.
ofType
(
T
::
class
.
java
)
.
filter
(
predicate
)
}
fun
register
(
eventId
:
Int
):
Observable
<
Int
>
{
return
bus
.
ofType
(
SimpleEvent
::
class
.
java
)
.
map
{
it
.
eventId
}
.
filter
{
it
==
eventId
}
}
interface
Event
private
class
SimpleEvent
(
val
eventId
:
Int
)
:
Event
}
\ No newline at end of file
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