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

Commit 489c42dd authored by Joseph Pirozzo's avatar Joseph Pirozzo
Browse files

AVRCP ignore duplicate volume changed notifications

If two volume changes come in quickly only the first one has its
absolute volume changed notification blocked.  Update code to keep track
of how many requests were received recently and block all of them.

Bug: 77526454
Test: Stream music and hold volume up/down on phone.
Change-Id: Ibc96050ed1ed536da568c2d6917bfeb5a851b84e
(cherry picked from commit 3c3f7619bd7921cd46efe1f9b060ce2197a1a768)
parent 18e0bb97
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -87,7 +87,9 @@ class AvrcpControllerStateMachine extends StateMachine {
    static final int MESSAGE_INTERNAL_BROWSE_DEPTH_INCREMENT = 401;
    static final int MESSAGE_INTERNAL_MOVE_N_LEVELS_UP = 402;
    static final int MESSAGE_INTERNAL_CMD_TIMEOUT = 403;
    static final int MESSAGE_INTERNAL_ABS_VOL_TIMEOUT = 404;

    static final int ABS_VOL_TIMEOUT_MILLIS = 1000; //1s
    static final int CMD_TIMEOUT_MILLIS = 5000; // 5s
    // Fetch only 5 items at a time.
    static final int GET_FOLDER_ITEMS_PAGINATION_SIZE = 5;
@@ -130,7 +132,7 @@ class AvrcpControllerStateMachine extends StateMachine {
    private AvrcpPlayer mAddressedPlayer;

    // Only accessed from State Machine processMessage
    private boolean mAbsoluteVolumeChangeInProgress = false;
    private int mVolumeChangedNotificationsToIgnore = 0;
    private int mPreviousPercentageVol = -1;

    // Depth from root of current browsing. This can be used to move to root directly.
@@ -377,7 +379,10 @@ class AvrcpControllerStateMachine extends StateMachine {
                        break;

                    case MESSAGE_PROCESS_SET_ABS_VOL_CMD:
                        mAbsoluteVolumeChangeInProgress = true;
                        mVolumeChangedNotificationsToIgnore++;
                        removeMessages(MESSAGE_INTERNAL_ABS_VOL_TIMEOUT);
                        sendMessageDelayed(MESSAGE_INTERNAL_ABS_VOL_TIMEOUT,
                                ABS_VOL_TIMEOUT_MILLIS);
                        setAbsVolume(msg.arg1, msg.arg2);
                        break;

@@ -396,8 +401,11 @@ class AvrcpControllerStateMachine extends StateMachine {
                    break;

                    case MESSAGE_PROCESS_VOLUME_CHANGED_NOTIFICATION: {
                        if (mAbsoluteVolumeChangeInProgress) {
                            mAbsoluteVolumeChangeInProgress = false;
                        if (mVolumeChangedNotificationsToIgnore > 0) {
                            mVolumeChangedNotificationsToIgnore--;
                            if (mVolumeChangedNotificationsToIgnore == 0) {
                                removeMessages(MESSAGE_INTERNAL_ABS_VOL_TIMEOUT);
                            }
                        } else {
                            if (mRemoteDevice.getAbsVolNotificationRequested()) {
                                int percentageVol = getVolumePercentage();
@@ -414,6 +422,14 @@ class AvrcpControllerStateMachine extends StateMachine {
                    }
                    break;

                    case MESSAGE_INTERNAL_ABS_VOL_TIMEOUT:
                        // Volume changed notifications should come back promptly from the
                        // AudioManager, if for some reason some notifications were squashed don't
                        // prevent future notifications.
                        if (DBG) Log.d(TAG, "Timed out on volume changed notification");
                        mVolumeChangedNotificationsToIgnore = 0;
                        break;

                    case MESSAGE_PROCESS_TRACK_CHANGED:
                        // Music start playing automatically and update Metadata
                        mAddressedPlayer.updateCurrentTrack((TrackInfo) msg.obj);