mobile/android/base/ServiceNotificationClient.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 package org.mozilla.gecko;
     8 import android.content.ComponentName;
     9 import android.content.Context;
    10 import android.content.Intent;
    11 import android.content.ServiceConnection;
    12 import android.os.IBinder;
    13 import android.util.Log;
    15 /**
    16  * Client for posting notifications through the NotificationService.
    17  */
    18 public class ServiceNotificationClient extends NotificationClient {
    19     private static final String LOGTAG = "GeckoServiceNotificationClient";
    21     private final ServiceConnection mConnection = new NotificationServiceConnection();
    22     private boolean mBound;
    23     private final Context mContext;
    25     public ServiceNotificationClient(Context context) {
    26         mContext = context;
    27     }
    29     @Override
    30     protected void bind() {
    31         super.bind();
    32         final Intent intent = new Intent(mContext, NotificationService.class);
    33         mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    34     }
    36     @Override
    37     protected void unbind() {
    38         // If there are no more tasks and no notifications being
    39         // displayed, the service is disconnected. Unfortunately,
    40         // since completed download notifications are shown by
    41         // removing the progress notification and creating a new
    42         // static one, this will cause the service to be unbound
    43         // and immediately rebound when a download completes.
    44         super.unbind();
    46         if (mBound) {
    47             mBound = false;
    48             mContext.unbindService(mConnection);
    49         }
    50     }
    52     class NotificationServiceConnection implements ServiceConnection {
    53         @Override
    54         public void onServiceConnected(ComponentName className, IBinder service) {
    55             final NotificationService.NotificationBinder binder =
    56                     (NotificationService.NotificationBinder) service;
    57             connectHandler(binder.getService().getNotificationHandler());
    58             mBound = true;
    59         }
    61         @Override
    62         public void onServiceDisconnected(ComponentName componentName) {
    63             // This is called when the connection with the service has been
    64             // unexpectedly disconnected -- that is, its process crashed.
    65             // Because it is running in our same process, we should never
    66             // see this happen, and the correctness of this class relies on
    67             // this never happening.
    68             Log.e(LOGTAG, "Notification service disconnected", new Exception());
    69         }
    70     }
    71 }

mercurial