Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit b97eaf1

Browse files
committed
Show quality notifiers in modules cards, and fix Magisk repo workaround.
1 parent b9bb6d4 commit b97eaf1

File tree

6 files changed

+191
-114
lines changed

6 files changed

+191
-114
lines changed

app/src/main/java/com/fox2code/mmm/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class Constants {
55
public static final int MAGISK_VER_CODE_UTIL_INSTALL = 20400;
66
public static final int MAGISK_VER_CODE_PATH_SUPPORT = 21000;
77
public static final int MAGISK_VER_CODE_INSTALL_COMMAND = 21200;
8-
public static final int MAGISK_VER_CODE_MAGISK_ZYGOTE = 23002;
8+
public static final int MAGISK_VER_CODE_MAGISK_ZYGOTE = 24000;
99
public static final String INTENT_INSTALL_INTERNAL =
1010
BuildConfig.APPLICATION_ID + ".intent.action.INSTALL_MODULE_INTERNAL";
1111
public static final String INTENT_ANDROIDACY_INTERNAL =

app/src/main/java/com/fox2code/mmm/ModuleViewAdapter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.fox2code.mmm.manager.LocalModuleInfo;
2222
import com.fox2code.mmm.manager.ModuleInfo;
2323
import com.fox2code.mmm.manager.ModuleManager;
24+
import com.fox2code.mmm.repo.RepoModule;
2425
import com.google.android.material.switchmaterial.SwitchMaterial;
2526
import com.topjohnwu.superuser.internal.UiThreadHandler;
2627

@@ -199,10 +200,14 @@ public boolean update(ModuleHolder moduleHolder) {
199200
}
200201
String updateText = moduleHolder.getUpdateTimeText();
201202
if (!updateText.isEmpty()) {
203+
RepoModule repoModule = moduleHolder.repoModule;
202204
this.updateText.setVisibility(View.VISIBLE);
203205
this.updateText.setText(
204206
this.getString(R.string.module_last_update) + " " + updateText + "\n" +
205-
this.getString(R.string.module_repo) + " " + moduleHolder.getRepoName());
207+
this.getString(R.string.module_repo) + " " + moduleHolder.getRepoName() +
208+
(repoModule.qualityText == 0 ? "" : (
209+
"\n" + this.getString(repoModule.qualityText) +
210+
" " + repoModule.qualityValue)));
206211
} else if (moduleHolder.moduleId.equals("hosts")) {
207212
this.updateText.setVisibility(View.VISIBLE);
208213
this.updateText.setText(R.string.magisk_builtin_module);

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public class AndroidacyRepoData extends RepoData {
2828
public AndroidacyRepoData(String url, File cacheRoot,
2929
SharedPreferences cachedPreferences) {
3030
super(url, cacheRoot, cachedPreferences);
31+
if (this.metaDataCache.exists()) {
32+
this.androidacyBlockade = this.metaDataCache.lastModified() + 5_000L;
33+
if (this.androidacyBlockade - 10_000L > System.currentTimeMillis()) {
34+
this.androidacyBlockade = 0; // Don't allow time travel
35+
}
36+
}
3137
}
3238

3339
@Override
@@ -185,6 +191,13 @@ public void storeMetadata(RepoModule repoModule, byte[] data) {}
185191

186192
@Override
187193
public boolean tryLoadMetadata(RepoModule repoModule) {
188-
return true;
194+
if (this.moduleHashMap.containsKey(repoModule.id)) {
195+
repoModule.moduleInfo.flags &=
196+
~ModuleInfo.FLAG_METADATA_INVALID;
197+
return true;
198+
}
199+
repoModule.moduleInfo.flags |=
200+
ModuleInfo.FLAG_METADATA_INVALID;
201+
return false;
189202
}
190203
}

app/src/main/java/com/fox2code/mmm/repo/RepoData.java

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import android.content.SharedPreferences;
55
import android.util.Log;
66

7+
import androidx.annotation.NonNull;
8+
9+
import com.fox2code.mmm.R;
710
import com.fox2code.mmm.manager.ModuleInfo;
811
import com.fox2code.mmm.utils.Files;
912
import com.fox2code.mmm.utils.Http;
@@ -27,6 +30,7 @@
2730
import java.util.Objects;
2831

2932
public class RepoData {
33+
private static final String TAG = "RepoData";
3034
private final Object populateLock = new Object();
3135
public final String url;
3236
public final File cacheRoot;
@@ -36,7 +40,7 @@ public class RepoData {
3640
public final HashMap<String, RepoModule> moduleHashMap;
3741
public long lastUpdate;
3842
public String name;
39-
private final Map<String, Long> specialTimes;
43+
private final Map<String, SpecialData> specialData;
4044
private long specialLastUpdate;
4145

4246
protected RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences) {
@@ -51,7 +55,7 @@ protected RepoData(String url, File cacheRoot, SharedPreferences cachedPreferenc
5155
this.special = special;
5256
this.moduleHashMap = new HashMap<>();
5357
this.name = this.url; // Set url as default name
54-
this.specialTimes = special ? new HashMap<>() : Collections.emptyMap();
58+
this.specialData = special ? new HashMap<>() : Collections.emptyMap();
5559
if (!this.cacheRoot.isDirectory()) {
5660
this.cacheRoot.mkdirs();
5761
} else {
@@ -63,10 +67,13 @@ protected RepoData(String url, File cacheRoot, SharedPreferences cachedPreferenc
6367
Files.read(this.metaDataCache), StandardCharsets.UTF_8));
6468
for (int i = 0; i < jsonArray.length(); i++) {
6569
JSONObject jsonObject = jsonArray.getJSONObject(i);
66-
this.specialTimes.put(jsonObject.getString("name"),
67-
Objects.requireNonNull(ISO_OFFSET_DATE_TIME.parse(
68-
jsonObject.getString("pushed_at"))).getTime());
69-
Log.d("RepoData", "Got " +
70+
this.specialData.put(
71+
jsonObject.getString("name"), new SpecialData(
72+
Objects.requireNonNull(ISO_OFFSET_DATE_TIME.parse(
73+
jsonObject.getString(
74+
"pushed_at"))).getTime(),
75+
jsonObject.optInt("stargazers_count")));
76+
Log.d(TAG, "Got " +
7077
jsonObject.getString("name") + " from local storage!");
7178
}
7279
this.specialLastUpdate = metaDataCacheSpecial.lastModified();
@@ -79,6 +86,10 @@ protected RepoData(String url, File cacheRoot, SharedPreferences cachedPreferenc
7986
}
8087
}
8188
if (this.metaDataCache.exists()) {
89+
this.lastUpdate = metaDataCache.lastModified();
90+
if (this.lastUpdate > System.currentTimeMillis()) {
91+
this.lastUpdate = 0; // Don't allow time travel
92+
}
8293
try {
8394
List<RepoModule> modules = this.populate(new JSONObject(
8495
new String(Files.read(this.metaDataCache), StandardCharsets.UTF_8)));
@@ -108,24 +119,22 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
108119
for (RepoModule repoModule : this.moduleHashMap.values()) {
109120
repoModule.processed = false;
110121
}
111-
Log.d("RepoData", "Data: " + this.specialTimes.toString());
112122
JSONArray array = jsonObject.getJSONArray("modules");
113123
int len = array.length();
114124
for (int i = 0; i < len; i++) {
115125
JSONObject module = array.getJSONObject(i);
116126
String moduleId = module.getString("id");
117127
// Deny remote modules ids shorter than 3 chars long or that start with a digit
118128
if (moduleId.length() < 3 || Character.isDigit(moduleId.charAt(0))) continue;
119-
Long moduleLastUpdateSpecial = this.specialTimes.get(moduleId);
129+
SpecialData moduleSpecialData = this.specialData.get(moduleId);
120130
long moduleLastUpdate = module.getLong("last_update");
121131
String moduleNotesUrl = module.getString("notes_url");
122132
String modulePropsUrl = module.getString("prop_url");
123133
String moduleZipUrl = module.getString("zip_url");
124134
String moduleChecksum = module.optString("checksum");
125-
if (moduleLastUpdateSpecial != null) { // Fix last update time
126-
Log.d("RepoData", "Data: " + moduleLastUpdate + " -> " +
127-
moduleLastUpdateSpecial + " for " + moduleId);
128-
moduleLastUpdate = Math.max(moduleLastUpdate, moduleLastUpdateSpecial);
135+
String moduleStars = module.optString("stars");
136+
if (moduleSpecialData != null) { // Fix last update time
137+
moduleLastUpdate = Math.max(moduleLastUpdate, moduleSpecialData.time);
129138
moduleNotesUrl = Http.updateLink(moduleNotesUrl);
130139
modulePropsUrl = Http.updateLink(modulePropsUrl);
131140
moduleZipUrl = Http.updateLink(moduleZipUrl);
@@ -152,6 +161,15 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
152161
repoModule.propUrl = modulePropsUrl;
153162
repoModule.zipUrl = moduleZipUrl;
154163
repoModule.checksum = moduleChecksum;
164+
if (moduleSpecialData != null) {
165+
repoModule.qualityValue = moduleSpecialData.stars;
166+
repoModule.qualityText = R.string.module_stars;
167+
} else if (!moduleStars.isEmpty()) {
168+
try {
169+
repoModule.qualityValue = Integer.parseInt(moduleStars);
170+
repoModule.qualityText = R.string.module_stars;
171+
} catch (NumberFormatException ignored) {}
172+
}
155173
}
156174
// Remove no longer existing modules
157175
Iterator<RepoModule> moduleInfoIterator = this.moduleHashMap.values().iterator();
@@ -184,6 +202,12 @@ public boolean tryLoadMetadata(RepoModule repoModule) {
184202
if (moduleInfo.version == null) {
185203
moduleInfo.version = "v" + moduleInfo.versionCode;
186204
}
205+
SpecialData moduleSpecialData =
206+
this.specialData.get(repoModule.id);
207+
if (moduleSpecialData != null) {
208+
repoModule.qualityValue = moduleSpecialData.stars;
209+
repoModule.qualityText = R.string.module_stars;
210+
}
187211
return true;
188212
} catch (Exception ignored) {
189213
file.delete();
@@ -200,20 +224,24 @@ public boolean tryLoadMetadata(RepoModule repoModule) {
200224
public void updateSpecialTimes(boolean force) throws IOException, JSONException {
201225
if (!this.special) return;
202226
synchronized (this.populateLock) {
203-
if (this.specialLastUpdate == 0L ||
204-
(force && this.specialLastUpdate < System.currentTimeMillis() - 60000L)) {
227+
if (this.specialLastUpdate == 0L || (force && (this.specialData.isEmpty() ||
228+
this.specialLastUpdate < System.currentTimeMillis() - 60000L))) {
205229
File metaDataCacheSpecial = new File(cacheRoot, "modules_times.json");
206-
this.specialTimes.clear();
230+
this.specialData.clear();
207231
try {
232+
// Requesting only 32 most recently pushed repos
208233
byte[] data = Http.doHttpGet(
209-
"https://api.github.com/users/Magisk-Modules-Repo/repos",
210-
false);
234+
"https://api.github.com/users/Magisk-Modules-Repo/" +
235+
"repos?sort=pushed&per_page=32", false);
211236
JSONArray jsonArray = new JSONArray(new String(data, StandardCharsets.UTF_8));
212237
for (int i = 0;i < jsonArray.length();i++) {
213238
JSONObject jsonObject = jsonArray.optJSONObject(i);
214-
this.specialTimes.put(jsonObject.getString("name"),
215-
Objects.requireNonNull(ISO_OFFSET_DATE_TIME.parse(
216-
jsonObject.getString("pushed_at"))).getTime());
239+
this.specialData.put(
240+
jsonObject.getString("name"), new SpecialData(
241+
Objects.requireNonNull(ISO_OFFSET_DATE_TIME.parse(
242+
jsonObject.getString(
243+
"pushed_at"))).getTime(),
244+
jsonObject.optInt("stargazers_count")));
217245
}
218246
Files.write(metaDataCacheSpecial, data);
219247
this.specialLastUpdate = System.currentTimeMillis();
@@ -229,4 +257,22 @@ public String getNameOrFallback(String fallback) {
229257
this.name.equals(this.url) ?
230258
fallback : this.name;
231259
}
260+
261+
private static class SpecialData {
262+
SpecialData(long time, int stars) {
263+
this.time = time; this.stars = stars;
264+
}
265+
266+
final long time;
267+
final int stars;
268+
269+
@NonNull
270+
@Override
271+
public String toString() {
272+
return "SpecialData{" +
273+
"time=" + time +
274+
", stars=" + stars +
275+
'}';
276+
}
277+
}
232278
}

app/src/main/java/com/fox2code/mmm/repo/RepoManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ private boolean scanInternal(UpdateListener updateListener) {
182182
Log.d(TAG, "Registering " + repoData.name);
183183
for (RepoModule repoModule:repoModules) {
184184
try {
185-
if (repoModule.propUrl != null) {
185+
if (repoModule.propUrl != null &&
186+
!repoModule.propUrl.isEmpty()) {
186187
repoData.storeMetadata(repoModule,
187188
Http.doHttpGet(repoModule.propUrl, false));
188189
Files.write(new File(repoData.cacheRoot, repoModule.id + ".prop"),

0 commit comments

Comments
 (0)