use of android.telephony.CellInfoCdma in project DataLogger by sussexwearlab.
the class CellsInfoDataCollector method getCellInfoString.
private String getCellInfoString(List<CellInfo> cellsInfo) {
// Timestamp in system nanoseconds since boot, including time spent in sleep.
long nanoTime = SystemClock.elapsedRealtimeNanos() + mNanosOffset;
// System local time in millis
long currentMillis = (new Date()).getTime();
String message = String.format("%s", currentMillis) + ";" + String.format("%s", nanoTime) + ";" + String.format("%s", mNanosOffset) + ";" + Integer.toString(cellsInfo.size());
// The list can include one or more CellInfoGsm, CellInfoCdma, CellInfoLte, and CellInfoWcdma objects, in any combination.
for (final CellInfo cellInfo : cellsInfo) {
if (cellInfo instanceof CellInfoGsm) {
// True if this cell is registered to the mobile network.
// 0, 1 or more CellInfo objects may return isRegistered() true.
int isRegistered = (cellInfo.isRegistered()) ? 1 : 0;
final CellSignalStrengthGsm gsmStrength = ((CellInfoGsm) cellInfo).getCellSignalStrength();
// Get the signal level as an asu value between 0..31, 99 is unknown Asu is calculated based on 3GPP RSRP.
int asuLevel = gsmStrength.getAsuLevel();
// Get the signal strength as dBm
int dBm = gsmStrength.getDbm();
// Get signal level as an int from 0..4
int level = gsmStrength.getLevel();
final CellIdentityGsm gsmId = ((CellInfoGsm) cellInfo).getCellIdentity();
// CID Either 16-bit GSM Cell Identity described in TS 27.007, 0..65535, Integer.MAX_VALUE if unknown
int cid = gsmId.getCid();
// 16-bit Location Area Code, 0..65535, Integer.MAX_VALUE if unknown
int lac = gsmId.getLac();
// 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown
int mcc = gsmId.getMcc();
// 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
int mnc = gsmId.getMnc();
message += ";GSM;" + isRegistered + ";" + cid + ";" + lac + ";" + mcc + ";" + mnc + ";" + asuLevel + ";" + dBm + ";" + level;
} else if (cellInfo instanceof CellInfoCdma) {
// True if this cell is registered to the mobile network.
// 0, 1 or more CellInfo objects may return isRegistered() true.
int isRegistered = (cellInfo.isRegistered()) ? 1 : 0;
final CellSignalStrengthCdma cdmaStength = ((CellInfoCdma) cellInfo).getCellSignalStrength();
// Get the signal level as an asu value between 0..97, 99 is unknown
int asuLevel = cdmaStength.getAsuLevel();
// Get the CDMA RSSI value in dBm
int cdmaDbm = cdmaStength.getCdmaDbm();
// Get the CDMA Ec/Io value in dB*10
int cdmaEcio = cdmaStength.getCdmaEcio();
// Get cdma as level 0..4
int cdmaLevel = cdmaStength.getCdmaLevel();
// Get the signal strength as dBm
int dBm = cdmaStength.getDbm();
// Get the EVDO RSSI value in dBm
int evdoDbm = cdmaStength.getEvdoDbm();
// Get the EVDO Ec/Io value in dB*10
int evdoEcio = cdmaStength.getEvdoEcio();
// Get Evdo as level 0..4
int evdoLevel = cdmaStength.getEvdoLevel();
// Get the signal to noise ratio.
int evdoSnr = cdmaStength.getEvdoSnr();
// Get signal level as an int from 0..4
int level = cdmaStength.getLevel();
final CellIdentityCdma cdmaId = ((CellInfoCdma) cellInfo).getCellIdentity();
// Base Station Id 0..65535, Integer.MAX_VALUE if unknown
int basestationId = cdmaId.getBasestationId();
// Base station latitude, which is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
// It is represented in units of 0.25 seconds and ranges from -1296000 to 1296000, both
// values inclusive (corresponding to a range of -90 to +90 degrees). Integer.MAX_VALUE if unknown.
int latitude = cdmaId.getLatitude();
// Base station longitude, which is a decimal number as specified in 3GPP2 C.S0005-A v6.0.
// It is represented in units of 0.25 seconds and ranges from -2592000 to 2592000, both
// values inclusive (corresponding to a range of -180 to +180 degrees). Integer.MAX_VALUE if unknown.
int longitude = cdmaId.getLongitude();
// Network Id 0..65535, Integer.MAX_VALUE if unknown
int networkId = cdmaId.getNetworkId();
// System Id 0..32767, Integer.MAX_VALUE if unknown
int systemId = cdmaId.getSystemId();
message += ";CDMA;" + isRegistered + ";" + basestationId + ";" + latitude + ";" + longitude + ";" + networkId + ";" + systemId + ";" + asuLevel + ";" + cdmaDbm + ";" + cdmaEcio + ";" + cdmaLevel + ";" + dBm + ";" + evdoDbm + ";" + evdoEcio + ";" + evdoLevel + ";" + evdoSnr + ";" + level;
} else if (cellInfo instanceof CellInfoLte) {
// True if this cell is registered to the mobile network.
// 0, 1 or more CellInfo objects may return isRegistered() true.
int isRegistered = (cellInfo.isRegistered()) ? 1 : 0;
final CellSignalStrengthLte lteStrength = ((CellInfoLte) cellInfo).getCellSignalStrength();
// Get the LTE signal level as an asu value between 0..97, 99 is unknown Asu is calculated based on 3GPP RSRP.
// Represents a normalized version of the signal strength as dBm
int asuLevel = lteStrength.getAsuLevel();
// Get the signal strength as dBm
// Returns RSRP – Reference Signal Received Power
int dBm = lteStrength.getDbm();
// Get signal level as an int from 0..4
int level = lteStrength.getLevel();
final CellIdentityLte lteId = ((CellInfoLte) cellInfo).getCellIdentity();
// 28-bit Cell Identity, Integer.MAX_VALUE if unknown
int ci = lteId.getCi();
// 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown
int mcc = lteId.getMcc();
// 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
int mnc = lteId.getMnc();
// Physical Cell Id 0..503, Integer.MAX_VALUE if unknown
int pci = lteId.getPci();
// 16-bit Tracking Area Code, Integer.MAX_VALUE if unknown
int tac = lteId.getTac();
message += ";LTE;" + isRegistered + ";" + ci + ";" + mcc + ";" + mnc + ";" + pci + ";" + tac + ";" + asuLevel + ";" + dBm + ";" + level;
// 13 129108338 114 -1
// LTE;129108338;234;10;384;144;39;-101;3
} else if (cellInfo instanceof CellInfoWcdma) {
// True if this cell is registered to the mobile network.
// 0, 1 or more CellInfo objects may return isRegistered() true.
int isRegistered = (cellInfo.isRegistered()) ? 1 : 0;
final CellSignalStrengthWcdma wcdmaStrength = ((CellInfoWcdma) cellInfo).getCellSignalStrength();
// Get the signal level as an asu value between 0..31, 99 is unknown Asu is calculated based on 3GPP RSRP.
int asuLevel = wcdmaStrength.getAsuLevel();
// Get the signal strength as dBm
int dBm = wcdmaStrength.getDbm();
// Get signal level as an int from 0..4
int level = wcdmaStrength.getLevel();
final CellIdentityWcdma wcdmaId = ((CellInfoWcdma) cellInfo).getCellIdentity();
// CID 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, Integer.MAX_VALUE if unknown
int cid = wcdmaId.getCid();
// 16-bit Location Area Code, 0..65535, Integer.MAX_VALUE if unknown
int lac = wcdmaId.getLac();
// 3-digit Mobile Country Code, 0..999, Integer.MAX_VALUE if unknown
int mcc = wcdmaId.getMcc();
// 2 or 3-digit Mobile Network Code, 0..999, Integer.MAX_VALUE if unknown
int mnc = wcdmaId.getMnc();
// 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511, Integer.MAX_VALUE if unknown
int psc = wcdmaId.getPsc();
message += ";WCDMA;" + isRegistered + ";" + cid + ";" + lac + ";" + mcc + ";" + mnc + ";" + psc + ";" + asuLevel + ";" + dBm + ";" + level;
} else {
Log.e(TAG, "Unknown type of cell signal");
}
}
return message;
}
use of android.telephony.CellInfoCdma in project android_frameworks_base by AOSPA.
the class NetworkMonitor method sendNetworkConditionsBroadcast.
/**
* @param responseReceived - whether or not we received a valid HTTP response to our request.
* If false, isCaptivePortal and responseTimestampMs are ignored
* TODO: This should be moved to the transports. The latency could be passed to the transports
* along with the captive portal result. Currently the TYPE_MOBILE broadcasts appear unused so
* perhaps this could just be added to the WiFi transport only.
*/
private void sendNetworkConditionsBroadcast(boolean responseReceived, boolean isCaptivePortal, long requestTimestampMs, long responseTimestampMs) {
if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 0) {
return;
}
if (systemReady == false)
return;
Intent latencyBroadcast = new Intent(ACTION_NETWORK_CONDITIONS_MEASURED);
switch(mNetworkAgentInfo.networkInfo.getType()) {
case ConnectivityManager.TYPE_WIFI:
WifiInfo currentWifiInfo = mWifiManager.getConnectionInfo();
if (currentWifiInfo != null) {
// NOTE: getSSID()'s behavior changed in API 17; before that, SSIDs were not
// surrounded by double quotation marks (thus violating the Javadoc), but this
// was changed to match the Javadoc in API 17. Since clients may have started
// sanitizing the output of this method since API 17 was released, we should
// not change it here as it would become impossible to tell whether the SSID is
// simply being surrounded by quotes due to the API, or whether those quotes
// are actually part of the SSID.
latencyBroadcast.putExtra(EXTRA_SSID, currentWifiInfo.getSSID());
latencyBroadcast.putExtra(EXTRA_BSSID, currentWifiInfo.getBSSID());
} else {
if (VDBG)
logw("network info is TYPE_WIFI but no ConnectionInfo found");
return;
}
break;
case ConnectivityManager.TYPE_MOBILE:
latencyBroadcast.putExtra(EXTRA_NETWORK_TYPE, mTelephonyManager.getNetworkType());
List<CellInfo> info = mTelephonyManager.getAllCellInfo();
if (info == null)
return;
int numRegisteredCellInfo = 0;
for (CellInfo cellInfo : info) {
if (cellInfo.isRegistered()) {
numRegisteredCellInfo++;
if (numRegisteredCellInfo > 1) {
if (VDBG)
logw("more than one registered CellInfo." + " Can't tell which is active. Bailing.");
return;
}
if (cellInfo instanceof CellInfoCdma) {
CellIdentityCdma cellId = ((CellInfoCdma) cellInfo).getCellIdentity();
latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
} else if (cellInfo instanceof CellInfoGsm) {
CellIdentityGsm cellId = ((CellInfoGsm) cellInfo).getCellIdentity();
latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
} else if (cellInfo instanceof CellInfoLte) {
CellIdentityLte cellId = ((CellInfoLte) cellInfo).getCellIdentity();
latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
} else if (cellInfo instanceof CellInfoWcdma) {
CellIdentityWcdma cellId = ((CellInfoWcdma) cellInfo).getCellIdentity();
latencyBroadcast.putExtra(EXTRA_CELL_ID, cellId);
} else {
if (VDBG)
logw("Registered cellinfo is unrecognized");
return;
}
}
}
break;
default:
return;
}
latencyBroadcast.putExtra(EXTRA_CONNECTIVITY_TYPE, mNetworkAgentInfo.networkInfo.getType());
latencyBroadcast.putExtra(EXTRA_RESPONSE_RECEIVED, responseReceived);
latencyBroadcast.putExtra(EXTRA_REQUEST_TIMESTAMP_MS, requestTimestampMs);
if (responseReceived) {
latencyBroadcast.putExtra(EXTRA_IS_CAPTIVE_PORTAL, isCaptivePortal);
latencyBroadcast.putExtra(EXTRA_RESPONSE_TIMESTAMP_MS, responseTimestampMs);
}
mContext.sendBroadcastAsUser(latencyBroadcast, UserHandle.CURRENT, PERMISSION_ACCESS_NETWORK_CONDITIONS);
}
use of android.telephony.CellInfoCdma in project PhoneProfilesPlus by henrichg.
the class PhoneStateScanner method getAllCellInfo.
/*
void resetListening(boolean oldPowerSaveMode, boolean forceReset) {
if ((forceReset) || (PPApplication.isPowerSaveMode != oldPowerSaveMode)) {
disconnect();
connect();
}
}
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void getAllCellInfo(List<CellInfo> cellInfo) {
if (cellInfo != null) {
if (Permissions.checkLocation(context.getApplicationContext())) {
for (CellInfo _cellInfo : cellInfo) {
if (_cellInfo instanceof CellInfoGsm) {
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "gsm info="+_cellInfo);
CellIdentityGsm identityGsm = ((CellInfoGsm) _cellInfo).getCellIdentity();
if (identityGsm.getCid() != Integer.MAX_VALUE) {
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "gsm mCid="+identityGsm.getCid());
if (_cellInfo.isRegistered()) {
registeredCell = identityGsm.getCid();
lastConnectedTime = Calendar.getInstance().getTimeInMillis();
}
}
} else if (_cellInfo instanceof CellInfoLte) {
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "lte info="+_cellInfo);
CellIdentityLte identityLte = ((CellInfoLte) _cellInfo).getCellIdentity();
if (identityLte.getCi() != Integer.MAX_VALUE) {
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "lte mCi="+identityLte.getCi());
if (_cellInfo.isRegistered()) {
registeredCell = identityLte.getCi();
lastConnectedTime = Calendar.getInstance().getTimeInMillis();
}
}
} else if (_cellInfo instanceof CellInfoWcdma) {
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "wcdma info="+_cellInfo);
// if (android.os.Build.VERSION.SDK_INT >= 18) {
CellIdentityWcdma identityWcdma = ((CellInfoWcdma) _cellInfo).getCellIdentity();
if (identityWcdma.getCid() != Integer.MAX_VALUE) {
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "wcdma mCid=" + identityWcdma.getCid());
if (_cellInfo.isRegistered()) {
registeredCell = identityWcdma.getCid();
lastConnectedTime = Calendar.getInstance().getTimeInMillis();
}
}
// }
// else {
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "wcdma mCid=not supported for API level < 18");
// }
} else if (_cellInfo instanceof CellInfoCdma) {
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "cdma info="+_cellInfo);
CellIdentityCdma identityCdma = ((CellInfoCdma) _cellInfo).getCellIdentity();
if (identityCdma.getBasestationId() != Integer.MAX_VALUE) {
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "wcdma mCid="+identityCdma.getBasestationId());
if (_cellInfo.isRegistered()) {
registeredCell = identityCdma.getBasestationId();
lastConnectedTime = Calendar.getInstance().getTimeInMillis();
}
}
}
// else {
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "unknown info="+_cellInfo);
// }
}
// PPApplication.logE("PhoneStateScanner.getAllCellInfo", "---- end ----------------------------");
PPApplication.logE("PhoneStateScanner.getAllCellInfo", "registeredCell=" + registeredCell);
}
} else
PPApplication.logE("PhoneStateScanner.getAllCellInfo", "cell info is null");
}
use of android.telephony.CellInfoCdma in project android_packages_apps_Settings by omnirom.
the class RadioInfo method buildCellInfoString.
private final String buildCellInfoString(List<CellInfo> arrayCi) {
String value = new String();
StringBuilder cdmaCells = new StringBuilder(), gsmCells = new StringBuilder(), lteCells = new StringBuilder(), wcdmaCells = new StringBuilder();
if (arrayCi != null) {
for (CellInfo ci : arrayCi) {
if (ci instanceof CellInfoLte) {
lteCells.append(buildLteInfoString((CellInfoLte) ci));
} else if (ci instanceof CellInfoWcdma) {
wcdmaCells.append(buildWcdmaInfoString((CellInfoWcdma) ci));
} else if (ci instanceof CellInfoGsm) {
gsmCells.append(buildGsmInfoString((CellInfoGsm) ci));
} else if (ci instanceof CellInfoCdma) {
cdmaCells.append(buildCdmaInfoString((CellInfoCdma) ci));
}
}
if (lteCells.length() != 0) {
value += String.format("LTE\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-3.3s %-6.6s %-4.4s %-4.4s %-2.2s\n", "SRV", "MCC", "MNC", "TAC", "CID", "PCI", "EARFCN", "RSRP", "RSRQ", "TA");
value += lteCells.toString();
}
if (wcdmaCells.length() != 0) {
value += String.format("WCDMA\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-3.3s %-4.4s\n", "SRV", "MCC", "MNC", "LAC", "CID", "UARFCN", "PSC", "RSCP");
value += wcdmaCells.toString();
}
if (gsmCells.length() != 0) {
value += String.format("GSM\n%-3.3s %-3.3s %-3.3s %-5.5s %-5.5s %-6.6s %-4.4s %-4.4s\n", "SRV", "MCC", "MNC", "LAC", "CID", "ARFCN", "BSIC", "RSSI");
value += gsmCells.toString();
}
if (cdmaCells.length() != 0) {
value += String.format("CDMA/EVDO\n%-3.3s %-5.5s %-5.5s %-5.5s %-6.6s %-6.6s %-6.6s %-6.6s %-5.5s\n", "SRV", "SID", "NID", "BSID", "C-RSSI", "C-ECIO", "E-RSSI", "E-ECIO", "E-SNR");
value += cdmaCells.toString();
}
} else {
value = "unknown";
}
return value.toString();
}
use of android.telephony.CellInfoCdma in project network-monitor by caarmen.
the class CellLocationDataSource method fillCellLocationV17.
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void fillCellLocationV17(ContentValues values) {
if (PermissionUtil.hasLocationPermission(mContext)) {
@SuppressLint("MissingPermission") List<CellInfo> cellInfos = mTelephonyManager.getAllCellInfo();
if (cellInfos == null || cellInfos.isEmpty()) {
fillCellLocation(values);
} else {
StreamSupport.stream(cellInfos).filter(CellInfo::isRegistered).forEach(cellInfo -> {
if (cellInfo instanceof CellInfoGsm) {
CellInfoGsm gsmCellInfo = (CellInfoGsm) cellInfo;
CellIdentityGsm cellIdentityGsm = gsmCellInfo.getCellIdentity();
setGsmCellInfo(values, cellIdentityGsm.getCid(), cellIdentityGsm.getLac());
} else if (cellInfo instanceof CellInfoCdma) {
CellInfoCdma cellInfoCdma = (CellInfoCdma) cellInfo;
CellIdentityCdma cellIdentityCdma = cellInfoCdma.getCellIdentity();
setCdmaCellInfo(values, cellIdentityCdma.getBasestationId(), cellIdentityCdma.getLatitude(), cellIdentityCdma.getLongitude(), cellIdentityCdma.getNetworkId(), cellIdentityCdma.getSystemId());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && cellInfo instanceof CellInfoWcdma) {
CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
CellIdentityWcdma cellIdentityWcdma = cellInfoWcdma.getCellIdentity();
setGsmCellInfo(values, cellIdentityWcdma.getCid(), cellIdentityWcdma.getLac());
values.put(NetMonColumns.GSM_CELL_PSC, cellIdentityWcdma.getPsc());
} else if (cellInfo instanceof CellInfoLte) {
CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
CellIdentityLte cellIdentityLte = cellInfoLte.getCellIdentity();
values.put(NetMonColumns.LTE_CELL_CI, cellIdentityLte.getCi());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
values.put(NetMonColumns.LTE_CELL_EARFCN, cellIdentityLte.getEarfcn());
}
values.put(NetMonColumns.LTE_CELL_TAC, cellIdentityLte.getTac());
values.put(NetMonColumns.LTE_CELL_PCI, cellIdentityLte.getPci());
}
});
}
}
}
Aggregations