Loading packages/SettingsLib/src/com/android/settingslib/media/InputMediaDevice.java +16 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,8 @@ public class InputMediaDevice extends MediaDevice { private final boolean mIsVolumeFixed; private final boolean mIsSelected; private final String mProductName; private InputMediaDevice( Loading @@ -62,6 +64,7 @@ public class InputMediaDevice extends MediaDevice { int maxVolume, int currentVolume, boolean isVolumeFixed, boolean isSelected, @Nullable String productName) { super(context, /* routeInfo= */ null, /* dynamicRouteAttributes= */ null, /* rlpItem= */ null); Loading @@ -71,6 +74,7 @@ public class InputMediaDevice extends MediaDevice { mMaxVolume = maxVolume; mCurrentVolume = currentVolume; mIsVolumeFixed = isVolumeFixed; mIsSelected = isSelected; mProductName = productName; initDeviceRecord(); } Loading @@ -84,6 +88,7 @@ public class InputMediaDevice extends MediaDevice { int maxVolume, int currentVolume, boolean isVolumeFixed, boolean isSelected, @Nullable String productName) { if (!isSupportedInputDevice(audioDeviceInfoType)) { return null; Loading @@ -97,6 +102,7 @@ public class InputMediaDevice extends MediaDevice { maxVolume, currentVolume, isVolumeFixed, isSelected, productName); } Loading Loading @@ -197,4 +203,14 @@ public class InputMediaDevice extends MediaDevice { public boolean isVolumeFixed() { return mIsVolumeFixed; } @Override public boolean isSelected() { return mIsSelected; } @Override public boolean isInputDevice() { return true; } } packages/SettingsLib/src/com/android/settingslib/media/InputRouteManager.java +10 −33 Original line number Diff line number Diff line Loading @@ -209,33 +209,6 @@ public final class InputRouteManager { return null; } @Nullable private MediaDevice findDeviceByType(@AudioDeviceType int type) { for (MediaDevice device : mInputMediaDevices) { if (((InputMediaDevice) device).getAudioDeviceInfoType() == type) { return device; } } return null; } @Nullable public MediaDevice getSelectedInputDevice() { MediaDevice exactDevice = findDeviceByTypeAndAddress(mSelectedInputDeviceType, mSelectedInputDeviceAddr); // This can happen because the address can sometimes contain surprising strings // such as "bottom" for the default internal mic. In those situations, // ignore the address and search by the type only. In any case, this also // serves as a sane fallback. if (exactDevice == null) { MediaDevice device = findDeviceByType(mSelectedInputDeviceType); return device; } return exactDevice; } private void applyDefaultSelectedTypeToAllPresets() { AudioDeviceAttributes deviceAttributes = retrieveDefaultSelectedInputDeviceAttrs(); Loading Loading @@ -278,6 +251,7 @@ public final class InputRouteManager { mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS); mInputMediaDevices.clear(); for (AudioDeviceInfo info : audioDeviceInfos) { boolean isSelected = isSelectedDevice(info.getType(), info.getAddress()); MediaDevice mediaDevice = InputMediaDevice.create( mContext, Loading @@ -287,11 +261,10 @@ public final class InputRouteManager { getMaxInputGain(), getCurrentInputGain(), isInputGainFixed(), isSelected, getProductNameFromAudioDeviceInfo(info)); if (mediaDevice != null) { if (info.getType() == mSelectedInputDeviceType && (TextUtils.isEmpty(mSelectedInputDeviceAddr) || info.getAddress() == mSelectedInputDeviceAddr)) { if (isSelected) { mInfoMediaManager.setDeviceState(mediaDevice, STATE_SELECTED); } mInputMediaDevices.add(mediaDevice); Loading @@ -306,6 +279,11 @@ public final class InputRouteManager { } } private boolean isSelectedDevice(@AudioDeviceType int type, @NonNull String address) { return type == mSelectedInputDeviceType && (TextUtils.isEmpty(mSelectedInputDeviceAddr) || address.equals(mSelectedInputDeviceAddr)); } /** * Gets the product name for the given {@link AudioDeviceInfo}. * Loading @@ -331,9 +309,8 @@ public final class InputRouteManager { return; } if (inputMediaDevice.getAudioDeviceInfoType() == mSelectedInputDeviceType && (TextUtils.isEmpty(mSelectedInputDeviceAddr) || inputMediaDevice.getAddress().equals(mSelectedInputDeviceAddr))) { if (isSelectedDevice(inputMediaDevice.getAudioDeviceInfoType(), inputMediaDevice.getAddress())) { Slog.w(TAG, "This device is already selected: " + device.getName()); return; } Loading packages/SettingsLib/src/com/android/settingslib/media/MediaDevice.java +4 −0 Original line number Diff line number Diff line Loading @@ -408,6 +408,10 @@ public abstract class MediaDevice implements Comparable<MediaDevice> { return mRouteInfo.getType() == TYPE_BLE_HEADSET; } public boolean isInputDevice() { return false; } /** * Get application label from MediaDevice. * Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InputMediaDeviceTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ public class InputMediaDeviceTest { private final int MAX_VOLUME = 1; private final int CURRENT_VOLUME = 0; private final boolean IS_VOLUME_FIXED = true; private static final boolean IS_SELECTED = true; private static final String PRODUCT_NAME_BUILTIN_MIC = "Built-in Mic"; private static final String PRODUCT_NAME_WIRED_HEADSET = "My Wired Headset"; private static final String PRODUCT_NAME_USB_HEADSET = "My USB Headset"; Loading Loading @@ -73,6 +74,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_BUILTIN_MIC); assertThat(builtinMediaDevice).isNotNull(); assertThat(builtinMediaDevice.getDrawableResId()).isEqualTo(R.drawable.ic_media_microphone); Loading @@ -89,6 +91,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_BUILTIN_MIC); assertThat(builtinMediaDevice).isNotNull(); assertThat(builtinMediaDevice.getName()) Loading @@ -106,6 +109,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_WIRED_HEADSET); assertThat(wiredMediaDevice).isNotNull(); assertThat(wiredMediaDevice.getName()) Loading @@ -123,6 +127,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_USB_HEADSET); assertThat(usbMediaDevice).isNotNull(); assertThat(usbMediaDevice.getName()).isEqualTo(PRODUCT_NAME_USB_HEADSET); Loading @@ -139,6 +144,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, null); assertThat(usbMediaDevice).isNotNull(); assertThat(usbMediaDevice.getName()) Loading @@ -156,6 +162,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_BT_HEADSET); assertThat(btMediaDevice).isNotNull(); assertThat(btMediaDevice.getName()).isEqualTo(PRODUCT_NAME_BT_HEADSET); Loading @@ -172,6 +179,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, null); assertThat(btMediaDevice).isNotNull(); assertThat(btMediaDevice.getName()) Loading @@ -189,6 +197,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_BLE_HEADSET); assertThat(bleMediaDevice).isNotNull(); assertThat(bleMediaDevice.getName()).isEqualTo(PRODUCT_NAME_BLE_HEADSET); Loading @@ -205,6 +214,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, null); assertThat(bleMediaDevice).isNotNull(); assertThat(bleMediaDevice.getName()) Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InputRouteManagerTest.java +14 −9 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import android.media.AudioDeviceInfo; import android.media.AudioManager; import android.media.MediaRecorder; import androidx.annotation.Nullable; import com.android.settingslib.testutils.shadow.ShadowRouter2Manager; import org.junit.Before; Loading Loading @@ -256,9 +258,7 @@ public class InputRouteManagerTest { onPreferredDevicesForCapturePresetChanged(); // The selected input device has the same type as the one returned from AudioManager. InputMediaDevice selectedInputDevice = (InputMediaDevice) mInputRouteManager.getSelectedInputDevice(); assertThat(selectedInputDevice.getAudioDeviceInfoType()) assertThat(getSelectedInputDevice().getAudioDeviceInfoType()) .isEqualTo(AudioDeviceInfo.TYPE_WIRED_HEADSET); } Loading @@ -278,9 +278,7 @@ public class InputRouteManagerTest { onPreferredDevicesForCapturePresetChanged(); // The selected input device has the same type as the first one returned from AudioManager. InputMediaDevice selectedInputDevice = (InputMediaDevice) mInputRouteManager.getSelectedInputDevice(); assertThat(selectedInputDevice.getAudioDeviceInfoType()) assertThat(getSelectedInputDevice().getAudioDeviceInfoType()) .isEqualTo(AudioDeviceInfo.TYPE_WIRED_HEADSET); } Loading @@ -297,9 +295,7 @@ public class InputRouteManagerTest { onPreferredDevicesForCapturePresetChanged(); // The selected input device has default type AudioDeviceInfo.TYPE_BUILTIN_MIC. InputMediaDevice selectedInputDevice = (InputMediaDevice) mInputRouteManager.getSelectedInputDevice(); assertThat(selectedInputDevice.getAudioDeviceInfoType()) assertThat(getSelectedInputDevice().getAudioDeviceInfoType()) .isEqualTo(AudioDeviceInfo.TYPE_BUILTIN_MIC); } Loading @@ -314,6 +310,7 @@ public class InputRouteManagerTest { MAX_VOLUME, CURRENT_VOLUME, VOLUME_FIXED_TRUE, /* isSelected= */ false, PRODUCT_NAME_BUILTIN_MIC); mInputRouteManager.selectDevice(builtinMicDevice); Loading Loading @@ -429,6 +426,7 @@ public class InputRouteManagerTest { MAX_VOLUME, CURRENT_VOLUME, VOLUME_FIXED_TRUE, /* isSelected= */ false, PRODUCT_NAME_USB_ACCESSORY); AudioDeviceInfo[] devices = {mockUsbHeadsetInfo()}; Loading Loading @@ -519,6 +517,13 @@ public class InputRouteManagerTest { MAX_VOLUME, CURRENT_VOLUME, VOLUME_FIXED_TRUE, /* isSelected= */ false, info.getProductName() == null ? null : info.getProductName().toString()); } @Nullable private InputMediaDevice getSelectedInputDevice() { return (InputMediaDevice) mInputRouteManager.mInputMediaDevices.stream().filter( MediaDevice::isSelected).findFirst().orElse(null); } } Loading
packages/SettingsLib/src/com/android/settingslib/media/InputMediaDevice.java +16 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,8 @@ public class InputMediaDevice extends MediaDevice { private final boolean mIsVolumeFixed; private final boolean mIsSelected; private final String mProductName; private InputMediaDevice( Loading @@ -62,6 +64,7 @@ public class InputMediaDevice extends MediaDevice { int maxVolume, int currentVolume, boolean isVolumeFixed, boolean isSelected, @Nullable String productName) { super(context, /* routeInfo= */ null, /* dynamicRouteAttributes= */ null, /* rlpItem= */ null); Loading @@ -71,6 +74,7 @@ public class InputMediaDevice extends MediaDevice { mMaxVolume = maxVolume; mCurrentVolume = currentVolume; mIsVolumeFixed = isVolumeFixed; mIsSelected = isSelected; mProductName = productName; initDeviceRecord(); } Loading @@ -84,6 +88,7 @@ public class InputMediaDevice extends MediaDevice { int maxVolume, int currentVolume, boolean isVolumeFixed, boolean isSelected, @Nullable String productName) { if (!isSupportedInputDevice(audioDeviceInfoType)) { return null; Loading @@ -97,6 +102,7 @@ public class InputMediaDevice extends MediaDevice { maxVolume, currentVolume, isVolumeFixed, isSelected, productName); } Loading Loading @@ -197,4 +203,14 @@ public class InputMediaDevice extends MediaDevice { public boolean isVolumeFixed() { return mIsVolumeFixed; } @Override public boolean isSelected() { return mIsSelected; } @Override public boolean isInputDevice() { return true; } }
packages/SettingsLib/src/com/android/settingslib/media/InputRouteManager.java +10 −33 Original line number Diff line number Diff line Loading @@ -209,33 +209,6 @@ public final class InputRouteManager { return null; } @Nullable private MediaDevice findDeviceByType(@AudioDeviceType int type) { for (MediaDevice device : mInputMediaDevices) { if (((InputMediaDevice) device).getAudioDeviceInfoType() == type) { return device; } } return null; } @Nullable public MediaDevice getSelectedInputDevice() { MediaDevice exactDevice = findDeviceByTypeAndAddress(mSelectedInputDeviceType, mSelectedInputDeviceAddr); // This can happen because the address can sometimes contain surprising strings // such as "bottom" for the default internal mic. In those situations, // ignore the address and search by the type only. In any case, this also // serves as a sane fallback. if (exactDevice == null) { MediaDevice device = findDeviceByType(mSelectedInputDeviceType); return device; } return exactDevice; } private void applyDefaultSelectedTypeToAllPresets() { AudioDeviceAttributes deviceAttributes = retrieveDefaultSelectedInputDeviceAttrs(); Loading Loading @@ -278,6 +251,7 @@ public final class InputRouteManager { mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS); mInputMediaDevices.clear(); for (AudioDeviceInfo info : audioDeviceInfos) { boolean isSelected = isSelectedDevice(info.getType(), info.getAddress()); MediaDevice mediaDevice = InputMediaDevice.create( mContext, Loading @@ -287,11 +261,10 @@ public final class InputRouteManager { getMaxInputGain(), getCurrentInputGain(), isInputGainFixed(), isSelected, getProductNameFromAudioDeviceInfo(info)); if (mediaDevice != null) { if (info.getType() == mSelectedInputDeviceType && (TextUtils.isEmpty(mSelectedInputDeviceAddr) || info.getAddress() == mSelectedInputDeviceAddr)) { if (isSelected) { mInfoMediaManager.setDeviceState(mediaDevice, STATE_SELECTED); } mInputMediaDevices.add(mediaDevice); Loading @@ -306,6 +279,11 @@ public final class InputRouteManager { } } private boolean isSelectedDevice(@AudioDeviceType int type, @NonNull String address) { return type == mSelectedInputDeviceType && (TextUtils.isEmpty(mSelectedInputDeviceAddr) || address.equals(mSelectedInputDeviceAddr)); } /** * Gets the product name for the given {@link AudioDeviceInfo}. * Loading @@ -331,9 +309,8 @@ public final class InputRouteManager { return; } if (inputMediaDevice.getAudioDeviceInfoType() == mSelectedInputDeviceType && (TextUtils.isEmpty(mSelectedInputDeviceAddr) || inputMediaDevice.getAddress().equals(mSelectedInputDeviceAddr))) { if (isSelectedDevice(inputMediaDevice.getAudioDeviceInfoType(), inputMediaDevice.getAddress())) { Slog.w(TAG, "This device is already selected: " + device.getName()); return; } Loading
packages/SettingsLib/src/com/android/settingslib/media/MediaDevice.java +4 −0 Original line number Diff line number Diff line Loading @@ -408,6 +408,10 @@ public abstract class MediaDevice implements Comparable<MediaDevice> { return mRouteInfo.getType() == TYPE_BLE_HEADSET; } public boolean isInputDevice() { return false; } /** * Get application label from MediaDevice. * Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InputMediaDeviceTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ public class InputMediaDeviceTest { private final int MAX_VOLUME = 1; private final int CURRENT_VOLUME = 0; private final boolean IS_VOLUME_FIXED = true; private static final boolean IS_SELECTED = true; private static final String PRODUCT_NAME_BUILTIN_MIC = "Built-in Mic"; private static final String PRODUCT_NAME_WIRED_HEADSET = "My Wired Headset"; private static final String PRODUCT_NAME_USB_HEADSET = "My USB Headset"; Loading Loading @@ -73,6 +74,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_BUILTIN_MIC); assertThat(builtinMediaDevice).isNotNull(); assertThat(builtinMediaDevice.getDrawableResId()).isEqualTo(R.drawable.ic_media_microphone); Loading @@ -89,6 +91,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_BUILTIN_MIC); assertThat(builtinMediaDevice).isNotNull(); assertThat(builtinMediaDevice.getName()) Loading @@ -106,6 +109,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_WIRED_HEADSET); assertThat(wiredMediaDevice).isNotNull(); assertThat(wiredMediaDevice.getName()) Loading @@ -123,6 +127,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_USB_HEADSET); assertThat(usbMediaDevice).isNotNull(); assertThat(usbMediaDevice.getName()).isEqualTo(PRODUCT_NAME_USB_HEADSET); Loading @@ -139,6 +144,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, null); assertThat(usbMediaDevice).isNotNull(); assertThat(usbMediaDevice.getName()) Loading @@ -156,6 +162,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_BT_HEADSET); assertThat(btMediaDevice).isNotNull(); assertThat(btMediaDevice.getName()).isEqualTo(PRODUCT_NAME_BT_HEADSET); Loading @@ -172,6 +179,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, null); assertThat(btMediaDevice).isNotNull(); assertThat(btMediaDevice.getName()) Loading @@ -189,6 +197,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, PRODUCT_NAME_BLE_HEADSET); assertThat(bleMediaDevice).isNotNull(); assertThat(bleMediaDevice.getName()).isEqualTo(PRODUCT_NAME_BLE_HEADSET); Loading @@ -205,6 +214,7 @@ public class InputMediaDeviceTest { MAX_VOLUME, CURRENT_VOLUME, IS_VOLUME_FIXED, IS_SELECTED, null); assertThat(bleMediaDevice).isNotNull(); assertThat(bleMediaDevice.getName()) Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InputRouteManagerTest.java +14 −9 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import android.media.AudioDeviceInfo; import android.media.AudioManager; import android.media.MediaRecorder; import androidx.annotation.Nullable; import com.android.settingslib.testutils.shadow.ShadowRouter2Manager; import org.junit.Before; Loading Loading @@ -256,9 +258,7 @@ public class InputRouteManagerTest { onPreferredDevicesForCapturePresetChanged(); // The selected input device has the same type as the one returned from AudioManager. InputMediaDevice selectedInputDevice = (InputMediaDevice) mInputRouteManager.getSelectedInputDevice(); assertThat(selectedInputDevice.getAudioDeviceInfoType()) assertThat(getSelectedInputDevice().getAudioDeviceInfoType()) .isEqualTo(AudioDeviceInfo.TYPE_WIRED_HEADSET); } Loading @@ -278,9 +278,7 @@ public class InputRouteManagerTest { onPreferredDevicesForCapturePresetChanged(); // The selected input device has the same type as the first one returned from AudioManager. InputMediaDevice selectedInputDevice = (InputMediaDevice) mInputRouteManager.getSelectedInputDevice(); assertThat(selectedInputDevice.getAudioDeviceInfoType()) assertThat(getSelectedInputDevice().getAudioDeviceInfoType()) .isEqualTo(AudioDeviceInfo.TYPE_WIRED_HEADSET); } Loading @@ -297,9 +295,7 @@ public class InputRouteManagerTest { onPreferredDevicesForCapturePresetChanged(); // The selected input device has default type AudioDeviceInfo.TYPE_BUILTIN_MIC. InputMediaDevice selectedInputDevice = (InputMediaDevice) mInputRouteManager.getSelectedInputDevice(); assertThat(selectedInputDevice.getAudioDeviceInfoType()) assertThat(getSelectedInputDevice().getAudioDeviceInfoType()) .isEqualTo(AudioDeviceInfo.TYPE_BUILTIN_MIC); } Loading @@ -314,6 +310,7 @@ public class InputRouteManagerTest { MAX_VOLUME, CURRENT_VOLUME, VOLUME_FIXED_TRUE, /* isSelected= */ false, PRODUCT_NAME_BUILTIN_MIC); mInputRouteManager.selectDevice(builtinMicDevice); Loading Loading @@ -429,6 +426,7 @@ public class InputRouteManagerTest { MAX_VOLUME, CURRENT_VOLUME, VOLUME_FIXED_TRUE, /* isSelected= */ false, PRODUCT_NAME_USB_ACCESSORY); AudioDeviceInfo[] devices = {mockUsbHeadsetInfo()}; Loading Loading @@ -519,6 +517,13 @@ public class InputRouteManagerTest { MAX_VOLUME, CURRENT_VOLUME, VOLUME_FIXED_TRUE, /* isSelected= */ false, info.getProductName() == null ? null : info.getProductName().toString()); } @Nullable private InputMediaDevice getSelectedInputDevice() { return (InputMediaDevice) mInputRouteManager.mInputMediaDevices.stream().filter( MediaDevice::isSelected).findFirst().orElse(null); } }