]> git.zerfleddert.de Git - ms2-fixes/commitdiff
extract module from apk and load it from its filepath
authorMichael Gernoth <michael@gernoth.net>
Fri, 20 May 2011 21:44:25 +0000 (23:44 +0200)
committerMichael Gernoth <michael@gernoth.net>
Fri, 20 May 2011 21:44:25 +0000 (23:44 +0200)
MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java

index 2f9804cda64cdd463a55a1259dc21a7d106140f9..7a9f3de200d4df1fe87f7744177487228699927b 100644 (file)
@@ -15,14 +15,29 @@ 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;
        }
@@ -36,10 +51,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) {}
        }
 }
Impressum, Datenschutz