mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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: https://github.com/facebook/react-native/pull/10291 Differential Revision: D4163659 Pulled By: cpojer fbshipit-source-id: 18bb4ee7401bc4eac4fcc97341fc2b3a2a0957c9
This commit is contained in:
committed by
Facebook Github Bot
parent
c416b40542
commit
f32dc63546
@@ -8,6 +8,7 @@ rn_android_library(
|
||||
],
|
||||
deps = [
|
||||
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
|
||||
react_native_dep("third-party/android/support/v4:lib-support-v4"),
|
||||
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
||||
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
||||
react_native_target("java/com/facebook/react/bridge:bridge"),
|
||||
|
||||
@@ -9,6 +9,7 @@ package com.facebook.react.modules.location;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
@@ -16,6 +17,7 @@ import android.location.LocationProvider;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
@@ -193,7 +195,7 @@ public class LocationModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getValidProvider(LocationManager locationManager, boolean highAccuracy) {
|
||||
private String getValidProvider(LocationManager locationManager, boolean highAccuracy) {
|
||||
String provider =
|
||||
highAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER;
|
||||
if (!locationManager.isProviderEnabled(provider)) {
|
||||
@@ -204,6 +206,11 @@ public class LocationModule extends ReactContextBaseJavaModule {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// If it's an enabled provider, but we don't have permissions, ignore it
|
||||
int finePermission = ContextCompat.checkSelfPermission(getReactApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION);
|
||||
if (provider.equals(LocationManager.GPS_PROVIDER) && finePermission != PackageManager.PERMISSION_GRANTED) {
|
||||
return null;
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user