From 5cd6b6a1b628fe628eea5fe33b3e1fa174530153 Mon Sep 17 00:00:00 2001 From: Ye ShanShan Date: Wed, 20 Nov 2024 17:18:02 +0800 Subject: [PATCH] fix: app crashed when parsing Actions for notification as title. Log: as title. pms: TASK-366403 --- panels/notification/bubble/bubbleitem.cpp | 12 +++++++++--- panels/notification/center/notifyitem.cpp | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/panels/notification/bubble/bubbleitem.cpp b/panels/notification/bubble/bubbleitem.cpp index a389b07d8..08b8f1b0a 100644 --- a/panels/notification/bubble/bubbleitem.cpp +++ b/panels/notification/bubble/bubbleitem.cpp @@ -243,12 +243,18 @@ QVariantList BubbleItem::actions() const void BubbleItem::updateActions() { QStringList actions = m_entity.actions(); - const auto defaultIndex = actions.indexOf(QLatin1String("default")); - if (defaultIndex >= 0) { - actions.remove(defaultIndex, 2); + if (actions.contains(QLatin1String("default"))) { + actions.removeAll(QLatin1String("default")); m_defaultAction = QLatin1String("default"); } + Q_ASSERT(actions.size() % 2 != 1); + if (actions.size() % 2 == 1) { + qWarning(notifyLog) << "Actions must be an even number except for default, The notify appName:" << m_entity.appName() + << ", actions:" << m_entity.actions(); + return; + } + QVariantList array; for (int i = 0; i < actions.size(); i += 2) { const auto id = actions[i]; diff --git a/panels/notification/center/notifyitem.cpp b/panels/notification/center/notifyitem.cpp index 4430a61bc..f8534e344 100644 --- a/panels/notification/center/notifyitem.cpp +++ b/panels/notification/center/notifyitem.cpp @@ -117,12 +117,18 @@ QVariantList AppNotifyItem::actions() const void AppNotifyItem::updateActions() { QStringList actions = m_entity.actions(); - const auto defaultIndex = actions.indexOf(QLatin1String("default")); - if (defaultIndex >= 0) { - actions.remove(defaultIndex, 2); + if (actions.contains(QLatin1String("default"))) { + actions.removeAll(QLatin1String("default")); m_defaultAction = QLatin1String("default"); } + Q_ASSERT(actions.size() % 2 != 1); + if (actions.size() % 2 == 1) { + qWarning(notifyLog) << "Actions must be an even number except for default, The notify appName:" << m_entity.appName() + << ", actions:" << m_entity.actions(); + return; + } + QVariantList array; for (int i = 0; i < actions.size(); i += 2) { const auto id = actions[i];