summaryrefslogtreecommitdiff
path: root/core/java/android/webkit/GeolocationService.java
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-05-18 15:16:55 +0100
committerSteve Block <steveblock@google.com>2010-05-18 15:16:55 +0100
commit3d9e066ab3bbb184a9651d47ace5fe4c1626287f (patch)
tree0d7c997db7765bdaa24fe344e86f835e7ff6eaff /core/java/android/webkit/GeolocationService.java
parentda35551845b1ab47dbbae2194f1628442b6115d7 (diff)
Make sure Geolocation is robust to location providers being absent on the device.
Bug: 2692830 Change-Id: I19f88e20f00fe7ecfb77c06197213d273bd80411
Diffstat (limited to 'core/java/android/webkit/GeolocationService.java')
-rwxr-xr-xcore/java/android/webkit/GeolocationService.java20
1 files changed, 15 insertions, 5 deletions
diff --git a/core/java/android/webkit/GeolocationService.java b/core/java/android/webkit/GeolocationService.java
index 24306f407b90..183b3c0d8862 100755
--- a/core/java/android/webkit/GeolocationService.java
+++ b/core/java/android/webkit/GeolocationService.java
@@ -62,9 +62,10 @@ final class GeolocationService implements LocationListener {
/**
* Start listening for location updates.
*/
- public void start() {
+ public boolean start() {
registerForLocationUpdates();
mIsRunning = true;
+ return mIsNetworkProviderAvailable || mIsGpsProviderAvailable;
}
/**
@@ -87,6 +88,8 @@ final class GeolocationService implements LocationListener {
// only unregister from all, then reregister with all but the GPS.
unregisterFromLocationUpdates();
registerForLocationUpdates();
+ // Check that the providers are still available after we re-register.
+ maybeReportError("The last location provider is no longer available");
}
}
}
@@ -156,11 +159,16 @@ final class GeolocationService implements LocationListener {
*/
private void registerForLocationUpdates() {
try {
- mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
- mIsNetworkProviderAvailable = true;
+ // Registration may fail if providers are not present on the device.
+ try {
+ mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
+ mIsNetworkProviderAvailable = true;
+ } catch(IllegalArgumentException e) { }
if (mIsGpsEnabled) {
- mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
- mIsGpsProviderAvailable = true;
+ try {
+ mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
+ mIsGpsProviderAvailable = true;
+ } catch(IllegalArgumentException e) { }
}
} catch(SecurityException e) {
Log.e(TAG, "Caught security exception registering for location updates from system. " +
@@ -173,6 +181,8 @@ final class GeolocationService implements LocationListener {
*/
private void unregisterFromLocationUpdates() {
mLocationManager.removeUpdates(this);
+ mIsNetworkProviderAvailable = false;
+ mIsGpsProviderAvailable = false;
}
/**