]> git.zerfleddert.de Git - ms2-fixes/blob - MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java
229f00ae72a568a3e5be878b44a4e27d84f45ce6
[ms2-fixes] / MS2Debounce / src / de / rmdir / ms2debounce / DebounceModuleHelper.java
1 package de.rmdir.ms2debounce;
2
3 import java.io.InputStream;
4 import java.io.OutputStream;
5 import java.io.File;
6 import java.io.FileReader;
7 import java.io.BufferedReader;
8
9 import android.content.Context;
10
11 public class DebounceModuleHelper
12 {
13 private Context ctx;
14
15 public DebounceModuleHelper(Context context) {
16 ctx = context;
17 }
18
19 public void loadModule() {
20 loadModule(10);
21 }
22
23 public void loadModule(int delay) {
24 File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
25
26 extractModule();
27
28 // FIXME: Read settings from database...
29
30 try {
31 Process insmod = Runtime.getRuntime().exec(new String[]{"su","-c","/system/bin/insmod " + debounce_ko + " debounce_delay=" + delay});
32 insmod.waitFor();
33 } catch (Exception e) {}
34 }
35
36 public void unloadModule() {
37 try {
38 Process rmmod = Runtime.getRuntime().exec(new String[]{"su","-c","/system/bin/rmmod debounce"});
39 rmmod.waitFor();
40 } catch (Exception e) {}
41 }
42
43 public boolean isLoaded() {
44 boolean loaded = false;
45 try {
46 String read;
47
48 FileReader modules = new FileReader("/proc/modules");
49 BufferedReader modules_buf = new BufferedReader(modules);
50
51 while((read = modules_buf.readLine()) != null) {
52 if (read.regionMatches(0, "debounce", 0, 8)) {
53 loaded = true;
54 }
55 }
56
57 } catch (Exception e) {
58 loaded = false;
59 }
60
61 return loaded;
62 }
63
64 public int getDelay() {
65 int debounce_delay = -1;
66
67 try {
68 String read;
69
70 FileReader delay = new FileReader("/sys/module/debounce/parameters/debounce_delay");
71 BufferedReader delay_buf = new BufferedReader(delay);
72
73 read = delay_buf.readLine();
74 if (read != null) {
75 debounce_delay = Integer.parseInt(read.trim());
76 }
77 } catch (Exception e) {}
78
79 return debounce_delay;
80 }
81
82 private synchronized void extractModule() {
83 File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
84
85 if (debounce_ko.exists()) {
86 return;
87 }
88
89 try {
90 InputStream apk = ctx.getAssets().open("debounce.ko");
91 OutputStream mod = ctx.openFileOutput("debounce.ko.tmp", 0);
92
93 //I assume a page is 4k...
94 byte buf[] = new byte[4096];
95 int bytes;
96
97 while((bytes = apk.read(buf)) != -1) {
98 mod.write(buf, 0, bytes);
99 }
100
101 apk.close();
102 mod.close();
103
104 File tmpfile = new File(debounce_ko + ".tmp");
105 tmpfile.renameTo(debounce_ko);
106 } catch (Exception e) {}
107 }
108 }
Impressum, Datenschutz