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
2aee0b0b
Commit
2aee0b0b
authored
Nov 11, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor code for handling MagiskDB
parent
817cdf71
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
89 additions
and
76 deletions
+89
-76
LogDao.kt
...rc/main/java/com/topjohnwu/magisk/data/database/LogDao.kt
+4
-4
PolicyDao.kt
...main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt
+6
-3
SettingsDao.kt
...in/java/com/topjohnwu/magisk/data/database/SettingsDao.kt
+6
-3
StringDao.kt
...main/java/com/topjohnwu/magisk/data/database/StringDao.kt
+6
-3
BaseDao.kt
...n/java/com/topjohnwu/magisk/data/database/base/BaseDao.kt
+0
-15
MagiskQuery.kt
...va/com/topjohnwu/magisk/data/database/base/MagiskQuery.kt
+0
-5
BaseDao.kt
...va/com/topjohnwu/magisk/data/database/magiskdb/BaseDao.kt
+44
-0
Query.kt
...java/com/topjohnwu/magisk/data/database/magiskdb/Query.kt
+14
-32
LogRepository.kt
...ava/com/topjohnwu/magisk/data/repository/LogRepository.kt
+5
-4
MagiskRepository.kt
.../com/topjohnwu/magisk/data/repository/MagiskRepository.kt
+1
-2
HideViewModel.kt
...c/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt
+3
-5
No files found.
app/src/main/java/com/topjohnwu/magisk/data/database/LogDao.kt
View file @
2aee0b0b
package
com.topjohnwu.magisk.data.database
import
com.topjohnwu.magisk.data.database.
base
.*
import
com.topjohnwu.magisk.data.database.
magiskdb
.*
import
com.topjohnwu.magisk.model.entity.MagiskLog
import
com.topjohnwu.magisk.model.entity.toLog
import
com.topjohnwu.magisk.model.entity.toMap
...
...
@@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit
class
LogDao
:
BaseDao
()
{
override
val
table
=
DatabaseDefinition
.
Table
.
LOG
override
val
table
=
Table
.
LOG
fun
deleteOutdated
(
suTimeout
:
Long
=
TimeUnit
.
DAYS
.
toMillis
(
14
)
...
...
@@ -18,7 +18,7 @@ class LogDao : BaseDao() {
}
}.
ignoreElement
()
fun
deleteAll
()
=
query
<
Delete
>
{}
.
ignoreElement
()
fun
deleteAll
()
=
query
<
Delete
>
()
.
ignoreElement
()
fun
fetchAll
()
=
query
<
Select
>
{
orderBy
(
"time"
,
Order
.
DESC
)
...
...
app/src/main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt
View file @
2aee0b0b
...
...
@@ -3,7 +3,10 @@ package com.topjohnwu.magisk.data.database
import
android.content.Context
import
android.content.pm.PackageManager
import
com.topjohnwu.magisk.Const
import
com.topjohnwu.magisk.data.database.base.*
import
com.topjohnwu.magisk.data.database.magiskdb.Delete
import
com.topjohnwu.magisk.data.database.magiskdb.BaseDao
import
com.topjohnwu.magisk.data.database.magiskdb.Replace
import
com.topjohnwu.magisk.data.database.magiskdb.Select
import
com.topjohnwu.magisk.extensions.now
import
com.topjohnwu.magisk.model.entity.MagiskPolicy
import
com.topjohnwu.magisk.model.entity.toMap
...
...
@@ -16,7 +19,7 @@ class PolicyDao(
private
val
context
:
Context
)
:
BaseDao
()
{
override
val
table
:
String
=
DatabaseDefinition
.
Table
.
POLICY
override
val
table
:
String
=
Table
.
POLICY
fun
deleteOutdated
(
nowSeconds
:
Long
=
TimeUnit
.
MILLISECONDS
.
toSeconds
(
now
)
...
...
app/src/main/java/com/topjohnwu/magisk/data/database/SettingsDao.kt
View file @
2aee0b0b
package
com.topjohnwu.magisk.data.database
import
com.topjohnwu.magisk.data.database.base.*
import
com.topjohnwu.magisk.data.database.magiskdb.Delete
import
com.topjohnwu.magisk.data.database.magiskdb.BaseDao
import
com.topjohnwu.magisk.data.database.magiskdb.Replace
import
com.topjohnwu.magisk.data.database.magiskdb.Select
class
SettingsDao
:
BaseDao
()
{
override
val
table
=
DatabaseDefinition
.
Table
.
SETTINGS
override
val
table
=
Table
.
SETTINGS
fun
delete
(
key
:
String
)
=
query
<
Delete
>
{
condition
{
equals
(
"key"
,
key
)
}
...
...
app/src/main/java/com/topjohnwu/magisk/data/database/StringDao.kt
View file @
2aee0b0b
package
com.topjohnwu.magisk.data.database
import
com.topjohnwu.magisk.data.database.base.*
import
com.topjohnwu.magisk.data.database.magiskdb.Delete
import
com.topjohnwu.magisk.data.database.magiskdb.BaseDao
import
com.topjohnwu.magisk.data.database.magiskdb.Replace
import
com.topjohnwu.magisk.data.database.magiskdb.Select
class
StringDao
:
BaseDao
()
{
override
val
table
=
DatabaseDefinition
.
Table
.
STRINGS
override
val
table
=
Table
.
STRINGS
fun
delete
(
key
:
String
)
=
query
<
Delete
>
{
condition
{
equals
(
"key"
,
key
)
}
...
...
app/src/main/java/com/topjohnwu/magisk/data/database/base/BaseDao.kt
deleted
100644 → 0
View file @
817cdf71
package
com.topjohnwu.magisk.data.database.base
abstract
class
BaseDao
{
abstract
val
table
:
String
inline
fun
<
reified
Builder
:
MagiskQueryBuilder
>
query
(
builder
:
Builder
.()
->
Unit
)
=
Builder
::
class
.
java
.
newInstance
()
.
apply
{
table
=
this
@BaseDao
.
table
}
.
apply
(
builder
)
.
toString
()
.
let
{
MagiskQuery
(
it
)
}
.
query
()
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQuery.kt
deleted
100644 → 0
View file @
817cdf71
package
com.topjohnwu.magisk.data.database.base
inline
class
MagiskQuery
(
private
val
_query
:
String
)
{
val
query
get
()
=
"magisk --sqlite '$_query'"
}
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/data/database/
base/DatabaseDefinition
.kt
→
app/src/main/java/com/topjohnwu/magisk/data/database/
magiskdb/BaseDao
.kt
View file @
2aee0b0b
package
com.topjohnwu.magisk.data.database.
base
package
com.topjohnwu.magisk.data.database.
magiskdb
import
androidx.annotation.
AnyThread
import
androidx.annotation.
StringDef
import
com.topjohnwu.superuser.Shell
import
io.reactivex.Single
object
DatabaseDefinition
{
abstract
class
BaseDao
{
object
Table
{
const
val
POLICY
=
"policies"
...
...
@@ -13,15 +13,29 @@ object DatabaseDefinition {
const
val
STRINGS
=
"strings"
}
@StringDef
(
Table
.
POLICY
,
Table
.
LOG
,
Table
.
SETTINGS
,
Table
.
STRINGS
)
@Retention
(
AnnotationRetention
.
SOURCE
)
annotation
class
TableStrict
@TableStrict
abstract
val
table
:
String
inline
fun
<
reified
Builder
:
Query
.
Builder
>
query
(
builder
:
Builder
.()
->
Unit
=
{})
=
Builder
::
class
.
java
.
newInstance
()
.
apply
{
table
=
this
@BaseDao
.
table
}
.
apply
(
builder
)
.
toString
()
.
let
{
Query
(
it
)
}
.
query
()
}
@AnyThread
fun
MagiskQuery
.
query
()
=
query
.
su
()
fun
Query
.
query
()
=
query
.
su
()
fun
String
.
suRaw
()
=
Single
.
fromCallable
{
Shell
.
su
(
this
).
exec
().
out
}
fun
String
.
su
()
=
suRaw
().
map
{
it
.
toMap
()
}
private
fun
String
.
suRaw
()
=
Single
.
fromCallable
{
Shell
.
su
(
this
).
exec
().
out
}
private
fun
String
.
su
()
=
suRaw
().
map
{
it
.
toMap
()
}
fun
List
<
String
>.
toMap
()
=
map
{
it
.
split
(
Regex
(
"\\|"
))
}
private
fun
List
<
String
>.
toMap
()
=
map
{
it
.
split
(
Regex
(
"\\|"
))
}
.
map
{
it
.
toMapInternal
()
}
private
fun
List
<
String
>.
toMapInternal
()
=
map
{
it
.
split
(
"="
,
limit
=
2
)
}
...
...
app/src/main/java/com/topjohnwu/magisk/data/database/
base/MagiskQueryBuilder
.kt
→
app/src/main/java/com/topjohnwu/magisk/data/database/
magiskdb/Query
.kt
View file @
2aee0b0b
package
com.topjohnwu.magisk.data.database.
base
package
com.topjohnwu.magisk.data.database.
magiskdb
import
androidx.annotation.StringDef
import
com.topjohnwu.magisk.data.database.base.Order.Companion.ASC
import
com.topjohnwu.magisk.data.database.base.Order.Companion.DESC
interface
MagiskQueryBuilder
{
class
Query
(
private
val
_query
:
String
)
{
val
query
get
()
=
"magisk --sqlite '$_query'"
interface
Builder
{
val
requestType
:
String
var
table
:
String
companion
object
{
inline
operator
fun
<
reified
Builder
:
MagiskQueryBuilder
>
invoke
(
builder
:
Builder
.()
->
Unit
):
MagiskQuery
=
Builder
::
class
.
java
.
newInstance
()
.
apply
(
builder
)
.
toString
()
.
let
{
MagiskQuery
(
it
)
}
}
}
class
Delete
:
MagiskQuery
Builder
{
class
Delete
:
Query
.
Builder
{
override
val
requestType
:
String
=
"DELETE FROM"
override
var
table
=
""
...
...
@@ -36,7 +26,7 @@ class Delete : MagiskQueryBuilder {
}
}
class
Select
:
MagiskQuery
Builder
{
class
Select
:
Query
.
Builder
{
override
val
requestType
:
String
get
()
=
"SELECT $fields FROM"
override
lateinit
var
table
:
String
...
...
@@ -69,7 +59,7 @@ class Replace : Insert() {
override
val
requestType
:
String
=
"REPLACE INTO"
}
open
class
Insert
:
MagiskQuery
Builder
{
open
class
Insert
:
Query
.
Builder
{
override
val
requestType
:
String
=
"INSERT INTO"
override
lateinit
var
table
:
String
...
...
@@ -137,19 +127,11 @@ class Condition {
}
}
class
Order
{
@set
:
OrderStrict
var
order
=
DESC
var
field
=
""
companion
object
{
object
Order
{
const
val
ASC
=
"ASC"
const
val
DESC
=
"DESC"
}
}
@StringDef
(
ASC
,
DESC
)
@StringDef
(
Order
.
ASC
,
Order
.
DESC
)
@Retention
(
AnnotationRetention
.
SOURCE
)
annotation
class
OrderStrict
app/src/main/java/com/topjohnwu/magisk/data/repository/LogRepository.kt
View file @
2aee0b0b
...
...
@@ -2,11 +2,11 @@ package com.topjohnwu.magisk.data.repository
import
com.topjohnwu.magisk.Const
import
com.topjohnwu.magisk.data.database.LogDao
import
com.topjohnwu.magisk.data.database.base.suRaw
import
com.topjohnwu.magisk.extensions.toSingle
import
com.topjohnwu.magisk.model.entity.MagiskLog
import
com.topjohnwu.magisk.model.entity.WrappedMagiskLog
import
com.topjohnwu.superuser.Shell
import
io.reactivex.Single
import
java.util.concurrent.TimeUnit
...
...
@@ -18,8 +18,9 @@ class LogRepository(
.
map
{
it
.
sortByDescending
{
it
.
date
.
time
};
it
}
.
map
{
it
.
wrap
()
}
fun
fetchMagiskLogs
()
=
"tail -n 5000 ${Const.MAGISK_LOG}"
.
suRaw
()
.
filter
{
it
.
isNotEmpty
()
}
fun
fetchMagiskLogs
()
=
Single
.
fromCallable
{
Shell
.
su
(
"tail -n 5000 ${Const.MAGISK_LOG}"
).
exec
().
out
}.
filter
{
it
.
isNotEmpty
()
}
fun
clearLogs
()
=
logDao
.
deleteAll
()
fun
clearOutdated
()
=
logDao
.
deleteOutdated
()
...
...
app/src/main/java/com/topjohnwu/magisk/data/repository/MagiskRepository.kt
View file @
2aee0b0b
...
...
@@ -3,7 +3,6 @@ package com.topjohnwu.magisk.data.repository
import
android.content.pm.PackageManager
import
com.topjohnwu.magisk.Config
import
com.topjohnwu.magisk.Info
import
com.topjohnwu.magisk.data.database.base.su
import
com.topjohnwu.magisk.data.network.GithubRawServices
import
com.topjohnwu.magisk.extensions.getLabel
import
com.topjohnwu.magisk.extensions.packageName
...
...
@@ -57,7 +56,7 @@ class MagiskRepository(
.
toList
()
fun
toggleHide
(
isEnabled
:
Boolean
,
packageName
:
String
,
process
:
String
)
=
"magiskhide --%s %s %s"
.
format
(
isEnabled
.
state
,
packageName
,
process
).
su
().
ignoreElemen
t
()
Shell
.
su
(
"magiskhide --${isEnabled.state} $packageName $process"
).
submi
t
()
private
val
Boolean
.
state
get
()
=
if
(
this
)
"add"
else
"rm"
...
...
app/src/main/java/com/topjohnwu/magisk/ui/hide/HideViewModel.kt
View file @
2aee0b0b
...
...
@@ -90,9 +90,7 @@ class HideViewModel(
.
toList
()
.
map
{
it
to
items
.
calculateDiff
(
it
)
}
private
fun
toggleItem
(
item
:
HideProcessRvItem
)
=
magiskRepo
.
toggleHide
(
item
.
isHidden
.
value
,
item
.
packageName
,
item
.
process
)
.
subscribeK
()
.
add
()
private
fun
toggleItem
(
item
:
HideProcessRvItem
)
=
magiskRepo
.
toggleHide
(
item
.
isHidden
.
value
,
item
.
packageName
,
item
.
process
)
}
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