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

Commit 3bbcc0c

Browse files
committed
Rework some parts of the app for better XPosed support.
1 parent 4f27117 commit 3bbcc0c

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class MainApplication extends CompatApplication {
6868
}
6969

7070
public MainApplication() {
71-
if (INSTANCE != null)
71+
if (INSTANCE != null && INSTANCE != this)
7272
throw new IllegalStateException("Duplicate application instance!");
7373
INSTANCE = this;
7474
}
@@ -280,6 +280,7 @@ public boolean isLightTheme() {
280280

281281
@Override
282282
public void onCreate() {
283+
if (INSTANCE == null) INSTANCE = this;
283284
super.onCreate();
284285
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
285286
if (MainApplication.isMonetEnabled()) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
@Keep
1818
public class XHooks {
19+
@Keep
20+
public static void onRepoManagerInitialized() {}
21+
1922
@Keep
2023
public static boolean isModuleActive(String moduleId) {
2124
return ModuleManager.isModuleActive(moduleId);

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.util.Log;
66

77
import com.fox2code.mmm.MainApplication;
8+
import com.fox2code.mmm.XHooks;
89
import com.fox2code.mmm.androidacy.AndroidacyRepoData;
910
import com.fox2code.mmm.manager.ModuleInfo;
1011
import com.fox2code.mmm.utils.Files;
@@ -45,6 +46,7 @@ public static RepoManager getINSTANCE() {
4546
MainApplication mainApplication = MainApplication.getINSTANCE();
4647
if (mainApplication != null) {
4748
INSTANCE = new RepoManager(mainApplication);
49+
XHooks.onRepoManagerInitialized();
4850
} else {
4951
throw new RuntimeException("Getting RepoManager too soon!");
5052
}
@@ -58,8 +60,10 @@ public static RepoManager getINSTANCE() {
5860
private final LinkedHashMap<String, RepoData> repoData;
5961
private final HashMap<String, RepoModule> modules;
6062
private final AndroidacyRepoData androidacyRepoData;
63+
private boolean initialized;
6164

6265
private RepoManager(MainApplication mainApplication) {
66+
this.initialized = false;
6367
this.mainApplication = mainApplication;
6468
this.repoData = new LinkedHashMap<>();
6569
this.modules = new HashMap<>();
@@ -69,19 +73,24 @@ private RepoManager(MainApplication mainApplication) {
6973
this.addAndroidacyRepoData();
7074
// Populate default cache
7175
for (RepoData repoData:this.repoData.values()) {
72-
for (RepoModule repoModule:repoData.moduleHashMap.values()) {
73-
if (!repoModule.moduleInfo.hasFlag(ModuleInfo.FLAG_METADATA_INVALID)) {
74-
RepoModule registeredRepoModule = this.modules.get(repoModule.id);
75-
if (registeredRepoModule == null) {
76-
this.modules.put(repoModule.id, repoModule);
77-
} else if (repoModule.moduleInfo.versionCode >
78-
registeredRepoModule.moduleInfo.versionCode) {
79-
this.modules.put(repoModule.id, repoModule);
80-
}
81-
} else {
82-
Log.e(TAG, "Detected module with invalid metadata: " +
83-
repoModule.repoName + "/" + repoModule.id);
76+
this.populateDefaultCache(repoData);
77+
}
78+
this.initialized = true;
79+
}
80+
81+
private void populateDefaultCache(RepoData repoData) {
82+
for (RepoModule repoModule:repoData.moduleHashMap.values()) {
83+
if (!repoModule.moduleInfo.hasFlag(ModuleInfo.FLAG_METADATA_INVALID)) {
84+
RepoModule registeredRepoModule = this.modules.get(repoModule.id);
85+
if (registeredRepoModule == null) {
86+
this.modules.put(repoModule.id, repoModule);
87+
} else if (repoModule.moduleInfo.versionCode >
88+
registeredRepoModule.moduleInfo.versionCode) {
89+
this.modules.put(repoModule.id, repoModule);
8490
}
91+
} else {
92+
Log.e(TAG, "Detected module with invalid metadata: " +
93+
repoModule.repoName + "/" + repoModule.id);
8594
}
8695
}
8796
}
@@ -121,18 +130,18 @@ public boolean isRepoUpdating() {
121130
return this.repoUpdating;
122131
}
123132

124-
public final void afterUpdate() {
133+
public void afterUpdate() {
125134
if (this.repoUpdating) synchronized (this.repoUpdateLock) {}
126135
}
127136

128-
public final void runAfterUpdate(Runnable runnable) {
137+
public void runAfterUpdate(Runnable runnable) {
129138
synchronized (this.repoUpdateLock) {
130139
runnable.run();
131140
}
132141
}
133142

134143
// MultiThread friendly method
135-
public final void update(UpdateListener updateListener) {
144+
public void update(UpdateListener updateListener) {
136145
if (!this.repoUpdating) {
137146
// Do scan
138147
synchronized (this.repoUpdateLock) {
@@ -255,6 +264,9 @@ private RepoData addRepoData(String url) {
255264
.getSharedPreferences("mmm_" + id, Context.MODE_PRIVATE);
256265
RepoData repoData = new RepoData(url, cacheRoot, sharedPreferences);
257266
this.repoData.put(url, repoData);
267+
if (this.initialized) {
268+
this.populateDefaultCache(repoData);
269+
}
258270
return repoData;
259271
}
260272

0 commit comments

Comments
 (0)