1 /* 2 * Copyright (C) 2015 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 */ 16 17 package android.telephony.cts; 18 19 import android.content.Context; 20 import android.cts.util.TestThread; 21 import android.net.ConnectivityManager; 22 import android.os.Looper; 23 import android.telephony.SubscriptionInfo; 24 import android.telephony.SubscriptionManager; 25 import android.test.AndroidTestCase; 26 import android.util.Log; 27 28 import java.util.List; 29 30 public class SubscriptionManagerTest extends AndroidTestCase { 31 private SubscriptionManager mSubscriptionManager; 32 private static ConnectivityManager mCm; 33 private SubscriptionManager.OnSubscriptionsChangedListener mListener; 34 private final Object mLock = new Object(); 35 private boolean mOnSubscriptionsChangedCalled = false; 36 private static final int TOLERANCE = 1000; 37 private static final String TAG = "android.telephony.cts.SubscriptionManagerTest"; 38 39 @Override setUp()40 protected void setUp() throws Exception { 41 super.setUp(); 42 mSubscriptionManager = new SubscriptionManager(getContext()); 43 mCm = (ConnectivityManager)getContext().getSystemService(Context.CONNECTIVITY_SERVICE); 44 } 45 46 @Override tearDown()47 protected void tearDown() throws Exception { 48 if (mListener != null) { 49 // unregister the listener 50 mSubscriptionManager.removeOnSubscriptionsChangedListener(mListener); 51 } 52 super.tearDown(); 53 } 54 testGetActiveSubscriptionInfoCount()55 public void testGetActiveSubscriptionInfoCount() { 56 if (mCm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) == null) { 57 Log.d(TAG, "Skipping test that requires ConnectivityManager.TYPE_MOBILE"); 58 return; 59 } 60 assertTrue(mSubscriptionManager.getActiveSubscriptionInfoCount() <= 61 mSubscriptionManager.getActiveSubscriptionInfoCountMax()); 62 } 63 testActiveSubscriptions()64 public void testActiveSubscriptions() { 65 if (mCm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) == null) { 66 Log.d(TAG, "Skipping test that requires ConnectivityManager.TYPE_MOBILE"); 67 return; 68 } 69 List<SubscriptionInfo> subList = mSubscriptionManager.getActiveSubscriptionInfoList(); 70 // Assert when there is no sim card present or detected 71 assertTrue(subList != null && subList.size() > 0); 72 for (int i = 0; i < subList.size(); i++) { 73 assertTrue(subList.get(i).getSubscriptionId() >= 0); 74 assertTrue(subList.get(i).getSimSlotIndex() >= 0); 75 } 76 } 77 } 78