Skip to content

Commit 9257192

Browse files
authored
fix: added validation for gps and network provider permissions separately (#317)
1 parent 5a5f200 commit 9257192

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

android/src/main/java/com/reactnativecommunity/geolocation/AndroidLocationManager.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public void onStatusChanged(String provider, int status, Bundle extras) {
4545
}
4646

4747
@Override
48-
public void onProviderEnabled(String provider) { }
48+
public void onProviderEnabled(String provider) {
49+
}
4950

5051
@Override
51-
public void onProviderDisabled(String provider) { }
52+
public void onProviderDisabled(String provider) {
53+
}
5254
};
5355

5456
protected AndroidLocationManager(ReactApplicationContext reactContext) {
@@ -134,7 +136,8 @@ private String getValidProvider(LocationManager locationManager, boolean highAcc
134136
// If it's an enabled provider, but we don't have permissions, ignore it
135137
int finePermission = ContextCompat.checkSelfPermission(mReactContext, android.Manifest.permission.ACCESS_FINE_LOCATION);
136138
int coarsePermission = ContextCompat.checkSelfPermission(mReactContext, android.Manifest.permission.ACCESS_COARSE_LOCATION);
137-
if (provider.equals(LocationManager.GPS_PROVIDER) && (finePermission != PackageManager.PERMISSION_GRANTED && coarsePermission != PackageManager.PERMISSION_GRANTED)) {
139+
if ((provider.equals(LocationManager.GPS_PROVIDER) && finePermission != PackageManager.PERMISSION_GRANTED) ||
140+
(provider.equals(LocationManager.NETWORK_PROVIDER) && coarsePermission != PackageManager.PERMISSION_GRANTED)) {
138141
return null;
139142
}
140143
return provider;
@@ -178,13 +181,16 @@ public void onLocationChanged(Location location) {
178181
}
179182

180183
@Override
181-
public void onStatusChanged(String provider, int status, Bundle extras) {}
184+
public void onStatusChanged(String provider, int status, Bundle extras) {
185+
}
182186

183187
@Override
184-
public void onProviderEnabled(String provider) {}
188+
public void onProviderEnabled(String provider) {
189+
}
185190

186191
@Override
187-
public void onProviderDisabled(String provider) {}
192+
public void onProviderDisabled(String provider) {
193+
}
188194
};
189195
private boolean mTriggered;
190196

@@ -209,11 +215,12 @@ public void invoke(Location location) {
209215

210216
private static final int TWO_MINUTES = 1000 * 60 * 2;
211217

212-
/** Determines whether one Location reading is better than the current Location fix
218+
/**
219+
* Determines whether one Location reading is better than the current Location fix
213220
* taken from Android Examples https://developer.android.com/guide/topics/location/strategies.html
214221
*
215-
* @param location The new Location that you want to evaluate
216-
* @param currentBestLocation The current Location fix, to which you want to compare the new one
222+
* @param location The new Location that you want to evaluate
223+
* @param currentBestLocation The current Location fix, to which you want to compare the new one
217224
*/
218225
private boolean isBetterLocation(Location location, Location currentBestLocation) {
219226
if (currentBestLocation == null) {
@@ -258,7 +265,9 @@ private boolean isBetterLocation(Location location, Location currentBestLocation
258265
return false;
259266
}
260267

261-
/** Checks whether two providers are the same */
268+
/**
269+
* Checks whether two providers are the same
270+
*/
262271
private boolean isSameProvider(String provider1, String provider2) {
263272
if (provider1 == null) {
264273
return provider2 == null;

0 commit comments

Comments
 (0)