]> cvs.zerfleddert.de Git - ms2-fixes/blobdiff - MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java
wait for module to be loaded before trying to set parameters
[ms2-fixes] / MS2Debounce / src / de / rmdir / ms2debounce / DebounceModuleHelper.java
index 2ee55014884806f3637cc82527a6d0415015cd5d..b01b2b52930fe67dc20e25f8738cbb210bea0de0 100644 (file)
@@ -69,9 +69,20 @@ public class DebounceModuleHelper
        }
 
        public synchronized boolean _loadModule() throws NotRootedException,ShellException {
-               File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
+               File insmod = new File("/system/bin/insmod");
+               if (!insmod.exists()) {
+                       insmod = new File("/system/xbin/insmod");
+                       if (!insmod.exists()) {
+                               return false;
+                       }
+               }
 
-               extractModule();
+               File debounce_ko = new File("/system/lib/modules/debounce.ko");
+               if (!debounce_ko.exists()) {
+                       debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
+
+                       extractModule();
+               }
 
                SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = settings.edit();
@@ -80,7 +91,17 @@ public class DebounceModuleHelper
                        editor.commit();
                }
 
-               runAsRoot("/system/bin/insmod " + debounce_ko + " || /system/xbin/insmod " + debounce_ko);
+               runAsRoot(insmod + " " + debounce_ko);
+
+               int cnt = 10;
+               while ((!isLoaded()) && (cnt > 0)) {
+                       try {
+                               Thread.sleep(100);
+                       } catch (Exception e) {
+                               return false;
+                       }
+                       cnt--;
+               }
 
                if (!isLoaded()) {
                        return false;
@@ -98,11 +119,21 @@ public class DebounceModuleHelper
        }
 
        public synchronized void unloadModule() throws NotRootedException,ShellException {
-               runAsRoot("/system/bin/rmmod debounce || /system/xbin/rmmod debounce");
+               File rmmod = new File("/system/bin/rmmod");
+
+               if (!rmmod.exists()) {
+                       rmmod = new File("/system/xbin/rmmod");
+                       if (!rmmod.exists()) {
+                               return;
+                       }
+               }
+
+               runAsRoot(rmmod + " debounce");
        }
 
        public synchronized boolean isLoaded() {
                boolean loaded = false;
+
                try {
                        String read;
 
@@ -111,10 +142,13 @@ public class DebounceModuleHelper
 
                        while((read = modules_buf.readLine()) != null) {
                                if (read.regionMatches(0, "debounce", 0, 8)) {
-                                       loaded = true;
+                                       File sysdir = new File("/sys/devices/debounce");
+                                       if (sysdir.exists() && sysdir.isDirectory()) {
+                                               loaded = true;
+                                               break;
+                                       }
                                }
                        }
-
                } catch (Exception e) {
                        loaded = false;
                }
Impressum, Datenschutz