Example usage for android.telephony PhoneStateListener LISTEN_CELL_LOCATION

List of usage examples for android.telephony PhoneStateListener LISTEN_CELL_LOCATION

Introduction

In this page you can find the example usage for android.telephony PhoneStateListener LISTEN_CELL_LOCATION.

Prototype

int LISTEN_CELL_LOCATION

To view the source code for android.telephony PhoneStateListener LISTEN_CELL_LOCATION.

Click Source Link

Document

Listen for changes to the device's cell location.

Usage

From source file:com.secupwn.aimsicd.service.CellTracker.java

/**
 *  Description:    Updates Neighboring Cell details
 *
 *                  TODO: add more details...
 *
 *
 *///from   www . ja v  a  2 s . c  om
public List<Cell> updateNeighboringCells() {
    List<Cell> neighboringCells = new ArrayList<>();
    List<NeighboringCellInfo> neighboringCellInfo = tm.getNeighboringCellInfo();
    if (neighboringCellInfo == null) {
        neighboringCellInfo = new ArrayList<>();
    }

    Boolean nclp = tinydb.getBoolean("nc_list_present"); // NC list present? (default is false)

    //if nclp = true then check for neighboringCellInfo
    if (neighboringCellInfo != null && neighboringCellInfo.size() == 0 && nclp) {

        log.info("NeighboringCellInfo is empty: start polling...");

        // Try to poll the neighboring cells for a few seconds
        neighboringCellBlockingQueue = new LinkedBlockingQueue<>(100); // TODO What is this ??

        //LISTEN_CELL_INFO added in API 17
        // TODO: See issue #555 (DeviceApi17.java is using API 18 CellInfoWcdma calls.
        if (Build.VERSION.SDK_INT > 17) {
            DeviceApi18.startListening(tm, phoneStatelistener);
        } else {
            tm.listen(phoneStatelistener,
                    PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_CELL_INFO | // API 17
                            PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
                            | PhoneStateListener.LISTEN_SERVICE_STATE
                            | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        }

        // TODO: Consider removing ??
        for (int i = 0; i < 10 && neighboringCellInfo.size() == 0; i++) {
            try {
                log.debug("NeighboringCellInfo empty: trying " + i);
                NeighboringCellInfo info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS);
                if (info == null) {
                    neighboringCellInfo = tm.getNeighboringCellInfo();
                    if (neighboringCellInfo != null) {
                        if (neighboringCellInfo.size() > 0) {
                            // Can we think of a better log message here?
                            log.debug("NeighboringCellInfo found on " + i + " try. (time based)");
                            break;
                        } else {
                            continue;
                        }
                    }
                }
                List<NeighboringCellInfo> cellInfoList = new ArrayList<>(
                        neighboringCellBlockingQueue.size() + 1);
                while (info != null) {
                    cellInfoList.add(info);
                    info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS);
                }
                neighboringCellInfo = cellInfoList;
            } catch (InterruptedException e) {
                // TODO: Add a more valuable message here!
                log.error("", e);
            }
        }
    }

    //log.debug(mTAG + ": neighboringCellInfo size: " + neighboringCellInfo.size());

    // Add NC list to DBi_measure:nc_list
    for (NeighboringCellInfo neighborCell : neighboringCellInfo) {
        log.info("NeighboringCellInfo -" + " LAC:" + neighborCell.getLac() + " CID:" + neighborCell.getCid()
                + " PSC:" + neighborCell.getPsc() + " RSSI:" + neighborCell.getRssi());

        final Cell cell = new Cell(neighborCell.getCid(), neighborCell.getLac(), neighborCell.getRssi(),
                neighborCell.getPsc(), neighborCell.getNetworkType(), false);
        neighboringCells.add(cell);
    }
    return neighboringCells;
}

From source file:com.SecUpwN.AIMSICD.service.AimsicdService.java

/**
 * Updates Neighbouring Cell details/*w  w  w.  ja  v a  2s .  co m*/
 */
public List<Cell> updateNeighbouringCells() {
    List<Cell> neighboringCells = new ArrayList<>();

    List<NeighboringCellInfo> neighboringCellInfo;
    neighboringCellInfo = tm.getNeighboringCellInfo();
    if (neighboringCellInfo.size() == 0) {
        // try to poll the neighboring cells for a few seconds
        final LinkedBlockingQueue<NeighboringCellInfo> neighboringCellBlockingQueue = new LinkedBlockingQueue<>(
                100);
        final PhoneStateListener listener = new PhoneStateListener() {
            private void handle() {
                List<NeighboringCellInfo> neighboringCellInfo;
                neighboringCellInfo = tm.getNeighboringCellInfo();
                if (neighboringCellInfo.size() == 0) {
                    return;
                }
                Log.i(TAG, "neighbouringCellInfo empty - event based polling succeeded!");
                tm.listen(this, PhoneStateListener.LISTEN_NONE);
                neighboringCellBlockingQueue.addAll(neighboringCellInfo);
            }

            @Override
            public void onServiceStateChanged(ServiceState serviceState) {
                handle();
            }

            @Override
            public void onDataConnectionStateChanged(int state) {
                handle();
            }

            @Override
            public void onDataConnectionStateChanged(int state, int networkType) {
                handle();
            }

            @Override
            public void onSignalStrengthsChanged(SignalStrength signalStrength) {
                handle();
            }

            @Override
            public void onCellInfoChanged(List<CellInfo> cellInfo) {
                handle();
            }
        };
        Log.i(TAG, "neighbouringCellInfo empty - start polling");

        //LISTEN_CELL_INFO added in API 17
        if (Build.VERSION.SDK_INT > 16) {
            tm.listen(listener, PhoneStateListener.LISTEN_CELL_INFO | PhoneStateListener.LISTEN_CELL_LOCATION
                    | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | PhoneStateListener.LISTEN_SERVICE_STATE
                    | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        } else {
            tm.listen(listener,
                    PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
                            | PhoneStateListener.LISTEN_SERVICE_STATE
                            | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        }

        for (int i = 0; i < 10 && neighboringCellInfo.size() == 0; i++) {
            try {
                Log.i(TAG, "neighbouringCellInfo empty - try " + i);
                NeighboringCellInfo info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS);
                if (info == null) {
                    neighboringCellInfo = tm.getNeighboringCellInfo();
                    if (neighboringCellInfo.size() > 0) {
                        Log.i(TAG, "neighbouringCellInfo empty - try " + i + " succeeded time based");
                        break;
                    } else {
                        continue;
                    }
                }
                ArrayList<NeighboringCellInfo> cellInfoList = new ArrayList<NeighboringCellInfo>(
                        neighboringCellBlockingQueue.size() + 1);
                while (info != null) {
                    cellInfoList.add(info);
                    info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS);
                }
                neighboringCellInfo = cellInfoList;
            } catch (InterruptedException e) {
                // normal
            }
        }
    }

    Log.i(TAG, "neighbouringCellInfo Size - " + neighboringCellInfo.size());
    for (NeighboringCellInfo neighbourCell : neighboringCellInfo) {
        Log.i(TAG, "neighbouringCellInfo - CID:" + neighbourCell.getCid() + " LAC:" + neighbourCell.getLac()
                + " RSSI:" + neighbourCell.getRssi() + " PSC:" + neighbourCell.getPsc());

        final Cell cell = new Cell(neighbourCell.getCid(), neighbourCell.getLac(), neighbourCell.getRssi(),
                neighbourCell.getPsc(), neighbourCell.getNetworkType(), false);
        neighboringCells.add(cell);
    }

    return neighboringCells;
}

From source file:net.kidlogger.kidlogger.KLService.java

public void setupLogging() {
    // Set up GPS / Network logging      
    if (Settings.loggingGps(this)) {
        startGpsUpdates();/*  w  w w .  ja va  2  s.c o  m*/
        gpsOn = true;
    }

    // Set up WiFi logging
    if (Settings.loggingWifi(this)) {
        wifiReceiver = new WifiReceiver(this);
        registerReceiver(wifiReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
        wifiOn = true;
    }

    // Set up SMS logging
    if (Settings.loggingSms(this)) {
        smsObserver = new SmsObserver(this, handlering);
        IntentFilter smsFilter = new IntentFilter(SMS_RECEIVED);
        registerReceiver(smsObserver.inSms, smsFilter);
        smsOn = true;
    }

    // Set up Calls logging
    if (Settings.loggingCalls(this)) {
        IntentFilter callsFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED);

        callsReceiver = new CallsReceiver(this);
        registerReceiver(callsReceiver, callsFilter);
        callOn = true;
    }

    // Set up Idle logging
    IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    idleFilter.addAction(Intent.ACTION_USER_PRESENT);

    idleReceiver = new IdleReceiver(this);
    registerReceiver(idleReceiver, idleFilter);
    idleOn = true;
    /*if(Settings.loggingIdle(this)){
       IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
       idleFilter.addAction(Intent.ACTION_USER_PRESENT);
               
       idleReceiver = new IdleReceiver(this);
       registerReceiver(idleReceiver, idleFilter);
       idleOn = true;
    }*/

    // Set up URL logging
    if (Settings.loggingUrl(this)) {
        urlObserver = new HistoryObserver(this, handlering);
        urlOn = true;
    }

    // Set up USB logging
    if (Settings.loggingUsb(this)) {
        IntentFilter usbFilter = new IntentFilter(Intent.ACTION_UMS_CONNECTED);
        usbFilter.addAction(Intent.ACTION_UMS_DISCONNECTED);

        usbReceiver = new UsbReceiver(this);
        registerReceiver(usbReceiver, usbFilter);
        usbOn = true;
    }

    // Set up Tasks logging
    if (logTask) {
        // Check if a new Application was started
        taskScan = new Runnable() {
            public void run() {
                new Thread(new Runnable() {
                    public void run() {
                        doScanTask();
                    }
                }).start();
                if (userPresent) {
                    handleTask.postDelayed(this, SCAN_TASK_TIME);
                    scanningTask = true;
                } else {
                    scanningTask = false;
                }
            }
        };
        handleTask.postDelayed(taskScan, SCAN_TASK_TIME);
        taskOn = true;
    }

    // Set up Clipboard logging
    if (logClip) {
        // Scan clipboard content, only first 30 characters
        clipboardScan = new Runnable() {
            public void run() {
                new Thread(new Runnable() {
                    public void run() {
                        doScanClipboard();
                    }
                }).start();
                if (userPresent) {
                    handleClipb.postDelayed(this, SCAN_CLIP_TIME);
                    scanningClip = true;
                } else {
                    scanningClip = false;
                }
            }
        };
        handleClipb.postDelayed(clipboardScan, SCAN_CLIP_TIME);
        clipOn = true;
    }

    // Set up Power logging
    if (Settings.loggingPower(this)) {
        IntentFilter powerFilter = new IntentFilter(Intent.ACTION_SHUTDOWN);

        powerReceiver = new ShutdownReceiver(this);
        registerReceiver(powerReceiver, powerFilter);
        powerOn = true;
    }

    // Set up Memory Card logging
    if (Settings.loggingMedia(this)) {
        IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_REMOVED);
        mediaFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
        mediaFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        mediaFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
        mediaFilter.addAction(Intent.ACTION_MEDIA_SHARED);
        mediaFilter.addDataScheme("file");

        mediaReceiver = new MediaReceiver(this);
        registerReceiver(mediaReceiver, mediaFilter);

        mediaOn = true;
    }

    // Set up GSM logging
    if (Settings.loggingGsm(this)) {
        gsmObserver = new GsmObserver(this);
        telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        telManager.listen(gsmObserver,
                PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_CELL_LOCATION);
        gsmOn = true;
    }

    // Set up Airplane mode receiver
    if (Settings.loggingAir(this)) {
        IntentFilter airFilter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);

        airReceiver = new AirplaneReceiver(this);
        registerReceiver(airReceiver, airFilter);
        airOn = true;
    }

    // Set up Photos logging
    if (Settings.loggingPhotos(this)) {
        photoObserver = new PhotoObserver(this, this, handlering);
        photoOn = true;
    }

    // Set up SliceMultimediaFile
    if (Settings.uploadPhotos(this) || Settings.uploadRecords(this)) {
        mediaSlicer = new SliceMultimediaFile(this);
    }

    // Set up ConnectivityReceiver
    mConReceiver = new ConnectivityReceiver(this);
    registerReceiver(mConReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    // Ser up CallIntentReceiver
    //outCallReceiver = new CallIntentReceiver();
    //registerReceiver(outCallReceiver, new IntentFilter(KLService.OUTGOING_CALL));
}

From source file:at.alladin.rmbt.android.util.InformationCollector.java

/** Returns mobile data network connection type. */
/*/*from  ww w .  ja  v a  2 s  .c om*/
 * private int getTelephonyNetworkType() { //assert
 * NETWORK_TYPES[14].compareTo("EHRPD") == 0;
 * 
 * int networkType = telManager.getNetworkType(); if (networkType <
 * NETWORK_TYPES.length) {
 * 
 * } else { return 0; } }
 */

// Listeners
private void registerListeners() {
    initNetwork();

    if (telListener == null) {
        telListener = new TelephonyStateListener();
        telManager.listen(telListener,
                PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_CELL_LOCATION);
    }
}

From source file:com.SecUpwN.AIMSICD.service.AimsicdService.java

/**
 * Cell Information Tracking and database logging
 *
 * @param track Enable/Disable tracking//from www . j  a va 2 s. co  m
 */
public void setCellTracking(boolean track) {
    if (track) {
        tm.listen(mCellSignalListener,
                PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
                        | PhoneStateListener.LISTEN_DATA_ACTIVITY
                        | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
        if (lm != null) {
            mLocationListener = new MyLocationListener();
            Log.i(TAG, "LocationManager already existed");
            lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_MIN_UPDATE_TIME,
                    GPS_MIN_UPDATE_DISTANCE, mLocationListener);
        } else {
            Log.i(TAG, "LocationManager did not exist");
            lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
            if (lm != null) {
                if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    Log.i(TAG, "LocationManager created");
                    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_MIN_UPDATE_TIME,
                            GPS_MIN_UPDATE_DISTANCE, mLocationListener);
                }
            }
        }
        Helpers.msgShort(this, "Tracking cell information");
        mTrackingCell = true;
    } else {
        tm.listen(mCellSignalListener, PhoneStateListener.LISTEN_NONE);
        lm.removeUpdates(mLocationListener);
        mDevice.mCell.setLon(0.0);
        mDevice.mCell.setLat(0.0);
        mTrackingCell = false;
        mDevice.setCellInfo("[0,0]|nn|nn|");
        Helpers.msgShort(this, "Stopped tracking cell information");
    }
    setNotification();
}

From source file:com.secupwn.aimsicd.service.CellTracker.java

/**
 * Start FemtoCell detection tracking (For CDMA Devices ONLY!)
 *//*  w w w.ja  v  a 2 s  . c o  m*/
public void startTrackingFemto() {

    /* Check if it is a CDMA phone */
    if (device.getPhoneId() != TelephonyManager.PHONE_TYPE_CDMA) {
        Helpers.msgShort(context, context.getString(R.string.femtocell_only_on_cdma_devices));
        return;
    }

    trackingFemtocell = true;
    mPhoneStateListener = new PhoneStateListener() {
        public void onServiceStateChanged(ServiceState s) {
            log.debug(context.getString(R.string.service_state_changed));
            getServiceStateInfo(s);
        }
    };
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION);
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    setNotification();
}

From source file:com.SecUpwN.AIMSICD.service.AimsicdService.java

/**
 * Start FemtoCell detection tracking/*from   w w w.  jav  a 2  s .c o m*/
 * CDMA Devices ONLY
 */
public void startTrackingFemto() {

    /* Check if it is a CDMA phone */
    if (mDevice.getPhoneID() != TelephonyManager.PHONE_TYPE_CDMA) {
        Helpers.msgShort(this, "AIMSICD can only detect Femtocell connections on CDMA devices.");
        return;
    }

    mTrackingFemtocell = true;
    mPhoneStateListener = new PhoneStateListener() {
        public void onServiceStateChanged(ServiceState s) {
            Log.d(TAG, "Service State changed!");
            getServiceStateInfo(s);
        }
    };
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION);
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    setNotification();
}