Search in sources :

Example 6 with GsmCellLocation

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

the class GsmCallTracker method handleMessage.

//****** Overridden from Handler
public void handleMessage(Message msg) {
    AsyncResult ar;
    switch(msg.what) {
        case EVENT_POLL_CALLS_RESULT:
            ar = (AsyncResult) msg.obj;
            if (msg == lastRelevantPoll) {
                if (DBG_POLL)
                    log("handle EVENT_POLL_CALL_RESULT: set needsPoll=F");
                needsPoll = false;
                lastRelevantPoll = null;
                handlePollCalls((AsyncResult) msg.obj);
            }
            break;
        case EVENT_OPERATION_COMPLETE:
            ar = (AsyncResult) msg.obj;
            operationComplete();
            break;
        case EVENT_SWITCH_RESULT:
        case EVENT_CONFERENCE_RESULT:
        case EVENT_SEPARATE_RESULT:
        case EVENT_ECT_RESULT:
            ar = (AsyncResult) msg.obj;
            if (ar.exception != null) {
                phone.notifySuppServiceFailed(getFailedService(msg.what));
            }
            operationComplete();
            break;
        case EVENT_GET_LAST_CALL_FAIL_CAUSE:
            int causeCode;
            ar = (AsyncResult) msg.obj;
            operationComplete();
            if (ar.exception != null) {
                // An exception occurred...just treat the disconnect
                // cause as "normal"
                causeCode = CallFailCause.NORMAL_CLEARING;
                Log.i(LOG_TAG, "Exception during getLastCallFailCause, assuming normal disconnect");
            } else {
                causeCode = ((int[]) ar.result)[0];
            }
            // 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) {
                GsmCellLocation loc = ((GsmCellLocation) phone.getCellLocation());
                EventLog.writeEvent(EventLogTags.CALL_DROP, causeCode, loc != null ? loc.getCid() : -1, TelephonyManager.getDefault().getNetworkType());
            }
            for (int i = 0, s = droppedDuringPoll.size(); i < s; i++) {
                GsmConnection conn = droppedDuringPoll.get(i);
                conn.onRemoteDisconnect(causeCode);
            }
            updatePhoneState();
            phone.notifyPreciseCallStateChanged();
            droppedDuringPoll.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;
    }
}
Also used : GsmConnection(com.android.internal.telephony.gsm.GsmConnection) GsmCellLocation(android.telephony.gsm.GsmCellLocation) AsyncResult(android.os.AsyncResult)

Example 7 with GsmCellLocation

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

Example 8 with GsmCellLocation

use of android.telephony.gsm.GsmCellLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class CellTracker method compareLac.

/**
     *          I removed the timer that activated this code and now the code will be run when
     *          the cell changes so it will detect faster rather than using a timer that might
     *          miss an imsi catcher, also says cpu rather than refreshing every x seconds.
     *
     *          original comments below from xLaMbChOpSx
     *
     *
     *  Description:    (From xLaMbChOpSx commit comment)
     *
     *      Initial implementation for detection method 1 to compare the CID & LAC with the Cell
     *      Information Table contents as an initial implementation for detection of a changed LAC,
     *      once OCID issues (API key use etc) have been finalised this detection method can be
     *      extended to include checking of external data.
     *
     *      REMOVED: refresh timer info
     *
     *      As I have no real way of testing this I require testing by other project members who
     *      do have access to equipment or an environment where a changing LAC can be simulated
     *      thus confirming the accuracy of this implementation.
     *
     *      Presently this will only invoke the MEDIUM threat level through the notification and
     *      does not fully implement the capturing and score based method as per the issue details
     *      once further testing is complete the alert and tracking of information can be refined.
     *
     *      See:
     *        https://github.com/xLaMbChOpSx/Android-IMSI-Catcher-Detector/commit/43ae77e2a0cad10dfd50f92da5a998f9ece95b38
     *        https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/issues/91#issuecomment-64391732
     *
     *  Short explanation:
     *
     *                  This is a polling mechanism for getting the LAC/CID and location
     *                  info for the currently connected cell.
     *
     *  Variables:
     *                  FIXED: now updates on cell change rather than a timer
     *                  There is a "timer" here (REFRESH_RATE), what exactly is it timing?
     *                  "Every REFRESH_RATE seconds, get connected cell details."
     *
     *  Issues:     [ ] We shouldn't do any detection here!
     *              [ ] We might wanna use a listener to do this?
     *                  Are there any reasons why not using a listener?
     *
     *  ChangeLog:
     *              2015-03-03  E:V:A           Changed getProp() to use TinyDB (SharedPreferences)
     *              2015-0x-xx  banjaxbanjo     Update: ??? (hey dude what did you do?)
     *
     */
public void compareLac(CellLocation location) {
    @Cleanup Realm realm = Realm.getDefaultInstance();
    switch(device.getPhoneId()) {
        case TelephonyManager.PHONE_TYPE_NONE:
        case TelephonyManager.PHONE_TYPE_SIP:
        case TelephonyManager.PHONE_TYPE_GSM:
            GsmCellLocation gsmCellLocation = (GsmCellLocation) location;
            if (gsmCellLocation != null) {
                monitorCell.setLocationAreaCode(gsmCellLocation.getLac());
                monitorCell.setCellId(gsmCellLocation.getCid());
                // Check if LAC is ok
                boolean lacOK = dbHelper.checkLAC(realm, monitorCell);
                if (!lacOK) {
                    changedLAC = true;
                    dbHelper.toEventLog(realm, 1, "Changing LAC");
                    // Detection Logs are made in checkLAC()
                    vibrate(100, Status.MEDIUM);
                } else {
                    changedLAC = false;
                }
                if (tinydb.getBoolean("ocid_downloaded")) {
                    if (!dbHelper.openCellExists(realm, monitorCell.getCellId())) {
                        dbHelper.toEventLog(realm, 2, "CID not in Import realm");
                        log.info("ALERT: Connected to unknown CID not in Import realm: " + monitorCell.getCellId());
                        vibrate(100, Status.MEDIUM);
                        cellIdNotInOpenDb = true;
                    } else {
                        cellIdNotInOpenDb = false;
                    }
                }
            }
            break;
        case TelephonyManager.PHONE_TYPE_CDMA:
            CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) location;
            if (cdmaCellLocation != null) {
                monitorCell.setLocationAreaCode(cdmaCellLocation.getNetworkId());
                monitorCell.setCellId(cdmaCellLocation.getBaseStationId());
                boolean lacOK = dbHelper.checkLAC(realm, monitorCell);
                if (!lacOK) {
                    changedLAC = true;
                    /*dbHelper.insertEventLog(
                                MiscUtils.getCurrentTimeStamp(),
                                monitorCell.getLAC(),
                                monitorCell.getCid(),
                                monitorCell.getPSC(),//This is giving weird values like 21478364... is this right?
                                String.valueOf(monitorCell.getLat()),
                                String.valueOf(monitorCell.getLon()),
                                (int)monitorCell.getAccuracy(),
                                1,
                                "Changing LAC"
                        );*/
                    dbHelper.toEventLog(realm, 1, "Changing LAC");
                } else {
                    changedLAC = false;
                }
            }
    }
    setNotification();
}
Also used : CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) Cleanup(lombok.Cleanup) Realm(io.realm.Realm)

Example 9 with GsmCellLocation

use of android.telephony.gsm.GsmCellLocation in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class Device method refreshDeviceInfo.

/**
     * Refreshes all device specific details
     */
public void refreshDeviceInfo(TelephonyManager tm, Context context) {
    //Phone type and associated details
    iMEI = tm.getDeviceId();
    iMEIv = tm.getDeviceSoftwareVersion();
    phoneId = tm.getPhoneType();
    roaming = tm.isNetworkRoaming();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        DeviceApi18.loadCellInfo(tm, this);
    }
    if (cell == null) {
        cell = new Cell();
    }
    switch(phoneId) {
        case TelephonyManager.PHONE_TYPE_NONE:
        case TelephonyManager.PHONE_TYPE_SIP:
        case TelephonyManager.PHONE_TYPE_GSM:
            phoneType = "GSM";
            mncMcc = tm.getNetworkOperator();
            if (mncMcc != null && mncMcc.length() >= 5) {
                try {
                    if (cell.getMobileCountryCode() == Integer.MAX_VALUE) {
                        cell.setMobileCountryCode(Integer.parseInt(tm.getNetworkOperator().substring(0, 3)));
                    }
                    if (cell.getMobileNetworkCode() == Integer.MAX_VALUE) {
                        cell.setMobileNetworkCode(Integer.parseInt(tm.getNetworkOperator().substring(3, 5)));
                    }
                } catch (Exception e) {
                    log.info("MncMcc parse exception: ", e);
                }
            }
            networkName = tm.getNetworkOperatorName();
            if (!cell.isValid()) {
                GsmCellLocation gsmCellLocation = (GsmCellLocation) tm.getCellLocation();
                if (gsmCellLocation != null) {
                    cell.setCellId(gsmCellLocation.getCid());
                    cell.setLocationAreaCode(gsmCellLocation.getLac());
                    cell.setPrimaryScramblingCode(gsmCellLocation.getPsc());
                }
            }
            break;
        case TelephonyManager.PHONE_TYPE_CDMA:
            phoneType = "CDMA";
            if (!cell.isValid()) {
                CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) tm.getCellLocation();
                if (cdmaCellLocation != null) {
                    cell.setCellId(cdmaCellLocation.getBaseStationId());
                    cell.setLocationAreaCode(cdmaCellLocation.getNetworkId());
                    // one of these must be a bug !!
                    cell.setSid(cdmaCellLocation.getSystemId());
                    // See: http://stackoverflow.com/questions/8088046/android-how-to-identify-carrier-on-cdma-network
                    // and: https://github.com/klinker41/android-smsmms/issues/26
                    // todo: check! (Also CellTracker.java)
                    cell.setMobileNetworkCode(cdmaCellLocation.getSystemId());
                    //Retrieve MCC through System Property
                    String homeOperator = Helpers.getSystemProp(context, "ro.cdma.home.operator.numeric", "UNKNOWN");
                    if (!homeOperator.contains("UNKNOWN")) {
                        try {
                            if (cell.getMobileCountryCode() == Integer.MAX_VALUE) {
                                cell.setMobileCountryCode(Integer.valueOf(homeOperator.substring(0, 3)));
                            }
                            if (cell.getMobileNetworkCode() == Integer.MAX_VALUE) {
                                cell.setMobileNetworkCode(Integer.valueOf(homeOperator.substring(3, 5)));
                            }
                        } catch (Exception e) {
                            log.info("HomeOperator parse exception - " + e.getMessage(), e);
                        }
                    }
                }
            }
            break;
    }
    // SIM Information
    simCountry = getSimCountry(tm);
    // Get the operator code of the active SIM (MCC + MNC)
    simOperator = getSimOperator(tm);
    simOperatorName = getSimOperatorName(tm);
    simSerial = getSimSerial(tm);
    simSubs = getSimSubs(tm);
    dataActivityType = getDataActivityType(tm);
    dataState = getDataState(tm);
}
Also used : CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation)

Example 10 with GsmCellLocation

use of android.telephony.gsm.GsmCellLocation in project android_frameworks_base by crdroidandroid.

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(), gsm_cell.getPsc());
        } 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)

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