java类android.telephony.CellInfo的实例源码

DeviceApi18.java 文件源码 项目:Android-IMSI-Catcher-Detector 阅读 24 收藏 0 点赞 0 评论 0
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
                    pDevice.cell.setDbm(gsm.getDbm()); // [dBm]
                    // 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!"
                            + "\n ClassName: " + info.getClass().getSimpleName()
                            + "\n ToString: " + info.toString());
                }
                if (pDevice.cell.isValid()) {
                    break;
                }
            }
        }
    } catch (NullPointerException npe) {
        log.error("loadCellInfo: Unable to obtain cell signal information: ", npe);
    }
}
LibPhoneStateListener.java 文件源码 项目:android-QoS 阅读 32 收藏 0 点赞 0 评论 0
@TargetApi(17) @Override
public void onCellInfoChanged(List<CellInfo> cellinfos) {
    super.onCellInfoChanged(cellinfos);
    try {
        if (!owner.isMMCActiveOrRunning())
            return;
        if (tmLastCellInfoUpdate + 60000 > System.currentTimeMillis() && cellinfos != null && cellinfos.size() > 0 && cellinfos.get(0).toString().equals(lastCellInfoString))
            return;
        if (cellinfos != null && cellinfos.size() > 0)
            lastCellInfoString = cellinfos.get(0).toString();
        else
            lastCellInfoString = "";    
        tmLastCellInfoUpdate = System.currentTimeMillis();

        if (mPhoneState.getNetworkType() == mPhoneState.NETWORK_NEWTYPE_LTE)
        {
            String neighbors = owner.getCellHistory().updateLteNeighborHistory(cellinfos);
            if (neighbors != null)
            {
                owner.getIntentDispatcher().updateLTEIdentity (neighbors);
                owner.getReportManager().setNeighbors(neighbors);
            }

        }

        if (cellinfos != null && cellinfos.size() > 0 && cellinfos.get(0) != null)
            for (int i=0; i<cellinfos.size(); i++)
            {
                //MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "onCellInfoChanged", "cellinfos["+i+"]: " + cellinfos.get(i).toString());
                if (mPhoneState.getNetworkType() == mPhoneState.NETWORK_NEWTYPE_LTE)
                {
                    if (cellinfos.get(i) instanceof CellInfoLte)
                    {
                        CellIdentityLte cellIDLte = ((CellInfoLte)cellinfos.get(i)).getCellIdentity();
                        //MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "onCellInfoChanged", "Reflected: " + listCellInfoFields(cellIDLte));
                    }
                }
            }
        //else
        //  MMCLogger.logToFile(MMCLogger.Level.ERROR, TAG, "onCellInfoChanged", "cellinfos: null");

    } catch (Exception intEx){
        LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "onCellInfoChanged", "InterruptedException: " + intEx.getMessage());
    } 
}
PlatformNetworksManager.java 文件源码 项目:365browser 阅读 17 收藏 0 点赞 0 评论 0
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static VisibleCell getConnectedCellPostJellyBeanMr1(
        Context context, TelephonyManager telephonyManager) {
    if (!hasLocationPermission(context)) {
        return VisibleCell.UNKNOWN_MISSING_LOCATION_PERMISSION_VISIBLE_CELL;
    }
    CellInfo cellInfo = getActiveCellInfo(telephonyManager);
    return getVisibleCellPostJellyBeanMr1(
            cellInfo, sTimeProvider.getElapsedRealtime(), sTimeProvider.getCurrentTime());
}
PlatformNetworksManager.java 文件源码 项目:365browser 阅读 15 收藏 0 点赞 0 评论 0
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static VisibleCell getVisibleCellPostJellyBeanMr1(
        @Nullable CellInfo cellInfo, long elapsedTime, long currentTime) {
    if (cellInfo == null) {
        return VisibleCell.UNKNOWN_VISIBLE_CELL;
    }
    long cellInfoAge = elapsedTime - TimeUnit.NANOSECONDS.toMillis(cellInfo.getTimeStamp());
    long cellTimestamp = currentTime - cellInfoAge;
    if (cellInfo instanceof CellInfoCdma) {
        CellIdentityCdma cellIdentityCdma = ((CellInfoCdma) cellInfo).getCellIdentity();
        return VisibleCell.builder(VisibleCell.CDMA_RADIO_TYPE)
                .setCellId(cellIdentityCdma.getBasestationId())
                .setLocationAreaCode(cellIdentityCdma.getNetworkId())
                .setMobileNetworkCode(cellIdentityCdma.getSystemId())
                .setTimestamp(cellTimestamp)
                .build();
    }
    if (cellInfo instanceof CellInfoGsm) {
        CellIdentityGsm cellIdentityGsm = ((CellInfoGsm) cellInfo).getCellIdentity();
        return VisibleCell.builder(VisibleCell.GSM_RADIO_TYPE)
                .setCellId(cellIdentityGsm.getCid())
                .setLocationAreaCode(cellIdentityGsm.getLac())
                .setMobileCountryCode(cellIdentityGsm.getMcc())
                .setMobileNetworkCode(cellIdentityGsm.getMnc())
                .setTimestamp(cellTimestamp)
                .build();
    }
    if (cellInfo instanceof CellInfoLte) {
        CellIdentityLte cellIdLte = ((CellInfoLte) cellInfo).getCellIdentity();
        return VisibleCell.builder(VisibleCell.LTE_RADIO_TYPE)
                .setCellId(cellIdLte.getCi())
                .setMobileCountryCode(cellIdLte.getMcc())
                .setMobileNetworkCode(cellIdLte.getMnc())
                .setPhysicalCellId(cellIdLte.getPci())
                .setTrackingAreaCode(cellIdLte.getTac())
                .setTimestamp(cellTimestamp)
                .build();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2
            && cellInfo instanceof CellInfoWcdma) {
        // CellInfoWcdma is only usable JB MR2 upwards.
        CellIdentityWcdma cellIdentityWcdma = ((CellInfoWcdma) cellInfo).getCellIdentity();
        return VisibleCell.builder(VisibleCell.WCDMA_RADIO_TYPE)
                .setCellId(cellIdentityWcdma.getCid())
                .setLocationAreaCode(cellIdentityWcdma.getLac())
                .setMobileCountryCode(cellIdentityWcdma.getMcc())
                .setMobileNetworkCode(cellIdentityWcdma.getMnc())
                .setPrimaryScramblingCode(cellIdentityWcdma.getPsc())
                .setTimestamp(cellTimestamp)
                .build();
    }
    return VisibleCell.UNKNOWN_VISIBLE_CELL;
}
AndroidCellularSignalStrength.java 文件源码 项目:365browser 阅读 17 收藏 0 点赞 0 评论 0
/**
 * @return Signal strength (in dbM) for the currently registered cellular network. Returns
 * {@link CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal strength is
 * unavailable or if there are multiple cellular radios on the device.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@CalledByNative
public static int getSignalStrengthDbm() {
    List<CellInfo> cellInfos = getRegisteredCellInfo();
    return cellInfos == null || cellInfos.size() != 1
            ? CellularSignalStrengthError.ERROR_NOT_SUPPORTED
            : getSignalStrengthDbm(cellInfos.get(0));
}
AndroidCellularSignalStrength.java 文件源码 项目:365browser 阅读 17 收藏 0 点赞 0 评论 0
/**
 * @return the signal strength level (between 0 and 4, both inclusive) for the currently
 * registered cellular network with lower value indicating lower signal strength. Returns
 * {@link CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal strength level is
 * unavailable or if there are multiple cellular radios on the device.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@CalledByNative
public static int getSignalStrengthLevel() {
    List<CellInfo> cellInfos = getRegisteredCellInfo();
    return cellInfos == null || cellInfos.size() != 1
            ? CellularSignalStrengthError.ERROR_NOT_SUPPORTED
            : getSignalStrengthLevel(cellInfos.get(0));
}
AndroidCellularSignalStrength.java 文件源码 项目:365browser 阅读 17 收藏 0 点赞 0 评论 0
/**
 * Returns all observed cell information from all radios on the device including the primary
 * and neighboring cells. Returns only the information of cells that are registered to a
 * mobile network. May return {@code null}.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static List<CellInfo> getRegisteredCellInfo() {
    if (!isAPIAvailable()) {
        return null;
    }

    TelephonyManager telephonyManager =
            (TelephonyManager) ContextUtils.getApplicationContext().getSystemService(
                    Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) {
        return null;
    }

    List<CellInfo> cellInfos = telephonyManager.getAllCellInfo();
    if (cellInfos == null) {
        return null;
    }

    Iterator<CellInfo> iter = cellInfos.iterator();
    while (iter.hasNext()) {
        if (!iter.next().isRegistered()) {
            iter.remove();
        }
    }
    return cellInfos;
}
Utilities.java 文件源码 项目:RadioControl 阅读 22 收藏 0 点赞 0 评论 0
public static int getCellStatus(Context c){
    int z = 0;
    try {
        TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
        List<CellInfo> cellInfoList = tm.getAllCellInfo();
        //This means cell is off
        if (cellInfoList.isEmpty()) {
            z = 1;
        }
        return z;
    } catch(SecurityException e){
        Log.e("RadioControl","Unable to get Location Permission",e);
    }
    return z;
}
CellBackendHelper.java 文件源码 项目:android_external_UnifiedNlpApi 阅读 17 收藏 0 点赞 0 评论 0
/**
 * Call this in {@link org.microg.nlp.api.LocationBackendService#onOpen()}.
 */
@Override
public synchronized void onOpen() {
    super.onOpen();

    if (phoneStateListener == null) {
        Handler mainHandler = new Handler(context.getMainLooper());
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                phoneStateListener = new PhoneStateListener() {

                    @Override
                    public void onCellInfoChanged(List<CellInfo> cellInfo) {
                        if (cellInfo != null && !cellInfo.isEmpty()) {
                            onCellsChanged(cellInfo);
                        } else if (supportsCellInfoChanged) {
                            supportsCellInfoChanged = false;
                            onSignalStrengthsChanged(null);
                        }
                    }

                    @Override
                    public void onSignalStrengthsChanged(SignalStrength signalStrength) {
                        if (!supportsCellInfoChanged) {
                            fallbackScan();
                        }
                    }
                };
                registerPhoneStateListener();
            }
        });
    } else {
        registerPhoneStateListener();
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号