]> cvs.zerfleddert.de Git - ms2-fixes/commitdiff
Check if it is safe to load the module on boot
authorMichael Gernoth <michael@gernoth.net>
Fri, 20 May 2011 22:37:55 +0000 (00:37 +0200)
committerMichael Gernoth <michael@gernoth.net>
Fri, 20 May 2011 22:37:55 +0000 (00:37 +0200)
MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootReceiver.java
MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java
MS2Debounce/src/de/rmdir/ms2debounce/MS2Debounce.java

index 2a15ea4271a8a0a53be2447b0fc604e9eaec49a8..cc072b066ead977ac2c567b24eb582c13d9eb54f 100644 (file)
@@ -10,7 +10,9 @@ public class DebounceBootReceiver extends BroadcastReceiver{
                if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
                        DebounceModuleHelper module = new DebounceModuleHelper(context);
 
-                       module.loadModule();
+                       if (module.is_safe_to_load()) {
+                               module.loadModule();
+                       }
                }
        }
 }
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");
 
index 654cf5ac988983ffe6a8bda607ac9195fdab2da8..4f8e703cd6620b309af1e86607f410a10a4e726c 100644 (file)
@@ -21,6 +21,6 @@ public class MS2Debounce extends Activity
                setContentView(R.layout.main);
 
                TextView text = (TextView)findViewById(R.id.text);
-               text.setText("You will soon be able to set the debounce_delay here.\nModule loaded: " + module.isLoaded() + "\ndebounce_delay: " + module.getDelay() + "ms");
+               text.setText("You will soon be able to set the debounce_delay here.\nModule loaded: " + module.isLoaded() + "\ndebounce_delay: " + module.getDelay() + "ms\nsafe_to_load: " + module.is_safe_to_load());
        }
 }
Impressum, Datenschutz