コード例 #1
0
  public void testNotify() {
    mNotificationManager.cancelAll();

    final int id = 1;
    sendNotification(id, R.drawable.black);
    // test updating the same notification
    sendNotification(id, R.drawable.blue);
    sendNotification(id, R.drawable.yellow);

    // assume that sendNotification tested to make sure individual notifications were present
    StatusBarNotification[] sbns = mNotificationManager.getActiveNotifications();
    for (StatusBarNotification sbn : sbns) {
      if (sbn.getId() != id) {
        fail("we got back other notifications besides the one we posted: " + sbn.getKey());
      }
    }
  }
コード例 #2
0
 @Override
 public void onNotificationPosted(StatusBarNotification sbn) {
   RemoteViews views = sbn.getNotification().contentView;
   RemoteViewsInfo info = RemoteViewsReader.read(this, views);
   if (info == null) return;
   List<RemoteViewsAction> actions = info.getActions();
   for (RemoteViewsAction action : actions) Log.v("NotificationWatcher", action.getActionName());
 }
コード例 #3
0
 @Override
 public void onNotificationRemoved(StatusBarNotification sbn) {
   try {
     maybeUnbundle(sbn, true, sbn.getUserId());
   } catch (Exception e) {
     Slog.e(TAG, "Error processing canceled notification", e);
   }
 }
コード例 #4
0
  @Override
  public void onNotificationPosted(StatusBarNotification sbn) {

    Log.i(TAG, sbn.getPackageName() + " Notification received:" + sbn.getNotification().tickerText);

    Notification postedNotification = sbn.getNotification();

    String packageName = sbn.getPackageName();

    if (postedNotification.tickerText == null
        || sbn.isOngoing()
        || !sbn.isClearable()
        || isInBlackList(packageName)) {
      return;
    }

    mNotificationHub.addNotification(sbn);

    mNotificationHub.setCurrentNotification(sbn);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    // Retrieve user specified peek timeout.
    int peekTimeoutMultiplier =
        Integer.parseInt(preferences.getString(PreferenceKeys.PREF_PEEK_TIMEOUT, "1"));

    // Does user select always listening?
    boolean alwaysListening = preferences.getBoolean(PreferenceKeys.PREF_ALWAYS_LISTENING, false);

    mNotificationPeek.showNotification(sbn, false, peekTimeoutMultiplier, alwaysListening);
  }
コード例 #5
0
 private boolean checkNotificationExistence(int id, boolean shouldExist) {
   // notification is a bit asynchronous so it may take a few ms to appear in
   // getActiveNotifications()
   // we will check for it for up to 200ms before giving up
   boolean found = false;
   for (int tries = 3; tries-- > 0; ) {
     final StatusBarNotification[] sbns = mNotificationManager.getActiveNotifications();
     for (StatusBarNotification sbn : sbns) {
       if (sbn.getId() == id) {
         found = true;
         break;
       }
     }
     if (found == shouldExist) break;
     try {
       Thread.sleep(100);
     } catch (InterruptedException ex) {
       // pass
     }
   }
   return found == shouldExist;
 }
コード例 #6
0
  @SuppressLint("NewApi")
  @Override
  public void onNotificationPosted(StatusBarNotification sbn) {

    String pack = sbn.getPackageName();
    // String ticker = sbn.getNotification().tickerText.toString();
    Bundle extras = sbn.getNotification().extras;
    String title = extras.getString("android.title");
    String text = extras.getCharSequence("android.text").toString();

    Log.i("Package", pack);
    // Log.i("Ticker", ticker);
    Log.i("Title", title);
    Log.i("Text", text);

    Intent msgrcv = new Intent("Msg");
    msgrcv.putExtra("package", pack);
    // msgrcv.putExtra("ticker", ticker);
    msgrcv.putExtra("title", title);
    msgrcv.putExtra("text", text);

    LocalBroadcastManager.getInstance(context).sendBroadcast(msgrcv);
  }
コード例 #7
0
 /**
  * Un-autobundles notifications that are now grouped by the app. Additionally cancels autobundling
  * if the status change of this notification resulted in the loose notification count being under
  * the limit.
  */
 private void maybeUnbundle(StatusBarNotification sbn, boolean notificationGone, int user) {
   List<String> notificationsToUnAutobundle = new ArrayList<>();
   boolean removeSummary = false;
   synchronized (mUnbundledNotifications) {
     Map<String, LinkedHashSet<String>> unbundledNotificationsByUser =
         mUnbundledNotifications.get(sbn.getUserId());
     if (unbundledNotificationsByUser == null || unbundledNotificationsByUser.size() == 0) {
       return;
     }
     LinkedHashSet<String> notificationsForPackage =
         unbundledNotificationsByUser.get(sbn.getPackageName());
     if (notificationsForPackage == null || notificationsForPackage.size() == 0) {
       return;
     }
     if (notificationsForPackage.remove(sbn.getKey())) {
       if (!notificationGone) {
         // Add the current notification to the unbundling list if it still exists.
         notificationsToUnAutobundle.add(sbn.getKey());
       }
       // If the status change of this notification has brought the number of loose
       // notifications back below the limit, remove the summary and un-autobundle.
       if (notificationsForPackage.size() == AUTOBUNDLE_AT_COUNT - 1) {
         removeSummary = true;
         for (String key : notificationsForPackage) {
           notificationsToUnAutobundle.add(key);
         }
       }
     }
   }
   if (notificationsToUnAutobundle.size() > 0) {
     if (removeSummary) {
       adjustAutobundlingSummary(sbn.getPackageName(), null, false, user);
     }
     adjustNotificationBundling(sbn.getPackageName(), notificationsToUnAutobundle, false, user);
   }
 }
コード例 #8
0
  @Override
  public void onNotificationPosted(StatusBarNotification sbn) {
    if (DEBUG) Log.i(TAG, "POSTED " + sbn.getKey());
    try {
      List<String> notificationsToBundle = new ArrayList<>();
      if (!sbn.isAppGroup()) {
        // Not grouped by the app, add to the list of notifications for the app;
        // send bundling update if app exceeds the autobundling limit.
        synchronized (mUnbundledNotifications) {
          Map<String, LinkedHashSet<String>> unbundledNotificationsByUser =
              mUnbundledNotifications.get(sbn.getUserId());
          if (unbundledNotificationsByUser == null) {
            unbundledNotificationsByUser = new HashMap<>();
          }
          mUnbundledNotifications.put(sbn.getUserId(), unbundledNotificationsByUser);
          LinkedHashSet<String> notificationsForPackage =
              unbundledNotificationsByUser.get(sbn.getPackageName());
          if (notificationsForPackage == null) {
            notificationsForPackage = new LinkedHashSet<>();
          }

          notificationsForPackage.add(sbn.getKey());
          unbundledNotificationsByUser.put(sbn.getPackageName(), notificationsForPackage);

          if (notificationsForPackage.size() >= AUTOBUNDLE_AT_COUNT) {
            for (String key : notificationsForPackage) {
              notificationsToBundle.add(key);
            }
          }
        }
        if (notificationsToBundle.size() > 0) {
          adjustAutobundlingSummary(
              sbn.getPackageName(), notificationsToBundle.get(0), true, sbn.getUserId());
          adjustNotificationBundling(
              sbn.getPackageName(), notificationsToBundle, true, sbn.getUserId());
        }
      } else {
        // Grouped, but not by us. Send updates to unautobundle, if we bundled it.
        maybeUnbundle(sbn, false, sbn.getUserId());
      }
    } catch (Exception e) {
      Slog.e(TAG, "Failure processing new notification", e);
    }
  }
コード例 #9
0
 @Override
 public Adjustment onNotificationEnqueued(
     StatusBarNotification sbn, int importance, boolean user) {
   if (DEBUG) Log.i(TAG, "ENQUEUED " + sbn.getKey());
   return null;
 }