Loading packages/SettingsLib/src/com/android/settingslib/media/InputRouteManager.java +17 −5 Original line number Diff line number Diff line Loading @@ -80,8 +80,14 @@ public final class InputRouteManager { // behavior. @AudioDeviceType int deviceTypeToActivate = mSelectedInputDeviceType; for (AudioDeviceInfo info : addedDevices) { if (InputMediaDevice.isSupportedInputDevice(info.getType())) { deviceTypeToActivate = info.getType(); @AudioDeviceType int type = info.getType(); // Since onAudioDevicesAdded is called not only when new device is hot // plugged, but also when the switcher dialog is opened, make sure to check // against existing device list and only activate if the device does not // exist previously. if (InputMediaDevice.isSupportedInputDevice(type) && findDeviceByType(type) == null) { deviceTypeToActivate = type; } } Loading Loading @@ -140,16 +146,22 @@ public final class InputRouteManager { } // TODO(b/355684672): handle edge case where there are two devices with the same type. Only // using a single mSelectedInputDeviceType might not be enough to recognize the correct device. public @Nullable MediaDevice getSelectedInputDevice() { // using a single type might not be enough to recognize the correct device. @Nullable private MediaDevice findDeviceByType(@AudioDeviceType int type) { for (MediaDevice device : mInputMediaDevices) { if (((InputMediaDevice) device).getAudioDeviceInfoType() == mSelectedInputDeviceType) { if (((InputMediaDevice) device).getAudioDeviceInfoType() == type) { return device; } } return null; } @Nullable public MediaDevice getSelectedInputDevice() { return findDeviceByType(mSelectedInputDeviceType); } private void applyDefaultSelectedTypeToAllPresets() { mSelectedInputDeviceType = retrieveDefaultSelectedDeviceType(); AudioDeviceAttributes deviceAttributes = Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InputRouteManagerTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -360,6 +360,26 @@ public class InputRouteManagerTest { } } @Test public void onAudioDevicesAdded_doNotActivatePreexistingDevice() { final AudioManager audioManager = mock(AudioManager.class); InputRouteManager inputRouteManager = new InputRouteManager(mContext, audioManager); final AudioDeviceInfo info = mockWiredHeadsetInfo(); InputMediaDevice device = createInputMediaDeviceFromDeviceInfo(info); inputRouteManager.mInputMediaDevices.add(device); // Trigger onAudioDevicesAdded with a device that already exists in the device list. AudioDeviceInfo[] devices = {info}; inputRouteManager.mAudioDeviceCallback.onAudioDevicesAdded(devices); // The device should not be activated. for (@MediaRecorder.Source int preset : PRESETS) { verify(audioManager, never()) .setPreferredDeviceForCapturePreset(preset, getWiredHeadsetDeviceAttributes()); } } @Test public void onAudioDevicesRemoved_shouldApplyDefaultSelectedDeviceToAllPresets() { final AudioManager audioManager = mock(AudioManager.class); Loading Loading
packages/SettingsLib/src/com/android/settingslib/media/InputRouteManager.java +17 −5 Original line number Diff line number Diff line Loading @@ -80,8 +80,14 @@ public final class InputRouteManager { // behavior. @AudioDeviceType int deviceTypeToActivate = mSelectedInputDeviceType; for (AudioDeviceInfo info : addedDevices) { if (InputMediaDevice.isSupportedInputDevice(info.getType())) { deviceTypeToActivate = info.getType(); @AudioDeviceType int type = info.getType(); // Since onAudioDevicesAdded is called not only when new device is hot // plugged, but also when the switcher dialog is opened, make sure to check // against existing device list and only activate if the device does not // exist previously. if (InputMediaDevice.isSupportedInputDevice(type) && findDeviceByType(type) == null) { deviceTypeToActivate = type; } } Loading Loading @@ -140,16 +146,22 @@ public final class InputRouteManager { } // TODO(b/355684672): handle edge case where there are two devices with the same type. Only // using a single mSelectedInputDeviceType might not be enough to recognize the correct device. public @Nullable MediaDevice getSelectedInputDevice() { // using a single type might not be enough to recognize the correct device. @Nullable private MediaDevice findDeviceByType(@AudioDeviceType int type) { for (MediaDevice device : mInputMediaDevices) { if (((InputMediaDevice) device).getAudioDeviceInfoType() == mSelectedInputDeviceType) { if (((InputMediaDevice) device).getAudioDeviceInfoType() == type) { return device; } } return null; } @Nullable public MediaDevice getSelectedInputDevice() { return findDeviceByType(mSelectedInputDeviceType); } private void applyDefaultSelectedTypeToAllPresets() { mSelectedInputDeviceType = retrieveDefaultSelectedDeviceType(); AudioDeviceAttributes deviceAttributes = Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InputRouteManagerTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -360,6 +360,26 @@ public class InputRouteManagerTest { } } @Test public void onAudioDevicesAdded_doNotActivatePreexistingDevice() { final AudioManager audioManager = mock(AudioManager.class); InputRouteManager inputRouteManager = new InputRouteManager(mContext, audioManager); final AudioDeviceInfo info = mockWiredHeadsetInfo(); InputMediaDevice device = createInputMediaDeviceFromDeviceInfo(info); inputRouteManager.mInputMediaDevices.add(device); // Trigger onAudioDevicesAdded with a device that already exists in the device list. AudioDeviceInfo[] devices = {info}; inputRouteManager.mAudioDeviceCallback.onAudioDevicesAdded(devices); // The device should not be activated. for (@MediaRecorder.Source int preset : PRESETS) { verify(audioManager, never()) .setPreferredDeviceForCapturePreset(preset, getWiredHeadsetDeviceAttributes()); } } @Test public void onAudioDevicesRemoved_shouldApplyDefaultSelectedDeviceToAllPresets() { final AudioManager audioManager = mock(AudioManager.class); Loading