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

Commit beb4925

Browse files
committed
Improve application Thread safety.
1 parent c1cad9b commit beb4925

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

app/src/main/java/com/fox2code/mmm/background/BackgroundBootListener.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import android.content.Intent;
66

77
import com.fox2code.mmm.MainApplication;
8-
import com.fox2code.mmm.installer.InstallerInitializer;
9-
import com.fox2code.mmm.manager.ModuleManager;
108

119
public class BackgroundBootListener extends BroadcastReceiver {
1210
private static final String BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
@@ -20,17 +18,5 @@ public void onReceive(Context context, Intent intent) {
2018
BackgroundUpdateChecker.doCheck(context);
2119
}
2220
}
23-
if (ModuleManager.FORCE_NEED_FALLBACK &&
24-
MainApplication.hasGottenRootAccess()) {
25-
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
26-
@Override
27-
public void onPathReceived(String path) {
28-
ModuleManager.getINSTANCE().scan();
29-
}
30-
31-
@Override
32-
public void onFailure(int error) {}
33-
});
34-
}
3521
}
3622
}

app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,30 @@ public Result doWork() {
5454

5555
static void doCheck(Context context) {
5656
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
57+
ModuleManager.getINSTANCE().scanAsync();
5758
RepoManager.getINSTANCE().update(null);
58-
ModuleManager.getINSTANCE().scan();
59-
int moduleUpdateCount = 0;
60-
HashMap<String, RepoModule> repoModules =
61-
RepoManager.getINSTANCE().getModules();
62-
for (LocalModuleInfo localModuleInfo :
63-
ModuleManager.getINSTANCE().getModules().values()) {
64-
if ("twrp-keep".equals(localModuleInfo.id)) continue;
65-
RepoModule repoModule = repoModules.get(localModuleInfo.id);
66-
localModuleInfo.checkModuleUpdate();
67-
if (localModuleInfo.updateVersionCode > localModuleInfo.versionCode &&
68-
!PropUtils.isNullString(localModuleInfo.updateVersion)) {
69-
moduleUpdateCount++;
70-
} else if (repoModule != null &&
71-
repoModule.moduleInfo.versionCode > localModuleInfo.versionCode &&
72-
!PropUtils.isNullString(repoModule.moduleInfo.version)) {
73-
moduleUpdateCount++;
59+
ModuleManager.getINSTANCE().runAfterScan(() -> {
60+
int moduleUpdateCount = 0;
61+
HashMap<String, RepoModule> repoModules =
62+
RepoManager.getINSTANCE().getModules();
63+
for (LocalModuleInfo localModuleInfo :
64+
ModuleManager.getINSTANCE().getModules().values()) {
65+
if ("twrp-keep".equals(localModuleInfo.id)) continue;
66+
RepoModule repoModule = repoModules.get(localModuleInfo.id);
67+
localModuleInfo.checkModuleUpdate();
68+
if (localModuleInfo.updateVersionCode > localModuleInfo.versionCode &&
69+
!PropUtils.isNullString(localModuleInfo.updateVersion)) {
70+
moduleUpdateCount++;
71+
} else if (repoModule != null &&
72+
repoModule.moduleInfo.versionCode > localModuleInfo.versionCode &&
73+
!PropUtils.isNullString(repoModule.moduleInfo.version)) {
74+
moduleUpdateCount++;
75+
}
7476
}
75-
}
76-
if (moduleUpdateCount != 0) {
77-
postNotification(context, moduleUpdateCount);
78-
}
77+
if (moduleUpdateCount != 0) {
78+
postNotification(context, moduleUpdateCount);
79+
}
80+
});
7981
}
8082

8183
public static void postNotification(Context context, int updateCount) {

app/src/main/java/com/fox2code/mmm/module/ModuleViewListBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public void appendRemoteModules() {
114114
public void applyTo(final RecyclerView moduleList,final ModuleViewAdapter moduleViewAdapter) {
115115
if (this.updating) return;
116116
this.updating = true;
117+
ModuleManager.getINSTANCE().afterScan();
118+
RepoManager.getINSTANCE().afterUpdate();
117119
final ArrayList<ModuleHolder> moduleHolders;
118120
final int newNotificationsLen;
119121
final boolean first;

app/src/main/java/com/fox2code/mmm/utils/SyncManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public abstract class SyncManager {
1515
private boolean syncing;
1616
private long lastSync;
1717

18+
public final void scanAsync() {
19+
if (!this.syncing) {
20+
new Thread(this::scan, "Scan Thread").start();
21+
}
22+
}
23+
1824
public final void scan() {
1925
this.update(null);
2026
}

0 commit comments

Comments
 (0)