-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
misl6
merged 2 commits into
kivy:develop
from
misl6:fix/reverse-2694-and-add-a-way-to-set-sdkversion
Dec 30, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import unittest | ||
import pytest | ||
import os | ||
import argparse | ||
|
||
from pythonforandroid.util import load_source | ||
|
||
|
||
class TestParsePermissions(unittest.TestCase): | ||
def test_parse_permissions_with_migrations(self): | ||
# Test that permissions declared in the old format are migrated to the | ||
# new format. | ||
# (Users can new declare permissions in both formats, even a mix) | ||
os.environ["P4A_BUILD_IS_RUNNING_UNITTESTS"] = "1" | ||
|
||
ap = argparse.ArgumentParser() | ||
ap.add_argument( | ||
"--permission", | ||
dest="permissions", | ||
action="append", | ||
default=[], | ||
help="The permissions to give this app.", | ||
nargs="+", | ||
) | ||
|
||
args = [ | ||
"--permission", | ||
"INTERNET", | ||
"--permission", | ||
"com.android.voicemail.permission.ADD_VOICEMAIL", | ||
"--permission", | ||
"(name=android.permission.WRITE_EXTERNAL_STORAGE;maxSdkVersion=18)", | ||
"--permission", | ||
"(name=android.permission.BLUETOOTH_SCAN;usesPermissionFlags=neverForLocation)", | ||
] | ||
|
||
args = ap.parse_args(args) | ||
|
||
build_src = os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), | ||
"../pythonforandroid/bootstraps/common/build/build.py", | ||
) | ||
|
||
buildpy = load_source("buildpy", build_src) | ||
parsed_permissions = buildpy.parse_permissions(args.permissions) | ||
|
||
assert parsed_permissions == [ | ||
dict(name="android.permission.INTERNET"), | ||
dict(name="com.android.voicemail.permission.ADD_VOICEMAIL"), | ||
dict(name="android.permission.WRITE_EXTERNAL_STORAGE", maxSdkVersion="18"), | ||
dict( | ||
name="android.permission.BLUETOOTH_SCAN", | ||
usesPermissionFlags="neverForLocation", | ||
), | ||
] | ||
|
||
def test_parse_permissions_invalid_property(self): | ||
os.environ["P4A_BUILD_IS_RUNNING_UNITTESTS"] = "1" | ||
|
||
ap = argparse.ArgumentParser() | ||
ap.add_argument( | ||
"--permission", | ||
dest="permissions", | ||
action="append", | ||
default=[], | ||
help="The permissions to give this app.", | ||
nargs="+", | ||
) | ||
|
||
args = [ | ||
"--permission", | ||
"(name=android.permission.BLUETOOTH_SCAN;propertyThatFails=neverForLocation)", | ||
] | ||
|
||
args = ap.parse_args(args) | ||
|
||
build_src = os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), | ||
"../pythonforandroid/bootstraps/common/build/build.py", | ||
) | ||
|
||
buildpy = load_source("buildpy", build_src) | ||
|
||
with pytest.raises( | ||
ValueError, match="Property 'propertyThatFails' is not supported." | ||
): | ||
buildpy.parse_permissions(args.permissions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
andpython-for-android
examples).What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense 👍