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
1418ec24
Commit
1418ec24
authored
Feb 12, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove module helper
parent
b51978f5
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
155 additions
and
171 deletions
+155
-171
MagiskManager.java
app/src/main/java/com/topjohnwu/magisk/MagiskManager.java
+2
-1
SettingsActivity.java
app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java
+1
-2
LoadModules.java
...rc/main/java/com/topjohnwu/magisk/asyncs/LoadModules.java
+20
-2
LoadRepos.java
app/src/main/java/com/topjohnwu/magisk/asyncs/LoadRepos.java
+113
-2
BaseModule.java
...src/main/java/com/topjohnwu/magisk/module/BaseModule.java
+1
-1
ModuleHelper.java
...c/main/java/com/topjohnwu/magisk/module/ModuleHelper.java
+0
-158
Repo.java
app/src/main/java/com/topjohnwu/magisk/module/Repo.java
+1
-2
SuRequestActivity.java
...ava/com/topjohnwu/magisk/superuser/SuRequestActivity.java
+3
-3
Utils.java
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
+14
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/MagiskManager.java
View file @
1418ec24
...
...
@@ -24,6 +24,7 @@ public class MagiskManager extends Application {
public
static
final
String
MAGISK_DISABLE_FILE
=
"/cache/.disable_magisk"
;
public
static
final
String
MAGISK_HIDE_PATH
=
"/magisk/.core/magiskhide/"
;
public
static
final
String
TMP_FOLDER_PATH
=
"/dev/tmp"
;
public
static
final
String
MAGISK_PATH
=
"/magisk"
;
// Events
public
final
CallbackEvent
<
Void
>
blockDetectionDone
=
new
CallbackEvent
<>();
...
...
@@ -33,7 +34,7 @@ public class MagiskManager extends Application {
public
final
CallbackEvent
<
Void
>
repoLoadDone
=
new
CallbackEvent
<>();
public
final
CallbackEvent
<
Void
>
updateCheckDone
=
new
CallbackEvent
<>();
public
final
CallbackEvent
<
Void
>
safetyNetDone
=
new
CallbackEvent
<>();
public
SparseArray
<
CallbackEvent
<
Policy
>>
uidMap
=
new
SparseArray
<>();
public
final
SparseArray
<
CallbackEvent
<
Policy
>>
uidSuRequest
=
new
SparseArray
<>();
// Info
public
double
magiskVersion
;
...
...
app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java
View file @
1418ec24
...
...
@@ -16,7 +16,6 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.asyncs.MagiskHide
;
import
com.topjohnwu.magisk.asyncs.SerialTask
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.module.ModuleHelper
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
...
...
@@ -104,7 +103,7 @@ public class SettingsActivity extends Activity {
setSummary
();
findPreference
(
"clear"
).
setOnPreferenceClickListener
((
pref
)
->
{
ModuleHelper
.
clearRepoCache
(
getActivity
());
Utils
.
clearRepoCache
(
getActivity
());
return
true
;
});
...
...
app/src/main/java/com/topjohnwu/magisk/asyncs/LoadModules.java
View file @
1418ec24
...
...
@@ -2,7 +2,12 @@ package com.topjohnwu.magisk.asyncs;
import
android.app.Activity
;
import
com.topjohnwu.magisk.module.ModuleHelper
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.module.BaseModule
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.ValueSortedMap
;
public
class
LoadModules
extends
SerialTask
<
Void
,
Void
,
Void
>
{
...
...
@@ -12,7 +17,20 @@ public class LoadModules extends SerialTask<Void, Void, Void> {
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
ModuleHelper
.
createModuleMap
(
magiskManager
);
Logger
.
dev
(
"LoadModules: Loading modules"
);
magiskManager
.
moduleMap
=
new
ValueSortedMap
<>();
for
(
String
path
:
Utils
.
getModList
(
MagiskManager
.
MAGISK_PATH
))
{
Logger
.
dev
(
"LoadModules: Adding modules from "
+
path
);
Module
module
;
try
{
module
=
new
Module
(
path
);
magiskManager
.
moduleMap
.
put
(
module
.
getId
(),
module
);
}
catch
(
BaseModule
.
CacheModException
ignored
)
{}
}
Logger
.
dev
(
"LoadModules: Data load done"
);
return
null
;
}
...
...
app/src/main/java/com/topjohnwu/magisk/asyncs/LoadRepos.java
View file @
1418ec24
package
com
.
topjohnwu
.
magisk
.
asyncs
;
import
android.app.Activity
;
import
android.content.SharedPreferences
;
import
com.topjohnwu.magisk.module.ModuleHelper
;
import
com.google.gson.Gson
;
import
com.google.gson.reflect.TypeToken
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.module.BaseModule
;
import
com.topjohnwu.magisk.module.Repo
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.ValueSortedMap
;
import
com.topjohnwu.magisk.utils.WebService
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
public
class
LoadRepos
extends
ParallelTask
<
Void
,
Void
,
Void
>
{
public
static
final
String
ETAG_KEY
=
"ETag"
;
public
static
final
String
VERSION_KEY
=
"version"
;
public
static
final
String
REPO_KEY
=
"repomap"
;
public
static
final
String
FILE_KEY
=
"RepoMap"
;
private
static
final
int
GSON_DB_VER
=
1
;
public
LoadRepos
(
Activity
context
)
{
super
(
context
);
}
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
ModuleHelper
.
createRepoMap
(
magiskManager
);
Logger
.
dev
(
"LoadRepos: Loading repos"
);
SharedPreferences
prefs
=
magiskManager
.
prefs
;
magiskManager
.
repoMap
=
new
ValueSortedMap
<>();
Gson
gson
=
new
Gson
();
String
jsonString
;
int
cachedVersion
=
prefs
.
getInt
(
VERSION_KEY
,
0
);
if
(
cachedVersion
!=
GSON_DB_VER
)
{
// Ignore incompatible cached database
jsonString
=
null
;
}
else
{
jsonString
=
prefs
.
getString
(
REPO_KEY
,
null
);
}
Map
<
String
,
Repo
>
cached
=
null
;
if
(
jsonString
!=
null
)
{
cached
=
gson
.
fromJson
(
jsonString
,
new
TypeToken
<
ValueSortedMap
<
String
,
Repo
>>(){}.
getType
());
}
if
(
cached
==
null
)
{
cached
=
new
ValueSortedMap
<>();
}
// Get cached ETag to add in the request header
String
etag
=
prefs
.
getString
(
ETAG_KEY
,
""
);
Map
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"If-None-Match"
,
etag
);
// Making a request to main URL for repo info
jsonString
=
WebService
.
request
(
magiskManager
.
getString
(
R
.
string
.
url_main
),
WebService
.
GET
,
null
,
header
,
false
);
if
(!
jsonString
.
isEmpty
())
{
try
{
JSONArray
jsonArray
=
new
JSONArray
(
jsonString
);
// If it gets to this point, the response is valid, update ETag
etag
=
WebService
.
getLastResponseHeader
().
get
(
ETAG_KEY
).
get
(
0
);
// Maybe bug in Android build tools, sometimes the ETag has crap in it...
etag
=
etag
.
substring
(
etag
.
indexOf
(
'\"'
),
etag
.
lastIndexOf
(
'\"'
)
+
1
);
// Update repo info
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
JSONObject
jsonobject
=
jsonArray
.
getJSONObject
(
i
);
String
id
=
jsonobject
.
getString
(
"description"
);
String
name
=
jsonobject
.
getString
(
"name"
);
String
lastUpdate
=
jsonobject
.
getString
(
"pushed_at"
);
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
,
Locale
.
US
);
Date
updatedDate
;
try
{
updatedDate
=
format
.
parse
(
lastUpdate
);
}
catch
(
ParseException
e
)
{
continue
;
}
Repo
repo
=
cached
.
get
(
id
);
try
{
if
(
repo
==
null
)
{
Logger
.
dev
(
"LoadRepos: Create new repo "
+
id
);
repo
=
new
Repo
(
magiskManager
,
name
,
updatedDate
);
}
else
{
Logger
.
dev
(
"LoadRepos: Update cached repo "
+
id
);
repo
.
update
(
updatedDate
);
}
if
(
repo
.
getId
()
!=
null
)
{
magiskManager
.
repoMap
.
put
(
id
,
repo
);
}
}
catch
(
BaseModule
.
CacheModException
ignored
)
{}
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
else
{
// Use cached if no internet or no updates
Logger
.
dev
(
"LoadRepos: No updates, use cached"
);
magiskManager
.
repoMap
.
putAll
(
cached
);
}
prefs
.
edit
()
.
putInt
(
VERSION_KEY
,
GSON_DB_VER
)
.
putString
(
REPO_KEY
,
gson
.
toJson
(
magiskManager
.
repoMap
))
.
putString
(
ETAG_KEY
,
etag
)
.
apply
();
Logger
.
dev
(
"LoadRepos: Repo load done"
);
return
null
;
}
...
...
app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java
View file @
1418ec24
...
...
@@ -97,7 +97,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
public
static
class
CacheModException
extends
Exception
{
public
CacheModException
(
String
id
)
{
Logger
.
dev
(
"Cache mods are no longer supported! id: "
+
id
);
Logger
.
error
(
"Cache mods are no longer supported! id: "
+
id
);
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/module/ModuleHelper.java
deleted
100644 → 0
View file @
b51978f5
package
com
.
topjohnwu
.
magisk
.
module
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.widget.Toast
;
import
com.google.gson.Gson
;
import
com.google.gson.reflect.TypeToken
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.asyncs.LoadRepos
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.ValueSortedMap
;
import
com.topjohnwu.magisk.utils.WebService
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
public
class
ModuleHelper
{
private
static
final
String
MAGISK_PATH
=
"/magisk"
;
private
static
final
int
GSON_DB_VER
=
1
;
private
static
final
String
ETAG_KEY
=
"ETag"
;
private
static
final
String
VERSION_KEY
=
"version"
;
private
static
final
String
REPO_KEY
=
"repomap"
;
private
static
final
String
FILE_KEY
=
"RepoMap"
;
public
static
void
createModuleMap
(
MagiskManager
magiskManager
)
{
Logger
.
dev
(
"ModuleHelper: Loading modules"
);
magiskManager
.
moduleMap
=
new
ValueSortedMap
<>();
for
(
String
path
:
Utils
.
getModList
(
MAGISK_PATH
))
{
Logger
.
dev
(
"ModuleHelper: Adding modules from "
+
path
);
Module
module
;
try
{
module
=
new
Module
(
path
);
magiskManager
.
moduleMap
.
put
(
module
.
getId
(),
module
);
}
catch
(
BaseModule
.
CacheModException
ignored
)
{}
}
Logger
.
dev
(
"ModuleHelper: Data load done"
);
}
public
static
void
createRepoMap
(
MagiskManager
magiskManager
)
{
Logger
.
dev
(
"ModuleHelper: Loading repos"
);
SharedPreferences
prefs
=
magiskManager
.
prefs
;
magiskManager
.
repoMap
=
new
ValueSortedMap
<>();
Gson
gson
=
new
Gson
();
String
jsonString
;
int
cachedVersion
=
prefs
.
getInt
(
VERSION_KEY
,
0
);
if
(
cachedVersion
!=
GSON_DB_VER
)
{
// Ignore incompatible cached database
jsonString
=
null
;
}
else
{
jsonString
=
prefs
.
getString
(
REPO_KEY
,
null
);
}
Map
<
String
,
Repo
>
cached
=
null
;
if
(
jsonString
!=
null
)
{
cached
=
gson
.
fromJson
(
jsonString
,
new
TypeToken
<
ValueSortedMap
<
String
,
Repo
>>(){}.
getType
());
}
if
(
cached
==
null
)
{
cached
=
new
ValueSortedMap
<>();
}
// Get cached ETag to add in the request header
String
etag
=
prefs
.
getString
(
ETAG_KEY
,
""
);
Map
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"If-None-Match"
,
etag
);
// Making a request to main URL for repo info
jsonString
=
WebService
.
request
(
magiskManager
.
getString
(
R
.
string
.
url_main
),
WebService
.
GET
,
null
,
header
,
false
);
if
(!
jsonString
.
isEmpty
())
{
try
{
JSONArray
jsonArray
=
new
JSONArray
(
jsonString
);
// If it gets to this point, the response is valid, update ETag
etag
=
WebService
.
getLastResponseHeader
().
get
(
ETAG_KEY
).
get
(
0
);
// Maybe bug in Android build tools, sometimes the ETag has crap in it...
etag
=
etag
.
substring
(
etag
.
indexOf
(
'\"'
),
etag
.
lastIndexOf
(
'\"'
)
+
1
);
// Update repo info
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
JSONObject
jsonobject
=
jsonArray
.
getJSONObject
(
i
);
String
id
=
jsonobject
.
getString
(
"description"
);
String
name
=
jsonobject
.
getString
(
"name"
);
String
lastUpdate
=
jsonobject
.
getString
(
"pushed_at"
);
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
,
Locale
.
US
);
Date
updatedDate
;
try
{
updatedDate
=
format
.
parse
(
lastUpdate
);
}
catch
(
ParseException
e
)
{
continue
;
}
Repo
repo
=
cached
.
get
(
id
);
try
{
if
(
repo
==
null
)
{
Logger
.
dev
(
"ModuleHelper: Create new repo "
+
id
);
repo
=
new
Repo
(
magiskManager
,
name
,
updatedDate
);
}
else
{
Logger
.
dev
(
"ModuleHelper: Update cached repo "
+
id
);
repo
.
update
(
updatedDate
);
}
if
(
repo
.
getId
()
!=
null
)
{
magiskManager
.
repoMap
.
put
(
id
,
repo
);
}
}
catch
(
BaseModule
.
CacheModException
ignored
)
{}
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
else
{
// Use cached if no internet or no updates
Logger
.
dev
(
"ModuleHelper: No updates, use cached"
);
magiskManager
.
repoMap
.
putAll
(
cached
);
}
prefs
.
edit
()
.
putInt
(
VERSION_KEY
,
GSON_DB_VER
)
.
putString
(
REPO_KEY
,
gson
.
toJson
(
magiskManager
.
repoMap
))
.
putString
(
ETAG_KEY
,
etag
)
.
apply
();
Logger
.
dev
(
"ModuleHelper: Repo load done"
);
}
public
static
void
clearRepoCache
(
Activity
activity
)
{
MagiskManager
magiskManager
=
Utils
.
getMagiskManager
(
activity
);
SharedPreferences
repoMap
=
activity
.
getSharedPreferences
(
FILE_KEY
,
Context
.
MODE_PRIVATE
);
repoMap
.
edit
()
.
remove
(
ETAG_KEY
)
.
remove
(
VERSION_KEY
)
.
apply
();
magiskManager
.
repoLoadDone
.
isTriggered
=
false
;
new
LoadRepos
(
activity
).
exec
();
Toast
.
makeText
(
activity
,
R
.
string
.
repo_cache_cleared
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
app/src/main/java/com/topjohnwu/magisk/module/Repo.java
View file @
1418ec24
...
...
@@ -28,8 +28,7 @@ public class Repo extends BaseModule {
}
public
void
update
(
Date
lastUpdate
)
throws
CacheModException
{
Logger
.
dev
(
"Repo: Old: "
+
mLastUpdate
);
Logger
.
dev
(
"Repo: New: "
+
lastUpdate
);
Logger
.
dev
(
"Repo: Old: "
+
mLastUpdate
+
" New: "
+
lastUpdate
);
if
(
mIsCacheModule
)
throw
new
CacheModException
(
mId
);
if
(
lastUpdate
.
after
(
mLastUpdate
))
{
...
...
app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java
View file @
1418ec24
...
...
@@ -223,7 +223,7 @@ public class SuRequestActivity extends Activity implements CallbackEvent.Listene
return
;
}
boolean
showRequest
=
false
;
event
=
magiskManager
.
uid
Map
.
get
(
uid
);
event
=
magiskManager
.
uid
SuRequest
.
get
(
uid
);
if
(
event
==
null
)
{
showRequest
=
true
;
event
=
new
CallbackEvent
<
Policy
>()
{
...
...
@@ -231,10 +231,10 @@ public class SuRequestActivity extends Activity implements CallbackEvent.Listene
public
void
trigger
(
Policy
result
)
{
super
.
trigger
(
result
);
unRegister
();
magiskManager
.
uid
Map
.
remove
(
uid
);
magiskManager
.
uid
SuRequest
.
remove
(
uid
);
}
};
magiskManager
.
uid
Map
.
put
(
uid
,
event
);
magiskManager
.
uid
SuRequest
.
put
(
uid
,
event
);
}
event
.
register
(
self
);
try
{
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
1418ec24
package
com
.
topjohnwu
.
magisk
.
utils
;
import
android.Manifest
;
import
android.app.Activity
;
import
android.app.DownloadManager
;
import
android.content.Context
;
import
android.content.IntentFilter
;
...
...
@@ -15,6 +16,7 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.asyncs.LoadRepos
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
java.io.File
;
...
...
@@ -152,4 +154,16 @@ public class Utils {
}
}.
requestTest
();
}
public
static
void
clearRepoCache
(
Activity
activity
)
{
MagiskManager
magiskManager
=
getMagiskManager
(
activity
);
SharedPreferences
repoMap
=
activity
.
getSharedPreferences
(
LoadRepos
.
FILE_KEY
,
Context
.
MODE_PRIVATE
);
repoMap
.
edit
()
.
remove
(
LoadRepos
.
ETAG_KEY
)
.
remove
(
LoadRepos
.
VERSION_KEY
)
.
apply
();
magiskManager
.
repoLoadDone
.
isTriggered
=
false
;
new
LoadRepos
(
activity
).
exec
();
Toast
.
makeText
(
activity
,
R
.
string
.
repo_cache_cleared
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
\ 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