From f1a52da79241a93bb1ca703f81daa640d2b4a352 Mon Sep 17 00:00:00 2001 From: changbetty Date: Wed, 8 Jan 2020 15:24:20 +0800 Subject: [PATCH] [Mainline] Use isActiveSubscriptionId instead of isActiveSubId for mainline Bug: 147206736 Test: make RunSettingsRoboTests ROBOTEST_FILTER=DisabledSubscriptionControllerTest make RunSettingsRoboTests ROBOTEST_FILTER=MobileNetworkSwitchControllerTest make RunSettingsRoboTests ROBOTEST_FILTER=SimSelectNotificationTest Merged-In: If740c2d7ea2c1392d5fe538091ea6e5c4575ad26 Change-Id: Idca7a76c591448a45ecc33cb392f416c70d32f91 --- .../telephony/MobileNetworkSwitchController.java | 6 ++---- .../settings/sim/SimSelectNotification.java | 2 +- .../MobileNetworkSwitchControllerTest.java | 14 +++++++------- .../settings/sim/SimSelectNotificationTest.java | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java index 02396ddef70..d04653c67b6 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java +++ b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java @@ -83,7 +83,7 @@ public class MobileNetworkSwitchController extends BasePreferenceController impl mSwitchBar.addOnSwitchChangeListener((switchView, isChecked) -> { // TODO b/135222940: re-evaluate whether to use // mSubscriptionManager#isSubscriptionEnabled - if (mSubscriptionManager.isActiveSubId(mSubId) != isChecked + if (mSubscriptionManager.isActiveSubscriptionId(mSubId) != isChecked && (!mSubscriptionManager.setSubscriptionEnabled(mSubId, isChecked))) { mSwitchBar.setChecked(!isChecked); } @@ -110,9 +110,7 @@ public class MobileNetworkSwitchController extends BasePreferenceController impl mSwitchBar.hide(); } else { mSwitchBar.show(); - // TODO b/135222940: re-evaluate whether to use - // mSubscriptionManager#isSubscriptionEnabled - mSwitchBar.setChecked(mSubscriptionManager.isActiveSubId(mSubId)); + mSwitchBar.setChecked(mSubscriptionManager.isActiveSubscriptionId(mSubId)); } } diff --git a/src/com/android/settings/sim/SimSelectNotification.java b/src/com/android/settings/sim/SimSelectNotification.java index fbf766c4983..02616f5ce16 100644 --- a/src/com/android/settings/sim/SimSelectNotification.java +++ b/src/com/android/settings/sim/SimSelectNotification.java @@ -103,7 +103,7 @@ public class SimSelectNotification extends BroadcastReceiver { SubscriptionManager subscriptionManager = ((SubscriptionManager) context.getSystemService( Context.TELEPHONY_SUBSCRIPTION_SERVICE)); - if (!subscriptionManager.isActiveSubId(subId)) { + if (!subscriptionManager.isActiveSubscriptionId(subId)) { Log.w(TAG, "onEnableMmsDataRequest invalid sub ID " + subId); return; } diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java index ccf345f8bdd..fb06e190266 100644 --- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkSwitchControllerTest.java @@ -109,7 +109,7 @@ public class MobileNetworkSwitchControllerTest { @Test public void displayPreference_oneEnabledSubscription_switchBarNotHidden() { - doReturn(true).when(mSubscriptionManager).isActiveSubId(mSubId); + doReturn(true).when(mSubscriptionManager).isActiveSubscriptionId(mSubId); SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription)); mController.displayPreference(mScreen); assertThat(mSwitchBar.isShowing()).isTrue(); @@ -117,7 +117,7 @@ public class MobileNetworkSwitchControllerTest { @Test public void displayPreference_oneDisabledSubscription_switchBarNotHidden() { - doReturn(false).when(mSubscriptionManager).isActiveSubId(mSubId); + doReturn(false).when(mSubscriptionManager).isActiveSubscriptionId(mSubId); SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription)); mController.displayPreference(mScreen); assertThat(mSwitchBar.isShowing()).isTrue(); @@ -125,7 +125,7 @@ public class MobileNetworkSwitchControllerTest { @Test public void displayPreference_subscriptionEnabled_switchIsOn() { - when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true); + when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true); mController.displayPreference(mScreen); assertThat(mSwitchBar.isShowing()).isTrue(); assertThat(mSwitchBar.isChecked()).isTrue(); @@ -133,7 +133,7 @@ public class MobileNetworkSwitchControllerTest { @Test public void displayPreference_subscriptionDisabled_switchIsOff() { - when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(false); + when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(false); mController.displayPreference(mScreen); assertThat(mSwitchBar.isShowing()).isTrue(); assertThat(mSwitchBar.isChecked()).isFalse(); @@ -141,7 +141,7 @@ public class MobileNetworkSwitchControllerTest { @Test public void switchChangeListener_fromEnabledToDisabled_setSubscriptionEnabledCalledCorrectly() { - when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true); + when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true); mController.displayPreference(mScreen); assertThat(mSwitchBar.isShowing()).isTrue(); assertThat(mSwitchBar.isChecked()).isTrue(); @@ -153,7 +153,7 @@ public class MobileNetworkSwitchControllerTest { public void switchChangeListener_fromEnabledToDisabled_setSubscriptionEnabledFailed() { when(mSubscriptionManager.setSubscriptionEnabled(eq(mSubId), anyBoolean())) .thenReturn(false); - when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true); + when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true); mController.displayPreference(mScreen); assertThat(mSwitchBar.isShowing()).isTrue(); assertThat(mSwitchBar.isChecked()).isTrue(); @@ -164,7 +164,7 @@ public class MobileNetworkSwitchControllerTest { @Test public void switchChangeListener_fromDisabledToEnabled_setSubscriptionEnabledCalledCorrectly() { - when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(false); + when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(false); mController.displayPreference(mScreen); assertThat(mSwitchBar.isShowing()).isTrue(); assertThat(mSwitchBar.isChecked()).isFalse(); diff --git a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java index 9b536363499..8f861eb7f46 100644 --- a/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java +++ b/tests/robotests/src/com/android/settings/sim/SimSelectNotificationTest.java @@ -117,7 +117,7 @@ public class SimSelectNotificationTest { when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager); when(mTelephonyManager.isDataEnabledForApn(TYPE_MMS)).thenReturn(false); - when(mSubscriptionManager.isActiveSubId(mSubId)).thenReturn(true); + when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true); when(mSubscriptionManager.getActiveSubscriptionInfo(mSubId)).thenReturn(mSubInfo); when(mSubInfo.getDisplayName()).thenReturn(mFakeDisplayName); when(mContext.getResources()).thenReturn(mResources);