use of android.telephony.CellInfo 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.CellInfo 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.CellInfo in project android_frameworks_base by AOSPA.
the class EmergencyAffordanceService method handleUpdateCellInfo.
private boolean handleUpdateCellInfo() {
List<CellInfo> cellInfos = mTelephonyManager.getAllCellInfo();
if (cellInfos == null) {
return false;
}
boolean stopScanningAfterScan = false;
for (CellInfo cellInfo : cellInfos) {
int mcc = 0;
if (cellInfo instanceof CellInfoGsm) {
mcc = ((CellInfoGsm) cellInfo).getCellIdentity().getMcc();
} else if (cellInfo instanceof CellInfoLte) {
mcc = ((CellInfoLte) cellInfo).getCellIdentity().getMcc();
} else if (cellInfo instanceof CellInfoWcdma) {
mcc = ((CellInfoWcdma) cellInfo).getCellIdentity().getMcc();
}
if (mccRequiresEmergencyAffordance(mcc)) {
setNetworkNeedsEmergencyAffordance(true);
return true;
} else if (mcc != 0 && mcc != Integer.MAX_VALUE) {
// we found an mcc that isn't in the list, abort
stopScanningAfterScan = true;
}
}
if (stopScanningAfterScan) {
stopScanning();
} else {
onCellScanFinishedUnsuccessful();
}
setNetworkNeedsEmergencyAffordance(false);
return false;
}
use of android.telephony.CellInfo in project android_frameworks_base by ResurrectionRemix.
the class EmergencyAffordanceService method handleUpdateCellInfo.
private boolean handleUpdateCellInfo() {
List<CellInfo> cellInfos = mTelephonyManager.getAllCellInfo();
if (cellInfos == null) {
return false;
}
boolean stopScanningAfterScan = false;
for (CellInfo cellInfo : cellInfos) {
int mcc = 0;
if (cellInfo instanceof CellInfoGsm) {
mcc = ((CellInfoGsm) cellInfo).getCellIdentity().getMcc();
} else if (cellInfo instanceof CellInfoLte) {
mcc = ((CellInfoLte) cellInfo).getCellIdentity().getMcc();
} else if (cellInfo instanceof CellInfoWcdma) {
mcc = ((CellInfoWcdma) cellInfo).getCellIdentity().getMcc();
}
if (mccRequiresEmergencyAffordance(mcc)) {
setNetworkNeedsEmergencyAffordance(true);
return true;
} else if (mcc != 0 && mcc != Integer.MAX_VALUE) {
// we found an mcc that isn't in the list, abort
stopScanningAfterScan = true;
}
}
if (stopScanningAfterScan) {
stopScanning();
} else {
onCellScanFinishedUnsuccessful();
}
setNetworkNeedsEmergencyAffordance(false);
return false;
}
use of android.telephony.CellInfo in project platform_frameworks_base by android.
the class EmergencyAffordanceService method handleUpdateCellInfo.
private boolean handleUpdateCellInfo() {
List<CellInfo> cellInfos = mTelephonyManager.getAllCellInfo();
if (cellInfos == null) {
return false;
}
boolean stopScanningAfterScan = false;
for (CellInfo cellInfo : cellInfos) {
int mcc = 0;
if (cellInfo instanceof CellInfoGsm) {
mcc = ((CellInfoGsm) cellInfo).getCellIdentity().getMcc();
} else if (cellInfo instanceof CellInfoLte) {
mcc = ((CellInfoLte) cellInfo).getCellIdentity().getMcc();
} else if (cellInfo instanceof CellInfoWcdma) {
mcc = ((CellInfoWcdma) cellInfo).getCellIdentity().getMcc();
}
if (mccRequiresEmergencyAffordance(mcc)) {
setNetworkNeedsEmergencyAffordance(true);
return true;
} else if (mcc != 0 && mcc != Integer.MAX_VALUE) {
// we found an mcc that isn't in the list, abort
stopScanningAfterScan = true;
}
}
if (stopScanningAfterScan) {
stopScanning();
} else {
onCellScanFinishedUnsuccessful();
}
setNetworkNeedsEmergencyAffordance(false);
return false;
}
Aggregations