summaryrefslogtreecommitdiffstats
path: root/tests/manual/permissions
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2022-05-10 15:02:43 +0200
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2022-11-03 15:02:36 +0100
commitf0a7d74e1dd2c1d802aa09d7b8c144599f4a54ce (patch)
tree31a684f2f8f63eaef4f07fee98ebe0bc4a6bd87d /tests/manual/permissions
parent1c6bf3e09ea9722717caedcfcceaaf3d607615cf (diff)
Add permission API backend for macOS and iOS
When submitting applications to the iOS and macOS AppStore the application goes through static analysis, which will trigger on uses of various privacy protected APIs, unless the application has a corresponding usage description for the permission in the Info.plist file. This applies even if the application never requests the given permission, but just links to a Qt library that has the offending symbols or library dependencies. To ensure that the application does not have to add usage descriptions to their Info.plist for permissions they never plan to use we split up the various permission implementations into small static libraries that register with the Qt plugin mechanism as permission backends. We can then inspect the application's Info.plist at configure time and only add the relevant static permission libraries. Furthermore, since some permissions can be checked without any usage description, we allow the implementation to be split up into two separate translation units. By putting the request in its own translation unit we can selectively include it during linking by telling the linker to look for a special symbol. This is useful for libraries such as Qt Multimedia who would like to check the current permission status, but without needing to request any permission of its own. Done-with: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Change-Id: Ic2a43e1a0c45a91df6101020639f473ffd9454cc Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/manual/permissions')
-rw-r--r--tests/manual/permissions/CMakeLists.txt49
-rw-r--r--tests/manual/permissions/Info.plist59
-rw-r--r--tests/manual/permissions/tst_qpermissions.cpp5
3 files changed, 113 insertions, 0 deletions
diff --git a/tests/manual/permissions/CMakeLists.txt b/tests/manual/permissions/CMakeLists.txt
index 847d9a7411..50ec89665f 100644
--- a/tests/manual/permissions/CMakeLists.txt
+++ b/tests/manual/permissions/CMakeLists.txt
@@ -5,3 +5,52 @@ qt_internal_add_test(tst_qpermissions
LIBRARIES
Qt::CorePrivate
)
+
+if (APPLE)
+ # Test an app bundle, but without any usage descriptions
+
+ qt_internal_add_test(tst_qpermissions_app
+ SOURCES
+ tst_qpermissions.cpp
+ DEFINES
+ tst_QPermissions=tst_QPermissionsApp
+ LIBRARIES
+ Qt::CorePrivate
+ )
+
+ set_property(TARGET tst_qpermissions_app
+ PROPERTY MACOSX_BUNDLE TRUE)
+ set_property(TARGET tst_qpermissions_app
+ PROPERTY MACOSX_BUNDLE_GUI_IDENTIFIER "io.qt.dev.tst_permissions_app")
+
+ # Test an app bundle with all the required usage descriptions
+
+ qt_internal_add_test(tst_qpermissions_app_with_usage_descriptions
+ SOURCES
+ tst_qpermissions.cpp
+ DEFINES
+ tst_QPermissions=tst_QPermissionsAppWithUsageDescriptions
+ HAVE_USAGE_DESCRIPTION=1
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ )
+
+ set_property(TARGET tst_qpermissions_app_with_usage_descriptions
+ PROPERTY MACOSX_BUNDLE TRUE)
+ set_property(TARGET tst_qpermissions_app_with_usage_descriptions
+ PROPERTY MACOSX_BUNDLE_GUI_IDENTIFIER "io.qt.dev.tst_qpermissions_app_with_usage_descriptions")
+ set_property(TARGET tst_qpermissions_app_with_usage_descriptions
+ PROPERTY MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist")
+
+ foreach(permission_plugin IN LISTS QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_permissions)
+ set(permission_plugin "${QT_CMAKE_EXPORT_NAMESPACE}::${permission_plugin}")
+ qt6_import_plugins(tst_qpermissions_app INCLUDE ${permission_plugin})
+ qt6_import_plugins(tst_qpermissions_app_with_usage_descriptions INCLUDE ${permission_plugin})
+ endforeach()
+
+ if(NOT CMAKE_GENERATOR STREQUAL "Xcode")
+ add_custom_command(TARGET tst_qpermissions_app_with_usage_descriptions
+ POST_BUILD COMMAND codesign -s - tst_qpermissions_app_with_usage_descriptions.app)
+ endif()
+endif()
diff --git a/tests/manual/permissions/Info.plist b/tests/manual/permissions/Info.plist
new file mode 100644
index 0000000000..dce43caf12
--- /dev/null
+++ b/tests/manual/permissions/Info.plist
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+
+ <key>CFBundleName</key>
+ <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
+ <key>CFBundleExecutable</key>
+ <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
+
+ <key>CFBundleVersion</key>
+ <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
+ <key>CFBundleShortVersionString</key>
+ <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
+
+ <key>LSMinimumSystemVersion</key>
+ <string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string>
+
+ <key>NSHumanReadableCopyright</key>
+ <string>${MACOSX_BUNDLE_COPYRIGHT}</string>
+
+ <key>CFBundleIconFile</key>
+ <string>${MACOSX_BUNDLE_ICON_FILE}</string>
+
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+
+ <key>NSSupportsAutomaticGraphicsSwitching</key>
+ <true/>
+
+ <key>NSBluetoothAlwaysUsageDescription</key>
+ <string>Testing BluetoothAlways</string>
+ <key>NSCalendarsUsageDescription</key>
+ <string>Testing Calendars</string>
+ <key>NSCameraUsageDescription</key>
+ <string>Testing Camera</string>
+ <key>NSContactsUsageDescription</key>
+ <string>Testing Contacts</string>
+ <key>NSHealthShareUsageDescription</key>
+ <string>Testing HealthShare</string>
+ <key>NSHealthUpdateUsageDescription</key>
+ <string>Testing HealthUpdate</string>
+ <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
+ <string>Testing LocationAlwaysAndWhenInUse</string>
+ <key>NSLocationAlwaysUsageDescription</key>
+ <string>Testing LocationAlways</string>
+ <key>NSLocationWhenInUseUsageDescription</key>
+ <string>Testing LocationWhenInUse</string>
+ <key>NSMicrophoneUsageDescription</key>
+ <string>Testing Microphone</string>
+
+</dict>
+</plist>
diff --git a/tests/manual/permissions/tst_qpermissions.cpp b/tests/manual/permissions/tst_qpermissions.cpp
index a97afe8487..db8d968b5a 100644
--- a/tests/manual/permissions/tst_qpermissions.cpp
+++ b/tests/manual/permissions/tst_qpermissions.cpp
@@ -9,6 +9,11 @@
#include <QtCore/qwaitcondition.h>
#include <QtCore/qtimer.h>
+#if defined(Q_OS_MACOS) && defined(QT_BUILD_INTERNAL)
+#include <private/qcore_mac_p.h>
+Q_CONSTRUCTOR_FUNCTION(qt_mac_ensureResponsible);
+#endif
+
class tst_QPermissions : public QObject
{
Q_OBJECT