From 16903b508819c6e5b0b64a701104460d0f65f3e7 Mon Sep 17 00:00:00 2001 From: markYao Date: Thu, 19 Oct 2023 23:08:57 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E5=AE=9E=E6=97=B6=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: markYao --- frameworks/ans/BUILD.gn | 8 + .../ans/src/notification_button_option.cpp | 103 +++++++ frameworks/ans/src/notification_capsule.cpp | 166 ++++++++++ frameworks/ans/src/notification_helper.cpp | 11 + .../notification_local_activity_button.cpp | 221 ++++++++++++++ .../notification_local_activity_content.cpp | 213 +++++++++++++ ...notification_local_activity_subscriber.cpp | 106 +++++++ frameworks/ans/src/notification_progress.cpp | 148 +++++++++ .../core/include/ans_manager_interface.h | 23 ++ frameworks/core/include/ans_manager_proxy.h | 23 ++ frameworks/core/include/ans_manager_stub.h | 18 ++ frameworks/core/include/ans_notification.h | 29 ++ .../ans_subscriber_local_activity_interface.h | 56 ++++ .../ans_subscriber_local_activity_proxy.h | 68 +++++ .../ans_subscriber_local_activity_stub.h | 67 +++++ ..._notification_service_ipc_interface_code.h | 3 + frameworks/core/src/ans_manager_proxy.cpp | 93 ++++++ frameworks/core/src/ans_manager_stub.cpp | 78 +++++ frameworks/core/src/ans_notification.cpp | 42 +++ .../ans_subscriber_local_activity_proxy.cpp | 118 ++++++++ .../ans_subscriber_local_activity_stub.cpp | 131 ++++++++ .../ans_notification_branch_test.cpp | 12 + .../inner_api/notification_button_option.h | 99 ++++++ interfaces/inner_api/notification_capsule.h | 117 ++++++++ interfaces/inner_api/notification_content.h | 17 +- interfaces/inner_api/notification_helper.h | 27 ++ .../notification_local_activity_button.h | 107 +++++++ .../notification_local_activity_content.h | 93 ++++++ .../notification_local_activity_subscriber.h | 96 ++++++ interfaces/inner_api/notification_progress.h | 113 +++++++ services/ans/BUILD.gn | 1 + .../include/advanced_notification_service.h | 22 ++ ...cation_local_activity_subscriber_manager.h | 112 +++++++ .../ans/src/advanced_notification_service.cpp | 80 +++++ ...tion_local_activity_subscriber_manager.cpp | 283 ++++++++++++++++++ services/ans/src/reminder_data_manager.cpp | 14 +- 36 files changed, 2916 insertions(+), 2 deletions(-) create mode 100644 frameworks/ans/src/notification_button_option.cpp create mode 100644 frameworks/ans/src/notification_capsule.cpp create mode 100644 frameworks/ans/src/notification_local_activity_button.cpp create mode 100644 frameworks/ans/src/notification_local_activity_content.cpp create mode 100644 frameworks/ans/src/notification_local_activity_subscriber.cpp create mode 100644 frameworks/ans/src/notification_progress.cpp create mode 100644 frameworks/core/include/ans_subscriber_local_activity_interface.h create mode 100644 frameworks/core/include/ans_subscriber_local_activity_proxy.h create mode 100644 frameworks/core/include/ans_subscriber_local_activity_stub.h create mode 100644 frameworks/core/src/ans_subscriber_local_activity_proxy.cpp create mode 100644 frameworks/core/src/ans_subscriber_local_activity_stub.cpp create mode 100644 interfaces/inner_api/notification_button_option.h create mode 100644 interfaces/inner_api/notification_capsule.h create mode 100644 interfaces/inner_api/notification_local_activity_button.h create mode 100644 interfaces/inner_api/notification_local_activity_content.h create mode 100644 interfaces/inner_api/notification_local_activity_subscriber.h create mode 100644 interfaces/inner_api/notification_progress.h create mode 100644 services/ans/include/notification_local_activity_subscriber_manager.h create mode 100644 services/ans/src/notification_local_activity_subscriber_manager.cpp diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 92524efdd..e468f53aa 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -54,6 +54,8 @@ ohos_shared_library("ans_innerkits") { "${core_path}/src/ans_manager_proxy.cpp", "${core_path}/src/ans_manager_stub.cpp", "${core_path}/src/ans_notification.cpp", + "${core_path}/src/ans_subscriber_local_activity_proxy.cpp", + "${core_path}/src/ans_subscriber_local_activity_stub.cpp", "${core_path}/src/ans_subscriber_proxy.cpp", "${core_path}/src/ans_subscriber_stub.cpp", "${frameworks_module_ans_path}/src/badge_number_callback_data.cpp", @@ -63,6 +65,8 @@ ohos_shared_library("ans_innerkits") { "${frameworks_module_ans_path}/src/notification_action_button.cpp", "${frameworks_module_ans_path}/src/notification_basic_content.cpp", "${frameworks_module_ans_path}/src/notification_bundle_option.cpp", + "${frameworks_module_ans_path}/src/notification_button_option.cpp", + "${frameworks_module_ans_path}/src/notification_capsule.cpp", "${frameworks_module_ans_path}/src/notification_constant.cpp", "${frameworks_module_ans_path}/src/notification_content.cpp", "${frameworks_module_ans_path}/src/notification_conversational_content.cpp", @@ -71,11 +75,15 @@ ohos_shared_library("ans_innerkits") { "${frameworks_module_ans_path}/src/notification_do_not_disturb_date.cpp", "${frameworks_module_ans_path}/src/notification_flags.cpp", "${frameworks_module_ans_path}/src/notification_helper.cpp", + "${frameworks_module_ans_path}/src/notification_local_activity_button.cpp", + "${frameworks_module_ans_path}/src/notification_local_activity_content.cpp", + "${frameworks_module_ans_path}/src/notification_local_activity_subscriber.cpp", "${frameworks_module_ans_path}/src/notification_long_text_content.cpp", "${frameworks_module_ans_path}/src/notification_media_content.cpp", "${frameworks_module_ans_path}/src/notification_multiline_content.cpp", "${frameworks_module_ans_path}/src/notification_normal_content.cpp", "${frameworks_module_ans_path}/src/notification_picture_content.cpp", + "${frameworks_module_ans_path}/src/notification_progress.cpp", "${frameworks_module_ans_path}/src/notification_request.cpp", "${frameworks_module_ans_path}/src/notification_slot.cpp", "${frameworks_module_ans_path}/src/notification_sorting.cpp", diff --git a/frameworks/ans/src/notification_button_option.cpp b/frameworks/ans/src/notification_button_option.cpp new file mode 100644 index 000000000..677e07082 --- /dev/null +++ b/frameworks/ans/src/notification_button_option.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_button_option.h" + +#include // for basic_string, operator+, basic_string<>... +#include // for shared_ptr, shared_ptr<>::element_type + + +#include "ans_image_util.h" +#include "ans_log_wrapper.h" +#include "nlohmann/json.hpp" // for json, basic_json<>::object_t, basic_json +#include "parcel.h" // for Parcel + +namespace OHOS { +namespace Notification { + +void NotificationButtonOption::SetButtonName(const std::string &buttonName) +{ + buttonName_ = buttonName; +} + +std::string NotificationButtonOption::GetButtonName() const +{ + return buttonName_; +} + +std::string NotificationButtonOption::Dump() +{ + return "NotificationButtonOption{ " + "buttonName = " + buttonName_ + + " }"; +} + +bool NotificationButtonOption::ToJson(nlohmann::json &jsonObject) const +{ + jsonObject["buttonName"] = buttonName_; + return true; +} + +NotificationButtonOption *NotificationButtonOption::FromJson(const nlohmann::json &jsonObject) +{ + if (jsonObject.is_null() or !jsonObject.is_object()) { + ANS_LOGE("Invalid JSON object"); + return nullptr; + } + + NotificationButtonOption *button = new (std::nothrow) NotificationButtonOption(); + if (button == nullptr) { + ANS_LOGE("Failed to create button option instance"); + return nullptr; + } + + const auto &jsonEnd = jsonObject.cend(); + if (jsonObject.find("buttonName") != jsonEnd && jsonObject.at("buttonName").is_string()) { + button->buttonName_ = jsonObject.at("buttonName").get(); + } + + return button; +} + +bool NotificationButtonOption::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString(buttonName_)) { + ANS_LOGE("Failed to write title"); + return false; + } + + return true; +} + +bool NotificationButtonOption::ReadFromParcel(Parcel &parcel) +{ + buttonName_ = parcel.ReadString(); + + return true; +} + +NotificationButtonOption *NotificationButtonOption::Unmarshalling(Parcel &parcel) +{ + NotificationButtonOption *button = new (std::nothrow) NotificationButtonOption(); + + if (button && !button->ReadFromParcel(parcel)) { + delete button; + button = nullptr; + } + + return button; +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/src/notification_capsule.cpp b/frameworks/ans/src/notification_capsule.cpp new file mode 100644 index 000000000..f2cafc693 --- /dev/null +++ b/frameworks/ans/src/notification_capsule.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_capsule.h" + +#include // for basic_string, operator+, basic_string<>... +#include // for shared_ptr, shared_ptr<>::element_type + + +#include "ans_image_util.h" +#include "ans_log_wrapper.h" +#include "nlohmann/json.hpp" // for json, basic_json<>::object_t, basic_json +#include "parcel.h" // for Parcel +#include "pixel_map.h" // for PixelMap + +namespace OHOS { +namespace Notification { + +void NotificationCapsule::SetTitle(const std::string &title) +{ + title_ = title; +} + +std::string NotificationCapsule::GetTitle() const +{ + return title_; +} + +void NotificationCapsule::SetBackgroundColor(const std::string &color) +{ + backgroundColor_ = color; +} + +std::string NotificationCapsule::GetBackgroundColor() const +{ + return backgroundColor_; +} + +void NotificationCapsule::SetIcon(const std::shared_ptr &pixelMap) +{ + icon_ = pixelMap; +} + +const std::shared_ptr NotificationCapsule::GetIcon() const +{ + return icon_; +} + +std::string NotificationCapsule::Dump() +{ + return "Capsule{ " + "title = " + title_ + + ", backgroundColor = " + backgroundColor_ + + ", icon = " + (icon_ ? "not null" : "null") + + " }"; +} + +bool NotificationCapsule::ToJson(nlohmann::json &jsonObject) const +{ + jsonObject["title"] = title_; + jsonObject["backgroundColor"] = backgroundColor_; + jsonObject["icon"] = AnsImageUtil::PackImage(icon_); + + return true; +} + +NotificationCapsule *NotificationCapsule::FromJson(const nlohmann::json &jsonObject) +{ + if (jsonObject.is_null() or !jsonObject.is_object()) { + ANS_LOGE("Invalid JSON object"); + return nullptr; + } + + NotificationCapsule *capsule = new (std::nothrow) NotificationCapsule(); + if (capsule == nullptr) { + ANS_LOGE("Failed to create capsule instance"); + return nullptr; + } + + const auto &jsonEnd = jsonObject.cend(); + if (jsonObject.find("title") != jsonEnd && jsonObject.at("title").is_string()) { + capsule->title_ = jsonObject.at("title").get(); + } + + if (jsonObject.find("backgroundColor") != jsonEnd && jsonObject.at("backgroundColor").is_string()) { + capsule->backgroundColor_ = jsonObject.at("backgroundColor").get(); + } + + if (jsonObject.find("icon") != jsonEnd && jsonObject.at("icon").is_string()) { + auto pmStr = jsonObject.at("icon").get(); + capsule->icon_ = AnsImageUtil::UnPackImage(pmStr); + } + + return capsule; +} + +bool NotificationCapsule::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString(title_)) { + ANS_LOGE("Failed to write title"); + return false; + } + + if (!parcel.WriteString(backgroundColor_)) { + ANS_LOGE("Failed to write backgroundColor"); + return false; + } + + bool valid = icon_ ? true : false; + if (!parcel.WriteBool(valid)) { + ANS_LOGE("Failed to write the flag which indicate whether icon pixelMap is null"); + return false; + } + + if (valid) { + if (!parcel.WriteParcelable(icon_.get())) { + ANS_LOGE("Failed to write icon"); + return false; + } + } + + return true; +} + +bool NotificationCapsule::ReadFromParcel(Parcel &parcel) +{ + title_ = parcel.ReadString(); + backgroundColor_ = parcel.ReadString(); + + bool valid = parcel.ReadBool(); + if (valid) { + icon_ = std::shared_ptr(parcel.ReadParcelable()); + if (!icon_) { + ANS_LOGE("Failed to read icon pixelMap"); + return false; + } + } + + return true; +} + +NotificationCapsule *NotificationCapsule::Unmarshalling(Parcel &parcel) +{ + NotificationCapsule *capsule = new (std::nothrow) NotificationCapsule(); + + if (capsule && !capsule->ReadFromParcel(parcel)) { + delete capsule; + capsule = nullptr; + } + + return capsule; +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 2eac92284..f9b375055 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -164,6 +164,11 @@ ErrCode NotificationHelper::SubscribeNotification(const NotificationSubscriber & return DelayedSingleton::GetInstance()->SubscribeNotification(subscriber); } +ErrCode NotificationHelper::SubscribeLocalActivityNotification(const NotificationLocalActivitySubscriber &subscriber) +{ + return DelayedSingleton::GetInstance()->SubscribeLocalActivityNotification(subscriber); +} + ErrCode NotificationHelper::SubscribeNotification( const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo) { @@ -181,6 +186,12 @@ ErrCode NotificationHelper::UnSubscribeNotification( return DelayedSingleton::GetInstance()->UnSubscribeNotification(subscriber, subscribeInfo); } +ErrCode NotificationHelper::TriggerLocalActivity(const NotificationBundleOption &bundleOption, + const int32_t notificationId, const NotificationButtonOption &buttonOption) +{ + return DelayedSingleton::GetInstance()->TriggerLocalActivity(bundleOption, notificationId, buttonOption); +} + ErrCode NotificationHelper::RemoveNotification(const std::string &key, int32_t removeReason) { return DelayedSingleton::GetInstance()->RemoveNotification(key, removeReason); diff --git a/frameworks/ans/src/notification_local_activity_button.cpp b/frameworks/ans/src/notification_local_activity_button.cpp new file mode 100644 index 000000000..6894d4300 --- /dev/null +++ b/frameworks/ans/src/notification_local_activity_button.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_local_activity_button.h" + +#include +#include // for basic_string, operator+, basic_string<>... +#include // for shared_ptr, shared_ptr<>::element_type +#include + + +#include "ans_image_util.h" +#include "ans_log_wrapper.h" +#include "nlohmann/json.hpp" // for json, basic_json<>::object_t, basic_json +#include "notification_button_option.h" +#include "notification_json_convert.h" +#include "parcel.h" // for Parcel +#include "pixel_map.h" // for PixelMap + +namespace OHOS { +namespace Notification { + +std::vector> NotificationLocalActivityButton::GetAllButtonOption() const +{ + return buttonOptions_; +} + +void NotificationLocalActivityButton::addSingleButtonOption(std::shared_ptr &buttonOption) +{ + if (buttonOptions_.size() >= 3) { + ANS_LOGW("already added 3 buttonOption"); + return; + } + + buttonOptions_.emplace_back(buttonOption); +} + +std::vector> NotificationLocalActivityButton::GetAllButtonIcon() const +{ + return buttonIcons_; +} + +void NotificationLocalActivityButton::addSingleButtonIcon(std::shared_ptr &icon) +{ + if (buttonIcons_.size() >= 3) { + ANS_LOGW("already added 3 buttonIcon"); + return; + } + + buttonIcons_.emplace_back(icon); +} + +std::string NotificationLocalActivityButton::Dump() +{ + // return "LocalActivityButton{ " + // "buttonOptions = " + title_ + + // ", buttonIcons = " + backgroundColor_ + + // ", icon = " + (icon_ ? "not null" : "null") + + // " }"; + return ""; +} + +bool NotificationLocalActivityButton::ToJson(nlohmann::json &jsonObject) const +{ + nlohmann::json buttonsArr = nlohmann::json::array(); + for (auto &btn : buttonOptions_) { + if (!btn) { + continue; + } + + nlohmann::json btnObj; + if (!NotificationJsonConverter::ConvertToJson(btn.get(), btnObj)) { + ANS_LOGE("Cannot convert actionButton to JSON"); + return false; + } + + buttonsArr.emplace_back(btnObj); + } + jsonObject["buttonOptions"] = buttonsArr; + + nlohmann::json iconsArr = nlohmann::json::array(); + for (auto &btn : buttonIcons_) { + if (!btn) { + continue; + } + nlohmann::json btnObj = AnsImageUtil::PackImage(btn); + iconsArr.emplace_back(btnObj); + } + jsonObject["buttonIcons"] = iconsArr; + + return true; +} + +NotificationLocalActivityButton *NotificationLocalActivityButton::FromJson(const nlohmann::json &jsonObject) +{ + if (jsonObject.is_null() or !jsonObject.is_object()) { + ANS_LOGE("Invalid JSON object"); + return nullptr; + } + + NotificationLocalActivityButton *button = new (std::nothrow) NotificationLocalActivityButton(); + if (button == nullptr) { + ANS_LOGE("Failed to create capsule instance"); + return nullptr; + } + + const auto &jsonEnd = jsonObject.cend(); + + if (jsonObject.find("buttonOptions") != jsonEnd) { + auto optionArr = jsonObject.at("buttonOptions"); + for (auto &optObj : optionArr) { + auto pOpt = NotificationJsonConverter::ConvertFromJson(optObj); + if (pOpt == nullptr) { + ANS_LOGE("Failed to parse button option"); + return nullptr; + } + button->buttonOptions_.emplace_back(pOpt); + } + } + + if (jsonObject.find("buttonIcons") != jsonEnd) { + auto iconArr = jsonObject.at("buttonIcons"); + for (auto &iconObj : iconArr) { + auto pIcon = AnsImageUtil::UnPackImage(iconObj.get()); + + if (pIcon == nullptr) { + ANS_LOGE("Failed to parse button icon"); + return nullptr; + } + button->buttonIcons_.emplace_back(pIcon); + } + } + + return button; +} + +bool NotificationLocalActivityButton::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint64(buttonOptions_.size())) { + ANS_LOGE("Failed to write the size of buttonOptions"); + return false; + } + + for (auto it = buttonOptions_.begin(); it != buttonOptions_.end(); ++it) { + if (!parcel.WriteParcelable(it->get())) { + ANS_LOGE("Failed to write buttonOptions"); + return false; + } + } + + if (!parcel.WriteUint64(buttonIcons_.size())) { + ANS_LOGE("Failed to write the size of buttonIcons"); + return false; + } + + for (auto it = buttonIcons_.begin(); it != buttonIcons_.end(); ++it) { + if (!parcel.WriteParcelable(it->get())) { + ANS_LOGE("Failed to write buttonIcons"); + return false; + } + } + + return true; +} + +bool NotificationLocalActivityButton::ReadFromParcel(Parcel &parcel) +{ + auto vsize = parcel.ReadUint64(); + vsize = (vsize < 3) ? vsize : 3; + for (uint64_t it = 0; it < vsize; ++it) { + auto member = parcel.ReadParcelable(); + if (member == nullptr) { + buttonOptions_.clear(); + ANS_LOGE("Failed to read actionButton"); + return false; + } + + buttonOptions_.emplace_back(member); + } + + vsize = parcel.ReadUint64(); + vsize = (vsize < 3) ? vsize : 3; + for (uint64_t it = 0; it < vsize; ++it) { + auto member = parcel.ReadParcelable(); + if (member == nullptr) { + buttonIcons_.clear(); + ANS_LOGE("Failed to read actionButton"); + return false; + } + + buttonIcons_.emplace_back(member); + } + + return true; +} + +NotificationLocalActivityButton *NotificationLocalActivityButton::Unmarshalling(Parcel &parcel) +{ + NotificationLocalActivityButton *button = new (std::nothrow) NotificationLocalActivityButton(); + + if (button && !button->ReadFromParcel(parcel)) { + delete button; + button = nullptr; + } + + return button; +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/src/notification_local_activity_content.cpp b/frameworks/ans/src/notification_local_activity_content.cpp new file mode 100644 index 000000000..cd45c124b --- /dev/null +++ b/frameworks/ans/src/notification_local_activity_content.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_local_activity_content.h" + +#include +#include // for basic_string, operator+ +#include // for min + +#include "ans_log_wrapper.h" +#include "nlohmann/json.hpp" // for json, basic_json<>::obje... +#include "notification_action_button.h" +#include "notification_basic_content.h" // for NotificationBasicContent +#include "notification_capsule.h" +#include "notification_json_convert.h" +#include "notification_progress.h" +#include "notification_local_activity_button.h" +#include "parcel.h" // for Parcel + +namespace OHOS { +namespace Notification { +std::string NotificationLocalActivityContent::Dump() +{ + return "NotificationLocalActivityContent{ " + NotificationBasicContent::Dump() + + ", type = " + std::to_string(type_) + + ", capsule = " + capsule_.Dump() + + ", button = " + button_.Dump() + + ", progress = " + progress_.Dump() + + " }"; +} + +bool NotificationLocalActivityContent::ToJson(nlohmann::json &jsonObject) const +{ + if (!NotificationBasicContent::ToJson(jsonObject)) { + ANS_LOGE("Cannot convert basicContent to JSON"); + return false; + } + + nlohmann::json capsuleObj; + if (!NotificationJsonConverter::ConvertToJson(&capsule_, capsuleObj)) { + ANS_LOGE("Cannot convert capsule to JSON"); + return false; + } + + nlohmann::json buttonObj; + if (!NotificationJsonConverter::ConvertToJson(&button_, buttonObj)) { + ANS_LOGE("Cannot convert button to JSON"); + return false; + } + + nlohmann::json progressObj; + if (!NotificationJsonConverter::ConvertToJson(&progress_, progressObj)) { + ANS_LOGE("Cannot convert progress to JSON"); + return false; + } + + jsonObject["type"] = type_; + jsonObject["capsule"] = capsuleObj; + jsonObject["button"] = buttonObj; + jsonObject["progress"] = progressObj; + + return true; +} + +NotificationLocalActivityContent *NotificationLocalActivityContent::FromJson(const nlohmann::json &jsonObject) +{ + if (jsonObject.is_null() or !jsonObject.is_object()) { + ANS_LOGE("Invalid JSON object"); + return nullptr; + } + + auto pContent = new (std::nothrow) NotificationLocalActivityContent(); + if (pContent == nullptr) { + ANS_LOGE("Failed to create localActivityContent instance"); + return nullptr; + } + + pContent->ReadFromJson(jsonObject); + + const auto &jsonEnd = jsonObject.cend(); + if (jsonObject.find("type") != jsonEnd ) { + pContent->type_ = jsonObject.at("type").get(); + } + + if (jsonObject.find("capsule") != jsonEnd ) { + auto capsuleObj = jsonObject.at("capsule"); + auto pCapsule = NotificationJsonConverter::ConvertFromJson(capsuleObj); + if (pCapsule != nullptr) { + pContent->capsule_ = *pCapsule; + delete pCapsule; + pCapsule = nullptr; + } + } + + if (jsonObject.find("button") != jsonEnd ) { + auto buttonObj = jsonObject.at("button"); + auto pButton = NotificationJsonConverter::ConvertFromJson(buttonObj); + if (pButton != nullptr) { + pContent->button_ = *pButton; + delete pButton; + pButton = nullptr; + } + } + + if (jsonObject.find("progress") != jsonEnd ) { + auto progressObj = jsonObject.at("progress"); + auto pProgress = NotificationJsonConverter::ConvertFromJson(progressObj); + if (pProgress != nullptr) { + pContent->progress_ = *pProgress; + delete pProgress; + pProgress = nullptr; + } + } + + return pContent; +} + +bool NotificationLocalActivityContent::Marshalling(Parcel &parcel) const +{ + if (!NotificationBasicContent::Marshalling(parcel)) { + ANS_LOGE("Failed to write basic"); + return false; + } + + if (!parcel.WriteInt32(type_)) { + ANS_LOGE("Write type fail."); + return false; + } + + if (!parcel.WriteParcelable(&capsule_)) { + ANS_LOGE("Failed to write capsule"); + return false; + } + + if (!parcel.WriteParcelable(&button_)) { + ANS_LOGE("Failed to write button"); + return false; + } + + if (!parcel.WriteParcelable(&progress_)) { + ANS_LOGE("Failed to write progress"); + return false; + } + + return true; +} + +NotificationLocalActivityContent *NotificationLocalActivityContent::Unmarshalling(Parcel &parcel) +{ + auto pContent = new (std::nothrow) NotificationLocalActivityContent(); + if ((pContent != nullptr) && !pContent->ReadFromParcel(parcel)) { + delete pContent; + pContent = nullptr; + } + + return pContent; +} + +bool NotificationLocalActivityContent::ReadFromParcel(Parcel &parcel) +{ + if (!NotificationBasicContent::ReadFromParcel(parcel)) { + ANS_LOGE("Failed to read basic"); + return false; + } + + if (!parcel.ReadInt32(type_)) { + ANS_LOGE("Read type failed."); + return false; + } + + auto pCapsule = parcel.ReadParcelable(); + if (pCapsule == nullptr) { + ANS_LOGE("Failed to read capsule"); + return false; + } + capsule_ = *pCapsule; + delete pCapsule; + pCapsule = nullptr; + + auto pButton = parcel.ReadParcelable(); + if (pButton == nullptr) { + ANS_LOGE("Failed to read button"); + return false; + } + button_ = *pButton; + delete pButton; + pButton = nullptr; + + auto pProgress = parcel.ReadParcelable(); + if (pProgress == nullptr) { + ANS_LOGE("Failed to read capsule"); + return false; + } + progress_ = *pProgress; + delete pProgress; + pProgress = nullptr; + + return true; +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/ans/src/notification_local_activity_subscriber.cpp b/frameworks/ans/src/notification_local_activity_subscriber.cpp new file mode 100644 index 000000000..d094e0ea9 --- /dev/null +++ b/frameworks/ans/src/notification_local_activity_subscriber.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_local_activity_subscriber.h" + +#include "hitrace_meter.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace Notification { +NotificationLocalActivitySubscriber::NotificationLocalActivitySubscriber() +{ + impl_ = new (std::nothrow) SubscriberLocalActivityImpl(*this); +}; + +NotificationLocalActivitySubscriber::~NotificationLocalActivitySubscriber() +{} + +const sptr NotificationLocalActivitySubscriber::GetImpl() const +{ + return impl_; +} + +NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::SubscriberLocalActivityImpl(NotificationLocalActivitySubscriber &subscriber) : subscriber_(subscriber) +{ + recipient_ = new (std::nothrow) DeathRecipient(*this); +}; + +void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnConnected() +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (GetAnsManagerProxy()) { + proxy_->AsObject()->AddDeathRecipient(recipient_); + ANS_LOGD("%s, Add death recipient.", __func__); + } + subscriber_.OnConnected(); +} + +void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnDisconnected() +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (GetAnsManagerProxy()) { + proxy_->AsObject()->RemoveDeathRecipient(recipient_); + ANS_LOGD("%s, Remove death recipient.", __func__); + } + subscriber_.OnDisconnected(); +} + +void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnResponse(int32_t notificationId, const sptr &buttonOption) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + subscriber_.OnResponse(notificationId, buttonOption); +} + +bool NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::GetAnsManagerProxy() +{ + if (proxy_ == nullptr) { + std::lock_guard lock(mutex_); + if (proxy_ == nullptr) { + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + return false; + } + + sptr remoteObject = + systemAbilityManager->GetSystemAbility(ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID); + if (!remoteObject) { + return false; + } + + proxy_ = iface_cast(remoteObject); + if ((proxy_ == nullptr) || (proxy_->AsObject() == nullptr)) { + return false; + } + } + } + + return true; +} + +NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::DeathRecipient::DeathRecipient(SubscriberLocalActivityImpl &subscriberImpl) + : subscriberImpl_(subscriberImpl) {}; + +NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::DeathRecipient::~DeathRecipient() {}; + +void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::DeathRecipient::OnRemoteDied(const wptr &object) +{ + subscriberImpl_.proxy_ = nullptr; + subscriberImpl_.subscriber_.OnDied(); +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/src/notification_progress.cpp b/frameworks/ans/src/notification_progress.cpp new file mode 100644 index 000000000..2b051c05e --- /dev/null +++ b/frameworks/ans/src/notification_progress.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_progress.h" + +#include +#include // for basic_string, operator+, basic_string<>... +#include // for shared_ptr, shared_ptr<>::element_type + + +#include "ans_log_wrapper.h" +#include "nlohmann/json.hpp" // for json, basic_json<>::object_t, basic_json +#include "parcel.h" // for Parcel + +namespace OHOS { +namespace Notification { + +int32_t NotificationProgress::GetMaxValue() const +{ + return maxValue_; +} + +void NotificationProgress::SetMaxValue(int32_t maxValue) +{ + maxValue_ = maxValue; +} + +int32_t NotificationProgress::GetCurrentValue() const +{ + return currentValue_; +} + +void NotificationProgress::SetCurrentValue(int32_t curValue) +{ + currentValue_ = curValue; +} + +int32_t NotificationProgress::GetIsPercentage() const +{ + return isPercentage_; +} + +void NotificationProgress::SetIsPercentage(int32_t isPercentage) +{ + isPercentage_ = isPercentage; +} + + +std::string NotificationProgress::Dump() +{ + return "Progress{ " + "maxValue = " + std::to_string(maxValue_) + + ", currentValue = " + std::to_string(currentValue_) + + ", isPercentage = " + std::to_string(isPercentage_) + + " }"; +} + +bool NotificationProgress::ToJson(nlohmann::json &jsonObject) const +{ + jsonObject["maxValue"] = maxValue_; + jsonObject["currentValue"] = currentValue_; + jsonObject["isPercentage"] = isPercentage_; + + return true; +} + +NotificationProgress *NotificationProgress::FromJson(const nlohmann::json &jsonObject) +{ + if (jsonObject.is_null() or !jsonObject.is_object()) { + ANS_LOGE("Invalid JSON object"); + return nullptr; + } + + NotificationProgress *progress = new (std::nothrow) NotificationProgress(); + if (progress == nullptr) { + ANS_LOGE("Failed to create capsule instance"); + return nullptr; + } + + const auto &jsonEnd = jsonObject.cend(); + if (jsonObject.find("maxValue") != jsonEnd && jsonObject.at("maxValue").is_number_integer()) { + progress->maxValue_ = jsonObject.at("maxValue").get(); + } + + if (jsonObject.find("currentValue") != jsonEnd && jsonObject.at("currentValue").is_number_integer()) { + progress->currentValue_ = jsonObject.at("currentValue").get(); + } + + if (jsonObject.find("isPercentage") != jsonEnd && jsonObject.at("isPercentage").is_number_integer()) { + progress->isPercentage_ = jsonObject.at("isPercentage_").get(); + } + + return progress; +} + +bool NotificationProgress::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteInt32(maxValue_)) { + ANS_LOGE("Failed to write maxValue"); + return false; + } + + if (!parcel.WriteInt32(currentValue_)) { + ANS_LOGE("Failed to write currentValue"); + return false; + } + + if (!parcel.WriteInt32(isPercentage_)) { + ANS_LOGE("Failed to write isPercentage"); + return false; + } + return true; +} + +bool NotificationProgress::ReadFromParcel(Parcel &parcel) +{ + maxValue_ = parcel.ReadInt32(); + currentValue_ = parcel.ReadInt32(); + isPercentage_ = parcel.ReadInt32(); + + return true; +} + +NotificationProgress *NotificationProgress::Unmarshalling(Parcel &parcel) +{ + NotificationProgress *progress = new (std::nothrow) NotificationProgress(); + + if (progress && !progress->ReadFromParcel(parcel)) { + delete progress; + progress = nullptr; + } + + return progress; +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 6159fd145..d8a0b864d 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -20,6 +20,7 @@ #include #include "ans_subscriber_interface.h" +#include "ans_subscriber_local_activity_interface.h" #include "iremote_broker.h" #include "notification_bundle_option.h" #include "notification_constant.h" @@ -246,6 +247,18 @@ public: */ virtual ErrCode HasNotificationPolicyAccessPermission(bool &granted) = 0; + /** + * @brief Trigger the local activity after the button has been clicked. + * @note Your application must have platform signature to use this method. + * + * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. + * @param notificationId Indicates the id of the notification. + * @param buttonOption Indicates which button has been clicked. + * @return Returns trigger localActivity result. + */ + virtual ErrCode TriggerLocalActivity(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) = 0; + /** * @brief Delete notification based on key. * @@ -384,6 +397,16 @@ public: virtual ErrCode Subscribe(const sptr &subscriber, const sptr &info) = 0; + /** + * @brief Subscribes system activity notifications. + * + * @param subscriber Indicates the subscriber. + * @param info Indicates the NotificationSubscribeInfo object. + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode SubscribeLocalActivity(const sptr &subscriber, + const sptr &info) = 0; + /** * @brief Unsubscribes notifications. * diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index c31fc4330..5e84d1247 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -235,6 +235,18 @@ public: */ ErrCode HasNotificationPolicyAccessPermission(bool &granted) override; + /** + * @brief Trigger the local activity after the button has been clicked. + * @note Your application must have platform signature to use this method. + * + * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. + * @param notificationId Indicates the id of the notification. + * @param buttonOption Indicates which button has been clicked. + * @return Returns trigger localActivity result. + */ + ErrCode TriggerLocalActivity(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) override; + /** * @brief Delete notification. * @@ -373,6 +385,17 @@ public: ErrCode Subscribe(const sptr &subscriber, const sptr &info) override; + /** + * @brief Subscribes notifications. + * + * @param subscriber Indicates the subscriber. + * @param info Indicates the NotificationSubscribeInfo object. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode SubscribeLocalActivity(const sptr &subscriber, + const sptr &info) override; + + /** * @brief Unsubscribes notifications. * diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index e901da196..6119a2ff8 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -20,6 +20,7 @@ #include #include "ans_manager_interface.h" +#include "ans_subscriber_local_activity_interface.h" #include "distributed_notification_service_ipc_interface_code.h" #include "iremote_stub.h" @@ -250,6 +251,18 @@ public: */ virtual ErrCode HasNotificationPolicyAccessPermission(bool &granted) override; + /** + * @brief Trigger the local activity after the button has been clicked. + * @note Your application must have platform signature to use this method. + * + * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. + * @param notificationId Indicates the id of the notification. + * @param buttonOption Indicates which button has been clicked. + * @return Returns trigger localActivity result. + */ + virtual ErrCode TriggerLocalActivity(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) override; + /** * @brief Delete notification. * @@ -391,6 +404,9 @@ public: virtual ErrCode Subscribe( const sptr &subscriber, const sptr &info) override; + virtual ErrCode SubscribeLocalActivity( + const sptr &subscriber, const sptr &info) override; + /** * @brief Unsubscribes notifications. * @@ -760,6 +776,8 @@ private: ErrCode HandleSetBadgeNumber(MessageParcel &data, MessageParcel &reply); ErrCode HandleRegisterPushCallback(MessageParcel &data, MessageParcel &reply); ErrCode HandleUnregisterPushCallback(MessageParcel &data, MessageParcel &reply); + ErrCode HandleSubscribeLocalActivity(MessageParcel &data, MessageParcel &reply); + ErrCode HandleTriggerLocalActivity(MessageParcel &data, MessageParcel &reply); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result) diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index b91ea0dec..0634f66ba 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -21,6 +21,7 @@ #include "ans_manager_death_recipient.h" #include "ans_manager_interface.h" #include "notification_subscriber.h" +#include "notification_local_activity_subscriber.h" namespace OHOS { namespace Notification { @@ -297,6 +298,22 @@ public: */ ErrCode SubscribeNotification(const NotificationSubscriber &subscriber); + /** + * @brief Subscribes to notifications from all applications. This method can be called only by applications + * with required system permissions. + * @note To subscribe to a notification, inherit the {NotificationSubscriber} class, override its + * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. + * After the notification is published, subscribers that meet the filter criteria can receive the + * notification. To subscribe to notifications published only by specified sources, for example, notifications from + * certain applications, call the {SubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} + * method. + * + * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. + * This parameter must be specified. + * @return Returns subscribe notification result. + */ + ErrCode SubscribeLocalActivityNotification(const NotificationLocalActivitySubscriber &subscriber); + /** * @brief Subscribes to all notifications based on the filtering criteria. This method can be called only * by applications with required system permissions. @@ -347,6 +364,18 @@ public: */ ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo); + /** + * @brief Trigger the local activity after the button has been clicked. + * @note Your application must have platform signature to use this method. + * + * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. + * @param notificationId Indicates the id of the notification. + * @param buttonOption Indicates which button has been clicked. + * @return Returns trigger localActivity result. + */ + ErrCode TriggerLocalActivity(const NotificationBundleOption &bundleOption, + const int32_t notificationId, const NotificationButtonOption &buttonOption); + /** * @brief Removes a specified removable notification of other applications. * @note Your application must have platform signature to use this method. diff --git a/frameworks/core/include/ans_subscriber_local_activity_interface.h b/frameworks/core/include/ans_subscriber_local_activity_interface.h new file mode 100644 index 000000000..8785072c4 --- /dev/null +++ b/frameworks/core/include/ans_subscriber_local_activity_interface.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_ACTIVITY_SUBSCRIBER_INTERFACE_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_ACTIVITY_SUBSCRIBER_INTERFACE_H + +#include "iremote_broker.h" + +#include "badge_number_callback_data.h" +#include "enabled_notification_callback_data.h" +#include "notification.h" +#include "notification_constant.h" +#include "notification_do_not_disturb_date.h" +#include "notification_request.h" +#include "notification_sorting.h" +#include "notification_sorting_map.h" + +namespace OHOS { +namespace Notification { +class AnsSubscriberLocalActivityInterface : public IRemoteBroker { +public: + AnsSubscriberLocalActivityInterface() = default; + virtual ~AnsSubscriberLocalActivityInterface() override = default; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalActivityInterface); + + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.AnsSubscriberLocalActivityInterface"); + + /** + * @brief The callback function for the subscriber to establish a connection. + */ + virtual void OnConnected() = 0; + + /** + * @brief The callback function for subscriber disconnected. + */ + virtual void OnDisconnected() = 0; + + virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) = 0; + +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_ACTIVITY_SUBSCRIBER_INTERFACE_H diff --git a/frameworks/core/include/ans_subscriber_local_activity_proxy.h b/frameworks/core/include/ans_subscriber_local_activity_proxy.h new file mode 100644 index 000000000..7b7e9b21c --- /dev/null +++ b/frameworks/core/include/ans_subscriber_local_activity_proxy.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_SYSTEM_ACTIVITY_PROXY_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_SYSTEM_ACTIVITY_PROXY_H + +#include "ans_subscriber_local_activity_interface.h" +#include "distributed_notification_service_ipc_interface_code.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace Notification { +class AnsSubscriberLocalActivityProxy : public IRemoteProxy { +public: + AnsSubscriberLocalActivityProxy() = delete; + explicit AnsSubscriberLocalActivityProxy(const sptr &impl); + ~AnsSubscriberLocalActivityProxy() override; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalActivityProxy); + + /** + * @brief The callback function for the subscriber to establish a connection. + */ + void OnConnected() override; + + /** + * @brief The callback function for subscriber disconnected. + */ + void OnDisconnected() override; + + void OnResponse(int32_t notificationId, const sptr &buttonOption) override; + +private: + ErrCode InnerTransact(NotificationInterfaceCode code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); + static inline BrokerDelegator delegator_; + + template + bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) + { + if (!data.WriteInt32(parcelableVector.size())) { + ANS_LOGE("write ParcelableVector size failed"); + return false; + } + + for (auto &parcelable : parcelableVector) { + if (!data.WriteStrongParcelable(parcelable)) { + ANS_LOGE("write ParcelableVector failed"); + return false; + } + } + return true; + } +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_SYSTEM_ACTIVITY_PROXY_H diff --git a/frameworks/core/include/ans_subscriber_local_activity_stub.h b/frameworks/core/include/ans_subscriber_local_activity_stub.h new file mode 100644 index 000000000..916540a98 --- /dev/null +++ b/frameworks/core/include/ans_subscriber_local_activity_stub.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_ACTIVITY_STUB_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_ACTIVITY_STUB_H + +#include "ans_subscriber_local_activity_interface.h" +#include "distributed_notification_service_ipc_interface_code.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace Notification { +class AnsSubscriberLocalActivityStub : public IRemoteStub { +public: + AnsSubscriberLocalActivityStub(); + ~AnsSubscriberLocalActivityStub() override; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalActivityStub); + + /** + * @brief Handle remote request. + * + * @param data Indicates the input parcel. + * @param reply Indicates the output parcel. + * @param option Indicates the message option. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + + /** + * @brief The callback function for the subscriber to establish a connection. + */ + void OnConnected() override; + + /** + * @brief The callback function for subscriber disconnected. + */ + void OnDisconnected() override; + + void OnResponse(int32_t notificationId, const sptr &buttonOption) override; + +private: + std::map> interfaces_; + + ErrCode HandleOnConnected(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnDisconnected(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnResponse(MessageParcel &data, MessageParcel &reply); + + template + bool ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data); +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_ACTIVITY_STUB_H diff --git a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h index 959baaa8d..f1fc8d4f2 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -117,6 +117,9 @@ namespace Notification { ON_BADGE_CHANGED, // push_callback_interface ON_CHECK_NOTIFICATION, + ON_RESPONSE, + SUBSCRIBE_LOCAL_ACTIVITY_NOTIFICATION, + TRIGGER_LOCAL_ACTIVITY_NOTIFICATION, }; } } diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index e50a8445f..3144b7937 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -18,6 +18,7 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" +#include "ans_subscriber_local_activity_interface.h" #include "distributed_notification_service_ipc_interface_code.h" #include "message_option.h" #include "message_parcel.h" @@ -739,6 +740,51 @@ ErrCode AnsManagerProxy::HasNotificationPolicyAccessPermission(bool &granted) return result; } +ErrCode AnsManagerProxy::TriggerLocalActivity(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) +{ + if (bundleOption == nullptr) { + ANS_LOGE("[TriggerLocalActivity] fail: bundle is empty."); + return ERR_ANS_INVALID_PARAM; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[TriggerLocalActivity] fail:, write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteStrongParcelable(bundleOption)) { + ANS_LOGE("[TriggerLocalActivity] fail:: write bundle failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteInt32(notificationId)) { + ANS_LOGE("[TriggerLocalActivity] fail: write notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteStrongParcelable(buttonOption)) { + ANS_LOGE("[TriggerLocalActivity] fail: write label failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::TRIGGER_LOCAL_ACTIVITY_NOTIFICATION, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[TriggerLocalActivity] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("[TriggerLocalActivity] fail: read result error."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + ErrCode AnsManagerProxy::RemoveNotification(const sptr &bundleOption, int32_t notificationId, const std::string &label, int32_t removeReason) { @@ -1358,6 +1404,53 @@ ErrCode AnsManagerProxy::Subscribe(const sptr &subscribe return result; } +ErrCode AnsManagerProxy::SubscribeLocalActivity(const sptr &subscriber, const sptr &info) +{ + if (subscriber == nullptr) { + ANS_LOGE("[Subscribe] fail: subscriber is empty."); + return ERR_ANS_INVALID_PARAM; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[Subscribe] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool ret = data.WriteRemoteObject(subscriber->AsObject()); + if (!ret) { + ANS_LOGE("[Subscribe] fail: write subscriber failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteBool(info != nullptr)) { + ANS_LOGE("[Subscribe] fail: write isSubcribeInfo failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (info != nullptr) { + if (!data.WriteParcelable(info)) { + ANS_LOGE("[Subscribe] fail: write subcribeInfo failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::SUBSCRIBE_LOCAL_ACTIVITY_NOTIFICATION, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[Subscribe] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("[Subscribe] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + ErrCode AnsManagerProxy::Unsubscribe( const sptr &subscriber, const sptr &info) { diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index d34a92c41..c1493069c 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -17,8 +17,10 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" +#include "ans_subscriber_local_activity_interface.h" #include "message_option.h" #include "message_parcel.h" +#include "notification_button_option.h" #include "parcel.h" #include "reminder_request_alarm.h" #include "reminder_request_calendar.h" @@ -251,6 +253,9 @@ const std::map bundleOption = data.ReadStrongParcelable(); + if (bundleOption == nullptr) { + ANS_LOGE("[HandleTriggerLocalActivity] fail: read bundle failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleTriggerLocalActivity] fail: read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr buttonOption = data.ReadStrongParcelable(); + if (buttonOption == nullptr) { + ANS_LOGE("[HandleTriggerLocalActivity] fail: read button failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = TriggerLocalActivity(bundleOption, notificationId, buttonOption); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleTriggerLocalActivity] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + ErrCode AnsManagerStub::HandleRemoveNotification(MessageParcel &data, MessageParcel &reply) { sptr bundleOption = data.ReadStrongParcelable(); @@ -1103,6 +1136,37 @@ ErrCode AnsManagerStub::HandleSubscribe(MessageParcel &data, MessageParcel &repl return ERR_OK; } +ErrCode AnsManagerStub::HandleSubscribeLocalActivity(MessageParcel &data, MessageParcel &reply) +{ + sptr subscriber = data.ReadRemoteObject(); + if (subscriber == nullptr) { + ANS_LOGE("[HandleSubscribeLocalActivity] fail: read subscriber failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool subcribeInfo = false; + if (!data.ReadBool(subcribeInfo)) { + ANS_LOGE("[HandleSubscribeLocalActivity] fail: read isSubcribeInfo failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + sptr info = nullptr; + if (subcribeInfo) { + info = data.ReadParcelable(); + if (info == nullptr) { + ANS_LOGE("[HandleSubscribeLocalActivity] fail: read info failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + ErrCode result = SubscribeLocalActivity(iface_cast(subscriber), info); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleSubscribeLocalActivity] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} + ErrCode AnsManagerStub::HandleUnsubscribe(MessageParcel &data, MessageParcel &reply) { sptr subscriber = data.ReadRemoteObject(); @@ -1884,6 +1948,13 @@ ErrCode AnsManagerStub::HasNotificationPolicyAccessPermission(bool &granted) return ERR_INVALID_OPERATION; } +ErrCode AnsManagerStub::TriggerLocalActivity(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) +{ + ANS_LOGE("AnsManagerStub::TriggerLocalActivity called!"); + return ERR_INVALID_OPERATION; +} + ErrCode AnsManagerStub::RemoveNotification(const sptr &bundleOption, int notificationId, const std::string &label, int32_t removeReason) { @@ -1985,6 +2056,13 @@ ErrCode AnsManagerStub::Subscribe(const sptr &subscriber return ERR_INVALID_OPERATION; } +ErrCode AnsManagerStub::SubscribeLocalActivity(const sptr &subscriber, + const sptr &info) +{ + ANS_LOGE("AnsManagerStub::SubscribeLocalActivity called!"); + return ERR_INVALID_OPERATION; +} + ErrCode AnsManagerStub::Unsubscribe(const sptr &subscriber, const sptr &info) { diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index c9b79d153..6f8df74eb 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -19,6 +19,8 @@ #include "ans_log_wrapper.h" #include "hitrace_meter.h" #include "iservice_registry.h" +#include "notification_button_option.h" +#include "notification_local_activity_subscriber.h" #include "reminder_request_alarm.h" #include "reminder_request_calendar.h" #include "reminder_request_timer.h" @@ -377,6 +379,22 @@ ErrCode AnsNotification::SubscribeNotification(const NotificationSubscriber &sub return ansManagerProxy_->Subscribe(subscriberSptr, nullptr); } +ErrCode AnsNotification::SubscribeLocalActivityNotification(const NotificationLocalActivitySubscriber &subscriber) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr subscriberSptr = subscriber.GetImpl(); + if (subscriberSptr == nullptr) { + ANS_LOGE("Failed to subscribe with SubscriberImpl null ptr."); + return ERR_ANS_INVALID_PARAM; + } + return ansManagerProxy_->SubscribeLocalActivity(subscriberSptr, nullptr); +} + ErrCode AnsNotification::SubscribeNotification( const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo) { @@ -439,6 +457,30 @@ ErrCode AnsNotification::UnSubscribeNotification( return ansManagerProxy_->Unsubscribe(subscriberSptr, sptrInfo); } +ErrCode AnsNotification::TriggerLocalActivity(const NotificationBundleOption &bundleOption, + const int32_t notificationId, const NotificationButtonOption &buttonOption) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (bundleOption.GetBundleName().empty()) { + ANS_LOGE("Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + + if (buttonOption.GetButtonName().empty()) { + ANS_LOGE("Invalid button name."); + return ERR_ANS_INVALID_PARAM; + } + + if (!GetAnsManagerProxy()) { + ANS_LOGE("Fail to GetAnsManagerProxy."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); + sptr button(new (std::nothrow) NotificationButtonOption(buttonOption)); + return ansManagerProxy_->TriggerLocalActivity(bo, notificationId, button); +} + ErrCode AnsNotification::RemoveNotification(const std::string &key, int32_t removeReason) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); diff --git a/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp b/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp new file mode 100644 index 000000000..b3227bb73 --- /dev/null +++ b/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ans_subscriber_local_activity_proxy.h" + +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "message_option.h" +#include "message_parcel.h" + +namespace OHOS { +namespace Notification { +AnsSubscriberLocalActivityProxy::AnsSubscriberLocalActivityProxy(const sptr &impl) : IRemoteProxy(impl) +{} + +AnsSubscriberLocalActivityProxy::~AnsSubscriberLocalActivityProxy() +{} + +ErrCode AnsSubscriberLocalActivityProxy::InnerTransact( + NotificationInterfaceCode code, MessageOption &flags, MessageParcel &data, MessageParcel &reply) +{ + auto remote = Remote(); + if (remote == nullptr) { + ANS_LOGE("[InnerTransact] fail: get Remote fail code %{public}u", code); + return ERR_DEAD_OBJECT; + } + + int32_t err = remote->SendRequest(static_cast(code), data, reply, flags); + switch (err) { + case NO_ERROR: { + return ERR_OK; + } + case DEAD_OBJECT: { + ANS_LOGE("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code); + return ERR_DEAD_OBJECT; + } + default: { + ANS_LOGE("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code); + return ERR_ANS_TRANSACT_FAILED; + } + } +} + +void AnsSubscriberLocalActivityProxy::OnConnected() +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsSubscriberLocalActivityProxy::GetDescriptor())) { + ANS_LOGE("[OnConnected] fail: write interface token failed."); + return; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_ASYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::ON_CONNECTED, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[OnConnected] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); + return; + } +} + +void AnsSubscriberLocalActivityProxy::OnDisconnected() +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsSubscriberLocalActivityProxy::GetDescriptor())) { + ANS_LOGE("[OnDisconnected] fail: write interface token failed."); + return; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_ASYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::ON_DISCONNECTED, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[OnDisconnected] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); + return; + } +} + + +void AnsSubscriberLocalActivityProxy::OnResponse(int32_t notificationId, const sptr &buttonOption) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsSubscriberLocalActivityProxy::GetDescriptor())) { + ANS_LOGE("[OnResponse] fail: write interface token failed."); + return; + } + + if (!data.WriteInt32(notificationId)) { + ANS_LOGE("[OnResponse] fail: write notificationId failed"); + return; + } + + if (!data.WriteParcelable(buttonOption)) { + ANS_LOGE("[OnResponse] fail: write buttonName failed"); + return; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_ASYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::ON_RESPONSE, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[OnResponse] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); + return; + } +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/core/src/ans_subscriber_local_activity_stub.cpp b/frameworks/core/src/ans_subscriber_local_activity_stub.cpp new file mode 100644 index 000000000..1db24040b --- /dev/null +++ b/frameworks/core/src/ans_subscriber_local_activity_stub.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ans_subscriber_local_activity_stub.h" + +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "message_option.h" +#include "message_parcel.h" +#include "notification_bundle_option.h" +#include "notification_button_option.h" +#include "parcel.h" +#include "refbase.h" +#include + +namespace OHOS { +namespace Notification { +AnsSubscriberLocalActivityStub::AnsSubscriberLocalActivityStub() +{ + interfaces_.emplace(NotificationInterfaceCode::ON_CONNECTED, + std::bind(&AnsSubscriberLocalActivityStub::HandleOnConnected, this, std::placeholders::_1, std::placeholders::_2)); + interfaces_.emplace(NotificationInterfaceCode::ON_DISCONNECTED, + std::bind(&AnsSubscriberLocalActivityStub::HandleOnDisconnected, this, std::placeholders::_1, std::placeholders::_2)); + interfaces_.emplace(NotificationInterfaceCode::ON_RESPONSE, + std::bind(&AnsSubscriberLocalActivityStub::HandleOnResponse, this, std::placeholders::_1, std::placeholders::_2)); +} + +AnsSubscriberLocalActivityStub::~AnsSubscriberLocalActivityStub() +{} + +int32_t AnsSubscriberLocalActivityStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &flags) +{ + std::u16string descriptor = AnsSubscriberLocalActivityStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + ANS_LOGW("[OnRemoteRequest] fail: invalid interface token!"); + return OBJECT_NULL; + } + + auto it = interfaces_.find(static_cast(code)); + if (it == interfaces_.end()) { + ANS_LOGW("[OnRemoteRequest] fail: unknown code!"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, flags); + } + + auto fun = it->second; + if (fun == nullptr) { + ANS_LOGW("[OnRemoteRequest] fail: not find function!"); + return IPCObjectStub::OnRemoteRequest(code, data, reply, flags); + } + + fun(data, reply); + return NO_ERROR; +} + +ErrCode AnsSubscriberLocalActivityStub::HandleOnConnected(MessageParcel &data, MessageParcel &reply) +{ + OnConnected(); + return ERR_OK; +} + +ErrCode AnsSubscriberLocalActivityStub::HandleOnDisconnected(MessageParcel &data, MessageParcel &reply) +{ + OnDisconnected(); + return ERR_OK; +} + +template +bool AnsSubscriberLocalActivityStub::ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) +{ + int32_t infoSize = 0; + if (!data.ReadInt32(infoSize)) { + ANS_LOGE("read Parcelable size failed."); + return false; + } + + parcelableInfos.clear(); + infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM; + for (int32_t index = 0; index < infoSize; index++) { + sptr info = data.ReadStrongParcelable(); + if (info == nullptr) { + ANS_LOGE("read Parcelable infos failed."); + return false; + } + parcelableInfos.emplace_back(info); + } + + return true; +} + +ErrCode AnsSubscriberLocalActivityStub::HandleOnResponse(MessageParcel &data, MessageParcel &reply) +{ + int32_t notificationId = 0; + if (!data.ReadInt32(notificationId)) { + ANS_LOGE("[HandleOnResponse] fail : read notificationId failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + sptr buttonOption = nullptr; + buttonOption = data.ReadParcelable(); + if (buttonOption == nullptr) { + ANS_LOGE("[HandleOnResponse] fail : read buttonOption failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + OnResponse(notificationId, buttonOption); + return ERR_OK; +} + +void AnsSubscriberLocalActivityStub::OnConnected() +{} + +void AnsSubscriberLocalActivityStub::OnDisconnected() +{} + +void AnsSubscriberLocalActivityStub::OnResponse(int32_t notificationId, const sptr &buttonOption) +{} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp index d0457ea46..955a2079d 100755 --- a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp @@ -246,6 +246,12 @@ public: return ERR_ANS_INVALID_PARAM; } + ErrCode SubscribeLocalActivity(const sptr &subscriber, + const sptr &info) override + { + return ERR_ANS_INVALID_PARAM; + } + ErrCode Unsubscribe( const sptr &subscriber, const sptr &info) override { @@ -425,6 +431,12 @@ public: { return ERR_ANS_INVALID_PARAM; } + + ErrCode TriggerLocalActivity(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) override + { + return ERR_ANS_INVALID_PARAM; + } }; class AnsNotificationBranchTest : public testing::Test { diff --git a/interfaces/inner_api/notification_button_option.h b/interfaces/inner_api/notification_button_option.h new file mode 100644 index 000000000..82a020c07 --- /dev/null +++ b/interfaces/inner_api/notification_button_option.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUTTON_OPTION_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUTTON_OPTION_H + +#include "notification_json_convert.h" +#include "parcel.h" + +namespace OHOS { +namespace Notification { +class NotificationButtonOption : public Parcelable, public NotificationJsonConvertionBase { +public: + NotificationButtonOption() = default; + + ~NotificationButtonOption() = default; + + + /** + * @brief Sets devices that support display. + * + * @param devices Indicates the devices that support display. + */ + void SetButtonName(const std::string &buttonName); + + /** + * @brief Obtains the devices that support display. + * + * @return Returns the devices that support display. + */ + std::string GetButtonName() const; + + /** + * @brief Returns a string representation of the object. + * + * @return Returns a string representation of the object. + */ + std::string Dump(); + + /** + * @brief Converts a NotificationButtonOptions object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a NotificationButtonOptions object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationButtonOptions. + */ + static NotificationButtonOption *FromJson(const nlohmann::json &jsonObject); + + /** + * @brief Marshal a object into a Parcel. + * + * @param parcel Indicates the object into the parcel. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns the NotificationButtonOptions object. + */ + static NotificationButtonOption *Unmarshalling(Parcel &parcel); + +private: + /** + * @brief Read a NotificationButtonOptions object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ReadFromParcel(Parcel &parcel); + +private: + std::string buttonName_ {}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BUTTON_OPTION_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_capsule.h b/interfaces/inner_api/notification_capsule.h new file mode 100644 index 000000000..3d77ff434 --- /dev/null +++ b/interfaces/inner_api/notification_capsule.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CAPSULE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CAPSULE_H + +#include "foundation/multimedia/image_framework/interfaces/innerkits/include/pixel_map.h" +#include "notification_json_convert.h" +#include "parcel.h" +#include + +namespace OHOS { +namespace Notification { +class NotificationCapsule : public Parcelable, public NotificationJsonConvertionBase { +public: + NotificationCapsule() = default; + + ~NotificationCapsule() = default; + + /** + * @brief Obtains the text to be displayed as the content of this message. + * + * @return Returns the message content. + */ + std::string GetTitle() const; + + void SetTitle(const std::string &title); + + /** + * @brief Obtains the time when this message arrived. + * + * @return Returns the time when this message arrived. + */ + const std::shared_ptr GetIcon() const; + + void SetIcon(const std::shared_ptr &icon); + + /** + * @brief Obtains the sender of this message. + * + * @return Returns the message sender. + */ + std::string GetBackgroundColor() const; + + void SetBackgroundColor(const std::string &color); + + + /** + * @brief Returns a string representation of the object. + * + * @return Returns a string representation of the object. + */ + std::string Dump(); + + /** + * @brief Converts a NotificationConversationalMessage object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a NotificationConversationalMessage object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationCapsule *FromJson(const nlohmann::json &jsonObject); + + /** + * @brief Marshal a object into a Parcel. + * + * @param parcel Indicates the object into the parcel. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationCapsule *Unmarshalling(Parcel &parcel); + +private: + + /** + * @brief Read a NotificationConversationalMessage object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ReadFromParcel(Parcel &parcel); + +private: + std::string title_ {}; + std::shared_ptr icon_ {}; + std::string backgroundColor_ {}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CAPSULE_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_content.h b/interfaces/inner_api/notification_content.h index 41d1957f2..d66e67cbb 100644 --- a/interfaces/inner_api/notification_content.h +++ b/interfaces/inner_api/notification_content.h @@ -24,6 +24,7 @@ #include "notification_multiline_content.h" #include "notification_normal_content.h" #include "notification_picture_content.h" +#include "notification_local_activity_content.h" #include "parcel.h" namespace OHOS { @@ -63,7 +64,12 @@ public: * Indicates notifications that include a picture. * Such notifications are created using NotificationPictureContent. */ - PICTURE + PICTURE, + /** + * Indicates notifications that include system activity. + * Such notifications are created using NotificationLocalActivityContent. + */ + LOCAL_ACTIVITY }; /** @@ -120,6 +126,15 @@ public: */ explicit NotificationContent(const std::shared_ptr &mediaContent); + /** + * @brief A constructor used to create a NotificationLocalActivityContent instance (obtained by calling + * GetNotificationContent()) and set the content type to NotificationContent::Type::LOCAL_ACTIVITY (obtained by calling + * GetContentType()). + * + * @param mediaContent Indicates the NotificationLocalActivityContent object. + */ + explicit NotificationContent(const std::shared_ptr &localActivityContent); + virtual ~NotificationContent(); /** diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index fdff33476..c5f19ea77 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -17,12 +17,14 @@ #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_HELPER_H #include "notification_bundle_option.h" +#include "notification_button_option.h" #include "notification_do_not_disturb_date.h" #include "enabled_notification_callback_data.h" #include "notification_request.h" #include "notification_slot.h" #include "notification_sorting_map.h" #include "notification_subscriber.h" +#include "notification_local_activity_subscriber.h" namespace OHOS { namespace Notification { @@ -319,6 +321,19 @@ public: static ErrCode SubscribeNotification( const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo); + /** + * @brief Subscribes the localActivity button click. This method can be called only + * by applications with required system permissions. + * @note To subscribe to a button click, inherit the {NotificationLocalActivitySubscriber} class, override its + * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. + * After the button is clicked, subscribers that meet the filter criteria can receive the response + * + * @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified. + * For details, see {NotificationSubscriber}. + * @return Returns subscribe notification result. + */ + static ErrCode SubscribeLocalActivityNotification(const NotificationLocalActivitySubscriber &subscriber); + /** * @brief Unsubscribes from all notifications. This method can be called only by applications with required * system permissions. @@ -349,6 +364,18 @@ public: */ static ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo); + /** + * @brief Trigger the local activity after the button has been clicked. + * @note Your application must have platform signature to use this method. + * + * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. + * @param notificationId Indicates the id of the notification. + * @param buttonOption Indicates which button has been clicked. + * @return Returns trigger localActivity result. + */ + static ErrCode TriggerLocalActivity(const NotificationBundleOption &bundleOption, + const int32_t notificationId, const NotificationButtonOption &buttonOption); + /** * @brief Removes a specified removable notification of other applications. * @note Your application must have platform signature to use this method. diff --git a/interfaces/inner_api/notification_local_activity_button.h b/interfaces/inner_api/notification_local_activity_button.h new file mode 100644 index 000000000..4749be3b2 --- /dev/null +++ b/interfaces/inner_api/notification_local_activity_button.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_ACTIVITY_BUTTON_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_ACTIVITY_BUTTON_H + +#include "base/notification/distributed_notification_service/interfaces/inner_api/notification_button_option.h" +#include "foundation/multimedia/image_framework/interfaces/innerkits/include/pixel_map.h" +#include "message_user.h" +#include "notification_json_convert.h" +#include "parcel.h" +#include "uri.h" +#include + +namespace OHOS { +namespace Notification { +class NotificationLocalActivityButton : public Parcelable, public NotificationJsonConvertionBase { +public: + NotificationLocalActivityButton() = default; + ~NotificationLocalActivityButton() = default; + + /** + * @brief Obtains the text to be displayed as the content of this message. + * + * @return Returns the message content. + */ + std::vector> GetAllButtonOption() const; + + void addSingleButtonOption(std::shared_ptr &buttonOption); + + /** + * @brief Obtains the time when this message arrived. + * + * @return Returns the time when this message arrived. + */ + std::vector> GetAllButtonIcon() const; + + void addSingleButtonIcon(std::shared_ptr &icon); + + + /** + * @brief Returns a string representation of the object. + * + * @return Returns a string representation of the object. + */ + std::string Dump(); + + /** + * @brief Converts a NotificationConversationalMessage object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a NotificationConversationalMessage object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationLocalActivityButton *FromJson(const nlohmann::json &jsonObject); + + /** + * @brief Marshal a object into a Parcel. + * + * @param parcel Indicates the object into the parcel. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationLocalActivityButton *Unmarshalling(Parcel &parcel); + +private: + /** + * @brief Read a NotificationConversationalMessage object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ReadFromParcel(Parcel &parcel); + + std::vector> buttonOptions_ {}; + std::vector> buttonIcons_ {}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_ACTIVITY_BUTTON_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_local_activity_content.h b/interfaces/inner_api/notification_local_activity_content.h new file mode 100644 index 000000000..aa4030fce --- /dev/null +++ b/interfaces/inner_api/notification_local_activity_content.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_ACTIVITY_CONTENT_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_ACTIVITY_CONTENT_H + +#include "base/notification/distributed_notification_service/interfaces/inner_api/notification_capsule.h" +#include "base/notification/distributed_notification_service/interfaces/inner_api/notification_progress.h" +#include "base/notification/distributed_notification_service/interfaces/inner_api/notification_local_activity_button.h" +#include "message_user.h" +#include "notification_basic_content.h" +#include "notification_conversational_message.h" +#include "notification_json_convert.h" +#include "parcel.h" + +namespace OHOS { +namespace Notification { +class NotificationLocalActivityContent : public NotificationBasicContent { +public: + NotificationLocalActivityContent() = default; + ~NotificationLocalActivityContent() = default; + + /** + * @brief Returns a string representation of the object. + * + * @return Returns a string representation of the object. + */ + std::string Dump() override; + + /** + * @brief Converts a NotificationConversationalContent object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a NotificationConversationalContent object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationConversationalContent. + */ + static NotificationLocalActivityContent *FromJson(const nlohmann::json &jsonObject); + + /** + * @brief Marshal a object into a Parcel. + * + * @param parcel Indicates the object into the parcel. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns the NotificationConversationalContent. + */ + static NotificationLocalActivityContent *Unmarshalling(Parcel &parcel); + +protected: + /** + * @brief Read a NotificationConversationalContent object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ReadFromParcel(Parcel &parcel) override; + +private: + + int32_t type_ {0}; + NotificationCapsule capsule_ {}; + NotificationLocalActivityButton button_ {}; + NotificationProgress progress_ {}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CONVERSATIONAL_CONTENT_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_local_activity_subscriber.h b/interfaces/inner_api/notification_local_activity_subscriber.h new file mode 100644 index 000000000..d7afeb479 --- /dev/null +++ b/interfaces/inner_api/notification_local_activity_subscriber.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_H + +#include "ans_manager_interface.h" +#include "ans_subscriber_stub.h" +#include "ans_subscriber_local_activity_stub.h" +#include "notification_request.h" +#include "notification_sorting.h" +#include "notification_sorting_map.h" + +namespace OHOS { +namespace Notification { +class NotificationLocalActivitySubscriber { +public: + NotificationLocalActivitySubscriber(); + + virtual ~NotificationLocalActivitySubscriber(); + + /** + * @brief Called back when the subscriber is connected to the Advanced Notification Service (ANS). + **/ + virtual void OnConnected() = 0; + + /** + * @brief Called back when the subscriber is disconnected from the ANS. + **/ + virtual void OnDisconnected() = 0; + + virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) = 0; + + /** + * @brief Called back when connection to the ANS has died. + **/ + virtual void OnDied() = 0; + +private: + class SubscriberLocalActivityImpl final : public AnsSubscriberLocalActivityStub { + public: + class DeathRecipient final : public IRemoteObject::DeathRecipient { + public: + DeathRecipient(SubscriberLocalActivityImpl &subscriberImpl); + + ~DeathRecipient(); + + void OnRemoteDied(const wptr &object) override; + + private: + SubscriberLocalActivityImpl &subscriberImpl_; + }; + + public: + SubscriberLocalActivityImpl(NotificationLocalActivitySubscriber &subscriber); + ~SubscriberLocalActivityImpl() {}; + + void OnConnected() override; + + void OnDisconnected() override; + + void OnResponse(int32_t notificationId, const sptr &buttonOption) override; + + bool GetAnsManagerProxy(); + + public: + NotificationLocalActivitySubscriber &subscriber_; + sptr recipient_ {nullptr}; + sptr proxy_ {nullptr}; + std::mutex mutex_ {}; + }; + +private: + const sptr GetImpl() const; + +private: + sptr impl_ = nullptr; + + friend class AnsNotification; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_progress.h b/interfaces/inner_api/notification_progress.h new file mode 100644 index 000000000..ef2e179ff --- /dev/null +++ b/interfaces/inner_api/notification_progress.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PROGRESS_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PROGRESS_H + +#include "notification_json_convert.h" +#include "parcel.h" +#include + +namespace OHOS { +namespace Notification { +class NotificationProgress : public Parcelable, public NotificationJsonConvertionBase { +public: + NotificationProgress() = default; + ~NotificationProgress() = default; + + /** + * @brief Obtains the text to be displayed as the content of this message. + * + * @return Returns the message content. + */ + int32_t GetMaxValue() const; + + void SetMaxValue(int32_t maxValue); + + /** + * @brief Obtains the time when this message arrived. + * + * @return Returns the time when this message arrived. + */ + int32_t GetCurrentValue() const; + + void SetCurrentValue(int32_t curValue); + + /** + * @brief Obtains the sender of this message. + * + * @return Returns the message sender. + */ + int32_t GetIsPercentage() const; + + void SetIsPercentage(int32_t isPercentage); + + /** + * @brief Returns a string representation of the object. + * + * @return Returns a string representation of the object. + */ + std::string Dump(); + + /** + * @brief Converts a NotificationConversationalMessage object into a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ToJson(nlohmann::json &jsonObject) const override; + + /** + * @brief Creates a NotificationConversationalMessage object from a Json. + * + * @param jsonObject Indicates the Json object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationProgress *FromJson(const nlohmann::json &jsonObject); + + /** + * @brief Marshal a object into a Parcel. + * + * @param parcel Indicates the object into the parcel. + * @return Returns true if succeed; returns false otherwise. + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * @brief Unmarshal object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns the NotificationConversationalMessage. + */ + static NotificationProgress *Unmarshalling(Parcel &parcel); + +private: + /** + * @brief Read a NotificationConversationalMessage object from a Parcel. + * + * @param parcel Indicates the parcel object. + * @return Returns true if succeed; returns false otherwise. + */ + bool ReadFromParcel(Parcel &parcel); + +private: + int32_t maxValue_ {0}; + int32_t currentValue_ {0}; + int32_t isPercentage_ {0}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_PROGRESS_H \ No newline at end of file diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index edc6d381a..e7b654248 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("libans") { "src/bundle_manager_helper.cpp", "src/event_report.cpp", "src/notification_dialog.cpp", + "src/notification_local_activity_subscriber_manager.cpp", "src/notification_preferences.cpp", "src/notification_preferences_database.cpp", "src/notification_preferences_info.cpp", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index c39458f3d..429792375 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -263,6 +263,18 @@ public: */ ErrCode HasNotificationPolicyAccessPermission(bool &granted) override; + /** + * @brief Trigger the local activity after the button has been clicked. + * @note Your application must have platform signature to use this method. + * + * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. + * @param notificationId Indicates the id of the notification. + * @param buttonOption Indicates which button has been clicked. + * @return Returns trigger localActivity result. + */ + ErrCode TriggerLocalActivity(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) override; + /** * @brief Delete notification. * @@ -401,6 +413,16 @@ public: ErrCode Subscribe(const sptr &subscriber, const sptr &info) override; + /** + * @brief Subscribes notifications. + * + * @param subscriber Indicates the subscriber. + * @param info Indicates the NotificationSubscribeInfo object. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode SubscribeLocalActivity(const sptr &subscriber, + const sptr &info) override; + /** * @brief Unsubscribes notifications. * diff --git a/services/ans/include/notification_local_activity_subscriber_manager.h b/services/ans/include/notification_local_activity_subscriber_manager.h new file mode 100644 index 000000000..7fe2a349e --- /dev/null +++ b/services/ans/include/notification_local_activity_subscriber_manager.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_LOCAL_ACTIVITY_MANAGER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_LOCAL_ACTIVITY_MANAGER_H + +#include +#include +#include + +#include "errors.h" +#include "event_handler.h" +#include "event_runner.h" +#include "ffrt.h" +#include "nocopyable.h" +#include "refbase.h" +#include "singleton.h" + +#include "ans_subscriber_local_activity_interface.h" +#include "notification_bundle_option.h" +#include "notification_constant.h" +#include "notification_request.h" +#include "notification_sorting_map.h" +#include "notification_subscribe_info.h" + +namespace OHOS { +namespace Notification { +class NotificationLocalActivitySubscriberManager : public DelayedSingleton { +public: + /** + * @brief Add a subscriber. + * + * @param subscriber Indicates the AnsSubscriberInterface object. + * @param subscribeInfo Indicates the NotificationSubscribeInfo object. + * @return Indicates the result code. + */ + ErrCode AddLocalActivitySubscriber(const sptr &subscriber, + const sptr &subscribeInfo); + + /** + * @brief Remove a subscriber. + * + * @param subscriber Indicates the AnsSubscriberInterface object. + * @param subscribeInfo Indicates the NotificationSubscribeInfo object. + * @return Indicates the result code. + */ + ErrCode RemoveLocalActivitySubscriber( + const sptr &subscriber, const sptr &subscribeInfo); + + + /** + * @brief Notify all subscribers on canceled. + * + * @param notification Indicates the Notification object. + * @param buttonOption Indicates the buttonOption object. + */ + void NotifyTriggerResponse(const sptr ¬ification, const sptr &buttonOption); + + /** + * @brief Obtains the death event. + * + * @param object Indicates the death object. + */ + void OnRemoteDied(const wptr &object); + + /** + * @brief Reset ffrt queue + */ + void ResetFfrtQueue(); + +private: + struct LocalActivitySubscriberRecord; + + std::shared_ptr FindSubscriberRecord(const wptr &object); + std::shared_ptr FindSubscriberRecord(const sptr &subscriber); + std::shared_ptr CreateSubscriberRecord(const sptr &subscriber); + + ErrCode AddSubscriberInner( + const sptr &subscriber, const sptr &subscribeInfo); + ErrCode RemoveSubscriberInner( + const sptr &subscriber, const sptr &subscribeInfo); + + void NotifyTriggerResponseInner(const sptr ¬ification, const sptr &buttonOption); + bool IsSystemUser(int32_t userId); + +private: + std::list> buttonRecordList_ {}; + std::shared_ptr runner_ {}; + std::shared_ptr handler_ {}; + sptr ansSubscriberProxy_ {}; + sptr recipient_ {}; + std::shared_ptr notificationButtonQueue_ = nullptr; + + DECLARE_DELAYED_SINGLETON(NotificationLocalActivitySubscriberManager); + DISALLOW_COPY_AND_MOVE(NotificationLocalActivitySubscriberManager); +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_LOCAL_ACTIVITY_MANAGER_H \ No newline at end of file diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 88bf369f2..b8444a6d5 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -45,6 +45,7 @@ #include "notification_slot.h" #include "notification_slot_filter.h" #include "notification_subscriber_manager.h" +#include "notification_local_activity_subscriber_manager.h" #include "os_account_manager.h" #include "permission_filter.h" #include "push_callback_proxy.h" @@ -1512,6 +1513,42 @@ ErrCode AdvancedNotificationService::Subscribe( return errCode; } +ErrCode AdvancedNotificationService::SubscribeLocalActivity( + const sptr &subscriber, const sptr &info) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + ANS_LOGD("%{public}s", __FUNCTION__); + + ErrCode errCode = ERR_OK; + do { + if (subscriber == nullptr) { + errCode = ERR_ANS_INVALID_PARAM; + break; + } + + // ¶©ÔÄ×Ô¼º È¥µôȨÏÞУÑé + bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { + ANS_LOGE("Client is not a system app or subsystem"); + errCode = ERR_ANS_NON_SYSTEM_APP; + break; + } + + if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { + errCode = ERR_ANS_PERMISSION_DENIED; + break; + } + + errCode = NotificationLocalActivitySubscriberManager::GetInstance()->AddLocalActivitySubscriber(subscriber, info); + if (errCode != ERR_OK) { + break; + } + } while (0); + + SendSubscribeHiSysEvent(IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid(), info, errCode); + return errCode; +} + ErrCode AdvancedNotificationService::Unsubscribe( const sptr &subscriber, const sptr &info) { @@ -2573,6 +2610,49 @@ ErrCode AdvancedNotificationService::AddSlotByType(NotificationConstant::SlotTyp return result; } +ErrCode AdvancedNotificationService::TriggerLocalActivity(const sptr &bundleOption, + const int32_t notificationId, const sptr &buttonOption) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + ANS_LOGD("%{public}s", __FUNCTION__); + + bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); + if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { + return ERR_ANS_NON_SYSTEM_APP; + } + + if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { + ANS_LOGD("CheckPermission is bogus."); + return ERR_ANS_PERMISSION_DENIED; + } + + sptr bundle = GenerateValidBundleOption(bundleOption); + if (bundle == nullptr) { + return ERR_ANS_INVALID_BUNDLE; + } + + ErrCode result = ERR_ANS_NOTIFICATION_NOT_EXISTS; + ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() { + ANS_LOGD("ffrt enter!"); + sptr notification = nullptr; + + for (auto record : notificationList_) { + if ((record->bundleOption->GetBundleName() == bundle->GetBundleName()) && + (record->bundleOption->GetUid() == bundle->GetUid()) && + (record->notification->GetId() == notificationId)) { + notification = record->notification; + result = ERR_OK; + break; + } + } + + if (notification != nullptr) { + NotificationLocalActivitySubscriberManager::GetInstance()->NotifyTriggerResponse(notification, buttonOption); + } + })); + notificationSvrQueue_->wait(handler); + return result; +} ErrCode AdvancedNotificationService::RemoveNotification(const sptr &bundleOption, int32_t notificationId, const std::string &label, int32_t removeReason) { diff --git a/services/ans/src/notification_local_activity_subscriber_manager.cpp b/services/ans/src/notification_local_activity_subscriber_manager.cpp new file mode 100644 index 000000000..6b3f3326d --- /dev/null +++ b/services/ans/src/notification_local_activity_subscriber_manager.cpp @@ -0,0 +1,283 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_local_activity_subscriber_manager.h" + +#include +#include +#include + +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "ans_watchdog.h" +#include "hitrace_meter.h" +#include "ipc_skeleton.h" +#include "notification_button_option.h" +#include "os_account_manager.h" +#include "remote_death_recipient.h" +#include "bundle_manager_helper.h" + +namespace OHOS { +namespace Notification { +struct NotificationLocalActivitySubscriberManager::LocalActivitySubscriberRecord { + sptr subscriber {nullptr}; + std::string bundleName {}; + int32_t userId {SUBSCRIBE_USER_INIT}; +}; + +NotificationLocalActivitySubscriberManager::NotificationLocalActivitySubscriberManager() +{ + ANS_LOGI("constructor"); + notificationButtonQueue_ = std::make_shared("NotificationLocalActivityMgr"); + recipient_ = new (std::nothrow) + RemoteDeathRecipient(std::bind(&NotificationLocalActivitySubscriberManager::OnRemoteDied, this, std::placeholders::_1)); + if (recipient_ == nullptr) { + ANS_LOGE("Failed to create RemoteDeathRecipient instance"); + } +} + +NotificationLocalActivitySubscriberManager::~NotificationLocalActivitySubscriberManager() +{ + ANS_LOGI("deconstructor"); + buttonRecordList_.clear(); +} + +void NotificationLocalActivitySubscriberManager::ResetFfrtQueue() +{ + if (notificationButtonQueue_ != nullptr) { + notificationButtonQueue_.reset(); + } +} + +ErrCode NotificationLocalActivitySubscriberManager::AddLocalActivitySubscriber( + const sptr &subscriber, const sptr &subscribeInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (subscriber == nullptr) { + ANS_LOGE("subscriber is null."); + return ERR_ANS_INVALID_PARAM; + } + + sptr subInfo = subscribeInfo; + if (subInfo == nullptr) { + subInfo = new (std::nothrow) NotificationSubscribeInfo(); + if (subInfo == nullptr) { + ANS_LOGE("Failed to create NotificationSubscribeInfo ptr."); + return ERR_ANS_NO_MEMORY; + } + } + + if (subInfo->GetAppUserId() == SUBSCRIBE_USER_INIT) { + int32_t userId = SUBSCRIBE_USER_INIT; + int32_t callingUid = IPCSkeleton::GetCallingUid(); + ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); + if (ret != ERR_OK) { + ANS_LOGD("Get userId failed, callingUid = <%{public}d>", callingUid); + return ERR_ANS_INVALID_PARAM; + } + + ANS_LOGD("Get userId succeeded, callingUid = <%{public}d> userId = <%{public}d>", callingUid, userId); + subInfo->AddAppUserId(userId); + } + + ErrCode result = ERR_ANS_TASK_ERR; + if (notificationButtonQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); + return result; + } + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationButtonQueue_->submit_h(std::bind([this, &subscriber, &subInfo, &result]() { + ANS_LOGE("ffrt enter!"); + result = this->AddSubscriberInner(subscriber, subInfo); + })); + notificationButtonQueue_->wait(handler); + ANS_LOGE("ffrt end!"); + return result; +} + +ErrCode NotificationLocalActivitySubscriberManager::RemoveLocalActivitySubscriber( + const sptr &subscriber, const sptr &subscribeInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (subscriber == nullptr) { + ANS_LOGE("subscriber is null."); + return ERR_ANS_INVALID_PARAM; + } + + ErrCode result = ERR_ANS_TASK_ERR; + if (notificationButtonQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); + return result; + } + ANS_LOGE("ffrt start!"); + ffrt::task_handle handler = notificationButtonQueue_->submit_h(std::bind([this, &subscriber, + &subscribeInfo, &result]() { + ANS_LOGE("ffrt enter!"); + result = this->RemoveSubscriberInner(subscriber, subscribeInfo); + })); + notificationButtonQueue_->wait(handler); + ANS_LOGE("ffrt end!"); + return result; +} + +void NotificationLocalActivitySubscriberManager::NotifyTriggerResponse(const sptr ¬ification, + const sptr &buttonOption) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + if (notificationButtonQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); + return; + } + AppExecFwk::EventHandler::Callback NotifyTriggerResponseFunc = + std::bind(&NotificationLocalActivitySubscriberManager::NotifyTriggerResponseInner, this, notification, buttonOption); + + ANS_LOGE("ffrt start!"); + notificationButtonQueue_->submit(NotifyTriggerResponseFunc); + ANS_LOGE("ffrt end!"); +} + +void NotificationLocalActivitySubscriberManager::OnRemoteDied(const wptr &object) +{ + ANS_LOGI("OnRemoteDied"); + if (notificationButtonQueue_ == nullptr) { + ANS_LOGE("queue is nullptr"); + return; + } + ffrt::task_handle handler = notificationButtonQueue_->submit_h(std::bind([this, object]() { + ANS_LOGE("ffrt enter!"); + std::shared_ptr record = FindSubscriberRecord(object); + if (record != nullptr) { + ANS_LOGW("subscriber removed."); + buttonRecordList_.remove(record); + } + })); + ANS_LOGE("ffrt start!"); + notificationButtonQueue_->wait(handler); + ANS_LOGE("ffrt end!"); +} + +std::shared_ptr NotificationLocalActivitySubscriberManager::FindSubscriberRecord( + const wptr &object) +{ + auto iter = buttonRecordList_.begin(); + + for (; iter != buttonRecordList_.end(); iter++) { + if ((*iter)->subscriber->AsObject() == object) { + return (*iter); + } + } + return nullptr; +} + +std::shared_ptr NotificationLocalActivitySubscriberManager::FindSubscriberRecord( + const sptr &subscriber) +{ + auto iter = buttonRecordList_.begin(); + + for (; iter != buttonRecordList_.end(); iter++) { + if ((*iter)->subscriber->AsObject() == subscriber->AsObject()) { + return (*iter); + } + } + return nullptr; +} + +std::shared_ptr NotificationLocalActivitySubscriberManager::CreateSubscriberRecord( + const sptr &subscriber) +{ + std::shared_ptr record = std::make_shared(); + // set bundleName and uid + int32_t callingUid = IPCSkeleton::GetCallingUid(); + std::string bundle; + std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); + if (bundleManager != nullptr) { + bundle = bundleManager->GetBundleNameByUid(callingUid); + } + + if (record != nullptr) { + record->subscriber = subscriber; + record->bundleName = bundle; + record->userId = callingUid; + } + return record; +} + + +ErrCode NotificationLocalActivitySubscriberManager::AddSubscriberInner( + const sptr &subscriber, const sptr &subscribeInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + std::shared_ptr record = FindSubscriberRecord(subscriber); + if (record == nullptr) { + record = CreateSubscriberRecord(subscriber); + if (record == nullptr) { + ANS_LOGE("CreateSubscriberRecord failed."); + return ERR_ANS_NO_MEMORY; + } + buttonRecordList_.push_back(record); + + record->subscriber->AsObject()->AddDeathRecipient(recipient_); + + record->subscriber->OnConnected(); + ANS_LOGI("subscriber is connected."); + } + + return ERR_OK; +} + +ErrCode NotificationLocalActivitySubscriberManager::RemoveSubscriberInner( + const sptr &subscriber, const sptr &subscribeInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + std::shared_ptr record = FindSubscriberRecord(subscriber); + + if (record == nullptr) { + ANS_LOGE("subscriber not found."); + return ERR_ANS_INVALID_PARAM; + } + + record->subscriber->AsObject()->RemoveDeathRecipient(recipient_); + + buttonRecordList_.remove(record); + + record->subscriber->OnDisconnected(); + ANS_LOGI("subscriber is disconnected."); + + return ERR_OK; +} + +void NotificationLocalActivitySubscriberManager::NotifyTriggerResponseInner(const sptr ¬ification, const sptr &buttonOption) +{ + ANS_LOGE("ffrt enter!"); + HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + ANS_LOGD("%{public}s notification->GetUserId <%{public}d>", __FUNCTION__, notification->GetUserId()); + int32_t sendUserId = notification->GetUserId(); + for (auto record : buttonRecordList_) { + ANS_LOGD("%{public}s record->userId = <%{public}d>", __FUNCTION__, record->userId); + auto bundleName = notification->GetBundleName(); + if (record->bundleName == bundleName && record->userId == sendUserId) { + record->subscriber->OnResponse(notification->GetId(), buttonOption); + } + } +} + +bool NotificationLocalActivitySubscriberManager::IsSystemUser(int32_t userId) +{ + return ((userId >= SUBSCRIBE_USER_SYSTEM_BEGIN) && (userId <= SUBSCRIBE_USER_SYSTEM_END)); +} + +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 6be270eeb..a2c646ab5 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -584,6 +584,12 @@ void ReminderDataManager::UpdateAndSaveReminderLocked( reminder->InitReminderId(); reminder->InitUserId(ReminderRequest::GetUserId(bundleOption->GetUid())); reminder->InitUid(bundleOption->GetUid()); + + if (reminder->GetTriggerTimeInMilli() == ReminderRequest::INVALID_LONG_LONG_VALUE) { + ANSR_LOGW("now publish reminder is expired. reminder is =%{public}s", + reminder->Dump().c_str()); + reminder->SetExpired(true); + } int32_t reminderId = reminder->GetReminderId(); ANSR_LOGD("Containers(map) add. reminderId=%{public}d", reminderId); auto ret = notificationBundleOptionMap_.insert( @@ -714,7 +720,13 @@ void ReminderDataManager::ShowActiveReminderExtendLocked(sptr & if ((*it)->IsExpired()) { continue; } - if ((*it)->GetTriggerTimeInMilli() - triggerTime > ReminderRequest::SAME_TIME_DISTINGUISH_MILLISECONDS) { + uint64_t tempTriggerTime = (*it)->GetTriggerTimeInMilli(); + if (tempTriggerTime < triggerTime) { + ANSR_LOGE("this reminder triggerTime is less than target triggerTime. " + "now trigger time is %{public}llu.", tempTriggerTime); + continue; + } + if (tempTriggerTime - triggerTime > ReminderRequest::SAME_TIME_DISTINGUISH_MILLISECONDS) { continue; } if (!isAlerting) { -- Gitee From 75aec38283f4d62ffbb9ac6ee7ff6bd10d4853cf Mon Sep 17 00:00:00 2001 From: dongqingran Date: Sat, 21 Oct 2023 09:49:58 +0800 Subject: [PATCH 02/12] local activity parse js object with napi Signed-off-by: dongqingran --- .../notification_local_activity_button.cpp | 59 +--- .../notification_local_activity_content.cpp | 21 ++ ...notification_local_activity_subscriber.cpp | 4 +- frameworks/js/napi/include/common.h | 70 ++++- frameworks/js/napi/src/common.cpp | 295 ++++++++++++++++++ .../notification_local_activity_button.h | 6 +- .../notification_local_activity_content.h | 30 ++ 7 files changed, 433 insertions(+), 52 deletions(-) diff --git a/frameworks/ans/src/notification_local_activity_button.cpp b/frameworks/ans/src/notification_local_activity_button.cpp index 6894d4300..ba3435438 100644 --- a/frameworks/ans/src/notification_local_activity_button.cpp +++ b/frameworks/ans/src/notification_local_activity_button.cpp @@ -32,19 +32,19 @@ namespace OHOS { namespace Notification { -std::vector> NotificationLocalActivityButton::GetAllButtonOption() const +std::vector NotificationLocalActivityButton::GetAllButtonNames() const { - return buttonOptions_; + return buttonNames_; } -void NotificationLocalActivityButton::addSingleButtonOption(std::shared_ptr &buttonOption) +void NotificationLocalActivityButton::addSingleButtonName(const std::string &buttonName) { - if (buttonOptions_.size() >= 3) { + if (buttonNames_.size() >= 3) { ANS_LOGW("already added 3 buttonOption"); return; } - buttonOptions_.emplace_back(buttonOption); + buttonNames_.emplace_back(buttonName); } std::vector> NotificationLocalActivityButton::GetAllButtonIcon() const @@ -75,20 +75,8 @@ std::string NotificationLocalActivityButton::Dump() bool NotificationLocalActivityButton::ToJson(nlohmann::json &jsonObject) const { nlohmann::json buttonsArr = nlohmann::json::array(); - for (auto &btn : buttonOptions_) { - if (!btn) { - continue; - } - nlohmann::json btnObj; - if (!NotificationJsonConverter::ConvertToJson(btn.get(), btnObj)) { - ANS_LOGE("Cannot convert actionButton to JSON"); - return false; - } - - buttonsArr.emplace_back(btnObj); - } - jsonObject["buttonOptions"] = buttonsArr; + jsonObject["buttonNames"] = nlohmann::json(buttonNames_); nlohmann::json iconsArr = nlohmann::json::array(); for (auto &btn : buttonIcons_) { @@ -118,16 +106,8 @@ NotificationLocalActivityButton *NotificationLocalActivityButton::FromJson(const const auto &jsonEnd = jsonObject.cend(); - if (jsonObject.find("buttonOptions") != jsonEnd) { - auto optionArr = jsonObject.at("buttonOptions"); - for (auto &optObj : optionArr) { - auto pOpt = NotificationJsonConverter::ConvertFromJson(optObj); - if (pOpt == nullptr) { - ANS_LOGE("Failed to parse button option"); - return nullptr; - } - button->buttonOptions_.emplace_back(pOpt); - } + if (jsonObject.find("buttonNames") != jsonEnd && jsonObject.at("buttonNames").is_array()) { + button->buttonNames_ = jsonObject.at("buttonNames").get>(); } if (jsonObject.find("buttonIcons") != jsonEnd) { @@ -148,18 +128,11 @@ NotificationLocalActivityButton *NotificationLocalActivityButton::FromJson(const bool NotificationLocalActivityButton::Marshalling(Parcel &parcel) const { - if (!parcel.WriteUint64(buttonOptions_.size())) { - ANS_LOGE("Failed to write the size of buttonOptions"); + if (!parcel.WriteStringVector(buttonNames_)) { + ANS_LOGE("Failed to write buttonNames"); return false; } - for (auto it = buttonOptions_.begin(); it != buttonOptions_.end(); ++it) { - if (!parcel.WriteParcelable(it->get())) { - ANS_LOGE("Failed to write buttonOptions"); - return false; - } - } - if (!parcel.WriteUint64(buttonIcons_.size())) { ANS_LOGE("Failed to write the size of buttonIcons"); return false; @@ -179,15 +152,9 @@ bool NotificationLocalActivityButton::ReadFromParcel(Parcel &parcel) { auto vsize = parcel.ReadUint64(); vsize = (vsize < 3) ? vsize : 3; - for (uint64_t it = 0; it < vsize; ++it) { - auto member = parcel.ReadParcelable(); - if (member == nullptr) { - buttonOptions_.clear(); - ANS_LOGE("Failed to read actionButton"); - return false; - } - - buttonOptions_.emplace_back(member); + if (!parcel.ReadStringVector(&buttonNames_)) { + ANS_LOGE("Failed to read button names"); + return false; } vsize = parcel.ReadUint64(); diff --git a/frameworks/ans/src/notification_local_activity_content.cpp b/frameworks/ans/src/notification_local_activity_content.cpp index cd45c124b..1e97cb994 100644 --- a/frameworks/ans/src/notification_local_activity_content.cpp +++ b/frameworks/ans/src/notification_local_activity_content.cpp @@ -31,6 +31,27 @@ namespace OHOS { namespace Notification { + +void NotificationLocalActivityContent::SetType(int32_t type) +{ + type_ = type; +} + +void NotificationLocalActivityContent::SetCapsule(NotificationCapsule capsule) +{ + capsule_ = capsule; +} + +void NotificationLocalActivityContent::SetButton(NotificationLocalActivityButton button) +{ + button_ = button; +} + +void NotificationLocalActivityContent::SetProgress(std::shared_ptr progress) +{ + progress_ = progress; +} + std::string NotificationLocalActivityContent::Dump() { return "NotificationLocalActivityContent{ " + NotificationBasicContent::Dump() + diff --git a/frameworks/ans/src/notification_local_activity_subscriber.cpp b/frameworks/ans/src/notification_local_activity_subscriber.cpp index d094e0ea9..6d4bd736c 100644 --- a/frameworks/ans/src/notification_local_activity_subscriber.cpp +++ b/frameworks/ans/src/notification_local_activity_subscriber.cpp @@ -59,10 +59,10 @@ void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnDisconn subscriber_.OnDisconnected(); } -void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnResponse(int32_t notificationId, const sptr &buttonOption) +void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnResponse(int32_t notificationId, const std::string &buttonName) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - subscriber_.OnResponse(notificationId, buttonOption); + subscriber_.OnResponse(notificationId, buttonName); } bool NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::GetAnsManagerProxy() diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index d7bb8acf9..a55cfc6f4 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -19,6 +19,7 @@ #include "napi/native_api.h" #include "napi/native_node_api.h" #include "notification_helper.h" +#include "notification_local_activity_button.h" namespace OHOS { namespace NotificationNapi { @@ -38,7 +39,8 @@ enum class ContentType { NOTIFICATION_CONTENT_LONG_TEXT, NOTIFICATION_CONTENT_PICTURE, NOTIFICATION_CONTENT_CONVERSATION, - NOTIFICATION_CONTENT_MULTILINE + NOTIFICATION_CONTENT_MULTILINE, + NOTIFICATION_CONTENT_LOCAL_ACTIVITY }; enum class SlotType { @@ -1203,6 +1205,72 @@ public: const napi_env &env, const napi_value &contentResult, std::shared_ptr &pictureContent); + /** + * @brief Gets a NotificationLocalActivityContent object from specified js object + * + * @param env Indicates the environment that the API is invoked under + * @param result Indicates a js object to be converted + * @param request Indicates a NotificationLocalActivityContent object from specified js object + * @return Returns the null object if success, returns the null value otherwise + */ + static napi_value GetNotificationLocalActivityContent( + const napi_env &env, const napi_value &result, NotificationRequest &request); + + /** + * @brief Gets a capsule of NotificationLocalActivityContent object from specified js object + * + * @param env Indicates the environment that the API is invoked under + * @param contentResult Indicates a js object to be converted + * @param pictureContent Indicates a capsule object from specified js object + * @return Returns the null object if success, returns the null value otherwise + */ + static napi_value GetNotificationLocalActivityCapsule( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + + /** + * @brief Gets a button of NotificationLocalActivityContent object from specified js object + * + * @param env Indicates the environment that the API is invoked under + * @param contentResult Indicates a js object to be converted + * @param pictureContent Indicates a button object from specified js object + * @return Returns the null object if success, returns the null value otherwise + */ + static napi_value GetNotificationLocalActivityButton( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + + /** + * @brief Gets a time of NotificationLocalActivityContent object from specified js object + * + * @param env Indicates the environment that the API is invoked under + * @param contentResult Indicates a js object to be converted + * @param pictureContent Indicates a time object from specified js object + * @return Returns the null object if success, returns the null value otherwise + */ + static napi_value GetNotificationLocalActivityTime( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + + /** + * @brief Gets a progess of NotificationLocalActivityContent object from specified js object + * + * @param env Indicates the environment that the API is invoked under + * @param contentResult Indicates a js object to be converted + * @param pictureContent Indicates a progess object from specified js object + * @return Returns the null object if success, returns the null value otherwise + */ + static napi_value GetNotificationLocalActivityProgess( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + + /** + * @brief Gets a NotificationPictureContent object from specified js object + * + * @param env Indicates the environment that the API is invoked under + * @param contentResult Indicates a js object to be converted + * @param pictureContent Indicates a NotificationPictureContent object from specified js object + * @return Returns the null object if success, returns the null value otherwise + */ + static napi_value GetNotificationLocalActivityContentDetailed( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + /** * @brief Gets a conversational content of NotificationRequest object from specified js object * diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index f1614d2dd..8e79e07f7 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -16,6 +16,9 @@ #include "common.h" #include "ans_inner_errors.h" #include "napi_common.h" +#include "notification_action_button.h" +#include "notification_capsule.h" +#include "notification_progress.h" #include "pixel_map_napi.h" namespace OHOS { @@ -1794,6 +1797,11 @@ napi_value Common::GetNotificationContent(const napi_env &env, const napi_value return nullptr; } break; + case NotificationContent::Type::LOCAL_ACTIVITY: + if (GetNotificationLocalActivityContent(env, result, request) == nullptr) { + return nullptr; + } + break; default: return nullptr; } @@ -3976,6 +3984,290 @@ napi_value Common::GetNotificationMultiLineContentLines(const napi_env &env, con return NapiGetNull(env); } +napi_value Common::GetNotificationLocalActivityContent( + const napi_env &env, const napi_value &result, NotificationRequest &request) +{ + ANS_LOGI("enter"); + + napi_valuetype valuetype = napi_undefined; + napi_value contentResult = nullptr; + bool hasProperty = false; + NAPI_CALL(env, napi_has_named_property(env, result, "localActivity", &hasProperty)); + if (!hasProperty) { + ANS_LOGE("Property normal expected."); + return nullptr; + } + napi_get_named_property(env, result, "localActivity", &contentResult); + NAPI_CALL(env, napi_typeof(env, contentResult, &valuetype)); + if (valuetype != napi_object) { + ANS_LOGE("Wrong argument type. Object expected."); + return nullptr; + } + + std::shared_ptr localActivityContent = std::make_shared(); + if (localActivityContent == nullptr) { + ANS_LOGE("localActivityContent is null"); + return nullptr; + } + + if (GetNotificationLocalActivityContentDetailed(env, contentResult, localActivityContent) == nullptr) { + return nullptr; + } + + request.SetContent(std::make_shared(localActivityContent)); + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationLocalActivityCapsule( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content) +{ + napi_value capsuleResult = nullptr; + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + size_t strLen = 0; + char str[STR_MAX_SIZE] = {0}; + std::shared_ptr pixelMap = nullptr; + napi_value result = nullptr; + + napi_get_named_property(env, contentResult, "capsule", &capsuleResult); + NAPI_CALL(env, napi_typeof(env, capsuleResult, &valuetype)); + if (valuetype != napi_object) { + ANS_LOGE("Wrong argument type. Object expected."); + return nullptr; + } + + NotificationCapsule capsule; + + NAPI_CALL(env, napi_has_named_property(env, capsuleResult, "title", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, capsuleResult, "title", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + if (valuetype != napi_string) { + ANS_LOGE("Wrong argument type. String expected."); + return nullptr; + } + + NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); + capsule.SetTitle(str); + } + + NAPI_CALL(env, napi_has_named_property(env, capsuleResult, "backgroundColor", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, capsuleResult, "backgroundColor", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + if (valuetype != napi_string) { + ANS_LOGE("Wrong argument type. String expected."); + return nullptr; + } + + NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); + capsule.SetBackgroundColor(str); + } + + NAPI_CALL(env, napi_has_named_property(env, capsuleResult, "icon", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, capsuleResult, "icon", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + if (valuetype != napi_object) { + ANS_LOGE("Wrong argument type. Object expected."); + return nullptr; + } + pixelMap = Media::PixelMapNapi::GetPixelMap(env, result); + if (pixelMap == nullptr) { + ANS_LOGE("Invalid object pixelMap"); + return nullptr; + } + capsule.SetIcon(pixelMap); + } + + content->SetCapsule(capsule); + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationLocalActivityButton( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content) +{ + napi_value result = nullptr; + napi_valuetype valuetype = napi_undefined; + bool isArray = false; + uint32_t length = 0; + napi_value buttonResult = nullptr; + bool hasProperty = false; + char str[STR_MAX_SIZE] = {0}; + size_t strLen = 0; + + napi_get_named_property(env, contentResult, "button", &buttonResult); + NAPI_CALL(env, napi_typeof(env, buttonResult, &valuetype)); + if (valuetype != napi_object) { + ANS_LOGE("Wrong argument type. Object expected."); + return nullptr; + } + + NotificationLocalActivityButton button; + + NAPI_CALL(env, napi_has_named_property(env, buttonResult, "buttonNames", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, buttonResult, "icon", &result); + napi_is_array(env, result, &isArray); + if (!isArray) { + ANS_LOGE("Property buttonNames is expected to be an array."); + return nullptr; + } + napi_get_array_length(env, result, &length); + for (size_t i = 0; i < length; i++) { + napi_value buttonName = nullptr; + napi_get_element(env, result, i, &buttonName); + NAPI_CALL(env, napi_typeof(env, buttonName, &valuetype)); + if (valuetype != napi_string) { + ANS_LOGE("Wrong argument type. String expected."); + return nullptr; + } + NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); + button.addSingleButtonName(str); + } + } + + NAPI_CALL(env, napi_has_named_property(env, buttonResult, "buttonIcons", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, buttonResult, "buttonIcons", &result); + napi_is_array(env, result, &isArray); + if (!isArray) { + ANS_LOGE("Property buttonIcons is expected to be an array."); + return nullptr; + } + napi_get_array_length(env, result, &length); + for (size_t i = 0; i < length; i++) { + napi_value buttonIcon = nullptr; + std::shared_ptr pixelMap = nullptr; + napi_get_element(env, result, i, &buttonIcon); + NAPI_CALL(env, napi_typeof(env, buttonIcon, &valuetype)); + if (valuetype != napi_object) { + ANS_LOGE("Wrong argument type. Object expected."); + return nullptr; + } + pixelMap = Media::PixelMapNapi::GetPixelMap(env, buttonIcon); + if (pixelMap == nullptr) { + ANS_LOGE("Invalid object pixelMap"); + return nullptr; + } + button.addSingleButtonIcon(pixelMap); + } + } + + return NapiGetNull(env); +} + +napi_value Common::GetNotificationLocalActivityProgess( + + + const napi_env &env, const napi_value &contentResult, std::shared_ptr content) +{ + napi_value result = nullptr; + napi_valuetype valuetype = napi_undefined; + bool hasProperty = false; + int32_t intValue = -1; + napi_value progessResult = nullptr; + + napi_get_named_property(env, contentResult, "progess", &progessResult); + NAPI_CALL(env, napi_typeof(env, progessResult, &valuetype)); + if (valuetype != napi_object) { + ANS_LOGE("Wrong argument type. Object expected."); + return nullptr; + } + + NotificationProgress progess; + + NAPI_CALL(env, napi_has_named_property(env, progessResult, "maxValue", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, progessResult, "maxValue", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } + napi_get_value_int32(env, result, &intValue); + progess.SetMaxValue(intValue); + } + + NAPI_CALL(env, napi_has_named_property(env, progessResult, "currentValue", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, progessResult, "currentValue", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } + napi_get_value_int32(env, result, &intValue); + progess.SetCurrentValue(intValue); + } + + NAPI_CALL(env, napi_has_named_property(env, progessResult, "isPercentage", &hasProperty)); + if (hasProperty) { + napi_get_named_property(env, progessResult, "isPercentage", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } + napi_get_value_int32(env, result, &intValue); + progess.SetIsPercentage(intValue); + } + + content->SetProgress(progess); + return NapiGetNull(env); +} + +napi_value Common::GetNotificationLocalActivityContentDetailed( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content) +{ + bool hasProperty = false; + int32_t type = -1; + napi_value result = nullptr; + napi_valuetype valuetype = napi_undefined; + + //title, text + if (GetNotificationBasicContentDetailed(env, contentResult, content) == nullptr) { + return nullptr; + } + + //type + NAPI_CALL(env, napi_has_named_property(env, contentResult, "type", &hasProperty)); + if (!hasProperty) { + ANS_LOGE("Property type expected."); + return nullptr; + } + napi_get_named_property(env, contentResult, "type", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } + napi_get_value_int32(env, result, &type); + content->SetType(type); + + //capsule? + NAPI_CALL(env, napi_has_named_property(env, contentResult, "capsule", &hasProperty)); + if (hasProperty && GetNotificationLocalActivityCapsule(env, result, content) == nullptr) { + return nullptr; + } + + //button? + NAPI_CALL(env, napi_has_named_property(env, contentResult, "button", &hasProperty)); + if (hasProperty && GetNotificationLocalActivityButton(env, result, content) == nullptr) { + return nullptr; + } + + //progess? + NAPI_CALL(env, napi_has_named_property(env, contentResult, "progess", &hasProperty)); + if (hasProperty && GetNotificationLocalActivityProgess(env, result, content) == nullptr) { + return nullptr; + } + + return NapiGetNull(env); +} + napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &value, NotificationSlot &slot) { ANS_LOGI("enter"); @@ -4365,6 +4657,9 @@ bool Common::ContentTypeJSToC(const ContentType &inType, NotificationContent::Ty case ContentType::NOTIFICATION_CONTENT_CONVERSATION: outType = NotificationContent::Type::CONVERSATION; break; + case ContentType::NOTIFICATION_CONTENT_LOCAL_ACTIVITY: + outType = NotificationContent::Type::LOCAL_ACTIVITY; + break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); return false; diff --git a/interfaces/inner_api/notification_local_activity_button.h b/interfaces/inner_api/notification_local_activity_button.h index 4749be3b2..36457f209 100644 --- a/interfaces/inner_api/notification_local_activity_button.h +++ b/interfaces/inner_api/notification_local_activity_button.h @@ -36,9 +36,9 @@ public: * * @return Returns the message content. */ - std::vector> GetAllButtonOption() const; + std::vector GetAllButtonNames() const; - void addSingleButtonOption(std::shared_ptr &buttonOption); + void addSingleButtonName(const std::string &buttonName); /** * @brief Obtains the time when this message arrived. @@ -98,7 +98,7 @@ private: */ bool ReadFromParcel(Parcel &parcel); - std::vector> buttonOptions_ {}; + std::vector buttonNames_ {}; std::vector> buttonIcons_ {}; }; } // namespace Notification diff --git a/interfaces/inner_api/notification_local_activity_content.h b/interfaces/inner_api/notification_local_activity_content.h index aa4030fce..b8c0b1243 100644 --- a/interfaces/inner_api/notification_local_activity_content.h +++ b/interfaces/inner_api/notification_local_activity_content.h @@ -32,6 +32,36 @@ public: NotificationLocalActivityContent() = default; ~NotificationLocalActivityContent() = default; + /* + * @brief Sets the type to be included in a local activity notification. + * + * @param type Indicates the type to be included. + */ + void SetType(int32_t type); + + /* + * @brief Sets the capsule to be included in a local activity notification. + * + * @param capsule Indicates the type to be included. + */ + void SetCapsule(NotificationCapsule capsule); + + /* + * @brief Sets the button to be included in a local activity notification. + * + * @param button Indicates the type to be included. + */ + void SetButton(NotificationLocalActivityButton button); + + /* + * @brief Sets the progress to be included in a local activity notification. + * + * @param progress Indicates the type to be included. + + + */ + void SetProgress(NotificationProgress progress); + /** * @brief Returns a string representation of the object. * -- Gitee From f62d5acafda46947998626898896003ef6de8ad3 Mon Sep 17 00:00:00 2001 From: dongqingran Date: Sat, 21 Oct 2023 09:49:58 +0800 Subject: [PATCH 03/12] local activity parse js object with napi Signed-off-by: dongqingran --- interfaces/inner_api/notification_local_activity_subscriber.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/inner_api/notification_local_activity_subscriber.h b/interfaces/inner_api/notification_local_activity_subscriber.h index d7afeb479..b14232184 100644 --- a/interfaces/inner_api/notification_local_activity_subscriber.h +++ b/interfaces/inner_api/notification_local_activity_subscriber.h @@ -41,7 +41,7 @@ public: **/ virtual void OnDisconnected() = 0; - virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) = 0; + virtual void OnResponse(int32_t notificationId, const std::string &buttonName) = 0; /** * @brief Called back when connection to the ANS has died. @@ -71,7 +71,7 @@ private: void OnDisconnected() override; - void OnResponse(int32_t notificationId, const sptr &buttonOption) override; + void OnResponse(int32_t notificationId, const std::string &buttonName) override; bool GetAnsManagerProxy(); -- Gitee From 660bec1fb05625658f1d3acec228cfbfe2b0346c Mon Sep 17 00:00:00 2001 From: markYao Date: Sat, 21 Oct 2023 10:38:01 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E5=AE=9E=E6=97=B6=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: markYao --- frameworks/ans/src/notification_content.cpp | 11 +++++++++++ .../ans/src/notification_local_activity_content.cpp | 2 +- .../src/notification_local_activity_subscriber.cpp | 4 ++-- frameworks/js/napi/include/common.h | 10 +++++----- .../notification_local_activity_subscriber.h | 4 ++-- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/frameworks/ans/src/notification_content.cpp b/frameworks/ans/src/notification_content.cpp index 244982c2d..a32c3cc5d 100644 --- a/frameworks/ans/src/notification_content.cpp +++ b/frameworks/ans/src/notification_content.cpp @@ -84,6 +84,17 @@ NotificationContent::NotificationContent(const std::shared_ptr &localActivityContent) +{ + if (!localActivityContent) { + ANS_LOGE("NotificationLocalActivityContent can not be null"); + return; + } + + contentType_ = NotificationContent::Type::LOCAL_ACTIVITY; + content_ = localActivityContent; +} + NotificationContent::~NotificationContent() {} diff --git a/frameworks/ans/src/notification_local_activity_content.cpp b/frameworks/ans/src/notification_local_activity_content.cpp index 1e97cb994..b3ce2e863 100644 --- a/frameworks/ans/src/notification_local_activity_content.cpp +++ b/frameworks/ans/src/notification_local_activity_content.cpp @@ -47,7 +47,7 @@ void NotificationLocalActivityContent::SetButton(NotificationLocalActivityButton button_ = button; } -void NotificationLocalActivityContent::SetProgress(std::shared_ptr progress) +void NotificationLocalActivityContent::SetProgress(NotificationProgress progress) { progress_ = progress; } diff --git a/frameworks/ans/src/notification_local_activity_subscriber.cpp b/frameworks/ans/src/notification_local_activity_subscriber.cpp index 6d4bd736c..d094e0ea9 100644 --- a/frameworks/ans/src/notification_local_activity_subscriber.cpp +++ b/frameworks/ans/src/notification_local_activity_subscriber.cpp @@ -59,10 +59,10 @@ void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnDisconn subscriber_.OnDisconnected(); } -void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnResponse(int32_t notificationId, const std::string &buttonName) +void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnResponse(int32_t notificationId, const sptr &buttonOption) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - subscriber_.OnResponse(notificationId, buttonName); + subscriber_.OnResponse(notificationId, buttonOption); } bool NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::GetAnsManagerProxy() diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index a55cfc6f4..209733649 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -1225,7 +1225,7 @@ public: * @return Returns the null object if success, returns the null value otherwise */ static napi_value GetNotificationLocalActivityCapsule( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** * @brief Gets a button of NotificationLocalActivityContent object from specified js object @@ -1236,7 +1236,7 @@ public: * @return Returns the null object if success, returns the null value otherwise */ static napi_value GetNotificationLocalActivityButton( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** * @brief Gets a time of NotificationLocalActivityContent object from specified js object @@ -1247,7 +1247,7 @@ public: * @return Returns the null object if success, returns the null value otherwise */ static napi_value GetNotificationLocalActivityTime( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** * @brief Gets a progess of NotificationLocalActivityContent object from specified js object @@ -1258,7 +1258,7 @@ public: * @return Returns the null object if success, returns the null value otherwise */ static napi_value GetNotificationLocalActivityProgess( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** * @brief Gets a NotificationPictureContent object from specified js object @@ -1269,7 +1269,7 @@ public: * @return Returns the null object if success, returns the null value otherwise */ static napi_value GetNotificationLocalActivityContentDetailed( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** * @brief Gets a conversational content of NotificationRequest object from specified js object diff --git a/interfaces/inner_api/notification_local_activity_subscriber.h b/interfaces/inner_api/notification_local_activity_subscriber.h index b14232184..d7afeb479 100644 --- a/interfaces/inner_api/notification_local_activity_subscriber.h +++ b/interfaces/inner_api/notification_local_activity_subscriber.h @@ -41,7 +41,7 @@ public: **/ virtual void OnDisconnected() = 0; - virtual void OnResponse(int32_t notificationId, const std::string &buttonName) = 0; + virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) = 0; /** * @brief Called back when connection to the ANS has died. @@ -71,7 +71,7 @@ private: void OnDisconnected() override; - void OnResponse(int32_t notificationId, const std::string &buttonName) override; + void OnResponse(int32_t notificationId, const sptr &buttonOption) override; bool GetAnsManagerProxy(); -- Gitee From e51d6cc8c77f090814f8c6791e3be274af7baf8f Mon Sep 17 00:00:00 2001 From: dongqingran Date: Sat, 21 Oct 2023 16:51:37 +0800 Subject: [PATCH 05/12] local activity parse js subscribe onResponse Signed-off-by: dongqingran --- frameworks/js/napi/include/common.h | 10 + .../napi/include/local_activity_subscribe.h | 101 ++++++ .../include/manager/napi_local_activity.h | 30 ++ frameworks/js/napi/src/common.cpp | 15 + frameworks/js/napi/src/manager/BUILD.gn | 2 + .../src/manager/local_activity_subscribe.cpp | 336 ++++++++++++++++++ .../napi/src/manager/napi_local_activity.cpp | 125 +++++++ .../notification_local_activity_subscriber.h | 4 +- 8 files changed, 621 insertions(+), 2 deletions(-) create mode 100644 frameworks/js/napi/include/local_activity_subscribe.h create mode 100644 frameworks/js/napi/include/manager/napi_local_activity.h create mode 100644 frameworks/js/napi/src/manager/local_activity_subscribe.cpp create mode 100644 frameworks/js/napi/src/manager/napi_local_activity.cpp diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 209733649..1c3ad4496 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -228,6 +228,16 @@ public: static void SetCallback( const napi_env &env, const napi_ref &callbackIn, const napi_value &result); + /** + * @brief Calls the callback with the result + * + * @param env Indicates the environment that the API is invoked under + * @param callbackIn Indicates the callback to be called + * @param result Indicates the result returned by the callback + */ + static void SetCallbackArg2( + const napi_env &env, const napi_ref &callbackIn, const napi_value &result0, const napi_value &result1); + /** * @brief Processes the promise with the result and error code * diff --git a/frameworks/js/napi/include/local_activity_subscribe.h b/frameworks/js/napi/include/local_activity_subscribe.h new file mode 100644 index 000000000..5a1475adc --- /dev/null +++ b/frameworks/js/napi/include/local_activity_subscribe.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_INCLUDE_SUBSCRIBE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_INCLUDE_SUBSCRIBE_H + +#include "common.h" + +namespace OHOS { +namespace NotificationNapi { +using namespace OHOS::Notification; + +class LocalActivitySubscriberInstance : public NotificationLocalActivitySubscriber { +public: + LocalActivitySubscriberInstance(); + virtual ~LocalActivitySubscriberInstance(); + + /** + * @brief Called back when a notification is canceled. + * + */ + virtual void OnConnected() override; + + /** + * @brief Called back when the subscriber is disconnected from the ANS. + * + */ + virtual void OnDisconnected() override; + + virtual void OnResponse(int32_t notificationId, sptr buttonOption) override; + + /** + * @brief Called back when connection to the ANS has died. + * + */ + virtual void OnDied() override; + + /** + * @brief Sets the callback information by type. + * + * @param env Indicates the environment that the API is invoked under. + * @param type Indicates the type of callback. + * @param ref Indicates the napi_ref of callback. + */ + void SetCallbackInfo(const napi_env &env, const std::string &type, const napi_ref &ref); + +private: + void SetResponseCallbackInfo(const napi_env &env, const napi_ref &ref); + +private: + struct CallbackInfo { + napi_env env = nullptr; + napi_ref ref = nullptr; + }; + + CallbackInfo responseCallbackInfo_; +}; + +struct LocalActivitySubscriberInstancesInfo { + napi_ref ref = nullptr; + LocalActivitySubscriberInstance *subscriber = nullptr; +}; + +struct AsyncCallbackInfoSubscribeLocalActivity { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + LocalActivitySubscriberInstance *objectInfo = nullptr; + CallbackPromiseInfo info; +}; + +static std::mutex mutex_; +static thread_local std::vector subscriberInstances_; + +static std::mutex delMutex_; +static std::vector DeletingSubscriber; + +bool HasNotificationSubscriber(const napi_env &env, const napi_value &value, LocalActivitySubscriberInstancesInfo &subscriberInfo); +bool AddSubscriberInstancesInfo(const napi_env &env, const LocalActivitySubscriberInstancesInfo &subscriberInfo); +bool DelSubscriberInstancesInfo(const napi_env &env, const LocalActivitySubscriberInstance *subscriber); + +bool AddDeletingSubscriber(LocalActivitySubscriberInstance *subscriber); +void DelDeletingSubscriber(LocalActivitySubscriberInstance *subscriber); + +napi_value Subscribe(napi_env env, napi_callback_info info); + +napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, + LocalActivitySubscriberInstance *&subscriber, napi_ref &callback); +} // namespace NotificationNapi +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_INCLUDE_SUBSCRIBE_H diff --git a/frameworks/js/napi/include/manager/napi_local_activity.h b/frameworks/js/napi/include/manager/napi_local_activity.h new file mode 100644 index 000000000..fb027820c --- /dev/null +++ b/frameworks/js/napi/include/manager/napi_local_activity.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_ACTIVITY_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_ACTIVITY_H + +#include "common.h" + +namespace OHOS { +namespace NotificationNapi { +using namespace OHOS::Notification; + +napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info); +napi_value NapiUnsubscriteLocalActivity(napi_env env, napi_callback_info info); +napi_value NapiTriggerLocalActivity(napi_env env, napi_callback_info info); + +} // namespace NotificationNapi +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_ACTIVITY_H diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index 8e79e07f7..5bc48eb05 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -172,6 +172,21 @@ void Common::SetCallback( ANS_LOGI("end"); } +void Common::SetCallbackArg2( + const napi_env &env, const napi_ref &callbackIn, const napi_value &result0, const napi_value &result1) +{ + ANS_LOGI("enter"); + napi_value result[ARGS_TWO] = {result0, result1}; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + + napi_value callback = nullptr; + napi_value resultout = nullptr; + napi_get_reference_value(env, callbackIn, &callback); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, result, &resultout)); + ANS_LOGI("end"); +} + void Common::SetPromise(const napi_env &env, const napi_deferred &deferred, const int32_t &errorCode, const napi_value &result, bool newType) { diff --git a/frameworks/js/napi/src/manager/BUILD.gn b/frameworks/js/napi/src/manager/BUILD.gn index c84977487..0e2695545 100644 --- a/frameworks/js/napi/src/manager/BUILD.gn +++ b/frameworks/js/napi/src/manager/BUILD.gn @@ -72,6 +72,8 @@ ohos_shared_library("notificationmanager") { "napi_remove_group.cpp", "napi_slot.cpp", "napi_template.cpp", + "napi_local_activity.cpp", + "local_activity_subscribe.cpp", ] deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] diff --git a/frameworks/js/napi/src/manager/local_activity_subscribe.cpp b/frameworks/js/napi/src/manager/local_activity_subscribe.cpp new file mode 100644 index 000000000..d156ac9fb --- /dev/null +++ b/frameworks/js/napi/src/manager/local_activity_subscribe.cpp @@ -0,0 +1,336 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "local_activity_subscribe.h" +#include "notification_button_option.h" + +#include +#include + +namespace OHOS { +namespace NotificationNapi { +const int32_t SUBSRIBE_MAX_PARA = 2; +const std::string RESPONSE = "onResponse"; + +struct LocalActivityReceiveDataWorker { + napi_env env = nullptr; + napi_ref ref = nullptr; + int32_t notificationId; + sptr buttonOption; + LocalActivitySubscriberInstance *subscriber = nullptr; +}; + +LocalActivitySubscriberInstance::LocalActivitySubscriberInstance() +{} + +LocalActivitySubscriberInstance::~LocalActivitySubscriberInstance() +{ + if (responseCallbackInfo_.ref != nullptr) { + napi_delete_reference(responseCallbackInfo_.env, responseCallbackInfo_.ref); + } +} + +void LocalActivitySubscriberInstance::OnDied() +{ + ANS_LOGI("enter"); +} + +void LocalActivitySubscriberInstance::OnConnected() +{ + ANS_LOGI("enter"); +} + +void LocalActivitySubscriberInstance::OnDisconnected() +{ + ANS_LOGI("enter"); +} + +void UvQueueWorkOnResponse(uv_work_t *work, int status) +{ + ANS_LOGI("OnResponse uv_work_t start"); + + if (work == nullptr) { + ANS_LOGE("work is nullptr"); + return; + } + + auto dataWorkerData = reinterpret_cast(work->data); + if (dataWorkerData == nullptr) { + ANS_LOGD("dataWorkerData is null."); + delete work; + work = nullptr; + return; + } + napi_value buttonOption = nullptr; + napi_value buttonName = nullptr; + napi_handle_scope scope; + napi_value notificationId = nullptr; + napi_open_handle_scope(dataWorkerData->env, &scope); + + // notificationId: number + napi_create_int32(dataWorkerData->env, dataWorkerData->notificationId, ¬ificationId); + + napi_create_object(dataWorkerData->env, &buttonOption); + napi_create_string_utf8(dataWorkerData->env, dataWorkerData->buttonOption->GetButtonName().c_str(), + NAPI_AUTO_LENGTH, &buttonName); + napi_set_named_property(dataWorkerData->env, buttonOption, "buttonName", buttonName); + + Common::SetCallbackArg2(dataWorkerData->env, dataWorkerData->ref, notificationId, buttonOption); + napi_close_handle_scope(dataWorkerData->env, scope); + + delete dataWorkerData; + dataWorkerData = nullptr; + delete work; +} + +void LocalActivitySubscriberInstance::OnResponse(int32_t notificationId, sptr buttonOption) +{ + ANS_LOGI("enter"); + + if (responseCallbackInfo_.ref == nullptr) { + ANS_LOGI("response callback unset"); + return; + } + + if (buttonOption == nullptr) { + ANS_LOGE("buttonOption is null"); + return; + } + + ANS_LOGI("OnResponse NotificationId = %{public}d", notificationId); + ANS_LOGI("OnResponse sortingMap size = %{public}s", buttonOption->GetButtonName().c_str()); + + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(responseCallbackInfo_.env, &loop); + if (loop == nullptr) { + ANS_LOGE("loop instance is nullptr"); + return; + } + + LocalActivityReceiveDataWorker *dataWorker = new (std::nothrow) LocalActivityReceiveDataWorker(); + if (dataWorker == nullptr) { + ANS_LOGE("DataWorker is nullptr."); + return; + } + + dataWorker->notificationId = notificationId; + dataWorker->buttonOption = buttonOption; + dataWorker->env = responseCallbackInfo_.env; + dataWorker->ref = responseCallbackInfo_.ref; + + uv_work_t *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + ANS_LOGE("new work failed"); + delete dataWorker; + dataWorker = nullptr; + return; + } + + work->data = reinterpret_cast(dataWorker); + + int ret = uv_queue_work_with_qos(loop, work, [](uv_work_t *work) {}, + UvQueueWorkOnResponse, uv_qos_user_initiated); + if (ret != 0) { + delete dataWorker; + dataWorker = nullptr; + delete work; + work = nullptr; + } +} + +void LocalActivitySubscriberInstance::SetResponseCallbackInfo(const napi_env &env, const napi_ref &ref) +{ + responseCallbackInfo_.env = env; + responseCallbackInfo_.ref = ref; +} + +void LocalActivitySubscriberInstance::SetCallbackInfo(const napi_env &env, const std::string &type, const napi_ref &ref) +{ + if (type == RESPONSE) { + SetResponseCallbackInfo(env, ref); + } else { + ANS_LOGW("type is error"); + } +} + +bool HasNotificationSubscriber(const napi_env &env, const napi_value &value, LocalActivitySubscriberInstancesInfo &subscriberInfo) +{ + std::lock_guard lock(mutex_); + for (auto vec : subscriberInstances_) { + napi_value callback = nullptr; + napi_get_reference_value(env, vec.ref, &callback); + bool isEquals = false; + napi_strict_equals(env, value, callback, &isEquals); + if (isEquals) { + subscriberInfo = vec; + return true; + } + } + return false; +} + +napi_value GetNotificationSubscriber( + const napi_env &env, const napi_value &value, LocalActivitySubscriberInstancesInfo &subscriberInfo) +{ + ANS_LOGI("enter"); + bool hasProperty = false; + napi_valuetype valuetype = napi_undefined; + napi_ref result = nullptr; + + subscriberInfo.subscriber = new (std::nothrow) LocalActivitySubscriberInstance(); + if (subscriberInfo.subscriber == nullptr) { + ANS_LOGE("subscriber is null"); + return nullptr; + } + + napi_create_reference(env, value, 1, &subscriberInfo.ref); + + // onResponse? + NAPI_CALL(env, napi_has_named_property(env, value, "onResponse", &hasProperty)); + if (hasProperty) { + napi_value onResponse = nullptr; + napi_get_named_property(env, value, "onResponse", &onResponse); + NAPI_CALL(env, napi_typeof(env, onResponse, &valuetype)); + if (valuetype != napi_function) { + ANS_LOGE("Wrong argument type. Function expected."); + return nullptr; + } + napi_create_reference(env, onResponse, 1, &result); + subscriberInfo.subscriber->SetCallbackInfo(env, RESPONSE, result); + } + + return Common::NapiGetNull(env); +} + +bool AddSubscriberInstancesInfo(const napi_env &env, const LocalActivitySubscriberInstancesInfo &subscriberInfo) +{ + ANS_LOGI("enter"); + if (subscriberInfo.ref == nullptr) { + ANS_LOGE("subscriberInfo.ref is null"); + return false; + } + if (subscriberInfo.subscriber == nullptr) { + ANS_LOGE("subscriberInfo.subscriber is null"); + return false; + } + std::lock_guard lock(mutex_); + subscriberInstances_.emplace_back(subscriberInfo); + + return true; +} + +bool DelSubscriberInstancesInfo(const napi_env &env, const LocalActivitySubscriberInstance *subscriber) +{ + ANS_LOGI("enter"); + if (subscriber == nullptr) { + ANS_LOGE("subscriber is null"); + return false; + } + + std::lock_guard lock(mutex_); + for (auto it = subscriberInstances_.begin(); it != subscriberInstances_.end(); ++it) { + if ((*it).subscriber == subscriber) { + if ((*it).ref != nullptr) { + napi_delete_reference(env, (*it).ref); + } + DelDeletingSubscriber((*it).subscriber); + delete (*it).subscriber; + (*it).subscriber = nullptr; + subscriberInstances_.erase(it); + return true; + } + } + return false; +} +napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, + LocalActivitySubscriberInstance *&subscriber, napi_ref &callback) +{ + ANS_LOGI("enter"); + + size_t argc = SUBSRIBE_MAX_PARA; + napi_value argv[SUBSRIBE_MAX_PARA] = {nullptr}; + napi_value thisVar = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); + if (argc < 1) { + ANS_LOGE("Wrong number of arguments"); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + + // argv[0]:LocalActivityButton + NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); + if (valuetype != napi_object) { + ANS_LOGE("Wrong argument type for arg0. LocalActivityButton object expected."); + return nullptr; + } + + LocalActivitySubscriberInstancesInfo subscriberInstancesInfo; + if (!HasNotificationSubscriber(env, argv[PARAM0], subscriberInstancesInfo)) { + if (GetNotificationSubscriber(env, argv[PARAM0], subscriberInstancesInfo) == nullptr) { + ANS_LOGE("LocalActivityButton parse failed"); + if (subscriberInstancesInfo.subscriber) { + delete subscriberInstancesInfo.subscriber; + subscriberInstancesInfo.subscriber = nullptr; + } + return nullptr; + } + if (!AddSubscriberInstancesInfo(env, subscriberInstancesInfo)) { + ANS_LOGE("AddSubscriberInstancesInfo add failed"); + if (subscriberInstancesInfo.subscriber) { + delete subscriberInstancesInfo.subscriber; + subscriberInstancesInfo.subscriber = nullptr; + } + return nullptr; + } + } + subscriber = subscriberInstancesInfo.subscriber; + + // argv[1]:callback + if (argc >= SUBSRIBE_MAX_PARA) { + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); + if (valuetype != napi_function) { + ANS_LOGE("Callback is not function enforce promise."); + return Common::NapiGetNull(env); + } + napi_create_reference(env, argv[PARAM1], 1, &callback); + } + + return Common::NapiGetNull(env); +} + +bool AddDeletingSubscriber(LocalActivitySubscriberInstance *subscriber) +{ + std::lock_guard lock(delMutex_); + auto iter = std::find(DeletingSubscriber.begin(), DeletingSubscriber.end(), subscriber); + if (iter != DeletingSubscriber.end()) { + return false; + } + + DeletingSubscriber.push_back(subscriber); + return true; +} + +void DelDeletingSubscriber(LocalActivitySubscriberInstance *subscriber) +{ + std::lock_guard lock(delMutex_); + auto iter = std::find(DeletingSubscriber.begin(), DeletingSubscriber.end(), subscriber); + if (iter != DeletingSubscriber.end()) { + DeletingSubscriber.erase(iter); + } +} + +} // namespace NotificationNapi +} // namespace OHOS diff --git a/frameworks/js/napi/src/manager/napi_local_activity.cpp b/frameworks/js/napi/src/manager/napi_local_activity.cpp new file mode 100644 index 000000000..5f0539b18 --- /dev/null +++ b/frameworks/js/napi/src/manager/napi_local_activity.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #include "napi_local_activity.h" + #include "local_activity_subscribe.h" + #include "ans_inner_errors.h" + +namespace OHOS { +namespace NotificationNapi { +const int32_t SUBSRIBE_MAX_PARA = 1; + +napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info) +{ + ANS_LOGI("enter"); + napi_ref callback = nullptr; + LocalActivitySubscriberInstance *objectInfo = nullptr; + if (ParseParameters(env, info, objectInfo, callback) == nullptr) { + if (objectInfo) { + delete objectInfo; + objectInfo = nullptr; + } + Common::NapiThrow(env, ERROR_PARAM_INVALID); + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoSubscribeLocalActivity *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoSubscribeLocalActivity { + .env = env, .asyncWork = nullptr, .objectInfo = objectInfo + }; + if (!asynccallbackinfo) { + if (objectInfo) { + delete objectInfo; + objectInfo = nullptr; + } + return Common::JSParaError(env, callback); + } + napi_value promise = nullptr; + Common::PaddingCallbackPromiseInfo(env, callback, asynccallbackinfo->info, promise); + + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "subscribeLocalActivityNotification", NAPI_AUTO_LENGTH, &resourceName); + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("NapiSubscribeLocalActivity work excute."); + if (!data) { + ANS_LOGE("Invalid asynccallbackinfo!"); + return; + } + auto asynccallbackinfo = reinterpret_cast(data); + + asynccallbackinfo->info.errorCode = + NotificationHelper::SubscribeLocalActivityNotification(*(asynccallbackinfo->objectInfo)); + + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("NapiSubscribeLocalActivity work complete."); + if (!data) { + ANS_LOGE("Invalid asynccallbackinfo!"); + return; + } + auto asynccallbackinfo = reinterpret_cast(data); + if (asynccallbackinfo) { + Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete napiSubscribeLocalActivity callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + ANS_LOGD("NapiSubscribeLocalActivity work complete end."); + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + + bool isCallback = asynccallbackinfo->info.isCallback; + napi_status status = napi_queue_async_work_with_qos(env, asynccallbackinfo->asyncWork, napi_qos_user_initiated); + if (status != napi_ok) { + ANS_LOGE("Queue napiSubscribeLocalActivity work failed return: %{public}d", status); + asynccallbackinfo->info.errorCode = ERROR_INTERNAL_ERROR; + Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete napiSubscribeLocalActivity callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + + if (isCallback) { + ANS_LOGD("napiSubscribeLocalActivity callback is nullptr."); + return Common::NapiGetNull(env); + } else { + return promise; + } +} + +napi_value NapiUnsubscriteLocalActivity(napi_env env, napi_callback_info info) +{ + +} + +napi_value NapiTriggerLocalActivity(napi_env env, napi_callback_info info) +{ + +} + +} // namespace NotificationNapi +} // namespace OHOS diff --git a/interfaces/inner_api/notification_local_activity_subscriber.h b/interfaces/inner_api/notification_local_activity_subscriber.h index d7afeb479..06260b2d2 100644 --- a/interfaces/inner_api/notification_local_activity_subscriber.h +++ b/interfaces/inner_api/notification_local_activity_subscriber.h @@ -41,7 +41,7 @@ public: **/ virtual void OnDisconnected() = 0; - virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) = 0; + virtual void OnResponse(int32_t notificationId, sptr buttonOption) = 0; /** * @brief Called back when connection to the ANS has died. @@ -71,7 +71,7 @@ private: void OnDisconnected() override; - void OnResponse(int32_t notificationId, const sptr &buttonOption) override; + void OnResponse(int32_t notificationId, const std::string &buttonName) override; bool GetAnsManagerProxy(); -- Gitee From 746816d07bebad30d6b6551b595d0c7e439b531b Mon Sep 17 00:00:00 2001 From: dongqingran Date: Sat, 21 Oct 2023 20:20:01 +0800 Subject: [PATCH 06/12] local activity parse js subscribe trigger Signed-off-by: dongqingran --- frameworks/js/napi/include/common.h | 10 ++ .../napi/include/local_activity_subscribe.h | 4 + frameworks/js/napi/src/common.cpp | 36 ++++- .../napi/src/manager/napi_local_activity.cpp | 126 ++++++++++++++++++ 4 files changed, 172 insertions(+), 4 deletions(-) diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 1c3ad4496..d56c5900f 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -1447,6 +1447,16 @@ public: */ static napi_value GetBundleOption(const napi_env &env, const napi_value &value, NotificationBundleOption &option); + /** + * @brief Gets a NotificationButtonOption object from specified js object + * + * @param env Indicates the environment that the API is invoked under + * @param value Indicates a js object to be converted + * @param option Indicates a NotificationButtonOption object from specified js object + * @return Returns the null object if success, returns the null value otherwise + */ + static napi_value GetButtonOption(const napi_env &env, const napi_value &value, NotificationButtonOption &option); + static napi_value GetHashCodes(const napi_env &env, const napi_value &value, std::vector &hashCodes); /** diff --git a/frameworks/js/napi/include/local_activity_subscribe.h b/frameworks/js/napi/include/local_activity_subscribe.h index 5a1475adc..8851058b7 100644 --- a/frameworks/js/napi/include/local_activity_subscribe.h +++ b/frameworks/js/napi/include/local_activity_subscribe.h @@ -16,6 +16,7 @@ #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_INCLUDE_SUBSCRIBE_H #include "common.h" +#include "notification_bundle_option.h" namespace OHOS { namespace NotificationNapi { @@ -76,6 +77,9 @@ struct AsyncCallbackInfoSubscribeLocalActivity { napi_env env = nullptr; napi_async_work asyncWork = nullptr; LocalActivitySubscriberInstance *objectInfo = nullptr; + NotificationBundleOption bundleOption; + NotificationButtonOption buttonOption; + int32_t notificationId; CallbackPromiseInfo info; }; diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index 5bc48eb05..b4309d761 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -4124,7 +4124,7 @@ napi_value Common::GetNotificationLocalActivityButton( NAPI_CALL(env, napi_has_named_property(env, buttonResult, "buttonNames", &hasProperty)); if (hasProperty) { - napi_get_named_property(env, buttonResult, "icon", &result); + napi_get_named_property(env, buttonResult, "buttonNames", &result); napi_is_array(env, result, &isArray); if (!isArray) { ANS_LOGE("Property buttonNames is expected to be an array."); @@ -4264,19 +4264,19 @@ napi_value Common::GetNotificationLocalActivityContentDetailed( //capsule? NAPI_CALL(env, napi_has_named_property(env, contentResult, "capsule", &hasProperty)); - if (hasProperty && GetNotificationLocalActivityCapsule(env, result, content) == nullptr) { + if (hasProperty && GetNotificationLocalActivityCapsule(env, contentResult, content) == nullptr) { return nullptr; } //button? NAPI_CALL(env, napi_has_named_property(env, contentResult, "button", &hasProperty)); - if (hasProperty && GetNotificationLocalActivityButton(env, result, content) == nullptr) { + if (hasProperty && GetNotificationLocalActivityButton(env, contentResult, content) == nullptr) { return nullptr; } //progess? NAPI_CALL(env, napi_has_named_property(env, contentResult, "progess", &hasProperty)); - if (hasProperty && GetNotificationLocalActivityProgess(env, result, content) == nullptr) { + if (hasProperty && GetNotificationLocalActivityProgess(env, contentResult, content) == nullptr) { return nullptr; } @@ -4587,6 +4587,34 @@ napi_value Common::GetBundleOption(const napi_env &env, const napi_value &value, return NapiGetNull(env); } +napi_value Common::GetButtonOption(const napi_env &env, const napi_value &value, NotificationButtonOption &option) +{ + ANS_LOGI("enter"); + + bool hasProperty {false}; + napi_valuetype valuetype = napi_undefined; + napi_value result = nullptr; + + char str[STR_MAX_SIZE] = {0}; + size_t strLen = 0; + // buttonName: string + NAPI_CALL(env, napi_has_named_property(env, value, "buttonName", &hasProperty)); + if (!hasProperty) { + ANS_LOGE("Property buttonName expected."); + return nullptr; + } + napi_get_named_property(env, value, "buttonName", &result); + NAPI_CALL(env, napi_typeof(env, result, &valuetype)); + if (valuetype != napi_string) { + ANS_LOGE("Wrong argument type. String expected."); + return nullptr; + } + NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); + option.SetButtonName(str); + + return NapiGetNull(env); +} + napi_value Common::GetHashCodes(const napi_env &env, const napi_value &value, std::vector &hashCodes) { ANS_LOGD("enter"); diff --git a/frameworks/js/napi/src/manager/napi_local_activity.cpp b/frameworks/js/napi/src/manager/napi_local_activity.cpp index 5f0539b18..ed95c5e2f 100644 --- a/frameworks/js/napi/src/manager/napi_local_activity.cpp +++ b/frameworks/js/napi/src/manager/napi_local_activity.cpp @@ -16,10 +16,12 @@ #include "napi_local_activity.h" #include "local_activity_subscribe.h" #include "ans_inner_errors.h" + #include "common.h" namespace OHOS { namespace NotificationNapi { const int32_t SUBSRIBE_MAX_PARA = 1; +const int32_t TRIGGER_PARA = 3; napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info) { @@ -116,9 +118,133 @@ napi_value NapiUnsubscriteLocalActivity(napi_env env, napi_callback_info info) } +napi_value ParseTriggerParameters(const napi_env &env, const napi_callback_info &info, + AsyncCallbackInfoSubscribeLocalActivity *asynccallbackinfo, napi_ref &callback) +{ + ANS_LOGI("enter"); + + size_t argc = TRIGGER_PARA; + napi_value argv[TRIGGER_PARA] = {nullptr, nullptr}; + napi_value thisVar = nullptr; + + int32_t notificationId = -1; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); + if (argc != TRIGGER_PARA) { + ANS_LOGE("Wrong number of arguments"); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + + // argv[0]:BundleOption + auto retValue = Common::GetBundleOption(env, argv[PARAM0], asynccallbackinfo->bundleOption); + if (retValue == nullptr) { + ANS_LOGE("GetBundleOption failed"); + return nullptr; + } + + // argv[1]:notificationId + NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); + if (valuetype != napi_number) { + ANS_LOGE("Wrong argument type. Number expected."); + return nullptr; + } + napi_get_value_int32(env, argv[PARAM1], ¬ificationId); + ANS_LOGI("notificationId = %{public}d", notificationId); + + + // argv[2]:buttonOption + retValue = Common::GetButtonOption(env, argv[PARAM2], asynccallbackinfo->buttonOption); + if (retValue == nullptr) { + ANS_LOGE("GetButtonOption failed"); + return nullptr; + } + return Common::NapiGetNull(env); +} + napi_value NapiTriggerLocalActivity(napi_env env, napi_callback_info info) { + ANS_LOGI("enter"); + napi_ref callback = nullptr; + + AsyncCallbackInfoSubscribeLocalActivity *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoSubscribeLocalActivity { + .env = env, .asyncWork = nullptr, + }; + if (!asynccallbackinfo) { + return Common::JSParaError(env, callback); + } + + if (ParseTriggerParameters(env, info, asynccallbackinfo, callback) == nullptr) { + Common::NapiThrow(env, ERROR_PARAM_INVALID); + return Common::NapiGetUndefined(env); + } + + napi_value promise = nullptr; + Common::PaddingCallbackPromiseInfo(env, callback, asynccallbackinfo->info, promise); + + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "triggerLocalActivity", NAPI_AUTO_LENGTH, &resourceName); + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("NapiTriggerLocalActivity work excute."); + if (!data) { + ANS_LOGE("Invalid asynccallbackinfo!"); + return; + } + auto asynccallbackinfo = reinterpret_cast(data); + + asynccallbackinfo->info.errorCode = + NotificationHelper::TriggerLocalActivity(asynccallbackinfo->bundleOption, + asynccallbackinfo->notificationId, asynccallbackinfo->buttonOption); + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("NapiSubscribeLocalActivity work complete."); + if (!data) { + ANS_LOGE("Invalid asynccallbackinfo!"); + return; + } + auto asynccallbackinfo = reinterpret_cast(data); + if (asynccallbackinfo) { + Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete napiSubscribeLocalActivity callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + ANS_LOGD("NapiSubscribeLocalActivity work complete end."); + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + + bool isCallback = asynccallbackinfo->info.isCallback; + napi_status status = napi_queue_async_work_with_qos(env, asynccallbackinfo->asyncWork, napi_qos_user_initiated); + if (status != napi_ok) { + ANS_LOGE("Queue napiSubscribeLocalActivity work failed return: %{public}d", status); + asynccallbackinfo->info.errorCode = ERROR_INTERNAL_ERROR; + Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); + if (asynccallbackinfo->info.callback != nullptr) { + ANS_LOGD("Delete napiSubscribeLocalActivity callback reference."); + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + + if (isCallback) { + ANS_LOGD("napiSubscribeLocalActivity callback is nullptr."); + return Common::NapiGetNull(env); + } else { + return promise; + } } } // namespace NotificationNapi -- Gitee From fc471fd27cdc41b25fb0ca48966f8be3ecbfab67 Mon Sep 17 00:00:00 2001 From: markYao Date: Sat, 21 Oct 2023 22:05:39 +0800 Subject: [PATCH 07/12] =?UTF-8?q?publish=E6=8E=A5=E5=8F=A3=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: markYao --- frameworks/ans/src/notification_content.cpp | 21 ++++-- .../notification_local_activity_button.cpp | 8 +- frameworks/js/napi/include/common.h | 6 +- frameworks/js/napi/src/common.cpp | 73 ++++++++++++------- .../js/napi/src/manager/init_module.cpp | 2 + 5 files changed, 68 insertions(+), 42 deletions(-) diff --git a/frameworks/ans/src/notification_content.cpp b/frameworks/ans/src/notification_content.cpp index a32c3cc5d..122e79253 100644 --- a/frameworks/ans/src/notification_content.cpp +++ b/frameworks/ans/src/notification_content.cpp @@ -15,6 +15,7 @@ #include "notification_content.h" #include "ans_log_wrapper.h" +#include "notification_local_activity_content.h" namespace OHOS { namespace Notification { @@ -110,12 +111,13 @@ std::shared_ptr NotificationContent::GetNotificationCo std::string NotificationContent::Dump() { - std::string contentTypeStr = (contentType_ == NotificationContent::Type::BASIC_TEXT) ? "BASIC_TEXT" - : (contentType_ == NotificationContent::Type::CONVERSATION) ? "CONVERSATION" - : (contentType_ == NotificationContent::Type::LONG_TEXT) ? "LONG_TEXT" - : (contentType_ == NotificationContent::Type::MEDIA) ? "MEDIA" - : (contentType_ == NotificationContent::Type::MULTILINE) ? "MULTILINE" - : (contentType_ == NotificationContent::Type::PICTURE) ? "PICTURE" : "NONE"; + std::string contentTypeStr = (contentType_ == NotificationContent::Type::BASIC_TEXT) ? "BASIC_TEXT" + : (contentType_ == NotificationContent::Type::CONVERSATION) ? "CONVERSATION" + : (contentType_ == NotificationContent::Type::LONG_TEXT) ? "LONG_TEXT" + : (contentType_ == NotificationContent::Type::MEDIA) ? "MEDIA" + : (contentType_ == NotificationContent::Type::MULTILINE) ? "MULTILINE" + : (contentType_ == NotificationContent::Type::PICTURE) ? "PICTURE" + : (contentType_ == NotificationContent::Type::LOCAL_ACTIVITY) ? "LOCAL_ACTIVITY" : "NONE"; return "NotificationContent{ " "contentType = " + contentTypeStr + @@ -238,6 +240,10 @@ bool NotificationContent::ReadFromParcel(Parcel &parcel) content_ = std::static_pointer_cast( std::shared_ptr(parcel.ReadParcelable())); break; + case NotificationContent::Type::LOCAL_ACTIVITY: + content_ = std::static_pointer_cast( + std::shared_ptr(parcel.ReadParcelable())); + break; default: ANS_LOGE("Invalid contentType"); return false; @@ -288,6 +294,9 @@ bool NotificationContent::ConvertJsonToContent(NotificationContent *target, cons case NotificationContent::Type::PICTURE: pBasicContent = NotificationJsonConverter::ConvertFromJson(contentObj); break; + case NotificationContent::Type::LOCAL_ACTIVITY: + pBasicContent = NotificationJsonConverter::ConvertFromJson(contentObj); + break; default: ANS_LOGE("Invalid contentType"); break; diff --git a/frameworks/ans/src/notification_local_activity_button.cpp b/frameworks/ans/src/notification_local_activity_button.cpp index ba3435438..7c51206de 100644 --- a/frameworks/ans/src/notification_local_activity_button.cpp +++ b/frameworks/ans/src/notification_local_activity_button.cpp @@ -150,20 +150,18 @@ bool NotificationLocalActivityButton::Marshalling(Parcel &parcel) const bool NotificationLocalActivityButton::ReadFromParcel(Parcel &parcel) { - auto vsize = parcel.ReadUint64(); - vsize = (vsize < 3) ? vsize : 3; if (!parcel.ReadStringVector(&buttonNames_)) { ANS_LOGE("Failed to read button names"); return false; } - vsize = parcel.ReadUint64(); + auto vsize = parcel.ReadUint64(); vsize = (vsize < 3) ? vsize : 3; for (uint64_t it = 0; it < vsize; ++it) { - auto member = parcel.ReadParcelable(); + auto member = std::shared_ptr(parcel.ReadParcelable()); if (member == nullptr) { buttonIcons_.clear(); - ANS_LOGE("Failed to read actionButton"); + ANS_LOGE("Failed to read LocalActivityButton %llu, %llu",it, vsize); return false; } diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index d56c5900f..3e5385a4c 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -1260,14 +1260,14 @@ public: const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** - * @brief Gets a progess of NotificationLocalActivityContent object from specified js object + * @brief Gets a progress of NotificationLocalActivityContent object from specified js object * * @param env Indicates the environment that the API is invoked under * @param contentResult Indicates a js object to be converted - * @param pictureContent Indicates a progess object from specified js object + * @param pictureContent Indicates a progress object from specified js object * @return Returns the null object if success, returns the null value otherwise */ - static napi_value GetNotificationLocalActivityProgess( + static napi_value GetNotificationLocalActivityProgress( const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index b4309d761..723c674fa 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -4009,7 +4009,7 @@ napi_value Common::GetNotificationLocalActivityContent( bool hasProperty = false; NAPI_CALL(env, napi_has_named_property(env, result, "localActivity", &hasProperty)); if (!hasProperty) { - ANS_LOGE("Property normal expected."); + ANS_LOGE("Property localActivity expected."); return nullptr; } napi_get_named_property(env, result, "localActivity", &contentResult); @@ -4019,7 +4019,7 @@ napi_value Common::GetNotificationLocalActivityContent( return nullptr; } - std::shared_ptr localActivityContent = std::make_shared(); + std::shared_ptr localActivityContent = std::make_shared(); if (localActivityContent == nullptr) { ANS_LOGE("localActivityContent is null"); return nullptr; @@ -4035,7 +4035,7 @@ napi_value Common::GetNotificationLocalActivityContent( } napi_value Common::GetNotificationLocalActivityCapsule( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content) + const napi_env &env, const napi_value &contentResult, std::shared_ptr content) { napi_value capsuleResult = nullptr; napi_valuetype valuetype = napi_undefined; @@ -4045,6 +4045,10 @@ napi_value Common::GetNotificationLocalActivityCapsule( std::shared_ptr pixelMap = nullptr; napi_value result = nullptr; + ANS_LOGI("enter"); + + NAPI_CALL(env, napi_has_named_property(env, contentResult, "capsule", &hasProperty)); + napi_get_named_property(env, contentResult, "capsule", &capsuleResult); NAPI_CALL(env, napi_typeof(env, capsuleResult, &valuetype)); if (valuetype != napi_object) { @@ -4065,6 +4069,7 @@ napi_value Common::GetNotificationLocalActivityCapsule( NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); capsule.SetTitle(str); + ANS_LOGD("capsule title = %{public}s", str); } NAPI_CALL(env, napi_has_named_property(env, capsuleResult, "backgroundColor", &hasProperty)); @@ -4075,11 +4080,10 @@ napi_value Common::GetNotificationLocalActivityCapsule( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); capsule.SetBackgroundColor(str); + ANS_LOGD("capsule backgroundColor = %{public}s", str); } - NAPI_CALL(env, napi_has_named_property(env, capsuleResult, "icon", &hasProperty)); if (hasProperty) { napi_get_named_property(env, capsuleResult, "icon", &result); @@ -4094,6 +4098,7 @@ napi_value Common::GetNotificationLocalActivityCapsule( return nullptr; } capsule.SetIcon(pixelMap); + ANS_LOGD("capsule icon = %{public}s", str); } content->SetCapsule(capsule); @@ -4102,7 +4107,7 @@ napi_value Common::GetNotificationLocalActivityCapsule( } napi_value Common::GetNotificationLocalActivityButton( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content) + const napi_env &env, const napi_value &contentResult, std::shared_ptr content) { napi_value result = nullptr; napi_valuetype valuetype = napi_undefined; @@ -4113,6 +4118,8 @@ napi_value Common::GetNotificationLocalActivityButton( char str[STR_MAX_SIZE] = {0}; size_t strLen = 0; + ANS_LOGI("enter"); + napi_get_named_property(env, contentResult, "button", &buttonResult); NAPI_CALL(env, napi_typeof(env, buttonResult, &valuetype)); if (valuetype != napi_object) { @@ -4139,8 +4146,9 @@ napi_value Common::GetNotificationLocalActivityButton( ANS_LOGE("Wrong argument type. String expected."); return nullptr; } - NAPI_CALL(env, napi_get_value_string_utf8(env, result, str, STR_MAX_SIZE - 1, &strLen)); + NAPI_CALL(env, napi_get_value_string_utf8(env, buttonName, str, STR_MAX_SIZE - 1, &strLen)); button.addSingleButtonName(str); + ANS_LOGD("button buttonName = %{public}s.", str); } } @@ -4170,80 +4178,87 @@ napi_value Common::GetNotificationLocalActivityButton( button.addSingleButtonIcon(pixelMap); } } + ANS_LOGD("button buttonIcon = %{public}s", str); return NapiGetNull(env); } -napi_value Common::GetNotificationLocalActivityProgess( - - - const napi_env &env, const napi_value &contentResult, std::shared_ptr content) +napi_value Common::GetNotificationLocalActivityProgress(const napi_env &env, + const napi_value &contentResult, std::shared_ptr content) { napi_value result = nullptr; napi_valuetype valuetype = napi_undefined; bool hasProperty = false; int32_t intValue = -1; - napi_value progessResult = nullptr; + napi_value progressResult = nullptr; + + ANS_LOGI("enter"); - napi_get_named_property(env, contentResult, "progess", &progessResult); - NAPI_CALL(env, napi_typeof(env, progessResult, &valuetype)); + napi_get_named_property(env, contentResult, "progress", &progressResult); + NAPI_CALL(env, napi_typeof(env, progressResult, &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type. Object expected."); return nullptr; } - NotificationProgress progess; + NotificationProgress progress; - NAPI_CALL(env, napi_has_named_property(env, progessResult, "maxValue", &hasProperty)); + NAPI_CALL(env, napi_has_named_property(env, progressResult, "maxValue", &hasProperty)); if (hasProperty) { - napi_get_named_property(env, progessResult, "maxValue", &result); + napi_get_named_property(env, progressResult, "maxValue", &result); NAPI_CALL(env, napi_typeof(env, result, &valuetype)); if (valuetype != napi_number) { ANS_LOGE("Wrong argument type. Number expected."); return nullptr; } napi_get_value_int32(env, result, &intValue); - progess.SetMaxValue(intValue); + progress.SetMaxValue(intValue); + ANS_LOGD("progress intValue = %{public}d", intValue); } - NAPI_CALL(env, napi_has_named_property(env, progessResult, "currentValue", &hasProperty)); + NAPI_CALL(env, napi_has_named_property(env, progressResult, "currentValue", &hasProperty)); if (hasProperty) { - napi_get_named_property(env, progessResult, "currentValue", &result); + napi_get_named_property(env, progressResult, "currentValue", &result); NAPI_CALL(env, napi_typeof(env, result, &valuetype)); if (valuetype != napi_number) { ANS_LOGE("Wrong argument type. Number expected."); return nullptr; } napi_get_value_int32(env, result, &intValue); - progess.SetCurrentValue(intValue); + progress.SetCurrentValue(intValue); + ANS_LOGD("progress currentValue = %{public}d", intValue); } - NAPI_CALL(env, napi_has_named_property(env, progessResult, "isPercentage", &hasProperty)); + NAPI_CALL(env, napi_has_named_property(env, progressResult, "isPercentage", &hasProperty)); if (hasProperty) { - napi_get_named_property(env, progessResult, "isPercentage", &result); + napi_get_named_property(env, progressResult, "isPercentage", &result); NAPI_CALL(env, napi_typeof(env, result, &valuetype)); if (valuetype != napi_number) { ANS_LOGE("Wrong argument type. Number expected."); return nullptr; } napi_get_value_int32(env, result, &intValue); - progess.SetIsPercentage(intValue); + progress.SetIsPercentage(intValue); + ANS_LOGD("progress isPercentage = %{public}d", intValue); } - content->SetProgress(progess); + content->SetProgress(progress); return NapiGetNull(env); } napi_value Common::GetNotificationLocalActivityContentDetailed( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content) + const napi_env &env, const napi_value &contentResult, std::shared_ptr content) { bool hasProperty = false; int32_t type = -1; napi_value result = nullptr; napi_valuetype valuetype = napi_undefined; + ANS_LOGI("enter"); + //title, text if (GetNotificationBasicContentDetailed(env, contentResult, content) == nullptr) { + ANS_LOGE("Basic content get fail."); return nullptr; } @@ -4261,6 +4276,8 @@ napi_value Common::GetNotificationLocalActivityContentDetailed( } napi_get_value_int32(env, result, &type); content->SetType(type); + ANS_LOGD("localActivity type = %{public}d", type); + //capsule? NAPI_CALL(env, napi_has_named_property(env, contentResult, "capsule", &hasProperty)); @@ -4275,8 +4292,8 @@ napi_value Common::GetNotificationLocalActivityContentDetailed( } //progess? - NAPI_CALL(env, napi_has_named_property(env, contentResult, "progess", &hasProperty)); - if (hasProperty && GetNotificationLocalActivityProgess(env, contentResult, content) == nullptr) { + NAPI_CALL(env, napi_has_named_property(env, contentResult, "progress", &hasProperty)); + if (hasProperty && GetNotificationLocalActivityProgress(env, contentResult, content) == nullptr) { return nullptr; } diff --git a/frameworks/js/napi/src/manager/init_module.cpp b/frameworks/js/napi/src/manager/init_module.cpp index 232d2d689..eae2ad772 100644 --- a/frameworks/js/napi/src/manager/init_module.cpp +++ b/frameworks/js/napi/src/manager/init_module.cpp @@ -101,6 +101,8 @@ napi_value NotificationManagerInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getDeviceRemindType", NapiGetDeviceRemindType), DECLARE_NAPI_FUNCTION("setSyncNotificationEnabledWithoutApp", NapiSetSyncNotificationEnabledWithoutApp), DECLARE_NAPI_FUNCTION("getSyncNotificationEnabledWithoutApp", NapiGetSyncNotificationEnabledWithoutApp), + DECLARE_NAPI_FUNCTION("subscribeLocalLiveView", NapiSubscriteLocalAcitvity), + DECLARE_NAPI_FUNCTION("trigger", NapiTriggerLocalActivity), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); -- Gitee From e8ac58d17a926a738379df29d7854cf49f3172aa Mon Sep 17 00:00:00 2001 From: markYao Date: Sat, 21 Oct 2023 23:05:24 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=BF=AE=E6=94=B9=20Si?= =?UTF-8?q?gned-off-by:=20markYao=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/js/napi/include/local_activity_subscribe.h | 2 +- frameworks/js/napi/src/manager/init_module.cpp | 1 + frameworks/js/napi/src/manager/napi_local_activity.cpp | 4 ++-- interfaces/inner_api/notification_local_activity_subscriber.h | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frameworks/js/napi/include/local_activity_subscribe.h b/frameworks/js/napi/include/local_activity_subscribe.h index 8851058b7..2291fcc72 100644 --- a/frameworks/js/napi/include/local_activity_subscribe.h +++ b/frameworks/js/napi/include/local_activity_subscribe.h @@ -39,7 +39,7 @@ public: */ virtual void OnDisconnected() override; - virtual void OnResponse(int32_t notificationId, sptr buttonOption) override; + virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) override; /** * @brief Called back when connection to the ANS has died. diff --git a/frameworks/js/napi/src/manager/init_module.cpp b/frameworks/js/napi/src/manager/init_module.cpp index eae2ad772..67388cba8 100644 --- a/frameworks/js/napi/src/manager/init_module.cpp +++ b/frameworks/js/napi/src/manager/init_module.cpp @@ -30,6 +30,7 @@ #include "napi_template.h" #include "pixel_map_napi.h" #include "napi_push.h" +#include "napi_local_activity.h" namespace OHOS { namespace NotificationNapi { diff --git a/frameworks/js/napi/src/manager/napi_local_activity.cpp b/frameworks/js/napi/src/manager/napi_local_activity.cpp index ed95c5e2f..484ca217f 100644 --- a/frameworks/js/napi/src/manager/napi_local_activity.cpp +++ b/frameworks/js/napi/src/manager/napi_local_activity.cpp @@ -20,7 +20,7 @@ namespace OHOS { namespace NotificationNapi { -const int32_t SUBSRIBE_MAX_PARA = 1; +//const int32_t SUBSRIBE_MAX_PARA = 1; const int32_t TRIGGER_PARA = 3; napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info) @@ -115,7 +115,7 @@ napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info) napi_value NapiUnsubscriteLocalActivity(napi_env env, napi_callback_info info) { - + return nullptr; } napi_value ParseTriggerParameters(const napi_env &env, const napi_callback_info &info, diff --git a/interfaces/inner_api/notification_local_activity_subscriber.h b/interfaces/inner_api/notification_local_activity_subscriber.h index 06260b2d2..d7afeb479 100644 --- a/interfaces/inner_api/notification_local_activity_subscriber.h +++ b/interfaces/inner_api/notification_local_activity_subscriber.h @@ -41,7 +41,7 @@ public: **/ virtual void OnDisconnected() = 0; - virtual void OnResponse(int32_t notificationId, sptr buttonOption) = 0; + virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) = 0; /** * @brief Called back when connection to the ANS has died. @@ -71,7 +71,7 @@ private: void OnDisconnected() override; - void OnResponse(int32_t notificationId, const std::string &buttonName) override; + void OnResponse(int32_t notificationId, const sptr &buttonOption) override; bool GetAnsManagerProxy(); -- Gitee From db2fa892081007abb2d1cbd91dbf1b7cb9f1b4cf Mon Sep 17 00:00:00 2001 From: markYao Date: Sat, 21 Oct 2023 23:26:40 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: markYao --- frameworks/ans/src/notification_local_activity_subscriber.cpp | 2 +- .../core/include/ans_subscriber_local_activity_interface.h | 2 +- frameworks/core/include/ans_subscriber_local_activity_proxy.h | 2 +- frameworks/core/include/ans_subscriber_local_activity_stub.h | 2 +- frameworks/core/src/ans_subscriber_local_activity_proxy.cpp | 2 +- frameworks/core/src/ans_subscriber_local_activity_stub.cpp | 2 +- frameworks/js/napi/include/local_activity_subscribe.h | 2 +- interfaces/inner_api/notification_local_activity_subscriber.h | 4 ++-- .../include/notification_local_activity_subscriber_manager.h | 2 +- .../src/notification_local_activity_subscriber_manager.cpp | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/frameworks/ans/src/notification_local_activity_subscriber.cpp b/frameworks/ans/src/notification_local_activity_subscriber.cpp index d094e0ea9..b0d136bb8 100644 --- a/frameworks/ans/src/notification_local_activity_subscriber.cpp +++ b/frameworks/ans/src/notification_local_activity_subscriber.cpp @@ -59,7 +59,7 @@ void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnDisconn subscriber_.OnDisconnected(); } -void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnResponse(int32_t notificationId, const sptr &buttonOption) +void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnResponse(int32_t notificationId, sptr buttonOption) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); subscriber_.OnResponse(notificationId, buttonOption); diff --git a/frameworks/core/include/ans_subscriber_local_activity_interface.h b/frameworks/core/include/ans_subscriber_local_activity_interface.h index 8785072c4..030696320 100644 --- a/frameworks/core/include/ans_subscriber_local_activity_interface.h +++ b/frameworks/core/include/ans_subscriber_local_activity_interface.h @@ -47,7 +47,7 @@ public: */ virtual void OnDisconnected() = 0; - virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) = 0; + virtual void OnResponse(int32_t notificationId, sptr buttonOption) = 0; }; } // namespace Notification diff --git a/frameworks/core/include/ans_subscriber_local_activity_proxy.h b/frameworks/core/include/ans_subscriber_local_activity_proxy.h index 7b7e9b21c..eb8f6252a 100644 --- a/frameworks/core/include/ans_subscriber_local_activity_proxy.h +++ b/frameworks/core/include/ans_subscriber_local_activity_proxy.h @@ -39,7 +39,7 @@ public: */ void OnDisconnected() override; - void OnResponse(int32_t notificationId, const sptr &buttonOption) override; + void OnResponse(int32_t notificationId, sptr buttonOption) override; private: ErrCode InnerTransact(NotificationInterfaceCode code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/core/include/ans_subscriber_local_activity_stub.h b/frameworks/core/include/ans_subscriber_local_activity_stub.h index 916540a98..8532f8829 100644 --- a/frameworks/core/include/ans_subscriber_local_activity_stub.h +++ b/frameworks/core/include/ans_subscriber_local_activity_stub.h @@ -49,7 +49,7 @@ public: */ void OnDisconnected() override; - void OnResponse(int32_t notificationId, const sptr &buttonOption) override; + void OnResponse(int32_t notificationId, sptr buttonOption) override; private: std::map> interfaces_; diff --git a/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp b/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp index b3227bb73..a22d63506 100644 --- a/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp +++ b/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp @@ -88,7 +88,7 @@ void AnsSubscriberLocalActivityProxy::OnDisconnected() } -void AnsSubscriberLocalActivityProxy::OnResponse(int32_t notificationId, const sptr &buttonOption) +void AnsSubscriberLocalActivityProxy::OnResponse(int32_t notificationId, sptr buttonOption) { MessageParcel data; if (!data.WriteInterfaceToken(AnsSubscriberLocalActivityProxy::GetDescriptor())) { diff --git a/frameworks/core/src/ans_subscriber_local_activity_stub.cpp b/frameworks/core/src/ans_subscriber_local_activity_stub.cpp index 1db24040b..0e410eb3b 100644 --- a/frameworks/core/src/ans_subscriber_local_activity_stub.cpp +++ b/frameworks/core/src/ans_subscriber_local_activity_stub.cpp @@ -125,7 +125,7 @@ void AnsSubscriberLocalActivityStub::OnConnected() void AnsSubscriberLocalActivityStub::OnDisconnected() {} -void AnsSubscriberLocalActivityStub::OnResponse(int32_t notificationId, const sptr &buttonOption) +void AnsSubscriberLocalActivityStub::OnResponse(int32_t notificationId, sptr buttonOption) {} } // namespace Notification } // namespace OHOS diff --git a/frameworks/js/napi/include/local_activity_subscribe.h b/frameworks/js/napi/include/local_activity_subscribe.h index 2291fcc72..8851058b7 100644 --- a/frameworks/js/napi/include/local_activity_subscribe.h +++ b/frameworks/js/napi/include/local_activity_subscribe.h @@ -39,7 +39,7 @@ public: */ virtual void OnDisconnected() override; - virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) override; + virtual void OnResponse(int32_t notificationId, sptr buttonOption) override; /** * @brief Called back when connection to the ANS has died. diff --git a/interfaces/inner_api/notification_local_activity_subscriber.h b/interfaces/inner_api/notification_local_activity_subscriber.h index d7afeb479..44942e9a5 100644 --- a/interfaces/inner_api/notification_local_activity_subscriber.h +++ b/interfaces/inner_api/notification_local_activity_subscriber.h @@ -41,7 +41,7 @@ public: **/ virtual void OnDisconnected() = 0; - virtual void OnResponse(int32_t notificationId, const sptr &buttonOption) = 0; + virtual void OnResponse(int32_t notificationId, sptr buttonOption) = 0; /** * @brief Called back when connection to the ANS has died. @@ -71,7 +71,7 @@ private: void OnDisconnected() override; - void OnResponse(int32_t notificationId, const sptr &buttonOption) override; + void OnResponse(int32_t notificationId, sptr buttonOption) override; bool GetAnsManagerProxy(); diff --git a/services/ans/include/notification_local_activity_subscriber_manager.h b/services/ans/include/notification_local_activity_subscriber_manager.h index 7fe2a349e..e4b23ca7d 100644 --- a/services/ans/include/notification_local_activity_subscriber_manager.h +++ b/services/ans/include/notification_local_activity_subscriber_manager.h @@ -92,7 +92,7 @@ private: ErrCode RemoveSubscriberInner( const sptr &subscriber, const sptr &subscribeInfo); - void NotifyTriggerResponseInner(const sptr ¬ification, const sptr &buttonOption); + void NotifyTriggerResponseInner(const sptr ¬ification, sptr buttonOption); bool IsSystemUser(int32_t userId); private: diff --git a/services/ans/src/notification_local_activity_subscriber_manager.cpp b/services/ans/src/notification_local_activity_subscriber_manager.cpp index 6b3f3326d..0afac9478 100644 --- a/services/ans/src/notification_local_activity_subscriber_manager.cpp +++ b/services/ans/src/notification_local_activity_subscriber_manager.cpp @@ -259,7 +259,7 @@ ErrCode NotificationLocalActivitySubscriberManager::RemoveSubscriberInner( return ERR_OK; } -void NotificationLocalActivitySubscriberManager::NotifyTriggerResponseInner(const sptr ¬ification, const sptr &buttonOption) +void NotificationLocalActivitySubscriberManager::NotifyTriggerResponseInner(const sptr ¬ification, const sptr buttonOption) { ANS_LOGE("ffrt enter!"); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); -- Gitee From 76ce00c026b6d86ba3845259ad32b1fc02adbdfc Mon Sep 17 00:00:00 2001 From: markYao Date: Sun, 22 Oct 2023 15:02:25 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: markYao --- frameworks/core/src/ans_manager_stub.cpp | 5 +++-- frameworks/js/napi/src/common.cpp | 3 +++ frameworks/js/napi/src/manager/napi_local_activity.cpp | 2 +- interfaces/inner_api/notification_constant.h | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frameworks/core/src/ans_manager_stub.cpp b/frameworks/core/src/ans_manager_stub.cpp index c1493069c..71be5f7aa 100644 --- a/frameworks/core/src/ans_manager_stub.cpp +++ b/frameworks/core/src/ans_manager_stub.cpp @@ -254,8 +254,9 @@ const std::mapnotificationId = notificationId; // argv[2]:buttonOption retValue = Common::GetButtonOption(env, argv[PARAM2], asynccallbackinfo->buttonOption); diff --git a/interfaces/inner_api/notification_constant.h b/interfaces/inner_api/notification_constant.h index de3e87263..3413024da 100644 --- a/interfaces/inner_api/notification_constant.h +++ b/interfaces/inner_api/notification_constant.h @@ -62,6 +62,7 @@ public: CONTENT_INFORMATION, // the notificatin type is content information OTHER, // the notificatin type is other CUSTOM, // the notification type is custom + LIVE_VIEW, // the notification type is live view }; enum class VisiblenessType { -- Gitee From 67b15218e6efbfa040eb74c8f54afcb53b944aa1 Mon Sep 17 00:00:00 2001 From: markYao Date: Sun, 22 Oct 2023 17:03:44 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: markYao --- .../src/manager/local_activity_subscribe.cpp | 2 +- ...cation_local_activity_subscriber_manager.h | 4 +- ...tion_local_activity_subscriber_manager.cpp | 63 ++++++++----------- 3 files changed, 28 insertions(+), 41 deletions(-) diff --git a/frameworks/js/napi/src/manager/local_activity_subscribe.cpp b/frameworks/js/napi/src/manager/local_activity_subscribe.cpp index d156ac9fb..68eb9d834 100644 --- a/frameworks/js/napi/src/manager/local_activity_subscribe.cpp +++ b/frameworks/js/napi/src/manager/local_activity_subscribe.cpp @@ -110,7 +110,7 @@ void LocalActivitySubscriberInstance::OnResponse(int32_t notificationId, sptrGetButtonName().c_str()); + ANS_LOGI("OnResponse buttonOption size = %{public}s", buttonOption->GetButtonName().c_str()); uv_loop_s *loop = nullptr; napi_get_uv_event_loop(responseCallbackInfo_.env, &loop); diff --git a/services/ans/include/notification_local_activity_subscriber_manager.h b/services/ans/include/notification_local_activity_subscriber_manager.h index e4b23ca7d..45069a1d2 100644 --- a/services/ans/include/notification_local_activity_subscriber_manager.h +++ b/services/ans/include/notification_local_activity_subscriber_manager.h @@ -85,10 +85,10 @@ private: std::shared_ptr FindSubscriberRecord(const wptr &object); std::shared_ptr FindSubscriberRecord(const sptr &subscriber); - std::shared_ptr CreateSubscriberRecord(const sptr &subscriber); + std::shared_ptr CreateSubscriberRecord(const sptr &subscriber, const sptr &bundleOption); ErrCode AddSubscriberInner( - const sptr &subscriber, const sptr &subscribeInfo); + const sptr &subscriber, const sptr &bundleOption); ErrCode RemoveSubscriberInner( const sptr &subscriber, const sptr &subscribeInfo); diff --git a/services/ans/src/notification_local_activity_subscriber_manager.cpp b/services/ans/src/notification_local_activity_subscriber_manager.cpp index 0afac9478..7f8507bfa 100644 --- a/services/ans/src/notification_local_activity_subscriber_manager.cpp +++ b/services/ans/src/notification_local_activity_subscriber_manager.cpp @@ -25,6 +25,7 @@ #include "ans_watchdog.h" #include "hitrace_meter.h" #include "ipc_skeleton.h" +#include "notification_bundle_option.h" #include "notification_button_option.h" #include "os_account_manager.h" #include "remote_death_recipient.h" @@ -71,37 +72,28 @@ ErrCode NotificationLocalActivitySubscriberManager::AddLocalActivitySubscriber( return ERR_ANS_INVALID_PARAM; } - sptr subInfo = subscribeInfo; - if (subInfo == nullptr) { - subInfo = new (std::nothrow) NotificationSubscribeInfo(); - if (subInfo == nullptr) { - ANS_LOGE("Failed to create NotificationSubscribeInfo ptr."); - return ERR_ANS_NO_MEMORY; - } - } - - if (subInfo->GetAppUserId() == SUBSCRIBE_USER_INIT) { - int32_t userId = SUBSCRIBE_USER_INIT; - int32_t callingUid = IPCSkeleton::GetCallingUid(); - ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); - if (ret != ERR_OK) { - ANS_LOGD("Get userId failed, callingUid = <%{public}d>", callingUid); - return ERR_ANS_INVALID_PARAM; - } - - ANS_LOGD("Get userId succeeded, callingUid = <%{public}d> userId = <%{public}d>", callingUid, userId); - subInfo->AddAppUserId(userId); + sptr bundleOption; + std::string bundle; + int32_t callingUid = IPCSkeleton::GetCallingUid(); + std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); + if (bundleManager != nullptr) { + bundle = bundleManager->GetBundleNameByUid(callingUid); } - + bundleOption = new (std::nothrow) NotificationBundleOption(bundle, callingUid); ErrCode result = ERR_ANS_TASK_ERR; + if (bundleOption == nullptr) { + ANS_LOGE("Failed to create NotificationBundleOption instance"); + return ERR_ANS_NO_MEMORY; + } + ANS_LOGD("Get userId succeeded, callingUid = <%{public}d> bundleName = <%{public}s>", callingUid, bundle.c_str()); if (notificationButtonQueue_ == nullptr) { ANS_LOGE("queue is nullptr"); return result; } ANS_LOGE("ffrt start!"); - ffrt::task_handle handler = notificationButtonQueue_->submit_h(std::bind([this, &subscriber, &subInfo, &result]() { + ffrt::task_handle handler = notificationButtonQueue_->submit_h(std::bind([this, &subscriber, &bundleOption, &result]() { ANS_LOGE("ffrt enter!"); - result = this->AddSubscriberInner(subscriber, subInfo); + result = this->AddSubscriberInner(subscriber, bundleOption); })); notificationButtonQueue_->wait(handler); ANS_LOGE("ffrt end!"); @@ -196,33 +188,27 @@ std::shared_ptr NotificationLocalActivitySubscriberManager::CreateSubscriberRecord( - const sptr &subscriber) + const sptr &subscriber, const sptr &bundleOption) { std::shared_ptr record = std::make_shared(); // set bundleName and uid - int32_t callingUid = IPCSkeleton::GetCallingUid(); - std::string bundle; - std::shared_ptr bundleManager = BundleManagerHelper::GetInstance(); - if (bundleManager != nullptr) { - bundle = bundleManager->GetBundleNameByUid(callingUid); - } - if (record != nullptr) { record->subscriber = subscriber; - record->bundleName = bundle; - record->userId = callingUid; + record->bundleName = bundleOption->GetBundleName(); + record->userId = bundleOption->GetUid(); + ANS_LOGD("Get userId succeeded, callingUid = <%{public}d> bundleName = <%{public}s>", record->userId, record->bundleName.c_str()); } return record; } ErrCode NotificationLocalActivitySubscriberManager::AddSubscriberInner( - const sptr &subscriber, const sptr &subscribeInfo) + const sptr &subscriber, const sptr &bundleOption) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); std::shared_ptr record = FindSubscriberRecord(subscriber); if (record == nullptr) { - record = CreateSubscriberRecord(subscriber); + record = CreateSubscriberRecord(subscriber, bundleOption); if (record == nullptr) { ANS_LOGE("CreateSubscriberRecord failed."); return ERR_ANS_NO_MEMORY; @@ -263,10 +249,11 @@ void NotificationLocalActivitySubscriberManager::NotifyTriggerResponseInner(cons { ANS_LOGE("ffrt enter!"); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - ANS_LOGD("%{public}s notification->GetUserId <%{public}d>", __FUNCTION__, notification->GetUserId()); - int32_t sendUserId = notification->GetUserId(); + ANS_LOGD("%{public}s notification->GetUserId <%{public}d>, bundlename <%{public}s>", __FUNCTION__, notification->GetUid(), + notification->GetBundleName().c_str()); + int32_t sendUserId = notification->GetUid(); for (auto record : buttonRecordList_) { - ANS_LOGD("%{public}s record->userId = <%{public}d>", __FUNCTION__, record->userId); + ANS_LOGD("%{public}s record->userId = <%{public}d>, bundlename <%{public}s>", __FUNCTION__, record->userId, record->bundleName.c_str()); auto bundleName = notification->GetBundleName(); if (record->bundleName == bundleName && record->userId == sendUserId) { record->subscriber->OnResponse(notification->GetId(), buttonOption); -- Gitee From b4d9de911b6b7cfefe2ba5ce0f59354518355c01 Mon Sep 17 00:00:00 2001 From: markYao Date: Sun, 22 Oct 2023 17:50:48 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9local=20activity?= =?UTF-8?q?=E4=B8=BAlocal=20live=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: markYao --- frameworks/ans/BUILD.gn | 10 ++-- frameworks/ans/src/notification_content.cpp | 22 +++---- frameworks/ans/src/notification_helper.cpp | 8 +-- ...> notification_local_live_view_button.cpp} | 33 +++++----- ... notification_local_live_view_content.cpp} | 36 +++++------ ...tification_local_live_view_subscriber.cpp} | 26 ++++---- .../core/include/ans_manager_interface.h | 8 +-- frameworks/core/include/ans_manager_proxy.h | 6 +- frameworks/core/include/ans_manager_stub.h | 14 ++--- frameworks/core/include/ans_notification.h | 8 +-- ...ns_subscriber_local_live_view_interface.h} | 16 ++--- ...=> ans_subscriber_local_live_view_proxy.h} | 14 ++--- ... => ans_subscriber_local_live_view_stub.h} | 16 ++--- ..._notification_service_ipc_interface_code.h | 4 +- frameworks/core/src/ans_manager_proxy.cpp | 25 ++++---- frameworks/core/src/ans_manager_stub.cpp | 42 ++++++------- frameworks/core/src/ans_notification.cpp | 12 ++-- ... ans_subscriber_local_live_view_proxy.cpp} | 20 +++---- ...> ans_subscriber_local_live_view_stub.cpp} | 30 +++++----- frameworks/js/napi/include/common.h | 39 ++++++------ ...ubscribe.h => local_live_view_subscribe.h} | 30 +++++----- ...ocal_activity.h => napi_local_live_view.h} | 10 ++-- frameworks/js/napi/src/common.cpp | 56 ++++++++--------- frameworks/js/napi/src/manager/BUILD.gn | 4 +- .../js/napi/src/manager/init_module.cpp | 4 +- ...ribe.cpp => local_live_view_subscribe.cpp} | 50 ++++++++-------- ..._activity.cpp => napi_local_live_view.cpp} | 60 +++++++++---------- interfaces/inner_api/notification_content.h | 14 ++--- interfaces/inner_api/notification_helper.h | 12 ++-- ... => notification_local_live_view_button.h} | 16 ++--- ...=> notification_local_live_view_content.h} | 20 +++---- ...notification_local_live_view_subscriber.h} | 30 +++++----- services/ans/BUILD.gn | 2 +- .../include/advanced_notification_service.h | 6 +- ...tion_local_live_view_subscriber_manager.h} | 36 +++++------ .../ans/src/advanced_notification_service.cpp | 12 ++-- ...on_local_live_view_subscriber_manager.cpp} | 60 +++++++++---------- 37 files changed, 404 insertions(+), 407 deletions(-) rename frameworks/ans/src/{notification_local_activity_button.cpp => notification_local_live_view_button.cpp} (78%) rename frameworks/ans/src/{notification_local_activity_content.cpp => notification_local_live_view_content.cpp} (83%) rename frameworks/ans/src/{notification_local_activity_subscriber.cpp => notification_local_live_view_subscriber.cpp} (68%) rename frameworks/core/include/{ans_subscriber_local_activity_interface.h => ans_subscriber_local_live_view_interface.h} (80%) rename frameworks/core/include/{ans_subscriber_local_activity_proxy.h => ans_subscriber_local_live_view_proxy.h} (83%) rename frameworks/core/include/{ans_subscriber_local_activity_stub.h => ans_subscriber_local_live_view_stub.h} (83%) rename frameworks/core/src/{ans_subscriber_local_activity_proxy.cpp => ans_subscriber_local_live_view_proxy.cpp} (84%) rename frameworks/core/src/{ans_subscriber_local_activity_stub.cpp => ans_subscriber_local_live_view_stub.cpp} (79%) rename frameworks/js/napi/include/{local_activity_subscribe.h => local_live_view_subscribe.h} (77%) rename frameworks/js/napi/include/manager/{napi_local_activity.h => napi_local_live_view.h} (82%) rename frameworks/js/napi/src/manager/{local_activity_subscribe.cpp => local_live_view_subscribe.cpp} (86%) rename frameworks/js/napi/src/manager/{napi_local_activity.cpp => napi_local_live_view.cpp} (80%) rename interfaces/inner_api/{notification_local_activity_button.h => notification_local_live_view_button.h} (88%) rename interfaces/inner_api/{notification_local_activity_content.h => notification_local_live_view_content.h} (87%) rename interfaces/inner_api/{notification_local_activity_subscriber.h => notification_local_live_view_subscriber.h} (73%) rename services/ans/include/{notification_local_activity_subscriber_manager.h => notification_local_live_view_subscriber_manager.h} (70%) rename services/ans/src/{notification_local_activity_subscriber_manager.cpp => notification_local_live_view_subscriber_manager.cpp} (78%) diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index e468f53aa..1173d7aa7 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -54,8 +54,8 @@ ohos_shared_library("ans_innerkits") { "${core_path}/src/ans_manager_proxy.cpp", "${core_path}/src/ans_manager_stub.cpp", "${core_path}/src/ans_notification.cpp", - "${core_path}/src/ans_subscriber_local_activity_proxy.cpp", - "${core_path}/src/ans_subscriber_local_activity_stub.cpp", + "${core_path}/src/ans_subscriber_local_live_view_proxy.cpp", + "${core_path}/src/ans_subscriber_local_live_view_stub.cpp", "${core_path}/src/ans_subscriber_proxy.cpp", "${core_path}/src/ans_subscriber_stub.cpp", "${frameworks_module_ans_path}/src/badge_number_callback_data.cpp", @@ -75,9 +75,9 @@ ohos_shared_library("ans_innerkits") { "${frameworks_module_ans_path}/src/notification_do_not_disturb_date.cpp", "${frameworks_module_ans_path}/src/notification_flags.cpp", "${frameworks_module_ans_path}/src/notification_helper.cpp", - "${frameworks_module_ans_path}/src/notification_local_activity_button.cpp", - "${frameworks_module_ans_path}/src/notification_local_activity_content.cpp", - "${frameworks_module_ans_path}/src/notification_local_activity_subscriber.cpp", + "${frameworks_module_ans_path}/src/notification_local_live_view_button.cpp", + "${frameworks_module_ans_path}/src/notification_local_live_view_content.cpp", + "${frameworks_module_ans_path}/src/notification_local_live_view_subscriber.cpp", "${frameworks_module_ans_path}/src/notification_long_text_content.cpp", "${frameworks_module_ans_path}/src/notification_media_content.cpp", "${frameworks_module_ans_path}/src/notification_multiline_content.cpp", diff --git a/frameworks/ans/src/notification_content.cpp b/frameworks/ans/src/notification_content.cpp index 122e79253..886e58863 100644 --- a/frameworks/ans/src/notification_content.cpp +++ b/frameworks/ans/src/notification_content.cpp @@ -15,7 +15,7 @@ #include "notification_content.h" #include "ans_log_wrapper.h" -#include "notification_local_activity_content.h" +#include "notification_local_live_view_content.h" namespace OHOS { namespace Notification { @@ -85,15 +85,15 @@ NotificationContent::NotificationContent(const std::shared_ptr &localActivityContent) +NotificationContent::NotificationContent(const std::shared_ptr &localLiveViewContent) { - if (!localActivityContent) { - ANS_LOGE("NotificationLocalActivityContent can not be null"); + if (!localLiveViewContent) { + ANS_LOGE("NotificationLocalLiveViewContent can not be null"); return; } - contentType_ = NotificationContent::Type::LOCAL_ACTIVITY; - content_ = localActivityContent; + contentType_ = NotificationContent::Type::LOCAL_LIVE_VIEW; + content_ = localLiveViewContent; } NotificationContent::~NotificationContent() @@ -117,7 +117,7 @@ std::string NotificationContent::Dump() : (contentType_ == NotificationContent::Type::MEDIA) ? "MEDIA" : (contentType_ == NotificationContent::Type::MULTILINE) ? "MULTILINE" : (contentType_ == NotificationContent::Type::PICTURE) ? "PICTURE" - : (contentType_ == NotificationContent::Type::LOCAL_ACTIVITY) ? "LOCAL_ACTIVITY" : "NONE"; + : (contentType_ == NotificationContent::Type::LOCAL_LIVE_VIEW) ? "LOCAL_LIVE_VIEW" : "NONE"; return "NotificationContent{ " "contentType = " + contentTypeStr + @@ -240,9 +240,9 @@ bool NotificationContent::ReadFromParcel(Parcel &parcel) content_ = std::static_pointer_cast( std::shared_ptr(parcel.ReadParcelable())); break; - case NotificationContent::Type::LOCAL_ACTIVITY: + case NotificationContent::Type::LOCAL_LIVE_VIEW: content_ = std::static_pointer_cast( - std::shared_ptr(parcel.ReadParcelable())); + std::shared_ptr(parcel.ReadParcelable())); break; default: ANS_LOGE("Invalid contentType"); @@ -294,8 +294,8 @@ bool NotificationContent::ConvertJsonToContent(NotificationContent *target, cons case NotificationContent::Type::PICTURE: pBasicContent = NotificationJsonConverter::ConvertFromJson(contentObj); break; - case NotificationContent::Type::LOCAL_ACTIVITY: - pBasicContent = NotificationJsonConverter::ConvertFromJson(contentObj); + case NotificationContent::Type::LOCAL_LIVE_VIEW: + pBasicContent = NotificationJsonConverter::ConvertFromJson(contentObj); break; default: ANS_LOGE("Invalid contentType"); diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index f9b375055..81a84f5b0 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -164,9 +164,9 @@ ErrCode NotificationHelper::SubscribeNotification(const NotificationSubscriber & return DelayedSingleton::GetInstance()->SubscribeNotification(subscriber); } -ErrCode NotificationHelper::SubscribeLocalActivityNotification(const NotificationLocalActivitySubscriber &subscriber) +ErrCode NotificationHelper::SubscribeLocalLiveViewNotification(const NotificationLocalLiveViewSubscriber &subscriber) { - return DelayedSingleton::GetInstance()->SubscribeLocalActivityNotification(subscriber); + return DelayedSingleton::GetInstance()->SubscribeLocalLiveViewNotification(subscriber); } ErrCode NotificationHelper::SubscribeNotification( @@ -186,10 +186,10 @@ ErrCode NotificationHelper::UnSubscribeNotification( return DelayedSingleton::GetInstance()->UnSubscribeNotification(subscriber, subscribeInfo); } -ErrCode NotificationHelper::TriggerLocalActivity(const NotificationBundleOption &bundleOption, +ErrCode NotificationHelper::TriggerLocalLiveView(const NotificationBundleOption &bundleOption, const int32_t notificationId, const NotificationButtonOption &buttonOption) { - return DelayedSingleton::GetInstance()->TriggerLocalActivity(bundleOption, notificationId, buttonOption); + return DelayedSingleton::GetInstance()->TriggerLocalLiveView(bundleOption, notificationId, buttonOption); } ErrCode NotificationHelper::RemoveNotification(const std::string &key, int32_t removeReason) diff --git a/frameworks/ans/src/notification_local_activity_button.cpp b/frameworks/ans/src/notification_local_live_view_button.cpp similarity index 78% rename from frameworks/ans/src/notification_local_activity_button.cpp rename to frameworks/ans/src/notification_local_live_view_button.cpp index 7c51206de..1bf090ed4 100644 --- a/frameworks/ans/src/notification_local_activity_button.cpp +++ b/frameworks/ans/src/notification_local_live_view_button.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "notification_local_activity_button.h" +#include "notification_local_live_view_button.h" #include #include // for basic_string, operator+, basic_string<>... @@ -32,12 +32,12 @@ namespace OHOS { namespace Notification { -std::vector NotificationLocalActivityButton::GetAllButtonNames() const +std::vector NotificationLocalLiveViewButton::GetAllButtonNames() const { return buttonNames_; } -void NotificationLocalActivityButton::addSingleButtonName(const std::string &buttonName) +void NotificationLocalLiveViewButton::addSingleButtonName(const std::string &buttonName) { if (buttonNames_.size() >= 3) { ANS_LOGW("already added 3 buttonOption"); @@ -47,12 +47,12 @@ void NotificationLocalActivityButton::addSingleButtonName(const std::string &but buttonNames_.emplace_back(buttonName); } -std::vector> NotificationLocalActivityButton::GetAllButtonIcon() const +std::vector> NotificationLocalLiveViewButton::GetAllButtonIcon() const { return buttonIcons_; } -void NotificationLocalActivityButton::addSingleButtonIcon(std::shared_ptr &icon) +void NotificationLocalLiveViewButton::addSingleButtonIcon(std::shared_ptr &icon) { if (buttonIcons_.size() >= 3) { ANS_LOGW("already added 3 buttonIcon"); @@ -62,17 +62,12 @@ void NotificationLocalActivityButton::addSingleButtonIcon(std::shared_ptr(parcel.ReadParcelable()); if (member == nullptr) { buttonIcons_.clear(); - ANS_LOGE("Failed to read LocalActivityButton %llu, %llu",it, vsize); + ANS_LOGE("Failed to read LocalLiveViewButton %llu, %llu",it, vsize); return false; } @@ -171,9 +166,9 @@ bool NotificationLocalActivityButton::ReadFromParcel(Parcel &parcel) return true; } -NotificationLocalActivityButton *NotificationLocalActivityButton::Unmarshalling(Parcel &parcel) +NotificationLocalLiveViewButton *NotificationLocalLiveViewButton::Unmarshalling(Parcel &parcel) { - NotificationLocalActivityButton *button = new (std::nothrow) NotificationLocalActivityButton(); + NotificationLocalLiveViewButton *button = new (std::nothrow) NotificationLocalLiveViewButton(); if (button && !button->ReadFromParcel(parcel)) { delete button; diff --git a/frameworks/ans/src/notification_local_activity_content.cpp b/frameworks/ans/src/notification_local_live_view_content.cpp similarity index 83% rename from frameworks/ans/src/notification_local_activity_content.cpp rename to frameworks/ans/src/notification_local_live_view_content.cpp index b3ce2e863..854d9d43d 100644 --- a/frameworks/ans/src/notification_local_activity_content.cpp +++ b/frameworks/ans/src/notification_local_live_view_content.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "notification_local_activity_content.h" +#include "notification_local_live_view_content.h" #include #include // for basic_string, operator+ @@ -26,35 +26,35 @@ #include "notification_capsule.h" #include "notification_json_convert.h" #include "notification_progress.h" -#include "notification_local_activity_button.h" +#include "notification_local_live_view_button.h" #include "parcel.h" // for Parcel namespace OHOS { namespace Notification { -void NotificationLocalActivityContent::SetType(int32_t type) +void NotificationLocalLiveViewContent::SetType(int32_t type) { type_ = type; } -void NotificationLocalActivityContent::SetCapsule(NotificationCapsule capsule) +void NotificationLocalLiveViewContent::SetCapsule(NotificationCapsule capsule) { capsule_ = capsule; } -void NotificationLocalActivityContent::SetButton(NotificationLocalActivityButton button) +void NotificationLocalLiveViewContent::SetButton(NotificationLocalLiveViewButton button) { button_ = button; } -void NotificationLocalActivityContent::SetProgress(NotificationProgress progress) +void NotificationLocalLiveViewContent::SetProgress(NotificationProgress progress) { progress_ = progress; } -std::string NotificationLocalActivityContent::Dump() +std::string NotificationLocalLiveViewContent::Dump() { - return "NotificationLocalActivityContent{ " + NotificationBasicContent::Dump() + + return "NotificationLocalLiveViewContent{ " + NotificationBasicContent::Dump() + ", type = " + std::to_string(type_) + ", capsule = " + capsule_.Dump() + ", button = " + button_.Dump() + @@ -62,7 +62,7 @@ std::string NotificationLocalActivityContent::Dump() " }"; } -bool NotificationLocalActivityContent::ToJson(nlohmann::json &jsonObject) const +bool NotificationLocalLiveViewContent::ToJson(nlohmann::json &jsonObject) const { if (!NotificationBasicContent::ToJson(jsonObject)) { ANS_LOGE("Cannot convert basicContent to JSON"); @@ -95,16 +95,16 @@ bool NotificationLocalActivityContent::ToJson(nlohmann::json &jsonObject) const return true; } -NotificationLocalActivityContent *NotificationLocalActivityContent::FromJson(const nlohmann::json &jsonObject) +NotificationLocalLiveViewContent *NotificationLocalLiveViewContent::FromJson(const nlohmann::json &jsonObject) { if (jsonObject.is_null() or !jsonObject.is_object()) { ANS_LOGE("Invalid JSON object"); return nullptr; } - auto pContent = new (std::nothrow) NotificationLocalActivityContent(); + auto pContent = new (std::nothrow) NotificationLocalLiveViewContent(); if (pContent == nullptr) { - ANS_LOGE("Failed to create localActivityContent instance"); + ANS_LOGE("Failed to create localLiveViewContent instance"); return nullptr; } @@ -127,7 +127,7 @@ NotificationLocalActivityContent *NotificationLocalActivityContent::FromJson(con if (jsonObject.find("button") != jsonEnd ) { auto buttonObj = jsonObject.at("button"); - auto pButton = NotificationJsonConverter::ConvertFromJson(buttonObj); + auto pButton = NotificationJsonConverter::ConvertFromJson(buttonObj); if (pButton != nullptr) { pContent->button_ = *pButton; delete pButton; @@ -148,7 +148,7 @@ NotificationLocalActivityContent *NotificationLocalActivityContent::FromJson(con return pContent; } -bool NotificationLocalActivityContent::Marshalling(Parcel &parcel) const +bool NotificationLocalLiveViewContent::Marshalling(Parcel &parcel) const { if (!NotificationBasicContent::Marshalling(parcel)) { ANS_LOGE("Failed to write basic"); @@ -178,9 +178,9 @@ bool NotificationLocalActivityContent::Marshalling(Parcel &parcel) const return true; } -NotificationLocalActivityContent *NotificationLocalActivityContent::Unmarshalling(Parcel &parcel) +NotificationLocalLiveViewContent *NotificationLocalLiveViewContent::Unmarshalling(Parcel &parcel) { - auto pContent = new (std::nothrow) NotificationLocalActivityContent(); + auto pContent = new (std::nothrow) NotificationLocalLiveViewContent(); if ((pContent != nullptr) && !pContent->ReadFromParcel(parcel)) { delete pContent; pContent = nullptr; @@ -189,7 +189,7 @@ NotificationLocalActivityContent *NotificationLocalActivityContent::Unmarshallin return pContent; } -bool NotificationLocalActivityContent::ReadFromParcel(Parcel &parcel) +bool NotificationLocalLiveViewContent::ReadFromParcel(Parcel &parcel) { if (!NotificationBasicContent::ReadFromParcel(parcel)) { ANS_LOGE("Failed to read basic"); @@ -210,7 +210,7 @@ bool NotificationLocalActivityContent::ReadFromParcel(Parcel &parcel) delete pCapsule; pCapsule = nullptr; - auto pButton = parcel.ReadParcelable(); + auto pButton = parcel.ReadParcelable(); if (pButton == nullptr) { ANS_LOGE("Failed to read button"); return false; diff --git a/frameworks/ans/src/notification_local_activity_subscriber.cpp b/frameworks/ans/src/notification_local_live_view_subscriber.cpp similarity index 68% rename from frameworks/ans/src/notification_local_activity_subscriber.cpp rename to frameworks/ans/src/notification_local_live_view_subscriber.cpp index b0d136bb8..5db0e1666 100644 --- a/frameworks/ans/src/notification_local_activity_subscriber.cpp +++ b/frameworks/ans/src/notification_local_live_view_subscriber.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "notification_local_activity_subscriber.h" +#include "notification_local_live_view_subscriber.h" #include "hitrace_meter.h" #include "iservice_registry.h" @@ -21,25 +21,25 @@ namespace OHOS { namespace Notification { -NotificationLocalActivitySubscriber::NotificationLocalActivitySubscriber() +NotificationLocalLiveViewSubscriber::NotificationLocalLiveViewSubscriber() { - impl_ = new (std::nothrow) SubscriberLocalActivityImpl(*this); + impl_ = new (std::nothrow) SubscriberLocalLiveViewImpl(*this); }; -NotificationLocalActivitySubscriber::~NotificationLocalActivitySubscriber() +NotificationLocalLiveViewSubscriber::~NotificationLocalLiveViewSubscriber() {} -const sptr NotificationLocalActivitySubscriber::GetImpl() const +const sptr NotificationLocalLiveViewSubscriber::GetImpl() const { return impl_; } -NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::SubscriberLocalActivityImpl(NotificationLocalActivitySubscriber &subscriber) : subscriber_(subscriber) +NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::SubscriberLocalLiveViewImpl(NotificationLocalLiveViewSubscriber &subscriber) : subscriber_(subscriber) { recipient_ = new (std::nothrow) DeathRecipient(*this); }; -void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnConnected() +void NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnConnected() { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (GetAnsManagerProxy()) { @@ -49,7 +49,7 @@ void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnConnect subscriber_.OnConnected(); } -void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnDisconnected() +void NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnDisconnected() { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (GetAnsManagerProxy()) { @@ -59,13 +59,13 @@ void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnDisconn subscriber_.OnDisconnected(); } -void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::OnResponse(int32_t notificationId, sptr buttonOption) +void NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::OnResponse(int32_t notificationId, sptr buttonOption) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); subscriber_.OnResponse(notificationId, buttonOption); } -bool NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::GetAnsManagerProxy() +bool NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::GetAnsManagerProxy() { if (proxy_ == nullptr) { std::lock_guard lock(mutex_); @@ -92,12 +92,12 @@ bool NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::GetAnsMan return true; } -NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::DeathRecipient::DeathRecipient(SubscriberLocalActivityImpl &subscriberImpl) +NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::DeathRecipient::DeathRecipient(SubscriberLocalLiveViewImpl &subscriberImpl) : subscriberImpl_(subscriberImpl) {}; -NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::DeathRecipient::~DeathRecipient() {}; +NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::DeathRecipient::~DeathRecipient() {}; -void NotificationLocalActivitySubscriber::SubscriberLocalActivityImpl::DeathRecipient::OnRemoteDied(const wptr &object) +void NotificationLocalLiveViewSubscriber::SubscriberLocalLiveViewImpl::DeathRecipient::OnRemoteDied(const wptr &object) { subscriberImpl_.proxy_ = nullptr; subscriberImpl_.subscriber_.OnDied(); diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index d8a0b864d..3a595b2cb 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -20,7 +20,7 @@ #include #include "ans_subscriber_interface.h" -#include "ans_subscriber_local_activity_interface.h" +#include "ans_subscriber_local_live_view_interface.h" #include "iremote_broker.h" #include "notification_bundle_option.h" #include "notification_constant.h" @@ -254,9 +254,9 @@ public: * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. * @param notificationId Indicates the id of the notification. * @param buttonOption Indicates which button has been clicked. - * @return Returns trigger localActivity result. + * @return Returns trigger localLiveView result. */ - virtual ErrCode TriggerLocalActivity(const sptr &bundleOption, + virtual ErrCode TriggerLocalLiveView(const sptr &bundleOption, const int32_t notificationId, const sptr &buttonOption) = 0; /** @@ -404,7 +404,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode SubscribeLocalActivity(const sptr &subscriber, + virtual ErrCode SubscribeLocalLiveView(const sptr &subscriber, const sptr &info) = 0; /** diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 5e84d1247..f938d548b 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -242,9 +242,9 @@ public: * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. * @param notificationId Indicates the id of the notification. * @param buttonOption Indicates which button has been clicked. - * @return Returns trigger localActivity result. + * @return Returns trigger localLiveView result. */ - ErrCode TriggerLocalActivity(const sptr &bundleOption, + ErrCode TriggerLocalLiveView(const sptr &bundleOption, const int32_t notificationId, const sptr &buttonOption) override; /** @@ -392,7 +392,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - ErrCode SubscribeLocalActivity(const sptr &subscriber, + ErrCode SubscribeLocalLiveView(const sptr &subscriber, const sptr &info) override; diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 6119a2ff8..2b1317a6c 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -20,7 +20,7 @@ #include #include "ans_manager_interface.h" -#include "ans_subscriber_local_activity_interface.h" +#include "ans_subscriber_local_live_view_interface.h" #include "distributed_notification_service_ipc_interface_code.h" #include "iremote_stub.h" @@ -258,9 +258,9 @@ public: * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. * @param notificationId Indicates the id of the notification. * @param buttonOption Indicates which button has been clicked. - * @return Returns trigger localActivity result. + * @return Returns trigger localLiveView result. */ - virtual ErrCode TriggerLocalActivity(const sptr &bundleOption, + virtual ErrCode TriggerLocalLiveView(const sptr &bundleOption, const int32_t notificationId, const sptr &buttonOption) override; /** @@ -404,8 +404,8 @@ public: virtual ErrCode Subscribe( const sptr &subscriber, const sptr &info) override; - virtual ErrCode SubscribeLocalActivity( - const sptr &subscriber, const sptr &info) override; + virtual ErrCode SubscribeLocalLiveView( + const sptr &subscriber, const sptr &info) override; /** * @brief Unsubscribes notifications. @@ -776,8 +776,8 @@ private: ErrCode HandleSetBadgeNumber(MessageParcel &data, MessageParcel &reply); ErrCode HandleRegisterPushCallback(MessageParcel &data, MessageParcel &reply); ErrCode HandleUnregisterPushCallback(MessageParcel &data, MessageParcel &reply); - ErrCode HandleSubscribeLocalActivity(MessageParcel &data, MessageParcel &reply); - ErrCode HandleTriggerLocalActivity(MessageParcel &data, MessageParcel &reply); + ErrCode HandleSubscribeLocalLiveView(MessageParcel &data, MessageParcel &reply); + ErrCode HandleTriggerLocalLiveView(MessageParcel &data, MessageParcel &reply); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result) diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index 0634f66ba..3ea593bd3 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -21,7 +21,7 @@ #include "ans_manager_death_recipient.h" #include "ans_manager_interface.h" #include "notification_subscriber.h" -#include "notification_local_activity_subscriber.h" +#include "notification_local_live_view_subscriber.h" namespace OHOS { namespace Notification { @@ -312,7 +312,7 @@ public: * This parameter must be specified. * @return Returns subscribe notification result. */ - ErrCode SubscribeLocalActivityNotification(const NotificationLocalActivitySubscriber &subscriber); + ErrCode SubscribeLocalLiveViewNotification(const NotificationLocalLiveViewSubscriber &subscriber); /** * @brief Subscribes to all notifications based on the filtering criteria. This method can be called only @@ -371,9 +371,9 @@ public: * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. * @param notificationId Indicates the id of the notification. * @param buttonOption Indicates which button has been clicked. - * @return Returns trigger localActivity result. + * @return Returns trigger localLiveView result. */ - ErrCode TriggerLocalActivity(const NotificationBundleOption &bundleOption, + ErrCode TriggerLocalLiveView(const NotificationBundleOption &bundleOption, const int32_t notificationId, const NotificationButtonOption &buttonOption); /** diff --git a/frameworks/core/include/ans_subscriber_local_activity_interface.h b/frameworks/core/include/ans_subscriber_local_live_view_interface.h similarity index 80% rename from frameworks/core/include/ans_subscriber_local_activity_interface.h rename to frameworks/core/include/ans_subscriber_local_live_view_interface.h index 030696320..44cd09767 100644 --- a/frameworks/core/include/ans_subscriber_local_activity_interface.h +++ b/frameworks/core/include/ans_subscriber_local_live_view_interface.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_ACTIVITY_SUBSCRIBER_INTERFACE_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_ACTIVITY_SUBSCRIBER_INTERFACE_H +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_LIVE_VIEW_SUBSCRIBER_INTERFACE_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_LIVE_VIEW_SUBSCRIBER_INTERFACE_H #include "iremote_broker.h" @@ -29,13 +29,13 @@ namespace OHOS { namespace Notification { -class AnsSubscriberLocalActivityInterface : public IRemoteBroker { +class AnsSubscriberLocalLiveViewInterface : public IRemoteBroker { public: - AnsSubscriberLocalActivityInterface() = default; - virtual ~AnsSubscriberLocalActivityInterface() override = default; - DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalActivityInterface); + AnsSubscriberLocalLiveViewInterface() = default; + virtual ~AnsSubscriberLocalLiveViewInterface() override = default; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalLiveViewInterface); - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.AnsSubscriberLocalActivityInterface"); + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.AnsSubscriberLocalLiveViewInterface"); /** * @brief The callback function for the subscriber to establish a connection. @@ -53,4 +53,4 @@ public: } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_ACTIVITY_SUBSCRIBER_INTERFACE_H +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_LOCAL_LIVE_VIEW_SUBSCRIBER_INTERFACE_H diff --git a/frameworks/core/include/ans_subscriber_local_activity_proxy.h b/frameworks/core/include/ans_subscriber_local_live_view_proxy.h similarity index 83% rename from frameworks/core/include/ans_subscriber_local_activity_proxy.h rename to frameworks/core/include/ans_subscriber_local_live_view_proxy.h index eb8f6252a..36cf7d8c8 100644 --- a/frameworks/core/include/ans_subscriber_local_activity_proxy.h +++ b/frameworks/core/include/ans_subscriber_local_live_view_proxy.h @@ -16,18 +16,18 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_SYSTEM_ACTIVITY_PROXY_H #define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_SYSTEM_ACTIVITY_PROXY_H -#include "ans_subscriber_local_activity_interface.h" +#include "ans_subscriber_local_live_view_interface.h" #include "distributed_notification_service_ipc_interface_code.h" #include "iremote_proxy.h" namespace OHOS { namespace Notification { -class AnsSubscriberLocalActivityProxy : public IRemoteProxy { +class AnsSubscriberLocalLiveViewProxy : public IRemoteProxy { public: - AnsSubscriberLocalActivityProxy() = delete; - explicit AnsSubscriberLocalActivityProxy(const sptr &impl); - ~AnsSubscriberLocalActivityProxy() override; - DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalActivityProxy); + AnsSubscriberLocalLiveViewProxy() = delete; + explicit AnsSubscriberLocalLiveViewProxy(const sptr &impl); + ~AnsSubscriberLocalLiveViewProxy() override; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalLiveViewProxy); /** * @brief The callback function for the subscriber to establish a connection. @@ -43,7 +43,7 @@ public: private: ErrCode InnerTransact(NotificationInterfaceCode code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); - static inline BrokerDelegator delegator_; + static inline BrokerDelegator delegator_; template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &data) diff --git a/frameworks/core/include/ans_subscriber_local_activity_stub.h b/frameworks/core/include/ans_subscriber_local_live_view_stub.h similarity index 83% rename from frameworks/core/include/ans_subscriber_local_activity_stub.h rename to frameworks/core/include/ans_subscriber_local_live_view_stub.h index 8532f8829..63e9080ca 100644 --- a/frameworks/core/include/ans_subscriber_local_activity_stub.h +++ b/frameworks/core/include/ans_subscriber_local_live_view_stub.h @@ -13,20 +13,20 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_ACTIVITY_STUB_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_ACTIVITY_STUB_H +#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_STUB_H +#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_STUB_H -#include "ans_subscriber_local_activity_interface.h" +#include "ans_subscriber_local_live_view_interface.h" #include "distributed_notification_service_ipc_interface_code.h" #include "iremote_stub.h" namespace OHOS { namespace Notification { -class AnsSubscriberLocalActivityStub : public IRemoteStub { +class AnsSubscriberLocalLiveViewStub : public IRemoteStub { public: - AnsSubscriberLocalActivityStub(); - ~AnsSubscriberLocalActivityStub() override; - DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalActivityStub); + AnsSubscriberLocalLiveViewStub(); + ~AnsSubscriberLocalLiveViewStub() override; + DISALLOW_COPY_AND_MOVE(AnsSubscriberLocalLiveViewStub); /** * @brief Handle remote request. @@ -64,4 +64,4 @@ private: } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_ACTIVITY_STUB_H +#endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_SUBSCRIBER_LOCAL_LIVE_VIEW_STUB_H diff --git a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h index f1fc8d4f2..78f24ac5d 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -118,8 +118,8 @@ namespace Notification { // push_callback_interface ON_CHECK_NOTIFICATION, ON_RESPONSE, - SUBSCRIBE_LOCAL_ACTIVITY_NOTIFICATION, - TRIGGER_LOCAL_ACTIVITY_NOTIFICATION, + SUBSCRIBE_LOCAL_LIVE_VIEW_NOTIFICATION, + TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION, }; } } diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index 3144b7937..f2acb74e3 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -18,8 +18,9 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" -#include "ans_subscriber_local_activity_interface.h" +#include "ans_subscriber_local_live_view_interface.h" #include "distributed_notification_service_ipc_interface_code.h" +#include "errors.h" #include "message_option.h" #include "message_parcel.h" #include "parcel.h" @@ -740,45 +741,45 @@ ErrCode AnsManagerProxy::HasNotificationPolicyAccessPermission(bool &granted) return result; } -ErrCode AnsManagerProxy::TriggerLocalActivity(const sptr &bundleOption, +ErrCode AnsManagerProxy::TriggerLocalLiveView(const sptr &bundleOption, const int32_t notificationId, const sptr &buttonOption) { if (bundleOption == nullptr) { - ANS_LOGE("[TriggerLocalActivity] fail: bundle is empty."); + ANS_LOGE("[TriggerLocalLiveView] fail: bundle is empty."); return ERR_ANS_INVALID_PARAM; } MessageParcel data; if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANS_LOGE("[TriggerLocalActivity] fail:, write interface token failed."); + ANS_LOGE("[TriggerLocalLiveView] fail:, write interface token failed."); return ERR_ANS_PARCELABLE_FAILED; } if (!data.WriteStrongParcelable(bundleOption)) { - ANS_LOGE("[TriggerLocalActivity] fail:: write bundle failed"); + ANS_LOGE("[TriggerLocalLiveView] fail:: write bundle failed"); return ERR_ANS_PARCELABLE_FAILED; } if (!data.WriteInt32(notificationId)) { - ANS_LOGE("[TriggerLocalActivity] fail: write notificationId failed"); + ANS_LOGE("[TriggerLocalLiveView] fail: write notificationId failed"); return ERR_ANS_PARCELABLE_FAILED; } if (!data.WriteStrongParcelable(buttonOption)) { - ANS_LOGE("[TriggerLocalActivity] fail: write label failed"); + ANS_LOGE("[TriggerLocalLiveView] fail: write label failed"); return ERR_ANS_PARCELABLE_FAILED; } MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::TRIGGER_LOCAL_ACTIVITY_NOTIFICATION, option, data, reply); + ErrCode result = InnerTransact(NotificationInterfaceCode::TRIGGER_LOCAL_LIVE_VIEW_NOTIFICATION, option, data, reply); if (result != ERR_OK) { - ANS_LOGE("[TriggerLocalActivity] fail: transact ErrCode=%{public}d", result); + ANS_LOGE("[TriggerLocalLiveView] fail: transact ErrCode=%{public}d", result); return ERR_ANS_TRANSACT_FAILED; } if (!reply.ReadInt32(result)) { - ANS_LOGE("[TriggerLocalActivity] fail: read result error."); + ANS_LOGE("[TriggerLocalLiveView] fail: read result error."); return ERR_ANS_PARCELABLE_FAILED; } @@ -1404,7 +1405,7 @@ ErrCode AnsManagerProxy::Subscribe(const sptr &subscribe return result; } -ErrCode AnsManagerProxy::SubscribeLocalActivity(const sptr &subscriber, const sptr &info) +ErrCode AnsManagerProxy::SubscribeLocalLiveView(const sptr &subscriber, const sptr &info) { if (subscriber == nullptr) { ANS_LOGE("[Subscribe] fail: subscriber is empty."); @@ -1437,7 +1438,7 @@ ErrCode AnsManagerProxy::SubscribeLocalActivity(const sptr bundleOption = data.ReadStrongParcelable(); if (bundleOption == nullptr) { - ANS_LOGE("[HandleTriggerLocalActivity] fail: read bundle failed."); + ANS_LOGE("[HandleTriggerLocalLiveView] fail: read bundle failed."); return ERR_ANS_PARCELABLE_FAILED; } int32_t notificationId = 0; if (!data.ReadInt32(notificationId)) { - ANS_LOGE("[HandleTriggerLocalActivity] fail: read notificationId failed"); + ANS_LOGE("[HandleTriggerLocalLiveView] fail: read notificationId failed"); return ERR_ANS_PARCELABLE_FAILED; } sptr buttonOption = data.ReadStrongParcelable(); if (buttonOption == nullptr) { - ANS_LOGE("[HandleTriggerLocalActivity] fail: read button failed."); + ANS_LOGE("[HandleTriggerLocalLiveView] fail: read button failed."); return ERR_ANS_PARCELABLE_FAILED; } - ErrCode result = TriggerLocalActivity(bundleOption, notificationId, buttonOption); + ErrCode result = TriggerLocalLiveView(bundleOption, notificationId, buttonOption); if (!reply.WriteInt32(result)) { - ANS_LOGE("[HandleTriggerLocalActivity] fail: write result failed, ErrCode=%{public}d", result); + ANS_LOGE("[HandleTriggerLocalLiveView] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; } return ERR_OK; @@ -1137,17 +1137,17 @@ ErrCode AnsManagerStub::HandleSubscribe(MessageParcel &data, MessageParcel &repl return ERR_OK; } -ErrCode AnsManagerStub::HandleSubscribeLocalActivity(MessageParcel &data, MessageParcel &reply) +ErrCode AnsManagerStub::HandleSubscribeLocalLiveView(MessageParcel &data, MessageParcel &reply) { sptr subscriber = data.ReadRemoteObject(); if (subscriber == nullptr) { - ANS_LOGE("[HandleSubscribeLocalActivity] fail: read subscriber failed"); + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read subscriber failed"); return ERR_ANS_PARCELABLE_FAILED; } bool subcribeInfo = false; if (!data.ReadBool(subcribeInfo)) { - ANS_LOGE("[HandleSubscribeLocalActivity] fail: read isSubcribeInfo failed"); + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read isSubcribeInfo failed"); return ERR_ANS_PARCELABLE_FAILED; } @@ -1155,14 +1155,14 @@ ErrCode AnsManagerStub::HandleSubscribeLocalActivity(MessageParcel &data, Messag if (subcribeInfo) { info = data.ReadParcelable(); if (info == nullptr) { - ANS_LOGE("[HandleSubscribeLocalActivity] fail: read info failed"); + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: read info failed"); return ERR_ANS_PARCELABLE_FAILED; } } - ErrCode result = SubscribeLocalActivity(iface_cast(subscriber), info); + ErrCode result = SubscribeLocalLiveView(iface_cast(subscriber), info); if (!reply.WriteInt32(result)) { - ANS_LOGE("[HandleSubscribeLocalActivity] fail: write result failed, ErrCode=%{public}d", result); + ANS_LOGE("[HandleSubscribeLocalLiveView] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; } return ERR_OK; @@ -1949,10 +1949,10 @@ ErrCode AnsManagerStub::HasNotificationPolicyAccessPermission(bool &granted) return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::TriggerLocalActivity(const sptr &bundleOption, +ErrCode AnsManagerStub::TriggerLocalLiveView(const sptr &bundleOption, const int32_t notificationId, const sptr &buttonOption) { - ANS_LOGE("AnsManagerStub::TriggerLocalActivity called!"); + ANS_LOGE("AnsManagerStub::TriggerLocalLiveView called!"); return ERR_INVALID_OPERATION; } @@ -2057,10 +2057,10 @@ ErrCode AnsManagerStub::Subscribe(const sptr &subscriber return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::SubscribeLocalActivity(const sptr &subscriber, +ErrCode AnsManagerStub::SubscribeLocalLiveView(const sptr &subscriber, const sptr &info) { - ANS_LOGE("AnsManagerStub::SubscribeLocalActivity called!"); + ANS_LOGE("AnsManagerStub::SubscribeLocalLiveView called!"); return ERR_INVALID_OPERATION; } diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 6f8df74eb..6aaf042c6 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -20,7 +20,7 @@ #include "hitrace_meter.h" #include "iservice_registry.h" #include "notification_button_option.h" -#include "notification_local_activity_subscriber.h" +#include "notification_local_live_view_subscriber.h" #include "reminder_request_alarm.h" #include "reminder_request_calendar.h" #include "reminder_request_timer.h" @@ -379,7 +379,7 @@ ErrCode AnsNotification::SubscribeNotification(const NotificationSubscriber &sub return ansManagerProxy_->Subscribe(subscriberSptr, nullptr); } -ErrCode AnsNotification::SubscribeLocalActivityNotification(const NotificationLocalActivitySubscriber &subscriber) +ErrCode AnsNotification::SubscribeLocalLiveViewNotification(const NotificationLocalLiveViewSubscriber &subscriber) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (!GetAnsManagerProxy()) { @@ -387,12 +387,12 @@ ErrCode AnsNotification::SubscribeLocalActivityNotification(const NotificationLo return ERR_ANS_SERVICE_NOT_CONNECTED; } - sptr subscriberSptr = subscriber.GetImpl(); + sptr subscriberSptr = subscriber.GetImpl(); if (subscriberSptr == nullptr) { ANS_LOGE("Failed to subscribe with SubscriberImpl null ptr."); return ERR_ANS_INVALID_PARAM; } - return ansManagerProxy_->SubscribeLocalActivity(subscriberSptr, nullptr); + return ansManagerProxy_->SubscribeLocalLiveView(subscriberSptr, nullptr); } ErrCode AnsNotification::SubscribeNotification( @@ -457,7 +457,7 @@ ErrCode AnsNotification::UnSubscribeNotification( return ansManagerProxy_->Unsubscribe(subscriberSptr, sptrInfo); } -ErrCode AnsNotification::TriggerLocalActivity(const NotificationBundleOption &bundleOption, +ErrCode AnsNotification::TriggerLocalLiveView(const NotificationBundleOption &bundleOption, const int32_t notificationId, const NotificationButtonOption &buttonOption) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); @@ -478,7 +478,7 @@ ErrCode AnsNotification::TriggerLocalActivity(const NotificationBundleOption &bu sptr bo(new (std::nothrow) NotificationBundleOption(bundleOption)); sptr button(new (std::nothrow) NotificationButtonOption(buttonOption)); - return ansManagerProxy_->TriggerLocalActivity(bo, notificationId, button); + return ansManagerProxy_->TriggerLocalLiveView(bo, notificationId, button); } ErrCode AnsNotification::RemoveNotification(const std::string &key, int32_t removeReason) diff --git a/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp b/frameworks/core/src/ans_subscriber_local_live_view_proxy.cpp similarity index 84% rename from frameworks/core/src/ans_subscriber_local_activity_proxy.cpp rename to frameworks/core/src/ans_subscriber_local_live_view_proxy.cpp index a22d63506..7a1cac44c 100644 --- a/frameworks/core/src/ans_subscriber_local_activity_proxy.cpp +++ b/frameworks/core/src/ans_subscriber_local_live_view_proxy.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "ans_subscriber_local_activity_proxy.h" +#include "ans_subscriber_local_live_view_proxy.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" @@ -22,13 +22,13 @@ namespace OHOS { namespace Notification { -AnsSubscriberLocalActivityProxy::AnsSubscriberLocalActivityProxy(const sptr &impl) : IRemoteProxy(impl) +AnsSubscriberLocalLiveViewProxy::AnsSubscriberLocalLiveViewProxy(const sptr &impl) : IRemoteProxy(impl) {} -AnsSubscriberLocalActivityProxy::~AnsSubscriberLocalActivityProxy() +AnsSubscriberLocalLiveViewProxy::~AnsSubscriberLocalLiveViewProxy() {} -ErrCode AnsSubscriberLocalActivityProxy::InnerTransact( +ErrCode AnsSubscriberLocalLiveViewProxy::InnerTransact( NotificationInterfaceCode code, MessageOption &flags, MessageParcel &data, MessageParcel &reply) { auto remote = Remote(); @@ -53,10 +53,10 @@ ErrCode AnsSubscriberLocalActivityProxy::InnerTransact( } } -void AnsSubscriberLocalActivityProxy::OnConnected() +void AnsSubscriberLocalLiveViewProxy::OnConnected() { MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberLocalActivityProxy::GetDescriptor())) { + if (!data.WriteInterfaceToken(AnsSubscriberLocalLiveViewProxy::GetDescriptor())) { ANS_LOGE("[OnConnected] fail: write interface token failed."); return; } @@ -70,10 +70,10 @@ void AnsSubscriberLocalActivityProxy::OnConnected() } } -void AnsSubscriberLocalActivityProxy::OnDisconnected() +void AnsSubscriberLocalLiveViewProxy::OnDisconnected() { MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberLocalActivityProxy::GetDescriptor())) { + if (!data.WriteInterfaceToken(AnsSubscriberLocalLiveViewProxy::GetDescriptor())) { ANS_LOGE("[OnDisconnected] fail: write interface token failed."); return; } @@ -88,10 +88,10 @@ void AnsSubscriberLocalActivityProxy::OnDisconnected() } -void AnsSubscriberLocalActivityProxy::OnResponse(int32_t notificationId, sptr buttonOption) +void AnsSubscriberLocalLiveViewProxy::OnResponse(int32_t notificationId, sptr buttonOption) { MessageParcel data; - if (!data.WriteInterfaceToken(AnsSubscriberLocalActivityProxy::GetDescriptor())) { + if (!data.WriteInterfaceToken(AnsSubscriberLocalLiveViewProxy::GetDescriptor())) { ANS_LOGE("[OnResponse] fail: write interface token failed."); return; } diff --git a/frameworks/core/src/ans_subscriber_local_activity_stub.cpp b/frameworks/core/src/ans_subscriber_local_live_view_stub.cpp similarity index 79% rename from frameworks/core/src/ans_subscriber_local_activity_stub.cpp rename to frameworks/core/src/ans_subscriber_local_live_view_stub.cpp index 0e410eb3b..f4cdb5469 100644 --- a/frameworks/core/src/ans_subscriber_local_activity_stub.cpp +++ b/frameworks/core/src/ans_subscriber_local_live_view_stub.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "ans_subscriber_local_activity_stub.h" +#include "ans_subscriber_local_live_view_stub.h" #include "ans_const_define.h" #include "ans_inner_errors.h" @@ -28,23 +28,23 @@ namespace OHOS { namespace Notification { -AnsSubscriberLocalActivityStub::AnsSubscriberLocalActivityStub() +AnsSubscriberLocalLiveViewStub::AnsSubscriberLocalLiveViewStub() { interfaces_.emplace(NotificationInterfaceCode::ON_CONNECTED, - std::bind(&AnsSubscriberLocalActivityStub::HandleOnConnected, this, std::placeholders::_1, std::placeholders::_2)); + std::bind(&AnsSubscriberLocalLiveViewStub::HandleOnConnected, this, std::placeholders::_1, std::placeholders::_2)); interfaces_.emplace(NotificationInterfaceCode::ON_DISCONNECTED, - std::bind(&AnsSubscriberLocalActivityStub::HandleOnDisconnected, this, std::placeholders::_1, std::placeholders::_2)); + std::bind(&AnsSubscriberLocalLiveViewStub::HandleOnDisconnected, this, std::placeholders::_1, std::placeholders::_2)); interfaces_.emplace(NotificationInterfaceCode::ON_RESPONSE, - std::bind(&AnsSubscriberLocalActivityStub::HandleOnResponse, this, std::placeholders::_1, std::placeholders::_2)); + std::bind(&AnsSubscriberLocalLiveViewStub::HandleOnResponse, this, std::placeholders::_1, std::placeholders::_2)); } -AnsSubscriberLocalActivityStub::~AnsSubscriberLocalActivityStub() +AnsSubscriberLocalLiveViewStub::~AnsSubscriberLocalLiveViewStub() {} -int32_t AnsSubscriberLocalActivityStub::OnRemoteRequest( +int32_t AnsSubscriberLocalLiveViewStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &flags) { - std::u16string descriptor = AnsSubscriberLocalActivityStub::GetDescriptor(); + std::u16string descriptor = AnsSubscriberLocalLiveViewStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { ANS_LOGW("[OnRemoteRequest] fail: invalid interface token!"); @@ -67,20 +67,20 @@ int32_t AnsSubscriberLocalActivityStub::OnRemoteRequest( return NO_ERROR; } -ErrCode AnsSubscriberLocalActivityStub::HandleOnConnected(MessageParcel &data, MessageParcel &reply) +ErrCode AnsSubscriberLocalLiveViewStub::HandleOnConnected(MessageParcel &data, MessageParcel &reply) { OnConnected(); return ERR_OK; } -ErrCode AnsSubscriberLocalActivityStub::HandleOnDisconnected(MessageParcel &data, MessageParcel &reply) +ErrCode AnsSubscriberLocalLiveViewStub::HandleOnDisconnected(MessageParcel &data, MessageParcel &reply) { OnDisconnected(); return ERR_OK; } template -bool AnsSubscriberLocalActivityStub::ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) +bool AnsSubscriberLocalLiveViewStub::ReadParcelableVector(std::vector> &parcelableInfos, MessageParcel &data) { int32_t infoSize = 0; if (!data.ReadInt32(infoSize)) { @@ -102,7 +102,7 @@ bool AnsSubscriberLocalActivityStub::ReadParcelableVector(std::vector> & return true; } -ErrCode AnsSubscriberLocalActivityStub::HandleOnResponse(MessageParcel &data, MessageParcel &reply) +ErrCode AnsSubscriberLocalLiveViewStub::HandleOnResponse(MessageParcel &data, MessageParcel &reply) { int32_t notificationId = 0; if (!data.ReadInt32(notificationId)) { @@ -119,13 +119,13 @@ ErrCode AnsSubscriberLocalActivityStub::HandleOnResponse(MessageParcel &data, Me return ERR_OK; } -void AnsSubscriberLocalActivityStub::OnConnected() +void AnsSubscriberLocalLiveViewStub::OnConnected() {} -void AnsSubscriberLocalActivityStub::OnDisconnected() +void AnsSubscriberLocalLiveViewStub::OnDisconnected() {} -void AnsSubscriberLocalActivityStub::OnResponse(int32_t notificationId, sptr buttonOption) +void AnsSubscriberLocalLiveViewStub::OnResponse(int32_t notificationId, sptr buttonOption) {} } // namespace Notification } // namespace OHOS diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 3e5385a4c..a050c3c40 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -19,7 +19,7 @@ #include "napi/native_api.h" #include "napi/native_node_api.h" #include "notification_helper.h" -#include "notification_local_activity_button.h" +#include "notification_local_live_view_button.h" namespace OHOS { namespace NotificationNapi { @@ -40,7 +40,7 @@ enum class ContentType { NOTIFICATION_CONTENT_PICTURE, NOTIFICATION_CONTENT_CONVERSATION, NOTIFICATION_CONTENT_MULTILINE, - NOTIFICATION_CONTENT_LOCAL_ACTIVITY + NOTIFICATION_CONTENT_LOCAL_LIVE_VIEW }; enum class SlotType { @@ -48,6 +48,7 @@ enum class SlotType { SOCIAL_COMMUNICATION = 1, SERVICE_INFORMATION = 2, CONTENT_INFORMATION = 3, + LIVE_VIEW = 4, OTHER_TYPES = 0xFFFF, }; @@ -1216,59 +1217,59 @@ public: std::shared_ptr &pictureContent); /** - * @brief Gets a NotificationLocalActivityContent object from specified js object + * @brief Gets a NotificationLocalLiveViewContent object from specified js object * * @param env Indicates the environment that the API is invoked under * @param result Indicates a js object to be converted - * @param request Indicates a NotificationLocalActivityContent object from specified js object + * @param request Indicates a NotificationLocalLiveViewContent object from specified js object * @return Returns the null object if success, returns the null value otherwise */ - static napi_value GetNotificationLocalActivityContent( + static napi_value GetNotificationLocalLiveViewContent( const napi_env &env, const napi_value &result, NotificationRequest &request); /** - * @brief Gets a capsule of NotificationLocalActivityContent object from specified js object + * @brief Gets a capsule of NotificationLocalLiveViewContent object from specified js object * * @param env Indicates the environment that the API is invoked under * @param contentResult Indicates a js object to be converted * @param pictureContent Indicates a capsule object from specified js object * @return Returns the null object if success, returns the null value otherwise */ - static napi_value GetNotificationLocalActivityCapsule( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + static napi_value GetNotificationLocalLiveViewCapsule( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** - * @brief Gets a button of NotificationLocalActivityContent object from specified js object + * @brief Gets a button of NotificationLocalLiveViewContent object from specified js object * * @param env Indicates the environment that the API is invoked under * @param contentResult Indicates a js object to be converted * @param pictureContent Indicates a button object from specified js object * @return Returns the null object if success, returns the null value otherwise */ - static napi_value GetNotificationLocalActivityButton( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + static napi_value GetNotificationLocalLiveViewButton( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** - * @brief Gets a time of NotificationLocalActivityContent object from specified js object + * @brief Gets a time of NotificationLocalLiveViewContent object from specified js object * * @param env Indicates the environment that the API is invoked under * @param contentResult Indicates a js object to be converted * @param pictureContent Indicates a time object from specified js object * @return Returns the null object if success, returns the null value otherwise */ - static napi_value GetNotificationLocalActivityTime( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + static napi_value GetNotificationLocalLiveViewTime( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** - * @brief Gets a progress of NotificationLocalActivityContent object from specified js object + * @brief Gets a progress of NotificationLocalLiveViewContent object from specified js object * * @param env Indicates the environment that the API is invoked under * @param contentResult Indicates a js object to be converted * @param pictureContent Indicates a progress object from specified js object * @return Returns the null object if success, returns the null value otherwise */ - static napi_value GetNotificationLocalActivityProgress( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + static napi_value GetNotificationLocalLiveViewProgress( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** * @brief Gets a NotificationPictureContent object from specified js object @@ -1278,8 +1279,8 @@ public: * @param pictureContent Indicates a NotificationPictureContent object from specified js object * @return Returns the null object if success, returns the null value otherwise */ - static napi_value GetNotificationLocalActivityContentDetailed( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content); + static napi_value GetNotificationLocalLiveViewContentDetailed( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content); /** * @brief Gets a conversational content of NotificationRequest object from specified js object diff --git a/frameworks/js/napi/include/local_activity_subscribe.h b/frameworks/js/napi/include/local_live_view_subscribe.h similarity index 77% rename from frameworks/js/napi/include/local_activity_subscribe.h rename to frameworks/js/napi/include/local_live_view_subscribe.h index 8851058b7..3282bfee6 100644 --- a/frameworks/js/napi/include/local_activity_subscribe.h +++ b/frameworks/js/napi/include/local_live_view_subscribe.h @@ -22,10 +22,10 @@ namespace OHOS { namespace NotificationNapi { using namespace OHOS::Notification; -class LocalActivitySubscriberInstance : public NotificationLocalActivitySubscriber { +class LocalLiveViewSubscriberInstance : public NotificationLocalLiveViewSubscriber { public: - LocalActivitySubscriberInstance(); - virtual ~LocalActivitySubscriberInstance(); + LocalLiveViewSubscriberInstance(); + virtual ~LocalLiveViewSubscriberInstance(); /** * @brief Called back when a notification is canceled. @@ -68,15 +68,15 @@ private: CallbackInfo responseCallbackInfo_; }; -struct LocalActivitySubscriberInstancesInfo { +struct LocalLiveViewSubscriberInstancesInfo { napi_ref ref = nullptr; - LocalActivitySubscriberInstance *subscriber = nullptr; + LocalLiveViewSubscriberInstance *subscriber = nullptr; }; -struct AsyncCallbackInfoSubscribeLocalActivity { +struct AsyncCallbackInfoSubscribeLocalLiveView { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - LocalActivitySubscriberInstance *objectInfo = nullptr; + LocalLiveViewSubscriberInstance *objectInfo = nullptr; NotificationBundleOption bundleOption; NotificationButtonOption buttonOption; int32_t notificationId; @@ -84,22 +84,22 @@ struct AsyncCallbackInfoSubscribeLocalActivity { }; static std::mutex mutex_; -static thread_local std::vector subscriberInstances_; +static thread_local std::vector subscriberInstances_; static std::mutex delMutex_; -static std::vector DeletingSubscriber; +static std::vector DeletingSubscriber; -bool HasNotificationSubscriber(const napi_env &env, const napi_value &value, LocalActivitySubscriberInstancesInfo &subscriberInfo); -bool AddSubscriberInstancesInfo(const napi_env &env, const LocalActivitySubscriberInstancesInfo &subscriberInfo); -bool DelSubscriberInstancesInfo(const napi_env &env, const LocalActivitySubscriberInstance *subscriber); +bool HasNotificationSubscriber(const napi_env &env, const napi_value &value, LocalLiveViewSubscriberInstancesInfo &subscriberInfo); +bool AddSubscriberInstancesInfo(const napi_env &env, const LocalLiveViewSubscriberInstancesInfo &subscriberInfo); +bool DelSubscriberInstancesInfo(const napi_env &env, const LocalLiveViewSubscriberInstance *subscriber); -bool AddDeletingSubscriber(LocalActivitySubscriberInstance *subscriber); -void DelDeletingSubscriber(LocalActivitySubscriberInstance *subscriber); +bool AddDeletingSubscriber(LocalLiveViewSubscriberInstance *subscriber); +void DelDeletingSubscriber(LocalLiveViewSubscriberInstance *subscriber); napi_value Subscribe(napi_env env, napi_callback_info info); napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, - LocalActivitySubscriberInstance *&subscriber, napi_ref &callback); + LocalLiveViewSubscriberInstance *&subscriber, napi_ref &callback); } // namespace NotificationNapi } // namespace OHOS #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_INCLUDE_SUBSCRIBE_H diff --git a/frameworks/js/napi/include/manager/napi_local_activity.h b/frameworks/js/napi/include/manager/napi_local_live_view.h similarity index 82% rename from frameworks/js/napi/include/manager/napi_local_activity.h rename to frameworks/js/napi/include/manager/napi_local_live_view.h index fb027820c..5e11c62b0 100644 --- a/frameworks/js/napi/include/manager/napi_local_activity.h +++ b/frameworks/js/napi/include/manager/napi_local_live_view.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_ACTIVITY_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_ACTIVITY_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_LIVE_VIEW_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_LIVE_VIEW_H #include "common.h" @@ -22,9 +22,9 @@ namespace NotificationNapi { using namespace OHOS::Notification; napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info); -napi_value NapiUnsubscriteLocalActivity(napi_env env, napi_callback_info info); -napi_value NapiTriggerLocalActivity(napi_env env, napi_callback_info info); +napi_value NapiUnsubscriteLocalLiveView(napi_env env, napi_callback_info info); +napi_value NapiTriggerLocalLiveView(napi_env env, napi_callback_info info); } // namespace NotificationNapi } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_ACTIVITY_H +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_JS_NAPI_LOCAL_LIVE_VIEW_H diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index d23398516..c8eb4ffa5 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -1812,8 +1812,8 @@ napi_value Common::GetNotificationContent(const napi_env &env, const napi_value return nullptr; } break; - case NotificationContent::Type::LOCAL_ACTIVITY: - if (GetNotificationLocalActivityContent(env, result, request) == nullptr) { + case NotificationContent::Type::LOCAL_LIVE_VIEW: + if (GetNotificationLocalLiveViewContent(env, result, request) == nullptr) { return nullptr; } break; @@ -3999,7 +3999,7 @@ napi_value Common::GetNotificationMultiLineContentLines(const napi_env &env, con return NapiGetNull(env); } -napi_value Common::GetNotificationLocalActivityContent( +napi_value Common::GetNotificationLocalLiveViewContent( const napi_env &env, const napi_value &result, NotificationRequest &request) { ANS_LOGI("enter"); @@ -4007,35 +4007,35 @@ napi_value Common::GetNotificationLocalActivityContent( napi_valuetype valuetype = napi_undefined; napi_value contentResult = nullptr; bool hasProperty = false; - NAPI_CALL(env, napi_has_named_property(env, result, "localActivity", &hasProperty)); + NAPI_CALL(env, napi_has_named_property(env, result, "localLiveView", &hasProperty)); if (!hasProperty) { - ANS_LOGE("Property localActivity expected."); + ANS_LOGE("Property localLiveView expected."); return nullptr; } - napi_get_named_property(env, result, "localActivity", &contentResult); + napi_get_named_property(env, result, "localLiveView", &contentResult); NAPI_CALL(env, napi_typeof(env, contentResult, &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type. Object expected."); return nullptr; } - std::shared_ptr localActivityContent = std::make_shared(); - if (localActivityContent == nullptr) { - ANS_LOGE("localActivityContent is null"); + std::shared_ptr localLiveViewContent = std::make_shared(); + if (localLiveViewContent == nullptr) { + ANS_LOGE("localLiveViewContent is null"); return nullptr; } - if (GetNotificationLocalActivityContentDetailed(env, contentResult, localActivityContent) == nullptr) { + if (GetNotificationLocalLiveViewContentDetailed(env, contentResult, localLiveViewContent) == nullptr) { return nullptr; } - request.SetContent(std::make_shared(localActivityContent)); + request.SetContent(std::make_shared(localLiveViewContent)); return NapiGetNull(env); } -napi_value Common::GetNotificationLocalActivityCapsule( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content) +napi_value Common::GetNotificationLocalLiveViewCapsule( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content) { napi_value capsuleResult = nullptr; napi_valuetype valuetype = napi_undefined; @@ -4106,8 +4106,8 @@ napi_value Common::GetNotificationLocalActivityCapsule( return NapiGetNull(env); } -napi_value Common::GetNotificationLocalActivityButton( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content) +napi_value Common::GetNotificationLocalLiveViewButton( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content) { napi_value result = nullptr; napi_valuetype valuetype = napi_undefined; @@ -4127,7 +4127,7 @@ napi_value Common::GetNotificationLocalActivityButton( return nullptr; } - NotificationLocalActivityButton button; + NotificationLocalLiveViewButton button; NAPI_CALL(env, napi_has_named_property(env, buttonResult, "buttonNames", &hasProperty)); if (hasProperty) { @@ -4183,8 +4183,8 @@ napi_value Common::GetNotificationLocalActivityButton( return NapiGetNull(env); } -napi_value Common::GetNotificationLocalActivityProgress(const napi_env &env, - const napi_value &contentResult, std::shared_ptr content) +napi_value Common::GetNotificationLocalLiveViewProgress(const napi_env &env, + const napi_value &contentResult, std::shared_ptr content) { napi_value result = nullptr; napi_valuetype valuetype = napi_undefined; @@ -4246,8 +4246,8 @@ napi_value Common::GetNotificationLocalActivityProgress(const napi_env &env, return NapiGetNull(env); } -napi_value Common::GetNotificationLocalActivityContentDetailed( - const napi_env &env, const napi_value &contentResult, std::shared_ptr content) +napi_value Common::GetNotificationLocalLiveViewContentDetailed( + const napi_env &env, const napi_value &contentResult, std::shared_ptr content) { bool hasProperty = false; int32_t type = -1; @@ -4276,24 +4276,24 @@ napi_value Common::GetNotificationLocalActivityContentDetailed( } napi_get_value_int32(env, result, &type); content->SetType(type); - ANS_LOGD("localActivity type = %{public}d", type); + ANS_LOGD("localLiveView type = %{public}d", type); //capsule? NAPI_CALL(env, napi_has_named_property(env, contentResult, "capsule", &hasProperty)); - if (hasProperty && GetNotificationLocalActivityCapsule(env, contentResult, content) == nullptr) { + if (hasProperty && GetNotificationLocalLiveViewCapsule(env, contentResult, content) == nullptr) { return nullptr; } //button? NAPI_CALL(env, napi_has_named_property(env, contentResult, "button", &hasProperty)); - if (hasProperty && GetNotificationLocalActivityButton(env, contentResult, content) == nullptr) { + if (hasProperty && GetNotificationLocalLiveViewButton(env, contentResult, content) == nullptr) { return nullptr; } //progess? NAPI_CALL(env, napi_has_named_property(env, contentResult, "progress", &hasProperty)); - if (hasProperty && GetNotificationLocalActivityProgress(env, contentResult, content) == nullptr) { + if (hasProperty && GetNotificationLocalLiveViewProgress(env, contentResult, content) == nullptr) { return nullptr; } @@ -4717,8 +4717,8 @@ bool Common::ContentTypeJSToC(const ContentType &inType, NotificationContent::Ty case ContentType::NOTIFICATION_CONTENT_CONVERSATION: outType = NotificationContent::Type::CONVERSATION; break; - case ContentType::NOTIFICATION_CONTENT_LOCAL_ACTIVITY: - outType = NotificationContent::Type::LOCAL_ACTIVITY; + case ContentType::NOTIFICATION_CONTENT_LOCAL_LIVE_VIEW: + outType = NotificationContent::Type::LOCAL_LIVE_VIEW; break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); @@ -4745,8 +4745,8 @@ bool Common::ContentTypeCToJS(const NotificationContent::Type &inType, ContentTy case NotificationContent::Type::CONVERSATION: outType = ContentType::NOTIFICATION_CONTENT_CONVERSATION; break; - case NotificationContent::Type::LOCAL_ACTIVITY: - outType = ContentType::NOTIFICATION_CONTENT_LOCAL_ACTIVITY; + case NotificationContent::Type::LOCAL_LIVE_VIEW: + outType = ContentType::NOTIFICATION_CONTENT_LOCAL_LIVE_VIEW; break; default: ANS_LOGE("ContentType %{public}d is an invalid value", inType); diff --git a/frameworks/js/napi/src/manager/BUILD.gn b/frameworks/js/napi/src/manager/BUILD.gn index 0e2695545..b046c12e6 100644 --- a/frameworks/js/napi/src/manager/BUILD.gn +++ b/frameworks/js/napi/src/manager/BUILD.gn @@ -72,8 +72,8 @@ ohos_shared_library("notificationmanager") { "napi_remove_group.cpp", "napi_slot.cpp", "napi_template.cpp", - "napi_local_activity.cpp", - "local_activity_subscribe.cpp", + "napi_local_live_view.cpp", + "local_live_view_subscribe.cpp", ] deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] diff --git a/frameworks/js/napi/src/manager/init_module.cpp b/frameworks/js/napi/src/manager/init_module.cpp index 67388cba8..1c0cc8e0f 100644 --- a/frameworks/js/napi/src/manager/init_module.cpp +++ b/frameworks/js/napi/src/manager/init_module.cpp @@ -30,7 +30,7 @@ #include "napi_template.h" #include "pixel_map_napi.h" #include "napi_push.h" -#include "napi_local_activity.h" +#include "napi_local_live_view.h" namespace OHOS { namespace NotificationNapi { @@ -103,7 +103,7 @@ napi_value NotificationManagerInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("setSyncNotificationEnabledWithoutApp", NapiSetSyncNotificationEnabledWithoutApp), DECLARE_NAPI_FUNCTION("getSyncNotificationEnabledWithoutApp", NapiGetSyncNotificationEnabledWithoutApp), DECLARE_NAPI_FUNCTION("subscribeLocalLiveView", NapiSubscriteLocalAcitvity), - DECLARE_NAPI_FUNCTION("trigger", NapiTriggerLocalActivity), + DECLARE_NAPI_FUNCTION("trigger", NapiTriggerLocalLiveView), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); diff --git a/frameworks/js/napi/src/manager/local_activity_subscribe.cpp b/frameworks/js/napi/src/manager/local_live_view_subscribe.cpp similarity index 86% rename from frameworks/js/napi/src/manager/local_activity_subscribe.cpp rename to frameworks/js/napi/src/manager/local_live_view_subscribe.cpp index 68eb9d834..156fc0ca5 100644 --- a/frameworks/js/napi/src/manager/local_activity_subscribe.cpp +++ b/frameworks/js/napi/src/manager/local_live_view_subscribe.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "local_activity_subscribe.h" +#include "local_live_view_subscribe.h" #include "notification_button_option.h" #include @@ -24,35 +24,35 @@ namespace NotificationNapi { const int32_t SUBSRIBE_MAX_PARA = 2; const std::string RESPONSE = "onResponse"; -struct LocalActivityReceiveDataWorker { +struct LocalLiveViewReceiveDataWorker { napi_env env = nullptr; napi_ref ref = nullptr; int32_t notificationId; sptr buttonOption; - LocalActivitySubscriberInstance *subscriber = nullptr; + LocalLiveViewSubscriberInstance *subscriber = nullptr; }; -LocalActivitySubscriberInstance::LocalActivitySubscriberInstance() +LocalLiveViewSubscriberInstance::LocalLiveViewSubscriberInstance() {} -LocalActivitySubscriberInstance::~LocalActivitySubscriberInstance() +LocalLiveViewSubscriberInstance::~LocalLiveViewSubscriberInstance() { if (responseCallbackInfo_.ref != nullptr) { napi_delete_reference(responseCallbackInfo_.env, responseCallbackInfo_.ref); } } -void LocalActivitySubscriberInstance::OnDied() +void LocalLiveViewSubscriberInstance::OnDied() { ANS_LOGI("enter"); } -void LocalActivitySubscriberInstance::OnConnected() +void LocalLiveViewSubscriberInstance::OnConnected() { ANS_LOGI("enter"); } -void LocalActivitySubscriberInstance::OnDisconnected() +void LocalLiveViewSubscriberInstance::OnDisconnected() { ANS_LOGI("enter"); } @@ -66,7 +66,7 @@ void UvQueueWorkOnResponse(uv_work_t *work, int status) return; } - auto dataWorkerData = reinterpret_cast(work->data); + auto dataWorkerData = reinterpret_cast(work->data); if (dataWorkerData == nullptr) { ANS_LOGD("dataWorkerData is null."); delete work; @@ -95,7 +95,7 @@ void UvQueueWorkOnResponse(uv_work_t *work, int status) delete work; } -void LocalActivitySubscriberInstance::OnResponse(int32_t notificationId, sptr buttonOption) +void LocalLiveViewSubscriberInstance::OnResponse(int32_t notificationId, sptr buttonOption) { ANS_LOGI("enter"); @@ -119,7 +119,7 @@ void LocalActivitySubscriberInstance::OnResponse(int32_t notificationId, sptr lock(mutex_); for (auto vec : subscriberInstances_) { @@ -182,14 +182,14 @@ bool HasNotificationSubscriber(const napi_env &env, const napi_value &value, Loc } napi_value GetNotificationSubscriber( - const napi_env &env, const napi_value &value, LocalActivitySubscriberInstancesInfo &subscriberInfo) + const napi_env &env, const napi_value &value, LocalLiveViewSubscriberInstancesInfo &subscriberInfo) { ANS_LOGI("enter"); bool hasProperty = false; napi_valuetype valuetype = napi_undefined; napi_ref result = nullptr; - subscriberInfo.subscriber = new (std::nothrow) LocalActivitySubscriberInstance(); + subscriberInfo.subscriber = new (std::nothrow) LocalLiveViewSubscriberInstance(); if (subscriberInfo.subscriber == nullptr) { ANS_LOGE("subscriber is null"); return nullptr; @@ -214,7 +214,7 @@ napi_value GetNotificationSubscriber( return Common::NapiGetNull(env); } -bool AddSubscriberInstancesInfo(const napi_env &env, const LocalActivitySubscriberInstancesInfo &subscriberInfo) +bool AddSubscriberInstancesInfo(const napi_env &env, const LocalLiveViewSubscriberInstancesInfo &subscriberInfo) { ANS_LOGI("enter"); if (subscriberInfo.ref == nullptr) { @@ -231,7 +231,7 @@ bool AddSubscriberInstancesInfo(const napi_env &env, const LocalActivitySubscrib return true; } -bool DelSubscriberInstancesInfo(const napi_env &env, const LocalActivitySubscriberInstance *subscriber) +bool DelSubscriberInstancesInfo(const napi_env &env, const LocalLiveViewSubscriberInstance *subscriber) { ANS_LOGI("enter"); if (subscriber == nullptr) { @@ -255,7 +255,7 @@ bool DelSubscriberInstancesInfo(const napi_env &env, const LocalActivitySubscrib return false; } napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, - LocalActivitySubscriberInstance *&subscriber, napi_ref &callback) + LocalLiveViewSubscriberInstance *&subscriber, napi_ref &callback) { ANS_LOGI("enter"); @@ -270,17 +270,17 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_valuetype valuetype = napi_undefined; - // argv[0]:LocalActivityButton + // argv[0]:LocalLiveViewButton NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { - ANS_LOGE("Wrong argument type for arg0. LocalActivityButton object expected."); + ANS_LOGE("Wrong argument type for arg0. LocalLiveViewButton object expected."); return nullptr; } - LocalActivitySubscriberInstancesInfo subscriberInstancesInfo; + LocalLiveViewSubscriberInstancesInfo subscriberInstancesInfo; if (!HasNotificationSubscriber(env, argv[PARAM0], subscriberInstancesInfo)) { if (GetNotificationSubscriber(env, argv[PARAM0], subscriberInstancesInfo) == nullptr) { - ANS_LOGE("LocalActivityButton parse failed"); + ANS_LOGE("LocalLiveViewButton parse failed"); if (subscriberInstancesInfo.subscriber) { delete subscriberInstancesInfo.subscriber; subscriberInstancesInfo.subscriber = nullptr; @@ -311,7 +311,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, return Common::NapiGetNull(env); } -bool AddDeletingSubscriber(LocalActivitySubscriberInstance *subscriber) +bool AddDeletingSubscriber(LocalLiveViewSubscriberInstance *subscriber) { std::lock_guard lock(delMutex_); auto iter = std::find(DeletingSubscriber.begin(), DeletingSubscriber.end(), subscriber); @@ -323,7 +323,7 @@ bool AddDeletingSubscriber(LocalActivitySubscriberInstance *subscriber) return true; } -void DelDeletingSubscriber(LocalActivitySubscriberInstance *subscriber) +void DelDeletingSubscriber(LocalLiveViewSubscriberInstance *subscriber) { std::lock_guard lock(delMutex_); auto iter = std::find(DeletingSubscriber.begin(), DeletingSubscriber.end(), subscriber); diff --git a/frameworks/js/napi/src/manager/napi_local_activity.cpp b/frameworks/js/napi/src/manager/napi_local_live_view.cpp similarity index 80% rename from frameworks/js/napi/src/manager/napi_local_activity.cpp rename to frameworks/js/napi/src/manager/napi_local_live_view.cpp index a7b1351a7..7110e2c47 100644 --- a/frameworks/js/napi/src/manager/napi_local_activity.cpp +++ b/frameworks/js/napi/src/manager/napi_local_live_view.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ - #include "napi_local_activity.h" - #include "local_activity_subscribe.h" + #include "napi_local_live_view.h" + #include "local_live_view_subscribe.h" #include "ans_inner_errors.h" #include "common.h" @@ -27,7 +27,7 @@ napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); napi_ref callback = nullptr; - LocalActivitySubscriberInstance *objectInfo = nullptr; + LocalLiveViewSubscriberInstance *objectInfo = nullptr; if (ParseParameters(env, info, objectInfo, callback) == nullptr) { if (objectInfo) { delete objectInfo; @@ -37,7 +37,7 @@ napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info) return Common::NapiGetUndefined(env); } - AsyncCallbackInfoSubscribeLocalActivity *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoSubscribeLocalActivity { + AsyncCallbackInfoSubscribeLocalLiveView *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoSubscribeLocalLiveView { .env = env, .asyncWork = nullptr, .objectInfo = objectInfo }; if (!asynccallbackinfo) { @@ -51,41 +51,41 @@ napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info) Common::PaddingCallbackPromiseInfo(env, callback, asynccallbackinfo->info, promise); napi_value resourceName = nullptr; - napi_create_string_latin1(env, "subscribeLocalActivityNotification", NAPI_AUTO_LENGTH, &resourceName); + napi_create_string_latin1(env, "subscribeLocalLiveViewNotification", NAPI_AUTO_LENGTH, &resourceName); // Asynchronous function call napi_create_async_work(env, nullptr, resourceName, [](napi_env env, void *data) { - ANS_LOGI("NapiSubscribeLocalActivity work excute."); + ANS_LOGI("NapiSubscribeLocalLiveView work excute."); if (!data) { ANS_LOGE("Invalid asynccallbackinfo!"); return; } - auto asynccallbackinfo = reinterpret_cast(data); + auto asynccallbackinfo = reinterpret_cast(data); asynccallbackinfo->info.errorCode = - NotificationHelper::SubscribeLocalActivityNotification(*(asynccallbackinfo->objectInfo)); + NotificationHelper::SubscribeLocalLiveViewNotification(*(asynccallbackinfo->objectInfo)); }, [](napi_env env, napi_status status, void *data) { - ANS_LOGI("NapiSubscribeLocalActivity work complete."); + ANS_LOGI("NapiSubscribeLocalLiveView work complete."); if (!data) { ANS_LOGE("Invalid asynccallbackinfo!"); return; } - auto asynccallbackinfo = reinterpret_cast(data); + auto asynccallbackinfo = reinterpret_cast(data); if (asynccallbackinfo) { Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); if (asynccallbackinfo->info.callback != nullptr) { - ANS_LOGD("Delete napiSubscribeLocalActivity callback reference."); + ANS_LOGD("Delete napiSubscribeLocalLiveView callback reference."); napi_delete_reference(env, asynccallbackinfo->info.callback); } napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } - ANS_LOGD("NapiSubscribeLocalActivity work complete end."); + ANS_LOGD("NapiSubscribeLocalLiveView work complete end."); }, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); @@ -93,11 +93,11 @@ napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info) bool isCallback = asynccallbackinfo->info.isCallback; napi_status status = napi_queue_async_work_with_qos(env, asynccallbackinfo->asyncWork, napi_qos_user_initiated); if (status != napi_ok) { - ANS_LOGE("Queue napiSubscribeLocalActivity work failed return: %{public}d", status); + ANS_LOGE("Queue napiSubscribeLocalLiveView work failed return: %{public}d", status); asynccallbackinfo->info.errorCode = ERROR_INTERNAL_ERROR; Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); if (asynccallbackinfo->info.callback != nullptr) { - ANS_LOGD("Delete napiSubscribeLocalActivity callback reference."); + ANS_LOGD("Delete napiSubscribeLocalLiveView callback reference."); napi_delete_reference(env, asynccallbackinfo->info.callback); } napi_delete_async_work(env, asynccallbackinfo->asyncWork); @@ -106,20 +106,20 @@ napi_value NapiSubscriteLocalAcitvity(napi_env env, napi_callback_info info) } if (isCallback) { - ANS_LOGD("napiSubscribeLocalActivity callback is nullptr."); + ANS_LOGD("napiSubscribeLocalLiveView callback is nullptr."); return Common::NapiGetNull(env); } else { return promise; } } -napi_value NapiUnsubscriteLocalActivity(napi_env env, napi_callback_info info) +napi_value NapiUnsubscriteLocalLiveView(napi_env env, napi_callback_info info) { return nullptr; } napi_value ParseTriggerParameters(const napi_env &env, const napi_callback_info &info, - AsyncCallbackInfoSubscribeLocalActivity *asynccallbackinfo, napi_ref &callback) + AsyncCallbackInfoSubscribeLocalLiveView *asynccallbackinfo, napi_ref &callback) { ANS_LOGI("enter"); @@ -163,12 +163,12 @@ napi_value ParseTriggerParameters(const napi_env &env, const napi_callback_info return Common::NapiGetNull(env); } -napi_value NapiTriggerLocalActivity(napi_env env, napi_callback_info info) +napi_value NapiTriggerLocalLiveView(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); napi_ref callback = nullptr; - AsyncCallbackInfoSubscribeLocalActivity *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoSubscribeLocalActivity { + AsyncCallbackInfoSubscribeLocalLiveView *asynccallbackinfo = new (std::nothrow) AsyncCallbackInfoSubscribeLocalLiveView { .env = env, .asyncWork = nullptr, }; if (!asynccallbackinfo) { @@ -184,42 +184,42 @@ napi_value NapiTriggerLocalActivity(napi_env env, napi_callback_info info) Common::PaddingCallbackPromiseInfo(env, callback, asynccallbackinfo->info, promise); napi_value resourceName = nullptr; - napi_create_string_latin1(env, "triggerLocalActivity", NAPI_AUTO_LENGTH, &resourceName); + napi_create_string_latin1(env, "triggerLocalLiveView", NAPI_AUTO_LENGTH, &resourceName); // Asynchronous function call napi_create_async_work(env, nullptr, resourceName, [](napi_env env, void *data) { - ANS_LOGI("NapiTriggerLocalActivity work excute."); + ANS_LOGI("NapiTriggerLocalLiveView work excute."); if (!data) { ANS_LOGE("Invalid asynccallbackinfo!"); return; } - auto asynccallbackinfo = reinterpret_cast(data); + auto asynccallbackinfo = reinterpret_cast(data); asynccallbackinfo->info.errorCode = - NotificationHelper::TriggerLocalActivity(asynccallbackinfo->bundleOption, + NotificationHelper::TriggerLocalLiveView(asynccallbackinfo->bundleOption, asynccallbackinfo->notificationId, asynccallbackinfo->buttonOption); }, [](napi_env env, napi_status status, void *data) { - ANS_LOGI("NapiSubscribeLocalActivity work complete."); + ANS_LOGI("NapiSubscribeLocalLiveView work complete."); if (!data) { ANS_LOGE("Invalid asynccallbackinfo!"); return; } - auto asynccallbackinfo = reinterpret_cast(data); + auto asynccallbackinfo = reinterpret_cast(data); if (asynccallbackinfo) { Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); if (asynccallbackinfo->info.callback != nullptr) { - ANS_LOGD("Delete napiSubscribeLocalActivity callback reference."); + ANS_LOGD("Delete napiSubscribeLocalLiveView callback reference."); napi_delete_reference(env, asynccallbackinfo->info.callback); } napi_delete_async_work(env, asynccallbackinfo->asyncWork); delete asynccallbackinfo; asynccallbackinfo = nullptr; } - ANS_LOGD("NapiSubscribeLocalActivity work complete end."); + ANS_LOGD("NapiSubscribeLocalLiveView work complete end."); }, (void *)asynccallbackinfo, &asynccallbackinfo->asyncWork); @@ -227,11 +227,11 @@ napi_value NapiTriggerLocalActivity(napi_env env, napi_callback_info info) bool isCallback = asynccallbackinfo->info.isCallback; napi_status status = napi_queue_async_work_with_qos(env, asynccallbackinfo->asyncWork, napi_qos_user_initiated); if (status != napi_ok) { - ANS_LOGE("Queue napiSubscribeLocalActivity work failed return: %{public}d", status); + ANS_LOGE("Queue napiSubscribeLocalLiveView work failed return: %{public}d", status); asynccallbackinfo->info.errorCode = ERROR_INTERNAL_ERROR; Common::CreateReturnValue(env, asynccallbackinfo->info, Common::NapiGetNull(env)); if (asynccallbackinfo->info.callback != nullptr) { - ANS_LOGD("Delete napiSubscribeLocalActivity callback reference."); + ANS_LOGD("Delete napiSubscribeLocalLiveView callback reference."); napi_delete_reference(env, asynccallbackinfo->info.callback); } napi_delete_async_work(env, asynccallbackinfo->asyncWork); @@ -240,7 +240,7 @@ napi_value NapiTriggerLocalActivity(napi_env env, napi_callback_info info) } if (isCallback) { - ANS_LOGD("napiSubscribeLocalActivity callback is nullptr."); + ANS_LOGD("napiSubscribeLocalLiveView callback is nullptr."); return Common::NapiGetNull(env); } else { return promise; diff --git a/interfaces/inner_api/notification_content.h b/interfaces/inner_api/notification_content.h index d66e67cbb..fb44a421d 100644 --- a/interfaces/inner_api/notification_content.h +++ b/interfaces/inner_api/notification_content.h @@ -24,7 +24,7 @@ #include "notification_multiline_content.h" #include "notification_normal_content.h" #include "notification_picture_content.h" -#include "notification_local_activity_content.h" +#include "notification_local_live_view_content.h" #include "parcel.h" namespace OHOS { @@ -67,9 +67,9 @@ public: PICTURE, /** * Indicates notifications that include system activity. - * Such notifications are created using NotificationLocalActivityContent. + * Such notifications are created using NotificationLocalLiveViewContent. */ - LOCAL_ACTIVITY + LOCAL_LIVE_VIEW }; /** @@ -127,13 +127,13 @@ public: explicit NotificationContent(const std::shared_ptr &mediaContent); /** - * @brief A constructor used to create a NotificationLocalActivityContent instance (obtained by calling - * GetNotificationContent()) and set the content type to NotificationContent::Type::LOCAL_ACTIVITY (obtained by calling + * @brief A constructor used to create a NotificationLocalLiveViewContent instance (obtained by calling + * GetNotificationContent()) and set the content type to NotificationContent::Type::LOCAL_LIVE_VIEW (obtained by calling * GetContentType()). * - * @param mediaContent Indicates the NotificationLocalActivityContent object. + * @param mediaContent Indicates the NotificationLocalLiveViewContent object. */ - explicit NotificationContent(const std::shared_ptr &localActivityContent); + explicit NotificationContent(const std::shared_ptr &localLiveViewContent); virtual ~NotificationContent(); diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index c5f19ea77..b0b119b20 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -24,7 +24,7 @@ #include "notification_slot.h" #include "notification_sorting_map.h" #include "notification_subscriber.h" -#include "notification_local_activity_subscriber.h" +#include "notification_local_live_view_subscriber.h" namespace OHOS { namespace Notification { @@ -322,9 +322,9 @@ public: const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo); /** - * @brief Subscribes the localActivity button click. This method can be called only + * @brief Subscribes the localLiveView button click. This method can be called only * by applications with required system permissions. - * @note To subscribe to a button click, inherit the {NotificationLocalActivitySubscriber} class, override its + * @note To subscribe to a button click, inherit the {NotificationLocalLiveViewSubscriber} class, override its * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. * After the button is clicked, subscribers that meet the filter criteria can receive the response * @@ -332,7 +332,7 @@ public: * For details, see {NotificationSubscriber}. * @return Returns subscribe notification result. */ - static ErrCode SubscribeLocalActivityNotification(const NotificationLocalActivitySubscriber &subscriber); + static ErrCode SubscribeLocalLiveViewNotification(const NotificationLocalLiveViewSubscriber &subscriber); /** * @brief Unsubscribes from all notifications. This method can be called only by applications with required @@ -371,9 +371,9 @@ public: * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. * @param notificationId Indicates the id of the notification. * @param buttonOption Indicates which button has been clicked. - * @return Returns trigger localActivity result. + * @return Returns trigger localLiveView result. */ - static ErrCode TriggerLocalActivity(const NotificationBundleOption &bundleOption, + static ErrCode TriggerLocalLiveView(const NotificationBundleOption &bundleOption, const int32_t notificationId, const NotificationButtonOption &buttonOption); /** diff --git a/interfaces/inner_api/notification_local_activity_button.h b/interfaces/inner_api/notification_local_live_view_button.h similarity index 88% rename from interfaces/inner_api/notification_local_activity_button.h rename to interfaces/inner_api/notification_local_live_view_button.h index 36457f209..bbf5ad889 100644 --- a/interfaces/inner_api/notification_local_activity_button.h +++ b/interfaces/inner_api/notification_local_live_view_button.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_ACTIVITY_BUTTON_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_ACTIVITY_BUTTON_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_BUTTON_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_BUTTON_H #include "base/notification/distributed_notification_service/interfaces/inner_api/notification_button_option.h" #include "foundation/multimedia/image_framework/interfaces/innerkits/include/pixel_map.h" @@ -26,10 +26,10 @@ namespace OHOS { namespace Notification { -class NotificationLocalActivityButton : public Parcelable, public NotificationJsonConvertionBase { +class NotificationLocalLiveViewButton : public Parcelable, public NotificationJsonConvertionBase { public: - NotificationLocalActivityButton() = default; - ~NotificationLocalActivityButton() = default; + NotificationLocalLiveViewButton() = default; + ~NotificationLocalLiveViewButton() = default; /** * @brief Obtains the text to be displayed as the content of this message. @@ -71,7 +71,7 @@ public: * @param jsonObject Indicates the Json object. * @return Returns the NotificationConversationalMessage. */ - static NotificationLocalActivityButton *FromJson(const nlohmann::json &jsonObject); + static NotificationLocalLiveViewButton *FromJson(const nlohmann::json &jsonObject); /** * @brief Marshal a object into a Parcel. @@ -87,7 +87,7 @@ public: * @param parcel Indicates the parcel object. * @return Returns the NotificationConversationalMessage. */ - static NotificationLocalActivityButton *Unmarshalling(Parcel &parcel); + static NotificationLocalLiveViewButton *Unmarshalling(Parcel &parcel); private: /** @@ -104,4 +104,4 @@ private: } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_ACTIVITY_BUTTON_H \ No newline at end of file +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_BUTTON_H \ No newline at end of file diff --git a/interfaces/inner_api/notification_local_activity_content.h b/interfaces/inner_api/notification_local_live_view_content.h similarity index 87% rename from interfaces/inner_api/notification_local_activity_content.h rename to interfaces/inner_api/notification_local_live_view_content.h index b8c0b1243..566f36303 100644 --- a/interfaces/inner_api/notification_local_activity_content.h +++ b/interfaces/inner_api/notification_local_live_view_content.h @@ -13,12 +13,12 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_ACTIVITY_CONTENT_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_ACTIVITY_CONTENT_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_CONTENT_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_CONTENT_H #include "base/notification/distributed_notification_service/interfaces/inner_api/notification_capsule.h" #include "base/notification/distributed_notification_service/interfaces/inner_api/notification_progress.h" -#include "base/notification/distributed_notification_service/interfaces/inner_api/notification_local_activity_button.h" +#include "base/notification/distributed_notification_service/interfaces/inner_api/notification_local_live_view_button.h" #include "message_user.h" #include "notification_basic_content.h" #include "notification_conversational_message.h" @@ -27,10 +27,10 @@ namespace OHOS { namespace Notification { -class NotificationLocalActivityContent : public NotificationBasicContent { +class NotificationLocalLiveViewContent : public NotificationBasicContent { public: - NotificationLocalActivityContent() = default; - ~NotificationLocalActivityContent() = default; + NotificationLocalLiveViewContent() = default; + ~NotificationLocalLiveViewContent() = default; /* * @brief Sets the type to be included in a local activity notification. @@ -51,7 +51,7 @@ public: * * @param button Indicates the type to be included. */ - void SetButton(NotificationLocalActivityButton button); + void SetButton(NotificationLocalLiveViewButton button); /* * @brief Sets the progress to be included in a local activity notification. @@ -83,7 +83,7 @@ public: * @param jsonObject Indicates the Json object. * @return Returns the NotificationConversationalContent. */ - static NotificationLocalActivityContent *FromJson(const nlohmann::json &jsonObject); + static NotificationLocalLiveViewContent *FromJson(const nlohmann::json &jsonObject); /** * @brief Marshal a object into a Parcel. @@ -99,7 +99,7 @@ public: * @param parcel Indicates the parcel object. * @return Returns the NotificationConversationalContent. */ - static NotificationLocalActivityContent *Unmarshalling(Parcel &parcel); + static NotificationLocalLiveViewContent *Unmarshalling(Parcel &parcel); protected: /** @@ -114,7 +114,7 @@ private: int32_t type_ {0}; NotificationCapsule capsule_ {}; - NotificationLocalActivityButton button_ {}; + NotificationLocalLiveViewButton button_ {}; NotificationProgress progress_ {}; }; } // namespace Notification diff --git a/interfaces/inner_api/notification_local_activity_subscriber.h b/interfaces/inner_api/notification_local_live_view_subscriber.h similarity index 73% rename from interfaces/inner_api/notification_local_activity_subscriber.h rename to interfaces/inner_api/notification_local_live_view_subscriber.h index 44942e9a5..900b3eff8 100644 --- a/interfaces/inner_api/notification_local_activity_subscriber.h +++ b/interfaces/inner_api/notification_local_live_view_subscriber.h @@ -13,23 +13,23 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_H #include "ans_manager_interface.h" #include "ans_subscriber_stub.h" -#include "ans_subscriber_local_activity_stub.h" +#include "ans_subscriber_local_live_view_stub.h" #include "notification_request.h" #include "notification_sorting.h" #include "notification_sorting_map.h" namespace OHOS { namespace Notification { -class NotificationLocalActivitySubscriber { +class NotificationLocalLiveViewSubscriber { public: - NotificationLocalActivitySubscriber(); + NotificationLocalLiveViewSubscriber(); - virtual ~NotificationLocalActivitySubscriber(); + virtual ~NotificationLocalLiveViewSubscriber(); /** * @brief Called back when the subscriber is connected to the Advanced Notification Service (ANS). @@ -49,23 +49,23 @@ public: virtual void OnDied() = 0; private: - class SubscriberLocalActivityImpl final : public AnsSubscriberLocalActivityStub { + class SubscriberLocalLiveViewImpl final : public AnsSubscriberLocalLiveViewStub { public: class DeathRecipient final : public IRemoteObject::DeathRecipient { public: - DeathRecipient(SubscriberLocalActivityImpl &subscriberImpl); + DeathRecipient(SubscriberLocalLiveViewImpl &subscriberImpl); ~DeathRecipient(); void OnRemoteDied(const wptr &object) override; private: - SubscriberLocalActivityImpl &subscriberImpl_; + SubscriberLocalLiveViewImpl &subscriberImpl_; }; public: - SubscriberLocalActivityImpl(NotificationLocalActivitySubscriber &subscriber); - ~SubscriberLocalActivityImpl() {}; + SubscriberLocalLiveViewImpl(NotificationLocalLiveViewSubscriber &subscriber); + ~SubscriberLocalLiveViewImpl() {}; void OnConnected() override; @@ -76,21 +76,21 @@ private: bool GetAnsManagerProxy(); public: - NotificationLocalActivitySubscriber &subscriber_; + NotificationLocalLiveViewSubscriber &subscriber_; sptr recipient_ {nullptr}; sptr proxy_ {nullptr}; std::mutex mutex_ {}; }; private: - const sptr GetImpl() const; + const sptr GetImpl() const; private: - sptr impl_ = nullptr; + sptr impl_ = nullptr; friend class AnsNotification; }; } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_H \ No newline at end of file +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_H \ No newline at end of file diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index e7b654248..5b944341b 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -50,7 +50,7 @@ ohos_shared_library("libans") { "src/bundle_manager_helper.cpp", "src/event_report.cpp", "src/notification_dialog.cpp", - "src/notification_local_activity_subscriber_manager.cpp", + "src/notification_local_live_view_subscriber_manager.cpp", "src/notification_preferences.cpp", "src/notification_preferences_database.cpp", "src/notification_preferences_info.cpp", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 429792375..b91f28598 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -270,9 +270,9 @@ public: * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked. * @param notificationId Indicates the id of the notification. * @param buttonOption Indicates which button has been clicked. - * @return Returns trigger localActivity result. + * @return Returns trigger localLiveView result. */ - ErrCode TriggerLocalActivity(const sptr &bundleOption, + ErrCode TriggerLocalLiveView(const sptr &bundleOption, const int32_t notificationId, const sptr &buttonOption) override; /** @@ -420,7 +420,7 @@ public: * @param info Indicates the NotificationSubscribeInfo object. * @return Returns ERR_OK on success, others on failure. */ - ErrCode SubscribeLocalActivity(const sptr &subscriber, + ErrCode SubscribeLocalLiveView(const sptr &subscriber, const sptr &info) override; /** diff --git a/services/ans/include/notification_local_activity_subscriber_manager.h b/services/ans/include/notification_local_live_view_subscriber_manager.h similarity index 70% rename from services/ans/include/notification_local_activity_subscriber_manager.h rename to services/ans/include/notification_local_live_view_subscriber_manager.h index 45069a1d2..7b95916eb 100644 --- a/services/ans/include/notification_local_activity_subscriber_manager.h +++ b/services/ans/include/notification_local_live_view_subscriber_manager.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_LOCAL_ACTIVITY_MANAGER_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_LOCAL_ACTIVITY_MANAGER_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_LOCAL_LIVE_VIEW_MANAGER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_LOCAL_LIVE_VIEW_MANAGER_H #include #include @@ -28,7 +28,7 @@ #include "refbase.h" #include "singleton.h" -#include "ans_subscriber_local_activity_interface.h" +#include "ans_subscriber_local_live_view_interface.h" #include "notification_bundle_option.h" #include "notification_constant.h" #include "notification_request.h" @@ -37,7 +37,7 @@ namespace OHOS { namespace Notification { -class NotificationLocalActivitySubscriberManager : public DelayedSingleton { +class NotificationLocalLiveViewSubscriberManager : public DelayedSingleton { public: /** * @brief Add a subscriber. @@ -46,7 +46,7 @@ public: * @param subscribeInfo Indicates the NotificationSubscribeInfo object. * @return Indicates the result code. */ - ErrCode AddLocalActivitySubscriber(const sptr &subscriber, + ErrCode AddLocalLiveViewSubscriber(const sptr &subscriber, const sptr &subscribeInfo); /** @@ -56,8 +56,8 @@ public: * @param subscribeInfo Indicates the NotificationSubscribeInfo object. * @return Indicates the result code. */ - ErrCode RemoveLocalActivitySubscriber( - const sptr &subscriber, const sptr &subscribeInfo); + ErrCode RemoveLocalLiveViewSubscriber( + const sptr &subscriber, const sptr &subscribeInfo); /** @@ -81,32 +81,32 @@ public: void ResetFfrtQueue(); private: - struct LocalActivitySubscriberRecord; + struct LocalLiveViewSubscriberRecord; - std::shared_ptr FindSubscriberRecord(const wptr &object); - std::shared_ptr FindSubscriberRecord(const sptr &subscriber); - std::shared_ptr CreateSubscriberRecord(const sptr &subscriber, const sptr &bundleOption); + std::shared_ptr FindSubscriberRecord(const wptr &object); + std::shared_ptr FindSubscriberRecord(const sptr &subscriber); + std::shared_ptr CreateSubscriberRecord(const sptr &subscriber, const sptr &bundleOption); ErrCode AddSubscriberInner( - const sptr &subscriber, const sptr &bundleOption); + const sptr &subscriber, const sptr &bundleOption); ErrCode RemoveSubscriberInner( - const sptr &subscriber, const sptr &subscribeInfo); + const sptr &subscriber, const sptr &subscribeInfo); void NotifyTriggerResponseInner(const sptr ¬ification, sptr buttonOption); bool IsSystemUser(int32_t userId); private: - std::list> buttonRecordList_ {}; + std::list> buttonRecordList_ {}; std::shared_ptr runner_ {}; std::shared_ptr handler_ {}; - sptr ansSubscriberProxy_ {}; + sptr ansSubscriberProxy_ {}; sptr recipient_ {}; std::shared_ptr notificationButtonQueue_ = nullptr; - DECLARE_DELAYED_SINGLETON(NotificationLocalActivitySubscriberManager); - DISALLOW_COPY_AND_MOVE(NotificationLocalActivitySubscriberManager); + DECLARE_DELAYED_SINGLETON(NotificationLocalLiveViewSubscriberManager); + DISALLOW_COPY_AND_MOVE(NotificationLocalLiveViewSubscriberManager); }; } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_ACTIVITY_SUBSCRIBER_LOCAL_ACTIVITY_MANAGER_H \ No newline at end of file +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_INCLUDE_NOTIFICATION_LOCAL_LIVE_VIEW_SUBSCRIBER_LOCAL_LIVE_VIEW_MANAGER_H \ No newline at end of file diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index b8444a6d5..57bfcd0ed 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -45,7 +45,7 @@ #include "notification_slot.h" #include "notification_slot_filter.h" #include "notification_subscriber_manager.h" -#include "notification_local_activity_subscriber_manager.h" +#include "notification_local_live_view_subscriber_manager.h" #include "os_account_manager.h" #include "permission_filter.h" #include "push_callback_proxy.h" @@ -1513,8 +1513,8 @@ ErrCode AdvancedNotificationService::Subscribe( return errCode; } -ErrCode AdvancedNotificationService::SubscribeLocalActivity( - const sptr &subscriber, const sptr &info) +ErrCode AdvancedNotificationService::SubscribeLocalLiveView( + const sptr &subscriber, const sptr &info) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); ANS_LOGD("%{public}s", __FUNCTION__); @@ -1539,7 +1539,7 @@ ErrCode AdvancedNotificationService::SubscribeLocalActivity( break; } - errCode = NotificationLocalActivitySubscriberManager::GetInstance()->AddLocalActivitySubscriber(subscriber, info); + errCode = NotificationLocalLiveViewSubscriberManager::GetInstance()->AddLocalLiveViewSubscriber(subscriber, info); if (errCode != ERR_OK) { break; } @@ -2610,7 +2610,7 @@ ErrCode AdvancedNotificationService::AddSlotByType(NotificationConstant::SlotTyp return result; } -ErrCode AdvancedNotificationService::TriggerLocalActivity(const sptr &bundleOption, +ErrCode AdvancedNotificationService::TriggerLocalLiveView(const sptr &bundleOption, const int32_t notificationId, const sptr &buttonOption) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); @@ -2647,7 +2647,7 @@ ErrCode AdvancedNotificationService::TriggerLocalActivity(const sptrNotifyTriggerResponse(notification, buttonOption); + NotificationLocalLiveViewSubscriberManager::GetInstance()->NotifyTriggerResponse(notification, buttonOption); } })); notificationSvrQueue_->wait(handler); diff --git a/services/ans/src/notification_local_activity_subscriber_manager.cpp b/services/ans/src/notification_local_live_view_subscriber_manager.cpp similarity index 78% rename from services/ans/src/notification_local_activity_subscriber_manager.cpp rename to services/ans/src/notification_local_live_view_subscriber_manager.cpp index 7f8507bfa..54ac6ef23 100644 --- a/services/ans/src/notification_local_activity_subscriber_manager.cpp +++ b/services/ans/src/notification_local_live_view_subscriber_manager.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "notification_local_activity_subscriber_manager.h" +#include "notification_local_live_view_subscriber_manager.h" #include #include @@ -33,38 +33,38 @@ namespace OHOS { namespace Notification { -struct NotificationLocalActivitySubscriberManager::LocalActivitySubscriberRecord { - sptr subscriber {nullptr}; +struct NotificationLocalLiveViewSubscriberManager::LocalLiveViewSubscriberRecord { + sptr subscriber {nullptr}; std::string bundleName {}; int32_t userId {SUBSCRIBE_USER_INIT}; }; -NotificationLocalActivitySubscriberManager::NotificationLocalActivitySubscriberManager() +NotificationLocalLiveViewSubscriberManager::NotificationLocalLiveViewSubscriberManager() { ANS_LOGI("constructor"); - notificationButtonQueue_ = std::make_shared("NotificationLocalActivityMgr"); + notificationButtonQueue_ = std::make_shared("NotificationLocalLiveViewMgr"); recipient_ = new (std::nothrow) - RemoteDeathRecipient(std::bind(&NotificationLocalActivitySubscriberManager::OnRemoteDied, this, std::placeholders::_1)); + RemoteDeathRecipient(std::bind(&NotificationLocalLiveViewSubscriberManager::OnRemoteDied, this, std::placeholders::_1)); if (recipient_ == nullptr) { ANS_LOGE("Failed to create RemoteDeathRecipient instance"); } } -NotificationLocalActivitySubscriberManager::~NotificationLocalActivitySubscriberManager() +NotificationLocalLiveViewSubscriberManager::~NotificationLocalLiveViewSubscriberManager() { ANS_LOGI("deconstructor"); buttonRecordList_.clear(); } -void NotificationLocalActivitySubscriberManager::ResetFfrtQueue() +void NotificationLocalLiveViewSubscriberManager::ResetFfrtQueue() { if (notificationButtonQueue_ != nullptr) { notificationButtonQueue_.reset(); } } -ErrCode NotificationLocalActivitySubscriberManager::AddLocalActivitySubscriber( - const sptr &subscriber, const sptr &subscribeInfo) +ErrCode NotificationLocalLiveViewSubscriberManager::AddLocalLiveViewSubscriber( + const sptr &subscriber, const sptr &subscribeInfo) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (subscriber == nullptr) { @@ -100,8 +100,8 @@ ErrCode NotificationLocalActivitySubscriberManager::AddLocalActivitySubscriber( return result; } -ErrCode NotificationLocalActivitySubscriberManager::RemoveLocalActivitySubscriber( - const sptr &subscriber, const sptr &subscribeInfo) +ErrCode NotificationLocalLiveViewSubscriberManager::RemoveLocalLiveViewSubscriber( + const sptr &subscriber, const sptr &subscribeInfo) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); if (subscriber == nullptr) { @@ -125,7 +125,7 @@ ErrCode NotificationLocalActivitySubscriberManager::RemoveLocalActivitySubscribe return result; } -void NotificationLocalActivitySubscriberManager::NotifyTriggerResponse(const sptr ¬ification, +void NotificationLocalLiveViewSubscriberManager::NotifyTriggerResponse(const sptr ¬ification, const sptr &buttonOption) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); @@ -134,14 +134,14 @@ void NotificationLocalActivitySubscriberManager::NotifyTriggerResponse(const spt return; } AppExecFwk::EventHandler::Callback NotifyTriggerResponseFunc = - std::bind(&NotificationLocalActivitySubscriberManager::NotifyTriggerResponseInner, this, notification, buttonOption); + std::bind(&NotificationLocalLiveViewSubscriberManager::NotifyTriggerResponseInner, this, notification, buttonOption); ANS_LOGE("ffrt start!"); notificationButtonQueue_->submit(NotifyTriggerResponseFunc); ANS_LOGE("ffrt end!"); } -void NotificationLocalActivitySubscriberManager::OnRemoteDied(const wptr &object) +void NotificationLocalLiveViewSubscriberManager::OnRemoteDied(const wptr &object) { ANS_LOGI("OnRemoteDied"); if (notificationButtonQueue_ == nullptr) { @@ -150,7 +150,7 @@ void NotificationLocalActivitySubscriberManager::OnRemoteDied(const wptrsubmit_h(std::bind([this, object]() { ANS_LOGE("ffrt enter!"); - std::shared_ptr record = FindSubscriberRecord(object); + std::shared_ptr record = FindSubscriberRecord(object); if (record != nullptr) { ANS_LOGW("subscriber removed."); buttonRecordList_.remove(record); @@ -161,7 +161,7 @@ void NotificationLocalActivitySubscriberManager::OnRemoteDied(const wptr NotificationLocalActivitySubscriberManager::FindSubscriberRecord( +std::shared_ptr NotificationLocalLiveViewSubscriberManager::FindSubscriberRecord( const wptr &object) { auto iter = buttonRecordList_.begin(); @@ -174,8 +174,8 @@ std::shared_ptr NotificationLocalActivitySubscriberManager::FindSubscriberRecord( - const sptr &subscriber) +std::shared_ptr NotificationLocalLiveViewSubscriberManager::FindSubscriberRecord( + const sptr &subscriber) { auto iter = buttonRecordList_.begin(); @@ -187,10 +187,10 @@ std::shared_ptr NotificationLocalActivitySubscriberManager::CreateSubscriberRecord( - const sptr &subscriber, const sptr &bundleOption) +std::shared_ptr NotificationLocalLiveViewSubscriberManager::CreateSubscriberRecord( + const sptr &subscriber, const sptr &bundleOption) { - std::shared_ptr record = std::make_shared(); + std::shared_ptr record = std::make_shared(); // set bundleName and uid if (record != nullptr) { record->subscriber = subscriber; @@ -202,11 +202,11 @@ std::shared_ptr &subscriber, const sptr &bundleOption) +ErrCode NotificationLocalLiveViewSubscriberManager::AddSubscriberInner( + const sptr &subscriber, const sptr &bundleOption) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - std::shared_ptr record = FindSubscriberRecord(subscriber); + std::shared_ptr record = FindSubscriberRecord(subscriber); if (record == nullptr) { record = CreateSubscriberRecord(subscriber, bundleOption); if (record == nullptr) { @@ -224,11 +224,11 @@ ErrCode NotificationLocalActivitySubscriberManager::AddSubscriberInner( return ERR_OK; } -ErrCode NotificationLocalActivitySubscriberManager::RemoveSubscriberInner( - const sptr &subscriber, const sptr &subscribeInfo) +ErrCode NotificationLocalLiveViewSubscriberManager::RemoveSubscriberInner( + const sptr &subscriber, const sptr &subscribeInfo) { HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - std::shared_ptr record = FindSubscriberRecord(subscriber); + std::shared_ptr record = FindSubscriberRecord(subscriber); if (record == nullptr) { ANS_LOGE("subscriber not found."); @@ -245,7 +245,7 @@ ErrCode NotificationLocalActivitySubscriberManager::RemoveSubscriberInner( return ERR_OK; } -void NotificationLocalActivitySubscriberManager::NotifyTriggerResponseInner(const sptr ¬ification, const sptr buttonOption) +void NotificationLocalLiveViewSubscriberManager::NotifyTriggerResponseInner(const sptr ¬ification, const sptr buttonOption) { ANS_LOGE("ffrt enter!"); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); @@ -261,7 +261,7 @@ void NotificationLocalActivitySubscriberManager::NotifyTriggerResponseInner(cons } } -bool NotificationLocalActivitySubscriberManager::IsSystemUser(int32_t userId) +bool NotificationLocalLiveViewSubscriberManager::IsSystemUser(int32_t userId) { return ((userId >= SUBSCRIBE_USER_SYSTEM_BEGIN) && (userId <= SUBSCRIBE_USER_SYSTEM_END)); } -- Gitee