Use Magisk folder to detect active modules. (No longer use boot listener)

pull/177/head
Fox2Code 2 years ago
parent 0e69f80162
commit 7356d7cf0d

@ -11,8 +11,6 @@
<uses-permission android:name="android.permission.INTERNET" />
<!-- WebView offline webpage support -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Make sure of the module active state by checking enabled modules on boot -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- Open config apps for applications -->
<uses-permission-sdk-23 android:name="android.permission.QUERY_ALL_PACKAGES" />
<!-- Supposed to fix bugs with old firmware, only requested on pre Marshmallow -->
@ -34,12 +32,6 @@
android:usesCleartextTraffic="false"
tools:targetApi="s"
tools:replace="android:supportsRtl">
<receiver android:name="com.fox2code.mmm.manager.ModuleBootReceive"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity
android:name=".settings.SettingsActivity"
android:parentActivityName=".MainActivity"

@ -150,17 +150,6 @@ public class MainApplication extends CompatApplication {
return firstBoot;
}
public static void notifyBootListenerCompleted() {
if (MainApplication.bootSharedPreferences != null) {
MainApplication.bootSharedPreferences.edit()
.putBoolean("first_boot", false).apply();
} else if (MainApplication.INSTANCE != null) {
MainApplication.getSharedPreferences().edit()
.putBoolean("first_boot", false).apply();
}
firstBoot = false;
}
public static boolean hasGottenRootAccess() {
return getSharedPreferences().getBoolean("has_root_access", false);
}

@ -42,6 +42,11 @@ public class InstallerInitializer extends Shell.Initializer {
InstallerInitializer.MAGISK_PATH + "/.magisk/mirror";
}
public static String peekModulesPath() {
return InstallerInitializer.MAGISK_PATH == null ? null :
InstallerInitializer.MAGISK_PATH + "/.magisk/modules";
}
public static int peekMagiskVersion() {
return InstallerInitializer.MAGISK_VERSION_CODE;
}

@ -1,32 +0,0 @@
package com.fox2code.mmm.manager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.installer.InstallerInitializer;
public class ModuleBootReceive extends BroadcastReceiver {
private static final String BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null || !BOOT_COMPLETED.equals(intent.getAction())
|| !MainApplication.hasGottenRootAccess()) {
return;
}
InstallerInitializer.tryGetMagiskPathAsync(new InstallerInitializer.Callback() {
@Override
public void onPathReceived(String path) {
MainApplication.notifyBootListenerCompleted();
ModuleManager.getINSTANCE().scan();
}
@Override
public void onFailure(int error) {
MainApplication.setHasGottenRootAccess(false);
}
});
}
}

@ -4,6 +4,7 @@ import android.content.SharedPreferences;
import android.util.Log;
import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.installer.InstallerInitializer;
import com.fox2code.mmm.utils.PropUtils;
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.io.SuFile;
@ -43,7 +44,7 @@ public final class ModuleManager {
}
// MultiThread friendly method
public final void scan() {
public void scan() {
if (!this.scanning) {
// Do scan
synchronized (scanLock) {
@ -61,11 +62,11 @@ public final class ModuleManager {
}
// Pause execution until the scan is completed if one is currently running
public final void afterScan() {
public void afterScan() {
if (this.scanning) synchronized (this.scanLock) {}
}
public final void runAfterScan(Runnable runnable) {
public void runAfterScan(Runnable runnable) {
synchronized (this.scanLock) {
runnable.run();
}
@ -86,7 +87,13 @@ public final class ModuleManager {
v.support = null;
v.config = null;
}
String modulesPath = InstallerInitializer.peekModulesPath();
String[] modules = new SuFile("/data/adb/modules").list();
boolean needFallback = modulesPath == null ||
!new SuFile(modulesPath).exists();
if (needFallback) {
Log.e(TAG, "Failed to detect modules folder, using fallback instead.");
}
if (modules != null) {
for (String module : modules) {
if (!new SuFile("/data/adb/modules/" + module).isDirectory())
@ -99,28 +106,22 @@ public final class ModuleManager {
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_UPDATING_ONLY;
}
moduleInfo.flags &= ~FLAGS_RESET_UPDATE;
boolean disabled = new SuFile(
"/data/adb/modules/" + module + "/disable").exists();
if (disabled) {
if (new SuFile("/data/adb/modules/" + module + "/disable").exists()) {
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_DISABLED;
if (firstBoot && firstScan) {
editor.putBoolean("module_" + moduleInfo.id + "_active", true);
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_MAYBE_ACTIVE;
}
} else {
} else if (needFallback && firstScan) {
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_ACTIVE;
editor.putBoolean("module_" + moduleInfo.id + "_active", true);
}
if (new SuFile("/data/adb/modules/" + module + "/remove").exists()) {
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_UNINSTALLING;
}
if ((!needFallback && new SuFile(modulesPath + module).exists()) || (!firstBoot
&& bootPrefs.getBoolean("module_" + moduleInfo.id + "_active", false))) {
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_ACTIVE;
if (firstScan) {
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_ACTIVE;
editor.putBoolean("module_" + moduleInfo.id + "_active", true);
} else if (!moduleInfo.hasFlag(ModuleInfo.FLAG_MODULE_MAYBE_ACTIVE) &&
bootPrefs.getBoolean("module_" + moduleInfo.id + "_active", false)) {
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_ACTIVE;
}
}
boolean uninstalling = new SuFile(
"/data/adb/modules/" + module + "/remove").exists();
if (uninstalling) {
moduleInfo.flags |= ModuleInfo.FLAG_MODULE_UNINSTALLING;
}
try {
PropUtils.readProperties(moduleInfo,
"/data/adb/modules/" + module + "/module.prop", true);

Loading…
Cancel
Save