use of android.telephony.CellInfo in project android_frameworks_opt_telephony by LineageOS.
the class RIL method convertHalCellInfoList.
static ArrayList<CellInfo> convertHalCellInfoList(ArrayList<android.hardware.radio.V1_0.CellInfo> records) {
ArrayList<CellInfo> response = new ArrayList<CellInfo>(records.size());
for (android.hardware.radio.V1_0.CellInfo record : records) {
// first convert RIL CellInfo to Parcel
Parcel p = Parcel.obtain();
p.writeInt(record.cellInfoType);
p.writeInt(record.registered ? 1 : 0);
p.writeInt(record.timeStampType);
p.writeLong(record.timeStamp);
switch(record.cellInfoType) {
case CellInfoType.GSM:
{
CellInfoGsm cellInfoGsm = record.gsm.get(0);
p.writeInt(Integer.parseInt(cellInfoGsm.cellIdentityGsm.mcc));
p.writeInt(Integer.parseInt(cellInfoGsm.cellIdentityGsm.mnc));
p.writeInt(cellInfoGsm.cellIdentityGsm.lac);
p.writeInt(cellInfoGsm.cellIdentityGsm.cid);
p.writeInt(cellInfoGsm.cellIdentityGsm.arfcn);
p.writeInt(Byte.toUnsignedInt(cellInfoGsm.cellIdentityGsm.bsic));
p.writeInt(cellInfoGsm.signalStrengthGsm.signalStrength);
p.writeInt(cellInfoGsm.signalStrengthGsm.bitErrorRate);
p.writeInt(cellInfoGsm.signalStrengthGsm.timingAdvance);
break;
}
case CellInfoType.CDMA:
{
CellInfoCdma cellInfoCdma = record.cdma.get(0);
p.writeInt(cellInfoCdma.cellIdentityCdma.networkId);
p.writeInt(cellInfoCdma.cellIdentityCdma.systemId);
p.writeInt(cellInfoCdma.cellIdentityCdma.baseStationId);
p.writeInt(cellInfoCdma.cellIdentityCdma.longitude);
p.writeInt(cellInfoCdma.cellIdentityCdma.latitude);
p.writeInt(cellInfoCdma.signalStrengthCdma.dbm);
p.writeInt(cellInfoCdma.signalStrengthCdma.ecio);
p.writeInt(cellInfoCdma.signalStrengthEvdo.dbm);
p.writeInt(cellInfoCdma.signalStrengthEvdo.ecio);
p.writeInt(cellInfoCdma.signalStrengthEvdo.signalNoiseRatio);
break;
}
case CellInfoType.LTE:
{
CellInfoLte cellInfoLte = record.lte.get(0);
p.writeInt(Integer.parseInt(cellInfoLte.cellIdentityLte.mcc));
p.writeInt(Integer.parseInt(cellInfoLte.cellIdentityLte.mnc));
p.writeInt(cellInfoLte.cellIdentityLte.ci);
p.writeInt(cellInfoLte.cellIdentityLte.pci);
p.writeInt(cellInfoLte.cellIdentityLte.tac);
p.writeInt(cellInfoLte.cellIdentityLte.earfcn);
p.writeInt(cellInfoLte.signalStrengthLte.signalStrength);
p.writeInt(cellInfoLte.signalStrengthLte.rsrp);
p.writeInt(cellInfoLte.signalStrengthLte.rsrq);
p.writeInt(cellInfoLte.signalStrengthLte.rssnr);
p.writeInt(cellInfoLte.signalStrengthLte.cqi);
p.writeInt(cellInfoLte.signalStrengthLte.timingAdvance);
break;
}
case CellInfoType.WCDMA:
{
CellInfoWcdma cellInfoWcdma = record.wcdma.get(0);
p.writeInt(Integer.parseInt(cellInfoWcdma.cellIdentityWcdma.mcc));
p.writeInt(Integer.parseInt(cellInfoWcdma.cellIdentityWcdma.mnc));
p.writeInt(cellInfoWcdma.cellIdentityWcdma.lac);
p.writeInt(cellInfoWcdma.cellIdentityWcdma.cid);
p.writeInt(cellInfoWcdma.cellIdentityWcdma.psc);
p.writeInt(cellInfoWcdma.cellIdentityWcdma.uarfcn);
p.writeInt(cellInfoWcdma.signalStrengthWcdma.signalStrength);
p.writeInt(cellInfoWcdma.signalStrengthWcdma.bitErrorRate);
break;
}
default:
throw new RuntimeException("unexpected cellinfotype: " + record.cellInfoType);
}
p.setDataPosition(0);
CellInfo InfoRec = CellInfo.CREATOR.createFromParcel(p);
p.recycle();
response.add(InfoRec);
}
return response;
}
use of android.telephony.CellInfo in project android_frameworks_opt_telephony by LineageOS.
the class RadioIndication method responseCellInfos.
private void responseCellInfos(int indicationType, android.hardware.radio.V1_1.NetworkScanResult result) {
mRil.processIndication(indicationType);
NetworkScanResult nsr = null;
ArrayList<CellInfo> infos = RIL.convertHalCellInfoList(result.networkInfos);
nsr = new NetworkScanResult(result.status, result.error, infos);
if (RIL.RILJ_LOGD)
mRil.unsljLogRet(RIL_UNSOL_NETWORK_SCAN_RESULT, nsr);
mRil.mRilNetworkScanResultRegistrants.notifyRegistrants(new AsyncResult(null, nsr, null));
}
use of android.telephony.CellInfo in project android_frameworks_opt_telephony by LineageOS.
the class RadioIndication method cellInfoList.
public void cellInfoList(int indicationType, ArrayList<android.hardware.radio.V1_0.CellInfo> records) {
mRil.processIndication(indicationType);
ArrayList<CellInfo> response = RIL.convertHalCellInfoList(records);
if (RIL.RILJ_LOGD)
mRil.unsljLogRet(RIL_UNSOL_CELL_INFO_LIST, response);
mRil.mRilCellInfoListRegistrants.notifyRegistrants(new AsyncResult(null, response, null));
}
use of android.telephony.CellInfo in project android_frameworks_opt_telephony by LineageOS.
the class ServiceStateTracker method handleMessage.
@Override
public void handleMessage(Message msg) {
AsyncResult ar;
int[] ints;
Message message;
if (VDBG)
log("received event " + msg.what);
switch(msg.what) {
case EVENT_SET_RADIO_POWER_OFF:
synchronized (this) {
if (mPendingRadioPowerOffAfterDataOff && (msg.arg1 == mPendingRadioPowerOffAfterDataOffTag)) {
if (DBG)
log("EVENT_SET_RADIO_OFF, turn radio off now.");
hangupAndPowerOff();
mPendingRadioPowerOffAfterDataOffTag += 1;
mPendingRadioPowerOffAfterDataOff = false;
} else {
log("EVENT_SET_RADIO_OFF is stale arg1=" + msg.arg1 + "!= tag=" + mPendingRadioPowerOffAfterDataOffTag);
}
}
break;
case EVENT_ICC_CHANGED:
onUpdateIccAvailability();
break;
case EVENT_GET_CELL_INFO_LIST:
{
ar = (AsyncResult) msg.obj;
CellInfoResult result = (CellInfoResult) ar.userObj;
synchronized (result.lockObj) {
if (ar.exception != null) {
log("EVENT_GET_CELL_INFO_LIST: error ret null, e=" + ar.exception);
result.list = null;
} else {
result.list = (List<CellInfo>) ar.result;
if (VDBG) {
log("EVENT_GET_CELL_INFO_LIST: size=" + result.list.size() + " list=" + result.list);
}
}
mLastCellInfoListTime = SystemClock.elapsedRealtime();
mLastCellInfoList = result.list;
result.lockObj.notify();
}
break;
}
case EVENT_UNSOL_CELL_INFO_LIST:
{
ar = (AsyncResult) msg.obj;
if (ar.exception != null) {
log("EVENT_UNSOL_CELL_INFO_LIST: error ignoring, e=" + ar.exception);
} else {
List<CellInfo> list = (List<CellInfo>) ar.result;
if (VDBG) {
log("EVENT_UNSOL_CELL_INFO_LIST: size=" + list.size() + " list=" + list);
}
mLastCellInfoListTime = SystemClock.elapsedRealtime();
mLastCellInfoList = list;
mPhone.notifyCellInfo(list);
}
break;
}
case // received unsol
EVENT_IMS_STATE_CHANGED:
mCi.getImsRegistrationState(this.obtainMessage(EVENT_IMS_STATE_DONE));
break;
case EVENT_IMS_STATE_DONE:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
int[] responseArray = (int[]) ar.result;
mImsRegistered = (responseArray[0] == 1) ? true : false;
}
break;
// GSM
case EVENT_SIM_READY:
// Reset the mPreviousSubId so we treat a SIM power bounce
// as a first boot. See b/19194287
mOnSubscriptionsChangedListener.mPreviousSubId.set(-1);
pollState();
// Signal strength polling stops when radio is off
queueNextSignalStrengthPoll();
break;
case EVENT_RADIO_STATE_CHANGED:
case EVENT_PHONE_TYPE_SWITCHED:
if (!mPhone.isPhoneTypeGsm() && mCi.getRadioState() == CommandsInterface.RadioState.RADIO_ON) {
handleCdmaSubscriptionSource(mCdmaSSM.getCdmaSubscriptionSource());
// Signal strength polling stops when radio is off.
queueNextSignalStrengthPoll();
}
// This will do nothing in the 'radio not available' case
setPowerStateToDesired();
// These events are modem triggered, so pollState() needs to be forced
modemTriggeredPollState();
break;
case EVENT_NETWORK_STATE_CHANGED:
modemTriggeredPollState();
break;
case EVENT_GET_SIGNAL_STRENGTH:
if (!(mCi.getRadioState().isOn())) {
// Polling will continue when radio turns back on
return;
}
ar = (AsyncResult) msg.obj;
onSignalStrengthResult(ar);
queueNextSignalStrengthPoll();
break;
case EVENT_GET_LOC_DONE:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
processCellLocationInfo(mCellLoc, (VoiceRegStateResult) ar.result);
mPhone.notifyLocationChanged();
}
// Release any temporary cell lock, which could have been
// acquired to allow a single-shot location update.
disableSingleLocationUpdate();
break;
case EVENT_POLL_STATE_REGISTRATION:
case EVENT_POLL_STATE_GPRS:
case EVENT_POLL_STATE_OPERATOR:
ar = (AsyncResult) msg.obj;
handlePollStateResult(msg.what, ar);
break;
case EVENT_POLL_STATE_NETWORK_SELECTION_MODE:
if (DBG)
log("EVENT_POLL_STATE_NETWORK_SELECTION_MODE");
ar = (AsyncResult) msg.obj;
if (mPhone.isPhoneTypeGsm()) {
handlePollStateResult(msg.what, ar);
} else {
if (ar.exception == null && ar.result != null) {
ints = (int[]) ar.result;
if (ints[0] == 1) {
// Manual selection.
mPhone.setNetworkSelectionModeAutomatic(null);
}
} else {
log("Unable to getNetworkSelectionMode");
}
}
break;
case EVENT_POLL_SIGNAL_STRENGTH:
// Just poll signal strength...not part of pollState()
mCi.getSignalStrength(obtainMessage(EVENT_GET_SIGNAL_STRENGTH));
break;
case EVENT_NITZ_TIME:
ar = (AsyncResult) msg.obj;
String nitzString = (String) ((Object[]) ar.result)[0];
long nitzReceiveTime = ((Long) ((Object[]) ar.result)[1]).longValue();
setTimeFromNITZString(nitzString, nitzReceiveTime);
break;
case EVENT_SIGNAL_STRENGTH_UPDATE:
// This is a notification from CommandsInterface.setOnSignalStrengthUpdate
ar = (AsyncResult) msg.obj;
// The radio is telling us about signal strength changes
// we don't have to ask it
mDontPollSignalStrength = true;
onSignalStrengthResult(ar);
break;
case EVENT_SIM_RECORDS_LOADED:
log("EVENT_SIM_RECORDS_LOADED: what=" + msg.what);
updatePhoneObject();
updateOtaspState();
if (mPhone.isPhoneTypeGsm()) {
updateSpnDisplay();
}
break;
case EVENT_LOCATION_UPDATES_ENABLED:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
mCi.getVoiceRegistrationState(obtainMessage(EVENT_GET_LOC_DONE, null));
}
break;
case EVENT_SET_PREFERRED_NETWORK_TYPE:
ar = (AsyncResult) msg.obj;
// Don't care the result, only use for dereg network (COPS=2)
message = obtainMessage(EVENT_RESET_PREFERRED_NETWORK_TYPE, ar.userObj);
mCi.setPreferredNetworkType(mPreferredNetworkType, message);
break;
case EVENT_RESET_PREFERRED_NETWORK_TYPE:
ar = (AsyncResult) msg.obj;
if (ar.userObj != null) {
AsyncResult.forMessage(((Message) ar.userObj)).exception = ar.exception;
((Message) ar.userObj).sendToTarget();
}
break;
case EVENT_GET_PREFERRED_NETWORK_TYPE:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
mPreferredNetworkType = ((int[]) ar.result)[0];
} else {
mPreferredNetworkType = RILConstants.NETWORK_MODE_GLOBAL;
}
message = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE, ar.userObj);
int toggledNetworkType = RILConstants.NETWORK_MODE_GLOBAL;
mCi.setPreferredNetworkType(toggledNetworkType, message);
break;
case EVENT_CHECK_REPORT_GPRS:
if (mPhone.isPhoneTypeGsm() && mSS != null && !isGprsConsistent(mSS.getDataRegState(), mSS.getVoiceRegState())) {
// Can't register data service while voice service is ok
// i.e. CREG is ok while CGREG is not
// possible a network or baseband side error
GsmCellLocation loc = ((GsmCellLocation) mPhone.getCellLocation());
EventLog.writeEvent(EventLogTags.DATA_NETWORK_REGISTRATION_FAIL, mSS.getOperatorNumeric(), loc != null ? loc.getCid() : -1);
mReportedGprsNoReg = true;
}
mStartedGprsRegCheck = false;
break;
case EVENT_RESTRICTED_STATE_CHANGED:
if (mPhone.isPhoneTypeGsm()) {
if (DBG)
log("EVENT_RESTRICTED_STATE_CHANGED");
ar = (AsyncResult) msg.obj;
onRestrictedStateChanged(ar);
}
break;
case EVENT_SIM_NOT_INSERTED:
if (DBG)
log("EVENT_SIM_NOT_INSERTED");
cancelAllNotifications();
mMdn = null;
mMin = null;
mIsMinInfoReady = false;
break;
case EVENT_ALL_DATA_DISCONNECTED:
int dds = SubscriptionManager.getDefaultDataSubscriptionId();
ProxyController.getInstance().unregisterForAllDataDisconnected(dds, this);
synchronized (this) {
if (mPendingRadioPowerOffAfterDataOff) {
if (DBG)
log("EVENT_ALL_DATA_DISCONNECTED, turn radio off now.");
hangupAndPowerOff();
mPendingRadioPowerOffAfterDataOff = false;
} else {
log("EVENT_ALL_DATA_DISCONNECTED is stale");
}
}
break;
case EVENT_CHANGE_IMS_STATE:
if (DBG)
log("EVENT_CHANGE_IMS_STATE:");
setPowerStateToDesired();
break;
case EVENT_IMS_CAPABILITY_CHANGED:
if (DBG)
log("EVENT_IMS_CAPABILITY_CHANGED");
updateSpnDisplay();
break;
// CDMA
case EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
handleCdmaSubscriptionSource(mCdmaSSM.getCdmaSubscriptionSource());
break;
case EVENT_RUIM_READY:
if (mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE) {
// Subscription will be read from SIM I/O
if (DBG)
log("Receive EVENT_RUIM_READY");
pollState();
} else {
if (DBG)
log("Receive EVENT_RUIM_READY and Send Request getCDMASubscription.");
getSubscriptionInfoAndStartPollingThreads();
}
// Only support automatic selection mode in CDMA.
mCi.getNetworkSelectionMode(obtainMessage(EVENT_POLL_STATE_NETWORK_SELECTION_MODE));
break;
case EVENT_NV_READY:
updatePhoneObject();
// Only support automatic selection mode in CDMA.
mCi.getNetworkSelectionMode(obtainMessage(EVENT_POLL_STATE_NETWORK_SELECTION_MODE));
// For Non-RUIM phones, the subscription information is stored in
// Non Volatile. Here when Non-Volatile is ready, we can poll the CDMA
// subscription info.
getSubscriptionInfoAndStartPollingThreads();
break;
case // Handle RIL_CDMA_SUBSCRIPTION
EVENT_POLL_STATE_CDMA_SUBSCRIPTION:
if (!mPhone.isPhoneTypeGsm()) {
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
String[] cdmaSubscription = (String[]) ar.result;
if (cdmaSubscription != null && cdmaSubscription.length >= 5) {
mMdn = cdmaSubscription[0];
parseSidNid(cdmaSubscription[1], cdmaSubscription[2]);
mMin = cdmaSubscription[3];
mPrlVersion = cdmaSubscription[4];
if (DBG)
log("GET_CDMA_SUBSCRIPTION: MDN=" + mMdn);
mIsMinInfoReady = true;
updateOtaspState();
// Notify apps subscription info is ready
notifyCdmaSubscriptionInfoReady();
if (!mIsSubscriptionFromRuim && mIccRecords != null) {
if (DBG) {
log("GET_CDMA_SUBSCRIPTION set imsi in mIccRecords");
}
mIccRecords.setImsi(getImsi());
} else {
if (DBG) {
log("GET_CDMA_SUBSCRIPTION either mIccRecords is null or NV " + "type device - not setting Imsi in mIccRecords");
}
}
} else {
if (DBG) {
log("GET_CDMA_SUBSCRIPTION: error parsing cdmaSubscription " + "params num=" + cdmaSubscription.length);
}
}
}
}
break;
case EVENT_RUIM_RECORDS_LOADED:
if (!mPhone.isPhoneTypeGsm()) {
log("EVENT_RUIM_RECORDS_LOADED: what=" + msg.what);
updatePhoneObject();
if (mPhone.isPhoneTypeCdma()) {
updateSpnDisplay();
} else {
RuimRecords ruim = (RuimRecords) mIccRecords;
if (ruim != null) {
if (ruim.isProvisioned()) {
mMdn = ruim.getMdn();
mMin = ruim.getMin();
parseSidNid(ruim.getSid(), ruim.getNid());
mPrlVersion = ruim.getPrlVersion();
mIsMinInfoReady = true;
}
updateOtaspState();
// Notify apps subscription info is ready
notifyCdmaSubscriptionInfoReady();
}
// SID/NID/PRL is loaded. Poll service state
// again to update to the roaming state with
// the latest variables.
pollState();
}
}
break;
case EVENT_ERI_FILE_LOADED:
// Repoll the state once the ERI file has been loaded.
if (DBG)
log("ERI file has been loaded, repolling.");
pollState();
break;
case EVENT_OTA_PROVISION_STATUS_CHANGE:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
ints = (int[]) ar.result;
int otaStatus = ints[0];
if (otaStatus == Phone.CDMA_OTA_PROVISION_STATUS_COMMITTED || otaStatus == Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_STOPPED) {
if (DBG)
log("EVENT_OTA_PROVISION_STATUS_CHANGE: Complete, Reload MDN");
mCi.getCDMASubscription(obtainMessage(EVENT_POLL_STATE_CDMA_SUBSCRIPTION));
}
}
break;
case EVENT_CDMA_PRL_VERSION_CHANGED:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
ints = (int[]) ar.result;
mPrlVersion = Integer.toString(ints[0]);
}
break;
case EVENT_RADIO_POWER_FROM_CARRIER:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
boolean enable = (boolean) ar.result;
if (DBG)
log("EVENT_RADIO_POWER_FROM_CARRIER: " + enable);
setRadioPowerFromCarrier(enable);
}
break;
default:
log("Unhandled message with number: " + msg.what);
break;
}
}
use of android.telephony.CellInfo in project android_frameworks_opt_telephony by LineageOS.
the class ServiceStateTracker method getCellLocation.
/**
* @param workSource calling WorkSource
* @return the current cell location information. Prefer Gsm location
* information if available otherwise return LTE location information
*/
public CellLocation getCellLocation(WorkSource workSource) {
if (((GsmCellLocation) mCellLoc).getLac() >= 0 && ((GsmCellLocation) mCellLoc).getCid() >= 0) {
if (VDBG)
log("getCellLocation(): X good mCellLoc=" + mCellLoc);
return mCellLoc;
} else {
List<CellInfo> result = getAllCellInfo(workSource);
if (result != null) {
// A hack to allow tunneling of LTE information via GsmCellLocation
// so that older Network Location Providers can return some information
// on LTE only networks, see bug 9228974.
//
// We'll search the return CellInfo array preferring GSM/WCDMA
// data, but if there is none we'll tunnel the first LTE information
// in the list.
//
// The tunnel'd LTE information is returned as follows:
// LAC = TAC field
// CID = CI field
// PSC = 0.
GsmCellLocation cellLocOther = new GsmCellLocation();
for (CellInfo ci : result) {
if (ci instanceof CellInfoGsm) {
CellInfoGsm cellInfoGsm = (CellInfoGsm) ci;
CellIdentityGsm cellIdentityGsm = cellInfoGsm.getCellIdentity();
cellLocOther.setLacAndCid(cellIdentityGsm.getLac(), cellIdentityGsm.getCid());
cellLocOther.setPsc(cellIdentityGsm.getPsc());
if (VDBG)
log("getCellLocation(): X ret GSM info=" + cellLocOther);
return cellLocOther;
} else if (ci instanceof CellInfoWcdma) {
CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) ci;
CellIdentityWcdma cellIdentityWcdma = cellInfoWcdma.getCellIdentity();
cellLocOther.setLacAndCid(cellIdentityWcdma.getLac(), cellIdentityWcdma.getCid());
cellLocOther.setPsc(cellIdentityWcdma.getPsc());
if (VDBG)
log("getCellLocation(): X ret WCDMA info=" + cellLocOther);
return cellLocOther;
} else if ((ci instanceof CellInfoLte) && ((cellLocOther.getLac() < 0) || (cellLocOther.getCid() < 0))) {
// We'll return the first good LTE info we get if there is no better answer
CellInfoLte cellInfoLte = (CellInfoLte) ci;
CellIdentityLte cellIdentityLte = cellInfoLte.getCellIdentity();
if ((cellIdentityLte.getTac() != Integer.MAX_VALUE) && (cellIdentityLte.getCi() != Integer.MAX_VALUE)) {
cellLocOther.setLacAndCid(cellIdentityLte.getTac(), cellIdentityLte.getCi());
cellLocOther.setPsc(0);
if (VDBG) {
log("getCellLocation(): possible LTE cellLocOther=" + cellLocOther);
}
}
}
}
if (VDBG) {
log("getCellLocation(): X ret best answer cellLocOther=" + cellLocOther);
}
return cellLocOther;
} else {
if (VDBG) {
log("getCellLocation(): X empty mCellLoc and CellInfo mCellLoc=" + mCellLoc);
}
return mCellLoc;
}
}
}
Aggregations