Rework some parts of the app for better XPosed support.

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

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

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

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

Loading…
Cancel
Save