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
817f050b
Commit
817f050b
authored
Mar 29, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Say goodbye to old modules
parent
60ae685d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
18 deletions
+35
-18
LoadRepos.java
app/src/main/java/com/topjohnwu/magisk/asyncs/LoadRepos.java
+10
-15
RepoDatabaseHelper.java
...ava/com/topjohnwu/magisk/database/RepoDatabaseHelper.java
+14
-2
BaseModule.java
...src/main/java/com/topjohnwu/magisk/module/BaseModule.java
+10
-1
Repo.java
app/src/main/java/com/topjohnwu/magisk/module/Repo.java
+1
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/asyncs/LoadRepos.java
View file @
817f050b
...
@@ -57,12 +57,10 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
...
@@ -57,12 +57,10 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
String
etag
=
prefs
.
getString
(
ETAG_KEY
,
""
);
String
etag
=
prefs
.
getString
(
ETAG_KEY
,
""
);
header
.
put
(
"If-None-Match"
,
etag
);
header
.
put
(
"If-None-Match"
,
etag
);
magiskManager
.
repoMap
=
new
ValueSortedMap
<>();
// Make a request to main URL for repo info
// Make a request to main URL for repo info
String
jsonString
=
WebService
.
request
(
REPO_URL
,
WebService
.
GET
,
null
,
header
,
false
);
String
jsonString
=
WebService
.
request
(
REPO_URL
,
WebService
.
GET
,
null
,
header
,
false
);
ValueSortedMap
<
String
,
Repo
>
cached
=
dbHelper
.
getRepoMap
();
ValueSortedMap
<
String
,
Repo
>
cached
=
dbHelper
.
getRepoMap
(
false
),
fetched
=
new
ValueSortedMap
<>(
);
if
(!
TextUtils
.
isEmpty
(
jsonString
))
{
if
(!
TextUtils
.
isEmpty
(
jsonString
))
{
try
{
try
{
...
@@ -97,27 +95,24 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
...
@@ -97,27 +95,24 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
repo
.
update
(
updatedDate
);
repo
.
update
(
updatedDate
);
}
}
if
(
repo
.
getId
()
!=
null
)
{
if
(
repo
.
getId
()
!=
null
)
{
magiskManager
.
repoMap
.
put
(
id
,
repo
);
fetched
.
put
(
id
,
repo
);
}
}
}
catch
(
BaseModule
.
CacheModException
ignored
)
{}
}
catch
(
BaseModule
.
CacheModException
ignored
)
{}
// Update the database
dbHelper
.
addRepoMap
(
fetched
);
// The leftover cached are those removed remote, cleanup db
dbHelper
.
removeRepo
(
cached
);
// Update ETag
prefs
.
edit
().
putString
(
ETAG_KEY
,
etag
).
apply
();
}
}
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
else
{
// Use cached if no internet or no updates
Logger
.
dev
(
"LoadRepos: No updates, use cached"
);
magiskManager
.
repoMap
.
putAll
(
cached
);
cached
.
clear
();
}
}
// Update the database
magiskManager
.
repoMap
=
dbHelper
.
getRepoMap
();
dbHelper
.
addRepoMap
(
magiskManager
.
repoMap
);
// The leftover cached are those removed remote, cleanup db
dbHelper
.
removeRepo
(
cached
);
// Update ETag
prefs
.
edit
().
putString
(
ETAG_KEY
,
etag
).
apply
();
Logger
.
dev
(
"LoadRepos: Repo load done"
);
Logger
.
dev
(
"LoadRepos: Repo load done"
);
return
null
;
return
null
;
...
...
app/src/main/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java
View file @
817f050b
...
@@ -13,7 +13,7 @@ import java.util.Collection;
...
@@ -13,7 +13,7 @@ import java.util.Collection;
public
class
RepoDatabaseHelper
extends
SQLiteOpenHelper
{
public
class
RepoDatabaseHelper
extends
SQLiteOpenHelper
{
private
static
final
int
DATABASE_VER
=
1
;
private
static
final
int
DATABASE_VER
=
2
;
private
static
final
String
TABLE_NAME
=
"repos"
;
private
static
final
String
TABLE_NAME
=
"repos"
;
public
RepoDatabaseHelper
(
Context
context
)
{
public
RepoDatabaseHelper
(
Context
context
)
{
...
@@ -33,8 +33,12 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
...
@@ -33,8 +33,12 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
"(id TEXT, name TEXT, version TEXT, versionCode INT, "
+
"(id TEXT, name TEXT, version TEXT, versionCode INT, "
+
"author TEXT, description TEXT, repo_name TEXT, last_update INT, "
+
"author TEXT, description TEXT, repo_name TEXT, last_update INT, "
+
"PRIMARY KEY(id))"
);
"PRIMARY KEY(id))"
);
oldVersion
++;
}
if
(
oldVersion
==
1
)
{
db
.
execSQL
(
"ALTER TABLE "
+
TABLE_NAME
+
" ADD template INT"
);
oldVersion
++;
}
}
// No upgrades yet
}
}
public
void
addRepoMap
(
ValueSortedMap
<
String
,
Repo
>
map
)
{
public
void
addRepoMap
(
ValueSortedMap
<
String
,
Repo
>
map
)
{
...
@@ -62,6 +66,10 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
...
@@ -62,6 +66,10 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
}
}
public
ValueSortedMap
<
String
,
Repo
>
getRepoMap
()
{
public
ValueSortedMap
<
String
,
Repo
>
getRepoMap
()
{
return
getRepoMap
(
true
);
}
public
ValueSortedMap
<
String
,
Repo
>
getRepoMap
(
boolean
filtered
)
{
ValueSortedMap
<
String
,
Repo
>
ret
=
new
ValueSortedMap
<>();
ValueSortedMap
<
String
,
Repo
>
ret
=
new
ValueSortedMap
<>();
SQLiteDatabase
db
=
getReadableDatabase
();
SQLiteDatabase
db
=
getReadableDatabase
();
Repo
repo
;
Repo
repo
;
...
@@ -69,6 +77,10 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
...
@@ -69,6 +77,10 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
while
(
c
.
moveToNext
())
{
while
(
c
.
moveToNext
())
{
repo
=
new
Repo
(
c
);
repo
=
new
Repo
(
c
);
Logger
.
dev
(
"Load from cache: "
+
repo
.
getId
());
Logger
.
dev
(
"Load from cache: "
+
repo
.
getId
());
if
(
repo
.
getTemplateVersion
()
<
3
&&
filtered
)
{
Logger
.
dev
(
"Outdated repo: "
+
repo
.
getId
());
continue
;
}
ret
.
put
(
repo
.
getId
(),
repo
);
ret
.
put
(
repo
.
getId
(),
repo
);
}
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java
View file @
817f050b
...
@@ -11,7 +11,7 @@ import java.util.List;
...
@@ -11,7 +11,7 @@ import java.util.List;
public
abstract
class
BaseModule
implements
Comparable
<
BaseModule
>
{
public
abstract
class
BaseModule
implements
Comparable
<
BaseModule
>
{
private
String
mId
,
mName
,
mVersion
,
mAuthor
,
mDescription
;
private
String
mId
,
mName
,
mVersion
,
mAuthor
,
mDescription
;
private
int
mVersionCode
=
0
;
private
int
mVersionCode
=
0
,
templateVersion
=
0
;
protected
BaseModule
()
{}
protected
BaseModule
()
{}
...
@@ -22,6 +22,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
...
@@ -22,6 +22,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
mVersionCode
=
c
.
getInt
(
c
.
getColumnIndex
(
"versionCode"
));
mVersionCode
=
c
.
getInt
(
c
.
getColumnIndex
(
"versionCode"
));
mAuthor
=
c
.
getString
(
c
.
getColumnIndex
(
"author"
));
mAuthor
=
c
.
getString
(
c
.
getColumnIndex
(
"author"
));
mDescription
=
c
.
getString
(
c
.
getColumnIndex
(
"description"
));
mDescription
=
c
.
getString
(
c
.
getColumnIndex
(
"description"
));
templateVersion
=
c
.
getInt
(
c
.
getColumnIndex
(
"template"
));
}
}
protected
void
parseProps
(
List
<
String
>
props
)
throws
CacheModException
{
parseProps
(
props
.
toArray
(
new
String
[
props
.
size
()]));
}
protected
void
parseProps
(
List
<
String
>
props
)
throws
CacheModException
{
parseProps
(
props
.
toArray
(
new
String
[
props
.
size
()]));
}
...
@@ -57,6 +58,10 @@ public abstract class BaseModule implements Comparable<BaseModule> {
...
@@ -57,6 +58,10 @@ public abstract class BaseModule implements Comparable<BaseModule> {
case
"description"
:
case
"description"
:
mDescription
=
prop
[
1
];
mDescription
=
prop
[
1
];
break
;
break
;
case
"template"
:
try
{
templateVersion
=
Integer
.
parseInt
(
prop
[
1
]);
}
catch
(
NumberFormatException
ignored
)
{}
case
"cacheModule"
:
case
"cacheModule"
:
if
(
Boolean
.
parseBoolean
(
prop
[
1
]))
if
(
Boolean
.
parseBoolean
(
prop
[
1
]))
throw
new
CacheModException
(
mId
);
throw
new
CacheModException
(
mId
);
...
@@ -99,6 +104,10 @@ public abstract class BaseModule implements Comparable<BaseModule> {
...
@@ -99,6 +104,10 @@ public abstract class BaseModule implements Comparable<BaseModule> {
return
mVersionCode
;
return
mVersionCode
;
}
}
public
int
getTemplateVersion
()
{
return
templateVersion
;
}
public
static
class
CacheModException
extends
Exception
{
public
static
class
CacheModException
extends
Exception
{
public
CacheModException
(
String
id
)
{
public
CacheModException
(
String
id
)
{
Logger
.
error
(
"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/Repo.java
View file @
817f050b
...
@@ -53,6 +53,7 @@ public class Repo extends BaseModule {
...
@@ -53,6 +53,7 @@ public class Repo extends BaseModule {
values
.
put
(
"description"
,
getDescription
());
values
.
put
(
"description"
,
getDescription
());
values
.
put
(
"repo_name"
,
repoName
);
values
.
put
(
"repo_name"
,
repoName
);
values
.
put
(
"last_update"
,
mLastUpdate
.
getTime
());
values
.
put
(
"last_update"
,
mLastUpdate
.
getTime
());
values
.
put
(
"template"
,
getTemplateVersion
());
return
values
;
return
values
;
}
}
...
...
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