Skip to content

Support permission properties (maxSdkVersion and usesPermissionFlags) + remove WRITE_EXTERNAL_STORAGE permission, which has been previously declared by default #2725

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

Merged

Conversation

misl6
Copy link
Member

@misl6 misl6 commented Dec 29, 2022

The --permission argument historically only accepted something like --permission android.permission.WRITE_EXTERNAL_STORAGE and --permission VIBRATE which is not enough in certain use cases.

As an example, when dealing with bluetooth permissions and targeting API 31, the legacy android.permission.BLUETOOTH and android.permission.BLUETOOTH_ADMIN permissions need the property android:maxSdkVersion be set to 30, and
the "android.permission.BLUETOOTH_SCAN needs to strongly assert that the app never derives physical location from Bluetooth scan results via android:usesPermissionFlags="neverForLocation".

Basically, nowadays, android permissions declarations need a lot of fine-tuning, which is not possible at this time via python-for-android, unless an extra manifest is used.

This PR introduces a new syntax: --permission (name=android.permission.WRITE_EXTERNAL_STORAGE;maxSdkVersion=18) that allows the user to set every single (and currently available/supported) property of the <uses-permission> element.

The old syntaxes are migrated before the template gets processed, so users will only notice this change when needed, and when reading the docs.

I also started to add some tests for our build.py script. I needed to add a switch to skip some things as ATM are not patchable (at least easily). The whole script needs some refactoring in order to be well-tested.

… + remove WRITE_EXTERNAL_STORAGE permission, which has been previously required by default
@misl6 misl6 force-pushed the fix/reverse-2694-and-add-a-way-to-set-sdkversion branch from ced6f70 to c28ae30 Compare December 29, 2022 16:07
AndreMiras
AndreMiras previously approved these changes Dec 30, 2022
Copy link
Member

@AndreMiras AndreMiras left a comment

Choose a reason for hiding this comment

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

Nice thanks!

Comment on lines +688 to +689
else:
_permissions.append(dict(name=f"android.permission.{permission}"))
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to add a warning in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean a deprecation warning? I thought the same, but then I decided to go with the slow path instead in order to avoid a large increase in support requests (users may start panicking 😀).

I did not officially deprecated it by purpose, instead, I've changed the docs and added a warning regarding "name-only" permissions.

There's a lot of documentation, posts, videos, etc ... which is referring to "name-only" permissions (And we even need to migrate buildozer and python-for-android examples).

What do you think about it?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that makes sense 👍

Comment on lines 83 to 86
try:
parsed_permissions = buildpy.parse_permissions(args.permissions) # noqa: F841
except ValueError as _e:
assert "Property 'propertyThatFails' is not supported." in str(_e)
Copy link
Member

Choose a reason for hiding this comment

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

If the exception isn't raised, the test won't catch it.
So we either want to make it fail explicitly after the parse_permissions() something like self.fail("ValueError not raised") or use something like the pytest.raises context manager e.g. with pytest.raises(ValueError, match="Property 'propertyThatFails' is not supported."):

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for catching this beginner-like error! 😓
Addressed.

@misl6 misl6 merged commit a636b88 into kivy:develop Dec 30, 2022
@misl6 misl6 deleted the fix/reverse-2694-and-add-a-way-to-set-sdkversion branch December 30, 2022 14:31
shyamnathp pushed a commit to shyamnathp/python-for-android that referenced this pull request Feb 17, 2023
…gs`) + remove `WRITE_EXTERNAL_STORAGE` permission, which has been previously declared by default (kivy#2725)

* Support permission properties (maxSdkVersion and usesPermissionFlags) + remove WRITE_EXTERNAL_STORAGE permission, which has been previously required by default

* Fix test for ValueError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants