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

feat(android): modified plugin annotation format for multi-permissions and empty (auto-grant) #3822

Merged
merged 6 commits into from
Nov 19, 2020

Conversation

carlpoole
Copy link
Member

Allows for the following annotation formats for permissions:

Multiple permissions can be grouped within the same @Permission sub-annotation and alias.

@CapacitorPlugin(
    name = "Geolocation",
    permissions = {
        @Permission(permission = { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION }, alias = "location")
    },
    permissionRequestCode = GeolocationPlugin.GEOLOCATION_REQUEST_PERMISSIONS
)

Permission element can be omitted to define a permission that should be auto-granted. Useful when another platform has the permission but Android does not.

@CapacitorPlugin(
    name = "Notifications",
    permissions = {
        @Permission(permission = {}, alias = "notifications")
    }
)

perms[i] = annotation.permissions()[i].permission();
HashSet<String> permsSet = new HashSet<>();
for (Permission perm : annotation.permissions()) {
// If a permission is defined with no permission constants, separate it for auto-granting.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still confused as to why this part is necessary: (perm.permission().length == 1 && perm.permission()[0].isEmpty())

It is handling this case?

@Permission(permission = {""}, alias = ...

Copy link
Member Author

Choose a reason for hiding this comment

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

yes or this valid definition

@Permission(permission = "", alias = ...

which on the back end translates to an array containing one empty element

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's switch to Kotlin.

@imhoffd imhoffd merged commit 1b5a3bd into main Nov 19, 2020
@imhoffd imhoffd deleted the perm-fix branch November 19, 2020 21:06
@imhoffd imhoffd added this to In progress 🤺 in Capacitor Engineering ⚡️ via automation Nov 19, 2020
@imhoffd imhoffd added this to the 3.0.0 milestone Nov 19, 2020
@imhoffd imhoffd moved this from In progress 🤺 to Done 🎉 in Capacitor Engineering ⚡️ Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants