Merge "Properly handle the autofill provider names, making sure place holder name is properly filtered out." into main
diff --git a/aconfig/accessibility/accessibility_flags.aconfig b/aconfig/accessibility/accessibility_flags.aconfig
index c9e1ece..2c92547 100644
--- a/aconfig/accessibility/accessibility_flags.aconfig
+++ b/aconfig/accessibility/accessibility_flags.aconfig
@@ -4,6 +4,13 @@
# NOTE: Keep alphabetized to help limit merge conflicts from multiple simultaneous editors.
flag {
+ name: "add_brightness_settings_in_suw"
+ namespace: "accessibility"
+ description: "Whether to add brightness preference in SUW Vision Settings"
+ bug: "332974327"
+}
+
+flag {
name: "edit_shortcuts_in_full_screen"
namespace: "accessibility"
description: "Show the edit shorcuts screen in full screen, since the shortcut options are increasing."
diff --git a/aconfig/settings_device_diagnostics_declarations.aconfig b/aconfig/settings_device_diagnostics_declarations.aconfig
new file mode 100644
index 0000000..90a12db
--- /dev/null
+++ b/aconfig/settings_device_diagnostics_declarations.aconfig
@@ -0,0 +1,9 @@
+package: "com.android.settings.flags"
+container: "system_ext"
+
+flag {
+ name: "enable_device_diagnostics_in_settings"
+ namespace: "phoenix"
+ description: "Enable the Device Diagnostics app in Settings"
+ bug: "309886423"
+}
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index ecc795e..bd90b98 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -2,6 +2,18 @@
<issues format="4">
<issue
+ id="LintError"
+ severity="Error"
+ message="No `.class` files were found in project ".", so none of the classfile based checks could be run. Does the project need to be built first?"
+ category="Lint"
+ priority="10"
+ summary="Lint Failure"
+ explanation="This issue type represents a problem running lint itself. Examples include failure to find bytecode for source files (which means certain detectors could not be run), parsing errors in lint configuration files, etc.
These errors are not errors in your own code, but they are shown to make it clear that some checks were not completed.">
+ <location
+ file="."/>
+ </issue>
+
+ <issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
@@ -4572,6 +4584,38 @@
errorLine1=" android:color="@color/accessibility_feature_background"/>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
+ file="res/drawable/ic_suw_brightness_auto.xml"
+ line="22"
+ column="13"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" android:color="@color/accessibility_feature_background"/>"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
+ file="res/drawable/ic_suw_brightness_level.xml"
+ line="22"
+ column="13"/>
+ </issue>
+
+ <issue
+ id="HardCodedColor"
+ severity="Error"
+ message="Avoid using hardcoded color"
+ category="Correctness"
+ priority="4"
+ summary="Using hardcoded color"
+ explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
+ errorLine1=" android:color="@color/accessibility_feature_background"/>"
+ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
+ <location
file="res/drawable/ic_system_controls.xml"
line="22"
column="13"/>
diff --git a/res/drawable/ic_brightness_auto.xml b/res/drawable/ic_brightness_auto.xml
new file mode 100644
index 0000000..7ace52b
--- /dev/null
+++ b/res/drawable/ic_brightness_auto.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="@dimen/accessibility_icon_foreground_size"
+ android:height="@dimen/accessibility_icon_foreground_size"
+ android:viewportWidth="960"
+ android:viewportHeight="960">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M312,640L376,640L408,548L554,548L586,640L648,640L512,280L448,280L312,640ZM426,496L478,346L482,346L534,496L426,496ZM480,932L346,800L160,800L160,614L28,480L160,346L160,160L346,160L480,28L614,160L800,160L800,346L932,480L800,614L800,800L614,800L480,932ZM480,820L580,720L720,720L720,580L820,480L720,380L720,240L580,240L480,140L380,240L240,240L240,380L140,480L240,580L240,720L380,720L480,820ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Z"/>
+</vector>
diff --git a/res/drawable/ic_brightness_medium.xml b/res/drawable/ic_brightness_medium.xml
new file mode 100644
index 0000000..3e77885
--- /dev/null
+++ b/res/drawable/ic_brightness_medium.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="@dimen/accessibility_icon_foreground_size"
+ android:height="@dimen/accessibility_icon_foreground_size"
+ android:viewportWidth="960"
+ android:viewportHeight="960">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M480,932L346,800L160,800L160,614L28,480L160,346L160,160L346,160L480,28L614,160L800,160L800,346L932,480L800,614L800,800L614,800L480,932ZM480,680Q563,680 621.5,621.5Q680,563 680,480Q680,397 621.5,338.5Q563,280 480,280L480,680ZM480,820L580,720L720,720L720,580L820,480L720,380L720,240L580,240L480,140L380,240L240,240L240,380L140,480L240,580L240,720L380,720L480,820ZM480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480Z"/>
+</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_device_diagnostics.xml b/res/drawable/ic_device_diagnostics.xml
new file mode 100644
index 0000000..26953a7
--- /dev/null
+++ b/res/drawable/ic_device_diagnostics.xml
@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="960"
+ android:viewportHeight="960"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:pathData="M320,760h320v-80L320,680v80ZM320,640h320v-80L320,560v80ZM480,492q66,-60 113,-106.5t47,-97.5q0,-36 -26,-62t-62,-26q-21,0 -40.5,8.5T480,232q-12,-15 -31.5,-23.5T408,200q-36,0 -62,26t-26,62q0,51 45.5,96T480,492ZM720,880L240,880q-33,0 -56.5,-23.5T160,800v-640q0,-33 23.5,-56.5T240,80h480q33,0 56.5,23.5T800,160v640q0,33 -23.5,56.5T720,880ZM240,800h480v-640L240,160v640ZM240,800v-640,640Z"
+ android:fillColor="#FFFFFFFF"/>
+</vector>
diff --git a/res/drawable/ic_suw_brightness_auto.xml b/res/drawable/ic_suw_brightness_auto.xml
new file mode 100644
index 0000000..a4221c5
--- /dev/null
+++ b/res/drawable/ic_suw_brightness_auto.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <com.android.settingslib.widget.AdaptiveIconShapeDrawable
+ android:width="@dimen/accessibility_icon_size"
+ android:height="@dimen/accessibility_icon_size"
+ android:color="@color/accessibility_feature_background"/>
+ </item>
+ <item android:gravity="center"
+ android:drawable="@drawable/ic_brightness_auto"/>
+</layer-list>
\ No newline at end of file
diff --git a/res/drawable/ic_suw_brightness_level.xml b/res/drawable/ic_suw_brightness_level.xml
new file mode 100644
index 0000000..57bd188
--- /dev/null
+++ b/res/drawable/ic_suw_brightness_level.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <com.android.settingslib.widget.AdaptiveIconShapeDrawable
+ android:width="@dimen/accessibility_icon_size"
+ android:height="@dimen/accessibility_icon_size"
+ android:color="@color/accessibility_feature_background"/>
+ </item>
+ <item android:gravity="center"
+ android:drawable="@drawable/ic_brightness_medium"/>
+</layer-list>
\ No newline at end of file
diff --git a/res/values/config.xml b/res/values/config.xml
index 4d3a233..4b638b2 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -836,4 +836,7 @@
<!-- The Activity intent to trigger to launch time-related feedback. -->
<string name="config_time_feedback_intent_uri" translatable="false" />
+
+ <!-- Package name for diagnostics app. -->
+ <string name="config_device_diagnostics_package_name" translatable="false">com.android.devicediagnostics</string>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8e26962..f88b036 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1257,8 +1257,8 @@
<string name="private_space_auto_lock_page_summary">You can lock your private space automatically if you haven\’t used your device for a period of time</string>
<!-- Configure auto lock: Value for auto lock configuration to lock private space every time device locks. [CHAR LIMIT=40] -->
<string name="private_space_auto_lock_every_time">Every time device locks</string>
- <!-- Configure auto lock: Value for auto lock configuration to lock private space after 5 minutes of inactivity. [CHAR LIMIT=40] -->
- <string name="private_space_auto_lock_after_inactivity">After 5 minutes of inactivity</string>
+ <!-- Configure auto lock: Value for auto lock configuration to lock private space after 5 minutes of inactivity post screen timeout. [CHAR LIMIT=40] -->
+ <string name="private_space_auto_lock_after_inactivity">5 minutes after screen timeout</string>
<!-- Configure auto lock: Value for auto lock configuration to lock private space only after device restarts. [CHAR LIMIT=40] -->
<string name="private_space_auto_lock_after_device_restart">Only after device restarts</string>
<!-- Title for the settings page for hiding private space. [CHAR LIMIT=45] -->
@@ -2732,6 +2732,10 @@
<!-- Display settings screen, Color mode option for "Adaptive color" [CHAR LIMIT=45] -->
<string name="color_mode_option_automatic">Adaptive</string>
+ <!-- Key for the brightness level preference -->
+ <string name="preference_key_brightness_level" translatable="false">brightness</string>
+ <!-- Key for the auto brightness preference -->
+ <string name="preference_key_auto_brightness" translatable="false">auto_brightness_entry</string>
<!-- Sound & display settings screen, setting option name to change brightness level -->
<string name="brightness">Brightness level</string>
<!-- Sound & display settings screen, setting option name to enable adaptive brightness [CHAR LIMIT=30] -->
@@ -4084,7 +4088,7 @@
<!-- Manage applications, restore updated system application to factory version -->
<string name="app_factory_reset">Uninstall updates</string>
<!-- [CHAR LIMIT=50] Manage applications, unlock restricted setting from lock screen title -->
- <string name="app_restricted_settings_lockscreen_title">Allow restricted permissions</string>
+ <string name="app_restricted_settings_lockscreen_title">Allow restricted settings</string>
<!-- Manage applications, individual application info screen, screen, message text under Launch by default heading. This is present if the app is set as a default for some actions. -->
<string name="auto_launch_enable_text">Some activities you\u2019ve selected open in this app by default.</string>
<!-- Manage applications, individual application info screen, screen, message text under Launch by default heading. This is present if the app was given user permission to create widgets. -->
@@ -7889,6 +7893,9 @@
<!-- Sound: Title for the Do not Disturb option and associated settings page. [CHAR LIMIT=50]-->
<string name="zen_mode_settings_title">Do Not Disturb</string>
+ <!-- Sound: Title for the Modes option and associated settings page. [CHAR LIMIT=50]-->
+ <string name="zen_modes_list_title">Priority Modes</string>
+
<!-- Sound: Summary for the Do not Disturb option and associated settings page. [CHAR LIMIT=240]-->
<string name="zen_mode_settings_summary">Only get notified by important people and apps</string>
@@ -13258,4 +13265,9 @@
<!--Title for Sync Across Devices category-->
<string name="sync_across_devices_title">Sync across devices</string>
+
+ <!-- Device Diagnostics -->
+
+ <!-- Title for System dashboard fragment -->
+ <string name="device_diagnostics_title">Device diagnostics</string>
</resources>
diff --git a/res/xml/accessibility_settings_for_setup_wizard.xml b/res/xml/accessibility_settings_for_setup_wizard.xml
index 0926d2d..a69dc26 100644
--- a/res/xml/accessibility_settings_for_setup_wizard.xml
+++ b/res/xml/accessibility_settings_for_setup_wizard.xml
@@ -29,6 +29,22 @@
settings:keywords="text_reading_options"
settings:controller="com.android.settings.accessibility.TextReadingFragmentForSuwController"/>
+ <com.android.settingslib.RestrictedPreference
+ android:key="@string/preference_key_brightness_level"
+ android:icon="@drawable/ic_suw_brightness_level"
+ android:title="@string/brightness"
+ settings:keywords="@string/keywords_display_brightness_level"
+ settings:useAdminDisabledSummary="true"
+ settings:userRestriction="no_config_brightness"/>
+
+ <com.android.settingslib.PrimarySwitchPreference
+ android:key="@string/preference_key_auto_brightness"
+ android:icon="@drawable/ic_suw_brightness_auto"
+ android:title="@string/auto_brightness_title"
+ android:fragment="com.android.settings.accessibility.AutoBrightnessPreferenceFragmentForSetupWizard"
+ settings:useAdminDisabledSummary="true"
+ settings:userRestriction="no_config_brightness"/>
+
<Preference
android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragmentForSetupWizard"
android:key="screen_magnification_preference"
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index abf0cc6..4e52cf4 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -26,14 +26,14 @@
android:order="-200">
<com.android.settingslib.RestrictedPreference
- android:key="brightness"
+ android:key="@string/preference_key_brightness_level"
android:title="@string/brightness"
settings:keywords="@string/keywords_display_brightness_level"
settings:useAdminDisabledSummary="true"
settings:userRestriction="no_config_brightness"/>
<com.android.settingslib.PrimarySwitchPreference
- android:key="auto_brightness_entry"
+ android:key="@string/preference_key_auto_brightness"
android:title="@string/auto_brightness_title"
android:fragment="com.android.settings.display.AutoBrightnessSettings"
settings:useAdminDisabledSummary="true"
diff --git a/res/xml/modes_list_settings.xml b/res/xml/modes_list_settings.xml
new file mode 100644
index 0000000..c6b6200
--- /dev/null
+++ b/res/xml/modes_list_settings.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/zen_modes_list_title" >
+
+ <!-- TODO: b/333682392 - add strings for summary as appropriate -->
+
+ <PreferenceCategory
+ android:key="zen_modes_list">
+ <!-- Preferences leading to rules are added in this PreferenceCategory. -->
+ </PreferenceCategory>
+
+</PreferenceScreen>
diff --git a/res/xml/modes_rule_settings.xml b/res/xml/modes_rule_settings.xml
new file mode 100644
index 0000000..d7e2694
--- /dev/null
+++ b/res/xml/modes_rule_settings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/zen_modes_list_title" >
+
+ <!-- TODO: b/308819292 - implement page, delete this test preference -->
+ <Preference
+ android:key="zen_mode_test" />
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/system_dashboard_fragment.xml b/res/xml/system_dashboard_fragment.xml
index 628eab9..6225f4f 100644
--- a/res/xml/system_dashboard_fragment.xml
+++ b/res/xml/system_dashboard_fragment.xml
@@ -98,6 +98,13 @@
settings:controller="com.android.settings.system.DeveloperOptionsController"/>
<Preference
+ android:key="device_diagnostics"
+ android:title="@string/device_diagnostics_title"
+ android:order="-35"
+ android:icon="@drawable/ic_device_diagnostics"
+ settings:controller="com.android.settings.system.DeviceDiagnosticsPreferenceController"/>
+
+ <Preference
android:key="reset_dashboard"
android:title="@string/reset_dashboard_title"
android:icon="@drawable/ic_restore"
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index 35fe6e4..2295dee 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -44,6 +44,7 @@
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.AccessibilityServiceFragmentType;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.development.Enable16kUtils;
import com.android.settings.inputmethod.PhysicalKeyboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -98,6 +99,8 @@
static final String EXTRA_TIME_FOR_LOGGING = "start_time_to_log_a11y_tool";
static final String EXTRA_METRICS_CATEGORY = "metrics_category";
+ public static final String VOICE_ACCESS_SERVICE = "android.apps.accessibility.voiceaccess";
+
// Timeout before we update the services if packages are added/removed
// since the AccessibilityManagerService has to do that processing first
// to generate the AccessibilityServiceInfo we need for proper
@@ -488,6 +491,11 @@
String[] services = getResources().getStringArray(key);
PreferenceCategory category = mCategoryToPrefCategoryMap.get(categoryKey);
for (int i = 0; i < services.length; i++) {
+ // TODO(b/335443194) Voice access is not available in 16kB mode.
+ if (services[i].contains(VOICE_ACCESS_SERVICE)
+ && Enable16kUtils.isPageAgnosticModeOn(getContext())) {
+ continue;
+ }
ComponentName component = ComponentName.unflattenFromString(services[i]);
mPreBundledServiceComponentToCategoryMap.put(component, category);
}
diff --git a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
index fdf7592..447e34e 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
@@ -24,6 +24,7 @@
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
+import android.content.Context;
import android.content.pm.ServiceInfo;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
@@ -40,11 +41,15 @@
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.display.AutoBrightnessPreferenceController;
+import com.android.settings.display.BrightnessLevelPreferenceController;
import com.android.settingslib.RestrictedPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupdesign.GlifPreferenceLayout;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -161,6 +166,21 @@
return TAG;
}
+ @Override
+ protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ BrightnessLevelPreferenceController brightnessLevelPreferenceController =
+ new BrightnessLevelPreferenceController(context, getSettingsLifecycle());
+ brightnessLevelPreferenceController.setInSetupWizard(true);
+ controllers.add(brightnessLevelPreferenceController);
+ String autoBrightnessKey = context.getString(R.string.preference_key_auto_brightness);
+ AutoBrightnessPreferenceController autoBrightnessPreferenceController =
+ new AutoBrightnessPreferenceController(context, autoBrightnessKey);
+ autoBrightnessPreferenceController.setInSetupWizard(true);
+ controllers.add(autoBrightnessPreferenceController);
+ return controllers;
+ }
+
/**
* Returns accessibility service info by given package name and service name.
*
diff --git a/src/com/android/settings/accessibility/AutoBrightnessPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/AutoBrightnessPreferenceFragmentForSetupWizard.java
new file mode 100644
index 0000000..ad1ae96
--- /dev/null
+++ b/src/com/android/settings/accessibility/AutoBrightnessPreferenceFragmentForSetupWizard.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.accessibility;
+
+import static android.app.Activity.RESULT_CANCELED;
+
+import android.app.settings.SettingsEnums;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.android.settings.R;
+import com.android.settings.display.AutoBrightnessSettings;
+import com.android.settingslib.Utils;
+
+import com.google.android.setupcompat.template.FooterBarMixin;
+import com.google.android.setupdesign.GlifPreferenceLayout;
+
+/**
+ * Fragment for adaptive brightness settings in the SetupWizard.
+ */
+public class AutoBrightnessPreferenceFragmentForSetupWizard extends AutoBrightnessSettings {
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+
+ if (view instanceof GlifPreferenceLayout) {
+ final GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
+ final String title = getContext().getString(
+ R.string.auto_brightness_title);
+ final Drawable icon = getContext().getDrawable(R.drawable.ic_accessibility_visibility);
+ icon.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorPrimary));
+ AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(getContext(), layout, title,
+ /* description= */ null, icon);
+
+ final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
+ AccessibilitySetupWizardUtils.setPrimaryButton(getContext(), mixin, R.string.done,
+ () -> {
+ setResult(RESULT_CANCELED);
+ finish();
+ });
+ }
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView onCreateRecyclerView(@NonNull LayoutInflater inflater,
+ @NonNull ViewGroup parent, @Nullable Bundle savedInstanceState) {
+ if (parent instanceof GlifPreferenceLayout) {
+ final GlifPreferenceLayout layout = (GlifPreferenceLayout) parent;
+ return layout.onCreateRecyclerView(inflater, parent, savedInstanceState);
+ }
+ return super.onCreateRecyclerView(inflater, parent, savedInstanceState);
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.SUW_ACCESSIBILITY_AUTO_BRIGHTNESS;
+ }
+}
diff --git a/src/com/android/settings/accessibility/RestrictedPreferenceHelper.java b/src/com/android/settings/accessibility/RestrictedPreferenceHelper.java
index c806c0b..7455eea 100644
--- a/src/com/android/settings/accessibility/RestrictedPreferenceHelper.java
+++ b/src/com/android/settings/accessibility/RestrictedPreferenceHelper.java
@@ -16,6 +16,7 @@
package com.android.settings.accessibility;
+import static com.android.settings.accessibility.AccessibilitySettings.VOICE_ACCESS_SERVICE;
import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_MEDIUM;
import android.accessibilityservice.AccessibilityServiceInfo;
@@ -37,6 +38,7 @@
import com.android.settings.R;
import com.android.settings.Utils;
+import com.android.settings.development.Enable16kUtils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
@@ -89,6 +91,11 @@
final AccessibilityServiceInfo info = installedServices.get(i);
final ResolveInfo resolveInfo = info.getResolveInfo();
final String packageName = resolveInfo.serviceInfo.packageName;
+ // TODO(b/335443194) Voice access is not available in 16kB mode.
+ if (packageName.contains(VOICE_ACCESS_SERVICE)
+ && Enable16kUtils.isPageAgnosticModeOn(mContext)) {
+ continue;
+ }
final ComponentName componentName = new ComponentName(packageName,
resolveInfo.serviceInfo.name);
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 4d43d79..7c601c0 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -28,6 +28,7 @@
import com.android.settings.accessibility.AccessibilityHearingAidsFragment;
import com.android.settings.accessibility.AccessibilitySettings;
import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
+import com.android.settings.accessibility.AutoBrightnessPreferenceFragmentForSetupWizard;
import com.android.settings.accessibility.CaptioningPropertiesFragment;
import com.android.settings.accessibility.ColorAndMotionFragment;
import com.android.settings.accessibility.HearingDevicePairingFragment;
@@ -258,6 +259,7 @@
EditShortcutsPreferenceFragment.class.getName(),
TextReadingPreferenceFragment.class.getName(),
TextReadingPreferenceFragmentForSetupWizard.class.getName(),
+ AutoBrightnessPreferenceFragmentForSetupWizard.class.getName(),
CaptioningPropertiesFragment.class.getName(),
ToggleDaltonizerPreferenceFragment.class.getName(),
ToggleColorInversionPreferenceFragment.class.getName(),
diff --git a/src/com/android/settings/display/AutoBrightnessPreferenceController.java b/src/com/android/settings/display/AutoBrightnessPreferenceController.java
index 3f9be2f..3014f62 100644
--- a/src/com/android/settings/display/AutoBrightnessPreferenceController.java
+++ b/src/com/android/settings/display/AutoBrightnessPreferenceController.java
@@ -25,6 +25,7 @@
import androidx.preference.Preference;
import com.android.settings.R;
+import com.android.settings.accessibility.Flags;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.PrimarySwitchPreference;
@@ -33,10 +34,16 @@
private final String SYSTEM_KEY = SCREEN_BRIGHTNESS_MODE;
private final int DEFAULT_VALUE = SCREEN_BRIGHTNESS_MODE_MANUAL;
+ private boolean mInSetupWizard;
+
public AutoBrightnessPreferenceController(Context context, String key) {
super(context, key);
}
+ public void setInSetupWizard(boolean inSetupWizard) {
+ mInSetupWizard = inSetupWizard;
+ }
+
@Override
public boolean isChecked() {
return Settings.System.getInt(mContext.getContentResolver(),
@@ -53,10 +60,14 @@
@Override
@AvailabilityStatus
public int getAvailabilityStatus() {
- return mContext.getResources().getBoolean(
- com.android.internal.R.bool.config_automatic_brightness_available)
- ? AVAILABLE_UNSEARCHABLE
- : UNSUPPORTED_ON_DEVICE;
+ if (!mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_automatic_brightness_available)) {
+ return UNSUPPORTED_ON_DEVICE;
+ }
+ if (mInSetupWizard && !Flags.addBrightnessSettingsInSuw()) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ return AVAILABLE_UNSEARCHABLE;
}
@Override
diff --git a/src/com/android/settings/display/BrightnessLevelPreferenceController.java b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
index 49b8da3..a32c965 100644
--- a/src/com/android/settings/display/BrightnessLevelPreferenceController.java
+++ b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
@@ -20,6 +20,7 @@
import static com.android.settingslib.display.BrightnessUtils.GAMMA_SPACE_MIN;
import static com.android.settingslib.display.BrightnessUtils.convertLinearToGammaFloat;
+import android.annotation.Nullable;
import android.app.ActivityOptions;
import android.content.ContentResolver;
import android.content.Context;
@@ -39,10 +40,12 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.settings.R;
import com.android.settings.Utils;
+import com.android.settings.accessibility.Flags;
+import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SettingsBaseActivity;
-import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
@@ -51,17 +54,18 @@
import java.text.NumberFormat;
-public class BrightnessLevelPreferenceController extends AbstractPreferenceController implements
+public class BrightnessLevelPreferenceController extends BasePreferenceController implements
PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop {
private static final String TAG = "BrightnessPrefCtrl";
- private static final String KEY_BRIGHTNESS = "brightness";
+
private static final Uri BRIGHTNESS_ADJ_URI;
private final ContentResolver mContentResolver;
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final DisplayManager mDisplayManager;
-
+ @Nullable
private Preference mPreference;
+ private boolean mInSetupWizard;
static {
BRIGHTNESS_ADJ_URI = System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ);
@@ -90,9 +94,12 @@
}
};
-
public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle) {
- super(context);
+ this(context, context.getString(R.string.preference_key_brightness_level), lifecycle);
+ }
+
+ private BrightnessLevelPreferenceController(Context context, String key, Lifecycle lifecycle) {
+ super(context, key);
mDisplayManager = context.getSystemService(DisplayManager.class);
if (lifecycle != null) {
@@ -101,20 +108,22 @@
mContentResolver = mContext.getContentResolver();
}
- @Override
- public boolean isAvailable() {
- return true;
+ public void setInSetupWizard(boolean inSetupWizard) {
+ mInSetupWizard = inSetupWizard;
}
@Override
- public String getPreferenceKey() {
- return KEY_BRIGHTNESS;
+ public int getAvailabilityStatus() {
+ if (mInSetupWizard && !Flags.addBrightnessSettingsInSuw()) {
+ return CONDITIONALLY_UNAVAILABLE;
+ }
+ return AVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- mPreference = screen.findPreference(KEY_BRIGHTNESS);
+ mPreference = screen.findPreference(getPreferenceKey());
}
@Override
diff --git a/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
index 06c3cee..0365f80 100644
--- a/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
@@ -61,9 +61,8 @@
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mBatteryUsageProgressBarPref = screen.findPreference(getPreferenceKey());
- // Set up loading text first to prevent layout flaky before info loaded.
- mBatteryUsageProgressBarPref.setBottomSummary(
- mContext.getString(R.string.settings_license_activity_loading));
+ // Set up empty space text first to prevent layout flaky before info loaded.
+ mBatteryUsageProgressBarPref.setBottomSummary(" ");
if (com.android.settings.Utils.isBatteryPresent(mContext)) {
quickUpdateHeaderPreference();
@@ -86,13 +85,14 @@
return mContext.getString(
com.android.settingslib.R.string.battery_info_status_charging_on_hold);
}
+ if (info.remainingLabel != null
+ && mBatterySettingsFeatureProvider.isChargingOptimizationMode(mContext)) {
+ return info.remainingLabel;
+ }
if (info.remainingLabel == null
|| info.batteryStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
return info.statusLabel;
}
- if (mBatterySettingsFeatureProvider.isChargingOptimizationMode(mContext)) {
- return info.remainingLabel;
- }
if (info.pluggedStatus == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
final CharSequence wirelessChargingLabel =
mBatterySettingsFeatureProvider.getWirelessChargingLabel(mContext, info);
diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java
index c333a33..b54801a 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfo.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfo.java
@@ -390,12 +390,37 @@
info.remainingLabel = null;
int chargingLimitedResId = R.string.power_charging_limited;
info.chargeLabel = context.getString(chargingLimitedResId, info.batteryPercentString);
- } else if ((chargeTimeMs > 0
+ return;
+ }
+ final BatterySettingsFeatureProvider featureProvider =
+ FeatureFactory.getFeatureFactory().getBatterySettingsFeatureProvider();
+ if (featureProvider.isChargingOptimizationMode(context)) {
+ final CharSequence chargeLabel =
+ featureProvider.getChargingOptimizationChargeLabel(
+ context,
+ info.batteryLevel,
+ info.batteryPercentString,
+ chargeTimeMs,
+ currentTimeMs);
+ if (chargeLabel != null) {
+ final CharSequence remainingLabel =
+ featureProvider.getChargingOptimizationRemainingLabel(
+ context,
+ info.batteryLevel,
+ info.pluggedStatus,
+ chargeTimeMs,
+ currentTimeMs);
+ if (remainingLabel != null) {
+ info.chargeLabel = chargeLabel;
+ info.remainingLabel = remainingLabel;
+ return;
+ }
+ }
+ }
+ if ((chargeTimeMs > 0
&& status != BatteryManager.BATTERY_STATUS_FULL
&& dockDefenderMode == BatteryUtils.DockDefenderMode.DISABLED)
|| dockDefenderMode == BatteryUtils.DockDefenderMode.TEMPORARILY_BYPASSED) {
- final BatterySettingsFeatureProvider featureProvider =
- FeatureFactory.getFeatureFactory().getBatterySettingsFeatureProvider();
// Battery is charging to full
info.remainingTimeUs = PowerUtil.convertMsToUs(chargeTimeMs);
int resId = getChargingDurationResId(info.isFastCharging);
@@ -419,8 +444,7 @@
info.batteryPercentString,
chargeTimeMs,
info.isFastCharging,
- currentTimeMs,
- featureProvider);
+ currentTimeMs);
} else if (dockDefenderMode == BatteryUtils.DockDefenderMode.FUTURE_BYPASS) {
// Dock defender will be triggered in the future, charging will be optimized.
info.chargeLabel =
@@ -447,14 +471,6 @@
int pluggedStatus,
long currentTimeMs,
BatterySettingsFeatureProvider featureProvider) {
- if (featureProvider.isChargingOptimizationMode(context)) {
- final CharSequence chargingOptimizationRemainingLabel =
- featureProvider.getChargingOptimizationRemainingLabel(
- context, chargeRemainingTimeMs, currentTimeMs);
- if (chargingOptimizationRemainingLabel != null) {
- return chargingOptimizationRemainingLabel;
- }
- }
if (pluggedStatus == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
final CharSequence wirelessChargingRemainingLabel =
featureProvider.getWirelessChargingRemainingLabel(
@@ -488,16 +504,7 @@
String batteryPercentString,
long chargeTimeMs,
boolean isFastCharging,
- long currentTimeMs,
- BatterySettingsFeatureProvider featureProvider) {
- if (featureProvider.isChargingOptimizationMode(context)) {
- final CharSequence chargingOptimizationChargeLabel =
- featureProvider.getChargingOptimizationChargeLabel(
- context, batteryPercentString, chargeTimeMs, currentTimeMs);
- if (chargingOptimizationChargeLabel != null) {
- return chargingOptimizationChargeLabel;
- }
- }
+ long currentTimeMs) {
if (com.android.settingslib.fuelgauge.BatteryUtils.isChargingStringV2Enabled()) {
var timeString =
PowerUtil.getTargetTimeShortString(context, chargeTimeMs, currentTimeMs);
diff --git a/src/com/android/settings/fuelgauge/BatterySettingsFeatureProvider.java b/src/com/android/settings/fuelgauge/BatterySettingsFeatureProvider.java
index ab6d5ac..454a295 100644
--- a/src/com/android/settings/fuelgauge/BatterySettingsFeatureProvider.java
+++ b/src/com/android/settings/fuelgauge/BatterySettingsFeatureProvider.java
@@ -60,13 +60,18 @@
/** Return a charging remaining time label for charging optimization mode. */
@Nullable
CharSequence getChargingOptimizationRemainingLabel(
- @NonNull Context context, long chargeRemainingTimeMs, long currentTimeMs);
+ @NonNull Context context,
+ int batteryLevel,
+ int pluggedStatus,
+ long chargeRemainingTimeMs,
+ long currentTimeMs);
/** Return a charge label for charging optimization mode. */
@Nullable
CharSequence getChargingOptimizationChargeLabel(
@NonNull Context context,
- @NonNull String batteryPercentageString,
+ int batteryLevel,
+ String batteryPercentageString,
long chargeRemainingTimeMs,
long currentTimeMs);
}
diff --git a/src/com/android/settings/fuelgauge/BatterySettingsFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/BatterySettingsFeatureProviderImpl.java
index b2db347..40cfd0c 100644
--- a/src/com/android/settings/fuelgauge/BatterySettingsFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/BatterySettingsFeatureProviderImpl.java
@@ -76,7 +76,11 @@
@Nullable
@Override
public CharSequence getChargingOptimizationRemainingLabel(
- @NonNull Context context, long chargeRemainingTimeMs, long currentTimeMs) {
+ @NonNull Context context,
+ int batteryLevel,
+ int pluggedStatus,
+ long chargeRemainingTimeMs,
+ long currentTimeMs) {
return null;
}
@@ -84,7 +88,8 @@
@Override
public CharSequence getChargingOptimizationChargeLabel(
@NonNull Context context,
- @NonNull String batteryPercentageString,
+ int batteryLevel,
+ String batteryPercentageString,
long chargeRemainingTimeMs,
long currentTimeMs) {
return null;
diff --git a/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java b/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java
index 08d49f1..fd0d820 100644
--- a/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java
@@ -159,6 +159,11 @@
com.android.settingslib.R.string.power_charging_on_hold_settings_home_page,
info.batteryPercentString);
}
+ final BatterySettingsFeatureProvider featureProvider =
+ FeatureFactory.getFeatureFactory().getBatterySettingsFeatureProvider();
+ if (info.chargeLabel != null && featureProvider.isChargingOptimizationMode(mContext)) {
+ return info.chargeLabel;
+ }
if (info.batteryStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
// Present status only if no remaining time or status anomalous
return info.statusLabel;
diff --git a/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java b/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
index eb833b1..b56c1b9 100644
--- a/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
@@ -31,6 +31,10 @@
super(context, preferenceKey, lifecycle, lifecycleOwner);
}
+ public CallsDefaultSubscriptionController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
@Override
protected int getDefaultSubscriptionId() {
int defaultCallSubId = SubscriptionManager.getDefaultVoiceSubscriptionId();
diff --git a/src/com/android/settings/network/telephony/ConvertToEsimPreferenceController.java b/src/com/android/settings/network/telephony/ConvertToEsimPreferenceController.java
index 1acfaf8..c08ea99 100644
--- a/src/com/android/settings/network/telephony/ConvertToEsimPreferenceController.java
+++ b/src/com/android/settings/network/telephony/ConvertToEsimPreferenceController.java
@@ -68,15 +68,19 @@
public ConvertToEsimPreferenceController(Context context, String key, Lifecycle lifecycle,
LifecycleOwner lifecycleOwner, int subId) {
- super(context, key);
+ this(context, key);
mSubId = subId;
- mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mLifecycleOwner = lifecycleOwner;
if (lifecycle != null) {
lifecycle.addObserver(this);
}
}
+ public ConvertToEsimPreferenceController(Context context, String key) {
+ super(context, key);
+ mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
+ }
+
public void init(int subId, SubscriptionInfoEntity subInfoEntity) {
mSubId = subId;
mSubscriptionInfoEntity = subInfoEntity;
diff --git a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
index fa8760c..b058694 100644
--- a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
@@ -64,16 +64,20 @@
public DefaultSubscriptionController(Context context, String preferenceKey, Lifecycle lifecycle,
LifecycleOwner lifecycleOwner) {
+ this(context, preferenceKey);
+ mLifecycleOwner = lifecycleOwner;
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ public DefaultSubscriptionController(Context context, String preferenceKey) {
super(context, preferenceKey);
mManager = context.getSystemService(SubscriptionManager.class);
mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection()
== View.LAYOUT_DIRECTION_RTL;
mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mDataSubscriptionChangedReceiver = new DefaultSubscriptionReceiver(context, this);
- mLifecycleOwner = lifecycleOwner;
- if (lifecycle != null) {
- lifecycle.addObserver(this);
- }
}
/** @return the id of the default subscription for the service, or
diff --git a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
index 2c3ab18..6adc505 100644
--- a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
+++ b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
@@ -73,16 +73,20 @@
public MobileDataPreferenceController(Context context, String key, Lifecycle lifecycle,
LifecycleOwner lifecycleOwner, int subId) {
- super(context, key);
+ this(context, key);
mSubId = subId;
- mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
- mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mLifecycleOwner = lifecycleOwner;
if (lifecycle != null) {
lifecycle.addObserver(this);
}
}
+ public MobileDataPreferenceController(Context context, String key) {
+ super(context, key);
+ mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
+ mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
+ }
+
@Override
public int getAvailabilityStatus(int subId) {
if (Flags.isDualSimOnboardingEnabled()) {
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index ea549ae..517f66a 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -709,12 +709,13 @@
return tm.getNetworkOperatorName();
}
- private static int[] getActiveSubscriptionIdList(Context context) {
+ @VisibleForTesting
+ static int[] getActiveSubscriptionIdList(Context context) {
final SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class).createForAllUserProfiles();
final List<SubscriptionInfo> subInfoList =
- subscriptionManager.getActiveSubscriptionInfoList();
- if (subInfoList == null) {
+ SubscriptionUtil.getActiveSubscriptions(subscriptionManager);
+ if (subInfoList == null || subInfoList.isEmpty()) {
return new int[0];
}
int[] activeSubIds = new int[subInfoList.size()];
diff --git a/src/com/android/settings/network/telephony/RoamingPreferenceController.java b/src/com/android/settings/network/telephony/RoamingPreferenceController.java
index fb8cd51..bf02308 100644
--- a/src/com/android/settings/network/telephony/RoamingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/RoamingPreferenceController.java
@@ -63,16 +63,20 @@
public RoamingPreferenceController(Context context, String key, Lifecycle lifecycle,
LifecycleOwner lifecycleOwner, int subId) {
- super(context, key);
+ this(context, key);
mSubId = subId;
- mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
- mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
mLifecycleOwner = lifecycleOwner;
if (lifecycle != null) {
lifecycle.addObserver(this);
}
}
+ public RoamingPreferenceController(Context context, String key) {
+ super(context, key);
+ mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
+ mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
+ }
+
@Override
public int getAvailabilityStatus() {
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
diff --git a/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java b/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
index c49647d..c35a78c 100644
--- a/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
@@ -35,6 +35,12 @@
.getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support);
}
+ public SmsDefaultSubscriptionController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ mIsAskEverytimeSupported = mContext.getResources()
+ .getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support);
+ }
+
@Override
protected int getDefaultSubscriptionId() {
int defaultSmsSubId = SubscriptionManager.getDefaultSmsSubscriptionId();
diff --git a/src/com/android/settings/notification/modes/ZenModeFragment.java b/src/com/android/settings/notification/modes/ZenModeFragment.java
new file mode 100644
index 0000000..616332e
--- /dev/null
+++ b/src/com/android/settings/notification/modes/ZenModeFragment.java
@@ -0,0 +1,78 @@
+/*
+ * 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.notification.modes;
+
+import android.app.AutomaticZenRule;
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ZenModeFragment extends ZenModeFragmentBase {
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.modes_rule_settings;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ // TODO: fill in with all the elements of this page. Each should be an instance of
+ // {@link AbstractZenModePreferenceController}.
+ List<AbstractPreferenceController> prefControllers = new ArrayList<>();
+ return prefControllers;
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ // Set title for the entire screen
+ ZenMode mode = getMode();
+ AutomaticZenRule azr = getAZR();
+ if (mode == null || azr == null) {
+ return;
+ }
+ getActivity().setTitle(azr.getName());
+
+ // TODO: b/308819292 - implement the real screen!
+ final PreferenceScreen screen = getPreferenceScreen();
+ if (screen == null) {
+ return;
+ }
+
+ Preference tmpPref = screen.findPreference("zen_mode_test");
+ if (tmpPref == null) {
+ return;
+ }
+ tmpPref.setTitle(azr.getTriggerDescription());
+ tmpPref.setSummary("active?: " + mode.isActive());
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ // TODO: b/332937635 - make this the correct metrics category
+ return SettingsEnums.NOTIFICATION_ZEN_MODE_AUTOMATION;
+ }
+}
diff --git a/src/com/android/settings/notification/modes/ZenModeListPreference.java b/src/com/android/settings/notification/modes/ZenModeListPreference.java
new file mode 100644
index 0000000..cb04561
--- /dev/null
+++ b/src/com/android/settings/notification/modes/ZenModeListPreference.java
@@ -0,0 +1,65 @@
+/*
+ * 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.notification.modes;
+
+import static com.android.settings.notification.modes.ZenModeFragmentBase.MODE_ID;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.os.Bundle;
+
+import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.notification.zen.ZenModeSettings;
+import com.android.settingslib.RestrictedPreference;
+
+/**
+ * Preference representing a single mode item on the modes aggregator page. Clicking on this
+ * preference leads to an individual mode's configuration page.
+ */
+public class ZenModeListPreference extends RestrictedPreference {
+ final Context mContext;
+ ZenMode mZenMode;
+
+ ZenModeListPreference(Context context, ZenMode zenMode) {
+ super(context);
+ mContext = context;
+ mZenMode = zenMode;
+ setTitle(mZenMode.getRule().getName());
+ setSummary((mZenMode.isActive() ? "ACTIVE" : "inactive") + ": "
+ + mZenMode.getRule().getTriggerDescription());
+ }
+
+ @Override
+ public void onClick() {
+ // TODO: b/322373473 - This implementation is a hack that just leads to the old DND page
+ // for manual only; remove this in favor of the real implementation.
+ if (mZenMode.isManualDnd()) {
+ new SubSettingLauncher(mContext)
+ .setDestination(ZenModeSettings.class.getName())
+ .setSourceMetricsCategory(SettingsEnums.NOTIFICATION_ZEN_MODE)
+ .launch();
+ } else {
+ Bundle bundle = new Bundle();
+ bundle.putString(MODE_ID, mZenMode.getId());
+ new SubSettingLauncher(mContext)
+ .setDestination(ZenModeFragment.class.getName())
+ .setArguments(bundle)
+ .setSourceMetricsCategory(SettingsEnums.NOTIFICATION_ZEN_MODE_AUTOMATION)
+ .launch();
+ }
+
+ }
+}
diff --git a/src/com/android/settings/notification/modes/ZenModesListFragment.java b/src/com/android/settings/notification/modes/ZenModesListFragment.java
new file mode 100644
index 0000000..040621e
--- /dev/null
+++ b/src/com/android/settings/notification/modes/ZenModesListFragment.java
@@ -0,0 +1,113 @@
+/*
+ * 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.notification.modes;
+
+import android.app.NotificationManager;
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.service.notification.ConditionProviderService;
+
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+
+import com.android.settings.R;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.utils.ManagedServiceSettings;
+import com.android.settings.utils.ZenServiceListing;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@SearchIndexable
+public class ZenModesListFragment extends ZenModesFragmentBase {
+ protected final ManagedServiceSettings.Config CONFIG = getConditionProviderConfig();
+
+ @Override
+ protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ ZenServiceListing serviceListing = new ZenServiceListing(getContext(), CONFIG);
+ serviceListing.reloadApprovedServices();
+ return buildPreferenceControllers(context, this, serviceListing);
+ }
+
+ private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
+ @Nullable Fragment parent, @Nullable ZenServiceListing serviceListing) {
+ // We need to redefine ZenModesBackend here even though mBackend exists so that this method
+ // can be static; it must be static to be able to be used in SEARCH_INDEX_DATA_PROVIDER.
+ ZenModesBackend backend = ZenModesBackend.getInstance(context);
+ List<AbstractPreferenceController> controllers = new ArrayList<>();
+ controllers.add(new ZenModesListPreferenceController(
+ context, parent, backend));
+
+ // TODO: b/326442408 - Add controller for "Add Mode" preference/flow, which is what uses
+ // the ZenServiceListing.
+ return controllers;
+ }
+
+ @Override
+ protected void updateZenModeState() {
+ // TODO: b/322373473 -- update any overall description of modes state here if necessary.
+ // Note the preferences linking to individual rules do not need to be updated, as
+ // updateState() is called on all preference controllers whenever the page is resumed.
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.modes_list_settings;
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ // TODO: b/332937635 - add new & set metrics categories correctly
+ return SettingsEnums.NOTIFICATION_ZEN_MODE_AUTOMATION;
+ }
+
+ protected static ManagedServiceSettings.Config getConditionProviderConfig() {
+ return new ManagedServiceSettings.Config.Builder()
+ .setTag(TAG)
+ .setIntentAction(ConditionProviderService.SERVICE_INTERFACE)
+ .setConfigurationIntentAction(NotificationManager.ACTION_AUTOMATIC_ZEN_RULE)
+ .setPermission(android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE)
+ .setNoun("condition provider")
+ .build();
+ }
+
+ // TODO: b/322373473 - Add 3-dot options menu with capability to delete modes.
+
+ /**
+ * For Search.
+ */
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider(R.xml.modes_list_settings) {
+
+ @Override
+ public List<String> getNonIndexableKeys(Context context) {
+ final List<String> keys = super.getNonIndexableKeys(context);
+ // TODO: b/332937523 - determine if this should be removed once the preference
+ // controller adds dynamic data to index
+ keys.add(ZenModesListPreferenceController.KEY);
+ return keys;
+ }
+
+ @Override
+ public List<AbstractPreferenceController> createPreferenceControllers(
+ Context context) {
+ return buildPreferenceControllers(context, null, null);
+ }
+ };
+}
diff --git a/src/com/android/settings/notification/modes/ZenModesListPreferenceController.java b/src/com/android/settings/notification/modes/ZenModesListPreferenceController.java
new file mode 100644
index 0000000..53336c8
--- /dev/null
+++ b/src/com/android/settings/notification/modes/ZenModesListPreferenceController.java
@@ -0,0 +1,80 @@
+/*
+ * 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.notification.modes;
+
+import android.app.Flags;
+import android.content.Context;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+
+import com.android.settingslib.core.AbstractPreferenceController;
+
+/**
+ * Controller for the PreferenceCategory on the modes aggregator page ({@link ZenModesListFragment})
+ * containing links to each individual mode. This is a central controller that populates and updates
+ * all the preferences that then lead to a mode configuration page.
+ */
+public class ZenModesListPreferenceController extends AbstractPreferenceController {
+ protected static final String KEY = "zen_modes_list";
+
+ @Nullable
+ protected Fragment mParent;
+ protected ZenModesBackend mBackend;
+
+ public ZenModesListPreferenceController(Context context, @Nullable Fragment parent,
+ @NonNull ZenModesBackend backend) {
+ super(context);
+ mParent = parent;
+ mBackend = backend;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return Flags.modesUi();
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ if (mBackend == null) {
+ return;
+ }
+
+ // The preference given us is a PreferenceCategory; create one preference inside the
+ // category for each rule that exists.
+ PreferenceCategory category = (PreferenceCategory) preference;
+
+ // TODO: b/322373473 - This is not the right way to replace these preferences; we should
+ // follow something similar to what
+ // ZenModeAutomaticRulesPreferenceController does to change rules
+ // only as necessary and update them.
+ category.removeAll();
+
+ for (ZenMode mode : mBackend.getModes()) {
+ Preference pref = new ZenModeListPreference(mContext, mode);
+ category.addPreference(pref);
+ }
+ }
+
+}
diff --git a/src/com/android/settings/notification/zen/ZenModePreferenceController.java b/src/com/android/settings/notification/zen/ZenModePreferenceController.java
index 24cf158..7c36d80 100644
--- a/src/com/android/settings/notification/zen/ZenModePreferenceController.java
+++ b/src/com/android/settings/notification/zen/ZenModePreferenceController.java
@@ -16,6 +16,7 @@
package com.android.settings.notification.zen;
+import android.app.Flags;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -27,7 +28,9 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.notification.modes.ZenModesListFragment;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
@@ -46,7 +49,9 @@
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- mSettingObserver = new SettingObserver(screen.findPreference(getPreferenceKey()));
+ Preference preference = screen.findPreference(getPreferenceKey());
+ mSettingObserver = new SettingObserver(preference);
+ maybeSetTitleAndDestination(preference);
}
@Override
@@ -71,11 +76,22 @@
@Override
public void updateState(Preference preference) {
super.updateState(preference);
+ maybeSetTitleAndDestination(preference);
if (preference.isEnabled()) {
preference.setSummary(mSummaryBuilder.getSoundSummary());
}
}
+ // Only when modes_ui is active: change title & target fragment.
+ private void maybeSetTitleAndDestination(Preference preference) {
+ if (!Flags.modesUi()) {
+ return;
+ }
+
+ preference.setTitle(R.string.zen_modes_list_title);
+ preference.setFragment(ZenModesListFragment.class.getCanonicalName());
+ }
+
class SettingObserver extends ContentObserver {
private final Uri ZEN_MODE_URI = Settings.Global.getUriFor(Settings.Global.ZEN_MODE);
private final Uri ZEN_MODE_CONFIG_ETAG_URI = Settings.Global.getUriFor(
diff --git a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
index 38f724a..42e8544 100644
--- a/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
+++ b/src/com/android/settings/privatespace/PrivateSpaceMaintainer.java
@@ -19,7 +19,7 @@
import static android.os.UserManager.USER_TYPE_PROFILE_PRIVATE;
import static android.provider.Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT;
import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK;
-import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_AFTER_DEVICE_RESTART;
+import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_ON_DEVICE_LOCK;
import static android.provider.Settings.Secure.SKIP_FIRST_USE_HINTS;
import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
@@ -69,7 +69,7 @@
/** Default value for private space auto lock settings. */
@Settings.Secure.PrivateSpaceAutoLockOption
public static final int PRIVATE_SPACE_AUTO_LOCK_DEFAULT_VAL =
- PRIVATE_SPACE_AUTO_LOCK_AFTER_DEVICE_RESTART;
+ PRIVATE_SPACE_AUTO_LOCK_ON_DEVICE_LOCK;
/** Default value for the hide private space sensitive notifications on lockscreen. */
public static final int HIDE_PRIVATE_SPACE_SENSITIVE_NOTIFICATIONS_DISABLED_VAL = 0;
diff --git a/src/com/android/settings/system/DeviceDiagnosticsPreferenceController.kt b/src/com/android/settings/system/DeviceDiagnosticsPreferenceController.kt
new file mode 100644
index 0000000..695bb5b
--- /dev/null
+++ b/src/com/android/settings/system/DeviceDiagnosticsPreferenceController.kt
@@ -0,0 +1,65 @@
+/*
+ * 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.system
+
+import android.content.Context
+import android.content.Intent
+import android.content.pm.ResolveInfo
+
+import androidx.preference.Preference
+
+import com.android.settings.R
+import com.android.settings.core.BasePreferenceController
+import com.android.settings.flags.Flags
+
+class DeviceDiagnosticsPreferenceController(context: Context, preferenceKey: String) :
+ BasePreferenceController(context, preferenceKey) {
+
+ override fun getAvailabilityStatus(): Int {
+ if (!Flags.enableDeviceDiagnosticsInSettings()) {
+ return UNSUPPORTED_ON_DEVICE
+ }
+ if (getIntent() == null) {
+ return UNSUPPORTED_ON_DEVICE
+ }
+ return AVAILABLE
+ }
+
+ override fun handlePreferenceTreeClick(preference: Preference): Boolean {
+ if (preferenceKey != preference.key) {
+ return false
+ }
+
+ val intent = getIntent()
+ if (intent == null) {
+ return false
+ }
+
+ preference.getContext().startActivity(intent)
+ return true
+ }
+
+ private fun getIntent(): Intent? {
+ val intent = Intent(Intent.ACTION_MAIN)
+
+ val packageName = mContext.getResources().getString(
+ R.string.config_device_diagnostics_package_name)
+ intent.setPackage(packageName)
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ return intent
+ }
+}
diff --git a/src/com/android/settings/users/MultiUserSwitchBarController.java b/src/com/android/settings/users/MultiUserSwitchBarController.java
index 33651c3..f57b795 100644
--- a/src/com/android/settings/users/MultiUserSwitchBarController.java
+++ b/src/com/android/settings/users/MultiUserSwitchBarController.java
@@ -63,8 +63,7 @@
.checkIfRestrictionEnforced(mContext, UserManager.DISALLOW_ADD_USER,
UserHandle.myUserId()));
} else {
- mSwitchBar.setEnabled(!mUserCapabilities.mDisallowSwitchUser
- && !mUserCapabilities.mIsGuest && mUserCapabilities.isAdmin());
+ mSwitchBar.setEnabled(mUserCapabilities.mIsMain);
}
mSwitchBar.setListener(this);
}
diff --git a/src/com/android/settings/users/UserCapabilities.java b/src/com/android/settings/users/UserCapabilities.java
index cf0e10b..590cb0c 100644
--- a/src/com/android/settings/users/UserCapabilities.java
+++ b/src/com/android/settings/users/UserCapabilities.java
@@ -32,6 +32,7 @@
boolean mEnabled = true;
boolean mCanAddUser = true;
boolean mCanAddRestrictedProfile;
+ boolean mIsMain;
boolean mIsAdmin;
boolean mIsGuest;
boolean mIsEphemeral;
@@ -57,6 +58,7 @@
final UserInfo myUserInfo = userManager.getUserInfo(UserHandle.myUserId());
caps.mIsGuest = myUserInfo.isGuest();
caps.mIsAdmin = myUserInfo.isAdmin();
+ caps.mIsMain = myUserInfo.isMain();
caps.mIsEphemeral = myUserInfo.isEphemeral();
DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
Context.DEVICE_POLICY_SERVICE);
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 083608d..bf21c9b 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -287,7 +287,7 @@
final SettingsActivity activity = (SettingsActivity) getActivity();
final SettingsMainSwitchBar switchBar = activity.getSwitchBar();
switchBar.setTitle(getContext().getString(R.string.multiple_users_main_switch_title));
- if (isCurrentUserAdmin()) {
+ if (!mUserCaps.mIsGuest) {
switchBar.show();
} else {
switchBar.hide();
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardTest.java
index 78c8880..2ae5984 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizardTest.java
@@ -23,6 +23,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -45,7 +46,10 @@
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
+import com.android.settings.display.AutoBrightnessPreferenceController;
+import com.android.settings.display.BrightnessLevelPreferenceController;
import com.android.settingslib.RestrictedPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupdesign.GlifPreferenceLayout;
@@ -88,7 +92,7 @@
private GlifPreferenceLayout mGlifLayoutView;
@Mock
private FooterBarMixin mFooterBarMixin;
- private AccessibilitySettingsForSetupWizard mFragment;
+ private TestAccessibilitySettingsForSetupWizard mFragment;
@Before
public void setUp() {
@@ -141,6 +145,19 @@
assertThat(mFragment.mSelectToSpeakPreference.getKey()).isNull();
}
+ @Test
+ public void createPreferenceControllers_brightnessPreferencesControllersAreCreated() {
+ mFragment.onAttach(mContext);
+
+ List<AbstractPreferenceController> controllers =
+ mFragment.createPreferenceControllers(mContext);
+
+ assertTrue(controllers.stream().anyMatch(
+ controller -> controller instanceof BrightnessLevelPreferenceController));
+ assertTrue(controllers.stream().anyMatch(
+ controller -> controller instanceof AutoBrightnessPreferenceController));
+ }
+
private void addEnabledServiceInfo(ComponentName componentName, boolean isAccessibilityTool) {
final AccessibilityServiceInfo a11yServiceInfo = mock(AccessibilityServiceInfo.class);
when(a11yServiceInfo.getComponentName()).thenReturn(componentName);
@@ -170,12 +187,14 @@
private final Context mContext;
private final PreferenceManager mPreferenceManager;
+ final PreferenceScreen mPreferenceScreen;
TestAccessibilitySettingsForSetupWizard(Context context) {
super();
mContext = context;
mPreferenceManager = new PreferenceManager(context);
- mPreferenceManager.setPreferences(mPreferenceManager.createPreferenceScreen(context));
+ mPreferenceScreen = spy(mPreferenceManager.createPreferenceScreen(context));
+ mPreferenceManager.setPreferences(mPreferenceScreen);
mDisplayMagnificationPreference = new Preference(context);
mScreenReaderPreference = new RestrictedPreference(context);
mSelectToSpeakPreference = new RestrictedPreference(context);
diff --git a/tests/robotests/src/com/android/settings/accessibility/AutoBrightnessPreferenceFragmentForSetupWizardTest.java b/tests/robotests/src/com/android/settings/accessibility/AutoBrightnessPreferenceFragmentForSetupWizardTest.java
new file mode 100644
index 0000000..1e6e068
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/AutoBrightnessPreferenceFragmentForSetupWizardTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.accessibility;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import androidx.lifecycle.LifecycleOwner;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
+
+import com.google.android.setupcompat.template.FooterBarMixin;
+import com.google.android.setupdesign.GlifPreferenceLayout;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+import org.robolectric.RobolectricTestRunner;
+
+/** Tests for {@link AutoBrightnessPreferenceFragmentForSetupWizard}. */
+@RunWith(RobolectricTestRunner.class)
+public class AutoBrightnessPreferenceFragmentForSetupWizardTest {
+
+ @Rule
+ public final MockitoRule mMockito = MockitoJUnit.rule();
+
+ @Spy
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ @Mock
+ private GlifPreferenceLayout mGlifLayoutView;
+ @Mock
+ private FooterBarMixin mFooterBarMixin;
+ private AutoBrightnessPreferenceFragmentForSetupWizard mFragment;
+
+ @Before
+ public void setUp() {
+ mFragment = spy(new AutoBrightnessPreferenceFragmentForSetupWizard());
+ doReturn(mock(LifecycleOwner.class)).when(mFragment).getViewLifecycleOwner();
+ doReturn(mContext).when(mFragment).getContext();
+ when(mGlifLayoutView.getMixin(eq(FooterBarMixin.class))).thenReturn(mFooterBarMixin);
+ }
+
+ @Test
+ public void setHeaderText_onViewCreated_verifyAction() {
+ final String title = "title";
+ doReturn(title).when(mContext).getString(R.string.auto_brightness_title);
+
+ mFragment.onViewCreated(mGlifLayoutView, null);
+
+ verify(mGlifLayoutView).setHeaderText(title);
+ }
+
+ @Test
+ public void getMetricsCategory_returnsCorrectCategory() {
+ assertThat(mFragment.getMetricsCategory()).isEqualTo(
+ SettingsEnums.SUW_ACCESSIBILITY_AUTO_BRIGHTNESS);
+ }
+
+ @Test
+ public void onViewCreated_verifyAction() {
+ mFragment.onViewCreated(mGlifLayoutView, null);
+
+ verify(mFooterBarMixin).setPrimaryButton(any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java
index 0229173..13cd86d 100644
--- a/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java
@@ -21,18 +21,24 @@
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import android.content.ContentResolver;
import android.content.Context;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import com.android.settings.R;
+import com.android.settings.accessibility.Flags;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
@@ -44,6 +50,9 @@
@Config(shadows = {SettingsShadowResources.class})
public class AutoBrightnessPreferenceControllerTest {
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
private static final String PREFERENCE_KEY = "auto_brightness";
private Context mContext;
@@ -121,7 +130,7 @@
}
@Test
- public void getAvailabilityStatus_configTrueSet_shouldReturnAvailableUnsearchable() {
+ public void getAvailabilityStatusNotInSUW_configTrueSet_shouldReturnAvailableUnsearchable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_automatic_brightness_available, true);
@@ -129,6 +138,27 @@
}
@Test
+ @EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
+ public void getAvailabilityStatusInSUW_configTrueAndFlagOn_shouldReturnAvailableUnsearchable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_automatic_brightness_available, true);
+ mController.setInSetupWizard(true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
+ public void
+ getAvailabilityStatusInSUW_configTrueAndFlagOff_shouldReturnConditionallyUnavailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_automatic_brightness_available, true);
+ mController.setInSetupWizard(true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
public void getAvailabilityStatus_configFalseSet_shouldReturnUnsupportedOnDevice() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_automatic_brightness_available, false);
diff --git a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
index bbc9cf3..009ca95 100644
--- a/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/BrightnessLevelPreferenceControllerTest.java
@@ -33,16 +33,22 @@
import android.content.Intent;
import android.hardware.display.BrightnessInfo;
import android.os.PowerManager;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings.System;
import android.view.Display;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.settings.R;
+import com.android.settings.accessibility.Flags;
import com.android.settings.core.SettingsBaseActivity;
import com.android.settingslib.transition.SettingsTransitionHelper;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -58,6 +64,9 @@
@RunWith(RobolectricTestRunner.class)
public class BrightnessLevelPreferenceControllerTest {
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
@Mock
private PowerManager mPowerManager;
@Mock
@@ -90,11 +99,25 @@
}
@Test
- public void isAvailable_shouldAlwaysReturnTrue() {
+ public void isAvailable_shouldAlwaysReturnTrueWhenNotInSetupWizard() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
+ @EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
+ public void isAvailable_inSetupWizardAndFlagOn_shouldReturnTrue() {
+ mController.setInSetupWizard(true);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
+ public void isAvailable_inSetupWizardAndFlagOff_shouldReturnFalse() {
+ mController.setInSetupWizard(true);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void onStart_shouldRegisterObserver() {
BrightnessLevelPreferenceController controller =
new BrightnessLevelPreferenceController(mContext, null);
@@ -169,13 +192,14 @@
final BrightnessLevelPreferenceController controller =
new BrightnessLevelPreferenceController(activity, null);
final ShadowActivity shadowActivity = shadowOf(activity);
- when(mPreference.getKey()).thenReturn("brightness");
+
+ String preferenceKey = mContext.getString(R.string.preference_key_brightness_level);
+ when(mPreference.getKey()).thenReturn(preferenceKey);
controller.handlePreferenceTreeClick(mPreference);
final Intent intent = shadowActivity.getNextStartedActivity();
assertThat(intent.getIntExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE, 0))
.isEqualTo(SettingsTransitionHelper.TransitionType.TRANSITION_NONE);
-
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
index bc6dadc..c987bcd 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
@@ -35,7 +35,6 @@
import androidx.preference.PreferenceScreen;
-import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
@@ -286,8 +285,9 @@
/* isFastCharging= */ true,
/* isChargingStringV2= */ true);
batteryInfo.pluggedStatus = BatteryManager.BATTERY_PLUGGED_WIRELESS;
- when(mFactory.batterySettingsFeatureProvider.getWirelessChargingLabel(eq(mContext),
- any(BatteryInfo.class))).thenReturn(label);
+ when(mFactory.batterySettingsFeatureProvider.getWirelessChargingLabel(
+ eq(mContext), any(BatteryInfo.class)))
+ .thenReturn(label);
mController.updateBatteryStatus(/* label= */ null, batteryInfo);
@@ -326,14 +326,64 @@
verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
}
+ @Test
+ public void updateBatteryStatus_chargingOptimizationMode_remainingLabel() {
+ var batteryInfo =
+ arrangeUpdateBatteryStatusTestWithRemainingLabel(
+ /* remainingLabel= */ "Expected remaining label",
+ /* statusLabel= */ "Fast Charging",
+ /* isFastCharging= */ true,
+ /* isChargingStringV2= */ true);
+ var expectedChargingString = batteryInfo.remainingLabel;
+ when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
+ .thenReturn(true);
+
+ mController.updateBatteryStatus(/* label= */ null, batteryInfo);
+
+ verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
+ }
+
+ @Test
+ public void updateBatteryStatus_chargingOptimizationModeNoRemainingLabel_statusLabel() {
+ var batteryInfo =
+ arrangeUpdateBatteryStatusTestWithRemainingLabel(
+ /* remainingLabel= */ null,
+ /* statusLabel= */ "Fast Charging",
+ /* isFastCharging= */ true,
+ /* isChargingStringV2= */ true);
+ var expectedChargingString = batteryInfo.statusLabel;
+ when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
+ .thenReturn(true);
+
+ mController.updateBatteryStatus(/* label= */ null, batteryInfo);
+
+ verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
+ }
+
+ @Test
+ public void updateBatteryStatus_notChargingOptimizationMode_statusWithRemainingLabel() {
+ var batteryInfo =
+ arrangeUpdateBatteryStatusTestWithRemainingLabel(
+ /* remainingLabel= */ "Full by 1:30 PM",
+ /* statusLabel= */ "Fast Charging",
+ /* isFastCharging= */ true,
+ /* isChargingStringV2= */ true);
+ var expectedChargingString = batteryInfo.statusLabel + " • " + batteryInfo.remainingLabel;
+ when(mFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
+ .thenReturn(false);
+
+ mController.updateBatteryStatus(/* label= */ null, batteryInfo);
+
+ verify(mBatteryUsageProgressBarPref).setBottomSummary(expectedChargingString);
+ }
+
private BatteryInfo arrangeUpdateBatteryStatusTestWithRemainingLabel(
String remainingLabel,
String statusLabel,
boolean isFastCharging,
boolean isChargingStringV2) {
SystemProperties.set(
- BatteryUtils.PROPERTY_CHARGING_STRING_V2_KEY,
- String.valueOf(isChargingStringV2));
+ BatteryUtils.PROPERTY_CHARGING_STRING_V2_KEY, String.valueOf(isChargingStringV2));
mBatteryInfo.isBatteryDefender = false;
mBatteryInfo.remainingLabel = remainingLabel;
mBatteryInfo.statusLabel = statusLabel;
@@ -389,8 +439,11 @@
mController.updateHeaderPreference(mBatteryInfo);
- verify(mBatteryUsageProgressBarPref).setBottomSummary(mContext.getString(
- com.android.settingslib.R.string.battery_info_status_charging_on_hold));
+ verify(mBatteryUsageProgressBarPref)
+ .setBottomSummary(
+ mContext.getString(
+ com.android.settingslib.R.string
+ .battery_info_status_charging_on_hold));
}
@Test
@@ -429,11 +482,10 @@
}
@Test
- public void displayPreference_init_showLoading() {
+ public void displayPreference_init_showEmptySpace() {
mController.displayPreference(mPreferenceScreen);
- verify(mBatteryUsageProgressBarPref)
- .setBottomSummary(mContext.getString(R.string.settings_license_activity_loading));
+ verify(mBatteryUsageProgressBarPref).setBottomSummary(" ");
}
private CharSequence formatBatteryPercentageText() {
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
index a1081f4..7bafc6d 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryInfoTest.java
@@ -724,15 +724,15 @@
Intent batteryIntent =
createIntentForGetBatteryInfoTest(
ChargingType.WIRED, ChargingSpeed.REGULAR, /* batteryLevel= */ 65);
- var expectedRemainingLabel = "Done charging by";
+ var expectedRemainingLabel = "Expected remaining label";
var expectedChargeLabel = "65% - " + expectedRemainingLabel;
when(mFeatureFactory.batterySettingsFeatureProvider.isChargingOptimizationMode(mContext))
.thenReturn(true);
when(mFeatureFactory.batterySettingsFeatureProvider.getChargingOptimizationRemainingLabel(
- eq(mContext), anyLong(), anyLong()))
+ eq(mContext), anyInt(), anyInt(), anyLong(), anyLong()))
.thenReturn(expectedRemainingLabel);
when(mFeatureFactory.batterySettingsFeatureProvider.getChargingOptimizationChargeLabel(
- eq(mContext), anyString(), anyLong(), anyLong()))
+ eq(mContext), anyInt(), anyString(), anyLong(), anyLong()))
.thenReturn(expectedChargeLabel);
var expectedStatusLabel = "Charging";
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatterySettingsFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatterySettingsFeatureProviderImplTest.java
index c55a121..9f04892 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatterySettingsFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatterySettingsFeatureProviderImplTest.java
@@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
+import android.os.BatteryManager;
import androidx.test.core.app.ApplicationProvider;
@@ -87,12 +88,15 @@
@Test
public void getChargingOptimizationRemainingLabel_default_returnNull() {
- assertThat(mImpl.getChargingOptimizationRemainingLabel(mContext, 1000L, 1000L)).isNull();
+ assertThat(
+ mImpl.getChargingOptimizationRemainingLabel(
+ mContext, 75, BatteryManager.BATTERY_PLUGGED_AC, 1000L, 1000L))
+ .isNull();
}
@Test
public void getChargingOptimizationChargeLabel_default_returnNull() {
- assertThat(mImpl.getChargingOptimizationChargeLabel(mContext, "70%", 1000L, 1000L))
+ assertThat(mImpl.getChargingOptimizationChargeLabel(mContext, 70, "70%", 1000L, 1000L))
.isNull();
}
}
diff --git a/tests/robotests/src/com/android/settings/notification/zen/ZenModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/zen/ZenModePreferenceControllerTest.java
index c2abbcd..f611c9b 100644
--- a/tests/robotests/src/com/android/settings/notification/zen/ZenModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/zen/ZenModePreferenceControllerTest.java
@@ -16,10 +16,13 @@
package com.android.settings.notification.zen;
+import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
+
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
@@ -27,13 +30,20 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.Flags;
import android.app.NotificationManager;
import android.app.NotificationManager.Policy;
import android.content.Context;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
import androidx.preference.Preference;
+import com.android.settings.notification.modes.ZenModesListFragment;
+
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -46,6 +56,9 @@
@RunWith(RobolectricTestRunner.class)
public class ZenModePreferenceControllerTest {
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(DEVICE_DEFAULT);
+
@Mock
private Preference mPreference;
@Mock
@@ -96,4 +109,20 @@
verify(mPreference, never()).setSummary(anyString());
}
+
+ @Test
+ @EnableFlags(Flags.FLAG_MODES_UI)
+ public void updateState_modesUi_resetsTitleAndFragment() {
+ mController.updateState(mPreference);
+ verify(mPreference).setTitle(anyInt()); // Resource IDs are ints
+ verify(mPreference).setFragment(ZenModesListFragment.class.getCanonicalName());
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_MODES_UI)
+ public void updateState_noModesUi_doesNotSetTitleAndFragment() {
+ mController.updateState(mPreference);
+ verify(mPreference, never()).setTitle(anyInt());
+ verify(mPreference, never()).setFragment(anyString());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java b/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java
index 4bddcd1..915231f 100644
--- a/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java
+++ b/tests/robotests/src/com/android/settings/testutils/BatteryTestUtils.java
@@ -228,6 +228,8 @@
/** Create a power anomaly event proto of adaptive brightness. */
public static PowerAnomalyEvent createAdaptiveBrightnessAnomalyEvent(boolean changeSettings) {
+ // TODO: migrate "auto_brightness_entry" to use R.string.preference_key_auto_brightness
+ // if we can access the Context here. (b/338314718)
WarningBannerInfo.Builder warningBannerInfoBuilder =
WarningBannerInfo.newBuilder()
.setMainButtonDestination(DisplaySettings.class.getName())
diff --git a/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java
index 1cfb3f6..bfab257 100644
--- a/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/users/MultiUserSwitchBarControllerTest.java
@@ -22,6 +22,7 @@
import static org.mockito.Mockito.verify;
import android.content.Context;
+import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
@@ -79,4 +80,26 @@
verify(mSwitchWidgetController, never()).setDisabledByAdmin(any());
}
+
+ @Test
+ public void onStart_userIsNotMain_shouldNotBeEnabled() {
+ mUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()),
+ UserManager.DISALLOW_USER_SWITCH, false);
+ mUserManager.addUser(10, "Test", UserInfo.FLAG_ADMIN);
+ mUserManager.switchUser(10);
+ new MultiUserSwitchBarController(mContext, mSwitchWidgetController, null);
+
+ verify(mSwitchWidgetController, never()).setDisabledByAdmin(any());
+ verify(mSwitchWidgetController).setEnabled(false);
+ }
+
+ @Test
+ public void onStart_userIsMain_shouldBeEnabled() {
+ mUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()),
+ UserManager.DISALLOW_USER_SWITCH, false);
+ new MultiUserSwitchBarController(mContext, mSwitchWidgetController, null);
+
+ verify(mSwitchWidgetController, never()).setDisabledByAdmin(any());
+ verify(mSwitchWidgetController).setEnabled(true);
+ }
}
diff --git a/tests/unit/src/com/android/settings/datausage/DataUsageInfoControllerTest.java b/tests/unit/src/com/android/settings/datausage/DataUsageInfoControllerTest.java
index cb5860a..4193b0a 100644
--- a/tests/unit/src/com/android/settings/datausage/DataUsageInfoControllerTest.java
+++ b/tests/unit/src/com/android/settings/datausage/DataUsageInfoControllerTest.java
@@ -23,10 +23,12 @@
import com.android.settingslib.net.DataUsageController.DataUsageInfo;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
+@Ignore("b/340657656")
public class DataUsageInfoControllerTest {
private static final int ZERO = 0;
diff --git a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressFeminineControllerTest.java b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressFeminineControllerTest.java
index 246fad6..215e58f 100644
--- a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressFeminineControllerTest.java
+++ b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressFeminineControllerTest.java
@@ -18,8 +18,6 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.spy;
-
import android.app.GrammaticalInflectionManager;
import android.content.Context;
import android.content.res.Configuration;
@@ -34,7 +32,6 @@
import com.android.settings.widget.TickButtonPreference;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
@@ -62,7 +59,7 @@
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mContext = spy(ApplicationProvider.getApplicationContext());
+ mContext = ApplicationProvider.getApplicationContext();
if (Looper.myLooper() == null) {
Looper.prepare();
@@ -93,7 +90,6 @@
}
@Test
- @Ignore("b/339543490")
public void displayPreference_setGrammaticalGenderIsFeminine_FeminineIsSelected() {
TickButtonPreference selectedPreference =
(TickButtonPreference) mPreferenceScreen.getPreference(2);
diff --git a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressMasculineControllerTest.java b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressMasculineControllerTest.java
index f5ed395..b4c8893 100644
--- a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressMasculineControllerTest.java
+++ b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressMasculineControllerTest.java
@@ -18,8 +18,6 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.spy;
-
import android.app.GrammaticalInflectionManager;
import android.content.Context;
import android.content.res.Configuration;
@@ -34,7 +32,6 @@
import com.android.settings.widget.TickButtonPreference;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
@@ -62,7 +59,7 @@
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mContext = spy(ApplicationProvider.getApplicationContext());
+ mContext = ApplicationProvider.getApplicationContext();
if (Looper.myLooper() == null) {
Looper.prepare();
@@ -93,7 +90,6 @@
}
@Test
- @Ignore("b/339543490")
public void displayPreference_setGrammaticalGenderIsMasculine_MasculineIsSelected() {
TickButtonPreference selectedPreference =
(TickButtonPreference) mPreferenceScreen.getPreference(3);
diff --git a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressNeutralControllerTest.java b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressNeutralControllerTest.java
index 0e53198..76aed0a 100644
--- a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressNeutralControllerTest.java
+++ b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressNeutralControllerTest.java
@@ -18,8 +18,6 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.spy;
-
import android.app.GrammaticalInflectionManager;
import android.content.Context;
import android.content.res.Configuration;
@@ -34,7 +32,6 @@
import com.android.settings.widget.TickButtonPreference;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
@@ -62,7 +59,7 @@
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mContext = spy(ApplicationProvider.getApplicationContext());
+ mContext = ApplicationProvider.getApplicationContext();
if (Looper.myLooper() == null) {
Looper.prepare();
@@ -93,7 +90,6 @@
}
@Test
- @Ignore("b/339543490")
public void displayPreference_setGrammaticalGenderIsNotSpecified_NeutralIsSelected() {
TickButtonPreference selectedPreference =
(TickButtonPreference) mPreferenceScreen.getPreference(4);
diff --git a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressNotSpecifiedControllerTest.java b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressNotSpecifiedControllerTest.java
index 96bac08..0f51b7d 100644
--- a/tests/unit/src/com/android/settings/localepicker/TermsOfAddressNotSpecifiedControllerTest.java
+++ b/tests/unit/src/com/android/settings/localepicker/TermsOfAddressNotSpecifiedControllerTest.java
@@ -18,8 +18,6 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.spy;
-
import android.app.GrammaticalInflectionManager;
import android.content.Context;
import android.content.res.Configuration;
@@ -34,7 +32,6 @@
import com.android.settings.widget.TickButtonPreference;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
@@ -62,7 +59,7 @@
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mContext = spy(ApplicationProvider.getApplicationContext());
+ mContext = ApplicationProvider.getApplicationContext();
if (Looper.myLooper() == null) {
Looper.prepare();
@@ -93,7 +90,6 @@
}
@Test
- @Ignore("b/339543490")
public void displayPreference_setGrammaticalGenderIsNotSpecified_NotSpecifiedIsSelected() {
TickButtonPreference selectedPreference =
(TickButtonPreference) mPreferenceScreen.getPreference(1);
diff --git a/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java b/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
index a6f8f2d..5f887de 100644
--- a/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
+++ b/tests/unit/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
@@ -244,6 +244,33 @@
}
@Test
+ public void getActiveSubscriptionIdList_nonActive_returnEmptyArray() {
+ int[] expectedList = new int[0];
+ when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(new ArrayList<>());
+
+ assertThat(MobileNetworkUtils.getActiveSubscriptionIdList(mContext))
+ .isEqualTo(expectedList);
+ }
+
+ @Test
+ public void getActiveSubscriptionIdList_normalCaseTwoActiveSims_returnValidSubId() {
+ int[] expectedList = {SUB_ID_1, SUB_ID_2};
+
+ assertThat(MobileNetworkUtils.getActiveSubscriptionIdList(mContext))
+ .isEqualTo(expectedList);
+ }
+
+ @Test
+ public void getActiveSubscriptionIdList_TwoActiveSimsAndOneIsNtn_returnOneSubId() {
+ int[] expectedList = {SUB_ID_2};
+ when(mSubscriptionInfo1.isEmbedded()).thenReturn(true);
+ when(mSubscriptionInfo1.isOnlyNonTerrestrialNetwork()).thenReturn(true);
+
+ assertThat(MobileNetworkUtils.getActiveSubscriptionIdList(mContext))
+ .isEqualTo(expectedList);
+ }
+
+ @Test
public void shouldDisplayNetworkSelectOptions_HideCarrierNetwork_returnFalse() {
mCarrierConfig.putBoolean(CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL,
true);
diff --git a/tests/unit/src/com/android/settings/privatespace/autolock/AutoLockPreferenceControllerTest.java b/tests/unit/src/com/android/settings/privatespace/autolock/AutoLockPreferenceControllerTest.java
index 3a605ea..fb2cddd 100644
--- a/tests/unit/src/com/android/settings/privatespace/autolock/AutoLockPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/privatespace/autolock/AutoLockPreferenceControllerTest.java
@@ -127,7 +127,7 @@
Settings.Secure.PRIVATE_SPACE_AUTO_LOCK,
Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_AFTER_INACTIVITY);
assertThat(mAutoLockPreferenceController.getSummary().toString())
- .isEqualTo("After 5 minutes of inactivity");
+ .isEqualTo("5 minutes after screen timeout");
}
/**