Loading packages/SettingsLib/aconfig/settingslib.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -69,3 +69,13 @@ flag { description: "Allow all widgets on the lock screen by default." bug: "328261690" } flag { name: "enable_determining_advanced_details_header_with_metadata" namespace: "pixel_cross_device_control" description: "Use metadata instead of device type to determine whether a bluetooth device should use advanced details header." bug: "328556903" metadata { purpose: PURPOSE_BUGFIX } } packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +17 −6 Original line number Diff line number Diff line Loading @@ -276,6 +276,14 @@ public class BluetoothUtils { if (isUntetheredHeadset(bluetoothDevice)) { return true; } if (Flags.enableDeterminingAdvancedDetailsHeaderWithMetadata()) { // A FastPair device that use advanced details header must have METADATA_MAIN_ICON if (getUriMetaData(bluetoothDevice, BluetoothDevice.METADATA_MAIN_ICON) != null) { Log.d(TAG, "isAdvancedDetailsHeader is true with main icon uri"); return true; } return false; } // The metadata is for Android S String deviceType = getStringMetaData(bluetoothDevice, BluetoothDevice.METADATA_DEVICE_TYPE); Loading @@ -302,13 +310,16 @@ public class BluetoothUtils { if (isUntetheredHeadset(bluetoothDevice)) { return true; } // The metadata is for Android S if (!Flags.enableDeterminingAdvancedDetailsHeaderWithMetadata()) { // The METADATA_IS_UNTETHERED_HEADSET of an untethered FastPair headset is always true, // so there's no need to check the device type. String deviceType = getStringMetaData(bluetoothDevice, BluetoothDevice.METADATA_DEVICE_TYPE); if (TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET)) { Log.d(TAG, "isAdvancedUntetheredDevice: is untethered device"); return true; } } return false; } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ package com.android.settingslib.bluetooth; import static com.android.settingslib.flags.Flags.FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; Loading @@ -33,11 +35,13 @@ import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.media.AudioManager; import android.net.Uri; import android.platform.test.flag.junit.SetFlagsRule; import android.util.Pair; import com.android.settingslib.widget.AdaptiveIcon; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; Loading Loading @@ -83,11 +87,15 @@ public class BluetoothUtilsTest { private static final String TEST_EXCLUSIVE_MANAGER_PACKAGE = "com.test.manager"; private static final String TEST_EXCLUSIVE_MANAGER_COMPONENT = "com.test.manager/.component"; @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Before public void setUp() { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); mSetFlagsRule.disableFlags(FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA); when(mLocalBluetoothManager.getProfileManager()).thenReturn(mProfileManager); when(mProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast); when(mProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant); Loading Loading @@ -252,6 +260,25 @@ public class BluetoothUtilsTest { assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isEqualTo(false); } @Test public void isAdvancedDetailsHeader_noMainIcon_returnFalse() { mSetFlagsRule.enableFlags(FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_MAIN_ICON)).thenReturn(null); assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isFalse(); } @Test public void isAdvancedDetailsHeader_hasMainIcon_returnTrue() { mSetFlagsRule.enableFlags(FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_MAIN_ICON)) .thenReturn(STRING_METADATA.getBytes()); assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isTrue(); } @Test public void isAdvancedUntetheredDevice_untetheredHeadset_returnTrue() { when(mBluetoothDevice.getMetadata( Loading Loading @@ -293,6 +320,18 @@ public class BluetoothUtilsTest { assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(false); } @Test public void isAdvancedUntetheredDevice_untetheredHeadsetMetadataIsFalse_returnFalse() { mSetFlagsRule.enableFlags(FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) .thenReturn("false".getBytes()); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)) .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes()); assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isFalse(); } @Test public void isAvailableMediaBluetoothDevice_isConnectedLeAudioDevice_returnTrue() { when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true); Loading Loading
packages/SettingsLib/aconfig/settingslib.aconfig +10 −0 Original line number Diff line number Diff line Loading @@ -69,3 +69,13 @@ flag { description: "Allow all widgets on the lock screen by default." bug: "328261690" } flag { name: "enable_determining_advanced_details_header_with_metadata" namespace: "pixel_cross_device_control" description: "Use metadata instead of device type to determine whether a bluetooth device should use advanced details header." bug: "328556903" metadata { purpose: PURPOSE_BUGFIX } }
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +17 −6 Original line number Diff line number Diff line Loading @@ -276,6 +276,14 @@ public class BluetoothUtils { if (isUntetheredHeadset(bluetoothDevice)) { return true; } if (Flags.enableDeterminingAdvancedDetailsHeaderWithMetadata()) { // A FastPair device that use advanced details header must have METADATA_MAIN_ICON if (getUriMetaData(bluetoothDevice, BluetoothDevice.METADATA_MAIN_ICON) != null) { Log.d(TAG, "isAdvancedDetailsHeader is true with main icon uri"); return true; } return false; } // The metadata is for Android S String deviceType = getStringMetaData(bluetoothDevice, BluetoothDevice.METADATA_DEVICE_TYPE); Loading @@ -302,13 +310,16 @@ public class BluetoothUtils { if (isUntetheredHeadset(bluetoothDevice)) { return true; } // The metadata is for Android S if (!Flags.enableDeterminingAdvancedDetailsHeaderWithMetadata()) { // The METADATA_IS_UNTETHERED_HEADSET of an untethered FastPair headset is always true, // so there's no need to check the device type. String deviceType = getStringMetaData(bluetoothDevice, BluetoothDevice.METADATA_DEVICE_TYPE); if (TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET)) { Log.d(TAG, "isAdvancedUntetheredDevice: is untethered device"); return true; } } return false; } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ package com.android.settingslib.bluetooth; import static com.android.settingslib.flags.Flags.FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; Loading @@ -33,11 +35,13 @@ import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.media.AudioManager; import android.net.Uri; import android.platform.test.flag.junit.SetFlagsRule; import android.util.Pair; import com.android.settingslib.widget.AdaptiveIcon; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; Loading Loading @@ -83,11 +87,15 @@ public class BluetoothUtilsTest { private static final String TEST_EXCLUSIVE_MANAGER_PACKAGE = "com.test.manager"; private static final String TEST_EXCLUSIVE_MANAGER_COMPONENT = "com.test.manager/.component"; @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Before public void setUp() { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); mSetFlagsRule.disableFlags(FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA); when(mLocalBluetoothManager.getProfileManager()).thenReturn(mProfileManager); when(mProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast); when(mProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant); Loading Loading @@ -252,6 +260,25 @@ public class BluetoothUtilsTest { assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isEqualTo(false); } @Test public void isAdvancedDetailsHeader_noMainIcon_returnFalse() { mSetFlagsRule.enableFlags(FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_MAIN_ICON)).thenReturn(null); assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isFalse(); } @Test public void isAdvancedDetailsHeader_hasMainIcon_returnTrue() { mSetFlagsRule.enableFlags(FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_MAIN_ICON)) .thenReturn(STRING_METADATA.getBytes()); assertThat(BluetoothUtils.isAdvancedDetailsHeader(mBluetoothDevice)).isTrue(); } @Test public void isAdvancedUntetheredDevice_untetheredHeadset_returnTrue() { when(mBluetoothDevice.getMetadata( Loading Loading @@ -293,6 +320,18 @@ public class BluetoothUtilsTest { assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isEqualTo(false); } @Test public void isAdvancedUntetheredDevice_untetheredHeadsetMetadataIsFalse_returnFalse() { mSetFlagsRule.enableFlags(FLAG_ENABLE_DETERMINING_ADVANCED_DETAILS_HEADER_WITH_METADATA); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) .thenReturn("false".getBytes()); when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)) .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes()); assertThat(BluetoothUtils.isAdvancedUntetheredDevice(mBluetoothDevice)).isFalse(); } @Test public void isAvailableMediaBluetoothDevice_isConnectedLeAudioDevice_returnTrue() { when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true); Loading