Search in sources :

Example 1 with GpsStatus

use of android.location.GpsStatus 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 GpsStatus

use of android.location.GpsStatus 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 GpsStatus

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

the class MainActivity method onGpsStatusChanged.

/**
 * Called when the status of the GPS changes. Updates GPS display.
 */
public void onGpsStatusChanged(int event) {
    GpsStatus status = locationManager.getGpsStatus(null);
    int satsInView = 0;
    int satsUsed = 0;
    Iterable<GpsSatellite> sats = status.getSatellites();
    for (GpsSatellite sat : sats) {
        satsInView++;
        if (sat.usedInFix()) {
            satsUsed++;
        }
    }
    if (gpsSectionFragment != null) {
        gpsSectionFragment.onGpsStatusChanged(status, satsInView, satsUsed, sats);
    }
    if (mapSectionFragment != null) {
        mapSectionFragment.onGpsStatusChanged(status, satsInView, satsUsed, sats);
    }
}
Also used : GpsStatus(android.location.GpsStatus) GpsSatellite(android.location.GpsSatellite)

Example 4 with GpsStatus

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

the class PasvLocListenerService method onLocationChanged.

@Override
public void onLocationChanged(Location location) {
    if (!location.getProvider().equals(LocationManager.GPS_PROVIDER))
        return;
    if (mNotifyFix && (mStatus != GPS_INACTIVE)) {
        mStatus = GPS_FIX;
        GpsStatus status = mLocationManager.getGpsStatus(null);
        int satsInView = 0;
        int satsUsed = 0;
        Iterable<GpsSatellite> sats = status.getSatellites();
        for (GpsSatellite sat : sats) {
            satsInView++;
            if (sat.usedInFix()) {
                satsUsed++;
            }
        }
        double lat = Math.abs(location.getLatitude());
        double lon = Math.abs(location.getLongitude());
        String ns = (location.getLatitude() > 0) ? getString(R.string.value_N) : (location.getLatitude() < 0) ? getString(R.string.value_S) : "";
        String ew = (location.getLongitude() > 0) ? getString(R.string.value_E) : (location.getLongitude() < 0) ? getString(R.string.value_W) : "";
        String title = "";
        if (prefCoord == Const.KEY_PREF_COORD_DECIMAL) {
            title = String.format("%.5f%s%s %.5f%s%s", lat, getString(R.string.unit_degree), ns, lon, getString(R.string.unit_degree), ew);
        } else if (prefCoord == Const.KEY_PREF_COORD_MIN) {
            double decY = lat;
            double degY = (int) decY;
            double minY = Math.abs(60.0 * (decY - degY));
            double decX = lon;
            double degX = (int) decX;
            double minX = Math.abs(60.0 * (decX - degX));
            title = String.format("%.0f%s %.3f' %s %.0f%s %.3f' %s", degY, getString(R.string.unit_degree), minY + /*rounding*/
            0.0005, ns, degX, getString(R.string.unit_degree), minX + /*rounding*/
            0.0005, ew);
        } else if (prefCoord == Const.KEY_PREF_COORD_SEC) {
            double decY = lat;
            double degY = (int) decY;
            double tmp = 60.0 * (decY - degY);
            double minY = (int) Math.abs(tmp);
            double secY = Math.abs(60.0 * (tmp - minY));
            double decX = lon;
            double degX = (int) decX;
            tmp = 60.0 * (decX - degX);
            double minX = (int) Math.abs(tmp);
            double secX = Math.abs(60.0 * (tmp - minX));
            title = String.format("%.0f%s %.0f' %.1f\" %s %.0f%s %.0f' %.1f\" %s", degY, getString(R.string.unit_degree), minY, secY + /*rounding*/
            0.05, ns, degX, getString(R.string.unit_degree), minX, secX + /*rounding*/
            0.05, ew);
        } else if (prefCoord == Const.KEY_PREF_COORD_MGRS) {
            title = new LatLng(location.getLatitude(), location.getLongitude()).toMGRSRef().toString(MGRSRef.PRECISION_1M);
        } else if (prefCoord == Const.KEY_PREF_COORD_UTM) {
            title = UTM.lat_lon_to_utm(location.getLatitude(), location.getLongitude(), this.getApplicationContext());
        }
        String text = "";
        if (location.hasAltitude()) {
            text = text + String.format("%.0f%s", (location.getAltitude() * (prefUnitType ? 1 : 3.28084)), getString(((prefUnitType) ? R.string.unit_meter : R.string.unit_feet)));
        }
        if (location.hasSpeed()) {
            text = text + (text.equals("") ? "" : ", ") + String.format("%.0f%s", (location.getSpeed() * (prefKnots ? 1.943844 : prefUnitType ? 3.6 : 2.23694)), getString(((prefKnots) ? R.string.unit_kn : (prefUnitType) ? R.string.unit_km_h : R.string.unit_mph)));
        }
        if (location.hasAccuracy()) {
            text = text + (text.equals("") ? "" : ", ") + String.format("\u03b5 = %.0f%s", (location.getAccuracy() * (prefUnitType ? 1 : 3.28084)), getString(((prefUnitType) ? R.string.unit_meter : R.string.unit_feet)));
        }
        text = text + (text.equals("") ? "" : ", ") + String.format("%d/%d", satsUsed, satsInView);
        text = text + (text.equals("") ? "" : ",\n") + String.format("TTFF %d s", status.getTimeToFirstFix() / 1000);
        mBuilder.setSmallIcon(R.drawable.ic_stat_notify_location);
        mBuilder.setContentTitle(title);
        mBuilder.setContentText(text);
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(text));
        startForeground(ONGOING_NOTIFICATION, mBuilder.build());
    } else {
        stopForeground(true);
    }
}
Also used : GpsStatus(android.location.GpsStatus) GpsSatellite(android.location.GpsSatellite) LatLng(uk.me.jstott.jcoord.LatLng)

Example 5 with GpsStatus

use of android.location.GpsStatus in project carat by amplab.

the class SamplingLibrary method getMaxNumSatellite.

/* Check the maximum number of satellites can be used in the satellite list */
public static int getMaxNumSatellite(Context context) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    GpsStatus gpsStatus = locationManager.getGpsStatus(null);
    int maxNumSatellite = gpsStatus.getMaxSatellites();
    // maxNumSatellite);
    return maxNumSatellite;
}
Also used : LocationManager(android.location.LocationManager) GpsStatus(android.location.GpsStatus)

Aggregations

GpsStatus (android.location.GpsStatus)5 GpsSatellite (android.location.GpsSatellite)4 Location (android.location.Location)1 LocationManager (android.location.LocationManager)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 LatLng (uk.me.jstott.jcoord.LatLng)1