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

Commit 66614281 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Replace profile-based calls to setActiveDevice with BluetoothAdapter...

Replace profile-based calls to setActiveDevice with BluetoothAdapter setActiveDevice in Telecom code and tests am: d4c99ad0 am: 4a9e8104

Change-Id: I95a23bcef9055342716e18071f24add7378288cf
parents 3e7af2d9 4a9e8104
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.telecom;
package com.android.server.telecom;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Context;


@@ -37,4 +38,11 @@ public class BluetoothAdapterProxy {
        }
        }
        return mBluetoothAdapter.getProfileProxy(context, listener, profile);
        return mBluetoothAdapter.getProfileProxy(context, listener, profile);
    }
    }

    public boolean setActiveDevice(BluetoothDevice device, int profiles) {
        if (mBluetoothAdapter == null) {
            return false;
        }
        return mBluetoothAdapter.setActiveDevice(device, profiles);
    }
}
}
+13 −5
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.server.telecom.bluetooth;
package com.android.server.telecom.bluetooth;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothHearingAid;
@@ -119,9 +120,11 @@ public class BluetoothDeviceManager {
    private BluetoothHeadsetProxy mBluetoothHeadsetService;
    private BluetoothHeadsetProxy mBluetoothHeadsetService;
    private BluetoothHearingAid mBluetoothHearingAidService;
    private BluetoothHearingAid mBluetoothHearingAidService;
    private BluetoothDevice mBluetoothHearingAidActiveDeviceCache;
    private BluetoothDevice mBluetoothHearingAidActiveDeviceCache;
    private BluetoothAdapterProxy mBluetoothAdapterProxy;


    public BluetoothDeviceManager(Context context, BluetoothAdapterProxy bluetoothAdapter) {
    public BluetoothDeviceManager(Context context, BluetoothAdapterProxy bluetoothAdapter) {
        if (bluetoothAdapter != null) {
        if (bluetoothAdapter != null) {
            mBluetoothAdapterProxy = bluetoothAdapter;
            bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener,
            bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener,
                    BluetoothProfile.HEADSET);
                    BluetoothProfile.HEADSET);
            bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener,
            bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener,
@@ -246,7 +249,8 @@ public class BluetoothDeviceManager {
        } else {
        } else {
            for (BluetoothDevice device : mBluetoothHearingAidService.getActiveDevices()) {
            for (BluetoothDevice device : mBluetoothHearingAidService.getActiveDevices()) {
                if (device != null) {
                if (device != null) {
                    mBluetoothHearingAidService.setActiveDevice(null);
                    mBluetoothAdapterProxy.setActiveDevice(null,
                        BluetoothAdapter.ACTIVE_DEVICE_ALL);
                }
                }
            }
            }
        }
        }
@@ -269,15 +273,17 @@ public class BluetoothDeviceManager {
                Log.w(this, "Attempting to turn on audio when the hearing aid service is null");
                Log.w(this, "Attempting to turn on audio when the hearing aid service is null");
                return false;
                return false;
            }
            }
            return mBluetoothHearingAidService.setActiveDevice(
            return mBluetoothAdapterProxy.setActiveDevice(
                    mHearingAidDevicesByAddress.get(address));
                    mHearingAidDevicesByAddress.get(address),
                    BluetoothAdapter.ACTIVE_DEVICE_ALL);
        } else if (mHfpDevicesByAddress.containsKey(address)) {
        } else if (mHfpDevicesByAddress.containsKey(address)) {
            BluetoothDevice device = mHfpDevicesByAddress.get(address);
            BluetoothDevice device = mHfpDevicesByAddress.get(address);
            if (mBluetoothHeadsetService == null) {
            if (mBluetoothHeadsetService == null) {
                Log.w(this, "Attempting to turn on audio when the headset service is null");
                Log.w(this, "Attempting to turn on audio when the headset service is null");
                return false;
                return false;
            }
            }
            boolean success = mBluetoothHeadsetService.setActiveDevice(device);
            boolean success = mBluetoothAdapterProxy.setActiveDevice(device,
                BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL);
            if (!success) {
            if (!success) {
                Log.w(this, "Couldn't set active device to %s", address);
                Log.w(this, "Couldn't set active device to %s", address);
                return false;
                return false;
@@ -304,7 +310,9 @@ public class BluetoothDeviceManager {


    public void restoreHearingAidDevice() {
    public void restoreHearingAidDevice() {
        if (mBluetoothHearingAidActiveDeviceCache != null && mBluetoothHearingAidService != null) {
        if (mBluetoothHearingAidActiveDeviceCache != null && mBluetoothHearingAidService != null) {
            mBluetoothHearingAidService.setActiveDevice(mBluetoothHearingAidActiveDeviceCache);
            mBluetoothAdapterProxy.setActiveDevice(
                mBluetoothHearingAidActiveDeviceCache,
                BluetoothAdapter.ACTIVE_DEVICE_ALL);
            mBluetoothHearingAidActiveDeviceCache = null;
            mBluetoothHearingAidActiveDeviceCache = null;
        }
        }
    }
    }
+7 −8
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.server.telecom.tests;
package com.android.server.telecom.tests;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothHearingAid;
@@ -215,12 +216,10 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
    public void testConnectDisconnectAudioHeadset() {
    public void testConnectDisconnectAudioHeadset() {
        receiverUnderTest.onReceive(mContext,
        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1, false));
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1, false));
        when(mHeadsetProxy.setActiveDevice(nullable(BluetoothDevice.class))).thenReturn(true);
        when(mAdapterProxy.setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL))).thenReturn(true);
        mBluetoothDeviceManager.connectAudio(device1.getAddress());
        mBluetoothDeviceManager.connectAudio(device1.getAddress());
        verify(mHeadsetProxy).setActiveDevice(device1);
        verify(mAdapterProxy).setActiveDevice(device1, BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL);
        verify(mHeadsetProxy).connectAudio();
        verify(mAdapterProxy, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL));
        verify(mBluetoothHearingAid, never()).setActiveDevice(nullable(BluetoothDevice.class));

        mBluetoothDeviceManager.disconnectAudio();
        mBluetoothDeviceManager.disconnectAudio();
        verify(mHeadsetProxy).disconnectAudio();
        verify(mHeadsetProxy).disconnectAudio();
    }
    }
@@ -231,14 +230,14 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        receiverUnderTest.onReceive(mContext,
        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2, true));
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2, true));
        mBluetoothDeviceManager.connectAudio(device2.getAddress());
        mBluetoothDeviceManager.connectAudio(device2.getAddress());
        verify(mBluetoothHearingAid).setActiveDevice(device2);
        verify(mAdapterProxy).setActiveDevice(device2, BluetoothAdapter.ACTIVE_DEVICE_ALL);
        verify(mHeadsetProxy, never()).connectAudio();
        verify(mHeadsetProxy, never()).connectAudio();
        verify(mHeadsetProxy, never()).setActiveDevice(nullable(BluetoothDevice.class));
        verify(mAdapterProxy, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL));


        when(mBluetoothHearingAid.getActiveDevices()).thenReturn(Arrays.asList(device2, null));
        when(mBluetoothHearingAid.getActiveDevices()).thenReturn(Arrays.asList(device2, null));


        mBluetoothDeviceManager.disconnectAudio();
        mBluetoothDeviceManager.disconnectAudio();
        verify(mBluetoothHearingAid).setActiveDevice(null);
        verify(mAdapterProxy).setActiveDevice(null, BluetoothAdapter.ACTIVE_DEVICE_ALL);
        verify(mHeadsetProxy).disconnectAudio();
        verify(mHeadsetProxy).disconnectAudio();
    }
    }