Bug 608624 - Clearing update notification launches fennec r=blassey a=dougt
authorAlex Pakhotin <alexp@mozilla.com>
Tue, 30 Nov 2010 21:57:21 -0800
changeset 59285 0daedff288b7b75afab18a375e6e9e0af6c8ff48
parent 59284 ec119059ab455f738b9fd09f90c249ceedc48c15
child 59287 9ea3e2d8b20227b7a20b0bb7a383e12c91e96bab
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersblassey, dougt
bugs608624
milestone2.0b9pre
Bug 608624 - Clearing update notification launches fennec r=blassey a=dougt
embedding/android/AndroidManifest.xml.in
embedding/android/GeckoAppShell.java
embedding/android/NotificationHandler.java.in
--- a/embedding/android/AndroidManifest.xml.in
+++ b/embedding/android/AndroidManifest.xml.in
@@ -59,24 +59,22 @@
 
             <!-- For debugging -->
             <intent-filter>
                 <action android:name="org.mozilla.gecko.DEBUG" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
         </activity>
 
-        <activity android:name="NotificationHandler"
-                  android:label="@MOZ_APP_DISPLAYNAME@ Notification"
-                  android:theme="@android:style/Theme.NoTitleBar">
+        <receiver android:name="NotificationHandler">
             <intent-filter>
                 <action android:name="org.mozilla.gecko.ACTION_ALERT_CLICK" />
                 <action android:name="org.mozilla.gecko.ACTION_ALERT_CLEAR" />
             </intent-filter>
-        </activity>
+        </receiver>
 
         <activity android:name="Restarter"
                   android:theme="@android:style/Theme.Light.NoTitleBar">
           <intent-filter>
             <action android:name="org.mozilla.gecko.restart@MOZ_APP_NAME@" 
 		    android:process="@MOZ_APP_NAME@Restarter"/>
           </intent-filter>
         </activity>
--- a/embedding/android/GeckoAppShell.java
+++ b/embedding/android/GeckoAppShell.java
@@ -523,27 +523,25 @@ class GeckoAppShell
         Intent notificationIntent = new Intent(GeckoApp.ACTION_ALERT_CLICK);
         notificationIntent.setClassName(GeckoApp.mAppContext,
             "org.mozilla." + GeckoApp.mAppContext.getAppName() + ".NotificationHandler");
 
         // Put the strings into the intent as an URI "alert:<name>#<cookie>"
         Uri dataUri = Uri.fromParts("alert", aAlertName, aAlertCookie);
         notificationIntent.setData(dataUri);
 
-        PendingIntent contentIntent = PendingIntent.getActivity(GeckoApp.mAppContext, 0, notificationIntent, 0);
+        PendingIntent contentIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, notificationIntent, 0);
         notification.setLatestEventInfo(GeckoApp.mAppContext, aAlertTitle, aAlertText, contentIntent);
 
         // The intent to execute when the status entry is deleted by the user with the "Clear All Notifications" button
         Intent clearNotificationIntent = new Intent(GeckoApp.ACTION_ALERT_CLEAR);
         clearNotificationIntent.setClassName(GeckoApp.mAppContext,
             "org.mozilla." + GeckoApp.mAppContext.getAppName() + ".NotificationHandler");
         clearNotificationIntent.setData(dataUri);
-
-        PendingIntent pendingClearIntent = PendingIntent.getActivity(GeckoApp.mAppContext, 0, clearNotificationIntent, 0);
-        notification.deleteIntent = pendingClearIntent;
+        notification.deleteIntent = PendingIntent.getBroadcast(GeckoApp.mAppContext, 0, clearNotificationIntent, 0);
 
         mAlertNotifications.put(notificationID, notification);
 
         notification.show();
 
         Log.i("GeckoAppJava", "Created notification ID " + notificationID);
     }
 
--- a/embedding/android/NotificationHandler.java.in
+++ b/embedding/android/NotificationHandler.java.in
@@ -33,40 +33,35 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #filter substitution
 package org.mozilla.@MOZ_APP_NAME@;
 
-import android.app.Activity;
 import android.app.NotificationManager;
 import android.content.Intent;
 import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.Context;
 import android.os.Bundle;
 import android.util.Log;
 import android.net.Uri;
 
 public class NotificationHandler
-    extends Activity
+    extends BroadcastReceiver
 {
     @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        Log.i("GeckoAppJava", "NotificationHandler.onCreate");
-
-        Intent intent = getIntent();
+    public void onReceive(Context context, Intent intent) {
         if (intent != null)
-            handleIntent(intent);
-
-        finish();
+            handleIntent(context, intent);
     }
 
-    protected void handleIntent(Intent notificationIntent) {
+    protected void handleIntent(Context context, Intent notificationIntent) {
         String action = notificationIntent.getAction();
         String alertName = "";
         String alertCookie = "";
         Uri data = notificationIntent.getData();
         if (data != null) {
             alertName = data.getSchemeSpecificPart();
             alertCookie = data.getFragment();
             if (alertCookie == null)
@@ -82,24 +77,25 @@ public class NotificationHandler
 
         Log.i("GeckoAppJava", "Handle notification ID " + notificationID);
 
         if (App.mAppContext != null) {
             // This should call the observer, if any
             App.mAppContext.handleNotification(action, alertName, alertCookie);
         } else {
             // The app is not running, just cancel this notification
-            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
             notificationManager.cancel(notificationID);
         }
 
         if (App.ACTION_ALERT_CLICK.equals(action)) {
             // Start or bring to front the main activity
             Intent appIntent = new Intent(Intent.ACTION_MAIN);
-            appIntent.setClassName(this, "org.mozilla.@MOZ_APP_NAME@.App");
+            appIntent.setClassName(context, "org.mozilla.@MOZ_APP_NAME@.App");
+            appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             try {
-                startActivity(appIntent);
+                context.startActivity(appIntent);
             } catch (ActivityNotFoundException e) {
                 Log.e("GeckoAppJava", "NotificationHandler Exception: " + e.getMessage());
             }
         }
     }
 }