Search in sources :

Example 1 with GsmCellLocation

use of android.telephony.gsm.GsmCellLocation in project XPrivacy by M66B.

the class XTelephonyManager method getDefacedCellLocation.

private static CellLocation getDefacedCellLocation(int uid) {
    int cid = (Integer) PrivacyManager.getDefacedProp(uid, "CID");
    int lac = (Integer) PrivacyManager.getDefacedProp(uid, "LAC");
    if (cid > 0 && lac > 0) {
        GsmCellLocation cellLocation = new GsmCellLocation();
        cellLocation.setLacAndCid(lac, cid);
        return cellLocation;
    } else
        return CellLocation.getEmpty();
}
Also used : GsmCellLocation(android.telephony.gsm.GsmCellLocation)

Example 2 with GsmCellLocation

use of android.telephony.gsm.GsmCellLocation 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 3 with GsmCellLocation

use of android.telephony.gsm.GsmCellLocation in project platform_frameworks_base by android.

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.");
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) GsmCellLocation(android.telephony.gsm.GsmCellLocation)

Example 4 with GsmCellLocation

use of android.telephony.gsm.GsmCellLocation 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 5 with GsmCellLocation

use of android.telephony.gsm.GsmCellLocation in project XobotOS by xamarin.

the class GsmServiceStateTracker method handleMessage.

public void handleMessage(Message msg) {
    AsyncResult ar;
    int[] ints;
    String[] strings;
    Message message;
    switch(msg.what) {
        case EVENT_RADIO_AVAILABLE:
            //setPowerStateToDesired();
            break;
        case EVENT_SIM_READY:
            // powered on.
            if (mNeedToRegForSimLoaded) {
                phone.mIccRecords.registerForRecordsLoaded(this, EVENT_SIM_RECORDS_LOADED, null);
                mNeedToRegForSimLoaded = false;
            }
            boolean skipRestoringSelection = phone.getContext().getResources().getBoolean(com.android.internal.R.bool.skip_restoring_network_selection);
            if (!skipRestoringSelection) {
                // restore the previous network selection.
                phone.restoreSavedNetworkSelection(null);
            }
            pollState();
            // Signal strength polling stops when radio is off
            queueNextSignalStrengthPoll();
            break;
        case EVENT_RADIO_STATE_CHANGED:
            // This will do nothing in the radio not
            // available case
            setPowerStateToDesired();
            pollState();
            break;
        case EVENT_NETWORK_STATE_CHANGED:
            pollState();
            break;
        case EVENT_GET_SIGNAL_STRENGTH:
            if (!(cm.getRadioState().isOn()) || (cm.getRadioState().isCdma())) {
                // Polling will continue when radio turns back on and not CDMA
                return;
            }
            ar = (AsyncResult) msg.obj;
            onSignalStrengthResult(ar);
            queueNextSignalStrengthPoll();
            break;
        case EVENT_GET_LOC_DONE:
            ar = (AsyncResult) msg.obj;
            if (ar.exception == null) {
                String[] states = (String[]) ar.result;
                int lac = -1;
                int cid = -1;
                if (states.length >= 3) {
                    try {
                        if (states[1] != null && states[1].length() > 0) {
                            lac = Integer.parseInt(states[1], 16);
                        }
                        if (states[2] != null && states[2].length() > 0) {
                            cid = Integer.parseInt(states[2], 16);
                        }
                    } catch (NumberFormatException ex) {
                        Log.w(LOG_TAG, "error parsing location: " + ex);
                    }
                }
                cellLoc.setLacAndCid(lac, cid);
                phone.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:
        case EVENT_POLL_STATE_NETWORK_SELECTION_MODE:
            ar = (AsyncResult) msg.obj;
            handlePollStateResult(msg.what, ar);
            break;
        case EVENT_POLL_SIGNAL_STRENGTH:
            // Just poll signal strength...not part of pollState()
            cm.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
            dontPollSignalStrength = true;
            onSignalStrengthResult(ar);
            break;
        case EVENT_SIM_RECORDS_LOADED:
            updateSpnDisplay();
            break;
        case EVENT_LOCATION_UPDATES_ENABLED:
            ar = (AsyncResult) msg.obj;
            if (ar.exception == null) {
                cm.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);
            cm.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;
            cm.setPreferredNetworkType(toggledNetworkType, message);
            break;
        case EVENT_CHECK_REPORT_GPRS:
            if (ss != null && !isGprsConsistent(gprsState, ss.getState())) {
                // 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) phone.getCellLocation());
                EventLog.writeEvent(EventLogTags.DATA_NETWORK_REGISTRATION_FAIL, ss.getOperatorNumeric(), loc != null ? loc.getCid() : -1);
                mReportedGprsNoReg = true;
            }
            mStartedGprsRegCheck = false;
            break;
        case EVENT_RESTRICTED_STATE_CHANGED:
            if (DBG)
                log("EVENT_RESTRICTED_STATE_CHANGED");
            ar = (AsyncResult) msg.obj;
            onRestrictedStateChanged(ar);
            break;
        default:
            super.handleMessage(msg);
            break;
    }
}
Also used : Message(android.os.Message) GsmCellLocation(android.telephony.gsm.GsmCellLocation) AsyncResult(android.os.AsyncResult)

Aggregations

GsmCellLocation (android.telephony.gsm.GsmCellLocation)19 TelephonyManager (android.telephony.TelephonyManager)9 CdmaCellLocation (android.telephony.cdma.CdmaCellLocation)7 AsyncResult (android.os.AsyncResult)2 CellLocation (android.telephony.CellLocation)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 ScanResult (android.net.wifi.ScanResult)1 WifiManager (android.net.wifi.WifiManager)1 Message (android.os.Message)1 NeighboringCellInfo (android.telephony.NeighboringCellInfo)1 ServiceState (android.telephony.ServiceState)1 JSONObject (com.alibaba.fastjson.JSONObject)1 GsmConnection (com.android.internal.telephony.gsm.GsmConnection)1 CellInfo (edu.berkeley.cs.amplab.carat.thrift.CellInfo)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1