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

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

Merge "AVRCP ignore duplicate volume changed notifications" into pi-dev

parents 4991d6fc 489c42dd
Loading
Loading
Loading
Loading
+20 −4
Original line number Original line 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_BROWSE_DEPTH_INCREMENT = 401;
    static final int MESSAGE_INTERNAL_MOVE_N_LEVELS_UP = 402;
    static final int MESSAGE_INTERNAL_MOVE_N_LEVELS_UP = 402;
    static final int MESSAGE_INTERNAL_CMD_TIMEOUT = 403;
    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
    static final int CMD_TIMEOUT_MILLIS = 5000; // 5s
    // Fetch only 5 items at a time.
    // Fetch only 5 items at a time.
    static final int GET_FOLDER_ITEMS_PAGINATION_SIZE = 5;
    static final int GET_FOLDER_ITEMS_PAGINATION_SIZE = 5;
@@ -130,7 +132,7 @@ class AvrcpControllerStateMachine extends StateMachine {
    private AvrcpPlayer mAddressedPlayer;
    private AvrcpPlayer mAddressedPlayer;


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


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


                    case MESSAGE_PROCESS_SET_ABS_VOL_CMD:
                    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);
                        setAbsVolume(msg.arg1, msg.arg2);
                        break;
                        break;


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


                    case MESSAGE_PROCESS_VOLUME_CHANGED_NOTIFICATION: {
                    case MESSAGE_PROCESS_VOLUME_CHANGED_NOTIFICATION: {
                        if (mAbsoluteVolumeChangeInProgress) {
                        if (mVolumeChangedNotificationsToIgnore > 0) {
                            mAbsoluteVolumeChangeInProgress = false;
                            mVolumeChangedNotificationsToIgnore--;
                            if (mVolumeChangedNotificationsToIgnore == 0) {
                                removeMessages(MESSAGE_INTERNAL_ABS_VOL_TIMEOUT);
                            }
                        } else {
                        } else {
                            if (mRemoteDevice.getAbsVolNotificationRequested()) {
                            if (mRemoteDevice.getAbsVolNotificationRequested()) {
                                int percentageVol = getVolumePercentage();
                                int percentageVol = getVolumePercentage();
@@ -414,6 +422,14 @@ class AvrcpControllerStateMachine extends StateMachine {
                    }
                    }
                    break;
                    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:
                    case MESSAGE_PROCESS_TRACK_CHANGED:
                        // Music start playing automatically and update Metadata
                        // Music start playing automatically and update Metadata
                        mAddressedPlayer.updateCurrentTrack((TrackInfo) msg.obj);
                        mAddressedPlayer.updateCurrentTrack((TrackInfo) msg.obj);