Search in sources :

Example 11 with CellLocation

use of android.telephony.CellLocation in project XobotOS by xamarin.

the class GsmDataConnectionTracker 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;
}
Also used : CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation)

Example 12 with CellLocation

use of android.telephony.CellLocation in project PhoneProfilesPlus by henrichg.

the class PhoneStateScanner method getCellLocation.

@SuppressLint("MissingPermission")
private void getCellLocation() {
    if (telephonyManager != null) {
        CellLocation location = null;
        if (Permissions.checkLocation(context.getApplicationContext()))
            location = telephonyManager.getCellLocation();
        getCellLocation(location);
    }
}
Also used : GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) CdmaCellLocation(android.telephony.cdma.CdmaCellLocation) SuppressLint(android.annotation.SuppressLint)

Example 13 with CellLocation

use of android.telephony.CellLocation in project android_frameworks_opt_telephony by LineageOS.

the class GsmCellBroadcastHandler method handleGsmBroadcastSms.

/**
 * Handle 3GPP format SMS-CB message.
 * @param ar the AsyncResult containing the received PDUs
 */
private SmsCbMessage handleGsmBroadcastSms(AsyncResult ar) {
    try {
        byte[] receivedPdu = (byte[]) ar.result;
        if (VDBG) {
            int pduLength = receivedPdu.length;
            for (int i = 0; i < pduLength; i += 8) {
                StringBuilder sb = new StringBuilder("SMS CB pdu data: ");
                for (int j = i; j < i + 8 && j < pduLength; j++) {
                    int b = receivedPdu[j] & 0xff;
                    if (b < 0x10) {
                        sb.append('0');
                    }
                    sb.append(Integer.toHexString(b)).append(' ');
                }
                log(sb.toString());
            }
        }
        SmsCbHeader header = new SmsCbHeader(receivedPdu);
        String plmn = TelephonyManager.from(mContext).getNetworkOperatorForPhone(mPhone.getPhoneId());
        int lac = -1;
        int cid = -1;
        CellLocation cl = mPhone.getCellLocation();
        // both 3GPP and 3GPP2 format messages
        if (cl instanceof GsmCellLocation) {
            GsmCellLocation cellLocation = (GsmCellLocation) cl;
            lac = cellLocation.getLac();
            cid = cellLocation.getCid();
        }
        SmsCbLocation location;
        switch(header.getGeographicalScope()) {
            case SmsCbMessage.GEOGRAPHICAL_SCOPE_LA_WIDE:
                location = new SmsCbLocation(plmn, lac, -1);
                break;
            case SmsCbMessage.GEOGRAPHICAL_SCOPE_CELL_WIDE:
            case SmsCbMessage.GEOGRAPHICAL_SCOPE_CELL_WIDE_IMMEDIATE:
                location = new SmsCbLocation(plmn, lac, cid);
                break;
            case SmsCbMessage.GEOGRAPHICAL_SCOPE_PLMN_WIDE:
            default:
                location = new SmsCbLocation(plmn);
                break;
        }
        byte[][] pdus;
        int pageCount = header.getNumberOfPages();
        if (pageCount > 1) {
            // Multi-page message
            SmsCbConcatInfo concatInfo = new SmsCbConcatInfo(header, location);
            // Try to find other pages of the same message
            pdus = mSmsCbPageMap.get(concatInfo);
            if (pdus == null) {
                // This is the first page of this message, make room for all
                // pages and keep until complete
                pdus = new byte[pageCount][];
                mSmsCbPageMap.put(concatInfo, pdus);
            }
            // Page parameter is one-based
            pdus[header.getPageIndex() - 1] = receivedPdu;
            for (byte[] pdu : pdus) {
                if (pdu == null) {
                    // Still missing pages, exit
                    return null;
                }
            }
            // Message complete, remove and dispatch
            mSmsCbPageMap.remove(concatInfo);
        } else {
            // Single page message
            pdus = new byte[1][];
            pdus[0] = receivedPdu;
        }
        // Remove messages that are out of scope to prevent the map from
        // growing indefinitely, containing incomplete messages that were
        // never assembled
        Iterator<SmsCbConcatInfo> iter = mSmsCbPageMap.keySet().iterator();
        while (iter.hasNext()) {
            SmsCbConcatInfo info = iter.next();
            if (!info.matchesLocation(plmn, lac, cid)) {
                iter.remove();
            }
        }
        return GsmSmsCbMessage.createSmsCbMessage(mContext, header, location, pdus);
    } catch (RuntimeException e) {
        loge("Error in decoding SMS CB pdu", e);
        return null;
    }
}
Also used : SmsCbLocation(android.telephony.SmsCbLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation)

Example 14 with CellLocation

use of android.telephony.CellLocation in project DataLogger by sussexwearlab.

the class Depr_CellsInfoDataCollector method getCellInfoString.

private String getCellInfoString(SignalStrength signalStrength) {
    // Timestamp in system nanoseconds since boot, including time spent in sleep.
    long nanoTime = SystemClock.elapsedRealtimeNanos() + mNanosOffset;
    // System local time in millis
    long currentMillis = (new Date()).getTime();
    String message = String.format("%s", currentMillis) + ";" + String.format("%s", nanoTime) + ";" + String.format("%s", mNanosOffset) + ";";
    CellLocation cell = mTelephonyManager.getCellLocation();
    if (cell instanceof GsmCellLocation) {
        int lac, cid, dbm;
        lac = ((GsmCellLocation) cell).getLac();
        cid = ((GsmCellLocation) cell).getCid();
        String generalNetworkType = networkTypeGeneral(mTelephonyManager.getNetworkType());
        // "SignalStrength: mGsmSignalStrength mGsmBitErrorRate mCdmaDbm mCdmaEcio mEvdoDbm
        // mEvdoEcio mEvdoSnr mLteSignalStrength mLteRsrp mLteRsrq mLteRssnr mLteCqi
        // (isGsm ? "gsm|lte" : "cdma"));
        String ssignal = signalStrength.toString();
        String[] parts = ssignal.split(" ");
        // Fallbacks will be triggered whenever generalNetworkType changes
        if (generalNetworkType.equals("4G")) {
            dbm = Integer.parseInt(parts[11]);
            if (dbm >= -2) {
                if (Integer.parseInt(parts[3]) < -2) {
                    dbm = Integer.parseInt(parts[3]);
                } else {
                    dbm = signalStrength.getGsmSignalStrength();
                }
            }
        } else if (generalNetworkType.equals("3G")) {
            dbm = Integer.parseInt(parts[3]);
            if (dbm >= -2) {
                if (Integer.parseInt(parts[11]) < -2) {
                    dbm = Integer.parseInt(parts[11]);
                } else {
                    dbm = signalStrength.getGsmSignalStrength();
                }
            }
        } else {
            dbm = signalStrength.getGsmSignalStrength();
            if (dbm >= -2) {
                if (Integer.parseInt(parts[3]) < -2) {
                    dbm = Integer.parseInt(parts[3]);
                } else {
                    dbm = Integer.parseInt(parts[11]);
                }
            }
        }
        // Returns the numeric name (MCC+MNC) of current registered operator.
        String mccMnc = mTelephonyManager.getNetworkOperator();
        String mcc, mnc;
        if (mccMnc != null && mccMnc.length() >= 4) {
            mcc = mccMnc.substring(0, 3);
            mnc = mccMnc.substring(3);
        } else {
            mcc = "NaN";
            mnc = "NaN";
        }
        if (dbm < -2) {
            message += mTelephonyManager.getNetworkType() + ";" + cid + ";" + lac + ";" + dbm + ";" + mcc + ";" + mnc;
        } else {
            message += mTelephonyManager.getNetworkType() + ";" + cid + ";" + lac + ";" + "NaN" + ";" + mcc + ";" + mnc;
        }
    }
    return message;
}
Also used : GsmCellLocation(android.telephony.gsm.GsmCellLocation) CellLocation(android.telephony.CellLocation) GsmCellLocation(android.telephony.gsm.GsmCellLocation) Date(java.util.Date)

Example 15 with CellLocation

use of android.telephony.CellLocation in project assertj-android by square.

the class TelephonyManagerAssert method hasCellLocation.

public TelephonyManagerAssert hasCellLocation(CellLocation cellLocation) {
    isNotNull();
    CellLocation actualCellLocation = actual.getCellLocation();
    // 
    assertThat(actualCellLocation).overridingErrorMessage("Expected cell location <%s> but was <%s>.", cellLocation, // 
    actualCellLocation).isEqualTo(cellLocation);
    return this;
}
Also used : CellLocation(android.telephony.CellLocation)

Aggregations

CellLocation (android.telephony.CellLocation)18 GsmCellLocation (android.telephony.gsm.GsmCellLocation)12 CdmaCellLocation (android.telephony.cdma.CdmaCellLocation)8 SuppressLint (android.annotation.SuppressLint)4 PhoneStateListener (android.telephony.PhoneStateListener)2 TelephonyManager (android.telephony.TelephonyManager)2 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 NetworkInfo (android.net.NetworkInfo)1 AsyncResult (android.os.AsyncResult)1 CellInfo (android.telephony.CellInfo)1 NeighboringCellInfo (android.telephony.NeighboringCellInfo)1 SmsCbLocation (android.telephony.SmsCbLocation)1 LatLng (com.google.android.gms.maps.model.LatLng)1 CellTowerCdma (com.vonglasow.michael.satstat.data.CellTowerCdma)1 CellTowerGsm (com.vonglasow.michael.satstat.data.CellTowerGsm)1 Realm (io.realm.Realm)1 Date (java.util.Date)1 Cleanup (lombok.Cleanup)1 Network (net.wigle.wigleandroid.model.Network)1