summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSooraj Sasindran <sasindran@google.com>2019-12-06 08:36:57 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-12-06 08:36:57 -0800
commitc64e2aa9c48ad9fd39cc7b959f17f8d805a79fc4 (patch)
treed6bbf2d73cb7e67709667acb2bd06bd5d590ddf7
parent2d1eefcfec3ede34c6a662d7fcd6a17af26ccc61 (diff)
parent334a2cb6bc8daa631245951f679f7921f23e7aa7 (diff)
downloadplatform_packages_services_AlternativeNetworkAccess-c64e2aa9c48ad9fd39cc7b959f17f8d805a79fc4.tar.gz
platform_packages_services_AlternativeNetworkAccess-c64e2aa9c48ad9fd39cc7b959f17f8d805a79fc4.tar.bz2
platform_packages_services_AlternativeNetworkAccess-c64e2aa9c48ad9fd39cc7b959f17f8d805a79fc4.zip
Switch data to default subscription am: 4b19d8f2ed
am: 334a2cb6bc Change-Id: Iffd1515cf0b9766248fcca19d1987c1f1e6b65a9
-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 ec0060c..a9e5fe1 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;
@@ -622,6 +623,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 86cf826..c979f4a 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);
@@ -544,4 +552,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);
+ }
+
}