Merge "Adds LockScreen SafetySource and SafetySource broadcast receivers."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 51f2a29..fcd6cc0 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2968,7 +2968,8 @@
<activity
android:name=".users.AddSupervisedUserActivity"
android:label="@*android:string/supervised_user_creation_label"
- android:icon="@drawable/ic_settings_multiuser">
+ android:icon="@drawable/ic_settings_multiuser"
+ android:exported="true">
</activity>
<activity
diff --git a/color-check-baseline.xml b/color-check-baseline.xml
index 559a589..16658f8 100644
--- a/color-check-baseline.xml
+++ b/color-check-baseline.xml
@@ -2885,6 +2885,22 @@
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_audio_description.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:fillColor="@color/battery_good_color_light""
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
diff --git a/packages/apps/Settings/src/com/android/settings/dream/OWNERS b/packages/apps/Settings/src/com/android/settings/dream/OWNERS
new file mode 100644
index 0000000..56e1b39
--- /dev/null
+++ b/packages/apps/Settings/src/com/android/settings/dream/OWNERS
@@ -0,0 +1 @@
+lusilva@google.com
\ No newline at end of file
diff --git a/res/drawable/accessibility_text_reading_reset_button_background.xml b/res/drawable/accessibility_text_reading_reset_button_background.xml
new file mode 100644
index 0000000..b86facf
--- /dev/null
+++ b/res/drawable/accessibility_text_reading_reset_button_background.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+-->
+
+<shape
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+ android:shape="rectangle">
+
+ <corners android:radius="100dp" />
+ <solid android:color="?androidprv:attr/colorAccentPrimary" />
+</shape>
diff --git a/res/drawable/ic_audio_description.xml b/res/drawable/ic_audio_description.xml
new file mode 100644
index 0000000..0226582
--- /dev/null
+++ b/res/drawable/ic_audio_description.xml
@@ -0,0 +1,35 @@
+<!--
+ Copyright 2022 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">
+ <vector
+ android:width="@dimen/accessibility_icon_foreground_size"
+ android:height="@dimen/accessibility_icon_foreground_size"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M10,18v-4L8,14v-2q0,-1.65 1.175,-2.825Q10.35,8 12,8q1.65,0 2.825,1.175Q16,10.35 16,12v2h-2v4h2.8q0.5,0 0.85,-0.35t0.35,-0.85L18,12q0,-2.5 -1.75,-4.25T12,6Q9.5,6 7.75,7.75T6,12v4.8q0,0.5 0.35,0.85t0.85,0.35zM5,21q-0.825,0 -1.413,-0.587Q3,19.825 3,19L3,5q0,-0.825 0.587,-1.413Q4.175,3 5,3h14q0.825,0 1.413,0.587Q21,4.175 21,5v14q0,0.825 -0.587,1.413Q19.825,21 19,21zM5,19h14L19,5L5,5v14zM5,19L5,5v14z"/>
+ </vector>
+ </item>
+</layer-list>
\ No newline at end of file
diff --git a/res/layout/accessibility_text_reading_reset_button.xml b/res/layout/accessibility_text_reading_reset_button.xml
new file mode 100644
index 0000000..43800df
--- /dev/null
+++ b/res/layout/accessibility_text_reading_reset_button.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2022 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.
+-->
+
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart">
+
+ <Button
+ android:id="@+id/reset_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:background="@drawable/accessibility_text_reading_reset_button_background"
+ android:paddingHorizontal="24dp"
+ android:paddingVertical="14dp"
+ android:text="@string/accessibility_text_reading_reset_button_title"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+</FrameLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5cbdb60..f071f5d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4983,6 +4983,9 @@
<!-- Summary text for keyboards when no layout has been selected. [CHAR LIMIT=35] -->
<string name="default_keyboard_layout">Default</string>
+ <!-- Title for the 'Speech' preference category. [CHAR LIMIT=45] -->
+ <string name="speech_category_title">Speech</string>
+
<!-- On Languages & input settings screen, setting summary. Setting for mouse pointer speed. [CHAR LIMIT=35] -->
<string name="pointer_speed">Pointer speed</string>
@@ -5233,6 +5236,8 @@
<string name="accessibility_text_reading_preview_mail_from">From: bill@email.com</string>
<!-- Content for the mail content of the accessibility text reading preview. [CHAR LIMIT=NONE] -->
<string name="accessibility_text_reading_preview_mail_content">Good morning! Following up on our last conversation, I’d like to check in on the progress of your time machine development plan. Will you be able to have a prototype ready to demo at E3 this year?</string>
+ <!-- Title for the reset button of the accessibility text reading page to reset all preferences state. [CHAR LIMIT=NONE] -->
+ <string name="accessibility_text_reading_reset_button_title">Reset</string>
<!-- Title for the footer text to explain what option accessibility service does. [CHAR LIMIT=35] -->
<string name="accessibility_screen_option">Options</string>
<!-- Summary for the accessibility preference to enable screen magnification. [CHAR LIMIT=25] -->
@@ -5499,7 +5504,7 @@
<!-- Used in the accessibility service settings to open the activity. [CHAR LIMIT=NONE] -->
<string name="accessibility_service_primary_open_title">Open <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g></string>
<!-- Used in the accessibility service settings to show quick settings tooltips. [CHAR LIMIT=NONE] -->
- <string name="accessibility_service_quick_settings_tooltips_content">Swipe down to quickly turn <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g> on or off in quick settings</string>
+ <string name="accessibility_service_quick_settings_tooltips_content"><xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g> added to Quick Settings. Swipe down to turn it on or off anytime.</string>
<!-- Used in the accessibility action for accessibility quick settings tooltips to dismiss. [CHAR LIMIT=NONE] -->
<string name="accessibility_quick_settings_tooltips_dismiss">Dismiss</string>
<!-- Used in the Color correction settings screen to control turning on/off the feature entirely [CHAR LIMIT=60] -->
@@ -5554,6 +5559,13 @@
</plurals>
<!-- Title for the accessibility audio adjustment page. [CHAR LIMIT=50] -->
<string name="accessibility_audio_adjustment_title">Audio adjustment</string>
+ <!-- Title for control audio description preference. [CHAR LIMIT=50] -->
+ <string name="accessibility_toggle_audio_description_preference_title">Audio Description</string>
+ <!-- Summary for accessibility preference for audio description when need
+ audio description in adopted apps. [CHAR_LIMIT=NONE] -->
+ <string name="accessibility_audio_description_summary">Select audio sound track with audio description by default</string>
+ <!-- List of synonyms used in the settings search bar to find the "Audio Description. [CHAR LIMIT=NONE] -->
+ <string name="keywords_audio_description">audio description, audio, description, low vision,</string>
<!-- Preference's shortcut when enabled. [CHAR LIMIT=NONE] -->
<string name="accessibility_summary_shortcut_enabled">Shortcut on</string>
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index dcf3fc2..fcdf47b 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -81,6 +81,16 @@
settings:keywords="@string/keywords_magnification"
settings:controller="com.android.settings.accessibility.MagnificationPreferenceController"/>
+ <SwitchPreference
+ android:key="toggle_audio_description"
+ android:persistent="false"
+ android:icon="@drawable/ic_audio_description"
+ android:summary="@string/accessibility_audio_description_summary"
+ android:title="@string/accessibility_toggle_audio_description_preference_title"
+ settings:keywords="@string/keywords_audio_description"
+ settings:searchable="true"
+ settings:controller="com.android.settings.accessibility.AudioDescriptionPreferenceController"/>
+
</PreferenceCategory>
<PreferenceCategory
diff --git a/res/xml/accessibility_text_reading_options.xml b/res/xml/accessibility_text_reading_options.xml
index 4bc9317..7d81565 100644
--- a/res/xml/accessibility_text_reading_options.xml
+++ b/res/xml/accessibility_text_reading_options.xml
@@ -21,16 +21,44 @@
android:persistent="false"
android:title="@string/accessibility_text_reading_options_title">
+ <com.android.settings.accessibility.TextReadingPreviewPreference
+ android:key="preview"
+ android:selectable="false"/>
+
+ <com.android.settings.widget.LabeledSeekBarPreference
+ android:key="font_size"
+ android:selectable="false"
+ android:summary="@string/short_summary_font_size"
+ android:title="@string/title_font_size"
+ settings:iconEnd="@drawable/ic_add_24dp"
+ settings:iconEndContentDescription="@string/font_size_make_larger_desc"
+ settings:iconStart="@drawable/ic_remove_24dp"
+ settings:iconStartContentDescription="@string/font_size_make_smaller_desc"/>
+
+ <com.android.settings.widget.LabeledSeekBarPreference
+ android:key="display_size"
+ android:selectable="false"
+ android:summary="@string/screen_zoom_short_summary"
+ android:title="@string/screen_zoom_title"
+ settings:iconEnd="@drawable/ic_add_24dp"
+ settings:iconEndContentDescription="@string/screen_zoom_make_larger_desc"
+ settings:iconStart="@drawable/ic_remove_24dp"
+ settings:iconStartContentDescription="@string/screen_zoom_make_smaller_desc"/>
+
<SwitchPreference
android:key="toggle_force_bold_text"
android:persistent="false"
android:title="@string/force_bold_text"
- settings:keywords="@string/keywords_bold_text"
- settings:controller="com.android.settings.accessibility.FontWeightAdjustmentPreferenceController"/>
+ settings:keywords="@string/keywords_bold_text" />
<SwitchPreference
android:key="toggle_high_text_contrast_preference"
android:persistent="false"
- android:title="@string/accessibility_toggle_high_text_contrast_preference_title"
- settings:controller="com.android.settings.accessibility.HighTextContrastPreferenceController"/>
+ android:title="@string/accessibility_toggle_high_text_contrast_preference_title" />
+
+ <com.android.settingslib.widget.LayoutPreference
+ android:key="reset"
+ android:layout="@layout/accessibility_text_reading_reset_button"
+ android:persistent="false"
+ android:selectable="false" />
</PreferenceScreen>
diff --git a/res/xml/language_and_input.xml b/res/xml/language_and_input.xml
index f2b6d8a..c99d591 100644
--- a/res/xml/language_and_input.xml
+++ b/res/xml/language_and_input.xml
@@ -38,8 +38,6 @@
android:name="classname"
android:value="com.android.settings.applications.appinfo.AppLocaleDetails" />
</Preference>
-
-
</PreferenceCategory>
<PreferenceCategory
@@ -50,6 +48,7 @@
android:title="@string/virtual_keyboard_category"
android:fragment="com.android.settings.inputmethod.AvailableVirtualKeyboardFragment"
settings:keywords="@string/keywords_virtual_keyboard"/>
+
<Preference
android:key="physical_keyboard_pref"
android:title="@string/physical_keyboard_title"
@@ -58,6 +57,21 @@
</PreferenceCategory>
<PreferenceCategory
+ android:key="speech_category"
+ android:title="@string/speech_category_title">
+ <com.android.settings.widget.GearPreference
+ android:key="voice_input_settings"
+ android:title="@string/voice_input_settings_title"
+ android:fragment="com.android.settings.language.DefaultVoiceInputPicker" />
+
+ <Preference
+ android:key="tts_settings_summary"
+ android:title="@string/tts_settings_title"
+ android:fragment="com.android.settings.tts.TextToSpeechSettings"
+ settings:searchable="false"/>
+ </PreferenceCategory>
+
+ <PreferenceCategory
android:key="input_assistance_category"
android:title="@string/input_assistance">
<!-- Spell checker preference title, summary and fragment will be set programmatically. -->
@@ -79,20 +93,12 @@
</PreferenceCategory>
<PreferenceCategory
- android:key="pointer_and_tts_category"
+ android:key="pointer_category"
android:layout="@layout/preference_category_no_label">
-
<com.android.settings.PointerSpeedPreference
android:key="pointer_speed"
android:title="@string/pointer_speed"
android:dialogTitle="@string/pointer_speed" />
-
- <Preference
- android:key="tts_settings_summary"
- android:title="@string/tts_settings_title"
- android:fragment="com.android.settings.tts.TextToSpeechSettings"
- settings:searchable="false"/>
-
</PreferenceCategory>
<SwitchPreference
diff --git a/res/xml/manage_assist.xml b/res/xml/manage_assist.xml
index 59ba2f5..c8dbe42 100644
--- a/res/xml/manage_assist.xml
+++ b/res/xml/manage_assist.xml
@@ -49,11 +49,6 @@
android:title="@string/assist_flash_title"
android:summary="@string/assist_flash_summary" />
- <com.android.settings.widget.GearPreference
- android:key="voice_input_settings"
- android:title="@string/voice_input_settings_title"
- android:fragment="com.android.settings.applications.assist.DefaultVoiceInputPicker" />
-
<com.android.settingslib.widget.FooterPreference
android:key="manage_assist_footer"
android:title="@string/assist_footer"
diff --git a/src/com/android/settings/accessibility/AudioDescriptionPreferenceController.java b/src/com/android/settings/accessibility/AudioDescriptionPreferenceController.java
new file mode 100644
index 0000000..a05a0d0
--- /dev/null
+++ b/src/com/android/settings/accessibility/AudioDescriptionPreferenceController.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2022 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.provider.Settings.Secure.ENABLED_ACCESSIBILITY_AUDIO_DESCRIPTION_BY_DEFAULT;
+
+import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
+import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.provider.Settings;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+
+/**
+ * A toggle preference controller for audio description
+ */
+public class AudioDescriptionPreferenceController extends TogglePreferenceController {
+
+ static final String PREF_KEY = "toggle_audio_description";
+
+ public AudioDescriptionPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return Settings.Secure.getIntForUser(mContext.getContentResolver(),
+ ENABLED_ACCESSIBILITY_AUDIO_DESCRIPTION_BY_DEFAULT,
+ OFF /* default */,
+ UserHandle.USER_CURRENT) == ON;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ return Settings.Secure.putIntForUser(mContext.getContentResolver(),
+ ENABLED_ACCESSIBILITY_AUDIO_DESCRIPTION_BY_DEFAULT,
+ isChecked ? ON : OFF,
+ UserHandle.USER_CURRENT);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public int getSliceHighlightMenuRes() {
+ return R.string.menu_key_accessibility;
+ }
+}
diff --git a/src/com/android/settings/accessibility/DisplaySizeData.java b/src/com/android/settings/accessibility/DisplaySizeData.java
new file mode 100644
index 0000000..42a8c46
--- /dev/null
+++ b/src/com/android/settings/accessibility/DisplaySizeData.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2022 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 android.content.Context;
+import android.content.res.Resources;
+import android.view.Display;
+
+import com.android.settingslib.display.DisplayDensityConfiguration;
+import com.android.settingslib.display.DisplayDensityUtils;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.stream.Collectors;
+
+/**
+ * Data class for storing the configurations related to the display size.
+ */
+class DisplaySizeData extends PreviewSizeData<Integer> {
+ DisplaySizeData(Context context) {
+ super(context);
+
+ final DisplayDensityUtils density = new DisplayDensityUtils(getContext());
+ final int initialIndex = density.getCurrentIndex();
+ if (initialIndex < 0) {
+ // Failed to obtain default density, which means we failed to
+ // connect to the window manager service. Just use the current
+ // density and don't let the user change anything.
+ final Resources resources = getContext().getResources();
+ final int densityDpi = resources.getDisplayMetrics().densityDpi;
+ setDefaultValue(densityDpi);
+ setInitialIndex(0);
+ setValues(Collections.singletonList(densityDpi));
+ } else {
+ setDefaultValue(density.getDefaultDensity());
+ setInitialIndex(initialIndex);
+ setValues(Arrays.stream(density.getValues()).boxed().collect(Collectors.toList()));
+ }
+ }
+
+ @Override
+ void commit(int currentProgress) {
+ final int densityDpi = getValues().get(currentProgress);
+ if (densityDpi == getDefaultValue()) {
+ DisplayDensityConfiguration.clearForcedDisplayDensity(Display.DEFAULT_DISPLAY);
+ } else {
+ DisplayDensityConfiguration.setForcedDisplayDensity(Display.DEFAULT_DISPLAY,
+ densityDpi);
+ }
+ }
+}
diff --git a/src/com/android/settings/accessibility/FontSizeData.java b/src/com/android/settings/accessibility/FontSizeData.java
new file mode 100644
index 0000000..1d4f6bd
--- /dev/null
+++ b/src/com/android/settings/accessibility/FontSizeData.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2022 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.android.settings.display.ToggleFontSizePreferenceFragment.fontSizeValueToIndex;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import android.provider.Settings;
+
+import com.android.settings.R;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Data class for storing the configurations related to the font size.
+ */
+final class FontSizeData extends PreviewSizeData<Float> {
+ private static final float FONT_SCALE_DEF_VALUE = 1.0f;
+
+ FontSizeData(Context context) {
+ super(context);
+
+ final Resources resources = getContext().getResources();
+ final ContentResolver resolver = getContext().getContentResolver();
+ final List<String> strEntryValues =
+ Arrays.asList(resources.getStringArray(R.array.entryvalues_font_size));
+ setDefaultValue(FONT_SCALE_DEF_VALUE);
+ final float currentScale =
+ Settings.System.getFloat(resolver, Settings.System.FONT_SCALE, getDefaultValue());
+ setInitialIndex(fontSizeValueToIndex(currentScale, strEntryValues.toArray(new String[0])));
+ setValues(strEntryValues.stream().map(Float::valueOf).collect(Collectors.toList()));
+ }
+
+ @Override
+ void commit(int currentProgress) {
+ final ContentResolver resolver = getContext().getContentResolver();
+ Settings.System.putFloat(resolver, Settings.System.FONT_SCALE,
+ getValues().get(currentProgress));
+ }
+}
diff --git a/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java b/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java
index b59b3b2..e3c1b9e 100644
--- a/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java
+++ b/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceController.java
@@ -24,7 +24,8 @@
import com.android.settings.core.TogglePreferenceController;
/** PreferenceController for displaying all text in bold. */
-public class FontWeightAdjustmentPreferenceController extends TogglePreferenceController {
+public class FontWeightAdjustmentPreferenceController extends TogglePreferenceController implements
+ TextReadingResetController.ResetStateListener {
static final int BOLD_TEXT_ADJUSTMENT =
FontStyle.FONT_WEIGHT_BOLD - FontStyle.FONT_WEIGHT_NORMAL;
@@ -53,4 +54,9 @@
public int getSliceHighlightMenuRes() {
return R.string.menu_key_accessibility;
}
+
+ @Override
+ public void resetState() {
+ setChecked(false);
+ }
}
diff --git a/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java b/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java
index e98a28c..aad69b9 100644
--- a/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java
+++ b/src/com/android/settings/accessibility/HighTextContrastPreferenceController.java
@@ -22,7 +22,11 @@
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
-public class HighTextContrastPreferenceController extends TogglePreferenceController {
+/**
+ * PreferenceController for displaying all text in high contrast style.
+ */
+public class HighTextContrastPreferenceController extends TogglePreferenceController implements
+ TextReadingResetController.ResetStateListener {
public HighTextContrastPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
@@ -49,4 +53,9 @@
public int getSliceHighlightMenuRes() {
return R.string.menu_key_accessibility;
}
+
+ @Override
+ public void resetState() {
+ setChecked(false);
+ }
}
diff --git a/src/com/android/settings/accessibility/PreviewSizeData.java b/src/com/android/settings/accessibility/PreviewSizeData.java
new file mode 100644
index 0000000..5d4204e
--- /dev/null
+++ b/src/com/android/settings/accessibility/PreviewSizeData.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2022 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 android.content.Context;
+
+import androidx.annotation.NonNull;
+
+import java.util.List;
+
+/**
+ * Abstract data class for storing and fetching the configurations related to the preview of the
+ * text and reading options.
+ */
+abstract class PreviewSizeData<T extends Number> {
+ private final Context mContext;
+ private int mInitialIndex;
+ private T mDefaultValue;
+ private List<T> mValues;
+
+ PreviewSizeData(@NonNull Context context) {
+ mContext = context;
+ }
+
+ Context getContext() {
+ return mContext;
+ }
+
+ List<T> getValues() {
+ return mValues;
+ }
+
+ void setValues(List<T> values) {
+ mValues = values;
+ }
+
+ T getDefaultValue() {
+ return mDefaultValue;
+ }
+
+ void setDefaultValue(T defaultValue) {
+ mDefaultValue = defaultValue;
+ }
+
+ int getInitialIndex() {
+ return mInitialIndex;
+ }
+
+ void setInitialIndex(int initialIndex) {
+ mInitialIndex = initialIndex;
+ }
+
+ /**
+ * Persists the selected size.
+ */
+ abstract void commit(int currentProgress);
+}
diff --git a/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java b/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java
new file mode 100644
index 0000000..c7dfd61
--- /dev/null
+++ b/src/com/android/settings/accessibility/PreviewSizeSeekBarController.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2022 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 android.content.Context;
+import android.widget.SeekBar;
+
+import androidx.annotation.NonNull;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.widget.LabeledSeekBarPreference;
+
+/**
+ * The controller of {@link LabeledSeekBarPreference} that listens to display size and font size
+ * settings changes and updates preview size threshold smoothly.
+ */
+class PreviewSizeSeekBarController extends BasePreferenceController implements
+ TextReadingResetController.ResetStateListener {
+ private final PreviewSizeData<? extends Number> mSizeData;
+ private boolean mSeekByTouch;
+ private ProgressInteractionListener mInteractionListener;
+ private LabeledSeekBarPreference mSeekBarPreference;
+
+ private final SeekBar.OnSeekBarChangeListener mSeekBarChangeListener =
+ new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ mInteractionListener.notifyPreferenceChanged();
+
+ if (!mSeekByTouch && mInteractionListener != null) {
+ mInteractionListener.onProgressChanged();
+ }
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ mSeekByTouch = true;
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ mSeekByTouch = false;
+
+ if (mInteractionListener != null) {
+ mInteractionListener.onEndTrackingTouch();
+ }
+ }
+ };
+
+ PreviewSizeSeekBarController(Context context, String preferenceKey,
+ @NonNull PreviewSizeData<? extends Number> sizeData) {
+ super(context, preferenceKey);
+ mSizeData = sizeData;
+ }
+
+ void setInteractionListener(ProgressInteractionListener interactionListener) {
+ mInteractionListener = interactionListener;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ final int dataSize = mSizeData.getValues().size();
+ final int initialIndex = mSizeData.getInitialIndex();
+ mSeekBarPreference = screen.findPreference(getPreferenceKey());
+ mSeekBarPreference.setMax(dataSize - 1);
+ mSeekBarPreference.setProgress(initialIndex);
+ mSeekBarPreference.setContinuousUpdates(true);
+ mSeekBarPreference.setOnSeekBarChangeListener(mSeekBarChangeListener);
+ }
+
+ @Override
+ public void resetState() {
+ final int defaultProgress = mSizeData.getValues().indexOf(mSizeData.getDefaultValue());
+ mSeekBarPreference.setProgress(defaultProgress);
+ }
+
+ /**
+ * Interface for callbacks when users interact with the seek bar.
+ */
+ interface ProgressInteractionListener {
+
+ /**
+ * Called when the progress is changed.
+ */
+ void notifyPreferenceChanged();
+
+ /**
+ * Called when the progress is changed without tracking touch.
+ */
+ void onProgressChanged();
+
+ /**
+ * Called when the seek bar is end tracking.
+ */
+ void onEndTrackingTouch();
+ }
+}
diff --git a/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java b/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
index 0e8457b..7dd70af 100644
--- a/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
@@ -16,13 +16,21 @@
package com.android.settings.accessibility;
+import static com.android.settings.accessibility.TextReadingResetController.ResetStateListener;
+
import android.app.settings.SettingsEnums;
+import android.content.Context;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
/**
* Accessibility settings for adjusting the system features which are related to the reading. For
* example, bold text, high contrast text, display size, font size and so on.
@@ -30,6 +38,12 @@
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class TextReadingPreferenceFragment extends DashboardFragment {
private static final String TAG = "TextReadingPreferenceFragment";
+ private static final String FONT_SIZE_KEY = "font_size";
+ private static final String DISPLAY_SIZE_KEY = "display_size";
+ private static final String PREVIEW_KEY = "preview";
+ private static final String RESET_KEY = "reset";
+ private static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
+ private static final String HIGHT_TEXT_CONTRAST_KEY = "toggle_high_text_contrast_preference";
@Override
protected int getPreferenceScreenResId() {
@@ -46,6 +60,44 @@
return SettingsEnums.ACCESSIBILITY_TEXT_READING_OPTIONS;
}
+ @Override
+ protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ final FontSizeData fontSizeData = new FontSizeData(context);
+ final DisplaySizeData displaySizeData = new DisplaySizeData(context);
+
+ final TextReadingPreviewController previewController = new TextReadingPreviewController(
+ context, PREVIEW_KEY, fontSizeData, displaySizeData);
+ controllers.add(previewController);
+
+ final PreviewSizeSeekBarController fontSizeController = new PreviewSizeSeekBarController(
+ context, FONT_SIZE_KEY, fontSizeData);
+ fontSizeController.setInteractionListener(previewController);
+ controllers.add(fontSizeController);
+
+ final PreviewSizeSeekBarController displaySizeController = new PreviewSizeSeekBarController(
+ context, DISPLAY_SIZE_KEY, displaySizeData);
+ displaySizeController.setInteractionListener(previewController);
+ controllers.add(displaySizeController);
+
+ final FontWeightAdjustmentPreferenceController fontWeightController =
+ new FontWeightAdjustmentPreferenceController(context, BOLD_TEXT_KEY);
+ controllers.add(fontWeightController);
+
+ final HighTextContrastPreferenceController highTextContrastController =
+ new HighTextContrastPreferenceController(context, HIGHT_TEXT_CONTRAST_KEY);
+ controllers.add(highTextContrastController);
+
+ final List<ResetStateListener> resetStateListeners =
+ controllers.stream().filter(c -> c instanceof ResetStateListener).map(
+ c -> (ResetStateListener) c).collect(Collectors.toList());
+ final TextReadingResetController resetController =
+ new TextReadingResetController(context, RESET_KEY, resetStateListeners);
+ controllers.add(resetController);
+
+ return controllers;
+ }
+
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.accessibility_text_reading_options);
}
diff --git a/src/com/android/settings/accessibility/TextReadingPreviewController.java b/src/com/android/settings/accessibility/TextReadingPreviewController.java
new file mode 100644
index 0000000..cef20aa
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingPreviewController.java
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2022 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 android.content.Context;
+import android.content.res.Configuration;
+import android.os.SystemClock;
+import android.view.Choreographer;
+import android.view.View;
+
+import androidx.annotation.NonNull;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.display.PreviewPagerAdapter;
+import com.android.settings.widget.LabeledSeekBarPreference;
+
+import java.util.Objects;
+
+/**
+ * A {@link BasePreferenceController} for controlling the preview pager of the text and reading
+ * options.
+ */
+class TextReadingPreviewController extends BasePreferenceController implements
+ PreviewSizeSeekBarController.ProgressInteractionListener {
+ static final int[] PREVIEW_SAMPLE_RES_IDS = new int[]{
+ R.layout.accessibility_text_reading_preview_app_grid,
+ R.layout.screen_zoom_preview_1,
+ R.layout.accessibility_text_reading_preview_mail_content};
+
+ private static final String PREVIEW_KEY = "preview";
+ private static final String FONT_SIZE_KEY = "font_size";
+ private static final String DISPLAY_SIZE_KEY = "display_size";
+ private static final long MIN_COMMIT_INTERVAL_MS = 800;
+ private static final long CHANGE_BY_SEEKBAR_DELAY_MS = 100;
+ private static final long CHANGE_BY_BUTTON_DELAY_MS = 300;
+ private final FontSizeData mFontSizeData;
+ private final DisplaySizeData mDisplaySizeData;
+ private int mLastFontProgress;
+ private int mLastDisplayProgress;
+ private long mLastCommitTime;
+ private TextReadingPreviewPreference mPreviewPreference;
+ private LabeledSeekBarPreference mFontSizePreference;
+ private LabeledSeekBarPreference mDisplaySizePreference;
+
+ private final Choreographer.FrameCallback mCommit = f -> {
+ tryCommitFontSizeConfig();
+ tryCommitDisplaySizeConfig();
+
+ mLastCommitTime = SystemClock.elapsedRealtime();
+ };
+
+ TextReadingPreviewController(Context context, String preferenceKey,
+ @NonNull FontSizeData fontSizeData, @NonNull DisplaySizeData displaySizeData) {
+ super(context, preferenceKey);
+ mFontSizeData = fontSizeData;
+ mDisplaySizeData = displaySizeData;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ mPreviewPreference = screen.findPreference(PREVIEW_KEY);
+
+ mFontSizePreference = screen.findPreference(FONT_SIZE_KEY);
+ mDisplaySizePreference = screen.findPreference(DISPLAY_SIZE_KEY);
+ Objects.requireNonNull(mFontSizePreference,
+ /* message= */ "Font size preference is null, the preview controller "
+ + "couldn't get the info");
+ Objects.requireNonNull(mDisplaySizePreference,
+ /* message= */ "Display size preference is null, the preview controller"
+ + " couldn't get the info");
+
+ mLastFontProgress = mFontSizePreference.getProgress();
+ mLastDisplayProgress = mDisplaySizePreference.getProgress();
+
+ final Configuration origConfig = mContext.getResources().getConfiguration();
+ final boolean isLayoutRtl =
+ origConfig.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
+ final PreviewPagerAdapter pagerAdapter = new PreviewPagerAdapter(mContext, isLayoutRtl,
+ PREVIEW_SAMPLE_RES_IDS, createConfig(origConfig));
+ mPreviewPreference.setPreviewAdapter(pagerAdapter);
+ pagerAdapter.setPreviewLayer(/* newLayerIndex= */ 0,
+ /* currentLayerIndex= */ 0,
+ /* currentFrameIndex= */ 0, /* animate= */ false);
+ }
+
+ @Override
+ public void notifyPreferenceChanged() {
+ final int displayDataSize = mDisplaySizeData.getValues().size();
+ final int fontSizeProgress = mFontSizePreference.getProgress();
+ final int displaySizeProgress = mDisplaySizePreference.getProgress();
+
+ // To be consistent with the
+ // {@link PreviewPagerAdapter#setPreviewLayer(int, int, int, boolean)} behavior,
+ // here also needs the same design. In addition, please also refer to
+ // the {@link #createConfig(Configuration)}.
+ final int pagerIndex = fontSizeProgress * displayDataSize + displaySizeProgress;
+
+ mPreviewPreference.notifyPreviewPagerChanged(pagerIndex);
+ }
+
+ @Override
+ public void onProgressChanged() {
+ postCommitDelayed(CHANGE_BY_BUTTON_DELAY_MS);
+ }
+
+ @Override
+ public void onEndTrackingTouch() {
+ postCommitDelayed(CHANGE_BY_SEEKBAR_DELAY_MS);
+ }
+
+ /**
+ * Avoids the flicker when switching to the previous or next level.
+ *
+ * <p><br>[Flickering problem steps] commit()-> snapshot in framework(old screenshot) ->
+ * app update the preview -> snapshot(old screen) fade out</p>
+ *
+ * <p><br>To prevent flickering problem, we make sure that we update the local preview
+ * first and then we do the commit later. </p>
+ *
+ * <p><br><b>Note:</b> It doesn't matter that we use
+ * Choreographer or main thread handler since the delay time is longer
+ * than 1 frame. Use Choreographer to let developer understand it's a
+ * window update.</p>
+ *
+ * @param commitDelayMs the interval time after a action.
+ */
+ void postCommitDelayed(long commitDelayMs) {
+ if (SystemClock.elapsedRealtime() - mLastCommitTime < MIN_COMMIT_INTERVAL_MS) {
+ commitDelayMs += MIN_COMMIT_INTERVAL_MS;
+ }
+
+ final Choreographer choreographer = Choreographer.getInstance();
+ choreographer.removeFrameCallback(mCommit);
+ choreographer.postFrameCallbackDelayed(mCommit, commitDelayMs);
+ }
+
+ private void tryCommitFontSizeConfig() {
+ final int fontProgress = mFontSizePreference.getProgress();
+ if (fontProgress != mLastFontProgress) {
+ mFontSizeData.commit(fontProgress);
+ mLastFontProgress = fontProgress;
+ }
+ }
+
+ private void tryCommitDisplaySizeConfig() {
+ final int displayProgress = mDisplaySizePreference.getProgress();
+ if (displayProgress != mLastDisplayProgress) {
+ mDisplaySizeData.commit(displayProgress);
+ mLastDisplayProgress = displayProgress;
+ }
+ }
+
+ private Configuration[] createConfig(Configuration origConfig) {
+ final int fontDataSize = mFontSizeData.getValues().size();
+ final int displayDataSize = mDisplaySizeData.getValues().size();
+ final int totalNum = fontDataSize * displayDataSize;
+ final Configuration[] configurations = new Configuration[totalNum];
+
+ for (int i = 0; i < fontDataSize; ++i) {
+ for (int j = 0; j < displayDataSize; ++j) {
+ final Configuration config = new Configuration(origConfig);
+ config.fontScale = mFontSizeData.getValues().get(i);
+ config.densityDpi = mDisplaySizeData.getValues().get(j);
+
+ configurations[i * displayDataSize + j] = config;
+ }
+ }
+
+ return configurations;
+ }
+}
diff --git a/src/com/android/settings/accessibility/TextReadingPreviewPreference.java b/src/com/android/settings/accessibility/TextReadingPreviewPreference.java
index 1b9cc4b..4b8ca39 100644
--- a/src/com/android/settings/accessibility/TextReadingPreviewPreference.java
+++ b/src/com/android/settings/accessibility/TextReadingPreviewPreference.java
@@ -32,8 +32,9 @@
/**
* A {@link Preference} that could show the preview related to the text and reading options.
*/
-final class TextReadingPreviewPreference extends Preference {
+public class TextReadingPreviewPreference extends Preference {
private int mCurrentItem;
+ private int mLastLayerIndex;
private PreviewPagerAdapter mPreviewAdapter;
TextReadingPreviewPreference(Context context) {
@@ -41,7 +42,7 @@
init();
}
- TextReadingPreviewPreference(Context context, AttributeSet attrs) {
+ public TextReadingPreviewPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
@@ -120,4 +121,16 @@
private void init() {
setLayoutResource(R.layout.accessibility_text_reading_preview);
}
+
+ void notifyPreviewPagerChanged(int pagerIndex) {
+ Preconditions.checkNotNull(mPreviewAdapter,
+ "Preview adapter is null, you should init the preview adapter first");
+
+ if (pagerIndex != mLastLayerIndex) {
+ mPreviewAdapter.setPreviewLayer(pagerIndex, mLastLayerIndex, getCurrentItem(),
+ /* animate= */ false);
+ }
+
+ mLastLayerIndex = pagerIndex;
+ }
}
diff --git a/src/com/android/settings/accessibility/TextReadingResetController.java b/src/com/android/settings/accessibility/TextReadingResetController.java
new file mode 100644
index 0000000..f4752cb
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingResetController.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2022 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 android.content.Context;
+import android.view.View;
+
+import androidx.annotation.NonNull;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.widget.LayoutPreference;
+
+import java.util.List;
+
+/**
+ * The controller of the reset button in the text and reading options page.
+ */
+class TextReadingResetController extends BasePreferenceController {
+ private final List<ResetStateListener> mListeners;
+
+ TextReadingResetController(Context context, String preferenceKey,
+ @NonNull List<ResetStateListener> listeners) {
+ super(context, preferenceKey);
+ mListeners = listeners;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ final LayoutPreference layoutPreference = screen.findPreference(getPreferenceKey());
+ final View view = layoutPreference.findViewById(R.id.reset_button);
+ view.setOnClickListener(v -> mListeners.forEach(ResetStateListener::resetState));
+ }
+
+ /**
+ * Interface for resetting to default state.
+ */
+ interface ResetStateListener {
+ /**
+ * Called when the reset button was clicked.
+ */
+ void resetState();
+ }
+}
diff --git a/src/com/android/settings/applications/appinfo/OWNERS b/src/com/android/settings/applications/appinfo/OWNERS
new file mode 100644
index 0000000..cd6abb8
--- /dev/null
+++ b/src/com/android/settings/applications/appinfo/OWNERS
@@ -0,0 +1,5 @@
+# just for per-app locale settings review
+allenwtsu@google.com
+danielwbhuang@google.com
+goldmanj@google.com
+tomhsu@google.com
diff --git a/src/com/android/settings/applications/assist/ManageAssist.java b/src/com/android/settings/applications/assist/ManageAssist.java
index c96f43f..ad6c71e 100644
--- a/src/com/android/settings/applications/assist/ManageAssist.java
+++ b/src/com/android/settings/applications/assist/ManageAssist.java
@@ -73,7 +73,6 @@
controllers.add(new AssistContextPreferenceController(context, lifecycle));
controllers.add(new AssistScreenshotPreferenceController(context, lifecycle));
controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle));
- controllers.add(new DefaultVoiceInputPreferenceController(context, lifecycle));
return controllers;
}
diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java
index b6a2970..de79739 100644
--- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java
+++ b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java
@@ -311,11 +311,13 @@
return;
}
- // othewise, only the defined default supervision profile owner can be set after user
- // setup.
+ // otherwise, only the defined default supervision profile owner or holder of
+ // supersvision role can be set after user setup.
final String supervisor = getString(
com.android.internal.R.string.config_defaultSupervisionProfileOwnerComponent);
- if (TextUtils.isEmpty(supervisor)) {
+ final String supervisionRolePackage = getString(
+ com.android.internal.R.string.config_systemSupervision);
+ if (TextUtils.isEmpty(supervisor) && TextUtils.isEmpty(supervisionRolePackage)) {
Log.w(TAG, "Unable to set profile owner post-setup, no default supervisor"
+ "profile owner defined");
finish();
@@ -324,7 +326,8 @@
final ComponentName supervisorComponent = ComponentName.unflattenFromString(
supervisor);
- if (supervisorComponent == null || who.compareTo(supervisorComponent) != 0) {
+ if (!who.equals(supervisorComponent)
+ && !who.getPackageName().equals(supervisionRolePackage)) {
Log.w(TAG, "Unable to set non-default profile owner post-setup " + who);
finish();
return;
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingController.java b/src/com/android/settings/bluetooth/BluetoothPairingController.java
index b75e02a..c70a56a 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingController.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingController.java
@@ -435,7 +435,7 @@
*/
public void onCancel() {
Log.d(TAG, "Pairing dialog canceled");
- mDevice.cancelPairing();
+ mDevice.cancelBondProcess();
}
/**
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingService.java b/src/com/android/settings/bluetooth/BluetoothPairingService.java
index bc5dc66..9883e61 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingService.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingService.java
@@ -98,7 +98,7 @@
} else if (action.equals(ACTION_DISMISS_PAIRING)) {
Log.d(TAG, "Notification cancel " + " (" +
mDevice.getName() + ")");
- mDevice.cancelPairing();
+ mDevice.cancelBondProcess();
} else {
int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
BluetoothDevice.ERROR);
@@ -144,7 +144,7 @@
createPairingNotification(intent);
} else if (TextUtils.equals(action, ACTION_DISMISS_PAIRING)) {
Log.d(TAG, "Notification cancel " + " (" + mDevice.getName() + ")");
- mDevice.cancelPairing();
+ mDevice.cancelBondProcess();
mNm.cancel(NOTIFICATION_ID);
stopSelf();
} else if (TextUtils.equals(action, ACTION_PAIRING_DIALOG)) {
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
index 1b3b47a..fe20a01 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
@@ -123,13 +123,13 @@
mDataUsageController = null;
}
- private void updateConfiguration(Context context,
+ protected void updateConfiguration(Context context,
int subscriptionId, SubscriptionInfo subInfo) {
final NetworkPolicyManager policyManager =
context.getSystemService(NetworkPolicyManager.class);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
- mDataUsageController = new DataUsageController(context);
+ mDataUsageController = createDataUsageController(context);
mDataUsageController.setSubscriptionId(subscriptionId);
mDataInfoController = new DataUsageInfoController();
@@ -146,6 +146,11 @@
}
@VisibleForTesting
+ DataUsageController createDataUsageController(Context context) {
+ return new DataUsageController(context);
+ }
+
+ @VisibleForTesting
DataUsageSummaryPreferenceController(
DataUsageController dataUsageController,
DataUsageInfoController dataInfoController,
@@ -186,8 +191,7 @@
.getSubscriptionPlans(subscriptionId);
}
- @VisibleForTesting
- SubscriptionInfo getSubscriptionInfo(int subscriptionId) {
+ protected SubscriptionInfo getSubscriptionInfo(int subscriptionId) {
if (!mHasMobileData) {
return null;
}
diff --git a/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java b/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java
index cd26ed1..ceba8be 100644
--- a/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java
+++ b/src/com/android/settings/datausage/UnrestrictedDataAccessPreference.java
@@ -88,7 +88,7 @@
@Override
protected void onClick() {
- if (mDataUsageState.isDataSaverDenylisted) {
+ if (mDataUsageState != null && mDataUsageState.isDataSaverDenylisted) {
// app is denylisted, launch App Data Usage screen
AppInfoDashboardFragment.startAppInfoFragment(AppDataUsage.class,
R.string.data_usage_app_summary_title,
diff --git a/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java
index 9d3054e..4d2dd00 100644
--- a/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java
@@ -26,23 +26,19 @@
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.net.DataUsageController;
+import java.util.HashSet;
import java.util.Set;
/**
* The controller displays a data usage chart for the specified Wi-Fi network.
*/
public class WifiDataUsageSummaryPreferenceController extends DataUsageSummaryPreferenceController {
- final String mNetworkId;
+ final Set<String> mAllNetworkKeys;
- public WifiDataUsageSummaryPreferenceController(Activity activity,
- Lifecycle lifecycle, PreferenceFragmentCompat fragment, CharSequence networkId) {
+ public WifiDataUsageSummaryPreferenceController(Activity activity, Lifecycle lifecycle,
+ PreferenceFragmentCompat fragment, Set<String> allNetworkKeys) {
super(activity, lifecycle, fragment, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
-
- if (networkId == null) {
- mNetworkId = null;
- } else {
- mNetworkId = String.valueOf(networkId);
- }
+ mAllNetworkKeys = new HashSet<>(allNetworkKeys);
}
@Override
@@ -52,10 +48,11 @@
}
final DataUsageSummaryPreference mPreference = (DataUsageSummaryPreference) preference;
- // TODO(b/126299427): Currently gets data usage of whole Wi-Fi networks, but should get
- // specified one.
final NetworkTemplate template = new NetworkTemplate.Builder(NetworkTemplate.MATCH_WIFI)
- .setWifiNetworkKeys(Set.of(mNetworkId)).build();
+ .setWifiNetworkKeys(mAllNetworkKeys).build();
+ if (mDataUsageController == null) {
+ updateConfiguration(mContext, mSubId, getSubscriptionInfo(mSubId));
+ }
final DataUsageController.DataUsageInfo info = mDataUsageController.getDataUsageInfo(
template);
mDataInfoController.updateDataLimit(info, mPolicyEditor.getPolicy(template));
diff --git a/src/com/android/settings/display/PreviewPagerAdapter.java b/src/com/android/settings/display/PreviewPagerAdapter.java
index 018be32..693d574 100644
--- a/src/com/android/settings/display/PreviewPagerAdapter.java
+++ b/src/com/android/settings/display/PreviewPagerAdapter.java
@@ -117,7 +117,15 @@
mAnimationEndAction = action;
}
- void setPreviewLayer(int newLayerIndex, int currentLayerIndex, int currentFrameIndex,
+ /**
+ * Switches the sample layouts for the preview pager.
+ *
+ * @param newLayerIndex the new layer index
+ * @param currentLayerIndex the current layer index
+ * @param currentFrameIndex the current frame index
+ * @param animate whether to enable the animation
+ */
+ public void setPreviewLayer(int newLayerIndex, int currentLayerIndex, int currentFrameIndex,
final boolean animate) {
for (FrameLayout previewFrame : mPreviewFrames) {
if (currentLayerIndex >= 0) {
diff --git a/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java b/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java
index 8bef708..94415a1 100644
--- a/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java
+++ b/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragment.java
@@ -68,16 +68,35 @@
public void onAttach(Context context) {
super.onAttach(context);
final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
- if (profileType == ProfileSelectFragment.ProfileType.WORK) {
- final UserManager userManager = UserManager.get(context);
- final UserHandle workUser = Utils.getManagedProfile(userManager);
- // get work userId
- mUserId = Utils.getManagedProfileId(userManager, UserHandle.myUserId());
- mUserAwareContext = context.createContextAsUser(workUser, 0);
- } else {
- mUserId = UserHandle.myUserId();
- mUserAwareContext = context;
+ final UserManager userManager = context.getSystemService(UserManager.class);
+ final int currentUserId = UserHandle.myUserId();
+ final int newUserId;
+ final Context newUserAwareContext;
+ switch (profileType) {
+ case ProfileSelectFragment.ProfileType.WORK: {
+ final UserHandle workUser;
+ if (currentUserId == UserHandle.MIN_SECONDARY_USER_ID) {
+ newUserId = currentUserId;
+ workUser = UserHandle.of(currentUserId);
+ } else {
+ newUserId = Utils.getManagedProfileId(userManager, currentUserId);
+ workUser = Utils.getManagedProfile(userManager);
+ }
+ newUserAwareContext = context.createContextAsUser(workUser, 0);
+ break;
+ }
+ case ProfileSelectFragment.ProfileType.PERSONAL: {
+ final UserHandle primaryUser = userManager.getPrimaryUser().getUserHandle();
+ newUserId = primaryUser.getIdentifier();
+ newUserAwareContext = context.createContextAsUser(primaryUser, 0);
+ break;
+ }
+ default:
+ newUserId = currentUserId;
+ newUserAwareContext = context;
}
+ mUserId = newUserId;
+ mUserAwareContext = newUserAwareContext;
}
@Override
@@ -140,7 +159,7 @@
// allowed by organization. Doing so will allow the user to disable the input method and
// remain complaint with the organization's policy. Once disabled, the input method
// cannot be re-enabled because it is not in the permitted list.
- final boolean isAllowedByOrganization = permittedList.isEmpty()
+ final boolean isAllowedByOrganization = permittedList == null
|| permittedList.contains(imi.getPackageName())
|| enabledImis.contains(imi);
final InputMethodPreference pref = new InputMethodPreference(prefContext, imi,
diff --git a/src/com/android/settings/applications/assist/DefaultVoiceInputPicker.java b/src/com/android/settings/language/DefaultVoiceInputPicker.java
similarity index 85%
rename from src/com/android/settings/applications/assist/DefaultVoiceInputPicker.java
rename to src/com/android/settings/language/DefaultVoiceInputPicker.java
index d4ea4a9..8a73fdf 100644
--- a/src/com/android/settings/applications/assist/DefaultVoiceInputPicker.java
+++ b/src/com/android/settings/language/DefaultVoiceInputPicker.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.applications.assist;
+package com.android.settings.language;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
@@ -31,6 +31,7 @@
import java.util.ArrayList;
import java.util.List;
+/** Controls the Voice Input setting. */
public class DefaultVoiceInputPicker extends DefaultAppPickerFragment {
private VoiceInputHelper mHelper;
@@ -76,7 +77,7 @@
@Override
protected boolean setDefaultKey(String value) {
for (VoiceInputHelper.RecognizerInfo info : mHelper.mAvailableRecognizerInfos) {
- if (TextUtils.equals(value, info.key)) {
+ if (TextUtils.equals(value, info.mKey)) {
Settings.Secure.putString(getContext().getContentResolver(),
Settings.Secure.VOICE_RECOGNITION_SERVICE, value);
return true;
@@ -85,35 +86,38 @@
return true;
}
+ /** Gets the current recognition service component. */
public static ComponentName getCurrentService(VoiceInputHelper helper) {
return helper.mCurrentRecognizer;
}
+ /** Stores the info of the Voice Input provider. */
public static class VoiceInputDefaultAppInfo extends DefaultAppInfo {
public VoiceInputHelper.BaseInfo mInfo;
public VoiceInputDefaultAppInfo(Context context, PackageManager pm, int userId,
VoiceInputHelper.BaseInfo info, boolean enabled) {
- super(context, pm, userId, info.componentName, null /* summary */, enabled);
+ super(context, pm, userId, info.mComponentName, null /* summary */, enabled);
mInfo = info;
}
@Override
public String getKey() {
- return mInfo.key;
+ return mInfo.mKey;
}
@Override
public CharSequence loadLabel() {
- return mInfo.label;
+ return mInfo.mLabel;
}
+ /** Gets the setting intent. */
public Intent getSettingIntent() {
- if (mInfo.settings == null) {
+ if (mInfo.mSettings == null) {
return null;
}
- return new Intent(Intent.ACTION_MAIN).setComponent(mInfo.settings);
+ return new Intent(Intent.ACTION_MAIN).setComponent(mInfo.mSettings);
}
}
}
diff --git a/src/com/android/settings/applications/assist/DefaultVoiceInputPreferenceController.java b/src/com/android/settings/language/DefaultVoiceInputPreferenceController.java
similarity index 94%
rename from src/com/android/settings/applications/assist/DefaultVoiceInputPreferenceController.java
rename to src/com/android/settings/language/DefaultVoiceInputPreferenceController.java
index 59f5731..74c156c 100644
--- a/src/com/android/settings/applications/assist/DefaultVoiceInputPreferenceController.java
+++ b/src/com/android/settings/language/DefaultVoiceInputPreferenceController.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,13 +14,12 @@
* limitations under the License.
*/
-package com.android.settings.applications.assist;
+package com.android.settings.language;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
-import android.net.Uri;
import android.text.TextUtils;
import androidx.preference.Preference;
@@ -33,8 +32,7 @@
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
-import java.util.List;
-
+/** Controller of the Voice Input preference. */
public class DefaultVoiceInputPreferenceController extends DefaultAppPreferenceController
implements LifecycleObserver, OnResume, OnPause {
@@ -95,7 +93,7 @@
}
for (VoiceInputHelper.RecognizerInfo info : mHelper.mAvailableRecognizerInfos) {
- if (TextUtils.equals(defaultKey, info.key)) {
+ if (TextUtils.equals(defaultKey, info.mKey)) {
return new DefaultVoiceInputPicker.VoiceInputDefaultAppInfo(mContext,
mPackageManager, mUserId, info, true /* enabled */);
}
diff --git a/src/com/android/settings/language/LanguageAndInputSettings.java b/src/com/android/settings/language/LanguageAndInputSettings.java
index 58c082b..23e37ba 100644
--- a/src/com/android/settings/language/LanguageAndInputSettings.java
+++ b/src/com/android/settings/language/LanguageAndInputSettings.java
@@ -47,8 +47,9 @@
private static final String TAG = "LangAndInputSettings";
private static final String KEY_KEYBOARDS_CATEGORY = "keyboards_category";
+ private static final String KEY_SPEECH_CATEGORY = "speech_category";
private static final String KEY_TEXT_TO_SPEECH = "tts_settings_summary";
- private static final String KEY_POINTER_AND_TTS_CATEGORY = "pointer_and_tts_category";
+ private static final String KEY_POINTER_CATEGORY = "pointer_category";
@Override
public int getMetricsCategory() {
@@ -109,15 +110,22 @@
Arrays.asList(virtualKeyboardPreferenceController,
physicalKeyboardPreferenceController)));
- // Pointer and Tts
+ // Speech
+ final DefaultVoiceInputPreferenceController defaultVoiceInputPreferenceController =
+ new DefaultVoiceInputPreferenceController(context, lifecycle);
final TtsPreferenceController ttsPreferenceController =
new TtsPreferenceController(context, KEY_TEXT_TO_SPEECH);
+ controllers.add(defaultVoiceInputPreferenceController);
controllers.add(ttsPreferenceController);
+ controllers.add(new PreferenceCategoryController(context,
+ KEY_SPEECH_CATEGORY).setChildren(
+ Arrays.asList(defaultVoiceInputPreferenceController, ttsPreferenceController)));
+
+ // Pointer
final PointerSpeedController pointerController = new PointerSpeedController(context);
controllers.add(pointerController);
controllers.add(new PreferenceCategoryController(context,
- KEY_POINTER_AND_TTS_CATEGORY).setChildren(
- Arrays.asList(pointerController, ttsPreferenceController)));
+ KEY_POINTER_CATEGORY).setChildren(Arrays.asList(pointerController)));
// Input Assistance
controllers.add(new SpellCheckerPreferenceController(context));
diff --git a/src/com/android/settings/applications/assist/VoiceInputHelper.java b/src/com/android/settings/language/VoiceInputHelper.java
similarity index 77%
rename from src/com/android/settings/applications/assist/VoiceInputHelper.java
rename to src/com/android/settings/language/VoiceInputHelper.java
index 285f4f7..7915ba4 100644
--- a/src/com/android/settings/applications/assist/VoiceInputHelper.java
+++ b/src/com/android/settings/language/VoiceInputHelper.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.applications.assist;
+package com.android.settings.language;
import android.content.ComponentName;
import android.content.Context;
@@ -39,40 +39,46 @@
import java.util.Collections;
import java.util.List;
+/** Helper class of the Voice Input setting. */
public final class VoiceInputHelper {
static final String TAG = "VoiceInputHelper";
final Context mContext;
final List<ResolveInfo> mAvailableRecognition;
- // TODO: Remove this superclass as we only have 1 class now (RecognizerInfo).
- static public class BaseInfo implements Comparable {
- public final ServiceInfo service;
- public final ComponentName componentName;
- public final String key;
- public final ComponentName settings;
- public final CharSequence label;
- public final String labelStr;
- public final CharSequence appLabel;
+ /**
+ * Base info of the Voice Input provider.
+ *
+ * TODO: Remove this superclass as we only have 1 class now (RecognizerInfo).
+ */
+ public static class BaseInfo implements Comparable<BaseInfo> {
+ public final ServiceInfo mService;
+ public final ComponentName mComponentName;
+ public final String mKey;
+ public final ComponentName mSettings;
+ public final CharSequence mLabel;
+ public final String mLabelStr;
+ public final CharSequence mAppLabel;
- public BaseInfo(PackageManager pm, ServiceInfo _service, String _settings) {
- service = _service;
- componentName = new ComponentName(_service.packageName, _service.name);
- key = componentName.flattenToShortString();
- settings = _settings != null
- ? new ComponentName(_service.packageName, _settings) : null;
- label = _service.loadLabel(pm);
- labelStr = label.toString();
- appLabel = _service.applicationInfo.loadLabel(pm);
+ public BaseInfo(PackageManager pm, ServiceInfo service, String settings) {
+ mService = service;
+ mComponentName = new ComponentName(service.packageName, service.name);
+ mKey = mComponentName.flattenToShortString();
+ mSettings = settings != null
+ ? new ComponentName(service.packageName, settings) : null;
+ mLabel = service.loadLabel(pm);
+ mLabelStr = mLabel.toString();
+ mAppLabel = service.applicationInfo.loadLabel(pm);
}
@Override
- public int compareTo(Object another) {
- return labelStr.compareTo(((BaseInfo) another).labelStr);
+ public int compareTo(BaseInfo another) {
+ return mLabelStr.compareTo(another.mLabelStr);
}
}
- static public class RecognizerInfo extends BaseInfo {
+ /** Info of the speech recognizer (i.e. recognition service). */
+ public static class RecognizerInfo extends BaseInfo {
public final boolean mSelectableAsDefault;
public RecognizerInfo(PackageManager pm,
@@ -96,6 +102,7 @@
PackageManager.GET_META_DATA);
}
+ /** Draws the UI of the Voice Input picker page. */
public void buildUi() {
// Get the currently selected recognizer from the secure setting.
String currentSetting = Settings.Secure.getString(
@@ -120,8 +127,8 @@
try (XmlResourceParser parser = si.loadXmlMetaData(mContext.getPackageManager(),
RecognitionService.SERVICE_META_DATA)) {
if (parser == null) {
- throw new XmlPullParserException("No " + RecognitionService.SERVICE_META_DATA +
- " meta-data for " + si.packageName);
+ throw new XmlPullParserException("No " + RecognitionService.SERVICE_META_DATA
+ + " meta-data for " + si.packageName);
}
Resources res = mContext.getPackageManager().getResourcesForApplication(
@@ -132,6 +139,7 @@
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
+ // Intentionally do nothing.
}
String nodeName = parser.getName();
diff --git a/src/com/android/settings/notification/OWNERS b/src/com/android/settings/notification/OWNERS
index edf266e..a2ae9ce 100644
--- a/src/com/android/settings/notification/OWNERS
+++ b/src/com/android/settings/notification/OWNERS
@@ -1,4 +1,5 @@
# Default reviewers for this and subdirectories.
-asc@google.com
+beverlyt@google.com
dsandler@android.com
-juliacr@google.com
\ No newline at end of file
+juliacr@google.com
+yurilin@google.com
\ No newline at end of file
diff --git a/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java b/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java
index 2f8d58d..49f94c8 100644
--- a/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java
+++ b/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceController.java
@@ -32,14 +32,12 @@
private static final int MY_USER_ID = UserHandle.myUserId();
private final LockPatternUtils mLockPatternUtils;
- private TrustAgentManager mTrustAgentManager;
public ManageTrustAgentsPreferenceController(Context context, String key) {
super(context, key);
final SecurityFeatureProvider securityFeatureProvider = FeatureFactory.getFactory(context)
.getSecurityFeatureProvider();
mLockPatternUtils = securityFeatureProvider.getLockPatternUtils(context);
- mTrustAgentManager = securityFeatureProvider.getTrustAgentManager();
}
@Override
@@ -66,6 +64,6 @@
}
private int getTrustAgentCount() {
- return mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils).size();
+ return mLockPatternUtils.getEnabledTrustAgents(MY_USER_ID).size();
}
}
diff --git a/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java b/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java
index 8c8964f..61241d0 100644
--- a/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java
+++ b/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java
@@ -26,12 +26,14 @@
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
+import android.telephony.UiccCardInfo;
import android.telephony.UiccSlotInfo;
import android.util.Log;
import com.android.settings.network.SubscriptionUtil;
import com.android.settings.network.UiccSlotUtil;
import com.android.settings.network.UiccSlotsException;
+import com.android.settings.network.telephony.ToggleSubscriptionDialogActivity;
import com.android.settings.sim.ChooseSimActivity;
import com.android.settings.sim.DsdsDialogActivity;
import com.android.settings.sim.SimActivationNotifier;
@@ -40,6 +42,7 @@
import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -83,8 +86,8 @@
throw new IllegalStateException("Cannot be called from main thread.");
}
- if (mTelMgr.getActiveModemCount() > 1) {
- Log.i(TAG, "The device is already in DSDS mode. Do nothing.");
+ if (mTelMgr.getActiveModemCount() > 1 && !isMultipleEnabledProfilesSupported()) {
+ Log.i(TAG, "The device is already in DSDS mode and no MEP. Do nothing.");
return;
}
@@ -96,17 +99,30 @@
int lastRemovableSlotState = getLastRemovableSimSlotState(mContext);
int currentRemovableSlotState = removableSlotInfo.getCardStateInfo();
+ boolean isRemovableSimInserted =
+ lastRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_ABSENT
+ && currentRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_PRESENT;
+ boolean isRemovableSimRemoved =
+ lastRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_PRESENT
+ && currentRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_ABSENT;
// Sets the current removable slot state.
setRemovableSimSlotState(mContext, currentRemovableSlotState);
- if (lastRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_ABSENT
- && currentRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_PRESENT) {
+ if (mTelMgr.getActiveModemCount() > 1 && isMultipleEnabledProfilesSupported()) {
+ if(!isRemovableSimInserted) {
+ Log.i(TAG, "Removable Sim is not inserted in DSDS mode and MEP. Do nothing.");
+ return;
+ }
+ handleRemovableSimInsertUnderDsdsMep(removableSlotInfo);
+ return;
+ }
+
+ if (isRemovableSimInserted) {
handleSimInsert(removableSlotInfo);
return;
}
- if (lastRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_PRESENT
- && currentRemovableSlotState == UiccSlotInfo.CARD_STATE_INFO_ABSENT) {
+ if (isRemovableSimRemoved) {
handleSimRemove(removableSlotInfo);
return;
}
@@ -232,6 +248,23 @@
startChooseSimActivity(false);
}
+ private void handleRemovableSimInsertUnderDsdsMep(UiccSlotInfo removableSlotInfo) {
+ Log.i(TAG, "Handle Removable SIM inserted under DSDS+Mep.");
+
+ if (removableSlotInfo.getPorts().stream().findFirst().get().isActive()) {
+ Log.i(TAG, "The removable slot is already active. Do nothing. removableSlotInfo: "
+ + removableSlotInfo);
+ return;
+ }
+
+ List<SubscriptionInfo> subscriptionInfos = getAvailableRemovableSubscription();
+ if (subscriptionInfos == null && subscriptionInfos.get(0) != null) {
+ Log.e(TAG, "Unable to find the removable subscriptionInfo. Do nothing.");
+ return;
+ }
+ startSimConfirmDialogActivity(subscriptionInfos.get(0).getSubscriptionId());
+ }
+
private int getLastRemovableSimSlotState(Context context) {
final SharedPreferences prefs = context.getSharedPreferences(EUICC_PREFS, MODE_PRIVATE);
return prefs.getInt(KEY_REMOVABLE_SLOT_STATE, UiccSlotInfo.CARD_STATE_INFO_ABSENT);
@@ -261,7 +294,6 @@
}
for (UiccSlotInfo slotInfo : slotInfos) {
if (slotInfo != null && slotInfo.isRemovable()) {
-
return slotInfo;
}
}
@@ -297,6 +329,16 @@
.collect(Collectors.toList()));
}
+ protected List<SubscriptionInfo> getAvailableRemovableSubscription() {
+ List<SubscriptionInfo> subList = new ArrayList<>();
+ for (SubscriptionInfo info : SubscriptionUtil.getAvailableSubscriptions(mContext)) {
+ if (!info.isEmbedded()) {
+ subList.add(info);
+ }
+ }
+ return subList;
+ }
+
private void startChooseSimActivity(boolean psimInserted) {
Intent intent = ChooseSimActivity.getIntent(mContext);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -317,5 +359,25 @@
mContext.startActivity(intent);
}
+ private void startSimConfirmDialogActivity(int subId) {
+ if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
+ Log.i(TAG, "Unable to enable subscription due to invalid subscription ID.");
+ return;
+ }
+ Intent intent = ToggleSubscriptionDialogActivity.getIntent(mContext, subId, true);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivity(intent);
+ }
+
+ private boolean isMultipleEnabledProfilesSupported() {
+ List<UiccCardInfo> cardInfos = mTelMgr.getUiccCardsInfo();
+ if (cardInfos == null) {
+ Log.w(TAG, "UICC cards info list is empty.");
+ return false;
+ }
+ return cardInfos.stream().anyMatch(
+ cardInfo -> cardInfo.isMultipleEnabledProfilesSupported());
+ }
+
private SimSlotChangeHandler() {}
}
diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
index f9d0db0..e3181e3 100644
--- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
+++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java
@@ -435,9 +435,9 @@
mDataUsageSummaryPref = screen.findPreference(KEY_DATA_USAGE_HEADER);
mDataUsageSummaryPref.setVisible(true);
mSummaryHeaderController =
- new WifiDataUsageSummaryPreferenceController(mFragment.getActivity(),
- mLifecycle, (PreferenceFragmentCompat) mFragment,
- mWifiEntry.getTitle());
+ new WifiDataUsageSummaryPreferenceController(mFragment.getActivity(),
+ mLifecycle, (PreferenceFragmentCompat) mFragment,
+ mWifiEntry.getWifiConfiguration().getAllNetworkKeys());
return;
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java
index 06a046b..ea0f317 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java
@@ -40,6 +40,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.FragmentActivity;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
@@ -53,6 +54,7 @@
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
@@ -92,6 +94,7 @@
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
when(mFragment.getContext()).thenReturn(mContext);
+ when(mFragment.getActivity()).thenReturn(Robolectric.setupActivity(FragmentActivity.class));
mScreen = spy(new PreferenceScreen(mContext, null));
when(mScreen.getPreferenceManager()).thenReturn(mPreferenceManager);
doReturn(mScreen).when(mFragment).getPreferenceScreen();
diff --git a/tests/robotests/src/com/android/settings/accessibility/AudioDescriptionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/AudioDescriptionPreferenceControllerTest.java
new file mode 100644
index 0000000..1d3ffa8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/AudioDescriptionPreferenceControllerTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2022 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.android.settings.accessibility.AccessibilityUtil.State.OFF;
+import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.core.BasePreferenceController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+
+@RunWith(RobolectricTestRunner.class)
+public class AudioDescriptionPreferenceControllerTest {
+
+ private static final String KEY_AUDIO_DESCRIPTION =
+ Settings.Secure.ENABLED_ACCESSIBILITY_AUDIO_DESCRIPTION_BY_DEFAULT;
+ private static final int UNKNOWN = -1;
+
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ private final SwitchPreference mSwitchPreference = spy(new SwitchPreference(mContext));
+ private final AudioDescriptionPreferenceController mController =
+ new AudioDescriptionPreferenceController(mContext,
+ AudioDescriptionPreferenceController.PREF_KEY);
+
+ @Before
+ public void setUp() {
+ final PreferenceManager preferenceManager = new PreferenceManager(mContext);
+ final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
+ mSwitchPreference.setKey(AudioDescriptionPreferenceController.PREF_KEY);
+ screen.addPreference(mSwitchPreference);
+ mController.displayPreference(screen);
+ }
+
+ @Test
+ public void getAvailabilityStatus_byDefault_shouldReturnAvailable() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.AVAILABLE);
+ }
+
+ @Test
+ public void isChecked_disableAudioDescription_onResumeShouldReturnFalse() {
+ Settings.Secure.putInt(mContext.getContentResolver(), KEY_AUDIO_DESCRIPTION, OFF);
+
+ mController.updateState(mSwitchPreference);
+
+ assertThat(mController.isChecked()).isFalse();
+ assertThat(mSwitchPreference.isChecked()).isFalse();
+ }
+
+ @Test
+ public void isChecked_enableAudioDescription_onResumeShouldReturnTrue() {
+ Settings.Secure.putInt(mContext.getContentResolver(), KEY_AUDIO_DESCRIPTION, ON);
+
+ mController.updateState(mSwitchPreference);
+
+ assertThat(mController.isChecked()).isTrue();
+ assertThat(mSwitchPreference.isChecked()).isTrue();
+ }
+
+ @Test
+ public void performClick_enableAudioDescription_shouldReturnTrue() {
+ Settings.Secure.putInt(mContext.getContentResolver(), KEY_AUDIO_DESCRIPTION, OFF);
+
+ mController.updateState(mSwitchPreference);
+
+ mSwitchPreference.performClick();
+
+ verify(mSwitchPreference).setChecked(true);
+ assertThat(mController.isChecked()).isTrue();
+ assertThat(mSwitchPreference.isChecked()).isTrue();
+ }
+
+ @Test
+ public void performClick_disableAudioDescription_shouldReturnFalse() {
+ Settings.Secure.putInt(mContext.getContentResolver(), KEY_AUDIO_DESCRIPTION, ON);
+
+ mController.updateState(mSwitchPreference);
+
+ mSwitchPreference.performClick();
+
+ verify(mSwitchPreference).setChecked(false);
+ assertThat(mController.isChecked()).isFalse();
+ assertThat(mSwitchPreference.isChecked()).isFalse();
+ }
+
+ @Test
+ public void setChecked_setFalse_shouldDisableAudioDescription() {
+ mController.setChecked(false);
+
+ assertThat(Settings.Secure.getInt(
+ mContext.getContentResolver(), KEY_AUDIO_DESCRIPTION, UNKNOWN)).isEqualTo(OFF);
+ }
+
+ @Test
+ public void setChecked_setTrue_shouldEnableAudioDescription() {
+ mController.setChecked(true);
+
+ assertThat(Settings.Secure.getInt(
+ mContext.getContentResolver(), KEY_AUDIO_DESCRIPTION, UNKNOWN)).isEqualTo(ON);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/DisplaySizeDataTest.java b/tests/robotests/src/com/android/settings/accessibility/DisplaySizeDataTest.java
new file mode 100644
index 0000000..fabf123
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/DisplaySizeDataTest.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2022 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 android.content.Context;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+/**
+ * Tests for {@link DisplaySizeData}.
+ */
+@RunWith(RobolectricTestRunner.class)
+public class DisplaySizeDataTest {
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ private DisplaySizeData mDisplaySizeData;
+
+ @Before
+ public void setUp() {
+ mDisplaySizeData = new DisplaySizeData(mContext);
+ }
+
+ @Ignore("Ignore it since a NPE is happened in ShadowWindowManagerGlobal. (Ref. b/214161063)")
+ @Test
+ public void commit_success() {
+ final int progress = 4;
+
+ mDisplaySizeData.commit(progress);
+ final float density = mContext.getResources().getDisplayMetrics().density;
+
+ assertThat(density).isEqualTo(mDisplaySizeData.getValues().get(progress));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/FontSizeDataTest.java b/tests/robotests/src/com/android/settings/accessibility/FontSizeDataTest.java
new file mode 100644
index 0000000..7e35714
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/FontSizeDataTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2022 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 android.content.Context;
+import android.provider.Settings;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+/**
+ * Tests for {@link FontSizeData}.
+ */
+@RunWith(RobolectricTestRunner.class)
+public class FontSizeDataTest {
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ private FontSizeData mFontSizeData;
+
+ @Before
+ public void setUp() {
+ mFontSizeData = new FontSizeData(mContext);
+ }
+
+ @Test
+ public void commit_success() {
+ final int progress = 3;
+
+ mFontSizeData.commit(progress);
+ final float currentScale =
+ Settings.System.getFloat(mContext.getContentResolver(), Settings.System.FONT_SCALE,
+ /* def= */ 1.0f);
+
+ assertThat(currentScale).isEqualTo(mFontSizeData.getValues().get(progress));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragmentTest.java
index 0c656b3..c44352f 100644
--- a/tests/robotests/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragmentTest.java
@@ -83,9 +83,8 @@
}
@Test
- public void getTileName_noTileServiceAssigned_noMatchString() {
- final CharSequence tileName = mFragment.getTileName();
- assertThat(tileName.toString()).isEqualTo("");
+ public void getTileName_noTileServiceAssigned_returnNull() {
+ assertThat(mFragment.getTileName()).isNull();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/accessibility/PreviewSizeSeekBarControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/PreviewSizeSeekBarControllerTest.java
new file mode 100644
index 0000000..d33d80e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/PreviewSizeSeekBarControllerTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2022 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.anyString;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.widget.LabeledSeekBarPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+/**
+ * Tests for {@link PreviewSizeSeekBarController}.
+ */
+@RunWith(RobolectricTestRunner.class)
+public class PreviewSizeSeekBarControllerTest {
+ private static final String FONT_SIZE_KEY = "font_size";
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ private PreviewSizeSeekBarController mSeekBarController;
+ private FontSizeData mFontSizeData;
+ private LabeledSeekBarPreference mSeekBarPreference;
+
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mFontSizeData = new FontSizeData(mContext);
+
+ mSeekBarController =
+ new PreviewSizeSeekBarController(mContext, FONT_SIZE_KEY, mFontSizeData);
+
+ mSeekBarPreference = spy(new LabeledSeekBarPreference(mContext, /* attrs= */ null));
+ when(mPreferenceScreen.findPreference(anyString())).thenReturn(mSeekBarPreference);
+ }
+
+ @Test
+ public void initMax_matchResult() {
+ when(mPreferenceScreen.findPreference(anyString())).thenReturn(mSeekBarPreference);
+
+ mSeekBarController.displayPreference(mPreferenceScreen);
+
+ assertThat(mSeekBarPreference.getMax()).isEqualTo(
+ mFontSizeData.getValues().size() - 1);
+ }
+
+ @Test
+ public void initProgress_matchResult() {
+ when(mPreferenceScreen.findPreference(anyString())).thenReturn(mSeekBarPreference);
+
+ mSeekBarController.displayPreference(mPreferenceScreen);
+
+ verify(mSeekBarPreference).setProgress(mFontSizeData.getInitialIndex());
+ }
+
+ @Test
+ public void resetToDefaultState_matchResult() {
+ final int defaultProgress =
+ mFontSizeData.getValues().indexOf(mFontSizeData.getDefaultValue());
+ when(mPreferenceScreen.findPreference(anyString())).thenReturn(mSeekBarPreference);
+
+ mSeekBarController.displayPreference(mPreferenceScreen);
+ mSeekBarPreference.setProgress(defaultProgress + 1);
+ mSeekBarController.resetState();
+
+ assertThat(mSeekBarPreference.getProgress()).isEqualTo(defaultProgress);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewControllerTest.java
new file mode 100644
index 0000000..b630509
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewControllerTest.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2022 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 org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.display.PreviewPagerAdapter;
+import com.android.settings.widget.LabeledSeekBarPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowChoreographer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for {@link TextReadingPreviewController}.
+ */
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowChoreographer.class)
+public class TextReadingPreviewControllerTest {
+ private static final String PREVIEW_KEY = "preview";
+ private static final String FONT_SIZE_KEY = "font_size";
+ private static final String DISPLAY_SIZE_KEY = "display_size";
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ private TextReadingPreviewController mPreviewController;
+ private TextReadingPreviewPreference mPreviewPreference;
+ private LabeledSeekBarPreference mFontSizePreference;
+ private LabeledSeekBarPreference mDisplaySizePreference;
+
+ @Mock
+ private DisplaySizeData mDisplaySizeData;
+
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ final FontSizeData fontSizeData = new FontSizeData(mContext);
+ final List<Integer> displayData = createFakeDisplayData();
+ when(mDisplaySizeData.getValues()).thenReturn(displayData);
+ mPreviewPreference = spy(new TextReadingPreviewPreference(mContext, /* attr= */ null));
+ mPreviewController = new TextReadingPreviewController(mContext, PREVIEW_KEY, fontSizeData,
+ mDisplaySizeData);
+ mFontSizePreference = new LabeledSeekBarPreference(mContext, /* attr= */ null);
+ mDisplaySizePreference = new LabeledSeekBarPreference(mContext, /* attr= */ null);
+ }
+
+ @Test
+ public void initPreviewerAdapter_verifyAction() {
+ when(mPreferenceScreen.findPreference(PREVIEW_KEY)).thenReturn(mPreviewPreference);
+ when(mPreferenceScreen.findPreference(FONT_SIZE_KEY)).thenReturn(mFontSizePreference);
+ when(mPreferenceScreen.findPreference(DISPLAY_SIZE_KEY)).thenReturn(mDisplaySizePreference);
+
+ mPreviewController.displayPreference(mPreferenceScreen);
+
+ verify(mPreviewPreference).setPreviewAdapter(any(PreviewPagerAdapter.class));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void initPreviewerAdapterWithoutDisplaySizePreference_throwNPE() {
+ when(mPreferenceScreen.findPreference(PREVIEW_KEY)).thenReturn(mPreviewPreference);
+ when(mPreferenceScreen.findPreference(DISPLAY_SIZE_KEY)).thenReturn(mDisplaySizePreference);
+
+ mPreviewController.displayPreference(mPreferenceScreen);
+
+ verify(mPreviewPreference).setPreviewAdapter(any(PreviewPagerAdapter.class));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void initPreviewerAdapterWithoutFontSizePreference_throwNPE() {
+ when(mPreferenceScreen.findPreference(PREVIEW_KEY)).thenReturn(mPreviewPreference);
+ when(mPreferenceScreen.findPreference(FONT_SIZE_KEY)).thenReturn(mFontSizePreference);
+
+ mPreviewController.displayPreference(mPreferenceScreen);
+
+ verify(mPreviewPreference).setPreviewAdapter(any(PreviewPagerAdapter.class));
+ }
+
+ private List<Integer> createFakeDisplayData() {
+ final List<Integer> list = new ArrayList<>();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+
+ return list;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java
index 6b9395a..3dc82da 100644
--- a/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java
@@ -16,8 +16,16 @@
package com.android.settings.accessibility;
+import static com.android.settings.accessibility.TextReadingPreviewController.PREVIEW_SAMPLE_RES_IDS;
+
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
import android.content.Context;
import android.content.res.Configuration;
import android.view.LayoutInflater;
@@ -50,12 +58,11 @@
@Before
public void setUp() {
final Context context = ApplicationProvider.getApplicationContext();
- final int[] sampleResIds = new int[]{1, 2, 3, 4, 5, 6};
- final Configuration[] configurations = createConfigurations(6);
+ final Configuration[] configurations = createConfigurations(PREVIEW_SAMPLE_RES_IDS.length);
mTextReadingPreviewPreference = new TextReadingPreviewPreference(context);
mPreviewPagerAdapter =
- new PreviewPagerAdapter(context, /* isLayoutRtl= */ false, sampleResIds,
- configurations);
+ spy(new PreviewPagerAdapter(context, /* isLayoutRtl= */ false,
+ PREVIEW_SAMPLE_RES_IDS, configurations));
final LayoutInflater inflater = LayoutInflater.from(context);
final View view =
inflater.inflate(mTextReadingPreviewPreference.getLayoutResource(),
@@ -87,7 +94,7 @@
@Test
public void setCurrentItem_success() {
- final int currentItem = 3;
+ final int currentItem = 1;
mTextReadingPreviewPreference.setPreviewAdapter(mPreviewPagerAdapter);
mTextReadingPreviewPreference.onBindViewHolder(mHolder);
@@ -104,6 +111,24 @@
mTextReadingPreviewPreference.setCurrentItem(currentItem);
}
+ @Test(expected = NullPointerException.class)
+ public void updatePagerWithoutPreviewAdapter_throwNPE() {
+ final int index = 1;
+
+ mTextReadingPreviewPreference.notifyPreviewPagerChanged(index);
+ }
+
+ @Test
+ public void notifyPreviewPager_setPreviewLayer() {
+ final int index = 2;
+ mTextReadingPreviewPreference.setPreviewAdapter(mPreviewPagerAdapter);
+ mTextReadingPreviewPreference.onBindViewHolder(mHolder);
+
+ mTextReadingPreviewPreference.notifyPreviewPagerChanged(index);
+
+ verify(mPreviewPagerAdapter).setPreviewLayer(eq(index), anyInt(), anyInt(), anyBoolean());
+ }
+
private static Configuration[] createConfigurations(int count) {
final Configuration[] configurations = new Configuration[count];
for (int i = 0; i < count; i++) {
diff --git a/tests/robotests/src/com/android/settings/accessibility/TextReadingResetControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/TextReadingResetControllerTest.java
new file mode 100644
index 0000000..2ae8e24
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/TextReadingResetControllerTest.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2022 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.android.settings.accessibility.TextReadingResetController.ResetStateListener;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.view.View;
+
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.widget.LayoutPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for {@link TextReadingResetController}.
+ */
+@RunWith(RobolectricTestRunner.class)
+public class TextReadingResetControllerTest {
+ private static final String TEST_KEY = "test";
+ private static final String RESET_KEY = "reset";
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+ private final View mResetView = new View(mContext);
+ private final List<ResetStateListener> mListeners = new ArrayList<>();
+ private TextReadingResetController mResetController;
+ private TestPreferenceController mPreferenceController;
+
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+
+ @Mock
+ private LayoutPreference mLayoutPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mPreferenceController = new TestPreferenceController(mContext, TEST_KEY);
+ mListeners.add(mPreferenceController);
+ mResetController = new TextReadingResetController(mContext, RESET_KEY, mListeners);
+ }
+
+ @Test
+ public void setClickListener_success() {
+ setupResetButton();
+
+ mResetController.displayPreference(mPreferenceScreen);
+
+ assertThat(mResetView.hasOnClickListeners()).isTrue();
+ }
+
+ @Test
+ public void triggerResetState_success() {
+ setupResetButton();
+
+ mResetController.displayPreference(mPreferenceScreen);
+ mResetView.callOnClick();
+
+ assertThat(mPreferenceController.isReset()).isTrue();
+ }
+
+ private void setupResetButton() {
+ when(mPreferenceScreen.findPreference(RESET_KEY)).thenReturn(mLayoutPreference);
+ when(mLayoutPreference.findViewById(R.id.reset_button)).thenReturn(mResetView);
+ }
+
+ private static class TestPreferenceController extends BasePreferenceController implements
+ ResetStateListener {
+ private boolean mIsReset = false;
+
+ TestPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public void resetState() {
+ mIsReset = true;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ boolean isReset() {
+ return mIsReset;
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragmentTest.java
index db5b83c..236f9f2 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragmentTest.java
@@ -83,9 +83,8 @@
}
@Test
- public void getTileName_noTileServiceAssigned_noMatchString() {
- final CharSequence tileName = mFragment.getTileName();
- assertThat(tileName.toString()).isEqualTo("");
+ public void getTileName_noTileServiceAssigned_returnNull() {
+ assertThat(mFragment.getTileName()).isNull();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java
index 2cec3d1..b6401cf 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppInfoDashboardFragmentTest.java
@@ -16,6 +16,7 @@
package com.android.settings.applications.appinfo;
+import static com.android.settings.applications.appinfo.AppInfoDashboardFragment.ACCESS_RESTRICTED_SETTINGS;
import static com.android.settings.applications.appinfo.AppInfoDashboardFragment.ARG_PACKAGE_NAME;
import static com.android.settings.applications.appinfo.AppInfoDashboardFragment.UNINSTALL_ALL_USERS_MENU;
import static com.android.settings.applications.appinfo.AppInfoDashboardFragment.UNINSTALL_UPDATES;
@@ -165,8 +166,10 @@
Menu menu = mock(Menu.class);
final MenuItem uninstallUpdatesMenuItem = mock(MenuItem.class);
final MenuItem uninstallForAllMenuItem = mock(MenuItem.class);
+ final MenuItem accessRestrictedMenuItem = mock(MenuItem.class);
when(menu.findItem(UNINSTALL_UPDATES)).thenReturn(uninstallUpdatesMenuItem);
when(menu.findItem(UNINSTALL_ALL_USERS_MENU)).thenReturn(uninstallForAllMenuItem);
+ when(menu.findItem(ACCESS_RESTRICTED_SETTINGS)).thenReturn(accessRestrictedMenuItem);
// Setup work to prevent NPE
final ApplicationInfo info = new ApplicationInfo();
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingServiceTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingServiceTest.java
index e73b447..3194e55 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingServiceTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingServiceTest.java
@@ -106,7 +106,7 @@
mBluetoothPairingService.onStartCommand(intent, /* flags */ 0, /* startId */ 0);
- verify(mDevice).cancelPairing();
+ verify(mDevice).cancelBondProcess();
verify(mNm).cancel(mBluetoothPairingService.NOTIFICATION_ID);
}
diff --git a/tests/robotests/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceControllerTest.java
new file mode 100644
index 0000000..711f6d7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceControllerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2022 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.datausage;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+import android.net.NetworkPolicyManager;
+import android.telephony.TelephonyManager;
+
+import androidx.fragment.app.FragmentActivity;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.net.DataUsageController;
+
+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;
+
+import java.util.HashSet;
+import java.util.Set;
+
+@RunWith(RobolectricTestRunner.class)
+public class WifiDataUsageSummaryPreferenceControllerTest {
+
+ @Rule
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Spy
+ Context mContext = ApplicationProvider.getApplicationContext();
+ @Mock
+ FragmentActivity mActivity;
+ @Mock
+ Lifecycle mLifecycle;
+ @Mock
+ TelephonyManager mTelephonyManager;
+ @Mock
+ NetworkPolicyManager mNetworkPolicyManager;
+ @Mock
+ DataUsageSummaryPreference mSummaryPreference;
+ @Mock
+ DataUsageController mDataUsageController;
+ @Mock
+ DataUsageController.DataUsageInfo mDataUsageInfo;
+
+ WifiDataUsageSummaryPreferenceController mController;
+ Set<String> mAllNetworkKeys = new HashSet<>();
+
+ @Before
+ public void setUp() {
+ doReturn(mContext.getResources()).when(mActivity).getResources();
+ doReturn(mTelephonyManager).when(mActivity).getSystemService(TelephonyManager.class);
+ doReturn(mNetworkPolicyManager).when(mActivity)
+ .getSystemService(NetworkPolicyManager.class);
+ doNothing().when(mSummaryPreference).setWifiMode(anyBoolean(), anyString(), anyBoolean());
+ doReturn(mDataUsageInfo).when(mDataUsageController).getDataUsageInfo(any());
+
+ mController = spy(new WifiDataUsageSummaryPreferenceController(mActivity, mLifecycle, null,
+ mAllNetworkKeys));
+ doReturn(mDataUsageController).when(mController).createDataUsageController(any());
+ }
+
+ @Test
+ public void updateState_nullOfDataUsageController_shouldNotCrash() {
+ mController.mDataUsageController = null;
+
+ mController.updateState(mSummaryPreference);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerBaseTest.java
index 8d5e4da..59e9e3c 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AdminActionPreferenceControllerBaseTest.java
@@ -18,13 +18,15 @@
import static com.google.common.truth.Truth.assertThat;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
-
-import java.util.Date;
import org.robolectric.RobolectricTestRunner;
+import java.util.Date;
+
@RunWith(RobolectricTestRunner.class)
+@Ignore
public class AdminActionPreferenceControllerBaseTest
extends AdminActionPreferenceControllerTestBase {
diff --git a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java
index 2ff9d17..018a64a 100644
--- a/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/AlwaysOnVpnCurrentUserPreferenceControllerTest.java
@@ -28,6 +28,7 @@
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -36,6 +37,7 @@
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
+@Ignore
public final class AlwaysOnVpnCurrentUserPreferenceControllerTest {
private static final String VPN_SET_DEVICE = "VPN set";
diff --git a/tests/robotests/src/com/android/settings/enterprise/BugReportsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/BugReportsPreferenceControllerTest.java
index 34853c6..0b5261b 100644
--- a/tests/robotests/src/com/android/settings/enterprise/BugReportsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/BugReportsPreferenceControllerTest.java
@@ -20,6 +20,7 @@
import static org.mockito.Mockito.when;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -27,6 +28,7 @@
import java.util.Date;
@RunWith(RobolectricTestRunner.class)
+@Ignore
public class BugReportsPreferenceControllerTest
extends AdminActionPreferenceControllerTestBase {
diff --git a/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java
index 799dd7e..130b3b9 100644
--- a/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/CaCertsCurrentUserPreferenceControllerTest.java
@@ -25,11 +25,13 @@
import com.android.settings.R;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
+@Ignore
public class CaCertsCurrentUserPreferenceControllerTest
extends CaCertsPreferenceControllerTestBase {
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
index e3f58f4..2b64c19 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
@@ -50,6 +50,7 @@
import com.google.common.collect.ImmutableList;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
@@ -139,6 +140,7 @@
}
@Test
+ @Ignore
public void testGetDeviceOwnerDisclosure() {
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
assertThat(mProvider.getDeviceOwnerDisclosure()).isNull();
diff --git a/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
index facdce5..dc9fb0c 100644
--- a/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/ImePreferenceControllerTest.java
@@ -28,6 +28,7 @@
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -58,6 +59,7 @@
}
@Test
+ @Ignore
public void testUpdateState() {
final Preference preference = new Preference(mContext, null, 0, 0);
diff --git a/tests/robotests/src/com/android/settings/enterprise/NetworkLogsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/NetworkLogsPreferenceControllerTest.java
index 89c208c..466ec0e 100644
--- a/tests/robotests/src/com/android/settings/enterprise/NetworkLogsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/NetworkLogsPreferenceControllerTest.java
@@ -20,13 +20,15 @@
import static org.mockito.Mockito.when;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
-
-import java.util.Date;
import org.robolectric.RobolectricTestRunner;
+import java.util.Date;
+
@RunWith(RobolectricTestRunner.class)
+@Ignore
public class NetworkLogsPreferenceControllerTest extends AdminActionPreferenceControllerTestBase {
@Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/PrivacyPreferenceControllerHelperTest.java b/tests/robotests/src/com/android/settings/enterprise/PrivacyPreferenceControllerHelperTest.java
index cbd6392e..e8a9e17 100644
--- a/tests/robotests/src/com/android/settings/enterprise/PrivacyPreferenceControllerHelperTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/PrivacyPreferenceControllerHelperTest.java
@@ -33,6 +33,7 @@
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -73,6 +74,7 @@
}
@Test
+ @Ignore
public void testUpdateState_noDeviceOwnerName_useGenericPreferenceSummary() {
final Preference preference = new Preference(mContext, null, 0, 0);
when(mContext.getString(R.string.enterprise_privacy_settings_summary_generic))
@@ -86,6 +88,7 @@
}
@Test
+ @Ignore
public void testUpdateState_deviceOwnerName_usePreferenceSummaryWithDeviceOwnerName() {
final Preference preference = new Preference(mContext, null, 0, 0);
when(mContext.getResources().getString(
diff --git a/tests/robotests/src/com/android/settings/enterprise/SecurityLogsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/enterprise/SecurityLogsPreferenceControllerTest.java
index 8612ee7..98bc82b 100644
--- a/tests/robotests/src/com/android/settings/enterprise/SecurityLogsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/SecurityLogsPreferenceControllerTest.java
@@ -20,13 +20,15 @@
import static org.mockito.Mockito.when;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
-
-import java.util.Date;
import org.robolectric.RobolectricTestRunner;
+import java.util.Date;
+
@RunWith(RobolectricTestRunner.class)
+@Ignore
public class SecurityLogsPreferenceControllerTest extends AdminActionPreferenceControllerTestBase {
@Override
diff --git a/tests/robotests/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragmentTest.java b/tests/robotests/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragmentTest.java
index c6c6a66..c6e7a97 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/AvailableVirtualKeyboardFragmentTest.java
@@ -20,7 +20,9 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -31,6 +33,7 @@
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
+import android.os.UserHandle;
import android.provider.SearchIndexableResource;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@@ -43,6 +46,7 @@
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.testutils.shadow.ShadowInputMethodManagerWithMethodList;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
+import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settingslib.inputmethod.InputMethodPreference;
import com.android.settingslib.inputmethod.InputMethodSettingValuesWrapper;
@@ -62,7 +66,8 @@
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowSecureSettings.class,
- ShadowInputMethodManagerWithMethodList.class
+ ShadowInputMethodManagerWithMethodList.class,
+ ShadowUserManager.class
})
public class AvailableVirtualKeyboardFragmentTest {
@@ -170,6 +175,7 @@
when(mFragment.getPreferenceScreen()).thenReturn(mPreferenceScreen);
when(mPreferenceManager.getContext()).thenReturn(mContext);
when(mContext.getSystemService(InputMethodManager.class)).thenReturn(mInputMethodManager);
+ doReturn(mContext).when(mContext).createContextAsUser(any(UserHandle.class), anyInt());
}
private List<InputMethodInfo> createFakeInputMethodInfoList(final String name, int num) {
diff --git a/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
index 8a81908..bf4811b 100644
--- a/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/EthernetTetherPreferenceControllerTest.java
@@ -31,6 +31,7 @@
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -72,6 +73,7 @@
}
@Test
+ @Ignore
public void lifecycle_shouldRegisterReceiverOnStart() {
mController.onStart();
diff --git a/tests/robotests/src/com/android/settings/security/ChangeScreenLockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/ChangeScreenLockPreferenceControllerTest.java
index 9913e55..bf9606d 100644
--- a/tests/robotests/src/com/android/settings/security/ChangeScreenLockPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/ChangeScreenLockPreferenceControllerTest.java
@@ -40,6 +40,7 @@
import com.android.settings.widget.GearPreference;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -50,6 +51,7 @@
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowUtils.class)
+@Ignore
public class ChangeScreenLockPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java
index 29a62ea..72bdd39 100644
--- a/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/trustagent/ManageTrustAgentsPreferenceControllerTest.java
@@ -21,13 +21,13 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;
+import android.content.ComponentName;
import android.content.Context;
import androidx.preference.Preference;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
-import com.android.settings.security.trustagent.TrustAgentManager.TrustAgentComponentInfo;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -46,8 +46,6 @@
public class ManageTrustAgentsPreferenceControllerTest {
@Mock
- private TrustAgentManager mTrustAgentManager;
- @Mock
private LockPatternUtils mLockPatternUtils;
private FakeFeatureFactory mFeatureFactory;
@@ -62,8 +60,6 @@
mFeatureFactory = FakeFeatureFactory.setupForTest();
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(mLockPatternUtils);
- when(mFeatureFactory.securityFeatureProvider.getTrustAgentManager())
- .thenReturn(mTrustAgentManager);
mController = new ManageTrustAgentsPreferenceController(mContext, "key");
mPreference = new Preference(mContext);
mPreference.setKey(mController.getPreferenceKey());
@@ -94,8 +90,7 @@
@Test
public void updateState_isSecure_noTrustAgent_shouldShowGenericSummary() {
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
- when(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils))
- .thenReturn(new ArrayList<>());
+ when(mLockPatternUtils.getEnabledTrustAgents(anyInt())).thenReturn(new ArrayList<>());
mController.updateState(mPreference);
@@ -107,8 +102,8 @@
@Test
public void updateState_isSecure_hasTrustAgent_shouldShowDetailedSummary() {
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
- when(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils))
- .thenReturn(Collections.singletonList(new TrustAgentComponentInfo()));
+ when(mLockPatternUtils.getEnabledTrustAgents(anyInt())).thenReturn(
+ Collections.singletonList(new ComponentName("packageName", "className")));
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java
index 20547d7..74e3971 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java
@@ -40,7 +40,7 @@
private static Map<Integer, Integer> sUserToProfileComplexityMap = new HashMap<>();
private static Map<Integer, PasswordMetrics> sUserToMetricsMap = new HashMap<>();
private static Map<Integer, PasswordMetrics> sUserToProfileMetricsMap = new HashMap<>();
-
+ private static Map<Integer, Boolean> sUserToIsSecureMap = new HashMap<>();
@Resetter
public static void reset() {
@@ -48,6 +48,7 @@
sUserToProfileComplexityMap.clear();
sUserToMetricsMap.clear();
sUserToProfileMetricsMap.clear();
+ sUserToIsSecureMap.clear();
sDeviceEncryptionEnabled = false;
}
@@ -57,8 +58,16 @@
}
@Implementation
- protected boolean isSecure(int id) {
- return true;
+ protected boolean isSecure(int userId) {
+ Boolean isSecure = sUserToIsSecureMap.get(userId);
+ if (isSecure == null) {
+ return true;
+ }
+ return isSecure;
+ }
+
+ public static void setIsSecure(int userId, boolean isSecure) {
+ sUserToIsSecureMap.put(userId, isSecure);
}
@Implementation
@@ -144,4 +153,13 @@
sUserToProfileMetricsMap.put(UserHandle.myUserId(), metrics);
}
+ @Implementation
+ public boolean isLockScreenDisabled(int userId) {
+ return false;
+ }
+
+ @Implementation
+ public boolean isSeparateProfileChallengeEnabled(int userHandle) {
+ return false;
+ }
}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
index dc42515..ea51370 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowUserManager.java
@@ -44,6 +44,8 @@
private static boolean sIsSupportsMultipleUsers;
+ private static final int PRIMARY_USER_ID = 0;
+
private final List<String> mBaseRestrictions = new ArrayList<>();
private final List<String> mGuestRestrictions = new ArrayList<>();
private final Map<String, List<EnforcingUser>> mRestrictionSources = new HashMap<>();
@@ -218,4 +220,10 @@
mEnabledTypes.remove(type);
}
}
+
+ @Implementation
+ protected UserInfo getPrimaryUser() {
+ return new UserInfo(PRIMARY_USER_ID, null, null,
+ UserInfo.FLAG_INITIALIZED | UserInfo.FLAG_ADMIN | UserInfo.FLAG_PRIMARY);
+ }
}
diff --git a/tests/unit/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceControllerTest.java b/tests/unit/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceControllerTest.java
index 7f4048d..e3d2408 100644
--- a/tests/unit/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/accessibility/FontWeightAdjustmentPreferenceControllerTest.java
@@ -31,6 +31,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+/**
+ * Tests for {@link FontWeightAdjustmentPreferenceController}.
+ */
@RunWith(AndroidJUnit4.class)
public class FontWeightAdjustmentPreferenceControllerTest {
private static final int ON = FontWeightAdjustmentPreferenceController.BOLD_TEXT_ADJUSTMENT;
@@ -91,4 +94,14 @@
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(OFF);
}
+
+ @Test
+ public void resetState_shouldDisableBoldText() {
+ mController.setChecked(true);
+
+ mController.resetState();
+
+ assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(OFF);
+ }
}
diff --git a/tests/unit/src/com/android/settings/accessibility/HighTextContrastPreferenceControllerTest.java b/tests/unit/src/com/android/settings/accessibility/HighTextContrastPreferenceControllerTest.java
index 6250fef..1ada051 100644
--- a/tests/unit/src/com/android/settings/accessibility/HighTextContrastPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/accessibility/HighTextContrastPreferenceControllerTest.java
@@ -31,6 +31,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+/**
+ * Tests for {@link HighTextContrastPreferenceController}.
+ */
@RunWith(AndroidJUnit4.class)
public class HighTextContrastPreferenceControllerTest {
@@ -93,4 +96,14 @@
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, UNKNOWN)).isEqualTo(OFF);
}
+
+ @Test
+ public void resetState_shouldDisableTextContrast() {
+ mController.setChecked(true);
+
+ mController.resetState();
+
+ assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, UNKNOWN)).isEqualTo(OFF);
+ }
}
diff --git a/tests/unit/src/com/android/settings/notification/OWNERS b/tests/unit/src/com/android/settings/notification/OWNERS
new file mode 100644
index 0000000..a2ae9ce
--- /dev/null
+++ b/tests/unit/src/com/android/settings/notification/OWNERS
@@ -0,0 +1,5 @@
+# Default reviewers for this and subdirectories.
+beverlyt@google.com
+dsandler@android.com
+juliacr@google.com
+yurilin@google.com
\ No newline at end of file