android.telephony.CellLocation Java Examples

The following examples show how to use android.telephony.CellLocation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MeasurementUpdater.java    From TowerCollector with Mozilla Public License 2.0 6 votes vote down vote up
private boolean isCellLocationEqual(CellLocation cl1, CellLocation cl2) {
    boolean result;
    if (cl1 instanceof GsmCellLocation && cl2 instanceof GsmCellLocation) {
        GsmCellLocation gsm1 = (GsmCellLocation) cl1;
        GsmCellLocation gsm2 = (GsmCellLocation) cl2;
        result = (gsm1.getCid() == gsm2.getCid()
                && gsm1.getLac() == gsm2.getLac()
                && gsm1.getPsc() == gsm2.getPsc());
        Timber.d("isCellLocationEqual(): GSM equals = %s", result);
    } else if (cl1 instanceof CdmaCellLocation && cl2 instanceof CdmaCellLocation) {
        CdmaCellLocation cdma1 = (CdmaCellLocation) cl1;
        CdmaCellLocation cdma2 = (CdmaCellLocation) cl2;
        result = (cdma1.getBaseStationId() == cdma2.getBaseStationId()
                && cdma1.getNetworkId() == cdma2.getNetworkId()
                && cdma1.getSystemId() == cdma2.getSystemId());
        Timber.d("isCellLocationEqual(): CDMA equal = %s", result);
    } else {
        // different types or nulls
        result = false;
        Timber.d("isCellLocationEqual(): Different types or nulls");
    }
    return result;
}
 
Example #2
Source File: MeasurementUpdater.java    From TowerCollector with Mozilla Public License 2.0 6 votes vote down vote up
public synchronized void setLastCellLocation(CellLocation cellLocation, NetworkGroup networkType,
                                             String operatorCode, String operatorName, List<NeighboringCellInfo> neighboringCells) {
    Timber.d("setLastCellLocation(): Cell location updated: %s, network type: %s, operator code: %s, operator name: %s", cellLocation, networkType, operatorCode, operatorName);
    // check if any changes
    boolean cellChanged = (!isCellLocationEqual(lastCellLocation, cellLocation)
            || lastNetworkType != networkType
            || !lastOperatorCode.equals(operatorCode)
            || !lastOperatorName.equals(operatorName));
    // update last cell
    this.lastCellLocation = cellLocation;
    this.lastNetworkType = networkType;
    this.lastOperatorCode = operatorCode;
    this.lastOperatorName = operatorName;
    this.neighboringCells = neighboringCells;
    if (this.neighboringCells == null) {
        this.neighboringCells = EMPTY_NEIGHBORING_CELL_LIST;
    }
    if (cellChanged) {
        notifyIfReadyToProcess();
    }
}
 
Example #3
Source File: CellbasedLocationProvider.java    From LocalGSMLocationProvider with Apache License 2.0 6 votes vote down vote up
/**
 * Handle a modem event by trying to pull all information. The parameter inc defines if the
 * measurement counter should be increased on success.
 * @param inc True if the measurement counter should be increased.
 */
private void handle(boolean inc) {
    if (telephonyManager == null) return;
    final List<android.telephony.CellInfo> cellInfos = telephonyManager.getAllCellInfo();
    final List<NeighboringCellInfo> neighbours = telephonyManager.getNeighboringCellInfo();
    final CellLocation cellLocation = telephonyManager.getCellLocation();
    if (cellInfos == null || cellInfos.isEmpty()) {
        if (neighbours == null || neighbours.isEmpty()) {
            if (cellLocation == null || !(cellLocation instanceof GsmCellLocation)) return;
        }
    }
    if (inc) measurement.getAndIncrement();
    add(cellLocation);
    addNeighbours(neighbours);
    addCells(cellInfos);
    synchronized (recentCells) {
        cleanup();
    }
}
 
Example #4
Source File: MainActivity.java    From DualSIMCard with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GsmCellLocation cl = (GsmCellLocation) CellLocation.getEmpty();
    CellLocation.requestLocationUpdate();
    System.out.println("GsmCellLocation " + cl.toString());
    MainActivity.context = getApplicationContext();
    setContentView(R.layout.activity_dual_sim_card_main);

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);


    clockwise(findViewById(R.id.listView));
    //readSims();
}
 
Example #5
Source File: ay.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
ay(CellLocation celllocation)
{
    a = 0x7fffffff;
    b = 0x7fffffff;
    c = 0x7fffffff;
    d = 0x7fffffff;
    e = 0x7fffffff;
    if (celllocation != null)
    {
        if (celllocation instanceof GsmCellLocation)
        {
            GsmCellLocation gsmcelllocation = (GsmCellLocation)celllocation;
            e = gsmcelllocation.getCid();
            d = gsmcelllocation.getLac();
        } else
        if (celllocation instanceof CdmaCellLocation)
        {
            CdmaCellLocation cdmacelllocation = (CdmaCellLocation)celllocation;
            c = cdmacelllocation.getBaseStationId();
            b = cdmacelllocation.getNetworkId();
            a = cdmacelllocation.getSystemId();
            return;
        }
    }
}
 
Example #6
Source File: CellLocationScannerDialogFragment.java    From Easer with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Void doInBackground(Void... voids) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        List<CellInfo> cellInfoList = telephonyManager.getAllCellInfo();
        if (cellInfoList != null) {
            for (CellInfo cellInfo : cellInfoList) {
                if (cellInfo.isRegistered()) {
                    publishProgress(CellLocationSingleData.fromCellInfo(cellInfo));
                }
            }
        }
    } else {
        CellLocation cellLocation = telephonyManager.getCellLocation();
        publishProgress(CellLocationSingleData.fromCellLocation(cellLocation));
    }
    return null;
}
 
Example #7
Source File: CellLocationSingleData.java    From Easer with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
static CellLocationSingleData fromCellLocation(@Nullable CellLocation location) {
    int cid, lac;
    if (location != null) {
        if (location instanceof GsmCellLocation) {
            cid = ((GsmCellLocation) location).getCid();
            lac = ((GsmCellLocation) location).getLac();
        }
        else if (location instanceof CdmaCellLocation) {
            cid = ((CdmaCellLocation) location).getBaseStationId();
            lac = ((CdmaCellLocation) location).getSystemId();
        } else {
            //TODO: More
            return null;
        }
        return new CellLocationSingleData(cid, lac);
    }
    return null;
}
 
Example #8
Source File: d.java    From letv with Apache License 2.0 6 votes vote down vote up
public final void e() {
    if (this.p == 1) {
        CellLocation.requestLocationUpdate();
        this.p = 2;
        this.l.sendEmptyMessage(1);
        if (this.s.b().isWifiEnabled()) {
            this.s.b().startScan();
            this.r = false;
        } else if (this.e) {
            this.o = System.currentTimeMillis();
            if (c && this.s.b().setWifiEnabled(true)) {
                this.r = true;
            } else {
                this.l.sendEmptyMessageDelayed(5, 8000);
            }
        } else {
            this.l.sendEmptyMessageDelayed(5, 0);
        }
    }
}
 
Example #9
Source File: CellLocationTracker.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private Boolean match(CellLocation location) {
    CellLocationSingleData curr = CellLocationSingleData.fromCellLocation(location);
    if (curr == null)
        return null;
    return data.data.contains(curr);
}
 
Example #10
Source File: CellLocationConverter.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
public Cell convert(CellLocation cellLocation, int mcc, int mnc, NetworkGroup networkType) {
    Cell cell = new Cell();
    if (cellLocation instanceof GsmCellLocation) {
        GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
        if (gsmCellLocation.getCid() <= 65535 && gsmCellLocation.getPsc() == NeighboringCellInfo.UNKNOWN_CID) {
            cell.setGsmCellLocation(mcc, mnc, gsmCellLocation.getLac(), gsmCellLocation.getCid(), NetworkGroup.Gsm);
        } else {
            // fix invalid network types (unfortunately not possible to distinguish between UMTS and LTE)
            if (networkType == NetworkGroup.Gsm || networkType == NetworkGroup.Cdma)
                networkType = NetworkGroup.Unknown;
            int psc = gsmCellLocation.getPsc();
            if (psc == NeighboringCellInfo.UNKNOWN_CID || psc == Cell.UNKNOWN_CID) {
                psc = Cell.UNKNOWN_CID;
            } else if (psc >= 504) {
                // only UMTS networks support larger PSC
                networkType = NetworkGroup.Wcdma;
            }
            cell.setGsmCellLocation(mcc, mnc, gsmCellLocation.getLac(), gsmCellLocation.getCid(), psc, networkType);
        }
    } else if (cellLocation instanceof CdmaCellLocation) {
        CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
        cell.setCdmaCellLocation(cdmaCellLocation.getSystemId(), cdmaCellLocation.getNetworkId(), cdmaCellLocation.getBaseStationId());
    } else {
        throw new UnsupportedOperationException("Cell location type not supported `" + cellLocation.getClass().getName() + "`");
    }
    return cell;
}
 
Example #11
Source File: LegacyMeasurementProcessingEvent.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
public LegacyMeasurementProcessingEvent(Location lastLocation, long lastLocationObtainedTime,
                                        CellLocation lastCellLocation, SignalStrength lastSignalStrength, NetworkGroup lastNetworkType,
                                        String lastOperatorCode, String lastOperatorName, List<NeighboringCellInfo> neighboringCells,
                                        int minDistance) {
    this.lastLocation = lastLocation;
    this.lastLocationObtainedTime = lastLocationObtainedTime;
    this.lastCellLocation = lastCellLocation;
    this.lastSignalStrength = lastSignalStrength;
    this.lastNetworkType = lastNetworkType;
    this.neighboringCells = neighboringCells;
    this.lastOperatorCode = lastOperatorCode;
    this.lastOperatorName = lastOperatorName;
    this.minDistance = minDistance;
}
 
Example #12
Source File: CellLocationSlot.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
@Override
synchronized public void onCellLocationChanged(CellLocation location) {
    super.onCellLocationChanged(location);
    curr = CellLocationSingleData.fromCellLocation(location);
    if (curr != null)
        changeSatisfiedState(eventData.data.contains(curr), dynamicsForCurrent(location));
}
 
Example #13
Source File: TelephonyManagerAssert.java    From assertj-android with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: RadioInfo.java    From CellularSignal with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCellLocationChanged(CellLocation location) {
    super.onCellLocationChanged(location);
    //Log.e(Tag,"onCellLocationChanged");
    if (location instanceof CdmaCellLocation) {
        cdma_SID = ((CdmaCellLocation) location).getSystemId();
        cdma_NID = ((CdmaCellLocation) location).getNetworkId();
        cdma_BSID = ((CdmaCellLocation) location).getBaseStationId();
        //Log.e(Tag,((CdmaCellLocation)location).toString());
    }
    ((MainActivity)mcontext).mSectionsPagerAdapter.notifyDataSetChanged();
}
 
Example #15
Source File: CellBackendHelper.java    From android_external_UnifiedNlpApi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private synchronized void fallbackScan() {
    if (lastScan + MIN_UPDATE_INTERVAL > System.currentTimeMillis()) return;
    List<CellInfo> allCellInfo = telephonyManager.getAllCellInfo();
    if ((allCellInfo == null || allCellInfo.isEmpty()) && telephonyManager.getNetworkType() > 0) {
        allCellInfo = new ArrayList<CellInfo>();
        CellLocation cellLocation = telephonyManager.getCellLocation();
        CellInfo cellInfo = fromCellLocation(cellLocation);
        if (cellInfo != null) allCellInfo.add(cellInfo);
    }
    onCellsChanged(allCellInfo);
}
 
Example #16
Source File: CellbasedLocationProvider.java    From LocalGSMLocationProvider with Apache License 2.0 5 votes vote down vote up
/**
 * Add a CellLocation, usually called if the phone switched to a new tower.
 * @param icell The new cell location.
 */
public void add(CellLocation icell) {
    if (icell == null) {
        return;
    }
    if (!(icell instanceof GsmCellLocation)) {
        return;
    }
    GsmCellLocation cell = (GsmCellLocation) icell;
    List<CellInfo> cellInfos = db.query(cell.getCid(), cell.getLac());
    if (cellInfos != null && !cellInfos.isEmpty()) {
        long measurement = this.measurement.get();
        for (CellInfo cellInfo : cellInfos) {
            cellInfo.measurement = measurement;
            cellInfo.seen = System.currentTimeMillis();
            pushRecentCells(cellInfo);
        }
    } else {
        CellInfo ci = new CellInfo();
        ci.measurement = this.measurement.get();
        ci.lng = 0d;
        ci.lat = 0d;
        ci.CID = ((GsmCellLocation) icell).getCid();
        ci.LAC = ((GsmCellLocation) icell).getLac();
        ci.MCC = -1;
        ci.MNC = -1;
        pushUnusedCells(ci);
    }
}
 
Example #17
Source File: CellBackendHelper.java    From android_external_UnifiedNlpApi with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private synchronized void fallbackScan() {
    if (lastScan + MIN_UPDATE_INTERVAL > System.currentTimeMillis()) return;
    List<CellInfo> allCellInfo = telephonyManager.getAllCellInfo();
    if ((allCellInfo == null || allCellInfo.isEmpty()) && telephonyManager.getNetworkType() > 0) {
        allCellInfo = new ArrayList<CellInfo>();
        CellLocation cellLocation = telephonyManager.getCellLocation();
        CellInfo cellInfo = fromCellLocation(cellLocation);
        if (cellInfo != null) allCellInfo.add(cellInfo);
    }
    onCellsChanged(allCellInfo);
}
 
Example #18
Source File: XTelephonyManager.java    From XPrivacy with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example #19
Source File: CellLocationValidator.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
public boolean isValid(CellLocation cellLocation, int mcc, int mnc) {
    if (cellLocation instanceof GsmCellLocation) {
        GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
        return getGsmValidator().isValid(gsmCellLocation, mcc, mnc);
    }
    if (cellLocation instanceof CdmaCellLocation) {
        CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
        return getCdmaValidator().isValid(cdmaCellLocation);
    }
    throw new UnsupportedOperationException("Cell location type not supported `" + cellLocation.getClass().getName() + "`");
}
 
Example #20
Source File: CollectorService.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
private void processCellLocation(TelephonyManager telephonyManager, CellLocation cellLocation, List<NeighboringCellInfo> neighboringCells) {
    // get network type
    int networkTypeInt = telephonyManager.getNetworkType();
    NetworkGroup networkType = NetworkTypeUtils.getNetworkGroup(networkTypeInt);
    // get network operator (may be unreliable for CDMA)
    String networkOperatorCode = telephonyManager.getNetworkOperator();
    String networkOperatorName = telephonyManager.getNetworkOperatorName();
    Timber.d("processCellLocation(): Operator code = '%s', name = '%s'", networkOperatorCode, networkOperatorName);
    Timber.d("processCellLocation(): Reported %s neighboring cells", (neighboringCells != null ? neighboringCells.size() : null));
    measurementUpdater.setLastCellLocation(cellLocation, networkType, networkOperatorCode, networkOperatorName, neighboringCells);
}
 
Example #21
Source File: LetvUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static GSMInfo getGSMInfo(Context context) {
    try {
        GSMInfo info = new GSMInfo();
        TelephonyManager manager = (TelephonyManager) context.getSystemService("phone");
        if (manager != null) {
            CellLocation cellLocation = manager.getCellLocation();
            int lac = 0;
            int cellid = 0;
            if (cellLocation != null) {
                if (cellLocation instanceof GsmCellLocation) {
                    lac = ((GsmCellLocation) cellLocation).getLac();
                    cellid = ((GsmCellLocation) cellLocation).getCid();
                } else if (cellLocation instanceof CdmaCellLocation) {
                    cellid = ((CdmaCellLocation) cellLocation).getNetworkId();
                    lac = ((CdmaCellLocation) cellLocation).getBaseStationId();
                }
            }
            info.lac = lac;
            info.cid = cellid;
        }
        AMapLocation location = AMapLocationTool.getInstance().location();
        if (location != null) {
            info.latitude = location.getLatitude();
            info.longitude = location.getLongitude();
            return info;
        }
        info.latitude = Double.parseDouble(PreferencesManager.getInstance().getLocationLongitude());
        info.longitude = Double.parseDouble(PreferencesManager.getInstance().getLocationLatitude());
        return info;
    } catch (Exception e) {
        LogInfo.log("ZSM++ ==== GSM exception e == " + e.getMessage());
        e.printStackTrace();
        return null;
    }
}
 
Example #22
Source File: LogToFile.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
public static void appendLog(Context context, String tag, String text1, CellLocation value1) {
    checkPreferences(context);
    if (!logToFileEnabled || (logFilePathname == null)) {
        return;
    }
    appendLog(context, tag, text1, (value1 != null)? value1.toString() : "null");
}
 
Example #23
Source File: CellsInfoDataCollector.java    From DataLogger with MIT License 5 votes vote down vote up
@Override
public void onCellLocationChanged(CellLocation location){
    super.onCellLocationChanged(location);

    // getAllCellInfo() returns all observed cell information from all radios on the device including the primary and neighboring cells
    // This is preferred over using getCellLocation although for older devices this may return null in which case getCellLocation should be called.
    logCellInfo(mTelephonyManager.getAllCellInfo());
}
 
Example #24
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
TelephonyRegistry(Context context) {
    CellLocation  location = CellLocation.getEmpty();

    mContext = context;
    mBatteryStats = BatteryStatsService.getService();

    int numPhones = TelephonyManager.getDefault().getPhoneCount();
    if (DBG) log("TelephonyRegistry: ctor numPhones=" + numPhones);
    mNumPhones = numPhones;
    mCallState = new int[numPhones];
    mDataActivity = new int[numPhones];
    mDataConnectionState = new int[numPhones];
    mDataConnectionNetworkType = new int[numPhones];
    mCallIncomingNumber = new String[numPhones];
    mServiceState = new ServiceState[numPhones];
    mVoiceActivationState = new int[numPhones];
    mDataActivationState = new int[numPhones];
    mUserMobileDataState = new boolean[numPhones];
    mSignalStrength = new SignalStrength[numPhones];
    mMessageWaiting = new boolean[numPhones];
    mCallForwarding = new boolean[numPhones];
    mCellLocation = new Bundle[numPhones];
    mCellInfo = new ArrayList<List<CellInfo>>();
    mPhysicalChannelConfigs = new ArrayList<List<PhysicalChannelConfig>>();
    for (int i = 0; i < numPhones; i++) {
        mCallState[i] =  TelephonyManager.CALL_STATE_IDLE;
        mDataActivity[i] = TelephonyManager.DATA_ACTIVITY_NONE;
        mDataConnectionState[i] = TelephonyManager.DATA_UNKNOWN;
        mVoiceActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
        mDataActivationState[i] = TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
        mCallIncomingNumber[i] =  "";
        mServiceState[i] =  new ServiceState();
        mSignalStrength[i] =  new SignalStrength();
        mUserMobileDataState[i] = false;
        mMessageWaiting[i] =  false;
        mCallForwarding[i] =  false;
        mCellLocation[i] = new Bundle();
        mCellInfo.add(i, null);
        mPhysicalChannelConfigs.add(i, new ArrayList<PhysicalChannelConfig>());
    }

    // Note that location can be null for non-phone builds like
    // like the generic one.
    if (location != null) {
        for (int i = 0; i < numPhones; i++) {
            location.fillInNotifierBundle(mCellLocation[i]);
        }
    }

    mAppOps = mContext.getSystemService(AppOpsManager.class);
}
 
Example #25
Source File: LegacyMeasurementParser.java    From TowerCollector with Mozilla Public License 2.0 4 votes vote down vote up
private ParseResult parse(Location location, CellLocation cellLocation, SignalStrength signalStrength,
                          NetworkGroup networkType, String operatorCode, String operatorName, List<NeighboringCellInfo> neighboringCells,
                          long timestamp, int minDistance) {
    // if required accuracy was achieved
    if (!locationValidator.isValid(location)) {
        Timber.d("parse(): Required accuracy not achieved: %s", location.getAccuracy());
        return ParseResult.AccuracyNotAchieved;
    }
    Timber.d("parse(): Required accuracy achieved: %s", location.getAccuracy());
    // get last location
    getAndSetLastLocation();
    // operator name may be unreliable for CDMA
    Timber.d("parse(): Operator name = '%s'", operatorName);
    // get operator codes
    int mcc = Cell.UNKNOWN_CID;
    int mnc = Cell.UNKNOWN_CID;
    if (cellLocation instanceof GsmCellLocation) {
        int[] mccMncPair = MobileUtils.getMccMncPair(operatorCode);
        if (mccMncPair != null) {
            mcc = mccMncPair[0];
            mnc = mccMncPair[1];
        } else {
            Timber.d("parseLocation(): Network operator unknown: %s", operatorCode);
        }
    }
    // validate cell
    if (!cellLocationValidator.isValid(cellLocation, mcc, mnc)) {
        Timber.d("parse(): Cell invalid");
        return ParseResult.NoNetworkSignal;
    }
    // create measurement with basic data
    Measurement measurement = new Measurement();
    measurement.setMeasuredAt(System.currentTimeMillis());
    Cell mainCell = cellLocationConverter.convert(cellLocation, mcc, mnc, networkType);
    measurement.addCell(mainCell);
    // fix time if incorrect
    fixMeasurementTimestamp(measurement, location);
    // if the same cell check distance condition, otherwise accept
    if (lastSavedMeasurement != null && lastSavedLocation != null && !conditionsValidator.isMinDistanceSatisfied(lastSavedLocation, location, minDistance)) {
        List<String> lastMeasurementsCellKeys = new ArrayList<>();
        for (Cell lastCell : lastSavedMeasurement.getCells()) {
            lastMeasurementsCellKeys.add(createCellKey(lastCell));
        }
        boolean mainCellChanged = !lastMeasurementsCellKeys.contains(createCellKey(mainCell));
        if (mainCellChanged) {
            Timber.d("parse(): Distance condition not achieved but cell changed");
        } else {
            Timber.d("parse(): Distance condition not achieved");
            return ParseResult.DistanceNotAchieved;
        }
    }
    // check if location has been obtained recently
    if (!locationValidator.isUpToDate(timestamp, System.currentTimeMillis())) {
        Timber.d("parse(): Location too old");
        return ParseResult.LocationTooOld;
    }
    Timber.d("parse(): Destination and time conditions achieved");
    // update measurement with location
    updateMeasurementWithLocation(measurement, location);
    // update measurement with signal strength
    if (signalStrength != null) {
        cellSignalConverter.update(mainCell, signalStrength);
    }
    if (collectNeighboringCells) {
        // remove duplicated neighboring cells
        removeDuplicatedNeighbors(neighboringCells, mainCell);
        // process neighboring cells
        for (NeighboringCellInfo neighboringCell : neighboringCells) {
            // validate cell
            if (cellLocationValidator.isValid(neighboringCell, mcc, mnc)) {
                // set values
                Cell tempCell = cellLocationConverter.convert(neighboringCell, mcc, mnc, mainCell.getLac(), mainCell.getCid());
                // update measurement with signal strength
                cellSignalConverter.update(tempCell, neighboringCell.getRssi());
                // save
                measurement.addCell(tempCell);
                Timber.d("parse(): Neighboring cell valid: %s", neighboringCell);
            } else {
                Timber.d("parse(): Neighboring cell invalid: %s", neighboringCell);
            }
        }
    }
    // write to database
    Timber.d("parse(): Measurement: %s", measurement);
    boolean inserted = MeasurementsDatabase.getInstance(MyApplication.getApplication()).insertMeasurement(measurement);
    if (inserted) {
        lastSavedLocation = location;
        lastSavedMeasurement = measurement;
        Timber.d("parse(): Measurement saved");
        // broadcast information to main activity
        Statistics stats = MeasurementsDatabase.getInstance(MyApplication.getApplication()).getMeasurementsStatistics();
        EventBus.getDefault().post(new MeasurementSavedEvent(measurement, stats));
        EventBus.getDefault().post(new MeasurementsCollectedEvent(measurement));
        Timber.d("parse(): Notification updated and measurement broadcasted");
        return ParseResult.Saved;
    } else {
        return ParseResult.SaveFailed;
    }
}
 
Example #26
Source File: XTelephonyManager.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCellLocationChanged(CellLocation location) {
	mListener.onCellLocationChanged(getDefacedCellLocation(Binder.getCallingUid()));
}
 
Example #27
Source File: EmergencyAffordanceService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onCellLocationChanged(CellLocation location) {
    if (!isEmergencyAffordanceNeeded()) {
        requestCellScan();
    }
}
 
Example #28
Source File: MainActivity.java    From satstat with GNU General Public License v3.0 4 votes vote down vote up
public void onCellLocationChanged (CellLocation location) {
	if (radioSectionFragment != null)
		radioSectionFragment.updateCellData(location, null, null);
}
 
Example #29
Source File: GsmService.java    From Local-GSM-Backend with Apache License 2.0 4 votes vote down vote up
private void setServiceRunning(boolean st) {
    final boolean cur_st = (worker != null);

    if (cur_st  == st)
        return;

    if (st) {
        tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
        th = new TelephonyHelper(ctx);

        try {
            if (worker != null && worker.isAlive()) worker.interrupt();

            worker = new Thread() {

                public void run() {
                    if (DEBUG) Log.i(TAG, "Starting reporter thread");
                    Looper.prepare();

                    final PhoneStateListener listener = new PhoneStateListener() {
                        public void onServiceStateChanged(ServiceState serviceState) {
                            scanGsm("onServiceStateChanged: ");
                        }

                        public void onCellLocationChanged(CellLocation location) {
                            scanGsm("onCellLocationChanged: ");
                        }

                        public void onCellInfoChanged(List<android.telephony.CellInfo> cellInfo) {
                            scanGsm("onCellInfoChanged: ");
                        }
                    };
                    tm.listen(
                            listener,
                            PhoneStateListener.LISTEN_CELL_INFO |
                                    PhoneStateListener.LISTEN_CELL_LOCATION |
                                    PhoneStateListener.LISTEN_SERVICE_STATE
                    );
                    Looper.loop();
                }
            };
            worker.start();
        } catch (Exception e) {
            if (DEBUG) Log.e(TAG, "Start failed: " + e.getMessage());
            e.printStackTrace();
            worker = null;
        }
    } else {
        try {
            if (worker != null && worker.isAlive())
                worker.interrupt();

            if (worker != null)
                worker = null;

        } finally {
            worker = null;
        }
    }
}
 
Example #30
Source File: Depr_CellsInfoDataCollector.java    From DataLogger with MIT License 4 votes vote down vote up
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(" ");

            // If the signal is not the right signal in db (a signal below -2) fallback
            // 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;
            }

        }

//        // Deprecated behavior, not collecting data
//        List<NeighboringCellInfo> neighboringCellInfoList = mTelephonyManager.getNeighboringCellInfo();
//        for (NeighboringCellInfo neighboringCellInfo : neighboringCellInfoList){
//        }

        return message;
    }