Search in sources :

Example 1 with GpsSatellite

use of android.location.GpsSatellite in project XPrivacy by M66B.

the class XLocationManager method after.

@Override
protected void after(XParam param) throws Throwable {
    switch(mMethod) {
        case addGeofence:
        case addNmeaListener:
        case addGpsStatusListener:
        case addProximityAlert:
        case Srv_requestGeofence:
        case Srv_addGpsStatusListener:
        case Srv_addGpsMeasurementsListener:
        case Srv_addGpsNavigationMessageListener:
        case Srv_removeGeofence:
        case Srv_removeGpsStatusListener:
        case Srv_removeGpsMeasurementsListener:
        case Srv_removeGpsNavigationMessageListener:
            // Do nothing
            break;
        case isProviderEnabled:
        case Srv_isProviderEnabled:
            if (param.args.length > 0) {
                String provider = (String) param.args[0];
                if (isRestrictedExtra(param, provider))
                    param.setResult(false);
            }
            break;
        case getGpsStatus:
            if (param.getResult() instanceof GpsStatus)
                if (isRestricted(param)) {
                    GpsStatus status = (GpsStatus) param.getResult();
                    // private GpsSatellite mSatellites[]
                    try {
                        Field mSatellites = status.getClass().getDeclaredField("mSatellites");
                        mSatellites.setAccessible(true);
                        mSatellites.set(status, new GpsSatellite[0]);
                    } catch (Throwable ex) {
                        Util.bug(null, ex);
                    }
                }
            break;
        case getProviders:
        case getAllProviders:
        case Srv_getAllProviders:
        case Srv_getProviders:
            if (isRestricted(param))
                param.setResult(new ArrayList<String>());
            break;
        case getBestProvider:
        case Srv_getBestProvider:
            if (param.getResult() != null)
                if (isRestricted(param))
                    param.setResult(null);
            break;
        case getLastKnownLocation:
            if (param.args.length > 0 && param.getResult() instanceof Location) {
                String provider = (String) param.args[0];
                Location location = (Location) param.getResult();
                if (isRestrictedExtra(param, provider))
                    param.setResult(PrivacyManager.getDefacedLocation(Binder.getCallingUid(), location));
            }
            break;
        case Srv_getLastLocation:
            if (param.getResult() instanceof Location) {
                Location location = (Location) param.getResult();
                if (isRestricted(param))
                    param.setResult(PrivacyManager.getDefacedLocation(Binder.getCallingUid(), location));
            }
            break;
        case removeUpdates:
        case requestLocationUpdates:
        case requestSingleUpdate:
        case Srv_removeUpdates:
        case Srv_requestLocationUpdates:
            // Do nothing
            break;
        case sendExtraCommand:
        case Srv_sendExtraCommand:
            if (param.args.length > 0) {
                String provider = (String) param.args[0];
                if (isRestrictedExtra(param, provider))
                    param.setResult(false);
            }
            break;
    }
}
Also used : GpsStatus(android.location.GpsStatus) Field(java.lang.reflect.Field) GpsSatellite(android.location.GpsSatellite) ArrayList(java.util.ArrayList) Location(android.location.Location)

Example 2 with GpsSatellite

use of android.location.GpsSatellite in project satstat by mvglasow.

the class PasvLocListenerService method onGpsStatusChanged.

@Override
public void onGpsStatusChanged(int event) {
    GpsStatus status = mLocationManager.getGpsStatus(null);
    int satsUsed = 0;
    Iterable<GpsSatellite> sats = status.getSatellites();
    for (GpsSatellite sat : sats) {
        if (sat.usedInFix()) {
            satsUsed++;
        }
    }
    if (satsUsed == 0) {
        if (mStatus != GPS_INACTIVE)
            mStatus = GPS_SEARCH;
        showStatusNoLocation();
    }
}
Also used : GpsStatus(android.location.GpsStatus) GpsSatellite(android.location.GpsSatellite)

Example 3 with GpsSatellite

use of android.location.GpsSatellite in project Osmand by osmandapp.

the class OsmAndLocationProvider method updateGPSInfo.

private void updateGPSInfo(GpsStatus s) {
    boolean fixed = false;
    int n = 0;
    int u = 0;
    if (s != null) {
        Iterator<GpsSatellite> iterator = s.getSatellites().iterator();
        while (iterator.hasNext()) {
            GpsSatellite g = iterator.next();
            n++;
            if (g.usedInFix()) {
                u++;
                fixed = true;
            }
        }
    }
    gpsInfo.fixed = fixed;
    gpsInfo.foundSatellites = n;
    gpsInfo.usedSatellites = u;
}
Also used : GpsSatellite(android.location.GpsSatellite) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint)

Example 4 with GpsSatellite

use of android.location.GpsSatellite in project android-gps-test-tool by Esri.

the class SatelliteDataActivityController method setLocationListenerGPSProvider.

private void setLocationListenerGPSProvider() {
    _locationListenerGPSProvider = new LocationListener() {

        @Override
        public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub
        }
    };
    _nmeaListener = new NmeaListener() {

        @Override
        public void onNmeaReceived(long timestamp, String nmea) {
            String time = _elapsedTimer.convertMillisToMDYHMSS(timestamp);
            _gpsNMEAText = "<b><font color='yellow'>GPS NMEA</b></font>" + "<br><b>Timestamp:</b> " + time + "<br><b>NMEA code:</b> " + nmea;
            _gpsNMEATextView.setText(Html.fromHtml(_gpsNMEAText));
        }
    };
    _locationManager.addNmeaListener(_nmeaListener);
    _gpsStatusListener = new GpsStatus.Listener() {

        String seconds;

        String minutes;

        String hours;

        String ms;

        String satelliteHMS;

        String usedInFix = "false";

        int t;

        @Override
        public void onGpsStatusChanged(int event) {
            _satelliteList = "";
            satelliteHMS = "N/A";
            //Occasionally there may be null values if GPS hiccups
            try {
                t = _locationManager.getGpsStatus(null).getTimeToFirstFix();
                //String seconds = String.format(_format, t/1000 % 60);
                seconds = String.format(_format, TimeUnit.MILLISECONDS.toSeconds(t));
                minutes = String.format(_format, TimeUnit.MILLISECONDS.toMinutes(t));
                hours = String.format(_format, TimeUnit.MILLISECONDS.toHours(t));
                ms = String.format(_format, t % 1000);
                satelliteHMS = hours + ":" + minutes + ":" + seconds + ":" + ms;
                _satellites = _locationManager.getGpsStatus(null).getSatellites();
                if (_satellites != null) {
                    for (GpsSatellite sat : _satellites) {
                        if (sat.usedInFix() == true) {
                            usedInFix = "<font color='red'>true</font>";
                        } else {
                            usedInFix = "false";
                        }
                        _satelliteList = _satelliteList + "<br>" + sat.getPrn() + ", " + sat.getSnr() + ", " + usedInFix;
                    }
                }
            } catch (Exception exc) {
                Log.d("GPSTester", "GPS Status error (onGpsStatusChanged): " + exc.getMessage());
            }
            if (_satelliteList != "") {
                _gpsSatelliteTextView.setText(Html.fromHtml("<b><font color='yellow'>GPS Satellite Info (No., SNR, Used in fix)</b></font>" + "<br><b>Time to 1st fix:</b> " + satelliteHMS + _satelliteList));
            }
        }
    };
    _locationManager.addGpsStatusListener(_gpsStatusListener);
    try {
        long minDistance = Long.valueOf(_preferences.getString("pref_key_updateGPSMinDistance", "0"));
        long minTime = Long.valueOf(_preferences.getString("pref_key_updateGPSMinTime", "0"));
        // Register the listener with the Location Manager to receive location updates
        _locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, _locationListenerGPSProvider);
    } catch (Exception exc) {
        Log.d("GPSTester", "Unable to start GPS provider. Bad value. " + exc.getMessage());
    }
}
Also used : NmeaListener(android.location.GpsStatus.NmeaListener) GpsStatus(android.location.GpsStatus) GpsSatellite(android.location.GpsSatellite) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Location(android.location.Location)

Example 5 with GpsSatellite

use of android.location.GpsSatellite in project DataLogger by sussexwearlab.

the class SatelliteDataCollector method logSatelliteInfo.

private void logSatelliteInfo(Iterable<GpsSatellite> gpsSatellites) {
    int satCounter = 0;
    // 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);
    for (GpsSatellite satellite : gpsSatellites) {
        satCounter++;
        // PRN (pseudo-random number) for the satellite.
        int prn = satellite.getPrn();
        // Signal to noise ratio for the satellite.
        float snr = satellite.getSnr();
        // Azimuth of the satellite in degrees.
        float azimuth = satellite.getAzimuth();
        // Elevation of the satellite in degrees.
        float elevation = satellite.getElevation();
        message += ";" + prn + ";" + snr + ";" + azimuth + ";" + elevation;
    }
    message += ";" + Integer.toString(satCounter);
    logger.log(message);
    logger.log(System.lineSeparator());
}
Also used : GpsSatellite(android.location.GpsSatellite) Date(java.util.Date)

Aggregations

GpsSatellite (android.location.GpsSatellite)9 GpsStatus (android.location.GpsStatus)5 Location (android.location.Location)2 Paint (android.graphics.Paint)1 NmeaListener (android.location.GpsStatus.NmeaListener)1 LocationListener (android.location.LocationListener)1 Bundle (android.os.Bundle)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 QuadPoint (net.osmand.data.QuadPoint)1 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)1 LatLng (uk.me.jstott.jcoord.LatLng)1