Merge "[Settings] Change the restart policy for MobileNetworkActivity" into rvc-dev am: fbe5a997d3

Change-Id: Ibb1ccf9625f7aa7d644bd5f4071068af007507ec
diff --git a/src/com/android/settings/network/telephony/MobileNetworkActivity.java b/src/com/android/settings/network/telephony/MobileNetworkActivity.java
index 0984102..5a4c70d 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkActivity.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkActivity.java
@@ -56,10 +56,15 @@
 
     @VisibleForTesting
     ProxySubscriptionManager mProxySubscriptionMgr;
+
     private int mCurSubscriptionId;
-    // To avoid from Preference Controller to have a complex design for the case of Activity
-    // restart. mIsEffectiveSubId is designed to force recreate of Preference Controller(s).
-    private boolean mIsEffectiveSubId;
+
+    // This flag forces subscription information fragment to be re-created.
+    // Otherwise, fragment will be kept when subscription id has not been changed.
+    //
+    // Set initial value to true allows subscription information fragment to be re-created when
+    // Activity re-create occur.
+    private boolean mFragmentForceReload = true;
 
     @Override
     protected void onNewIntent(Intent intent) {
@@ -73,7 +78,7 @@
         }
         int oldSubId = mCurSubscriptionId;
         mCurSubscriptionId = updateSubscriptionIndex;
-        mIsEffectiveSubId = (mCurSubscriptionId != SUB_ID_NULL);
+        mFragmentForceReload = (mCurSubscriptionId == oldSubId);
         updateSubscriptions(getSubscription());
 
         // If the subscription has changed or the new intent doesnt contain the opt in action,
@@ -117,7 +122,6 @@
                 : ((startIntent != null)
                 ? startIntent.getIntExtra(Settings.EXTRA_SUB_ID, SUB_ID_NULL)
                 : SUB_ID_NULL);
-        mIsEffectiveSubId = (mCurSubscriptionId != SUB_ID_NULL);
 
         final SubscriptionInfo subscription = getSubscription();
         updateTitleAndNavigation(subscription);
@@ -207,7 +211,7 @@
         switchFragment(subscription);
 
         mCurSubscriptionId = subscriptionIndex;
-        mIsEffectiveSubId = true;
+        mFragmentForceReload = false;
     }
 
     /**
@@ -217,7 +221,7 @@
      */
     @VisibleForTesting
     SubscriptionInfo getSubscription() {
-        if (mIsEffectiveSubId && (mCurSubscriptionId != SUB_ID_NULL)) {
+        if (mCurSubscriptionId != SUB_ID_NULL) {
             return getSubscriptionForSubId(mCurSubscriptionId);
         }
         final List<SubscriptionInfo> subInfos = getProxySubscriptionManager()
@@ -245,7 +249,7 @@
 
         final String fragmentTag = buildFragmentTag(subId);
         if (fragmentManager.findFragmentByTag(fragmentTag) != null) {
-            if (mIsEffectiveSubId) {
+            if (!mFragmentForceReload) {
                 Log.d(TAG, "Keep current fragment: " + fragmentTag);
                 return;
             }