summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author weichinweng <weichinweng@google.com> 2018-10-09 18:02:17 +0800
committer Stanley Tng <stng@google.com> 2018-10-18 13:31:11 -0700
commit0de4adc7cadc45e094d8ec6d5d454cc8d88ea9d6 (patch)
tree7e1bf80f166cd3c5579f197c66dd9c2076519c1c
parente7ca4fe6eefc9af222fc636a6f6de6c86f3a04f9 (diff)
AudioService: Add Hearing Aid Switch Control
1) Add setBluetoothHearingAidDeviceConnectionState interface to control suppressNoisyIntent flag. 2) Add check to confirm the previous device is active or not when want to clean it. Bug: 112279820 Test: Build Pass, BT off/on when play A2DP, Switch active device Change-Id: I73f1236d44213c6cf4a2708f3c96144416cfa67d Merged-In: I73f1236d44213c6cf4a2708f3c96144416cfa67d
-rw-r--r--media/java/android/media/AudioManager.java19
-rw-r--r--media/java/android/media/IAudioService.aidl5
-rw-r--r--services/core/java/com/android/server/audio/AudioService.java39
3 files changed, 39 insertions, 24 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 8686253506f4..d138c942d54f 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -3896,18 +3896,31 @@ public class AudioManager {
}
/**
- * Indicate Hearing Aid connection state change.
+ * Indicate Hearing Aid connection state change and eventually suppress
+ * the {@link AudioManager.ACTION_AUDIO_BECOMING_NOISY} intent.
* @param device Bluetooth device connected/disconnected
* @param state new connection state (BluetoothProfile.STATE_xxx)
+ * @param musicDevice Default get system volume for the connecting device.
+ * (either {@link android.bluetooth.BluetoothProfile.hearingaid} or
+ * {@link android.bluetooth.BluetoothProfile.HEARING_AID})
+ * @param suppressNoisyIntent if true the
+ * {@link AudioManager.ACTION_AUDIO_BECOMING_NOISY} intent will not be sent.
+ * @return a delay in ms that the caller should wait before broadcasting
+ * BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED intent.
* {@hide}
*/
- public void setHearingAidDeviceConnectionState(BluetoothDevice device, int state) {
+ public int setBluetoothHearingAidDeviceConnectionState(
+ BluetoothDevice device, int state, boolean suppressNoisyIntent,
+ int musicDevice) {
final IAudioService service = getService();
+ int delay = 0;
try {
- service.setHearingAidDeviceConnectionState(device, state);
+ delay = service.setBluetoothHearingAidDeviceConnectionState(device,
+ state, suppressNoisyIntent, musicDevice);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
+ return delay;
}
/**
diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl
index 569db16c312e..abd64119de61 100644
--- a/media/java/android/media/IAudioService.aidl
+++ b/media/java/android/media/IAudioService.aidl
@@ -151,8 +151,6 @@ interface IAudioService {
void setWiredDeviceConnectionState(int type, int state, String address, String name,
String caller);
- void setHearingAidDeviceConnectionState(in BluetoothDevice device, int state);
-
int setBluetoothA2dpDeviceConnectionState(in BluetoothDevice device, int state, int profile);
void handleBluetoothA2dpDeviceConfigChange(in BluetoothDevice device);
@@ -210,6 +208,9 @@ interface IAudioService {
oneway void playerHasOpPlayAudio(in int piid, in boolean hasOpPlayAudio);
+ int setBluetoothHearingAidDeviceConnectionState(in BluetoothDevice device,
+ int state, boolean suppressNoisyIntent, int musicDevice);
+
int setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(in BluetoothDevice device,
int state, int profile, boolean suppressNoisyIntent, int a2dpVolume);
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 462dffbf1ea7..75f6cb3adc05 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -4628,15 +4628,6 @@ public class AudioService extends IAudioService.Stub
}
}
- @Override
- public void setHearingAidDeviceConnectionState(BluetoothDevice device, int state)
- {
- Log.i(TAG, "setBluetoothHearingAidDeviceConnectionState");
-
- setBluetoothHearingAidDeviceConnectionState(
- device, state, false /* suppressNoisyIntent */, AudioSystem.DEVICE_NONE);
- }
-
public int setBluetoothHearingAidDeviceConnectionState(
BluetoothDevice device, int state, boolean suppressNoisyIntent,
int musicDevice)
@@ -5837,6 +5828,7 @@ public class AudioService extends IAudioService.Stub
address));
sendMsg(mAudioHandler, MSG_ACCESSORY_PLUG_MEDIA_UNMUTE, SENDMSG_QUEUE,
AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0, null, 0);
+ setCurrentAudioRouteNameIfPossible(name);
}
private void onSendBecomingNoisyIntent() {
@@ -5856,7 +5848,7 @@ public class AudioService extends IAudioService.Stub
mConnectedDevices.remove(
makeDeviceListKey(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, address));
// Remove A2DP routes as well
- setCurrentAudioRouteName(null);
+ setCurrentAudioRouteNameIfPossible(null);
if (mDockAddress == address) {
mDockAddress = null;
}
@@ -5926,6 +5918,7 @@ public class AudioService extends IAudioService.Stub
sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE,
AudioSystem.DEVICE_OUT_HEARING_AID, 0,
mStreamStates[AudioSystem.STREAM_MUSIC], 0);
+ setCurrentAudioRouteNameIfPossible(name);
}
// must be called synchronized on mConnectedDevices
@@ -5935,7 +5928,7 @@ public class AudioService extends IAudioService.Stub
mConnectedDevices.remove(
makeDeviceListKey(AudioSystem.DEVICE_OUT_HEARING_AID, address));
// Remove Hearing Aid routes as well
- setCurrentAudioRouteName(null);
+ setCurrentAudioRouteNameIfPossible(null);
}
// must be called synchronized on mConnectedDevices
@@ -5980,7 +5973,6 @@ public class AudioService extends IAudioService.Stub
} else {
makeA2dpDeviceUnavailableNow(address);
}
- setCurrentAudioRouteName(null);
} else if (!isConnected && state == BluetoothProfile.STATE_CONNECTED) {
if (btDevice.isBluetoothDock()) {
// this could be a reconnection after a transient disconnection
@@ -6004,7 +5996,6 @@ public class AudioService extends IAudioService.Stub
}
makeA2dpDeviceAvailable(address, btDevice.getName(),
"onSetA2dpSinkConnectionState");
- setCurrentAudioRouteName(btDevice.getAliasName());
}
}
}
@@ -6056,25 +6047,35 @@ public class AudioService extends IAudioService.Stub
if (isConnected && state != BluetoothProfile.STATE_CONNECTED) {
makeHearingAidDeviceUnavailable(address);
- setCurrentAudioRouteName(null);
} else if (!isConnected && state == BluetoothProfile.STATE_CONNECTED) {
makeHearingAidDeviceAvailable(address, btDevice.getName(),
"onSetHearingAidConnectionState");
- setCurrentAudioRouteName(btDevice.getAliasName());
}
}
}
- private void setCurrentAudioRouteName(String name){
+ private void setCurrentAudioRouteNameIfPossible(String name) {
synchronized (mCurAudioRoutes) {
if (!TextUtils.equals(mCurAudioRoutes.bluetoothName, name)) {
- mCurAudioRoutes.bluetoothName = name;
- sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES,
- SENDMSG_NOOP, 0, 0, null, 0);
+ if (name != null || !isCurrentDeviceConnected()) {
+ mCurAudioRoutes.bluetoothName = name;
+ sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES,
+ SENDMSG_NOOP, 0, 0, null, 0);
+ }
}
}
}
+ private boolean isCurrentDeviceConnected() {
+ for (int i = 0; i < mConnectedDevices.size(); i++) {
+ DeviceListSpec deviceSpec = mConnectedDevices.valueAt(i);
+ if (TextUtils.equals(deviceSpec.mDeviceName, mCurAudioRoutes.bluetoothName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private void onBluetoothA2dpDeviceConfigChange(BluetoothDevice btDevice)
{
if (DEBUG_DEVICES) {