MOBILE-4470 location: Improve handling approximate location

main
Dani Palou 2024-06-17 10:07:56 +02:00
parent 68bd0952e1
commit 1e2851225f
2 changed files with 12 additions and 46 deletions

View File

@ -116,15 +116,20 @@ export class Diagnostic {
permission.accessFineLocation, permission.accessFineLocation,
permission.accessBackgroundLocation, permission.accessBackgroundLocation,
]).then(statuses => { ]).then(statuses => {
const coarseStatus = statuses[permission.accessCoarseLocation];
const fineStatus = statuses[permission.accessFineLocation];
const backgroundStatus = typeof statuses[permission.accessBackgroundLocation] !== 'undefined' ? const backgroundStatus = typeof statuses[permission.accessBackgroundLocation] !== 'undefined' ?
statuses[permission.accessBackgroundLocation] : true; statuses[permission.accessBackgroundLocation] : true;
let status = this.combinePermissionStatuses({ let status: string = permissionStatus.notRequested;
[permission.accessCoarseLocation]: statuses[permission.accessCoarseLocation],
[permission.accessFineLocation]: statuses[permission.accessFineLocation], if (coarseStatus === permissionStatus.granted || fineStatus === permissionStatus.granted) {
}); status = backgroundStatus === permissionStatus.granted ?
if (status === permissionStatus.granted && backgroundStatus !== permissionStatus.granted) { permissionStatus.granted : permissionStatus.grantedWhenInUse;
status = permissionStatus.grantedWhenInUse; } else if (coarseStatus === permissionStatus.deniedOnce || fineStatus === permissionStatus.deniedOnce) {
status = permissionStatus.deniedOnce;
} else if (coarseStatus === permissionStatus.deniedAlways || fineStatus === permissionStatus.deniedAlways) {
status = permissionStatus.deniedAlways;
} }
resolve(status); resolve(status);
@ -204,45 +209,6 @@ export class Diagnostic {
}); });
} }
/**
* Given a list of permissions and their statuses, returns the combined status.
*
* @param statuses Permissions with statuses.
* @returns Combined status.
*/
protected combinePermissionStatuses(statuses: Record<string, string>): string {
if (this.anyStatusIs(statuses, permissionStatus.deniedAlways)) {
return permissionStatus.deniedAlways;
}
if (this.anyStatusIs(statuses, permissionStatus.deniedOnce)) {
return permissionStatus.deniedOnce;
}
if (this.anyStatusIs(statuses, permissionStatus.granted)) {
return permissionStatus.granted;
}
return permissionStatus.notRequested;
}
/**
* Check if any of the permissions in the statuses object has the specified status.
*
* @param statuses Permissions with status for each permission.
* @param status Status to check.
* @returns True if any permission has the specified status.
*/
protected anyStatusIs(statuses: Record<string, string>, status: string): boolean {
for (const permission in statuses) {
if (statuses[permission] === status) {
return true;
}
}
return false;
}
/** /**
* Android only. Requests app to be granted authorisation for a runtime permission. * Android only. Requests app to be granted authorisation for a runtime permission.
* *