From fb9d83ad68d4f64676f8f329b1df8acd3440ca37 Mon Sep 17 00:00:00 2001 From: Haijie Hong Date: Thu, 14 Nov 2024 15:31:23 +0800 Subject: [PATCH 1/7] Add metrics for new bluetooth device details BUG: 343317785 Test: atest DeviceDetailsFragmentFormatterTest Flag: com.android.settings.flags.enable_bluetooth_device_details_polish Change-Id: Ic74a885627a1426c338b093dcf949688fe9784d1 --- .../ui/view/DeviceDetailsFragmentFormatter.kt | 155 +++++++++++++----- .../DeviceDetailsFragmentFormatterTest.kt | 28 +++- 2 files changed, 144 insertions(+), 39 deletions(-) diff --git a/src/com/android/settings/bluetooth/ui/view/DeviceDetailsFragmentFormatter.kt b/src/com/android/settings/bluetooth/ui/view/DeviceDetailsFragmentFormatter.kt index 23878da421b..003eef0b73f 100644 --- a/src/com/android/settings/bluetooth/ui/view/DeviceDetailsFragmentFormatter.kt +++ b/src/com/android/settings/bluetooth/ui/view/DeviceDetailsFragmentFormatter.kt @@ -17,6 +17,7 @@ package com.android.settings.bluetooth.ui.view import android.app.ActivityOptions +import android.app.settings.SettingsEnums import android.bluetooth.BluetoothAdapter import android.content.Context import android.content.Intent @@ -39,6 +40,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.lifecycle.lifecycleScope import androidx.preference.Preference import com.android.settings.R import com.android.settings.SettingsPreferenceFragment @@ -50,30 +52,33 @@ import com.android.settings.bluetooth.ui.model.FragmentTypeModel import com.android.settings.bluetooth.ui.view.DeviceDetailsMoreSettingsFragment.Companion.KEY_DEVICE_ADDRESS import com.android.settings.bluetooth.ui.viewmodel.BluetoothDeviceDetailsViewModel import com.android.settings.core.SubSettingLauncher +import com.android.settings.overlay.FeatureFactory import com.android.settings.spa.preference.ComposePreference import com.android.settingslib.bluetooth.CachedBluetoothDevice import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingActionModel import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingConfigItemModel import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingIcon import com.android.settingslib.spa.framework.theme.SettingsDimension -import com.android.settingslib.spa.widget.button.ActionButton -import com.android.settingslib.spa.widget.button.ActionButtons import com.android.settingslib.spa.widget.preference.Preference as SpaPreference import com.android.settingslib.spa.widget.preference.PreferenceModel import com.android.settingslib.spa.widget.preference.SwitchPreference import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel import com.android.settingslib.spa.widget.preference.TwoTargetSwitchPreference -import com.android.settingslib.spa.widget.scaffold.RegularScaffold import com.android.settingslib.spa.widget.ui.Footer import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.FlowPreview +import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.emitAll import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.runBlocking /** Handles device details fragment layout according to config. */ @@ -93,6 +98,7 @@ interface DeviceDetailsFragmentFormatter { ): Flow } +@FlowPreview @OptIn(ExperimentalCoroutinesApi::class) class DeviceDetailsFragmentFormatterImpl( private val context: Context, @@ -101,6 +107,9 @@ class DeviceDetailsFragmentFormatterImpl( private val cachedDevice: CachedBluetoothDevice, private val backgroundCoroutineContext: CoroutineContext, ) : DeviceDetailsFragmentFormatter { + private val metricsFeatureProvider = FeatureFactory.featureFactory.metricsFeatureProvider + private val prefVisibility = mutableMapOf>() + private val prefVisibilityJobs = mutableListOf() private val viewModel: BluetoothDeviceDetailsViewModel = ViewModelProvider( @@ -147,21 +156,33 @@ class DeviceDetailsFragmentFormatterImpl( prefKeyToSettingId[pref.key]?.let { id -> settingIdToXmlPreferences[id] = pref } } fragment.preferenceScreen.removeAll() + for (job in prefVisibilityJobs) { + job.cancel() + } + prefVisibilityJobs.clear() for (row in items.indices) { val settingId = items[row].settingId if (settingIdToXmlPreferences.containsKey(settingId)) { fragment.preferenceScreen.addPreference( - settingIdToXmlPreferences[settingId]!!.apply { order = row } + settingIdToXmlPreferences[settingId]!! + .apply { order = row } + .also { logItemShown(it.key, it.isVisible) } ) } else { + val prefKey = getPreferenceKey(settingId) + prefVisibilityJobs.add( + getDevicesSettingForRow(layout, row) + .onEach { logItemShown(prefKey, it.isNotEmpty()) } + .launchIn(fragment.lifecycleScope) + ) val pref = ComposePreference(context) .apply { - key = getPreferenceKey(settingId) + key = prefKey order = row } - .also { pref -> pref.setContent { buildPreference(layout, row) } } + .also { pref -> pref.setContent { buildPreference(layout, row, prefKey) } } fragment.preferenceScreen.addPreference(pref) } } @@ -183,24 +204,28 @@ class DeviceDetailsFragmentFormatterImpl( } ?: emit(null) } - @Composable - private fun buildPreference(layout: DeviceSettingLayout, row: Int) { - val contents by - remember(row) { - layout.rows[row].columns.flatMapLatest { columns -> - if (columns.isEmpty()) { - flowOf(emptyList()) - } else { - combine( - columns.map { column -> - viewModel.getDeviceSetting(cachedDevice, column.settingId) - } - ) { - it.toList() - } - } + private fun getDevicesSettingForRow( + layout: DeviceSettingLayout, + row: Int, + ): Flow> = + layout.rows[row].columns.flatMapLatest { columns -> + if (columns.isEmpty()) { + flowOf(emptyList()) + } else { + combine( + columns.map { column -> + viewModel.getDeviceSetting(cachedDevice, column.settingId) } + ) { + it.toList().filterNotNull() } + } + } + + @Composable + private fun buildPreference(layout: DeviceSettingLayout, row: Int, prefKey: String) { + val contents by + remember(row) { getDevicesSettingForRow(layout, row) } .collectAsStateWithLifecycle(initialValue = listOf()) val highlighted by @@ -226,31 +251,31 @@ class DeviceDetailsFragmentFormatterImpl( shape = RoundedCornerShape(28.dp), ) ) {} - buildPreferences(settings) + buildPreferences(settings, prefKey) } } } @Composable - fun buildPreferences(settings: List) { + fun buildPreferences(settings: List, prefKey: String) { when (settings.size) { 0 -> {} 1 -> { when (val setting = settings[0]) { is DeviceSettingPreferenceModel.PlainPreference -> { - buildPlainPreference(setting) + buildPlainPreference(setting, prefKey) } is DeviceSettingPreferenceModel.SwitchPreference -> { - buildSwitchPreference(setting) + buildSwitchPreference(setting, prefKey) } is DeviceSettingPreferenceModel.MultiTogglePreference -> { - buildMultiTogglePreference(setting) + buildMultiTogglePreference(setting, prefKey) } is DeviceSettingPreferenceModel.FooterPreference -> { buildFooterPreference(setting) } is DeviceSettingPreferenceModel.MoreSettingsPreference -> { - buildMoreSettingsPreference() + buildMoreSettingsPreference(prefKey) } is DeviceSettingPreferenceModel.HelpPreference -> {} null -> {} @@ -262,20 +287,32 @@ class DeviceDetailsFragmentFormatterImpl( @Composable private fun buildMultiTogglePreference( - pref: DeviceSettingPreferenceModel.MultiTogglePreference + pref: DeviceSettingPreferenceModel.MultiTogglePreference, + prefKey: String, ) { - MultiTogglePreference(pref) + MultiTogglePreference( + pref.copy( + onSelectedChange = { newState -> + logItemClick(prefKey, newState) + pref.onSelectedChange(newState) + } + ) + ) } @Composable - private fun buildSwitchPreference(model: DeviceSettingPreferenceModel.SwitchPreference) { + private fun buildSwitchPreference( + model: DeviceSettingPreferenceModel.SwitchPreference, + prefKey: String, + ) { val switchPrefModel = object : SwitchPreferenceModel { override val title = model.title override val summary = { model.summary ?: "" } override val checked = { model.checked } - override val onCheckedChange = { newChecked: Boolean -> - model.onCheckedChange(newChecked) + override val onCheckedChange = { newState: Boolean -> + logItemClick(prefKey, if (newState) EVENT_SWITCH_ON else EVENT_SWITCH_OFF) + model.onCheckedChange(newState) } override val changeable = { !model.disabled } override val icon: (@Composable () -> Unit)? @@ -289,8 +326,11 @@ class DeviceDetailsFragmentFormatterImpl( if (model.action != null) { TwoTargetSwitchPreference( switchPrefModel, - primaryOnClick = { triggerAction(model.action) }, - primaryEnabled = { !model.disabled } + primaryOnClick = { + logItemClick(prefKey, EVENT_CLICK_PRIMARY) + triggerAction(model.action) + }, + primaryEnabled = { !model.disabled }, ) } else { SwitchPreference(switchPrefModel) @@ -298,12 +338,16 @@ class DeviceDetailsFragmentFormatterImpl( } @Composable - private fun buildPlainPreference(model: DeviceSettingPreferenceModel.PlainPreference) { + private fun buildPlainPreference( + model: DeviceSettingPreferenceModel.PlainPreference, + prefKey: String, + ) { SpaPreference( object : PreferenceModel { override val title = model.title override val summary = { model.summary ?: "" } override val onClick = { + logItemClick(prefKey, EVENT_CLICK_PRIMARY) model.action?.let { triggerAction(it) } Unit } @@ -319,7 +363,7 @@ class DeviceDetailsFragmentFormatterImpl( } @Composable - fun buildMoreSettingsPreference() { + fun buildMoreSettingsPreference(prefKey: String) { SpaPreference( object : PreferenceModel { override val title = @@ -328,6 +372,7 @@ class DeviceDetailsFragmentFormatterImpl( context.getString(R.string.bluetooth_device_more_settings_preference_summary) } override val onClick = { + logItemClick(prefKey, EVENT_CLICK_PRIMARY) SubSettingLauncher(context) .setDestination(DeviceDetailsMoreSettingsFragment::class.java.name) .setSourceMetricsCategory(fragment.getMetricsCategory()) @@ -356,6 +401,35 @@ class DeviceDetailsFragmentFormatterImpl( icon?.let { Icon(it, modifier = Modifier.size(SettingsDimension.itemIconSize)) } } + private fun logItemClick(preferenceKey: String, value: Int = 0) { + logAction(preferenceKey, SettingsEnums.ACTION_BLUETOOTH_DEVICE_DETAILS_ITEM_CLICKED, value) + } + + private fun logItemShown(preferenceKey: String, visible: Boolean) { + if (!visible && !prefVisibility.containsKey(preferenceKey)) { + return + } + prefVisibility + .computeIfAbsent(preferenceKey) { + MutableStateFlow(true).also { visibilityFlow -> + visibilityFlow + .onEach { + logAction( + preferenceKey, + SettingsEnums.ACTION_BLUETOOTH_DEVICE_DETAILS_ITEM_SHOWN, + if (it) EVENT_VISIBLE else EVENT_INVISIBLE, + ) + } + .launchIn(fragment.lifecycleScope) + } + } + .value = visible + } + + private fun logAction(preferenceKey: String, action: Int, value: Int) { + metricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, action, 0, preferenceKey, value) + } + private fun triggerAction(action: DeviceSettingActionModel) { when (action) { is DeviceSettingActionModel.IntentAction -> { @@ -375,7 +449,12 @@ class DeviceDetailsFragmentFormatterImpl( private fun getPreferenceKey(settingId: Int) = "DEVICE_SETTING_${settingId}" - companion object { + private companion object { const val TAG = "DeviceDetailsFormatter" + const val EVENT_SWITCH_OFF = 0 + const val EVENT_SWITCH_ON = 1 + const val EVENT_CLICK_PRIMARY = 2 + const val EVENT_INVISIBLE = 0 + const val EVENT_VISIBLE = 1 } } diff --git a/tests/robotests/src/com/android/settings/bluetooth/ui/view/DeviceDetailsFragmentFormatterTest.kt b/tests/robotests/src/com/android/settings/bluetooth/ui/view/DeviceDetailsFragmentFormatterTest.kt index bd56021e38d..28eaeaaa194 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/ui/view/DeviceDetailsFragmentFormatterTest.kt +++ b/tests/robotests/src/com/android/settings/bluetooth/ui/view/DeviceDetailsFragmentFormatterTest.kt @@ -16,6 +16,7 @@ package com.android.settings.bluetooth.ui.view +import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothAdapter import android.content.Context import android.content.Intent @@ -39,6 +40,7 @@ import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSetti import com.android.settingslib.bluetooth.devicesettings.shared.model.DeviceSettingStateModel import com.android.settingslib.bluetooth.devicesettings.shared.model.ToggleModel import com.google.common.truth.Truth.assertThat +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.launchIn @@ -53,6 +55,7 @@ import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.eq import org.mockito.Mock import org.mockito.Mockito.any +import org.mockito.Mockito.verify import org.mockito.Mockito.`when` import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoRule @@ -62,6 +65,7 @@ import org.robolectric.shadows.ShadowLooper import org.robolectric.shadows.ShadowLooper.shadowMainLooper +@ExperimentalCoroutinesApi @RunWith(RobolectricTestRunner::class) class DeviceDetailsFragmentFormatterTest { @get:Rule val mockitoRule: MockitoRule = MockitoJUnit.rule() @@ -70,6 +74,7 @@ class DeviceDetailsFragmentFormatterTest { @Mock private lateinit var bluetoothAdapter: BluetoothAdapter @Mock private lateinit var repository: DeviceSettingRepository + private lateinit var context: Context private lateinit var fragment: TestFragment private lateinit var underTest: DeviceDetailsFragmentFormatter private lateinit var featureFactory: FakeFeatureFactory @@ -78,7 +83,7 @@ class DeviceDetailsFragmentFormatterTest { @Before fun setUp() { - val context = ApplicationProvider.getApplicationContext() + context = ApplicationProvider.getApplicationContext() featureFactory = FakeFeatureFactory.setupForTest() `when`( featureFactory.bluetoothFeatureProvider.getDeviceSettingRepository( @@ -204,9 +209,22 @@ class DeviceDetailsFragmentFormatterTest { null)) underTest.updateLayout(FragmentTypeModel.DeviceDetailsMainFragment) + runCurrent() assertThat(getDisplayedPreferences().mapNotNull { it.key }) .containsExactly("bluetooth_device_header", "keyboard_settings") + verify(featureFactory.metricsFeatureProvider) + .action( + SettingsEnums.PAGE_UNKNOWN, + SettingsEnums.ACTION_BLUETOOTH_DEVICE_DETAILS_ITEM_SHOWN, + 0, + "bluetooth_device_header", 1) + verify(featureFactory.metricsFeatureProvider) + .action( + SettingsEnums.PAGE_UNKNOWN, + SettingsEnums.ACTION_BLUETOOTH_DEVICE_DETAILS_ITEM_SHOWN, + 0, + "keyboard_settings", 1) } } @@ -249,12 +267,20 @@ class DeviceDetailsFragmentFormatterTest { updateState = {}))) underTest.updateLayout(FragmentTypeModel.DeviceDetailsMainFragment) + runCurrent() assertThat(getDisplayedPreferences().mapNotNull { it.key }) .containsExactly( "bluetooth_device_header", "DEVICE_SETTING_${DeviceSettingId.DEVICE_SETTING_ID_ANC}", "keyboard_settings") + verify(featureFactory.metricsFeatureProvider) + .action( + SettingsEnums.PAGE_UNKNOWN, + SettingsEnums.ACTION_BLUETOOTH_DEVICE_DETAILS_ITEM_SHOWN, + 0, + "DEVICE_SETTING_${DeviceSettingId.DEVICE_SETTING_ID_ANC}", 1 + ) } } From 14926a34a677c457ac139b2a89fe98dd6ff52b74 Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Wed, 20 Nov 2024 17:11:02 +0800 Subject: [PATCH 2/7] Update color for reset_esim_desc Fix: 379816199 Flag: EXEMPT bug fix Test: visual Change-Id: I88ee350222dcb273b777274acddcc71d9baf19b2 --- res/layout/reset_esim_checkbox.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/layout/reset_esim_checkbox.xml b/res/layout/reset_esim_checkbox.xml index 626ecc3b22d..59f92631af1 100644 --- a/res/layout/reset_esim_checkbox.xml +++ b/res/layout/reset_esim_checkbox.xml @@ -49,7 +49,7 @@ android:text="@string/reset_esim_title"/> From 34ea3dc0751d7ea52b2d4bb531567a84243b07c1 Mon Sep 17 00:00:00 2001 From: danielwbhuang Date: Wed, 20 Nov 2024 10:54:58 +0800 Subject: [PATCH 3/7] Use flag to control the hierarchy tree changes This change includes these: 1. App languages 2.Regional preferences 2-1. Temperature 2-2. First day of week 2-3. Numbering system 3. Terms of address Bug: 379962955 Flag: com.android.settings.flags.regional_preferences_api_enabled Test: check hsv and atest TermsOfAddressCategoryControllerTest, FirstDayOfWeekControllerTest, NumberingSystemControllerTest, TemperatureUnitControllerTest Change-Id: I9ae376f24ac4d1cf9a186ad3d77b539ac4b83642 Change-Id: I1b2f508f618fba94e67b5f8b102620837a6dda1c --- res/values/strings.xml | 14 +- res/xml/language_and_input.xml | 139 ------------------ res/xml/language_settings.xml | 69 +++++++++ .../ManageAppLocalePreferenceController.java | 42 ++++++ ...ewManageAppLocalePreferenceController.java | 43 ++++++ ...reLanguagesSettingsCategoryController.java | 38 +++++ .../NewTermsOfAddressController.java | 76 ++++++++++ .../TermsOfAddressCategoryController.java | 5 +- .../NewFirstDayOfWeekController.java | 73 +++++++++ .../NewNumberingSystemController.java | 88 +++++++++++ ...NewRegionalFooterPreferenceController.java | 81 ++++++++++ .../NewTemperatureUnitController.java | 74 ++++++++++ ...RegionalPreferencesCategoryController.java | 38 +++++ .../RegionalPreferencesController.java | 4 + .../RegionalPreferencesEntriesFragment.java | 12 +- .../TermsOfAddressCategoryControllerTest.java | 4 + .../FirstDayOfWeekControllerTest.java | 6 + .../NumberingSystemControllerTest.java | 5 + .../TemperatureUnitControllerTest.java | 6 + 19 files changed, 670 insertions(+), 147 deletions(-) delete mode 100644 res/xml/language_and_input.xml create mode 100644 src/com/android/settings/applications/appinfo/ManageAppLocalePreferenceController.java create mode 100644 src/com/android/settings/applications/appinfo/NewManageAppLocalePreferenceController.java create mode 100644 src/com/android/settings/language/MoreLanguagesSettingsCategoryController.java create mode 100644 src/com/android/settings/localepicker/NewTermsOfAddressController.java create mode 100644 src/com/android/settings/regionalpreferences/NewFirstDayOfWeekController.java create mode 100644 src/com/android/settings/regionalpreferences/NewNumberingSystemController.java create mode 100644 src/com/android/settings/regionalpreferences/NewRegionalFooterPreferenceController.java create mode 100644 src/com/android/settings/regionalpreferences/NewTemperatureUnitController.java create mode 100644 src/com/android/settings/regionalpreferences/RegionalPreferencesCategoryController.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 8b5e63f4329..232799ae467 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -387,12 +387,6 @@ Preferred Language - - App languages - - - Set the language for each app - App language @@ -459,6 +453,14 @@ Let apps know your regional preferences so they can personalize your experience. Apps will use your regional preferences where possible. + + More language settings + + App languages + + Set the language for each app + + Regional preferences Temperature diff --git a/res/xml/language_and_input.xml b/res/xml/language_and_input.xml deleted file mode 100644 index 1848f86ce4e..00000000000 --- a/res/xml/language_and_input.xml +++ /dev/null @@ -1,139 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/xml/language_settings.xml b/res/xml/language_settings.xml index 7618399db97..7983b05da5b 100644 --- a/res/xml/language_settings.xml +++ b/res/xml/language_settings.xml @@ -28,6 +28,7 @@ android:title="@string/system_language" android:fragment="com.android.settings.localepicker.LocaleListEditor" settings:controller="com.android.settings.language.PhoneLanguagePreferenceController" /> + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/android/settings/applications/appinfo/ManageAppLocalePreferenceController.java b/src/com/android/settings/applications/appinfo/ManageAppLocalePreferenceController.java new file mode 100644 index 00000000000..60cb8be16fe --- /dev/null +++ b/src/com/android/settings/applications/appinfo/ManageAppLocalePreferenceController.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.applications.appinfo; + +import android.content.Context; + +import androidx.annotation.NonNull; + +import com.android.settings.core.BasePreferenceController; +import com.android.settings.flags.Flags; + +/** + * A controller to update current locale information of application + * and a entry to launch {@link ManageApplications}. + */ +public class ManageAppLocalePreferenceController extends BasePreferenceController { + public ManageAppLocalePreferenceController(@NonNull Context context, @NonNull String key) { + super(context, key); + } + + @Override + public int getAvailabilityStatus() { + if (!Flags.regionalPreferencesApiEnabled()) { + return AVAILABLE; + } + return CONDITIONALLY_UNAVAILABLE; + } +} diff --git a/src/com/android/settings/applications/appinfo/NewManageAppLocalePreferenceController.java b/src/com/android/settings/applications/appinfo/NewManageAppLocalePreferenceController.java new file mode 100644 index 00000000000..00daab6b9a5 --- /dev/null +++ b/src/com/android/settings/applications/appinfo/NewManageAppLocalePreferenceController.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.applications.appinfo; + +import android.content.Context; + +import androidx.annotation.NonNull; + +import com.android.settings.core.BasePreferenceController; +import com.android.settings.flags.Flags; + +/** + * A controller to update current locale information of application + * and a entry to launch {@link ManageApplications}. + */ +public class NewManageAppLocalePreferenceController extends BasePreferenceController { + + public NewManageAppLocalePreferenceController(@NonNull Context context, @NonNull String key) { + super(context, key); + } + + @Override + public int getAvailabilityStatus() { + if (Flags.regionalPreferencesApiEnabled()) { + return AVAILABLE; + } + return CONDITIONALLY_UNAVAILABLE; + } +} diff --git a/src/com/android/settings/language/MoreLanguagesSettingsCategoryController.java b/src/com/android/settings/language/MoreLanguagesSettingsCategoryController.java new file mode 100644 index 00000000000..b174ae0ceb7 --- /dev/null +++ b/src/com/android/settings/language/MoreLanguagesSettingsCategoryController.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.language; + +import android.content.Context; + +import androidx.annotation.NonNull; + +import com.android.settings.flags.Flags; +import com.android.settings.widget.PreferenceCategoryController; + +public class MoreLanguagesSettingsCategoryController extends PreferenceCategoryController { + + public MoreLanguagesSettingsCategoryController(@NonNull Context context, @NonNull String key) { + super(context, key); + } + + @Override + public int getAvailabilityStatus() { + if (Flags.regionalPreferencesApiEnabled()) { + return AVAILABLE; + } + return CONDITIONALLY_UNAVAILABLE; + } +} diff --git a/src/com/android/settings/localepicker/NewTermsOfAddressController.java b/src/com/android/settings/localepicker/NewTermsOfAddressController.java new file mode 100644 index 00000000000..fe92405f1a1 --- /dev/null +++ b/src/com/android/settings/localepicker/NewTermsOfAddressController.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.localepicker; + +import android.content.Context; +import android.os.LocaleList; + +import androidx.annotation.NonNull; + +import com.android.internal.app.LocaleStore; +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; +import com.android.settings.flags.Flags; + +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +public class NewTermsOfAddressController extends BasePreferenceController { + + public NewTermsOfAddressController(@NonNull Context context, @NonNull String preferenceKey) { + super(context, preferenceKey); + } + + @Override + public int getAvailabilityStatus() { + if (Flags.regionalPreferencesApiEnabled()) { + if (Flags.termsOfAddressEnabled()) { + return checkAvailabilityStatus(); + } + } + return CONDITIONALLY_UNAVAILABLE; + } + + private int checkAvailabilityStatus() { + // If language is not available for system language, or if ToA does not apply to + // system language, we will hide it. + final Locale defaultLocale = Locale.getDefault(); + LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(defaultLocale); + final List supportedLanguageList = Arrays.asList( + mContext.getResources().getStringArray( + R.array.terms_of_address_supported_languages)); + final List notSupportedLocaleList = Arrays.asList( + mContext.getResources().getStringArray( + R.array.terms_of_address_unsupported_locales)); + + final Locale locale = localeInfo.getLocale().stripExtensions(); + final String language = locale.getLanguage(); + final String localeTag = locale.toLanguageTag(); + + // Supported locales: + // 1. All French is supported except fr-CA. + // 2. QA language en-XA (LTR pseudo locale), ar_XB (RTL pseudo locale). + if ((supportedLanguageList.contains(language) + && !notSupportedLocaleList.contains(localeTag)) + || LocaleList.isPseudoLocale(locale)) { + return AVAILABLE; + } + + return CONDITIONALLY_UNAVAILABLE; + } +} diff --git a/src/com/android/settings/localepicker/TermsOfAddressCategoryController.java b/src/com/android/settings/localepicker/TermsOfAddressCategoryController.java index 01168c7ff7b..1e2fbef7e83 100644 --- a/src/com/android/settings/localepicker/TermsOfAddressCategoryController.java +++ b/src/com/android/settings/localepicker/TermsOfAddressCategoryController.java @@ -20,7 +20,6 @@ import static com.android.settings.flags.Flags.termsOfAddressEnabled; import android.content.Context; import android.os.LocaleList; -import android.text.TextUtils; import android.util.Log; import androidx.preference.PreferenceCategory; @@ -28,6 +27,7 @@ import androidx.preference.PreferenceScreen; import com.android.internal.app.LocaleStore; import com.android.settings.R; +import com.android.settings.flags.Flags; import com.android.settings.widget.PreferenceCategoryController; import java.util.Arrays; @@ -64,6 +64,9 @@ public class TermsOfAddressCategoryController extends PreferenceCategoryControll @Override public int getAvailabilityStatus() { + if (Flags.regionalPreferencesApiEnabled()) { + return CONDITIONALLY_UNAVAILABLE; + } if (!termsOfAddressEnabled()) { return CONDITIONALLY_UNAVAILABLE; diff --git a/src/com/android/settings/regionalpreferences/NewFirstDayOfWeekController.java b/src/com/android/settings/regionalpreferences/NewFirstDayOfWeekController.java new file mode 100644 index 00000000000..aa691ed0b45 --- /dev/null +++ b/src/com/android/settings/regionalpreferences/NewFirstDayOfWeekController.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.regionalpreferences; + +import android.content.Context; +import android.provider.Settings; + +import androidx.annotation.NonNull; +import androidx.core.text.util.LocalePreferences; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; +import com.android.settings.flags.Flags; + +import java.util.Locale; + +/** A controller for the entry of First Day of Week's page */ +public class NewFirstDayOfWeekController extends BasePreferenceController { + + public NewFirstDayOfWeekController(@NonNull Context context, @NonNull String preferenceKey) { + super(context, preferenceKey); + } + + /** + * @return {@link AvailabilityStatus} for the Setting. This status is used to determine if the + * Setting should be shown or disabled in Settings. Further, it can be used to produce + * appropriate error / warning Slice in the case of unavailability. + *

+ * The status is used for the convenience methods: {@link #isAvailable()}, {@link + * #isSupported()} + *

+ * The inherited class doesn't need to check work profile if android:forWork="true" is set in + * preference xml. + */ + @Override + public int getAvailabilityStatus() { + if (Flags.regionalPreferencesApiEnabled()) { + return AVAILABLE; + } + return CONDITIONALLY_UNAVAILABLE; + } + + @Override + public CharSequence getSummary() { + String record = Settings.System.getString( + mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES); + String result = ""; + if (record != null) { + result = LocalePreferences.getFirstDayOfWeek(Locale.forLanguageTag(record), false); + } + + if (result.isEmpty()) { + result = LocalePreferences.getFirstDayOfWeek(false); + } + return result.isEmpty() + ? mContext.getString(R.string.default_string_of_regional_preference) + : RegionalPreferencesDataUtils.dayConverter(mContext, result); + } +} diff --git a/src/com/android/settings/regionalpreferences/NewNumberingSystemController.java b/src/com/android/settings/regionalpreferences/NewNumberingSystemController.java new file mode 100644 index 00000000000..429d1f35503 --- /dev/null +++ b/src/com/android/settings/regionalpreferences/NewNumberingSystemController.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.regionalpreferences; + +import android.content.Context; +import android.os.LocaleList; + +import androidx.annotation.NonNull; + +import com.android.internal.app.LocaleStore; +import com.android.settings.core.BasePreferenceController; +import com.android.settings.flags.Flags; +import com.android.settings.localepicker.LocaleFeatureProviderImpl; + +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; + +/** A controller for the entry of Numbering System's page */ +public class NewNumberingSystemController extends BasePreferenceController { + private static final String TAG = NewNumberingSystemController.class.getSimpleName(); + + private LocaleList mLocaleList; + public NewNumberingSystemController(@NonNull Context context, @NonNull String preferenceKey) { + super(context, preferenceKey); + // Initialize the supported languages to LocaleInfos + LocaleStore.fillCache(context); + mLocaleList = getNumberingSystemLocale(); + } + + /** + * @return {@link AvailabilityStatus} for the Setting. This status is used to determine if the + * Setting should be shown or disabled in Settings. Further, it can be used to produce + * appropriate error / warning Slice in the case of unavailability. + *

+ * The status is used for the convenience methods: {@link #isAvailable()}, {@link + * #isSupported()} + *

+ * The inherited class doesn't need to check work profile if android:forWork="true" is set in + * preference xml. + */ + @Override + public int getAvailabilityStatus() { + if (Flags.regionalPreferencesApiEnabled()) { + return mLocaleList.isEmpty() ? CONDITIONALLY_UNAVAILABLE : AVAILABLE; + } + return CONDITIONALLY_UNAVAILABLE; + } + + private static LocaleList getNumberingSystemLocale() { + LocaleList localeList = LocaleList.getDefault(); + Set localesHasNumberingSystems = new HashSet<>(); + for (int i = 0; i < localeList.size(); i++) { + Locale locale = localeList.get(i); + LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(locale); + if (localeInfo.hasNumberingSystems()) { + localesHasNumberingSystems.add(locale); + } + } + return convertToLocaleList(localesHasNumberingSystems); + } + + private static LocaleList convertToLocaleList(Set locales) { + if (locales.isEmpty()) { + return LocaleList.getEmptyLocaleList(); + } + return new LocaleList(locales.stream().toArray(Locale[]::new)); + } + + @Override + public CharSequence getSummary() { + return new LocaleFeatureProviderImpl().getLocaleNames(getNumberingSystemLocale()); + } +} diff --git a/src/com/android/settings/regionalpreferences/NewRegionalFooterPreferenceController.java b/src/com/android/settings/regionalpreferences/NewRegionalFooterPreferenceController.java new file mode 100644 index 00000000000..9c800de82c8 --- /dev/null +++ b/src/com/android/settings/regionalpreferences/NewRegionalFooterPreferenceController.java @@ -0,0 +1,81 @@ +/** + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.regionalpreferences; + +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; +import androidx.preference.PreferenceScreen; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; +import com.android.settings.flags.Flags; +import com.android.settingslib.HelpUtils; +import com.android.settingslib.widget.FooterPreference; + +/** + * Preference controller for regional preference footer. + */ +public class NewRegionalFooterPreferenceController extends BasePreferenceController { + + private static final String TAG = "NewRegionalFooterPreferenceController"; + + public NewRegionalFooterPreferenceController(@NonNull Context context, @NonNull String key) { + super(context, key); + } + + @Override + public int getAvailabilityStatus() { + if (Flags.regionalPreferencesApiEnabled()) { + return AVAILABLE_UNSEARCHABLE; + } + + + return CONDITIONALLY_UNAVAILABLE; + } + + @Override + public void displayPreference(@NonNull PreferenceScreen screen) { + super.displayPreference(screen); + FooterPreference footerPreference = screen.findPreference(getPreferenceKey()); + setupFooterPreference(footerPreference); + } + + @VisibleForTesting + void setupFooterPreference(FooterPreference footerPreference) { + if (footerPreference != null) { + footerPreference.setLearnMoreAction(v -> openLocaleLearnMoreLink()); + footerPreference.setLearnMoreText(mContext.getString( + R.string.desc_regional_pref_footer_learn_more)); + } + } + + private void openLocaleLearnMoreLink() { + Intent intent = HelpUtils.getHelpIntent( + mContext, + mContext.getString(R.string.regional_pref_footer_learn_more_link), + mContext.getClass().getName()); + if (intent != null) { + mContext.startActivity(intent); + } else { + Log.w(TAG, "HelpIntent is null"); + } + } +} diff --git a/src/com/android/settings/regionalpreferences/NewTemperatureUnitController.java b/src/com/android/settings/regionalpreferences/NewTemperatureUnitController.java new file mode 100644 index 00000000000..7d3dc3e59c6 --- /dev/null +++ b/src/com/android/settings/regionalpreferences/NewTemperatureUnitController.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.regionalpreferences; + +import android.content.Context; +import android.provider.Settings; + +import androidx.annotation.NonNull; +import androidx.core.text.util.LocalePreferences; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; +import com.android.settings.flags.Flags; + +import java.util.Locale; + +/** A controller for the entry of Temperature units' page */ +public class NewTemperatureUnitController extends BasePreferenceController { + private static final String TAG = NewTemperatureUnitController.class.getSimpleName(); + public NewTemperatureUnitController(@NonNull Context context, @NonNull String preferenceKey) { + super(context, preferenceKey); + } + + /** + * @return {@link AvailabilityStatus} for the Setting. This status is used to determine if the + * Setting should be shown or disabled in Settings. Further, it can be used to produce + * appropriate error / warning Slice in the case of unavailability. + *

+ * The status is used for the convenience methods: {@link #isAvailable()}, {@link + * #isSupported()} + *

+ * The inherited class doesn't need to check work profile if android:forWork="true" is set in + * preference xml. + */ + @Override + public int getAvailabilityStatus() { + if (Flags.regionalPreferencesApiEnabled()) { + return AVAILABLE; + } + return CONDITIONALLY_UNAVAILABLE; + } + + @Override + public CharSequence getSummary() { + String record = Settings.System.getString( + mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES); + String result = ""; + if (record != null) { + result = LocalePreferences.getTemperatureUnit(Locale.forLanguageTag(record), false); + } + + if (result.isEmpty()) { + result = LocalePreferences.getTemperatureUnit(false); + } + + return result.isEmpty() + ? mContext.getString(R.string.default_string_of_regional_preference) + : RegionalPreferencesDataUtils.temperatureUnitsConverter(mContext, result); + } +} diff --git a/src/com/android/settings/regionalpreferences/RegionalPreferencesCategoryController.java b/src/com/android/settings/regionalpreferences/RegionalPreferencesCategoryController.java new file mode 100644 index 00000000000..ad524a4ed3c --- /dev/null +++ b/src/com/android/settings/regionalpreferences/RegionalPreferencesCategoryController.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.regionalpreferences; + +import android.content.Context; + +import androidx.annotation.NonNull; + +import com.android.settings.flags.Flags; +import com.android.settings.widget.PreferenceCategoryController; + +public class RegionalPreferencesCategoryController extends PreferenceCategoryController { + public RegionalPreferencesCategoryController(@NonNull Context context, @NonNull String key) { + super(context, key); + } + + @Override + public int getAvailabilityStatus() { + if (Flags.regionalPreferencesApiEnabled()) { + return AVAILABLE; + } + return CONDITIONALLY_UNAVAILABLE; + } +} diff --git a/src/com/android/settings/regionalpreferences/RegionalPreferencesController.java b/src/com/android/settings/regionalpreferences/RegionalPreferencesController.java index 5e5fc9d2175..f194659c00b 100644 --- a/src/com/android/settings/regionalpreferences/RegionalPreferencesController.java +++ b/src/com/android/settings/regionalpreferences/RegionalPreferencesController.java @@ -20,6 +20,7 @@ import android.content.Context; import android.os.SystemProperties; import com.android.settings.core.BasePreferenceController; +import com.android.settings.flags.Flags; /** A controller for the entry of Regional preferences */ public class RegionalPreferencesController extends BasePreferenceController { @@ -42,6 +43,9 @@ public class RegionalPreferencesController extends BasePreferenceController { */ @Override public int getAvailabilityStatus() { + if (Flags.regionalPreferencesApiEnabled()) { + return CONDITIONALLY_UNAVAILABLE; + } return SystemProperties.getBoolean(FEATURE_PROPERTY, true) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; } diff --git a/src/com/android/settings/regionalpreferences/RegionalPreferencesEntriesFragment.java b/src/com/android/settings/regionalpreferences/RegionalPreferencesEntriesFragment.java index 848febcf2d2..8b1e749ef79 100644 --- a/src/com/android/settings/regionalpreferences/RegionalPreferencesEntriesFragment.java +++ b/src/com/android/settings/regionalpreferences/RegionalPreferencesEntriesFragment.java @@ -17,9 +17,11 @@ package com.android.settings.regionalpreferences; import android.app.settings.SettingsEnums; +import android.content.Context; import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.flags.Flags; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.search.SearchIndexable; @@ -55,5 +57,13 @@ public class RegionalPreferencesEntriesFragment extends DashboardFragment { } public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = - new BaseSearchIndexProvider(R.xml.regional_preference_main_page); + new BaseSearchIndexProvider(R.xml.regional_preference_main_page) { + @Override + protected boolean isPageSearchEnabled(Context context) { + if (Flags.regionalPreferencesApiEnabled()) { + return false; + } + return true; + } + }; } diff --git a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressCategoryControllerTest.java b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressCategoryControllerTest.java index b025abdf06a..ed878f48f2b 100644 --- a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressCategoryControllerTest.java +++ b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressCategoryControllerTest.java @@ -24,10 +24,13 @@ import static org.mockito.Mockito.spy; import android.content.Context; import android.os.Looper; +import android.platform.test.annotations.DisableFlags; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.android.settings.flags.Flags; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -65,6 +68,7 @@ public class TermsOfAddressCategoryControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getAvailabilityStatus_returnAvailable() { Locale.setDefault(Locale.forLanguageTag("fr-FR")); diff --git a/tests/unit/src/com/android/settings/regionalpreferences/FirstDayOfWeekControllerTest.java b/tests/unit/src/com/android/settings/regionalpreferences/FirstDayOfWeekControllerTest.java index 062aef8393a..759b356cfab 100644 --- a/tests/unit/src/com/android/settings/regionalpreferences/FirstDayOfWeekControllerTest.java +++ b/tests/unit/src/com/android/settings/regionalpreferences/FirstDayOfWeekControllerTest.java @@ -19,10 +19,12 @@ package com.android.settings.regionalpreferences; import static org.junit.Assert.assertEquals; import android.content.Context; +import android.platform.test.annotations.DisableFlags; import android.provider.Settings; import androidx.test.core.app.ApplicationProvider; +import com.android.settings.flags.Flags; import com.android.settings.testutils.ResourcesUtils; import org.junit.After; @@ -54,6 +56,7 @@ public class FirstDayOfWeekControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_hasProviderValue_resultIsWed() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, "und-u-fw-wed"); @@ -64,6 +67,7 @@ public class FirstDayOfWeekControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_hasProviderValue_resultIsSat() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, "und-u-fw-sat"); @@ -74,6 +78,7 @@ public class FirstDayOfWeekControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_noProviderValueButHasDefaultLocaleWithSubtag_resultIsSat() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, ""); Locale.setDefault(Locale.forLanguageTag("en-US-u-fw-sat")); @@ -85,6 +90,7 @@ public class FirstDayOfWeekControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_noProviderValueAndDefaultLocaleWithoutSubtag_resultIsdefault() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, ""); Locale.setDefault(Locale.forLanguageTag("en-US")); diff --git a/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemControllerTest.java b/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemControllerTest.java index 6a95bb95826..bb745a6fb28 100644 --- a/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemControllerTest.java +++ b/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemControllerTest.java @@ -23,9 +23,12 @@ import static org.junit.Assert.assertEquals; import android.content.Context; import android.os.LocaleList; +import android.platform.test.annotations.DisableFlags; import androidx.test.core.app.ApplicationProvider; +import com.android.settings.flags.Flags; + import org.junit.Before; import org.junit.Test; @@ -39,6 +42,7 @@ public class NumberingSystemControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getAvailabilityStatus_noLocale_unavailable() { LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-Hant-TW")); mController = new NumberingSystemController(mApplicationContext, "key"); @@ -49,6 +53,7 @@ public class NumberingSystemControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getAvailabilityStatus_hasLocaleWithNumberingSystems_available() { // ar-JO has different numbering system. LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-Hant-TW,ar-JO")); diff --git a/tests/unit/src/com/android/settings/regionalpreferences/TemperatureUnitControllerTest.java b/tests/unit/src/com/android/settings/regionalpreferences/TemperatureUnitControllerTest.java index aa652cab1f4..fb05dfaedb4 100644 --- a/tests/unit/src/com/android/settings/regionalpreferences/TemperatureUnitControllerTest.java +++ b/tests/unit/src/com/android/settings/regionalpreferences/TemperatureUnitControllerTest.java @@ -19,10 +19,12 @@ package com.android.settings.regionalpreferences; import static org.junit.Assert.assertEquals; import android.content.Context; +import android.platform.test.annotations.DisableFlags; import android.provider.Settings; import androidx.test.core.app.ApplicationProvider; +import com.android.settings.flags.Flags; import com.android.settings.testutils.ResourcesUtils; import org.junit.After; @@ -54,6 +56,7 @@ public class TemperatureUnitControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_hasProviderValue_resultIsCelsius() { RegionalPreferenceTestUtils.setSettingsProviderContent( mApplicationContext, "und-u-mu-celsius"); @@ -65,6 +68,7 @@ public class TemperatureUnitControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_hasProviderValue_resultIsFahrenheit() { RegionalPreferenceTestUtils.setSettingsProviderContent( mApplicationContext, "und-u-mu-fahrenhe"); @@ -76,6 +80,7 @@ public class TemperatureUnitControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_noProviderValueButHasDefaultLocaleWithSubtag_resultIsFahrenheit() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, ""); Locale.setDefault(Locale.forLanguageTag("en-US-u-mu-fahrenhe")); @@ -87,6 +92,7 @@ public class TemperatureUnitControllerTest { } @Test + @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_noProviderValueAndDefaultLocaleWithoutSubtag_resultIsDefault() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, ""); Locale.setDefault(Locale.forLanguageTag("en-US")); From 5641752fb14b0e281888176412aaa1dd150af642 Mon Sep 17 00:00:00 2001 From: Pat Manning Date: Wed, 20 Nov 2024 16:30:57 +0000 Subject: [PATCH 4/7] Remove selectability from pointer preferences. Fix: 379840620 Fix: 374902522 Fix: 374902467 Fix: 374898232 Fix: 374894728 Fix: 374894804 Test: Manual. Talkback, switch access, voice access. Flag: EXEMPT BugFix. Change-Id: I550bd78893124b453d49f98d51dab2f49bee84f7 --- res/xml/input_touchpad_three_finger_tap_customization.xml | 2 -- .../settings/inputmethod/PointerFillStylePreference.java | 1 + .../settings/inputmethod/PointerStrokeStylePreference.java | 1 + .../settings/inputmethod/TouchpadThreeFingerTapSelector.java | 1 + 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/res/xml/input_touchpad_three_finger_tap_customization.xml b/res/xml/input_touchpad_three_finger_tap_customization.xml index f0103aeda73..74510811158 100644 --- a/res/xml/input_touchpad_three_finger_tap_customization.xml +++ b/res/xml/input_touchpad_three_finger_tap_customization.xml @@ -16,7 +16,6 @@ @@ -25,5 +24,4 @@ android:key="input_touchpad_three_finger_tap_preference" android:title="@string/three_finger_tap_preference_title"/> - diff --git a/src/com/android/settings/inputmethod/PointerFillStylePreference.java b/src/com/android/settings/inputmethod/PointerFillStylePreference.java index 52535f9321d..74284d64250 100644 --- a/src/com/android/settings/inputmethod/PointerFillStylePreference.java +++ b/src/com/android/settings/inputmethod/PointerFillStylePreference.java @@ -47,6 +47,7 @@ public class PointerFillStylePreference extends Preference { public PointerFillStylePreference(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); setLayoutResource(R.layout.pointer_icon_fill_style_layout); + setSelectable(false); } @Override diff --git a/src/com/android/settings/inputmethod/PointerStrokeStylePreference.java b/src/com/android/settings/inputmethod/PointerStrokeStylePreference.java index 1c02332f8a1..fdbad929de2 100644 --- a/src/com/android/settings/inputmethod/PointerStrokeStylePreference.java +++ b/src/com/android/settings/inputmethod/PointerStrokeStylePreference.java @@ -38,6 +38,7 @@ public class PointerStrokeStylePreference extends Preference { public PointerStrokeStylePreference(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); setLayoutResource(R.layout.pointer_icon_stroke_style_layout); + setSelectable(false); } @Override diff --git a/src/com/android/settings/inputmethod/TouchpadThreeFingerTapSelector.java b/src/com/android/settings/inputmethod/TouchpadThreeFingerTapSelector.java index 164098b808b..b56d2ead775 100644 --- a/src/com/android/settings/inputmethod/TouchpadThreeFingerTapSelector.java +++ b/src/com/android/settings/inputmethod/TouchpadThreeFingerTapSelector.java @@ -45,6 +45,7 @@ public class TouchpadThreeFingerTapSelector extends Preference { super(context, attrs); setLayoutResource(R.layout.touchpad_three_finger_tap_layout); mInputManager = context.getSystemService(InputManager.class); + setSelectable(false); } @Override From b6132572ea9ab2bd4213019d1c7640422ffc117f Mon Sep 17 00:00:00 2001 From: Jacky Wang Date: Wed, 20 Nov 2024 19:08:26 +0800 Subject: [PATCH 5/7] [Catalyst] Migrate "Lock screen" entry point Bug: 372307567 Flag: com.android.settings.flags.catalyst_lockscreen_from_display_settings Test: manual Change-Id: I0c269c550c678362f345c9b5438a133c7a76fe10 --- res/xml/security_lockscreen_settings.xml | 1 + .../settings/dashboard/DashboardFragment.java | 4 ++++ .../android/settings/display/DisplayScreen.kt | 15 +++++++++------ .../security/LockScreenPreferenceScreen.kt | 16 +++++++++++----- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/res/xml/security_lockscreen_settings.xml b/res/xml/security_lockscreen_settings.xml index 15d530357d9..fdc738afca8 100644 --- a/res/xml/security_lockscreen_settings.xml +++ b/res/xml/security_lockscreen_settings.xml @@ -17,6 +17,7 @@ keys = getPreferenceKeysInHierarchy(); Iterator iterator = mControllers.iterator(); + Lifecycle lifecycle = getSettingsLifecycle(); while (iterator.hasNext()) { AbstractPreferenceController controller = iterator.next(); String key = controller.getPreferenceKey(); @@ -438,6 +439,9 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment if (controllers != null) { controllers.remove(controller); } + if (controller instanceof LifecycleObserver) { + lifecycle.removeObserver((LifecycleObserver) controller); + } } } } diff --git a/src/com/android/settings/display/DisplayScreen.kt b/src/com/android/settings/display/DisplayScreen.kt index 422ea67618a..d8a6be11e21 100644 --- a/src/com/android/settings/display/DisplayScreen.kt +++ b/src/com/android/settings/display/DisplayScreen.kt @@ -21,6 +21,7 @@ import com.android.settings.R import com.android.settings.Settings.DisplaySettingsActivity import com.android.settings.display.darkmode.DarkModeScreen import com.android.settings.flags.Flags +import com.android.settings.security.LockScreenPreferenceScreen import com.android.settings.utils.makeLaunchIntent import com.android.settingslib.metadata.PreferenceAvailabilityProvider import com.android.settingslib.metadata.PreferenceIconProvider @@ -50,12 +51,14 @@ open class DisplayScreen : override fun fragmentClass() = DisplaySettings::class.java - override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(this) { - +BrightnessLevelPreference() - +AutoBrightnessScreen.KEY - +DarkModeScreen.KEY - +PeakRefreshRateSwitchPreference() - } + override fun getPreferenceHierarchy(context: Context) = + preferenceHierarchy(this) { + +BrightnessLevelPreference() + +AutoBrightnessScreen.KEY + +LockScreenPreferenceScreen.KEY + +DarkModeScreen.KEY + +PeakRefreshRateSwitchPreference() + } override fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?) = makeLaunchIntent(context, DisplaySettingsActivity::class.java, metadata?.key) diff --git a/src/com/android/settings/security/LockScreenPreferenceScreen.kt b/src/com/android/settings/security/LockScreenPreferenceScreen.kt index 0c7877f88e5..55c18d96ff8 100644 --- a/src/com/android/settings/security/LockScreenPreferenceScreen.kt +++ b/src/com/android/settings/security/LockScreenPreferenceScreen.kt @@ -18,12 +18,14 @@ package com.android.settings.security import android.content.Context import com.android.settings.R import com.android.settings.flags.Flags +import com.android.settings.notification.LockScreenNotificationPreferenceController +import com.android.settingslib.metadata.PreferenceSummaryProvider import com.android.settingslib.metadata.ProvidePreferenceScreen import com.android.settingslib.metadata.preferenceHierarchy import com.android.settingslib.preference.PreferenceScreenCreator @ProvidePreferenceScreen -open class LockScreenPreferenceScreen : PreferenceScreenCreator { +open class LockScreenPreferenceScreen : PreferenceScreenCreator, PreferenceSummaryProvider { override val key: String get() = KEY @@ -33,17 +35,21 @@ open class LockScreenPreferenceScreen : PreferenceScreenCreator { override val keywords: Int get() = R.string.keywords_ambient_display_screen + override fun getSummary(context: Context): CharSequence? = + context.getString(LockScreenNotificationPreferenceController.getSummaryResource(context)) + override fun isFlagEnabled(context: Context) = Flags.catalystLockscreenFromDisplaySettings() override fun hasCompleteHierarchy() = false override fun fragmentClass() = LockscreenDashboardFragment::class.java - override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(this) { - // add hierarchy here - } + override fun getPreferenceHierarchy(context: Context) = + preferenceHierarchy(this) { + // add hierarchy here + } companion object { const val KEY = "lockscreen_from_display_settings" } -} \ No newline at end of file +} From efcb4dfddfb261c966aed3c387c8ba12c3d38f21 Mon Sep 17 00:00:00 2001 From: Jacky Wang Date: Thu, 21 Nov 2024 10:21:55 +0800 Subject: [PATCH 6/7] [Catalyst] Migrate AmbientDisplayAlwaysOnPreferenceController As the preference is exported as external settings, for safety, do not update the preference key with datastore key. As a workaround, manage a mapping between preference hierarchy key and datastore key. Bug: 372307567 Flag: com.android.settings.flags.catalyst_lockscreen_from_display_settings Test: devtool Change-Id: I56126485061859b41216cd23b8e1caf63823a1ec --- .../settings/SettingsPreferenceFragment.java | 2 +- .../AmbientDisplayAlwaysOnPreference.kt | 116 ++++++++++++++++++ ...ntDisplayAlwaysOnPreferenceController.java | 2 + .../security/LockScreenPreferenceScreen.kt | 9 +- .../security/LockscreenDashboardFragment.java | 6 +- .../LockscreenDashboardFragmentTest.java | 7 +- 6 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 src/com/android/settings/display/AmbientDisplayAlwaysOnPreference.kt diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java index e5a12847623..363d601d0d1 100644 --- a/src/com/android/settings/SettingsPreferenceFragment.java +++ b/src/com/android/settings/SettingsPreferenceFragment.java @@ -186,7 +186,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF } /** Returns if catalyst is enabled on current screen. */ - protected final boolean isCatalystEnabled() { + public final boolean isCatalystEnabled() { // TODO(b/379130874): make Catalyst compatible with desktop device, such as user restriction // check. Context context = getContext(); diff --git a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreference.kt b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreference.kt new file mode 100644 index 00000000000..0537e625159 --- /dev/null +++ b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreference.kt @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.display + +import android.content.Context +import android.hardware.display.AmbientDisplayConfiguration +import android.os.SystemProperties +import android.os.UserHandle +import android.os.UserManager +import android.provider.Settings.Secure.DOZE_ALWAYS_ON +import com.android.settings.PreferenceRestrictionMixin +import com.android.settings.R +import com.android.settings.display.AmbientDisplayAlwaysOnPreferenceController.isAodSuppressedByBedtime +import com.android.settingslib.datastore.HandlerExecutor +import com.android.settingslib.datastore.KeyValueStore +import com.android.settingslib.datastore.KeyedObservableDelegate +import com.android.settingslib.datastore.KeyedObserver +import com.android.settingslib.datastore.SettingsSecureStore +import com.android.settingslib.datastore.SettingsStore +import com.android.settingslib.metadata.PreferenceAvailabilityProvider +import com.android.settingslib.metadata.PreferenceLifecycleContext +import com.android.settingslib.metadata.PreferenceLifecycleProvider +import com.android.settingslib.metadata.PreferenceSummaryProvider +import com.android.settingslib.metadata.ReadWritePermit +import com.android.settingslib.metadata.SwitchPreference + +// LINT.IfChange +class AmbientDisplayAlwaysOnPreference : + SwitchPreference(KEY, R.string.doze_always_on_title, R.string.doze_always_on_summary), + PreferenceAvailabilityProvider, + PreferenceSummaryProvider, + PreferenceLifecycleProvider, + PreferenceRestrictionMixin { + + private var keyMappingObserver: KeyedObserver? = null + + override val keywords: Int + get() = R.string.keywords_always_show_time_info + + override val restrictionKeys: Array + get() = arrayOf(UserManager.DISALLOW_AMBIENT_DISPLAY) + + override fun isEnabled(context: Context) = super.isEnabled(context) + + override fun isAvailable(context: Context) = + !SystemProperties.getBoolean(PROP_AWARE_AVAILABLE, false) && + AmbientDisplayConfiguration(context).alwaysOnAvailableForUser(UserHandle.myUserId()) + + override fun getSummary(context: Context): CharSequence? = + context.getText( + when { + isAodSuppressedByBedtime(context) -> R.string.aware_summary_when_bedtime_on + else -> R.string.doze_always_on_summary + } + ) + + override fun storage(context: Context): KeyValueStore = Storage(context) + + override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = + ReadWritePermit.ALLOW + + override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = + ReadWritePermit.ALLOW + + override fun onCreate(context: PreferenceLifecycleContext) { + val storage = SettingsSecureStore.get(context) + keyMappingObserver = + KeyedObserver { _, reason -> storage.notifyChange(KEY, reason) } + .also { storage.addObserver(DOZE_ALWAYS_ON, it, HandlerExecutor.main) } + } + + override fun onDestroy(context: PreferenceLifecycleContext) { + keyMappingObserver?.let { + SettingsSecureStore.get(context).removeObserver(DOZE_ALWAYS_ON, it) + } + } + + @Suppress("UNCHECKED_CAST") + class Storage( + private val context: Context, + private val settingsStore: SettingsStore = SettingsSecureStore.get(context), + ) : KeyedObservableDelegate(settingsStore), KeyValueStore { + + override fun contains(key: String) = settingsStore.contains(DOZE_ALWAYS_ON) + + override fun getDefaultValue(key: String, valueType: Class) = + context.resources.getBoolean(com.android.internal.R.bool.config_dozeAlwaysOnEnabled) + as T + + override fun getValue(key: String, valueType: Class) = + settingsStore.getValue(DOZE_ALWAYS_ON, valueType) ?: getDefaultValue(key, valueType) + + override fun setValue(key: String, valueType: Class, value: T?) = + settingsStore.setValue(DOZE_ALWAYS_ON, valueType, value) + } + + companion object { + const val KEY = "ambient_display_always_on" + private const val PROP_AWARE_AVAILABLE = "ro.vendor.aware_available" + } +} +// LINT.ThenChange(AmbientDisplayAlwaysOnPreferenceController.java) diff --git a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java index 245803493e2..17cecad0810 100644 --- a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java +++ b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java @@ -29,6 +29,7 @@ import androidx.preference.Preference; import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; +// LINT.IfChange public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreferenceController { private final int ON = 1; @@ -130,3 +131,4 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference return powerManager.isAmbientDisplaySuppressedForTokenByApp(AOD_SUPPRESSED_TOKEN, uid); } } +// LINT.ThenChange(AmbientDisplayAlwaysOnPreference.kt) diff --git a/src/com/android/settings/security/LockScreenPreferenceScreen.kt b/src/com/android/settings/security/LockScreenPreferenceScreen.kt index 55c18d96ff8..3c00b428ebd 100644 --- a/src/com/android/settings/security/LockScreenPreferenceScreen.kt +++ b/src/com/android/settings/security/LockScreenPreferenceScreen.kt @@ -17,8 +17,12 @@ package com.android.settings.security import android.content.Context import com.android.settings.R +import com.android.settings.Settings.LockScreenSettingsActivity +import com.android.settings.display.AmbientDisplayAlwaysOnPreference import com.android.settings.flags.Flags import com.android.settings.notification.LockScreenNotificationPreferenceController +import com.android.settings.utils.makeLaunchIntent +import com.android.settingslib.metadata.PreferenceMetadata import com.android.settingslib.metadata.PreferenceSummaryProvider import com.android.settingslib.metadata.ProvidePreferenceScreen import com.android.settingslib.metadata.preferenceHierarchy @@ -44,9 +48,12 @@ open class LockScreenPreferenceScreen : PreferenceScreenCreator, PreferenceSumma override fun fragmentClass() = LockscreenDashboardFragment::class.java + override fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?) = + makeLaunchIntent(context, LockScreenSettingsActivity::class.java, metadata?.key) + override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(this) { - // add hierarchy here + +AmbientDisplayAlwaysOnPreference() } companion object { diff --git a/src/com/android/settings/security/LockscreenDashboardFragment.java b/src/com/android/settings/security/LockscreenDashboardFragment.java index 1e299a36cf5..ef4c778549c 100644 --- a/src/com/android/settings/security/LockscreenDashboardFragment.java +++ b/src/com/android/settings/security/LockscreenDashboardFragment.java @@ -56,8 +56,6 @@ import java.util.List; public class LockscreenDashboardFragment extends DashboardFragment implements OwnerInfoPreferenceController.OwnerInfoCallback { - public static final String KEY_AMBIENT_DISPLAY_ALWAYS_ON = "ambient_display_always_on"; - private static final String TAG = "LockscreenDashboardFragment"; @VisibleForTesting @@ -111,7 +109,9 @@ public class LockscreenDashboardFragment extends DashboardFragment @Override public void onAttach(Context context) { super.onAttach(context); - use(AmbientDisplayAlwaysOnPreferenceController.class).setConfig(getConfig(context)); + if (!isCatalystEnabled()) { + use(AmbientDisplayAlwaysOnPreferenceController.class).setConfig(getConfig(context)); + } use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context)); use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context)); use(PickupGesturePreferenceController.class).setConfig(getConfig(context)); diff --git a/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java index bf5e9577250..5ca9f729cc4 100644 --- a/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java @@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import android.content.Context; @@ -88,7 +89,11 @@ public class LockscreenDashboardFragmentTest { AmbientDisplayAlwaysOnPreferenceController.class); mTestFragment.onAttach(mContext); - verify(controller).setConfig(any()); + if (mTestFragment.isCatalystEnabled()) { + verifyNoInteractions(controller); + } else { + verify(controller).setConfig(any()); + } } @Test From 2f996492fff2e2c0e63eb2c5a079bdbbd2af2fb0 Mon Sep 17 00:00:00 2001 From: "Priyanka Advani (xWF)" Date: Thu, 21 Nov 2024 18:57:44 +0000 Subject: [PATCH 7/7] Revert "Use flag to control the hierarchy tree changes" This reverts commit 34ea3dc0751d7ea52b2d4bb531567a84243b07c1. Reason for revert: Droidmonitor created revert due to b/380258772. Will be verifying through ABTD before submission. Change-Id: Ife4707fba00b52ade53eb6dc2f4bcd7a466afe0f --- res/values/strings.xml | 14 +- res/xml/language_and_input.xml | 139 ++++++++++++++++++ res/xml/language_settings.xml | 69 --------- .../ManageAppLocalePreferenceController.java | 42 ------ ...ewManageAppLocalePreferenceController.java | 43 ------ ...reLanguagesSettingsCategoryController.java | 38 ----- .../NewTermsOfAddressController.java | 76 ---------- .../TermsOfAddressCategoryController.java | 5 +- .../NewFirstDayOfWeekController.java | 73 --------- .../NewNumberingSystemController.java | 88 ----------- ...NewRegionalFooterPreferenceController.java | 81 ---------- .../NewTemperatureUnitController.java | 74 ---------- ...RegionalPreferencesCategoryController.java | 38 ----- .../RegionalPreferencesController.java | 4 - .../RegionalPreferencesEntriesFragment.java | 12 +- .../TermsOfAddressCategoryControllerTest.java | 4 - .../FirstDayOfWeekControllerTest.java | 6 - .../NumberingSystemControllerTest.java | 5 - .../TemperatureUnitControllerTest.java | 6 - 19 files changed, 147 insertions(+), 670 deletions(-) create mode 100644 res/xml/language_and_input.xml delete mode 100644 src/com/android/settings/applications/appinfo/ManageAppLocalePreferenceController.java delete mode 100644 src/com/android/settings/applications/appinfo/NewManageAppLocalePreferenceController.java delete mode 100644 src/com/android/settings/language/MoreLanguagesSettingsCategoryController.java delete mode 100644 src/com/android/settings/localepicker/NewTermsOfAddressController.java delete mode 100644 src/com/android/settings/regionalpreferences/NewFirstDayOfWeekController.java delete mode 100644 src/com/android/settings/regionalpreferences/NewNumberingSystemController.java delete mode 100644 src/com/android/settings/regionalpreferences/NewRegionalFooterPreferenceController.java delete mode 100644 src/com/android/settings/regionalpreferences/NewTemperatureUnitController.java delete mode 100644 src/com/android/settings/regionalpreferences/RegionalPreferencesCategoryController.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 232799ae467..8b5e63f4329 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -387,6 +387,12 @@ Preferred Language + + App languages + + + Set the language for each app + App language @@ -453,14 +459,6 @@ Let apps know your regional preferences so they can personalize your experience. Apps will use your regional preferences where possible. - - More language settings - - App languages - - Set the language for each app - - Regional preferences Temperature diff --git a/res/xml/language_and_input.xml b/res/xml/language_and_input.xml new file mode 100644 index 00000000000..1848f86ce4e --- /dev/null +++ b/res/xml/language_and_input.xml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/language_settings.xml b/res/xml/language_settings.xml index 7983b05da5b..7618399db97 100644 --- a/res/xml/language_settings.xml +++ b/res/xml/language_settings.xml @@ -28,7 +28,6 @@ android:title="@string/system_language" android:fragment="com.android.settings.localepicker.LocaleListEditor" settings:controller="com.android.settings.language.PhoneLanguagePreferenceController" /> - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/com/android/settings/applications/appinfo/ManageAppLocalePreferenceController.java b/src/com/android/settings/applications/appinfo/ManageAppLocalePreferenceController.java deleted file mode 100644 index 60cb8be16fe..00000000000 --- a/src/com/android/settings/applications/appinfo/ManageAppLocalePreferenceController.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.applications.appinfo; - -import android.content.Context; - -import androidx.annotation.NonNull; - -import com.android.settings.core.BasePreferenceController; -import com.android.settings.flags.Flags; - -/** - * A controller to update current locale information of application - * and a entry to launch {@link ManageApplications}. - */ -public class ManageAppLocalePreferenceController extends BasePreferenceController { - public ManageAppLocalePreferenceController(@NonNull Context context, @NonNull String key) { - super(context, key); - } - - @Override - public int getAvailabilityStatus() { - if (!Flags.regionalPreferencesApiEnabled()) { - return AVAILABLE; - } - return CONDITIONALLY_UNAVAILABLE; - } -} diff --git a/src/com/android/settings/applications/appinfo/NewManageAppLocalePreferenceController.java b/src/com/android/settings/applications/appinfo/NewManageAppLocalePreferenceController.java deleted file mode 100644 index 00daab6b9a5..00000000000 --- a/src/com/android/settings/applications/appinfo/NewManageAppLocalePreferenceController.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.applications.appinfo; - -import android.content.Context; - -import androidx.annotation.NonNull; - -import com.android.settings.core.BasePreferenceController; -import com.android.settings.flags.Flags; - -/** - * A controller to update current locale information of application - * and a entry to launch {@link ManageApplications}. - */ -public class NewManageAppLocalePreferenceController extends BasePreferenceController { - - public NewManageAppLocalePreferenceController(@NonNull Context context, @NonNull String key) { - super(context, key); - } - - @Override - public int getAvailabilityStatus() { - if (Flags.regionalPreferencesApiEnabled()) { - return AVAILABLE; - } - return CONDITIONALLY_UNAVAILABLE; - } -} diff --git a/src/com/android/settings/language/MoreLanguagesSettingsCategoryController.java b/src/com/android/settings/language/MoreLanguagesSettingsCategoryController.java deleted file mode 100644 index b174ae0ceb7..00000000000 --- a/src/com/android/settings/language/MoreLanguagesSettingsCategoryController.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.settings.language; - -import android.content.Context; - -import androidx.annotation.NonNull; - -import com.android.settings.flags.Flags; -import com.android.settings.widget.PreferenceCategoryController; - -public class MoreLanguagesSettingsCategoryController extends PreferenceCategoryController { - - public MoreLanguagesSettingsCategoryController(@NonNull Context context, @NonNull String key) { - super(context, key); - } - - @Override - public int getAvailabilityStatus() { - if (Flags.regionalPreferencesApiEnabled()) { - return AVAILABLE; - } - return CONDITIONALLY_UNAVAILABLE; - } -} diff --git a/src/com/android/settings/localepicker/NewTermsOfAddressController.java b/src/com/android/settings/localepicker/NewTermsOfAddressController.java deleted file mode 100644 index fe92405f1a1..00000000000 --- a/src/com/android/settings/localepicker/NewTermsOfAddressController.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.localepicker; - -import android.content.Context; -import android.os.LocaleList; - -import androidx.annotation.NonNull; - -import com.android.internal.app.LocaleStore; -import com.android.settings.R; -import com.android.settings.core.BasePreferenceController; -import com.android.settings.flags.Flags; - -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -public class NewTermsOfAddressController extends BasePreferenceController { - - public NewTermsOfAddressController(@NonNull Context context, @NonNull String preferenceKey) { - super(context, preferenceKey); - } - - @Override - public int getAvailabilityStatus() { - if (Flags.regionalPreferencesApiEnabled()) { - if (Flags.termsOfAddressEnabled()) { - return checkAvailabilityStatus(); - } - } - return CONDITIONALLY_UNAVAILABLE; - } - - private int checkAvailabilityStatus() { - // If language is not available for system language, or if ToA does not apply to - // system language, we will hide it. - final Locale defaultLocale = Locale.getDefault(); - LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(defaultLocale); - final List supportedLanguageList = Arrays.asList( - mContext.getResources().getStringArray( - R.array.terms_of_address_supported_languages)); - final List notSupportedLocaleList = Arrays.asList( - mContext.getResources().getStringArray( - R.array.terms_of_address_unsupported_locales)); - - final Locale locale = localeInfo.getLocale().stripExtensions(); - final String language = locale.getLanguage(); - final String localeTag = locale.toLanguageTag(); - - // Supported locales: - // 1. All French is supported except fr-CA. - // 2. QA language en-XA (LTR pseudo locale), ar_XB (RTL pseudo locale). - if ((supportedLanguageList.contains(language) - && !notSupportedLocaleList.contains(localeTag)) - || LocaleList.isPseudoLocale(locale)) { - return AVAILABLE; - } - - return CONDITIONALLY_UNAVAILABLE; - } -} diff --git a/src/com/android/settings/localepicker/TermsOfAddressCategoryController.java b/src/com/android/settings/localepicker/TermsOfAddressCategoryController.java index 1e2fbef7e83..01168c7ff7b 100644 --- a/src/com/android/settings/localepicker/TermsOfAddressCategoryController.java +++ b/src/com/android/settings/localepicker/TermsOfAddressCategoryController.java @@ -20,6 +20,7 @@ import static com.android.settings.flags.Flags.termsOfAddressEnabled; import android.content.Context; import android.os.LocaleList; +import android.text.TextUtils; import android.util.Log; import androidx.preference.PreferenceCategory; @@ -27,7 +28,6 @@ import androidx.preference.PreferenceScreen; import com.android.internal.app.LocaleStore; import com.android.settings.R; -import com.android.settings.flags.Flags; import com.android.settings.widget.PreferenceCategoryController; import java.util.Arrays; @@ -64,9 +64,6 @@ public class TermsOfAddressCategoryController extends PreferenceCategoryControll @Override public int getAvailabilityStatus() { - if (Flags.regionalPreferencesApiEnabled()) { - return CONDITIONALLY_UNAVAILABLE; - } if (!termsOfAddressEnabled()) { return CONDITIONALLY_UNAVAILABLE; diff --git a/src/com/android/settings/regionalpreferences/NewFirstDayOfWeekController.java b/src/com/android/settings/regionalpreferences/NewFirstDayOfWeekController.java deleted file mode 100644 index aa691ed0b45..00000000000 --- a/src/com/android/settings/regionalpreferences/NewFirstDayOfWeekController.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.regionalpreferences; - -import android.content.Context; -import android.provider.Settings; - -import androidx.annotation.NonNull; -import androidx.core.text.util.LocalePreferences; - -import com.android.settings.R; -import com.android.settings.core.BasePreferenceController; -import com.android.settings.flags.Flags; - -import java.util.Locale; - -/** A controller for the entry of First Day of Week's page */ -public class NewFirstDayOfWeekController extends BasePreferenceController { - - public NewFirstDayOfWeekController(@NonNull Context context, @NonNull String preferenceKey) { - super(context, preferenceKey); - } - - /** - * @return {@link AvailabilityStatus} for the Setting. This status is used to determine if the - * Setting should be shown or disabled in Settings. Further, it can be used to produce - * appropriate error / warning Slice in the case of unavailability. - *

- * The status is used for the convenience methods: {@link #isAvailable()}, {@link - * #isSupported()} - *

- * The inherited class doesn't need to check work profile if android:forWork="true" is set in - * preference xml. - */ - @Override - public int getAvailabilityStatus() { - if (Flags.regionalPreferencesApiEnabled()) { - return AVAILABLE; - } - return CONDITIONALLY_UNAVAILABLE; - } - - @Override - public CharSequence getSummary() { - String record = Settings.System.getString( - mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES); - String result = ""; - if (record != null) { - result = LocalePreferences.getFirstDayOfWeek(Locale.forLanguageTag(record), false); - } - - if (result.isEmpty()) { - result = LocalePreferences.getFirstDayOfWeek(false); - } - return result.isEmpty() - ? mContext.getString(R.string.default_string_of_regional_preference) - : RegionalPreferencesDataUtils.dayConverter(mContext, result); - } -} diff --git a/src/com/android/settings/regionalpreferences/NewNumberingSystemController.java b/src/com/android/settings/regionalpreferences/NewNumberingSystemController.java deleted file mode 100644 index 429d1f35503..00000000000 --- a/src/com/android/settings/regionalpreferences/NewNumberingSystemController.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.regionalpreferences; - -import android.content.Context; -import android.os.LocaleList; - -import androidx.annotation.NonNull; - -import com.android.internal.app.LocaleStore; -import com.android.settings.core.BasePreferenceController; -import com.android.settings.flags.Flags; -import com.android.settings.localepicker.LocaleFeatureProviderImpl; - -import java.util.HashSet; -import java.util.Locale; -import java.util.Set; - -/** A controller for the entry of Numbering System's page */ -public class NewNumberingSystemController extends BasePreferenceController { - private static final String TAG = NewNumberingSystemController.class.getSimpleName(); - - private LocaleList mLocaleList; - public NewNumberingSystemController(@NonNull Context context, @NonNull String preferenceKey) { - super(context, preferenceKey); - // Initialize the supported languages to LocaleInfos - LocaleStore.fillCache(context); - mLocaleList = getNumberingSystemLocale(); - } - - /** - * @return {@link AvailabilityStatus} for the Setting. This status is used to determine if the - * Setting should be shown or disabled in Settings. Further, it can be used to produce - * appropriate error / warning Slice in the case of unavailability. - *

- * The status is used for the convenience methods: {@link #isAvailable()}, {@link - * #isSupported()} - *

- * The inherited class doesn't need to check work profile if android:forWork="true" is set in - * preference xml. - */ - @Override - public int getAvailabilityStatus() { - if (Flags.regionalPreferencesApiEnabled()) { - return mLocaleList.isEmpty() ? CONDITIONALLY_UNAVAILABLE : AVAILABLE; - } - return CONDITIONALLY_UNAVAILABLE; - } - - private static LocaleList getNumberingSystemLocale() { - LocaleList localeList = LocaleList.getDefault(); - Set localesHasNumberingSystems = new HashSet<>(); - for (int i = 0; i < localeList.size(); i++) { - Locale locale = localeList.get(i); - LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(locale); - if (localeInfo.hasNumberingSystems()) { - localesHasNumberingSystems.add(locale); - } - } - return convertToLocaleList(localesHasNumberingSystems); - } - - private static LocaleList convertToLocaleList(Set locales) { - if (locales.isEmpty()) { - return LocaleList.getEmptyLocaleList(); - } - return new LocaleList(locales.stream().toArray(Locale[]::new)); - } - - @Override - public CharSequence getSummary() { - return new LocaleFeatureProviderImpl().getLocaleNames(getNumberingSystemLocale()); - } -} diff --git a/src/com/android/settings/regionalpreferences/NewRegionalFooterPreferenceController.java b/src/com/android/settings/regionalpreferences/NewRegionalFooterPreferenceController.java deleted file mode 100644 index 9c800de82c8..00000000000 --- a/src/com/android/settings/regionalpreferences/NewRegionalFooterPreferenceController.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.regionalpreferences; - -import android.content.Context; -import android.content.Intent; -import android.util.Log; - -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; -import androidx.preference.PreferenceScreen; - -import com.android.settings.R; -import com.android.settings.core.BasePreferenceController; -import com.android.settings.flags.Flags; -import com.android.settingslib.HelpUtils; -import com.android.settingslib.widget.FooterPreference; - -/** - * Preference controller for regional preference footer. - */ -public class NewRegionalFooterPreferenceController extends BasePreferenceController { - - private static final String TAG = "NewRegionalFooterPreferenceController"; - - public NewRegionalFooterPreferenceController(@NonNull Context context, @NonNull String key) { - super(context, key); - } - - @Override - public int getAvailabilityStatus() { - if (Flags.regionalPreferencesApiEnabled()) { - return AVAILABLE_UNSEARCHABLE; - } - - - return CONDITIONALLY_UNAVAILABLE; - } - - @Override - public void displayPreference(@NonNull PreferenceScreen screen) { - super.displayPreference(screen); - FooterPreference footerPreference = screen.findPreference(getPreferenceKey()); - setupFooterPreference(footerPreference); - } - - @VisibleForTesting - void setupFooterPreference(FooterPreference footerPreference) { - if (footerPreference != null) { - footerPreference.setLearnMoreAction(v -> openLocaleLearnMoreLink()); - footerPreference.setLearnMoreText(mContext.getString( - R.string.desc_regional_pref_footer_learn_more)); - } - } - - private void openLocaleLearnMoreLink() { - Intent intent = HelpUtils.getHelpIntent( - mContext, - mContext.getString(R.string.regional_pref_footer_learn_more_link), - mContext.getClass().getName()); - if (intent != null) { - mContext.startActivity(intent); - } else { - Log.w(TAG, "HelpIntent is null"); - } - } -} diff --git a/src/com/android/settings/regionalpreferences/NewTemperatureUnitController.java b/src/com/android/settings/regionalpreferences/NewTemperatureUnitController.java deleted file mode 100644 index 7d3dc3e59c6..00000000000 --- a/src/com/android/settings/regionalpreferences/NewTemperatureUnitController.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.regionalpreferences; - -import android.content.Context; -import android.provider.Settings; - -import androidx.annotation.NonNull; -import androidx.core.text.util.LocalePreferences; - -import com.android.settings.R; -import com.android.settings.core.BasePreferenceController; -import com.android.settings.flags.Flags; - -import java.util.Locale; - -/** A controller for the entry of Temperature units' page */ -public class NewTemperatureUnitController extends BasePreferenceController { - private static final String TAG = NewTemperatureUnitController.class.getSimpleName(); - public NewTemperatureUnitController(@NonNull Context context, @NonNull String preferenceKey) { - super(context, preferenceKey); - } - - /** - * @return {@link AvailabilityStatus} for the Setting. This status is used to determine if the - * Setting should be shown or disabled in Settings. Further, it can be used to produce - * appropriate error / warning Slice in the case of unavailability. - *

- * The status is used for the convenience methods: {@link #isAvailable()}, {@link - * #isSupported()} - *

- * The inherited class doesn't need to check work profile if android:forWork="true" is set in - * preference xml. - */ - @Override - public int getAvailabilityStatus() { - if (Flags.regionalPreferencesApiEnabled()) { - return AVAILABLE; - } - return CONDITIONALLY_UNAVAILABLE; - } - - @Override - public CharSequence getSummary() { - String record = Settings.System.getString( - mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES); - String result = ""; - if (record != null) { - result = LocalePreferences.getTemperatureUnit(Locale.forLanguageTag(record), false); - } - - if (result.isEmpty()) { - result = LocalePreferences.getTemperatureUnit(false); - } - - return result.isEmpty() - ? mContext.getString(R.string.default_string_of_regional_preference) - : RegionalPreferencesDataUtils.temperatureUnitsConverter(mContext, result); - } -} diff --git a/src/com/android/settings/regionalpreferences/RegionalPreferencesCategoryController.java b/src/com/android/settings/regionalpreferences/RegionalPreferencesCategoryController.java deleted file mode 100644 index ad524a4ed3c..00000000000 --- a/src/com/android/settings/regionalpreferences/RegionalPreferencesCategoryController.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.regionalpreferences; - -import android.content.Context; - -import androidx.annotation.NonNull; - -import com.android.settings.flags.Flags; -import com.android.settings.widget.PreferenceCategoryController; - -public class RegionalPreferencesCategoryController extends PreferenceCategoryController { - public RegionalPreferencesCategoryController(@NonNull Context context, @NonNull String key) { - super(context, key); - } - - @Override - public int getAvailabilityStatus() { - if (Flags.regionalPreferencesApiEnabled()) { - return AVAILABLE; - } - return CONDITIONALLY_UNAVAILABLE; - } -} diff --git a/src/com/android/settings/regionalpreferences/RegionalPreferencesController.java b/src/com/android/settings/regionalpreferences/RegionalPreferencesController.java index f194659c00b..5e5fc9d2175 100644 --- a/src/com/android/settings/regionalpreferences/RegionalPreferencesController.java +++ b/src/com/android/settings/regionalpreferences/RegionalPreferencesController.java @@ -20,7 +20,6 @@ import android.content.Context; import android.os.SystemProperties; import com.android.settings.core.BasePreferenceController; -import com.android.settings.flags.Flags; /** A controller for the entry of Regional preferences */ public class RegionalPreferencesController extends BasePreferenceController { @@ -43,9 +42,6 @@ public class RegionalPreferencesController extends BasePreferenceController { */ @Override public int getAvailabilityStatus() { - if (Flags.regionalPreferencesApiEnabled()) { - return CONDITIONALLY_UNAVAILABLE; - } return SystemProperties.getBoolean(FEATURE_PROPERTY, true) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; } diff --git a/src/com/android/settings/regionalpreferences/RegionalPreferencesEntriesFragment.java b/src/com/android/settings/regionalpreferences/RegionalPreferencesEntriesFragment.java index 8b1e749ef79..848febcf2d2 100644 --- a/src/com/android/settings/regionalpreferences/RegionalPreferencesEntriesFragment.java +++ b/src/com/android/settings/regionalpreferences/RegionalPreferencesEntriesFragment.java @@ -17,11 +17,9 @@ package com.android.settings.regionalpreferences; import android.app.settings.SettingsEnums; -import android.content.Context; import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; -import com.android.settings.flags.Flags; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.search.SearchIndexable; @@ -57,13 +55,5 @@ public class RegionalPreferencesEntriesFragment extends DashboardFragment { } public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = - new BaseSearchIndexProvider(R.xml.regional_preference_main_page) { - @Override - protected boolean isPageSearchEnabled(Context context) { - if (Flags.regionalPreferencesApiEnabled()) { - return false; - } - return true; - } - }; + new BaseSearchIndexProvider(R.xml.regional_preference_main_page); } diff --git a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressCategoryControllerTest.java b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressCategoryControllerTest.java index ed878f48f2b..b025abdf06a 100644 --- a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressCategoryControllerTest.java +++ b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressCategoryControllerTest.java @@ -24,13 +24,10 @@ import static org.mockito.Mockito.spy; import android.content.Context; import android.os.Looper; -import android.platform.test.annotations.DisableFlags; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; -import com.android.settings.flags.Flags; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -68,7 +65,6 @@ public class TermsOfAddressCategoryControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getAvailabilityStatus_returnAvailable() { Locale.setDefault(Locale.forLanguageTag("fr-FR")); diff --git a/tests/unit/src/com/android/settings/regionalpreferences/FirstDayOfWeekControllerTest.java b/tests/unit/src/com/android/settings/regionalpreferences/FirstDayOfWeekControllerTest.java index 759b356cfab..062aef8393a 100644 --- a/tests/unit/src/com/android/settings/regionalpreferences/FirstDayOfWeekControllerTest.java +++ b/tests/unit/src/com/android/settings/regionalpreferences/FirstDayOfWeekControllerTest.java @@ -19,12 +19,10 @@ package com.android.settings.regionalpreferences; import static org.junit.Assert.assertEquals; import android.content.Context; -import android.platform.test.annotations.DisableFlags; import android.provider.Settings; import androidx.test.core.app.ApplicationProvider; -import com.android.settings.flags.Flags; import com.android.settings.testutils.ResourcesUtils; import org.junit.After; @@ -56,7 +54,6 @@ public class FirstDayOfWeekControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_hasProviderValue_resultIsWed() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, "und-u-fw-wed"); @@ -67,7 +64,6 @@ public class FirstDayOfWeekControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_hasProviderValue_resultIsSat() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, "und-u-fw-sat"); @@ -78,7 +74,6 @@ public class FirstDayOfWeekControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_noProviderValueButHasDefaultLocaleWithSubtag_resultIsSat() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, ""); Locale.setDefault(Locale.forLanguageTag("en-US-u-fw-sat")); @@ -90,7 +85,6 @@ public class FirstDayOfWeekControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_noProviderValueAndDefaultLocaleWithoutSubtag_resultIsdefault() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, ""); Locale.setDefault(Locale.forLanguageTag("en-US")); diff --git a/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemControllerTest.java b/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemControllerTest.java index bb745a6fb28..6a95bb95826 100644 --- a/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemControllerTest.java +++ b/tests/unit/src/com/android/settings/regionalpreferences/NumberingSystemControllerTest.java @@ -23,12 +23,9 @@ import static org.junit.Assert.assertEquals; import android.content.Context; import android.os.LocaleList; -import android.platform.test.annotations.DisableFlags; import androidx.test.core.app.ApplicationProvider; -import com.android.settings.flags.Flags; - import org.junit.Before; import org.junit.Test; @@ -42,7 +39,6 @@ public class NumberingSystemControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getAvailabilityStatus_noLocale_unavailable() { LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-Hant-TW")); mController = new NumberingSystemController(mApplicationContext, "key"); @@ -53,7 +49,6 @@ public class NumberingSystemControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getAvailabilityStatus_hasLocaleWithNumberingSystems_available() { // ar-JO has different numbering system. LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-Hant-TW,ar-JO")); diff --git a/tests/unit/src/com/android/settings/regionalpreferences/TemperatureUnitControllerTest.java b/tests/unit/src/com/android/settings/regionalpreferences/TemperatureUnitControllerTest.java index fb05dfaedb4..aa652cab1f4 100644 --- a/tests/unit/src/com/android/settings/regionalpreferences/TemperatureUnitControllerTest.java +++ b/tests/unit/src/com/android/settings/regionalpreferences/TemperatureUnitControllerTest.java @@ -19,12 +19,10 @@ package com.android.settings.regionalpreferences; import static org.junit.Assert.assertEquals; import android.content.Context; -import android.platform.test.annotations.DisableFlags; import android.provider.Settings; import androidx.test.core.app.ApplicationProvider; -import com.android.settings.flags.Flags; import com.android.settings.testutils.ResourcesUtils; import org.junit.After; @@ -56,7 +54,6 @@ public class TemperatureUnitControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_hasProviderValue_resultIsCelsius() { RegionalPreferenceTestUtils.setSettingsProviderContent( mApplicationContext, "und-u-mu-celsius"); @@ -68,7 +65,6 @@ public class TemperatureUnitControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_hasProviderValue_resultIsFahrenheit() { RegionalPreferenceTestUtils.setSettingsProviderContent( mApplicationContext, "und-u-mu-fahrenhe"); @@ -80,7 +76,6 @@ public class TemperatureUnitControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_noProviderValueButHasDefaultLocaleWithSubtag_resultIsFahrenheit() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, ""); Locale.setDefault(Locale.forLanguageTag("en-US-u-mu-fahrenhe")); @@ -92,7 +87,6 @@ public class TemperatureUnitControllerTest { } @Test - @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) public void getSummary_noProviderValueAndDefaultLocaleWithoutSubtag_resultIsDefault() { RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, ""); Locale.setDefault(Locale.forLanguageTag("en-US"));