Loading services/core/java/com/android/server/audio/AudioDeviceBroker.java +41 −27 Original line number Diff line number Diff line Loading @@ -1126,26 +1126,15 @@ public class AudioDeviceBroker { .set(MediaMetrics.Property.NAME, name) .set(MediaMetrics.Property.STATUS, data.mInfo.getProfile()) .record(); synchronized (mDeviceStateLock) { postBluetoothDeviceConfigChange(createBtDeviceInfo(data, data.mNewDevice, BluetoothProfile.STATE_CONNECTED)); } postBluetoothDeviceConfigChange(data); } else { synchronized (mDeviceStateLock) { if (data.mPreviousDevice != null) { btMediaMetricRecord(data.mPreviousDevice, MediaMetrics.Value.DISCONNECTED, data); sendLMsgNoDelay(MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT, SENDMSG_QUEUE, createBtDeviceInfo(data, data.mPreviousDevice, BluetoothProfile.STATE_DISCONNECTED)); btMediaMetricRecord(data.mPreviousDevice, MediaMetrics.Value.DISCONNECTED, data); } if (data.mNewDevice != null) { btMediaMetricRecord(data.mNewDevice, MediaMetrics.Value.CONNECTED, data); sendLMsgNoDelay(MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT, SENDMSG_QUEUE, createBtDeviceInfo(data, data.mNewDevice, BluetoothProfile.STATE_CONNECTED)); } } postBluetoothDeviceConnectionChange(data); } } Loading Loading @@ -1392,8 +1381,12 @@ public class AudioDeviceBroker { SENDMSG_REPLACE, new AudioModeInfo(mode, pid, uid)); } /*package*/ void postBluetoothDeviceConfigChange(@NonNull BtDeviceInfo info) { sendLMsgNoDelay(MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE, SENDMSG_QUEUE, info); /*package*/ void postBluetoothDeviceConfigChange(@NonNull BtDeviceChangedData data) { sendLMsgNoDelay(MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE, SENDMSG_QUEUE, data); } /*package*/ void postBluetoothDeviceConnectionChange(@NonNull BtDeviceChangedData data) { sendLMsgNoDelay(MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT, SENDMSG_QUEUE, data); } /*package*/ void startBluetoothScoForClient(IBinder cb, Loading Loading @@ -2094,7 +2087,14 @@ public class AudioDeviceBroker { } break; case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE: { final BtDeviceInfo btInfo = (BtDeviceInfo) msg.obj; final BtDeviceChangedData data = (BtDeviceChangedData) msg.obj; if (data.mNewDevice == null) { Slog.e(TAG, "Malformed MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE message"); break; } final BtDeviceInfo btInfo = createBtDeviceInfo( data, data.mNewDevice, BluetoothProfile.STATE_CONNECTED); final Pair<Integer, Boolean> codecAndChanged = mBtHelper.getCodecWithFallback( btInfo.mDevice, btInfo.mProfile, btInfo.mIsLeOutput, "MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE"); Loading Loading @@ -2206,12 +2206,26 @@ public class AudioDeviceBroker { } break; case MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT: { final BtDeviceInfo btInfo = (BtDeviceInfo) msg.obj; if (btInfo.mDevice == null) break; AudioService.sDeviceLogger.enqueue((new EventLogger.StringEvent( "msg: MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT " + btInfo)).printLog(TAG)); final BtDeviceChangedData data = (BtDeviceChangedData) msg.obj; if (data.mPreviousDevice == null && data.mNewDevice == null) { Slog.e(TAG, "Malformed MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT message"); break; } if (data.mPreviousDevice != null) { final BtDeviceInfo btInfo = createBtDeviceInfo( data, data.mPreviousDevice, BluetoothProfile.STATE_DISCONNECTED); synchronized (mDeviceStateLock) { mDeviceInventory.setBluetoothActiveDevice(btInfo); mDeviceInventory.setBluetoothActiveDevice(btInfo, "MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT" /*eventSource*/); } } if (data.mNewDevice != null) { final BtDeviceInfo btInfo = createBtDeviceInfo( data, data.mNewDevice, BluetoothProfile.STATE_CONNECTED); synchronized (mDeviceStateLock) { mDeviceInventory.setBluetoothActiveDevice(btInfo, "MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT" /*eventSource*/); } } } break; case MSG_CHECK_MUTE_MUSIC: Loading services/core/java/com/android/server/audio/AudioDeviceInventory.java +6 −5 Original line number Diff line number Diff line Loading @@ -1180,7 +1180,8 @@ public class AudioDeviceInventory { } if (disconnectDevice) { setBluetoothActiveDevice(new AudioDeviceBroker.BtDeviceInfo(btInfo, BluetoothProfile.STATE_DISCONNECTED)); BluetoothProfile.STATE_DISCONNECTED), "onBluetoothDeviceConfigChange" /*eventSource*/); } mmi.record(); return delayMs; Loading Loading @@ -2261,7 +2262,8 @@ public class AudioDeviceInventory { * Set a Bluetooth device to active. */ @GuardedBy("mDeviceBroker.mDeviceStateLock") public int setBluetoothActiveDevice(@NonNull AudioDeviceBroker.BtDeviceInfo info) { public int setBluetoothActiveDevice( @NonNull AudioDeviceBroker.BtDeviceInfo info, String eventSource) { int delay; synchronized (mDevicesLock) { if (!info.mSupprNoisy Loading @@ -2280,9 +2282,8 @@ public class AudioDeviceInventory { } else { delay = 0; } if (AudioService.DEBUG_DEVICES) { Log.i(TAG, "setBluetoothActiveDevice " + info.toString() + " delay(ms): " + delay); } AudioService.sDeviceLogger.enqueue((new EventLogger.StringEvent( "setBluetoothActiveDevice called from " + eventSource + info)).printLog(TAG)); } mDeviceBroker.postBluetoothActiveDevice(info, delay); return delay; Loading services/core/java/com/android/server/audio/AudioService.java +2 −11 Original line number Diff line number Diff line Loading @@ -480,7 +480,6 @@ public class AudioService extends IAudioService.Stub private static final int MSG_UPDATE_A11Y_SERVICE_UIDS = 35; private static final int MSG_UPDATE_AUDIO_MODE = 36; private static final int MSG_RECORDING_CONFIG_CHANGE = 37; private static final int MSG_BT_DEV_CHANGED = 38; private static final int MSG_UPDATE_AUDIO_MODE_SIGNAL = 39; private static final int MSG_DISPATCH_AUDIO_MODE = 40; private static final int MSG_ROUTING_UPDATED = 41; Loading Loading @@ -9203,11 +9202,8 @@ public class AudioService extends IAudioService.Stub sDeviceLogger.enqueue(new EventLogger.StringEvent("BluetoothActiveDeviceChanged for " + BluetoothProfile.getProfileName(profile) + ", device update " + previousDevice + " -> " + newDevice).printLog(TAG)); AudioDeviceBroker.BtDeviceChangedData data = new AudioDeviceBroker.BtDeviceChangedData(newDevice, previousDevice, info, "AudioService"); sendMsg(mAudioHandler, MSG_BT_DEV_CHANGED, SENDMSG_QUEUE, 0, 0, /*obj*/ data, /*delay*/ 0); mDeviceBroker.queueOnBluetoothActiveDeviceChanged(new AudioDeviceBroker.BtDeviceChangedData( newDevice, previousDevice, info, "AudioService")); } /** only public for mocking/spying, do not call outside of AudioService */ Loading Loading @@ -11316,11 +11312,6 @@ public class AudioService extends IAudioService.Stub } break; case MSG_BT_DEV_CHANGED: mDeviceBroker.queueOnBluetoothActiveDeviceChanged( (AudioDeviceBroker.BtDeviceChangedData) msg.obj); break; case MSG_DISPATCH_AUDIO_MODE: dispatchMode(msg.arg1); break; Loading services/tests/servicestests/src/com/android/server/audio/AudioDeviceBrokerTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doNothing; Loading Loading @@ -125,7 +126,7 @@ public class AudioDeviceBrokerTest { BluetoothProfileConnectionInfo.createA2dpInfo(true, 1), "testSource")); Thread.sleep(2 * MAX_MESSAGE_HANDLING_DELAY_MS); verify(mSpyDevInventory, times(1)).setBluetoothActiveDevice( any(AudioDeviceBroker.BtDeviceInfo.class)); any(AudioDeviceBroker.BtDeviceInfo.class), anyString()); // verify the connection was reported to AudioSystem checkSingleSystemConnection(mFakeBtDevice); Loading Loading
services/core/java/com/android/server/audio/AudioDeviceBroker.java +41 −27 Original line number Diff line number Diff line Loading @@ -1126,26 +1126,15 @@ public class AudioDeviceBroker { .set(MediaMetrics.Property.NAME, name) .set(MediaMetrics.Property.STATUS, data.mInfo.getProfile()) .record(); synchronized (mDeviceStateLock) { postBluetoothDeviceConfigChange(createBtDeviceInfo(data, data.mNewDevice, BluetoothProfile.STATE_CONNECTED)); } postBluetoothDeviceConfigChange(data); } else { synchronized (mDeviceStateLock) { if (data.mPreviousDevice != null) { btMediaMetricRecord(data.mPreviousDevice, MediaMetrics.Value.DISCONNECTED, data); sendLMsgNoDelay(MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT, SENDMSG_QUEUE, createBtDeviceInfo(data, data.mPreviousDevice, BluetoothProfile.STATE_DISCONNECTED)); btMediaMetricRecord(data.mPreviousDevice, MediaMetrics.Value.DISCONNECTED, data); } if (data.mNewDevice != null) { btMediaMetricRecord(data.mNewDevice, MediaMetrics.Value.CONNECTED, data); sendLMsgNoDelay(MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT, SENDMSG_QUEUE, createBtDeviceInfo(data, data.mNewDevice, BluetoothProfile.STATE_CONNECTED)); } } postBluetoothDeviceConnectionChange(data); } } Loading Loading @@ -1392,8 +1381,12 @@ public class AudioDeviceBroker { SENDMSG_REPLACE, new AudioModeInfo(mode, pid, uid)); } /*package*/ void postBluetoothDeviceConfigChange(@NonNull BtDeviceInfo info) { sendLMsgNoDelay(MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE, SENDMSG_QUEUE, info); /*package*/ void postBluetoothDeviceConfigChange(@NonNull BtDeviceChangedData data) { sendLMsgNoDelay(MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE, SENDMSG_QUEUE, data); } /*package*/ void postBluetoothDeviceConnectionChange(@NonNull BtDeviceChangedData data) { sendLMsgNoDelay(MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT, SENDMSG_QUEUE, data); } /*package*/ void startBluetoothScoForClient(IBinder cb, Loading Loading @@ -2094,7 +2087,14 @@ public class AudioDeviceBroker { } break; case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE: { final BtDeviceInfo btInfo = (BtDeviceInfo) msg.obj; final BtDeviceChangedData data = (BtDeviceChangedData) msg.obj; if (data.mNewDevice == null) { Slog.e(TAG, "Malformed MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE message"); break; } final BtDeviceInfo btInfo = createBtDeviceInfo( data, data.mNewDevice, BluetoothProfile.STATE_CONNECTED); final Pair<Integer, Boolean> codecAndChanged = mBtHelper.getCodecWithFallback( btInfo.mDevice, btInfo.mProfile, btInfo.mIsLeOutput, "MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE"); Loading Loading @@ -2206,12 +2206,26 @@ public class AudioDeviceBroker { } break; case MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT: { final BtDeviceInfo btInfo = (BtDeviceInfo) msg.obj; if (btInfo.mDevice == null) break; AudioService.sDeviceLogger.enqueue((new EventLogger.StringEvent( "msg: MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT " + btInfo)).printLog(TAG)); final BtDeviceChangedData data = (BtDeviceChangedData) msg.obj; if (data.mPreviousDevice == null && data.mNewDevice == null) { Slog.e(TAG, "Malformed MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT message"); break; } if (data.mPreviousDevice != null) { final BtDeviceInfo btInfo = createBtDeviceInfo( data, data.mPreviousDevice, BluetoothProfile.STATE_DISCONNECTED); synchronized (mDeviceStateLock) { mDeviceInventory.setBluetoothActiveDevice(btInfo); mDeviceInventory.setBluetoothActiveDevice(btInfo, "MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT" /*eventSource*/); } } if (data.mNewDevice != null) { final BtDeviceInfo btInfo = createBtDeviceInfo( data, data.mNewDevice, BluetoothProfile.STATE_CONNECTED); synchronized (mDeviceStateLock) { mDeviceInventory.setBluetoothActiveDevice(btInfo, "MSG_L_BT_ACTIVE_DEVICE_CHANGE_EXT" /*eventSource*/); } } } break; case MSG_CHECK_MUTE_MUSIC: Loading
services/core/java/com/android/server/audio/AudioDeviceInventory.java +6 −5 Original line number Diff line number Diff line Loading @@ -1180,7 +1180,8 @@ public class AudioDeviceInventory { } if (disconnectDevice) { setBluetoothActiveDevice(new AudioDeviceBroker.BtDeviceInfo(btInfo, BluetoothProfile.STATE_DISCONNECTED)); BluetoothProfile.STATE_DISCONNECTED), "onBluetoothDeviceConfigChange" /*eventSource*/); } mmi.record(); return delayMs; Loading Loading @@ -2261,7 +2262,8 @@ public class AudioDeviceInventory { * Set a Bluetooth device to active. */ @GuardedBy("mDeviceBroker.mDeviceStateLock") public int setBluetoothActiveDevice(@NonNull AudioDeviceBroker.BtDeviceInfo info) { public int setBluetoothActiveDevice( @NonNull AudioDeviceBroker.BtDeviceInfo info, String eventSource) { int delay; synchronized (mDevicesLock) { if (!info.mSupprNoisy Loading @@ -2280,9 +2282,8 @@ public class AudioDeviceInventory { } else { delay = 0; } if (AudioService.DEBUG_DEVICES) { Log.i(TAG, "setBluetoothActiveDevice " + info.toString() + " delay(ms): " + delay); } AudioService.sDeviceLogger.enqueue((new EventLogger.StringEvent( "setBluetoothActiveDevice called from " + eventSource + info)).printLog(TAG)); } mDeviceBroker.postBluetoothActiveDevice(info, delay); return delay; Loading
services/core/java/com/android/server/audio/AudioService.java +2 −11 Original line number Diff line number Diff line Loading @@ -480,7 +480,6 @@ public class AudioService extends IAudioService.Stub private static final int MSG_UPDATE_A11Y_SERVICE_UIDS = 35; private static final int MSG_UPDATE_AUDIO_MODE = 36; private static final int MSG_RECORDING_CONFIG_CHANGE = 37; private static final int MSG_BT_DEV_CHANGED = 38; private static final int MSG_UPDATE_AUDIO_MODE_SIGNAL = 39; private static final int MSG_DISPATCH_AUDIO_MODE = 40; private static final int MSG_ROUTING_UPDATED = 41; Loading Loading @@ -9203,11 +9202,8 @@ public class AudioService extends IAudioService.Stub sDeviceLogger.enqueue(new EventLogger.StringEvent("BluetoothActiveDeviceChanged for " + BluetoothProfile.getProfileName(profile) + ", device update " + previousDevice + " -> " + newDevice).printLog(TAG)); AudioDeviceBroker.BtDeviceChangedData data = new AudioDeviceBroker.BtDeviceChangedData(newDevice, previousDevice, info, "AudioService"); sendMsg(mAudioHandler, MSG_BT_DEV_CHANGED, SENDMSG_QUEUE, 0, 0, /*obj*/ data, /*delay*/ 0); mDeviceBroker.queueOnBluetoothActiveDeviceChanged(new AudioDeviceBroker.BtDeviceChangedData( newDevice, previousDevice, info, "AudioService")); } /** only public for mocking/spying, do not call outside of AudioService */ Loading Loading @@ -11316,11 +11312,6 @@ public class AudioService extends IAudioService.Stub } break; case MSG_BT_DEV_CHANGED: mDeviceBroker.queueOnBluetoothActiveDeviceChanged( (AudioDeviceBroker.BtDeviceChangedData) msg.obj); break; case MSG_DISPATCH_AUDIO_MODE: dispatchMode(msg.arg1); break; Loading
services/tests/servicestests/src/com/android/server/audio/AudioDeviceBrokerTest.java +2 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doNothing; Loading Loading @@ -125,7 +126,7 @@ public class AudioDeviceBrokerTest { BluetoothProfileConnectionInfo.createA2dpInfo(true, 1), "testSource")); Thread.sleep(2 * MAX_MESSAGE_HANDLING_DELAY_MS); verify(mSpyDevInventory, times(1)).setBluetoothActiveDevice( any(AudioDeviceBroker.BtDeviceInfo.class)); any(AudioDeviceBroker.BtDeviceInfo.class), anyString()); // verify the connection was reported to AudioSystem checkSingleSystemConnection(mFakeBtDevice); Loading