Skip to content

Commit

Permalink
fix: added validation for gps and network provider permissions separa…
Browse files Browse the repository at this point in the history
…tely (#317)
  • Loading branch information
caghp94 authored Aug 31, 2024
1 parent 5a5f200 commit 9257192
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ public void onStatusChanged(String provider, int status, Bundle extras) {
}

@Override
public void onProviderEnabled(String provider) { }
public void onProviderEnabled(String provider) {
}

@Override
public void onProviderDisabled(String provider) { }
public void onProviderDisabled(String provider) {
}
};

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

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onStatusChanged(String provider, int status, Bundle extras) {
}

@Override
public void onProviderEnabled(String provider) {}
public void onProviderEnabled(String provider) {
}

@Override
public void onProviderDisabled(String provider) {}
public void onProviderDisabled(String provider) {
}
};
private boolean mTriggered;

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

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

/** Determines whether one Location reading is better than the current Location fix
/**
* Determines whether one Location reading is better than the current Location fix
* taken from Android Examples https://developer.android.com/guide/topics/location/strategies.html
*
* @param location The new Location that you want to evaluate
* @param currentBestLocation The current Location fix, to which you want to compare the new one
* @param location The new Location that you want to evaluate
* @param currentBestLocation The current Location fix, to which you want to compare the new one
*/
private boolean isBetterLocation(Location location, Location currentBestLocation) {
if (currentBestLocation == null) {
Expand Down Expand Up @@ -258,7 +265,9 @@ private boolean isBetterLocation(Location location, Location currentBestLocation
return false;
}

/** Checks whether two providers are the same */
/**
* Checks whether two providers are the same
*/
private boolean isSameProvider(String provider1, String provider2) {
if (provider1 == null) {
return provider2 == null;
Expand Down

0 comments on commit 9257192

Please sign in to comment.