Improve application Thread safety.

pull/202/head
Fox2Code 2 years ago
parent c1cad9b30b
commit beb4925ff3

@ -5,8 +5,6 @@ import android.content.Context;
import android.content.Intent;
import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.installer.InstallerInitializer;
import com.fox2code.mmm.manager.ModuleManager;
public class BackgroundBootListener extends BroadcastReceiver {
private static final String BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
@ -20,17 +18,5 @@ public class BackgroundBootListener extends BroadcastReceiver {
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) {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
ModuleManager.getINSTANCE().scanAsync();
RepoManager.getINSTANCE().update(null);
ModuleManager.getINSTANCE().scan();
int moduleUpdateCount = 0;
HashMap<String, RepoModule> repoModules =
RepoManager.getINSTANCE().getModules();
for (LocalModuleInfo localModuleInfo :
ModuleManager.getINSTANCE().getModules().values()) {
if ("twrp-keep".equals(localModuleInfo.id)) continue;
RepoModule repoModule = repoModules.get(localModuleInfo.id);
localModuleInfo.checkModuleUpdate();
if (localModuleInfo.updateVersionCode > localModuleInfo.versionCode &&
!PropUtils.isNullString(localModuleInfo.updateVersion)) {
moduleUpdateCount++;
} else if (repoModule != null &&
repoModule.moduleInfo.versionCode > localModuleInfo.versionCode &&
!PropUtils.isNullString(repoModule.moduleInfo.version)) {
moduleUpdateCount++;
ModuleManager.getINSTANCE().runAfterScan(() -> {
int moduleUpdateCount = 0;
HashMap<String, RepoModule> repoModules =
RepoManager.getINSTANCE().getModules();
for (LocalModuleInfo localModuleInfo :
ModuleManager.getINSTANCE().getModules().values()) {
if ("twrp-keep".equals(localModuleInfo.id)) continue;
RepoModule repoModule = repoModules.get(localModuleInfo.id);
localModuleInfo.checkModuleUpdate();
if (localModuleInfo.updateVersionCode > localModuleInfo.versionCode &&
!PropUtils.isNullString(localModuleInfo.updateVersion)) {
moduleUpdateCount++;
} else if (repoModule != null &&
repoModule.moduleInfo.versionCode > localModuleInfo.versionCode &&
!PropUtils.isNullString(repoModule.moduleInfo.version)) {
moduleUpdateCount++;
}
}
}
if (moduleUpdateCount != 0) {
postNotification(context, moduleUpdateCount);
}
if (moduleUpdateCount != 0) {
postNotification(context, moduleUpdateCount);
}
});
}
public static void postNotification(Context context, int updateCount) {

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

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

Loading…
Cancel
Save