Fix permission handling for internal modules

Update the code that generates <module>-android-dependencies.xml.

Use the correct qt_internal_add_android_permission instead of
setting permissions property manually.

Amends f430c5ae81

Change-Id: Icc46a54f6915bc344afe5507b3244225d750cb7c
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2025-07-15 11:56:16 +02:00
parent 415967b7fa
commit a85ae7094b
5 changed files with 52 additions and 30 deletions

View File

@ -191,21 +191,8 @@ function(qt_internal_android_dependencies_content target file_content_out)
endif()
# Android Permissions
if(arg_PERMISSIONS)
foreach(permission IN LISTS arg_PERMISSIONS)
# Check if the permission has also extra attributes in addition to the permission name
list(LENGTH permission permission_len)
if(permission_len EQUAL 1)
string(APPEND file_contents "<permission name=\"${permission}\" />\n")
elseif(permission_len EQUAL 2)
list(GET permission 0 name)
list(GET permission 1 extras)
string(APPEND file_contents "<permission name=\"${name}\" extras=\"${extras}\"/>\n")
else()
message(FATAL_ERROR "Invalid permission format: ${permission} ${permission_len}")
endif()
endforeach()
endif()
_qt_internal_android_convert_permissions(permissions_string ${target} "DEPENDENCIESXML")
string(APPEND file_contents "${permissions_string}")
# Android Features
if(arg_FEATURES)
@ -482,14 +469,8 @@ function(qt_internal_android_add_interface_permissions target)
return()
endif()
set(postprocessed_permissions "")
foreach(permission IN LISTS permissions)
# TODO: skip processing extras for now, add them back once internal API
# will cover adding extras using internal function.
list(APPEND postprocessed_permissions "name\;${permission}")
endforeach()
qt_internal_set_module_transitive_properties(${target} TYPE LINK PROPERTIES
INTERFACE_QT_ANDROID_PERMISSIONS "${postprocessed_permissions}")
INTERFACE_QT_ANDROID_PERMISSIONS "${permissions}")
endfunction()
# The function stores Android features that are required by the module target.

View File

@ -491,8 +491,11 @@ if(ANDROID)
set_property(TARGET Core APPEND PROPERTY QT_ANDROID_LIB_DEPENDENCIES
${INSTALL_PLUGINSDIR}/platforms/libplugins_platforms_qtforandroid.so
)
set_property(TARGET Core APPEND PROPERTY QT_ANDROID_PERMISSIONS
android.permission.INTERNET android.permission.WRITE_EXTERNAL_STORAGE
qt_internal_add_android_permission(Core
NAME android.permission.WRITE_EXTERNAL_STORAGE
)
qt_internal_add_android_permission(Core
NAME android.permission.INTERNET
)
endif()

View File

@ -25,7 +25,47 @@
#
# `XML`
# Generate XML content compatible with AndroidManifest.xml.
#
# `DEPENDENCIESXML`
# Generate XML content compatible with <module>-android-dependencies.xml.
# This format doesn't produce generator expression, so it should be used in
# the scope finalizer.
function(_qt_internal_android_convert_permissions out_var target type)
if(type STREQUAL "DEPENDENCIESXML")
set(output "")
get_target_property(permissions ${target} QT_ANDROID_PERMISSIONS)
if(NOT permissions)
return()
endif()
foreach(permission IN LISTS permissions)
list(JOIN permission "=\"" permission)
list(LENGTH permission permission_length)
if(permission_length LESS 1)
message(FATAL_ERROR "Invalid QT_ANDROID_PERMISSIONS format for target"
" ${target}: ${arg_PERMISSIONS}")
endif()
list(GET permission 0 permission_name)
string(APPEND output "<permission ${permission_name}\"")
math(EXPR permission_length "${permission_length} - 1")
set(extras_string "")
if(permission_length GREATER_EQUAL 1)
set(attributes "")
foreach(i RANGE 1 ${permission_length})
list(GET permission ${i} permission_attribute)
list(APPEND attributes "android:${permission_attribute}'")
endforeach()
list(JOIN attributes " " attributes)
string(REPLACE "\"" "'" attributes "${attributes}")
set(extras_string " extras=\"${attributes}\"")
endif()
string(APPEND output "${extras_string}/>\n")
endforeach()
set(${out_var} "${output}" PARENT_SCOPE)
return()
endif()
set(permissions_property "$<TARGET_PROPERTY:${target},QT_ANDROID_PERMISSIONS>")
set(permissions_genex "$<$<BOOL:${permissions_property}>:")
if(type STREQUAL "JSON")

View File

@ -38,9 +38,6 @@ set_property(
jar/Qt${QtBase_VERSION_MAJOR}AndroidNetworkInformationBackend.jar
)
set_property(
TARGET
QAndroidNetworkInformationPlugin
APPEND PROPERTY QT_ANDROID_PERMISSIONS
android.permission.ACCESS_NETWORK_STATE
qt_internal_add_android_permission(QAndroidNetworkInformationPlugin
NAME android.permission.ACCESS_NETWORK_STATE
)

View File

@ -87,7 +87,8 @@ void tst_android_deployment_settings::DeploymentSettings_data()
<< "permissions"
<< "[{\"maxSdkVersion\":\"34\",\"minSdkVersion\":\"32\",\"name\":\"PERMISSION_WITH_"
"ATTRIBUTES\"},{\"name\":\"PERMISSION_WITHOUT_ATTRIBUTES\"},{\"name\":\"android."
"permission.INTERNET\"},{\"name\":\"android.permission.WRITE_EXTERNAL_STORAGE\"}]";
"permission.WRITE_EXTERNAL_STORAGE\"},{\"name\":\"android."
"permission.INTERNET\"}]";
}
void tst_android_deployment_settings::DeploymentSettings()