Fix issue that the wifi calling text cannot be customized based on sim

Some carriers have requirements that the wifi calling text should be
customizable. However, the resources for the wifi calling text are
not obtained based on sim. So it cannot be customized per sim for multi
sim device. To solve this issue, obtain the resources with specified
sim.

Test: manual - Checked that the wifi calling text could be customized
based on sim.
Bug: 117257109

Change-Id: I6b3f6b06c9cc984ee6a68a19ae317b5d1d4e48e2
Merged-In: I6b3f6b06c9cc984ee6a68a19ae317b5d1d4e48e2
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 21bec16..5a536d9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2337,7 +2337,7 @@
         <item>"1"</item>
     </string-array>
     <!-- Wi-Fi Calling settings. Text displayed when Wi-Fi Calling is off -->
-    <string name="wifi_calling_off_explanation">When Wi-Fi calling is on, your phone can route calls via Wi-Fi networks or your carrier\u2019s network, depending on your preference and which signal is stronger. Before turning on this feature, check with your carrier regarding fees and other details.</string>
+    <string name="wifi_calling_off_explanation">When Wi-Fi calling is on, your phone can route calls via Wi-Fi networks or your carrier\u2019s network, depending on your preference and which signal is stronger. Before turning on this feature, check with your carrier regarding fees and other details.<xliff:g id="additional_text" example="Learn More">%1$s</xliff:g></string>
     <!-- Wi-Fi Calling settings. Additional text displayed when Wi-Fi Calling is off. Default empty. [CHAR LIMIT=NONE] -->
     <string name="wifi_calling_off_explanation_2"></string>
     <!-- Title of a preference for updating emergency address [CHAR LIMIT=40] -->
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettings.java b/src/com/android/settings/wifi/calling/WifiCallingSettings.java
index a9c0ee9..5d11c55 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSettings.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettings.java
@@ -29,6 +29,7 @@
 
 import com.android.ims.ImsManager;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.util.CollectionUtils;
 import com.android.settings.R;
 import com.android.settings.core.InstrumentedFragment;
 import com.android.settings.search.actionbar.SearchMenuController;
@@ -52,6 +53,24 @@
     private WifiCallingViewPagerAdapter mPagerAdapter;
     private SlidingTabLayout mTabLayout;
 
+    private final class InternalViewPagerListener implements
+            RtlCompatibleViewPager.OnPageChangeListener {
+        @Override
+        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+            // Do nothing.
+        }
+
+        @Override
+        public void onPageSelected(int position) {
+            updateTitleForCurrentSub();
+        }
+
+        @Override
+        public void onPageScrollStateChanged(int state) {
+            // Do nothing.
+        }
+    }
+
     @Override
     public int getMetricsCategory() {
         return MetricsEvent.WIFI_CALLING;
@@ -67,6 +86,7 @@
 
         mPagerAdapter = new WifiCallingViewPagerAdapter(getChildFragmentManager(), mViewPager);
         mViewPager.setAdapter(mPagerAdapter);
+        mViewPager.addOnPageChangeListener(new InternalViewPagerListener());
 
         return view;
     }
@@ -92,6 +112,8 @@
         } else {
             mTabLayout.setVisibility(View.GONE);
         }
+
+        updateTitleForCurrentSub();
     }
 
     @Override
@@ -162,4 +184,13 @@
             }
         }
     }
+
+    private void updateTitleForCurrentSub() {
+        if (CollectionUtils.size(mSil) > 1) {
+            final int subId = mSil.get(mViewPager.getCurrentItem()).getSubscriptionId();
+            final String title = SubscriptionManager.getResourcesForSubId(getContext(), subId)
+                    .getString(R.string.wifi_calling_settings_title);
+            getActivity().getActionBar().setTitle(title);
+        }
+    }
 }
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
index 00f4758..8659938 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
@@ -23,6 +23,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.res.Resources;
 import android.os.Bundle;
 import android.os.PersistableBundle;
 import androidx.preference.ListPreference;
@@ -158,8 +159,9 @@
 
         mEmptyView = getView().findViewById(android.R.id.empty);
         setEmptyView(mEmptyView);
-        String emptyViewText = activity.getString(R.string.wifi_calling_off_explanation)
-                + activity.getString(R.string.wifi_calling_off_explanation_2);
+        final Resources res = SubscriptionManager.getResourcesForSubId(getActivity(), mSubId);
+        String emptyViewText = res.getString(R.string.wifi_calling_off_explanation,
+                res.getString(R.string.wifi_calling_off_explanation_2));
         mEmptyView.setText(emptyViewText);
 
         mSwitchBar = getView().findViewById(R.id.switch_bar);