]> cvs.zerfleddert.de Git - ms2-fixes/blobdiff - MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java
add gitignore
[ms2-fixes] / MS2Debounce / src / de / rmdir / ms2debounce / DebounceModuleHelper.java
index 229f00ae72a568a3e5be878b44a4e27d84f45ce6..93fd221a54fe3aa85961cfd60823b58d12cfc679 100644 (file)
@@ -7,20 +7,25 @@ import java.io.FileReader;
 import java.io.BufferedReader;
 
 import android.content.Context;
+import android.content.SharedPreferences;
 
 public class DebounceModuleHelper
 {
        private Context ctx;
+       public static final String PREFS_NAME = "DebounceCfg";
 
        public DebounceModuleHelper(Context context) {
                ctx = context;
        }
 
        public void loadModule() {
-               loadModule(10);
+               SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
+
+               int delay = settings.getInt("debounce_delay", 10);
+               loadModule(delay);
        }
 
-       public void loadModule(int delay) {
+       public synchronized void loadModule(int delay) {
                File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
 
                extractModule();
@@ -30,17 +35,31 @@ public class DebounceModuleHelper
                try {
                        Process insmod = Runtime.getRuntime().exec(new String[]{"su","-c","/system/bin/insmod " + debounce_ko + " debounce_delay=" + delay});
                        insmod.waitFor();
-               } catch (Exception e) {}
+               } catch (Exception e) {
+                       return;
+               }
+       
+               if (getDelay() <= 0) {
+                       return;
+               }
+
+               /* Module was obviously loaded, so it is safe to load on boot */
+               if (!is_safe_to_load()) {
+                       SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
+                       SharedPreferences.Editor editor = settings.edit();
+                       editor.putBoolean("safe_to_load", true);
+                       editor.commit();
+               }
        }
 
-       public void unloadModule() {
+       public synchronized void unloadModule() {
                try {
                        Process rmmod = Runtime.getRuntime().exec(new String[]{"su","-c","/system/bin/rmmod debounce"});
                        rmmod.waitFor();
                } catch (Exception e) {}
        }
 
-       public boolean isLoaded() {
+       public synchronized boolean isLoaded() {
                boolean loaded = false;
                try {
                        String read;
@@ -61,7 +80,7 @@ public class DebounceModuleHelper
                return loaded;
        }
 
-       public int getDelay() {
+       public synchronized int getDelay() {
                int debounce_delay = -1;
 
                try {
@@ -79,6 +98,13 @@ public class DebounceModuleHelper
                return debounce_delay;
        }
 
+       public synchronized boolean is_safe_to_load() {
+               SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
+               boolean safe_to_load = settings.getBoolean("safe_to_load", false);
+
+               return safe_to_load;
+       }
+
        private synchronized void extractModule() {
                File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
 
Impressum, Datenschutz