Improve application Thread safety.

pull/27/head
Fox2Code 3 years ago
parent c1cad9b30b
commit beb4925ff3

@ -5,8 +5,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.installer.InstallerInitializer;
import com.fox2code.mmm.manager.ModuleManager;
public class BackgroundBootListener extends BroadcastReceiver { public class BackgroundBootListener extends BroadcastReceiver {
private static final String BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED"; private static final String BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
@ -20,17 +18,5 @@ public class BackgroundBootListener extends BroadcastReceiver {
BackgroundUpdateChecker.doCheck(context); BackgroundUpdateChecker.doCheck(context);
} }
} }
if (ModuleManager.FORCE_NEED_FALLBACK &&
MainApplication.hasGottenRootAccess()) {
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
@Override
public void onPathReceived(String path) {
ModuleManager.getINSTANCE().scan();
}
@Override
public void onFailure(int error) {}
});
}
} }
} }

@ -54,28 +54,30 @@ public class BackgroundUpdateChecker extends Worker {
static void doCheck(Context context) { static void doCheck(Context context) {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY); Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
ModuleManager.getINSTANCE().scanAsync();
RepoManager.getINSTANCE().update(null); RepoManager.getINSTANCE().update(null);
ModuleManager.getINSTANCE().scan(); ModuleManager.getINSTANCE().runAfterScan(() -> {
int moduleUpdateCount = 0; int moduleUpdateCount = 0;
HashMap<String, RepoModule> repoModules = HashMap<String, RepoModule> repoModules =
RepoManager.getINSTANCE().getModules(); RepoManager.getINSTANCE().getModules();
for (LocalModuleInfo localModuleInfo : for (LocalModuleInfo localModuleInfo :
ModuleManager.getINSTANCE().getModules().values()) { ModuleManager.getINSTANCE().getModules().values()) {
if ("twrp-keep".equals(localModuleInfo.id)) continue; if ("twrp-keep".equals(localModuleInfo.id)) continue;
RepoModule repoModule = repoModules.get(localModuleInfo.id); RepoModule repoModule = repoModules.get(localModuleInfo.id);
localModuleInfo.checkModuleUpdate(); localModuleInfo.checkModuleUpdate();
if (localModuleInfo.updateVersionCode > localModuleInfo.versionCode && if (localModuleInfo.updateVersionCode > localModuleInfo.versionCode &&
!PropUtils.isNullString(localModuleInfo.updateVersion)) { !PropUtils.isNullString(localModuleInfo.updateVersion)) {
moduleUpdateCount++; moduleUpdateCount++;
} else if (repoModule != null && } else if (repoModule != null &&
repoModule.moduleInfo.versionCode > localModuleInfo.versionCode && repoModule.moduleInfo.versionCode > localModuleInfo.versionCode &&
!PropUtils.isNullString(repoModule.moduleInfo.version)) { !PropUtils.isNullString(repoModule.moduleInfo.version)) {
moduleUpdateCount++; moduleUpdateCount++;
}
} }
} if (moduleUpdateCount != 0) {
if (moduleUpdateCount != 0) { postNotification(context, moduleUpdateCount);
postNotification(context, moduleUpdateCount); }
} });
} }
public static void postNotification(Context context, int updateCount) { public static void postNotification(Context context, int updateCount) {

@ -114,6 +114,8 @@ public class ModuleViewListBuilder {
public void applyTo(final RecyclerView moduleList,final ModuleViewAdapter moduleViewAdapter) { public void applyTo(final RecyclerView moduleList,final ModuleViewAdapter moduleViewAdapter) {
if (this.updating) return; if (this.updating) return;
this.updating = true; this.updating = true;
ModuleManager.getINSTANCE().afterScan();
RepoManager.getINSTANCE().afterUpdate();
final ArrayList<ModuleHolder> moduleHolders; final ArrayList<ModuleHolder> moduleHolders;
final int newNotificationsLen; final int newNotificationsLen;
final boolean first; final boolean first;

@ -15,6 +15,12 @@ public abstract class SyncManager {
private boolean syncing; private boolean syncing;
private long lastSync; private long lastSync;
public final void scanAsync() {
if (!this.syncing) {
new Thread(this::scan, "Scan Thread").start();
}
}
public final void scan() { public final void scan() {
this.update(null); this.update(null);
} }

Loading…
Cancel
Save