1 | /* |
2 | SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org> |
3 | SPDX-License-Identifier: LGPL-2.0-or-later |
4 | */ |
5 | |
6 | #include "knotificationpermission.h" |
7 | #include <qnamespace.h> |
8 | |
9 | #ifdef Q_OS_ANDROID |
10 | #include <QtCore/private/qandroidextras_p.h> |
11 | |
12 | Qt::PermissionStatus KNotificationPermission::checkPermission() |
13 | { |
14 | if (QtAndroidPrivate::androidSdkVersion() < 33) { |
15 | return Qt::PermissionStatus::Granted; |
16 | } |
17 | |
18 | return QtAndroidPrivate::checkPermission(QStringLiteral("" )).result() == QtAndroidPrivate::PermissionResult::Authorized ? Qt::PermissionStatus::Granted |
19 | : Qt::PermissionStatus::Denied; |
20 | } |
21 | |
22 | void KNotificationPermission::requestPermission(QObject *context, const std::function<void(Qt::PermissionStatus)> &callback) |
23 | { |
24 | if (QtAndroidPrivate::androidSdkVersion() < 33) { |
25 | callback(Qt::PermissionStatus::Granted); |
26 | } |
27 | |
28 | QtAndroidPrivate::requestPermission(QStringLiteral("android.permission.POST_NOTIFICATIONS" )) |
29 | .then(context, [&callback](QtAndroidPrivate::PermissionResult res) { |
30 | callback(res == QtAndroidPrivate::PermissionResult::Authorized ? Qt::PermissionStatus::Granted : Qt::PermissionStatus::Denied); |
31 | }); |
32 | } |
33 | |
34 | #else |
35 | Qt::PermissionStatus KNotificationPermission::checkPermission() |
36 | { |
37 | return Qt::PermissionStatus::Granted; |
38 | } |
39 | |
40 | void KNotificationPermission::requestPermission([[maybe_unused]] QObject *context, const std::function<void(Qt::PermissionStatus)> &callback) |
41 | { |
42 | callback(Qt::PermissionStatus::Granted); |
43 | } |
44 | #endif |
45 | |