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 Project: letv   Author: JackChan1999   File: d.java    License: 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 #2
Source Project: TowerCollector   Author: zamojski   File: MeasurementUpdater.java    License: 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 Project: TowerCollector   Author: zamojski   File: MeasurementUpdater.java    License: 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 #4
Source Project: Easer   Author: renyuneyun   File: CellLocationScannerDialogFragment.java    License: 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 #5
Source Project: Easer   Author: renyuneyun   File: CellLocationSingleData.java    License: 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 #6
Source Project: MiBandDecompiled   Author: vishnudevk   File: ay.java    License: 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 #7
Source Project: DualSIMCard   Author: ITger   File: MainActivity.java    License: 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 #8
Source Project: LocalGSMLocationProvider   Author: rtreffer   File: CellbasedLocationProvider.java    License: 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 #9
Source Project: your-local-weather   Author: thuryn   File: LogToFile.java    License: 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 #10
Source Project: DataLogger   Author: STRCWearlab   File: CellsInfoDataCollector.java    License: 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 #11
Source Project: letv   Author: JackChan1999   File: LetvUtils.java    License: 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 #12
Source Project: TowerCollector   Author: zamojski   File: CollectorService.java    License: 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 #13
Source Project: TowerCollector   Author: zamojski   File: CellLocationValidator.java    License: 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 #14
Source Project: TowerCollector   Author: zamojski   File: CellLocationConverter.java    License: 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 #15
Source Project: TowerCollector   Author: zamojski   File: LegacyMeasurementProcessingEvent.java    License: 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 #16
Source Project: Easer   Author: renyuneyun   File: CellLocationSlot.java    License: 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 #17
Source Project: Easer   Author: renyuneyun   File: CellLocationTracker.java    License: 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 #18
Source Project: CellularSignal   Author: hugecheng   File: RadioInfo.java    License: 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 #19
Source Project: android_external_UnifiedNlpApi   Author: microg   File: CellBackendHelper.java    License: 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 #20
Source Project: LocalGSMLocationProvider   Author: rtreffer   File: CellbasedLocationProvider.java    License: 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 #21
Source Project: android_external_UnifiedNlpApi   Author: microg   File: CellBackendHelper.java    License: 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 #22
Source Project: XPrivacy   Author: M66B   File: XTelephonyManager.java    License: 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 #23
Source Project: assertj-android   Author: square   File: TelephonyManagerAssert.java    License: 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 #24
Source Project: android_9.0.0_r45   Author: lulululbj   File: TelephonyRegistry.java    License: 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 Project: android_9.0.0_r45   Author: lulululbj   File: EmergencyAffordanceService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onCellLocationChanged(CellLocation location) {
    if (!isEmergencyAffordanceNeeded()) {
        requestCellScan();
    }
}
 
Example #26
Source Project: DataLogger   Author: STRCWearlab   File: Depr_CellsInfoDataCollector.java    License: 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;
    }
 
Example #27
Source Project: AIMSICDL   Author: 5GSD   File: CellTracker.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void onCellLocationChanged(CellLocation location) {

            checkForNeighbourCount(location);
            compareLac(location);
            refreshDevice();
            mDevice.setNetID(tm);
            mDevice.getNetworkTypeName();

            switch (mDevice.getPhoneID()) {

                case TelephonyManager.PHONE_TYPE_NONE:
                case TelephonyManager.PHONE_TYPE_SIP:
                case TelephonyManager.PHONE_TYPE_GSM:
                    GsmCellLocation gsmCellLocation = (GsmCellLocation) location;
                    if (gsmCellLocation != null) {
                        //TODO @EVA where are we sending this setCellInfo data?

                        //TODO
                        /*@EVA
                            Is it a good idea to dump all cells to db because if we spot a known cell
                            with different lac then this will also be dump to db.

                        */
                        mDevice.setCellInfo(
                                gsmCellLocation.toString() +                // ??
                                mDevice.getDataActivityTypeShort() + "|" +  // No,In,Ou,IO,Do
                                mDevice.getDataStateShort() + "|" +         // Di,Ct,Cd,Su
                                mDevice.getNetworkTypeName() + "|"          // HSPA,LTE etc
                        );

                        mDevice.mCell.setLAC(gsmCellLocation.getLac());     // LAC
                        mDevice.mCell.setCID(gsmCellLocation.getCid());     // CID
                        if (gsmCellLocation.getPsc() != -1) {
                            mDevice.mCell.setPSC(gsmCellLocation.getPsc()); // PSC
                        }

                        /*
                            Add cell if gps is not enabled
                            when gps enabled lat lon will be updated
                            by function below

                         */
                    }
                    break;

                case TelephonyManager.PHONE_TYPE_CDMA:
                    CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) location;
                    if (cdmaCellLocation != null) {
                        mDevice.setCellInfo(
                                cdmaCellLocation.toString() +                       // ??
                                mDevice.getDataActivityTypeShort() + "|" +  // No,In,Ou,IO,Do
                                mDevice.getDataStateShort() + "|" +         // Di,Ct,Cd,Su
                                mDevice.getNetworkTypeName() + "|"          // HSPA,LTE etc
                        );
                        mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId());      // NID
                        mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId());  // BID
                        mDevice.mCell.setSID(cdmaCellLocation.getSystemId());       // SID
                        mDevice.mCell.setMNC(cdmaCellLocation.getSystemId());       // MNC <== BUG!??
                        mDevice.setNetworkName(tm.getNetworkOperatorName());        // ??
                    }
            }

        }
 
Example #28
Source Project: AIMSICDL   Author: 5GSD   File: CellTracker.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Description:    Add entries to the "DBi_measure" DB table
 *
 * Issues:
 *                  [ ]
 *
 * Notes:           (a)
 *
 *
 * TODO:  Remove OLD notes below, once we have new ones relevant to our new table
 *
 *  From "locationinfo":
 *
 *      $ sqlite3.exe -header aimsicd.db 'select * from locationinfo;'
 *      _id|Lac|CellID|Net|Lat|Lng|Signal|Connection|Timestamp
 *      1|10401|6828xxx|10|54.67874392|25.28693531|24|[10401,6828320,126]No|Di|HSPA||2015-01-21 20:45:10
 *
 *  From "cellinfo":
 *
 *      $ sqlite3.exe -header aimsicd.db 'select * from cellinfo;'
 *      _id|Lac|CellID|Net|Lat|Lng|Signal|Mcc|Mnc|Accuracy|Speed|Direction|NetworkType|MeasurementTaken|OCID_SUBMITTED|Timestamp
 *      1|10401|6828xxx|10|54.67874392|25.28693531|24|246|2|69.0|0.0|0.0|HSPA|82964|0|2015-01-21 20:45:10
 *
 *  Issues:
 *
 */
public void onLocationChanged(Location loc) {

    DeviceApi18.loadCellInfo(tm, mDevice);

    if (!mDevice.mCell.isValid()) {
        CellLocation cellLocation = tm.getCellLocation();
        if (cellLocation != null) {
            switch (mDevice.getPhoneID()) {

                case TelephonyManager.PHONE_TYPE_NONE:
                case TelephonyManager.PHONE_TYPE_SIP:
                case TelephonyManager.PHONE_TYPE_GSM:
                    GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
                    mDevice.mCell.setCID(gsmCellLocation.getCid()); // CID
                    mDevice.mCell.setLAC(gsmCellLocation.getLac()); // LAC
                    mDevice.mCell.setPSC(gsmCellLocation.getPsc()); // PSC
                    break;

                case TelephonyManager.PHONE_TYPE_CDMA:
                    CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
                    mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId()); // BSID ??
                    mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId());     // NID
                    mDevice.mCell.setSID(cdmaCellLocation.getSystemId());      // SID
                    mDevice.mCell.setMNC(cdmaCellLocation.getSystemId());      // MNC <== BUG!??

                    break;
            }
        }
    }

    if (loc != null &&  (Double.doubleToRawLongBits(loc.getLatitude()) != 0  &&  Double.doubleToRawLongBits(loc.getLongitude()) != 0)) {

        mDevice.mCell.setLon(loc.getLongitude());       // gpsd_lon
        mDevice.mCell.setLat(loc.getLatitude());        // gpsd_lat
        mDevice.mCell.setSpeed(loc.getSpeed());         // speed        // TODO: Remove, we're not using it!
        mDevice.mCell.setAccuracy(loc.getAccuracy());   // gpsd_accu
        mDevice.mCell.setBearing(loc.getBearing());     // -- [deg]??   // TODO: Remove, we're not using it!
        mDevice.setLastLocation(loc);                   //

        // Store last known location in preference
        SharedPreferences.Editor prefsEditor;
        prefsEditor = prefs.edit();
        prefsEditor.putString(context.getString(R.string.data_last_lat_lon),
                String.valueOf(loc.getLatitude()) + ":" + String.valueOf(loc.getLongitude()));
        prefsEditor.apply();

        // This only logs a BTS if we have GPS lock
        // Test: ~~Is correct behaviour? We should consider logging all cells, even without GPS.~~
        //if (mTrackingCell) {
            // This also checks that the lac are cid are not in DB before inserting
            dbHelper.insertBTS(mDevice.mCell);
        //}
    }
}
 
Example #29
Source Project: AIMSICDL   Author: 5GSD   File: CellTracker.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCellLocationChanged(CellLocation location) {
    handle();
}
 
Example #30
Source Project: letv   Author: JackChan1999   File: c.java    License: Apache License 2.0 4 votes vote down vote up
public final void onCellLocationChanged(CellLocation cellLocation) {
}