blob: 32d737c951c8ee4e74e0d035c2a1ee4ded4eb5a9 [file] [log] [blame]
Hall Liuf62630a2015-10-27 14:53:39 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.server.telecom;
18
Hall Liu486cb192016-10-21 18:23:33 -070019import com.android.server.telecom.bluetooth.BluetoothRouteManager;
20
Hall Liuf62630a2015-10-27 14:53:39 -070021/**
22 * A class that acts as a listener to things that could change call audio routing, namely
23 * bluetooth status, wired headset status, and dock status.
24 */
Hall Liue74af082016-02-10 16:12:47 -080025public class CallAudioRoutePeripheralAdapter implements WiredHeadsetManager.Listener,
Hall Liu486cb192016-10-21 18:23:33 -070026 DockManager.Listener, BluetoothRouteManager.BluetoothStateListener {
Hall Liue74af082016-02-10 16:12:47 -080027
Hall Liuf62630a2015-10-27 14:53:39 -070028 private final CallAudioRouteStateMachine mCallAudioRouteStateMachine;
Hall Liu486cb192016-10-21 18:23:33 -070029 private final BluetoothRouteManager mBluetoothRouteManager;
Hall Liuf62630a2015-10-27 14:53:39 -070030
31 public CallAudioRoutePeripheralAdapter(
32 CallAudioRouteStateMachine callAudioRouteStateMachine,
Hall Liu486cb192016-10-21 18:23:33 -070033 BluetoothRouteManager bluetoothManager,
Hall Liuf62630a2015-10-27 14:53:39 -070034 WiredHeadsetManager wiredHeadsetManager,
35 DockManager dockManager) {
36 mCallAudioRouteStateMachine = callAudioRouteStateMachine;
Hall Liu486cb192016-10-21 18:23:33 -070037 mBluetoothRouteManager = bluetoothManager;
Hall Liuf62630a2015-10-27 14:53:39 -070038
Hall Liu486cb192016-10-21 18:23:33 -070039 mBluetoothRouteManager.setListener(this);
Hall Liuf62630a2015-10-27 14:53:39 -070040 wiredHeadsetManager.addListener(this);
41 dockManager.addListener(this);
42 }
43
Hall Liuf62630a2015-10-27 14:53:39 -070044 public boolean isBluetoothAudioOn() {
Hall Liu486cb192016-10-21 18:23:33 -070045 return mBluetoothRouteManager.isBluetoothAudioConnectedOrPending();
Hall Liuf62630a2015-10-27 14:53:39 -070046 }
47
Hall Liue74af082016-02-10 16:12:47 -080048 @Override
Hall Liu132a5572017-11-02 18:44:57 -070049 public void onBluetoothDeviceListChanged() {
50 mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
51 CallAudioRouteStateMachine.BLUETOOTH_DEVICE_LIST_CHANGED);
Hall Liue74af082016-02-10 16:12:47 -080052 }
Hall Liu132a5572017-11-02 18:44:57 -070053
54 @Override
55 public void onBluetoothDeviceAvailable() {
56 mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
57 CallAudioRouteStateMachine.CONNECT_BLUETOOTH);
58 }
59
60 @Override
61 public void onBluetoothDeviceUnavailable() {
62 mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
63 CallAudioRouteStateMachine.DISCONNECT_BLUETOOTH);
64 }
65
66 @Override
67 public void onBluetoothAudioConnected() {
68 mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
69 CallAudioRouteStateMachine.BT_AUDIO_CONNECTED);
70 }
71
72 @Override
73 public void onBluetoothAudioDisconnected() {
74 mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
75 CallAudioRouteStateMachine.BT_AUDIO_DISCONNECTED);
76 }
77
Hall Liuf62630a2015-10-27 14:53:39 -070078 /**
79 * Updates the audio route when the headset plugged in state changes. For example, if audio is
80 * being routed over speakerphone and a headset is plugged in then switch to wired headset.
81 */
82 @Override
83 public void onWiredHeadsetPluggedInChanged(boolean oldIsPluggedIn, boolean newIsPluggedIn) {
84 if (!oldIsPluggedIn && newIsPluggedIn) {
Brad Ebinger72930a82015-11-23 10:06:40 -080085 mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
Hall Liuf62630a2015-10-27 14:53:39 -070086 CallAudioRouteStateMachine.CONNECT_WIRED_HEADSET);
87 } else if (oldIsPluggedIn && !newIsPluggedIn){
Brad Ebinger72930a82015-11-23 10:06:40 -080088 mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
Hall Liuf62630a2015-10-27 14:53:39 -070089 CallAudioRouteStateMachine.DISCONNECT_WIRED_HEADSET);
90 }
91 }
92
93 @Override
94 public void onDockChanged(boolean isDocked) {
Brad Ebinger72930a82015-11-23 10:06:40 -080095 mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
Hall Liuf62630a2015-10-27 14:53:39 -070096 isDocked ? CallAudioRouteStateMachine.CONNECT_DOCK
97 : CallAudioRouteStateMachine.DISCONNECT_DOCK
98 );
99 }
100}