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

Commit 7356d7c

Browse files
committed
Use Magisk folder to detect active modules. (No longer use boot listener)
1 parent 0e69f80 commit 7356d7c

File tree

5 files changed

+26
-71
lines changed

5 files changed

+26
-71
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
<uses-permission android:name="android.permission.INTERNET" />
1212
<!-- WebView offline webpage support -->
1313
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
14-
<!-- Make sure of the module active state by checking enabled modules on boot -->
15-
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
1614
<!-- Open config apps for applications -->
1715
<uses-permission-sdk-23 android:name="android.permission.QUERY_ALL_PACKAGES" />
1816
<!-- Supposed to fix bugs with old firmware, only requested on pre Marshmallow -->
@@ -34,12 +32,6 @@
3432
android:usesCleartextTraffic="false"
3533
tools:targetApi="s"
3634
tools:replace="android:supportsRtl">
37-
<receiver android:name="com.fox2code.mmm.manager.ModuleBootReceive"
38-
android:exported="true">
39-
<intent-filter>
40-
<action android:name="android.intent.action.BOOT_COMPLETED" />
41-
</intent-filter>
42-
</receiver>
4335
<activity
4436
android:name=".settings.SettingsActivity"
4537
android:parentActivityName=".MainActivity"

app/src/main/java/com/fox2code/mmm/MainApplication.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,6 @@ public static boolean isFirstBoot() {
150150
return firstBoot;
151151
}
152152

153-
public static void notifyBootListenerCompleted() {
154-
if (MainApplication.bootSharedPreferences != null) {
155-
MainApplication.bootSharedPreferences.edit()
156-
.putBoolean("first_boot", false).apply();
157-
} else if (MainApplication.INSTANCE != null) {
158-
MainApplication.getSharedPreferences().edit()
159-
.putBoolean("first_boot", false).apply();
160-
}
161-
firstBoot = false;
162-
}
163-
164153
public static boolean hasGottenRootAccess() {
165154
return getSharedPreferences().getBoolean("has_root_access", false);
166155
}

app/src/main/java/com/fox2code/mmm/installer/InstallerInitializer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public static String peekMirrorPath() {
4242
InstallerInitializer.MAGISK_PATH + "/.magisk/mirror";
4343
}
4444

45+
public static String peekModulesPath() {
46+
return InstallerInitializer.MAGISK_PATH == null ? null :
47+
InstallerInitializer.MAGISK_PATH + "/.magisk/modules";
48+
}
49+
4550
public static int peekMagiskVersion() {
4651
return InstallerInitializer.MAGISK_VERSION_CODE;
4752
}

app/src/main/java/com/fox2code/mmm/manager/ModuleBootReceive.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

app/src/main/java/com/fox2code/mmm/manager/ModuleManager.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.util.Log;
55

66
import com.fox2code.mmm.MainApplication;
7+
import com.fox2code.mmm.installer.InstallerInitializer;
78
import com.fox2code.mmm.utils.PropUtils;
89
import com.topjohnwu.superuser.Shell;
910
import com.topjohnwu.superuser.io.SuFile;
@@ -43,7 +44,7 @@ private ModuleManager() {
4344
}
4445

4546
// MultiThread friendly method
46-
public final void scan() {
47+
public void scan() {
4748
if (!this.scanning) {
4849
// Do scan
4950
synchronized (scanLock) {
@@ -61,11 +62,11 @@ public final void scan() {
6162
}
6263

6364
// Pause execution until the scan is completed if one is currently running
64-
public final void afterScan() {
65+
public void afterScan() {
6566
if (this.scanning) synchronized (this.scanLock) {}
6667
}
6768

68-
public final void runAfterScan(Runnable runnable) {
69+
public void runAfterScan(Runnable runnable) {
6970
synchronized (this.scanLock) {
7071
runnable.run();
7172
}
@@ -86,7 +87,13 @@ private void scanInternal() {
8687
v.support = null;
8788
v.config = null;
8889
}
90+
String modulesPath = InstallerInitializer.peekModulesPath();
8991
String[] modules = new SuFile("/data/adb/modules").list();
92+
boolean needFallback = modulesPath == null ||
93+
!new SuFile(modulesPath).exists();
94+
if (needFallback) {
95+
Log.e(TAG, "Failed to detect modules folder, using fallback instead.");
96+
}
9097
if (modules != null) {
9198
for (String module : modules) {
9299
if (!new SuFile("/data/adb/modules/" + module).isDirectory())
@@ -99,28 +106,22 @@ private void scanInternal() {
99106
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_UPDATING_ONLY;
100107
}
101108
moduleInfo.flags &= ~FLAGS_RESET_UPDATE;
102-
boolean disabled = new SuFile(
103-
"/data/adb/modules/" + module + "/disable").exists();
104-
if (disabled) {
109+
if (new SuFile("/data/adb/modules/" + module + "/disable").exists()) {
105110
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_DISABLED;
106-
if (firstBoot && firstScan) {
107-
editor.putBoolean("module_" + moduleInfo.id + "_active", true);
108-
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_MAYBE_ACTIVE;
109-
}
110-
} else {
111+
} else if (needFallback && firstScan) {
112+
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_ACTIVE;
113+
editor.putBoolean("module_" + moduleInfo.id + "_active", true);
114+
}
115+
if (new SuFile("/data/adb/modules/" + module + "/remove").exists()) {
116+
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_UNINSTALLING;
117+
}
118+
if ((!needFallback && new SuFile(modulesPath + module).exists()) || (!firstBoot
119+
&& bootPrefs.getBoolean("module_" + moduleInfo.id + "_active", false))) {
120+
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_ACTIVE;
111121
if (firstScan) {
112-
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_ACTIVE;
113122
editor.putBoolean("module_" + moduleInfo.id + "_active", true);
114-
} else if (!moduleInfo.hasFlag(ModuleInfo.FLAG_MODULE_MAYBE_ACTIVE) &&
115-
bootPrefs.getBoolean("module_" + moduleInfo.id + "_active", false)) {
116-
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_ACTIVE;
117123
}
118124
}
119-
boolean uninstalling = new SuFile(
120-
"/data/adb/modules/" + module + "/remove").exists();
121-
if (uninstalling) {
122-
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_UNINSTALLING;
123-
}
124125
try {
125126
PropUtils.readProperties(moduleInfo,
126127
"/data/adb/modules/" + module + "/module.prop", true);

0 commit comments

Comments
 (0)