]> git.zerfleddert.de Git - ms2-fixes/blob - MS2Debounce/src/de/rmdir/ms2debounce/DebounceModuleHelper.java
7a9f3de200d4df1fe87f7744177487228699927b
[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
7 import android.content.Context;
8
9 public class DebounceModuleHelper
10 {
11 private Context ctx;
12
13 public DebounceModuleHelper(Context context) {
14 ctx = context;
15 }
16
17 public void loadModule() {
18 loadModule(10);
19 }
20
21 public void loadModule(int delay) {
22 File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
23
24 extractModule();
25
26 // FIXME: Read settings from database...
27
28 try {
29 Process insmod = Runtime.getRuntime().exec(new String[]{"su","-c","/system/bin/insmod " + debounce_ko + " debounce_delay=" + delay});
30 insmod.waitFor();
31 } catch (Exception e) {}
32 }
33
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
41 public boolean isLoaded() {
42 return false;
43 }
44
45 private synchronized void extractModule() {
46 File debounce_ko = new File(ctx.getFilesDir() + "/debounce.ko");
47
48 if (debounce_ko.exists()) {
49 return;
50 }
51
52 try {
53 InputStream apk = ctx.getAssets().open("debounce.ko");
54 OutputStream mod = ctx.openFileOutput("debounce.ko.tmp", 0);
55
56 //I assume a page is 4k...
57 byte buf[] = new byte[4096];
58 int bytes;
59
60 while((bytes = apk.read(buf)) != -1) {
61 mod.write(buf, 0, bytes);
62 }
63
64 apk.close();
65 mod.close();
66
67 File tmpfile = new File(debounce_ko + ".tmp");
68 tmpfile.renameTo(debounce_ko);
69 } catch (Exception e) {}
70 }
71 }
Impressum, Datenschutz