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

Commit bb2a044e authored by Joseph Pirozzo's avatar Joseph Pirozzo Committed by Gerrit Code Review
Browse files

Merge "Reduce Media State change callbacks"

parents 12301d7b ddb51407
Loading
Loading
Loading
Loading
+0 −40
Original line number Diff line number Diff line
@@ -121,15 +121,12 @@ public class A2dpSinkStreamHandler extends Handler {
                // Audio stream has started, stop it if we don't have focus.
                if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
                    sendAvrcpPause();
                } else {
                    startAvrcpUpdates();
                }
                break;

            case SRC_STR_STOP:
                // Audio stream has stopped, maintain focus but stop avrcp updates.
                mStreamAvailable = false;
                stopAvrcpUpdates();
                break;

            case SNK_PLAY:
@@ -137,12 +134,10 @@ public class A2dpSinkStreamHandler extends Handler {
                if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
                    requestAudioFocus();
                }
                startAvrcpUpdates();
                break;

            case SNK_PAUSE:
                // Local pause command, maintain focus but stop avrcp updates.
                stopAvrcpUpdates();
                break;

            case SRC_PLAY:
@@ -152,20 +147,16 @@ public class A2dpSinkStreamHandler extends Handler {
                    if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
                        requestAudioFocus();
                    }
                    startAvrcpUpdates();
                    break;
                }
                // Otherwise, pause if we don't have focus
                if (mAudioFocus == AudioManager.AUDIOFOCUS_NONE) {
                    sendAvrcpPause();
                } else {
                    startAvrcpUpdates();
                }
                break;

            case SRC_PAUSE:
                // Remote pause command, stop avrcp updates.
                stopAvrcpUpdates();
                break;

            case REQUEST_FOCUS:
@@ -176,7 +167,6 @@ public class A2dpSinkStreamHandler extends Handler {

            case DISCONNECT:
                // Remote device has disconnected, restore everything to default state.
                stopAvrcpUpdates();
                mSentPause = false;
                break;

@@ -185,7 +175,6 @@ public class A2dpSinkStreamHandler extends Handler {
                switch ((int) message.obj) {
                    case AudioManager.AUDIOFOCUS_GAIN:
                        // Begin playing audio, if we paused the remote, send a play now.
                        startAvrcpUpdates();
                        startFluorideStreaming();
                        if (mSentPause) {
                            sendMessageDelayed(obtainMessage(DELAYED_RESUME), SETTLE_TIMEOUT);
@@ -259,7 +248,6 @@ public class A2dpSinkStreamHandler extends Handler {
        int focusRequestStatus = mAudioManager.requestAudioFocus(focusRequest);
        // If the request is granted begin streaming immediately and schedule an upgrade.
        if (focusRequestStatus == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
            startAvrcpUpdates();
            startFluorideStreaming();
            mAudioFocus = AudioManager.AUDIOFOCUS_GAIN;
        }
@@ -286,34 +274,6 @@ public class A2dpSinkStreamHandler extends Handler {
        mA2dpSinkSm.informAudioTrackGainNative(gain);
    }

    private void startAvrcpUpdates() {
        // Since AVRCP gets started after A2DP we may need to request it later in cycle.
        AvrcpControllerService avrcpService = AvrcpControllerService.getAvrcpControllerService();

        if (DBG) {
            Log.d(TAG, "startAvrcpUpdates");
        }
        if (avrcpService != null && avrcpService.getConnectedDevices().size() == 1) {
            avrcpService.startAvrcpUpdates();
        } else {
            Log.e(TAG, "startAvrcpUpdates failed because of connection.");
        }
    }

    private void stopAvrcpUpdates() {
        // Since AVRCP gets started after A2DP we may need to request it later in cycle.
        AvrcpControllerService avrcpService = AvrcpControllerService.getAvrcpControllerService();

        if (DBG) {
            Log.d(TAG, "stopAvrcpUpdates");
        }
        if (avrcpService != null && avrcpService.getConnectedDevices().size() == 1) {
            avrcpService.stopAvrcpUpdates();
        } else {
            Log.e(TAG, "stopAvrcpUpdates failed because of connection.");
        }
    }

    private void sendAvrcpPause() {
        // Since AVRCP gets started after A2DP we may need to request it later in cycle.
        AvrcpControllerService avrcpService = AvrcpControllerService.getAvrcpControllerService();
+0 −10
Original line number Diff line number Diff line
@@ -316,16 +316,6 @@ public class AvrcpControllerService extends ProfileService {
        mAvrcpCtSm.sendMessage(msg);
    }

    public void startAvrcpUpdates() {
        mAvrcpCtSm.obtainMessage(AvrcpControllerStateMachine.MESSAGE_START_METADATA_BROADCASTS)
                .sendToTarget();
    }

    public void stopAvrcpUpdates() {
        mAvrcpCtSm.obtainMessage(AvrcpControllerStateMachine.MESSAGE_STOP_METADATA_BROADCASTS)
                .sendToTarget();
    }

    public synchronized MediaMetadata getMetaData(BluetoothDevice device) {
        if (DBG) {
            Log.d(TAG, "getMetaData");
+0 −9
Original line number Diff line number Diff line
@@ -69,10 +69,6 @@ class AvrcpControllerStateMachine extends StateMachine {
    static final int MESSAGE_PROCESS_SET_ADDRESSED_PLAYER = 114;
    static final int MESSAGE_PROCESS_ADDRESSED_PLAYER_CHANGED = 115;

    // commands from A2DP sink
    static final int MESSAGE_STOP_METADATA_BROADCASTS = 201;
    static final int MESSAGE_START_METADATA_BROADCASTS = 202;

    // commands for connection
    static final int MESSAGE_PROCESS_RC_FEATURES = 301;
    static final int MESSAGE_PROCESS_CONNECTION_CHANGE = 302;
@@ -381,7 +377,6 @@ class AvrcpControllerStateMachine extends StateMachine {
                    case MESSAGE_PROCESS_PLAY_STATUS_CHANGED:
                        int status = msg.arg1;
                        mAddressedPlayer.setPlayStatus(status);
                        broadcastPlayBackStateChanged(getCurrentPlayBackState());
                        if (status == PlaybackState.STATE_PLAYING) {
                            a2dpSinkService.informTGStatePlaying(mRemoteDevice.mBTDevice, true);
                        } else if (status == PlaybackState.STATE_PAUSED
@@ -550,8 +545,6 @@ class AvrcpControllerStateMachine extends StateMachine {
                case MESSAGE_PROCESS_PLAY_POS_CHANGED:
                case MESSAGE_PROCESS_PLAY_STATUS_CHANGED:
                case MESSAGE_PROCESS_VOLUME_CHANGED_NOTIFICATION:
                case MESSAGE_STOP_METADATA_BROADCASTS:
                case MESSAGE_START_METADATA_BROADCASTS:
                case MESSAGE_PROCESS_CONNECTION_CHANGE:
                case MESSAGE_PROCESS_BROWSE_CONNECTION_CHANGE:
                    // All of these messages should be handled by parent state immediately.
@@ -687,8 +680,6 @@ class AvrcpControllerStateMachine extends StateMachine {
                case MESSAGE_PROCESS_PLAY_POS_CHANGED:
                case MESSAGE_PROCESS_PLAY_STATUS_CHANGED:
                case MESSAGE_PROCESS_VOLUME_CHANGED_NOTIFICATION:
                case MESSAGE_STOP_METADATA_BROADCASTS:
                case MESSAGE_START_METADATA_BROADCASTS:
                case MESSAGE_PROCESS_CONNECTION_CHANGE:
                case MESSAGE_PROCESS_BROWSE_CONNECTION_CHANGE:
                    // All of these messages should be handled by parent state immediately.
+0 −3
Original line number Diff line number Diff line
@@ -319,9 +319,6 @@ public class BluetoothMediaBrowserService extends MediaBrowserService {
            synchronized (BluetoothMediaBrowserService.this) {
                // Play the item if possible.
                mAvrcpCtrlSrvc.fetchAttrAndPlayItem(mA2dpDevice, mediaId);

                // Since we request explicit playback here we should start the updates to UI.
                mAvrcpCtrlSrvc.startAvrcpUpdates();
            }

            // TRACK_EVENT should be fired eventually and the UI should be hence updated.