]> git.zerfleddert.de Git - ms2-fixes/blame - MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java
make textview more dynamic
[ms2-fixes] / MS2Debounce / src / de / rmdir / ms2debounce / DebounceModuleHelper.java
CommitLineData
0ae502f6
MG
1package de.rmdir.ms2debounce;
2
5738a32f
MG
3import java.io.InputStream;
4import java.io.OutputStream;
226a7d4d
MG
5import java.io.File;
6
5738a32f
MG
7import android.content.Context;
8
0ae502f6
MG
9public class DebounceModuleHelper
10{
5738a32f 11 private Context ctx;
226a7d4d 12
5738a32f
MG
13 public DebounceModuleHelper(Context context) {
14 ctx = context;
226a7d4d
MG
15 }
16
17 public void loadModule() {
40697a47
MG
18 loadModule(10);
19 }
20
21 public void loadModule(int delay) {
22 File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
23
226a7d4d
MG
24 extractModule();
25
40697a47
MG
26 // FIXME: Read settings from database...
27
0ae502f6 28 try {
40697a47 29 Process insmod = Runtime.getRuntime().exec(new String[]{"su","-c","/system/bin/insmod " + debounce_ko + " debounce_delay=" + delay});
0ae502f6
MG
30 insmod.waitFor();
31 } catch (Exception e) {}
32 }
33
40697a47
MG
34 public void unloadModule() {
35 try {
36 Process rmmod = Runtime.getRuntime().exec(new String[]{"su","-c","/system/bin/rmmod debounce"});
37 rmmod.waitFor();
38 } catch (Exception e) {}
39 }
40
226a7d4d 41 public boolean isLoaded() {
0ae502f6
MG
42 return false;
43 }
226a7d4d 44
ee6322a1
MG
45 public int getDelay() {
46 return 10;
47 }
48
5738a32f
MG
49 private synchronized void extractModule() {
50 File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
226a7d4d
MG
51
52 if (debounce_ko.exists()) {
53 return;
54 }
5738a32f
MG
55
56 try {
57 InputStream apk = ctx.getAssets().open("debounce.ko");
40697a47
MG
58 OutputStream mod = ctx.openFileOutput("debounce.ko.tmp", 0);
59
60 //I assume a page is 4k...
61 byte buf[] = new byte[4096];
62 int bytes;
63
64 while((bytes = apk.read(buf)) != -1) {
65 mod.write(buf, 0, bytes);
66 }
5738a32f
MG
67
68 apk.close();
69 mod.close();
40697a47
MG
70
71 File tmpfile = new File(debounce_ko + ".tmp");
72 tmpfile.renameTo(debounce_ko);
5738a32f 73 } catch (Exception e) {}
226a7d4d 74 }
0ae502f6 75}
Impressum, Datenschutz