Repository: kivy/python-for-android

Issue:
Multiple permissions in .p4a
If I use --permission CAMERA,INTERNET just like with --requirements for recipes I get this error:

```
     [aapt] /home/paul/.local/share/python-for-android/dists/testproject/bin/AndroidManifest.xml:31: Tag <uses-permission> attribute name has invalid character ','.    

BUILD FAILED    
/home/paul/android-sdk-linux/tools/ant/build.xml:649: The following error occurred while executing this line:   
/home/paul/android-sdk-linux/tools/ant/build.xml:694: null returned: 1
```

This does work: --permission CAMERA --permission INTERNET but gets annoying for all the permissions I want.
## <bountysource-plugin>

Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/31609792-multiple-permissions-in-p4a?utm_campaign=plugin&utm_content=tracker%2F11371&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F11371&utm_medium=issues&utm_source=github).
</bountysource-plugin>



Discussion:
I see no major reason not to allow this (or maybe a --permissions), if someone would like to make a PR it should be fine.

This could be probably closed after [bdist](https://github.com/kivy/python-for-android/blob/master/pythonforandroid/bdistapk.py) is documented, as there is an option for multiple permissions in bdist since #898 _and_ it makes a usage of p4a much more comportable:

    python <file> apk

rather than:

    p4a --to --infinity --and_beyond

😋 

with a file constructed like [this](https://github.com/kivy/python-for-android/blob/2004698e8b34a67c05a113626a9708ead182a97a/testapps/testlauncher_setup/sdl2.py) + after #965 you could just import the permission groups and put them into the dictionary like this:

    from pythonforandroid import permissions as p
    options = {'apk': {.......
                   'permissions': p.SENSORS + p.NETWORK}}
I'd like to make toolchain.py accept --permissions as well as just the bdist command.

Resolving patch:
diff --git a/pythonforandroid/bootstraps/pygame/build/build.py b/pythonforandroid/bootstraps/pygame/build/build.py
--- a/pythonforandroid/bootstraps/pygame/build/build.py
+++ b/pythonforandroid/bootstraps/pygame/build/build.py
@@ -415,7 +415,7 @@ def parse_args(args=None):
                           'Usually one of "landscape", "portrait" or '
                           '"sensor"'))
     ap.add_argument('--permission', dest='permissions', action='append',
-                    help='The permissions to give this app.')
+                    help='The permissions to give this app.', nargs='+')
     ap.add_argument('--ignore-path', dest='ignore_path', action='append',
                     help='Ignore path when building the app')
     ap.add_argument('--icon', dest='icon',
@@ -488,6 +488,9 @@ def parse_args(args=None):
 
     if args.permissions is None:
         args.permissions = []
+    elif args.permissions:
+        if isinstance(args.permissions[0], list):
+            args.permissions = [p for perm in args.permissions for p in perm]
 
     if args.ignore_path is None:
         args.ignore_path = []
diff --git a/pythonforandroid/bootstraps/sdl2/build/build.py b/pythonforandroid/bootstraps/sdl2/build/build.py
--- a/pythonforandroid/bootstraps/sdl2/build/build.py
+++ b/pythonforandroid/bootstraps/sdl2/build/build.py
@@ -417,7 +417,7 @@ def parse_args(args=None):
     ap.add_argument('--icon', dest='icon',
                     help='A png file to use as the icon for the application.')
     ap.add_argument('--permission', dest='permissions', action='append',
-                    help='The permissions to give this app.')
+                    help='The permissions to give this app.', nargs='+')
     ap.add_argument('--meta-data', dest='meta_data', action='append',
                     help='Custom key=value to add in application metadata')
     ap.add_argument('--presplash', dest='presplash',
@@ -488,6 +488,9 @@ def parse_args(args=None):
 
     if args.permissions is None:
         args.permissions = []
+    elif args.permissions:
+        if isinstance(args.permissions[0], list):
+            args.permissions = [p for perm in args.permissions for p in perm]
 
     if args.meta_data is None:
         args.meta_data = []
diff --git a/pythonforandroid/bootstraps/webview/build/build.py b/pythonforandroid/bootstraps/webview/build/build.py
--- a/pythonforandroid/bootstraps/webview/build/build.py
+++ b/pythonforandroid/bootstraps/webview/build/build.py
@@ -404,7 +404,7 @@ def parse_args(args=None):
     ap.add_argument('--icon', dest='icon',
                     help='A png file to use as the icon for the application.')
     ap.add_argument('--permission', dest='permissions', action='append',
-                    help='The permissions to give this app.')
+                    help='The permissions to give this app.', nargs='+')
     ap.add_argument('--meta-data', dest='meta_data', action='append',
                     help='Custom key=value to add in application metadata')
     ap.add_argument('--presplash', dest='presplash',
@@ -465,6 +465,9 @@ def parse_args(args=None):
 
     if args.permissions is None:
         args.permissions = []
+    elif args.permissions:
+        if isinstance(args.permissions[0], list):
+            args.permissions = [p for perm in args.permissions for p in perm]
 
     if args.meta_data is None:
         args.meta_data = []


Test patch: