Snap for 7135444 from 2b9f139a2d to sc-v2-release

Change-Id: Id1d096fb8ebf94bdf1664af97d0839999ce0493f
This commit is contained in:
android-build-team Robot
2021-02-10 02:10:59 +00:00
37 changed files with 1169 additions and 587 deletions

View File

@@ -954,7 +954,7 @@
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<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"
android:value="true" />
</activity>

View File

@@ -2669,6 +2669,54 @@
column="13"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"
message="Avoid using hardcoded color"
category="Correctness"
priority="4"
summary="Using hardcoded color"
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" android:fillColor=&quot;@color/homepage_generic_icon_background&quot; />"
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.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" android:fillColor=&quot;@color/homepage_generic_icon_background&quot; />"
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.&#xA;This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
errorLine1=" android:fillColor=&quot;@color/homepage_generic_icon_background&quot; />"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="res/drawable/ic_network_signal_blue.xml"
line="27"
column="11"/>
</issue>
<issue
id="HardCodedColor"
severity="Error"

View File

@@ -13,25 +13,17 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:pathData="M 0 0 H 32 V 32 H 0 V 0 Z" />
<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
V6.67C22.67,5.93,23.26,5.33,24,5.33z" />
<path
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" />
<path android:pathData="M 0 0 H 32 V 32 H 0 V 0 Z" />
<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.33V6.67C22.67,5.93,23.26,5.33,24,5.33z" />
<path 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.33V20C6.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-12C14.67,12.6,15.26,12,16,12z" />
</vector>

View File

@@ -97,6 +97,15 @@
<!-- Description for the button that makes interface elements larger. [CHAR_LIMIT=NONE] -->
<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.&lt;br>&lt;br>
&lt;a href="<xliff:g example="http://www.google.com" id="url">http://support.google.com/mobile?p=telephony_rtt</xliff:g>">Learn more&lt;/a>
</string>
<string name="font_size_preview_text_headline">Sample text</string>
<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.">
@@ -2704,8 +2713,18 @@
<!-- Display settings --><skip/>
<!-- Sound & display settings screen, section header for settings related to display -->
<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 -->
<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] -->
<string name="color_mode_title">Colors</string>
<!-- Display settings screen, Color mode option for "natural(sRGB) color" [CHAR LIMIT=45] -->
@@ -4950,6 +4969,8 @@
<string name="display_category_title">Display</string>
<!-- Title for the accessibility text options page. [CHAR LIMIT=50] -->
<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] -->
<string name="interaction_control_category_title">Interaction controls</string>
<!-- Title for the accessibility tap assistance page. [CHAR LIMIT=50] -->
@@ -12590,13 +12611,15 @@
<!-- Provider Model: SMS preference title -->
<string name="sms_preference_title">SMS</string>
<!-- Provider Model: Preferred status in summary for Calls & SMS -->
<string name="calls_sms_preferred">Preferred for calls &amp; SMS</string>
<string name="calls_sms_preferred">preferred</string>
<!-- 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 -->
<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 -->
<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 -->
<string name="calls_sms_no_sim">No SIM</string>
<!-- Network & internet preferences title [CHAR LIMIT=NONE] -->

View File

@@ -21,18 +21,33 @@
android:persistent="false"
android:title="@string/accessibility_text_and_display_title">
<SwitchPreference
android:key="toggle_high_text_contrast_preference"
<Preference
android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
android:key="font_size_preference_screen"
android:persistent="false"
android:title="@string/accessibility_toggle_high_text_contrast_preference_title"
settings:controller="com.android.settings.accessibility.HighTextContrastPreferenceController"/>
android:title="@string/title_font_size"
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
android:key="dark_ui_mode_accessibility"
android:key="toggle_force_bold_text"
android:persistent="false"
android:title="@string/dark_ui_mode"
settings:controller="com.android.settings.display.DarkUIPreferenceController"
settings:searchable="false"/>
android:title="@string/force_bold_text"
settings:controller="com.android.settings.accessibility.FontWeightAdjustmentPreferenceController"/>
<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
android:fragment="com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment"
@@ -42,21 +57,11 @@
android:title="@string/accessibility_display_daltonizer_preference_title"
settings:controller="com.android.settings.accessibility.DaltonizerPreferenceController"/>
<Preference
android:fragment="com.android.settings.accessibility.ToggleColorInversionPreferenceFragment"
android:icon="@drawable/ic_color_inversion"
android:key="toggle_inversion_preference"
<SwitchPreference
android:key="toggle_high_text_contrast_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"/>
android:title="@string/accessibility_toggle_high_text_contrast_preference_title"
settings:controller="com.android.settings.accessibility.HighTextContrastPreferenceController"/>
<SwitchPreference
android:key="toggle_disable_animations"
@@ -64,27 +69,6 @@
android:title="@string/accessibility_disable_animations"
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
android:key="toggle_large_pointer_icon"
android:persistent="false"
@@ -94,7 +78,6 @@
<PreferenceCategory
android:key="experimental_category"
android:persistent="false"
android:title="@string/experimental_category_title"
settings:initialExpandedChildrenCount="1">
android:title="@string/experimental_category_title">
</PreferenceCategory>
</PreferenceScreen>

View 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>

View 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>

View File

@@ -115,12 +115,6 @@
android:title="@string/snooze_options_title"
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 -->
<SwitchPreference
android:key="notification_badging"

View File

@@ -134,12 +134,6 @@
android:title="@string/snooze_options_title"
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 -->
<SwitchPreference
android:key="notification_badging"

View File

@@ -592,16 +592,6 @@
android:title="@string/show_notification_channel_warnings"
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
android:key="asst_feedback_indicator"
android:title="@string/asst_feedback_indicator_title"

View File

@@ -17,7 +17,6 @@
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;
@@ -28,7 +27,6 @@ import androidx.preference.SwitchPreference;
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;
@@ -42,15 +40,10 @@ public class TextAndDisplayFragment extends DashboardFragment {
// Preferences
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_LARGE_POINTER_ICON = "toggle_large_pointer_icon";
private Preference mDisplayDaltonizerPreferenceScreen;
private Preference mToggleInversionPreference;
private Preference mReduceBrightColorsPreference;
private SwitchPreference mToggleDisableAnimationsPreference;
private SwitchPreference mToggleLargePointerIconPreference;
@@ -67,12 +60,6 @@ public class TextAndDisplayFragment extends DashboardFragment {
updateSystemPreferences();
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(DarkUIPreferenceController.class).setParentFragment(this);
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.accessibility_text_and_display;
@@ -87,13 +74,6 @@ public class TextAndDisplayFragment extends DashboardFragment {
// Display color adjustments.
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.
mToggleDisableAnimationsPreference = findPreference(TOGGLE_DISABLE_ANIMATIONS);
@@ -110,22 +90,14 @@ public class TextAndDisplayFragment extends DashboardFragment {
if (ColorDisplayManager.isColorTransformAccelerated(getContext())) {
mDisplayDaltonizerPreferenceScreen.setSummary(AccessibilityUtil.getSummary(
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);
} else {
// Move following preferences to experimental category if device don't supports HWC
// hardware-accelerated color transform.
getPreferenceScreen().removePreference(mDisplayDaltonizerPreferenceScreen);
getPreferenceScreen().removePreference(mToggleInversionPreference);
getPreferenceScreen().removePreference(mReduceBrightColorsPreference);
getPreferenceScreen().removePreference(mToggleDisableAnimationsPreference);
getPreferenceScreen().removePreference(mToggleLargePointerIconPreference);
experimentalCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
experimentalCategory.addPreference(mToggleInversionPreference);
experimentalCategory.addPreference(mReduceBrightColorsPreference);
experimentalCategory.addPreference(mToggleDisableAnimationsPreference);
experimentalCategory.addPreference(mToggleLargePointerIconPreference);
}

View File

@@ -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);
}

View File

@@ -83,6 +83,7 @@ import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionSettings;
import com.android.settings.deviceinfo.legal.ModuleLicensesDashboard;
import com.android.settings.display.NightDisplaySettings;
import com.android.settings.display.SmartAutoRotatePreferenceFragment;
import com.android.settings.display.darkmode.DarkModeSettingsFragment;
import com.android.settings.dream.DreamSettings;
import com.android.settings.enterprise.EnterprisePrivacySettings;
@@ -176,6 +177,7 @@ public class SettingsGateway {
SavedAccessPointsWifiSettings2.class.getName(),
AllInOneTetherSettings.class.getName(),
TetherSettings.class.getName(),
SmartAutoRotatePreferenceFragment.class.getName(),
WifiP2pSettings.class.getName(),
WifiTetherSettings.class.getName(),
BackgroundCheckSummary.class.getName(),

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
};
}

View File

@@ -103,6 +103,7 @@ public class InternetPreferenceController extends AbstractPreferenceController i
if (mPreference == null) {
return;
}
final @IdRes int icon = sIconMap.get(mInternetType);
if (icon != 0) {
final Drawable drawable = mContext.getDrawable(icon);
@@ -112,10 +113,17 @@ public class InternetPreferenceController extends AbstractPreferenceController i
mPreference.setIcon(drawable);
}
}
if (mustUseWiFiHelperSummary(mSummaryHelper.isWifiConnected(),
mSummaryHelper.getSummary())) {
return;
}
if (mInternetType == INTERNET_CELLULAR) {
updateCellularSummary();
return;
}
final @IdRes int summary = sSummaryMap.get(mInternetType);
if (summary != 0) {
mPreference.setSummary(summary);
@@ -161,9 +169,17 @@ public class InternetPreferenceController extends AbstractPreferenceController i
@Override
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);
}
return needUpdate;
}
@VisibleForTesting

View File

@@ -20,8 +20,10 @@ import static androidx.lifecycle.Lifecycle.Event;
import android.content.Context;
import android.os.UserManager;
import android.telephony.ServiceState;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.LifecycleObserver;
@@ -31,6 +33,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.Utils;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -45,7 +48,7 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
private UserManager mUserManager;
private SubscriptionManager mSubscriptionManager;
private SubscriptionsChangeListener mSubscriptionsChangeListener;
private TelephonyManager mTelephonyManager;
private RestrictedPreference mPreference;
/**
@@ -57,6 +60,7 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
mUserManager = context.getSystemService(UserManager.class);
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
if (lifecycle != null) {
mSubscriptionsChangeListener = new SubscriptionsChangeListener(context, this);
lifecycle.addObserver(this);
@@ -91,16 +95,18 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
final StringBuilder summary = new StringBuilder();
for (SubscriptionInfo subInfo : subs) {
int subsSize = subs.size();
int subId = subInfo.getSubscriptionId();
final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName(
subInfo, mContext);
// Set displayName as summary if there is only one valid SIM.
if (subsSize == 1
&& SubscriptionManager.isValidSubscriptionId(subInfo.getSubscriptionId())) {
&& SubscriptionManager.isValidSubscriptionId(subId)
&& isInService(subId)) {
return displayName;
}
CharSequence status = getPreferredStatus(subInfo);
CharSequence status = getPreferredStatus(subsSize, subId);
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.
@@ -121,14 +127,14 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
}
@VisibleForTesting
protected CharSequence getPreferredStatus(SubscriptionInfo subInfo) {
final int subId = subInfo.getSubscriptionId();
protected CharSequence getPreferredStatus(int subsSize, int subId) {
String status = "";
boolean isDataPreferred = subId == getDefaultVoiceSubscriptionId();
boolean isSmsPreferred = subId == getDefaultSmsSubscriptionId();
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
status = setSummaryResId(R.string.calls_sms_unavailable);
if (!SubscriptionManager.isValidSubscriptionId(subId) || !isInService(subId)) {
status = setSummaryResId(subsSize > 1 ? R.string.calls_sms_unavailable :
R.string.calls_sms_temp_unavailable);
} else {
if (isDataPreferred && isSmsPreferred) {
status = setSummaryResId(R.string.calls_sms_preferred);
@@ -203,4 +209,11 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
refreshSummary(mPreference);
update();
}
@VisibleForTesting
protected boolean isInService(int subId) {
ServiceState serviceState =
mTelephonyManager.createForSubscriptionId(subId).getServiceState();
return Utils.isInService(serviceState);
}
}

View File

@@ -19,12 +19,10 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.net.VpnManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -64,7 +62,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
private final String mToggleable;
private final UserManager mUserManager;
private final ConnectivityManager mConnectivityManager;
private final IConnectivityManager mConnectivityManagerService;
private final VpnManager mVpnManager;
private Preference mPreference;
public VpnPreferenceController(Context context) {
@@ -74,8 +72,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mConnectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
mConnectivityManagerService = IConnectivityManager.Stub.asInterface(
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
mVpnManager = context.getSystemService(VpnManager.class);
}
@Override
@@ -122,27 +119,20 @@ public class VpnPreferenceController extends AbstractPreferenceController
}
// Copied from SystemUI::SecurityControllerImpl
SparseArray<VpnConfig> vpns = new SparseArray<>();
try {
final List<UserInfo> users = mUserManager.getUsers();
for (UserInfo user : users) {
VpnConfig cfg = mConnectivityManagerService.getVpnConfig(user.id);
if (cfg == null) {
final List<UserInfo> users = mUserManager.getUsers();
for (UserInfo user : users) {
VpnConfig cfg = mVpnManager.getVpnConfig(user.id);
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;
} 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) {
// Roll back to previous state
Log.e(TAG, "Unable to list active VPNs", rme);
return;
vpns.put(user.id, cfg);
}
final UserInfo userInfo = mUserManager.getUserInfo(UserHandle.myUserId());
final int uid;

View File

@@ -20,6 +20,8 @@ import android.content.Context;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import com.android.settings.Utils;
public class CallsDefaultSubscriptionController extends DefaultSubscriptionController {
public CallsDefaultSubscriptionController(Context context, String preferenceKey) {
@@ -40,4 +42,13 @@ public class CallsDefaultSubscriptionController extends DefaultSubscriptionContr
protected void setDefaultSubscription(int subscriptionId) {
mManager.setDefaultVoiceSubscriptionId(subscriptionId);
}
@Override
public CharSequence getSummary() {
if (Utils.isProviderModelEnabled(mContext)) {
return MobileNetworkUtils.getPreferredStatus(mContext, mManager, true);
} else {
return super.getSummary();
}
}
}

View File

@@ -73,6 +73,7 @@ import com.android.internal.util.ArrayUtils;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.network.SubscriptionUtil;
import com.android.settings.network.ims.WifiCallingQueryImsState;
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
@@ -600,8 +601,7 @@ public class MobileNetworkUtils {
final Drawable networkDrawable =
iconType == NO_CELL_DATA_TYPE_ICON
? EMPTY_DRAWABLE
: context
.getResources().getDrawable(iconType, context.getTheme());
: context.getResources().getDrawable(iconType, context.getTheme());
// Overlay the two drawables
final Drawable[] layers = {networkDrawable, signalDrawable};
@@ -920,4 +920,78 @@ public class MobileNetworkUtils {
}
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);
}
}

View File

@@ -21,6 +21,8 @@ import android.telecom.PhoneAccountHandle;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import com.android.settings.Utils;
public class SmsDefaultSubscriptionController extends DefaultSubscriptionController {
private final boolean mIsAskEverytimeSupported;
@@ -56,4 +58,13 @@ public class SmsDefaultSubscriptionController extends DefaultSubscriptionControl
// Not supporting calling account override by VoIP
return null;
}
@Override
public CharSequence getSummary() {
if (Utils.isProviderModelEnabled(mContext)) {
return MobileNetworkUtils.getPreferredStatus(mContext, mManager, false);
} else {
return super.getSummary();
}
}
}

View File

@@ -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;
}
}

View File

@@ -16,24 +16,20 @@
package com.android.settings.users;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import androidx.preference.Preference;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.RestrictedSwitchPreference;
public class AddUserWhenLockedPreferenceController extends TogglePreferenceController {
private final UserCapabilities mUserCaps;
private final LockPatternUtils mLockPatternUtils;
public AddUserWhenLockedPreferenceController(Context context, String key) {
super(context, key);
mUserCaps = UserCapabilities.create(context);
mLockPatternUtils = new LockPatternUtils(context);
}
@Override
@@ -57,8 +53,6 @@ public class AddUserWhenLockedPreferenceController extends TogglePreferenceContr
return DISABLED_FOR_USER;
} else if (mUserCaps.disallowAddUser() || mUserCaps.disallowAddUserSetByAdmin()) {
return DISABLED_FOR_USER;
} else if (!mLockPatternUtils.isSecure(UserHandle.myUserId())) {
return CONDITIONALLY_UNAVAILABLE;
} else {
return mUserCaps.mUserSwitcherEnabled ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}

View File

@@ -18,17 +18,13 @@ package com.android.settings.vpn2;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.net.IConnectivityManager;
import android.net.ConnectivityManager;
import android.net.VpnManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
@@ -52,9 +48,9 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
private PackageInfo mPackageInfo;
private Listener mListener;
private ConnectivityManager mConnectivityManager;
private UserManager mUserManager;
private final IConnectivityManager mService = IConnectivityManager.Stub.asInterface(
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
private VpnManager mVpnManager;
@Override
public int getMetricsCategory() {
@@ -97,7 +93,9 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mConnectivityManager = getContext().getSystemService(ConnectivityManager.class);
mUserManager = UserManager.get(getContext());
mVpnManager = getContext().getSystemService(VpnManager.class);
}
@Override
@@ -145,14 +143,9 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
return;
}
final int userId = getUserId();
try {
mService.setVpnPackageAuthorization(
mPackageInfo.packageName, userId, VpnManager.TYPE_VPN_NONE);
onDisconnect(dialog);
} catch (RemoteException e) {
Log.e(TAG, "Failed to forget authorization of " + mPackageInfo.packageName +
" for user " + userId, e);
}
mVpnManager.setVpnPackageAuthorization(
mPackageInfo.packageName, userId, VpnManager.TYPE_VPN_NONE);
onDisconnect(dialog);
if (mListener != null) {
mListener.onForget();
@@ -164,15 +157,10 @@ public class AppDialogFragment extends InstrumentedDialogFragment implements App
return;
}
final int userId = getUserId();
try {
if (mPackageInfo.packageName.equals(VpnUtils.getConnectedPackage(mService, userId))) {
mService.setAlwaysOnVpnPackage(userId, null, /* lockdownEnabled */ false,
/* lockdownAllowlist */ null);
mService.prepareVpn(mPackageInfo.packageName, VpnConfig.LEGACY_VPN, userId);
}
} catch (RemoteException e) {
Log.e(TAG, "Failed to disconnect package " + mPackageInfo.packageName +
" for user " + userId, e);
if (mPackageInfo.packageName.equals(VpnUtils.getConnectedPackage(mVpnManager, userId))) {
mConnectivityManager.setAlwaysOnVpnPackageForUser(userId, null,
/* lockdownEnabled */ false, /* lockdownAllowlist */ null);
mVpnManager.prepareVpn(mPackageInfo.packageName, VpnConfig.LEGACY_VPN, userId);
}
}

View File

@@ -29,10 +29,8 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.VpnManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
@@ -72,7 +70,7 @@ public class AppManagementFragment extends SettingsPreferenceFragment
private PackageManager mPackageManager;
private DevicePolicyManager mDevicePolicyManager;
private ConnectivityManager mConnectivityManager;
private IConnectivityManager mConnectivityService;
private VpnManager mVpnManager;
// VPN app info
private final int mUserId = UserHandle.myUserId();
@@ -125,8 +123,7 @@ public class AppManagementFragment extends SettingsPreferenceFragment
mPackageManager = getContext().getPackageManager();
mDevicePolicyManager = getContext().getSystemService(DevicePolicyManager.class);
mConnectivityManager = getContext().getSystemService(ConnectivityManager.class);
mConnectivityService = IConnectivityManager.Stub
.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
mVpnManager = getContext().getSystemService(VpnManager.class);
mPreferenceVersion = findPreference(KEY_VERSION);
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.
*/
private boolean isAnotherVpnActive() {
try {
final VpnConfig config = mConnectivityService.getVpnConfig(mUserId);
return config != null && !TextUtils.equals(config.user, mPackageName);
} catch (RemoteException e) {
Log.w(TAG, "Failure to look up active VPN", e);
return false;
}
final VpnConfig config = mVpnManager.getVpnConfig(mUserId);
return config != null && !TextUtils.equals(config.user, mPackageName);
}
public static class CannotConnectFragment extends InstrumentedDialogFragment {

View File

@@ -21,10 +21,9 @@ import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.VpnManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.security.Credentials;
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_EXISTS = "exists";
private final IConnectivityManager mService = IConnectivityManager.Stub.asInterface(
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
private Context mContext;
private VpnManager mService;
@Override
@@ -80,6 +78,7 @@ public class ConfigDialogFragment extends InstrumentedDialogFragment implements
public void onAttach(final Context context) {
super.onAttach(context);
mContext = context;
mService = context.getSystemService(VpnManager.class);
}
@Override
@@ -212,8 +211,6 @@ public class ConfigDialogFragment extends InstrumentedDialogFragment implements
mService.startLegacyVpn(profile);
} catch (IllegalStateException e) {
Toast.makeText(mContext, R.string.vpn_no_network, Toast.LENGTH_LONG).show();
} catch (RemoteException e) {
Log.e(TAG, "Failed to connect", e);
}
}
}

View File

@@ -30,16 +30,14 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager.NetworkCallback;
import android.net.IConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.net.VpnManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.security.Credentials;
@@ -92,10 +90,9 @@ public class VpnSettings extends RestrictedSettingsFragment implements
.removeCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED)
.build();
private final IConnectivityManager mConnectivityService = IConnectivityManager.Stub
.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
private ConnectivityManager mConnectivityManager;
private UserManager mUserManager;
private VpnManager mVpnManager;
private final KeyStore mKeyStore = KeyStore.getInstance();
@@ -124,6 +121,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mVpnManager = (VpnManager) getSystemService(Context.VPN_MANAGEMENT_SERVICE);
mUnavailable = isUiRestricted();
setHasOptionsMenu(!mUnavailable);
@@ -467,13 +465,9 @@ public class VpnSettings extends RestrictedSettingsFragment implements
@WorkerThread
private Map<String, LegacyVpnInfo> getConnectedLegacyVpns() {
try {
mConnectedLegacyVpn = mConnectivityService.getLegacyVpnInfo(UserHandle.myUserId());
if (mConnectedLegacyVpn != null) {
return Collections.singletonMap(mConnectedLegacyVpn.key, mConnectedLegacyVpn);
}
} catch (RemoteException e) {
Log.e(LOG_TAG, "Failure updating VPN list with connected legacy VPNs", e);
mConnectedLegacyVpn = mVpnManager.getLegacyVpnInfo(UserHandle.myUserId());
if (mConnectedLegacyVpn != null) {
return Collections.singletonMap(mConnectedLegacyVpn.key, mConnectedLegacyVpn);
}
return Collections.emptyMap();
}
@@ -482,15 +476,11 @@ public class VpnSettings extends RestrictedSettingsFragment implements
private Set<AppVpnInfo> getConnectedAppVpns() {
// Mark connected third-party services
Set<AppVpnInfo> connections = new ArraySet<>();
try {
for (UserHandle profile : mUserManager.getUserProfiles()) {
VpnConfig config = mConnectivityService.getVpnConfig(profile.getIdentifier());
if (config != null && !config.legacy) {
connections.add(new AppVpnInfo(profile.getIdentifier(), config.user));
}
for (UserHandle profile : mUserManager.getUserProfiles()) {
VpnConfig config = mVpnManager.getVpnConfig(profile.getIdentifier());
if (config != null && !config.legacy) {
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;
}

View File

@@ -17,13 +17,11 @@ package com.android.settings.vpn2;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.VpnManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.security.Credentials;
import android.security.KeyStore;
import android.util.Log;
import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnConfig;
@@ -71,12 +69,11 @@ public class VpnUtils {
}
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)
throws RemoteException {
final VpnConfig config = service.getVpnConfig(userId);
public static String getConnectedPackage(VpnManager vpnManager, final int userId) {
final VpnConfig config = vpnManager.getVpnConfig(userId);
return config != null ? config.user : null;
}
@@ -84,9 +81,8 @@ public class VpnUtils {
return context.getSystemService(ConnectivityManager.class);
}
private static IConnectivityManager getIConnectivityManager() {
return IConnectivityManager.Stub.asInterface(
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
private static VpnManager getVpnManager(Context context) {
return context.getSystemService(VpnManager.class);
}
public static boolean isAlwaysOnVpnSet(ConnectivityManager cm, final int userId) {
@@ -94,17 +90,12 @@ public class VpnUtils {
}
public static boolean disconnectLegacyVpn(Context context) {
try {
int userId = context.getUserId();
IConnectivityManager connectivityService = getIConnectivityManager();
LegacyVpnInfo currentLegacyVpn = connectivityService.getLegacyVpnInfo(userId);
if (currentLegacyVpn != null) {
clearLockdownVpn(context);
connectivityService.prepareVpn(null, VpnConfig.LEGACY_VPN, userId);
return true;
}
} catch (RemoteException e) {
Log.e(TAG, "Legacy VPN could not be disconnected", e);
int userId = context.getUserId();
LegacyVpnInfo currentLegacyVpn = getVpnManager(context).getLegacyVpnInfo(userId);
if (currentLegacyVpn != null) {
clearLockdownVpn(context);
getVpnManager(context).prepareVpn(null, VpnConfig.LEGACY_VPN, userId);
return true;
}
return false;
}

View File

@@ -98,4 +98,11 @@ public final class WifiSummaryUpdater extends SummaryUpdater {
com.android.settingslib.R.string.preference_summary_default_combination,
ssid, mWifiTracker.statusLabel);
}
/**
* return true if Wi-Fi connected.
*/
public boolean isWifiConnected() {
return mWifiTracker.connected;
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.users;
import static com.google.common.truth.Truth.assertThat;
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.verify;
import static org.mockito.Mockito.when;
@@ -28,8 +27,6 @@ import android.provider.Settings.Global;
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.settingslib.RestrictedSwitchPreference;
@@ -42,7 +39,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowUserManager.class})
@@ -55,16 +51,13 @@ public class AddUserWhenLockedPreferenceControllerTest {
private Context mContext;
private ShadowUserManager mUserManager;
private AddUserWhenLockedPreferenceController mController;
private LockPatternUtils mLockPatternUtils;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mLockPatternUtils = mock(LockPatternUtils.class);
mUserManager = ShadowUserManager.getShadow();
mController = new AddUserWhenLockedPreferenceController(mContext, "fake_key");
ReflectionHelpers.setField(mController, "mLockPatternUtils", mLockPatternUtils);
mUserManager.setSupportsMultipleUsers(true);
}
@@ -76,7 +69,6 @@ public class AddUserWhenLockedPreferenceControllerTest {
@Test
public void displayPref_NotAdmin_shouldNotDisplay() {
mUserManager.setIsAdminUser(false);
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
when(mScreen.findPreference(preference.getKey())).thenReturn(preference);
@@ -89,7 +81,6 @@ public class AddUserWhenLockedPreferenceControllerTest {
@Test
public void updateState_NotAdmin_shouldNotDisplayPreference() {
mUserManager.setIsAdminUser(false);
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
final RestrictedSwitchPreference preference = mock(RestrictedSwitchPreference.class);
mController.updateState(preference);
@@ -102,10 +93,8 @@ public class AddUserWhenLockedPreferenceControllerTest {
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);
@@ -154,40 +143,4 @@ public class AddUserWhenLockedPreferenceControllerTest {
assertThat(Global.getInt(mContext.getContentResolver(), Global.ADD_USERS_WHEN_LOCKED, 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);
}
}

View File

@@ -16,6 +16,7 @@
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.google.common.truth.Truth.assertThat;
@@ -57,6 +58,7 @@ import org.mockito.junit.MockitoRule;
public class InternetPreferenceControllerTest {
private static final String TEST_SUMMARY = "test summary";
private static final String NOT_CONNECTED = "Not connected";
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@@ -117,13 +119,37 @@ public class InternetPreferenceControllerTest {
}
@Test
public void onSummaryChanged_shouldUpdatePreferenceSummary() {
public void mustUseWiFiHelperSummary_internetWifi_updateSummary() {
mController.onInternetTypeChanged(INTERNET_WIFI);
mController.displayPreference(mScreen);
mController.onSummaryChanged(TEST_SUMMARY);
mController.mustUseWiFiHelperSummary(true /* isWifiConnected */, 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

View File

@@ -93,7 +93,7 @@ public class NetworkProviderCallsSmsControllerTest {
private int mDefaultVoiceSubscriptionId;
private int mDefaultSmsSubscriptionId;
private boolean mIsInService;
@Override
protected int getDefaultVoiceSubscriptionId() {
return mDefaultVoiceSubscriptionId;
@@ -104,6 +104,11 @@ public class NetworkProviderCallsSmsControllerTest {
return mDefaultSmsSubscriptionId;
}
@Override
protected boolean isInService(int subId) {
return mIsInService;
}
public void setDefaultVoiceSubscriptionId(int subscriptionId) {
mDefaultVoiceSubscriptionId = subscriptionId;
}
@@ -111,6 +116,10 @@ public class NetworkProviderCallsSmsControllerTest {
public void setDefaultSmsSubscriptionId(int subscriptionId) {
mDefaultSmsSubscriptionId = subscriptionId;
}
public void setInService(boolean inService) {
mIsInService = inService;
}
}
@Before
@@ -128,7 +137,7 @@ public class NetworkProviderCallsSmsControllerTest {
mPreference = new RestrictedPreference(mContext);
mPreference.setKey(KEY_PREFERENCE_CALLS_SMS);
mController = new MockNetworkProviderCallsSmsController(mContext, mLifecycle);
mController.setInService(true);
mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
}
@@ -176,7 +185,7 @@ public class NetworkProviderCallsSmsControllerTest {
final StringBuilder summary = new StringBuilder();
summary.append(DISPLAY_NAME_1)
.append(" (")
.append(setSummaryResId("calls_sms_unavailable"))
.append(setSummaryResId("calls_sms_temp_unavailable"))
.append(")");
assertTrue(TextUtils.equals(mController.getSummary(), summary));