diff options
3 files changed, 76 insertions, 7 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java index e7c7476d4797..f4b79db67d88 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java @@ -120,4 +120,10 @@ public @interface DeviceSettingId { /** Device setting ID for ANC. */ int DEVICE_SETTING_ID_ANC = 1001; + + /** Device setting expandable ID 1. */ + int DEVICE_SETTING_ID_EXPANDABLE_1 = 3001; + + /** Device setting expandable ID 2. */ + int DEVICE_SETTING_ID_EXPANDABLE_2 = 3100; } diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepository.kt b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepository.kt index 8537897cb329..c68dbeead26b 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepository.kt +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepository.kt @@ -106,26 +106,40 @@ class DeviceSettingRepositoryImpl( private fun DeviceSettingsConfig.toModel(): DeviceSettingConfigModel = DeviceSettingConfigModel( - mainItems = mainContentItems.map { it.toModel() }, - moreSettingsItems = moreSettingsItems.map { it.toModel() }, + mainItems = mainContentItems.toModel(), + moreSettingsItems = moreSettingsItems.toModel(), moreSettingsHelpItem = moreSettingsHelpItem?.toModel(), ) - private fun DeviceSettingItem.toModel(): DeviceSettingConfigItemModel { + private fun List<DeviceSettingItem>.toModel(): List<DeviceSettingConfigItemModel> { + return this.flatMap { item -> + if (item.settingId in EXPANDABLE_SETTING_IDS) { + IntRange(item.settingId, item.settingId + SETTING_ID_EXPAND_LIMIT - 1).map { + item.toModel(overrideSettingId = it) + } + } else { + listOf(item.toModel()) + } + } + } + + private fun DeviceSettingItem.toModel( + overrideSettingId: Int? = null + ): DeviceSettingConfigItemModel { return if (!TextUtils.isEmpty(preferenceKey)) { if (settingId == DeviceSettingId.DEVICE_SETTING_ID_BLUETOOTH_PROFILES) { BluetoothProfilesItem( - settingId, + overrideSettingId ?: settingId, highlighted, preferenceKey!!, extras.getStringArrayList(DeviceSettingContract.INVISIBLE_PROFILES) ?: emptyList(), ) } else { - CommonBuiltinItem(settingId, highlighted, preferenceKey!!) + CommonBuiltinItem(overrideSettingId ?: settingId, highlighted, preferenceKey!!) } } else { - AppProvidedItem(settingId, highlighted) + AppProvidedItem(overrideSettingId ?: settingId, highlighted) } } @@ -134,6 +148,7 @@ class DeviceSettingRepositoryImpl( is DeviceSettingIntentAction -> DeviceSettingActionModel.IntentAction(this.intent) is DeviceSettingPendingIntentAction -> DeviceSettingActionModel.PendingIntentAction(this.pendingIntent) + else -> null } @@ -150,7 +165,7 @@ class DeviceSettingRepositoryImpl( summary = pref.summary, icon = pref.icon?.let { DeviceSettingIcon.BitmapIcon(it) }, isAllowedChangingState = pref.isAllowedChangingState, - action = pref.action?.toModel(), + action = pref.action.toModel(), switchState = if (pref.hasSwitch()) { DeviceSettingStateModel.ActionSwitchPreferenceState(pref.checked) @@ -163,6 +178,7 @@ class DeviceSettingRepositoryImpl( } }, ) + is MultiTogglePreference -> DeviceSettingModel.MultiTogglePreference( cachedDevice = cachedDevice, @@ -178,21 +194,33 @@ class DeviceSettingRepositoryImpl( } }, ) + is DeviceSettingFooterPreference -> DeviceSettingModel.FooterPreference( cachedDevice = cachedDevice, id = settingId, footerText = pref.footerText, ) + is DeviceSettingHelpPreference -> DeviceSettingModel.HelpPreference( cachedDevice = cachedDevice, id = settingId, intent = pref.intent, ) + else -> DeviceSettingModel.Unknown(cachedDevice, settingId) } private fun ToggleInfo.toModel(): ToggleModel = ToggleModel(label, DeviceSettingIcon.BitmapIcon(icon)) + + companion object { + private val EXPANDABLE_SETTING_IDS = + listOf( + DeviceSettingId.DEVICE_SETTING_ID_EXPANDABLE_1, + DeviceSettingId.DEVICE_SETTING_ID_EXPANDABLE_2, + ) + private const val SETTING_ID_EXPAND_LIMIT = 15 + } } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt index 4e62fd3b27c5..3d4e4492ffd1 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt @@ -167,6 +167,26 @@ class DeviceSettingRepositoryTest { } @Test + fun getDeviceSettingsConfig_expandable_success() { + testScope.runTest { + setUpConfigService(true, DEVICE_SETTING_CONFIG_EXPANDABLE) + `when`(settingProviderService1.serviceStatus) + .thenReturn(DeviceSettingsProviderServiceStatus(true)) + `when`(settingProviderService2.serviceStatus) + .thenReturn(DeviceSettingsProviderServiceStatus(true)) + + val config = underTest.getDeviceSettingsConfig(cachedDevice)!! + + assertThat(config.mainItems.map { it.settingId }).isEqualTo( + IntRange( + DeviceSettingId.DEVICE_SETTING_ID_EXPANDABLE_1, + DeviceSettingId.DEVICE_SETTING_ID_EXPANDABLE_1 + 14 + ).toList() + ) + } + } + + @Test fun getDeviceSettingsConfig_noMetadata_returnNull() { testScope.runTest { `when`( @@ -510,6 +530,13 @@ class DeviceSettingRepositoryTest { SETTING_PROVIDER_SERVICE_CLASS_NAME_2, SETTING_PROVIDER_SERVICE_INTENT_ACTION_2, ) + val DEVICE_SETTING_APP_PROVIDED_ITEM_EXPANDABLE = + DeviceSettingItem( + DeviceSettingId.DEVICE_SETTING_ID_EXPANDABLE_1, + SETTING_PROVIDER_SERVICE_PACKAGE_NAME_1, + SETTING_PROVIDER_SERVICE_CLASS_NAME_1, + SETTING_PROVIDER_SERVICE_INTENT_ACTION_1, + ) val DEVICE_SETTING_BUILT_IN_ITEM = DeviceSettingItem( DeviceSettingId.DEVICE_SETTING_ID_BLUETOOTH_AUDIO_DEVICE_TYPE_GROUP, @@ -581,5 +608,13 @@ class DeviceSettingRepositoryTest { listOf(DEVICE_SETTING_APP_PROVIDED_ITEM_2), DEVICE_SETTING_HELP_ITEM, ) + val DEVICE_SETTING_CONFIG_EXPANDABLE = + DeviceSettingsConfig( + listOf( + DEVICE_SETTING_APP_PROVIDED_ITEM_EXPANDABLE, + ), + listOf(), + DEVICE_SETTING_HELP_ITEM, + ) } } |