Make MobileNetworkActivity support onNewIntent

The launchMode for MobileNetworkActivity specified in the android
manifest is "singleTask", which means that when an intent to it is
launched, if there is an existing instance we will reuse that instead of
creating a new one. But to handle this properly we need to know when it
happens by implementing onNewIntent, which we weren't doing.

Implementing this fixes a bug we noticed that if you have multiple SIMs
and recently visit the details page for SIM 1 but then click on a SIM
selection notification that should bring you to the details for SIM 2,
we'd just bring up the details page for SIM 1 again.

Fixes: 133447239
Test: make RunSettingsRoboTests
Change-Id: Ia9106b15ffde437f6dd6fd2da23336ec5b28f75e
diff --git a/src/com/android/settings/network/telephony/MobileNetworkActivity.java b/src/com/android/settings/network/telephony/MobileNetworkActivity.java
index b8ed31f..e20032f 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkActivity.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkActivity.java
@@ -77,6 +77,13 @@
     };
 
     @Override
+    protected void onNewIntent(Intent intent) {
+        super.onNewIntent(intent);
+        setIntent(intent);
+        updateSubscriptions(null);
+    }
+
+    @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkActivityTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkActivityTest.java
index f38f2a2..e43655b 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkActivityTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkActivityTest.java
@@ -40,6 +40,8 @@
 import com.android.internal.telephony.TelephonyIntents;
 import com.android.internal.view.menu.ContextMenuBuilder;
 import com.android.settings.R;
+import com.android.settings.core.FeatureFlags;
+import com.android.settings.development.featureflags.FeatureFlagPersistent;
 import com.android.settings.network.SubscriptionUtil;
 
 import com.google.android.material.bottomnavigation.BottomNavigationView;
@@ -207,4 +209,19 @@
 
         assertThat(bundle.getInt(Settings.EXTRA_SUB_ID)).isEqualTo(PREV_SUB_ID);
     }
+
+    @Test
+    public void onNewIntent_newSubscriptionId_fragmentReplaced() {
+        FeatureFlagPersistent.setEnabled(mContext, FeatureFlags.NETWORK_INTERNET_V2, true);
+
+        mSubscriptionInfos.add(mSubscriptionInfo);
+        mSubscriptionInfos.add(mSubscriptionInfo2);
+        SubscriptionUtil.setAvailableSubscriptionsForTesting(mSubscriptionInfos);
+        mMobileNetworkActivity.mCurSubscriptionId = PREV_SUB_ID;
+
+        final Intent newIntent = new Intent();
+        newIntent.putExtra(Settings.EXTRA_SUB_ID, CURRENT_SUB_ID);
+        mMobileNetworkActivity.onNewIntent(newIntent);
+        assertThat(mMobileNetworkActivity.mCurSubscriptionId).isEqualTo(CURRENT_SUB_ID);
+    }
 }