diff options
author | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2023-04-28 14:00:23 +0200 |
---|---|---|
committer | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2023-09-05 14:14:09 +0200 |
commit | 9c292a60196fc4ab0c87995d42d5416c32c667a9 (patch) | |
tree | 6728d32c13901fdb5473e8852be5edf294e47a94 /sources/pyside-tools/deploy_lib | |
parent | 394e42ce2af7d939283ceb386ab7904c738dd4c4 (diff) |
Android Deployment: Add App Permissions
- App runtime permissions are fetched from the corresponding Android
dependency xml file based on the Qt modules used.
* The Android wheels for PySide6 bundles these dependency files which
are located in `lib`.
* The dependency files also contain important information like the
other dependent libraries, jars and plugins for each module.
* The `zipfile` Python module is used to read the contents of these
dependency xml files without extracting the PySide Android wheel.
- The reference branch for python-for-android is changed from
`pyside_support` to `pyside_support_2` to prevent failures in already
released technical preview of pyside6-android-deploy. This will be
changed when my patch for Qt support in python-for-android is merged.
- Docstring is added to AndroidData class.
Task-number: PYSIDE-1612
Change-Id: I63eb90e2f7f264e2f1d63af21cfd329eb7466e3f
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools/deploy_lib')
-rw-r--r-- | sources/pyside-tools/deploy_lib/android/android_helper.py | 3 | ||||
-rw-r--r-- | sources/pyside-tools/deploy_lib/android/buildozer.py | 59 |
2 files changed, 58 insertions, 4 deletions
diff --git a/sources/pyside-tools/deploy_lib/android/android_helper.py b/sources/pyside-tools/deploy_lib/android/android_helper.py index b93fcdbdc..321fc3734 100644 --- a/sources/pyside-tools/deploy_lib/android/android_helper.py +++ b/sources/pyside-tools/deploy_lib/android/android_helper.py @@ -10,6 +10,9 @@ from dataclasses import dataclass @dataclass class AndroidData: + """ + Dataclass to store all the Android data obtained through cli + """ wheel_pyside: Path wheel_shiboken: Path ndk_path: Path diff --git a/sources/pyside-tools/deploy_lib/android/buildozer.py b/sources/pyside-tools/deploy_lib/android/buildozer.py index 2ebd49d1a..e49bbe80f 100644 --- a/sources/pyside-tools/deploy_lib/android/buildozer.py +++ b/sources/pyside-tools/deploy_lib/android/buildozer.py @@ -2,8 +2,12 @@ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only import logging +import xml.etree.ElementTree as ET +import zipfile from pathlib import Path -from .. import run_command, BaseConfig, Config +from typing import List + +from .. import MAJOR_VERSION, BaseConfig, Config, run_command class BuildozerConfig(BaseConfig): @@ -20,6 +24,7 @@ class BuildozerConfig(BaseConfig): self.set_value("app", "requirements", "python3,shiboken6,PySide6") + # android platform specific if pysidedeploy_config.ndk_path: self.set_value("app", "android.ndk_path", str(pysidedeploy_config.ndk_path)) @@ -32,14 +37,14 @@ class BuildozerConfig(BaseConfig): "armv7a": "armeabi-v7a", "i686": "x86", "x86_64": "x86_64"} - arch = platform_map[pysidedeploy_config.arch] - self.set_value("app", "android.archs", arch) + self.arch = platform_map[pysidedeploy_config.arch] + self.set_value("app", "android.archs", self.arch) # p4a changes logging.info("[DEPLOY] Using custom fork of python-for-android: " "https://github.com/shyamnathp/python-for-android/tree/pyside_support") self.set_value("app", "p4a.fork", "shyamnathp") - self.set_value("app", "p4a.branch", "pyside_support") + self.set_value("app", "p4a.branch", "pyside_support_2") self.set_value('app', "p4a.local_recipes", str(pysidedeploy_config.recipe_dir)) self.set_value("app", "p4a.bootstrap", "qt") @@ -48,6 +53,11 @@ class BuildozerConfig(BaseConfig): extra_args = (f"--qt-libs={modules} --load-local-libs={local_libs}") self.set_value("app", "p4a.extra_args", extra_args) + dependency_files = self.__get_dependency_files(pysidedeploy_config) + permissions = self.__find_permissions(dependency_files) + permissions = ", ".join(permissions) + self.set_value("app", "android.permissions", permissions) + # TODO: does not work atm. Seems like a bug with buildozer # change buildozer build_dir # self.set_value("buildozer", "build_dir", str(build_dir.relative_to(Path.cwd()))) @@ -57,6 +67,47 @@ class BuildozerConfig(BaseConfig): self.update_config() + def __get_dependency_files(self, pysidedeploy_config: Config) -> List[zipfile.Path]: + """ + Based on pysidedeploy_config.modules, returns the + Qt6{module}_{arch}-android-dependencies.xml file, which contains the various + dependencies of the module, like permissions, plugins etc + """ + dependency_files = [] + needed_dependency_files = [(f"Qt{MAJOR_VERSION}{module}_{self.arch}" + "-android-dependencies.xml") for module in + pysidedeploy_config.modules] + archive = zipfile.ZipFile(pysidedeploy_config.wheel_pyside) + + # find parent path to dependency files in the wheel + dependency_parent_path = None + for file in archive.namelist(): + if file.endswith("android-dependencies.xml"): + dependency_parent_path = Path(file).parent + # all dependency files are in the same path + break + + for dependency_file_name in needed_dependency_files: + dependency_file = dependency_parent_path / dependency_file_name + # convert from pathlib.Path to zipfile.Path + dependency_file = zipfile.Path(archive, at=str(dependency_file)) + + if dependency_file.exists(): + dependency_files.append(dependency_file) + + logging.info(f"[DEPLOY] The following dependency files were found: {*dependency_files,}") + + return dependency_files + + def __find_permissions(self, dependency_files: List[zipfile.Path]): + permissions = set() + for dependency_file in dependency_files: + xml_content = dependency_file.read_text() + root = ET.fromstring(xml_content) + for permission in root.iter("permission"): + permissions.add(permission.attrib['name']) + return permissions + class Buildozer: dry_run = False |