diff --git a/cordova-plugin-moodleapp/src/ts/plugins/Diagnostic.ts b/cordova-plugin-moodleapp/src/ts/plugins/Diagnostic.ts index 9ac2f3aebf0..fecf21c3d2e 100644 --- a/cordova-plugin-moodleapp/src/ts/plugins/Diagnostic.ts +++ b/cordova-plugin-moodleapp/src/ts/plugins/Diagnostic.ts @@ -116,15 +116,20 @@ export class Diagnostic { permission.accessFineLocation, permission.accessBackgroundLocation, ]).then(statuses => { + const coarseStatus = statuses[permission.accessCoarseLocation]; + const fineStatus = statuses[permission.accessFineLocation]; const backgroundStatus = typeof statuses[permission.accessBackgroundLocation] !== 'undefined' ? statuses[permission.accessBackgroundLocation] : true; - let status = this.combinePermissionStatuses({ - [permission.accessCoarseLocation]: statuses[permission.accessCoarseLocation], - [permission.accessFineLocation]: statuses[permission.accessFineLocation], - }); - if (status === permissionStatus.granted && backgroundStatus !== permissionStatus.granted) { - status = permissionStatus.grantedWhenInUse; + let status: string = permissionStatus.notRequested; + + if (coarseStatus === permissionStatus.granted || fineStatus === permissionStatus.granted) { + status = backgroundStatus === permissionStatus.granted ? + permissionStatus.granted : 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); @@ -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 { - 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, 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. * diff --git a/src/core/services/geolocation.ts b/src/core/services/geolocation.ts index 5974f5de55d..29f2600d0ea 100644 --- a/src/core/services/geolocation.ts +++ b/src/core/services/geolocation.ts @@ -125,7 +125,7 @@ export class CoreGeolocationProvider { case diagnostic.permissionStatus.granted: case diagnostic.permissionStatus.grantedWhenInUse: // Location is authorized. - return; + return; case diagnostic.permissionStatus.deniedOnce: if (failOnDeniedOnce) {