From f0a7d74e1dd2c1d802aa09d7b8c144599f4a54ce Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 10 May 2022 15:02:43 +0200 Subject: Add permission API backend for macOS and iOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø Change-Id: Ic2a43e1a0c45a91df6101020639f473ffd9454cc Reviewed-by: Tor Arne Vestbø --- examples/corelib/permissions/CMakeLists.txt | 10 +++++ examples/corelib/permissions/Info.plist | 59 +++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 examples/corelib/permissions/Info.plist (limited to 'examples') diff --git a/examples/corelib/permissions/CMakeLists.txt b/examples/corelib/permissions/CMakeLists.txt index bca93b679f..5c9af5f0d9 100644 --- a/examples/corelib/permissions/CMakeLists.txt +++ b/examples/corelib/permissions/CMakeLists.txt @@ -15,6 +15,11 @@ qt_add_executable(permissions main.cpp ) +set_target_properties(permissions PROPERTIES + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist" +) + target_link_libraries(permissions PUBLIC Qt::Core Qt::Gui @@ -26,3 +31,8 @@ install(TARGETS permissions BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) + +if(APPLE AND NOT CMAKE_GENERATOR STREQUAL "Xcode") + add_custom_command(TARGET permissions + POST_BUILD COMMAND codesign -s - permissions.app) +endif() diff --git a/examples/corelib/permissions/Info.plist b/examples/corelib/permissions/Info.plist new file mode 100644 index 0000000000..dce43caf12 --- /dev/null +++ b/examples/corelib/permissions/Info.plist @@ -0,0 +1,59 @@ + + + + + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + APPL + + CFBundleName + ${MACOSX_BUNDLE_BUNDLE_NAME} + CFBundleIdentifier + ${MACOSX_BUNDLE_GUI_IDENTIFIER} + CFBundleExecutable + ${MACOSX_BUNDLE_EXECUTABLE_NAME} + + CFBundleVersion + ${MACOSX_BUNDLE_BUNDLE_VERSION} + CFBundleShortVersionString + ${MACOSX_BUNDLE_SHORT_VERSION_STRING} + + LSMinimumSystemVersion + ${CMAKE_OSX_DEPLOYMENT_TARGET} + + NSHumanReadableCopyright + ${MACOSX_BUNDLE_COPYRIGHT} + + CFBundleIconFile + ${MACOSX_BUNDLE_ICON_FILE} + + CFBundleDevelopmentRegion + English + + NSSupportsAutomaticGraphicsSwitching + + + NSBluetoothAlwaysUsageDescription + Testing BluetoothAlways + NSCalendarsUsageDescription + Testing Calendars + NSCameraUsageDescription + Testing Camera + NSContactsUsageDescription + Testing Contacts + NSHealthShareUsageDescription + Testing HealthShare + NSHealthUpdateUsageDescription + Testing HealthUpdate + NSLocationAlwaysAndWhenInUseUsageDescription + Testing LocationAlwaysAndWhenInUse + NSLocationAlwaysUsageDescription + Testing LocationAlways + NSLocationWhenInUseUsageDescription + Testing LocationWhenInUse + NSMicrophoneUsageDescription + Testing Microphone + + + -- cgit v1.2.3