android.telephony.CellInfoCdma Java Examples

The following examples show how to use android.telephony.CellInfoCdma. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CellTowerListCdma.java    From satstat with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds or updates a cell tower.
 * <p>
 * If the cell tower is already in the list, it is replaced; 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. If the API level is 18 or 
 * higher, it will also set the generation.
 * @return The new or updated entry.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public CellTowerCdma update(CellInfoCdma cell) {
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) 
		return null;
	CellIdentityCdma cid = cell.getCellIdentity();
	CellTowerCdma result = this.get(cid.getSystemId(), cid.getNetworkId(), cid.getBasestationId());
	if (result == null) {
		result = new CellTowerCdma(cid.getSystemId(), cid.getNetworkId(), cid.getBasestationId());
		this.put(result.getText(), result);
	}
	result.setCellInfo(true);
	result.setDbm(cell.getCellSignalStrength().getDbm());
	result.setServing(cell.isRegistered());
	return result;
}
 
Example #2
Source File: AndroidCellularSignalStrength.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @return the signal level from {@link cellInfo}. Returns {@link
 * CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal
 * level is unavailable with lower value indicating lower signal strength.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static int getSignalStrengthLevel(CellInfo cellInfo) {
    if (cellInfo instanceof CellInfoCdma) {
        return ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel();
    }
    if (cellInfo instanceof CellInfoGsm) {
        return ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel();
    }
    if (cellInfo instanceof CellInfoLte) {
        return ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel();
    }
    if (cellInfo instanceof CellInfoWcdma) {
        return ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel();
    }
    return CellularSignalStrengthError.ERROR_NOT_SUPPORTED;
}
 
Example #3
Source File: AndroidCellularSignalStrength.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @return Signal strength (in dbM) from {@link cellInfo}. Returns {@link
 * CellularSignalStrengthError#ERROR_NOT_SUPPORTED} if the signal strength is unavailable.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static int getSignalStrengthDbm(CellInfo cellInfo) {
    if (cellInfo instanceof CellInfoCdma) {
        return ((CellInfoCdma) cellInfo).getCellSignalStrength().getDbm();
    }
    if (cellInfo instanceof CellInfoGsm) {
        return ((CellInfoGsm) cellInfo).getCellSignalStrength().getDbm();
    }
    if (cellInfo instanceof CellInfoLte) {
        return ((CellInfoLte) cellInfo).getCellSignalStrength().getDbm();
    }
    if (cellInfo instanceof CellInfoWcdma) {
        return ((CellInfoWcdma) cellInfo).getCellSignalStrength().getDbm();
    }
    return CellularSignalStrengthError.ERROR_NOT_SUPPORTED;
}
 
Example #4
Source File: CellTowerListCdma.java    From satstat with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds or updates a list of cell towers.
 * <p>
 * This method first calls {@link #removeSource(int)} with
 * {@link com.vonglasow.michael.satstat.data.CellTower#SOURCE_CELL_INFO} as
 * its argument. Then it iterates through all entries in {@code cells} and
 * updates each entry that is of type {@link android.telephony.CellInfoCdma}
 * by calling {@link #update(CellInfoCdma)}, passing that entry as the
 * argument.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void updateAll(List<CellInfo> cells) {
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) 
		return;
	this.removeSource(CellTower.SOURCE_CELL_INFO);
	if (cells == null)
		return;
	for (CellInfo cell : cells)
		if (cell instanceof CellInfoCdma)
			this.update((CellInfoCdma) cell);
}
 
Example #5
Source File: PhoneUtils.java    From Mobilyzer with Apache License 2.0 5 votes vote down vote up
public HashMap<String, Integer> getAllCellInfoSignalStrength(){
	if(!(ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION)==PackageManager.PERMISSION_GRANTED)){
		return null;
	}
	TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
	List<CellInfo> cellInfos = (List<CellInfo>) telephonyManager.getAllCellInfo();
	
	HashMap<String,	 Integer> results = new HashMap<String, Integer>();
	
	if(cellInfos==null){
		return results;
	}
	
	for(CellInfo cellInfo : cellInfos){
		if(cellInfo.getClass().equals(CellInfoLte.class)){
			results.put("LTE", ((CellInfoLte) cellInfo).getCellSignalStrength().getDbm());
		}else if(cellInfo.getClass().equals(CellInfoGsm.class)){
			results.put("GSM", ((CellInfoGsm) cellInfo).getCellSignalStrength().getDbm());
		}else if(cellInfo.getClass().equals(CellInfoCdma.class)){
			results.put("CDMA", ((CellInfoCdma) cellInfo).getCellSignalStrength().getDbm());
		}else if(cellInfo.getClass().equals(CellInfoWcdma.class)){
             results.put("WCDMA", ((CellInfoWcdma) cellInfo).getCellSignalStrength().getDbm());
		}
	}
	
	return results;
}
 
Example #6
Source File: CellLocationController.java    From cordova-plugin-advanced-geolocation with Apache License 2.0 5 votes vote down vote up
private static void processCellInfos(List<CellInfo> cellInfos){
    if(cellInfos != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){

        for(CellInfo cellInfo : cellInfos){

            if(cellInfo instanceof  CellInfoWcdma){
                final CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoWCDMAJSON(cellInfoWcdma, _returnSignalStrength));
            }
            if(cellInfo instanceof CellInfoGsm){
                final CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoGSMJSON(cellInfoGsm, _returnSignalStrength));
            }
            if(cellInfo instanceof  CellInfoCdma){
                final CellInfoCdma cellIdentityCdma = (CellInfoCdma) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoCDMAJSON(cellIdentityCdma, _returnSignalStrength));
            }
            if(cellInfo instanceof  CellInfoLte){
                final CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
                sendCallback(PluginResult.Status.OK,
                        JSONHelper.cellInfoLTEJSON(cellInfoLte, _returnSignalStrength));
            }

            Log.d(TAG,cellInfo.toString());
        }
    }
    else {
        Log.e(TAG, "CellInfoLocation returning null. Is it supported on this phone?");

        // There are several reasons as to why cell location data would be null.
        // * could be an older device running an unsupported version of the Android OS
        // * could be a device that doesn't support this capability.
        // * could be incorrect permissions: ACCESS_COARSE_LOCATION
        sendCallback(PluginResult.Status.ERROR,
                JSONHelper.errorJSON(CELLINFO_PROVIDER, ErrorMessages.CELL_DATA_IS_NULL()));
    }
}
 
Example #7
Source File: CellIdentityValidator.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
public boolean isValid(CellInfo cellInfo) {
    if (cellInfo instanceof CellInfoGsm) {
        CellInfoGsm gsmCellInfo = (CellInfoGsm) cellInfo;
        // If is compatible with API 17 hack (PSC on GSM) return true
        boolean wcdmaApi17Valid = getWcdmaValidator().isValid(gsmCellInfo.getCellIdentity());
        if (wcdmaApi17Valid)
            return true;
        return getGsmValidator().isValid(gsmCellInfo.getCellIdentity());
    }
    if (cellInfo instanceof CellInfoWcdma) {
        CellInfoWcdma wcdmaCellInfo = (CellInfoWcdma) cellInfo;
        return getWcdmaValidator().isValid(wcdmaCellInfo.getCellIdentity());
    }
    if (cellInfo instanceof CellInfoLte) {
        CellInfoLte lteCellInfo = (CellInfoLte) cellInfo;
        return getLteValidator().isValid(lteCellInfo.getCellIdentity());
    }
    if (cellInfo instanceof CellInfoCdma) {
        CellInfoCdma cdmaCellInfo = (CellInfoCdma) cellInfo;
        return getCdmaValidator().isValid(cdmaCellInfo.getCellIdentity());
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && cellInfo instanceof CellInfoNr) {
        CellInfoNr nrCellInfo = (CellInfoNr) cellInfo;
        return getNrValidator().isValid((CellIdentityNr) nrCellInfo.getCellIdentity());
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && cellInfo instanceof CellInfoTdscdma) {
        CellInfoTdscdma tdscdmaCellInfo = (CellInfoTdscdma) cellInfo;
        return getTdscdmaValidator().isValid(tdscdmaCellInfo.getCellIdentity());
    }
    throw new UnsupportedOperationException("Cell identity type not supported `" + cellInfo.getClass().getName() + "`");
}
 
Example #8
Source File: RadioInfo.java    From CellularSignal with GNU General Public License v3.0 4 votes vote down vote up
private void getCellIdentity() {
    List<CellInfo> cellInfoList = mTM.getAllCellInfo();

    if (cellInfoList == null) {
        //Log.e(Tag,"getAllCellInfo is null");
        return;
    }
    //Log.e(Tag,"getAllCellInfo size "+cellInfoList.size());

    for (CellInfo cellInfo : cellInfoList) {

        if (!cellInfo.isRegistered())
            continue;

        if (cellInfo instanceof CellInfoLte) {

            CellInfoLte lteinfo = (CellInfoLte) cellInfo;

            lte_MCC = lteinfo.getCellIdentity().getMcc();
            lte_MNC = lteinfo.getCellIdentity().getMnc();
            lte_CI = lteinfo.getCellIdentity().getCi();
            lte_PCI = lteinfo.getCellIdentity().getPci();
            lte_TAC = lteinfo.getCellIdentity().getTac();
            //Log.e(Tag,lteinfo.toString());

        } else if (cellInfo instanceof CellInfoCdma) {

            CellInfoCdma cdmainfo = (CellInfoCdma) cellInfo;

            cdma_SID = cdmainfo.getCellIdentity().getSystemId();
            cdma_NID = cdmainfo.getCellIdentity().getNetworkId();
            cdma_BSID = cdmainfo.getCellIdentity().getBasestationId();

            //Log.e(Tag,cdmainfo.toString());
        } else if (cellInfo instanceof CellInfoGsm) {
            CellInfoGsm gsmInfo = (CellInfoGsm) cellInfo;

            gsm_MCC = gsmInfo.getCellIdentity().getMcc();
            gsm_MNC = gsmInfo.getCellIdentity().getMnc();
            gsm_CID = gsmInfo.getCellIdentity().getCid();
            gsm_LAC = gsmInfo.getCellIdentity().getLac();

        } else if (cellInfo instanceof CellInfoWcdma) {
            CellInfoWcdma wcdmaInfo = (CellInfoWcdma) cellInfo;

            wcdma_MCC = wcdmaInfo.getCellIdentity().getMcc();
            wcdma_MNC = wcdmaInfo.getCellIdentity().getMnc();
            wcdma_CID = wcdmaInfo.getCellIdentity().getCid();
            wcdma_LAC = wcdmaInfo.getCellIdentity().getLac();
            wcdma_PSC = wcdmaInfo.getCellIdentity().getPsc();
        }
    }
}
 
Example #9
Source File: CellInfoCdmaAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public CellInfoCdmaAssert(CellInfoCdma actual) {
  super(actual, CellInfoCdmaAssert.class);
}
 
Example #10
Source File: PhoneStateScanner.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
private void getAllCellInfo(List<CellInfo> cellInfo) {
    // only for registered cells is returned identify
    // SlimKat in Galaxy Nexus - returns null :-/
    // Honor 7 - returns empty list (not null), Dual SIM?

    //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "cellInfo="+cellInfo);

    if (cellInfo!=null) {

        if (Permissions.checkLocation(context.getApplicationContext())) {

            //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "---- start ----------------------------");

            boolean anyRegistered = false;

            for (CellInfo _cellInfo : cellInfo) {
                //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "registered="+_cellInfo.isRegistered());

                boolean isRegistered = false;

                if (_cellInfo instanceof CellInfoGsm) {
                    //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "gsm info="+_cellInfo);
                    CellIdentityGsm identityGsm = ((CellInfoGsm) _cellInfo).getCellIdentity();
                    //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "gsm cid="+identityGsm.getCid());
                    if (isValidCellId(identityGsm.getCid())) {
                        if (_cellInfo.isRegistered()) {
                            registeredCell = identityGsm.getCid();
                            //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "gsm registeredCell="+registeredCell);
                            lastConnectedTime = Calendar.getInstance().getTimeInMillis();
                            isRegistered = true;
                        }
                    }
                } else if (_cellInfo instanceof CellInfoLte) {
                    //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "lte info="+_cellInfo);
                    CellIdentityLte identityLte = ((CellInfoLte) _cellInfo).getCellIdentity();
                    //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "lte cid="+identityLte.getCi());
                    if (isValidCellId(identityLte.getCi())) {
                        if (_cellInfo.isRegistered()) {
                            registeredCell = identityLte.getCi();
                            //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "lte registeredCell="+registeredCell);
                            lastConnectedTime = Calendar.getInstance().getTimeInMillis();
                            isRegistered = true;
                        }
                    }
                } else if (_cellInfo instanceof CellInfoWcdma) {
                    //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "wcdma info="+_cellInfo);
                    CellIdentityWcdma identityWcdma = ((CellInfoWcdma) _cellInfo).getCellIdentity();
                    //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "wcdma cid=" + identityWcdma.getCid());
                    if (isValidCellId(identityWcdma.getCid())) {
                        if (_cellInfo.isRegistered()) {
                            registeredCell = identityWcdma.getCid();
                            //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "wcdma registeredCell="+registeredCell);
                            lastConnectedTime = Calendar.getInstance().getTimeInMillis();
                            isRegistered = true;
                        }
                    }
                } else if (_cellInfo instanceof CellInfoCdma) {
                    //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "cdma info="+_cellInfo);
                    CellIdentityCdma identityCdma = ((CellInfoCdma) _cellInfo).getCellIdentity();
                    //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "wcdma cid="+identityCdma.getBasestationId());
                    if (isValidCellId(identityCdma.getBasestationId())) {
                        if (_cellInfo.isRegistered()) {
                            registeredCell = identityCdma.getBasestationId();
                            //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "cdma registeredCell="+registeredCell);
                            lastConnectedTime = Calendar.getInstance().getTimeInMillis();
                            isRegistered = true;
                        }
                    }
                }
                /*else {
                    PPApplication.logE("PhoneStateScanner.getAllCellInfo", "unknown info="+_cellInfo);
                }*/

                if (isRegistered) {
                    anyRegistered = true;
                    /*if (PPApplication.logEnabled()) {
                        PPApplication.logE("PhoneStateScanner.getAllCellInfo", "registeredCell=" + registeredCell);
                        PPApplication.logE("PhoneStateScanner.getAllCellInfo", "is registered, save it");
                    }*/
                    DatabaseHandler db = DatabaseHandler.getInstance(context);
                    db.updateMobileCellLastConnectedTime(registeredCell, lastConnectedTime);
                    doAutoRegistration(registeredCell);
                }
            }

            if (!anyRegistered) {
                //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "empty cellInfo");
                registeredCell = Integer.MAX_VALUE;
                doAutoRegistration(registeredCell);
            }

            //PPApplication.logE("PhoneStateScanner.getAllCellInfo", "---- end ----------------------------");
        }

    }
    //else
    //    PPApplication.logE("PhoneStateScanner.getAllCellInfo", "cell info is null");
}
 
Example #11
Source File: PlatformNetworksManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example #12
Source File: CellularDrawer.java    From meter with Apache License 2.0 4 votes vote down vote up
public CellularDrawer(final Context context){
    super(
            context,
            context.getResources().getColor(R.color.cellular_background),
            context.getResources().getColor(R.color.cellular_triangle_background),
            context.getResources().getColor(R.color.cellular_triangle_foreground),
            context.getResources().getColor(R.color.cellular_triangle_critical)
    );

    this.label1 = "Cellular";

    tManager = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
    setLabel2();

    tManager.listen(new PhoneStateListener(){
        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            super.onSignalStrengthsChanged(signalStrength);

            int level = 0;
            String tech = "";

            if( isAirplaneModeOn(context) ){
                percent = 0f;
                connected = false;
                label1 = "No connection";
                label2 = "Airplane Mode Enabled";
                return;
            }

            List<CellInfo> infos = null;

            try {
                infos = tManager.getAllCellInfo();
            } catch (SecurityException e){
                Log.e(TAG, e.toString());
            }

            if( infos == null ){
                connected = false;
                return;
            }

            for (final CellInfo info : infos) {
                if (info instanceof CellInfoWcdma) {
                    final CellSignalStrengthWcdma  wcdma = ((CellInfoWcdma) info).getCellSignalStrength();

                    if(level < wcdma.getLevel()) {
                        level = wcdma.getLevel();
                        tech = "wcdma";
                    }
                } else if (info instanceof CellInfoGsm) {
                    final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();

                    if(level < gsm.getLevel()) {
                        level = gsm.getLevel();
                        tech = "gsm";
                    }
                } else if (info instanceof CellInfoCdma) {
                    final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();

                    if(level < cdma.getLevel()) {
                        level = cdma.getLevel();
                        tech = "cdma";
                    }
                } else if (info instanceof CellInfoLte) {
                    final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();

                    if(level < lte.getLevel()) {
                        level = lte.getLevel();
                        tech = "lte";
                    }

                }
            }

            connected = true;
            label1 = "Cellular";
            percent = (float) (level / 4.0);

            if (firstRead) {
                firstRead = false;
                _percent = (float) (percent - 0.001);
            }
        }

        @Override
        public void onServiceStateChanged(ServiceState serviceState) {
            super.onServiceStateChanged(serviceState);
            setLabel2();
            Log.d(TAG,"STATE "+String.valueOf(serviceState)+"   "+serviceState.getState());
        }
    },PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_SERVICE_STATE);

}
 
Example #13
Source File: Net.java    From HttpInfo with Apache License 2.0 4 votes vote down vote up
public static void getMobileDbm(Context context, NetBean netBean) {
    int dbm = 0;
    int level = 0;
    int asu = 0;
    try {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        List<CellInfo> cellInfoList;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            if (tm == null) {
                return;
            }
            cellInfoList = tm.getAllCellInfo();
            if (null != cellInfoList) {
                for (CellInfo cellInfo : cellInfoList) {
                    if (cellInfo instanceof CellInfoGsm) {
                        CellSignalStrengthGsm cellSignalStrengthGsm = ((CellInfoGsm) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthGsm.getDbm();
                        level = cellSignalStrengthGsm.getLevel();
                        asu = cellSignalStrengthGsm.getAsuLevel();
                    } else if (cellInfo instanceof CellInfoCdma) {
                        CellSignalStrengthCdma cellSignalStrengthCdma =
                                ((CellInfoCdma) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthCdma.getDbm();
                        level = cellSignalStrengthCdma.getLevel();
                        asu = cellSignalStrengthCdma.getAsuLevel();
                    } else if (cellInfo instanceof CellInfoLte) {
                        CellSignalStrengthLte cellSignalStrengthLte = ((CellInfoLte) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthLte.getDbm();
                        level = cellSignalStrengthLte.getLevel();
                        asu = cellSignalStrengthLte.getAsuLevel();
                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                        if (cellInfo instanceof CellInfoWcdma) {
                            CellSignalStrengthWcdma cellSignalStrengthWcdma =
                                    ((CellInfoWcdma) cellInfo).getCellSignalStrength();
                            dbm = cellSignalStrengthWcdma.getDbm();
                            level = cellSignalStrengthWcdma.getLevel();
                            asu = cellSignalStrengthWcdma.getAsuLevel();
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        HttpLog.e("signal info:" + e.toString());
    }
    netBean.setMobAsu(asu);
    netBean.setMobDbm(dbm);
    netBean.setMobLevel(level);
}
 
Example #14
Source File: RadioInfo.java    From CellularSignal with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCellInfoChanged(List<CellInfo> cellInfoList) {
    super.onCellInfoChanged(cellInfoList);


    if (cellInfoList == null) {
        //Log.e(Tag,"onCellInfoChanged is null");
        return;
    }

    //Log.e(Tag,"onCellInfoChanged size "+cellInfoList.size());

    for (CellInfo cellInfo : cellInfoList) {

        if (!cellInfo.isRegistered())
            continue;

        if (cellInfo instanceof CellInfoLte) {

            CellInfoLte lteinfo = (CellInfoLte) cellInfo;

            lte_MCC = lteinfo.getCellIdentity().getMcc();
            lte_MNC = lteinfo.getCellIdentity().getMnc();
            lte_CI = lteinfo.getCellIdentity().getCi();
            lte_PCI = lteinfo.getCellIdentity().getPci();
            lte_TAC = lteinfo.getCellIdentity().getTac();
            //Log.e(Tag,lteinfo.toString());

        } else if (cellInfo instanceof CellInfoCdma) {

            CellInfoCdma cdmainfo = (CellInfoCdma) cellInfo;

            cdma_SID = cdmainfo.getCellIdentity().getSystemId();
            cdma_NID = cdmainfo.getCellIdentity().getNetworkId();
            cdma_BSID = cdmainfo.getCellIdentity().getBasestationId();

            //Log.e(Tag,cdmainfo.toString());
        } else if (cellInfo instanceof CellInfoGsm) {
            CellInfoGsm gsmInfo = (CellInfoGsm) cellInfo;

            gsm_MCC = gsmInfo.getCellIdentity().getMcc();
            gsm_MNC = gsmInfo.getCellIdentity().getMnc();
            gsm_CID = gsmInfo.getCellIdentity().getCid();
            gsm_LAC = gsmInfo.getCellIdentity().getLac();

        } else if (cellInfo instanceof CellInfoWcdma) {
            CellInfoWcdma wcdmaInfo = (CellInfoWcdma) cellInfo;

            wcdma_MCC = wcdmaInfo.getCellIdentity().getMcc();
            wcdma_MNC = wcdmaInfo.getCellIdentity().getMnc();
            wcdma_CID = wcdmaInfo.getCellIdentity().getCid();
            wcdma_LAC = wcdmaInfo.getCellIdentity().getLac();
            wcdma_PSC = wcdmaInfo.getCellIdentity().getPsc();
        }
    }

    ((MainActivity)mcontext).mSectionsPagerAdapter.notifyDataSetChanged();
}
 
Example #15
Source File: JSONHelper.java    From cordova-plugin-advanced-geolocation with Apache License 2.0 4 votes vote down vote up
/**
 * Converts CellInfoCdma into JSON
 * @param cellInfo CellInfoCdma
 * @return JSON
 */
public static String cellInfoCDMAJSON(CellInfoCdma cellInfo, boolean returnSignalStrength){

    final Calendar calendar = Calendar.getInstance();
    final JSONObject json = new JSONObject();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && cellInfo != null) {
        try {
            json.put("provider", CELLINFO_PROVIDER);
            json.put("type", CDMA);
            json.put("timestamp", calendar.getTimeInMillis());

            final CellIdentityCdma identityCdma = cellInfo.getCellIdentity();

            json.put("latitude", CdmaCellLocation.convertQuartSecToDecDegrees(identityCdma.getLatitude()));
            json.put("longitude", CdmaCellLocation.convertQuartSecToDecDegrees(identityCdma.getLongitude()));
            json.put("basestationId", identityCdma.getBasestationId());
            json.put("networkId", identityCdma.getNetworkId());
            json.put("systemId", identityCdma.getSystemId());

            if (returnSignalStrength){
                final JSONObject jsonSignalStrength = new JSONObject();
                final CellSignalStrengthCdma cellSignalStrengthCdma = cellInfo.getCellSignalStrength();
                jsonSignalStrength.put("asuLevel", cellSignalStrengthCdma.getAsuLevel());
                jsonSignalStrength.put("cdmaDbm", cellSignalStrengthCdma.getCdmaDbm());
                jsonSignalStrength.put("cdmaEcio", cellSignalStrengthCdma.getCdmaEcio());
                jsonSignalStrength.put("cdmaLevel", cellSignalStrengthCdma.getCdmaLevel());
                jsonSignalStrength.put("dbm", cellSignalStrengthCdma.getDbm());
                jsonSignalStrength.put("evdoDbm", cellSignalStrengthCdma.getEvdoDbm());
                jsonSignalStrength.put("evdoEcio", cellSignalStrengthCdma.getEvdoEcio());
                jsonSignalStrength.put("evdoLevel", cellSignalStrengthCdma.getEvdoLevel());
                jsonSignalStrength.put("evdoSnr", cellSignalStrengthCdma.getEvdoSnr());
                jsonSignalStrength.put("level", cellSignalStrengthCdma.getLevel());

                json.put("cellSignalStrengthCdma", jsonSignalStrength);
            }
        }
        catch(JSONException exc) {
            logJSONException(exc);
        }
    }

    return json.toString();
}
 
Example #16
Source File: DeviceApi18.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
public static void loadCellInfo(TelephonyManager tm, Device pDevice) {
    int lCurrentApiVersion = android.os.Build.VERSION.SDK_INT;
    try {
        if (pDevice.mCell == null) {
            pDevice.mCell = new Cell();
        }
        List<CellInfo> cellInfoList = tm.getAllCellInfo();
        if (cellInfoList != null) {
            for (final CellInfo info : cellInfoList) {

                //Network Type
                pDevice.mCell.setNetType(tm.getNetworkType());

                if (info instanceof CellInfoGsm) {
                    final CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
                    final CellIdentityGsm identityGsm = ((CellInfoGsm) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(gsm.getDbm()); // [dBm]
                    // Cell Identity
                    pDevice.mCell.setCID(identityGsm.getCid());
                    pDevice.mCell.setMCC(identityGsm.getMcc());
                    pDevice.mCell.setMNC(identityGsm.getMnc());
                    pDevice.mCell.setLAC(identityGsm.getLac());

                } else if (info instanceof CellInfoCdma) {
                    final CellSignalStrengthCdma cdma = ((CellInfoCdma) info).getCellSignalStrength();
                    final CellIdentityCdma identityCdma = ((CellInfoCdma) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(cdma.getDbm());
                    // Cell Identity
                    pDevice.mCell.setCID(identityCdma.getBasestationId());
                    pDevice.mCell.setMNC(identityCdma.getSystemId());
                    pDevice.mCell.setLAC(identityCdma.getNetworkId());
                    pDevice.mCell.setSID(identityCdma.getSystemId());

                } else if (info instanceof CellInfoLte) {
                    final CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
                    final CellIdentityLte identityLte = ((CellInfoLte) info).getCellIdentity();
                    // Signal Strength
                    pDevice.mCell.setDBM(lte.getDbm());
                    pDevice.mCell.setTimingAdvance(lte.getTimingAdvance());
                    // Cell Identity
                    pDevice.mCell.setMCC(identityLte.getMcc());
                    pDevice.mCell.setMNC(identityLte.getMnc());
                    pDevice.mCell.setCID(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.mCell.setDBM(wcdma.getDbm());
                    // Cell Identity
                    pDevice.mCell.setLAC(identityWcdma.getLac());
                    pDevice.mCell.setMCC(identityWcdma.getMcc());
                    pDevice.mCell.setMNC(identityWcdma.getMnc());
                    pDevice.mCell.setCID(identityWcdma.getCid());
                    pDevice.mCell.setPSC(identityWcdma.getPsc());

                } else {
                    Log.i(TAG, mTAG + "Unknown type of cell signal!"
                            + "\n ClassName: " + info.getClass().getSimpleName()
                            + "\n ToString: " + info.toString());
                }
                if (pDevice.mCell.isValid()) {
                    break;
                }
            }
        }
    } catch (NullPointerException npe) {
       Log.e(TAG, mTAG + "loadCellInfo: Unable to obtain cell signal information: ", npe);
    }
}
 
Example #17
Source File: DeviceApi17.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
public static void loadCellInfo(TelephonyManager tm, Device pDevice) {
    int lCurrentApiVersion = android.os.Build.VERSION.SDK_INT;
    try {
        if (pDevice.mCell == null) {
            pDevice.mCell = new Cell();
        }
        List<CellInfo> cellInfoList = tm.getAllCellInfo();
        if (cellInfoList != null) {
            for (final CellInfo info : cellInfoList) {

                //Network Type
                pDevice.mCell.setNetType(tm.getNetworkType());

                if (info instanceof CellInfoGsm) {
                    final CellSignalStrengthGsm gsm = ((CellInfoGsm) info)
                            .getCellSignalStrength();
                    final CellIdentityGsm identityGsm = ((CellInfoGsm) info)
                            .getCellIdentity();
                    //Signal Strength
                    pDevice.mCell.setDBM(gsm.getDbm()); // [dBm]
                    //Cell Identity
                    pDevice.mCell.setCID(identityGsm.getCid());
                    pDevice.mCell.setMCC(identityGsm.getMcc());
                    pDevice.mCell.setMNC(identityGsm.getMnc());
                    pDevice.mCell.setLAC(identityGsm.getLac());

                } else if (info instanceof CellInfoCdma) {
                    final CellSignalStrengthCdma cdma = ((CellInfoCdma) info)
                            .getCellSignalStrength();
                    final CellIdentityCdma identityCdma = ((CellInfoCdma) info)
                            .getCellIdentity();
                    //Signal Strength
                    pDevice.mCell.setDBM(cdma.getDbm());
                    //Cell Identity
                    pDevice.mCell.setCID(identityCdma.getBasestationId());
                    pDevice.mCell.setMNC(identityCdma.getSystemId());
                    pDevice.mCell.setLAC(identityCdma.getNetworkId());
                    pDevice.mCell.setSID(identityCdma.getSystemId());

                } else if (info instanceof CellInfoLte) {
                    final CellSignalStrengthLte lte = ((CellInfoLte) info)
                            .getCellSignalStrength();
                    final CellIdentityLte identityLte = ((CellInfoLte) info)
                            .getCellIdentity();
                    //Signal Strength
                    pDevice.mCell.setDBM(lte.getDbm());
                    pDevice.mCell.setTimingAdvance(lte.getTimingAdvance());
                    //Cell Identity
                    pDevice.mCell.setMCC(identityLte.getMcc());
                    pDevice.mCell.setMNC(identityLte.getMnc());
                    pDevice.mCell.setCID(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.mCell.setDBM(wcdma.getDbm());
                    //Cell Identity
                    pDevice.mCell.setLAC(identityWcdma.getLac());
                    pDevice.mCell.setMCC(identityWcdma.getMcc());
                    pDevice.mCell.setMNC(identityWcdma.getMnc());
                    pDevice.mCell.setCID(identityWcdma.getCid());
                    pDevice.mCell.setPSC(identityWcdma.getPsc());

                } else {
                    Log.i(TAG, mTAG + "Unknown type of cell signal! "
                            + "ClassName: " + info.getClass().getSimpleName()
                            + " ToString: " + info.toString());
                }
                if (pDevice.mCell.isValid()) {
                    break;
                }
            }
        }
    } catch (NullPointerException npe) {
       Log.e(TAG, mTAG + "loadCellInfo: Unable to obtain cell signal information: ", npe);
    }

}
 
Example #18
Source File: LocationNetworkSourcesService.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
private void processCellInfoList(Context context,
                                 TelephonyManager mTelephonyManager,
                                 List<CellInfo> cellInfoList,
                                 List<Cell> cells) {
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return;
    }
    for (CellInfo c : cellInfoList) {
        Cell cell = new Cell();
        if (c instanceof CellInfoGsm) {
            //Log.v(TAG, "GSM cell found");
            cell.cellId = ((CellInfoGsm) c).getCellIdentity().getCid();
            cell.area = ((CellInfoGsm) c).getCellIdentity().getLac();
            cell.mcc = ((CellInfoGsm)c).getCellIdentity().getMcc();
            cell.mnc = ((CellInfoGsm)c).getCellIdentity().getMnc();
            cell.psc = ((CellInfoGsm)c).getCellIdentity().getPsc();
            cell.technology = mTelephonyManager.getNetworkType();
            appendLog(context, TAG, "CellInfoGsm for ", cell.mcc, cell.mnc, cell.area, cell.cellId, cell.technology);
        } else if (c instanceof CellInfoCdma) {
            /* object.put("cellId", ((CellInfoCdma)s).getCellIdentity().getBasestationId());
                object.put("locationAreaCode", ((CellInfoCdma)s).getCellIdentity().getLac());
                object.put("mobileCountryCode", ((CellInfoCdma)s).getCellIdentity().get());
                object.put("mobileNetworkCode", ((CellInfoCdma)s).getCellIdentity().getMnc());*/
            appendLog(context, TAG, ":Using of CDMA cells for NLP not yet implemented");
        } else if (c instanceof CellInfoLte) {
            //Log.v(TAG, "LTE cell found");
            cell.cellId = ((CellInfoLte) c).getCellIdentity().getCi();
            cell.area = ((CellInfoLte) c).getCellIdentity().getTac();
            cell.mcc = ((CellInfoLte)c).getCellIdentity().getMcc();
            cell.mnc = ((CellInfoLte)c).getCellIdentity().getMnc();
            cell.technology = mTelephonyManager.getNetworkType();
            appendLog(context, TAG, "CellInfoLte for ", cell.mcc, cell.mnc, cell.area, cell.cellId, cell.technology, ((CellInfoLte)c).getCellIdentity().getPci());
        } else if (c instanceof CellInfoWcdma) {
            //Log.v(TAG, "CellInfoWcdma cell found");
            cell.cellId = ((CellInfoWcdma) c).getCellIdentity().getCid();
            cell.area = ((CellInfoWcdma) c).getCellIdentity().getLac();
            cell.mcc = ((CellInfoWcdma)c).getCellIdentity().getMcc();
            cell.mnc = ((CellInfoWcdma)c).getCellIdentity().getMnc();
            cell.psc = ((CellInfoWcdma)c).getCellIdentity().getPsc();
            cell.technology = mTelephonyManager.getNetworkType();
            appendLog(context, TAG, "CellInfoLte for ", cell.mcc, cell.mnc, cell.area, cell.cellId, cell.technology, ((CellInfoWcdma) c).getCellIdentity().getPsc());
        } else {
            appendLog(context, TAG, "CellInfo of unexpected type: " + c);
        }
        cells.add(cell);
    }
}
 
Example #19
Source File: SignalInfo.java    From MobileInfo with Apache License 2.0 4 votes vote down vote up
/**
 * mobile
 *
 * @param context
 * @return
 */
@SuppressLint("MissingPermission")
private static void getMobileDbm(Context context, SignalBean signalBean) {
    int dbm = -1;
    int level = 0;
    try {
        signalBean.setnIpAddress(getNetIPV4());
        signalBean.setnIpAddressIpv6(getNetIP());
        signalBean.setMacAddress(getMac(context));
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        List<CellInfo> cellInfoList;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            if (tm == null) {
                return;
            }
            cellInfoList = tm.getAllCellInfo();
            if (null != cellInfoList) {
                for (CellInfo cellInfo : cellInfoList) {
                    if (cellInfo instanceof CellInfoGsm) {
                        CellSignalStrengthGsm cellSignalStrengthGsm = ((CellInfoGsm) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthGsm.getDbm();
                        level = cellSignalStrengthGsm.getLevel();
                    } else if (cellInfo instanceof CellInfoCdma) {
                        CellSignalStrengthCdma cellSignalStrengthCdma =
                                ((CellInfoCdma) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthCdma.getDbm();
                        level = cellSignalStrengthCdma.getLevel();
                    } else if (cellInfo instanceof CellInfoLte) {
                        CellSignalStrengthLte cellSignalStrengthLte = ((CellInfoLte) cellInfo).getCellSignalStrength();
                        dbm = cellSignalStrengthLte.getDbm();
                        level = cellSignalStrengthLte.getLevel();

                    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                        if (cellInfo instanceof CellInfoWcdma) {
                            CellSignalStrengthWcdma cellSignalStrengthWcdma =
                                    ((CellInfoWcdma) cellInfo).getCellSignalStrength();
                            dbm = cellSignalStrengthWcdma.getDbm();
                            level = cellSignalStrengthWcdma.getLevel();
                        }
                    }
                }
            }
        }
        signalBean.setRssi(dbm );
        signalBean.setLevel(level);
    } catch (Exception e) {
        Log.i(TAG, e.toString());
    }
}