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

Commit d132634a authored by Iván Budnik's avatar Iván Budnik Committed by Android (Google) Code Review
Browse files

Merge "Remove unnecessary volume session cache"

parents fe28d876 3dd277ff
Loading
Loading
Loading
Loading
+0 −10
Original line number Original line Diff line number Diff line
@@ -63,8 +63,6 @@ class MediaSessionStack {
     */
     */
    private MediaSessionRecordImpl mMediaButtonSession;
    private MediaSessionRecordImpl mMediaButtonSession;


    private MediaSessionRecordImpl mCachedVolumeDefault;

    /**
    /**
     * Cache the result of the {@link #getActiveSessions} per user.
     * Cache the result of the {@link #getActiveSessions} per user.
     */
     */
@@ -145,9 +143,6 @@ class MediaSessionStack {
            mSessions.remove(record);
            mSessions.remove(record);
            mSessions.add(0, record);
            mSessions.add(0, record);
            clearCache(record.getUserId());
            clearCache(record.getUserId());
        } else if (record.checkPlaybackActiveState(false)) {
            // Just clear the volume cache when a state goes inactive
            mCachedVolumeDefault = null;
        }
        }


        // In most cases, playback state isn't needed for finding media button session,
        // In most cases, playback state isn't needed for finding media button session,
@@ -318,15 +313,11 @@ class MediaSessionStack {
    }
    }


    public MediaSessionRecordImpl getDefaultVolumeSession() {
    public MediaSessionRecordImpl getDefaultVolumeSession() {
        if (mCachedVolumeDefault != null) {
            return mCachedVolumeDefault;
        }
        List<MediaSessionRecord> records = getPriorityList(true, UserHandle.USER_ALL);
        List<MediaSessionRecord> records = getPriorityList(true, UserHandle.USER_ALL);
        int size = records.size();
        int size = records.size();
        for (int i = 0; i < size; i++) {
        for (int i = 0; i < size; i++) {
            MediaSessionRecord record = records.get(i);
            MediaSessionRecord record = records.get(i);
            if (record.checkPlaybackActiveState(true) && record.canHandleVolumeKey()) {
            if (record.checkPlaybackActiveState(true) && record.canHandleVolumeKey()) {
                mCachedVolumeDefault = record;
                return record;
                return record;
            }
            }
        }
        }
@@ -406,7 +397,6 @@ class MediaSessionStack {
    }
    }


    private void clearCache(int userId) {
    private void clearCache(int userId) {
        mCachedVolumeDefault = null;
        mCachedActiveLists.remove(userId);
        mCachedActiveLists.remove(userId);
        // mCachedActiveLists may also include the list of sessions for UserHandle.USER_ALL,
        // mCachedActiveLists may also include the list of sessions for UserHandle.USER_ALL,
        // so they also need to be cleared.
        // so they also need to be cleared.