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

Commit 9ea54131 authored by Chienyuan's avatar Chienyuan
Browse files

HFP: Choose proper address for native command/callback

Tag: #refactor
Bug: 197044261
Test: manual
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: Id31a0f9a39480b6d5f163c5e7d74c4a0079dc303
parent c42ae6ce
Loading
Loading
Loading
Loading
+31 −21
Original line number Original line Diff line number Diff line
@@ -20,9 +20,11 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.util.Log;
import android.util.Log;


import com.android.bluetooth.Utils;
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
@@ -39,8 +41,12 @@ public class HeadsetNativeInterface {


    private static HeadsetNativeInterface sInterface;
    private static HeadsetNativeInterface sInterface;
    private static final Object INSTANCE_LOCK = new Object();
    private static final Object INSTANCE_LOCK = new Object();
    private AdapterService mAdapterService;


    private HeadsetNativeInterface() {}
    private HeadsetNativeInterface() {
        mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(),
                "AdapterService cannot be null when HeadsetNativeInterface init");
    }


    /**
    /**
     * This class is a singleton because native library should only be loaded once
     * This class is a singleton because native library should only be loaded once
@@ -68,7 +74,11 @@ public class HeadsetNativeInterface {
    }
    }


    private BluetoothDevice getDevice(byte[] address) {
    private BluetoothDevice getDevice(byte[] address) {
        return mAdapter.getRemoteDevice(Utils.getAddressStringFromByte(address));
        return mAdapterService.getDeviceFromByte(address);
    }

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


    void onConnectionStateChanged(int state, byte[] address) {
    void onConnectionStateChanged(int state, byte[] address) {
@@ -238,7 +248,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean atResponseCode(BluetoothDevice device, int responseCode, int errorCode) {
    public boolean atResponseCode(BluetoothDevice device, int responseCode, int errorCode) {
        return atResponseCodeNative(responseCode, errorCode, Utils.getByteAddress(device));
        return atResponseCodeNative(responseCode, errorCode, getByteAddress(device));
    }
    }


    /**
    /**
@@ -250,7 +260,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean atResponseString(BluetoothDevice device, String responseString) {
    public boolean atResponseString(BluetoothDevice device, String responseString) {
        return atResponseStringNative(responseString, Utils.getByteAddress(device));
        return atResponseStringNative(responseString, getByteAddress(device));
    }
    }


    /**
    /**
@@ -261,7 +271,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean connectHfp(BluetoothDevice device) {
    public boolean connectHfp(BluetoothDevice device) {
        return connectHfpNative(Utils.getByteAddress(device));
        return connectHfpNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -272,7 +282,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean disconnectHfp(BluetoothDevice device) {
    public boolean disconnectHfp(BluetoothDevice device) {
        return disconnectHfpNative(Utils.getByteAddress(device));
        return disconnectHfpNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -283,7 +293,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean connectAudio(BluetoothDevice device) {
    public boolean connectAudio(BluetoothDevice device) {
        return connectAudioNative(Utils.getByteAddress(device));
        return connectAudioNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -294,7 +304,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean disconnectAudio(BluetoothDevice device) {
    public boolean disconnectAudio(BluetoothDevice device) {
        return disconnectAudioNative(Utils.getByteAddress(device));
        return disconnectAudioNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -305,7 +315,7 @@ public class HeadsetNativeInterface {
     * @return true if the device support echo cancellation or noise reduction, false otherwise
     * @return true if the device support echo cancellation or noise reduction, false otherwise
     */
     */
    public boolean isNoiseReductionSupported(BluetoothDevice device) {
    public boolean isNoiseReductionSupported(BluetoothDevice device) {
        return isNoiseReductionSupportedNative(Utils.getByteAddress(device));
        return isNoiseReductionSupportedNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -315,7 +325,7 @@ public class HeadsetNativeInterface {
     * @return true if the device supports voice recognition, false otherwise
     * @return true if the device supports voice recognition, false otherwise
     */
     */
    public boolean isVoiceRecognitionSupported(BluetoothDevice device) {
    public boolean isVoiceRecognitionSupported(BluetoothDevice device) {
        return isVoiceRecognitionSupportedNative(Utils.getByteAddress(device));
        return isVoiceRecognitionSupportedNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -326,7 +336,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean startVoiceRecognition(BluetoothDevice device) {
    public boolean startVoiceRecognition(BluetoothDevice device) {
        return startVoiceRecognitionNative(Utils.getByteAddress(device));
        return startVoiceRecognitionNative(getByteAddress(device));
    }
    }




@@ -338,7 +348,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean stopVoiceRecognition(BluetoothDevice device) {
    public boolean stopVoiceRecognition(BluetoothDevice device) {
        return stopVoiceRecognitionNative(Utils.getByteAddress(device));
        return stopVoiceRecognitionNative(getByteAddress(device));
    }
    }


    /**
    /**
@@ -351,7 +361,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean setVolume(BluetoothDevice device, int volumeType, int volume) {
    public boolean setVolume(BluetoothDevice device, int volumeType, int volume) {
        return setVolumeNative(volumeType, volume, Utils.getByteAddress(device));
        return setVolumeNative(volumeType, volume, getByteAddress(device));
    }
    }


    /**
    /**
@@ -371,7 +381,7 @@ public class HeadsetNativeInterface {
    public boolean cindResponse(BluetoothDevice device, int service, int numActive, int numHeld,
    public boolean cindResponse(BluetoothDevice device, int service, int numActive, int numHeld,
            int callState, int signal, int roam, int batteryCharge) {
            int callState, int signal, int roam, int batteryCharge) {
        return cindResponseNative(service, numActive, numHeld, callState, signal, roam,
        return cindResponseNative(service, numActive, numHeld, callState, signal, roam,
                batteryCharge, Utils.getByteAddress(device));
                batteryCharge, getByteAddress(device));
    }
    }


    /**
    /**
@@ -384,7 +394,7 @@ public class HeadsetNativeInterface {
    @VisibleForTesting
    @VisibleForTesting
    public boolean notifyDeviceStatus(BluetoothDevice device, HeadsetDeviceState deviceState) {
    public boolean notifyDeviceStatus(BluetoothDevice device, HeadsetDeviceState deviceState) {
        return notifyDeviceStatusNative(deviceState.mService, deviceState.mRoam,
        return notifyDeviceStatusNative(deviceState.mService, deviceState.mRoam,
                deviceState.mSignal, deviceState.mBatteryCharge, Utils.getByteAddress(device));
                deviceState.mSignal, deviceState.mBatteryCharge, getByteAddress(device));
    }
    }


    /**
    /**
@@ -410,7 +420,7 @@ public class HeadsetNativeInterface {
    public boolean clccResponse(BluetoothDevice device, int index, int dir, int status, int mode,
    public boolean clccResponse(BluetoothDevice device, int index, int dir, int status, int mode,
            boolean mpty, String number, int type) {
            boolean mpty, String number, int type) {
        return clccResponseNative(index, dir, status, mode, mpty, number, type,
        return clccResponseNative(index, dir, status, mode, mpty, number, type,
                Utils.getByteAddress(device));
                getByteAddress(device));
    }
    }


    /**
    /**
@@ -422,7 +432,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean copsResponse(BluetoothDevice device, String operatorName) {
    public boolean copsResponse(BluetoothDevice device, String operatorName) {
        return copsResponseNative(operatorName, Utils.getByteAddress(device));
        return copsResponseNative(operatorName, getByteAddress(device));
    }
    }


    /**
    /**
@@ -441,7 +451,7 @@ public class HeadsetNativeInterface {
    public boolean phoneStateChange(BluetoothDevice device, HeadsetCallState callState) {
    public boolean phoneStateChange(BluetoothDevice device, HeadsetCallState callState) {
        return phoneStateChangeNative(callState.mNumActive, callState.mNumHeld,
        return phoneStateChangeNative(callState.mNumActive, callState.mNumHeld,
                callState.mCallState, callState.mNumber, callState.mType, callState.mName,
                callState.mCallState, callState.mNumber, callState.mType, callState.mName,
                Utils.getByteAddress(device));
                getByteAddress(device));
    }
    }


    /**
    /**
@@ -464,7 +474,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean sendBsir(BluetoothDevice device, boolean value) {
    public boolean sendBsir(BluetoothDevice device, boolean value) {
        return sendBsirNative(value, Utils.getByteAddress(device));
        return sendBsirNative(value, getByteAddress(device));
    }
    }


    /**
    /**
@@ -474,7 +484,7 @@ public class HeadsetNativeInterface {
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public boolean setActiveDevice(BluetoothDevice device) {
    public boolean setActiveDevice(BluetoothDevice device) {
        return setActiveDeviceNative(Utils.getByteAddress(device));
        return setActiveDeviceNative(getByteAddress(device));
    }
    }


    /* Native methods */
    /* Native methods */
+1 −1
Original line number Original line Diff line number Diff line
@@ -124,7 +124,7 @@ public class PanService extends ProfileService {
    @Override
    @Override
    protected boolean start() {
    protected boolean start() {
        mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(),
        mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(),
                "AdapterService cannot be null when HeadsetService starts");
                "AdapterService cannot be null when PanService starts");
        mDatabaseManager = Objects.requireNonNull(AdapterService.getAdapterService().getDatabase(),
        mDatabaseManager = Objects.requireNonNull(AdapterService.getAdapterService().getDatabase(),
                "DatabaseManager cannot be null when PanService starts");
                "DatabaseManager cannot be null when PanService starts");