summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-12-07 02:05:38 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-12-07 02:05:38 +0000
commitd04c1b3428c3294f1b50f5b493f8197f1cf182c4 (patch)
treeecd34cd20eda45080dd0e50c7efba958bab10500
parentdf16ec93c00aa9b1902e3d26a19e548fbf2c105d (diff)
parent4b19d8f2edb4c97ac5d0966275db3001adc0167e (diff)
downloadplatform_packages_services_AlternativeNetworkAccess-android10-qpr2-release.tar.gz
platform_packages_services_AlternativeNetworkAccess-android10-qpr2-release.tar.bz2
platform_packages_services_AlternativeNetworkAccess-android10-qpr2-release.zip
Change-Id: Ic150d082b3024a7ddc9e72e311bac24010b0a169
-rw-r--r--src/com/android/ons/ONSProfileSelector.java9
-rw-r--r--tests/src/com/android/ons/ONSProfileSelectorTest.java105
2 files changed, 113 insertions, 1 deletions
diff --git a/src/com/android/ons/ONSProfileSelector.java b/src/com/android/ons/ONSProfileSelector.java
index 4bf38b9..83c4883 100644
--- a/src/com/android/ons/ONSProfileSelector.java
+++ b/src/com/android/ons/ONSProfileSelector.java
@@ -97,7 +97,8 @@ public class ONSProfileSelector {
private ONSProfileSelectionCallback mProfileSelectionCallback;
private int mSequenceId;
private int mSubId;
- private int mCurrentDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+ @VisibleForTesting
+ protected int mCurrentDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
private ArrayList<AvailableNetworkInfo> mAvailableNetworkInfos;
private IUpdateAvailableNetworksCallback mNetworkScanCallback;
@@ -615,6 +616,12 @@ public class ONSProfileSelector {
return false;
}
+ // If disabling modem for opportunistic sub, make sure to switch data back to default sub.
+ if (!enable) {
+ if (mSubscriptionManager.getPreferredDataSubscriptionId() == subId) {
+ selectProfileForData(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, false, null);
+ }
+ }
int phoneId = SubscriptionManager.getPhoneId(subId);
/* Todo: b/135067156
* Reenable this code once 135067156 is fixed
diff --git a/tests/src/com/android/ons/ONSProfileSelectorTest.java b/tests/src/com/android/ons/ONSProfileSelectorTest.java
index a3b5a72..253971f 100644
--- a/tests/src/com/android/ons/ONSProfileSelectorTest.java
+++ b/tests/src/com/android/ons/ONSProfileSelectorTest.java
@@ -82,6 +82,14 @@ public class ONSProfileSelectorTest extends ONSBaseTest {
updateOpportunisticSubscriptions();
}
+ public int getCurrentPreferredData() {
+ return mCurrentDataSubId;
+ }
+
+ public void setCurrentPreferredData(int subId) {
+ mCurrentDataSubId = subId;
+ }
+
protected void init(Context c,
MyONSProfileSelector.ONSProfileSelectionCallback aNSProfileSelectionCallback) {
super.init(c, aNSProfileSelectionCallback);
@@ -543,4 +551,101 @@ public class ONSProfileSelectorTest extends ONSBaseTest {
assertEquals(TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS, mResult);
assertTrue(mReady);
}
+
+ @Test
+ public void testStopProfileSelectionWithPreferredDataOnSame() {
+ List<SubscriptionInfo> subscriptionInfoList = new ArrayList<SubscriptionInfo>();
+ SubscriptionInfo subscriptionInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1,
+ "123", 1, null, "310", "210", "", true, null, "1", true, null, 0, 0);
+ subscriptionInfoList.add(subscriptionInfo);
+
+ IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() {
+ @Override
+ public void onComplete(int result) {
+ mResult = result;
+ }
+ };
+
+ mResult = -1;
+ mReady = false;
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ Looper.prepare();
+ doReturn(subscriptionInfoList).when(mSubscriptionManager)
+ .getOpportunisticSubscriptions();
+ doReturn(true).when(mSubscriptionManager).isActiveSubId(anyInt());
+ doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot(
+ anyInt(), anyBoolean());
+ doReturn(5).when(mSubscriptionManager).getPreferredDataSubscriptionId();
+ doReturn(subscriptionInfoList).when(mSubscriptionManager)
+ .getActiveSubscriptionInfoList(anyBoolean());
+
+ mONSProfileSelector = new MyONSProfileSelector(mContext,
+ new MyONSProfileSelector.ONSProfileSelectionCallback() {
+ public void onProfileSelectionDone() {
+ setReady(true);
+ }
+ });
+ mONSProfileSelector.updateOppSubs();
+ mONSProfileSelector.setCurrentPreferredData(5);
+ mONSProfileSelector.stopProfileSelection(null);
+ mLooper = Looper.myLooper();
+ setReady(true);
+ Looper.loop();
+ }
+ }).start();
+ waitUntilReady();
+ waitForMs(500);
+ assertEquals(mONSProfileSelector.getCurrentPreferredData(), SubscriptionManager.DEFAULT_SUBSCRIPTION_ID);
+ }
+
+ @Test
+ public void testStopProfileSelectionWithPreferredDataOnDifferent() {
+ List<SubscriptionInfo> subscriptionInfoList = new ArrayList<SubscriptionInfo>();
+ SubscriptionInfo subscriptionInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1,
+ "123", 1, null, "310", "210", "", true, null, "1", true, null, 0, 0);
+ subscriptionInfoList.add(subscriptionInfo);
+
+ IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() {
+ @Override
+ public void onComplete(int result) {
+ mResult = result;
+ }
+ };
+
+ mResult = -1;
+ mReady = false;
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ Looper.prepare();
+ doReturn(subscriptionInfoList).when(mSubscriptionManager)
+ .getOpportunisticSubscriptions();
+ doReturn(true).when(mSubscriptionManager).isActiveSubId(anyInt());
+ doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot(
+ anyInt(), anyBoolean());
+ doReturn(4).when(mSubscriptionManager).getPreferredDataSubscriptionId();
+ doReturn(subscriptionInfoList).when(mSubscriptionManager)
+ .getActiveSubscriptionInfoList(anyBoolean());
+
+ mONSProfileSelector = new MyONSProfileSelector(mContext,
+ new MyONSProfileSelector.ONSProfileSelectionCallback() {
+ public void onProfileSelectionDone() {
+ setReady(true);
+ }
+ });
+ mONSProfileSelector.updateOppSubs();
+ mONSProfileSelector.setCurrentPreferredData(5);
+ mONSProfileSelector.stopProfileSelection(null);
+ mLooper = Looper.myLooper();
+ setReady(true);
+ Looper.loop();
+ }
+ }).start();
+ waitUntilReady();
+ waitForMs(500);
+ assertEquals(mONSProfileSelector.getCurrentPreferredData(), 5);
+ }
+
}