1 /* 2 * Copyright (C) 2014 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 package android.telephony.cts; 17 18 import android.content.Context; 19 import android.content.pm.PackageManager; 20 import android.net.ConnectivityManager; 21 import android.telephony.CellInfo; 22 import android.telephony.CellInfoGsm; 23 import android.telephony.CellInfoLte; 24 import android.telephony.CellInfoWcdma; 25 import android.telephony.CellSignalStrengthLte; 26 import android.telephony.TelephonyManager; 27 import android.test.AndroidTestCase; 28 import android.util.Log; 29 30 import java.util.List; 31 32 /** 33 * Test TelephonyManager.getAllCellInfo() 34 * <p> 35 * TODO(chesnutt): test onCellInfoChanged() once the implementation 36 * of async callbacks is complete (see http://b/13788638) 37 */ 38 public class CellInfoTest extends AndroidTestCase{ 39 private final Object mLock = new Object(); 40 private TelephonyManager mTelephonyManager; 41 private static ConnectivityManager mCm; 42 private static final String TAG = "android.telephony.cts.CellInfoTest"; 43 // Maximum and minimum possible RSSI values(in dbm). 44 private static final int MAX_RSSI = -10; 45 private static final int MIN_RSSI = -150; 46 private PackageManager mPm; 47 48 @Override setUp()49 protected void setUp() throws Exception { 50 super.setUp(); 51 mTelephonyManager = 52 (TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE); 53 mCm = (ConnectivityManager)getContext().getSystemService(Context.CONNECTIVITY_SERVICE); 54 mPm = getContext().getPackageManager(); 55 } 56 testCellInfo()57 public void testCellInfo() throws Throwable { 58 59 if(! (mPm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY))) { 60 Log.d(TAG, "Skipping test that requires FEATURE_TELEPHONY"); 61 return; 62 } 63 64 if (mCm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) == null) { 65 Log.d(TAG, "Skipping test that requires ConnectivityManager.TYPE_MOBILE"); 66 return; 67 } 68 69 // getAllCellInfo should never return null, and there should 70 // be at least one entry. 71 List<CellInfo> allCellInfo = mTelephonyManager.getAllCellInfo(); 72 assertNotNull("TelephonyManager.getAllCellInfo() returned NULL!", allCellInfo); 73 assertTrue("TelephonyManager.getAllCellInfo() returned zero-length list!", 74 allCellInfo.size() > 0); 75 76 int numRegisteredCells = 0; 77 for (CellInfo cellInfo : allCellInfo) { 78 if (cellInfo.isRegistered()) { 79 ++numRegisteredCells; 80 } 81 if (cellInfo instanceof CellInfoLte) { 82 verifyLteInfo((CellInfoLte) cellInfo); 83 } else if (cellInfo instanceof CellInfoWcdma) { 84 verifyWcdmaInfo((CellInfoWcdma) cellInfo); 85 } else if (cellInfo instanceof CellInfoGsm) { 86 verifyGsmInfo((CellInfoGsm) cellInfo); 87 } 88 } 89 90 //FIXME: The maximum needs to be calculated based on the number of 91 // radios and the technologies used (ex SRLTE); however, we have 92 // not hit any of these cases yet. 93 assertTrue("None or too many registered cells : " + numRegisteredCells, 94 numRegisteredCells > 0 && numRegisteredCells <= 2); 95 } 96 97 // Verify lte cell information is within correct range. verifyLteInfo(CellInfoLte lte)98 private void verifyLteInfo(CellInfoLte lte) { 99 verifyRssiDbm(lte.getCellSignalStrength().getDbm()); 100 // Verify LTE physical cell id information. 101 // Only physical cell id is available for LTE neighbor. 102 int pci = lte.getCellIdentity().getPci(); 103 // Physical cell id should be within [0, 503]. 104 assertTrue("getPci() out of range [0, 503]", pci >= 0 && pci <= 503); 105 106 int earfcn = lte.getCellIdentity().getEarfcn(); 107 // Reference 3GPP 36.101 Table 5.7.3-1 108 assertTrue("getEarfcn() out of range [0,47000]", earfcn >= 0 && earfcn <= 47000); 109 110 int ta = ((CellSignalStrengthLte)lte.getCellSignalStrength()).getTimingAdvance(); 111 //Integer.MAX_VALUE indicates an unavailable field 112 assertTrue("getTimingAdvance() invalid [0-1282] | Integer.MAX_VALUE", 113 ta == Integer.MAX_VALUE || (ta >= 0 && ta <=1282)); 114 } 115 116 // Verify wcdma cell information is within correct range. verifyWcdmaInfo(CellInfoWcdma wcdma)117 private void verifyWcdmaInfo(CellInfoWcdma wcdma) { 118 verifyRssiDbm(wcdma.getCellSignalStrength().getDbm()); 119 // Verify wcdma primary scrambling code information. 120 // Primary scrambling code should be within [0, 511]. 121 int psc = wcdma.getCellIdentity().getPsc(); 122 assertTrue("getPsc() out of range [0, 511]", psc >= 0 && psc <= 511); 123 124 int uarfcn = wcdma.getCellIdentity().getUarfcn(); 125 // Reference 3GPP 25.101 Table 5.2 126 assertTrue("getUarfcn() out of range [400,11000]", uarfcn >= 400 && uarfcn <= 11000); 127 } 128 129 // Verify gsm cell information is within correct range. verifyGsmInfo(CellInfoGsm gsm)130 private void verifyGsmInfo(CellInfoGsm gsm) { 131 verifyRssiDbm(gsm.getCellSignalStrength().getDbm()); 132 // Verify gsm local area code and cellid. 133 // Local area code and cellid should be with [0, 65535]. 134 int lac = gsm.getCellIdentity().getLac(); 135 assertTrue("getLac() out of range [0, 65535]", lac >= 0 && lac <= 65535); 136 int cid = gsm.getCellIdentity().getCid(); 137 assertTrue("getCid() out range [0, 65535]", cid >= 0 && cid <= 65535); 138 139 int arfcn = gsm.getCellIdentity().getArfcn(); 140 // Reference 3GPP 45.005 Table 2-2 141 assertTrue("getArfcn() out of range [0,1024]", arfcn >= 0 && arfcn <= 1024); 142 143 int bsic = gsm.getCellIdentity().getBsic(); 144 assertTrue("getBsic() out of range [0,63]", bsic >=0 && bsic <=63); 145 } 146 147 // Rssi(in dbm) should be within [MIN_RSSI, MAX_RSSI]. verifyRssiDbm(int dbm)148 private void verifyRssiDbm(int dbm) { 149 assertTrue("getCellSignalStrength().getDbm() out of range", 150 dbm >= MIN_RSSI && dbm <= MAX_RSSI); 151 } 152 } 153