From 6dd874305e8e14d4b06a0c3648390e9f663337b6 Mon Sep 17 00:00:00 2001 From: Antony Sargent Date: Mon, 15 Jul 2019 17:11:19 -0700 Subject: [PATCH] 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 --- .../telephony/MobileNetworkActivity.java | 7 +++++++ .../telephony/MobileNetworkActivityTest.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/com/android/settings/network/telephony/MobileNetworkActivity.java b/src/com/android/settings/network/telephony/MobileNetworkActivity.java index b8ed31f94b8..e20032f61ee 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkActivity.java +++ b/src/com/android/settings/network/telephony/MobileNetworkActivity.java @@ -76,6 +76,13 @@ public class MobileNetworkActivity extends SettingsBaseActivity { } }; + @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 f38f2a2bb0c..e43655b32d1 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 android.view.View; 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 @@ public class MobileNetworkActivityTest { 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); + } }