Java Code Examples for android.telephony.CellInfoLte#getCellIdentity()

The following examples show how to use android.telephony.CellInfoLte#getCellIdentity() . 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 CellInfoLte into JSON
 * @param cellInfo CellInfoLte
 * @return JSON
 */
public static String cellInfoLTEJSON(CellInfoLte 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", LTE);
            json.put("timestamp", calendar.getTimeInMillis());

            final CellIdentityLte identityLte = cellInfo.getCellIdentity();

            json.put("ci", identityLte.getCi());
            json.put("mcc", identityLte.getMcc());
            json.put("mnc", identityLte.getMnc());
            json.put("pci", identityLte.getPci());
            json.put("tac", identityLte.getTac());

            if (returnSignalStrength){
                final JSONObject jsonSignalStrength = new JSONObject();
                final CellSignalStrengthLte cellSignalStrengthLte = cellInfo.getCellSignalStrength();
                jsonSignalStrength.put("asuLevel", cellSignalStrengthLte.getAsuLevel());
                jsonSignalStrength.put("dbm", cellSignalStrengthLte.getDbm());
                jsonSignalStrength.put("level", cellSignalStrengthLte.getLevel());
                jsonSignalStrength.put("timingAdvance", cellSignalStrengthLte.getTimingAdvance());

                json.put("cellSignalStrengthLte", jsonSignalStrength);
            }
        }
        catch(JSONException exc) {
            logJSONException(exc);
        }
    }
    return json.toString();
}
 
Example 2
Source File: CellTowerListLte.java    From satstat with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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;
}