Merge "Import the window extension libary in the Settings app" into sc-v2-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 1268584..64bef73 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -276,10 +276,6 @@
                 <action android:name="android.settings.WIFI_SETTINGS" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
-            <intent-filter android:priority="1">
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="com.android.settings.SHORTCUT" />
-            </intent-filter>
             <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                 android:value="com.android.settings.wifi.WifiSettings" />
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -288,7 +284,7 @@
 
         <activity
             android:name="Settings$NetworkProviderSettingsActivity"
-            android:label="@string/network_dashboard_title"
+            android:label="@string/provider_internet_settings"
             android:icon="@drawable/ic_homepage_network"
             android:exported="true"
             android:configChanges="orientation|keyboardHidden|screenSize">
diff --git a/res/layout/settings_summary_preference.xml b/res/layout/settings_summary_preference.xml
index c4b6c1c..61f27ca 100644
--- a/res/layout/settings_summary_preference.xml
+++ b/res/layout/settings_summary_preference.xml
@@ -30,7 +30,7 @@
         android:layout_marginBottom="5dp"
         android:fontFamily="@*android:string/config_headlineFontFamily"
         android:paddingTop="0dp"
-        android:textColor="?android:attr/colorAccent"
+        android:textColor="?android:attr/textColorPrimary"
         android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Display1"
         />
 
@@ -45,9 +45,9 @@
     <ProgressBar
         android:id="@+id/color_bar"
         style="?android:attr/progressBarStyleHorizontal"
+        android:scaleY="1"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:progressDrawable="@drawable/color_bar_progress"/>
+        android:layout_height="wrap_content"/>
 
     <LinearLayout
         android:id="@+id/label_bar"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 03e2319..f193a31 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -13404,8 +13404,10 @@
     <string name="carrier_wifi_network_title">W+ network</string>
     <!-- Provider Model: title of SIM category -->
     <string name="sim_category_title">SIM</string>
-    <!-- Provider Model: title of Downloaded category. [CHAR LIMIT=50] -->
+    <!-- Provider Model: title of Downloaded SIM category. [CHAR LIMIT=50] -->
     <string name="downloaded_sim_category_title">DOWNLOADED SIM</string>
+    <!-- Provider Model: title of Downloaded SIMs category. [CHAR LIMIT=50] -->
+    <string name="downloaded_sims_category_title">DOWNLOADED SIMS</string>
     <!-- Provider Model: summary of Active in SIM category. [CHAR LIMIT=50] -->
     <string name="sim_category_active_sim">Active</string>
     <!-- Provider Model: summary of Inactive in SIM category. [CHAR LIMIT=50] -->
diff --git a/src/com/android/settings/network/NetworkProviderCallsSmsController.java b/src/com/android/settings/network/NetworkProviderCallsSmsController.java
index f83418b..c8b1c49 100644
--- a/src/com/android/settings/network/NetworkProviderCallsSmsController.java
+++ b/src/com/android/settings/network/NetworkProviderCallsSmsController.java
@@ -24,6 +24,7 @@
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
+import android.view.View;
 
 import androidx.annotation.VisibleForTesting;
 import androidx.lifecycle.LifecycleObserver;
@@ -44,12 +45,14 @@
 
     private static final String TAG = "NetworkProviderCallsSmsController";
     private static final String KEY = "calls_and_sms";
+    private static final String RTL_MARK = "\u200F";
 
     private UserManager mUserManager;
     private SubscriptionManager mSubscriptionManager;
     private SubscriptionsChangeListener mSubscriptionsChangeListener;
     private TelephonyManager mTelephonyManager;
     private RestrictedPreference mPreference;
+    private boolean mIsRtlMode;
 
     /**
      * The summary text and click behavior of the "Calls & SMS" item on the
@@ -61,6 +64,8 @@
         mUserManager = context.getSystemService(UserManager.class);
         mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
         mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
+        mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection()
+                == View.LAYOUT_DIRECTION_RTL;
         if (lifecycle != null) {
             mSubscriptionsChangeListener = new SubscriptionsChangeListener(context, this);
             lifecycle.addObserver(this);
@@ -121,6 +126,10 @@
                 if (subInfo != subs.get(subs.size() - 1)) {
                     summary.append(", ");
                 }
+
+                if (mIsRtlMode) {
+                    summary.insert(0, RTL_MARK).insert(summary.length(), RTL_MARK);
+                }
             }
             return summary;
         }
@@ -152,12 +161,12 @@
     }
 
     @VisibleForTesting
-    protected int getDefaultVoiceSubscriptionId(){
+    protected int getDefaultVoiceSubscriptionId() {
         return SubscriptionManager.getDefaultVoiceSubscriptionId();
     }
 
     @VisibleForTesting
-    protected int getDefaultSmsSubscriptionId(){
+    protected int getDefaultSmsSubscriptionId() {
         return SubscriptionManager.getDefaultSmsSubscriptionId();
     }
 
diff --git a/src/com/android/settings/network/NetworkProviderDownloadedSimsCategoryController.java b/src/com/android/settings/network/NetworkProviderDownloadedSimsCategoryController.java
index 199740f..f7c70f2 100644
--- a/src/com/android/settings/network/NetworkProviderDownloadedSimsCategoryController.java
+++ b/src/com/android/settings/network/NetworkProviderDownloadedSimsCategoryController.java
@@ -3,9 +3,11 @@
 import android.content.Context;
 
 import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
 import androidx.preference.PreferenceCategory;
 import androidx.preference.PreferenceScreen;
 
+import com.android.settings.R;
 import com.android.settings.widget.PreferenceCategoryController;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -15,6 +17,7 @@
 
     private static final String KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM =
             "provider_model_downloaded_sim_category";
+    private PreferenceCategory mPreferenceCategory;
     private NetworkProviderDownloadedSimListController mNetworkProviderDownloadedSimListController;
 
     public NetworkProviderDownloadedSimsCategoryController(Context context, String key) {
@@ -44,9 +47,19 @@
     @Override
     public void displayPreference(PreferenceScreen screen) {
         super.displayPreference(screen);
-        PreferenceCategory preferenceCategory = screen.findPreference(
+        mPreferenceCategory = screen.findPreference(
                 KEY_PREFERENCE_CATEGORY_DOWNLOADED_SIM);
-        preferenceCategory.setVisible(isAvailable());
+        mPreferenceCategory.setVisible(isAvailable());
         mNetworkProviderDownloadedSimListController.displayPreference(screen);
     }
+
+    @Override
+    public void updateState(Preference preference) {
+        super.updateState(preference);
+        int count = mPreferenceCategory.getPreferenceCount();
+        String title = mContext.getString(count > 1
+                ? R.string.downloaded_sims_category_title
+                : R.string.downloaded_sim_category_title);
+        mPreferenceCategory.setTitle(title);
+    }
 }
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index 35a34d4..fefae9e 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -710,6 +710,11 @@
             Log.i(TAG, "onWifiStateChanged called with wifi state: " + wifiState);
         }
 
+        if (isFinishingOrDestroyed()) {
+            Log.w(TAG, "onWifiStateChanged shouldn't run when fragment is finishing or destroyed");
+            return;
+        }
+
         switch (wifiState) {
             case WifiManager.WIFI_STATE_ENABLED:
                 updateWifiEntryPreferences();
@@ -981,6 +986,11 @@
 
     private String getSavedNetworkSettingsSummaryText(
             int numSavedNetworks, int numSavedSubscriptions) {
+        if (getResources() == null) {
+            Log.w(TAG, "getSavedNetworkSettingsSummaryText shouldn't run if resource is not ready");
+            return null;
+        }
+
         if (numSavedSubscriptions == 0) {
             return getResources().getQuantityString(R.plurals.wifi_saved_access_points_summary,
                     numSavedNetworks, numSavedNetworks);
diff --git a/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java b/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
index 36b19ba..16ac8f7 100644
--- a/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/CallsDefaultSubscriptionController.java
@@ -46,7 +46,7 @@
     @Override
     public CharSequence getSummary() {
         if (Utils.isProviderModelEnabled(mContext)) {
-            return MobileNetworkUtils.getPreferredStatus(mContext, mManager, true);
+            return MobileNetworkUtils.getPreferredStatus(isRtlMode(), mContext, mManager, true);
         } else {
             return super.getSummary();
         }
diff --git a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
index 4fb6cff7..d21d584 100644
--- a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java
@@ -26,6 +26,7 @@
 import android.telecom.TelecomManager;
 import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
+import android.view.View;
 
 import androidx.lifecycle.Lifecycle;
 import androidx.lifecycle.LifecycleObserver;
@@ -62,11 +63,14 @@
     private static final ComponentName PSTN_CONNECTION_SERVICE_COMPONENT =
             new ComponentName("com.android.phone",
                     "com.android.services.telephony.TelephonyConnectionService");
+    private boolean mIsRtlMode;
 
     public DefaultSubscriptionController(Context context, String preferenceKey) {
         super(context, preferenceKey);
         mManager = context.getSystemService(SubscriptionManager.class);
         mChangeListener = new SubscriptionsChangeListener(context, this);
+        mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection()
+                == View.LAYOUT_DIRECTION_RTL;
     }
 
     public void init(Lifecycle lifecycle) {
@@ -285,4 +289,8 @@
             refreshSummary(mPreference);
         }
     }
+
+    boolean isRtlMode() {
+        return mIsRtlMode;
+    }
 }
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index 1898484..6e5d4b7 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -99,6 +99,7 @@
             "esim.enable_esim_system_ui_by_default";
     private static final String LEGACY_ACTION_CONFIGURE_PHONE_ACCOUNT =
             "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
+    private static final String RTL_MARK = "\u200F";
 
     // The following constants are used to draw signal icon.
     public static final int NO_CELL_DATA_TYPE_ICON = 0;
@@ -922,7 +923,7 @@
     /**
      * Returns preferred status of Calls & SMS separately when Provider Model is enabled.
      */
-    public static CharSequence getPreferredStatus(Context context,
+    public static CharSequence getPreferredStatus(boolean isRtlMode, Context context,
             SubscriptionManager subscriptionManager, boolean isPreferredCallStatus) {
         final List<SubscriptionInfo> subs = SubscriptionUtil.getActiveSubscriptions(
                 subscriptionManager);
@@ -956,6 +957,10 @@
                 if (subInfo != subs.get(subs.size() - 1)) {
                     summary.append(", ");
                 }
+
+                if (isRtlMode) {
+                    summary.insert(0, RTL_MARK).insert(summary.length(), RTL_MARK);
+                }
             }
             return summary;
         } else {
diff --git a/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java b/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
index ca8c0f6..a73c621 100644
--- a/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
+++ b/src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java
@@ -62,7 +62,7 @@
     @Override
     public CharSequence getSummary() {
         if (Utils.isProviderModelEnabled(mContext)) {
-            return MobileNetworkUtils.getPreferredStatus(mContext, mManager, false);
+            return MobileNetworkUtils.getPreferredStatus(isRtlMode(), mContext, mManager, false);
         } else {
             return super.getSummary();
         }
diff --git a/src/com/android/settings/wifi/WifiDialog2.java b/src/com/android/settings/wifi/WifiDialog2.java
index dc546f3..05dad3f 100644
--- a/src/com/android/settings/wifi/WifiDialog2.java
+++ b/src/com/android/settings/wifi/WifiDialog2.java
@@ -21,6 +21,8 @@
 import android.content.DialogInterface;
 import android.os.Bundle;
 import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
 import android.widget.Button;
 import android.widget.ImageButton;
 import android.widget.TextView;
@@ -108,6 +110,8 @@
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
+        setWindowsOverlay();
+
         mView = getLayoutInflater().inflate(R.layout.wifi_dialog, /* root */ null);
         setView(mView);
         mController = new WifiConfigController2(this, mView, mWifiEntry, mMode);
@@ -126,6 +130,13 @@
         }
     }
 
+    private void setWindowsOverlay() {
+        final Window window = getWindow();
+        final WindowManager.LayoutParams lp = window.getAttributes();
+        window.setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
+        window.setAttributes(lp);
+    }
+
     @Override
     protected void onStart() {
         final ImageButton ssidScannerButton = findViewById(R.id.ssid_scanner_button);