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

Commit 9691e3d8 authored by Leslie Watkins's avatar Leslie Watkins Committed by Automerger Merge Worker
Browse files

Merge "Add mockable BluetoothHeadsetClientProxy to allow for testing." am: 9b563ba7

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1751554

Change-Id: I0166cbcf0cf1c25846a636effc8d55cb192eb044
parents 60c10aec 9b563ba7
Loading
Loading
Loading
Loading
+102 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.bluetooth.hfpclient.connserv;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothHeadsetClientCall;
import android.os.Bundle;

import java.util.List;

/**
 * A mockable proxy class that facilitates testing of the {@code hfpclient.connserv} package.
 *
 * <p>This is necessary due to the "final" attribute of the BluetoothHeadsetClient class.
 */
public class BluetoothHeadsetClientProxy {

    private final BluetoothHeadsetClient mBluetoothHeadsetClient;

    public BluetoothHeadsetClientProxy(BluetoothHeadsetClient bluetoothHeadsetClient) {
        mBluetoothHeadsetClient = bluetoothHeadsetClient;
    }

    public BluetoothHeadsetClient getProxiedBluetoothHeadsetClient() {
        return mBluetoothHeadsetClient;
    }

    /** @see BluetoothHeadsetClient#dial(BluetoothDevice, String) */
    public BluetoothHeadsetClientCall dial(BluetoothDevice device, String number) {
        return mBluetoothHeadsetClient.dial(device, number);
    }

    /** @see BluetoothHeadsetClient#enterPrivateMode(BluetoothDevice, int) */
    public boolean enterPrivateMode(BluetoothDevice device, int index) {
        return mBluetoothHeadsetClient.enterPrivateMode(device, index);
    }

    /** @see BluetoothHeadsetClient#sendDTMF(BluetoothDevice, byte) */
    public boolean sendDTMF(BluetoothDevice device, byte code) {
        return mBluetoothHeadsetClient.sendDTMF(device, code);
    }

    /** @see BluetoothHeadsetClient#terminateCall(BluetoothDevice, BluetoothHeadsetClientCall) */
    public boolean terminateCall(BluetoothDevice device, BluetoothHeadsetClientCall call) {
        return mBluetoothHeadsetClient.terminateCall(device, call);
    }

    /** @see BluetoothHeadsetClient#holdCall(BluetoothDevice) */
    public boolean holdCall(BluetoothDevice device) {
        return mBluetoothHeadsetClient.holdCall(device);
    }

    /** @see BluetoothHeadsetClient#acceptCall(BluetoothDevice, int) */
    public boolean acceptCall(BluetoothDevice device, int flag) {
        return mBluetoothHeadsetClient.acceptCall(device, flag);
    }

    /** @see BluetoothHeadsetClient#rejectCall(BluetoothDevice) */
    public boolean rejectCall(BluetoothDevice device) {
        return mBluetoothHeadsetClient.rejectCall(device);
    }

    /** @see BluetoothHeadsetClient#connectAudio(BluetoothDevice) */
    public boolean connectAudio(BluetoothDevice device) {
        return mBluetoothHeadsetClient.connectAudio(device);
    }

    /** @see BluetoothHeadsetClient#disconnectAudio(BluetoothDevice) */
    public boolean disconnectAudio(BluetoothDevice device) {
        return mBluetoothHeadsetClient.disconnectAudio(device);
    }

    /** @see BluetoothHeadsetClient#getCurrentAgEvents(BluetoothDevice) */
    public Bundle getCurrentAgEvents(BluetoothDevice device) {
        return mBluetoothHeadsetClient.getCurrentAgEvents(device);
    }

    /** @see BluetoothHeadsetClient#getConnectedDevices() */
    public List<BluetoothDevice> getConnectedDevices() {
        return mBluetoothHeadsetClient.getConnectedDevices();
    }

    /** @see BluetoothHeadsetClient#getCurrentCalls(BluetoothDevice) */
    public List<BluetoothHeadsetClientCall> getCurrentCalls(BluetoothDevice device) {
        return mBluetoothHeadsetClient.getCurrentCalls(device);
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.bluetooth.hfpclient.connserv;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.hfpclient.connserv.BluetoothHeadsetClientProxy;
import android.telecom.Conference;
import android.telecom.Connection;
import android.telecom.PhoneAccountHandle;
@@ -26,10 +27,10 @@ public class HfpClientConference extends Conference {
    private static final String TAG = "HfpClientConference";

    private BluetoothDevice mDevice;
    private BluetoothHeadsetClient mHeadsetProfile;
    private BluetoothHeadsetClientProxy mHeadsetProfile;

    public HfpClientConference(PhoneAccountHandle handle, BluetoothDevice device,
            BluetoothHeadsetClient client) {
            BluetoothHeadsetClientProxy client) {
        super(handle);
        mDevice = device;
        mHeadsetProfile = client;
+4 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.bluetooth.hfpclient.connserv;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothHeadsetClientCall;
import android.bluetooth.hfpclient.connserv.BluetoothHeadsetClientProxy;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
@@ -40,7 +41,7 @@ public class HfpClientConnection extends Connection {

    private final Context mContext;
    private final BluetoothDevice mDevice;
    private BluetoothHeadsetClient mHeadsetProfile;
    private BluetoothHeadsetClientProxy mHeadsetProfile;
    private HfpClientConnectionService mHfpClientConnectionService;

    private BluetoothHeadsetClientCall mCurrentCall;
@@ -54,7 +55,7 @@ public class HfpClientConnection extends Connection {
    // Constructor to be used when there's an existing call (such as that created on the AG or
    // when connection happens and we see calls for the first time).
    public HfpClientConnection(Context context, BluetoothDevice device,
            BluetoothHeadsetClient client, BluetoothHeadsetClientCall call) {
            BluetoothHeadsetClientProxy client, BluetoothHeadsetClientCall call) {
        mDevice = device;
        mContext = context;
        mHeadsetProfile = client;
@@ -72,7 +73,7 @@ public class HfpClientConnection extends Connection {
    // Constructor to be used when a call is intiated on the HF. The call handle is obtained by
    // using the dial() command.
    public HfpClientConnection(Context context, BluetoothDevice device,
            BluetoothHeadsetClient client, Uri number) {
            BluetoothHeadsetClientProxy client, Uri number) {
        mDevice = device;
        mContext = context;
        mHeadsetProfile = client;
+8 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothHeadsetClientCall;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.hfpclient.connserv.BluetoothHeadsetClientProxy;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -53,7 +54,7 @@ public class HfpClientConnectionService extends ConnectionService {
    private BluetoothAdapter mAdapter;

    // BluetoothHeadset proxy.
    private BluetoothHeadsetClient mHeadsetProfile;
    private BluetoothHeadsetClientProxy mHeadsetProfile;
    private TelecomManager mTelecomManager;

    private final Map<BluetoothDevice, HfpClientDeviceBlock> mDeviceBlocks = new HashMap<>();
@@ -145,7 +146,8 @@ public class HfpClientConnectionService extends ConnectionService {
        }
        // Close the profile.
        if (mHeadsetProfile != null) {
            mAdapter.closeProfileProxy(BluetoothProfile.HEADSET_CLIENT, mHeadsetProfile);
            mAdapter.closeProfileProxy(BluetoothProfile.HEADSET_CLIENT,
                    mHeadsetProfile.getProxiedBluetoothHeadsetClient());
        }

        // Unregister the broadcast receiver.
@@ -286,7 +288,7 @@ public class HfpClientConnectionService extends ConnectionService {
            if (DBG) {
                Log.d(TAG, "onServiceConnected");
            }
            mHeadsetProfile = (BluetoothHeadsetClient) proxy;
            mHeadsetProfile = new BluetoothHeadsetClientProxy((BluetoothHeadsetClient) proxy);

            List<BluetoothDevice> devices = mHeadsetProfile.getConnectedDevices();
            if (devices == null) {
@@ -366,7 +368,9 @@ public class HfpClientConnectionService extends ConnectionService {
        return account;
    }

    public static boolean hasHfpClientEcc(BluetoothHeadsetClient client, BluetoothDevice device) {
    /** Checks if device has Enhanced Call Control (ECC) feature. */
    public static boolean hasHfpClientEcc(BluetoothHeadsetClientProxy client,
            BluetoothDevice device) {
        Bundle features = client.getCurrentAgEvents(device);
        return features != null && features.getBoolean(BluetoothHeadsetClient.EXTRA_AG_FEATURE_ECC,
                false);
+3 −3
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@
package com.android.bluetooth.hfpclient.connserv;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothHeadsetClientCall;
import android.bluetooth.hfpclient.connserv.BluetoothHeadsetClientProxy;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
@@ -48,10 +48,10 @@ public class HfpClientDeviceBlock {
    private final HfpClientConnectionService mConnServ;
    private HfpClientConference mConference;

    private BluetoothHeadsetClient mHeadsetProfile;
    private BluetoothHeadsetClientProxy mHeadsetProfile;

    HfpClientDeviceBlock(HfpClientConnectionService connServ, BluetoothDevice device,
            BluetoothHeadsetClient headsetProfile) {
            BluetoothHeadsetClientProxy headsetProfile) {
        mConnServ = connServ;
        mContext = connServ;
        mDevice = device;