Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(android) startScanning unhandled rejection if user denies location permissions #265

Open
delaneyb opened this issue Feb 11, 2023 · 0 comments

Comments

@delaneyb
Copy link

delaneyb commented Feb 11, 2023

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.

ble/src/ble/index.android.ts

Lines 1235 to 1261 in 9820235

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);
});
}

@delaneyb delaneyb changed the title startScanning unhandled rejection if user denies location permissions (android) startScanning unhandled rejection if user denies location permissions Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant