Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java +6 −0 Original line number Diff line number Diff line Loading @@ -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; } packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepository.kt +35 −7 Original line number Diff line number Diff line Loading @@ -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) } } Loading @@ -134,6 +148,7 @@ class DeviceSettingRepositoryImpl( is DeviceSettingIntentAction -> DeviceSettingActionModel.IntentAction(this.intent) is DeviceSettingPendingIntentAction -> DeviceSettingActionModel.PendingIntentAction(this.pendingIntent) else -> null } Loading @@ -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) Loading @@ -163,6 +178,7 @@ class DeviceSettingRepositoryImpl( } }, ) is MultiTogglePreference -> DeviceSettingModel.MultiTogglePreference( cachedDevice = cachedDevice, Loading @@ -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 } } packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt +35 −0 Original line number Diff line number Diff line Loading @@ -166,6 +166,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 { Loading Loading @@ -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, Loading Loading @@ -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, ) } } Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/DeviceSettingId.java +6 −0 Original line number Diff line number Diff line Loading @@ -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; }
packages/SettingsLib/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepository.kt +35 −7 Original line number Diff line number Diff line Loading @@ -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) } } Loading @@ -134,6 +148,7 @@ class DeviceSettingRepositoryImpl( is DeviceSettingIntentAction -> DeviceSettingActionModel.IntentAction(this.intent) is DeviceSettingPendingIntentAction -> DeviceSettingActionModel.PendingIntentAction(this.pendingIntent) else -> null } Loading @@ -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) Loading @@ -163,6 +178,7 @@ class DeviceSettingRepositoryImpl( } }, ) is MultiTogglePreference -> DeviceSettingModel.MultiTogglePreference( cachedDevice = cachedDevice, Loading @@ -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 } }
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/devicesettings/data/repository/DeviceSettingRepositoryTest.kt +35 −0 Original line number Diff line number Diff line Loading @@ -166,6 +166,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 { Loading Loading @@ -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, Loading Loading @@ -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, ) } }