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

Commit 64d3a4e2 authored by Hall Liu's avatar Hall Liu Committed by Gerrit Code Review
Browse files

Merge changes Ib66706ca,Ibd7c7f97

* changes:
  Create new list of BT devices when querying
  Integrate the BT multi-hfp apis with Telecom
parents 5160d525 b56a9951
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -60,11 +60,18 @@ public class BluetoothHeadsetProxy {
        return mBluetoothHeadset.isAudioConnected(device);
    }

    public boolean connectAudio(String deviceAddress) {
        // TODO: update once the BT stack has this api.
    public boolean connectAudio() {
        return mBluetoothHeadset.connectAudio();
    }

    public boolean setActiveDevice(BluetoothDevice device) {
        return mBluetoothHeadset.setActiveDevice(device);
    }

    public boolean isAudioOn() {
        return mBluetoothHeadset.isAudioOn();
    }

    public boolean disconnectAudio() {
        return mBluetoothHeadset.disconnectAudio();
    }
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.media.IAudioService;
import android.os.Binder;
import android.os.Message;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.telecom.CallAudioState;
import android.telecom.Log;
@@ -789,7 +788,8 @@ public class CallAudioRouteStateMachine extends StateMachine {
                    }
                    return HANDLED;
                case BT_AUDIO_CONNECTED:
                    // Nothing to do
                    // Update the in-call app on the new active BT device in case that changed.
                    updateSystemAudioState();
                    return HANDLED;
                case SWITCH_BLUETOOTH:
                case USER_SWITCH_BLUETOOTH:
+4 −0
Original line number Diff line number Diff line
@@ -129,6 +129,10 @@ public class BluetoothDeviceManager {
        mBluetoothHeadsetService = bluetoothHeadset;
    }

    public BluetoothDevice getDeviceFromAddress(String address) {
        return mConnectedDevicesByAddress.get(address);
    }

    void onDeviceConnected(BluetoothDevice device) {
        synchronized (mLock) {
            if (!mConnectedDevicesByAddress.containsKey(device.getAddress())) {
+19 −8
Original line number Diff line number Diff line
@@ -17,11 +17,7 @@
package com.android.server.telecom.bluetooth;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Message;
import android.telecom.Log;
import android.telecom.Logging.Session;
@@ -36,7 +32,9 @@ import com.android.server.telecom.BluetoothHeadsetProxy;
import com.android.server.telecom.TelecomSystem;
import com.android.server.telecom.Timeouts;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
@@ -567,7 +565,7 @@ public class BluetoothRouteManager extends StateMachine {
        sendMessage(NEW_DEVICE_CONNECTED, args);

        mListener.onBluetoothDeviceListChanged();
        if (getConnectedDevices().size() == 1) {
        if (mDeviceManager.getConnectedDevices().size() == 1) {
            mListener.onBluetoothDeviceAvailable();
        }
    }
@@ -579,13 +577,14 @@ public class BluetoothRouteManager extends StateMachine {
        sendMessage(LOST_DEVICE, args);

        mListener.onBluetoothDeviceListChanged();
        if (getConnectedDevices().size() == 0) {
        if (mDeviceManager.getConnectedDevices().size() == 0) {
            mListener.onBluetoothDeviceUnavailable();
        }
    }

    public Collection<BluetoothDevice> getConnectedDevices() {
        return mDeviceManager.getConnectedDevices();
        return Collections.unmodifiableCollection(
                new ArrayList<>(mDeviceManager.getConnectedDevices()));
    }

    private String connectHfpAudio(String address) {
@@ -712,7 +711,19 @@ public class BluetoothRouteManager extends StateMachine {
            Log.w(this, "Trying to connect audio but no headset service exists.");
            return false;
        }
        return bluetoothHeadset.connectAudio(address);
        BluetoothDevice device = mDeviceManager.getDeviceFromAddress(address);
        if (device == null) {
            Log.w(this, "Attempting to turn on audio for a disconnected device");
            return false;
        }
        if (!bluetoothHeadset.setActiveDevice(device)) {
            Log.w(LOG_TAG, "Couldn't set active device to %s", address);
            return false;
        }
        if (!bluetoothHeadset.isAudioOn()) {
            return bluetoothHeadset.connectAudio();
        }
        return true;
    }

    private void disconnectAudio() {
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
        android:minSdkVersion="23"
        android:targetSdkVersion="23" />

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.CONTROL_INCALL_EXPERIENCE" />
Loading