]> git.zerfleddert.de Git - ms2-fixes/blobdiff - MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java
use module included in ROM (when available)
[ms2-fixes] / MS2Debounce / src / de / rmdir / ms2debounce / DebounceModuleHelper.java
index 6234eae8e604cc138395db916c68c82452dac4b1..fbcc8374aad6c3532db6fbbacfe9cdf5cb219e12 100644 (file)
@@ -32,26 +32,57 @@ public class DebounceModuleHelper
                setActiveHigh(getSavedActiveHigh());
        }
 
-       public void loadModule() {
-               _loadModule();
+       public boolean loadModule() throws NotRootedException,ShellException {
+               if (!_loadModule())
+                       return false;
+
                setAllValues();
+
+               return true;
        }
 
-       protected void runAsRoot(String command) throws java.io.IOException,java.lang.InterruptedException {
-               Process rootcmd = Runtime.getRuntime().exec(new String[]{"su","-c","sh"});
-               DataOutputStream sh = new DataOutputStream(rootcmd.getOutputStream());
-               sh.writeBytes(command + "\n");
-               sh.writeBytes("exit\n");
-               sh.flush();
-               sh.close();
+       protected void runAsRoot(String command) throws NotRootedException,ShellException {
+               Process rootcmd;
+
+               try {
+                       rootcmd = Runtime.getRuntime().exec(new String[]{"su","-c","sh"});
+               } catch (java.io.IOException e) {
+                       throw new NotRootedException();
+               }
+
+               try {
+                       DataOutputStream sh = new DataOutputStream(rootcmd.getOutputStream());
+                       sh.writeBytes(command + "\n");
+                       sh.writeBytes("exit\n");
+                       sh.flush();
+                       sh.close();
+               } catch (java.io.IOException e) {
+                       throw new ShellException();
+               }
 
-               rootcmd.waitFor();
+               try {
+                       if (rootcmd.waitFor() != 0)
+                               throw new ShellException();
+               } catch (java.lang.InterruptedException e) {
+                       throw new ShellException();
+               }
        }
 
-       public synchronized void _loadModule() {
-               File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
+       public synchronized boolean _loadModule() throws NotRootedException,ShellException {
+               File insmod = new File("/system/bin/insmod");
+               if (!insmod.exists()) {
+                       insmod = new File("/system/xbin/insmod");
+                       if (!insmod.exists()) {
+                               return false;
+                       }
+               }
+
+               File debounce_ko = new File("/system/lib/modules/debounce.ko");
+               if (!debounce_ko.exists()) {
+                       debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
 
-               extractModule();
+                       extractModule();
+               }
 
                SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = settings.edit();
@@ -60,29 +91,34 @@ public class DebounceModuleHelper
                        editor.commit();
                }
 
-               try {
-                       runAsRoot("/system/bin/insmod " + debounce_ko);
-               } catch (Exception e) {
-                       return;
-               }
+               runAsRoot(insmod + " " + debounce_ko);
 
                if (!isLoaded()) {
-                       return;
+                       return false;
                }
 
                if (getDelay() < 0) {
-                       return;
+                       return false;
                }
 
                /* Module was obviously loaded, so it is safe to load on boot */
                editor.putBoolean("safe_to_load", true);
                editor.commit();
+
+               return true;
        }
 
-       public synchronized void unloadModule() {
-               try {
-                       runAsRoot("/system/bin/rmmod debounce");
-               } catch (Exception e) {}
+       public synchronized void unloadModule() throws NotRootedException,ShellException {
+               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() {
Impressum, Datenschutz