Merge "Switch Settings from IConnectivityManager to VpnManager." into sc-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index bc86338..83029f4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4950,6 +4950,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] -->
@@ -5276,17 +5278,40 @@
     <!-- Summary shown for tritanomaly (blue-yellow color blindness) [CHAR LIMIT=45] -->
     <string name="daltonizer_mode_tritanomaly_summary">Blue-yellow</string>
 
-    <!-- TODO(b/170970602): remove translatable=false when RBC has official name and strings -->
-    <!-- Title for the accessibility preference to configure Reduce Bright Colors feature. [CHAR LIMIT=NONE] -->
-    <string name="reduce_bright_colors_preference_title" translatable="false">Reduce Bright Colors</string>
-    <!-- Used in the accessibility service settings to control switching Reduce Bright Colors on/off. [CHAR LIMIT=NONE] -->
-    <string name="reduce_bright_colors_switch_title" translatable="false">Use Reduce Bright Colors</string>
-    <!-- Subtitle that describes Reduce Bright Colors. [CHAR LIMIT=NONE] -->
-    <string name="reduce_bright_colors_preference_subtitle" translatable="false">Reduce Bright Colors reduces screen brightness.</string>
-    <!-- Title for setting the brightness intensity of the display using Reduce Bright Colors. [CHAR LIMIT=NONE] -->
-    <string name="reduce_bright_colors_intensity_preference_title" translatable="false">Intensity</string>
-    <!-- Title for setting whether the Reduce Bright Colors activation state persists across reboots. [CHAR LIMIT=NONE] -->
-    <string name="reduce_bright_colors_persist_preference_title" translatable="false">Keeps feature on after a restart</string>
+    <!-- Title for the accessibility preference and switch of the Reduce Brightness feature. [CHAR LIMIT=NONE] -->
+    <string name="reduce_bright_colors_preference_title">Reduce Brightness</string>
+    <!-- Summary for the accessibility preference to configure Reduce Brightness feature. [CHAR LIMIT=NONE] -->
+    <string name="reduce_bright_colors_preference_summary" product="default">Make screen darker than your phone\u2019s minimum brightness</string>
+    <!-- Summary for the accessibility preference to configure Reduce Brightness feature. [CHAR LIMIT=NONE] -->
+    <string name="reduce_bright_colors_preference_summary" product="tablet">Make screen darker than your tablet\u2019s minimum brightness</string>
+    <!-- Subtitle that describes Reduce Brightness. [CHAR LIMIT=NONE] -->
+    <string name="reduce_bright_colors_preference_subtitle" product="default">
+        <![CDATA[Make your screen darker so it\u2019s more comfortable to read.<br/><br/>
+        This can be helpful when:
+        <ol>
+            <li>\u00a0Your phone\u2019s default minimum brightness is still too bright</li>
+            <li>\u00a0You\u2019re using your phone in dark situations, like at night or in a dark room before bed</li>
+        </ol>
+        ]]>
+    </string>
+    <!-- Subtitle that describes Reduce Brightness. [CHAR LIMIT=NONE] -->
+    <string name="reduce_bright_colors_preference_subtitle" product="tablet">
+        <![CDATA[Make your screen darker so it\u2019s more comfortable to read.<br/><br/>
+        This can be helpful when:
+        <ol>
+            <li>\u00a0Your tablet\u2019s default minimum brightness is still too bright</li>
+            <li>\u00a0You\u2019re using your tablet in dark situations, like at night or in a dark room before bed</li>
+        </ol>
+        ]]>
+    </string>
+    <!-- Title for setting the brightness intensity of the display using Reduce Brightness. [CHAR LIMIT=NONE] -->
+    <string name="reduce_bright_colors_intensity_preference_title">Intensity</string>
+    <!-- Start label for setting the brightness intensity of the display using Reduce Brightness. [CHAR LIMIT=50] -->
+    <string name="reduce_bright_colors_intensity_preference_start_label">Slightly darker</string>
+    <!-- End label for setting the brightness intensity of the display using Reduce Brightness. [CHAR LIMIT=NONE] -->
+    <string name="reduce_bright_colors_intensity_preference_end_label">Darkest</string>
+    <!-- Title for setting whether the Reduce Brightness activation state persists across reboots. [CHAR LIMIT=NONE] -->
+    <string name="reduce_bright_colors_persist_preference_title">Keep on after device restarts</string>
 
     <!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
     <plurals name="accessibilty_autoclick_preference_subtitle_short_delay">
@@ -12567,13 +12592,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] -->
diff --git a/res/xml/accessibility_text_and_display.xml b/res/xml/accessibility_text_and_display.xml
index 7dce826..bd30e61 100644
--- a/res/xml/accessibility_text_and_display.xml
+++ b/res/xml/accessibility_text_and_display.xml
@@ -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>
\ No newline at end of file
diff --git a/res/xml/accessibility_turn_screen_darker.xml b/res/xml/accessibility_turn_screen_darker.xml
new file mode 100644
index 0000000..d87f23b
--- /dev/null
+++ b/res/xml/accessibility_turn_screen_darker.xml
@@ -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>
\ No newline at end of file
diff --git a/src/com/android/settings/accessibility/TextAndDisplayFragment.java b/src/com/android/settings/accessibility/TextAndDisplayFragment.java
index b496e3d..e81dded 100644
--- a/src/com/android/settings/accessibility/TextAndDisplayFragment.java
+++ b/src/com/android/settings/accessibility/TextAndDisplayFragment.java
@@ -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 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 @@
 
     // 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;
 
@@ -68,12 +61,6 @@
     }
 
     @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 @@
         // 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 @@
         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);
         }
diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
index 5562795..ca19681 100644
--- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
@@ -157,7 +157,7 @@
 
     @Override
     protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
-        switchPreference.setTitle(R.string.reduce_bright_colors_switch_title);
+        switchPreference.setTitle(R.string.reduce_bright_colors_preference_title);
     }
 
     @Override
diff --git a/src/com/android/settings/accessibility/TurnScreenDarkerFragment.java b/src/com/android/settings/accessibility/TurnScreenDarkerFragment.java
new file mode 100644
index 0000000..ad4bd56
--- /dev/null
+++ b/src/com/android/settings/accessibility/TurnScreenDarkerFragment.java
@@ -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);
+}
diff --git a/src/com/android/settings/network/NetworkProviderCallsSmsController.java b/src/com/android/settings/network/NetworkProviderCallsSmsController.java
index 417c4a9..f83418b 100644
--- a/src/com/android/settings/network/NetworkProviderCallsSmsController.java
+++ b/src/com/android/settings/network/NetworkProviderCallsSmsController.java
@@ -20,8 +20,10 @@
 
 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 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 @@
     private UserManager mUserManager;
     private SubscriptionManager mSubscriptionManager;
     private SubscriptionsChangeListener mSubscriptionsChangeListener;
-
+    private TelephonyManager mTelephonyManager;
     private RestrictedPreference mPreference;
 
     /**
@@ -57,6 +60,7 @@
 
         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 @@
             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 @@
     }
 
     @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 @@
         refreshSummary(mPreference);
         update();
     }
+
+    @VisibleForTesting
+    protected boolean isInService(int subId) {
+        ServiceState serviceState =
+                mTelephonyManager.createForSubscriptionId(subId).getServiceState();
+        return Utils.isInService(serviceState);
+    }
 }
diff --git a/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java b/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
index 99009c9..36b19ba 100644
--- a/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
@@ -20,6 +20,8 @@
 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 @@
     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();
+        }
+    }
 }
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index e8f9770..0834632 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -73,6 +73,7 @@
 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 @@
         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 @@
         }
         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);
+    }
+
 }
diff --git a/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java b/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
index fadddd5..ca8c0f6 100644
--- a/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
@@ -21,6 +21,8 @@
 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 @@
         // 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();
+        }
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/accessibility/TurnScreenDarkerFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/TurnScreenDarkerFragmentTest.java
new file mode 100644
index 0000000..f256201
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/TurnScreenDarkerFragmentTest.java
@@ -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);
+    }
+}
diff --git a/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsControllerTest.java b/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsControllerTest.java
index 16433c3..eba45d4 100644
--- a/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsControllerTest.java
+++ b/tests/unit/src/com/android/settings/network/NetworkProviderCallsSmsControllerTest.java
@@ -93,7 +93,7 @@
 
         private int mDefaultVoiceSubscriptionId;
         private int mDefaultSmsSubscriptionId;
-
+        private boolean mIsInService;
         @Override
         protected int getDefaultVoiceSubscriptionId() {
             return mDefaultVoiceSubscriptionId;
@@ -104,6 +104,11 @@
             return mDefaultSmsSubscriptionId;
         }
 
+        @Override
+        protected boolean isInService(int subId) {
+            return mIsInService;
+        }
+
         public void setDefaultVoiceSubscriptionId(int subscriptionId) {
             mDefaultVoiceSubscriptionId = subscriptionId;
         }
@@ -111,6 +116,10 @@
         public void setDefaultSmsSubscriptionId(int subscriptionId) {
             mDefaultSmsSubscriptionId = subscriptionId;
         }
+
+        public void setInService(boolean inService) {
+            mIsInService = inService;
+        }
     }
 
     @Before
@@ -128,7 +137,7 @@
         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 @@
         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));