Skip to content

Commit 2b7346f

Browse files
mikelambertgrabbou
authored andcommitted
Fix two bugs with Location when not using ACCESS_FINE_LOCATION (#10291)
Summary: Fix two bugs with Location when not using ACCESS_FINE_LOCATION: - If we request highAccuracy=false, because we don't have ACCESS_FINE_LOCATION, but we don't have access to the NETWORK_PROVIDER...then the code should not trigger a SecurityException because it fell-back to using GPS_PROVIDER (which we don't have permission for) - If the device is pre-lollipop, and doesn't have a provider, we should detect this properly instead of letting the pre-lollipop code raise a SecurityException. Unfortunately, SecurityExceptions cannot be caught by the calling JS code. But I am not fixing that one here, instead choosing to fix/obviate the SecurityExceptions altogether. Pull Request resolved: #10291 Differential Revision: D4163659 Pulled By: cpojer fbshipit-source-id: 18bb4ee7401bc4eac4fcc97341fc2b3a2a0957c9
1 parent d7c4c37 commit 2b7346f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/location/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ rn_android_library(
88
],
99
deps = [
1010
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
11+
react_native_dep("third-party/android/support/v4:lib-support-v4"),
1112
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
1213
react_native_dep("third-party/java/jsr-305:jsr-305"),
1314
react_native_target("java/com/facebook/react/bridge:bridge"),

ReactAndroid/src/main/java/com/facebook/react/modules/location/LocationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99

1010
import android.annotation.SuppressLint;
1111
import android.content.Context;
12+
import android.content.pm.PackageManager;
1213
import android.location.Location;
1314
import android.location.LocationListener;
1415
import android.location.LocationManager;
1516
import android.location.LocationProvider;
1617
import android.os.Build;
1718
import android.os.Bundle;
1819
import android.os.Handler;
20+
import android.support.v4.content.ContextCompat;
1921
import com.facebook.common.logging.FLog;
2022
import com.facebook.react.bridge.Arguments;
2123
import com.facebook.react.bridge.Callback;
@@ -193,7 +195,7 @@ public void stopObserving() {
193195
}
194196

195197
@Nullable
196-
private static String getValidProvider(LocationManager locationManager, boolean highAccuracy) {
198+
private String getValidProvider(LocationManager locationManager, boolean highAccuracy) {
197199
String provider =
198200
highAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER;
199201
if (!locationManager.isProviderEnabled(provider)) {
@@ -204,6 +206,11 @@ private static String getValidProvider(LocationManager locationManager, boolean
204206
return null;
205207
}
206208
}
209+
// If it's an enabled provider, but we don't have permissions, ignore it
210+
int finePermission = ContextCompat.checkSelfPermission(getReactApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION);
211+
if (provider.equals(LocationManager.GPS_PROVIDER) && finePermission != PackageManager.PERMISSION_GRANTED) {
212+
return null;
213+
}
207214
return provider;
208215
}
209216

0 commit comments

Comments
 (0)