Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 16 | package com.android.ons; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 17 | |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 18 | import static org.mockito.Mockito.*; |
| 19 | |
| 20 | import android.content.BroadcastReceiver; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 23 | import android.os.IBinder; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 24 | import android.os.Looper; |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 25 | import android.os.ServiceManager; |
Sooraj Sasindran | 2394227 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 26 | import android.telephony.AvailableNetworkInfo; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 27 | import android.telephony.CellIdentityLte; |
Avinash Malipatil | 284c5ef | 2022-08-17 07:29:56 +0000 | [diff] [blame] | 28 | import android.telephony.CellIdentityNr; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 29 | import android.telephony.CellInfo; |
| 30 | import android.telephony.CellInfoLte; |
Avinash Malipatil | 284c5ef | 2022-08-17 07:29:56 +0000 | [diff] [blame] | 31 | import android.telephony.CellInfoNr; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 32 | import android.telephony.SubscriptionInfo; |
| 33 | import android.telephony.SubscriptionManager; |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 34 | import android.telephony.TelephonyManager; |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 35 | import android.telephony.UiccCardInfo; |
| 36 | import android.telephony.UiccPortInfo; |
| 37 | import android.telephony.euicc.EuiccManager; |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 38 | import android.util.Log; |
| 39 | |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 40 | import com.android.internal.telephony.ISub; |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 41 | import com.android.internal.telephony.IUpdateAvailableNetworksCallback; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 42 | |
| 43 | import org.junit.After; |
| 44 | import org.junit.Before; |
| 45 | import org.junit.Test; |
| 46 | import org.mockito.Mock; |
| 47 | import org.mockito.MockitoAnnotations; |
| 48 | |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 49 | import java.lang.reflect.Field; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 50 | import java.util.ArrayList; |
Avinash Malipatil | 284c5ef | 2022-08-17 07:29:56 +0000 | [diff] [blame] | 51 | import java.util.Collections; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 52 | import java.util.List; |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 53 | import java.util.Map; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 54 | |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 55 | public class ONSProfileSelectorTest extends ONSBaseTest { |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 56 | |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 57 | private MyONSProfileSelector mONSProfileSelector; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 58 | private boolean testFailed; |
| 59 | private boolean mCallbackInvoked; |
| 60 | private int mDataSubId; |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 61 | private int mResult; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 62 | @Mock |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 63 | EuiccManager mMockEuiccManager; |
| 64 | @Mock |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 65 | ONSNetworkScanCtlr mONSNetworkScanCtlr; |
danielwbhuang | f699f74 | 2019-07-03 21:42:59 +0800 | [diff] [blame] | 66 | @Mock |
| 67 | TelephonyManager mSubscriptionBoundTelephonyManager; |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 68 | @Mock |
| 69 | ISub mISubMock; |
| 70 | @Mock |
| 71 | IBinder mISubBinderMock; |
| 72 | @Mock |
| 73 | SubscriptionInfo mSubInfo; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 74 | private Looper mLooper; |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 75 | private static final String TAG = "ONSProfileSelectorTest"; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 76 | |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 77 | MyONSProfileSelector.ONSProfileSelectionCallback mONSProfileSelectionCallback = |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 78 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 79 | public void onProfileSelectionDone() { |
| 80 | mCallbackInvoked = true; |
| 81 | setReady(true); |
| 82 | } |
| 83 | }; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 84 | |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 85 | public class MyONSProfileSelector extends ONSProfileSelector { |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 86 | |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 87 | public SubscriptionManager.OnOpportunisticSubscriptionsChangedListener mProfileChngLstnrCpy; |
| 88 | public BroadcastReceiver mProfileSelectorBroadcastReceiverCpy; |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 89 | public ONSNetworkScanCtlr.NetworkAvailableCallBack mNetworkAvailableCallBackCpy; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 90 | |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 91 | public MyONSProfileSelector(Context c, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 92 | MyONSProfileSelector.ONSProfileSelectionCallback aNSProfileSelectionCallback) { |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 93 | super(c, aNSProfileSelectionCallback); |
| 94 | } |
| 95 | |
| 96 | public void triggerProfileUpdate() { |
| 97 | mHandler.sendEmptyMessage(1); |
| 98 | } |
| 99 | |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 100 | public void updateOppSubs() { |
| 101 | updateOpportunisticSubscriptions(); |
| 102 | } |
| 103 | |
Sooraj Sasindran | 4b19d8f | 2019-11-19 11:24:28 -0800 | [diff] [blame] | 104 | public int getCurrentPreferredData() { |
| 105 | return mCurrentDataSubId; |
| 106 | } |
| 107 | |
| 108 | public void setCurrentPreferredData(int subId) { |
| 109 | mCurrentDataSubId = subId; |
| 110 | } |
| 111 | |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 112 | protected void init(Context c, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 113 | MyONSProfileSelector.ONSProfileSelectionCallback aNSProfileSelectionCallback) { |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 114 | super.init(c, aNSProfileSelectionCallback); |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 115 | this.mSubscriptionManager = ONSProfileSelectorTest.this.mSubscriptionManager; |
danielwbhuang | f699f74 | 2019-07-03 21:42:59 +0800 | [diff] [blame] | 116 | this.mSubscriptionBoundTelephonyManager = |
| 117 | ONSProfileSelectorTest.this.mSubscriptionBoundTelephonyManager; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 118 | mProfileChngLstnrCpy = mProfileChangeListener; |
Sooraj Sasindran | 3247a4b | 2019-04-01 15:30:16 -0700 | [diff] [blame] | 119 | mProfileSelectorBroadcastReceiverCpy = null; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 120 | mNetworkAvailableCallBackCpy = mNetworkAvailableCallBack; |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 121 | mNetworkScanCtlr = mONSNetworkScanCtlr; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 125 | private void addISubService() throws Exception { |
| 126 | Field field = ServiceManager.class.getDeclaredField("sCache"); |
| 127 | field.setAccessible(true); |
| 128 | ((Map<String, IBinder>)field.get(null)).put("isub", mISubBinderMock); |
| 129 | doReturn(mISubMock).when(mISubBinderMock).queryLocalInterface(any()); |
| 130 | } |
| 131 | |
| 132 | private void removeISubService() throws Exception { |
| 133 | Field field = ServiceManager.class.getDeclaredField("sCache"); |
| 134 | field.setAccessible(true); |
| 135 | ((Map<String, IBinder>)field.get(null)).remove("isub"); |
| 136 | } |
| 137 | |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 138 | @Before |
| 139 | public void setUp() throws Exception { |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 140 | super.setUp("ONSTest"); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 141 | mLooper = null; |
| 142 | MockitoAnnotations.initMocks(this); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 143 | addISubService(); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | @After |
| 147 | public void tearDown() throws Exception { |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 148 | removeISubService(); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 149 | super.tearDown(); |
| 150 | if (mLooper != null) { |
| 151 | mLooper.quit(); |
| 152 | mLooper.getThread().join(); |
| 153 | } |
| 154 | } |
| 155 | |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 156 | |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 157 | @Test |
| 158 | public void testStartProfileSelectionWithNoOpportunisticSub() { |
| 159 | List<CellInfo> results2 = new ArrayList<CellInfo>(); |
| 160 | CellIdentityLte cellIdentityLte = new CellIdentityLte(310, 210, 1, 1, 1); |
| 161 | CellInfoLte cellInfoLte = new CellInfoLte(); |
| 162 | cellInfoLte.setCellIdentity(cellIdentityLte); |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 163 | results2.add((CellInfo) cellInfoLte); |
Sooraj Sasindran | 2394227 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 164 | ArrayList<String> mccMncs = new ArrayList<>(); |
| 165 | mccMncs.add("310210"); |
Sooraj Sasindran | 825d5a8 | 2019-03-08 08:08:04 -0800 | [diff] [blame] | 166 | AvailableNetworkInfo availableNetworkInfo = new AvailableNetworkInfo(1, 1, mccMncs, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 167 | new ArrayList<Integer>()); |
Sooraj Sasindran | 2394227 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 168 | ArrayList<AvailableNetworkInfo> availableNetworkInfos = new ArrayList<AvailableNetworkInfo>(); |
| 169 | availableNetworkInfos.add(availableNetworkInfo); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 170 | |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 171 | UiccPortInfo uiccPortInfo = new UiccPortInfo("", 1, 1, false); |
| 172 | ArrayList<UiccPortInfo> uiccPortInfoList = new ArrayList<>(); |
| 173 | uiccPortInfoList.add(uiccPortInfo); |
| 174 | |
| 175 | UiccCardInfo uiccCardInfo = new UiccCardInfo(true, 1, "", 0, false, true, uiccPortInfoList); |
| 176 | ArrayList<UiccCardInfo> uiccCardInfoList = new ArrayList<>(); |
| 177 | uiccCardInfoList.add(uiccCardInfo); |
| 178 | |
| 179 | doReturn(uiccCardInfoList).when(mMockTelephonyManager).getUiccCardsInfo(); |
| 180 | doReturn(mMockEuiccManager).when(mMockEuiccManager).createForCardId(1); |
| 181 | doReturn(true).when(mMockEuiccManager).isSimPortAvailable(1); |
| 182 | |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 183 | IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() { |
| 184 | @Override |
| 185 | public void onComplete(int result) { |
| 186 | Log.d(TAG, "mResult end:" + result); |
| 187 | mResult = result; |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | mResult = -1; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 192 | mReady = false; |
| 193 | mCallbackInvoked = false; |
| 194 | new Thread(new Runnable() { |
| 195 | @Override |
| 196 | public void run() { |
| 197 | Looper.prepare(); |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 198 | doReturn(true).when(mONSNetworkScanCtlr).startFastNetworkScan(anyObject()); |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 199 | doReturn(new ArrayList<>()).when(mSubscriptionManager) |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 200 | .getOpportunisticSubscriptions(); |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 201 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 202 | mONSProfileSelectionCallback); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 203 | mONSProfileSelector.mTelephonyManager = mMockTelephonyManager; |
| 204 | mONSProfileSelector.mEuiccManager = mMockEuiccManager; |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 205 | mONSProfileSelector.updateOppSubs(); |
| 206 | mONSProfileSelector.startProfileSelection(availableNetworkInfos, mCallback); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 207 | mLooper = Looper.myLooper(); |
| 208 | setReady(true); |
| 209 | Looper.loop(); |
| 210 | } |
| 211 | }).start(); |
| 212 | |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 213 | // Wait till initialization is complete. |
| 214 | waitUntilReady(); |
| 215 | mReady = false; |
| 216 | |
| 217 | // Testing startProfileSelection without any oppotunistic data. |
| 218 | // should not get any callback invocation. |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 219 | waitUntilReady(100); |
danielwbhuang | 0245be2 | 2019-10-29 20:29:50 +0800 | [diff] [blame] | 220 | assertEquals( |
| 221 | TelephonyManager.UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE, mResult); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 222 | assertFalse(mCallbackInvoked); |
| 223 | } |
| 224 | |
| 225 | @Test |
| 226 | public void testStartProfileSelectionSuccess() { |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 227 | int subId = 5; |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 228 | List<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 229 | List<SubscriptionInfo> oppSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 230 | SubscriptionInfo subscriptionInfo1 = new SubscriptionInfo(subId, "", 1, "TMO", "TMO", 1, 1, |
| 231 | "123", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1, 1, 1, |
| 232 | null, null, false, 0); |
| 233 | SubscriptionInfo subscriptionInfo2 = new SubscriptionInfo(6, "", 1, "TMO", "TMO", 1, 1, |
| 234 | "123", 1, null, "310", "211", "", true, null, "1", 1, false, null, false, 1, 1, 1, |
| 235 | null, null, false, 0); |
| 236 | oppSubscriptionInfoList.add(subscriptionInfo1); |
| 237 | activeSubscriptionInfoList.add(subscriptionInfo1); |
| 238 | activeSubscriptionInfoList.add(subscriptionInfo2); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 239 | |
| 240 | List<CellInfo> results2 = new ArrayList<CellInfo>(); |
| 241 | CellIdentityLte cellIdentityLte = new CellIdentityLte(310, 210, 1, 1, 1); |
| 242 | CellInfoLte cellInfoLte = new CellInfoLte(); |
| 243 | cellInfoLte.setCellIdentity(cellIdentityLte); |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 244 | results2.add((CellInfo) cellInfoLte); |
Sooraj Sasindran | 2394227 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 245 | ArrayList<String> mccMncs = new ArrayList<>(); |
| 246 | mccMncs.add("310210"); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 247 | AvailableNetworkInfo availableNetworkInfo = new AvailableNetworkInfo(subId, 1, mccMncs, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 248 | new ArrayList<Integer>()); |
Sooraj Sasindran | 2394227 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 249 | ArrayList<AvailableNetworkInfo> availableNetworkInfos = new ArrayList<AvailableNetworkInfo>(); |
| 250 | availableNetworkInfos.add(availableNetworkInfo); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 251 | |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 252 | IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() { |
| 253 | @Override |
| 254 | public void onComplete(int result) { |
| 255 | mResult = result; |
| 256 | } |
| 257 | }; |
| 258 | |
| 259 | mResult = -1; |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 260 | mReady = false; |
| 261 | new Thread(new Runnable() { |
| 262 | @Override |
| 263 | public void run() { |
| 264 | Looper.prepare(); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 265 | doReturn(subscriptionInfo1).when(mSubscriptionManager) |
| 266 | .getActiveSubscriptionInfo(subId); |
| 267 | doReturn(oppSubscriptionInfoList).when(mSubscriptionManager) |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 268 | .getOpportunisticSubscriptions(); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 269 | doReturn(activeSubscriptionInfoList).when(mSubscriptionManager) |
| 270 | .getActiveSubscriptionInfoList(); |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 271 | doReturn(activeSubscriptionInfoList).when(mSubscriptionManager) |
| 272 | .getCompleteActiveSubscriptionInfoList(); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 273 | doReturn(true).when(mSubscriptionManager).isActiveSubId(subId); |
danielwbhuang | f699f74 | 2019-07-03 21:42:59 +0800 | [diff] [blame] | 274 | doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot( |
| 275 | anyInt(), anyBoolean()); |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 276 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 277 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 278 | public void onProfileSelectionDone() { |
| 279 | setReady(true); |
| 280 | } |
| 281 | }); |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 282 | mONSProfileSelector.updateOppSubs(); |
| 283 | mONSProfileSelector.startProfileSelection(availableNetworkInfos, mCallback); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 284 | mLooper = Looper.myLooper(); |
| 285 | setReady(true); |
| 286 | Looper.loop(); |
| 287 | } |
| 288 | }).start(); |
| 289 | |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 290 | // Wait till initialization is complete. |
| 291 | waitUntilReady(); |
| 292 | mReady = false; |
| 293 | mDataSubId = -1; |
| 294 | |
| 295 | // Testing startProfileSelection with oppotunistic sub. |
| 296 | // On success onProfileSelectionDone must get invoked. |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 297 | assertFalse(mReady); |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 298 | waitForMs(500); |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 299 | mONSProfileSelector.mNetworkAvailableCallBackCpy.onNetworkAvailability(results2); |
| 300 | Intent callbackIntent = new Intent(MyONSProfileSelector.ACTION_SUB_SWITCH); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 301 | callbackIntent.putExtra("sequenceId", 1); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 302 | callbackIntent.putExtra("subId", subId); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 303 | waitUntilReady(); |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 304 | assertEquals(TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS, mResult); |
Sooraj Sasindran | e59c0e8 | 2018-10-30 23:02:36 -0700 | [diff] [blame] | 305 | assertTrue(mReady); |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 306 | } |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 307 | |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 308 | @Test |
danielwbhuang | b220c29 | 2019-12-12 18:04:28 +0800 | [diff] [blame] | 309 | public void testStartProfileSelectionWithDifferentPrioritySubInfo() { |
| 310 | int PRIORITY_HIGH = 1; |
| 311 | int PRIORITY_MED = 2; |
| 312 | |
| 313 | List<SubscriptionInfo> subscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 314 | SubscriptionInfo subscriptionInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 315 | "123", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1, 1, 1, |
| 316 | null, null, false, 0); |
danielwbhuang | b220c29 | 2019-12-12 18:04:28 +0800 | [diff] [blame] | 317 | subscriptionInfoList.add(subscriptionInfo); |
| 318 | SubscriptionInfo subscriptionInfo_2 = new SubscriptionInfo(8, "", 1, "Vzw", "Vzw", 1, 1, |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 319 | "456", 1, null, "311", "480", "", true, null, "1", 1, true, null, false, 1, 1, 1, |
| 320 | null, null, false, 1); |
danielwbhuang | b220c29 | 2019-12-12 18:04:28 +0800 | [diff] [blame] | 321 | subscriptionInfoList.add(subscriptionInfo_2); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 322 | doReturn(subscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(5); |
| 323 | doReturn(subscriptionInfo_2).when(mSubscriptionManager).getActiveSubscriptionInfo(8); |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 324 | doReturn(subscriptionInfoList).when(mSubscriptionManager) |
| 325 | .getCompleteActiveSubscriptionInfoList(); |
| 326 | doReturn(subscriptionInfoList).when(mSubscriptionManager).getOpportunisticSubscriptions(); |
danielwbhuang | b220c29 | 2019-12-12 18:04:28 +0800 | [diff] [blame] | 327 | |
| 328 | List<CellInfo> results2 = new ArrayList<CellInfo>(); |
| 329 | CellIdentityLte cellIdentityLte = new CellIdentityLte(310, 210, 1, 1, 1); |
| 330 | CellInfoLte cellInfoLte = new CellInfoLte(); |
| 331 | cellInfoLte.setCellIdentity(cellIdentityLte); |
| 332 | results2.add((CellInfo) cellInfoLte); |
| 333 | CellIdentityLte cellIdentityLte_2 = new CellIdentityLte(311, 480, 1, 1, 1); |
| 334 | CellInfoLte cellInfoLte_2 = new CellInfoLte(); |
| 335 | cellInfoLte_2.setCellIdentity(cellIdentityLte_2); |
| 336 | results2.add((CellInfo) cellInfoLte_2); |
| 337 | |
| 338 | ArrayList<String> mccMncs = new ArrayList<>(); |
| 339 | mccMncs.add("310210"); |
| 340 | AvailableNetworkInfo availableNetworkInfo = new AvailableNetworkInfo(5, PRIORITY_MED, |
| 341 | mccMncs, new ArrayList<Integer>()); |
| 342 | ArrayList<AvailableNetworkInfo> availableNetworkInfos = new ArrayList<>(); |
| 343 | availableNetworkInfos.add(availableNetworkInfo); |
| 344 | ArrayList<String> mccMncs_2 = new ArrayList<>(); |
| 345 | mccMncs_2.add("311480"); |
| 346 | AvailableNetworkInfo availableNetworkInfo_2 = new AvailableNetworkInfo(8, PRIORITY_HIGH, |
| 347 | mccMncs_2, new ArrayList<Integer>()); |
| 348 | availableNetworkInfos.add(availableNetworkInfo_2); |
| 349 | |
| 350 | IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() { |
| 351 | @Override |
| 352 | public void onComplete(int result) { |
| 353 | mResult = result; |
| 354 | } |
| 355 | }; |
| 356 | |
| 357 | mResult = -1; |
| 358 | mReady = false; |
| 359 | new Thread(new Runnable() { |
| 360 | @Override |
| 361 | public void run() { |
| 362 | Looper.prepare(); |
danielwbhuang | b220c29 | 2019-12-12 18:04:28 +0800 | [diff] [blame] | 363 | doReturn(true).when(mSubscriptionManager).isActiveSubId(anyInt()); |
| 364 | doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot( |
| 365 | anyInt(), anyBoolean()); |
| 366 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
| 367 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 368 | public void onProfileSelectionDone() { |
| 369 | setReady(true); |
| 370 | } |
| 371 | }); |
| 372 | mONSProfileSelector.updateOppSubs(); |
| 373 | mONSProfileSelector.startProfileSelection(availableNetworkInfos, mCallback); |
| 374 | mLooper = Looper.myLooper(); |
| 375 | setReady(true); |
| 376 | Looper.loop(); |
| 377 | } |
| 378 | }).start(); |
| 379 | waitUntilReady(); |
| 380 | waitForMs(500); |
| 381 | // get high priority subId |
| 382 | int retrieveSubId = mONSProfileSelector.retrieveBestSubscription(results2); |
| 383 | mONSProfileSelector.mNetworkAvailableCallBackCpy.onNetworkAvailability(results2); |
| 384 | assertEquals(8, retrieveSubId); |
| 385 | assertEquals(TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS, mResult); |
| 386 | } |
| 387 | |
| 388 | @Test |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 389 | public void testStartProfileSelectionWithActivePrimarySimOnESim() { |
| 390 | List<SubscriptionInfo> opportunisticSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 391 | List<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 392 | SubscriptionInfo subscriptionInfo1 = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
| 393 | "123", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1839, 1, |
| 394 | 1, null, null, false, 1); |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 395 | SubscriptionInfo subscriptionInfo2 = new SubscriptionInfo(6, "", 1, "TMO", "TMO", 1, 1, |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 396 | "456", 1, null, "310", "211", "", true, null, "1", 1, false, null, false, 1839, 1, |
| 397 | 1, null, null, false, 2); |
| 398 | |
| 399 | activeSubscriptionInfoList.add(subscriptionInfo1); |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 400 | activeSubscriptionInfoList.add(subscriptionInfo2); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 401 | doReturn(subscriptionInfo1).when(mSubscriptionManager).getActiveSubscriptionInfo(5); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 402 | doReturn(subscriptionInfo2).when(mSubscriptionManager).getActiveSubscriptionInfo(6); |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 403 | |
| 404 | ArrayList<String> mccMncs = new ArrayList<>(); |
| 405 | mccMncs.add("310210"); |
| 406 | AvailableNetworkInfo availableNetworkInfo = new AvailableNetworkInfo(5, 2, mccMncs, |
| 407 | new ArrayList<Integer>()); |
| 408 | ArrayList<AvailableNetworkInfo> availableNetworkInfos = new ArrayList<AvailableNetworkInfo>(); |
| 409 | availableNetworkInfos.add(availableNetworkInfo); |
| 410 | |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 411 | ArrayList<UiccPortInfo> uiccPortInfoList = new ArrayList<>(); |
| 412 | uiccPortInfoList.add(new UiccPortInfo("1", 0, 0, false)); |
| 413 | uiccPortInfoList.add(new UiccPortInfo("2", 1, 1, true)); |
| 414 | |
| 415 | UiccCardInfo uiccCardInfo = new UiccCardInfo( |
| 416 | true, 1, "1", 0, false, true, uiccPortInfoList); |
| 417 | ArrayList<UiccCardInfo> uiccCardInfoList = new ArrayList<>(); |
| 418 | uiccCardInfoList.add(uiccCardInfo); |
| 419 | |
| 420 | doReturn(uiccCardInfoList).when(mMockTelephonyManager).getUiccCardsInfo(); |
| 421 | doReturn(mMockEuiccManager).when(mMockEuiccManager).createForCardId(1); |
| 422 | doReturn(true).when(mMockEuiccManager).isSimPortAvailable(1); |
| 423 | |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 424 | IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() { |
| 425 | @Override |
| 426 | public void onComplete(int result) { |
| 427 | mResult = result; |
| 428 | } |
| 429 | }; |
| 430 | |
| 431 | mResult = -1; |
| 432 | mReady = false; |
| 433 | new Thread(new Runnable() { |
| 434 | @Override |
| 435 | public void run() { |
| 436 | Looper.prepare(); |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 437 | doReturn(opportunisticSubscriptionInfoList).when(mSubscriptionManager) |
| 438 | .getOpportunisticSubscriptions(); |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 439 | doReturn(false).when(mSubscriptionManager).isActiveSubId(anyInt()); |
| 440 | doReturn(activeSubscriptionInfoList).when(mSubscriptionManager) |
| 441 | .getActiveSubscriptionInfoList(anyBoolean()); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 442 | doReturn(activeSubscriptionInfoList).when(mSubscriptionManager) |
| 443 | .getActiveSubscriptionInfoList(); |
| 444 | doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot( |
| 445 | anyInt(), anyBoolean()); |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 446 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
| 447 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 448 | public void onProfileSelectionDone() { |
| 449 | setReady(true); |
| 450 | } |
| 451 | }); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 452 | mONSProfileSelector.mTelephonyManager = mMockTelephonyManager; |
| 453 | mONSProfileSelector.mEuiccManager = mMockEuiccManager; |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 454 | mONSProfileSelector.updateOppSubs(); |
| 455 | mONSProfileSelector.startProfileSelection(availableNetworkInfos, mCallback); |
| 456 | mLooper = Looper.myLooper(); |
| 457 | setReady(true); |
| 458 | Looper.loop(); |
| 459 | } |
| 460 | }).start(); |
| 461 | |
| 462 | // Wait till initialization is complete. |
| 463 | waitUntilReady(); |
| 464 | mReady = false; |
| 465 | mDataSubId = -1; |
| 466 | |
| 467 | // Testing startProfileSelection with opportunistic sub. |
| 468 | // On success onProfileSelectionDone must get invoked. |
| 469 | assertFalse(mReady); |
| 470 | waitForMs(100); |
| 471 | Intent callbackIntent = new Intent(MyONSProfileSelector.ACTION_SUB_SWITCH); |
| 472 | callbackIntent.putExtra("sequenceId", 1); |
| 473 | callbackIntent.putExtra("subId", 5); |
| 474 | waitUntilReady(); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 475 | assertEquals(TelephonyManager.UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE, |
| 476 | mResult); |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 477 | } |
| 478 | |
danielwbhuang | 9949a6a | 2019-03-27 17:56:31 +0800 | [diff] [blame] | 479 | public static void waitForMs(long ms) { |
| 480 | try { |
| 481 | Thread.sleep(ms); |
| 482 | } catch (InterruptedException e) { |
| 483 | Log.d(TAG, "InterruptedException while waiting: " + e); |
| 484 | } |
| 485 | } |
| 486 | |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 487 | @Test |
| 488 | public void testselectProfileForDataWithNoOpportunsticSub() { |
| 489 | mReady = false; |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 490 | doReturn(new ArrayList<>()).when(mSubscriptionManager).getOpportunisticSubscriptions(); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 491 | new Thread(new Runnable() { |
| 492 | @Override |
| 493 | public void run() { |
| 494 | Looper.prepare(); |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 495 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 496 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 497 | public void onProfileSelectionDone() { |
| 498 | } |
| 499 | }); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 500 | mLooper = Looper.myLooper(); |
| 501 | setReady(true); |
| 502 | Looper.loop(); |
| 503 | } |
| 504 | }).start(); |
| 505 | |
| 506 | // Wait till initialization is complete. |
| 507 | waitUntilReady(); |
| 508 | |
| 509 | // Testing selectProfileForData with no oppotunistic sub and the function should |
| 510 | // return false. |
Sooraj Sasindran | 1be32b2 | 2019-02-28 14:47:45 -0800 | [diff] [blame] | 511 | mONSProfileSelector.selectProfileForData(1, false, null); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | @Test |
| 515 | public void testselectProfileForDataWithInActiveSub() { |
| 516 | List<SubscriptionInfo> subscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 517 | SubscriptionInfo subscriptionInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 518 | "123", 1, null, "310", "210", "", false, null, "1"); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 519 | subscriptionInfoList.add(subscriptionInfo); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 520 | doReturn(subscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(5); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 521 | mReady = false; |
Sooraj Sasindran | d6b19aa | 2019-04-10 17:15:12 -0700 | [diff] [blame] | 522 | doReturn(new ArrayList<>()).when(mSubscriptionManager).getOpportunisticSubscriptions(); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 523 | new Thread(new Runnable() { |
| 524 | @Override |
| 525 | public void run() { |
| 526 | Looper.prepare(); |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 527 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 528 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 529 | public void onProfileSelectionDone() { |
| 530 | } |
| 531 | }); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 532 | mLooper = Looper.myLooper(); |
| 533 | setReady(true); |
| 534 | Looper.loop(); |
| 535 | } |
| 536 | }).start(); |
| 537 | |
| 538 | // Wait till initialization is complete. |
| 539 | waitUntilReady(); |
| 540 | |
| 541 | // Testing selectProfileForData with in active sub and the function should return false. |
Sooraj Sasindran | 1be32b2 | 2019-02-28 14:47:45 -0800 | [diff] [blame] | 542 | mONSProfileSelector.selectProfileForData(5, false, null); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | @Test |
| 546 | public void testselectProfileForDataWithInvalidSubId() { |
| 547 | List<SubscriptionInfo> subscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 548 | SubscriptionInfo subscriptionInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 549 | "123", 1, null, "310", "210", "", false, null, "1"); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 550 | subscriptionInfoList.add(subscriptionInfo); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 551 | doReturn(subscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(5); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 552 | mReady = false; |
| 553 | doReturn(subscriptionInfoList).when(mSubscriptionManager).getOpportunisticSubscriptions(); |
Malcolm Chen | 9341f63 | 2019-02-05 18:41:46 -0800 | [diff] [blame] | 554 | doNothing().when(mSubscriptionManager).setPreferredDataSubscriptionId( |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 555 | anyInt(), anyBoolean(), any(), any()); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 556 | new Thread(new Runnable() { |
| 557 | @Override |
| 558 | public void run() { |
| 559 | Looper.prepare(); |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 560 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 561 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 562 | public void onProfileSelectionDone() { |
| 563 | } |
| 564 | }); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 565 | mLooper = Looper.myLooper(); |
| 566 | setReady(true); |
| 567 | Looper.loop(); |
| 568 | } |
| 569 | }).start(); |
| 570 | |
| 571 | // Wait till initialization is complete. |
| 572 | waitUntilReady(); |
| 573 | |
| 574 | // Testing selectProfileForData with INVALID_SUBSCRIPTION_ID and the function should |
| 575 | // return true. |
Sooraj Sasindran | 1be32b2 | 2019-02-28 14:47:45 -0800 | [diff] [blame] | 576 | mONSProfileSelector.selectProfileForData( |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 577 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, false, null); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | @Test |
| 581 | public void testselectProfileForDataWithValidSub() { |
| 582 | List<SubscriptionInfo> subscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 583 | SubscriptionInfo subscriptionInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 584 | "123", 1, null, "310", "210", "", false, null, "1"); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 585 | subscriptionInfoList.add(subscriptionInfo); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 586 | doReturn(subscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(5); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 587 | mReady = false; |
| 588 | doReturn(subscriptionInfoList).when(mSubscriptionManager) |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 589 | .getActiveSubscriptionInfoList(); |
Malcolm Chen | 9341f63 | 2019-02-05 18:41:46 -0800 | [diff] [blame] | 590 | doNothing().when(mSubscriptionManager).setPreferredDataSubscriptionId( |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 591 | anyInt(), anyBoolean(), any(), any()); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 592 | new Thread(new Runnable() { |
| 593 | @Override |
| 594 | public void run() { |
| 595 | Looper.prepare(); |
| 596 | doReturn(subscriptionInfoList).when(mSubscriptionManager) |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 597 | .getOpportunisticSubscriptions(); |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 598 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 599 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 600 | public void onProfileSelectionDone() { |
| 601 | } |
| 602 | }); |
Sooraj Sasindran | 653edbd | 2019-01-08 13:17:29 -0800 | [diff] [blame] | 603 | mONSProfileSelector.updateOppSubs(); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 604 | mLooper = Looper.myLooper(); |
| 605 | setReady(true); |
| 606 | Looper.loop(); |
| 607 | } |
| 608 | }).start(); |
| 609 | |
| 610 | // Wait till initialization is complete. |
| 611 | waitUntilReady(); |
| 612 | |
| 613 | // Testing selectProfileForData with valid opportunistic sub and the function should |
| 614 | // return true. |
Sooraj Sasindran | 1be32b2 | 2019-02-28 14:47:45 -0800 | [diff] [blame] | 615 | mONSProfileSelector.selectProfileForData(5, false, null); |
Sooraj Sasindran | 5f71962 | 2018-10-30 23:04:43 -0700 | [diff] [blame] | 616 | } |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 617 | |
| 618 | @Test |
| 619 | public void testStartProfileSelectionSuccessWithSameArgumentsAgain() { |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 620 | List<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 621 | List<SubscriptionInfo> oppSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 622 | SubscriptionInfo subscriptionInfo1 = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
| 623 | "123", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1, 1, 1, |
| 624 | null, null, false, 0); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 625 | SubscriptionInfo subscriptionInfo2 = new SubscriptionInfo(6, "", 1, "TMO", "TMO", 1, 1, |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 626 | "123", 1, null, "310", "211", "", true, null, "1", 1, false, null, false, 1, 1, 1, |
| 627 | null, null, false, 0); |
| 628 | |
| 629 | oppSubscriptionInfoList.add(subscriptionInfo1); |
| 630 | doReturn(subscriptionInfo1).when(mSubscriptionManager).getActiveSubscriptionInfo(5); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 631 | doReturn(subscriptionInfo2).when(mSubscriptionManager).getActiveSubscriptionInfo(6); |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 632 | |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 633 | activeSubscriptionInfoList.add(subscriptionInfo1); |
| 634 | activeSubscriptionInfoList.add(subscriptionInfo2); |
| 635 | doReturn(activeSubscriptionInfoList).when(mSubscriptionManager) |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 636 | .getCompleteActiveSubscriptionInfoList(); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 637 | |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 638 | List<CellInfo> results2 = new ArrayList<CellInfo>(); |
| 639 | CellIdentityLte cellIdentityLte = new CellIdentityLte(310, 210, 1, 1, 1); |
| 640 | CellInfoLte cellInfoLte = new CellInfoLte(); |
| 641 | cellInfoLte.setCellIdentity(cellIdentityLte); |
| 642 | results2.add((CellInfo) cellInfoLte); |
| 643 | ArrayList<String> mccMncs = new ArrayList<>(); |
| 644 | mccMncs.add("310210"); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 645 | AvailableNetworkInfo availableNetworkInfo = new AvailableNetworkInfo(5, 1, mccMncs, |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 646 | new ArrayList<Integer>()); |
| 647 | ArrayList<AvailableNetworkInfo> availableNetworkInfos = new ArrayList<AvailableNetworkInfo>(); |
| 648 | availableNetworkInfos.add(availableNetworkInfo); |
| 649 | |
| 650 | IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() { |
| 651 | @Override |
| 652 | public void onComplete(int result) { |
| 653 | mResult = result; |
| 654 | } |
| 655 | }; |
| 656 | |
| 657 | mResult = -1; |
| 658 | mReady = false; |
| 659 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
| 660 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 661 | public void onProfileSelectionDone() { |
| 662 | setReady(true); |
| 663 | } |
| 664 | }); |
| 665 | new Thread(new Runnable() { |
| 666 | @Override |
| 667 | public void run() { |
| 668 | Looper.prepare(); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 669 | doReturn(oppSubscriptionInfoList).when(mSubscriptionManager) |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 670 | .getOpportunisticSubscriptions(); |
| 671 | doReturn(true).when(mSubscriptionManager).isActiveSubId(anyInt()); |
| 672 | doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot( |
| 673 | anyInt(), anyBoolean()); |
| 674 | |
| 675 | mONSProfileSelector.updateOppSubs(); |
| 676 | mONSProfileSelector.startProfileSelection(availableNetworkInfos, mCallback); |
| 677 | mLooper = Looper.myLooper(); |
| 678 | setReady(true); |
| 679 | Looper.loop(); |
| 680 | } |
| 681 | }).start(); |
| 682 | |
| 683 | // Wait till initialization is complete. |
| 684 | waitUntilReady(); |
| 685 | mReady = false; |
| 686 | mDataSubId = -1; |
| 687 | |
| 688 | // Testing startProfileSelection with oppotunistic sub. |
| 689 | // On success onProfileSelectionDone must get invoked. |
| 690 | assertFalse(mReady); |
| 691 | waitForMs(500); |
| 692 | mONSProfileSelector.mNetworkAvailableCallBackCpy.onNetworkAvailability(results2); |
| 693 | Intent callbackIntent = new Intent(MyONSProfileSelector.ACTION_SUB_SWITCH); |
| 694 | callbackIntent.putExtra("sequenceId", 1); |
| 695 | callbackIntent.putExtra("subId", 5); |
| 696 | waitUntilReady(); |
| 697 | assertEquals(TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS, mResult); |
| 698 | assertTrue(mReady); |
| 699 | |
| 700 | mResult = -1; |
| 701 | mReady = false; |
| 702 | new Thread(new Runnable() { |
| 703 | @Override |
| 704 | public void run() { |
| 705 | Looper.prepare(); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 706 | doReturn(oppSubscriptionInfoList).when(mSubscriptionManager) |
Sooraj Sasindran | 81f153f | 2019-07-09 10:58:24 -0700 | [diff] [blame] | 707 | .getOpportunisticSubscriptions(); |
| 708 | doReturn(true).when(mSubscriptionManager).isActiveSubId(anyInt()); |
| 709 | doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot( |
| 710 | anyInt(), anyBoolean()); |
| 711 | mONSProfileSelector.updateOppSubs(); |
| 712 | mONSProfileSelector.startProfileSelection(availableNetworkInfos, mCallback); |
| 713 | mLooper = Looper.myLooper(); |
| 714 | setReady(true); |
| 715 | Looper.loop(); |
| 716 | } |
| 717 | }).start(); |
| 718 | |
| 719 | // Wait till initialization is complete. |
| 720 | waitUntilReady(); |
| 721 | mReady = false; |
| 722 | mDataSubId = -1; |
| 723 | |
| 724 | // Testing startProfileSelection with oppotunistic sub. |
| 725 | // On success onProfileSelectionDone must get invoked. |
| 726 | assertFalse(mReady); |
| 727 | waitForMs(500); |
| 728 | mONSProfileSelector.mNetworkAvailableCallBackCpy.onNetworkAvailability(results2); |
| 729 | waitUntilReady(); |
| 730 | assertEquals(TelephonyManager.UPDATE_AVAILABLE_NETWORKS_SUCCESS, mResult); |
| 731 | assertTrue(mReady); |
| 732 | } |
Sooraj Sasindran | 4b19d8f | 2019-11-19 11:24:28 -0800 | [diff] [blame] | 733 | |
| 734 | @Test |
| 735 | public void testStopProfileSelectionWithPreferredDataOnSame() { |
| 736 | List<SubscriptionInfo> subscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 737 | SubscriptionInfo subscriptionInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
| 738 | "123", 1, null, "310", "210", "", true, null, "1", true, null, 0, 0); |
| 739 | subscriptionInfoList.add(subscriptionInfo); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 740 | doReturn(subscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(5); |
Sooraj Sasindran | 4b19d8f | 2019-11-19 11:24:28 -0800 | [diff] [blame] | 741 | |
| 742 | IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() { |
| 743 | @Override |
| 744 | public void onComplete(int result) { |
| 745 | mResult = result; |
| 746 | } |
| 747 | }; |
| 748 | |
| 749 | mResult = -1; |
| 750 | mReady = false; |
| 751 | new Thread(new Runnable() { |
| 752 | @Override |
| 753 | public void run() { |
| 754 | Looper.prepare(); |
| 755 | doReturn(subscriptionInfoList).when(mSubscriptionManager) |
| 756 | .getOpportunisticSubscriptions(); |
| 757 | doReturn(true).when(mSubscriptionManager).isActiveSubId(anyInt()); |
| 758 | doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot( |
| 759 | anyInt(), anyBoolean()); |
| 760 | doReturn(5).when(mSubscriptionManager).getPreferredDataSubscriptionId(); |
| 761 | doReturn(subscriptionInfoList).when(mSubscriptionManager) |
| 762 | .getActiveSubscriptionInfoList(anyBoolean()); |
| 763 | |
| 764 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
| 765 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 766 | public void onProfileSelectionDone() { |
| 767 | setReady(true); |
| 768 | } |
| 769 | }); |
| 770 | mONSProfileSelector.updateOppSubs(); |
| 771 | mONSProfileSelector.setCurrentPreferredData(5); |
| 772 | mONSProfileSelector.stopProfileSelection(null); |
| 773 | mLooper = Looper.myLooper(); |
| 774 | setReady(true); |
| 775 | Looper.loop(); |
| 776 | } |
| 777 | }).start(); |
| 778 | waitUntilReady(); |
| 779 | waitForMs(500); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 780 | assertEquals(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, mONSProfileSelector.getCurrentPreferredData()); |
Sooraj Sasindran | 4b19d8f | 2019-11-19 11:24:28 -0800 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | @Test |
| 784 | public void testStopProfileSelectionWithPreferredDataOnDifferent() { |
| 785 | List<SubscriptionInfo> subscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 786 | SubscriptionInfo subscriptionInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
| 787 | "123", 1, null, "310", "210", "", true, null, "1", true, null, 0, 0); |
| 788 | subscriptionInfoList.add(subscriptionInfo); |
Malcolm Chen | 9059f47 | 2019-12-18 14:33:32 -0800 | [diff] [blame] | 789 | doReturn(subscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(5); |
Sooraj Sasindran | 4b19d8f | 2019-11-19 11:24:28 -0800 | [diff] [blame] | 790 | |
| 791 | IUpdateAvailableNetworksCallback mCallback = new IUpdateAvailableNetworksCallback.Stub() { |
| 792 | @Override |
| 793 | public void onComplete(int result) { |
| 794 | mResult = result; |
| 795 | } |
| 796 | }; |
| 797 | |
| 798 | mResult = -1; |
| 799 | mReady = false; |
| 800 | new Thread(new Runnable() { |
| 801 | @Override |
| 802 | public void run() { |
| 803 | Looper.prepare(); |
| 804 | doReturn(subscriptionInfoList).when(mSubscriptionManager) |
| 805 | .getOpportunisticSubscriptions(); |
| 806 | doReturn(true).when(mSubscriptionManager).isActiveSubId(anyInt()); |
| 807 | doReturn(true).when(mSubscriptionBoundTelephonyManager).enableModemForSlot( |
| 808 | anyInt(), anyBoolean()); |
| 809 | doReturn(4).when(mSubscriptionManager).getPreferredDataSubscriptionId(); |
| 810 | doReturn(subscriptionInfoList).when(mSubscriptionManager) |
| 811 | .getActiveSubscriptionInfoList(anyBoolean()); |
| 812 | |
| 813 | mONSProfileSelector = new MyONSProfileSelector(mContext, |
| 814 | new MyONSProfileSelector.ONSProfileSelectionCallback() { |
| 815 | public void onProfileSelectionDone() { |
| 816 | setReady(true); |
| 817 | } |
| 818 | }); |
| 819 | mONSProfileSelector.updateOppSubs(); |
| 820 | mONSProfileSelector.setCurrentPreferredData(5); |
| 821 | mONSProfileSelector.stopProfileSelection(null); |
| 822 | mLooper = Looper.myLooper(); |
| 823 | setReady(true); |
| 824 | Looper.loop(); |
| 825 | } |
| 826 | }).start(); |
| 827 | waitUntilReady(); |
| 828 | waitForMs(500); |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 829 | assertEquals(5, mONSProfileSelector.getCurrentPreferredData()); |
Sooraj Sasindran | 4b19d8f | 2019-11-19 11:24:28 -0800 | [diff] [blame] | 830 | } |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 831 | |
| 832 | @Test |
| 833 | public void testAvailablePortWhenTwoPrimarySIMsAreActive() { |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 834 | /** |
| 835 | * 2 - Primary active subscriptions and |
| 836 | * 1 - Inactive opportunistic subscription |
| 837 | */ |
| 838 | |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 839 | List<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 840 | List<SubscriptionInfo> opportunisticInfoList = new ArrayList<SubscriptionInfo>(); |
| 841 | |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 842 | SubscriptionInfo oppSubInfo = new SubscriptionInfo(4, "", -1, "TMO", "TMO", 1, 1, |
| 843 | "001", 1, null, "110", "210", "", true, null, "1", 1, true, null, false, 2839, 1, |
| 844 | 1, null, null, false, TelephonyManager.INVALID_PORT_INDEX); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 845 | |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 846 | SubscriptionInfo primarySubInfo1 = new SubscriptionInfo(5, "", 0, "TMO", "TMO", 1, 1, |
| 847 | "123", 1, null, "310", "210", "", true, null, "1", 1, false, null, false, 1839, 1, |
| 848 | 1, null, null, false, 0); |
| 849 | SubscriptionInfo primarySubInfo2 = new SubscriptionInfo(6, "", 0, "TMO", "TMO", 1, 1, |
| 850 | "456", 1, null, "310", "211", "", true, null, "1", 1, false, null, false, 1839, 1, |
| 851 | 1, null, null, false, 1); |
| 852 | |
| 853 | activeSubscriptionInfoList.add(primarySubInfo1); |
| 854 | activeSubscriptionInfoList.add(primarySubInfo2); |
| 855 | opportunisticInfoList.add(oppSubInfo); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 856 | |
| 857 | doReturn(opportunisticInfoList).when(mSubscriptionManager).getOpportunisticSubscriptions(); |
| 858 | doReturn(activeSubscriptionInfoList).when(mSubscriptionManager) |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 859 | .getCompleteActiveSubscriptionInfoList(); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 860 | |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 861 | UiccPortInfo uiccPortInfo1 = new UiccPortInfo("", 0, 0, true); |
| 862 | UiccPortInfo uiccPortInfo2 = new UiccPortInfo("", 1, 0, true); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 863 | ArrayList<UiccPortInfo> uiccPortInfoList = new ArrayList<>(); |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 864 | uiccPortInfoList.add(uiccPortInfo1); |
| 865 | uiccPortInfoList.add(uiccPortInfo2); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 866 | |
| 867 | UiccCardInfo uiccCardInfo = new UiccCardInfo(true, 1, "", 0, false, true, uiccPortInfoList); |
| 868 | ArrayList<UiccCardInfo> uiccCardInfoList = new ArrayList<>(); |
| 869 | uiccCardInfoList.add(uiccCardInfo); |
| 870 | |
| 871 | doReturn(uiccCardInfoList).when(mMockTelephonyManager).getUiccCardsInfo(); |
| 872 | doReturn(mMockEuiccManager).when(mMockEuiccManager).createForCardId(1); |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 873 | doReturn(false).when(mMockEuiccManager).isSimPortAvailable(0); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 874 | doReturn(false).when(mMockEuiccManager).isSimPortAvailable(1); |
| 875 | |
| 876 | mONSProfileSelector = new MyONSProfileSelector(mContext, null); |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 877 | mONSProfileSelector.mTelephonyManager = mMockTelephonyManager; |
| 878 | mONSProfileSelector.mEuiccManager = mMockEuiccManager; |
| 879 | |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 880 | int portIdx = mONSProfileSelector.getAvailableESIMPortIndex(); |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 881 | assertEquals(TelephonyManager.INVALID_PORT_INDEX, portIdx); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | @Test |
| 885 | public void testAvailablePortWhenOpportunisticEsimIsActive() { |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 886 | /** |
| 887 | * 1 - Primary active subscriptions and |
| 888 | * 1 - Active opportunistic subscription |
| 889 | */ |
| 890 | |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 891 | List<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 892 | List<SubscriptionInfo> opportunisticInfoList = new ArrayList<SubscriptionInfo>(); |
| 893 | |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 894 | SubscriptionInfo oppSubInfo = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 895 | "123", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1839, 1, |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 896 | 1, null, null, false, 0); |
| 897 | |
| 898 | SubscriptionInfo primarySubInfo = new SubscriptionInfo(6, "", 1, "TMO", "TMO", 1, 1, |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 899 | "456", 1, null, "310", "211", "", true, null, "1", 1, false, null, false, 1839, 1, |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 900 | 1, null, null, false, 1); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 901 | |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 902 | opportunisticInfoList.add(oppSubInfo); |
| 903 | activeSubscriptionInfoList.add(oppSubInfo); |
| 904 | activeSubscriptionInfoList.add(primarySubInfo); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 905 | |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 906 | doReturn(opportunisticInfoList).when(mSubscriptionManager) |
| 907 | .getOpportunisticSubscriptions(); |
| 908 | doReturn(activeSubscriptionInfoList).when(mSubscriptionManager) |
| 909 | .getCompleteActiveSubscriptionInfoList(); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 910 | |
| 911 | mONSProfileSelector = new MyONSProfileSelector(mContext, null); |
| 912 | int portIdx = mONSProfileSelector.getAvailableESIMPortIndex(); |
Avinash Malipatil | ee91767 | 2022-07-25 17:35:38 +0000 | [diff] [blame] | 913 | assertEquals(0, portIdx); |
| 914 | } |
| 915 | |
| 916 | @Test |
| 917 | public void testAvailablePortWhenTwoOpportunisticEsimsAreActive() { |
| 918 | /** |
| 919 | * 2 - Active opportunistic subscriptions. |
| 920 | */ |
| 921 | |
| 922 | List<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 923 | List<SubscriptionInfo> opportunisticInfoList = new ArrayList<SubscriptionInfo>(); |
| 924 | |
| 925 | SubscriptionInfo opportunisticSubInfo1 = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
| 926 | "123", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1839, 1, |
| 927 | 1, null, null, false, 0); |
| 928 | |
| 929 | SubscriptionInfo opportunisticSubInfo2 = new SubscriptionInfo(6, "", 1, "TMO", "TMO", 1, 1, |
| 930 | "456", 1, null, "310", "211", "", true, null, "1", 1, true, null, false, 1839, 1, |
| 931 | 1, null, null, false, 1); |
| 932 | |
| 933 | opportunisticInfoList.add(opportunisticSubInfo1); |
| 934 | opportunisticInfoList.add(opportunisticSubInfo2); |
| 935 | activeSubscriptionInfoList.add(opportunisticSubInfo1); |
| 936 | activeSubscriptionInfoList.add(opportunisticSubInfo2); |
| 937 | |
| 938 | doReturn(opportunisticInfoList).when(mSubscriptionManager) |
| 939 | .getOpportunisticSubscriptions(); |
| 940 | doReturn(activeSubscriptionInfoList).when(mSubscriptionManager) |
| 941 | .getCompleteActiveSubscriptionInfoList(); |
| 942 | |
| 943 | mONSProfileSelector = new MyONSProfileSelector(mContext, null); |
| 944 | int portIdx = mONSProfileSelector.getAvailableESIMPortIndex(); |
| 945 | |
| 946 | /* one of the opportunistic eSIM port should be selected */ |
| 947 | assertTrue(portIdx == 0 || portIdx == 1); |
| 948 | } |
| 949 | |
| 950 | @Test |
| 951 | public void testAvailablePortWhenOpportunisticEsimIsActiveAndInactiveSubscriptions() { |
| 952 | /** |
| 953 | * 1 - Primary active subscription and |
| 954 | * 1 - Active opportunistic subscription and |
| 955 | * 2 - Inactive opportunistic subscriptions |
| 956 | */ |
| 957 | |
| 958 | List<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 959 | List<SubscriptionInfo> opportunisticInfoList = new ArrayList<SubscriptionInfo>(); |
| 960 | |
| 961 | SubscriptionInfo opportunisticSubInfo1 = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
| 962 | "123", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1839, 1, |
| 963 | 1, null, null, false, 1); |
| 964 | SubscriptionInfo primarySubInfo = new SubscriptionInfo(6, "", 1, "TMO", "TMO", 1, 1, |
| 965 | "456", 1, null, "310", "211", "", true, null, "1", 1, false, null, false, 1839, 1, |
| 966 | 1, null, null, false, 0); |
| 967 | |
| 968 | SubscriptionInfo opportunisticSubInfo2 = new SubscriptionInfo(7, "", 1, "TMO", "TMO", 1, 1, |
| 969 | "789", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1839, 1, |
| 970 | 1, null, null, false, TelephonyManager.INVALID_PORT_INDEX); |
| 971 | |
| 972 | SubscriptionInfo oppSubInfo3 = new SubscriptionInfo(8, "", 1, "TMO", "TMO", 1, 1, |
| 973 | "012", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1839, 1, |
| 974 | 1, null, null, false, TelephonyManager.INVALID_PORT_INDEX); |
| 975 | |
| 976 | opportunisticInfoList.add(opportunisticSubInfo1); |
| 977 | opportunisticInfoList.add(opportunisticSubInfo2); |
| 978 | opportunisticInfoList.add(oppSubInfo3); |
| 979 | activeSubscriptionInfoList.add(opportunisticSubInfo1); |
| 980 | activeSubscriptionInfoList.add(primarySubInfo); |
| 981 | |
| 982 | doReturn(opportunisticInfoList).when(mSubscriptionManager) |
| 983 | .getOpportunisticSubscriptions(); |
| 984 | doReturn(activeSubscriptionInfoList).when(mSubscriptionManager) |
| 985 | .getCompleteActiveSubscriptionInfoList(); |
| 986 | |
| 987 | mONSProfileSelector = new MyONSProfileSelector(mContext, null); |
| 988 | int portIdx = mONSProfileSelector.getAvailableESIMPortIndex(); |
| 989 | assertEquals(1, portIdx); |
| 990 | } |
| 991 | |
| 992 | @Test |
| 993 | public void testAvailablePortWhenOnlyInactiveSubscriptions() { |
| 994 | /** |
| 995 | * 1 - Primary inactive subscription and |
| 996 | * 2 - Inactive opportunistic subscriptions |
| 997 | */ |
| 998 | |
| 999 | List<SubscriptionInfo> activeSubscriptionInfoList = new ArrayList<SubscriptionInfo>(); |
| 1000 | List<SubscriptionInfo> opportunisticInfoList = new ArrayList<SubscriptionInfo>(); |
| 1001 | |
| 1002 | SubscriptionInfo oppSubInfo1 = new SubscriptionInfo(5, "", 1, "TMO", "TMO", 1, 1, |
| 1003 | "123", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1839, 1, |
| 1004 | 1, null, null, false, TelephonyManager.INVALID_PORT_INDEX); |
| 1005 | |
| 1006 | // Not used in activeSubscriptionInfoList or opportunisticInfoList |
| 1007 | /*SubscriptionInfo primarySubInfo = new SubscriptionInfo(6, "", 1, "TMO", "TMO", 1, 1, |
| 1008 | "456", 1, null, "310", "211", "", true, null, "1", 1, false, null, false, 1839, 1, |
| 1009 | 1, null, null, false, 2);*/ |
| 1010 | |
| 1011 | SubscriptionInfo oppSubInfo2 = new SubscriptionInfo(7, "", 1, "TMO", "TMO", 1, 1, |
| 1012 | "789", 1, null, "310", "210", "", true, null, "1", 1, true, null, false, 1839, 1, |
| 1013 | 1, null, null, false, TelephonyManager.INVALID_PORT_INDEX); |
| 1014 | |
| 1015 | opportunisticInfoList.add(oppSubInfo1); |
| 1016 | opportunisticInfoList.add(oppSubInfo2); |
| 1017 | |
| 1018 | doReturn(opportunisticInfoList).when(mSubscriptionManager) |
| 1019 | .getOpportunisticSubscriptions(); |
| 1020 | doReturn(activeSubscriptionInfoList).when(mSubscriptionManager) |
| 1021 | .getCompleteActiveSubscriptionInfoList(); |
| 1022 | |
| 1023 | UiccPortInfo uiccPortInfo1 = new UiccPortInfo("", 0, 0, false); |
| 1024 | UiccPortInfo uiccPortInfo2 = new UiccPortInfo("", 1, 0, false); |
| 1025 | ArrayList<UiccPortInfo> uiccPortInfoList = new ArrayList<>(); |
| 1026 | uiccPortInfoList.add(uiccPortInfo1); |
| 1027 | uiccPortInfoList.add(uiccPortInfo2); |
| 1028 | |
| 1029 | UiccCardInfo uiccCardInfo = new UiccCardInfo(true, 1, "", 0, false, true, uiccPortInfoList); |
| 1030 | ArrayList<UiccCardInfo> uiccCardInfoList = new ArrayList<>(); |
| 1031 | uiccCardInfoList.add(uiccCardInfo); |
| 1032 | |
| 1033 | doReturn(uiccCardInfoList).when(mMockTelephonyManager).getUiccCardsInfo(); |
| 1034 | doReturn(mMockEuiccManager).when(mMockEuiccManager).createForCardId(1); |
| 1035 | doReturn(true).when(mMockEuiccManager).isSimPortAvailable(0); |
| 1036 | doReturn(true).when(mMockEuiccManager).isSimPortAvailable(1); |
| 1037 | |
| 1038 | mONSProfileSelector = new MyONSProfileSelector(mContext, null); |
| 1039 | mONSProfileSelector.mTelephonyManager = mMockTelephonyManager; |
| 1040 | mONSProfileSelector.mEuiccManager = mMockEuiccManager; |
| 1041 | |
| 1042 | int portIdx = mONSProfileSelector.getAvailableESIMPortIndex(); |
| 1043 | assertTrue(portIdx == 0 || portIdx == 1); |
Avinash Malipatil | 7957295 | 2022-05-26 08:48:31 +0000 | [diff] [blame] | 1044 | } |
Avinash Malipatil | 284c5ef | 2022-08-17 07:29:56 +0000 | [diff] [blame] | 1045 | |
| 1046 | @Test |
| 1047 | public void testGetMncMccFromCellInfoNr() { |
| 1048 | mONSProfileSelector = new MyONSProfileSelector(mContext, null); |
| 1049 | |
| 1050 | CellIdentityNr cellIdentityNr = new CellIdentityNr(0, 0, 0, new int[]{0}, "111", "222", 0, |
| 1051 | "", "", Collections.emptyList()); |
| 1052 | |
| 1053 | CellInfoNr cellinfoNr = new CellInfoNr(0, true, 0, cellIdentityNr, null); |
| 1054 | |
| 1055 | assertEquals(mONSProfileSelector.getMcc(cellinfoNr), "111"); |
| 1056 | assertEquals(mONSProfileSelector.getMnc(cellinfoNr), "222"); |
| 1057 | } |
Sooraj Sasindran | 3334515 | 2018-10-01 11:22:56 -0700 | [diff] [blame] | 1058 | } |