Don't throw an exception from isProviderEnabled and getLastKnownLocation
if the location provider does not exist. Instead use the same behavior
as if the provider were disabled in settings
(return false for isProviderEnabled and null from getLastKnownLocation).
This eliminates for a lot of exception handling around some simple
queries to the location manager.
BUG: 2841014
Change-Id: I4fbe0c088e915c90969e13083201dd3e7f4029cb
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/services/java/com/android/server/LocationManagerService.java b/services/java/com/android/server/LocationManagerService.java
index 8519e2c..3bcf427 100644
--- a/services/java/com/android/server/LocationManagerService.java
+++ b/services/java/com/android/server/LocationManagerService.java
@@ -1613,8 +1613,6 @@
}
} catch (SecurityException se) {
throw se;
- } catch (IllegalArgumentException iae) {
- throw iae;
} catch (Exception e) {
Slog.e(TAG, "isProviderEnabled got exception:", e);
return false;
@@ -1638,7 +1636,7 @@
LocationProviderInterface p = mProvidersByName.get(provider);
if (p == null) {
- throw new IllegalArgumentException("provider=" + provider);
+ return false;
}
return isAllowedBySettingsLocked(provider);
}
@@ -1650,8 +1648,6 @@
}
} catch (SecurityException se) {
throw se;
- } catch (IllegalArgumentException iae) {
- throw iae;
} catch (Exception e) {
Slog.e(TAG, "getLastKnownLocation got exception:", e);
return null;
@@ -1663,7 +1659,7 @@
LocationProviderInterface p = mProvidersByName.get(provider);
if (p == null) {
- throw new IllegalArgumentException("provider=" + provider);
+ return null;
}
if (!isAllowedBySettingsLocked(provider)) {