android.telephony.CellSignalStrengthGsm Java Examples

The following examples show how to use android.telephony.CellSignalStrengthGsm. 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: JSONHelper.java    From cordova-plugin-advanced-geolocation with Apache License 2.0 5 votes vote down vote up
/**
 * Converts CellInfoGsm into JSON
 * @param cellInfo CellInfoGsm
 * @return JSON
 */
public static String cellInfoGSMJSON(CellInfoGsm 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", GSM);
            json.put("timestamp", calendar.getTimeInMillis());

            final CellIdentityGsm identityGsm = cellInfo.getCellIdentity();

            json.put("cid", identityGsm.getCid());
            json.put("lac", identityGsm.getLac());
            json.put("mcc", identityGsm.getMcc());
            json.put("mnc", identityGsm.getMnc());

            if (returnSignalStrength){
                final JSONObject jsonSignalStrength = new JSONObject();
                final CellSignalStrengthGsm cellSignalStrengthGsm = cellInfo.getCellSignalStrength();
                jsonSignalStrength.put("asuLevel", cellSignalStrengthGsm.getAsuLevel());
                jsonSignalStrength.put("dbm", cellSignalStrengthGsm.getDbm());
                jsonSignalStrength.put("level", cellSignalStrengthGsm.getLevel());

                json.put("cellSignalStrengthGsm", jsonSignalStrength);
            }
        }
        catch(JSONException exc) {
            logJSONException(exc);
        }
    }
    return json.toString();
}
 
Example #2
Source File: CellInfoGsmAssert.java    From assertj-android with Apache License 2.0 5 votes vote down vote up
public CellInfoGsmAssert hasCellSignalStrength(CellSignalStrengthGsm cellSignalStrength) {
  isNotNull();
  CellSignalStrengthGsm actualCellSignalStrength = actual.getCellSignalStrength();
  assertThat(actualCellSignalStrength) //
      .overridingErrorMessage("Expected cell signal strength <%s> but was <%s>.", cellSignalStrength, actualCellSignalStrength) //
      .isEqualTo(cellSignalStrength);
  return this;
}
 
Example #3
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 #4
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());
    }
}
 
Example #5
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 #6
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 #7
Source File: DeviceInfo.java    From proofmode with GNU General Public License v3.0 4 votes vote down vote up
public static String getCellInfo(Context ctx) throws SecurityException {
        TelephonyManager tel = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);

        JSONArray cellList = new JSONArray();

// Type of the network
        int phoneTypeInt = tel.getPhoneType();
        String phoneType = null;
        phoneType = phoneTypeInt == TelephonyManager.PHONE_TYPE_GSM ? "gsm" : phoneType;
        phoneType = phoneTypeInt == TelephonyManager.PHONE_TYPE_CDMA ? "cdma" : phoneType;

        //from Android M up must use getAllCellInfo
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {

            List<CellInfo> infos = null;
            infos = tel.getAllCellInfo();

            for (int i = 0; i < infos.size(); ++i) {
                try {
                    JSONObject cellObj = new JSONObject();
                    CellInfo info = infos.get(i);
                    if (info instanceof CellInfoGsm) {
                        CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
                        CellIdentityGsm identityGsm = ((CellInfoGsm) info).getCellIdentity();
                        cellObj.put("cellId", identityGsm.getCid());
                        cellObj.put("lac", identityGsm.getLac());
                        cellObj.put("dbm", gsm.getDbm());
                        cellList.put(cellObj);
                    } else if (info instanceof CellInfoLte) {
                        CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
                        CellIdentityLte identityLte = ((CellInfoLte) info).getCellIdentity();
                        cellObj.put("cellId", identityLte.getCi());
                        cellObj.put("tac", identityLte.getTac());
                        cellObj.put("dbm", lte.getDbm());
                        cellList.put(cellObj);
                    }

                } catch (Exception ex) {

                }
            }
        }


        return cellList.toString();
    }
 
Example #8
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 #9
Source File: ScanService.java    From spidey with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void startScan() {
	
	logMessage("starting tower scan... ");
	Scan scan = new Scan();

	// TODO: Get location from user?
	scan.setLocation(lastScanName);

	// TODO: use actual GPS Coordinates
	scan.setLatitude(lastScanLat);
	scan.setLongitude(lastScanLon);

	long scan_id = db.createScan(scan);

	List<CellInfo> cellInfos = (List<CellInfo>) this.telephonyManager
			.getAllCellInfo();

	// TODO: better error handling of null cellinfos
	if (cellInfos != null) {
		for (CellInfo cellInfo : cellInfos) {

			if (cellInfo instanceof CellInfoGsm) {
				CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;

				CellIdentityGsm cellIdentity = cellInfoGsm
						.getCellIdentity();
				CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm
						.getCellSignalStrength();

				int dbmLevel = cellSignalStrengthGsm.getDbm();
				
				com.spideyapp.sqlite.model.CellInfo cell = new com.spideyapp.sqlite.model.CellInfo(
						cellIdentity.getCid(), cellIdentity.getLac(),
						cellIdentity.getMcc(), cellIdentity.getMnc(),dbmLevel);

				db.createCell(cell, scan_id);

				shareCellInfo (cell);
				
			}
		}
	}

}
 
Example #10
Source File: CellSignalStrengthGsmAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public CellSignalStrengthGsmAssert(CellSignalStrengthGsm actual) {
  super(actual, CellSignalStrengthGsmAssert.class);
}