From e004eaa51b1f71de8f903fce6da50a3307135c1a Mon Sep 17 00:00:00 2001 From: Etienne Ruffieux Date: Thu, 7 Oct 2021 16:40:15 +0000 Subject: [PATCH 1/2] Make BluetoothCodecConfig and BluetoothCodecStatus public Tag: #feature Bug: 200202780 Test: make RunSettingsRoboTests Change-Id: I2a81216de050b143cee5c537d899a699d5012330 --- .../development/BluetoothA2dpConfigStore.java | 16 +++-- ...ctBluetoothDialogPreferenceController.java | 16 +++-- ...etoothCodecDialogPreferenceController.java | 8 +-- ...uetoothDialogPreferenceControllerTest.java | 23 +++++--- ...rSampleDialogPreferenceControllerTest.java | 28 ++++----- ...nelModeDialogPreferenceControllerTest.java | 28 ++++----- ...thCodecDialogPreferenceControllerTest.java | 59 ++++++++++++------- ...QualityDialogPreferenceControllerTest.java | 30 +++++----- ...pleRateDialogPreferenceControllerTest.java | 34 ++++++----- 9 files changed, 139 insertions(+), 103 deletions(-) diff --git a/src/com/android/settings/development/BluetoothA2dpConfigStore.java b/src/com/android/settings/development/BluetoothA2dpConfigStore.java index 0b154d245a3..7fd7b133f38 100644 --- a/src/com/android/settings/development/BluetoothA2dpConfigStore.java +++ b/src/com/android/settings/development/BluetoothA2dpConfigStore.java @@ -71,10 +71,16 @@ public class BluetoothA2dpConfigStore { } public BluetoothCodecConfig createCodecConfig() { - return new BluetoothCodecConfig(mCodecType, mCodecPriority, - mSampleRate, mBitsPerSample, - mChannelMode, mCodecSpecific1Value, - mCodecSpecific2Value, mCodecSpecific3Value, - mCodecSpecific4Value); + return new BluetoothCodecConfig.Builder() + .setCodecType(mCodecType) + .setCodecPriority(mCodecPriority) + .setSampleRate(mSampleRate) + .setBitsPerSample(mBitsPerSample) + .setChannelMode(mChannelMode) + .setCodecSpecific1(mCodecSpecific1Value) + .setCodecSpecific2(mCodecSpecific2Value) + .setCodecSpecific3(mCodecSpecific3Value) + .setCodecSpecific4(mCodecSpecific4Value) + .build(); } } diff --git a/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java index 765c5f85ef6..1af6e969001 100644 --- a/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java +++ b/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceController.java @@ -30,6 +30,8 @@ import androidx.preference.Preference; import com.android.settings.development.BluetoothA2dpConfigStore; import com.android.settingslib.core.lifecycle.Lifecycle; +import java.util.List; + /** * Abstract class for Bluetooth A2DP config dialog controller in developer option. */ @@ -170,7 +172,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends * * @return Array of {@link BluetoothCodecConfig}. */ - protected BluetoothCodecConfig[] getSelectableConfigs(BluetoothDevice device) { + protected List getSelectableConfigs(BluetoothDevice device) { final BluetoothA2dp bluetoothA2dp = mBluetoothA2dp; if (bluetoothA2dp == null) { return null; @@ -198,11 +200,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends Log.d(TAG, "Unable to get selectable config. No active device."); return null; } - final BluetoothCodecConfig[] configs = getSelectableConfigs(activeDevice); - if (configs == null) { - Log.d(TAG, "Unable to get selectable config. Selectable configs is empty."); - return null; - } + final List configs = getSelectableConfigs(activeDevice); for (BluetoothCodecConfig config : configs) { if (config.getCodecType() == codecTypeValue) { return config; @@ -220,7 +218,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends public void onHDAudioEnabled(boolean enabled) {} static int getHighestCodec(BluetoothA2dp bluetoothA2dp, BluetoothDevice activeDevice, - BluetoothCodecConfig[] configs) { + List configs) { if (configs == null) { Log.d(TAG, "Unable to get highest codec. Configs are empty"); return BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID; @@ -231,8 +229,8 @@ public abstract class AbstractBluetoothDialogPreferenceController extends return BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC; } for (int i = 0; i < CODEC_TYPES.length; i++) { - for (int j = 0; j < configs.length; j++) { - if ((configs[j].getCodecType() == CODEC_TYPES[i])) { + for (BluetoothCodecConfig config : configs) { + if (config.getCodecType() == CODEC_TYPES[i]) { return CODEC_TYPES[i]; } } diff --git a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java index b1b58e55c55..5f916f38d1a 100644 --- a/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java +++ b/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceController.java @@ -77,7 +77,7 @@ public class BluetoothCodecDialogPreferenceController extends // Check HD audio is enabled, display the available list. if (bluetoothA2dp.isOptionalCodecsEnabled(activeDevice) == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) { - BluetoothCodecConfig[] configs = getSelectableConfigs(activeDevice); + List configs = getSelectableConfigs(activeDevice); if (configs != null) { return getIndexFromConfig(configs); } @@ -153,10 +153,10 @@ public class BluetoothCodecDialogPreferenceController extends writeConfigurationValues(/* index= */ 0); } - private List getIndexFromConfig(BluetoothCodecConfig[] configs) { + private List getIndexFromConfig(List configs) { List indexArray = new ArrayList<>(); - for (int i = 0; i < configs.length; i++) { - indexArray.add(convertCfgToBtnIndex(configs[i].getCodecType())); + for (BluetoothCodecConfig config : configs) { + indexArray.add(convertCfgToBtnIndex(config.getCodecType())); } return indexArray; } diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java index a12131d51f6..c1648bf4fb0 100644 --- a/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/bluetooth/AbstractBluetoothDialogPreferenceControllerTest.java @@ -47,6 +47,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; @RunWith(RobolectricTestRunner.class) @@ -85,8 +86,12 @@ public class AbstractBluetoothDialogPreferenceControllerTest { mBluetoothA2dpConfigStore)); mPreference = spy(new BaseBluetoothDialogPreferenceImpl(mContext)); - mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC); - mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC); + mCodecConfigAAC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC) + .build(); + mCodecConfigSBC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) + .build(); mCodecConfigs[0] = mCodecConfigAAC; mCodecConfigs[1] = mCodecConfigSBC; @@ -160,17 +165,19 @@ public class AbstractBluetoothDialogPreferenceControllerTest { @Test public void getSelectableConfigs_verifyConfig() { - mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus( mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); - assertThat(mController.getSelectableConfigs(null)).isEqualTo(mCodecConfigs); + assertThat(mController.getSelectableConfigs(null)).isEqualTo(Arrays.asList(mCodecConfigs)); } @Test public void getSelectableByCodecType_verifyConfig() { - mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus( mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); @@ -181,7 +188,8 @@ public class AbstractBluetoothDialogPreferenceControllerTest { @Test public void getSelectableByCodecType_unavailable() { - mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus( mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); @@ -192,7 +200,8 @@ public class AbstractBluetoothDialogPreferenceControllerTest { @Test public void onBluetoothServiceConnected_verifyBluetoothA2dpConfigStore() { - mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus( mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java index 0996ae3fcb9..a042ebe1e6b 100644 --- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothBitPerSampleDialogPreferenceControllerTest.java @@ -44,6 +44,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; @RunWith(RobolectricTestRunner.class) @@ -80,25 +81,23 @@ public class BluetoothBitPerSampleDialogPreferenceControllerTest { mPreference = new BluetoothBitPerSampleDialogPreference(mContext); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); mController.displayPreference(mScreen); - mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, - BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, - BluetoothCodecConfig.SAMPLE_RATE_NONE, - BluetoothCodecConfig.BITS_PER_SAMPLE_16 | BluetoothCodecConfig.BITS_PER_SAMPLE_24, - BluetoothCodecConfig.CHANNEL_MODE_NONE, - 0, 0, 0, 0); - mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, - BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, - BluetoothCodecConfig.SAMPLE_RATE_NONE, - BluetoothCodecConfig.BITS_PER_SAMPLE_24, - BluetoothCodecConfig.CHANNEL_MODE_NONE, - 0, 0, 0, 0); + mCodecConfigAAC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC) + .setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_16 + | BluetoothCodecConfig.BITS_PER_SAMPLE_24) + .build(); + mCodecConfigSBC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) + .setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_24) + .build(); when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice); } @Test public void writeConfigurationValues_selectDefault_setHighest() { BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; - mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); @@ -127,7 +126,8 @@ public class BluetoothBitPerSampleDialogPreferenceControllerTest { @Test public void getSelectableIndex_verifyList() { BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; - mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); List indexList = new ArrayList<>(); diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java index 81fb3fe4e57..75d8fc4fd01 100644 --- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothChannelModeDialogPreferenceControllerTest.java @@ -44,6 +44,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; @RunWith(RobolectricTestRunner.class) @@ -80,25 +81,23 @@ public class BluetoothChannelModeDialogPreferenceControllerTest { mPreference = new BluetoothChannelModeDialogPreference(mContext); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); mController.displayPreference(mScreen); - mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, - BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, - BluetoothCodecConfig.SAMPLE_RATE_NONE, - BluetoothCodecConfig.BITS_PER_SAMPLE_NONE, - BluetoothCodecConfig.CHANNEL_MODE_STEREO, - 0, 0, 0, 0); - mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, - BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, - BluetoothCodecConfig.SAMPLE_RATE_NONE, - BluetoothCodecConfig.BITS_PER_SAMPLE_NONE, - BluetoothCodecConfig.CHANNEL_MODE_MONO | BluetoothCodecConfig.CHANNEL_MODE_STEREO, - 0, 0, 0, 0); + mCodecConfigAAC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC) + .setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_STEREO) + .build(); + mCodecConfigSBC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) + .setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_MONO + | BluetoothCodecConfig.CHANNEL_MODE_STEREO) + .build(); when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice); } @Test public void writeConfigurationValues_selectDefault_setHighest() { BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; - mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); @@ -124,7 +123,8 @@ public class BluetoothChannelModeDialogPreferenceControllerTest { @Test public void getSelectableIndex_verifyList() { BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; - mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); List indexList = new ArrayList<>(); diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java index 0f01e00a3f4..3a34aa02903 100644 --- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothCodecDialogPreferenceControllerTest.java @@ -45,6 +45,9 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; +import java.util.Arrays; +import java.util.List; + @RunWith(RobolectricTestRunner.class) public class BluetoothCodecDialogPreferenceControllerTest { @@ -85,29 +88,41 @@ public class BluetoothCodecDialogPreferenceControllerTest { mPreference = new BluetoothCodecDialogPreference(mContext); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); mController.displayPreference(mScreen); - mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, - BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST, - BluetoothCodecConfig.SAMPLE_RATE_96000 | BluetoothCodecConfig.SAMPLE_RATE_176400, - BluetoothCodecConfig.BITS_PER_SAMPLE_32, - BluetoothCodecConfig.CHANNEL_MODE_MONO | BluetoothCodecConfig.CHANNEL_MODE_STEREO, - 0, 0, 0, 0); - mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, - BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST, - BluetoothCodecConfig.SAMPLE_RATE_48000 | BluetoothCodecConfig.SAMPLE_RATE_88200, - BluetoothCodecConfig.BITS_PER_SAMPLE_16 | BluetoothCodecConfig.BITS_PER_SAMPLE_24, - BluetoothCodecConfig.CHANNEL_MODE_STEREO, - 0, 0, 0, 0); - mCodecConfigAPTX = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX); - mCodecConfigAPTXHD = new BluetoothCodecConfig( - BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD); - mCodecConfigLDAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC); + mCodecConfigSBC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) + .setCodecPriority(BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST) + .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_96000 + | BluetoothCodecConfig.SAMPLE_RATE_176400) + .setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_32) + .setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_MONO + | BluetoothCodecConfig.CHANNEL_MODE_STEREO) + .build(); + mCodecConfigAAC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC) + .setCodecPriority(BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST) + .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_48000 + | BluetoothCodecConfig.SAMPLE_RATE_88200) + .setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_16 + | BluetoothCodecConfig.BITS_PER_SAMPLE_24) + .setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_STEREO) + .build(); + mCodecConfigAPTX = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX) + .build(); + mCodecConfigAPTXHD = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD) + .build(); + mCodecConfigLDAC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC) + .build(); when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice); } @Test public void writeConfigurationValues_selectDefault_setHighest() { BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; - mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus); when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn( BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED); @@ -121,7 +136,8 @@ public class BluetoothCodecDialogPreferenceControllerTest { public void writeConfigurationValues_checkCodec() { BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX, mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC}; - mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); @@ -148,7 +164,8 @@ public class BluetoothCodecDialogPreferenceControllerTest { public void writeConfigurationValues_resetHighestConfig() { BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX, mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC}; - mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.writeConfigurationValues(2); @@ -178,7 +195,7 @@ public class BluetoothCodecDialogPreferenceControllerTest { @Test public void onHDAudioEnabled_optionalCodecEnabled_setsCodecTypeAsAAC() { - BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; + List mCodecConfigs = Arrays.asList(mCodecConfigAAC, mCodecConfigSBC); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, /* codecsLocalCapabilities= */ null, mCodecConfigs); @@ -194,7 +211,7 @@ public class BluetoothCodecDialogPreferenceControllerTest { } @Test public void onHDAudioEnabled_optionalCodecDisabled_setsCodecTypeAsSBC() { - BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; + List mCodecConfigs = Arrays.asList(mCodecConfigAAC, mCodecConfigSBC); mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, /* codecsLocalCapabilities= */ null, mCodecConfigs); diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java index ef209a2ee3c..e50b716ec73 100644 --- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothQualityDialogPreferenceControllerTest.java @@ -43,6 +43,8 @@ import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; +import java.util.Arrays; + @RunWith(RobolectricTestRunner.class) public class BluetoothQualityDialogPreferenceControllerTest { @@ -77,18 +79,16 @@ public class BluetoothQualityDialogPreferenceControllerTest { mPreference = new BluetoothQualityDialogPreference(mContext); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); mController.displayPreference(mScreen); - mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, - BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, - BluetoothCodecConfig.SAMPLE_RATE_48000 | BluetoothCodecConfig.SAMPLE_RATE_88200, - BluetoothCodecConfig.BITS_PER_SAMPLE_NONE, - BluetoothCodecConfig.CHANNEL_MODE_NONE, - 0, 0, 0, 0); - mCodecConfigLDAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC, - BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, - BluetoothCodecConfig.SAMPLE_RATE_96000, - BluetoothCodecConfig.BITS_PER_SAMPLE_NONE, - BluetoothCodecConfig.CHANNEL_MODE_NONE, - 1001, 0, 0, 0); + mCodecConfigAAC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC) + .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_48000 + | BluetoothCodecConfig.SAMPLE_RATE_88200) + .build(); + mCodecConfigLDAC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC) + .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_96000) + .setCodecSpecific1(1001) + .build(); when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice); } @@ -116,7 +116,8 @@ public class BluetoothQualityDialogPreferenceControllerTest { @Test public void updateState_codeTypeIsLDAC_enablePreference() { BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC}; - mCodecStatus = new BluetoothCodecStatus(mCodecConfigLDAC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigLDAC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.updateState(mPreference); @@ -127,7 +128,8 @@ public class BluetoothQualityDialogPreferenceControllerTest { @Test public void updateState_codeTypeAAC_disablePreference() { BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC}; - mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); mController.updateState(mPreference); diff --git a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java index c649fdf169b..fca154d79f8 100644 --- a/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/bluetooth/BluetoothSampleRateDialogPreferenceControllerTest.java @@ -44,6 +44,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; @RunWith(RobolectricTestRunner.class) @@ -81,26 +82,26 @@ public class BluetoothSampleRateDialogPreferenceControllerTest { mPreference = new BluetoothSampleRateDialogPreference(mContext); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); mController.displayPreference(mScreen); - mCodecConfigAAC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC, - BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, - BluetoothCodecConfig.SAMPLE_RATE_48000 | BluetoothCodecConfig.SAMPLE_RATE_88200, - BluetoothCodecConfig.BITS_PER_SAMPLE_NONE, - BluetoothCodecConfig.CHANNEL_MODE_NONE, - 0, 0, 0, 0); - mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC, - BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, - BluetoothCodecConfig.SAMPLE_RATE_96000, - BluetoothCodecConfig.BITS_PER_SAMPLE_NONE, - BluetoothCodecConfig.CHANNEL_MODE_NONE, - 0, 0, 0, 0); + mCodecConfigAAC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC) + .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_48000 + | BluetoothCodecConfig.SAMPLE_RATE_88200) + .build(); + mCodecConfigSBC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) + .setSampleRate(BluetoothCodecConfig.SAMPLE_RATE_96000) + .build(); when(mBluetoothA2dp.getActiveDevice()).thenReturn(mActiveDevice); } @Test public void writeConfigurationValues_selectDefault_setHighest() { - mCodecConfigSBC = new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC); + BluetoothCodecConfig mCodecConfigSBC = new BluetoothCodecConfig.Builder() + .setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) + .build(); BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; - mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); + mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, + Arrays.asList(mCodecConfigs)); when(mBluetoothA2dp.getCodecStatus( mActiveDevice)).thenReturn(mCodecStatus); mController.onBluetoothServiceConnected(mBluetoothA2dp); @@ -132,7 +133,10 @@ public class BluetoothSampleRateDialogPreferenceControllerTest { @Test public void getSelectableIndex_verifyList() { - BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC}; + List mCodecConfigs = new ArrayList() {{ + add(mCodecConfigAAC); + add(mCodecConfigSBC); + }}; mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs); when(mBluetoothA2dp.getCodecStatus( mActiveDevice)).thenReturn(mCodecStatus); From 627fd3928c12165a8edb71851286804eb2c93e24 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Fri, 3 Dec 2021 17:12:08 +0800 Subject: [PATCH 2/2] Improve the cold start performance The performance regressed since the previous change that hide the homepage view from using View.GONE to View.INVISIBLE This change only initializes the list views in the invisible homepage view to prevent a scroll flicker when scrolling is needed. Test: manual Bug: 206555277 Bug: 205823792 Change-Id: I8f173b135cfa1d27a1362d5fa8e3f338e2428ad2 --- .../homepage/SettingsHomepageActivity.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/homepage/SettingsHomepageActivity.java b/src/com/android/settings/homepage/SettingsHomepageActivity.java index e25e1f50730..d5e82353bd3 100644 --- a/src/com/android/settings/homepage/SettingsHomepageActivity.java +++ b/src/com/android/settings/homepage/SettingsHomepageActivity.java @@ -167,10 +167,13 @@ public class SettingsHomepageActivity extends FragmentActivity implements mCategoryMixin = new CategoryMixin(this); getLifecycle().addObserver(mCategoryMixin); + final String highlightMenuKey = getHighlightMenuKey(); // Only allow features on high ram devices. if (!getSystemService(ActivityManager.class).isLowRamDevice()) { initAvatarView(); - showSuggestionFragment(); + final boolean scrollNeeded = mIsEmbeddingActivityEnabled + && !TextUtils.equals(getString(DEFAULT_HIGHLIGHT_MENU_KEY), highlightMenuKey); + showSuggestionFragment(scrollNeeded); if (FeatureFlagUtils.isEnabled(this, FeatureFlags.CONTEXTUAL_HOME)) { showFragment(() -> new ContextualCardsFragment(), R.id.contextual_cards_content); } @@ -178,7 +181,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements mMainFragment = showFragment(() -> { final TopLevelSettings fragment = new TopLevelSettings(); fragment.getArguments().putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, - getHighlightMenuKey()); + highlightMenuKey); return fragment; }, R.id.main_content); @@ -265,7 +268,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements findViewById(R.id.settings_homepage_container).setBackgroundColor(color); } - private void showSuggestionFragment() { + private void showSuggestionFragment(boolean scrollNeeded) { final Class fragmentClass = FeatureFactory.getFactory(this) .getSuggestionFeatureProvider(this).getContextualSuggestionFragment(); if (fragmentClass == null) { @@ -275,8 +278,9 @@ public class SettingsHomepageActivity extends FragmentActivity implements mSuggestionView = findViewById(R.id.suggestion_content); mTwoPaneSuggestionView = findViewById(R.id.two_pane_suggestion_content); mHomepageView = findViewById(R.id.settings_homepage_container); - // Hide the homepage for preparing the suggestion. - mHomepageView.setVisibility(View.INVISIBLE); + // Hide the homepage for preparing the suggestion. If scrolling is needed, the list views + // should be initialized in the invisible homepage view to prevent a scroll flicker. + mHomepageView.setVisibility(scrollNeeded ? View.INVISIBLE : View.GONE); // Schedule a timer to show the homepage and hide the suggestion on timeout. mHomepageView.postDelayed(() -> showHomepageWithSuggestion(false), HOMEPAGE_LOADING_TIMEOUT_MS);