Merge "AudioService: Add Hearing Aid Switch Control"
This commit is contained in:
@@ -3932,18 +3932,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 device Bluetooth device connected/disconnected
|
||||||
* @param state new connection state (BluetoothProfile.STATE_xxx)
|
* @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}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
public void setHearingAidDeviceConnectionState(BluetoothDevice device, int state) {
|
public int setBluetoothHearingAidDeviceConnectionState(
|
||||||
|
BluetoothDevice device, int state, boolean suppressNoisyIntent,
|
||||||
|
int musicDevice) {
|
||||||
final IAudioService service = getService();
|
final IAudioService service = getService();
|
||||||
|
int delay = 0;
|
||||||
try {
|
try {
|
||||||
service.setHearingAidDeviceConnectionState(device, state);
|
delay = service.setBluetoothHearingAidDeviceConnectionState(device,
|
||||||
|
state, suppressNoisyIntent, musicDevice);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
return delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -151,8 +151,6 @@ interface IAudioService {
|
|||||||
void setWiredDeviceConnectionState(int type, int state, String address, String name,
|
void setWiredDeviceConnectionState(int type, int state, String address, String name,
|
||||||
String caller);
|
String caller);
|
||||||
|
|
||||||
void setHearingAidDeviceConnectionState(in BluetoothDevice device, int state);
|
|
||||||
|
|
||||||
int setBluetoothA2dpDeviceConnectionState(in BluetoothDevice device, int state, int profile);
|
int setBluetoothA2dpDeviceConnectionState(in BluetoothDevice device, int state, int profile);
|
||||||
|
|
||||||
void handleBluetoothA2dpDeviceConfigChange(in BluetoothDevice device);
|
void handleBluetoothA2dpDeviceConfigChange(in BluetoothDevice device);
|
||||||
@@ -210,6 +208,9 @@ interface IAudioService {
|
|||||||
|
|
||||||
oneway void playerHasOpPlayAudio(in int piid, in boolean hasOpPlayAudio);
|
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 setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent(in BluetoothDevice device,
|
||||||
int state, int profile, boolean suppressNoisyIntent, int a2dpVolume);
|
int state, int profile, boolean suppressNoisyIntent, int a2dpVolume);
|
||||||
|
|
||||||
|
|||||||
@@ -4661,22 +4661,15 @@ public class AudioService extends IAudioService.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setHearingAidDeviceConnectionState(BluetoothDevice device, int state)
|
|
||||||
{
|
|
||||||
mDeviceLogger.log((new AudioEventLogger.StringEvent(
|
|
||||||
"setHearingAidDeviceConnectionState state=" + state
|
|
||||||
+ " addr=" + device.getAddress())).printLog(TAG));
|
|
||||||
|
|
||||||
setBluetoothHearingAidDeviceConnectionState(
|
|
||||||
device, state, false /* suppressNoisyIntent */, AudioSystem.DEVICE_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int setBluetoothHearingAidDeviceConnectionState(
|
public int setBluetoothHearingAidDeviceConnectionState(
|
||||||
BluetoothDevice device, int state, boolean suppressNoisyIntent,
|
BluetoothDevice device, int state, boolean suppressNoisyIntent,
|
||||||
int musicDevice)
|
int musicDevice)
|
||||||
{
|
{
|
||||||
int delay;
|
int delay;
|
||||||
|
mDeviceLogger.log((new AudioEventLogger.StringEvent(
|
||||||
|
"setHearingAidDeviceConnectionState state=" + state
|
||||||
|
+ " addr=" + device.getAddress()
|
||||||
|
+ " supprNoisy=" + suppressNoisyIntent)).printLog(TAG));
|
||||||
synchronized (mConnectedDevices) {
|
synchronized (mConnectedDevices) {
|
||||||
if (!suppressNoisyIntent) {
|
if (!suppressNoisyIntent) {
|
||||||
int intState = (state == BluetoothHearingAid.STATE_CONNECTED) ? 1 : 0;
|
int intState = (state == BluetoothHearingAid.STATE_CONNECTED) ? 1 : 0;
|
||||||
@@ -5866,6 +5859,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
address));
|
address));
|
||||||
sendMsg(mAudioHandler, MSG_ACCESSORY_PLUG_MEDIA_UNMUTE, SENDMSG_QUEUE,
|
sendMsg(mAudioHandler, MSG_ACCESSORY_PLUG_MEDIA_UNMUTE, SENDMSG_QUEUE,
|
||||||
AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0, null, 0);
|
AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, 0, null, 0);
|
||||||
|
setCurrentAudioRouteNameIfPossible(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSendBecomingNoisyIntent() {
|
private void onSendBecomingNoisyIntent() {
|
||||||
@@ -5887,7 +5881,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
mConnectedDevices.remove(
|
mConnectedDevices.remove(
|
||||||
makeDeviceListKey(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, address));
|
makeDeviceListKey(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, address));
|
||||||
// Remove A2DP routes as well
|
// Remove A2DP routes as well
|
||||||
setCurrentAudioRouteName(null);
|
setCurrentAudioRouteNameIfPossible(null);
|
||||||
if (mDockAddress == address) {
|
if (mDockAddress == address) {
|
||||||
mDockAddress = null;
|
mDockAddress = null;
|
||||||
}
|
}
|
||||||
@@ -5957,6 +5951,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE,
|
sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE,
|
||||||
AudioSystem.DEVICE_OUT_HEARING_AID, 0,
|
AudioSystem.DEVICE_OUT_HEARING_AID, 0,
|
||||||
mStreamStates[AudioSystem.STREAM_MUSIC], 0);
|
mStreamStates[AudioSystem.STREAM_MUSIC], 0);
|
||||||
|
setCurrentAudioRouteNameIfPossible(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// must be called synchronized on mConnectedDevices
|
// must be called synchronized on mConnectedDevices
|
||||||
@@ -5966,7 +5961,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
mConnectedDevices.remove(
|
mConnectedDevices.remove(
|
||||||
makeDeviceListKey(AudioSystem.DEVICE_OUT_HEARING_AID, address));
|
makeDeviceListKey(AudioSystem.DEVICE_OUT_HEARING_AID, address));
|
||||||
// Remove Hearing Aid routes as well
|
// Remove Hearing Aid routes as well
|
||||||
setCurrentAudioRouteName(null);
|
setCurrentAudioRouteNameIfPossible(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// must be called synchronized on mConnectedDevices
|
// must be called synchronized on mConnectedDevices
|
||||||
@@ -6011,7 +6006,6 @@ public class AudioService extends IAudioService.Stub
|
|||||||
} else {
|
} else {
|
||||||
makeA2dpDeviceUnavailableNow(address);
|
makeA2dpDeviceUnavailableNow(address);
|
||||||
}
|
}
|
||||||
setCurrentAudioRouteName(null);
|
|
||||||
} else if (!isConnected && state == BluetoothProfile.STATE_CONNECTED) {
|
} else if (!isConnected && state == BluetoothProfile.STATE_CONNECTED) {
|
||||||
if (btDevice.isBluetoothDock()) {
|
if (btDevice.isBluetoothDock()) {
|
||||||
// this could be a reconnection after a transient disconnection
|
// this could be a reconnection after a transient disconnection
|
||||||
@@ -6035,7 +6029,6 @@ public class AudioService extends IAudioService.Stub
|
|||||||
}
|
}
|
||||||
makeA2dpDeviceAvailable(address, btDevice.getName(),
|
makeA2dpDeviceAvailable(address, btDevice.getName(),
|
||||||
"onSetA2dpSinkConnectionState");
|
"onSetA2dpSinkConnectionState");
|
||||||
setCurrentAudioRouteName(btDevice.getAliasName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6087,25 +6080,35 @@ public class AudioService extends IAudioService.Stub
|
|||||||
|
|
||||||
if (isConnected && state != BluetoothProfile.STATE_CONNECTED) {
|
if (isConnected && state != BluetoothProfile.STATE_CONNECTED) {
|
||||||
makeHearingAidDeviceUnavailable(address);
|
makeHearingAidDeviceUnavailable(address);
|
||||||
setCurrentAudioRouteName(null);
|
|
||||||
} else if (!isConnected && state == BluetoothProfile.STATE_CONNECTED) {
|
} else if (!isConnected && state == BluetoothProfile.STATE_CONNECTED) {
|
||||||
makeHearingAidDeviceAvailable(address, btDevice.getName(),
|
makeHearingAidDeviceAvailable(address, btDevice.getName(),
|
||||||
"onSetHearingAidConnectionState");
|
"onSetHearingAidConnectionState");
|
||||||
setCurrentAudioRouteName(btDevice.getAliasName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCurrentAudioRouteName(String name){
|
private void setCurrentAudioRouteNameIfPossible(String name) {
|
||||||
synchronized (mCurAudioRoutes) {
|
synchronized (mCurAudioRoutes) {
|
||||||
if (!TextUtils.equals(mCurAudioRoutes.bluetoothName, name)) {
|
if (!TextUtils.equals(mCurAudioRoutes.bluetoothName, name)) {
|
||||||
mCurAudioRoutes.bluetoothName = name;
|
if (name != null || !isCurrentDeviceConnected()) {
|
||||||
sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES,
|
mCurAudioRoutes.bluetoothName = name;
|
||||||
SENDMSG_NOOP, 0, 0, null, 0);
|
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)
|
private void onBluetoothA2dpDeviceConfigChange(BluetoothDevice btDevice)
|
||||||
{
|
{
|
||||||
if (DEBUG_DEVICES) {
|
if (DEBUG_DEVICES) {
|
||||||
|
|||||||
Reference in New Issue
Block a user