use of android.telephony.gsm.GsmCellLocation in project android_frameworks_base by ParanoidAndroid.
the class GpsLocationProvider method requestRefLocation.
/**
* Called from native code to request reference location info
*/
private void requestRefLocation(int flags) {
TelephonyManager phone = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
final int phoneType = phone.getPhoneType();
if (phoneType == TelephonyManager.PHONE_TYPE_GSM) {
GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation();
if ((gsm_cell != null) && (phone.getNetworkOperator() != null) && (phone.getNetworkOperator().length() > 3)) {
int type;
int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3));
int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3));
int networkType = phone.getNetworkType();
if (networkType == TelephonyManager.NETWORK_TYPE_UMTS || networkType == TelephonyManager.NETWORK_TYPE_HSDPA || networkType == TelephonyManager.NETWORK_TYPE_HSUPA || networkType == TelephonyManager.NETWORK_TYPE_HSPA || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) {
type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
} else {
type = AGPS_REF_LOCATION_TYPE_GSM_CELLID;
}
native_agps_set_ref_location_cellid(type, mcc, mnc, gsm_cell.getLac(), gsm_cell.getCid());
} else {
Log.e(TAG, "Error getting cell location info.");
}
} else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
Log.e(TAG, "CDMA not supported.");
}
}
use of android.telephony.gsm.GsmCellLocation 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.gsm.GsmCellLocation in project AisenWeiBo by wangdan.
the class SinaSDK method locationMobileGetLocation.
/**
* 根据移动基站WIFI等数据获取当前位置信息
*
* @return
* @throws TaskException
*/
public SinaLocationMap locationMobileGetLocation() throws TaskException {
Map<String, Object> requestMap = new HashMap<String, Object>();
// 请求版本信息
requestMap.put("version", "2.0");
// 请求地址信息
requestMap.put("host", "api.weibo.com");
// 请求类型
requestMap.put("radio_type", "gsm");
// 是否需要返回详细地址,可选,默认:false
requestMap.put("request_address", "true");
// 返回坐标是否偏移处理,偏移后坐标适合在新浪地图上使用(http://map.sina.com.cn),
// 不适用于百度地图(各地图偏移量不同,请谨慎处理);可选,默认:false
requestMap.put("decode_pos", "true");
TelephonyManager mTelNet = (TelephonyManager) GlobalContext.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation location = null;
if (mTelNet != null)
location = (GsmCellLocation) mTelNet.getCellLocation();
if (location != null) {
String operator = mTelNet.getNetworkOperator();
int mcc = Integer.parseInt(operator.substring(0, 3));
int mnc = Integer.parseInt(operator.substring(3));
List<NeighboringCellInfo> cellInfoList = mTelNet.getNeighboringCellInfo();
ArrayList<Map<String, Object>> cellMapList = new ArrayList<Map<String, Object>>();
for (NeighboringCellInfo cellInfo : cellInfoList) {
// 基站信息
Map<String, Object> cellMap = new HashMap<String, Object>();
// 基站号
cellMap.put("cell_id", location.getCid());
// 小区号
cellMap.put("location_area_code", cellInfo.getLac());
// 地区代码
cellMap.put("mobile_country_code", mcc);
// 运营商号
cellMap.put("mobile_network_code", mnc);
// 信号强度
cellMap.put("signal_strength", cellInfo.getRssi());
cellMapList.add(cellMap);
}
if (cellMapList.size() > 0)
requestMap.put("cell_towers", cellMapList);
}
WifiManager wm = (WifiManager) GlobalContext.getInstance().getSystemService(Context.WIFI_SERVICE);
List<ScanResult> scanResultList = wm.getScanResults();
if (scanResultList != null && scanResultList.size() > 0) {
ArrayList<Map<String, Object>> wifiMapList = new ArrayList<Map<String, Object>>();
for (ScanResult scanResult : scanResultList) {
// WIFI信息
Map<String, Object> wifiMap = new HashMap<String, Object>();
wifiMapList.add(wifiMap);
wifiMap.put("mac_address", scanResult.BSSID);
wifiMap.put("mac_name", scanResult.SSID);
// 信号强度
wifiMap.put("signal_strength", scanResult.level);
}
if (wifiMapList.size() > 0)
requestMap.put("wifi_towers", wifiMapList);
}
HttpConfig config = getHttpConfig();
Params params = new Params();
params.addParameter("json", JSON.toJSONString(requestMap));
return doPost(config, getSetting("locationMobileGetLocation"), null, params, null, SinaLocationMap.class);
}
use of android.telephony.gsm.GsmCellLocation in project android_frameworks_base by AOSPA.
the class GnssLocationProvider method requestRefLocation.
/**
* Called from native code to request reference location info
*/
private void requestRefLocation(int flags) {
TelephonyManager phone = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
final int phoneType = phone.getPhoneType();
if (phoneType == TelephonyManager.PHONE_TYPE_GSM) {
GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation();
if ((gsm_cell != null) && (phone.getNetworkOperator() != null) && (phone.getNetworkOperator().length() > 3)) {
int type;
int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3));
int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3));
int networkType = phone.getNetworkType();
if (networkType == TelephonyManager.NETWORK_TYPE_UMTS || networkType == TelephonyManager.NETWORK_TYPE_HSDPA || networkType == TelephonyManager.NETWORK_TYPE_HSUPA || networkType == TelephonyManager.NETWORK_TYPE_HSPA || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) {
type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
} else {
type = AGPS_REF_LOCATION_TYPE_GSM_CELLID;
}
native_agps_set_ref_location_cellid(type, mcc, mnc, gsm_cell.getLac(), gsm_cell.getCid());
} else {
Log.e(TAG, "Error getting cell location info.");
}
} else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
Log.e(TAG, "CDMA not supported.");
}
}
use of android.telephony.gsm.GsmCellLocation in project XobotOS by xamarin.
the class GsmSMSDispatcher method handleBroadcastSms.
/**
* Handle 3GPP format SMS-CB message.
* @param ar the AsyncResult containing the received PDUs
*/
private void handleBroadcastSms(AsyncResult ar) {
try {
byte[] receivedPdu = (byte[]) ar.result;
if (false) {
for (int i = 0; i < receivedPdu.length; i += 8) {
StringBuilder sb = new StringBuilder("SMS CB pdu data: ");
for (int j = i; j < i + 8 && j < receivedPdu.length; j++) {
int b = receivedPdu[j] & 0xff;
if (b < 0x10) {
sb.append('0');
}
sb.append(Integer.toHexString(b)).append(' ');
}
Log.d(TAG, sb.toString());
}
}
SmsCbHeader header = new SmsCbHeader(receivedPdu);
String plmn = SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC);
GsmCellLocation cellLocation = (GsmCellLocation) mPhone.getCellLocation();
int lac = cellLocation.getLac();
int cid = cellLocation.getCid();
byte[][] pdus;
if (header.nrOfPages > 1) {
// Multi-page message
SmsCbConcatInfo concatInfo = new SmsCbConcatInfo(header, plmn, lac, cid);
// Try to find other pages of the same message
pdus = mSmsCbPageMap.get(concatInfo);
if (pdus == null) {
// This it the first page of this message, make room for all
// pages and keep until complete
pdus = new byte[header.nrOfPages][];
mSmsCbPageMap.put(concatInfo, pdus);
}
// Page parameter is one-based
pdus[header.pageIndex - 1] = receivedPdu;
for (int i = 0; i < pdus.length; i++) {
if (pdus[i] == null) {
// Still missing pages, exit
return;
}
}
// Message complete, remove and dispatch
mSmsCbPageMap.remove(concatInfo);
} else {
// Single page message
pdus = new byte[1][];
pdus[0] = receivedPdu;
}
boolean isEmergencyMessage = SmsCbHeader.isEmergencyMessage(header.messageIdentifier);
dispatchBroadcastPdus(pdus, isEmergencyMessage);
// 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();
}
}
} catch (RuntimeException e) {
Log.e(TAG, "Error in decoding SMS CB pdu", e);
}
}
Aggregations