Rework some parts of the app for better XPosed support.

pull/164/head
Fox2Code 2 years ago
parent 4f27117c8d
commit 3bbcc0c197

@ -68,7 +68,7 @@ public class MainApplication extends CompatApplication {
}
public MainApplication() {
if (INSTANCE != null)
if (INSTANCE != null && INSTANCE != this)
throw new IllegalStateException("Duplicate application instance!");
INSTANCE = this;
}
@ -280,6 +280,7 @@ public class MainApplication extends CompatApplication {
@Override
public void onCreate() {
if (INSTANCE == null) INSTANCE = this;
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (MainApplication.isMonetEnabled()) {

@ -16,6 +16,9 @@ import com.fox2code.mmm.repo.RepoManager;
*/
@Keep
public class XHooks {
@Keep
public static void onRepoManagerInitialized() {}
@Keep
public static boolean isModuleActive(String moduleId) {
return ModuleManager.isModuleActive(moduleId);

@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import android.util.Log;
import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.XHooks;
import com.fox2code.mmm.androidacy.AndroidacyRepoData;
import com.fox2code.mmm.manager.ModuleInfo;
import com.fox2code.mmm.utils.Files;
@ -45,6 +46,7 @@ public final class RepoManager {
MainApplication mainApplication = MainApplication.getINSTANCE();
if (mainApplication != null) {
INSTANCE = new RepoManager(mainApplication);
XHooks.onRepoManagerInitialized();
} else {
throw new RuntimeException("Getting RepoManager too soon!");
}
@ -58,8 +60,10 @@ public final class RepoManager {
private final LinkedHashMap<String, RepoData> repoData;
private final HashMap<String, RepoModule> modules;
private final AndroidacyRepoData androidacyRepoData;
private boolean initialized;
private RepoManager(MainApplication mainApplication) {
this.initialized = false;
this.mainApplication = mainApplication;
this.repoData = new LinkedHashMap<>();
this.modules = new HashMap<>();
@ -69,19 +73,24 @@ public final class RepoManager {
this.addAndroidacyRepoData();
// Populate default cache
for (RepoData repoData:this.repoData.values()) {
for (RepoModule repoModule:repoData.moduleHashMap.values()) {
if (!repoModule.moduleInfo.hasFlag(ModuleInfo.FLAG_METADATA_INVALID)) {
RepoModule registeredRepoModule = this.modules.get(repoModule.id);
if (registeredRepoModule == null) {
this.modules.put(repoModule.id, repoModule);
} else if (repoModule.moduleInfo.versionCode >
registeredRepoModule.moduleInfo.versionCode) {
this.modules.put(repoModule.id, repoModule);
}
} else {
Log.e(TAG, "Detected module with invalid metadata: " +
repoModule.repoName + "/" + repoModule.id);
this.populateDefaultCache(repoData);
}
this.initialized = true;
}
private void populateDefaultCache(RepoData repoData) {
for (RepoModule repoModule:repoData.moduleHashMap.values()) {
if (!repoModule.moduleInfo.hasFlag(ModuleInfo.FLAG_METADATA_INVALID)) {
RepoModule registeredRepoModule = this.modules.get(repoModule.id);
if (registeredRepoModule == null) {
this.modules.put(repoModule.id, repoModule);
} else if (repoModule.moduleInfo.versionCode >
registeredRepoModule.moduleInfo.versionCode) {
this.modules.put(repoModule.id, repoModule);
}
} else {
Log.e(TAG, "Detected module with invalid metadata: " +
repoModule.repoName + "/" + repoModule.id);
}
}
}
@ -121,18 +130,18 @@ public final class RepoManager {
return this.repoUpdating;
}
public final void afterUpdate() {
public void afterUpdate() {
if (this.repoUpdating) synchronized (this.repoUpdateLock) {}
}
public final void runAfterUpdate(Runnable runnable) {
public void runAfterUpdate(Runnable runnable) {
synchronized (this.repoUpdateLock) {
runnable.run();
}
}
// MultiThread friendly method
public final void update(UpdateListener updateListener) {
public void update(UpdateListener updateListener) {
if (!this.repoUpdating) {
// Do scan
synchronized (this.repoUpdateLock) {
@ -255,6 +264,9 @@ public final class RepoManager {
.getSharedPreferences("mmm_" + id, Context.MODE_PRIVATE);
RepoData repoData = new RepoData(url, cacheRoot, sharedPreferences);
this.repoData.put(url, repoData);
if (this.initialized) {
this.populateDefaultCache(repoData);
}
return repoData;
}

Loading…
Cancel
Save