Search in sources :

Example 21 with CellIdentityLte

use of android.telephony.CellIdentityLte in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class DeviceApi17 method loadCellInfo.

public static void loadCellInfo(TelephonyManager tm, Device pDevice) {
    int lCurrentApiVersion = Build.VERSION.SDK_INT;
    try {
        if (pDevice.cell == null) {
            pDevice.cell = new Cell();
        }
        List<CellInfo> cellInfoList = tm.getAllCellInfo();
        if (cellInfoList != null) {
            for (final CellInfo info : cellInfoList) {
                // Network Type
                pDevice.cell.setNetType(tm.getNetworkType());
                if (info instanceof CellInfoGsm) {
                    final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
                    final CellIdentityGsm identityGsm = ((CellInfoGsm) info).getCellIdentity();
                    // Signal Strength
                    // [dBm]
                    pDevice.cell.setDbm(gsm.getDbm());
                    // Cell Identity
                    pDevice.cell.setCellId(identityGsm.getCid());
                    pDevice.cell.setMobileCountryCode(identityGsm.getMcc());
                    pDevice.cell.setMobileNetworkCode(identityGsm.getMnc());
                    pDevice.cell.setLocationAreaCode(identityGsm.getLac());
                } else if (info instanceof CellInfoCdma) {
                    final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();
                    final CellIdentityCdma identityCdma = ((CellInfoCdma) info).getCellIdentity();
                    // Signal Strength
                    pDevice.cell.setDbm(cdma.getDbm());
                    // Cell Identity
                    pDevice.cell.setCellId(identityCdma.getBasestationId());
                    pDevice.cell.setMobileNetworkCode(identityCdma.getSystemId());
                    pDevice.cell.setLocationAreaCode(identityCdma.getNetworkId());
                    pDevice.cell.setSid(identityCdma.getSystemId());
                } else if (info instanceof CellInfoLte) {
                    final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
                    final CellIdentityLte identityLte = ((CellInfoLte) info).getCellIdentity();
                    // Signal Strength
                    pDevice.cell.setDbm(lte.getDbm());
                    pDevice.cell.setTimingAdvance(lte.getTimingAdvance());
                    // Cell Identity
                    pDevice.cell.setMobileCountryCode(identityLte.getMcc());
                    pDevice.cell.setMobileNetworkCode(identityLte.getMnc());
                    pDevice.cell.setCellId(identityLte.getCi());
                } else if (lCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 && info instanceof CellInfoWcdma) {
                    final CellSignalStrengthWcdma wcdma = ((CellInfoWcdma) info).getCellSignalStrength();
                    final CellIdentityWcdma identityWcdma = ((CellInfoWcdma) info).getCellIdentity();
                    // Signal Strength
                    pDevice.cell.setDbm(wcdma.getDbm());
                    // Cell Identity
                    pDevice.cell.setLocationAreaCode(identityWcdma.getLac());
                    pDevice.cell.setMobileCountryCode(identityWcdma.getMcc());
                    pDevice.cell.setMobileNetworkCode(identityWcdma.getMnc());
                    pDevice.cell.setCellId(identityWcdma.getCid());
                    pDevice.cell.setPrimaryScramblingCode(identityWcdma.getPsc());
                } else {
                    log.info("Unknown type of cell signal! " + "ClassName: " + info.getClass().getSimpleName() + " ToString: " + info.toString());
                }
                if (pDevice.cell.isValid()) {
                    break;
                }
            }
        }
    } catch (NullPointerException npe) {
        log.error("loadCellInfo: Unable to obtain cell signal information: ", npe);
    }
}
Also used : CellInfoCdma(android.telephony.CellInfoCdma) CellInfoWcdma(android.telephony.CellInfoWcdma) CellIdentityGsm(android.telephony.CellIdentityGsm) CellSignalStrengthWcdma(android.telephony.CellSignalStrengthWcdma) CellInfoGsm(android.telephony.CellInfoGsm) CellSignalStrengthLte(android.telephony.CellSignalStrengthLte) CellInfoLte(android.telephony.CellInfoLte) CellIdentityCdma(android.telephony.CellIdentityCdma) CellInfo(android.telephony.CellInfo) CellSignalStrengthGsm(android.telephony.CellSignalStrengthGsm) CellIdentityLte(android.telephony.CellIdentityLte) CellSignalStrengthCdma(android.telephony.CellSignalStrengthCdma) CellIdentityWcdma(android.telephony.CellIdentityWcdma)

Example 22 with CellIdentityLte

use of android.telephony.CellIdentityLte in project satstat by mvglasow.

the class CellTowerListLte method update.

/**
 * Adds or updates a cell tower.
 * <p>
 * If the cell tower is already in the list, its data is updated; if not, a
 * new entry is created.
 * <p>
 * This method will set the cell's identity data, its signal strength and
 * whether it is the currently serving cell.
 * @return The new or updated entry.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public CellTowerLte update(CellInfoLte cell) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
        return null;
    CellIdentityLte cid = cell.getCellIdentity();
    CellTowerLte result = null;
    CellTowerLte cand = this.get(cid.getMcc(), cid.getMnc(), cid.getTac(), cid.getCi());
    if ((cand != null) && CellTower.matches(cid.getPci(), cand.getPci()))
        result = cand;
    if (result == null) {
        cand = this.get(cid.getPci());
        if ((cand != null) && ((cid.getMcc() == Integer.MAX_VALUE) || CellTower.matches(cid.getMcc(), cand.getMcc())) && ((cid.getMnc() == Integer.MAX_VALUE) || CellTower.matches(cid.getMnc(), cand.getMnc())) && ((cid.getTac() == Integer.MAX_VALUE) || CellTower.matches(cid.getTac(), cand.getTac())) && ((cid.getCi() == Integer.MAX_VALUE) || CellTower.matches(cid.getCi(), cand.getCi())))
            result = cand;
    }
    if (result == null)
        result = new CellTowerLte(cid.getMcc(), cid.getMnc(), cid.getTac(), cid.getCi(), cid.getPci());
    if (result.getMcc() == CellTower.UNKNOWN)
        result.setMcc(cid.getMcc());
    if (result.getMnc() == CellTower.UNKNOWN)
        result.setMnc(cid.getMnc());
    if (result.getTac() == CellTower.UNKNOWN)
        result.setTac(cid.getTac());
    if (result.getCi() == CellTower.UNKNOWN)
        result.setCi(cid.getCi());
    if (result.getPci() == CellTower.UNKNOWN)
        result.setPci(cid.getPci());
    this.put(result.getText(), result);
    this.put(result.getAltText(), result);
    result.setCellInfo(true);
    result.setDbm(cell.getCellSignalStrength().getDbm());
    result.setServing(cell.isRegistered());
    Log.d(this.getClass().getSimpleName(), String.format("Added CellInfoLte for %s, %d G, %d dBm", result.getText(), result.getGeneration(), result.getDbm()));
    return result;
}
Also used : CellIdentityLte(android.telephony.CellIdentityLte) TargetApi(android.annotation.TargetApi)

Aggregations

CellIdentityLte (android.telephony.CellIdentityLte)22 CellIdentityGsm (android.telephony.CellIdentityGsm)13 CellInfoGsm (android.telephony.CellInfoGsm)13 CellInfoLte (android.telephony.CellInfoLte)13 CellIdentityWcdma (android.telephony.CellIdentityWcdma)12 CellInfo (android.telephony.CellInfo)12 CellInfoWcdma (android.telephony.CellInfoWcdma)12 CellIdentityCdma (android.telephony.CellIdentityCdma)11 CellInfoCdma (android.telephony.CellInfoCdma)11 CellSignalStrengthLte (android.telephony.CellSignalStrengthLte)11 PendingIntent (android.app.PendingIntent)5 Intent (android.content.Intent)5 WifiInfo (android.net.wifi.WifiInfo)5 CellSignalStrengthGsm (android.telephony.CellSignalStrengthGsm)4 TargetApi (android.annotation.TargetApi)3 CellSignalStrengthCdma (android.telephony.CellSignalStrengthCdma)3 CellSignalStrengthWcdma (android.telephony.CellSignalStrengthWcdma)3 SuppressLint (android.annotation.SuppressLint)1 Parcel (android.os.Parcel)1 SmallTest (android.support.test.filters.SmallTest)1