X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/ms2-fixes/blobdiff_plain/5738a32fed2d7c93bfbcfcb8e1ccdffdc5dceb6a..ee6322a1851220fd0855348d07cca15e826c6a5e:/MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java diff --git a/MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java b/MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java index 2f9804c..e4ad296 100644 --- a/MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java +++ b/MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java @@ -15,18 +15,37 @@ public class DebounceModuleHelper } public void loadModule() { + loadModule(10); + } + + public void loadModule(int delay) { + File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko"); + extractModule(); + // FIXME: Read settings from database... + try { - Process insmod = Runtime.getRuntime().exec(new String[]{"su","-c","/system/bin/insmod /system/lib/modules/debounce.ko"}); + Process insmod = Runtime.getRuntime().exec(new String[]{"su","-c","/system/bin/insmod " + debounce_ko + " debounce_delay=" + delay}); insmod.waitFor(); } catch (Exception e) {} } + public void unloadModule() { + try { + Process rmmod = Runtime.getRuntime().exec(new String[]{"su","-c","/system/bin/rmmod debounce"}); + rmmod.waitFor(); + } catch (Exception e) {} + } + public boolean isLoaded() { return false; } + public int getDelay() { + return 10; + } + private synchronized void extractModule() { File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko"); @@ -36,10 +55,21 @@ public class DebounceModuleHelper try { InputStream apk = ctx.getAssets().open("debounce.ko"); - OutputStream mod = ctx.openFileOutput("debounce.ko", 0); + OutputStream mod = ctx.openFileOutput("debounce.ko.tmp", 0); + + //I assume a page is 4k... + byte buf[] = new byte[4096]; + int bytes; + + while((bytes = apk.read(buf)) != -1) { + mod.write(buf, 0, bytes); + } apk.close(); mod.close(); + + File tmpfile = new File(debounce_ko + ".tmp"); + tmpfile.renameTo(debounce_ko); } catch (Exception e) {} } }