]>
cvs.zerfleddert.de Git - ms2-fixes/blob - MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java
7a9f3de200d4df1fe87f7744177487228699927b
1 package de
.rmdir
.ms2debounce
;
3 import java
.io
.InputStream
;
4 import java
.io
.OutputStream
;
7 import android
.content
.Context
;
9 public class DebounceModuleHelper
13 public DebounceModuleHelper(Context context
) {
17 public void loadModule() {
21 public void loadModule(int delay
) {
22 File debounce_ko
= new File(ctx
.getFilesDir() + "/debounce.ko");
26 // FIXME: Read settings from database...
29 Process insmod
= Runtime
.getRuntime().exec(new String
[]{"su","-c","/system/bin/insmod " + debounce_ko
+ " debounce_delay=" + delay
});
31 } catch (Exception e
) {}
34 public void unloadModule() {
36 Process rmmod
= Runtime
.getRuntime().exec(new String
[]{"su","-c","/system/bin/rmmod debounce"});
38 } catch (Exception e
) {}
41 public boolean isLoaded() {
45 private synchronized void extractModule() {
46 File debounce_ko
= new File(ctx
.getFilesDir() + "/debounce.ko");
48 if (debounce_ko
.exists()) {
53 InputStream apk
= ctx
.getAssets().open("debounce.ko");
54 OutputStream mod
= ctx
.openFileOutput("debounce.ko.tmp", 0);
56 //I assume a page is 4k...
57 byte buf
[] = new byte[4096];
60 while((bytes
= apk
.read(buf
)) != -1) {
61 mod
.write(buf
, 0, bytes
);
67 File tmpfile
= new File(debounce_ko
+ ".tmp");
68 tmpfile
.renameTo(debounce_ko
);
69 } catch (Exception e
) {}