MCPcopy Create free account
hub / github.com/XCSoar/XCSoar / InternalGPS

Class InternalGPS

android/src/InternalGPS.java:38–215  ·  view source on GitHub ↗

Code to support the internal GPS receiver via #LocationManager.

Source from the content-addressed store, hash-verified

36 * Code to support the internal GPS receiver via #LocationManager.
37 */
38public class InternalGPS
39 implements LocationListener, Runnable, AndroidSensor
40{
41 private final Handler handler;
42
43 private final SensorListener listener;
44
45 /** the name of the currently selected location provider */
46 static final String locationProvider = LocationManager.GPS_PROVIDER;
47
48 private final LocationManager locationManager;
49 private static boolean queriedLocationSettings = false;
50
51 private int state = STATE_LIMBO;
52
53 private final SafeDestruct safeDestruct = new SafeDestruct();
54
55 InternalGPS(Context context, SensorListener listener) {
56 handler = new Handler(context.getMainLooper());
57 this.listener = listener;
58
59 locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
60 if (locationManager == null ||
61 locationManager.getProvider(locationProvider) == null) {
62 /* on the Nook Simple Touch, LocationManager.isProviderEnabled()
63 can crash, but LocationManager.getProvider() appears to be
64 safe, therefore we're first checking the latter; if the
65 device does have a GPS, it returns non-null even when the
66 user has disabled GPS */
67 return;
68 } else if (!locationManager.isProviderEnabled(locationProvider) &&
69 !queriedLocationSettings) {
70 // Let user turn on GPS, XCSoar is not allowed to.
71 Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
72 context.startActivity(myIntent);
73 queriedLocationSettings = true;
74 }
75
76 handler.post(this);
77 }
78
79 /**
80 * Called by the #Handler, indirectly by update(). Updates the
81 * LocationManager subscription inside the main thread.
82 */
83 @Override public void run() {
84 try {
85 locationManager.requestLocationUpdates(locationProvider,
86 1000, 0, this);
87 } catch (SecurityException e) {
88 submitError(e.toString());
89 } catch (IllegalArgumentException e) {
90 /* this exception was recorded on the Android Market, message
91 was: "provider=gps" - no idea what that means */
92 }
93 }
94
95 @Override

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected