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

Commit 7095632c authored by Chienyuan's avatar Chienyuan
Browse files

HFP Client: Choose proper address for native command/callback

Tag: #refactor
Bug: 197044261
Test: manual

Change-Id: Ie6419cd7bf8391fcc5bb6d7ff98f9b444a4015fb
parent bbf5511c
Loading
Loading
Loading
Loading
+25 −33
Original line number Original line Diff line number Diff line
@@ -361,7 +361,7 @@ public class HeadsetClientStateMachine extends StateMachine {
    private boolean queryCallsStart() {
    private boolean queryCallsStart() {
        logD("queryCallsStart");
        logD("queryCallsStart");
        clearPendingAction();
        clearPendingAction();
        mNativeInterface.queryCurrentCalls(getByteAddress(mCurrentDevice));
        mNativeInterface.queryCurrentCalls(mCurrentDevice);
        addQueuedAction(QUERY_CURRENT_CALLS, 0);
        addQueuedAction(QUERY_CURRENT_CALLS, 0);
        return true;
        return true;
    }
    }
@@ -592,7 +592,7 @@ public class HeadsetClientStateMachine extends StateMachine {
            routeHfpAudio(true);
            routeHfpAudio(true);
        }
        }


        if (mNativeInterface.handleCallAction(getByteAddress(mCurrentDevice), action, 0)) {
        if (mNativeInterface.handleCallAction(mCurrentDevice, action, 0)) {
            addQueuedAction(ACCEPT_CALL, action);
            addQueuedAction(ACCEPT_CALL, action);
        } else {
        } else {
            Log.e(TAG, "ERROR: Couldn't accept a call, action:" + action);
            Log.e(TAG, "ERROR: Couldn't accept a call, action:" + action);
@@ -631,7 +631,7 @@ public class HeadsetClientStateMachine extends StateMachine {
                return;
                return;
        }
        }


        if (mNativeInterface.handleCallAction(getByteAddress(mCurrentDevice), action, 0)) {
        if (mNativeInterface.handleCallAction(mCurrentDevice, action, 0)) {
            logD("Reject call action " + action);
            logD("Reject call action " + action);
            addQueuedAction(REJECT_CALL, action);
            addQueuedAction(REJECT_CALL, action);
        } else {
        } else {
@@ -656,7 +656,7 @@ public class HeadsetClientStateMachine extends StateMachine {
            action = HeadsetClientHalConstants.CALL_ACTION_CHLD_2;
            action = HeadsetClientHalConstants.CALL_ACTION_CHLD_2;
        }
        }


        if (mNativeInterface.handleCallAction(getByteAddress(mCurrentDevice), action, 0)) {
        if (mNativeInterface.handleCallAction(mCurrentDevice, action, 0)) {
            addQueuedAction(HOLD_CALL, action);
            addQueuedAction(HOLD_CALL, action);
        } else {
        } else {
            Log.e(TAG, "ERROR: Couldn't hold a call, action:" + action);
            Log.e(TAG, "ERROR: Couldn't hold a call, action:" + action);
@@ -677,7 +677,7 @@ public class HeadsetClientStateMachine extends StateMachine {
            action = HeadsetClientHalConstants.CALL_ACTION_CHLD_0;
            action = HeadsetClientHalConstants.CALL_ACTION_CHLD_0;
        }
        }
        if (c != null) {
        if (c != null) {
            if (mNativeInterface.handleCallAction(getByteAddress(mCurrentDevice), action, 0)) {
            if (mNativeInterface.handleCallAction(mCurrentDevice, action, 0)) {
                addQueuedAction(TERMINATE_CALL, action);
                addQueuedAction(TERMINATE_CALL, action);
            } else {
            } else {
                Log.e(TAG, "ERROR: Couldn't terminate outgoing call");
                Log.e(TAG, "ERROR: Couldn't terminate outgoing call");
@@ -695,7 +695,7 @@ public class HeadsetClientStateMachine extends StateMachine {
            return;
            return;
        }
        }


        if (mNativeInterface.handleCallAction(getByteAddress(mCurrentDevice),
        if (mNativeInterface.handleCallAction(mCurrentDevice,
                HeadsetClientHalConstants.CALL_ACTION_CHLD_2X, idx)) {
                HeadsetClientHalConstants.CALL_ACTION_CHLD_2X, idx)) {
            addQueuedAction(ENTER_PRIVATE_MODE, c);
            addQueuedAction(ENTER_PRIVATE_MODE, c);
        } else {
        } else {
@@ -711,7 +711,7 @@ public class HeadsetClientStateMachine extends StateMachine {
            return;
            return;
        }
        }


        if (mNativeInterface.handleCallAction(getByteAddress(mCurrentDevice),
        if (mNativeInterface.handleCallAction(mCurrentDevice,
                HeadsetClientHalConstants.CALL_ACTION_CHLD_4, -1)) {
                HeadsetClientHalConstants.CALL_ACTION_CHLD_4, -1)) {
            addQueuedAction(EXPLICIT_CALL_TRANSFER);
            addQueuedAction(EXPLICIT_CALL_TRANSFER);
        } else {
        } else {
@@ -853,7 +853,7 @@ public class HeadsetClientStateMachine extends StateMachine {
    public void doQuit() {
    public void doQuit() {
        logD("doQuit");
        logD("doQuit");
        if (mCurrentDevice != null) {
        if (mCurrentDevice != null) {
            mNativeInterface.disconnect(getByteAddress(mCurrentDevice));
            mNativeInterface.disconnect(mCurrentDevice);
        }
        }
        routeHfpAudio(false);
        routeHfpAudio(false);
        returnAudioFocusIfNecessary();
        returnAudioFocusIfNecessary();
@@ -939,7 +939,7 @@ public class HeadsetClientStateMachine extends StateMachine {
            switch (message.what) {
            switch (message.what) {
                case CONNECT:
                case CONNECT:
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    BluetoothDevice device = (BluetoothDevice) message.obj;
                    if (!mNativeInterface.connect(getByteAddress(device))) {
                    if (!mNativeInterface.connect(device)) {
                        // No state transition is involved, fire broadcast immediately
                        // No state transition is involved, fire broadcast immediately
                        broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
                        broadcastConnectionState(device, BluetoothProfile.STATE_DISCONNECTED,
                                BluetoothProfile.STATE_DISCONNECTED);
                                BluetoothProfile.STATE_DISCONNECTED);
@@ -986,7 +986,7 @@ public class HeadsetClientStateMachine extends StateMachine {
                                + device.getBondState());
                                + device.getBondState());
                        // reject the connection and stay in Disconnected state
                        // reject the connection and stay in Disconnected state
                        // itself
                        // itself
                        mNativeInterface.disconnect(getByteAddress(device));
                        mNativeInterface.disconnect(device);
                        // the other profile connection should be initiated
                        // the other profile connection should be initiated
                        AdapterService adapterService = AdapterService.getAdapterService();
                        AdapterService adapterService = AdapterService.getAdapterService();
                        // No state transition is involved, fire broadcast immediately
                        // No state transition is involved, fire broadcast immediately
@@ -1100,7 +1100,7 @@ public class HeadsetClientStateMachine extends StateMachine {


                    // We do not support devices which do not support enhanced call status (ECS).
                    // We do not support devices which do not support enhanced call status (ECS).
                    if ((mPeerFeatures & HeadsetClientHalConstants.PEER_FEAT_ECS) == 0) {
                    if ((mPeerFeatures & HeadsetClientHalConstants.PEER_FEAT_ECS) == 0) {
                        mNativeInterface.disconnect(getByteAddress(device));
                        mNativeInterface.disconnect(device);
                        return;
                        return;
                    }
                    }


@@ -1108,7 +1108,7 @@ public class HeadsetClientStateMachine extends StateMachine {
                    if (HeadsetClientHalConstants.HANDSFREECLIENT_NREC_SUPPORTED && (
                    if (HeadsetClientHalConstants.HANDSFREECLIENT_NREC_SUPPORTED && (
                            (mPeerFeatures & HeadsetClientHalConstants.PEER_FEAT_ECNR)
                            (mPeerFeatures & HeadsetClientHalConstants.PEER_FEAT_ECNR)
                                    == HeadsetClientHalConstants.PEER_FEAT_ECNR)) {
                                    == HeadsetClientHalConstants.PEER_FEAT_ECNR)) {
                        if (mNativeInterface.sendATCmd(getByteAddress(mCurrentDevice),
                        if (mNativeInterface.sendATCmd(mCurrentDevice,
                                HeadsetClientHalConstants.HANDSFREECLIENT_AT_CMD_NREC, 1, 0,
                                HeadsetClientHalConstants.HANDSFREECLIENT_AT_CMD_NREC, 1, 0,
                                null)) {
                                null)) {
                            addQueuedAction(DISABLE_NREC);
                            addQueuedAction(DISABLE_NREC);
@@ -1200,20 +1200,20 @@ public class HeadsetClientStateMachine extends StateMachine {
                        // already connected to this device, do nothing
                        // already connected to this device, do nothing
                        break;
                        break;
                    }
                    }
                    mNativeInterface.connect(getByteAddress(device));
                    mNativeInterface.connect(device);
                    break;
                    break;
                case DISCONNECT:
                case DISCONNECT:
                    BluetoothDevice dev = (BluetoothDevice) message.obj;
                    BluetoothDevice dev = (BluetoothDevice) message.obj;
                    if (!mCurrentDevice.equals(dev)) {
                    if (!mCurrentDevice.equals(dev)) {
                        break;
                        break;
                    }
                    }
                    if (!mNativeInterface.disconnect(getByteAddress(dev))) {
                    if (!mNativeInterface.disconnect(dev)) {
                        Log.e(TAG, "disconnectNative failed for " + dev);
                        Log.e(TAG, "disconnectNative failed for " + dev);
                    }
                    }
                    break;
                    break;


                case CONNECT_AUDIO:
                case CONNECT_AUDIO:
                    if (!mNativeInterface.connectAudio(getByteAddress(mCurrentDevice))) {
                    if (!mNativeInterface.connectAudio(mCurrentDevice)) {
                        Log.e(TAG, "ERROR: Couldn't connect Audio for device " + mCurrentDevice);
                        Log.e(TAG, "ERROR: Couldn't connect Audio for device " + mCurrentDevice);
                        // No state transition is involved, fire broadcast immediately
                        // No state transition is involved, fire broadcast immediately
                        broadcastAudioState(mCurrentDevice,
                        broadcastAudioState(mCurrentDevice,
@@ -1225,15 +1225,14 @@ public class HeadsetClientStateMachine extends StateMachine {
                    break;
                    break;


                case DISCONNECT_AUDIO:
                case DISCONNECT_AUDIO:
                    if (!mNativeInterface.disconnectAudio(getByteAddress(mCurrentDevice))) {
                    if (!mNativeInterface.disconnectAudio(mCurrentDevice)) {
                        Log.e(TAG, "ERROR: Couldn't disconnect Audio for device " + mCurrentDevice);
                        Log.e(TAG, "ERROR: Couldn't disconnect Audio for device " + mCurrentDevice);
                    }
                    }
                    break;
                    break;


                case VOICE_RECOGNITION_START:
                case VOICE_RECOGNITION_START:
                    if (mVoiceRecognitionActive == HeadsetClientHalConstants.VR_STATE_STOPPED) {
                    if (mVoiceRecognitionActive == HeadsetClientHalConstants.VR_STATE_STOPPED) {
                        if (mNativeInterface.startVoiceRecognition(
                        if (mNativeInterface.startVoiceRecognition(mCurrentDevice)) {
                                    getByteAddress(mCurrentDevice))) {
                            addQueuedAction(VOICE_RECOGNITION_START);
                            addQueuedAction(VOICE_RECOGNITION_START);
                        } else {
                        } else {
                            Log.e(TAG, "ERROR: Couldn't start voice recognition");
                            Log.e(TAG, "ERROR: Couldn't start voice recognition");
@@ -1243,8 +1242,7 @@ public class HeadsetClientStateMachine extends StateMachine {


                case VOICE_RECOGNITION_STOP:
                case VOICE_RECOGNITION_STOP:
                    if (mVoiceRecognitionActive == HeadsetClientHalConstants.VR_STATE_STARTED) {
                    if (mVoiceRecognitionActive == HeadsetClientHalConstants.VR_STATE_STARTED) {
                        if (mNativeInterface.stopVoiceRecognition(
                        if (mNativeInterface.stopVoiceRecognition(mCurrentDevice)) {
                                    getByteAddress(mCurrentDevice))) {
                            addQueuedAction(VOICE_RECOGNITION_STOP);
                            addQueuedAction(VOICE_RECOGNITION_STOP);
                        } else {
                        } else {
                            Log.e(TAG, "ERROR: Couldn't stop voice recognition");
                            Log.e(TAG, "ERROR: Couldn't stop voice recognition");
@@ -1264,7 +1262,7 @@ public class HeadsetClientStateMachine extends StateMachine {
                            == HeadsetClientHalConstants.PEER_FEAT_HF_IND) {
                            == HeadsetClientHalConstants.PEER_FEAT_HF_IND) {
                        int indicatorID = message.arg1;
                        int indicatorID = message.arg1;
                        int value = message.arg2;
                        int value = message.arg2;
                        mNativeInterface.sendATCmd(getByteAddress(mCurrentDevice),
                        mNativeInterface.sendATCmd(mCurrentDevice,
                                HeadsetClientHalConstants.HANDSFREECLIENT_AT_CMD_BIEV,
                                HeadsetClientHalConstants.HANDSFREECLIENT_AT_CMD_BIEV,
                                indicatorID,
                                indicatorID,
                                value,
                                value,
@@ -1284,7 +1282,7 @@ public class HeadsetClientStateMachine extends StateMachine {
                        logD("Volume" + amVol + ":" + mCommandedSpeakerVolume);
                        logD("Volume" + amVol + ":" + mCommandedSpeakerVolume);
                        // Volume was changed by a 3rd party
                        // Volume was changed by a 3rd party
                        mCommandedSpeakerVolume = -1;
                        mCommandedSpeakerVolume = -1;
                        if (mNativeInterface.setVolume(getByteAddress(mCurrentDevice),
                        if (mNativeInterface.setVolume(mCurrentDevice,
                                HeadsetClientHalConstants.VOLUME_TYPE_SPK, hfVol)) {
                                HeadsetClientHalConstants.VOLUME_TYPE_SPK, hfVol)) {
                            addQueuedAction(SET_SPEAKER_VOLUME);
                            addQueuedAction(SET_SPEAKER_VOLUME);
                        }
                        }
@@ -1295,7 +1293,7 @@ public class HeadsetClientStateMachine extends StateMachine {
                    BluetoothHeadsetClientCall c = (BluetoothHeadsetClientCall) message.obj;
                    BluetoothHeadsetClientCall c = (BluetoothHeadsetClientCall) message.obj;
                    mCalls.put(HF_ORIGINATED_CALL_ID, c);
                    mCalls.put(HF_ORIGINATED_CALL_ID, c);


                    if (mNativeInterface.dial(getByteAddress(mCurrentDevice), c.getNumber())) {
                    if (mNativeInterface.dial(mCurrentDevice, c.getNumber())) {
                        addQueuedAction(DIAL_NUMBER, c.getNumber());
                        addQueuedAction(DIAL_NUMBER, c.getNumber());
                        // Start looping on calling current calls.
                        // Start looping on calling current calls.
                        sendMessage(QUERY_CURRENT_CALLS);
                        sendMessage(QUERY_CURRENT_CALLS);
@@ -1327,7 +1325,7 @@ public class HeadsetClientStateMachine extends StateMachine {
                    explicitCallTransfer();
                    explicitCallTransfer();
                    break;
                    break;
                case SEND_DTMF:
                case SEND_DTMF:
                    if (mNativeInterface.sendDtmf(getByteAddress(mCurrentDevice),
                    if (mNativeInterface.sendDtmf(mCurrentDevice,
                            (byte) message.arg1)) {
                            (byte) message.arg1)) {
                        addQueuedAction(SEND_DTMF);
                        addQueuedAction(SEND_DTMF);
                    } else {
                    } else {
@@ -1335,8 +1333,7 @@ public class HeadsetClientStateMachine extends StateMachine {
                    }
                    }
                    break;
                    break;
                case SUBSCRIBER_INFO:
                case SUBSCRIBER_INFO:
                    if (mNativeInterface.retrieveSubscriberInfo(
                    if (mNativeInterface.retrieveSubscriberInfo(mCurrentDevice)) {
                            getByteAddress(mCurrentDevice))) {
                        addQueuedAction(SUBSCRIBER_INFO);
                        addQueuedAction(SUBSCRIBER_INFO);
                    } else {
                    } else {
                        Log.e(TAG, "ERROR: Couldn't retrieve subscriber info");
                        Log.e(TAG, "ERROR: Couldn't retrieve subscriber info");
@@ -1394,8 +1391,7 @@ public class HeadsetClientStateMachine extends StateMachine {


                            if (mIndicatorNetworkState
                            if (mIndicatorNetworkState
                                    == HeadsetClientHalConstants.NETWORK_STATE_AVAILABLE) {
                                    == HeadsetClientHalConstants.NETWORK_STATE_AVAILABLE) {
                                if (mNativeInterface.queryCurrentOperatorName(
                                if (mNativeInterface.queryCurrentOperatorName(mCurrentDevice)) {
                                        getByteAddress(mCurrentDevice))) {
                                    addQueuedAction(QUERY_OPERATOR_NAME);
                                    addQueuedAction(QUERY_OPERATOR_NAME);
                                } else {
                                } else {
                                    Log.e(TAG, "ERROR: Couldn't querry operator name");
                                    Log.e(TAG, "ERROR: Couldn't querry operator name");
@@ -1708,7 +1704,7 @@ public class HeadsetClientStateMachine extends StateMachine {
                     * StackEvent.EVENT_TYPE_AUDIO_STATE_CHANGED, that triggers State
                     * StackEvent.EVENT_TYPE_AUDIO_STATE_CHANGED, that triggers State
                     * Machines state changing
                     * Machines state changing
                     */
                     */
                    if (mNativeInterface.disconnectAudio(getByteAddress(mCurrentDevice))) {
                    if (mNativeInterface.disconnectAudio(mCurrentDevice)) {
                        routeHfpAudio(false);
                        routeHfpAudio(false);
                        returnAudioFocusIfNecessary();
                        returnAudioFocusIfNecessary();
                    }
                    }
@@ -1959,10 +1955,6 @@ public class HeadsetClientStateMachine extends StateMachine {
        return devices;
        return devices;
    }
    }


    private byte[] getByteAddress(BluetoothDevice device) {
        return Utils.getBytesFromAddress(device.getAddress());
    }

    public List<BluetoothHeadsetClientCall> getCurrentCalls() {
    public List<BluetoothHeadsetClientCall> getCurrentCalls() {
        return new ArrayList<BluetoothHeadsetClientCall>(mCalls.values());
        return new ArrayList<BluetoothHeadsetClientCall>(mCalls.values());
    }
    }
+45 −35
Original line number Original line Diff line number Diff line
@@ -20,12 +20,14 @@
 */
 */
package com.android.bluetooth.hfpclient;
package com.android.bluetooth.hfpclient;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.util.Log;
import android.util.Log;


import com.android.bluetooth.btservice.AdapterService;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;


import java.util.Objects;

/**
/**
 * Defines native calls that are used by state machine/service to either send or receive
 * Defines native calls that are used by state machine/service to either send or receive
 * messages to/from the native stack. This file is registered for the native methods in
 * messages to/from the native stack. This file is registered for the native methods in
@@ -34,12 +36,16 @@ import com.android.internal.annotations.VisibleForTesting;
public class NativeInterface {
public class NativeInterface {
    private static final String TAG = "NativeInterface";
    private static final String TAG = "NativeInterface";
    private static final boolean DBG = false;
    private static final boolean DBG = false;
    private AdapterService mAdapterService;


    static {
    static {
        classInitNative();
        classInitNative();
    }
    }


    private NativeInterface() {}
    private NativeInterface() {
        mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(),
                "AdapterService cannot be null when NativeInterface init");
    }
    private static NativeInterface sInterface;
    private static NativeInterface sInterface;
    private static final Object INSTANCE_LOCK = new Object();
    private static final Object INSTANCE_LOCK = new Object();


@@ -81,8 +87,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean connect(byte[] address) {
    public boolean connect(BluetoothDevice device) {
        return connectNative(address);
        return connectNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -92,8 +98,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean disconnect(byte[] address) {
    public boolean disconnect(BluetoothDevice device) {
        return disconnectNative(address);
        return disconnectNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -103,8 +109,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean connectAudio(byte[] address) {
    public boolean connectAudio(BluetoothDevice device) {
        return connectAudioNative(address);
        return connectAudioNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -113,8 +119,8 @@ public class NativeInterface {
     * @param address target device's address
     * @param address target device's address
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    public boolean disconnectAudio(byte[] address) {
    public boolean disconnectAudio(BluetoothDevice device) {
        return disconnectAudioNative(address);
        return disconnectAudioNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -124,8 +130,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean startVoiceRecognition(byte[] address) {
    public boolean startVoiceRecognition(BluetoothDevice device) {
        return startVoiceRecognitionNative(address);
        return startVoiceRecognitionNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -135,8 +141,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean stopVoiceRecognition(byte[] address) {
    public boolean stopVoiceRecognition(BluetoothDevice device) {
        return stopVoiceRecognitionNative(address);
        return stopVoiceRecognitionNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -149,8 +155,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean setVolume(byte[] address, int volumeType, int volume) {
    public boolean setVolume(BluetoothDevice device, int volumeType, int volume) {
        return setVolumeNative(address, volumeType, volume);
        return setVolumeNative(getByteAddress(device), volumeType, volume);
    }
    }


    /**
    /**
@@ -161,8 +167,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean dial(byte[] address, String number) {
    public boolean dial(BluetoothDevice device, String number) {
        return dialNative(address, number);
        return dialNative(getByteAddress(device), number);
    }
    }


    /**
    /**
@@ -173,8 +179,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean dialMemory(byte[] address, int location) {
    public boolean dialMemory(BluetoothDevice device, int location) {
        return dialMemoryNative(address, location);
        return dialMemoryNative(getByteAddress(device), location);
    }
    }


    /**
    /**
@@ -186,8 +192,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean handleCallAction(byte[] address, int action, int index) {
    public boolean handleCallAction(BluetoothDevice device, int action, int index) {
        return handleCallActionNative(address, action, index);
        return handleCallActionNative(getByteAddress(device), action, index);
    }
    }


    /**
    /**
@@ -197,8 +203,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean queryCurrentCalls(byte[] address) {
    public boolean queryCurrentCalls(BluetoothDevice device) {
        return queryCurrentCallsNative(address);
        return queryCurrentCallsNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -208,8 +214,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean queryCurrentOperatorName(byte[] address) {
    public boolean queryCurrentOperatorName(BluetoothDevice device) {
        return queryCurrentOperatorNameNative(address);
        return queryCurrentOperatorNameNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -219,8 +225,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public  boolean retrieveSubscriberInfo(byte[] address) {
    public  boolean retrieveSubscriberInfo(BluetoothDevice device) {
        return retrieveSubscriberInfoNative(address);
        return retrieveSubscriberInfoNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -231,8 +237,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean sendDtmf(byte[] address, byte code) {
    public boolean sendDtmf(BluetoothDevice device, byte code) {
        return sendDtmfNative(address, code);
        return sendDtmfNative(getByteAddress(device), code);
    }
    }


    /**
    /**
@@ -242,8 +248,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean requestLastVoiceTagNumber(byte[] address) {
    public boolean requestLastVoiceTagNumber(BluetoothDevice device) {
        return requestLastVoiceTagNumberNative(address);
        return requestLastVoiceTagNumberNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -256,8 +262,8 @@ public class NativeInterface {
     * @return True on success, False on failure
     * @return True on success, False on failure
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean sendATCmd(byte[] address, int atCmd, int val1, int val2, String arg) {
    public boolean sendATCmd(BluetoothDevice device, int atCmd, int val1, int val2, String arg) {
        return sendATCmdNative(address, atCmd, val1, val2, arg);
        return sendATCmdNative(getByteAddress(device), atCmd, val1, val2, arg);
    }
    }


    // Native methods that call into the JNI interface
    // Native methods that call into the JNI interface
@@ -301,7 +307,11 @@ public class NativeInterface {
            String arg);
            String arg);


    private BluetoothDevice getDevice(byte[] address) {
    private BluetoothDevice getDevice(byte[] address) {
        return BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        return mAdapterService.getDeviceFromByte(address);
    }

    private byte[] getByteAddress(BluetoothDevice device) {
        return mAdapterService.getByteIdentityAddress(device);
    }
    }


    // Callbacks from the native back into the java framework. All callbacks are routed via the
    // Callbacks from the native back into the java framework. All callbacks are routed via the
+1 −1
Original line number Original line Diff line number Diff line
@@ -112,7 +112,7 @@ class VendorCommandResponseProcessor {
            return false;
            return false;
        }
        }


        if (!mNativeInterface.sendATCmd(Utils.getBytesFromAddress(device.getAddress()),
        if (!mNativeInterface.sendATCmd(device,
                                        HeadsetClientHalConstants
                                        HeadsetClientHalConstants
                                        .HANDSFREECLIENT_AT_CMD_VENDOR_SPECIFIC_CMD,
                                        .HANDSFREECLIENT_AT_CMD_VENDOR_SPECIFIC_CMD,
                                        0, 0, atCommand)) {
                                        0, 0, atCommand)) {
+4 −4
Original line number Original line Diff line number Diff line
@@ -401,7 +401,7 @@ public class HeadsetClientStateMachineTest {
        mHeadsetClientStateMachine.sendMessage(msg);
        mHeadsetClientStateMachine.sendMessage(msg);


        verify(mNativeInterface, timeout(STANDARD_WAIT_MILLIS).times(1)).sendATCmd(
        verify(mNativeInterface, timeout(STANDARD_WAIT_MILLIS).times(1)).sendATCmd(
                Utils.getBytesFromAddress(mTestDevice.getAddress()),
                mTestDevice,
                HeadsetClientHalConstants.HANDSFREECLIENT_AT_CMD_VENDOR_SPECIFIC_CMD,
                HeadsetClientHalConstants.HANDSFREECLIENT_AT_CMD_VENDOR_SPECIFIC_CMD,
                0, 0, atCommand);
                0, 0, atCommand);
    }
    }
@@ -584,8 +584,8 @@ public class HeadsetClientStateMachineTest {
        // Setup connection state machine to be in connected state
        // Setup connection state machine to be in connected state
        when(mHeadsetClientService.getConnectionPolicy(any(BluetoothDevice.class))).thenReturn(
        when(mHeadsetClientService.getConnectionPolicy(any(BluetoothDevice.class))).thenReturn(
                BluetoothProfile.CONNECTION_POLICY_ALLOWED);
                BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        when(mNativeInterface.startVoiceRecognition(any(byte[].class))).thenReturn(true);
        doReturn(true).when(mNativeInterface).startVoiceRecognition(any(BluetoothDevice.class));
        when(mNativeInterface.stopVoiceRecognition(any(byte[].class))).thenReturn(true);
        doReturn(true).when(mNativeInterface).stopVoiceRecognition(any(BluetoothDevice.class));


        int expectedBroadcastIndex = 1;
        int expectedBroadcastIndex = 1;
        expectedBroadcastIndex = setUpHfpClientConnection(expectedBroadcastIndex);
        expectedBroadcastIndex = setUpHfpClientConnection(expectedBroadcastIndex);
@@ -653,7 +653,7 @@ public class HeadsetClientStateMachineTest {


        verify(mNativeInterface, timeout(STANDARD_WAIT_MILLIS).times(1))
        verify(mNativeInterface, timeout(STANDARD_WAIT_MILLIS).times(1))
                .sendATCmd(
                .sendATCmd(
                        Utils.getBytesFromAddress(mTestDevice.getAddress()),
                        mTestDevice,
                        HeadsetClientHalConstants.HANDSFREECLIENT_AT_CMD_BIEV,
                        HeadsetClientHalConstants.HANDSFREECLIENT_AT_CMD_BIEV,
                        indicator_id,
                        indicator_id,
                        indicator_value,
                        indicator_value,