From eee21ac252d364b9bbad742eabf007cc54da9ae4 Mon Sep 17 00:00:00 2001 From: Felix Bechstein Date: Mon, 16 Nov 2009 22:57:32 +0100 Subject: [PATCH] fix wrapper for cm 4.2.5 --- src/de/ub0r/android/adBlock/HelperAPI5.java | 14 ----------- src/de/ub0r/android/adBlock/Proxy.java | 36 ++++++++++++++++++----------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/de/ub0r/android/adBlock/HelperAPI5.java b/src/de/ub0r/android/adBlock/HelperAPI5.java index 83ec03a..96e3e53 100644 --- a/src/de/ub0r/android/adBlock/HelperAPI5.java +++ b/src/de/ub0r/android/adBlock/HelperAPI5.java @@ -42,18 +42,4 @@ public class HelperAPI5 { final Notification notification) { service.startForeground(id, notification); } - - /** - * Run Service in background. - * - * @see Service.stopForeground() - * @param service - * Service - * @param removeNotification - * remove notification? - */ - final void stopForeground(final Service service, - final boolean removeNotification) { - service.stopForeground(removeNotification); - } } diff --git a/src/de/ub0r/android/adBlock/Proxy.java b/src/de/ub0r/android/adBlock/Proxy.java index 50e634d..869fe4d 100644 --- a/src/de/ub0r/android/adBlock/Proxy.java +++ b/src/de/ub0r/android/adBlock/Proxy.java @@ -49,6 +49,8 @@ import android.widget.Toast; * @author Felix Bechstein */ public class Proxy extends Service implements Runnable { + /** Tag for output. */ + private static final String TAG = "AdBlock.Proxy"; /** Preferences: Port. */ static final String PREFS_PORT = "port"; @@ -78,9 +80,6 @@ public class Proxy extends Service implements Runnable { /** Stop proxy? */ private boolean stop = false; - /** Tag for output. */ - private static final String TAG = "AdBlock.Proxy"; - /** * Connection handles a single HTTP Connection. Run this as a Thread. * @@ -518,21 +517,32 @@ public class Proxy extends Service implements Runnable { public final void onStart(final Intent intent, final int startId) { super.onStart(intent, startId); - // Don't kill me! - this.setForeground(true); - final Notification notification = new Notification( - R.drawable.stat_notify_proxy, "", System.currentTimeMillis()); - final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, - new Intent(this, AdBlock.class), 0); - notification.setLatestEventInfo(this, this - .getString(R.string.notify_proxy), "", contentIntent); - notification.defaults |= Notification.FLAG_NO_CLEAR; + HelperAPI5 helperAPI5 = null; try { - new HelperAPI5().startForeground(this, 0, notification); + helperAPI5 = new HelperAPI5(); } catch (VerifyError e) { Log.i(TAG, "no api 5"); } + // Don't kill me! + if (helperAPI5 == null) { + this.setForeground(true); + } else { + final Notification notification = new Notification( + R.drawable.stat_notify_proxy, "", System + .currentTimeMillis()); + final PendingIntent contentIntent = PendingIntent.getActivity(this, + 0, new Intent(this, AdBlock.class), 0); + notification.setLatestEventInfo(this, this + .getString(R.string.notify_proxy), "", contentIntent); + notification.defaults |= Notification.FLAG_NO_CLEAR; + try { + helperAPI5.startForeground(this, 0, notification); + } catch (NoSuchMethodError e) { + this.setForeground(true); + } + } + SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(this); int p = Integer.parseInt(preferences.getString(PREFS_PORT, "8080")); -- 2.11.4.GIT