Skip to content

Commit

Permalink
bugfix: Camera plugin allows to access the photo gallery and pick the…
Browse files Browse the repository at this point in the history
… photo(s) even if the user has not granted the required permission

For details please see ionic-team/capacitor#7320
  • Loading branch information
ryaa committed Mar 7, 2024
1 parent d5483ce commit db9f0ec
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,24 @@ private boolean checkPhotosPermissions(PluginCall call) {
@PermissionCallback
private void cameraPermissionsCallback(PluginCall call) {
if (call.getMethodName().equals("pickImages")) {
openPhotos(call, true, true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
if (getPermissionState(PHOTOS) != PermissionState.GRANTED) {
Logger.debug(getLogTag(), "User denied photos permission: " + getPermissionState(PHOTOS).toString());
call.reject(PERMISSION_DENIED_ERROR_PHOTOS);
return;
}
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
if (getPermissionState(READ_EXTERNAL_STORAGE) != PermissionState.GRANTED) {
Logger.debug(getLogTag(), "User denied photos permission: " + getPermissionState(READ_EXTERNAL_STORAGE).toString());
call.reject(PERMISSION_DENIED_ERROR_PHOTOS);
return;
}
} else if (getPermissionState(MEDIA) != PermissionState.GRANTED) {
Logger.debug(getLogTag(), "User denied photos permission: " + getPermissionState(MEDIA).toString());
call.reject(PERMISSION_DENIED_ERROR_PHOTOS);
return;
}
openPhotos(call, true, true);
} else {
if (settings.getSource() == CameraSource.CAMERA && getPermissionState(CAMERA) != PermissionState.GRANTED) {
Logger.debug(getLogTag(), "User denied camera permission: " + getPermissionState(CAMERA).toString());
Expand Down

0 comments on commit db9f0ec

Please sign in to comment.