From b254ab6addb46aefa59d26d261f846f381f4ece8 Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Thu, 23 Oct 2014 16:46:02 +0900 Subject: [PATCH] Fix a bug where LocationManager's addGpsStatusListener does not throw a SecurityException if LocationManagerService.mGpsStatusProvider is null even when ACCESS_FINE_LOCATION permission is not present. Tested under Nexus 5 and Molly with lmp-mr1-dev build with android.location2.cts.LocationManagerTest#testGpsStatusListener CTS test case such that it has been modified to expect SecurityException only from .addGpsStatusListener. Bug: 18095673 Change-Id: I09f9e7224a3b0eab91001f5092f0ef6e0ada7b08 --- .../java/com/android/server/LocationManagerService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index 28a6917cb0c74..d9c96e4a25372 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -1796,9 +1796,6 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public boolean addGpsStatusListener(IGpsStatusListener listener, String packageName) { - if (mGpsStatusProvider == null) { - return false; - } int allowedResolutionLevel = getCallerAllowedResolutionLevel(); checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, LocationManager.GPS_PROVIDER); @@ -1813,6 +1810,10 @@ public class LocationManagerService extends ILocationManager.Stub { Binder.restoreCallingIdentity(ident); } + if (mGpsStatusProvider == null) { + return false; + } + try { mGpsStatusProvider.addGpsStatusListener(listener); } catch (RemoteException e) {