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

Commit ac935c47 authored by Hall Liu's avatar Hall Liu Committed by android-build-merger
Browse files

Replace BluetoothManager (multi-hfp part 3) am: 486cb197

am: d1b47792

Change-Id: I6fda12d25190b09969e8d83140ad88668a19558a
parents 14da17ff d1b47792
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -16,66 +16,68 @@

package com.android.server.telecom;

import com.android.server.telecom.bluetooth.BluetoothRouteManager;

/**
 * A class that acts as a listener to things that could change call audio routing, namely
 * bluetooth status, wired headset status, and dock status.
 */
public class CallAudioRoutePeripheralAdapter implements WiredHeadsetManager.Listener,
        DockManager.Listener, BluetoothManager.BluetoothStateListener {
        DockManager.Listener, BluetoothRouteManager.BluetoothStateListener {

    private final CallAudioRouteStateMachine mCallAudioRouteStateMachine;
    private final BluetoothManager mBluetoothManager;
    private final BluetoothRouteManager mBluetoothRouteManager;

    public CallAudioRoutePeripheralAdapter(
            CallAudioRouteStateMachine callAudioRouteStateMachine,
            BluetoothManager bluetoothManager,
            BluetoothRouteManager bluetoothManager,
            WiredHeadsetManager wiredHeadsetManager,
            DockManager dockManager) {
        mCallAudioRouteStateMachine = callAudioRouteStateMachine;
        mBluetoothManager = bluetoothManager;
        mBluetoothRouteManager = bluetoothManager;

        mBluetoothManager.setBluetoothStateListener(this);
        mBluetoothRouteManager.setListener(this);
        wiredHeadsetManager.addListener(this);
        dockManager.addListener(this);
    }

    public boolean isBluetoothAudioOn() {
        return mBluetoothManager.isBluetoothAudioConnected();
        return mBluetoothRouteManager.isBluetoothAudioConnectedOrPending();
    }

    @Override
    public void onBluetoothStateChange(int oldState, int newState) {
        switch (oldState) {
            case BluetoothManager.BLUETOOTH_DISCONNECTED:
            case BluetoothManager.BLUETOOTH_UNINITIALIZED:
            case BluetoothRouteManager.BLUETOOTH_DISCONNECTED:
            case BluetoothRouteManager.BLUETOOTH_UNINITIALIZED:
                switch (newState) {
                    case BluetoothManager.BLUETOOTH_DEVICE_CONNECTED:
                    case BluetoothManager.BLUETOOTH_AUDIO_CONNECTED:
                    case BluetoothRouteManager.BLUETOOTH_DEVICE_CONNECTED:
                    case BluetoothRouteManager.BLUETOOTH_AUDIO_CONNECTED:
                        mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
                                CallAudioRouteStateMachine.CONNECT_BLUETOOTH);
                        break;
                }
                break;
            case BluetoothManager.BLUETOOTH_DEVICE_CONNECTED:
            case BluetoothRouteManager.BLUETOOTH_DEVICE_CONNECTED:
                switch (newState) {
                    case BluetoothManager.BLUETOOTH_DISCONNECTED:
                    case BluetoothRouteManager.BLUETOOTH_DISCONNECTED:
                        mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
                                CallAudioRouteStateMachine.DISCONNECT_BLUETOOTH);
                        break;
                    case BluetoothManager.BLUETOOTH_AUDIO_CONNECTED:
                    case BluetoothRouteManager.BLUETOOTH_AUDIO_CONNECTED:
                        mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
                                CallAudioRouteStateMachine.SWITCH_BLUETOOTH);
                        break;
                }
                break;
            case BluetoothManager.BLUETOOTH_AUDIO_CONNECTED:
            case BluetoothManager.BLUETOOTH_AUDIO_PENDING:
            case BluetoothRouteManager.BLUETOOTH_AUDIO_CONNECTED:
            case BluetoothRouteManager.BLUETOOTH_AUDIO_PENDING:
                switch (newState) {
                    case BluetoothManager.BLUETOOTH_DISCONNECTED:
                    case BluetoothRouteManager.BLUETOOTH_DISCONNECTED:
                        mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
                                CallAudioRouteStateMachine.DISCONNECT_BLUETOOTH);
                        break;
                    case BluetoothManager.BLUETOOTH_DEVICE_CONNECTED:
                    case BluetoothRouteManager.BLUETOOTH_DEVICE_CONNECTED:
                        mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
                                CallAudioRouteStateMachine.BT_AUDIO_DISCONNECT);
                        break;
+13 −12
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.util.SparseArray;
import com.android.internal.util.IState;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.server.telecom.bluetooth.BluetoothRouteManager;

import java.util.HashMap;

@@ -829,6 +830,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
            super.enter();
            mHasUserExplicitlyLeftBluetooth = false;
            updateInternalCallAudioState();
            setBluetoothOn(false);
        }

        @Override
@@ -1135,7 +1137,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
    private final Context mContext;
    private final CallsManager mCallsManager;
    private final AudioManager mAudioManager;
    private final BluetoothManager mBluetoothManager;
    private final BluetoothRouteManager mBluetoothRouteManager;
    private final WiredHeadsetManager mWiredHeadsetManager;
    private final StatusBarNotifier mStatusBarNotifier;
    private final CallAudioManager.AudioServiceFactory mAudioServiceFactory;
@@ -1155,7 +1157,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
    public CallAudioRouteStateMachine(
            Context context,
            CallsManager callsManager,
            BluetoothManager bluetoothManager,
            BluetoothRouteManager bluetoothManager,
            WiredHeadsetManager wiredHeadsetManager,
            StatusBarNotifier statusBarNotifier,
            CallAudioManager.AudioServiceFactory audioServiceFactory,
@@ -1175,7 +1177,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
        mContext = context;
        mCallsManager = callsManager;
        mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        mBluetoothManager = bluetoothManager;
        mBluetoothRouteManager = bluetoothManager;
        mWiredHeadsetManager = wiredHeadsetManager;
        mStatusBarNotifier = statusBarNotifier;
        mAudioServiceFactory = audioServiceFactory;
@@ -1290,7 +1292,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
                return;
            default:
                Log.e(this, new IllegalStateException(),
                        "Unexpected message code");
                        "Unexpected message code %d", msg.what);
        }
    }

@@ -1350,14 +1352,13 @@ public class CallAudioRouteStateMachine extends StateMachine {
    }

    private void setBluetoothOn(boolean on) {
        if (mBluetoothManager.isBluetoothAvailable()) {
            boolean isAlreadyOn = mBluetoothManager.isBluetoothAudioConnectedOrPending();
            if (on != isAlreadyOn) {
        if (mBluetoothRouteManager.isBluetoothAvailable()) {
            if (on != mBluetoothRouteManager.isBluetoothAudioConnectedOrPending()) {
                Log.i(this, "connecting bluetooth %s", on);
                if (on) {
                    mBluetoothManager.connectBluetoothAudio();
                    mBluetoothRouteManager.connectBluetoothAudio(null /*TODO: add real address*/);
                } else {
                    mBluetoothManager.disconnectBluetoothAudio();
                    mBluetoothRouteManager.disconnectBluetoothAudio();
                }
            }
        }
@@ -1365,8 +1366,8 @@ public class CallAudioRouteStateMachine extends StateMachine {

    private void setMuteOn(boolean mute) {
        mIsMuted = mute;
        Log.addEvent(mCallsManager.getForegroundCall(), mute ? LogUtils.Events.MUTE : LogUtils.Events.UNMUTE);

        Log.addEvent(mCallsManager.getForegroundCall(), mute ?
                LogUtils.Events.MUTE : LogUtils.Events.UNMUTE);
        if (mute != mAudioManager.isMicrophoneMute() && isInActiveState()) {
            IAudioService audio = mAudioServiceFactory.getAudioService();
            Log.i(this, "changing microphone mute state to: %b [serviceIsNull=%b]",
@@ -1450,7 +1451,7 @@ public class CallAudioRouteStateMachine extends StateMachine {
            routeMask |= CallAudioState.ROUTE_EARPIECE;
        }

        if (mBluetoothManager.isBluetoothAvailable()) {
        if (mBluetoothRouteManager.isBluetoothAvailable()) {
            routeMask |=  CallAudioState.ROUTE_BLUETOOTH;
        }

+6 −5
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import com.android.internal.telephony.AsyncEmergencyContactNotifier;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyProperties;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.telecom.bluetooth.BluetoothRouteManager;
import com.android.server.telecom.callfiltering.AsyncBlockCheckFilter;
import com.android.server.telecom.callfiltering.BlockCheckerAdapter;
import com.android.server.telecom.callfiltering.CallFilterResultCallback;
@@ -180,7 +181,7 @@ public class CallsManager extends Call.ListenerBase
            new ConcurrentHashMap<CallsManagerListener, Boolean>(16, 0.9f, 1));
    private final HeadsetMediaButton mHeadsetMediaButton;
    private final WiredHeadsetManager mWiredHeadsetManager;
    private final BluetoothManager mBluetoothManager;
    private final BluetoothRouteManager mBluetoothRouteManager;
    private final DockManager mDockManager;
    private final TtyManager mTtyManager;
    private final ProximitySensorManager mProximitySensorManager;
@@ -222,7 +223,7 @@ public class CallsManager extends Call.ListenerBase
            ProximitySensorManagerFactory proximitySensorManagerFactory,
            InCallWakeLockControllerFactory inCallWakeLockControllerFactory,
            CallAudioManager.AudioServiceFactory audioServiceFactory,
            BluetoothManager bluetoothManager,
            BluetoothRouteManager bluetoothManager,
            WiredHeadsetManager wiredHeadsetManager,
            SystemStateProvider systemStateProvider,
            DefaultDialerCache defaultDialerCache,
@@ -239,8 +240,8 @@ public class CallsManager extends Call.ListenerBase
        mMissedCallNotifier = missedCallNotifier;
        StatusBarNotifier statusBarNotifier = new StatusBarNotifier(context, this);
        mWiredHeadsetManager = wiredHeadsetManager;
        mBluetoothManager = bluetoothManager;
        mDefaultDialerCache = defaultDialerCache;
        mBluetoothRouteManager = bluetoothManager;
        mDockManager = new DockManager(context);
        mTimeoutsAdapter = timeoutsAdapter;
        mCallerInfoLookupHelper = new CallerInfoLookupHelper(context, mCallerInfoAsyncQueryFactory,
@@ -1105,7 +1106,7 @@ public class CallsManager extends Call.ListenerBase
    public boolean isSpeakerphoneAutoEnabledForVideoCalls(int videoState) {
        return VideoProfile.isVideo(videoState) &&
            !mWiredHeadsetManager.isPluggedIn() &&
            !mBluetoothManager.isBluetoothAvailable() &&
            !mBluetoothRouteManager.isBluetoothAvailable() &&
            isSpeakerEnabledForVideoCalls();
    }

@@ -1119,7 +1120,7 @@ public class CallsManager extends Call.ListenerBase
    private boolean isSpeakerphoneEnabledForDock() {
        return mDockManager.isDocked() &&
            !mWiredHeadsetManager.isPluggedIn() &&
            !mBluetoothManager.isBluetoothAvailable();
            !mBluetoothRouteManager.isBluetoothAvailable();
    }

    /**
+7 −3
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.server.telecom;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.telecom.bluetooth.BluetoothDeviceManager;
import com.android.server.telecom.bluetooth.BluetoothRouteManager;
import com.android.server.telecom.components.UserCallIntentProcessor;
import com.android.server.telecom.components.UserCallIntentProcessorFactory;
import com.android.server.telecom.ui.MissedCallNotifierImpl.MissedCallNotifierImplFactory;
@@ -200,8 +202,10 @@ public class TelecomSystem {
                        return context.getContentResolver().openInputStream(uri);
                    }
                });
        BluetoothManager bluetoothManager = new BluetoothManager(mContext,
                new BluetoothAdapterProxy());
        BluetoothDeviceManager bluetoothDeviceManager = new BluetoothDeviceManager(mContext,
                new BluetoothAdapterProxy(), mLock);
        BluetoothRouteManager bluetoothRouteManager = new BluetoothRouteManager(mContext, mLock,
                bluetoothDeviceManager, new Timeouts.Adapter());
        WiredHeadsetManager wiredHeadsetManager = new WiredHeadsetManager(mContext);
        SystemStateProvider systemStateProvider = new SystemStateProvider(mContext);

@@ -219,7 +223,7 @@ public class TelecomSystem {
                proximitySensorManagerFactory,
                inCallWakeLockControllerFactory,
                audioServiceFactory,
                bluetoothManager,
                bluetoothRouteManager,
                wiredHeadsetManager,
                systemStateProvider,
                defaultDialerCache,
+2 −0
Original line number Diff line number Diff line
@@ -604,6 +604,8 @@ public class CallAudioModeStateMachineTest extends StateMachineTestBase<CallAudi
                verify(mCallAudioManager).stopCallWaiting();
                break;
        }

        sm.quitNow();
    }

    private void resetMocks() {
Loading