Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f21db15 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

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
parent 0e981bc3
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -379,6 +379,7 @@ public class NotificationMediaManager implements Dumpable {
        }
        }
    }
    }


    @Nullable
    public String getMediaNotificationKey() {
    public String getMediaNotificationKey() {
        return mMediaNotificationKey;
        return mMediaNotificationKey;
    }
    }
+8 −6
Original line number Original line Diff line number Diff line
@@ -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.collection.NotifCollection.REASON_UNKNOWN;
import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationCallback;
import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationCallback;


import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Notification;
import android.app.Notification;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemClock;
@@ -33,6 +31,9 @@ import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.Log;
import android.util.Log;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
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
     * filtered out if for instance they are not for the current user
     */
     */
    private final ArrayMap<String, NotificationEntry> mActiveNotifications = new ArrayMap<>();
    private final ArrayMap<String, NotificationEntry> mActiveNotifications = new ArrayMap<>();
    @VisibleForTesting
    /** This is the list of "active notifications for this user in this context" */
    /** This is the list of "active notifications for this user in this context" */
    @VisibleForTesting
    protected final ArrayList<NotificationEntry> mSortedAndFiltered = new ArrayList<>();
    protected final ArrayList<NotificationEntry> mSortedAndFiltered = new ArrayList<>();
    private final List<NotificationEntry> mReadOnlyNotifications =
    private final List<NotificationEntry> mReadOnlyNotifications =
            Collections.unmodifiableList(mSortedAndFiltered);
            Collections.unmodifiableList(mSortedAndFiltered);
@@ -899,7 +900,7 @@ public class NotificationEntryManager implements
    }
    }


    /** Calls to NotificationRankingManager and updates mSortedAndFiltered */
    /** Calls to NotificationRankingManager and updates mSortedAndFiltered */
    private void updateRankingAndSort(@NonNull RankingMap rankingMap, String reason) {
    private void updateRankingAndSort(RankingMap rankingMap, String reason) {
        if (mNotifPipelineFlags.isNewPipelineEnabled()) {
        if (mNotifPipelineFlags.isNewPipelineEnabled()) {
            mLogger.logUseWhileNewPipelineActive("updateRankingAndSort", reason);
            mLogger.logUseWhileNewPipelineActive("updateRankingAndSort", reason);
            return;
            return;
@@ -961,6 +962,7 @@ public class NotificationEntryManager implements
     * Returns a collections containing ALL notifications we know about, including ones that are
     * Returns a collections containing ALL notifications we know about, including ones that are
     * hidden or for other users. See {@link CommonNotifCollection#getAllNotifs()}.
     * hidden or for other users. See {@link CommonNotifCollection#getAllNotifs()}.
     */
     */
    @NonNull
    @Override
    @Override
    public Collection<NotificationEntry> getAllNotifs() {
    public Collection<NotificationEntry> getAllNotifs() {
        mNotifPipelineFlags.checkLegacyPipelineEnabled();
        mNotifPipelineFlags.checkLegacyPipelineEnabled();
@@ -969,7 +971,7 @@ public class NotificationEntryManager implements


    @Nullable
    @Nullable
    @Override
    @Override
    public NotificationEntry getEntry(String key) {
    public NotificationEntry getEntry(@NonNull String key) {
        mNotifPipelineFlags.checkLegacyPipelineEnabled();
        mNotifPipelineFlags.checkLegacyPipelineEnabled();
        return getPendingOrActiveNotif(key);
        return getPendingOrActiveNotif(key);
    }
    }
@@ -989,7 +991,7 @@ public class NotificationEntryManager implements
    }
    }


    @Override
    @Override
    public void addCollectionListener(NotifCollectionListener listener) {
    public void addCollectionListener(@NonNull NotifCollectionListener listener) {
        mNotifCollectionListeners.add(listener);
        mNotifCollectionListeners.add(listener);
    }
    }


+3 −2
Original line number Original line Diff line number Diff line
@@ -44,7 +44,6 @@ import static java.util.Objects.requireNonNull;


import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.MainThread;
import android.annotation.MainThread;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.annotation.UserIdInt;
import android.app.Notification;
import android.app.Notification;
import android.os.Handler;
import android.os.Handler;
@@ -59,6 +58,7 @@ import android.util.ArrayMap;
import android.util.Pair;
import android.util.Pair;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.IStatusBarService;
import com.android.systemui.Dumpable;
import com.android.systemui.Dumpable;
@@ -193,7 +193,8 @@ public class NotifCollection implements Dumpable {
    }
    }


    /** @see NotifPipeline#getEntry(String) () */
    /** @see NotifPipeline#getEntry(String) () */
    NotificationEntry getEntry(String key) {
    @Nullable
    NotificationEntry getEntry(@NonNull String key) {
        return mNotificationSet.get(key);
        return mNotificationSet.get(key);
    }
    }


+4 −3
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.systemui.statusbar.notification.collection.notifcollection;
package com.android.systemui.statusbar.notification.collection.notifcollection;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;


import com.android.systemui.statusbar.notification.NotificationEntryManager;
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,
     * Registers a listener to be informed when notifications are created, added, updated, removed,
     * or deleted.
     * 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
     * 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.
     * 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;
     * Returns the notification entry for the given notification key;
     * the returned entry (if present) may be in any state.
     * the returned entry (if present) may be in any state.
     */
     */
    @Nullable NotificationEntry getEntry(String key);
    @Nullable NotificationEntry getEntry(@NonNull String key);
}
}
+5 −5
Original line number Original line Diff line number Diff line
@@ -77,11 +77,11 @@ class BypassHeadsUpNotifier @Inject constructor(


    override fun onPrimaryMetadataOrStateChanged(metadata: MediaMetadata?, state: Int) {
    override fun onPrimaryMetadataOrStateChanged(metadata: MediaMetadata?, state: Int) {
        val previous = currentMediaEntry
        val previous = currentMediaEntry
        var newEntry = commonNotifCollection.getEntry(mediaManager.mediaNotificationKey)
        val mediaNotificationKey = mediaManager.mediaNotificationKey
        if (!NotificationMediaManager.isPlayingState(state)) {
        currentMediaEntry =
            newEntry = null
            if (mediaNotificationKey != null && NotificationMediaManager.isPlayingState(state))
        }
                commonNotifCollection.getEntry(mediaNotificationKey)
        currentMediaEntry = newEntry
            else null
        updateAutoHeadsUp(previous)
        updateAutoHeadsUp(previous)
        updateAutoHeadsUp(currentMediaEntry)
        updateAutoHeadsUp(currentMediaEntry)
    }
    }