Bug 1233150 - Use service. draft
authorChenxia Liu <liuche@mozilla.com>
Fri, 04 Dec 2015 17:19:40 -0500
changeset 315868 45d68810ab5d962125318ac2263a99a52b956989
parent 315867 331af554a6de8e088c7ea0bb15799cfccf17ea1e
child 315869 bf1df460a1b6fb1216b4042f315e5b38806153d3
push id8474
push usercliu@mozilla.com
push dateWed, 16 Dec 2015 22:12:37 +0000
bugs1233150
milestone46.0a1
Bug 1233150 - Use service.
mobile/android/base/java/org/mozilla/gecko/NotificationHandler.java
mobile/android/base/java/org/mozilla/gecko/NotificationService.java
--- a/mobile/android/base/java/org/mozilla/gecko/NotificationHandler.java
+++ b/mobile/android/base/java/org/mozilla/gecko/NotificationHandler.java
@@ -55,16 +55,17 @@ public class NotificationHandler {
                     String aAlertText, PendingIntent contentIntent, String origin) {
         // Remove the old notification with the same ID, if any
         remove(notificationID);
 
         // TODO: Service intent to clear pref on reopen.
         Intent prefIntent = new Intent(Intent.ACTION_VIEW);
         prefIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
         PendingIntent buttonIntent = PendingIntent.getActivity(mContext, 0, prefIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+        PendingIntent testIntent = PendingIntent.getService(mContext, 0, prefIntent, PendingIntent.FLAG_UPDATE_CURRENT);
 
         final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
                 .setContentTitle(aAlertTitle)
                 .setContentText(aAlertText)
                 .setSmallIcon(R.drawable.ic_status_logo)
                 .setContentIntent(contentIntent)
                 .setAutoCancel(true)
                 .setStyle(new NotificationCompat.InboxStyle()
--- a/mobile/android/base/java/org/mozilla/gecko/NotificationService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/NotificationService.java
@@ -1,25 +1,31 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
+import android.app.IntentService;
 import android.app.Notification;
 import android.app.Service;
 import android.content.Intent;
 import android.os.Binder;
 import android.os.IBinder;
 
-public class NotificationService extends Service {
+public class NotificationService extends IntentService {
+    private static final String LOGTAG = "GeckoNotifactionService";
     private final IBinder mBinder = new NotificationBinder();
     private NotificationHandler mHandler;
 
+    public NotificationService(){
+        super(LOGTAG);
+    }
+
     @Override
     public void onCreate() {
         // This has to be initialized in onCreate in order to ensure that the NotificationHandler can
         // access the NotificationManager service.
         mHandler = new NotificationHandler(this) {
             @Override
             protected void setForegroundNotification(int id, Notification notification) {
                 super.setForegroundNotification(id, notification);
@@ -28,16 +34,22 @@ public class NotificationService extends
                     stopForeground(true);
                 } else {
                     startForeground(id, notification);
                 }
             }
         };
     }
 
+    @Override
+    protected void onHandleIntent(final Intent intent) {
+        // If Firefox is running, process intent immediately and block notifications from the site.
+        // If Firefox is not running, save a JSON file and update a pref.
+    }
+
     public class NotificationBinder extends Binder {
         NotificationService getService() {
             // Return this instance of NotificationService so clients can call public methods
             return NotificationService.this;
         }
     }
 
     @Override