diff --git a/frameworks/core/common/include/ans_const_define.h b/frameworks/core/common/include/ans_const_define.h index abc37ced4306f5af4b33088a0e21a04c42565c93..6b80bf344b8d6c0663e528f6906420b41dcb356c 100644 --- a/frameworks/core/common/include/ans_const_define.h +++ b/frameworks/core/common/include/ans_const_define.h @@ -50,6 +50,7 @@ constexpr int64_t INVALID_PROFILE_ID = -1; constexpr int32_t SUBSCRIBE_USER_INIT = -1; constexpr int32_t SUBSCRIBE_USER_ALL = -2; constexpr int32_t DEFAULT_USER_ID = 100; +constexpr int32_t ZERO_USERID = 0; constexpr int32_t SUBSCRIBE_USER_SYSTEM_BEGIN = 0; constexpr int32_t SUBSCRIBE_USER_SYSTEM_END = 99; constexpr int32_t NOTIFICATION_MIN_COUNT = 0; diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index 1c356b7905fe4786ceb821c7e161ef0b8b956843..daa7e35e31a2c1d0b7fbc25b45b8051fabd54e1a 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -1707,6 +1707,9 @@ ErrCode AnsNotification::SetBadgeNumberByBundle(const NotificationBundleOption & return ERR_ANS_INVALID_PARAM; } + ANS_LOGI("SetBadgeNumberForDhByBundle, info:%{public}s %{public}d %{public}d", + bundleOption.GetBundleName().c_str(), bundleOption.GetUid(), badgeNumber); + sptr proxy = GetAnsManagerProxy(); if (!proxy) { ANS_LOGE("Unable to connect to ANS service."); diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index d8b860a9cd5d707d7617c5cfedb08094187fb955..d0071feac1a31d824cb80f70173ec71456067dde 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -84,6 +84,7 @@ ohos_source_set("ans_service_sources") { "src/ans_manager_stub.cpp", "src/ans_manager_stub_invalid.cpp", "src/bundle_manager_helper.cpp", + "src/clone/dh_notification_clone_bundle_service.cpp", "src/clone/notification_clone_bundle_info.cpp", "src/clone/notification_clone_bundle_service.cpp", "src/clone/notification_clone_disturb_service.cpp", diff --git a/services/ans/include/dh_notification_clone_bundle_service.h b/services/ans/include/dh_notification_clone_bundle_service.h new file mode 100644 index 0000000000000000000000000000000000000000..efd0ce692eb26fe5fbcb569731cb4e3de9ffe929 --- /dev/null +++ b/services/ans/include/dh_notification_clone_bundle_service.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024-2024 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_ANS_INCLUDE_DH_NOTIFICATION_CLONE_BUNDLE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DH_NOTIFICATION_CLONE_BUNDLE_H + +#include "notification_clone_template.h" +#include "ffrt.h" +#include "notification_bundle_option.h" +#include "notification_clone_bundle_info.h" + +namespace OHOS { +namespace Notification { +class DhNotificationCloneBundle final : public NotificationCloneTemplate { +public: + DhNotificationCloneBundle(); + ~DhNotificationCloneBundle() override; + static std::shared_ptr GetInstance(); + ErrCode OnBackup(nlohmann::json &jsonObject) override; + void OnRestoreStart(const std::string bundleName, int32_t appIndex, int32_t userId, int32_t uid) override; + void OnRestore(const nlohmann::json &jsonObject) override; + void OnUserSwitch(int32_t userId) override; + bool isDhSource() override; +private: + std::vector bundlesInfo_; + std::shared_ptr dhCloneBundleQueue_ = nullptr; + ffrt::mutex lock_; +}; +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_DH_NOTIFICATION_CLONE_BUNDLE_H \ No newline at end of file diff --git a/services/ans/include/notification_analytics_util.h b/services/ans/include/notification_analytics_util.h index ee131ce421ad81af16d5bfab2511af285df4caad..4fcb7c4617e130d02487dc2f59a23a59261680ed 100644 --- a/services/ans/include/notification_analytics_util.h +++ b/services/ans/include/notification_analytics_util.h @@ -38,6 +38,7 @@ enum EventSceneId { SCENE_11 = 11, SCENE_20 = 20, SCENE_21 = 21, + SCENE_22 = 22, }; enum EventBranchId { diff --git a/services/ans/include/notification_clone_manager.h b/services/ans/include/notification_clone_manager.h index a93a9846fe48b32f444a92d7985ecfce2405b58a..26832710752c9c0f1b481fdd59c7054ac8d5974f 100644 --- a/services/ans/include/notification_clone_manager.h +++ b/services/ans/include/notification_clone_manager.h @@ -23,9 +23,24 @@ #include "iremote_proxy.h" #include "common_event_data.h" #include "notification_clone_template.h" +#include "common_event_data.h" +#include "common_event_subscriber.h" namespace OHOS { namespace Notification { +class AncoRestoreStartEventSubscriber : public EventFwk::CommonEventSubscriber { +public: + DISALLOW_COPY_AND_MOVE(AncoRestoreStartEventSubscriber); + explicit AncoRestoreStartEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo); + ~AncoRestoreStartEventSubscriber() override; + void OnReceiveEvent(const EventFwk::CommonEventData& data) override; + static std::shared_ptr create(); + +private: + inline static const std::string EVENT_NAME = "usual.event.ANCO_RESTORE_START"; + inline static const std::string EVENT_PUBLISHER_PERMISSION = "ohos.permission.RECEIVE_BMS_BROKER_MESSAGES"; +}; + class NotificationCloneManager { public: static NotificationCloneManager& GetInstance(); @@ -34,6 +49,7 @@ public: int32_t OnRestore(MessageParcel& data, MessageParcel& reply); void OnUserSwitch(int32_t userId); void OnRestoreStart(EventFwk::Want want); + void OnDhRestoreStart(const std::string bundleName, const int32_t uid); private: NotificationCloneManager(); @@ -42,7 +58,8 @@ private: void RemoveBackUpFile(); ErrCode LoadConfig(UniqueFd &fd, std::string& config); ErrCode SaveConfig(const std::string& config); - std::map> cloneTemplates; + std::vector>> cloneTemplates; + std::shared_ptr restoreStartEventSubscriber_ = nullptr; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/notification_clone_template.h b/services/ans/include/notification_clone_template.h index 02a486acd689d6de6b3b63c8834602f6926bade2..b5b696086955ae7598c8b1c173ea7018605c724c 100644 --- a/services/ans/include/notification_clone_template.h +++ b/services/ans/include/notification_clone_template.h @@ -31,6 +31,10 @@ public: virtual void OnUserSwitch(int32_t userId) = 0; virtual void OnRestoreStart(const std::string bundleName, int32_t appIndex, int32_t userId, int32_t uid) = 0; + virtual bool isDhSource() + { + return false; + }; }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index a675c0d4d854bed956009a4e20e3cd7f3894e545..e6ea8df60edfb24542daedb41ab98ca1d0e0f5c7 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -315,6 +315,16 @@ public: bool GetBundleRemoveFlag(const sptr &bundleOption, const NotificationConstant::SlotType &slotType, int32_t sourceType); + /** + * @brief ParseBundleFromDistureDB + * @param info bundle info. + * @param entries bundle keys. + * @param userId userId. + * @return void + */ + void ParseBundleFromDistureDB(NotificationPreferencesInfo &info, + const std::unordered_map &entries, const int32_t &userId); + private: bool CheckRdbStore(); @@ -354,8 +364,6 @@ private: const std::string &bundleKey, const std::string &type = "", const std::string &subType = "") const; std::string GenerateBundleKey(const std::string &bundleKey, const std::string &type = "") const; - void ParseBundleFromDistureDB(NotificationPreferencesInfo &info, - const std::unordered_map &entries, const int32_t &userId); void ParseSlotFromDisturbeDB(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &bundleKey, const std::pair &entry, const int32_t &userId); void ParseBundlePropertyFromDisturbeDB(NotificationPreferencesInfo::BundleInfo &bundleInfo, diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index c18ee2146ede13ee2c668bdaa2d9a538f90b76eb..af79cac702be96eb37a3f9941b4a9620e19d2fe3 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -1102,7 +1102,9 @@ ErrCode AdvancedNotificationService::CommonRequestEnableNotification(const std:: ANS_LOGI("%{public}s_%{public}d, deviceId: %{public}s, Request enable notification dailog result: %{public}d", bundleOption->GetBundleName().c_str(), bundleOption->GetUid(), deviceId.c_str(), result); message.ErrorCode(result); - NotificationAnalyticsUtil::ReportModifyEvent(message); + if (!innerLake || result == ERR_ANS_DIALOG_POP_SUCCEEDED) { + NotificationAnalyticsUtil::ReportModifyEvent(message); + } return result; } @@ -2664,9 +2666,16 @@ ErrCode AdvancedNotificationService::SetBadgeNumber(int32_t badgeNumber, const s ErrCode AdvancedNotificationService::SetBadgeNumberForDhByBundle( const sptr &bundleOption, int32_t badgeNumber) { - if (bundleOption == nullptr || bundleOption->GetBundleName().empty() || - bundleOption->GetUid() <= DEFAULT_UID) { - ANS_LOGE("SetBadgeNumberForDhByBundle invalid bundleOption"); + if (bundleOption == nullptr) { + ANS_LOGE("SetBadgeNumberForDhByBundle bundleOption is null"); + return ERR_ANS_INVALID_PARAM; + } + if (bundleOption->GetBundleName().empty()) { + ANS_LOGE("SetBadgeNumberForDhByBundle Invalid bundle name."); + return ERR_ANS_INVALID_PARAM; + } + if (bundleOption->GetUid() <= DEFAULT_UID) { + ANS_LOGE("SetBadgeNumberForDhByBundle invalid uid"); return ERR_ANS_INVALID_PARAM; } if (badgeNumber < BADGE_NUM_LIMIT) { diff --git a/services/ans/src/clone/dh_notification_clone_bundle_service.cpp b/services/ans/src/clone/dh_notification_clone_bundle_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e93e2a5f7bd8d3d874f97e77336182555d2e433 --- /dev/null +++ b/services/ans/src/clone/dh_notification_clone_bundle_service.cpp @@ -0,0 +1,146 @@ +/* +* Copyright (c) 2024-2024 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 "dh_notification_clone_bundle_service.h" + +#include "ans_log_wrapper.h" +#include "notification_preferences.h" +#include "notification_clone_util.h" +#include "notification_clone_bundle_info.h" +#include "os_account_manager_helper.h" +#include "advanced_notification_service.h" + +namespace OHOS { +namespace Notification { + +std::shared_ptr DhNotificationCloneBundle::GetInstance() +{ + static std::shared_ptr instance = + std::make_shared(); + return instance; +} + +DhNotificationCloneBundle::DhNotificationCloneBundle() +{ + dhCloneBundleQueue_ = std::make_shared("DhNotificationCloneBundleQueue"); + if (!dhCloneBundleQueue_) { + ANS_LOGE("ffrt create failed!"); + return; + } +} + +DhNotificationCloneBundle::~DhNotificationCloneBundle() +{ +} + +ErrCode DhNotificationCloneBundle::OnBackup(nlohmann::json &jsonObject) +{ + ANS_LOGI("dh Notification bundle backup."); + std::vector cloneBundles; + NotificationPreferences::GetInstance()->GetAllCLoneBundlesInfo(ZERO_USERID, cloneBundles); + + if (cloneBundles.empty()) { + ANS_LOGI("dh Notification bundle list is empty."); + return ERR_OK; + } + jsonObject = nlohmann::json::array(); + for (size_t index = 0; index < cloneBundles.size(); index++) { + nlohmann::json jsonNode; + cloneBundles[index].ToJson(jsonNode); + jsonObject.emplace_back(jsonNode); + ANS_LOGD("Event dh bundle backup %{public}s.", cloneBundles[index].Dump().c_str()); + } + ANS_LOGD("dh Notification bundle list %{public}s", jsonObject.dump().c_str()); + return ERR_OK; +} + +void DhNotificationCloneBundle::OnRestore(const nlohmann::json &jsonObject) +{ + ANS_LOGI("dh Notification bundle list on restore."); + if (jsonObject.is_null() || !jsonObject.is_array()) { + ANS_LOGI("dh Notification bundle list is null or not array."); + return; + } + + std::unique_lock lock(lock_); + if (!bundlesInfo_.empty()) { + NotificationPreferences::GetInstance()->DelBatchCloneBundleInfo(ZERO_USERID, bundlesInfo_); + bundlesInfo_.clear(); + } + for (const auto &profile : jsonObject) { + NotificationCloneBundleInfo cloneBundleInfo; + cloneBundleInfo.FromJson(profile); + bundlesInfo_.emplace_back(cloneBundleInfo); + } + ANS_LOGI("dh Notification bundle list size %{public}zu.", bundlesInfo_.size()); + if (dhCloneBundleQueue_ == nullptr || bundlesInfo_.empty()) { + ANS_LOGE("Clone dh bundle is invalidated or empty."); + return; + } + + NotificationPreferences::GetInstance()->UpdateBatchCloneBundleInfo(ZERO_USERID, bundlesInfo_); + for (auto bundle = bundlesInfo_.begin(); bundle != bundlesInfo_.end(); bundle++) { + ANS_LOGI("Event dh bundle left %{public}s.", bundle->Dump().c_str()); + } + ANS_LOGI("dh Notification bundle list on restore end."); +} + +void DhNotificationCloneBundle::OnRestoreStart(const std::string bundleName, int32_t appIndex, + int32_t userId, int32_t uid) +{ + ANS_LOGI("Handle dh bundle event %{public}s %{public}d %{public}zu.", + bundleName.c_str(), uid, bundlesInfo_.size()); + std::unique_lock lock(lock_); + if (bundlesInfo_.empty()) { + return; + } + + for (auto bundle = bundlesInfo_.begin(); bundle != bundlesInfo_.end();) { + if (bundle->GetBundleName() == bundleName) { + bundle->SetUid(uid); + AdvancedNotificationService::GetInstance()->UpdateCloneBundleInfo(*bundle); + NotificationPreferences::GetInstance()->DelCloneBundleInfo(ZERO_USERID, *bundle); + bundle = bundlesInfo_.erase(bundle); + break; + } + bundle++; + } + ANS_LOGI("Event dh bundle left %{public}zu.", bundlesInfo_.size()); +} + +void DhNotificationCloneBundle::OnUserSwitch(int32_t userId) +{ + ANS_LOGI("Handler user switch %{public}d", userId); + if (dhCloneBundleQueue_ == nullptr) { + ANS_LOGW("Clone bundle queue is null."); + return; + } + dhCloneBundleQueue_->submit_h(std::bind([&, userId]() { + std::unique_lock lock(lock_); + bundlesInfo_.clear(); + NotificationPreferences::GetInstance()->GetAllCloneBundleInfo(ZERO_USERID, bundlesInfo_); + for (auto bundle = bundlesInfo_.begin(); bundle != bundlesInfo_.end(); bundle++) { + ANS_LOGI("Event dh bundle OnUserSwitch %{public}s.", bundle->Dump().c_str()); + } + })); +} + +bool DhNotificationCloneBundle::isDhSource() +{ + return true; +} + +} +} \ No newline at end of file diff --git a/services/ans/src/clone/notification_clone_bundle_service.cpp b/services/ans/src/clone/notification_clone_bundle_service.cpp index 4dae3d501dc3a483d6c66fbba6ad2c49beda3a1a..9bdf7f60bb226621ff937103a895d993aa67a9cb 100644 --- a/services/ans/src/clone/notification_clone_bundle_service.cpp +++ b/services/ans/src/clone/notification_clone_bundle_service.cpp @@ -81,7 +81,7 @@ void NotificationCloneBundle::OnRestore(const nlohmann::json &jsonObject) bundlesInfo_.clear(); } for (const auto &profile : jsonObject) { - NotificationCloneBundleInfo cloneBundleInfo;; + NotificationCloneBundleInfo cloneBundleInfo; cloneBundleInfo.FromJson(profile); bundlesInfo_.emplace_back(cloneBundleInfo); } @@ -115,11 +115,11 @@ void NotificationCloneBundle::OnRestoreStart(const std::string bundleName, int32 { ANS_LOGI("Handle bundle event %{public}s %{public}d %{public}d %{public}d %{public}zu.", bundleName.c_str(), appIndex, userId, uid, bundlesInfo_.size()); + std::unique_lock lock(lock_); if (bundlesInfo_.empty()) { return; } - std::unique_lock lcck(lock_); for (auto bundle = bundlesInfo_.begin(); bundle != bundlesInfo_.end();) { if (bundle->GetBundleName() == bundleName && bundle->GetAppIndex() == appIndex) { bundle->SetUid(uid); diff --git a/services/ans/src/clone/notification_clone_manager.cpp b/services/ans/src/clone/notification_clone_manager.cpp index 1f4d4392a988e0eaa68e81f7e4f3527b80856d19..95533d846993a085da8da056d222baad34fa01ee 100644 --- a/services/ans/src/clone/notification_clone_manager.cpp +++ b/services/ans/src/clone/notification_clone_manager.cpp @@ -27,15 +27,58 @@ #include "notification_clone_disturb_service.h" #include "notification_clone_bundle_service.h" #include "notification_clone_util.h" +#include "dh_notification_clone_bundle_service.h" +#include "common_event_manager.h" +#include "notification_analytics_util.h" namespace OHOS { namespace Notification { const int ANS_CLONE_ERROR = -1; +const int32_t DEFAULT_APP_INDEX = -1; constexpr const char *CLONE_ITEM_BUNDLE_INFO = "notificationBundle"; +constexpr const char *DH_CLONE_ITEM_BUNDLE_INFO = "dhNotificationBundle"; constexpr const char *CLONE_ITEM_DISTURB = "notificationDisturb"; constexpr const char *BACKUP_CONFIG_FILE_PATH = "/data/service/el1/public/notification/backup_config.conf"; +std::shared_ptr AncoRestoreStartEventSubscriber::create() +{ + ANS_LOGI("AncoRestoreStartEventSubscriber create"); + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(AncoRestoreStartEventSubscriber::EVENT_NAME); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + subscriberInfo.SetPermission(AncoRestoreStartEventSubscriber::EVENT_PUBLISHER_PERMISSION); + return std::make_shared(subscriberInfo); + ANS_LOGI("AncoRestoreStartEventSubscriber create end"); +} + +AncoRestoreStartEventSubscriber::AncoRestoreStartEventSubscriber( + const EventFwk::CommonEventSubscribeInfo &subscribeInfo) + : EventFwk::CommonEventSubscriber(subscribeInfo) +{ +} + +AncoRestoreStartEventSubscriber::~AncoRestoreStartEventSubscriber() +{ + ANS_LOGI("AncoRestoreStartEventSubscriber release"); +} + +void AncoRestoreStartEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData& data) +{ + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_22, EventBranchId::BRANCH_4); + std::string bundleName = data.GetWant().GetStringParam("bundleName"); + int32_t uid = data.GetWant().GetIntParam("uid", 0); + ANS_LOGI("AncoRestoreStartEventSubscriber Get Data %{public}s %{public}d", + bundleName.c_str(), uid); + if (uid <= 0) { + message.Message("dh restoreStart uid error" + bundleName); + NotificationAnalyticsUtil::ReportModifyEvent(message); + ANS_LOGE("AncoRestoreStartEventSubscriber uid error"); + return; + } + NotificationCloneManager::GetInstance().OnDhRestoreStart(bundleName, uid); +} + NotificationCloneManager& NotificationCloneManager::GetInstance() { static NotificationCloneManager notificationCloneManager; @@ -60,6 +103,8 @@ static std::string SetBackUpReply() int32_t NotificationCloneManager::OnBackup(MessageParcel& data, MessageParcel& reply) { + ANS_LOGI("OnBackup start"); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_22, EventBranchId::BRANCH_1); if (cloneTemplates.empty()) { ANS_LOGI("Notification no need Backup."); return ERR_OK; @@ -81,18 +126,24 @@ int32_t NotificationCloneManager::OnBackup(MessageParcel& data, MessageParcel& r } if (SaveConfig(jsonObject.dump()) != ERR_OK) { + message.Message("SaveConfig failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return ANS_CLONE_ERROR; } UniqueFd fd = UniqueFd(open(BACKUP_CONFIG_FILE_PATH, O_RDONLY)); if (fd.Get() < 0) { - ANS_LOGW("Notification open file failed."); + ANS_LOGE("Notification open file failed."); + message.Message("Notification open file failed."); + NotificationAnalyticsUtil::ReportModifyEvent(message); return ANS_CLONE_ERROR; } if (reply.WriteFileDescriptor(fd) == false) { close(fd.Release()); - ANS_LOGW("Notification write file descriptor failed!"); + ANS_LOGE("Notification write file descriptor failed!"); + message.Message("Notification write file descriptor failed!"); + NotificationAnalyticsUtil::ReportModifyEvent(message); return ANS_CLONE_ERROR; } @@ -103,23 +154,31 @@ int32_t NotificationCloneManager::OnBackup(MessageParcel& data, MessageParcel& r int32_t NotificationCloneManager::OnRestore(MessageParcel& data, MessageParcel& reply) { + ANS_LOGI("OnRestore start"); + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_22, EventBranchId::BRANCH_2); reply.WriteString(SetBackUpReply()); std::string storeMessage; UniqueFd fd(data.ReadFileDescriptor()); if (LoadConfig(fd, storeMessage) != ERR_OK) { close(fd.Release()); RemoveBackUpFile(); + message.Message("LoadConfig failed!"); + NotificationAnalyticsUtil::ReportModifyEvent(message); return ANS_CLONE_ERROR; } RemoveBackUpFile(); if (storeMessage.empty() || !nlohmann::json::accept(storeMessage)) { ANS_LOGE("Invalid JSON"); + message.Message("Invalid JSON"); + NotificationAnalyticsUtil::ReportModifyEvent(message); return ANS_CLONE_ERROR; } nlohmann::json jsonObject = nlohmann::json::parse(storeMessage, nullptr, false); if (jsonObject.is_null() || !jsonObject.is_object()) { ANS_LOGE("Invalid JSON object"); + message.Message("Invalid JSON object"); + NotificationAnalyticsUtil::ReportModifyEvent(message); return ANS_CLONE_ERROR; } for (auto iter = cloneTemplates.begin(); iter != cloneTemplates.end(); ++iter) { @@ -127,14 +186,24 @@ int32_t NotificationCloneManager::OnRestore(MessageParcel& data, MessageParcel& iter->second->OnRestore(jsonObject.at(iter->first)); } } + ANS_LOGI("OnRestore end"); return ERR_OK; } NotificationCloneManager::NotificationCloneManager() { ANS_LOGI("Notification clone manager init."); - cloneTemplates.insert_or_assign(CLONE_ITEM_BUNDLE_INFO, NotificationCloneBundle::GetInstance()); - cloneTemplates.insert_or_assign(CLONE_ITEM_DISTURB, NotificationCloneDisturb::GetInstance()); + // not change push sequence, ensure [clone item] before [dh clone item] + cloneTemplates.push_back(std::make_pair(CLONE_ITEM_BUNDLE_INFO, NotificationCloneBundle::GetInstance())); + cloneTemplates.push_back(std::make_pair(DH_CLONE_ITEM_BUNDLE_INFO, DhNotificationCloneBundle::GetInstance())); + cloneTemplates.push_back(std::make_pair(CLONE_ITEM_DISTURB, NotificationCloneDisturb::GetInstance())); + + restoreStartEventSubscriber_ = AncoRestoreStartEventSubscriber::create(); + if (!EventFwk::CommonEventManager::SubscribeCommonEvent(restoreStartEventSubscriber_)) { + ANS_LOGE("Subscribe AncoRestoreStartEventSubscriber Failed."); + restoreStartEventSubscriber_ = nullptr; + } + ANS_LOGI("Subscribe AncoRestoreStartEventSubscriber success."); } NotificationCloneManager::~NotificationCloneManager() @@ -212,20 +281,32 @@ void NotificationCloneManager::OnUserSwitch(int32_t userId) void NotificationCloneManager::OnRestoreStart(EventFwk::Want want) { + HaMetaMessage message = HaMetaMessage(EventSceneId::SCENE_22, EventBranchId::BRANCH_3); int32_t appIndex = want.GetIntParam("index", -1); std::string bundleName = want.GetStringParam("bundleName"); int32_t userId = NotificationCloneUtil::GetActiveUserId(); if (appIndex == -1 || bundleName.empty()) { ANS_LOGW("Invalid restore data %{public}d %{public}d %{public}s", appIndex, userId, bundleName.c_str()); + message.Message("Invalid restore data"); + NotificationAnalyticsUtil::ReportModifyEvent(message); return; } int32_t uid = NotificationCloneUtil::GetBundleUid(bundleName, userId, appIndex); for (auto iter = cloneTemplates.begin(); iter != cloneTemplates.end(); ++iter) { - if (iter->second != nullptr) { + if (iter->second != nullptr && !iter->second->isDhSource()) { iter->second->OnRestoreStart(bundleName, appIndex, userId, uid); } } } + +void NotificationCloneManager::OnDhRestoreStart(const std::string bundleName, const int32_t uid) +{ + for (auto iter = cloneTemplates.begin(); iter != cloneTemplates.end(); ++iter) { + if (iter->second != nullptr && iter->second->isDhSource()) { + iter->second->OnRestoreStart(bundleName, DEFAULT_APP_INDEX, ZERO_USERID, uid); + } + } +} } } diff --git a/services/ans/src/notification_dialog.cpp b/services/ans/src/notification_dialog.cpp index ac53a95455c63f714aec08c964cb18b8356c0532..5698fabc4360b04640ba29eda4d774847a570ae5 100644 --- a/services/ans/src/notification_dialog.cpp +++ b/services/ans/src/notification_dialog.cpp @@ -51,16 +51,16 @@ ErrCode NotificationDialog::StartEnableNotificationDialogAbility( auto topBundleName = IN_PROCESS_CALL(AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility().GetBundleName()); if (topBundleName != appBundleName) { - ANS_LOGE("Current application isn't in foreground, top is %{public}s.", topBundleName.c_str()); + ANS_LOGW("Current application isn't in foreground, top is %{public}s.", topBundleName.c_str()); if (!innerLake) { return ERR_ANS_INVALID_BUNDLE; } else { - ANS_LOGE("get top ability again"); + ANS_LOGW("get top ability again"); std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME)); topBundleName = IN_PROCESS_CALL( AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility().GetBundleName()); if (topBundleName != appBundleName) { - ANS_LOGE("get top ability again failed"); + ANS_LOGW("get top ability again failed"); return ERR_ANS_INVALID_BUNDLE; } } diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index 61945894596991a7069721da8928f46bf0fbaaf6..d6b33778d6bf8584e8476ab1bc82da57f754e72d 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -732,6 +732,7 @@ void NotificationPreferences::GetAllCLoneBundlesInfo(int32_t userId, ANS_LOGE("Get bundle map info failed."); return; } + preferncesDB_->ParseBundleFromDistureDB(preferencesInfo, bundlesMap, userId); preferencesInfo.GetAllCLoneBundlesInfo(userId, bundlesMap, cloneBundles); preferencesInfo_ = preferencesInfo; }