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();
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;
return loaded;
}
- public int getDelay() {
+ public synchronized int getDelay() {
int debounce_delay = -1;
try {
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");