use of android.telephony.CellLocation in project XobotOS by xamarin.
the class GsmDataConnectionTracker method getCellLocationId.
private int getCellLocationId() {
int cid = -1;
CellLocation loc = mPhone.getCellLocation();
if (loc != null) {
if (loc instanceof GsmCellLocation) {
cid = ((GsmCellLocation) loc).getCid();
} else if (loc instanceof CdmaCellLocation) {
cid = ((CdmaCellLocation) loc).getBaseStationId();
}
}
return cid;
}
use of android.telephony.CellLocation in project PhoneProfilesPlus by henrichg.
the class PhoneStateScanner method getCellLocation.
@SuppressLint("MissingPermission")
private void getCellLocation() {
if (telephonyManager != null) {
CellLocation location = null;
if (Permissions.checkLocation(context.getApplicationContext()))
location = telephonyManager.getCellLocation();
getCellLocation(location);
}
}
use of android.telephony.CellLocation in project android_frameworks_opt_telephony by LineageOS.
the class GsmCellBroadcastHandler method handleGsmBroadcastSms.
/**
* Handle 3GPP format SMS-CB message.
* @param ar the AsyncResult containing the received PDUs
*/
private SmsCbMessage handleGsmBroadcastSms(AsyncResult ar) {
try {
byte[] receivedPdu = (byte[]) ar.result;
if (VDBG) {
int pduLength = receivedPdu.length;
for (int i = 0; i < pduLength; i += 8) {
StringBuilder sb = new StringBuilder("SMS CB pdu data: ");
for (int j = i; j < i + 8 && j < pduLength; j++) {
int b = receivedPdu[j] & 0xff;
if (b < 0x10) {
sb.append('0');
}
sb.append(Integer.toHexString(b)).append(' ');
}
log(sb.toString());
}
}
SmsCbHeader header = new SmsCbHeader(receivedPdu);
String plmn = TelephonyManager.from(mContext).getNetworkOperatorForPhone(mPhone.getPhoneId());
int lac = -1;
int cid = -1;
CellLocation cl = mPhone.getCellLocation();
// both 3GPP and 3GPP2 format messages
if (cl instanceof GsmCellLocation) {
GsmCellLocation cellLocation = (GsmCellLocation) cl;
lac = cellLocation.getLac();
cid = cellLocation.getCid();
}
SmsCbLocation location;
switch(header.getGeographicalScope()) {
case SmsCbMessage.GEOGRAPHICAL_SCOPE_LA_WIDE:
location = new SmsCbLocation(plmn, lac, -1);
break;
case SmsCbMessage.GEOGRAPHICAL_SCOPE_CELL_WIDE:
case SmsCbMessage.GEOGRAPHICAL_SCOPE_CELL_WIDE_IMMEDIATE:
location = new SmsCbLocation(plmn, lac, cid);
break;
case SmsCbMessage.GEOGRAPHICAL_SCOPE_PLMN_WIDE:
default:
location = new SmsCbLocation(plmn);
break;
}
byte[][] pdus;
int pageCount = header.getNumberOfPages();
if (pageCount > 1) {
// Multi-page message
SmsCbConcatInfo concatInfo = new SmsCbConcatInfo(header, location);
// Try to find other pages of the same message
pdus = mSmsCbPageMap.get(concatInfo);
if (pdus == null) {
// This is the first page of this message, make room for all
// pages and keep until complete
pdus = new byte[pageCount][];
mSmsCbPageMap.put(concatInfo, pdus);
}
// Page parameter is one-based
pdus[header.getPageIndex() - 1] = receivedPdu;
for (byte[] pdu : pdus) {
if (pdu == null) {
// Still missing pages, exit
return null;
}
}
// Message complete, remove and dispatch
mSmsCbPageMap.remove(concatInfo);
} else {
// Single page message
pdus = new byte[1][];
pdus[0] = receivedPdu;
}
// Remove messages that are out of scope to prevent the map from
// growing indefinitely, containing incomplete messages that were
// never assembled
Iterator<SmsCbConcatInfo> iter = mSmsCbPageMap.keySet().iterator();
while (iter.hasNext()) {
SmsCbConcatInfo info = iter.next();
if (!info.matchesLocation(plmn, lac, cid)) {
iter.remove();
}
}
return GsmSmsCbMessage.createSmsCbMessage(mContext, header, location, pdus);
} catch (RuntimeException e) {
loge("Error in decoding SMS CB pdu", e);
return null;
}
}
use of android.telephony.CellLocation in project DataLogger by sussexwearlab.
the class Depr_CellsInfoDataCollector method getCellInfoString.
private String getCellInfoString(SignalStrength signalStrength) {
// 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) + ";";
CellLocation cell = mTelephonyManager.getCellLocation();
if (cell instanceof GsmCellLocation) {
int lac, cid, dbm;
lac = ((GsmCellLocation) cell).getLac();
cid = ((GsmCellLocation) cell).getCid();
String generalNetworkType = networkTypeGeneral(mTelephonyManager.getNetworkType());
// "SignalStrength: mGsmSignalStrength mGsmBitErrorRate mCdmaDbm mCdmaEcio mEvdoDbm
// mEvdoEcio mEvdoSnr mLteSignalStrength mLteRsrp mLteRsrq mLteRssnr mLteCqi
// (isGsm ? "gsm|lte" : "cdma"));
String ssignal = signalStrength.toString();
String[] parts = ssignal.split(" ");
// Fallbacks will be triggered whenever generalNetworkType changes
if (generalNetworkType.equals("4G")) {
dbm = Integer.parseInt(parts[11]);
if (dbm >= -2) {
if (Integer.parseInt(parts[3]) < -2) {
dbm = Integer.parseInt(parts[3]);
} else {
dbm = signalStrength.getGsmSignalStrength();
}
}
} else if (generalNetworkType.equals("3G")) {
dbm = Integer.parseInt(parts[3]);
if (dbm >= -2) {
if (Integer.parseInt(parts[11]) < -2) {
dbm = Integer.parseInt(parts[11]);
} else {
dbm = signalStrength.getGsmSignalStrength();
}
}
} else {
dbm = signalStrength.getGsmSignalStrength();
if (dbm >= -2) {
if (Integer.parseInt(parts[3]) < -2) {
dbm = Integer.parseInt(parts[3]);
} else {
dbm = Integer.parseInt(parts[11]);
}
}
}
// Returns the numeric name (MCC+MNC) of current registered operator.
String mccMnc = mTelephonyManager.getNetworkOperator();
String mcc, mnc;
if (mccMnc != null && mccMnc.length() >= 4) {
mcc = mccMnc.substring(0, 3);
mnc = mccMnc.substring(3);
} else {
mcc = "NaN";
mnc = "NaN";
}
if (dbm < -2) {
message += mTelephonyManager.getNetworkType() + ";" + cid + ";" + lac + ";" + dbm + ";" + mcc + ";" + mnc;
} else {
message += mTelephonyManager.getNetworkType() + ";" + cid + ";" + lac + ";" + "NaN" + ";" + mcc + ";" + mnc;
}
}
return message;
}
use of android.telephony.CellLocation in project assertj-android by square.
the class TelephonyManagerAssert method hasCellLocation.
public TelephonyManagerAssert hasCellLocation(CellLocation cellLocation) {
isNotNull();
CellLocation actualCellLocation = actual.getCellLocation();
//
assertThat(actualCellLocation).overridingErrorMessage("Expected cell location <%s> but was <%s>.", cellLocation, //
actualCellLocation).isEqualTo(cellLocation);
return this;
}
Aggregations