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
da4f53eb
Commit
da4f53eb
authored
Jul 20, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't store multiple repo copies in memory
parent
8458553b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
77 additions
and
70 deletions
+77
-70
MagiskManager.java
app/src/main/java/com/topjohnwu/magisk/MagiskManager.java
+2
-4
ReposFragment.java
app/src/main/java/com/topjohnwu/magisk/ReposFragment.java
+8
-14
SplashActivity.java
app/src/main/java/com/topjohnwu/magisk/SplashActivity.java
+2
-2
ReposAdapter.java
...main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
+20
-6
UpdateRepos.java
...rc/main/java/com/topjohnwu/magisk/asyncs/UpdateRepos.java
+16
-18
RepoDatabaseHelper.java
...ava/com/topjohnwu/magisk/database/RepoDatabaseHelper.java
+24
-22
Repo.java
app/src/main/java/com/topjohnwu/magisk/module/Repo.java
+3
-1
Utils.java
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
+2
-3
No files found.
app/src/main/java/com/topjohnwu/magisk/MagiskManager.java
View file @
da4f53eb
...
@@ -15,15 +15,14 @@ import android.widget.Toast;
...
@@ -15,15 +15,14 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.database.SuDatabaseHelper
;
import
com.topjohnwu.magisk.database.SuDatabaseHelper
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.Repo
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.SafetyNetHelper
;
import
com.topjohnwu.magisk.utils.SafetyNetHelper
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.ValueSortedMap
;
import
java.io.File
;
import
java.io.File
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
public
class
MagiskManager
extends
Application
{
public
class
MagiskManager
extends
Application
{
...
@@ -65,8 +64,7 @@ public class MagiskManager extends Application {
...
@@ -65,8 +64,7 @@ public class MagiskManager extends Application {
public
boolean
disabled
;
public
boolean
disabled
;
// Data
// Data
public
ValueSortedMap
<
String
,
Repo
>
repoMap
;
public
Map
<
String
,
Module
>
moduleMap
;
public
ValueSortedMap
<
String
,
Module
>
moduleMap
;
public
List
<
String
>
blockList
;
public
List
<
String
>
blockList
;
public
List
<
ApplicationInfo
>
appList
;
public
List
<
ApplicationInfo
>
appList
;
public
List
<
String
>
magiskHideList
;
public
List
<
String
>
magiskHideList
;
...
...
app/src/main/java/com/topjohnwu/magisk/ReposFragment.java
View file @
da4f53eb
...
@@ -13,7 +13,7 @@ import android.widget.SearchView;
...
@@ -13,7 +13,7 @@ import android.widget.SearchView;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.topjohnwu.magisk.adapters.ReposAdapter
;
import
com.topjohnwu.magisk.adapters.ReposAdapter
;
import
com.topjohnwu.magisk.asyncs.
Load
Repos
;
import
com.topjohnwu.magisk.asyncs.
Update
Repos
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Logger
;
...
@@ -43,15 +43,14 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener<Vo
...
@@ -43,15 +43,14 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener<Vo
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_repos
,
container
,
false
);
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_repos
,
container
,
false
);
unbinder
=
ButterKnife
.
bind
(
this
,
view
);
unbinder
=
ButterKnife
.
bind
(
this
,
view
);
adapter
=
new
ReposAdapter
(
getApplication
().
repoMap
);
adapter
=
new
ReposAdapter
(
getApplication
().
repoDB
,
getApplication
().
moduleMap
);
recyclerView
.
setAdapter
(
adapter
);
recyclerView
.
setAdapter
(
adapter
);
mSwipeRefreshLayout
.
setRefreshing
(
true
);
mSwipeRefreshLayout
.
setRefreshing
(
true
);
mSwipeRefreshLayout
.
setOnRefreshListener
(()
->
{
mSwipeRefreshLayout
.
setOnRefreshListener
(()
->
{
recyclerView
.
setVisibility
(
View
.
GONE
);
recyclerView
.
setVisibility
(
View
.
GONE
);
new
Load
Repos
(
getActivity
()).
exec
();
new
Update
Repos
(
getActivity
()).
exec
();
});
});
if
(
getApplication
().
repoLoadDone
.
isTriggered
)
{
if
(
getApplication
().
repoLoadDone
.
isTriggered
)
{
...
@@ -64,15 +63,10 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener<Vo
...
@@ -64,15 +63,10 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener<Vo
@Override
@Override
public
void
onTrigger
(
CallbackEvent
<
Void
>
event
)
{
public
void
onTrigger
(
CallbackEvent
<
Void
>
event
)
{
Logger
.
dev
(
"ReposFragment: UI refresh triggered"
);
Logger
.
dev
(
"ReposFragment: UI refresh triggered"
);
if
(
getApplication
().
repoMap
.
isEmpty
())
{
mSwipeRefreshLayout
.
setRefreshing
(
false
);
recyclerView
.
setVisibility
(
View
.
GONE
);
adapter
.
notifyDBChanged
();
emptyRv
.
setVisibility
(
View
.
VISIBLE
);
recyclerView
.
setVisibility
(
adapter
.
getItemCount
()
==
0
?
View
.
GONE
:
View
.
VISIBLE
);
}
else
{
emptyRv
.
setVisibility
(
adapter
.
getItemCount
()
==
0
?
View
.
VISIBLE
:
View
.
GONE
);
adapter
.
filter
(
getApplication
().
moduleMap
,
""
);
recyclerView
.
setVisibility
(
View
.
VISIBLE
);
emptyRv
.
setVisibility
(
View
.
GONE
);
mSwipeRefreshLayout
.
setRefreshing
(
false
);
}
}
}
@Override
@Override
...
@@ -87,7 +81,7 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener<Vo
...
@@ -87,7 +81,7 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener<Vo
@Override
@Override
public
boolean
onQueryTextChange
(
String
newText
)
{
public
boolean
onQueryTextChange
(
String
newText
)
{
adapter
.
filter
(
getApplication
().
moduleMap
,
newText
);
adapter
.
filter
(
newText
);
return
false
;
return
false
;
}
}
});
});
...
...
app/src/main/java/com/topjohnwu/magisk/SplashActivity.java
View file @
da4f53eb
...
@@ -10,7 +10,7 @@ import android.text.TextUtils;
...
@@ -10,7 +10,7 @@ import android.text.TextUtils;
import
com.topjohnwu.magisk.asyncs.LoadApps
;
import
com.topjohnwu.magisk.asyncs.LoadApps
;
import
com.topjohnwu.magisk.asyncs.LoadModules
;
import
com.topjohnwu.magisk.asyncs.LoadModules
;
import
com.topjohnwu.magisk.asyncs.
Load
Repos
;
import
com.topjohnwu.magisk.asyncs.
Update
Repos
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.services.UpdateCheckService
;
import
com.topjohnwu.magisk.services.UpdateCheckService
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
...
@@ -48,7 +48,7 @@ public class SplashActivity extends Activity{
...
@@ -48,7 +48,7 @@ public class SplashActivity extends Activity{
JobScheduler
scheduler
=
(
JobScheduler
)
getSystemService
(
Context
.
JOB_SCHEDULER_SERVICE
);
JobScheduler
scheduler
=
(
JobScheduler
)
getSystemService
(
Context
.
JOB_SCHEDULER_SERVICE
);
scheduler
.
schedule
(
jobInfo
);
scheduler
.
schedule
(
jobInfo
);
}
}
loadModuleTask
.
setCallBack
(()
->
new
Load
Repos
(
this
).
exec
());
loadModuleTask
.
setCallBack
(()
->
new
Update
Repos
(
this
).
exec
());
}
}
// Now fire all async tasks
// Now fire all async tasks
...
...
app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
View file @
da4f53eb
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.adapters;
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.adapters;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v7.widget.RecyclerView
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
...
@@ -16,14 +17,15 @@ import com.topjohnwu.magisk.R;
...
@@ -16,14 +17,15 @@ import com.topjohnwu.magisk.R;
import
com.topjohnwu.magisk.asyncs.ProcessRepoZip
;
import
com.topjohnwu.magisk.asyncs.ProcessRepoZip
;
import
com.topjohnwu.magisk.components.AlertDialogBuilder
;
import
com.topjohnwu.magisk.components.AlertDialogBuilder
;
import
com.topjohnwu.magisk.components.MarkDownWindow
;
import
com.topjohnwu.magisk.components.MarkDownWindow
;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.Repo
;
import
com.topjohnwu.magisk.module.Repo
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.ValueSortedMap
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
butterknife.BindView
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
...
@@ -36,10 +38,13 @@ public class ReposAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
...
@@ -36,10 +38,13 @@ public class ReposAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private
List
<
Repo
>
mUpdateRepos
,
mInstalledRepos
,
mOthersRepos
;
private
List
<
Repo
>
mUpdateRepos
,
mInstalledRepos
,
mOthersRepos
;
private
int
[]
sectionList
;
private
int
[]
sectionList
;
private
int
size
;
private
int
size
;
private
ValueSortedMap
<
String
,
Repo
>
repoMap
;
private
Cursor
repoCursor
=
null
;
private
Map
<
String
,
Module
>
moduleMap
;
private
RepoDatabaseHelper
repoDB
;
public
ReposAdapter
(
ValueSortedMap
<
String
,
Repo
>
map
)
{
public
ReposAdapter
(
RepoDatabaseHelper
db
,
Map
<
String
,
Module
>
map
)
{
repoMap
=
map
;
repoDB
=
db
;
moduleMap
=
map
;
mUpdateRepos
=
new
ArrayList
<>();
mUpdateRepos
=
new
ArrayList
<>();
mInstalledRepos
=
new
ArrayList
<>();
mInstalledRepos
=
new
ArrayList
<>();
mOthersRepos
=
new
ArrayList
<>();
mOthersRepos
=
new
ArrayList
<>();
...
@@ -137,12 +142,20 @@ public class ReposAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
...
@@ -137,12 +142,20 @@ public class ReposAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
return
size
;
return
size
;
}
}
public
void
filter
(
ValueSortedMap
<
String
,
Module
>
moduleMap
,
String
s
)
{
public
void
notifyDBChanged
()
{
if
(
repoCursor
!=
null
)
repoCursor
.
close
();
repoCursor
=
repoDB
.
getRepoCursor
();
filter
(
""
);
}
public
void
filter
(
String
s
)
{
mUpdateRepos
.
clear
();
mUpdateRepos
.
clear
();
mInstalledRepos
.
clear
();
mInstalledRepos
.
clear
();
mOthersRepos
.
clear
();
mOthersRepos
.
clear
();
sectionList
[
0
]
=
sectionList
[
1
]
=
sectionList
[
2
]
=
0
;
sectionList
[
0
]
=
sectionList
[
1
]
=
sectionList
[
2
]
=
0
;
for
(
Repo
repo
:
repoMap
.
values
())
{
while
(
repoCursor
.
moveToNext
())
{
Repo
repo
=
new
Repo
(
repoCursor
);
if
(
repo
.
getName
().
toLowerCase
().
contains
(
s
.
toLowerCase
())
if
(
repo
.
getName
().
toLowerCase
().
contains
(
s
.
toLowerCase
())
||
repo
.
getAuthor
().
toLowerCase
().
contains
(
s
.
toLowerCase
())
||
repo
.
getAuthor
().
toLowerCase
().
contains
(
s
.
toLowerCase
())
||
repo
.
getDescription
().
toLowerCase
().
contains
(
s
.
toLowerCase
())
||
repo
.
getDescription
().
toLowerCase
().
contains
(
s
.
toLowerCase
())
...
@@ -161,6 +174,7 @@ public class ReposAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
...
@@ -161,6 +174,7 @@ public class ReposAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
}
}
}
}
}
repoCursor
.
moveToFirst
();
sectionList
[
0
]
=
mUpdateRepos
.
isEmpty
()
?
-
1
:
0
;
sectionList
[
0
]
=
mUpdateRepos
.
isEmpty
()
?
-
1
:
0
;
size
=
mUpdateRepos
.
isEmpty
()
?
0
:
mUpdateRepos
.
size
()
+
1
;
size
=
mUpdateRepos
.
isEmpty
()
?
0
:
mUpdateRepos
.
size
()
+
1
;
...
...
app/src/main/java/com/topjohnwu/magisk/asyncs/
Load
Repos.java
→
app/src/main/java/com/topjohnwu/magisk/asyncs/
Update
Repos.java
View file @
da4f53eb
...
@@ -9,7 +9,6 @@ import com.topjohnwu.magisk.database.RepoDatabaseHelper;
...
@@ -9,7 +9,6 @@ import com.topjohnwu.magisk.database.RepoDatabaseHelper;
import
com.topjohnwu.magisk.module.BaseModule
;
import
com.topjohnwu.magisk.module.BaseModule
;
import
com.topjohnwu.magisk.module.Repo
;
import
com.topjohnwu.magisk.module.Repo
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.ValueSortedMap
;
import
com.topjohnwu.magisk.utils.WebService
;
import
com.topjohnwu.magisk.utils.WebService
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
...
@@ -25,7 +24,7 @@ import java.util.List;
...
@@ -25,7 +24,7 @@ import java.util.List;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map
;
public
class
Load
Repos
extends
ParallelTask
<
Void
,
Void
,
Void
>
{
public
class
Update
Repos
extends
ParallelTask
<
Void
,
Void
,
Void
>
{
public
static
final
String
ETAG_KEY
=
"ETag"
;
public
static
final
String
ETAG_KEY
=
"ETag"
;
...
@@ -38,11 +37,11 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
...
@@ -38,11 +37,11 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
private
static
final
int
LOAD_PREV
=
2
;
private
static
final
int
LOAD_PREV
=
2
;
private
List
<
String
>
etags
;
private
List
<
String
>
etags
;
private
ValueSortedMap
<
String
,
Repo
>
cached
,
fet
ched
;
private
List
<
String
>
ca
ched
;
private
RepoDatabaseHelper
repoDB
;
private
RepoDatabaseHelper
repoDB
;
private
SharedPreferences
prefs
;
private
SharedPreferences
prefs
;
public
Load
Repos
(
Context
context
)
{
public
Update
Repos
(
Context
context
)
{
super
(
context
);
super
(
context
);
prefs
=
getMagiskManager
().
prefs
;
prefs
=
getMagiskManager
().
prefs
;
repoDB
=
getMagiskManager
().
repoDB
;
repoDB
=
getMagiskManager
().
repoDB
;
...
@@ -68,25 +67,27 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
...
@@ -68,25 +67,27 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
String
lastUpdate
=
jsonobject
.
getString
(
"pushed_at"
);
String
lastUpdate
=
jsonobject
.
getString
(
"pushed_at"
);
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
,
Locale
.
US
);
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
,
Locale
.
US
);
Date
updatedDate
=
format
.
parse
(
lastUpdate
);
Date
updatedDate
=
format
.
parse
(
lastUpdate
);
Repo
repo
=
cached
.
get
(
id
);
Repo
repo
=
repoDB
.
getRepo
(
id
);
try
{
try
{
Boolean
updated
;
if
(
repo
==
null
)
{
if
(
repo
==
null
)
{
Logger
.
dev
(
"
Load
Repos: Create new repo "
+
id
);
Logger
.
dev
(
"
Update
Repos: Create new repo "
+
id
);
repo
=
new
Repo
(
name
,
updatedDate
);
repo
=
new
Repo
(
name
,
updatedDate
);
updated
=
true
;
}
else
{
}
else
{
// Popout from cached
// Popout from cached
cached
.
remove
(
id
);
cached
.
remove
(
id
);
repo
.
update
(
updatedDate
);
updated
=
repo
.
update
(
updatedDate
);
}
}
if
(
repo
.
getId
()
!=
null
)
{
if
(
updated
)
{
fetched
.
put
(
id
,
repo
);
repoDB
.
addRepo
(
repo
);
}
}
}
catch
(
BaseModule
.
CacheModException
ignored
)
{}
}
catch
(
BaseModule
.
CacheModException
ignored
)
{}
}
}
}
}
private
boolean
loadPage
(
int
page
,
String
url
,
int
mode
)
{
private
boolean
loadPage
(
int
page
,
String
url
,
int
mode
)
{
Logger
.
dev
(
"
Load
Repos: Loading page: "
+
(
page
+
1
));
Logger
.
dev
(
"
Update
Repos: Loading page: "
+
(
page
+
1
));
Map
<
String
,
String
>
header
=
new
HashMap
<>();
Map
<
String
,
String
>
header
=
new
HashMap
<>();
if
(
mode
==
CHECK_ETAG
&&
page
<
etags
.
size
()
&&
!
TextUtils
.
isEmpty
(
etags
.
get
(
page
)))
{
if
(
mode
==
CHECK_ETAG
&&
page
<
etags
.
size
()
&&
!
TextUtils
.
isEmpty
(
etags
.
get
(
page
)))
{
Logger
.
dev
(
"ETAG: "
+
etags
.
get
(
page
));
Logger
.
dev
(
"ETAG: "
+
etags
.
get
(
page
));
...
@@ -157,18 +158,16 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
...
@@ -157,18 +158,16 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
protected
Void
doInBackground
(
Void
...
voids
)
{
protected
Void
doInBackground
(
Void
...
voids
)
{
MagiskManager
magiskManager
=
getMagiskManager
();
MagiskManager
magiskManager
=
getMagiskManager
();
if
(
magiskManager
==
null
)
return
null
;
if
(
magiskManager
==
null
)
return
null
;
Logger
.
dev
(
"
Load
Repos: Loading repos"
);
Logger
.
dev
(
"
Update
Repos: Loading repos"
);
cached
=
repoDB
.
getRepoMap
(
false
);
cached
=
repoDB
.
getRepoIDList
();
fetched
=
new
ValueSortedMap
<>();
if
(!
loadPage
(
0
,
null
,
CHECK_ETAG
))
{
if
(!
loadPage
(
0
,
null
,
CHECK_ETAG
))
{
magiskManager
.
repoMap
=
repoDB
.
getRepoMap
();
Logger
.
dev
(
"UpdateRepos: No updates, use DB"
);
Logger
.
dev
(
"LoadRepos: No updates, use DB"
);
return
null
;
return
null
;
}
}
repoDB
.
addRepoMap
(
fetched
);
// The leftover cached means they are removed from online repo
repoDB
.
removeRepo
(
cached
);
repoDB
.
removeRepo
(
cached
);
// Update ETag
// Update ETag
...
@@ -179,8 +178,7 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
...
@@ -179,8 +178,7 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
}
}
prefs
.
edit
().
putString
(
ETAG_KEY
,
etagBuilder
.
toString
()).
apply
();
prefs
.
edit
().
putString
(
ETAG_KEY
,
etagBuilder
.
toString
()).
apply
();
magiskManager
.
repoMap
=
repoDB
.
getRepoMap
();
Logger
.
dev
(
"UpdateRepos: Done"
);
Logger
.
dev
(
"LoadRepos: Done"
);
return
null
;
return
null
;
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java
View file @
da4f53eb
...
@@ -7,9 +7,9 @@ import android.database.sqlite.SQLiteOpenHelper;
...
@@ -7,9 +7,9 @@ import android.database.sqlite.SQLiteOpenHelper;
import
com.topjohnwu.magisk.module.Repo
;
import
com.topjohnwu.magisk.module.Repo
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.ValueSortedMap
;
import
java.util.Collection
;
import
java.util.LinkedList
;
import
java.util.List
;
public
class
RepoDatabaseHelper
extends
SQLiteOpenHelper
{
public
class
RepoDatabaseHelper
extends
SQLiteOpenHelper
{
...
@@ -45,37 +45,39 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
...
@@ -45,37 +45,39 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
}
}
}
}
public
void
addRepoMap
(
ValueSortedMap
<
String
,
Repo
>
map
)
{
public
void
clearRepo
()
{
Collection
<
Repo
>
list
=
map
.
values
();
mDb
.
delete
(
TABLE_NAME
,
null
,
null
);
for
(
Repo
repo
:
list
)
{
}
Logger
.
dev
(
"Add to DB: "
+
repo
.
getId
());
mDb
.
replace
(
TABLE_NAME
,
null
,
repo
.
getContentValues
());
public
void
removeRepo
(
List
<
String
>
list
)
{
for
(
String
id
:
list
)
{
Logger
.
dev
(
"Remove from DB: "
+
id
);
mDb
.
delete
(
TABLE_NAME
,
"id=?"
,
new
String
[]
{
id
});
}
}
}
}
public
void
clearRepo
(
)
{
public
void
addRepo
(
Repo
repo
)
{
mDb
.
delete
(
TABLE_NAME
,
null
,
null
);
mDb
.
replace
(
TABLE_NAME
,
null
,
repo
.
getContentValues
()
);
}
}
public
void
removeRepo
(
ValueSortedMap
<
String
,
Repo
>
map
)
{
public
Repo
getRepo
(
String
id
)
{
Collection
<
Repo
>
list
=
map
.
values
();
try
(
Cursor
c
=
mDb
.
query
(
TABLE_NAME
,
null
,
"id=?"
,
new
String
[]
{
id
},
null
,
null
,
null
))
{
for
(
Repo
repo
:
list
)
{
if
(
c
.
moveToNext
()
)
{
Logger
.
dev
(
"Remove from DB: "
+
repo
.
getId
()
);
return
new
Repo
(
c
);
mDb
.
delete
(
TABLE_NAME
,
"id=?"
,
new
String
[]
{
repo
.
getId
()
});
}
}
}
return
null
;
}
}
public
ValueSortedMap
<
String
,
Repo
>
getRepoMap
()
{
public
Cursor
getRepoCursor
()
{
return
getRepoMap
(
true
);
return
mDb
.
query
(
TABLE_NAME
,
null
,
"template>=?"
,
new
String
[]
{
String
.
valueOf
(
MIN_TEMPLATE_VER
)
},
null
,
null
,
"name COLLATE NOCASE"
);
}
}
public
ValueSortedMap
<
String
,
Repo
>
getRepoMap
(
boolean
filtered
)
{
public
List
<
String
>
getRepoIDList
()
{
ValueSortedMap
<
String
,
Repo
>
ret
=
new
ValueSortedMap
<>();
LinkedList
<
String
>
ret
=
new
LinkedList
<>();
Repo
repo
;
try
(
Cursor
c
=
mDb
.
query
(
TABLE_NAME
,
null
,
null
,
null
,
null
,
null
,
null
))
{
try
(
Cursor
c
=
mDb
.
query
(
TABLE_NAME
,
null
,
"template>=?"
,
new
String
[]
{
filtered
?
String
.
valueOf
(
MIN_TEMPLATE_VER
)
:
"0"
},
null
,
null
,
null
))
{
while
(
c
.
moveToNext
())
{
while
(
c
.
moveToNext
())
{
repo
=
new
Repo
(
c
);
ret
.
add
(
c
.
getString
(
c
.
getColumnIndex
(
"id"
)));
ret
.
put
(
repo
.
getId
(),
repo
);
}
}
}
}
return
ret
;
return
ret
;
...
...
app/src/main/java/com/topjohnwu/magisk/module/Repo.java
View file @
da4f53eb
...
@@ -35,11 +35,13 @@ public class Repo extends BaseModule {
...
@@ -35,11 +35,13 @@ public class Repo extends BaseModule {
Logger
.
dev
(
"Repo: Fetching prop: "
+
getId
());
Logger
.
dev
(
"Repo: Fetching prop: "
+
getId
());
}
}
public
void
update
(
Date
lastUpdate
)
throws
CacheModException
{
public
boolean
update
(
Date
lastUpdate
)
throws
CacheModException
{
if
(
lastUpdate
.
after
(
mLastUpdate
))
{
if
(
lastUpdate
.
after
(
mLastUpdate
))
{
mLastUpdate
=
lastUpdate
;
mLastUpdate
=
lastUpdate
;
update
();
update
();
return
true
;
}
}
return
false
;
}
}
public
ContentValues
getContentValues
()
{
public
ContentValues
getContentValues
()
{
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
da4f53eb
...
@@ -27,9 +27,8 @@ import android.widget.Toast;
...
@@ -27,9 +27,8 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.SplashActivity
;
import
com.topjohnwu.magisk.SplashActivity
;
import
com.topjohnwu.magisk.asyncs.
Load
Repos
;
import
com.topjohnwu.magisk.asyncs.
Update
Repos
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.receivers.ManagerUpdate
;
import
com.topjohnwu.magisk.receivers.ManagerUpdate
;
...
@@ -142,7 +141,7 @@ public class Utils {
...
@@ -142,7 +141,7 @@ public class Utils {
public
static
void
clearRepoCache
(
Context
context
)
{
public
static
void
clearRepoCache
(
Context
context
)
{
MagiskManager
magiskManager
=
getMagiskManager
(
context
);
MagiskManager
magiskManager
=
getMagiskManager
(
context
);
magiskManager
.
prefs
.
edit
().
remove
(
Load
Repos
.
ETAG_KEY
).
apply
();
magiskManager
.
prefs
.
edit
().
remove
(
Update
Repos
.
ETAG_KEY
).
apply
();
magiskManager
.
repoDB
.
clearRepo
();
magiskManager
.
repoDB
.
clearRepo
();
magiskManager
.
toast
(
R
.
string
.
repo_cache_cleared
,
Toast
.
LENGTH_SHORT
);
magiskManager
.
toast
(
R
.
string
.
repo_cache_cleared
,
Toast
.
LENGTH_SHORT
);
}
}
...
...
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