]> git.zerfleddert.de Git - ms2-fixes/commitdiff
start service while booting to prevent module-loading getting killed
authorMichael Gernoth <michael@gernoth.net>
Mon, 29 Oct 2012 14:06:46 +0000 (15:06 +0100)
committerMichael Gernoth <michael@gernoth.net>
Mon, 29 Oct 2012 14:06:46 +0000 (15:06 +0100)
MS2Debounce/AndroidManifest.xml
MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootReceiver.java
MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootService.java [new file with mode: 0644]

index f54f16394c2da00ce97c6ba89b03b5c91ff6b745..fc249dc5c1041feb3d78efa5408a2b0673c799bd 100644 (file)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="de.rmdir.ms2debounce"
-      android:versionCode="7"
-      android:versionName="1.7">
+      android:versionCode="8"
+      android:versionName="1.8">
     <uses-sdk android:minSdkVersion="8" />
     <uses-configuration android:reqKeyboardType="qwerty" />
     <supports-screens android:smallScreens="false"
@@ -23,5 +23,9 @@
                        <category android:name="android.intent.category.HOME" />
                </intent-filter>
        </receiver>
+       <service
+               android:name=".DebounceBootService"
+               android.label="DebounceBootService">
+       </service>
     </application>
 </manifest> 
index 14e76a9cf2758480628ec89e8b4724db2e9dbf14..a4930709892adeec110b43060a93f5e40528578d 100644 (file)
@@ -11,9 +11,7 @@ public class DebounceBootReceiver extends BroadcastReceiver{
                        DebounceModuleHelper module = new DebounceModuleHelper(context);
 
                        if (module.get_on_boot() && module.is_safe_to_load()) {
-                               try {
-                                       module.loadModule();
-                               } catch (Exception e) {}
+                               context.startService(new Intent(context, DebounceBootService.class));
                        }
                }
        }
diff --git a/MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootService.java b/MS2Debounce/src/de/rmdir/ms2debounce/DebounceBootService.java
new file mode 100644 (file)
index 0000000..78e4274
--- /dev/null
@@ -0,0 +1,56 @@
+package de.rmdir.ms2debounce;
+
+import android.app.Service;
+import android.content.Intent;
+import android.content.Context;
+import android.os.IBinder;
+import android.os.AsyncTask;
+import android.util.Log;
+
+public class DebounceBootService extends Service
+{
+       private static final String TAG = "DebounceBootService";
+
+       public IBinder onBind(Intent intent)
+       {
+               return null;
+       }
+
+       @Override
+       public void onCreate() 
+       {
+               Log.i(TAG, "Starting AsyncTask");
+               new AsyncTask<DebounceBootService, Void, Void>() {
+                       @Override
+                       protected Void doInBackground(DebounceBootService... svc) {
+                               Context context = getApplicationContext();
+                               DebounceModuleHelper module = new DebounceModuleHelper(context);
+
+                               Log.i(TAG, "Loading Module");
+
+                               try {
+                                       module.loadModule();
+                               } catch (Exception e) {
+                                       Log.e(TAG, "Got Exception: " + e.getMessage() + " (" + e.getCause() + ")");
+                               }
+
+                               svc[0].stopSelf();
+
+                               return null;
+                       }
+               }.execute(this);
+       }
+
+       @Override
+       public int onStartCommand(Intent intent, int flags, int startId) 
+       {
+               Log.i(TAG, "Creating STICKY service");
+               return START_STICKY;
+       }
+
+       @Override
+       public void onDestroy() 
+       {
+               Log.i(TAG, "Destroying service");
+       }
+}
Impressum, Datenschutz