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

Commit cc197724 authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

Tweak the selection of media button session

Key events were sent to the session which the lastly activated player app has.
After this CL, key events will be sent to a session 1) which the app
making sounds has, or 2) which the lastly activated player app has.

Bug: 113240750
Test: manually
Change-Id: I6ac128458fd0d30c9e0ed3382939ca9e4e581e22
parent cf44c411
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -142,7 +142,8 @@ class AudioPlayerStateMonitor {

    /**
     * Returns the sorted list of UIDs that have had active audio playback. (i.e. playing an
     * audio/video) The UID whose audio playback becomes active at the last comes first.
     * audio/video) The UID whose audio is currently playing comes first, then the UID whose audio
     * playback becomes active at the last comes next.
     */
    public IntArray getSortedAudioPlaybackClientUids() {
        IntArray sortedAudioPlaybackClientUids = new IntArray();
@@ -253,6 +254,26 @@ class AudioPlayerStateMonitor {
                        mSortedAudioPlaybackClientUids.add(0, uid);
                    }
                }

                if (mActiveAudioUids.size() > 0
                        && !mActiveAudioUids.contains(mSortedAudioPlaybackClientUids.get(0))) {
                    int firstActiveUid = -1;
                    int firatActiveUidIndex = -1;
                    for (int i = 1; i < mSortedAudioPlaybackClientUids.size(); ++i) {
                        int uid = mSortedAudioPlaybackClientUids.get(i);
                        if (mActiveAudioUids.contains(uid)) {
                            firatActiveUidIndex = i;
                            firstActiveUid = uid;
                            break;
                        }
                    }
                    for (int i = firatActiveUidIndex; i > 0; --i) {
                        mSortedAudioPlaybackClientUids.set(i,
                                mSortedAudioPlaybackClientUids.get(i - 1));
                    }
                    mSortedAudioPlaybackClientUids.set(0, firstActiveUid);
                }

                // Notify the active state change of audio players.
                for (AudioPlaybackConfiguration config : configs) {
                    final int pii = config.getPlayerInterfaceId();
+1 −1
Original line number Diff line number Diff line
@@ -171,7 +171,7 @@ public class MediaSessionServiceImpl extends MediaSessionService.ServiceImpl {
        mAudioPlayerStateMonitor = AudioPlayerStateMonitor.getInstance(mContext);
        mAudioPlayerStateMonitor.registerListener(
                (config, isRemoved) -> {
                    if (isRemoved || !config.isActive() || config.getPlayerType()
                    if (config.getPlayerType()
                            == AudioPlaybackConfiguration.PLAYER_TYPE_JAM_SOUNDPOOL) {
                        return;
                    }