Search in sources :

Example 1 with CdmaCellLocation

use of android.telephony.cdma.CdmaCellLocation in project FastDev4Android by jiangqqlmj.

the class StrUtils method getIpBaseStation.

// 获取ip基站
public static String getIpBaseStation() {
    TelephonyManager telMgr = (TelephonyManager) FDApplication.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
    int cid = 0;
    int lac = 0;
    try {
        if (telMgr != null) {
            GsmCellLocation gc = (GsmCellLocation) telMgr.getCellLocation();
            if (null == gc) {
                return "0_0";
            }
            cid = gc.getCid();
            lac = gc.getLac();
        }
    } catch (Exception e) {
        if (telMgr != null) {
            CdmaCellLocation location = (CdmaCellLocation) telMgr.getCellLocation();
            if (null == location) {
                return "0_0";
            }
            lac = location.getNetworkId();
            cid = location.getBaseStationId();
            cid /= 16;
        }
    }
    return lac + "_" + cid;
}
Also used : TelephonyManager(android.telephony.TelephonyManager) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) SuppressLint(android.annotation.SuppressLint) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with CdmaCellLocation

use of android.telephony.cdma.CdmaCellLocation in project carat by amplab.

the class SamplingLibrary method getCellInfo.

/* check the GSM cell information */
public static CellInfo getCellInfo(Context context) {
    CellInfo curCell = new CellInfo();
    TelephonyManager myTelManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String netOperator = myTelManager.getNetworkOperator();
    // etc)
    if (netOperator == null || netOperator.length() < 3) {
        return curCell;
    }
    if (SamplingLibrary.getPhoneType(context) == PHONE_TYPE_CDMA) {
        CdmaCellLocation cdmaLocation = (CdmaCellLocation) myTelManager.getCellLocation();
        if (cdmaLocation == null) {
        // Log.v("cdmaLocation", "CDMA Location:" + cdmaLocation);
        } else {
            int cid = cdmaLocation.getBaseStationId();
            int lac = cdmaLocation.getNetworkId();
            int mnc = cdmaLocation.getSystemId();
            int mcc = Integer.parseInt(netOperator.substring(0, 3));
            curCell.CID = cid;
            curCell.LAC = lac;
            curCell.MNC = mnc;
            curCell.MCC = mcc;
            curCell.radioType = SamplingLibrary.getMobileNetworkType(context);
        // Log.v("MCC", "MCC is:" + mcc);
        // Log.v("MNC", "MNC is:" + mnc);
        // Log.v("CID", "CID is:" + cid);
        // Log.v("LAC", "LAC is:" + lac);
        }
    } else if (SamplingLibrary.getPhoneType(context) == PHONE_TYPE_GSM) {
        GsmCellLocation gsmLocation = (GsmCellLocation) myTelManager.getCellLocation();
        if (gsmLocation == null) {
        // Log.v("gsmLocation", "GSM Location:" + gsmLocation);
        } else {
            int cid = gsmLocation.getCid();
            int lac = gsmLocation.getLac();
            int mcc = Integer.parseInt(netOperator.substring(0, 3));
            int mnc = Integer.parseInt(netOperator.substring(3));
            curCell.MCC = mcc;
            curCell.MNC = mnc;
            curCell.LAC = lac;
            curCell.CID = cid;
            curCell.radioType = SamplingLibrary.getMobileNetworkType(context);
        // Log.v("MCC", "MCC is:" + mcc);
        // Log.v("MNC", "MNC is:" + mnc);
        // Log.v("CID", "CID is:" + cid);
        // Log.v("LAC", "LAC is:" + lac);
        }
    }
    return curCell;
}
Also used : CellInfo(edu.berkeley.cs.amplab.carat.thrift.CellInfo) TelephonyManager(android.telephony.TelephonyManager) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation)

Example 3 with CdmaCellLocation

use of android.telephony.cdma.CdmaCellLocation in project XobotOS by xamarin.

the class CdmaDataConnectionTracker method onCdmaDataDetached.

private void onCdmaDataDetached() {
    if (mState == State.CONNECTED) {
        startNetStatPoll();
        notifyDataConnection(Phone.REASON_CDMA_DATA_DETACHED);
    } else {
        if (mState == State.FAILED) {
            cleanUpConnection(false, Phone.REASON_CDMA_DATA_DETACHED);
            mDataConnections.get(0).resetRetryCount();
            CdmaCellLocation loc = (CdmaCellLocation) (mPhone.getCellLocation());
            EventLog.writeEvent(EventLogTags.CDMA_DATA_SETUP_FAILED, loc != null ? loc.getBaseStationId() : -1, TelephonyManager.getDefault().getNetworkType());
        }
        trySetupData(Phone.REASON_CDMA_DATA_DETACHED);
    }
}
Also used : CdmaCellLocation(android.telephony.cdma.CdmaCellLocation)

Example 4 with CdmaCellLocation

use of android.telephony.cdma.CdmaCellLocation in project XobotOS by xamarin.

the class CdmaLteServiceStateTracker method pollStateDone.

@Override
protected void pollStateDone() {
    // determine data NetworkType from both LET and CDMA SS
    if (mLteSS.getState() == ServiceState.STATE_IN_SERVICE) {
        //in LTE service
        newNetworkType = mLteSS.getRadioTechnology();
        mNewDataConnectionState = mLteSS.getState();
        newSS.setRadioTechnology(newNetworkType);
        log("pollStateDone LTE/eHRPD STATE_IN_SERVICE newNetworkType = " + newNetworkType);
    } else {
        // LTE out of service, get CDMA Service State
        newNetworkType = newSS.getRadioTechnology();
        mNewDataConnectionState = radioTechnologyToDataServiceState(newNetworkType);
        log("pollStateDone CDMA STATE_IN_SERVICE newNetworkType = " + newNetworkType + " mNewDataConnectionState = " + mNewDataConnectionState);
    }
    // databases/settings.db "update secure set value='11' where name='preferred_network_mode'"
    if (newSS.getState() == ServiceState.STATE_OUT_OF_SERVICE) {
        int networkMode = android.provider.Settings.Secure.getInt(phone.getContext().getContentResolver(), android.provider.Settings.Secure.PREFERRED_NETWORK_MODE, RILConstants.PREFERRED_NETWORK_MODE);
        if (networkMode == RILConstants.NETWORK_MODE_LTE_ONLY) {
            if (DBG)
                log("pollState: LTE Only mode");
            newSS.setState(mLteSS.getState());
        }
    }
    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);
    boolean has4gHandoff = mNewDataConnectionState == ServiceState.STATE_IN_SERVICE && (((networkType == ServiceState.RADIO_TECHNOLOGY_LTE) && (newNetworkType == ServiceState.RADIO_TECHNOLOGY_EHRPD)) || ((networkType == ServiceState.RADIO_TECHNOLOGY_EHRPD) && (newNetworkType == ServiceState.RADIO_TECHNOLOGY_LTE)));
    boolean hasMultiApnSupport = (((newNetworkType == ServiceState.RADIO_TECHNOLOGY_LTE) || (newNetworkType == ServiceState.RADIO_TECHNOLOGY_EHRPD)) && ((networkType != ServiceState.RADIO_TECHNOLOGY_LTE) && (networkType != ServiceState.RADIO_TECHNOLOGY_EHRPD)));
    boolean hasLostMultiApnSupport = ((newNetworkType >= ServiceState.RADIO_TECHNOLOGY_IS95A) && (newNetworkType <= ServiceState.RADIO_TECHNOLOGY_EVDO_A));
    if (DBG) {
        log("pollStateDone:" + " hasRegistered=" + hasRegistered + " hasDeegistered=" + hasDeregistered + " hasCdmaDataConnectionAttached=" + hasCdmaDataConnectionAttached + " hasCdmaDataConnectionDetached=" + hasCdmaDataConnectionDetached + " hasCdmaDataConnectionChanged=" + hasCdmaDataConnectionChanged + " hasNetworkTypeChanged = " + hasNetworkTypeChanged + " hasChanged=" + hasChanged + " hasRoamingOn=" + hasRoamingOn + " hasRoamingOff=" + hasRoamingOff + " hasLocationChanged=" + hasLocationChanged + " has4gHandoff = " + has4gHandoff + " hasMultiApnSupport=" + hasMultiApnSupport + " hasLostMultiApnSupport=" + hasLostMultiApnSupport);
    }
    // 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();
    mLteSS.setStateOutOfService();
    if ((hasMultiApnSupport) && (phone.mDataConnectionTracker instanceof CdmaDataConnectionTracker)) {
        if (DBG)
            log("GsmDataConnectionTracker Created");
        phone.mDataConnectionTracker.dispose();
        phone.mDataConnectionTracker = new GsmDataConnectionTracker(mCdmaLtePhone);
    }
    if ((hasLostMultiApnSupport) && (phone.mDataConnectionTracker instanceof GsmDataConnectionTracker)) {
        if (DBG)
            log("GsmDataConnectionTracker disposed");
        phone.mDataConnectionTracker.dispose();
        phone.mDataConnectionTracker = new CdmaDataConnectionTracker(phone);
    }
    CdmaCellLocation tcl = cellLoc;
    cellLoc = newCellLoc;
    newCellLoc = tcl;
    mDataConnectionState = mNewDataConnectionState;
    networkType = newNetworkType;
    // 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 (phone.isEriFileLoaded()) {
            String eriText;
            // 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);
        }
        if (cm.getSimState().isSIMReady()) {
            // SIM is found on the device. If ERI roaming is OFF and SID/NID matches
            // one configfured in SIM, use operator name from CSIM record.
            boolean showSpn = ((CdmaLteUiccRecords) phone.mIccRecords).getCsimSpnDisplayCondition();
            int iconIndex = ss.getCdmaEriIconIndex();
            if (showSpn && (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) && isInHomeSidNid(ss.getSystemId(), ss.getNetworkId())) {
                ss.setOperatorAlphaLong(phone.mIccRecords.getServiceProviderName());
            }
        }
        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("countryCodeForMcc error" + ex);
            } catch (StringIndexOutOfBoundsException ex) {
                loge("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 || has4gHandoff) {
        mAttachedRegistrants.notifyRegistrants();
    }
    if (hasCdmaDataConnectionDetached) {
        mDetachedRegistrants.notifyRegistrants();
    }
    if ((hasCdmaDataConnectionChanged || hasNetworkTypeChanged)) {
        phone.notifyDataConnection(null);
    }
    if (hasRoamingOn) {
        mRoamingOnRegistrants.notifyRegistrants();
    }
    if (hasRoamingOff) {
        mRoamingOffRegistrants.notifyRegistrants();
    }
    if (hasLocationChanged) {
        phone.notifyLocationChanged();
    }
}
Also used : ServiceState(android.telephony.ServiceState) GsmDataConnectionTracker(com.android.internal.telephony.gsm.GsmDataConnectionTracker) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation)

Example 5 with CdmaCellLocation

use of android.telephony.cdma.CdmaCellLocation in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RadioInfo method updateLocation.

private final void updateLocation(CellLocation location) {
    Resources r = getResources();
    if (location instanceof GsmCellLocation) {
        GsmCellLocation loc = (GsmCellLocation) location;
        int lac = loc.getLac();
        int cid = loc.getCid();
        mLocation.setText(r.getString(R.string.radioInfo_lac) + " = " + ((lac == -1) ? "unknown" : Integer.toHexString(lac)) + "   " + r.getString(R.string.radioInfo_cid) + " = " + ((cid == -1) ? "unknown" : Integer.toHexString(cid)));
    } else if (location instanceof CdmaCellLocation) {
        CdmaCellLocation loc = (CdmaCellLocation) location;
        int bid = loc.getBaseStationId();
        int sid = loc.getSystemId();
        int nid = loc.getNetworkId();
        int lat = loc.getBaseStationLatitude();
        int lon = loc.getBaseStationLongitude();
        mLocation.setText("BID = " + ((bid == -1) ? "unknown" : Integer.toHexString(bid)) + "   " + "SID = " + ((sid == -1) ? "unknown" : Integer.toHexString(sid)) + "   " + "NID = " + ((nid == -1) ? "unknown" : Integer.toHexString(nid)) + "\n" + "LAT = " + ((lat == -1) ? "unknown" : Integer.toHexString(lat)) + "   " + "LONG = " + ((lon == -1) ? "unknown" : Integer.toHexString(lon)));
    } else {
        mLocation.setText("unknown");
    }
}
Also used : CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) Resources(android.content.res.Resources) GsmCellLocation(android.telephony.gsm.GsmCellLocation)

Aggregations

CdmaCellLocation (android.telephony.cdma.CdmaCellLocation)12 GsmCellLocation (android.telephony.gsm.GsmCellLocation)7 CellLocation (android.telephony.CellLocation)2 ServiceState (android.telephony.ServiceState)2 TelephonyManager (android.telephony.TelephonyManager)2 Realm (io.realm.Realm)2 Cleanup (lombok.Cleanup)2 SuppressLint (android.annotation.SuppressLint)1 SharedPreferences (android.content.SharedPreferences)1 Resources (android.content.res.Resources)1 GsmDataConnectionTracker (com.android.internal.telephony.gsm.GsmDataConnectionTracker)1 CellInfo (edu.berkeley.cs.amplab.carat.thrift.CellInfo)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1