From 993cbef7f41446b550c28fcbb30c5c4a5b40d19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 27 Jun 2023 18:08:00 +0200 Subject: [PATCH] permissions: Handle unknown permission statuses gracefully If an application runs on a macOS or iOS version that introduces new permission statuses that we haven't accounted for, we don't want to crash. Replace Q_UNREACHABLE with a warning and Qt::PermissionStatus::Denied. Pick-to: 6.5 6.6 Change-Id: I063042f510caaa8936742f6195bd455d09c4d9ee Reviewed-by: Volker Hilsheimer --- .../platform/darwin/qdarwinpermissionplugin_bluetooth.mm | 6 ++++-- .../platform/darwin/qdarwinpermissionplugin_calendar.mm | 6 ++++-- .../platform/darwin/qdarwinpermissionplugin_location.mm | 9 ++++++--- .../platform/darwin/qdarwinpermissionplugin_p_p.h | 4 +++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/corelib/platform/darwin/qdarwinpermissionplugin_bluetooth.mm b/src/corelib/platform/darwin/qdarwinpermissionplugin_bluetooth.mm index 01fb638283..0cd375561f 100644 --- a/src/corelib/platform/darwin/qdarwinpermissionplugin_bluetooth.mm +++ b/src/corelib/platform/darwin/qdarwinpermissionplugin_bluetooth.mm @@ -31,7 +31,8 @@ - (Qt::PermissionStatus)currentStatus { - switch (CBCentralManager.authorization) { + auto status = CBCentralManager.authorization; + switch (status) { case CBManagerAuthorizationNotDetermined: return Qt::PermissionStatus::Undetermined; case CBManagerAuthorizationRestricted: @@ -41,7 +42,8 @@ return Qt::PermissionStatus::Granted; } - Q_UNREACHABLE(); + qCWarning(lcPermissions) << "Unknown permission status" << status << "detected in" << self; + return Qt::PermissionStatus::Denied; } - (void)requestPermission:(QPermission)permission withCallback:(PermissionCallback)callback diff --git a/src/corelib/platform/darwin/qdarwinpermissionplugin_calendar.mm b/src/corelib/platform/darwin/qdarwinpermissionplugin_calendar.mm index cf91a4f1cd..a3eddd6d8f 100644 --- a/src/corelib/platform/darwin/qdarwinpermissionplugin_calendar.mm +++ b/src/corelib/platform/darwin/qdarwinpermissionplugin_calendar.mm @@ -18,7 +18,8 @@ - (Qt::PermissionStatus)currentStatus { - switch ([EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent]) { + auto status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent]; + switch (status) { case EKAuthorizationStatusNotDetermined: return Qt::PermissionStatus::Undetermined; case EKAuthorizationStatusRestricted: @@ -33,7 +34,8 @@ #endif } - Q_UNREACHABLE(); + qCWarning(lcPermissions) << "Unknown permission status" << status << "detected in" << self; + return Qt::PermissionStatus::Denied; } - (QStringList)usageDescriptionsFor:(QPermission)permission diff --git a/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm b/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm index ed6acd3c9f..3676ba0963 100644 --- a/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm +++ b/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm @@ -73,7 +73,8 @@ struct PermissionRequest return Qt::PermissionStatus::Denied; } - switch ([self authorizationStatus]) { + auto status = [self authorizationStatus]; + switch (status) { case kCLAuthorizationStatusRestricted: case kCLAuthorizationStatusDenied: return Qt::PermissionStatus::Denied; @@ -89,7 +90,8 @@ struct PermissionRequest #endif } - Q_UNREACHABLE(); + qCWarning(lcPermissions) << "Unknown permission status" << status << "detected in" << self; + return Qt::PermissionStatus::Denied; } - (CLAuthorizationStatus)authorizationStatus @@ -118,7 +120,8 @@ struct PermissionRequest return Qt::PermissionStatus::Denied; } - Q_UNREACHABLE(); + qCWarning(lcPermissions) << "Unknown accuracy status" << status << "detected in" << self; + return Qt::PermissionStatus::Denied; } - (QStringList)usageDescriptionsFor:(QPermission)permission diff --git a/src/corelib/platform/darwin/qdarwinpermissionplugin_p_p.h b/src/corelib/platform/darwin/qdarwinpermissionplugin_p_p.h index 9e4bbe92de..649af06507 100644 --- a/src/corelib/platform/darwin/qdarwinpermissionplugin_p_p.h +++ b/src/corelib/platform/darwin/qdarwinpermissionplugin_p_p.h @@ -83,7 +83,9 @@ Qt::PermissionStatus nativeStatusToQtStatus(NativeStatus status) case Converter::Undetermined: return Qt::PermissionStatus::Undetermined; } - Q_UNREACHABLE(); + qCWarning(lcPermissions) << "Unknown permission status" << status << "detected in" + << QT_STRINGIFY(QT_DARWIN_PERMISSION_PLUGIN); + return Qt::PermissionStatus::Denied; } } // namespace