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
d5467332
Commit
d5467332
authored
May 12, 2019
by
Viktor De Pasquale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed direct static usages of database from app
parent
c275326d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
27 additions
and
33 deletions
+27
-33
App.kt
app/src/main/java/com/topjohnwu/magisk/App.kt
+0
-5
DatabaseModule.kt
app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt
+1
-2
PolicyRvItem.kt
...om/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt
+4
-5
RxEvents.kt
...c/main/java/com/topjohnwu/magisk/model/events/RxEvents.kt
+2
-2
BasePreferenceFragment.kt
...va/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.kt
+2
-2
SettingsFragment.java
...va/com/topjohnwu/magisk/ui/settings/SettingsFragment.java
+3
-1
SuperuserViewModel.kt
...a/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
+15
-16
No files found.
app/src/main/java/com/topjohnwu/magisk/App.kt
View file @
d5467332
...
...
@@ -11,14 +11,12 @@ import android.os.Bundle
import
androidx.appcompat.app.AppCompatDelegate
import
androidx.multidex.MultiDex
import
com.chibatching.kotpref.Kotpref
import
com.topjohnwu.magisk.data.database.MagiskDB
import
com.topjohnwu.magisk.di.koinModules
import
com.topjohnwu.magisk.utils.LocaleManager
import
com.topjohnwu.magisk.utils.RootUtils
import
com.topjohnwu.magisk.utils.inject
import
com.topjohnwu.net.Networking
import
com.topjohnwu.superuser.Shell
import
org.koin.android.ext.android.inject
import
org.koin.android.ext.koin.androidContext
import
org.koin.core.context.startKoin
import
timber.log.Timber
...
...
@@ -28,9 +26,6 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
lateinit
var
protectedContext
:
Context
@Deprecated
(
"Use dependency injection"
,
level
=
DeprecationLevel
.
ERROR
)
val
DB
:
MagiskDB
by
inject
()
@Volatile
private
var
foreground
:
Activity
?
=
null
...
...
app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt
View file @
d5467332
...
...
@@ -2,13 +2,12 @@ package com.topjohnwu.magisk.di
import
android.content.Context
import
androidx.room.Room
import
com.topjohnwu.magisk.App
import
com.topjohnwu.magisk.data.database.*
import
org.koin.dsl.module
val
databaseModule
=
module
{
single
{
MagiskDB
(
get
<
App
>().
protectedContext
)
}
//
single { MagiskDB(get<App>().protectedContext) }
single
{
createDatabase
(
get
())
}
single
{
LogDao
()
}
single
{
PolicyDao
(
get
())
}
...
...
app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt
View file @
d5467332
...
...
@@ -6,13 +6,14 @@ import com.skoumal.teanity.extensions.addOnPropertyChangedCallback
import
com.skoumal.teanity.rxbus.RxBus
import
com.skoumal.teanity.util.KObservableField
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.model.entity.MagiskPolicy
import
com.topjohnwu.magisk.model.entity.Policy
import
com.topjohnwu.magisk.model.events.PolicyEnableEvent
import
com.topjohnwu.magisk.model.events.PolicyUpdateEvent
import
com.topjohnwu.magisk.utils.inject
import
com.topjohnwu.magisk.utils.toggle
class
PolicyRvItem
(
val
item
:
Policy
,
val
icon
:
Drawable
)
:
ComparableRvItem
<
PolicyRvItem
>()
{
class
PolicyRvItem
(
val
item
:
Magisk
Policy
,
val
icon
:
Drawable
)
:
ComparableRvItem
<
PolicyRvItem
>()
{
override
val
layoutRes
:
Int
=
R
.
layout
.
item_policy
...
...
@@ -32,13 +33,11 @@ class PolicyRvItem(val item: Policy, val icon: Drawable) : ComparableRvItem<Poli
}
shouldNotify
.
addOnPropertyChangedCallback
{
it
?:
return
@addOnPropertyChangedCallback
item
.
notification
=
it
rxBus
.
post
(
PolicyUpdateEvent
.
Notification
(
this
@PolicyRvItem
))
rxBus
.
post
(
PolicyUpdateEvent
.
Notification
(
this
@PolicyRvItem
,
shouldNotify
.
value
))
}
shouldLog
.
addOnPropertyChangedCallback
{
it
?:
return
@addOnPropertyChangedCallback
item
.
logging
=
it
rxBus
.
post
(
PolicyUpdateEvent
.
Log
(
this
@PolicyRvItem
))
rxBus
.
post
(
PolicyUpdateEvent
.
Log
(
this
@PolicyRvItem
,
shouldLog
.
value
))
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/model/events/RxEvents.kt
View file @
d5467332
...
...
@@ -9,8 +9,8 @@ class HideProcessEvent(val item: HideProcessRvItem) : RxBus.Event
class
PolicyEnableEvent
(
val
item
:
PolicyRvItem
,
val
enable
:
Boolean
)
:
RxBus
.
Event
sealed
class
PolicyUpdateEvent
(
val
item
:
PolicyRvItem
)
:
RxBus
.
Event
{
class
Notification
(
item
:
PolicyRvItem
)
:
PolicyUpdateEvent
(
item
)
class
Log
(
item
:
PolicyRvItem
)
:
PolicyUpdateEvent
(
item
)
class
Notification
(
item
:
PolicyRvItem
,
val
shouldNotify
:
Boolean
)
:
PolicyUpdateEvent
(
item
)
class
Log
(
item
:
PolicyRvItem
,
val
shouldLog
:
Boolean
)
:
PolicyUpdateEvent
(
item
)
}
class
ModuleUpdatedEvent
(
val
item
:
ModuleRvItem
)
:
RxBus
.
Event
app/src/main/java/com/topjohnwu/magisk/ui/base/BasePreferenceFragment.kt
View file @
d5467332
...
...
@@ -13,7 +13,7 @@ import androidx.preference.*
import
androidx.recyclerview.widget.RecyclerView
import
com.topjohnwu.magisk.App
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.data.
database.MagiskDB
import
com.topjohnwu.magisk.data.
repository.SettingRepository
import
org.koin.android.ext.android.inject
abstract
class
BasePreferenceFragment
:
PreferenceFragmentCompat
(),
...
...
@@ -21,7 +21,7 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat(),
protected
val
prefs
:
SharedPreferences
by
inject
()
protected
val
app
:
App
by
inject
()
protected
val
database
:
MagiskDB
by
inject
()
protected
val
settingRepo
:
SettingRepository
by
inject
()
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
...
...
app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java
View file @
d5467332
...
...
@@ -212,7 +212,9 @@ public final class SettingsFragment extends BasePreferenceFragment {
case
Config
.
Key
.
ROOT_ACCESS
:
case
Config
.
Key
.
SU_MULTIUSER_MODE
:
case
Config
.
Key
.
SU_MNT_NS
:
getDatabase
().
setSettings
(
key
,
Utils
.
getPrefsInt
(
prefs
,
key
));
getSettingRepo
().
put
(
key
,
Utils
.
getPrefsInt
(
prefs
,
key
))
.
subscribe
(()
->
{
},
Throwable:
:
printStackTrace
);
break
;
case
Config
.
Key
.
DARK_THEME
:
requireActivity
().
recreate
();
...
...
app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
View file @
d5467332
...
...
@@ -10,7 +10,8 @@ import com.skoumal.teanity.util.DiffObservableList
import
com.skoumal.teanity.viewevents.SnackbarEvent
import
com.topjohnwu.magisk.BR
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.data.database.MagiskDB
import
com.topjohnwu.magisk.data.repository.AppRepository
import
com.topjohnwu.magisk.model.entity.MagiskPolicy
import
com.topjohnwu.magisk.model.entity.Policy
import
com.topjohnwu.magisk.model.entity.recycler.PolicyRvItem
import
com.topjohnwu.magisk.model.events.PolicyEnableEvent
...
...
@@ -24,7 +25,7 @@ import io.reactivex.Single
import
me.tatarka.bindingcollectionadapter2.ItemBinding
class
SuperuserViewModel
(
private
val
database
:
MagiskDB
,
private
val
appRepo
:
AppRepository
,
private
val
packageManager
:
PackageManager
,
private
val
resources
:
Resources
,
rxBus
:
RxBus
...
...
@@ -50,9 +51,9 @@ class SuperuserViewModel(
}
fun
updatePolicies
()
{
Single
.
fromCallable
{
database
.
policyList
}
appRepo
.
fetchAll
()
.
flattenAsFlowable
{
it
}
.
map
{
PolicyRvItem
(
it
,
it
.
i
nfo
.
loadIcon
(
packageManager
))
}
.
map
{
PolicyRvItem
(
it
,
it
.
applicationI
nfo
.
loadIcon
(
packageManager
))
}
.
toList
()
.
applySchedulers
()
.
applyViewModel
(
this
)
...
...
@@ -84,12 +85,12 @@ class SuperuserViewModel(
}
private
fun
updatePolicy
(
it
:
PolicyUpdateEvent
)
=
when
(
it
)
{
is
PolicyUpdateEvent
.
Notification
->
updatePolicy
(
it
.
item
)
{
is
PolicyUpdateEvent
.
Notification
->
updatePolicy
(
it
.
item
.
item
.
copy
(
notification
=
it
.
shouldNotify
)
)
{
val
textId
=
if
(
it
.
logging
)
R
.
string
.
su_snack_notif_on
else
R
.
string
.
su_snack_notif_off
val
text
=
resources
.
getString
(
textId
).
format
(
it
.
appName
)
SnackbarEvent
(
text
).
publish
()
}
is
PolicyUpdateEvent
.
Log
->
updatePolicy
(
it
.
item
)
{
is
PolicyUpdateEvent
.
Log
->
updatePolicy
(
it
.
item
.
item
.
copy
(
logging
=
it
.
shouldLog
)
)
{
val
textId
=
if
(
it
.
notification
)
R
.
string
.
su_snack_log_on
else
R
.
string
.
su_snack_log_off
val
text
=
resources
.
getString
(
textId
).
format
(
it
.
appName
)
...
...
@@ -97,16 +98,16 @@ class SuperuserViewModel(
}
}
private
fun
updatePolicy
(
item
:
PolicyRvItem
,
onSuccess
:
(
Policy
)
->
Unit
)
=
updatePolicy
(
item
.
item
)
private
fun
updatePolicy
(
item
:
MagiskPolicy
,
onSuccess
:
(
Magisk
Policy
)
->
Unit
)
=
updatePolicy
(
item
)
.
subscribeK
{
onSuccess
(
it
)
}
.
add
()
private
fun
togglePolicy
(
item
:
PolicyRvItem
,
enable
:
Boolean
)
{
fun
updateState
()
{
item
.
item
.
policy
=
if
(
enable
)
Policy
.
ALLOW
else
Policy
.
DENY
val
app
=
item
.
item
.
copy
(
policy
=
if
(
enable
)
MagiskPolicy
.
ALLOW
else
MagiskPolicy
.
DENY
)
updatePolicy
(
item
.
item
)
updatePolicy
(
app
)
.
map
{
it
.
policy
==
Policy
.
ALLOW
}
.
subscribeK
{
val
textId
=
if
(
it
)
R
.
string
.
su_snack_grant
else
R
.
string
.
su_snack_deny
...
...
@@ -128,12 +129,10 @@ class SuperuserViewModel(
}
}
private
fun
updatePolicy
(
policy
:
Policy
)
=
Single
.
fromCallable
{
database
.
updatePolicy
(
policy
);
policy
}
.
applySchedulers
()
private
fun
updatePolicy
(
policy
:
MagiskPolicy
)
=
appRepo
.
update
(
policy
).
andThen
(
Single
.
just
(
policy
))
private
fun
deletePolicy
(
policy
:
Policy
)
=
Single
.
fromCallable
{
database
.
deletePolicy
(
policy
);
policy
}
.
applySchedulers
()
private
fun
deletePolicy
(
policy
:
MagiskPolicy
)
=
appRepo
.
delete
(
policy
.
uid
).
andThen
(
Single
.
just
(
policy
))
}
\ 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