requestLocationPermission is passed a callback which is never invoked if the user denies permissions. If the user calls startScanning and this happens, the promise returned by startScanning never resolves as the callback is never invoked and no error is propagated to the user application.
startScanning needs to account for requestLocationPermission potentially rejecting and rethrow this error to the caller.
|
public requestLocationPermission(callback?: () => void): Promise<boolean> { |
|
return new Promise((resolve, reject) => { |
|
let permissionCb = (args: AndroidActivityRequestPermissionsEventData) => { |
|
if (args.requestCode === ACCESS_LOCATION_PERMISSION_REQUEST_CODE) { |
|
andApp.off(AndroidApplication.activityRequestPermissionsEvent, permissionCb); |
|
permissionCb = null; |
|
for (let i = 0; i < args.permissions.length; i++) { |
|
if (args.grantResults[i] === android.content.pm.PackageManager.PERMISSION_DENIED) { |
|
reject('Permission denied'); |
|
return; |
|
} |
|
} |
|
|
|
if (callback) { |
|
callback(); |
|
} |
|
resolve(true); |
|
} |
|
}; |
|
|
|
// grab the permission dialog result |
|
andApp.on(AndroidApplication.activityRequestPermissionsEvent, permissionCb); |
|
const neededPermission = sdkVersion < ANDROID10 ? android.Manifest.permission.ACCESS_COARSE_LOCATION : android.Manifest.permission.ACCESS_FINE_LOCATION; |
|
// invoke the permission dialog |
|
androidx.core.app.ActivityCompat.requestPermissions(this._getActivity(), [neededPermission], ACCESS_LOCATION_PERMISSION_REQUEST_CODE); |
|
}); |
|
} |
requestLocationPermissionis passed a callback which is never invoked if the user denies permissions. If the user callsstartScanningand this happens, the promise returned bystartScanningnever resolves as the callback is never invoked and no error is propagated to the user application.startScanningneeds to account forrequestLocationPermissionpotentially rejecting and rethrow this error to the caller.ble/src/ble/index.android.ts
Lines 1235 to 1261 in 9820235