use of android.telephony.CellLocation in project satstat by mvglasow.
the class RadioSectionFragment method updateCellData.
/**
* Updates all cell data.
*
* This method is called whenever any change in the cell environment (cells in view or signal
* strengths) is signaled, e.g. by a call to a {@link android.telephony.PhoneStateListener}. The
* arguments of this method should be filled with the data passed to the
* {@link android.telephony.PhoneStateListener} where possible, and null passed for all others.
*
* To force an update of all cell data, simply call this method with each argument set to null.
*
* If any of the arguments is null, this method will try to obtain that data by querying
* {@link android.telephony.TelephonyManager}. The only exception is {@code signalStrength}, which
* will not be explicitly queried if missing.
*
* It will first process {@code aCellInfo}, then {@code aLocation}, querying current values from
* {@link android.telephony.TelephonyManager} if one of these arguments is null. Next it will process
* {@code signalStrength}, if supplied, and eventually obtain neighboring cells by calling
* {@link android.telephony.TelephonyManager#getNeighboringCellInfo()} and process these. Eventually
* it will refresh the list of cells.
*
* @param aLocation The {@link android.telephony.CellLocation} reported by a
* {@link android.telephony.PhoneStateListener}. If null, the current value will be queried.
* @param aSignalStrength The {@link android.telephony.SignalStrength} reported by a
* {@link android.telephony.PhoneStateListener}. If null, the signal strength of the serving cell
* will either be taken from {@code aCellInfo}, if available, or not be updated at all.
* @param aCellInfo A list of {@link android.telephony.CellInfo} instances reported by a
* {@link android.telephony.PhoneStateListener}. If null, the current value will be queried.
*/
@SuppressLint("NewApi")
public void updateCellData(CellLocation aLocation, SignalStrength signalStrength, List<CellInfo> aCellInfo) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
try {
/*
* CellInfo requires API 17+ and should in theory return all cells in view. In practice,
* some devices do not implement it or return only a partial list. On some devices,
* PhoneStateListener#onCellInfoChanged() will fire but always receive a null argument.
*/
List<CellInfo> cellInfo = (aCellInfo != null) ? aCellInfo : mainActivity.telephonyManager.getAllCellInfo();
mCellsGsm.updateAll(cellInfo);
mCellsCdma.updateAll(cellInfo);
mCellsLte.updateAll(cellInfo);
} catch (SecurityException e) {
// Permission not granted, can't retrieve cell data
Log.w(TAG, "Permission not granted, TelephonyManager#getAllCellInfo() failed");
}
}
try {
/*
* CellLocation should return the serving cell, unless it is LTE (in which case it should
* return null). In practice, however, some devices do return LTE cells. The approach of
* this method does not work well for devices with multiple radios.
*/
CellLocation location = (aLocation != null) ? aLocation : mainActivity.telephonyManager.getCellLocation();
String networkOperator = mainActivity.telephonyManager.getNetworkOperator();
mCellsGsm.removeSource(CellTower.SOURCE_CELL_LOCATION);
mCellsCdma.removeSource(CellTower.SOURCE_CELL_LOCATION);
mCellsLte.removeSource(CellTower.SOURCE_CELL_LOCATION);
if (location instanceof GsmCellLocation) {
if (mLastNetworkGen < 4) {
mServingCell = mCellsGsm.update(networkOperator, (GsmCellLocation) location);
if ((mServingCell.getDbm() == CellTower.DBM_UNKNOWN) && (mServingCell instanceof CellTowerGsm))
((CellTowerGsm) mServingCell).setAsu(mLastCellAsu);
} else {
mServingCell = mCellsLte.update(networkOperator, (GsmCellLocation) location);
if (mServingCell.getDbm() == CellTower.DBM_UNKNOWN)
((CellTowerLte) mServingCell).setAsu(mLastCellAsu);
}
} else if (location instanceof CdmaCellLocation) {
mServingCell = mCellsCdma.update((CdmaCellLocation) location);
if (mServingCell.getDbm() == CellTower.DBM_UNKNOWN)
((CellTowerCdma) mServingCell).setDbm(mLastCellDbm);
}
networkTimehandler.removeCallbacks(networkTimeRunnable);
} catch (SecurityException e) {
// Permission not granted, can't retrieve cell data
Log.w(TAG, "Permission not granted, cannot retrieve cell location");
}
if ((mServingCell == null) || (mServingCell.getGeneration() <= 0)) {
if ((mLastNetworkGen != 0) && (mServingCell != null))
mServingCell.setGeneration(mLastNetworkGen);
NetworkInfo netinfo = mainActivity.connectivityManager.getActiveNetworkInfo();
if ((netinfo == null) || (netinfo.getType() < ConnectivityManager.TYPE_MOBILE_MMS) || (netinfo.getType() > ConnectivityManager.TYPE_MOBILE_HIPRI)) {
networkTimehandler.postDelayed(networkTimeRunnable, NETWORK_REFRESH_DELAY);
}
} else if (mServingCell != null) {
mLastNetworkGen = mServingCell.getGeneration();
}
if ((signalStrength != null) && (mServingCell != null)) {
int pt = mainActivity.telephonyManager.getPhoneType();
if (pt == PHONE_TYPE_GSM) {
mLastCellAsu = signalStrength.getGsmSignalStrength();
updateNeighboringCellInfo();
if (mServingCell instanceof CellTowerGsm)
((CellTowerGsm) mServingCell).setAsu(mLastCellAsu);
else
Log.w(MainActivity.class.getSimpleName(), "Got SignalStrength for PHONE_TYPE_GSM but serving cell is not GSM");
} else if (pt == PHONE_TYPE_CDMA) {
mLastCellDbm = signalStrength.getCdmaDbm();
if ((mServingCell != null) && (mServingCell instanceof CellTowerCdma))
mServingCell.setDbm(mLastCellDbm);
else
Log.w(MainActivity.class.getSimpleName(), "Got SignalStrength for PHONE_TYPE_CDMA but serving cell is not CDMA");
} else
Log.w(MainActivity.class.getSimpleName(), String.format("Got SignalStrength for unknown phone type (%d)", pt));
} else if (mServingCell == null) {
Log.w(MainActivity.class.getSimpleName(), "Got SignalStrength but serving cell is null");
}
updateNeighboringCellInfo();
showCells();
}
use of android.telephony.CellLocation in project BaseProject by fly803.
the class AppSysMgr method getSysPhoneLoaction.
/**
* 获得手机方位
* @param context 上下文
* @return CellLocation 手机方位
*/
public static CellLocation getSysPhoneLoaction(Context context) {
CellLocation cellLocation = getSysTelephonyManager(context).getCellLocation();
AppLogMessageMgr.i("AppSysMgr-->>getSysPhoneLoaction", cellLocation + "");
return cellLocation;
}
use of android.telephony.CellLocation in project network-monitor by caarmen.
the class CellLocationDataSource method fillCellLocation.
private void fillCellLocation(ContentValues values) {
// noinspection deprecation We only use this deprecated call when the new APIs aren't available or don't work.
if (PermissionUtil.hasLocationPermission(mContext)) {
@SuppressLint("MissingPermission") CellLocation cellLocation = mTelephonyManager.getCellLocation();
if (cellLocation instanceof GsmCellLocation) {
GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
setGsmCellInfo(values, gsmCellLocation.getCid(), gsmCellLocation.getLac());
} else if (cellLocation instanceof CdmaCellLocation) {
CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
setCdmaCellInfo(values, cdmaCellLocation.getBaseStationId(), cdmaCellLocation.getBaseStationLatitude(), cdmaCellLocation.getBaseStationLongitude(), cdmaCellLocation.getNetworkId(), cdmaCellLocation.getSystemId());
}
}
}
use of android.telephony.CellLocation in project android_frameworks_opt_telephony by LineageOS.
the class GsmCdmaCallTracker method handleMessage.
// ****** Overridden from Handler
@Override
public void handleMessage(Message msg) {
AsyncResult ar;
switch(msg.what) {
case EVENT_POLL_CALLS_RESULT:
Rlog.d(LOG_TAG, "Event EVENT_POLL_CALLS_RESULT Received");
if (msg == mLastRelevantPoll) {
if (DBG_POLL)
log("handle EVENT_POLL_CALL_RESULT: set needsPoll=F");
mNeedsPoll = false;
mLastRelevantPoll = null;
handlePollCalls((AsyncResult) msg.obj);
}
break;
case EVENT_OPERATION_COMPLETE:
operationComplete();
break;
case EVENT_CONFERENCE_RESULT:
if (isPhoneTypeGsm()) {
// The conference merge failed, so notify listeners. Ultimately this bubbles up
// to Telecom, which will inform the InCall UI of the failure.
Connection connection = mForegroundCall.getLatestConnection();
if (connection != null) {
connection.onConferenceMergeFailed();
}
}
// fall through
case EVENT_SEPARATE_RESULT:
case EVENT_ECT_RESULT:
case EVENT_SWITCH_RESULT:
if (isPhoneTypeGsm()) {
ar = (AsyncResult) msg.obj;
if (ar.exception != null) {
mPhone.notifySuppServiceFailed(getFailedService(msg.what));
}
operationComplete();
} else {
if (msg.what != EVENT_SWITCH_RESULT) {
// to do. Other messages however are not expected in CDMA.
throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
}
}
break;
case EVENT_GET_LAST_CALL_FAIL_CAUSE:
int causeCode;
String vendorCause = null;
ar = (AsyncResult) msg.obj;
operationComplete();
if (ar.exception != null) {
// An exception occurred...just treat the disconnect
// cause as "normal"
causeCode = CallFailCause.NORMAL_CLEARING;
Rlog.i(LOG_TAG, "Exception during getLastCallFailCause, assuming normal disconnect");
} else {
LastCallFailCause failCause = (LastCallFailCause) ar.result;
causeCode = failCause.causeCode;
vendorCause = failCause.vendorCause;
}
// Log the causeCode if its not normal
if (causeCode == CallFailCause.NO_CIRCUIT_AVAIL || causeCode == CallFailCause.TEMPORARY_FAILURE || causeCode == CallFailCause.SWITCHING_CONGESTION || causeCode == CallFailCause.CHANNEL_NOT_AVAIL || causeCode == CallFailCause.QOS_NOT_AVAIL || causeCode == CallFailCause.BEARER_NOT_AVAIL || causeCode == CallFailCause.ERROR_UNSPECIFIED) {
CellLocation loc = mPhone.getCellLocation();
int cid = -1;
if (loc != null) {
if (isPhoneTypeGsm()) {
cid = ((GsmCellLocation) loc).getCid();
} else {
cid = ((CdmaCellLocation) loc).getBaseStationId();
}
}
EventLog.writeEvent(EventLogTags.CALL_DROP, causeCode, cid, TelephonyManager.getDefault().getNetworkType());
}
for (int i = 0, s = mDroppedDuringPoll.size(); i < s; i++) {
GsmCdmaConnection conn = mDroppedDuringPoll.get(i);
conn.onRemoteDisconnect(causeCode, vendorCause);
}
updatePhoneState();
mPhone.notifyPreciseCallStateChanged();
mMetrics.writeRilCallList(mPhone.getPhoneId(), mDroppedDuringPoll);
mDroppedDuringPoll.clear();
break;
case EVENT_REPOLL_AFTER_DELAY:
case EVENT_CALL_STATE_CHANGE:
pollCallsWhenSafe();
break;
case EVENT_RADIO_AVAILABLE:
handleRadioAvailable();
break;
case EVENT_RADIO_NOT_AVAILABLE:
handleRadioNotAvailable();
break;
case EVENT_EXIT_ECM_RESPONSE_CDMA:
if (!isPhoneTypeGsm()) {
// no matter the result, we still do the same here
if (mPendingCallInEcm) {
mCi.dial(mPendingMO.getAddress(), mPendingCallClirMode, obtainCompleteMessage());
mPendingCallInEcm = false;
}
mPhone.unsetOnEcbModeExitResponse(this);
} else {
throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
}
break;
case EVENT_CALL_WAITING_INFO_CDMA:
if (!isPhoneTypeGsm()) {
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
handleCallWaitingInfo((CdmaCallWaitingNotification) ar.result);
Rlog.d(LOG_TAG, "Event EVENT_CALL_WAITING_INFO_CDMA Received");
}
} else {
throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
}
break;
case EVENT_THREE_WAY_DIAL_L2_RESULT_CDMA:
if (!isPhoneTypeGsm()) {
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
// Assume 3 way call is connected
mPendingMO.onConnectedInOrOut();
mPendingMO = null;
}
} else {
throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
}
break;
case EVENT_THREE_WAY_DIAL_BLANK_FLASH:
if (!isPhoneTypeGsm()) {
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
postDelayed(new Runnable() {
public void run() {
if (mPendingMO != null) {
mCi.sendCDMAFeatureCode(mPendingMO.getAddress(), obtainMessage(EVENT_THREE_WAY_DIAL_L2_RESULT_CDMA));
}
}
}, m3WayCallFlashDelay);
} else {
mPendingMO = null;
Rlog.w(LOG_TAG, "exception happened on Blank Flash for 3-way call");
}
} else {
throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
}
break;
default:
{
throw new RuntimeException("unexpected event " + msg.what + " not handled by " + "phone type " + mPhone.getPhoneType());
}
}
}
use of android.telephony.CellLocation in project android_frameworks_opt_telephony by LineageOS.
the class DcTracker 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;
}
Aggregations