Skip to content

Commit

Permalink
Use approximate location permission (#5665)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1205648422731273/1209434223230239

### Description

### Steps to test this PR

_Grant approximate location permission_
- [x] Fresh install and visit permission.site
- [x] Ask for Location permissions
- [x] Verify Location dialog appears
- [x] Allow permissions
- [x] Verify system dialog is shown
- [x] Allow access to **approximate** location
- [x] Verify location is granted (location button is green)

_Verify SERP can access approximate location_
- [x] Fresh install and search for "cafe nearby"
- [x] Verify Location dialog appears
- [x] Deny permissions
- [x] Verify results are based on IP geolocation and there is no blue
dot on the map indicating your position
- You might want to use VPN to be able to easily tell the difference
between IP geolocation and real approximate location
- [x] Tap on the location icon in the top right corner of the map
- [x] Tap "use location"
- [x] Verify Location dialog appears
- [x] Allow permissions
- [x] Verify system dialog is shown
- [x] Allow access to **approximate** location
- [x] Verify that map has reloaded and your approximate location is
marked with a blue dot.

#### Check following scenarios for regression - no behavior changes are
expected

_Precise location permission granted_
- [x] Fresh install and visit permission.site
- [x] Ask for Location permissions
- [x] Verify Location dialog appears
- [x] Allow permissions
- [x] Verify system dialog is shown
- [x] Allow access to **precise** location
- [x] Verify location is granted (location button is green)

_Location permission not granted_
- [x] Fresh install and visit permission.site
- [x] Ask for Location permissions
- [x] Verify Location dialog appears
- [x] Deny permissions
- [x] Verify location is not granted (location button is red)

_Location permission granted (not system granted)_
- [x] Fresh install and visit permission.site
- [x] Ask for Location permissions
- [x] Verify Location dialog appears
- [x] Allow permissions
- [x] Verify system dialog is shown
- [x] Deny permissions
- [x] Verify location is not granted (location button is red)
- [x] Verify Snackbar appears
- [x] Ask for Location permissions
- [x] Verify system dialog is shown
- [x] Deny permissions
- [x] Verify Settings dialog appears
- [x] Tap on Open Settings
- [x] Verify Device Settings screen opens

### No UI changes

---------

Co-authored-by: Noelia Alcala <nalcalag@gmail.com>
  • Loading branch information
lmac012 and nalcalag authored Feb 21, 2025
1 parent 089dbb1 commit fea8ede
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ class SitePermissionsDialogActivityLauncher @Inject constructor(
systemPermissionGranted()
} else {
systemPermissionsHelper.requestMultiplePermissions(
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION),
// ACCESS_FINE_LOCATION is now considered optional, so ACCESS_COARSE_LOCATION should be first on the list,
// because of how systemPermissionsHelper handles showing rationale dialog in case permissions are rejected.
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ class SystemPermissionsHelperImpl @Inject constructor(
override fun hasCameraPermissionsGranted(): Boolean =
ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED

override fun hasLocationPermissionsGranted(): Boolean {
return ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
}
override fun hasLocationPermissionsGranted(): Boolean =
ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED

override fun registerPermissionLaunchers(
caller: ActivityResultCaller,
Expand All @@ -75,7 +73,8 @@ class SystemPermissionsHelperImpl @Inject constructor(
}

multiplePermissionsLauncher = caller.registerForActivityResult(RequestMultiplePermissions()) {
onResultMultiplePermissionsRequest(it)
val permissionsRequestResult = optimiseLocationPermissions(it)
onResultMultiplePermissionsRequest(permissionsRequestResult)
}
}

Expand All @@ -99,4 +98,15 @@ class SystemPermissionsHelperImpl @Inject constructor(

override fun isPermissionsRejectedForever(activity: Activity): Boolean =
currentPermissionRequested?.let { !ActivityCompat.shouldShowRequestPermissionRationale(activity, it) } ?: true

private fun optimiseLocationPermissions(permissionsRequestedResult: Map<String, Boolean>): Map<String, Boolean> {
val locationPermissions = setOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)

return if (permissionsRequestedResult.keys == locationPermissions) {
// For location permissions request, it is enough for the user to grant access to approximate location
mapOf(Manifest.permission.ACCESS_COARSE_LOCATION to permissionsRequestedResult.getValue(Manifest.permission.ACCESS_COARSE_LOCATION))
} else {
permissionsRequestedResult
}
}
}

0 comments on commit fea8ede

Please sign in to comment.