Fix crash when no media present.
Also improves annotations in order to make this less likely in the future. Fixes: 212434516 Test: launch phone with new pipeline, no media. Change-Id: Iab616b0a03c9a06cef55dc85e03faae7ab0f10fc
This commit is contained in:
@@ -379,6 +379,7 @@ public class NotificationMediaManager implements Dumpable {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMediaNotificationKey() {
|
||||
return mMediaNotificationKey;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ import static android.service.notification.NotificationListenerService.REASON_ER
|
||||
import static com.android.systemui.statusbar.notification.collection.NotifCollection.REASON_UNKNOWN;
|
||||
import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationCallback;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Notification;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemClock;
|
||||
@@ -33,6 +31,9 @@ import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.statusbar.IStatusBarService;
|
||||
import com.android.internal.statusbar.NotificationVisibility;
|
||||
@@ -123,8 +124,8 @@ public class NotificationEntryManager implements
|
||||
* filtered out if for instance they are not for the current user
|
||||
*/
|
||||
private final ArrayMap<String, NotificationEntry> mActiveNotifications = new ArrayMap<>();
|
||||
@VisibleForTesting
|
||||
/** This is the list of "active notifications for this user in this context" */
|
||||
@VisibleForTesting
|
||||
protected final ArrayList<NotificationEntry> mSortedAndFiltered = new ArrayList<>();
|
||||
private final List<NotificationEntry> mReadOnlyNotifications =
|
||||
Collections.unmodifiableList(mSortedAndFiltered);
|
||||
@@ -899,7 +900,7 @@ public class NotificationEntryManager implements
|
||||
}
|
||||
|
||||
/** Calls to NotificationRankingManager and updates mSortedAndFiltered */
|
||||
private void updateRankingAndSort(@NonNull RankingMap rankingMap, String reason) {
|
||||
private void updateRankingAndSort(RankingMap rankingMap, String reason) {
|
||||
if (mNotifPipelineFlags.isNewPipelineEnabled()) {
|
||||
mLogger.logUseWhileNewPipelineActive("updateRankingAndSort", reason);
|
||||
return;
|
||||
@@ -961,6 +962,7 @@ public class NotificationEntryManager implements
|
||||
* Returns a collections containing ALL notifications we know about, including ones that are
|
||||
* hidden or for other users. See {@link CommonNotifCollection#getAllNotifs()}.
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public Collection<NotificationEntry> getAllNotifs() {
|
||||
mNotifPipelineFlags.checkLegacyPipelineEnabled();
|
||||
@@ -969,7 +971,7 @@ public class NotificationEntryManager implements
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public NotificationEntry getEntry(String key) {
|
||||
public NotificationEntry getEntry(@NonNull String key) {
|
||||
mNotifPipelineFlags.checkLegacyPipelineEnabled();
|
||||
return getPendingOrActiveNotif(key);
|
||||
}
|
||||
@@ -989,7 +991,7 @@ public class NotificationEntryManager implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCollectionListener(NotifCollectionListener listener) {
|
||||
public void addCollectionListener(@NonNull NotifCollectionListener listener) {
|
||||
mNotifCollectionListeners.add(listener);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ import static java.util.Objects.requireNonNull;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.MainThread;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.Notification;
|
||||
import android.os.Handler;
|
||||
@@ -59,6 +58,7 @@ import android.util.ArrayMap;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.statusbar.IStatusBarService;
|
||||
import com.android.systemui.Dumpable;
|
||||
@@ -193,7 +193,8 @@ public class NotifCollection implements Dumpable {
|
||||
}
|
||||
|
||||
/** @see NotifPipeline#getEntry(String) () */
|
||||
NotificationEntry getEntry(String key) {
|
||||
@Nullable
|
||||
NotificationEntry getEntry(@NonNull String key) {
|
||||
return mNotificationSet.get(key);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.systemui.statusbar.notification.collection.notifcollection;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.systemui.statusbar.notification.NotificationEntryManager;
|
||||
@@ -37,7 +38,7 @@ public interface CommonNotifCollection {
|
||||
* Registers a listener to be informed when notifications are created, added, updated, removed,
|
||||
* or deleted.
|
||||
*/
|
||||
void addCollectionListener(NotifCollectionListener listener);
|
||||
void addCollectionListener(@NonNull NotifCollectionListener listener);
|
||||
|
||||
/**
|
||||
* Returns the list of all known notifications, i.e. the notifications that are currently posted
|
||||
@@ -46,11 +47,11 @@ public interface CommonNotifCollection {
|
||||
*
|
||||
* The returned collection is read-only, unsorted, unfiltered, and ungrouped.
|
||||
*/
|
||||
Collection<NotificationEntry> getAllNotifs();
|
||||
@NonNull Collection<NotificationEntry> getAllNotifs();
|
||||
|
||||
/**
|
||||
* Returns the notification entry for the given notification key;
|
||||
* the returned entry (if present) may be in any state.
|
||||
*/
|
||||
@Nullable NotificationEntry getEntry(String key);
|
||||
@Nullable NotificationEntry getEntry(@NonNull String key);
|
||||
}
|
||||
|
||||
@@ -77,11 +77,11 @@ class BypassHeadsUpNotifier @Inject constructor(
|
||||
|
||||
override fun onPrimaryMetadataOrStateChanged(metadata: MediaMetadata?, state: Int) {
|
||||
val previous = currentMediaEntry
|
||||
var newEntry = commonNotifCollection.getEntry(mediaManager.mediaNotificationKey)
|
||||
if (!NotificationMediaManager.isPlayingState(state)) {
|
||||
newEntry = null
|
||||
}
|
||||
currentMediaEntry = newEntry
|
||||
val mediaNotificationKey = mediaManager.mediaNotificationKey
|
||||
currentMediaEntry =
|
||||
if (mediaNotificationKey != null && NotificationMediaManager.isPlayingState(state))
|
||||
commonNotifCollection.getEntry(mediaNotificationKey)
|
||||
else null
|
||||
updateAutoHeadsUp(previous)
|
||||
updateAutoHeadsUp(currentMediaEntry)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user