use of android.telephony.cdma.CdmaCellLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class CellTracker method compareLac.
/**
* I removed the timer that activated this code and now the code will be run when
* the cell changes so it will detect faster rather than using a timer that might
* miss an imsi catcher, also says cpu rather than refreshing every x seconds.
*
* original comments below from xLaMbChOpSx
*
*
* Description: (From xLaMbChOpSx commit comment)
*
* Initial implementation for detection method 1 to compare the CID & LAC with the Cell
* Information Table contents as an initial implementation for detection of a changed LAC,
* once OCID issues (API key use etc) have been finalised this detection method can be
* extended to include checking of external data.
*
* REMOVED: refresh timer info
*
* As I have no real way of testing this I require testing by other project members who
* do have access to equipment or an environment where a changing LAC can be simulated
* thus confirming the accuracy of this implementation.
*
* Presently this will only invoke the MEDIUM threat level through the notification and
* does not fully implement the capturing and score based method as per the issue details
* once further testing is complete the alert and tracking of information can be refined.
*
* See:
* https://github.com/xLaMbChOpSx/Android-IMSI-Catcher-Detector/commit/43ae77e2a0cad10dfd50f92da5a998f9ece95b38
* https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/91#issuecomment-64391732
*
* Short explanation:
*
* This is a polling mechanism for getting the LAC/CID and location
* info for the currently connected cell.
*
* Variables:
* FIXED: now updates on cell change rather than a timer
* There is a "timer" here (REFRESH_RATE), what exactly is it timing?
* "Every REFRESH_RATE seconds, get connected cell details."
*
* Issues: [ ] We shouldn't do any detection here!
* [ ] We might wanna use a listener to do this?
* Are there any reasons why not using a listener?
*
* ChangeLog:
* 2015-03-03 E:V:A Changed getProp() to use TinyDB (SharedPreferences)
* 2015-0x-xx banjaxbanjo Update: ??? (hey dude what did you do?)
*
*/
public void compareLac(CellLocation location) {
@Cleanup Realm realm = Realm.getDefaultInstance();
switch(device.getPhoneId()) {
case TelephonyManager.PHONE_TYPE_NONE:
case TelephonyManager.PHONE_TYPE_SIP:
case TelephonyManager.PHONE_TYPE_GSM:
GsmCellLocation gsmCellLocation = (GsmCellLocation) location;
if (gsmCellLocation != null) {
monitorCell.setLocationAreaCode(gsmCellLocation.getLac());
monitorCell.setCellId(gsmCellLocation.getCid());
// Check if LAC is ok
boolean lacOK = dbHelper.checkLAC(realm, monitorCell);
if (!lacOK) {
changedLAC = true;
dbHelper.toEventLog(realm, 1, "Changing LAC");
// Detection Logs are made in checkLAC()
vibrate(100, Status.MEDIUM);
} else {
changedLAC = false;
}
if (tinydb.getBoolean("ocid_downloaded")) {
if (!dbHelper.openCellExists(realm, monitorCell.getCellId())) {
dbHelper.toEventLog(realm, 2, "CID not in Import realm");
log.info("ALERT: Connected to unknown CID not in Import realm: " + monitorCell.getCellId());
vibrate(100, Status.MEDIUM);
cellIdNotInOpenDb = true;
} else {
cellIdNotInOpenDb = false;
}
}
}
break;
case TelephonyManager.PHONE_TYPE_CDMA:
CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) location;
if (cdmaCellLocation != null) {
monitorCell.setLocationAreaCode(cdmaCellLocation.getNetworkId());
monitorCell.setCellId(cdmaCellLocation.getBaseStationId());
boolean lacOK = dbHelper.checkLAC(realm, monitorCell);
if (!lacOK) {
changedLAC = true;
/*dbHelper.insertEventLog(
MiscUtils.getCurrentTimeStamp(),
monitorCell.getLAC(),
monitorCell.getCid(),
monitorCell.getPSC(),//This is giving weird values like 21478364... is this right?
String.valueOf(monitorCell.getLat()),
String.valueOf(monitorCell.getLon()),
(int)monitorCell.getAccuracy(),
1,
"Changing LAC"
);*/
dbHelper.toEventLog(realm, 1, "Changing LAC");
} else {
changedLAC = false;
}
}
}
setNotification();
}
use of android.telephony.cdma.CdmaCellLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class Device method refreshDeviceInfo.
/**
* Refreshes all device specific details
*/
public void refreshDeviceInfo(TelephonyManager tm, Context context) {
//Phone type and associated details
iMEI = tm.getDeviceId();
iMEIv = tm.getDeviceSoftwareVersion();
phoneId = tm.getPhoneType();
roaming = tm.isNetworkRoaming();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
DeviceApi18.loadCellInfo(tm, this);
}
if (cell == null) {
cell = new Cell();
}
switch(phoneId) {
case TelephonyManager.PHONE_TYPE_NONE:
case TelephonyManager.PHONE_TYPE_SIP:
case TelephonyManager.PHONE_TYPE_GSM:
phoneType = "GSM";
mncMcc = tm.getNetworkOperator();
if (mncMcc != null && mncMcc.length() >= 5) {
try {
if (cell.getMobileCountryCode() == Integer.MAX_VALUE) {
cell.setMobileCountryCode(Integer.parseInt(tm.getNetworkOperator().substring(0, 3)));
}
if (cell.getMobileNetworkCode() == Integer.MAX_VALUE) {
cell.setMobileNetworkCode(Integer.parseInt(tm.getNetworkOperator().substring(3, 5)));
}
} catch (Exception e) {
log.info("MncMcc parse exception: ", e);
}
}
networkName = tm.getNetworkOperatorName();
if (!cell.isValid()) {
GsmCellLocation gsmCellLocation = (GsmCellLocation) tm.getCellLocation();
if (gsmCellLocation != null) {
cell.setCellId(gsmCellLocation.getCid());
cell.setLocationAreaCode(gsmCellLocation.getLac());
cell.setPrimaryScramblingCode(gsmCellLocation.getPsc());
}
}
break;
case TelephonyManager.PHONE_TYPE_CDMA:
phoneType = "CDMA";
if (!cell.isValid()) {
CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) tm.getCellLocation();
if (cdmaCellLocation != null) {
cell.setCellId(cdmaCellLocation.getBaseStationId());
cell.setLocationAreaCode(cdmaCellLocation.getNetworkId());
// one of these must be a bug !!
cell.setSid(cdmaCellLocation.getSystemId());
// See: http://stackoverflow.com/questions/8088046/android-how-to-identify-carrier-on-cdma-network
// and: https://github.com/klinker41/android-smsmms/issues/26
// todo: check! (Also CellTracker.java)
cell.setMobileNetworkCode(cdmaCellLocation.getSystemId());
//Retrieve MCC through System Property
String homeOperator = Helpers.getSystemProp(context, "ro.cdma.home.operator.numeric", "UNKNOWN");
if (!homeOperator.contains("UNKNOWN")) {
try {
if (cell.getMobileCountryCode() == Integer.MAX_VALUE) {
cell.setMobileCountryCode(Integer.valueOf(homeOperator.substring(0, 3)));
}
if (cell.getMobileNetworkCode() == Integer.MAX_VALUE) {
cell.setMobileNetworkCode(Integer.valueOf(homeOperator.substring(3, 5)));
}
} catch (Exception e) {
log.info("HomeOperator parse exception - " + e.getMessage(), e);
}
}
}
}
break;
}
// SIM Information
simCountry = getSimCountry(tm);
// Get the operator code of the active SIM (MCC + MNC)
simOperator = getSimOperator(tm);
simOperatorName = getSimOperatorName(tm);
simSerial = getSimSerial(tm);
simSubs = getSimSubs(tm);
dataActivityType = getDataActivityType(tm);
dataState = getDataState(tm);
}
use of android.telephony.cdma.CdmaCellLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class CellTracker method IsConnectedToCdmaFemto.
private boolean IsConnectedToCdmaFemto(ServiceState s) {
if (s == null) {
return false;
}
/* Get International Roaming indicator
* if indicator is not 0 return false
*/
/* Get the radio technology */
int networkType = device.cell.getNetType();
/* Check if it is EvDo network */
boolean evDoNetwork = isEvDoNetwork(networkType);
/* If it is not an evDo network check the network ID range.
* If it is connected to Femtocell, the NID should be between [0xfa, 0xff)
*/
if (!evDoNetwork) {
/* get network ID */
if (tm != null) {
CdmaCellLocation c = (CdmaCellLocation) tm.getCellLocation();
if (c != null) {
int networkID = c.getNetworkId();
int FEMTO_NID_MAX = 0xff;
int FEMTO_NID_MIN = 0xfa;
return !((networkID < FEMTO_NID_MIN) || (networkID >= FEMTO_NID_MAX));
} else {
log.verbose("Cell location info is null.");
return false;
}
} else {
log.verbose("Telephony Manager is null.");
return false;
}
} else {
/* get network ID */
if (tm != null) {
CdmaCellLocation c = (CdmaCellLocation) tm.getCellLocation();
if (c != null) {
int networkID = c.getNetworkId();
int FEMTO_NID_MAX = 0xff;
int FEMTO_NID_MIN = 0xfa;
return !((networkID < FEMTO_NID_MIN) || (networkID >= FEMTO_NID_MAX));
} else {
log.verbose("Cell location info is null.");
return false;
}
} else {
log.verbose("Telephony Manager is null.");
return false;
}
}
}
use of android.telephony.cdma.CdmaCellLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class CellTracker method onLocationChanged.
/**
* Add entries to the {@link com.secupwn.aimsicd.data.model.Measure Measure} realm
*/
public void onLocationChanged(Location loc) {
// TODO: See issue #555 (DeviceApi17.java is using API 18 CellInfoWcdma calls.
if (Build.VERSION.SDK_INT > 17) {
DeviceApi18.loadCellInfo(tm, device);
}
if (!device.cell.isValid()) {
CellLocation cellLocation = tm.getCellLocation();
if (cellLocation != null) {
switch(device.getPhoneId()) {
case TelephonyManager.PHONE_TYPE_NONE:
case TelephonyManager.PHONE_TYPE_SIP:
case TelephonyManager.PHONE_TYPE_GSM:
GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
// CID
device.cell.setCellId(gsmCellLocation.getCid());
// LAC
device.cell.setLocationAreaCode(gsmCellLocation.getLac());
// PSC
device.cell.setPrimaryScramblingCode(gsmCellLocation.getPsc());
break;
case TelephonyManager.PHONE_TYPE_CDMA:
CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
// BSID ??
device.cell.setCellId(cdmaCellLocation.getBaseStationId());
// NID
device.cell.setLocationAreaCode(cdmaCellLocation.getNetworkId());
// SID
device.cell.setSid(cdmaCellLocation.getSystemId());
// MNC <== BUG!??
device.cell.setMobileNetworkCode(cdmaCellLocation.getSystemId());
break;
}
}
}
if (loc != null && (Double.doubleToRawLongBits(loc.getLatitude()) != 0 && Double.doubleToRawLongBits(loc.getLongitude()) != 0)) {
// gpsd_lon
device.cell.setLon(loc.getLongitude());
// gpsd_lat
device.cell.setLat(loc.getLatitude());
// speed // TODO: Remove, we're not using it!
device.cell.setSpeed(loc.getSpeed());
// gpsd_accu
device.cell.setAccuracy(loc.getAccuracy());
// -- [deg]?? // TODO: Remove, we're not using it!
device.cell.setBearing(loc.getBearing());
//
device.setLastLocation(loc);
// Store last known location in preference
SharedPreferences.Editor prefsEditor;
prefsEditor = prefs.edit();
prefsEditor.putString(context.getString(R.string.data_last_lat_lon), String.valueOf(loc.getLatitude()) + ":" + String.valueOf(loc.getLongitude()));
prefsEditor.apply();
// TODO: Is correct behaviour? We should consider logging all cells, even without GPS.
if (trackingCell) {
// This also checks that the locationAreaCode are cid are not in DB before inserting
@Cleanup Realm realm = Realm.getDefaultInstance();
dbHelper.insertBTS(realm, device.cell);
}
}
}
use of android.telephony.cdma.CdmaCellLocation in project XobotOS by xamarin.
the class CdmaServiceStateTracker method pollStateDone.
protected void pollStateDone() {
if (DBG)
log("pollStateDone: oldSS=[" + ss + "] newSS=[" + newSS + "]");
boolean hasRegistered = ss.getState() != ServiceState.STATE_IN_SERVICE && newSS.getState() == ServiceState.STATE_IN_SERVICE;
boolean hasDeregistered = ss.getState() == ServiceState.STATE_IN_SERVICE && newSS.getState() != ServiceState.STATE_IN_SERVICE;
boolean hasCdmaDataConnectionAttached = mDataConnectionState != ServiceState.STATE_IN_SERVICE && mNewDataConnectionState == ServiceState.STATE_IN_SERVICE;
boolean hasCdmaDataConnectionDetached = mDataConnectionState == ServiceState.STATE_IN_SERVICE && mNewDataConnectionState != ServiceState.STATE_IN_SERVICE;
boolean hasCdmaDataConnectionChanged = mDataConnectionState != mNewDataConnectionState;
boolean hasNetworkTypeChanged = networkType != newNetworkType;
boolean hasChanged = !newSS.equals(ss);
boolean hasRoamingOn = !ss.getRoaming() && newSS.getRoaming();
boolean hasRoamingOff = ss.getRoaming() && !newSS.getRoaming();
boolean hasLocationChanged = !newCellLoc.equals(cellLoc);
// Add an event log when connection state changes
if (ss.getState() != newSS.getState() || mDataConnectionState != mNewDataConnectionState) {
EventLog.writeEvent(EventLogTags.CDMA_SERVICE_STATE_CHANGE, ss.getState(), mDataConnectionState, newSS.getState(), mNewDataConnectionState);
}
ServiceState tss;
tss = ss;
ss = newSS;
newSS = tss;
// clean slate for next time
newSS.setStateOutOfService();
CdmaCellLocation tcl = cellLoc;
cellLoc = newCellLoc;
newCellLoc = tcl;
mDataConnectionState = mNewDataConnectionState;
networkType = newNetworkType;
// this new state has been applied - forget it until we get a new new state
newNetworkType = 0;
// clean slate for next time
newSS.setStateOutOfService();
if (hasNetworkTypeChanged) {
phone.setSystemProperty(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, ServiceState.radioTechnologyToString(networkType));
}
if (hasRegistered) {
mNetworkAttachedRegistrants.notifyRegistrants();
}
if (hasChanged) {
if (cm.getRadioState().isNVReady()) {
String eriText;
// Now the CDMAPhone sees the new ServiceState so it can get the new ERI text
if (ss.getState() == ServiceState.STATE_IN_SERVICE) {
eriText = phone.getCdmaEriText();
} else {
// Note that ServiceState.STATE_OUT_OF_SERVICE is valid used for
// mRegistrationState 0,2,3 and 4
eriText = phone.getContext().getText(com.android.internal.R.string.roamingTextSearching).toString();
}
ss.setOperatorAlphaLong(eriText);
}
String operatorNumeric;
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA, ss.getOperatorAlphaLong());
operatorNumeric = ss.getOperatorNumeric();
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);
if (operatorNumeric == null) {
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
mGotCountryCode = false;
} else {
String isoCountryCode = "";
try {
isoCountryCode = MccTable.countryCodeForMcc(Integer.parseInt(operatorNumeric.substring(0, 3)));
} catch (NumberFormatException ex) {
loge("pollStateDone: countryCodeForMcc error" + ex);
} catch (StringIndexOutOfBoundsException ex) {
loge("pollStateDone: countryCodeForMcc error" + ex);
}
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, isoCountryCode);
mGotCountryCode = true;
if (mNeedFixZone) {
fixTimeZone(isoCountryCode);
}
}
phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, ss.getRoaming() ? "true" : "false");
updateSpnDisplay();
phone.notifyServiceStateChanged(ss);
}
if (hasCdmaDataConnectionAttached) {
mAttachedRegistrants.notifyRegistrants();
}
if (hasCdmaDataConnectionDetached) {
mDetachedRegistrants.notifyRegistrants();
}
if (hasCdmaDataConnectionChanged || hasNetworkTypeChanged) {
phone.notifyDataConnection(null);
}
if (hasRoamingOn) {
mRoamingOnRegistrants.notifyRegistrants();
}
if (hasRoamingOff) {
mRoamingOffRegistrants.notifyRegistrants();
}
if (hasLocationChanged) {
phone.notifyLocationChanged();
}
}
Aggregations