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

Perms changes for when #3939 makes it in #134

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Base64;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import com.getcapacitor.FileUtils;
import com.getcapacitor.JSObject;
Expand Down Expand Up @@ -454,20 +453,33 @@ private void returnBase64(PluginCall call, ExifWrapper exif, ByteArrayOutputStre
call.resolve(data);
}

@Nullable
@Override
protected String overrideStateForPermission(Permission permission) {
if (permission.alias().equals("camera")) {
// If the camera permission is defined in the manifest, then we have to prompt the user
// or else we will get a security exception when trying to present the camera. If, however,
// it is not defined in the manifest then we don't need to prompt and it will just work.
if (hasDefinedPermissions(new Permission[] { permission })) {
return null;
} else {
return "granted";
}
@PluginMethod
public void requestPermissions(PluginCall call) {
// If the camera permission is defined in the manifest, then we have to prompt the user
// or else we will get a security exception when trying to present the camera. If, however,
// it is not defined in the manifest then we don't need to prompt and it will just work.
if (hasDefinedPermissions(new String[] { Manifest.permission.CAMERA })) {
// Request all permissions (includes camera)
super.requestPermissions(call);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This did not handle the situation where the app only requested 'camera' permissions. It should be superseded now by the latest changes.

// Camera not needed, just request storage permissions
String[] perms = { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE };

requestPermissions(call, perms, CameraPlugin.CAMERA_REQUEST_PERMISSIONS);
}
return super.overrideStateForPermission(permission);
}

@Override
public JSObject getPermissionStates() {
JSObject permissionStates = super.getPermissionStates();

// If Camera is not in the manifest and therefore not required, say the permission is granted
if (!hasDefinedPermissions(new String[] { Manifest.permission.CAMERA })) {
permissionStates.put("camera", "granted");
}

return permissionStates;
}

@Override
Expand Down