]> git.zerfleddert.de Git - ms2-fixes/blobdiff - MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java
make textview more dynamic
[ms2-fixes] / MS2Debounce / src / de / rmdir / ms2debounce / DebounceModuleHelper.java
index fe9ffa80d06a972c7a5548ec4bbb81a48ce1c96f..e4ad296e2e47c5b2cad17967de860a2906061073 100644 (file)
@@ -1,33 +1,75 @@
 package de.rmdir.ms2debounce;
 
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.File;
 
+import android.content.Context;
+
 public class DebounceModuleHelper
 {
-       private File filesdir;
+       private Context ctx;
 
-       public DebounceModuleHelper(File appdir) {
-               filesdir = appdir;
+       public DebounceModuleHelper(Context context) {
+               ctx = context;
        }
 
        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;
        }
 
-       private void extractModule() {
-               File debounce_ko = new File(filesdir + "/debounce.ko");
+       public int getDelay() {
+               return 10;
+       }
+
+       private synchronized void extractModule() {
+               File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
 
                if (debounce_ko.exists()) {
                        return;
                }
+
+               try {
+                       InputStream apk = ctx.getAssets().open("debounce.ko");
+                       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) {}
        }
 }
Impressum, Datenschutz