2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.service.notification;
19 import android.annotation.SystemApi;
20 import android.annotation.SdkConstant;
21 import android.app.INotificationManager;
22 import android.app.Notification;
23 import android.app.Notification.Builder;
24 import android.app.Service;
25 import android.content.ComponentName;
26 import android.content.Context;
27 import android.content.Intent;
28 import android.content.pm.ParceledListSlice;
29 import android.os.Bundle;
30 import android.os.IBinder;
31 import android.os.Parcel;
32 import android.os.Parcelable;
33 import android.os.RemoteException;
34 import android.os.ServiceManager;
35 import android.util.ArrayMap;
36 import android.util.ArraySet;
37 import android.util.Log;
39 import java.util.Collections;
40 import java.util.List;
43 * A service that receives calls from the system when new notifications are
44 * posted or removed, or their ranking changed.
45 * <p>To extend this class, you must declare the service in your manifest file with
46 * the {@link android.Manifest.permission#BIND_NOTIFICATION_LISTENER_SERVICE} permission
47 * and include an intent filter with the {@link #SERVICE_INTERFACE} action. For example:</p>
49 * <service android:name=".NotificationListener"
50 * android:label="@string/service_name"
51 * android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
53 * <action android:name="android.service.notification.NotificationListenerService" />
57 public abstract class NotificationListenerService extends Service {
58 // TAG = "NotificationListenerService[MySubclass]"
59 private final String TAG = NotificationListenerService.class.getSimpleName()
60 + "[" + getClass().getSimpleName() + "]";
63 * {@link #getCurrentInterruptionFilter() Interruption filter} constant -
64 * Normal interruption filter.
66 public static final int INTERRUPTION_FILTER_ALL = 1;
69 * {@link #getCurrentInterruptionFilter() Interruption filter} constant -
70 * Priority interruption filter.
72 public static final int INTERRUPTION_FILTER_PRIORITY = 2;
75 * {@link #getCurrentInterruptionFilter() Interruption filter} constant -
76 * No interruptions filter.
78 public static final int INTERRUPTION_FILTER_NONE = 3;
80 /** {@link #getCurrentListenerHints() Listener hints} constant - the primary device UI
81 * should disable notification sound, vibrating and other visual or aural effects.
82 * This does not change the interruption filter, only the effects. **/
83 public static final int HINT_HOST_DISABLE_EFFECTS = 1;
86 * The full trim of the StatusBarNotification including all its features.
91 public static final int TRIM_FULL = 0;
94 * A light trim of the StatusBarNotification excluding the following features:
97 * <li>{@link Notification#tickerView tickerView}</li>
98 * <li>{@link Notification#contentView contentView}</li>
99 * <li>{@link Notification#largeIcon largeIcon}</li>
100 * <li>{@link Notification#bigContentView bigContentView}</li>
101 * <li>{@link Notification#headsUpContentView headsUpContentView}</li>
102 * <li>{@link Notification#EXTRA_LARGE_ICON extras[EXTRA_LARGE_ICON]}</li>
103 * <li>{@link Notification#EXTRA_LARGE_ICON_BIG extras[EXTRA_LARGE_ICON_BIG]}</li>
104 * <li>{@link Notification#EXTRA_PICTURE extras[EXTRA_PICTURE]}</li>
105 * <li>{@link Notification#EXTRA_BIG_TEXT extras[EXTRA_BIG_TEXT]}</li>
111 public static final int TRIM_LIGHT = 1;
113 private INotificationListenerWrapper mWrapper = null;
114 private RankingMap mRankingMap;
116 private INotificationManager mNoMan;
118 /** Only valid after a successful call to (@link registerAsService}. */
119 private int mCurrentUser;
122 // This context is required for system services since NotificationListenerService isn't
123 // started as a real Service and hence no context is available.
124 private Context mSystemContext;
127 * The {@link Intent} that must be declared as handled by the service.
129 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
130 public static final String SERVICE_INTERFACE
131 = "android.service.notification.NotificationListenerService";
134 * Implement this method to learn about new notifications as they are posted by apps.
136 * @param sbn A data structure encapsulating the original {@link android.app.Notification}
137 * object as well as its identifying information (tag and id) and source
140 public void onNotificationPosted(StatusBarNotification sbn) {
145 * Implement this method to learn about new notifications as they are posted by apps.
147 * @param sbn A data structure encapsulating the original {@link android.app.Notification}
148 * object as well as its identifying information (tag and id) and source
150 * @param rankingMap The current ranking map that can be used to retrieve ranking information
151 * for active notifications, including the newly posted one.
153 public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) {
154 onNotificationPosted(sbn);
158 * Implement this method to learn when notifications are removed.
160 * This might occur because the user has dismissed the notification using system UI (or another
161 * notification listener) or because the app has withdrawn the notification.
163 * NOTE: The {@link StatusBarNotification} object you receive will be "light"; that is, the
164 * result from {@link StatusBarNotification#getNotification} may be missing some heavyweight
165 * fields such as {@link android.app.Notification#contentView} and
166 * {@link android.app.Notification#largeIcon}. However, all other fields on
167 * {@link StatusBarNotification}, sufficient to match this call with a prior call to
168 * {@link #onNotificationPosted(StatusBarNotification)}, will be intact.
170 * @param sbn A data structure encapsulating at least the original information (tag and id)
171 * and source (package name) used to post the {@link android.app.Notification} that
174 public void onNotificationRemoved(StatusBarNotification sbn) {
179 * Implement this method to learn when notifications are removed.
181 * This might occur because the user has dismissed the notification using system UI (or another
182 * notification listener) or because the app has withdrawn the notification.
184 * NOTE: The {@link StatusBarNotification} object you receive will be "light"; that is, the
185 * result from {@link StatusBarNotification#getNotification} may be missing some heavyweight
186 * fields such as {@link android.app.Notification#contentView} and
187 * {@link android.app.Notification#largeIcon}. However, all other fields on
188 * {@link StatusBarNotification}, sufficient to match this call with a prior call to
189 * {@link #onNotificationPosted(StatusBarNotification)}, will be intact.
191 * @param sbn A data structure encapsulating at least the original information (tag and id)
192 * and source (package name) used to post the {@link android.app.Notification} that
194 * @param rankingMap The current ranking map that can be used to retrieve ranking information
195 * for active notifications.
198 public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap) {
199 onNotificationRemoved(sbn);
203 * Implement this method to learn about when the listener is enabled and connected to
204 * the notification manager. You are safe to call {@link #getActiveNotifications()}
207 public void onListenerConnected() {
212 * Implement this method to be notified when the notification ranking changes.
214 * @param rankingMap The current ranking map that can be used to retrieve ranking information
215 * for active notifications.
217 public void onNotificationRankingUpdate(RankingMap rankingMap) {
222 * Implement this method to be notified when the
223 * {@link #getCurrentListenerHints() Listener hints} change.
225 * @param hints The current {@link #getCurrentListenerHints() listener hints}.
227 public void onListenerHintsChanged(int hints) {
232 * Implement this method to be notified when the
233 * {@link #getCurrentInterruptionFilter() interruption filter} changed.
235 * @param interruptionFilter The current
236 * {@link #getCurrentInterruptionFilter() interruption filter}.
238 public void onInterruptionFilterChanged(int interruptionFilter) {
242 private final INotificationManager getNotificationInterface() {
243 if (mNoMan == null) {
244 mNoMan = INotificationManager.Stub.asInterface(
245 ServiceManager.getService(Context.NOTIFICATION_SERVICE));
251 * Inform the notification manager about dismissal of a single notification.
253 * Use this if your listener has a user interface that allows the user to dismiss individual
254 * notifications, similar to the behavior of Android's status bar and notification panel.
255 * It should be called after the user dismisses a single notification using your UI;
256 * upon being informed, the notification manager will actually remove the notification
257 * and you will get an {@link #onNotificationRemoved(StatusBarNotification)} callback.
259 * <b>Note:</b> If your listener allows the user to fire a notification's
260 * {@link android.app.Notification#contentIntent} by tapping/clicking/etc., you should call
261 * this method at that time <i>if</i> the Notification in question has the
262 * {@link android.app.Notification#FLAG_AUTO_CANCEL} flag set.
264 * @param pkg Package of the notifying app.
265 * @param tag Tag of the notification as specified by the notifying app in
266 * {@link android.app.NotificationManager#notify(String, int, android.app.Notification)}.
267 * @param id ID of the notification as specified by the notifying app in
268 * {@link android.app.NotificationManager#notify(String, int, android.app.Notification)}.
270 * @deprecated Use {@link #cancelNotification(String key)}
271 * instead. Beginning with {@link android.os.Build.VERSION_CODES#L} this method will no longer
272 * cancel the notification. It will continue to cancel the notification for applications
273 * whose {@code targetSdkVersion} is earlier than {@link android.os.Build.VERSION_CODES#L}.
275 public final void cancelNotification(String pkg, String tag, int id) {
276 if (!isBound()) return;
278 getNotificationInterface().cancelNotificationFromListener(
279 mWrapper, pkg, tag, id);
280 } catch (android.os.RemoteException ex) {
281 Log.v(TAG, "Unable to contact notification manager", ex);
286 * Inform the notification manager about dismissal of a single notification.
288 * Use this if your listener has a user interface that allows the user to dismiss individual
289 * notifications, similar to the behavior of Android's status bar and notification panel.
290 * It should be called after the user dismisses a single notification using your UI;
291 * upon being informed, the notification manager will actually remove the notification
292 * and you will get an {@link #onNotificationRemoved(StatusBarNotification)} callback.
294 * <b>Note:</b> If your listener allows the user to fire a notification's
295 * {@link android.app.Notification#contentIntent} by tapping/clicking/etc., you should call
296 * this method at that time <i>if</i> the Notification in question has the
297 * {@link android.app.Notification#FLAG_AUTO_CANCEL} flag set.
299 * @param key Notification to dismiss from {@link StatusBarNotification#getKey()}.
301 public final void cancelNotification(String key) {
302 if (!isBound()) return;
304 getNotificationInterface().cancelNotificationsFromListener(mWrapper,
306 } catch (android.os.RemoteException ex) {
307 Log.v(TAG, "Unable to contact notification manager", ex);
312 * Inform the notification manager about dismissal of all notifications.
314 * Use this if your listener has a user interface that allows the user to dismiss all
315 * notifications, similar to the behavior of Android's status bar and notification panel.
316 * It should be called after the user invokes the "dismiss all" function of your UI;
317 * upon being informed, the notification manager will actually remove all active notifications
318 * and you will get multiple {@link #onNotificationRemoved(StatusBarNotification)} callbacks.
320 * {@see #cancelNotification(String, String, int)}
322 public final void cancelAllNotifications() {
323 cancelNotifications(null /*all*/);
327 * Inform the notification manager about dismissal of specific notifications.
329 * Use this if your listener has a user interface that allows the user to dismiss
330 * multiple notifications at once.
332 * @param keys Notifications to dismiss, or {@code null} to dismiss all.
334 * {@see #cancelNotification(String, String, int)}
336 public final void cancelNotifications(String[] keys) {
337 if (!isBound()) return;
339 getNotificationInterface().cancelNotificationsFromListener(mWrapper, keys);
340 } catch (android.os.RemoteException ex) {
341 Log.v(TAG, "Unable to contact notification manager", ex);
346 * Sets the notification trim that will be received via {@link #onNotificationPosted}.
349 * Setting a trim other than {@link #TRIM_FULL} enables listeners that don't need access to the
350 * full notification features right away to reduce their memory footprint. Full notifications
351 * can be requested on-demand via {@link #getActiveNotifications(int)}.
354 * Set to {@link #TRIM_FULL} initially.
358 * @param trim trim of the notifications to be passed via {@link #onNotificationPosted}.
359 * See <code>TRIM_*</code> constants.
362 public final void setOnNotificationPostedTrim(int trim) {
363 if (!isBound()) return;
365 getNotificationInterface().setOnNotificationPostedTrimFromListener(mWrapper, trim);
366 } catch (RemoteException ex) {
367 Log.v(TAG, "Unable to contact notification manager", ex);
372 * Request the list of outstanding notifications (that is, those that are visible to the
373 * current user). Useful when you don't know what's already been posted.
375 * @return An array of active notifications, sorted in natural order.
377 public StatusBarNotification[] getActiveNotifications() {
378 return getActiveNotifications(null, TRIM_FULL);
382 * Request the list of outstanding notifications (that is, those that are visible to the
383 * current user). Useful when you don't know what's already been posted.
387 * @param trim trim of the notifications to be returned. See <code>TRIM_*</code> constants.
388 * @return An array of active notifications, sorted in natural order.
391 public StatusBarNotification[] getActiveNotifications(int trim) {
392 return getActiveNotifications(null, trim);
396 * Request one or more notifications by key. Useful if you have been keeping track of
397 * notifications but didn't want to retain the bits, and now need to go back and extract
398 * more data out of those notifications.
400 * @param keys the keys of the notifications to request
401 * @return An array of notifications corresponding to the requested keys, in the
402 * same order as the key list.
404 public StatusBarNotification[] getActiveNotifications(String[] keys) {
405 return getActiveNotifications(keys, TRIM_FULL);
409 * Request one or more notifications by key. Useful if you have been keeping track of
410 * notifications but didn't want to retain the bits, and now need to go back and extract
411 * more data out of those notifications.
415 * @param keys the keys of the notifications to request
416 * @param trim trim of the notifications to be returned. See <code>TRIM_*</code> constants.
417 * @return An array of notifications corresponding to the requested keys, in the
418 * same order as the key list.
421 public StatusBarNotification[] getActiveNotifications(String[] keys, int trim) {
425 ParceledListSlice<StatusBarNotification> parceledList = getNotificationInterface()
426 .getActiveNotificationsFromListener(mWrapper, keys, trim);
427 List<StatusBarNotification> list = parceledList.getList();
430 for (int i = 0; i < N; i++) {
431 Notification notification = list.get(i).getNotification();
432 Builder.rebuild(getContext(), notification);
434 return list.toArray(new StatusBarNotification[N]);
435 } catch (android.os.RemoteException ex) {
436 Log.v(TAG, "Unable to contact notification manager", ex);
442 * Gets the set of hints representing current state.
445 * The current state may differ from the requested state if the hint represents state
446 * shared across all listeners or a feature the notification host does not support or refuses
449 * @return Zero or more of the HINT_ constants.
451 public final int getCurrentListenerHints() {
452 if (!isBound()) return 0;
454 return getNotificationInterface().getHintsFromListener(mWrapper);
455 } catch (android.os.RemoteException ex) {
456 Log.v(TAG, "Unable to contact notification manager", ex);
462 * Gets the current notification interruption filter active on the host.
465 * The interruption filter defines which notifications are allowed to interrupt the user
466 * (e.g. via sound & vibration) and is applied globally. Listeners can find out whether
467 * a specific notification matched the interruption filter via
468 * {@link Ranking#matchesInterruptionFilter()}.
470 * The current filter may differ from the previously requested filter if the notification host
471 * does not support or refuses to apply the requested filter, or if another component changed
472 * the filter in the meantime.
474 * Listen for updates using {@link #onInterruptionFilterChanged(int)}.
476 * @return One of the INTERRUPTION_FILTER_ constants, or 0 on errors.
478 public final int getCurrentInterruptionFilter() {
479 if (!isBound()) return 0;
481 return getNotificationInterface().getHintsFromListener(mWrapper);
482 } catch (android.os.RemoteException ex) {
483 Log.v(TAG, "Unable to contact notification manager", ex);
489 * Sets the desired {@link #getCurrentListenerHints() listener hints}.
492 * This is merely a request, the host may or may not choose to take action depending
493 * on other listener requests or other global state.
495 * Listen for updates using {@link #onListenerHintsChanged(int)}.
497 * @param hints One or more of the HINT_ constants.
499 public final void requestListenerHints(int hints) {
500 if (!isBound()) return;
502 getNotificationInterface().requestHintsFromListener(mWrapper, hints);
503 } catch (android.os.RemoteException ex) {
504 Log.v(TAG, "Unable to contact notification manager", ex);
509 * Sets the desired {@link #getCurrentInterruptionFilter() interruption filter}.
512 * This is merely a request, the host may or may not choose to apply the requested
513 * interruption filter depending on other listener requests or other global state.
515 * Listen for updates using {@link #onInterruptionFilterChanged(int)}.
517 * @param interruptionFilter One of the INTERRUPTION_FILTER_ constants.
519 public final void requestInterruptionFilter(int interruptionFilter) {
520 if (!isBound()) return;
522 getNotificationInterface()
523 .requestInterruptionFilterFromListener(mWrapper, interruptionFilter);
524 } catch (android.os.RemoteException ex) {
525 Log.v(TAG, "Unable to contact notification manager", ex);
530 * Returns current ranking information.
533 * The returned object represents the current ranking snapshot and only
534 * applies for currently active notifications.
536 * Generally you should use the RankingMap that is passed with events such
537 * as {@link #onNotificationPosted(StatusBarNotification, RankingMap)},
538 * {@link #onNotificationRemoved(StatusBarNotification, RankingMap)}, and
539 * so on. This method should only be used when needing access outside of
540 * such events, for example to retrieve the RankingMap right after
543 * @return A {@link RankingMap} object providing access to ranking information
545 public RankingMap getCurrentRanking() {
550 public IBinder onBind(Intent intent) {
551 if (mWrapper == null) {
552 mWrapper = new INotificationListenerWrapper();
557 private boolean isBound() {
558 if (mWrapper == null) {
559 Log.w(TAG, "Notification listener service not yet bound.");
566 * Directly register this service with the Notification Manager.
568 * <p>Only system services may use this call. It will fail for non-system callers.
569 * Apps should ask the user to add their listener in Settings.
571 * @param context Context required for accessing resources. Since this service isn't
572 * launched as a real Service when using this method, a context has to be passed in.
573 * @param componentName the component that will consume the notification information
574 * @param currentUser the user to use as the stream filter
578 public void registerAsSystemService(Context context, ComponentName componentName,
579 int currentUser) throws RemoteException {
580 mSystemContext = context;
581 if (mWrapper == null) {
582 mWrapper = new INotificationListenerWrapper();
584 INotificationManager noMan = getNotificationInterface();
585 noMan.registerListener(mWrapper, componentName, currentUser);
586 mCurrentUser = currentUser;
590 * Directly unregister this service from the Notification Manager.
592 * <P>This method will fail for listeners that were not registered
593 * with (@link registerAsService).
597 public void unregisterAsSystemService() throws RemoteException {
598 if (mWrapper != null) {
599 INotificationManager noMan = getNotificationInterface();
600 noMan.unregisterListener(mWrapper, mCurrentUser);
604 private class INotificationListenerWrapper extends INotificationListener.Stub {
606 public void onNotificationPosted(StatusBarNotification sbn,
607 NotificationRankingUpdate update) {
608 Notification.Builder.rebuild(getContext(), sbn.getNotification());
610 // protect subclass from concurrent modifications of (@link mNotificationKeys}.
611 synchronized (mWrapper) {
614 NotificationListenerService.this.onNotificationPosted(sbn, mRankingMap);
615 } catch (Throwable t) {
616 Log.w(TAG, "Error running onNotificationPosted", t);
621 public void onNotificationRemoved(StatusBarNotification sbn,
622 NotificationRankingUpdate update) {
623 // protect subclass from concurrent modifications of (@link mNotificationKeys}.
624 synchronized (mWrapper) {
627 NotificationListenerService.this.onNotificationRemoved(sbn, mRankingMap);
628 } catch (Throwable t) {
629 Log.w(TAG, "Error running onNotificationRemoved", t);
634 public void onListenerConnected(NotificationRankingUpdate update) {
635 // protect subclass from concurrent modifications of (@link mNotificationKeys}.
636 synchronized (mWrapper) {
639 NotificationListenerService.this.onListenerConnected();
640 } catch (Throwable t) {
641 Log.w(TAG, "Error running onListenerConnected", t);
646 public void onNotificationRankingUpdate(NotificationRankingUpdate update)
647 throws RemoteException {
648 // protect subclass from concurrent modifications of (@link mNotificationKeys}.
649 synchronized (mWrapper) {
652 NotificationListenerService.this.onNotificationRankingUpdate(mRankingMap);
653 } catch (Throwable t) {
654 Log.w(TAG, "Error running onNotificationRankingUpdate", t);
659 public void onListenerHintsChanged(int hints) throws RemoteException {
661 NotificationListenerService.this.onListenerHintsChanged(hints);
662 } catch (Throwable t) {
663 Log.w(TAG, "Error running onListenerHintsChanged", t);
668 public void onInterruptionFilterChanged(int interruptionFilter) throws RemoteException {
670 NotificationListenerService.this.onInterruptionFilterChanged(interruptionFilter);
671 } catch (Throwable t) {
672 Log.w(TAG, "Error running onInterruptionFilterChanged", t);
677 private void applyUpdate(NotificationRankingUpdate update) {
678 mRankingMap = new RankingMap(update);
681 private Context getContext() {
682 if (mSystemContext != null) {
683 return mSystemContext;
689 * Stores ranking related information on a currently active notification.
692 * Ranking objects aren't automatically updated as notification events
693 * occur. Instead, ranking information has to be retrieved again via the
694 * current {@link RankingMap}.
696 public static class Ranking {
697 /** Value signifying that the user has not expressed a per-app visibility override value.
699 public static final int VISIBILITY_NO_OVERRIDE = -1000;
702 private int mRank = -1;
703 private boolean mIsAmbient;
704 private boolean mMatchesInterruptionFilter;
705 private int mVisibilityOverride;
710 * Returns the key of the notification this Ranking applies to.
712 public String getKey() {
717 * Returns the rank of the notification.
719 * @return the rank of the notification, that is the 0-based index in
720 * the list of active notifications.
722 public int getRank() {
727 * Returns whether the notification is an ambient notification, that is
728 * a notification that doesn't require the user's immediate attention.
730 public boolean isAmbient() {
735 * Returns the user specificed visibility for the package that posted
736 * this notification, or
737 * {@link NotificationListenerService.Ranking#VISIBILITY_NO_OVERRIDE} if
738 * no such preference has been expressed.
741 public int getVisibilityOverride() {
742 return mVisibilityOverride;
746 * Returns whether the notification meets the user's interruption
751 public boolean meetsInterruptionFilter() {
752 return mMatchesInterruptionFilter;
756 * Returns whether the notification matches the user's interruption
759 public boolean matchesInterruptionFilter() {
760 return mMatchesInterruptionFilter;
763 private void populate(String key, int rank, boolean isAmbient,
764 boolean matchesInterruptionFilter, int visibilityOverride) {
767 mIsAmbient = isAmbient;
768 mMatchesInterruptionFilter = matchesInterruptionFilter;
769 mVisibilityOverride = visibilityOverride;
774 * Provides access to ranking information on currently active
778 * Note that this object represents a ranking snapshot that only applies to
779 * notifications active at the time of retrieval.
781 public static class RankingMap implements Parcelable {
782 private final NotificationRankingUpdate mRankingUpdate;
783 private ArrayMap<String,Integer> mRanks;
784 private ArraySet<Object> mIntercepted;
785 private ArrayMap<String, Integer> mVisibilityOverrides;
787 private RankingMap(NotificationRankingUpdate rankingUpdate) {
788 mRankingUpdate = rankingUpdate;
792 * Request the list of notification keys in their current ranking
795 * @return An array of active notification keys, in their ranking order.
797 public String[] getOrderedKeys() {
798 return mRankingUpdate.getOrderedKeys();
802 * Populates outRanking with ranking information for the notification
803 * with the given key.
805 * @return true if a valid key has been passed and outRanking has
806 * been populated; false otherwise
808 public boolean getRanking(String key, Ranking outRanking) {
809 int rank = getRank(key);
810 outRanking.populate(key, rank, isAmbient(key), !isIntercepted(key),
811 getVisibilityOverride(key));
815 private int getRank(String key) {
816 synchronized (this) {
817 if (mRanks == null) {
821 Integer rank = mRanks.get(key);
822 return rank != null ? rank : -1;
825 private boolean isAmbient(String key) {
826 int firstAmbientIndex = mRankingUpdate.getFirstAmbientIndex();
827 if (firstAmbientIndex < 0) {
830 int rank = getRank(key);
831 return rank >= 0 && rank >= firstAmbientIndex;
834 private boolean isIntercepted(String key) {
835 synchronized (this) {
836 if (mIntercepted == null) {
837 buildInterceptedSetLocked();
840 return mIntercepted.contains(key);
843 private int getVisibilityOverride(String key) {
844 synchronized (this) {
845 if (mVisibilityOverrides == null) {
846 buildVisibilityOverridesLocked();
849 Integer overide = mVisibilityOverrides.get(key);
850 if (overide == null) {
851 return Ranking.VISIBILITY_NO_OVERRIDE;
853 return overide.intValue();
857 private void buildRanksLocked() {
858 String[] orderedKeys = mRankingUpdate.getOrderedKeys();
859 mRanks = new ArrayMap<>(orderedKeys.length);
860 for (int i = 0; i < orderedKeys.length; i++) {
861 String key = orderedKeys[i];
867 private void buildInterceptedSetLocked() {
868 String[] dndInterceptedKeys = mRankingUpdate.getInterceptedKeys();
869 mIntercepted = new ArraySet<>(dndInterceptedKeys.length);
870 Collections.addAll(mIntercepted, dndInterceptedKeys);
874 private void buildVisibilityOverridesLocked() {
875 Bundle visibilityBundle = mRankingUpdate.getVisibilityOverrides();
876 mVisibilityOverrides = new ArrayMap<>(visibilityBundle.size());
877 for (String key: visibilityBundle.keySet()) {
878 mVisibilityOverrides.put(key, visibilityBundle.getInt(key));
882 // ----------- Parcelable
885 public int describeContents() {
890 public void writeToParcel(Parcel dest, int flags) {
891 dest.writeParcelable(mRankingUpdate, flags);
894 public static final Creator<RankingMap> CREATOR = new Creator<RankingMap>() {
896 public RankingMap createFromParcel(Parcel source) {
897 NotificationRankingUpdate rankingUpdate = source.readParcelable(null);
898 return new RankingMap(rankingUpdate);
902 public RankingMap[] newArray(int size) {
903 return new RankingMap[size];