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

Commit f3a1e63

Browse files
committed
Remove Magisk-Modules-Repo life support.
1 parent 5ee90a1 commit f3a1e63

File tree

4 files changed

+5
-123
lines changed

4 files changed

+5
-123
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ The app currently use these two repo as it's module sources, with it's benefits
3434
- Officially supported by Fox's mmm
3535

3636
[https://github.com/Magisk-Modules-Repo](https://github.com/Magisk-Modules-Repo)
37-
- No longer accept new modules or update to existing modules
38-
(Fox's MMM use a workaround to get latest version of modules, because the
39-
method used by the official Magisk app give outdated versions of the modules)
37+
- No longer accept new modules or receive update to existing modules
4038
- May be shut down at any moment
4139
- Official app dropped support for it
42-
- Officially supported by Fox's mmm
40+
- End of life support by Fox's mmm
4341

4442
As the main repo may shutting down due to the main app no longer supporting it,
4543
and also stopped accepting new modules, it is recommended to submit your modules
Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package com.fox2code.mmm.repo;
22

3-
import android.annotation.SuppressLint;
43
import android.content.SharedPreferences;
5-
import android.util.Log;
6-
7-
import androidx.annotation.NonNull;
84

95
import com.fox2code.mmm.MainApplication;
106
import com.fox2code.mmm.R;
117
import com.fox2code.mmm.manager.ModuleInfo;
128
import com.fox2code.mmm.utils.Files;
13-
import com.fox2code.mmm.utils.Http;
149
import com.fox2code.mmm.utils.PropUtils;
1510

1611
import org.json.JSONArray;
@@ -20,15 +15,10 @@
2015
import java.io.File;
2116
import java.io.IOException;
2217
import java.nio.charset.StandardCharsets;
23-
import java.text.ParseException;
24-
import java.text.SimpleDateFormat;
2518
import java.util.ArrayList;
26-
import java.util.Collections;
2719
import java.util.HashMap;
2820
import java.util.Iterator;
2921
import java.util.List;
30-
import java.util.Map;
31-
import java.util.Objects;
3222

3323
public class RepoData {
3424
private static final String TAG = "RepoData";
@@ -38,59 +28,24 @@ public class RepoData {
3828
public final File cacheRoot;
3929
public final SharedPreferences cachedPreferences;
4030
public final File metaDataCache;
41-
public final boolean special;
4231
public final HashMap<String, RepoModule> moduleHashMap;
4332
public long lastUpdate;
4433
public String name;
4534
private boolean enabled; // Cache for speed
46-
private final Map<String, SpecialData> specialData;
47-
private long specialLastUpdate;
4835

4936
protected RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences) {
50-
this(url, cacheRoot, cachedPreferences, false);
51-
}
52-
53-
RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences,boolean special) {
5437
this.url = url;
5538
this.id = RepoManager.internalIdOfUrl(url);
5639
this.cacheRoot = cacheRoot;
5740
this.cachedPreferences = cachedPreferences;
5841
this.metaDataCache = new File(cacheRoot, "modules.json");
59-
this.special = special;
6042
this.moduleHashMap = new HashMap<>();
6143
this.name = this.url; // Set url as default name
6244
this.enabled = MainApplication.getSharedPreferences()
6345
.getBoolean("pref_" + this.id + "_enabled", true);
64-
this.specialData = special ? new HashMap<>() : Collections.emptyMap();
6546
if (!this.cacheRoot.isDirectory()) {
6647
this.cacheRoot.mkdirs();
6748
} else {
68-
if (special) { // Special times need to be loaded before populate
69-
File metaDataCacheSpecial = new File(cacheRoot, "modules_times.json");
70-
if (metaDataCacheSpecial.exists()) {
71-
try {
72-
JSONArray jsonArray = new JSONArray(new String(
73-
Files.read(this.metaDataCache), StandardCharsets.UTF_8));
74-
for (int i = 0; i < jsonArray.length(); i++) {
75-
JSONObject jsonObject = jsonArray.getJSONObject(i);
76-
this.specialData.put(
77-
jsonObject.getString("name"), new SpecialData(
78-
Objects.requireNonNull(ISO_OFFSET_DATE_TIME.parse(
79-
jsonObject.getString(
80-
"pushed_at"))).getTime(),
81-
jsonObject.optInt("stargazers_count")));
82-
Log.d(TAG, "Got " +
83-
jsonObject.getString("name") + " from local storage!");
84-
}
85-
this.specialLastUpdate = metaDataCacheSpecial.lastModified();
86-
if (this.specialLastUpdate > System.currentTimeMillis()) {
87-
this.specialLastUpdate = 0; // Don't allow time travel
88-
}
89-
} catch (Exception e) {
90-
metaDataCacheSpecial.delete();
91-
}
92-
}
93-
}
9449
if (this.metaDataCache.exists()) {
9550
this.lastUpdate = metaDataCache.lastModified();
9651
if (this.lastUpdate > System.currentTimeMillis()) {
@@ -132,19 +87,12 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
13287
String moduleId = module.getString("id");
13388
// Deny remote modules ids shorter than 3 chars long or that start with a digit
13489
if (moduleId.length() < 3 || Character.isDigit(moduleId.charAt(0))) continue;
135-
SpecialData moduleSpecialData = this.specialData.get(moduleId);
13690
long moduleLastUpdate = module.getLong("last_update");
13791
String moduleNotesUrl = module.getString("notes_url");
13892
String modulePropsUrl = module.getString("prop_url");
13993
String moduleZipUrl = module.getString("zip_url");
14094
String moduleChecksum = module.optString("checksum");
14195
String moduleStars = module.optString("stars");
142-
if (moduleSpecialData != null) { // Fix last update time
143-
moduleLastUpdate = Math.max(moduleLastUpdate, moduleSpecialData.time);
144-
moduleNotesUrl = Http.updateLink(moduleNotesUrl);
145-
modulePropsUrl = Http.updateLink(modulePropsUrl);
146-
moduleZipUrl = Http.updateLink(moduleZipUrl);
147-
}
14896
RepoModule repoModule = this.moduleHashMap.get(moduleId);
14997
if (repoModule == null) {
15098
repoModule = new RepoModule(this, moduleId);
@@ -163,10 +111,7 @@ protected List<RepoModule> populate(JSONObject jsonObject) throws JSONException
163111
repoModule.propUrl = modulePropsUrl;
164112
repoModule.zipUrl = moduleZipUrl;
165113
repoModule.checksum = moduleChecksum;
166-
if (moduleSpecialData != null) {
167-
repoModule.qualityValue = moduleSpecialData.stars;
168-
repoModule.qualityText = R.string.module_stars;
169-
} else if (!moduleStars.isEmpty()) {
114+
if (!moduleStars.isEmpty()) {
170115
try {
171116
repoModule.qualityValue = Integer.parseInt(moduleStars);
172117
repoModule.qualityText = R.string.module_stars;
@@ -204,12 +149,6 @@ public boolean tryLoadMetadata(RepoModule repoModule) {
204149
if (moduleInfo.version == null) {
205150
moduleInfo.version = "v" + moduleInfo.versionCode;
206151
}
207-
SpecialData moduleSpecialData =
208-
this.specialData.get(repoModule.id);
209-
if (moduleSpecialData != null) {
210-
repoModule.qualityValue = moduleSpecialData.stars;
211-
repoModule.qualityText = R.string.module_stars;
212-
}
213152
return true;
214153
} catch (Exception ignored) {
215154
file.delete();
@@ -219,41 +158,6 @@ public boolean tryLoadMetadata(RepoModule repoModule) {
219158
return false;
220159
}
221160

222-
@SuppressLint("SimpleDateFormat")
223-
private static final SimpleDateFormat ISO_OFFSET_DATE_TIME =
224-
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
225-
226-
public void updateSpecialTimes(boolean force) throws IOException, JSONException {
227-
if (!this.special) return;
228-
synchronized (this.populateLock) {
229-
if (this.specialLastUpdate == 0L || (force && (this.specialData.isEmpty() ||
230-
this.specialLastUpdate < System.currentTimeMillis() - 60000L))) {
231-
File metaDataCacheSpecial = new File(cacheRoot, "modules_times.json");
232-
this.specialData.clear();
233-
try {
234-
// Requesting only 32 most recently pushed repos
235-
byte[] data = Http.doHttpGet(
236-
"https://api.github.com/users/Magisk-Modules-Repo/" +
237-
"repos?sort=pushed&per_page=32", false);
238-
JSONArray jsonArray = new JSONArray(new String(data, StandardCharsets.UTF_8));
239-
for (int i = 0;i < jsonArray.length();i++) {
240-
JSONObject jsonObject = jsonArray.optJSONObject(i);
241-
this.specialData.put(
242-
jsonObject.getString("name"), new SpecialData(
243-
Objects.requireNonNull(ISO_OFFSET_DATE_TIME.parse(
244-
jsonObject.getString(
245-
"pushed_at"))).getTime(),
246-
jsonObject.optInt("stargazers_count")));
247-
}
248-
Files.write(metaDataCacheSpecial, data);
249-
this.specialLastUpdate = System.currentTimeMillis();
250-
} catch (ParseException e) {
251-
throw new IOException(e);
252-
}
253-
}
254-
}
255-
}
256-
257161
public String getNameOrFallback(String fallback) {
258162
return this.name == null ||
259163
this.name.equals(this.url) ?
@@ -274,22 +178,4 @@ public void updateEnabledState() {
274178
this.enabled = MainApplication.getSharedPreferences()
275179
.getBoolean("pref_" + this.id + "_enabled", true);
276180
}
277-
278-
private static class SpecialData {
279-
SpecialData(long time, int stars) {
280-
this.time = time; this.stars = stars;
281-
}
282-
283-
final long time;
284-
final int stars;
285-
286-
@NonNull
287-
@Override
288-
public String toString() {
289-
return "SpecialData{" +
290-
"time=" + time +
291-
", stars=" + stars +
292-
'}';
293-
}
294-
}
295181
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ private RepoManager(MainApplication mainApplication) {
6868
this.repoData = new LinkedHashMap<>();
6969
this.modules = new HashMap<>();
7070
// We do not have repo list config yet.
71-
this.addRepoData(MAGISK_REPO);
7271
this.addRepoData(MAGISK_ALT_REPO);
7372
this.addAndroidacyRepoData();
73+
this.addRepoData(MAGISK_REPO);
7474
// Populate default cache
7575
for (RepoData repoData:this.repoData.values()) {
7676
for (RepoModule repoModule:repoData.moduleHashMap.values()) {
@@ -264,8 +264,7 @@ private RepoData addRepoData(String url) {
264264
File cacheRoot = new File(this.mainApplication.getCacheDir(), id);
265265
SharedPreferences sharedPreferences = this.mainApplication
266266
.getSharedPreferences("mmm_" + id, Context.MODE_PRIVATE);
267-
RepoData repoData = new RepoData(url, cacheRoot,
268-
sharedPreferences, id.equals("magisk_repo"));
267+
RepoData repoData = new RepoData(url, cacheRoot, sharedPreferences);
269268
this.repoData.put(url, repoData);
270269
return repoData;
271270
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public int fetchIndex() {
3737
return 0;
3838
}
3939
this.indexRaw = Http.doHttpGet(this.repoData.url, false);
40-
if (this.repoData.special) this.repoData.updateSpecialTimes(true);
4140
this.toUpdate = this.repoData.populate(new JSONObject(
4241
new String(this.indexRaw, StandardCharsets.UTF_8)));
4342
// Since we reuse instances this should work

0 commit comments

Comments
 (0)