[Settings] Fix RTL issue of Calls and SMS

Screenshot: https://screenshot.googleplex.com/9BqEh99vz7xp2g4.png

Bug: 189300799
Test: make
Change-Id: I022253efbe0ea25f11d5ac6c2b3b0fcd1d9f54aa
(cherry picked from commit 54bd206fbc319f8e2e6e4d6b7b735ee95ae43d07)
Merged-In: I022253efbe0ea25f11d5ac6c2b3b0fcd1d9f54aa
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/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();
         }