44import android .util .Log ;
55
66import com .fox2code .mmm .MainApplication ;
7+ import com .fox2code .mmm .installer .InstallerInitializer ;
78import com .fox2code .mmm .utils .PropUtils ;
89import com .topjohnwu .superuser .Shell ;
910import 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