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
This commit is contained in:
Antony Sargent
2019-07-15 17:11:19 -07:00
parent 365beaebdb
commit 6dd874305e
2 changed files with 24 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);
}
}