Loading services/core/java/com/android/server/audio/AudioDeviceBroker.java +6 −5 Original line number Diff line number Diff line Loading @@ -1535,8 +1535,9 @@ public class AudioDeviceBroker { sendLMsgNoDelay(MSG_L_SYNCHRONIZE_ADI_DEVICES_IN_INVENTORY, SENDMSG_QUEUE, deviceState); } /*package*/ void postUpdatedAdiDeviceState(AdiDeviceState deviceState) { sendLMsgNoDelay(MSG_L_UPDATED_ADI_DEVICE_STATE, SENDMSG_QUEUE, deviceState); /*package*/ void postUpdatedAdiDeviceState(AdiDeviceState deviceState, boolean initSA) { sendILMsgNoDelay( MSG_IL_UPDATED_ADI_DEVICE_STATE, SENDMSG_QUEUE, initSA ? 1 : 0, deviceState); } /*package*/ static final class CommunicationDeviceInfo { Loading Loading @@ -2068,8 +2069,8 @@ public class AudioDeviceBroker { } } break; case MSG_L_UPDATED_ADI_DEVICE_STATE: mAudioService.onUpdatedAdiDeviceState((AdiDeviceState) msg.obj); case MSG_IL_UPDATED_ADI_DEVICE_STATE: mAudioService.onUpdatedAdiDeviceState((AdiDeviceState) msg.obj, msg.arg1 == 1); break; default: Loading Loading @@ -2156,7 +2157,7 @@ public class AudioDeviceBroker { private static final int MSG_CHECK_COMMUNICATION_ROUTE_CLIENT_STATE = 56; private static final int MSG_I_UPDATE_LE_AUDIO_GROUP_ADDRESSES = 57; private static final int MSG_L_SYNCHRONIZE_ADI_DEVICES_IN_INVENTORY = 58; private static final int MSG_L_UPDATED_ADI_DEVICE_STATE = 59; private static final int MSG_IL_UPDATED_ADI_DEVICE_STATE = 59; Loading services/core/java/com/android/server/audio/AudioDeviceInventory.java +6 −6 Original line number Diff line number Diff line Loading @@ -169,7 +169,7 @@ public class AudioDeviceInventory { if (ads != null) { if (ads.getAudioDeviceCategory() != category) { ads.setAudioDeviceCategory(category); mDeviceBroker.postUpdatedAdiDeviceState(ads); mDeviceBroker.postUpdatedAdiDeviceState(ads, false /*initSA*/); mDeviceBroker.postPersistAudioDeviceSettings(); } mDeviceBroker.postSynchronizeAdiDevicesInInventory(ads); Loading @@ -182,7 +182,7 @@ public class AudioDeviceInventory { mDeviceInventory.put(ads.getDeviceId(), ads); checkDeviceInventorySize_l(); mDeviceBroker.postUpdatedAdiDeviceState(ads); mDeviceBroker.postUpdatedAdiDeviceState(ads, true /*initSA*/); mDeviceBroker.postPersistAudioDeviceSettings(); } } Loading Loading @@ -212,7 +212,7 @@ public class AudioDeviceInventory { checkDeviceInventorySize_l(); } if (updatedCategory.get()) { mDeviceBroker.postUpdatedAdiDeviceState(deviceState); mDeviceBroker.postUpdatedAdiDeviceState(deviceState, false /*initSA*/); } mDeviceBroker.postSynchronizeAdiDevicesInInventory(deviceState); } Loading Loading @@ -314,7 +314,7 @@ public class AudioDeviceInventory { } ads2.setAudioDeviceCategory(updatedDevice.getAudioDeviceCategory()); mDeviceBroker.postUpdatedAdiDeviceState(ads2); mDeviceBroker.postUpdatedAdiDeviceState(ads2, false /*initSA*/); AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "synchronizeBleDeviceInInventory synced device pair ads1=" + updatedDevice + " ads2=" + ads2).printLog(TAG)); Loading @@ -335,7 +335,7 @@ public class AudioDeviceInventory { } ads2.setAudioDeviceCategory(updatedDevice.getAudioDeviceCategory()); mDeviceBroker.postUpdatedAdiDeviceState(ads2); mDeviceBroker.postUpdatedAdiDeviceState(ads2, false /*initSA*/); AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "synchronizeBleDeviceInInventory synced device pair ads1=" + updatedDevice + " peer ads2=" + ads2).printLog(TAG)); Loading @@ -360,7 +360,7 @@ public class AudioDeviceInventory { } ads.setAudioDeviceCategory(updatedDevice.getAudioDeviceCategory()); mDeviceBroker.postUpdatedAdiDeviceState(ads); mDeviceBroker.postUpdatedAdiDeviceState(ads, false /*initSA*/); AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "synchronizeDeviceProfilesInInventory synced device pair ads1=" + updatedDevice + " ads2=" + ads).printLog(TAG)); Loading services/core/java/com/android/server/audio/AudioService.java +4 −3 Original line number Diff line number Diff line Loading @@ -11253,7 +11253,8 @@ public class AudioService extends IAudioService.Stub mDeviceBroker.addOrUpdateBtAudioDeviceCategoryInInventory(deviceState); mDeviceBroker.postPersistAudioDeviceSettings(); mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes()); mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes(), false /* initState */); mSoundDoseHelper.setAudioDeviceCategory(addr, internalType, btAudioDeviceCategory == AUDIO_DEVICE_CATEGORY_HEADPHONES); } Loading Loading @@ -11324,11 +11325,11 @@ public class AudioService extends IAudioService.Stub /** Update the sound dose and spatializer state based on the new AdiDeviceState. */ @VisibleForTesting(visibility = PACKAGE) public void onUpdatedAdiDeviceState(AdiDeviceState deviceState) { public void onUpdatedAdiDeviceState(AdiDeviceState deviceState, boolean initSA) { if (deviceState == null) { return; } mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes()); mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes(), initSA); mSoundDoseHelper.setAudioDeviceCategory(deviceState.getDeviceAddress(), deviceState.getInternalDeviceType(), deviceState.getAudioDeviceCategory() == AUDIO_DEVICE_CATEGORY_HEADPHONES); Loading services/core/java/com/android/server/audio/SpatializerHelper.java +9 −6 Original line number Diff line number Diff line Loading @@ -295,11 +295,11 @@ public class SpatializerHelper { // could have been called another time after boot in case of audioserver restart addCompatibleAudioDevice( new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_SPEAKER, ""), false /*forceEnable*/); false /*forceEnable*/, false /*forceInit*/); // not force-enabling as this device might already be in the device list addCompatibleAudioDevice( new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE, ""), false /*forceEnable*/); false /*forceEnable*/, false /*forceInit*/); } catch (RemoteException e) { resetCapabilities(); } finally { Loading Loading @@ -526,7 +526,7 @@ public class SpatializerHelper { } synchronized void addCompatibleAudioDevice(@NonNull AudioDeviceAttributes ada) { addCompatibleAudioDevice(ada, true /*forceEnable*/); addCompatibleAudioDevice(ada, true /*forceEnable*/, false /*forceInit*/); } /** Loading @@ -540,7 +540,7 @@ public class SpatializerHelper { */ @GuardedBy("this") private void addCompatibleAudioDevice(@NonNull AudioDeviceAttributes ada, boolean forceEnable) { boolean forceEnable, boolean forceInit) { if (!isDeviceCompatibleWithSpatializationModes(ada)) { return; } Loading @@ -548,6 +548,9 @@ public class SpatializerHelper { final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada); AdiDeviceState updatedDevice = null; // non-null on update. if (deviceState != null) { if (forceInit) { initSAState(deviceState); } if (forceEnable && !deviceState.isSAEnabled()) { updatedDevice = deviceState; updatedDevice.setSAEnabled(true); Loading Loading @@ -756,10 +759,10 @@ public class SpatializerHelper { } } synchronized void refreshDevice(@NonNull AudioDeviceAttributes ada) { synchronized void refreshDevice(@NonNull AudioDeviceAttributes ada, boolean initState) { final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada); if (isAvailableForAdiDeviceState(deviceState)) { addCompatibleAudioDevice(ada, /*forceEnable=*/deviceState.isSAEnabled()); addCompatibleAudioDevice(ada, /*forceEnable=*/deviceState.isSAEnabled(), initState); setHeadTrackerEnabled(deviceState.isHeadTrackerEnabled(), ada); } else { removeCompatibleAudioDevice(ada); Loading services/tests/servicestests/src/com/android/server/audio/AudioDeviceBrokerTest.java +4 −3 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; 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.eq; import static org.mockito.Mockito.any; Loading Loading @@ -315,7 +316,7 @@ public class AudioDeviceBrokerTest { mFakeBtDevice.getAddress())); verify(mMockAudioService, timeout(MAX_MESSAGE_HANDLING_DELAY_MS).times(0)).onUpdatedAdiDeviceState( eq(devState)); eq(devState), anyBoolean()); } // metadata set Loading @@ -326,7 +327,7 @@ public class AudioDeviceBrokerTest { mFakeBtDevice.getAddress())); verify(mMockAudioService, timeout(MAX_MESSAGE_HANDLING_DELAY_MS)).onUpdatedAdiDeviceState( any()); any(), anyBoolean()); } } finally { // reset the metadata device type Loading Loading @@ -354,7 +355,7 @@ public class AudioDeviceBrokerTest { verify(mMockAudioService, timeout(MAX_MESSAGE_HANDLING_DELAY_MS).atLeast(1)).onUpdatedAdiDeviceState( ArgumentMatchers.argThat(devState -> devState.getAudioDeviceCategory() == AudioManager.AUDIO_DEVICE_CATEGORY_OTHER)); == AudioManager.AUDIO_DEVICE_CATEGORY_OTHER), anyBoolean()); } private void doTestConnectionDisconnectionReconnection(int delayAfterDisconnection, Loading Loading
services/core/java/com/android/server/audio/AudioDeviceBroker.java +6 −5 Original line number Diff line number Diff line Loading @@ -1535,8 +1535,9 @@ public class AudioDeviceBroker { sendLMsgNoDelay(MSG_L_SYNCHRONIZE_ADI_DEVICES_IN_INVENTORY, SENDMSG_QUEUE, deviceState); } /*package*/ void postUpdatedAdiDeviceState(AdiDeviceState deviceState) { sendLMsgNoDelay(MSG_L_UPDATED_ADI_DEVICE_STATE, SENDMSG_QUEUE, deviceState); /*package*/ void postUpdatedAdiDeviceState(AdiDeviceState deviceState, boolean initSA) { sendILMsgNoDelay( MSG_IL_UPDATED_ADI_DEVICE_STATE, SENDMSG_QUEUE, initSA ? 1 : 0, deviceState); } /*package*/ static final class CommunicationDeviceInfo { Loading Loading @@ -2068,8 +2069,8 @@ public class AudioDeviceBroker { } } break; case MSG_L_UPDATED_ADI_DEVICE_STATE: mAudioService.onUpdatedAdiDeviceState((AdiDeviceState) msg.obj); case MSG_IL_UPDATED_ADI_DEVICE_STATE: mAudioService.onUpdatedAdiDeviceState((AdiDeviceState) msg.obj, msg.arg1 == 1); break; default: Loading Loading @@ -2156,7 +2157,7 @@ public class AudioDeviceBroker { private static final int MSG_CHECK_COMMUNICATION_ROUTE_CLIENT_STATE = 56; private static final int MSG_I_UPDATE_LE_AUDIO_GROUP_ADDRESSES = 57; private static final int MSG_L_SYNCHRONIZE_ADI_DEVICES_IN_INVENTORY = 58; private static final int MSG_L_UPDATED_ADI_DEVICE_STATE = 59; private static final int MSG_IL_UPDATED_ADI_DEVICE_STATE = 59; Loading
services/core/java/com/android/server/audio/AudioDeviceInventory.java +6 −6 Original line number Diff line number Diff line Loading @@ -169,7 +169,7 @@ public class AudioDeviceInventory { if (ads != null) { if (ads.getAudioDeviceCategory() != category) { ads.setAudioDeviceCategory(category); mDeviceBroker.postUpdatedAdiDeviceState(ads); mDeviceBroker.postUpdatedAdiDeviceState(ads, false /*initSA*/); mDeviceBroker.postPersistAudioDeviceSettings(); } mDeviceBroker.postSynchronizeAdiDevicesInInventory(ads); Loading @@ -182,7 +182,7 @@ public class AudioDeviceInventory { mDeviceInventory.put(ads.getDeviceId(), ads); checkDeviceInventorySize_l(); mDeviceBroker.postUpdatedAdiDeviceState(ads); mDeviceBroker.postUpdatedAdiDeviceState(ads, true /*initSA*/); mDeviceBroker.postPersistAudioDeviceSettings(); } } Loading Loading @@ -212,7 +212,7 @@ public class AudioDeviceInventory { checkDeviceInventorySize_l(); } if (updatedCategory.get()) { mDeviceBroker.postUpdatedAdiDeviceState(deviceState); mDeviceBroker.postUpdatedAdiDeviceState(deviceState, false /*initSA*/); } mDeviceBroker.postSynchronizeAdiDevicesInInventory(deviceState); } Loading Loading @@ -314,7 +314,7 @@ public class AudioDeviceInventory { } ads2.setAudioDeviceCategory(updatedDevice.getAudioDeviceCategory()); mDeviceBroker.postUpdatedAdiDeviceState(ads2); mDeviceBroker.postUpdatedAdiDeviceState(ads2, false /*initSA*/); AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "synchronizeBleDeviceInInventory synced device pair ads1=" + updatedDevice + " ads2=" + ads2).printLog(TAG)); Loading @@ -335,7 +335,7 @@ public class AudioDeviceInventory { } ads2.setAudioDeviceCategory(updatedDevice.getAudioDeviceCategory()); mDeviceBroker.postUpdatedAdiDeviceState(ads2); mDeviceBroker.postUpdatedAdiDeviceState(ads2, false /*initSA*/); AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "synchronizeBleDeviceInInventory synced device pair ads1=" + updatedDevice + " peer ads2=" + ads2).printLog(TAG)); Loading @@ -360,7 +360,7 @@ public class AudioDeviceInventory { } ads.setAudioDeviceCategory(updatedDevice.getAudioDeviceCategory()); mDeviceBroker.postUpdatedAdiDeviceState(ads); mDeviceBroker.postUpdatedAdiDeviceState(ads, false /*initSA*/); AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "synchronizeDeviceProfilesInInventory synced device pair ads1=" + updatedDevice + " ads2=" + ads).printLog(TAG)); Loading
services/core/java/com/android/server/audio/AudioService.java +4 −3 Original line number Diff line number Diff line Loading @@ -11253,7 +11253,8 @@ public class AudioService extends IAudioService.Stub mDeviceBroker.addOrUpdateBtAudioDeviceCategoryInInventory(deviceState); mDeviceBroker.postPersistAudioDeviceSettings(); mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes()); mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes(), false /* initState */); mSoundDoseHelper.setAudioDeviceCategory(addr, internalType, btAudioDeviceCategory == AUDIO_DEVICE_CATEGORY_HEADPHONES); } Loading Loading @@ -11324,11 +11325,11 @@ public class AudioService extends IAudioService.Stub /** Update the sound dose and spatializer state based on the new AdiDeviceState. */ @VisibleForTesting(visibility = PACKAGE) public void onUpdatedAdiDeviceState(AdiDeviceState deviceState) { public void onUpdatedAdiDeviceState(AdiDeviceState deviceState, boolean initSA) { if (deviceState == null) { return; } mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes()); mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes(), initSA); mSoundDoseHelper.setAudioDeviceCategory(deviceState.getDeviceAddress(), deviceState.getInternalDeviceType(), deviceState.getAudioDeviceCategory() == AUDIO_DEVICE_CATEGORY_HEADPHONES); Loading
services/core/java/com/android/server/audio/SpatializerHelper.java +9 −6 Original line number Diff line number Diff line Loading @@ -295,11 +295,11 @@ public class SpatializerHelper { // could have been called another time after boot in case of audioserver restart addCompatibleAudioDevice( new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_SPEAKER, ""), false /*forceEnable*/); false /*forceEnable*/, false /*forceInit*/); // not force-enabling as this device might already be in the device list addCompatibleAudioDevice( new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE, ""), false /*forceEnable*/); false /*forceEnable*/, false /*forceInit*/); } catch (RemoteException e) { resetCapabilities(); } finally { Loading Loading @@ -526,7 +526,7 @@ public class SpatializerHelper { } synchronized void addCompatibleAudioDevice(@NonNull AudioDeviceAttributes ada) { addCompatibleAudioDevice(ada, true /*forceEnable*/); addCompatibleAudioDevice(ada, true /*forceEnable*/, false /*forceInit*/); } /** Loading @@ -540,7 +540,7 @@ public class SpatializerHelper { */ @GuardedBy("this") private void addCompatibleAudioDevice(@NonNull AudioDeviceAttributes ada, boolean forceEnable) { boolean forceEnable, boolean forceInit) { if (!isDeviceCompatibleWithSpatializationModes(ada)) { return; } Loading @@ -548,6 +548,9 @@ public class SpatializerHelper { final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada); AdiDeviceState updatedDevice = null; // non-null on update. if (deviceState != null) { if (forceInit) { initSAState(deviceState); } if (forceEnable && !deviceState.isSAEnabled()) { updatedDevice = deviceState; updatedDevice.setSAEnabled(true); Loading Loading @@ -756,10 +759,10 @@ public class SpatializerHelper { } } synchronized void refreshDevice(@NonNull AudioDeviceAttributes ada) { synchronized void refreshDevice(@NonNull AudioDeviceAttributes ada, boolean initState) { final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada); if (isAvailableForAdiDeviceState(deviceState)) { addCompatibleAudioDevice(ada, /*forceEnable=*/deviceState.isSAEnabled()); addCompatibleAudioDevice(ada, /*forceEnable=*/deviceState.isSAEnabled(), initState); setHeadTrackerEnabled(deviceState.isHeadTrackerEnabled(), ada); } else { removeCompatibleAudioDevice(ada); Loading
services/tests/servicestests/src/com/android/server/audio/AudioDeviceBrokerTest.java +4 −3 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; 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.eq; import static org.mockito.Mockito.any; Loading Loading @@ -315,7 +316,7 @@ public class AudioDeviceBrokerTest { mFakeBtDevice.getAddress())); verify(mMockAudioService, timeout(MAX_MESSAGE_HANDLING_DELAY_MS).times(0)).onUpdatedAdiDeviceState( eq(devState)); eq(devState), anyBoolean()); } // metadata set Loading @@ -326,7 +327,7 @@ public class AudioDeviceBrokerTest { mFakeBtDevice.getAddress())); verify(mMockAudioService, timeout(MAX_MESSAGE_HANDLING_DELAY_MS)).onUpdatedAdiDeviceState( any()); any(), anyBoolean()); } } finally { // reset the metadata device type Loading Loading @@ -354,7 +355,7 @@ public class AudioDeviceBrokerTest { verify(mMockAudioService, timeout(MAX_MESSAGE_HANDLING_DELAY_MS).atLeast(1)).onUpdatedAdiDeviceState( ArgumentMatchers.argThat(devState -> devState.getAudioDeviceCategory() == AudioManager.AUDIO_DEVICE_CATEGORY_OTHER)); == AudioManager.AUDIO_DEVICE_CATEGORY_OTHER), anyBoolean()); } private void doTestConnectionDisconnectionReconnection(int delayAfterDisconnection, Loading