Snap for 7135444 from 2b9f139a2d to sc-v2-release
Change-Id: Id1d096fb8ebf94bdf1664af97d0839999ce0493f
This commit is contained in:
@@ -954,7 +954,7 @@
|
|||||||
<category android:name="com.android.settings.SHORTCUT" />
|
<category android:name="com.android.settings.SHORTCUT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
android:value="com.android.settings.DisplaySettings" />
|
android:value="@string/rotate_settings_class" />
|
||||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
||||||
android:value="true" />
|
android:value="true" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|||||||
@@ -2669,6 +2669,54 @@
|
|||||||
column="13"/>
|
column="13"/>
|
||||||
</issue>
|
</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/homepage_generic_icon_background" />"
|
||||||
|
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||||
|
<location
|
||||||
|
file="res/drawable/ic_network_signal_blue.xml"
|
||||||
|
line="23"
|
||||||
|
column="11"/>
|
||||||
|
</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/homepage_generic_icon_background" />"
|
||||||
|
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||||
|
<location
|
||||||
|
file="res/drawable/ic_network_signal_blue.xml"
|
||||||
|
line="25"
|
||||||
|
column="11"/>
|
||||||
|
</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/homepage_generic_icon_background" />"
|
||||||
|
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||||
|
<location
|
||||||
|
file="res/drawable/ic_network_signal_blue.xml"
|
||||||
|
line="27"
|
||||||
|
column="11"/>
|
||||||
|
</issue>
|
||||||
|
|
||||||
<issue
|
<issue
|
||||||
id="HardCodedColor"
|
id="HardCodedColor"
|
||||||
severity="Error"
|
severity="Error"
|
||||||
|
|||||||
@@ -13,25 +13,17 @@
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:width="32dp"
|
android:width="32dp"
|
||||||
android:height="32dp"
|
android:height="32dp"
|
||||||
android:viewportWidth="32"
|
android:viewportWidth="32"
|
||||||
android:viewportHeight="32">
|
android:viewportHeight="32">
|
||||||
|
|
||||||
<path
|
<path android:pathData="M 0 0 H 32 V 32 H 0 V 0 Z" />
|
||||||
android:pathData="M 0 0 H 32 V 32 H 0 V 0 Z" />
|
<path android:fillColor="@color/homepage_generic_icon_background"
|
||||||
<path
|
android:pathData="M24,5.33h1.33c0.74,0,1.33,0.6,1.33,1.33v18.67c0,0.74-0.6,1.33-1.33,1.33H24c-0.74,0-1.33-0.6-1.33-1.33V6.67C22.67,5.93,23.26,5.33,24,5.33z" />
|
||||||
android:fillColor="@color/homepage_generic_icon_background"
|
<path android:fillColor="@color/homepage_generic_icon_background"
|
||||||
android:pathData="M24,5.33h1.33c0.74,0,1.33,0.6,1.33,1.33v18.67c0,0.74-0.6,1.33-1.33,1.33H24c-0.74,0-1.33-0.6-1.33-1.33
|
android:pathData="M8,18.67h1.33c0.74,0,1.33,0.6,1.33,1.33v5.33c0,0.74-0.6,1.33-1.33,1.33H8c-0.74,0-1.33-0.6-1.33-1.33V20C6.67,19.26,7.26,18.67,8,18.67z" />
|
||||||
V6.67C22.67,5.93,23.26,5.33,24,5.33z" />
|
<path android:fillColor="@color/homepage_generic_icon_background"
|
||||||
<path
|
android:pathData="M16,12h1.33c0.74,0,1.33,0.6,1.33,1.33v12c0,0.74-0.6,1.33-1.33,1.33H16c-0.74,0-1.33-0.6-1.33-1.33v-12C14.67,12.6,15.26,12,16,12z" />
|
||||||
android:fillColor="@color/homepage_generic_icon_background"
|
|
||||||
android:pathData="M8,18.67h1.33c0.74,0,1.33,0.6,1.33,1.33v5.33c0,0.74-0.6,1.33-1.33,1.33H8c-0.74,0-1.33-0.6-1.33-1.33V20
|
|
||||||
C6.67,19.26,7.26,18.67,8,18.67z" />
|
|
||||||
<path
|
|
||||||
android:fillColor="@color/homepage_generic_icon_background"
|
|
||||||
android:pathData="M16,12h1.33c0.74,0,1.33,0.6,1.33,1.33v12c0,0.74-0.6,1.33-1.33,1.33H16c-0.74,0-1.33-0.6-1.33-1.33v-12
|
|
||||||
C14.67,12.6,15.26,12,16,12z" />
|
|
||||||
</vector>
|
</vector>
|
||||||
|
|||||||
@@ -97,6 +97,15 @@
|
|||||||
<!-- Description for the button that makes interface elements larger. [CHAR_LIMIT=NONE] -->
|
<!-- Description for the button that makes interface elements larger. [CHAR_LIMIT=NONE] -->
|
||||||
<string name="font_size_make_larger_desc">Make larger</string>
|
<string name="font_size_make_larger_desc">Make larger</string>
|
||||||
|
|
||||||
|
<!-- Auto rotate switchbar title. [CHAR_LIMIT=NONE] -->
|
||||||
|
<string name="auto_rotate_settings_primary_switch_title">Use Auto-Rotate</string>
|
||||||
|
|
||||||
|
<!-- Disclaimer for camera based rotate [CHAR_LIMIT=NONE] -->
|
||||||
|
<string name="smart_rotate_text_headline">
|
||||||
|
Face based Autorotate uses the front camera to see if and how someone is looking at the screen. It allows
|
||||||
|
for reading while lying down and images are never stored or sent to Google.<br><br>
|
||||||
|
<a href="<xliff:g example="http://www.google.com" id="url">http://support.google.com/mobile?p=telephony_rtt</xliff:g>">Learn more</a>
|
||||||
|
</string>
|
||||||
<string name="font_size_preview_text_headline">Sample text</string>
|
<string name="font_size_preview_text_headline">Sample text</string>
|
||||||
<string name="font_size_preview_text_title"
|
<string name="font_size_preview_text_title"
|
||||||
translation_description="Title text in sample text used to illustrate how the currently selected font size will appear to the user. NOTE: Translate manually. No not adopt any copyrighted material for translation.">
|
translation_description="Title text in sample text used to illustrate how the currently selected font size will appear to the user. NOTE: Translate manually. No not adopt any copyrighted material for translation.">
|
||||||
@@ -2704,8 +2713,18 @@
|
|||||||
<!-- Display settings --><skip/>
|
<!-- Display settings --><skip/>
|
||||||
<!-- Sound & display settings screen, section header for settings related to display -->
|
<!-- Sound & display settings screen, section header for settings related to display -->
|
||||||
<string name="display_settings">Display</string>
|
<string name="display_settings">Display</string>
|
||||||
|
<!-- Sound & display settings screen, section header for settings related to display -->
|
||||||
|
<string name="rotate_settings_class" translatable="false">com.android.settings.DisplaySettings</string>
|
||||||
<!-- Sound & display settings screen, accelerometer-based rotation check box label -->
|
<!-- Sound & display settings screen, accelerometer-based rotation check box label -->
|
||||||
<string name="accelerometer_title">Auto-rotate screen</string>
|
<string name="accelerometer_title">Auto-rotate screen</string>
|
||||||
|
<!-- Sound & display settings screen, locked rotation check box label [CHAR LIMIT=30] -->
|
||||||
|
<string name="auto_rotate_option_off">Off</string>
|
||||||
|
<!-- Sound & display settings screen, accelerometer-based rotation check box label [CHAR LIMIT=30] -->
|
||||||
|
<string name="auto_rotate_option_on">On</string>
|
||||||
|
<!-- Sound & display settings screen, face-based rotation check box label [CHAR LIMIT=30] -->
|
||||||
|
<string name="auto_rotate_option_face_based">On - Face-based</string>
|
||||||
|
<!-- SmartAutoRotatePreferenceFragment settings screen, face-based rotation switch label [CHAR LIMIT=30] -->
|
||||||
|
<string name="auto_rotate_switch_face_based">Enable Face Detection</string>
|
||||||
<!-- Display settings screen, Color mode settings title [CHAR LIMIT=30] -->
|
<!-- Display settings screen, Color mode settings title [CHAR LIMIT=30] -->
|
||||||
<string name="color_mode_title">Colors</string>
|
<string name="color_mode_title">Colors</string>
|
||||||
<!-- Display settings screen, Color mode option for "natural(sRGB) color" [CHAR LIMIT=45] -->
|
<!-- Display settings screen, Color mode option for "natural(sRGB) color" [CHAR LIMIT=45] -->
|
||||||
@@ -4950,6 +4969,8 @@
|
|||||||
<string name="display_category_title">Display</string>
|
<string name="display_category_title">Display</string>
|
||||||
<!-- Title for the accessibility text options page. [CHAR LIMIT=50] -->
|
<!-- Title for the accessibility text options page. [CHAR LIMIT=50] -->
|
||||||
<string name="accessibility_text_and_display_title">Text and display</string>
|
<string name="accessibility_text_and_display_title">Text and display</string>
|
||||||
|
<!-- Title for the accessibility text options page. [CHAR LIMIT=50] -->
|
||||||
|
<string name="accessibility_turn_screen_darker_title">Turn screen darker</string>
|
||||||
<!-- Title for the accessibility preference category of interaction control services and settings. [CHAR LIMIT=50] -->
|
<!-- Title for the accessibility preference category of interaction control services and settings. [CHAR LIMIT=50] -->
|
||||||
<string name="interaction_control_category_title">Interaction controls</string>
|
<string name="interaction_control_category_title">Interaction controls</string>
|
||||||
<!-- Title for the accessibility tap assistance page. [CHAR LIMIT=50] -->
|
<!-- Title for the accessibility tap assistance page. [CHAR LIMIT=50] -->
|
||||||
@@ -12590,13 +12611,15 @@
|
|||||||
<!-- Provider Model: SMS preference title -->
|
<!-- Provider Model: SMS preference title -->
|
||||||
<string name="sms_preference_title">SMS</string>
|
<string name="sms_preference_title">SMS</string>
|
||||||
<!-- Provider Model: Preferred status in summary for Calls & SMS -->
|
<!-- Provider Model: Preferred status in summary for Calls & SMS -->
|
||||||
<string name="calls_sms_preferred">Preferred for calls & SMS</string>
|
<string name="calls_sms_preferred">preferred</string>
|
||||||
<!-- Provider Model: Calls Preferred status in summary for Calls & SMS -->
|
<!-- Provider Model: Calls Preferred status in summary for Calls & SMS -->
|
||||||
<string name="calls_sms_calls_preferred">Preferred for calls</string>
|
<string name="calls_sms_calls_preferred">preferred for calls</string>
|
||||||
<!-- Provider Model: SMS Preferred status in summary for Calls & SMS -->
|
<!-- Provider Model: SMS Preferred status in summary for Calls & SMS -->
|
||||||
<string name="calls_sms_sms_preferred">Preferred for SMS</string>
|
<string name="calls_sms_sms_preferred">preferred for SMS</string>
|
||||||
<!-- Provider Model: Unavailable status in summary for Calls & SMS -->
|
<!-- Provider Model: Unavailable status in summary for Calls & SMS -->
|
||||||
<string name="calls_sms_unavailable">Temporarily unavailable</string>
|
<string name="calls_sms_unavailable">unavailable</string>
|
||||||
|
<!-- Provider Model: Temporarily unavailable status in summary for Calls & SMS -->
|
||||||
|
<string name="calls_sms_temp_unavailable">Temporarily unavailable</string>
|
||||||
<!-- Provider Model: No SIM status in summary for Calls & SMS -->
|
<!-- Provider Model: No SIM status in summary for Calls & SMS -->
|
||||||
<string name="calls_sms_no_sim">No SIM</string>
|
<string name="calls_sms_no_sim">No SIM</string>
|
||||||
<!-- Network & internet preferences title [CHAR LIMIT=NONE] -->
|
<!-- Network & internet preferences title [CHAR LIMIT=NONE] -->
|
||||||
|
|||||||
@@ -21,18 +21,33 @@
|
|||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/accessibility_text_and_display_title">
|
android:title="@string/accessibility_text_and_display_title">
|
||||||
|
|
||||||
<SwitchPreference
|
<Preference
|
||||||
android:key="toggle_high_text_contrast_preference"
|
android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
|
||||||
|
android:key="font_size_preference_screen"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/accessibility_toggle_high_text_contrast_preference_title"
|
android:title="@string/title_font_size"
|
||||||
settings:controller="com.android.settings.accessibility.HighTextContrastPreferenceController"/>
|
settings:controller="com.android.settings.display.FontSizePreferenceController"
|
||||||
|
settings:searchable="false"/>
|
||||||
|
|
||||||
|
<com.android.settings.display.ScreenZoomPreference
|
||||||
|
android:fragment="com.android.settings.display.ScreenZoomSettings"
|
||||||
|
android:key="accessibility_settings_screen_zoom"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/screen_zoom_title"
|
||||||
|
settings:searchable="false"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="dark_ui_mode_accessibility"
|
android:key="toggle_force_bold_text"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/dark_ui_mode"
|
android:title="@string/force_bold_text"
|
||||||
settings:controller="com.android.settings.display.DarkUIPreferenceController"
|
settings:controller="com.android.settings.accessibility.FontWeightAdjustmentPreferenceController"/>
|
||||||
settings:searchable="false"/>
|
|
||||||
|
<Preference
|
||||||
|
android:fragment="com.android.settings.accessibility.TurnScreenDarkerFragment"
|
||||||
|
android:key="turn_screen_darker_preference_screen"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/accessibility_turn_screen_darker_title"
|
||||||
|
settings:searchable="true"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:fragment="com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment"
|
android:fragment="com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment"
|
||||||
@@ -42,21 +57,11 @@
|
|||||||
android:title="@string/accessibility_display_daltonizer_preference_title"
|
android:title="@string/accessibility_display_daltonizer_preference_title"
|
||||||
settings:controller="com.android.settings.accessibility.DaltonizerPreferenceController"/>
|
settings:controller="com.android.settings.accessibility.DaltonizerPreferenceController"/>
|
||||||
|
|
||||||
<Preference
|
<SwitchPreference
|
||||||
android:fragment="com.android.settings.accessibility.ToggleColorInversionPreferenceFragment"
|
android:key="toggle_high_text_contrast_preference"
|
||||||
android:icon="@drawable/ic_color_inversion"
|
|
||||||
android:key="toggle_inversion_preference"
|
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/accessibility_display_inversion_preference_title"
|
android:title="@string/accessibility_toggle_high_text_contrast_preference_title"
|
||||||
settings:controller="com.android.settings.accessibility.ColorInversionPreferenceController"/>
|
settings:controller="com.android.settings.accessibility.HighTextContrastPreferenceController"/>
|
||||||
|
|
||||||
<!--TODO(b/170973645): Get icon-->
|
|
||||||
<Preference
|
|
||||||
android:fragment="com.android.settings.accessibility.ToggleReduceBrightColorsPreferenceFragment"
|
|
||||||
android:key="reduce_bright_colors_preference"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/reduce_bright_colors_preference_title"
|
|
||||||
settings:controller="com.android.settings.accessibility.ReduceBrightColorsPreferenceController"/>
|
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="toggle_disable_animations"
|
android:key="toggle_disable_animations"
|
||||||
@@ -64,27 +69,6 @@
|
|||||||
android:title="@string/accessibility_disable_animations"
|
android:title="@string/accessibility_disable_animations"
|
||||||
settings:controller="com.android.settings.accessibility.DisableAnimationsPreferenceController"/>
|
settings:controller="com.android.settings.accessibility.DisableAnimationsPreferenceController"/>
|
||||||
|
|
||||||
<com.android.settings.display.ScreenZoomPreference
|
|
||||||
android:fragment="com.android.settings.display.ScreenZoomSettings"
|
|
||||||
android:key="accessibility_settings_screen_zoom"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/screen_zoom_title"
|
|
||||||
settings:searchable="false"/>
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
|
|
||||||
android:key="font_size_preference_screen"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/title_font_size"
|
|
||||||
settings:controller="com.android.settings.display.FontSizePreferenceController"
|
|
||||||
settings:searchable="false"/>
|
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="toggle_force_bold_text"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/force_bold_text"
|
|
||||||
settings:controller="com.android.settings.accessibility.FontWeightAdjustmentPreferenceController"/>
|
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="toggle_large_pointer_icon"
|
android:key="toggle_large_pointer_icon"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
@@ -94,7 +78,6 @@
|
|||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="experimental_category"
|
android:key="experimental_category"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/experimental_category_title"
|
android:title="@string/experimental_category_title">
|
||||||
settings:initialExpandedChildrenCount="1">
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
66
res/xml/accessibility_turn_screen_darker.xml
Normal file
66
res/xml/accessibility_turn_screen_darker.xml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2021 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:key="accessibility_turn_screen_darker"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/accessibility_turn_screen_darker_title">
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="dark_ui_mode_accessibility"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/dark_ui_mode"
|
||||||
|
settings:controller="com.android.settings.display.DarkUIPreferenceController"
|
||||||
|
settings:searchable="false"/>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:fragment="com.android.settings.accessibility.ToggleColorInversionPreferenceFragment"
|
||||||
|
android:icon="@drawable/ic_color_inversion"
|
||||||
|
android:key="toggle_inversion_preference"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/accessibility_display_inversion_preference_title"
|
||||||
|
settings:controller="com.android.settings.accessibility.ColorInversionPreferenceController"/>
|
||||||
|
|
||||||
|
<!--TODO(b/170973645): Get icon-->
|
||||||
|
<Preference
|
||||||
|
android:fragment="com.android.settings.accessibility.ToggleReduceBrightColorsPreferenceFragment"
|
||||||
|
android:key="reduce_bright_colors_preference"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/reduce_bright_colors_preference_title"
|
||||||
|
settings:controller="com.android.settings.accessibility.ReduceBrightColorsPreferenceController"/>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="auto_brightness_entry"
|
||||||
|
android:title="@string/auto_brightness_title"
|
||||||
|
android:summary="@string/summary_placeholder"
|
||||||
|
android:fragment="com.android.settings.display.AutoBrightnessSettings"
|
||||||
|
settings:controller="com.android.settings.display.AutoBrightnessPreferenceController"/>
|
||||||
|
|
||||||
|
<com.android.settings.widget.PrimarySwitchPreference
|
||||||
|
android:key="night_display"
|
||||||
|
android:title="@string/night_display_title"
|
||||||
|
android:fragment="com.android.settings.display.NightDisplaySettings"
|
||||||
|
settings:controller="com.android.settings.display.NightDisplayPreferenceController"
|
||||||
|
settings:keywords="@string/keywords_display_night_display"/>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="experimental_category"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/experimental_category_title">
|
||||||
|
</PreferenceCategory>
|
||||||
|
</PreferenceScreen>
|
||||||
33
res/xml/auto_rotate_settings.xml
Normal file
33
res/xml/auto_rotate_settings.xml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2021 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:title="@string/accelerometer_title" >
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="face_based_rotate"
|
||||||
|
android:title="@string/auto_rotate_switch_face_based"
|
||||||
|
settings:controller="com.android.settings.display.SmartAutoRotateController" />
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.FooterPreference
|
||||||
|
android:icon="@drawable/ic_privacy_shield_24dp"
|
||||||
|
android:selectable="false"
|
||||||
|
settings:searchable="false" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
@@ -115,12 +115,6 @@
|
|||||||
android:title="@string/snooze_options_title"
|
android:title="@string/snooze_options_title"
|
||||||
settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" />
|
settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" />
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="asst_capabilities_actions_replies"
|
|
||||||
android:title="@string/asst_capabilities_actions_replies_title"
|
|
||||||
android:summary="@string/asst_capabilities_actions_replies_summary"
|
|
||||||
settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
|
|
||||||
|
|
||||||
<!-- Notification badging -->
|
<!-- Notification badging -->
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="notification_badging"
|
android:key="notification_badging"
|
||||||
|
|||||||
@@ -134,12 +134,6 @@
|
|||||||
android:title="@string/snooze_options_title"
|
android:title="@string/snooze_options_title"
|
||||||
settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" />
|
settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" />
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="asst_capabilities_actions_replies"
|
|
||||||
android:title="@string/asst_capabilities_actions_replies_title"
|
|
||||||
android:summary="@string/asst_capabilities_actions_replies_summary"
|
|
||||||
settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
|
|
||||||
|
|
||||||
<!-- Notification badging -->
|
<!-- Notification badging -->
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="notification_badging"
|
android:key="notification_badging"
|
||||||
|
|||||||
@@ -592,16 +592,6 @@
|
|||||||
android:title="@string/show_notification_channel_warnings"
|
android:title="@string/show_notification_channel_warnings"
|
||||||
android:summary="@string/show_notification_channel_warnings_summary" />
|
android:summary="@string/show_notification_channel_warnings_summary" />
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="asst_capability_prioritizer"
|
|
||||||
android:title="@string/asst_capability_prioritizer_title"
|
|
||||||
settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
|
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="asst_capability_ranking"
|
|
||||||
android:title="@string/asst_capability_ranking_title"
|
|
||||||
settings:controller="com.android.settings.notification.AssistantCapabilityPreferenceController" />
|
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="asst_feedback_indicator"
|
android:key="asst_feedback_indicator"
|
||||||
android:title="@string/asst_feedback_indicator_title"
|
android:title="@string/asst_feedback_indicator_title"
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
|
||||||
import android.hardware.display.ColorDisplayManager;
|
import android.hardware.display.ColorDisplayManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -28,7 +27,6 @@ import androidx.preference.SwitchPreference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.display.DarkUIPreferenceController;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
@@ -42,15 +40,10 @@ public class TextAndDisplayFragment extends DashboardFragment {
|
|||||||
|
|
||||||
// Preferences
|
// Preferences
|
||||||
private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN = "daltonizer_preference";
|
private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN = "daltonizer_preference";
|
||||||
private static final String TOGGLE_INVERSION_PREFERENCE = "toggle_inversion_preference";
|
|
||||||
private static final String DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN =
|
|
||||||
"reduce_bright_colors_preference";
|
|
||||||
private static final String TOGGLE_DISABLE_ANIMATIONS = "toggle_disable_animations";
|
private static final String TOGGLE_DISABLE_ANIMATIONS = "toggle_disable_animations";
|
||||||
private static final String TOGGLE_LARGE_POINTER_ICON = "toggle_large_pointer_icon";
|
private static final String TOGGLE_LARGE_POINTER_ICON = "toggle_large_pointer_icon";
|
||||||
|
|
||||||
private Preference mDisplayDaltonizerPreferenceScreen;
|
private Preference mDisplayDaltonizerPreferenceScreen;
|
||||||
private Preference mToggleInversionPreference;
|
|
||||||
private Preference mReduceBrightColorsPreference;
|
|
||||||
private SwitchPreference mToggleDisableAnimationsPreference;
|
private SwitchPreference mToggleDisableAnimationsPreference;
|
||||||
private SwitchPreference mToggleLargePointerIconPreference;
|
private SwitchPreference mToggleLargePointerIconPreference;
|
||||||
|
|
||||||
@@ -67,12 +60,6 @@ public class TextAndDisplayFragment extends DashboardFragment {
|
|||||||
updateSystemPreferences();
|
updateSystemPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Context context) {
|
|
||||||
super.onAttach(context);
|
|
||||||
use(DarkUIPreferenceController.class).setParentFragment(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getPreferenceScreenResId() {
|
protected int getPreferenceScreenResId() {
|
||||||
return R.xml.accessibility_text_and_display;
|
return R.xml.accessibility_text_and_display;
|
||||||
@@ -87,13 +74,6 @@ public class TextAndDisplayFragment extends DashboardFragment {
|
|||||||
// Display color adjustments.
|
// Display color adjustments.
|
||||||
mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
|
mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
|
||||||
|
|
||||||
// Display inversion.
|
|
||||||
mToggleInversionPreference = findPreference(TOGGLE_INVERSION_PREFERENCE);
|
|
||||||
|
|
||||||
// Reduce brightness.
|
|
||||||
mReduceBrightColorsPreference =
|
|
||||||
findPreference(DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN);
|
|
||||||
|
|
||||||
// Disable animation.
|
// Disable animation.
|
||||||
mToggleDisableAnimationsPreference = findPreference(TOGGLE_DISABLE_ANIMATIONS);
|
mToggleDisableAnimationsPreference = findPreference(TOGGLE_DISABLE_ANIMATIONS);
|
||||||
|
|
||||||
@@ -110,22 +90,14 @@ public class TextAndDisplayFragment extends DashboardFragment {
|
|||||||
if (ColorDisplayManager.isColorTransformAccelerated(getContext())) {
|
if (ColorDisplayManager.isColorTransformAccelerated(getContext())) {
|
||||||
mDisplayDaltonizerPreferenceScreen.setSummary(AccessibilityUtil.getSummary(
|
mDisplayDaltonizerPreferenceScreen.setSummary(AccessibilityUtil.getSummary(
|
||||||
getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED));
|
getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED));
|
||||||
mToggleInversionPreference.setSummary(AccessibilityUtil.getSummary(
|
|
||||||
getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED));
|
|
||||||
mReduceBrightColorsPreference.setSummary(AccessibilityUtil.getSummary(
|
|
||||||
getContext(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED));
|
|
||||||
getPreferenceScreen().removePreference(experimentalCategory);
|
getPreferenceScreen().removePreference(experimentalCategory);
|
||||||
} else {
|
} else {
|
||||||
// Move following preferences to experimental category if device don't supports HWC
|
// Move following preferences to experimental category if device don't supports HWC
|
||||||
// hardware-accelerated color transform.
|
// hardware-accelerated color transform.
|
||||||
getPreferenceScreen().removePreference(mDisplayDaltonizerPreferenceScreen);
|
getPreferenceScreen().removePreference(mDisplayDaltonizerPreferenceScreen);
|
||||||
getPreferenceScreen().removePreference(mToggleInversionPreference);
|
|
||||||
getPreferenceScreen().removePreference(mReduceBrightColorsPreference);
|
|
||||||
getPreferenceScreen().removePreference(mToggleDisableAnimationsPreference);
|
getPreferenceScreen().removePreference(mToggleDisableAnimationsPreference);
|
||||||
getPreferenceScreen().removePreference(mToggleLargePointerIconPreference);
|
getPreferenceScreen().removePreference(mToggleLargePointerIconPreference);
|
||||||
experimentalCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
|
experimentalCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
|
||||||
experimentalCategory.addPreference(mToggleInversionPreference);
|
|
||||||
experimentalCategory.addPreference(mReduceBrightColorsPreference);
|
|
||||||
experimentalCategory.addPreference(mToggleDisableAnimationsPreference);
|
experimentalCategory.addPreference(mToggleDisableAnimationsPreference);
|
||||||
experimentalCategory.addPreference(mToggleLargePointerIconPreference);
|
experimentalCategory.addPreference(mToggleLargePointerIconPreference);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.hardware.display.ColorDisplayManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.display.DarkUIPreferenceController;
|
||||||
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
|
/** Accessibility settings for turning screen darker. */
|
||||||
|
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||||
|
public class TurnScreenDarkerFragment extends DashboardFragment {
|
||||||
|
|
||||||
|
private static final String TAG = "TurnDarkerFragment";
|
||||||
|
|
||||||
|
private static final String CATEGORY_EXPERIMENTAL = "experimental_category";
|
||||||
|
|
||||||
|
// Preferences
|
||||||
|
private static final String TOGGLE_INVERSION_PREFERENCE = "toggle_inversion_preference";
|
||||||
|
private static final String DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN =
|
||||||
|
"reduce_bright_colors_preference";
|
||||||
|
|
||||||
|
private Preference mToggleInversionPreference;
|
||||||
|
private Preference mReduceBrightColorsPreference;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.ACCESSIBILITY_TURN_SCREEN_DARKER;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle icicle) {
|
||||||
|
super.onCreate(icicle);
|
||||||
|
initializeAllPreferences();
|
||||||
|
updateSystemPreferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
use(DarkUIPreferenceController.class).setParentFragment(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.accessibility_turn_screen_darker;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeAllPreferences() {
|
||||||
|
// Display inversion.
|
||||||
|
mToggleInversionPreference = findPreference(TOGGLE_INVERSION_PREFERENCE);
|
||||||
|
|
||||||
|
// Reduce brightness.
|
||||||
|
mReduceBrightColorsPreference =
|
||||||
|
findPreference(DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates preferences related to system configurations.
|
||||||
|
*/
|
||||||
|
private void updateSystemPreferences() {
|
||||||
|
final PreferenceCategory experimentalCategory = getPreferenceScreen().findPreference(
|
||||||
|
CATEGORY_EXPERIMENTAL);
|
||||||
|
if (ColorDisplayManager.isColorTransformAccelerated(getContext())) {
|
||||||
|
mToggleInversionPreference.setSummary(AccessibilityUtil.getSummary(
|
||||||
|
getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED));
|
||||||
|
mReduceBrightColorsPreference.setSummary(AccessibilityUtil.getSummary(
|
||||||
|
getContext(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED));
|
||||||
|
getPreferenceScreen().removePreference(experimentalCategory);
|
||||||
|
} else {
|
||||||
|
// Move following preferences to experimental category if device don't supports HWC
|
||||||
|
// hardware-accelerated color transform.
|
||||||
|
getPreferenceScreen().removePreference(mToggleInversionPreference);
|
||||||
|
getPreferenceScreen().removePreference(mReduceBrightColorsPreference);
|
||||||
|
experimentalCategory.addPreference(mToggleInversionPreference);
|
||||||
|
experimentalCategory.addPreference(mReduceBrightColorsPreference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
new BaseSearchIndexProvider(R.xml.accessibility_turn_screen_darker);
|
||||||
|
}
|
||||||
@@ -83,6 +83,7 @@ import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
|
|||||||
import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionSettings;
|
import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionSettings;
|
||||||
import com.android.settings.deviceinfo.legal.ModuleLicensesDashboard;
|
import com.android.settings.deviceinfo.legal.ModuleLicensesDashboard;
|
||||||
import com.android.settings.display.NightDisplaySettings;
|
import com.android.settings.display.NightDisplaySettings;
|
||||||
|
import com.android.settings.display.SmartAutoRotatePreferenceFragment;
|
||||||
import com.android.settings.display.darkmode.DarkModeSettingsFragment;
|
import com.android.settings.display.darkmode.DarkModeSettingsFragment;
|
||||||
import com.android.settings.dream.DreamSettings;
|
import com.android.settings.dream.DreamSettings;
|
||||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||||
@@ -176,6 +177,7 @@ public class SettingsGateway {
|
|||||||
SavedAccessPointsWifiSettings2.class.getName(),
|
SavedAccessPointsWifiSettings2.class.getName(),
|
||||||
AllInOneTetherSettings.class.getName(),
|
AllInOneTetherSettings.class.getName(),
|
||||||
TetherSettings.class.getName(),
|
TetherSettings.class.getName(),
|
||||||
|
SmartAutoRotatePreferenceFragment.class.getName(),
|
||||||
WifiP2pSettings.class.getName(),
|
WifiP2pSettings.class.getName(),
|
||||||
WifiTetherSettings.class.getName(),
|
WifiTetherSettings.class.getName(),
|
||||||
BackgroundCheckSummary.class.getName(),
|
BackgroundCheckSummary.class.getName(),
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.display;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
|
import com.android.internal.view.RotationPolicy;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||||
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The switch controller for the location.
|
||||||
|
*/
|
||||||
|
public class AutoRotateSwitchBarController implements OnMainSwitchChangeListener,
|
||||||
|
LifecycleObserver, OnStart, OnStop {
|
||||||
|
|
||||||
|
private final SettingsMainSwitchBar mSwitchBar;
|
||||||
|
private final Context mContext;
|
||||||
|
private boolean mValidListener;
|
||||||
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
|
public AutoRotateSwitchBarController(Context context, SettingsMainSwitchBar switchBar,
|
||||||
|
Lifecycle lifecycle) {
|
||||||
|
mSwitchBar = switchBar;
|
||||||
|
mContext = context;
|
||||||
|
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||||
|
if (lifecycle != null) {
|
||||||
|
lifecycle.addObserver(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
if (!mValidListener) {
|
||||||
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
mValidListener = true;
|
||||||
|
}
|
||||||
|
onChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
if (mValidListener) {
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
|
mValidListener = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens to the state change of the rotation primary switch.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
|
setRotationLock(isChecked);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void onChange() {
|
||||||
|
final boolean isEnabled = !RotationPolicy.isRotationLocked(mContext);
|
||||||
|
if (isEnabled != mSwitchBar.isChecked()) {
|
||||||
|
// set listener to null so that that code below doesn't trigger onCheckedChanged()
|
||||||
|
if (mValidListener) {
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
|
}
|
||||||
|
mSwitchBar.setChecked(isEnabled);
|
||||||
|
if (mValidListener) {
|
||||||
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setRotationLock(boolean isChecked) {
|
||||||
|
final boolean isLocked = !isChecked;
|
||||||
|
mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ROTATION_LOCK, isLocked);
|
||||||
|
RotationPolicy.setRotationLock(mContext, isLocked);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.android.settings.display;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.CAMERA_AUTOROTATE;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.internal.view.RotationPolicy;
|
||||||
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SmartAutoRotateController controls whether auto rotation is enabled
|
||||||
|
*/
|
||||||
|
public class SmartAutoRotateController extends TogglePreferenceController implements
|
||||||
|
Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
|
public SmartAutoRotateController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return !RotationPolicy.isRotationLocked(mContext)
|
||||||
|
? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChecked() {
|
||||||
|
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
CAMERA_AUTOROTATE, 0) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setChecked(boolean isChecked) {
|
||||||
|
mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_CAMERA_ROTATE_TOGGLE,
|
||||||
|
isChecked);
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
CAMERA_AUTOROTATE,
|
||||||
|
isChecked ? 1 : 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.display;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.CAMERA_AUTOROTATE;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.internal.view.RotationPolicy;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SmartAutoRotatePreferenceController provides auto rotate summary in display settings
|
||||||
|
*/
|
||||||
|
public class SmartAutoRotatePreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
private static final String TAG = "SmartAutoRotatePreferenceController";
|
||||||
|
|
||||||
|
public SmartAutoRotatePreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return RotationPolicy.isRotationLockToggleVisible(mContext)
|
||||||
|
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void update(Preference preference) {
|
||||||
|
refreshSummary(preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
int activeStringId = R.string.auto_rotate_option_off;
|
||||||
|
if (!RotationPolicy.isRotationLocked(mContext)) {
|
||||||
|
try {
|
||||||
|
final int cameraRotate = Settings.Secure.getIntForUser(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
CAMERA_AUTOROTATE,
|
||||||
|
UserHandle.USER_CURRENT);
|
||||||
|
activeStringId = cameraRotate == 1 ? R.string.auto_rotate_option_face_based
|
||||||
|
: R.string.auto_rotate_option_on;
|
||||||
|
} catch (Settings.SettingNotFoundException e) {
|
||||||
|
Log.w(TAG, "CAMERA_AUTOROTATE setting not found", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mContext.getString(activeStringId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.android.settings.display;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.internal.view.RotationPolicy;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsActivity;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.search.Indexable;
|
||||||
|
import com.android.settingslib.widget.FooterPreference;
|
||||||
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference fragment used to auto rotation
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
|
@SearchIndexable
|
||||||
|
public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
|
||||||
|
|
||||||
|
private static final String TAG = "SmartAutoRotatePreferenceFragment";
|
||||||
|
|
||||||
|
private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
|
||||||
|
private AutoRotateSwitchBarController mSwitchBarController;
|
||||||
|
private static final String FACE_SWITCH_PREFERENCE_ID = "face_based_rotate";
|
||||||
|
private static final String SMART_AUTO_ROTATE_CONTROLLER_KEY = "auto_rotate";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.auto_rotate_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||||
|
final SettingsMainSwitchBar switchBar = activity.getSwitchBar();
|
||||||
|
switchBar.setTitle(
|
||||||
|
getContext().getString(R.string.auto_rotate_settings_primary_switch_title));
|
||||||
|
switchBar.show();
|
||||||
|
mSwitchBarController = new AutoRotateSwitchBarController(activity, switchBar,
|
||||||
|
getSettingsLifecycle());
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (mRotationPolicyListener == null) {
|
||||||
|
mRotationPolicyListener = new RotationPolicy.RotationPolicyListener() {
|
||||||
|
@Override
|
||||||
|
public void onChange() {
|
||||||
|
mSwitchBarController.onChange();
|
||||||
|
final boolean isLocked = RotationPolicy.isRotationLocked(getContext());
|
||||||
|
final Preference preference = findPreference(FACE_SWITCH_PREFERENCE_ID);
|
||||||
|
if (preference != null) {
|
||||||
|
preference.setEnabled(!isLocked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
RotationPolicy.registerRotationPolicyListener(getPrefContext(),
|
||||||
|
mRotationPolicyListener);
|
||||||
|
|
||||||
|
findPreference(FooterPreference.KEY_FOOTER).setTitle(
|
||||||
|
Html.fromHtml(getString(R.string.smart_rotate_text_headline),
|
||||||
|
Html.FROM_HTML_MODE_COMPACT));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
|
||||||
|
if (mRotationPolicyListener != null) {
|
||||||
|
RotationPolicy.unregisterRotationPolicyListener(getPrefContext(),
|
||||||
|
mRotationPolicyListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.DISPLAY_AUTO_ROTATE_SETTINGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
|
return buildPreferenceControllers(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<AbstractPreferenceController> buildPreferenceControllers(
|
||||||
|
Context context) {
|
||||||
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
controllers.add(
|
||||||
|
new SmartAutoRotatePreferenceController(context, SMART_AUTO_ROTATE_CONTROLLER_KEY));
|
||||||
|
return controllers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
new BaseSearchIndexProvider(R.xml.auto_rotate_settings) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||||
|
Context context) {
|
||||||
|
return buildPreferenceControllers(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -103,6 +103,7 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
|||||||
if (mPreference == null) {
|
if (mPreference == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final @IdRes int icon = sIconMap.get(mInternetType);
|
final @IdRes int icon = sIconMap.get(mInternetType);
|
||||||
if (icon != 0) {
|
if (icon != 0) {
|
||||||
final Drawable drawable = mContext.getDrawable(icon);
|
final Drawable drawable = mContext.getDrawable(icon);
|
||||||
@@ -112,10 +113,17 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
|||||||
mPreference.setIcon(drawable);
|
mPreference.setIcon(drawable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mustUseWiFiHelperSummary(mSummaryHelper.isWifiConnected(),
|
||||||
|
mSummaryHelper.getSummary())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mInternetType == INTERNET_CELLULAR) {
|
if (mInternetType == INTERNET_CELLULAR) {
|
||||||
updateCellularSummary();
|
updateCellularSummary();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final @IdRes int summary = sSummaryMap.get(mInternetType);
|
final @IdRes int summary = sSummaryMap.get(mInternetType);
|
||||||
if (summary != 0) {
|
if (summary != 0) {
|
||||||
mPreference.setSummary(summary);
|
mPreference.setSummary(summary);
|
||||||
@@ -161,9 +169,17 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSummaryChanged(String summary) {
|
public void onSummaryChanged(String summary) {
|
||||||
if (mPreference != null && mInternetType == INTERNET_WIFI) {
|
mustUseWiFiHelperSummary(mSummaryHelper.isWifiConnected(), summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean mustUseWiFiHelperSummary(boolean isWifiConnected, String summary) {
|
||||||
|
final boolean needUpdate = (mInternetType == INTERNET_WIFI)
|
||||||
|
|| (mInternetType == INTERNET_APM_NETWORKS && isWifiConnected);
|
||||||
|
if (needUpdate && mPreference != null) {
|
||||||
mPreference.setSummary(summary);
|
mPreference.setSummary(summary);
|
||||||
}
|
}
|
||||||
|
return needUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ import static androidx.lifecycle.Lifecycle.Event;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.telephony.ServiceState;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
@@ -31,6 +33,7 @@ import androidx.preference.PreferenceScreen;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
|
import com.android.settingslib.Utils;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
@@ -45,7 +48,7 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
|||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionManager mSubscriptionManager;
|
||||||
private SubscriptionsChangeListener mSubscriptionsChangeListener;
|
private SubscriptionsChangeListener mSubscriptionsChangeListener;
|
||||||
|
private TelephonyManager mTelephonyManager;
|
||||||
private RestrictedPreference mPreference;
|
private RestrictedPreference mPreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,6 +60,7 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
|||||||
|
|
||||||
mUserManager = context.getSystemService(UserManager.class);
|
mUserManager = context.getSystemService(UserManager.class);
|
||||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
||||||
|
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
mSubscriptionsChangeListener = new SubscriptionsChangeListener(context, this);
|
mSubscriptionsChangeListener = new SubscriptionsChangeListener(context, this);
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
@@ -91,16 +95,18 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
|||||||
final StringBuilder summary = new StringBuilder();
|
final StringBuilder summary = new StringBuilder();
|
||||||
for (SubscriptionInfo subInfo : subs) {
|
for (SubscriptionInfo subInfo : subs) {
|
||||||
int subsSize = subs.size();
|
int subsSize = subs.size();
|
||||||
|
int subId = subInfo.getSubscriptionId();
|
||||||
final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
|
final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
|
||||||
subInfo, mContext);
|
subInfo, mContext);
|
||||||
|
|
||||||
// Set displayName as summary if there is only one valid SIM.
|
// Set displayName as summary if there is only one valid SIM.
|
||||||
if (subsSize == 1
|
if (subsSize == 1
|
||||||
&& SubscriptionManager.isValidSubscriptionId(subInfo.getSubscriptionId())) {
|
&& SubscriptionManager.isValidSubscriptionId(subId)
|
||||||
|
&& isInService(subId)) {
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
CharSequence status = getPreferredStatus(subInfo);
|
CharSequence status = getPreferredStatus(subsSize, subId);
|
||||||
if (status.toString().isEmpty()) {
|
if (status.toString().isEmpty()) {
|
||||||
// If there are 2 or more SIMs and one of these has no preferred status,
|
// If there are 2 or more SIMs and one of these has no preferred status,
|
||||||
// set only its displayName as summary.
|
// set only its displayName as summary.
|
||||||
@@ -121,14 +127,14 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected CharSequence getPreferredStatus(SubscriptionInfo subInfo) {
|
protected CharSequence getPreferredStatus(int subsSize, int subId) {
|
||||||
final int subId = subInfo.getSubscriptionId();
|
|
||||||
String status = "";
|
String status = "";
|
||||||
boolean isDataPreferred = subId == getDefaultVoiceSubscriptionId();
|
boolean isDataPreferred = subId == getDefaultVoiceSubscriptionId();
|
||||||
boolean isSmsPreferred = subId == getDefaultSmsSubscriptionId();
|
boolean isSmsPreferred = subId == getDefaultSmsSubscriptionId();
|
||||||
|
|
||||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
if (!SubscriptionManager.isValidSubscriptionId(subId) || !isInService(subId)) {
|
||||||
status = setSummaryResId(R.string.calls_sms_unavailable);
|
status = setSummaryResId(subsSize > 1 ? R.string.calls_sms_unavailable :
|
||||||
|
R.string.calls_sms_temp_unavailable);
|
||||||
} else {
|
} else {
|
||||||
if (isDataPreferred && isSmsPreferred) {
|
if (isDataPreferred && isSmsPreferred) {
|
||||||
status = setSummaryResId(R.string.calls_sms_preferred);
|
status = setSummaryResId(R.string.calls_sms_preferred);
|
||||||
@@ -203,4 +209,11 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
|||||||
refreshSummary(mPreference);
|
refreshSummary(mPreference);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
protected boolean isInService(int subId) {
|
||||||
|
ServiceState serviceState =
|
||||||
|
mTelephonyManager.createForSubscriptionId(subId).getServiceState();
|
||||||
|
return Utils.isInService(serviceState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,10 @@ import android.content.Context;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.IConnectivityManager;
|
|
||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
import android.net.NetworkCapabilities;
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.NetworkRequest;
|
import android.net.NetworkRequest;
|
||||||
import android.os.RemoteException;
|
import android.net.VpnManager;
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -64,7 +62,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
|
|||||||
private final String mToggleable;
|
private final String mToggleable;
|
||||||
private final UserManager mUserManager;
|
private final UserManager mUserManager;
|
||||||
private final ConnectivityManager mConnectivityManager;
|
private final ConnectivityManager mConnectivityManager;
|
||||||
private final IConnectivityManager mConnectivityManagerService;
|
private final VpnManager mVpnManager;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|
||||||
public VpnPreferenceController(Context context) {
|
public VpnPreferenceController(Context context) {
|
||||||
@@ -74,8 +72,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
|
|||||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
mConnectivityManager =
|
mConnectivityManager =
|
||||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
mConnectivityManagerService = IConnectivityManager.Stub.asInterface(
|
mVpnManager = context.getSystemService(VpnManager.class);
|
||||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -122,27 +119,20 @@ public class VpnPreferenceController extends AbstractPreferenceController
|
|||||||
}
|
}
|
||||||
// Copied from SystemUI::SecurityControllerImpl
|
// Copied from SystemUI::SecurityControllerImpl
|
||||||
SparseArray<VpnConfig> vpns = new SparseArray<>();
|
SparseArray<VpnConfig> vpns = new SparseArray<>();
|
||||||
try {
|
final List<UserInfo> users = mUserManager.getUsers();
|
||||||
final List<UserInfo> users = mUserManager.getUsers();
|
for (UserInfo user : users) {
|
||||||
for (UserInfo user : users) {
|
VpnConfig cfg = mVpnManager.getVpnConfig(user.id);
|
||||||
VpnConfig cfg = mConnectivityManagerService.getVpnConfig(user.id);
|
if (cfg == null) {
|
||||||
if (cfg == null) {
|
continue;
|
||||||
|
} else if (cfg.legacy) {
|
||||||
|
// Legacy VPNs should do nothing if the network is disconnected. Third-party
|
||||||
|
// VPN warnings need to continue as traffic can still go to the app.
|
||||||
|
final LegacyVpnInfo legacyVpn = mVpnManager.getLegacyVpnInfo(user.id);
|
||||||
|
if (legacyVpn == null || legacyVpn.state != LegacyVpnInfo.STATE_CONNECTED) {
|
||||||
continue;
|
continue;
|
||||||
} else if (cfg.legacy) {
|
|
||||||
// Legacy VPNs should do nothing if the network is disconnected. Third-party
|
|
||||||
// VPN warnings need to continue as traffic can still go to the app.
|
|
||||||
final LegacyVpnInfo legacyVpn =
|
|
||||||
mConnectivityManagerService.getLegacyVpnInfo(user.id);
|
|
||||||
if (legacyVpn == null || legacyVpn.state != LegacyVpnInfo.STATE_CONNECTED) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
vpns.put(user.id, cfg);
|
|
||||||
}
|
}
|
||||||
} catch (RemoteException rme) {
|
vpns.put(user.id, cfg);
|
||||||
// Roll back to previous state
|
|
||||||
Log.e(TAG, "Unable to list active VPNs", rme);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
final UserInfo userInfo = mUserManager.getUserInfo(UserHandle.myUserId());
|
final UserInfo userInfo = mUserManager.getUserInfo(UserHandle.myUserId());
|
||||||
final int uid;
|
final int uid;
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import android.content.Context;
|
|||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
public class CallsDefaultSubscriptionController extends DefaultSubscriptionController {
|
public class CallsDefaultSubscriptionController extends DefaultSubscriptionController {
|
||||||
|
|
||||||
public CallsDefaultSubscriptionController(Context context, String preferenceKey) {
|
public CallsDefaultSubscriptionController(Context context, String preferenceKey) {
|
||||||
@@ -40,4 +42,13 @@ public class CallsDefaultSubscriptionController extends DefaultSubscriptionContr
|
|||||||
protected void setDefaultSubscription(int subscriptionId) {
|
protected void setDefaultSubscription(int subscriptionId) {
|
||||||
mManager.setDefaultVoiceSubscriptionId(subscriptionId);
|
mManager.setDefaultVoiceSubscriptionId(subscriptionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
if (Utils.isProviderModelEnabled(mContext)) {
|
||||||
|
return MobileNetworkUtils.getPreferredStatus(mContext, mManager, true);
|
||||||
|
} else {
|
||||||
|
return super.getSummary();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ import com.android.internal.util.ArrayUtils;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
import com.android.settings.network.ims.WifiCallingQueryImsState;
|
||||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
@@ -600,8 +601,7 @@ public class MobileNetworkUtils {
|
|||||||
final Drawable networkDrawable =
|
final Drawable networkDrawable =
|
||||||
iconType == NO_CELL_DATA_TYPE_ICON
|
iconType == NO_CELL_DATA_TYPE_ICON
|
||||||
? EMPTY_DRAWABLE
|
? EMPTY_DRAWABLE
|
||||||
: context
|
: context.getResources().getDrawable(iconType, context.getTheme());
|
||||||
.getResources().getDrawable(iconType, context.getTheme());
|
|
||||||
|
|
||||||
// Overlay the two drawables
|
// Overlay the two drawables
|
||||||
final Drawable[] layers = {networkDrawable, signalDrawable};
|
final Drawable[] layers = {networkDrawable, signalDrawable};
|
||||||
@@ -920,4 +920,78 @@ public class MobileNetworkUtils {
|
|||||||
}
|
}
|
||||||
return isWifiCallingEnabled;
|
return isWifiCallingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns preferred status of Calls & SMS separately when Provider Model is enabled.
|
||||||
|
*/
|
||||||
|
public static CharSequence getPreferredStatus(Context context,
|
||||||
|
SubscriptionManager subscriptionManager, boolean isPreferredCallStatus) {
|
||||||
|
final List<SubscriptionInfo> subs = SubscriptionUtil.getActiveSubscriptions(
|
||||||
|
subscriptionManager);
|
||||||
|
if (!subs.isEmpty()) {
|
||||||
|
final StringBuilder summary = new StringBuilder();
|
||||||
|
for (SubscriptionInfo subInfo : subs) {
|
||||||
|
int subsSize = subs.size();
|
||||||
|
final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
|
||||||
|
subInfo, context);
|
||||||
|
|
||||||
|
// Set displayName as summary if there is only one valid SIM.
|
||||||
|
if (subsSize == 1
|
||||||
|
&& SubscriptionManager.isValidSubscriptionId(subInfo.getSubscriptionId())) {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
CharSequence status = isPreferredCallStatus
|
||||||
|
? getPreferredCallStatus(context, subInfo)
|
||||||
|
: getPreferredSmsStatus(context, subInfo);
|
||||||
|
if (status.toString().isEmpty()) {
|
||||||
|
// If there are 2 or more SIMs and one of these has no preferred status,
|
||||||
|
// set only its displayName as summary.
|
||||||
|
summary.append(displayName);
|
||||||
|
} else {
|
||||||
|
summary.append(displayName)
|
||||||
|
.append(" (")
|
||||||
|
.append(status)
|
||||||
|
.append(")");
|
||||||
|
}
|
||||||
|
// Do not add ", " for the last subscription.
|
||||||
|
if (subInfo != subs.get(subs.size() - 1)) {
|
||||||
|
summary.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return summary;
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CharSequence getPreferredCallStatus(Context context, SubscriptionInfo subInfo) {
|
||||||
|
final int subId = subInfo.getSubscriptionId();
|
||||||
|
String status = "";
|
||||||
|
boolean isDataPreferred = subId == SubscriptionManager.getDefaultVoiceSubscriptionId();
|
||||||
|
|
||||||
|
if (isDataPreferred) {
|
||||||
|
status = setSummaryResId(context, R.string.calls_sms_preferred);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CharSequence getPreferredSmsStatus(Context context, SubscriptionInfo subInfo) {
|
||||||
|
final int subId = subInfo.getSubscriptionId();
|
||||||
|
String status = "";
|
||||||
|
boolean isSmsPreferred = subId == SubscriptionManager.getDefaultSmsSubscriptionId();
|
||||||
|
|
||||||
|
if (isSmsPreferred) {
|
||||||
|
status = setSummaryResId(context, R.string.calls_sms_preferred);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String setSummaryResId(Context context, int resId) {
|
||||||
|
return context.getResources().getString(resId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import android.telecom.PhoneAccountHandle;
|
|||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
public class SmsDefaultSubscriptionController extends DefaultSubscriptionController {
|
public class SmsDefaultSubscriptionController extends DefaultSubscriptionController {
|
||||||
|
|
||||||
private final boolean mIsAskEverytimeSupported;
|
private final boolean mIsAskEverytimeSupported;
|
||||||
@@ -56,4 +58,13 @@ public class SmsDefaultSubscriptionController extends DefaultSubscriptionControl
|
|||||||
// Not supporting calling account override by VoIP
|
// Not supporting calling account override by VoIP
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
if (Utils.isProviderModelEnabled(mContext)) {
|
||||||
|
return MobileNetworkUtils.getPreferredStatus(mContext, mManager, false);
|
||||||
|
} else {
|
||||||
|
return super.getSummary();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.notification;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.service.notification.Adjustment;
|
|
||||||
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AssistantCapabilityPreferenceController extends TogglePreferenceController {
|
|
||||||
|
|
||||||
static final String PRIORITIZER_KEY = "asst_capability_prioritizer";
|
|
||||||
static final String RANKING_KEY = "asst_capability_ranking";
|
|
||||||
static final String SMART_KEY = "asst_capabilities_actions_replies";
|
|
||||||
private NotificationBackend mBackend;
|
|
||||||
|
|
||||||
public AssistantCapabilityPreferenceController(Context context, String key) {
|
|
||||||
super(context, key);
|
|
||||||
mBackend = new NotificationBackend();
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void setBackend(NotificationBackend backend) {
|
|
||||||
mBackend = backend;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
List<String> capabilities = mBackend.getAssistantAdjustments(mContext.getPackageName());
|
|
||||||
if (PRIORITIZER_KEY.equals(getPreferenceKey())) {
|
|
||||||
return capabilities.contains(Adjustment.KEY_IMPORTANCE);
|
|
||||||
} else if (RANKING_KEY.equals(getPreferenceKey())) {
|
|
||||||
return capabilities.contains(Adjustment.KEY_RANKING_SCORE);
|
|
||||||
} else if (SMART_KEY.equals(getPreferenceKey())) {
|
|
||||||
return capabilities.contains(Adjustment.KEY_CONTEXTUAL_ACTIONS)
|
|
||||||
&& capabilities.contains(Adjustment.KEY_TEXT_REPLIES);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
if (PRIORITIZER_KEY.equals(getPreferenceKey())) {
|
|
||||||
mBackend.allowAssistantAdjustment(Adjustment.KEY_IMPORTANCE, isChecked);
|
|
||||||
} else if (RANKING_KEY.equals(getPreferenceKey())) {
|
|
||||||
mBackend.allowAssistantAdjustment(Adjustment.KEY_RANKING_SCORE, isChecked);
|
|
||||||
} else if (SMART_KEY.equals(getPreferenceKey())) {
|
|
||||||
mBackend.allowAssistantAdjustment(Adjustment.KEY_CONTEXTUAL_ACTIONS, isChecked);
|
|
||||||
mBackend.allowAssistantAdjustment(Adjustment.KEY_TEXT_REPLIES, isChecked);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
return mBackend.getAllowedNotificationAssistant() != null
|
|
||||||
? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -16,24 +16,20 @@
|
|||||||
package com.android.settings.users;
|
package com.android.settings.users;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
public class AddUserWhenLockedPreferenceController extends TogglePreferenceController {
|
public class AddUserWhenLockedPreferenceController extends TogglePreferenceController {
|
||||||
|
|
||||||
private final UserCapabilities mUserCaps;
|
private final UserCapabilities mUserCaps;
|
||||||
private final LockPatternUtils mLockPatternUtils;
|
|
||||||
|
|
||||||
public AddUserWhenLockedPreferenceController(Context context, String key) {
|
public AddUserWhenLockedPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mUserCaps = UserCapabilities.create(context);
|
mUserCaps = UserCapabilities.create(context);
|
||||||
mLockPatternUtils = new LockPatternUtils(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -57,8 +53,6 @@ public class AddUserWhenLockedPreferenceController extends TogglePreferenceContr
|
|||||||
return DISABLED_FOR_USER;
|
return DISABLED_FOR_USER;
|
||||||
} else if (mUserCaps.disallowAddUser() || mUserCaps.disallowAddUserSetByAdmin()) {
|
} else if (mUserCaps.disallowAddUser() || mUserCaps.disallowAddUserSetByAdmin()) {
|
||||||
return DISABLED_FOR_USER;
|
return DISABLED_FOR_USER;
|
||||||
} else if (!mLockPatternUtils.isSecure(UserHandle.myUserId())) {
|
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
|
||||||
} else {
|
} else {
|
||||||
return mUserCaps.mUserSwitcherEnabled ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
return mUserCaps.mUserSwitcherEnabled ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,17 +18,13 @@ package com.android.settings.vpn2;
|
|||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.net.IConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.VpnManager;
|
import android.net.VpnManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
@@ -52,9 +48,9 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
|
|||||||
private PackageInfo mPackageInfo;
|
private PackageInfo mPackageInfo;
|
||||||
private Listener mListener;
|
private Listener mListener;
|
||||||
|
|
||||||
|
private ConnectivityManager mConnectivityManager;
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
private final IConnectivityManager mService = IConnectivityManager.Stub.asInterface(
|
private VpnManager mVpnManager;
|
||||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
@@ -97,7 +93,9 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
mConnectivityManager = getContext().getSystemService(ConnectivityManager.class);
|
||||||
mUserManager = UserManager.get(getContext());
|
mUserManager = UserManager.get(getContext());
|
||||||
|
mVpnManager = getContext().getSystemService(VpnManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -145,14 +143,9 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int userId = getUserId();
|
final int userId = getUserId();
|
||||||
try {
|
mVpnManager.setVpnPackageAuthorization(
|
||||||
mService.setVpnPackageAuthorization(
|
mPackageInfo.packageName, userId, VpnManager.TYPE_VPN_NONE);
|
||||||
mPackageInfo.packageName, userId, VpnManager.TYPE_VPN_NONE);
|
onDisconnect(dialog);
|
||||||
onDisconnect(dialog);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Failed to forget authorization of " + mPackageInfo.packageName +
|
|
||||||
" for user " + userId, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mListener != null) {
|
if (mListener != null) {
|
||||||
mListener.onForget();
|
mListener.onForget();
|
||||||
@@ -164,15 +157,10 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int userId = getUserId();
|
final int userId = getUserId();
|
||||||
try {
|
if (mPackageInfo.packageName.equals(VpnUtils.getConnectedPackage(mVpnManager, userId))) {
|
||||||
if (mPackageInfo.packageName.equals(VpnUtils.getConnectedPackage(mService, userId))) {
|
mConnectivityManager.setAlwaysOnVpnPackageForUser(userId, null,
|
||||||
mService.setAlwaysOnVpnPackage(userId, null, /* lockdownEnabled */ false,
|
/* lockdownEnabled */ false, /* lockdownAllowlist */ null);
|
||||||
/* lockdownAllowlist */ null);
|
mVpnManager.prepareVpn(mPackageInfo.packageName, VpnConfig.LEGACY_VPN, userId);
|
||||||
mService.prepareVpn(mPackageInfo.packageName, VpnConfig.LEGACY_VPN, userId);
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Failed to disconnect package " + mPackageInfo.packageName +
|
|
||||||
" for user " + userId, e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,10 +29,8 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.IConnectivityManager;
|
import android.net.VpnManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -72,7 +70,7 @@ public class AppManagementFragment extends SettingsPreferenceFragment
|
|||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
private DevicePolicyManager mDevicePolicyManager;
|
private DevicePolicyManager mDevicePolicyManager;
|
||||||
private ConnectivityManager mConnectivityManager;
|
private ConnectivityManager mConnectivityManager;
|
||||||
private IConnectivityManager mConnectivityService;
|
private VpnManager mVpnManager;
|
||||||
|
|
||||||
// VPN app info
|
// VPN app info
|
||||||
private final int mUserId = UserHandle.myUserId();
|
private final int mUserId = UserHandle.myUserId();
|
||||||
@@ -125,8 +123,7 @@ public class AppManagementFragment extends SettingsPreferenceFragment
|
|||||||
mPackageManager = getContext().getPackageManager();
|
mPackageManager = getContext().getPackageManager();
|
||||||
mDevicePolicyManager = getContext().getSystemService(DevicePolicyManager.class);
|
mDevicePolicyManager = getContext().getSystemService(DevicePolicyManager.class);
|
||||||
mConnectivityManager = getContext().getSystemService(ConnectivityManager.class);
|
mConnectivityManager = getContext().getSystemService(ConnectivityManager.class);
|
||||||
mConnectivityService = IConnectivityManager.Stub
|
mVpnManager = getContext().getSystemService(VpnManager.class);
|
||||||
.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
|
||||||
|
|
||||||
mPreferenceVersion = findPreference(KEY_VERSION);
|
mPreferenceVersion = findPreference(KEY_VERSION);
|
||||||
mPreferenceAlwaysOn = (RestrictedSwitchPreference) findPreference(KEY_ALWAYS_ON_VPN);
|
mPreferenceAlwaysOn = (RestrictedSwitchPreference) findPreference(KEY_ALWAYS_ON_VPN);
|
||||||
@@ -335,13 +332,8 @@ public class AppManagementFragment extends SettingsPreferenceFragment
|
|||||||
* @return {@code true} if another VPN (VpnService or legacy) is connected or set as always-on.
|
* @return {@code true} if another VPN (VpnService or legacy) is connected or set as always-on.
|
||||||
*/
|
*/
|
||||||
private boolean isAnotherVpnActive() {
|
private boolean isAnotherVpnActive() {
|
||||||
try {
|
final VpnConfig config = mVpnManager.getVpnConfig(mUserId);
|
||||||
final VpnConfig config = mConnectivityService.getVpnConfig(mUserId);
|
return config != null && !TextUtils.equals(config.user, mPackageName);
|
||||||
return config != null && !TextUtils.equals(config.user, mPackageName);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.w(TAG, "Failure to look up active VPN", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CannotConnectFragment extends InstrumentedDialogFragment {
|
public static class CannotConnectFragment extends InstrumentedDialogFragment {
|
||||||
|
|||||||
@@ -21,10 +21,9 @@ import android.app.settings.SettingsEnums;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.IConnectivityManager;
|
import android.net.VpnManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.security.Credentials;
|
import android.security.Credentials;
|
||||||
import android.security.KeyStore;
|
import android.security.KeyStore;
|
||||||
@@ -52,9 +51,8 @@ public class ConfigDialogFragment extends InstrumentedDialogFragment implements
|
|||||||
private static final String ARG_EDITING = "editing";
|
private static final String ARG_EDITING = "editing";
|
||||||
private static final String ARG_EXISTS = "exists";
|
private static final String ARG_EXISTS = "exists";
|
||||||
|
|
||||||
private final IConnectivityManager mService = IConnectivityManager.Stub.asInterface(
|
|
||||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private VpnManager mService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -80,6 +78,7 @@ public class ConfigDialogFragment extends InstrumentedDialogFragment implements
|
|||||||
public void onAttach(final Context context) {
|
public void onAttach(final Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
mService = context.getSystemService(VpnManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -212,8 +211,6 @@ public class ConfigDialogFragment extends InstrumentedDialogFragment implements
|
|||||||
mService.startLegacyVpn(profile);
|
mService.startLegacyVpn(profile);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
Toast.makeText(mContext, R.string.vpn_no_network, Toast.LENGTH_LONG).show();
|
Toast.makeText(mContext, R.string.vpn_no_network, Toast.LENGTH_LONG).show();
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Failed to connect", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,16 +30,14 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.ConnectivityManager.NetworkCallback;
|
import android.net.ConnectivityManager.NetworkCallback;
|
||||||
import android.net.IConnectivityManager;
|
|
||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
import android.net.NetworkCapabilities;
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.NetworkRequest;
|
import android.net.NetworkRequest;
|
||||||
|
import android.net.VpnManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.security.Credentials;
|
import android.security.Credentials;
|
||||||
@@ -92,10 +90,9 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
|||||||
.removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED)
|
.removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private final IConnectivityManager mConnectivityService = IConnectivityManager.Stub
|
|
||||||
.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
|
||||||
private ConnectivityManager mConnectivityManager;
|
private ConnectivityManager mConnectivityManager;
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
|
private VpnManager mVpnManager;
|
||||||
|
|
||||||
private final KeyStore mKeyStore = KeyStore.getInstance();
|
private final KeyStore mKeyStore = KeyStore.getInstance();
|
||||||
|
|
||||||
@@ -124,6 +121,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
|||||||
|
|
||||||
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
|
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||||
mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
mVpnManager = (VpnManager) getSystemService(Context.VPN_MANAGEMENT_SERVICE);
|
||||||
|
|
||||||
mUnavailable = isUiRestricted();
|
mUnavailable = isUiRestricted();
|
||||||
setHasOptionsMenu(!mUnavailable);
|
setHasOptionsMenu(!mUnavailable);
|
||||||
@@ -467,13 +465,9 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
|||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private Map<String, LegacyVpnInfo> getConnectedLegacyVpns() {
|
private Map<String, LegacyVpnInfo> getConnectedLegacyVpns() {
|
||||||
try {
|
mConnectedLegacyVpn = mVpnManager.getLegacyVpnInfo(UserHandle.myUserId());
|
||||||
mConnectedLegacyVpn = mConnectivityService.getLegacyVpnInfo(UserHandle.myUserId());
|
if (mConnectedLegacyVpn != null) {
|
||||||
if (mConnectedLegacyVpn != null) {
|
return Collections.singletonMap(mConnectedLegacyVpn.key, mConnectedLegacyVpn);
|
||||||
return Collections.singletonMap(mConnectedLegacyVpn.key, mConnectedLegacyVpn);
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(LOG_TAG, "Failure updating VPN list with connected legacy VPNs", e);
|
|
||||||
}
|
}
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
@@ -482,15 +476,11 @@ public class VpnSettings extends RestrictedSettingsFragment implements
|
|||||||
private Set<AppVpnInfo> getConnectedAppVpns() {
|
private Set<AppVpnInfo> getConnectedAppVpns() {
|
||||||
// Mark connected third-party services
|
// Mark connected third-party services
|
||||||
Set<AppVpnInfo> connections = new ArraySet<>();
|
Set<AppVpnInfo> connections = new ArraySet<>();
|
||||||
try {
|
for (UserHandle profile : mUserManager.getUserProfiles()) {
|
||||||
for (UserHandle profile : mUserManager.getUserProfiles()) {
|
VpnConfig config = mVpnManager.getVpnConfig(profile.getIdentifier());
|
||||||
VpnConfig config = mConnectivityService.getVpnConfig(profile.getIdentifier());
|
if (config != null && !config.legacy) {
|
||||||
if (config != null && !config.legacy) {
|
connections.add(new AppVpnInfo(profile.getIdentifier(), config.user));
|
||||||
connections.add(new AppVpnInfo(profile.getIdentifier(), config.user));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(LOG_TAG, "Failure updating VPN list with connected app VPNs", e);
|
|
||||||
}
|
}
|
||||||
return connections;
|
return connections;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,11 @@ package com.android.settings.vpn2;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.IConnectivityManager;
|
import android.net.VpnManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.security.Credentials;
|
import android.security.Credentials;
|
||||||
import android.security.KeyStore;
|
import android.security.KeyStore;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.android.internal.net.LegacyVpnInfo;
|
import com.android.internal.net.LegacyVpnInfo;
|
||||||
import com.android.internal.net.VpnConfig;
|
import com.android.internal.net.VpnConfig;
|
||||||
@@ -71,12 +69,11 @@ public class VpnUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVpnActive(Context context) throws RemoteException {
|
public static boolean isVpnActive(Context context) throws RemoteException {
|
||||||
return getIConnectivityManager().getVpnConfig(context.getUserId()) != null;
|
return getVpnManager(context).getVpnConfig(context.getUserId()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getConnectedPackage(IConnectivityManager service, final int userId)
|
public static String getConnectedPackage(VpnManager vpnManager, final int userId) {
|
||||||
throws RemoteException {
|
final VpnConfig config = vpnManager.getVpnConfig(userId);
|
||||||
final VpnConfig config = service.getVpnConfig(userId);
|
|
||||||
return config != null ? config.user : null;
|
return config != null ? config.user : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,9 +81,8 @@ public class VpnUtils {
|
|||||||
return context.getSystemService(ConnectivityManager.class);
|
return context.getSystemService(ConnectivityManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IConnectivityManager getIConnectivityManager() {
|
private static VpnManager getVpnManager(Context context) {
|
||||||
return IConnectivityManager.Stub.asInterface(
|
return context.getSystemService(VpnManager.class);
|
||||||
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAlwaysOnVpnSet(ConnectivityManager cm, final int userId) {
|
public static boolean isAlwaysOnVpnSet(ConnectivityManager cm, final int userId) {
|
||||||
@@ -94,17 +90,12 @@ public class VpnUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean disconnectLegacyVpn(Context context) {
|
public static boolean disconnectLegacyVpn(Context context) {
|
||||||
try {
|
int userId = context.getUserId();
|
||||||
int userId = context.getUserId();
|
LegacyVpnInfo currentLegacyVpn = getVpnManager(context).getLegacyVpnInfo(userId);
|
||||||
IConnectivityManager connectivityService = getIConnectivityManager();
|
if (currentLegacyVpn != null) {
|
||||||
LegacyVpnInfo currentLegacyVpn = connectivityService.getLegacyVpnInfo(userId);
|
clearLockdownVpn(context);
|
||||||
if (currentLegacyVpn != null) {
|
getVpnManager(context).prepareVpn(null, VpnConfig.LEGACY_VPN, userId);
|
||||||
clearLockdownVpn(context);
|
return true;
|
||||||
connectivityService.prepareVpn(null, VpnConfig.LEGACY_VPN, userId);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Legacy VPN could not be disconnected", e);
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,4 +98,11 @@ public final class WifiSummaryUpdater extends SummaryUpdater {
|
|||||||
com.android.settingslib.R.string.preference_summary_default_combination,
|
com.android.settingslib.R.string.preference_summary_default_combination,
|
||||||
ssid, mWifiTracker.statusLabel);
|
ssid, mWifiTracker.statusLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return true if Wi-Fi connected.
|
||||||
|
*/
|
||||||
|
public boolean isWifiConnected() {
|
||||||
|
return mWifiTracker.connected;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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 com.android.settings.R;
|
||||||
|
import com.android.settings.testutils.XmlTestUtils;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** Tests for {@link TurnScreenDarkerFragment}. */
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class TurnScreenDarkerFragmentTest {
|
||||||
|
|
||||||
|
private Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getNonIndexableKeys_existInXmlLayout() {
|
||||||
|
final List<String> niks = TurnScreenDarkerFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||||
|
.getNonIndexableKeys(mContext);
|
||||||
|
final List<String> keys =
|
||||||
|
XmlTestUtils.getKeysFromPreferenceXml(mContext,
|
||||||
|
R.xml.accessibility_turn_screen_darker);
|
||||||
|
|
||||||
|
assertThat(keys).containsAtLeastElementsIn(niks);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.display;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.CAMERA_AUTOROTATE;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class SmartAutoRotatePreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private PackageManager mPackageManager;
|
||||||
|
private ContentResolver mContentResolver;
|
||||||
|
private SmartAutoRotatePreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
FakeFeatureFactory.setupForTest();
|
||||||
|
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||||
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
|
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
||||||
|
when(mContext.getString(R.string.auto_rotate_option_off))
|
||||||
|
.thenReturn("Off");
|
||||||
|
when(mContext.getString(R.string.auto_rotate_option_on))
|
||||||
|
.thenReturn("On");
|
||||||
|
when(mContext.getString(R.string.auto_rotate_option_face_based))
|
||||||
|
.thenReturn("On - Face-based");
|
||||||
|
|
||||||
|
disableCameraBasedRotation();
|
||||||
|
|
||||||
|
mController = new SmartAutoRotatePreferenceController(mContext, "smart_auto_rotate");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailableWhenPolicyAllows() {
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
|
||||||
|
enableAutoRotationPreference();
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updatePreference_settingsIsOff_shouldTurnOffToggle() {
|
||||||
|
disableAutoRotation();
|
||||||
|
|
||||||
|
assertThat(mController.getSummary()).isEqualTo("Off");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updatePreference_settingsIsOn_shouldTurnOnToggle() {
|
||||||
|
enableAutoRotation();
|
||||||
|
|
||||||
|
assertThat(mController.getSummary()).isEqualTo("On");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updatePreference_settingsIsCameraBased_shouldTurnOnToggle() {
|
||||||
|
enableCameraBasedRotation();
|
||||||
|
enableAutoRotation();
|
||||||
|
|
||||||
|
assertThat(mController.getSummary()).isEqualTo("On - Face-based");
|
||||||
|
|
||||||
|
disableAutoRotation();
|
||||||
|
|
||||||
|
assertThat(mController.getSummary()).isEqualTo("Off");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAvailabilityStatus() {
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(BasePreferenceController
|
||||||
|
.UNSUPPORTED_ON_DEVICE);
|
||||||
|
|
||||||
|
enableAutoRotationPreference();
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(BasePreferenceController
|
||||||
|
.AVAILABLE);
|
||||||
|
|
||||||
|
disableAutoRotationPreference();
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(BasePreferenceController
|
||||||
|
.UNSUPPORTED_ON_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSliceableCorrectKey_returnsTrue() {
|
||||||
|
final AutoRotatePreferenceController controller =
|
||||||
|
new AutoRotatePreferenceController(mContext, "auto_rotate");
|
||||||
|
assertThat(controller.isSliceable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSliceableIncorrectKey_returnsFalse() {
|
||||||
|
final AutoRotatePreferenceController controller =
|
||||||
|
new AutoRotatePreferenceController(mContext, "bad_key");
|
||||||
|
assertThat(controller.isSliceable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableAutoRotationPreference() {
|
||||||
|
when(mPackageManager.hasSystemFeature(anyString())).thenReturn(true);
|
||||||
|
when(mContext.getResources().getBoolean(anyInt())).thenReturn(true);
|
||||||
|
Settings.System.putInt(mContentResolver,
|
||||||
|
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disableAutoRotationPreference() {
|
||||||
|
when(mPackageManager.hasSystemFeature(anyString())).thenReturn(true);
|
||||||
|
when(mContext.getResources().getBoolean(anyInt())).thenReturn(true);
|
||||||
|
Settings.System.putInt(mContentResolver,
|
||||||
|
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableAutoRotation() {
|
||||||
|
Settings.System.putIntForUser(mContentResolver,
|
||||||
|
Settings.System.ACCELEROMETER_ROTATION, 1, UserHandle.USER_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disableAutoRotation() {
|
||||||
|
Settings.System.putIntForUser(mContentResolver,
|
||||||
|
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableCameraBasedRotation() {
|
||||||
|
Settings.Secure.putIntForUser(mContentResolver,
|
||||||
|
CAMERA_AUTOROTATE, 1, UserHandle.USER_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disableCameraBasedRotation() {
|
||||||
|
Settings.Secure.putIntForUser(mContentResolver,
|
||||||
|
CAMERA_AUTOROTATE, 0, UserHandle.USER_CURRENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,217 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.notification;
|
|
||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
|
||||||
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
|
||||||
import static com.android.settings.notification.AssistantCapabilityPreferenceController.PRIORITIZER_KEY;
|
|
||||||
import static com.android.settings.notification.AssistantCapabilityPreferenceController.RANKING_KEY;
|
|
||||||
import static com.android.settings.notification.AssistantCapabilityPreferenceController.SMART_KEY;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.service.notification.Adjustment;
|
|
||||||
|
|
||||||
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.RuntimeEnvironment;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class AssistantCapabilityPreferenceControllerTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private NotificationBackend mBackend;
|
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private AssistantCapabilityPreferenceController mPrioritizerController;
|
|
||||||
private AssistantCapabilityPreferenceController mRankingController;
|
|
||||||
private AssistantCapabilityPreferenceController mChipController;
|
|
||||||
private Preference mPrioritizerPreference;
|
|
||||||
private Preference mRankingPreference;
|
|
||||||
private Preference mChipPreference;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mPrioritizerController = new AssistantCapabilityPreferenceController(
|
|
||||||
mContext, PRIORITIZER_KEY);
|
|
||||||
mPrioritizerController.setBackend(mBackend);
|
|
||||||
mPrioritizerPreference = new Preference(mContext);
|
|
||||||
mPrioritizerPreference.setKey(mPrioritizerController.getPreferenceKey());
|
|
||||||
when(mScreen.findPreference(
|
|
||||||
mPrioritizerController.getPreferenceKey())).thenReturn(mPrioritizerPreference);
|
|
||||||
mRankingController = new AssistantCapabilityPreferenceController(
|
|
||||||
mContext, RANKING_KEY);
|
|
||||||
mRankingController.setBackend(mBackend);
|
|
||||||
mRankingPreference = new Preference(mContext);
|
|
||||||
mRankingPreference.setKey(mRankingController.getPreferenceKey());
|
|
||||||
when(mScreen.findPreference(
|
|
||||||
mRankingController.getPreferenceKey())).thenReturn(mRankingPreference);
|
|
||||||
mChipController = new AssistantCapabilityPreferenceController(mContext, SMART_KEY);
|
|
||||||
mChipController.setBackend(mBackend);
|
|
||||||
mChipPreference = new Preference(mContext);
|
|
||||||
mChipPreference.setKey(mChipController.getPreferenceKey());
|
|
||||||
when(mScreen.findPreference(
|
|
||||||
mChipController.getPreferenceKey())).thenReturn(mChipPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_NAS() {
|
|
||||||
when(mBackend.getAllowedNotificationAssistant()).thenReturn(mock(ComponentName.class));
|
|
||||||
assertThat(mPrioritizerController.getAvailabilityStatus())
|
|
||||||
.isEqualTo(AVAILABLE);
|
|
||||||
assertThat(mChipController.getAvailabilityStatus())
|
|
||||||
.isEqualTo(AVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_noNAS() {
|
|
||||||
when(mBackend.getAllowedNotificationAssistant()).thenReturn(null);
|
|
||||||
assertThat(mPrioritizerController.getAvailabilityStatus())
|
|
||||||
.isEqualTo(DISABLED_DEPENDENT_SETTING);
|
|
||||||
assertThat(mChipController.getAvailabilityStatus())
|
|
||||||
.isEqualTo(DISABLED_DEPENDENT_SETTING);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_prioritizerSettingIsOff_false() {
|
|
||||||
List<String> capabilities = new ArrayList<>();
|
|
||||||
capabilities.add(Adjustment.KEY_USER_SENTIMENT);
|
|
||||||
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
|
|
||||||
assertThat(mPrioritizerController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_prioritizerSettingIsOn_true() {
|
|
||||||
List<String> capabilities = new ArrayList<>();
|
|
||||||
capabilities.add(Adjustment.KEY_IMPORTANCE);
|
|
||||||
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
|
|
||||||
assertThat(mPrioritizerController.isChecked()).isTrue();
|
|
||||||
|
|
||||||
capabilities = new ArrayList<>();
|
|
||||||
capabilities.add(Adjustment.KEY_RANKING_SCORE);
|
|
||||||
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
|
|
||||||
assertThat(mPrioritizerController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_rankingSettingIsOff_false() {
|
|
||||||
List<String> capabilities = new ArrayList<>();
|
|
||||||
capabilities.add(Adjustment.KEY_IMPORTANCE);
|
|
||||||
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
|
|
||||||
assertThat(mRankingController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_rankingSettingIsOn_true() {
|
|
||||||
List<String> capabilities = new ArrayList<>();
|
|
||||||
capabilities.add(Adjustment.KEY_RANKING_SCORE);
|
|
||||||
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
|
|
||||||
assertThat(mRankingController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_chipSettingIsOff_false() {
|
|
||||||
List<String> capabilities = new ArrayList<>();
|
|
||||||
capabilities.add(Adjustment.KEY_IMPORTANCE);
|
|
||||||
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
|
|
||||||
assertThat(mChipController.isChecked()).isFalse();
|
|
||||||
|
|
||||||
capabilities = new ArrayList<>();
|
|
||||||
capabilities.add(Adjustment.KEY_RANKING_SCORE);
|
|
||||||
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
|
|
||||||
assertThat(mChipController.isChecked()).isFalse();
|
|
||||||
|
|
||||||
capabilities = new ArrayList<>();
|
|
||||||
capabilities.add(Adjustment.KEY_CONTEXTUAL_ACTIONS);
|
|
||||||
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
|
|
||||||
assertThat(mChipController.isChecked()).isFalse();
|
|
||||||
|
|
||||||
capabilities = new ArrayList<>();
|
|
||||||
capabilities.add(Adjustment.KEY_TEXT_REPLIES);
|
|
||||||
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
|
|
||||||
assertThat(mChipController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_chipSettingIsOn_true() {
|
|
||||||
List<String> capabilities = new ArrayList<>();
|
|
||||||
capabilities.add(Adjustment.KEY_TEXT_REPLIES);
|
|
||||||
capabilities.add(Adjustment.KEY_CONTEXTUAL_ACTIONS);
|
|
||||||
when(mBackend.getAssistantAdjustments(anyString())).thenReturn(capabilities);
|
|
||||||
assertThat(mChipController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_prioritizerOn() {
|
|
||||||
mPrioritizerController.onPreferenceChange(mPrioritizerPreference, true);
|
|
||||||
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_IMPORTANCE, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_prioritizerOff() {
|
|
||||||
mPrioritizerController.onPreferenceChange(mPrioritizerPreference, false);
|
|
||||||
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_IMPORTANCE, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_rankingOn() {
|
|
||||||
mRankingController.onPreferenceChange(mRankingPreference, true);
|
|
||||||
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_RANKING_SCORE, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_rankingOff() {
|
|
||||||
mRankingController.onPreferenceChange(mRankingPreference, false);
|
|
||||||
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_RANKING_SCORE, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_chipsOn() {
|
|
||||||
mChipController.onPreferenceChange(mChipPreference, true);
|
|
||||||
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_CONTEXTUAL_ACTIONS, true);
|
|
||||||
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_TEXT_REPLIES, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_chipsOff() {
|
|
||||||
mChipController.onPreferenceChange(mChipPreference, false);
|
|
||||||
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_CONTEXTUAL_ACTIONS, false);
|
|
||||||
verify(mBackend).allowAssistantAdjustment(Adjustment.KEY_TEXT_REPLIES, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -18,7 +18,6 @@ package com.android.settings.users;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -28,8 +27,6 @@ import android.provider.Settings.Global;
|
|||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
|
||||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
@@ -42,7 +39,6 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {ShadowUserManager.class})
|
@Config(shadows = {ShadowUserManager.class})
|
||||||
@@ -55,16 +51,13 @@ public class AddUserWhenLockedPreferenceControllerTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private ShadowUserManager mUserManager;
|
private ShadowUserManager mUserManager;
|
||||||
private AddUserWhenLockedPreferenceController mController;
|
private AddUserWhenLockedPreferenceController mController;
|
||||||
private LockPatternUtils mLockPatternUtils;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mLockPatternUtils = mock(LockPatternUtils.class);
|
|
||||||
mUserManager = ShadowUserManager.getShadow();
|
mUserManager = ShadowUserManager.getShadow();
|
||||||
mController = new AddUserWhenLockedPreferenceController(mContext, "fake_key");
|
mController = new AddUserWhenLockedPreferenceController(mContext, "fake_key");
|
||||||
ReflectionHelpers.setField(mController, "mLockPatternUtils", mLockPatternUtils);
|
|
||||||
mUserManager.setSupportsMultipleUsers(true);
|
mUserManager.setSupportsMultipleUsers(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +69,6 @@ public class AddUserWhenLockedPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void displayPref_NotAdmin_shouldNotDisplay() {
|
public void displayPref_NotAdmin_shouldNotDisplay() {
|
||||||
mUserManager.setIsAdminUser(false);
|
mUserManager.setIsAdminUser(false);
|
||||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
|
||||||
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
||||||
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
|
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
when(mScreen.findPreference(preference.getKey())).thenReturn(preference);
|
when(mScreen.findPreference(preference.getKey())).thenReturn(preference);
|
||||||
@@ -89,7 +81,6 @@ public class AddUserWhenLockedPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateState_NotAdmin_shouldNotDisplayPreference() {
|
public void updateState_NotAdmin_shouldNotDisplayPreference() {
|
||||||
mUserManager.setIsAdminUser(false);
|
mUserManager.setIsAdminUser(false);
|
||||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
|
||||||
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
||||||
|
|
||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
@@ -102,10 +93,8 @@ public class AddUserWhenLockedPreferenceControllerTest {
|
|||||||
mUserManager.setIsAdminUser(true);
|
mUserManager.setIsAdminUser(true);
|
||||||
mUserManager.setUserSwitcherEnabled(true);
|
mUserManager.setUserSwitcherEnabled(true);
|
||||||
mUserManager.setSupportsMultipleUsers(true);
|
mUserManager.setSupportsMultipleUsers(true);
|
||||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
|
||||||
final AddUserWhenLockedPreferenceController controller =
|
final AddUserWhenLockedPreferenceController controller =
|
||||||
new AddUserWhenLockedPreferenceController(mContext, "fake_key");
|
new AddUserWhenLockedPreferenceController(mContext, "fake_key");
|
||||||
ReflectionHelpers.setField(controller, "mLockPatternUtils", mLockPatternUtils);
|
|
||||||
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
||||||
|
|
||||||
controller.updateState(preference);
|
controller.updateState(preference);
|
||||||
@@ -154,40 +143,4 @@ public class AddUserWhenLockedPreferenceControllerTest {
|
|||||||
assertThat(Global.getInt(mContext.getContentResolver(), Global.ADD_USERS_WHEN_LOCKED, 0))
|
assertThat(Global.getInt(mContext.getContentResolver(), Global.ADD_USERS_WHEN_LOCKED, 0))
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateState_insecureLockScreen_shouldNotDisplayPreference() {
|
|
||||||
mUserManager.setIsAdminUser(true);
|
|
||||||
mUserManager.setUserSwitcherEnabled(true);
|
|
||||||
mUserManager.setSupportsMultipleUsers(true);
|
|
||||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
|
||||||
final AddUserWhenLockedPreferenceController controller =
|
|
||||||
new AddUserWhenLockedPreferenceController(mContext, "fake_key");
|
|
||||||
ReflectionHelpers.setField(controller, "mLockPatternUtils", mLockPatternUtils);
|
|
||||||
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
|
||||||
|
|
||||||
controller.updateState(preference);
|
|
||||||
|
|
||||||
verify(preference).setVisible(false);
|
|
||||||
assertThat(controller.getAvailabilityStatus()).isEqualTo(
|
|
||||||
BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateState_secureLockScreen_shouldDisplayPreference() {
|
|
||||||
mUserManager.setIsAdminUser(true);
|
|
||||||
mUserManager.setUserSwitcherEnabled(true);
|
|
||||||
mUserManager.setSupportsMultipleUsers(true);
|
|
||||||
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
|
||||||
final AddUserWhenLockedPreferenceController controller =
|
|
||||||
new AddUserWhenLockedPreferenceController(mContext, "fake_key");
|
|
||||||
ReflectionHelpers.setField(controller, "mLockPatternUtils", mLockPatternUtils);
|
|
||||||
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
|
|
||||||
|
|
||||||
controller.updateState(preference);
|
|
||||||
|
|
||||||
verify(preference).setVisible(true);
|
|
||||||
assertThat(controller.getAvailabilityStatus()).isEqualTo(
|
|
||||||
BasePreferenceController.AVAILABLE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
|
import static com.android.settings.network.InternetUpdater.INTERNET_APM_NETWORKS;
|
||||||
import static com.android.settings.network.InternetUpdater.INTERNET_WIFI;
|
import static com.android.settings.network.InternetUpdater.INTERNET_WIFI;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
@@ -57,6 +58,7 @@ import org.mockito.junit.MockitoRule;
|
|||||||
public class InternetPreferenceControllerTest {
|
public class InternetPreferenceControllerTest {
|
||||||
|
|
||||||
private static final String TEST_SUMMARY = "test summary";
|
private static final String TEST_SUMMARY = "test summary";
|
||||||
|
private static final String NOT_CONNECTED = "Not connected";
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
@@ -117,13 +119,37 @@ public class InternetPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onSummaryChanged_shouldUpdatePreferenceSummary() {
|
public void mustUseWiFiHelperSummary_internetWifi_updateSummary() {
|
||||||
mController.onInternetTypeChanged(INTERNET_WIFI);
|
mController.onInternetTypeChanged(INTERNET_WIFI);
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
mController.onSummaryChanged(TEST_SUMMARY);
|
mController.mustUseWiFiHelperSummary(true /* isWifiConnected */, TEST_SUMMARY);
|
||||||
|
|
||||||
assertThat(mPreference.getSummary()).isEqualTo(TEST_SUMMARY);
|
assertThat(mPreference.getSummary()).isEqualTo(TEST_SUMMARY);
|
||||||
|
|
||||||
|
mController.mustUseWiFiHelperSummary(false /* isWifiConnected */, NOT_CONNECTED);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo(NOT_CONNECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mustUseWiFiHelperSummary_internetApmNetworksWifiConnected_updateSummary() {
|
||||||
|
mController.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
mController.mustUseWiFiHelperSummary(true /* isWifiConnected */, TEST_SUMMARY);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo(TEST_SUMMARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mustUseWiFiHelperSummary_internetApmNetworksWifiDisconnected_notUpdateSummary() {
|
||||||
|
mController.onInternetTypeChanged(INTERNET_APM_NETWORKS);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
mController.mustUseWiFiHelperSummary(false /* isWifiConnected */, NOT_CONNECTED);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isNotEqualTo(NOT_CONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class NetworkProviderCallsSmsControllerTest {
|
|||||||
|
|
||||||
private int mDefaultVoiceSubscriptionId;
|
private int mDefaultVoiceSubscriptionId;
|
||||||
private int mDefaultSmsSubscriptionId;
|
private int mDefaultSmsSubscriptionId;
|
||||||
|
private boolean mIsInService;
|
||||||
@Override
|
@Override
|
||||||
protected int getDefaultVoiceSubscriptionId() {
|
protected int getDefaultVoiceSubscriptionId() {
|
||||||
return mDefaultVoiceSubscriptionId;
|
return mDefaultVoiceSubscriptionId;
|
||||||
@@ -104,6 +104,11 @@ public class NetworkProviderCallsSmsControllerTest {
|
|||||||
return mDefaultSmsSubscriptionId;
|
return mDefaultSmsSubscriptionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isInService(int subId) {
|
||||||
|
return mIsInService;
|
||||||
|
}
|
||||||
|
|
||||||
public void setDefaultVoiceSubscriptionId(int subscriptionId) {
|
public void setDefaultVoiceSubscriptionId(int subscriptionId) {
|
||||||
mDefaultVoiceSubscriptionId = subscriptionId;
|
mDefaultVoiceSubscriptionId = subscriptionId;
|
||||||
}
|
}
|
||||||
@@ -111,6 +116,10 @@ public class NetworkProviderCallsSmsControllerTest {
|
|||||||
public void setDefaultSmsSubscriptionId(int subscriptionId) {
|
public void setDefaultSmsSubscriptionId(int subscriptionId) {
|
||||||
mDefaultSmsSubscriptionId = subscriptionId;
|
mDefaultSmsSubscriptionId = subscriptionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setInService(boolean inService) {
|
||||||
|
mIsInService = inService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -128,7 +137,7 @@ public class NetworkProviderCallsSmsControllerTest {
|
|||||||
mPreference = new RestrictedPreference(mContext);
|
mPreference = new RestrictedPreference(mContext);
|
||||||
mPreference.setKey(KEY_PREFERENCE_CALLS_SMS);
|
mPreference.setKey(KEY_PREFERENCE_CALLS_SMS);
|
||||||
mController = new MockNetworkProviderCallsSmsController(mContext, mLifecycle);
|
mController = new MockNetworkProviderCallsSmsController(mContext, mLifecycle);
|
||||||
|
mController.setInService(true);
|
||||||
mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
|
mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
|
||||||
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
|
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
|
||||||
}
|
}
|
||||||
@@ -176,7 +185,7 @@ public class NetworkProviderCallsSmsControllerTest {
|
|||||||
final StringBuilder summary = new StringBuilder();
|
final StringBuilder summary = new StringBuilder();
|
||||||
summary.append(DISPLAY_NAME_1)
|
summary.append(DISPLAY_NAME_1)
|
||||||
.append(" (")
|
.append(" (")
|
||||||
.append(setSummaryResId("calls_sms_unavailable"))
|
.append(setSummaryResId("calls_sms_temp_unavailable"))
|
||||||
.append(")");
|
.append(")");
|
||||||
|
|
||||||
assertTrue(TextUtils.equals(mController.getSummary(), summary));
|
assertTrue(TextUtils.equals(mController.getSummary(), summary));
|
||||||
|
|||||||
Reference in New Issue
Block a user