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

Commit f9ce056b authored by Sanket Agarwal's avatar Sanket Agarwal
Browse files

Fixes for HFP & AVRCP

1. Fix NPE for when the phone does not respond to a call
2. Add PTS hooks for changing vol up/dn.

Bug: 31661223
Change-Id: I3423fcf67a2ea0fad6b9efde7ef239dbb683b737
(cherry picked from commit 342d29da30d147fe611f8bb37c66fdd9d511b5ea)
parent 1cc1c70a
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -85,6 +85,10 @@ public class A2dpMediaBrowserService extends MediaBrowserService {
    // Message sent when folder list is fetched.
    private static final int MSG_FOLDER_LIST = 9;

    // Custom actions for PTS testing.
    private String CUSTOM_ACTION_VOL_UP = "com.android.bluetooth.a2dpsink.mbs.CUSTOM_ACTION_VOL_UP";
    private String CUSTOM_ACTION_VOL_DN = "com.android.bluetooth.a2dpsink.mbs.CUSTOM_ACTION_VOL_DN";

    private MediaSession mSession;
    private MediaMetadata mA2dpMetadata;

@@ -284,6 +288,23 @@ public class A2dpMediaBrowserService extends MediaBrowserService {

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

        // Support VOL UP and VOL DOWN events for PTS testing.
        @Override
        public void onCustomAction(String action, Bundle extras) {
            Log.d(TAG, "onCustomAction " + action);
            if (CUSTOM_ACTION_VOL_UP.equals(action)) {
                mAvrcpCommandQueue.obtainMessage(
                    MSG_AVRCP_PASSTHRU,
                    AvrcpControllerService.PASS_THRU_CMD_ID_VOL_UP).sendToTarget();
            } else if (CUSTOM_ACTION_VOL_DN.equals(action)) {
                mAvrcpCommandQueue.obtainMessage(
                    MSG_AVRCP_PASSTHRU,
                    AvrcpControllerService.PASS_THRU_CMD_ID_VOL_DOWN).sendToTarget();
            } else {
                Log.w(TAG, "Custom action " + action + " not supported.");
            }
        }
    };

    private BroadcastReceiver mBtReceiver = new BroadcastReceiver() {
+9 −14
Original line number Diff line number Diff line
@@ -424,15 +424,21 @@ final class HeadsetClientStateMachine extends StateMachine {
                callRetainedIds.add(hfOriginatedAssoc);
            } else if (SystemClock.elapsedRealtime() - cCreationElapsed > OUTGOING_TIMEOUT_MILLI) {
                Log.w(TAG, "Outgoing call did not see a response, clear the calls and send CHUP");
                // We send a terminate because we are in a bad state and trying to
                // recover.
                terminateCall();

                // Clean out the state.
                // Clean out the state for outgoing call.
                for (Integer idx : mCalls.keySet()) {
                    BluetoothHeadsetClientCall c1 = mCalls.get(idx);
                    c1.setState(BluetoothHeadsetClientCall.CALL_STATE_TERMINATED);
                    sendCallChangedIntent(c);
                    sendCallChangedIntent(c1);
                }
                mCalls.clear();

                // We return here, if there's any update to the phone we should get a
                // follow up by getting some call indicators and hence update the calls.
                return;
            }
        }

@@ -491,18 +497,7 @@ final class HeadsetClientStateMachine extends StateMachine {
        if (DBG) {
            Log.d(TAG, "loopQueryCalls, starting call query loop");
        }
        if (mCalls.size() > 0) {
            return true;
        }

        // Workaround for Windows Phone 7.8 not sending callsetup=0 after
        // rejecting incoming call in 3WC use case (when no active calls present).
        // Fixes both, AG and HF rejecting the call.
        BluetoothHeadsetClientCall c = getCall(BluetoothHeadsetClientCall.CALL_STATE_INCOMING);
        if (c != null && mIndicatorCallSetup == HeadsetClientHalConstants.CALLSETUP_NONE)
            return true;

        return false;
        return (mCalls.size() > 0);
    }

    private void acceptCall(int flag, boolean retry) {