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

Commit f2f0c768 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Clean notification_media_manager_background_execution flag." into main

parents 5bc9431f 5bd487b1
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -1433,16 +1433,6 @@ flag {
   }
}

flag {
  name: "notification_media_manager_background_execution"
  namespace: "systemui"
  description: "Decide whether to execute binder calls in background thread"
  bug: "336612071"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "dozeui_scheduling_alarms_background_execution"
  namespace: "systemui"
+1 −15
Original line number Diff line number Diff line
@@ -125,8 +125,7 @@ class NotificationMediaManagerTest : SysuiTestCase() {
    }

    @Test
    @EnableFlags(Flags.FLAG_NOTIFICATION_MEDIA_MANAGER_BACKGROUND_EXECUTION)
    fun clearMediaNotification_flagOn_resetMediaMetadata() {
    fun clearMediaNotification_resetMediaMetadata() {
        // set up media metadata.
        notificationMediaManager.mMediaListener.onMetadataChanged(MediaMetadata.Builder().build())
        backgroundExecutor.runAllReady()
@@ -138,17 +137,4 @@ class NotificationMediaManagerTest : SysuiTestCase() {
        assertThat(notificationMediaManager.mediaMetadata).isNull()
        assertThat(notificationMediaManager.mMediaController).isNull()
    }

    @Test
    @DisableFlags(Flags.FLAG_NOTIFICATION_MEDIA_MANAGER_BACKGROUND_EXECUTION)
    fun clearMediaNotification_flagOff_resetMediaMetadata() {
        // set up media metadata.
        notificationMediaManager.mMediaListener.onMetadataChanged(MediaMetadata.Builder().build())

        // clear media notification.
        notificationMediaManager.clearCurrentMediaNotification()

        assertThat(notificationMediaManager.mediaMetadata).isNull()
        assertThat(notificationMediaManager.mMediaController).isNull()
    }
}
+9 −69
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package com.android.systemui.statusbar;

import static com.android.systemui.Flags.mediaControlsUserInitiatedDeleteintent;
import static com.android.systemui.Flags.notificationMediaManagerBackgroundExecution;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -116,12 +115,7 @@ public class NotificationMediaManager implements Dumpable {
            if (DEBUG_MEDIA) {
                Log.v(TAG, "DEBUG_MEDIA: onMetadataChanged: " + metadata);
            }
            if (notificationMediaManagerBackgroundExecution()) {
            mBackgroundExecutor.execute(() -> setMediaMetadata(metadata));
            } else {
                setMediaMetadata(metadata);
            }

            dispatchUpdateMediaMetaData();
        }
    };
@@ -283,11 +277,7 @@ public class NotificationMediaManager implements Dumpable {

    public void addCallback(MediaListener callback) {
        mMediaListeners.add(callback);
        if (notificationMediaManagerBackgroundExecution()) {
        mBackgroundExecutor.execute(() -> updateMediaMetaData(callback));
        } else {
            updateMediaMetaData(callback);
        }
    }

    private void updateMediaMetaData(MediaListener callback) {
@@ -303,57 +293,15 @@ public class NotificationMediaManager implements Dumpable {
    public void findAndUpdateMediaNotifications() {
        // TODO(b/169655907): get the semi-filtered notifications for current user
        Collection<NotificationEntry> allNotifications = mNotifPipeline.getAllNotifs();
        if (notificationMediaManagerBackgroundExecution()) {
        // Create new sbn list to be accessed in background thread.
        List<StatusBarNotification> statusBarNotifications = new ArrayList<>();
        for (NotificationEntry entry : allNotifications) {
            statusBarNotifications.add(entry.getSbn());
        }
        mBackgroundExecutor.execute(() -> findPlayingMediaNotification(statusBarNotifications));
        } else {
            findPlayingMediaNotification(allNotifications);
        }
        dispatchUpdateMediaMetaData();
    }

    /**
     * Find a notification and media controller associated with the playing media session, and
     * update this manager's internal state.
     * TODO(b/273443374) check this method
     */
    void findPlayingMediaNotification(@NonNull Collection<NotificationEntry> allNotifications) {
        // Promote the media notification with a controller in 'playing' state, if any.
        NotificationEntry mediaNotification = null;
        MediaController controller = null;
        for (NotificationEntry entry : allNotifications) {
            Notification notif = entry.getSbn().getNotification();
            if (notif.isMediaNotification()) {
                final MediaSession.Token token =
                        entry.getSbn().getNotification().extras.getParcelable(
                                Notification.EXTRA_MEDIA_SESSION, MediaSession.Token.class);
                if (token != null) {
                    MediaController aController = new MediaController(mContext, token);
                    if (PlaybackState.STATE_PLAYING
                            == getMediaControllerPlaybackState(aController)) {
                        if (DEBUG_MEDIA) {
                            Log.v(TAG, "DEBUG_MEDIA: found mediastyle controller matching "
                                    + entry.getSbn().getKey());
                        }
                        mediaNotification = entry;
                        controller = aController;
                        break;
                    }
                }
            }
        }

        StatusBarNotification statusBarNotification = null;
        if (mediaNotification != null) {
            statusBarNotification = mediaNotification.getSbn();
        }
        setUpControllerAndKey(controller, statusBarNotification);
    }

    /**
     * Find a notification and media controller associated with the playing media session, and
     * update this manager's internal state.
@@ -415,11 +363,7 @@ public class NotificationMediaManager implements Dumpable {
    }

    public void clearCurrentMediaNotification() {
        if (notificationMediaManagerBackgroundExecution()) {
        mBackgroundExecutor.execute(this::clearMediaNotification);
        } else {
            clearMediaNotification();
        }
    }

    private void clearMediaNotification() {
@@ -429,11 +373,7 @@ public class NotificationMediaManager implements Dumpable {

    private void dispatchUpdateMediaMetaData() {
        ArrayList<MediaListener> callbacks = new ArrayList<>(mMediaListeners);
        if (notificationMediaManagerBackgroundExecution()) {
        mBackgroundExecutor.execute(() -> updateMediaMetaData(callbacks));
        } else {
            updateMediaMetaData(callbacks);
        }
    }

    private void updateMediaMetaData(List<MediaListener> callbacks) {