1 package de
.rmdir
.ms2debounce
;
3 import java
.io
.InputStream
;
4 import java
.io
.OutputStream
;
6 import java
.io
.FileReader
;
7 import java
.io
.BufferedReader
;
9 import android
.content
.Context
;
11 public class DebounceModuleHelper
15 public DebounceModuleHelper(Context context
) {
19 public void loadModule() {
23 public void loadModule(int delay
) {
24 File debounce_ko
= new File(ctx
.getFilesDir() + "/debounce.ko");
28 // FIXME: Read settings from database...
31 Process insmod
= Runtime
.getRuntime().exec(new String
[]{"su","-c","/system/bin/insmod " + debounce_ko
+ " debounce_delay=" + delay
});
33 } catch (Exception e
) {}
36 public void unloadModule() {
38 Process rmmod
= Runtime
.getRuntime().exec(new String
[]{"su","-c","/system/bin/rmmod debounce"});
40 } catch (Exception e
) {}
43 public boolean isLoaded() {
44 boolean loaded
= false;
48 FileReader modules
= new FileReader("/proc/modules");
49 BufferedReader modules_buf
= new BufferedReader(modules
);
51 while((read
= modules_buf
.readLine()) != null) {
52 if (read
.regionMatches(0, "debounce", 0, 8)) {
57 } catch (Exception e
) {
64 public int getDelay() {
65 int debounce_delay
= -1;
70 FileReader delay
= new FileReader("/sys/module/debounce/parameters/debounce_delay");
71 BufferedReader delay_buf
= new BufferedReader(delay
);
73 read
= delay_buf
.readLine();
75 debounce_delay
= Integer
.parseInt(read
.trim());
77 } catch (Exception e
) {}
79 return debounce_delay
;
82 private synchronized void extractModule() {
83 File debounce_ko
= new File(ctx
.getFilesDir() + "/debounce.ko");
85 if (debounce_ko
.exists()) {
90 InputStream apk
= ctx
.getAssets().open("debounce.ko");
91 OutputStream mod
= ctx
.openFileOutput("debounce.ko.tmp", 0);
93 //I assume a page is 4k...
94 byte buf
[] = new byte[4096];
97 while((bytes
= apk
.read(buf
)) != -1) {
98 mod
.write(buf
, 0, bytes
);
104 File tmpfile
= new File(debounce_ko
+ ".tmp");
105 tmpfile
.renameTo(debounce_ko
);
106 } catch (Exception e
) {}