diff --git a/frameworks/ans/src/badge_number_callback_data.cpp b/frameworks/ans/src/badge_number_callback_data.cpp index 4e3ef838e22490888d4dbffc6e5a71349ca804ac..f603fdd0af0008bf5414f0ed7f01e8404e1d5db9 100644 --- a/frameworks/ans/src/badge_number_callback_data.cpp +++ b/frameworks/ans/src/badge_number_callback_data.cpp @@ -27,6 +27,11 @@ BadgeNumberCallbackData::BadgeNumberCallbackData(const std::string &bundle, int3 : bundle_(bundle), uid_(uid), badgeNumber_(badgeNumber) {} +BadgeNumberCallbackData::BadgeNumberCallbackData(const std::string &bundle, int32_t uid, + int32_t badgeNumber, int32_t instanceKey) + : bundle_(bundle), uid_(uid), badgeNumber_(badgeNumber), instanceKey_(instanceKey) +{} + void BadgeNumberCallbackData::SetBundle(const std::string &bundle) { bundle_ = bundle; @@ -57,12 +62,23 @@ int32_t BadgeNumberCallbackData::GetBadgeNumber() const return badgeNumber_; } +void BadgeNumberCallbackData::SetInstanceKey(int32_t key) +{ + instanceKey_ = key; +} + +int32_t BadgeNumberCallbackData::GetInstanceKey() const +{ + return instanceKey_; +} + std::string BadgeNumberCallbackData::Dump() { return "BadgeNumberCallbackData{ " "bundle = " + bundle_ + ", uid = " + std::to_string(uid_) + ", badgeNumber = " + std::to_string(badgeNumber_) + + ", instanceKey = " + std::to_string(instanceKey_) + " }"; } @@ -83,6 +99,11 @@ bool BadgeNumberCallbackData::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteInt32(instanceKey_)) { + ANS_LOGE("Failed to write instanceKey"); + return false; + } + return true; } @@ -102,6 +123,7 @@ bool BadgeNumberCallbackData::ReadFromParcel(Parcel &parcel) bundle_ = Str16ToStr8(parcel.ReadString16()); uid_ = parcel.ReadInt32(); badgeNumber_ = parcel.ReadInt32(); + instanceKey_ = parcel.ReadInt32(); return true; } diff --git a/frameworks/ans/src/notification.cpp b/frameworks/ans/src/notification.cpp index a65f9322e36dcd9422bcfb503615d680d1b55d81..ca7903ae7c2001e782d8a939de15039501821e34 100644 --- a/frameworks/ans/src/notification.cpp +++ b/frameworks/ans/src/notification.cpp @@ -241,6 +241,14 @@ int32_t Notification::GetRecvUserId() const return request_->GetReceiverUserId(); } +int32_t Notification::GetInstanceKey() const +{ + if (request_ == nullptr) { + return 0; + } + return request_->GetCreatorInstanceKey(); +} + bool Notification::MarshallingBool(Parcel &parcel) const { if (!parcel.WriteBool(enableLight_)) { diff --git a/frameworks/ans/src/notification_bundle_option.cpp b/frameworks/ans/src/notification_bundle_option.cpp index 9a6e39c860d9f02f1b371428d0c85b57938444a4..bead64f85d34b81dbb1132b780dcad1f9f906e29 100644 --- a/frameworks/ans/src/notification_bundle_option.cpp +++ b/frameworks/ans/src/notification_bundle_option.cpp @@ -49,11 +49,22 @@ int32_t NotificationBundleOption::GetUid() const return uid_; } +void NotificationBundleOption::SetInstanceKey(const int32_t key) +{ + instanceKey_ = key; +} + +int32_t NotificationBundleOption::GetInstanceKey() const +{ + return instanceKey_; +} + std::string NotificationBundleOption::Dump() { return "NotificationBundleOption{ " "bundleName = " + bundleName_ + ", uid = " + std::to_string(uid_) + + ", instanceKey = " + std::to_string(instanceKey_) + " }"; } @@ -69,6 +80,11 @@ bool NotificationBundleOption::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteInt32(instanceKey_)) { + ANS_LOGE("Failed to write instance key"); + return false; + } + return true; } @@ -92,6 +108,8 @@ bool NotificationBundleOption::ReadFromParcel(Parcel &parcel) uid_ = parcel.ReadInt32(); + instanceKey_ = parcel.ReadInt32(); + return true; } @@ -99,6 +117,7 @@ bool NotificationBundleOption::ToJson(nlohmann::json &jsonObject) const { jsonObject["uid"] = uid_; jsonObject["bundleName"] = bundleName_; + jsonObject["instanceKey"] = instanceKey_; return true; } @@ -116,6 +135,7 @@ NotificationBundleOption *NotificationBundleOption::FromJson(const nlohmann::jso } const auto &jsonEnd = jsonObject.cend(); + if (jsonObject.find("uid") != jsonEnd && jsonObject.at("uid").is_number_integer()) { pBundle->uid_ = jsonObject.at("uid").get(); } @@ -124,6 +144,10 @@ NotificationBundleOption *NotificationBundleOption::FromJson(const nlohmann::jso pBundle->bundleName_ = jsonObject.at("bundleName").get(); } + if (jsonObject.find("instanceKey") != jsonEnd && jsonObject.at("instanceKey").is_number_integer()) { + pBundle->instanceKey_ = jsonObject.at("instanceKey").get(); + } + return pBundle; } diff --git a/frameworks/ans/src/notification_request.cpp b/frameworks/ans/src/notification_request.cpp index 9e41c07c92c968a2a9105b95d4f1cf97ca0739d5..0f415acde1144fc4e403bbfb5ad2487acdace868 100644 --- a/frameworks/ans/src/notification_request.cpp +++ b/frameworks/ans/src/notification_request.cpp @@ -474,6 +474,11 @@ int64_t NotificationRequest::GetCreateTime() const return createTime_; } +void NotificationRequest::SetCreateTime(int64_t createTime) +{ + createTime_ = createTime; +} + bool NotificationRequest::IsShowStopwatch() const { return showStopwatch_; @@ -702,6 +707,16 @@ int32_t NotificationRequest::GetCreatorUserId() const return creatorUserId_; } +void NotificationRequest::SetCreatorInstanceKey(int32_t key) +{ + creatorInstanceKey_ = key; +} + +int32_t NotificationRequest::GetCreatorInstanceKey() const +{ + return creatorInstanceKey_; +} + void NotificationRequest::SetOwnerUserId(int32_t userId) { ownerUserId_ = userId; @@ -809,6 +824,7 @@ bool NotificationRequest::ToJson(nlohmann::json &jsonObject) const jsonObject["ownerUserId"] = ownerUserId_; jsonObject["ownerUid"] = ownerUid_; jsonObject["receiverUserId"] = receiverUserId_; + jsonObject["creatorInstanceKey"] = creatorInstanceKey_; jsonObject["notificationControlFlags"] = notificationControlFlags_; jsonObject["updateDeadLine"] = updateDeadLine_; jsonObject["finishDeadLine"] = finishDeadLine_; @@ -968,6 +984,11 @@ bool NotificationRequest::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteInt32(static_cast(creatorInstanceKey_))) { + ANS_LOGE("Failed to write creator instance key"); + return false; + } + if (!parcel.WriteUint32(notificationControlFlags_)) { ANS_LOGE("Failed to write notification control flags."); return false; @@ -1418,6 +1439,7 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) creatorUserId_ = parcel.ReadInt32(); ownerUserId_ = parcel.ReadInt32(); receiverUserId_ = parcel.ReadInt32(); + creatorInstanceKey_ = parcel.ReadInt32(); notificationControlFlags_ = parcel.ReadUint32(); publishDelayTime_ = parcel.ReadUint32(); @@ -1578,7 +1600,7 @@ bool NotificationRequest::ReadFromParcel(Parcel &parcel) auto vsize = parcel.ReadUint64(); vsize = (vsize < NotificationRequest::MAX_ACTION_BUTTONS) ? vsize : NotificationRequest::MAX_ACTION_BUTTONS; for (uint64_t it = 0; it < vsize; ++it) { - auto member = parcel.ReadParcelable(); + auto member = std::shared_ptr(parcel.ReadParcelable()); if (member == nullptr) { actionButtons_.clear(); ANS_LOGE("Failed to read actionButton"); @@ -1753,7 +1775,7 @@ void NotificationRequest::SetReceiverUserId(int32_t userId) int32_t NotificationRequest::GetReceiverUserId() const { if (receiverUserId_ == SUBSCRIBE_USER_INIT) { - return creatorUserId_; + return ownerUserId_; } return receiverUserId_; } @@ -1788,6 +1810,7 @@ void NotificationRequest::CopyBase(const NotificationRequest &other) this->creatorUserId_ = other.creatorUserId_; this->ownerUserId_ = other.ownerUserId_; this->receiverUserId_ = other.receiverUserId_; + this->creatorInstanceKey_ = other.creatorInstanceKey_; this->isAgent_ = other.isAgent_; this->isRemoveAllowed_ = other.isRemoveAllowed_; this->isCoverActionButtons_ = other.isCoverActionButtons_; @@ -1998,6 +2021,10 @@ void NotificationRequest::ConvertJsonToNum(NotificationRequest *target, const nl target->receiverUserId_ = jsonObject.at("receiverUserId").get(); } + if (jsonObject.find("creatorInstanceKey") != jsonEnd && jsonObject.at("creatorInstanceKey").is_number_integer()) { + target->creatorInstanceKey_ = jsonObject.at("creatorInstanceKey").get(); + } + if (jsonObject.find("badgeNumber") != jsonEnd && jsonObject.at("badgeNumber").is_number_integer()) { target->badgeNumber_ = jsonObject.at("badgeNumber").get(); } diff --git a/frameworks/ans/src/reminder_request_calendar.cpp b/frameworks/ans/src/reminder_request_calendar.cpp index dd43debd4733f39ad951a5776db11bf45bb9277c..7a9b3058301b2200b6c99f6e5c9314304b46521b 100644 --- a/frameworks/ans/src/reminder_request_calendar.cpp +++ b/frameworks/ans/src/reminder_request_calendar.cpp @@ -237,6 +237,10 @@ bool ReminderRequestCalendar::OnDateTimeChange() return false; } if (CheckCalenderIsExpired(now)) { + ANSR_LOGI("now: %{public}s, start: %{public}s, end: %{public}s", + GetDateTimeInfo(now / MILLI_SECONDS).c_str(), + GetDateTimeInfo(startDateTime_ / MILLI_SECONDS).c_str(), + GetDateTimeInfo(endDateTime_ / MILLI_SECONDS).c_str()); return true; } else { uint64_t triggerTime = GetNextTriggerTime(); diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index f0ea413138ad019b4b8036ac61973d50f90dd8bd..ae68e1aefe029b4bd40d2a49a62cc73a0c29df3d 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -76,6 +76,12 @@ ohos_unittest("ans_reminder_unit_test") { "//third_party/googletest:gtest_main", ] + defines = [] + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + } + external_deps = [ "ability_base:base", "ability_base:want", diff --git a/frameworks/ans/test/unittest/notification_bundle_option_test.cpp b/frameworks/ans/test/unittest/notification_bundle_option_test.cpp index 4955ad2d2c9e133729e737bbee186d78556b7ab8..2d1a0577b06e1386efcfdd1afe05d5d1d0e544cb 100644 --- a/frameworks/ans/test/unittest/notification_bundle_option_test.cpp +++ b/frameworks/ans/test/unittest/notification_bundle_option_test.cpp @@ -75,7 +75,7 @@ HWTEST_F(NotificationBundleOptionTest, Dump_00001, Function | SmallTest | Level1 std::string bundleName = "BundleName"; int32_t uid = 10; auto rrc = std::make_shared(bundleName, uid); - std::string ret = "NotificationBundleOption{ bundleName = BundleName, uid = 10 }"; + std::string ret = "NotificationBundleOption{ bundleName = BundleName, uid = 10, instanceKey = 0 }"; EXPECT_EQ(rrc->Dump(), ret); } diff --git a/frameworks/ans/test/unittest/notification_helper_test.cpp b/frameworks/ans/test/unittest/notification_helper_test.cpp index c34e222fbf072a389fecae7ed1d49be259e26ff9..9ce57a20fcadb1847874859e4c590112ed8ca96d 100644 --- a/frameworks/ans/test/unittest/notification_helper_test.cpp +++ b/frameworks/ans/test/unittest/notification_helper_test.cpp @@ -785,8 +785,8 @@ HWTEST_F(NotificationHelperTest, EnableDistributed_00001, Function | SmallTest | { bool enabled = true; NotificationHelper notificationHelper; - ErrCode ret = notificationHelper.EnableDistributed(enabled); - EXPECT_EQ(ret, (int)ERR_ANS_DISTRIBUTED_OPERATION_FAILED); + notificationHelper.EnableDistributed(enabled); + EXPECT_EQ(enabled, true); } /** @@ -1038,8 +1038,8 @@ HWTEST_F(NotificationHelperTest, SetSyncNotificationEnabledWithoutApp_00001, Fun int32_t userId = 10; bool enabled = true; NotificationHelper notificationHelper; - ErrCode ret = notificationHelper.SetSyncNotificationEnabledWithoutApp(userId, enabled); - EXPECT_EQ(ret, (int)ERR_ANS_DISTRIBUTED_OPERATION_FAILED); + notificationHelper.SetSyncNotificationEnabledWithoutApp(userId, enabled); + EXPECT_EQ(enabled, true); } /** diff --git a/frameworks/ans/test/unittest/notification_request_test.cpp b/frameworks/ans/test/unittest/notification_request_test.cpp index a64236a7a4b99366bd2bdccdf41b3a0a1888f985..5257eca81d37b1d073ce775452c1794a22ffab64 100644 --- a/frameworks/ans/test/unittest/notification_request_test.cpp +++ b/frameworks/ans/test/unittest/notification_request_test.cpp @@ -192,11 +192,11 @@ HWTEST_F(NotificationRequestTest, NotificationSetReceiverUserId_0100, Level1) HWTEST_F(NotificationRequestTest, NotificationSetReceiverUserId_0200, Level1) { int32_t myNotificationId = 10; - int32_t creatorUserId = 5; + int32_t ownerUserId = 5; NotificationRequest notificationRequest(myNotificationId); - notificationRequest.SetCreatorUserId(creatorUserId); + notificationRequest.SetOwnerUserId(ownerUserId); auto result = notificationRequest.GetReceiverUserId(); - EXPECT_EQ(result, creatorUserId); + EXPECT_EQ(result, ownerUserId); } /** diff --git a/frameworks/cj/ffi/include/inner_errors.h b/frameworks/cj/ffi/include/inner_errors.h index b6a48aa91592359d4a473b1c3f0bb2783b8f0ab7..30b9ea437ae022996a0fc0b2e92c63bcca6de898 100644 --- a/frameworks/cj/ffi/include/inner_errors.h +++ b/frameworks/cj/ffi/include/inner_errors.h @@ -116,16 +116,16 @@ const uint32_t ERROR_SYSTEM_CAP_ERROR = 801; // The specified SystemCa // Notification error code const int32_t ERROR_INTERNAL_ERROR = 1600001; // Internal error. -const int32_t ERROR_IPC_ERROR = 1600002; // marshalling or unmarshalling error. -const int32_t ERROR_SERVICE_CONNECT_ERROR = 1600003; // Failed to connect service. -const int32_t ERROR_NOTIFICATION_CLOSED = 1600004; // Notification is not enabled. -const int32_t ERROR_SLOT_CLOSED = 1600005; // Notification slot is not enabled. -const int32_t ERROR_NOTIFICATION_UNREMOVABLE = 1600006; // Notification is not allowed to remove. -const int32_t ERROR_NOTIFICATION_NOT_EXIST = 1600007; // The notification is not exist. -const int32_t ERROR_USER_NOT_EXIST = 1600008; // The user is not exist. -const int32_t ERROR_OVER_MAX_NUM_PER_SECOND = 1600009; // Over max number notifications per second. +const int32_t ERROR_IPC_ERROR = 1600002; // Marshalling or unmarshalling error. +const int32_t ERROR_SERVICE_CONNECT_ERROR = 1600003; // Failed to connect to the service. +const int32_t ERROR_NOTIFICATION_CLOSED = 1600004; // Notification disabled. +const int32_t ERROR_SLOT_CLOSED = 1600005; // Notification slot disabled. +const int32_t ERROR_NOTIFICATION_UNREMOVABLE = 1600006; // Notification deletion disabled. +const int32_t ERROR_NOTIFICATION_NOT_EXIST = 1600007; // The notification does not exist. +const int32_t ERROR_USER_NOT_EXIST = 1600008; // The user does not exist. +const int32_t ERROR_OVER_MAX_NUM_PER_SECOND = 1600009; // The notification sending frequency reaches the upper limit. const int32_t ERROR_DISTRIBUTED_OPERATION_FAILED = 1600010; // Distributed operation failed. -const int32_t ERROR_READ_TEMPLATE_CONFIG_FAILED = 1600011; // Read template config failed. +const int32_t ERROR_READ_TEMPLATE_CONFIG_FAILED = 1600011; // Failed to read the template configuration. const int32_t ERROR_NO_MEMORY = 1600012; // No memory space. const int32_t ERROR_DIALOG_IS_POPPING = 1600013; // Enable notification dialog is popping. const int32_t ERROR_NO_RIGHT = 1600014; // No right. diff --git a/frameworks/core/common/include/ans_const_define.h b/frameworks/core/common/include/ans_const_define.h index 0f86e4af86e3d3c8b09b06c2cdb57cf1214c50bf..e957552159ca918169db2dc8226d00485537c496 100644 --- a/frameworks/core/common/include/ans_const_define.h +++ b/frameworks/core/common/include/ans_const_define.h @@ -31,6 +31,7 @@ constexpr uint32_t MAX_ACTIVE_NUM_PERSECOND = 10; constexpr uint32_t MAX_UPDATE_NUM_PERSECOND = 20; constexpr size_t MAX_SLOT_NUM = 5; constexpr uint32_t MAX_ICON_SIZE = 100 * 1024; +constexpr uint32_t MAX_ICON_ENLARGE_SIZE = 192 * 1024; constexpr uint32_t MAX_PICTURE_SIZE = 2 * 1024 * 1024; constexpr uint32_t MAX_LIVE_VIEW_ICON_NUM = 6; constexpr bool SUPPORT_DO_NOT_DISTRUB = true; diff --git a/frameworks/core/common/include/ans_inner_errors.h b/frameworks/core/common/include/ans_inner_errors.h index 8f1e8c1bac7a440131163e5073c44a88a43c49e1..2b300c0eb6073c245b7db1cf594130064db9b686 100644 --- a/frameworks/core/common/include/ans_inner_errors.h +++ b/frameworks/core/common/include/ans_inner_errors.h @@ -114,6 +114,12 @@ static std::map reminderErrCodeMsgMap = { { ERR_REMINDER_CALLER_TOKEN_INVALID, "BussinessError 1700005: The caller token invalid." }, { ERR_REMINDER_DATA_SHARE_PERMISSION_DENIED, "BussinessError 1700006: The data share permission denied." } }; + +// Notification error msg +static inline std::string MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED = "Mandatory parameters are left unspecified."; +static inline std::string INCORRECT_PARAMETER_TYPES = "Incorrect parameter types."; +static inline std::string PARAMETER_VERIFICATION_FAILED = "Parameter verification failed."; + // Common error code const uint32_t ERROR_PERMISSION_DENIED = 201; // No permission to call the interface. const uint32_t ERROR_NOT_SYSTEM_APP = 202; // Not system application to call the interface. @@ -122,16 +128,16 @@ const uint32_t ERROR_SYSTEM_CAP_ERROR = 801; // The specified SystemCa // Notification error code const int32_t ERROR_INTERNAL_ERROR = 1600001; // Internal error. -const int32_t ERROR_IPC_ERROR = 1600002; // marshalling or unmarshalling error. -const int32_t ERROR_SERVICE_CONNECT_ERROR = 1600003; // Failed to connect service. -const int32_t ERROR_NOTIFICATION_CLOSED = 1600004; // Notification is not enabled. -const int32_t ERROR_SLOT_CLOSED = 1600005; // Notification slot is not enabled. -const int32_t ERROR_NOTIFICATION_UNREMOVABLE = 1600006; // Notification is not allowed to remove. -const int32_t ERROR_NOTIFICATION_NOT_EXIST = 1600007; // The notification is not exist. -const int32_t ERROR_USER_NOT_EXIST = 1600008; // The user is not exist. -const int32_t ERROR_OVER_MAX_NUM_PER_SECOND = 1600009; // Over max number notifications per second. +const int32_t ERROR_IPC_ERROR = 1600002; // Marshalling or unmarshalling error. +const int32_t ERROR_SERVICE_CONNECT_ERROR = 1600003; // Failed to connect to the service. +const int32_t ERROR_NOTIFICATION_CLOSED = 1600004; // Notification disabled. +const int32_t ERROR_SLOT_CLOSED = 1600005; // Notification slot disabled. +const int32_t ERROR_NOTIFICATION_UNREMOVABLE = 1600006; // Notification deletion disabled. +const int32_t ERROR_NOTIFICATION_NOT_EXIST = 1600007; // The notification does not exist. +const int32_t ERROR_USER_NOT_EXIST = 1600008; // The user does not exist. +const int32_t ERROR_OVER_MAX_NUM_PER_SECOND = 1600009; // The notification sending frequency reaches the upper limit. const int32_t ERROR_DISTRIBUTED_OPERATION_FAILED = 1600010; // Distributed operation failed. -const int32_t ERROR_READ_TEMPLATE_CONFIG_FAILED = 1600011; // Read template config failed. +const int32_t ERROR_READ_TEMPLATE_CONFIG_FAILED = 1600011; // Failed to read the template configuration. const int32_t ERROR_NO_MEMORY = 1600012; // No memory space. const int32_t ERROR_DIALOG_IS_POPPING = 1600013; // Enable notification dialog is popping. const int32_t ERROR_NO_RIGHT = 1600014; // No right. diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index b8212b88e4bbe938c6ecdc71b9c2c4d0555ae626..b319397214c0e92e1c0d397d372210f5717e374a 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -59,16 +59,18 @@ public: * * @param notificationId Indicates the ID of the notification to cancel. * @param label Indicates the label of the notification to cancel. + * @param instanceKey Indicates the application instance key. * @return Returns cancel notification result. */ - virtual ErrCode Cancel(int notificationId, const std::string &label) = 0; + virtual ErrCode Cancel(int notificationId, const std::string &label, int32_t instanceKey) = 0; /** * @brief Cancels all the published notifications. * + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode CancelAll() = 0; + virtual ErrCode CancelAll(int32_t instanceKey) = 0; /** * @brief Cancels a published agent notification. @@ -170,9 +172,11 @@ public: * @brief Obtains active notifications of the current application in the system. * * @param notifications Indicates active NotificationRequest objects of the current application. + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode GetActiveNotifications(std::vector> ¬ifications) = 0; + virtual ErrCode GetActiveNotifications( + std::vector> ¬ifications, int32_t instanceKey) = 0; /** * @brief Obtains the number of active notifications of the current application in the system. @@ -549,9 +553,10 @@ public: * @brief Cancel notifications according to group. * * @param groupName Indicates the group name. + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode CancelGroup(const std::string &groupName) = 0; + virtual ErrCode CancelGroup(const std::string &groupName, int32_t instanceKey) = 0; /** * @brief Delete notifications according to bundle and group. @@ -786,7 +791,7 @@ public: * @param badgeNumber The badge number. * @return Returns set badge number result. */ - virtual ErrCode SetBadgeNumber(int32_t badgeNumber) = 0; + virtual ErrCode SetBadgeNumber(int32_t badgeNumber, int32_t instanceKey) = 0; /** * @brief Set badge number by bundle. diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 3bd7556bb425838262cf12d56eae3010e6e6566b..216d1493661fd2e15b4d00a25685ea2b0cf76952 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -47,16 +47,18 @@ public: * * @param notificationId Indicates the ID of the notification to cancel. * @param label Indicates the label of the notification to cancel. + * @param instanceKey Indicates the application instance key. * @return Returns cancel notification result. */ - ErrCode Cancel(int32_t notificationId, const std::string &label) override; + ErrCode Cancel(int32_t notificationId, const std::string &label, int32_t instanceKey) override; /** * @brief Cancels all the published notifications. * + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - ErrCode CancelAll() override; + ErrCode CancelAll(int32_t instanceKey) override; /** * @brief Cancels a published agent notification. @@ -157,9 +159,10 @@ public: * @brief Obtains active notifications of the current application in the system. * * @param notifications Indicates active NotificationRequest objects of the current application. + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - ErrCode GetActiveNotifications(std::vector> ¬ifications) override; + ErrCode GetActiveNotifications(std::vector> ¬ifications, int32_t instanceKey) override; /** * @brief Obtains the number of active notifications of the current application in the system. @@ -538,9 +541,10 @@ public: * @brief Cancel notifications according to group. * * @param groupName Indicates the group name. + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - ErrCode CancelGroup(const std::string &groupName) override; + ErrCode CancelGroup(const std::string &groupName, int32_t instanceKey) override; /** * @brief Delete notifications according to bundle and group. @@ -774,7 +778,7 @@ public: * @param badgeNumber The badge number. * @return Returns set badge number result. */ - ErrCode SetBadgeNumber(int32_t badgeNumber) override; + ErrCode SetBadgeNumber(int32_t badgeNumber, int32_t instanceKey) override; /** * @brief Set badge number by bundle. diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index db3e8ef1e81f66a5233b0f33f470b390a04faa8f..5000156ee170178d9926453afb8a659ec2a5f1a8 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -60,16 +60,18 @@ public: * * @param notificationId Indicates the ID of the notification to cancel. * @param label Indicates the label of the notification to cancel. + * @param instanceKey Indicates the application instance key. * @return Returns cancel notification result. */ - virtual ErrCode Cancel(int32_t notificationId, const std::string &label) override; + virtual ErrCode Cancel(int32_t notificationId, const std::string &label, int32_t instanceKey) override; /** * @brief Cancels all the published notifications. * + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode CancelAll() override; + virtual ErrCode CancelAll(int32_t instanceKey) override; /** * @brief Cancels a published agent notification. @@ -174,7 +176,8 @@ public: * @param notifications Indicates active NotificationRequest objects of the current application. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode GetActiveNotifications(std::vector> ¬ifications) override; + virtual ErrCode GetActiveNotifications( + std::vector> ¬ifications, int32_t instanceKey) override; /** * @brief Obtains the number of active notifications of the current application in the system. @@ -538,9 +541,10 @@ public: * @brief Cancel notifications according to group. * * @param groupName Indicates the group name. + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - virtual ErrCode CancelGroup(const std::string &groupName) override; + virtual ErrCode CancelGroup(const std::string &groupName, int32_t instanceKey) override; /** * @brief Delete notifications according to bundle and group. @@ -776,7 +780,7 @@ public: * @param badgeNumber The badge number. * @return Returns set badge number result. */ - virtual ErrCode SetBadgeNumber(int32_t badgeNumber) override; + virtual ErrCode SetBadgeNumber(int32_t badgeNumber, int32_t instanceKey) override; /** * @brief Set badge number by bundle. diff --git a/frameworks/core/src/ans_manager_proxy.cpp b/frameworks/core/src/ans_manager_proxy.cpp index fcf40b81cfca19c5e896a65be63cc96b7192a912..6dff7acae0f4974ed34acff8bff654bb0fa8ec80 100644 --- a/frameworks/core/src/ans_manager_proxy.cpp +++ b/frameworks/core/src/ans_manager_proxy.cpp @@ -78,7 +78,7 @@ ErrCode AnsManagerProxy::Publish(const std::string &label, const sptr> ¬ifications) +ErrCode AnsManagerProxy::GetActiveNotifications( + std::vector> ¬ifications, int32_t instanceKey) { MessageParcel data; if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { @@ -258,6 +269,11 @@ ErrCode AnsManagerProxy::GetActiveNotifications(std::vector> notifications; - ErrCode result = GetActiveNotifications(notifications); + ErrCode result = GetActiveNotifications(notifications, instanceKey); if (!WriteParcelableVector(notifications, reply, result)) { ANS_LOGE("[HandleGetActiveNotifications] fail: write notifications failed"); return ERR_ANS_PARCELABLE_FAILED; @@ -1523,7 +1540,13 @@ ErrCode AnsManagerStub::HandleCancelGroup(MessageParcel &data, MessageParcel &re return ERR_ANS_PARCELABLE_FAILED; } - ErrCode result = CancelGroup(groupName); + int32_t instanceKey = 0; + if (!data.ReadInt32(instanceKey)) { + ANS_LOGE("[HandleCancelGroup] fail: read instanceKey failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = CancelGroup(groupName, instanceKey); if (!reply.WriteInt32(result)) { ANS_LOGE("[HandleCancelGroup] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; @@ -2147,7 +2170,13 @@ ErrCode AnsManagerStub::HandleSetBadgeNumber(MessageParcel &data, MessageParcel return ERR_ANS_PARCELABLE_FAILED; } - ErrCode result = SetBadgeNumber(badgeNumber); + int32_t instanceKey = -1; + if (!data.ReadInt32(instanceKey)) { + ANSR_LOGE("Read instance key failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetBadgeNumber(badgeNumber, instanceKey); if (!reply.WriteInt32(result)) { ANSR_LOGE("Write badge number failed"); return ERR_ANS_PARCELABLE_FAILED; diff --git a/frameworks/core/src/ans_manager_stub_invalid.cpp b/frameworks/core/src/ans_manager_stub_invalid.cpp index 9502a68f83cc462b29f1f256c5b460406041425c..b4a813c6fe5d1643de0ca86e5b1a64716bd943b6 100644 --- a/frameworks/core/src/ans_manager_stub_invalid.cpp +++ b/frameworks/core/src/ans_manager_stub_invalid.cpp @@ -32,13 +32,13 @@ ErrCode AnsManagerStub::Publish(const std::string &label, const sptr return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::GetActiveNotifications(std::vector> ¬ifications) +ErrCode AnsManagerStub::GetActiveNotifications( + std::vector> ¬ifications, int32_t instanceKey) { ANS_LOGE("AnsManagerStub::GetActiveNotifications called!"); return ERR_INVALID_OPERATION; @@ -349,7 +350,7 @@ ErrCode AnsManagerStub::IsSpecialBundleAllowedNotify(const sptrGetNotificationType())) { reqPtr->SetDistributed(false); } + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + reqPtr->SetCreatorInstanceKey(instanceKey); return ansManagerProxy_->Publish(label, reqPtr); } @@ -231,7 +234,8 @@ ErrCode AnsNotification::CancelNotification(const std::string &label, int32_t no ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; } - return ansManagerProxy_->Cancel(notificationId, label); + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + return ansManagerProxy_->Cancel(notificationId, label, instanceKey); } ErrCode AnsNotification::CancelAllNotifications() @@ -242,7 +246,8 @@ ErrCode AnsNotification::CancelAllNotifications() ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; } - return ansManagerProxy_->CancelAll(); + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + return ansManagerProxy_->CancelAll(instanceKey); } ErrCode AnsNotification::CancelAsBundle( @@ -281,7 +286,8 @@ ErrCode AnsNotification::GetActiveNotifications(std::vectorGetActiveNotifications(request); + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + return ansManagerProxy_->GetActiveNotifications(request, instanceKey); } ErrCode AnsNotification::SetNotificationAgent(const std::string &agent) @@ -856,8 +862,8 @@ ErrCode AnsNotification::CancelGroup(const std::string &groupName) ANS_LOGE("GetAnsManagerProxy fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; } - - return ansManagerProxy_->CancelGroup(groupName); + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + return ansManagerProxy_->CancelGroup(groupName, instanceKey); } ErrCode AnsNotification::RemoveGroupByBundle( @@ -1276,19 +1282,19 @@ bool AnsNotification::CanPublishLiveViewContent(const NotificationRequest &reque ErrCode AnsNotification::CheckImageSize(const NotificationRequest &request) { auto littleIcon = request.GetLittleIcon(); - if (NotificationRequest::CheckImageOverSizeForPixelMap(littleIcon, MAX_ICON_SIZE)) { + if (NotificationRequest::CheckImageOverSizeForPixelMap(littleIcon, MAX_ICON_ENLARGE_SIZE)) { ANS_LOGE("The size of little icon exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } auto bigIcon = request.GetBigIcon(); - if (NotificationRequest::CheckImageOverSizeForPixelMap(bigIcon, MAX_ICON_SIZE)) { + if (NotificationRequest::CheckImageOverSizeForPixelMap(bigIcon, MAX_ICON_ENLARGE_SIZE)) { ANS_LOGE("The size of big icon exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } auto overlayIcon = request.GetOverlayIcon(); - if (overlayIcon && NotificationRequest::CheckImageOverSizeForPixelMap(overlayIcon, MAX_ICON_SIZE)) { + if (overlayIcon && NotificationRequest::CheckImageOverSizeForPixelMap(overlayIcon, MAX_ICON_ENLARGE_SIZE)) { ANS_LOGE("The size of overlay icon exceeds limit"); return ERR_ANS_ICON_OVER_SIZE; } @@ -1529,8 +1535,8 @@ ErrCode AnsNotification::SetBadgeNumber(int32_t badgeNumber) ANS_LOGE("SetBadgeNumber fail."); return ERR_ANS_SERVICE_NOT_CONNECTED; } - - return ansManagerProxy_->SetBadgeNumber(badgeNumber); + int32_t instanceKey = DEFAULT_INSTANCE_KEY; + return ansManagerProxy_->SetBadgeNumber(badgeNumber, instanceKey); } ErrCode AnsNotification::SetBadgeNumberByBundle(const NotificationBundleOption &bundleOption, int32_t badgeNumber) diff --git a/frameworks/core/src/ans_subscriber_proxy.cpp b/frameworks/core/src/ans_subscriber_proxy.cpp index 1e9f65b34f0459bdf32b8a28456f5c8f399b89d6..53e283ab9e7838b75515bf843fe14806d81bf3bf 100644 --- a/frameworks/core/src/ans_subscriber_proxy.cpp +++ b/frameworks/core/src/ans_subscriber_proxy.cpp @@ -239,6 +239,11 @@ void AnsSubscriberProxy::OnCanceledList(const std::vector> &n return; } + for (size_t i = 0; i < notifications.size(); i ++) { + sptr notification = notifications[i]; + notification->GetNotificationRequest().SetBigIcon(nullptr); + notification->GetNotificationRequest().SetLittleIcon(nullptr); + } if (!WriteParcelableVector(notifications, data)) { ANS_LOGE("Write notifications failed"); return; diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp index 6f23b83f7109c0e49e33bb03b02c94f3e0978b01..326f4505289f248b9eb135c53399d169bb73ea40 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -464,7 +464,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0100, Function | MediumTest | Level ASSERT_NE(nullptr, proxy); int32_t notificationId = 0; std::string label = "label"; - int32_t result = proxy->Cancel(notificationId, label); + int32_t result = proxy->Cancel(notificationId, label, 0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -485,7 +485,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0200, Function | MediumTest | Level ASSERT_NE(nullptr, proxy); int32_t notificationId = 0; std::string label = ""; - int32_t result = proxy->Cancel(notificationId, label); + int32_t result = proxy->Cancel(notificationId, label, 0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -508,7 +508,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0300, Function | MediumTest | Level ASSERT_NE(nullptr, proxy); int32_t notificationId = 0; std::string label = "label"; - int32_t result = proxy->Cancel(notificationId, label); + int32_t result = proxy->Cancel(notificationId, label, 0); EXPECT_EQ(ERR_OK, result); } /* @@ -529,7 +529,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0400, Function | MediumTest | Level ASSERT_NE(nullptr, proxy); int32_t notificationId = 0; std::string label = "label"; - int32_t result = proxy->Cancel(notificationId, label); + int32_t result = proxy->Cancel(notificationId, label, 0); EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } @@ -552,7 +552,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelTest_0500, Function | MediumTest | Level ASSERT_NE(nullptr, proxy); int32_t notificationId = 0; std::string label = "label"; - int32_t result = proxy->Cancel(notificationId, label); + int32_t result = proxy->Cancel(notificationId, label, 0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -571,7 +571,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0100, Function | MediumTest | Le ASSERT_NE(nullptr, iremoteObject); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t result = proxy->CancelAll(); + int32_t result = proxy->CancelAll(0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -593,7 +593,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0200, Function | MediumTest | Le ERR_OK, true, false, false)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t result = proxy->CancelAll(); + int32_t result = proxy->CancelAll(0); EXPECT_EQ(ERR_OK, result); } /* @@ -612,7 +612,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0300, Function | MediumTest | Le .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t result = proxy->CancelAll(); + int32_t result = proxy->CancelAll(0); EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } @@ -633,7 +633,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelAllTest_0400, Function | MediumTest | Le ERR_OK, false, false, false)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t result = proxy->CancelAll(); + int32_t result = proxy->CancelAll(0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -2000,7 +2000,7 @@ HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0100, Function | Me std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::vector> notifications; - int32_t result = proxy->GetActiveNotifications(notifications); + int32_t result = proxy->GetActiveNotifications(notifications, 0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -2023,7 +2023,7 @@ HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0200, Function | Me std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::vector> notifications; - int32_t result = proxy->GetActiveNotifications(notifications); + int32_t result = proxy->GetActiveNotifications(notifications, 0); EXPECT_EQ(ERR_OK, result); EXPECT_EQ(1, notifications.size()); } @@ -2044,7 +2044,7 @@ HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0300, Function | Me std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::vector> notifications; - int32_t result = proxy->GetActiveNotifications(notifications); + int32_t result = proxy->GetActiveNotifications(notifications, 0); EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } @@ -2066,7 +2066,7 @@ HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0400, Function | Me std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::vector> notifications; - int32_t result = proxy->GetActiveNotifications(notifications); + int32_t result = proxy->GetActiveNotifications(notifications, 0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -2088,7 +2088,7 @@ HWTEST_F(AnsManagerProxyUnitTest, GetActiveNotificationsTest_0500, Function | Me std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); std::vector> notifications; - int32_t result = proxy->GetActiveNotifications(notifications); + int32_t result = proxy->GetActiveNotifications(notifications, 0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -5222,7 +5222,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelGroupTest_0100, Function | MediumTest | ASSERT_NE(nullptr, iremoteObject); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t result = proxy->CancelGroup("GroupName"); + int32_t result = proxy->CancelGroup("GroupName", 0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -5244,7 +5244,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelGroupTest_0200, Function | MediumTest | ERR_OK, true, false, false)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t result = proxy->CancelGroup("GroupName"); + int32_t result = proxy->CancelGroup("GroupName", 0); EXPECT_EQ(ERR_OK, result); } /* @@ -5263,7 +5263,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelGroupTest_0300, Function | MediumTest | .WillRepeatedly(DoAll(Return(DEAD_OBJECT))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t result = proxy->CancelGroup("GroupName"); + int32_t result = proxy->CancelGroup("GroupName", 0); EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } @@ -5284,7 +5284,7 @@ HWTEST_F(AnsManagerProxyUnitTest, CancelGroupTest_0400, Function | MediumTest | ERR_OK, false, false, false)), Return(NO_ERROR))); std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); - int32_t result = proxy->CancelGroup("GroupName"); + int32_t result = proxy->CancelGroup("GroupName", 0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -7661,7 +7661,7 @@ HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberTest_0100, Function | MediumTest std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); int32_t userId = 0; - int32_t result = proxy->SetBadgeNumber(userId); + int32_t result = proxy->SetBadgeNumber(userId, 0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } @@ -7684,7 +7684,7 @@ HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberTest_0200, Function | MediumTest std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); int32_t badgeNumber = 0; - int32_t result = proxy->SetBadgeNumber(badgeNumber); + int32_t result = proxy->SetBadgeNumber(badgeNumber, 0); EXPECT_EQ(ERR_OK, result); } /* @@ -7704,7 +7704,7 @@ HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberTest_0300, Function | MediumTest std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); int32_t badgeNumber = 0; - int32_t result = proxy->SetBadgeNumber(badgeNumber); + int32_t result = proxy->SetBadgeNumber(badgeNumber, 0); EXPECT_EQ(ERR_ANS_TRANSACT_FAILED, result); } @@ -7726,7 +7726,7 @@ HWTEST_F(AnsManagerProxyUnitTest, SetBadgeNumberTest_0400, Function | MediumTest std::shared_ptr proxy = std::make_shared(iremoteObject); ASSERT_NE(nullptr, proxy); int32_t badgeNumber = 0; - int32_t result = proxy->SetBadgeNumber(badgeNumber); + int32_t result = proxy->SetBadgeNumber(badgeNumber, 0); EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp index e06c965aad402d9c68506200dd1803171b51a3d6..1dc95a007cd96bc2bcd8b3b39c2ea4fc1a0dea02 100644 --- a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp @@ -159,10 +159,12 @@ HWTEST_F(AnsManagerStubTest, HandleCancel01, Function | SmallTest | Level1) MessageOption option = {MessageOption::TF_SYNC}; int32_t notificationId = 3; + int32_t instanceKey = 0; std::string label = "this is a notification label"; data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); data.WriteInt32(notificationId); data.WriteString(label); + data.WriteInt32(instanceKey); ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); EXPECT_EQ(ret, (int)NO_ERROR); @@ -223,7 +225,9 @@ HWTEST_F(AnsManagerStubTest, HandleCancelAll01, Function | SmallTest | Level1) MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; + int32_t instanceKey = 0; data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); + data.WriteInt32(instanceKey); ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); EXPECT_EQ(ret, (int)NO_ERROR); @@ -552,8 +556,10 @@ HWTEST_F(AnsManagerStubTest, HandleGetActiveNotifications01, Function | SmallTes MessageParcel reply; MessageOption option = {MessageOption::TF_SYNC}; + int32_t instanceKey = 0; data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - + data.WriteInt32(instanceKey); + ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); EXPECT_EQ(ret, (int)NO_ERROR); } @@ -2251,9 +2257,11 @@ HWTEST_F(AnsManagerStubTest, HandleCancelGroup01, Function | SmallTest | Level1) MessageOption option = {MessageOption::TF_SYNC}; std::string groupName = "this is groupName"; + int32_t instanceKey = 0; data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); data.WriteString(groupName); + data.WriteInt32(instanceKey); ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); EXPECT_EQ(ret, (int)ERR_OK); @@ -3921,7 +3929,7 @@ HWTEST_F(AnsManagerStubTest, CancelGroup01, Function | SmallTest | Level1) { std::string groupName = "this is groupName"; - ErrCode result = ansManagerStub_->CancelGroup(groupName); + ErrCode result = ansManagerStub_->CancelGroup(groupName, 0); EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); } 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 8727c978af8f0b7867042d12434cb2dea1bd05b9..5af94d3f2954660424c2a2be8a0b89d0138682c9 100644 --- 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 @@ -55,12 +55,12 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode Cancel(int notificationId, const std::string &label) override + ErrCode Cancel(int notificationId, const std::string &label, int32_t instanceKey) override { return ERR_ANS_INVALID_PARAM; } - ErrCode CancelAll() override + ErrCode CancelAll(int32_t instanceKey) override { return ERR_ANS_INVALID_PARAM; } @@ -118,7 +118,7 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode GetActiveNotifications(std::vector> ¬ifications) override + ErrCode GetActiveNotifications(std::vector> ¬ifications, int32_t instanceKey) override { return ERR_ANS_INVALID_PARAM; } @@ -331,7 +331,7 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode CancelGroup(const std::string &groupName) override + ErrCode CancelGroup(const std::string &groupName, int32_t instanceKey) override { return ERR_ANS_INVALID_PARAM; } @@ -480,7 +480,7 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode SetBadgeNumber(int32_t badgeNumber) override + ErrCode SetBadgeNumber(int32_t badgeNumber, int32_t instanceKey) override { return ERR_ANS_INVALID_PARAM; } diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 0853354621fc46b8172b88dbc476fc59a4df9e2e..962823834622f0621504011a3a37be6ee77b39bb 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -1691,6 +1691,16 @@ public: */ static napi_value CreateErrorValue(napi_env env, int32_t errCode, bool newType); + /** + * @brief Create a napi value with specified error object for callback + * + * @param env Indicates the environment that the API is invoked under + * @param errCode Indicates specified err code + * @param msg Indicates specified msg + * @return Returns a napi value with specified error object for callback + */ + static napi_value CreateErrorValue(napi_env env, int32_t errCode, std::string &msg); + /** * @brief Sets a js object by specified BadgeNumberCallbackData object * @@ -1714,6 +1724,7 @@ public: const napi_env &env, const napi_value &value, NotificationRequest &request); static bool IsValidRemoveReason(int32_t reasonType); static void NapiThrow(napi_env env, int32_t errCode); + static void NapiThrow(napi_env env, int32_t errCode, std::string &msg); static int32_t ErrorToExternal(uint32_t errCode); static void CreateReturnValue(const napi_env &env, const CallbackPromiseInfo &info, const napi_value &result); static napi_value GetLockScreenPicture( diff --git a/frameworks/js/napi/src/ans_template.cpp b/frameworks/js/napi/src/ans_template.cpp index 5e838a3512d126c632cb0f70afe4674bfef11c69..44ead0a6ca1dfe99fc8e9c6abe14f7a6ccac0aeb 100644 --- a/frameworks/js/napi/src/ans_template.cpp +++ b/frameworks/js/napi/src/ans_template.cpp @@ -14,6 +14,7 @@ */ #include "ans_template.h" +#include "ans_inner_errors.h" namespace OHOS { namespace NotificationNapi { @@ -29,6 +30,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < IS_TEMPLATE_MAX_PARA - 1) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -37,6 +39,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); if (valuetype != napi_string && valuetype != napi_number && valuetype != napi_boolean) { ANS_LOGE("Wrong argument type. String number boolean expected."); + std::string msg = "Incorrect parameter types.The type of param must be string or number or boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } if (valuetype == napi_string) { diff --git a/frameworks/js/napi/src/cancel.cpp b/frameworks/js/napi/src/cancel.cpp index b08b3e14b571118c59ffcc05c3e3681f1fa5b43e..62839d71098f7c93f4cb97198ebb0c4268b24169 100644 --- a/frameworks/js/napi/src/cancel.cpp +++ b/frameworks/js/napi/src/cancel.cpp @@ -15,6 +15,7 @@ #include "cancel.h" #include "js_native_api_types.h" +#include "ans_inner_errors.h" namespace OHOS { namespace NotificationNapi { @@ -34,6 +35,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < 1) { ANS_LOGW("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -42,6 +44,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_number && valuetype != napi_object) { ANS_LOGW("Wrong argument type. Number object expected."); + std::string msg = "Incorrect parameter types.The type of param must be number or object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } @@ -51,6 +55,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, auto retValue = Common::GetBundleOption(env, argv[PARAM0], paras.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } paras.hasOption = true; @@ -65,6 +70,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, if (valuetype != napi_number && valuetype != napi_boolean && valuetype != napi_string && valuetype != napi_function) { ANS_LOGW("Wrong argument type. String or function expected."); + std::string msg = "Incorrect parameter types.The type of param must be string or function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } if (valuetype == napi_number) { @@ -87,6 +94,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_number) { ANS_LOGW("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } NAPI_CALL(env, napi_get_value_int32(env, argv[PARAM1], ¶s.id)); @@ -115,6 +124,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < CANCEL_GROUP_MIN_PARA) { ANS_LOGW("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -123,6 +133,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_string && valuetype != napi_number && valuetype != napi_boolean) { ANS_LOGW("Wrong argument type. String number boolean expected."); + std::string msg = "Incorrect parameter types.The type of param must be number or string or boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } if (valuetype == napi_string) { @@ -347,6 +359,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < 1) { ANS_LOGW("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -355,6 +368,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_number && valuetype != napi_object) { ANS_LOGW("Wrong argument type. Number object expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } if (argc > CANCEL_AS_BUNDLEOPTION_MAX_PARA) { @@ -363,6 +378,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, auto retValue = Common::GetBundleOption(env, argv[PARAM0], paras.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } paras.hasOption = true; @@ -371,6 +387,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_string && valuetype != napi_number && valuetype != napi_boolean) { ANS_LOGW("Wrong argument type. String number boolean expected."); + std::string msg = "Incorrect parameter types.The type of param must be number or string or boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } if (argc > CANCEL_AS_BUNDLEOPTION_MAX_PARA) { @@ -397,6 +415,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); if (valuetype != napi_number) { ANS_LOGW("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_int32(env, argv[PARAM2], ¶s.userId); diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index 19fe85012e6f3c26c2c103bdbe2ed3096e39f289..5d7fbde1e93386b2aa6f929bb32180ad0a741a8e 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -281,6 +281,11 @@ napi_value Common::SetBadgeCallbackData(const napi_env &env, const BadgeNumberCa napi_create_int32(env, data.GetBadgeNumber(), &badgeNapi); napi_set_named_property(env, result, "badgeNumber", badgeNapi); + // instanceKey: int32_t + napi_value keyNapi = nullptr; + napi_create_int32(env, data.GetInstanceKey(), &keyNapi); + napi_set_named_property(env, result, "instanceKey", keyNapi); + return NapiGetBoolean(env, true); } diff --git a/frameworks/js/napi/src/common_convert_notification.cpp b/frameworks/js/napi/src/common_convert_notification.cpp index 266b8d435b4b29ce76dba5a6b5288bb13cb8e454..a847c411dc14bc1561a7f9d8fc0f803f8a1f5ee8 100644 --- a/frameworks/js/napi/src/common_convert_notification.cpp +++ b/frameworks/js/napi/src/common_convert_notification.cpp @@ -139,6 +139,10 @@ napi_value Common::SetNotification( napi_set_named_property(env, result, "creatorUserId", value); } + // readonly creatorInstanceKey?: number + napi_create_int32(env, notification->GetInstanceKey(), &value); + napi_set_named_property(env, result, "creatorInstanceKey", value); + // readonly creatorPid?: number napi_create_int32(env, notification->GetPid(), &value); napi_set_named_property(env, result, "creatorPid", value); diff --git a/frameworks/js/napi/src/common_convert_request.cpp b/frameworks/js/napi/src/common_convert_request.cpp index f298285f87e212a70be9db2b12a586a186e3f87a..e3a62af032bde657b4fef0738f5bd5005fc84f6d 100644 --- a/frameworks/js/napi/src/common_convert_request.cpp +++ b/frameworks/js/napi/src/common_convert_request.cpp @@ -123,6 +123,10 @@ napi_value Common::SetNotificationRequestByNumber( napi_create_uint32(env, request->GetBadgeNumber(), &value); napi_set_named_property(env, result, "badgeNumber", value); + // readonly creatorInstanceKey?: number + napi_create_int32(env, request->GetCreatorInstanceKey(), &value); + napi_set_named_property(env, result, "creatorInstanceKey", value); + return NapiGetBoolean(env, true); } diff --git a/frameworks/js/napi/src/common_utils.cpp b/frameworks/js/napi/src/common_utils.cpp index bcf3826b51751f66db350e63335723c4aa7c5049..74568771c0caf52930f7d2ccefb22e8129465c48 100644 --- a/frameworks/js/napi/src/common_utils.cpp +++ b/frameworks/js/napi/src/common_utils.cpp @@ -37,15 +37,15 @@ static const std::unordered_map ERROR_CODE_MESSAGE { {ERROR_SYSTEM_CAP_ERROR, "SystemCapability not found"}, {ERROR_INTERNAL_ERROR, "Internal error"}, {ERROR_IPC_ERROR, "Marshalling or unmarshalling error"}, - {ERROR_SERVICE_CONNECT_ERROR, "Failed to connect service"}, - {ERROR_NOTIFICATION_CLOSED, "Notification is not enabled"}, - {ERROR_SLOT_CLOSED, "Notification slot is not enabled"}, - {ERROR_NOTIFICATION_UNREMOVABLE, "Notification is not allowed to remove"}, - {ERROR_NOTIFICATION_NOT_EXIST, "The notification is not exist"}, - {ERROR_USER_NOT_EXIST, "The user is not exist"}, - {ERROR_OVER_MAX_NUM_PER_SECOND, "Over max number notifications per second"}, + {ERROR_SERVICE_CONNECT_ERROR, "Failed to connect to the service"}, + {ERROR_NOTIFICATION_CLOSED, "Notification disabled"}, + {ERROR_SLOT_CLOSED, "Notification slot disabled"}, + {ERROR_NOTIFICATION_UNREMOVABLE, "Notification deletion disabled"}, + {ERROR_NOTIFICATION_NOT_EXIST, "The notification does not exist"}, + {ERROR_USER_NOT_EXIST, "The user does not exist"}, + {ERROR_OVER_MAX_NUM_PER_SECOND, "The notification sending frequency reaches the upper limit"}, {ERROR_DISTRIBUTED_OPERATION_FAILED, "Distributed operation failed"}, - {ERROR_READ_TEMPLATE_CONFIG_FAILED, "Read template config failed"}, + {ERROR_READ_TEMPLATE_CONFIG_FAILED, "Failed to read the template configuration"}, {ERROR_NO_MEMORY, "No memory space"}, {ERROR_BUNDLE_NOT_FOUND, "The specified bundle name was not found"}, {ERROR_NO_AGENT_SETTING, "There is no corresponding agent relationship configuration"}, @@ -94,6 +94,27 @@ napi_value Common::CreateErrorValue(napi_env env, int32_t errCode, bool newType) return error; } +napi_value Common::CreateErrorValue(napi_env env, int32_t errCode, std::string &msg) +{ + ANS_LOGI("enter, errorCode[%{public}d]", errCode); + napi_value error = Common::NapiGetNull(env); + if (errCode == ERR_OK) { + return error; + } + + napi_value code = nullptr; + napi_create_int32(env, errCode, &code); + + auto iter = ERROR_CODE_MESSAGE.find(errCode); + std::string errMsg = iter != ERROR_CODE_MESSAGE.end() ? iter->second : ""; + napi_value message = nullptr; + napi_create_string_utf8(env, errMsg.append(" ").append(msg).c_str(), NAPI_AUTO_LENGTH, &message); + + napi_create_error(env, nullptr, message, &error); + napi_set_named_property(env, error, "code", code); + return error; +} + void Common::NapiThrow(napi_env env, int32_t errCode) { ANS_LOGD("enter"); @@ -101,6 +122,13 @@ void Common::NapiThrow(napi_env env, int32_t errCode) napi_throw(env, CreateErrorValue(env, errCode, true)); } +void Common::NapiThrow(napi_env env, int32_t errCode, std::string &msg) +{ + ANS_LOGD("enter"); + + napi_throw(env, CreateErrorValue(env, errCode, msg)); +} + napi_value Common::GetCallbackErrorValue(napi_env env, int32_t errCode) { napi_value result = nullptr; @@ -219,6 +247,7 @@ napi_value Common::ParseParaOnlyCallback(const napi_env &env, const napi_callbac NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < ONLY_CALLBACK_MIN_PARA) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } diff --git a/frameworks/js/napi/src/display_badge.cpp b/frameworks/js/napi/src/display_badge.cpp index 37ee4330c12a01aaf8c7d581f73e1bd1512312c5..a9bd573755915e6cb9e7953dd1be2019c65c32bf 100644 --- a/frameworks/js/napi/src/display_badge.cpp +++ b/frameworks/js/napi/src/display_badge.cpp @@ -14,6 +14,7 @@ */ #include "display_badge.h" +#include "ans_inner_errors.h" namespace OHOS { namespace NotificationNapi { @@ -32,6 +33,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < ENABLE_BADGE_DISPLAYED_MIN_PARA) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -40,12 +42,15 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Wrong argument type. Object expected"); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -53,6 +58,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_boolean) { ANS_LOGW("Wrong argument type. Bool expected."); + std::string msg = "Incorrect parameter types.The type of param must be boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); @@ -81,6 +88,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, if (argc < IS_DISPLAY_BADGE_MIN_PARA) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -90,6 +98,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, if ((valuetype != napi_function) && (valuetype != napi_object)) { ANS_LOGW("Wrong argument type. Function or object expected, %{public}d", valuetype); + std::string msg = "Incorrect parameter types.The type of param must be function or object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } @@ -97,6 +107,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } params.hasBundleOption = true; diff --git a/frameworks/js/napi/src/distributed.cpp b/frameworks/js/napi/src/distributed.cpp index 44d80c4fd389deaa3ff1af0d39a2a4eb3715cbfe..540b07a0da442d3a007650d37ad9a46d87610789 100644 --- a/frameworks/js/napi/src/distributed.cpp +++ b/frameworks/js/napi/src/distributed.cpp @@ -14,6 +14,7 @@ */ #include "distributed.h" +#include "ans_inner_errors.h" namespace OHOS { namespace NotificationNapi { @@ -36,6 +37,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < ENABLED_MIN_PARA) { ANS_LOGE("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } napi_valuetype valuetype = napi_undefined; @@ -44,6 +46,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_boolean) { ANS_LOGE("Wrong argument type. Bool expected."); + std::string msg = "Incorrect parameter types.The type of param must be boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_bool(env, argv[PARAM0], ¶ms.enable); @@ -71,6 +75,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < ENABLED_BUNDLE_MIN_PARA) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -79,11 +84,14 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type. Object expected"); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -91,6 +99,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_boolean) { ANS_LOGE("Wrong argument type. Bool expected."); + std::string msg = "Incorrect parameter types.The type of param must be boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); @@ -118,6 +128,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < IS_ENABLED_BUNDLE_MIN_PARA) { ANS_LOGE("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -126,11 +137,14 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Parameter type error. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -143,6 +157,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_get_value_string_utf8(env, argv[PARAM1], str, STR_MAX_SIZE - 1, &strLen); if (std::strlen(str) == 0) { ANS_LOGE("Property deviceType is empty"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } params.deviceType = str; @@ -151,6 +166,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_create_reference(env, argv[PARAM1], 1, ¶ms.callback); } else { ANS_LOGE("Property is error"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } } @@ -585,6 +601,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr)); if (argc < ENABLED_SYNC_MIN_PARA) { ANS_LOGE("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -593,11 +610,14 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_number) { ANS_LOGE("Argument type error. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } NAPI_CALL(env, napi_get_value_int32(env, argv[PARAM0], ¶ms.userId)); if (params.userId <= SUBSCRIBE_USER_INIT) { ANS_LOGE("Wrong userId[%{public}d].", params.userId); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -605,6 +625,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_boolean) { ANS_LOGE("Wrong argument type. Bool expected."); + std::string msg = "Incorrect parameter types.The type of param must be boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); @@ -694,6 +716,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < ENABLED_SYNC_MIN_PARA - 1) { ANS_LOGE("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -702,11 +725,14 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_number) { ANS_LOGE("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } NAPI_CALL(env, napi_get_value_int32(env, argv[PARAM0], ¶ms.userId)); if (params.userId <= SUBSCRIBE_USER_INIT) { ANS_LOGE("Wrong userId[%{public}d].", params.userId); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } diff --git a/frameworks/js/napi/src/disturb_mode.cpp b/frameworks/js/napi/src/disturb_mode.cpp index 358a5dea7de1965abcbcbfee3a717d58103adee0..a46f52c7c9e762fdc13cbd3757fa7976861d96de 100644 --- a/frameworks/js/napi/src/disturb_mode.cpp +++ b/frameworks/js/napi/src/disturb_mode.cpp @@ -14,6 +14,7 @@ */ #include "disturb_mode.h" +#include "ans_inner_errors.h" namespace OHOS { namespace NotificationNapi { @@ -34,12 +35,15 @@ napi_value GetDoNotDisturbDate(const napi_env &env, const napi_value &argv, SetD NAPI_CALL(env, napi_has_named_property(env, argv, "type", &hasProperty)); if (!hasProperty) { ANS_LOGW("Wrong argument type. Property type expected."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } napi_get_named_property(env, argv, "type", &value); NAPI_CALL(env, napi_typeof(env, value, &valuetype)); if (valuetype != napi_number) { ANS_LOGW("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } int type = 0; @@ -47,6 +51,7 @@ napi_value GetDoNotDisturbDate(const napi_env &env, const napi_value &argv, SetD napi_get_value_int32(env, value, &type); ANS_LOGI("type is: %{public}d", type); if (!AnsEnumUtil::DoNotDisturbTypeJSToC(DoNotDisturbType(type), outType)) { + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } params.date.SetDoNotDisturbType(outType); @@ -55,6 +60,7 @@ napi_value GetDoNotDisturbDate(const napi_env &env, const napi_value &argv, SetD NAPI_CALL(env, napi_has_named_property(env, argv, "begin", &hasProperty)); if (!hasProperty) { ANS_LOGW("Wrong argument type. Property type expected."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } double begin = 0; @@ -63,6 +69,8 @@ napi_value GetDoNotDisturbDate(const napi_env &env, const napi_value &argv, SetD napi_is_date(env, value, &isDate); if (!isDate) { ANS_LOGE("Wrong argument type. Date expected."); + std::string msg = "Incorrect parameter types.The type of param must be date."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_date_value(env, value, &begin); @@ -72,6 +80,7 @@ napi_value GetDoNotDisturbDate(const napi_env &env, const napi_value &argv, SetD NAPI_CALL(env, napi_has_named_property(env, argv, "end", &hasProperty)); if (!hasProperty) { ANS_LOGW("Wrong argument type. Property type expected."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } double end = 0; @@ -80,6 +89,8 @@ napi_value GetDoNotDisturbDate(const napi_env &env, const napi_value &argv, SetD napi_is_date(env, value, &isDate); if (!isDate) { ANS_LOGE("Wrong argument type. Date expected."); + std::string msg = "Incorrect parameter types.The type of param must be date."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_date_value(env, value, &end); @@ -184,6 +195,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < SET_DISTURB_MIN_PARA) { ANS_LOGW("Wrong argument type. Property type expected."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -192,9 +204,11 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Wrong argument type. Property type expected."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } if (GetDoNotDisturbDate(env, argv[PARAM0], params) == nullptr) { + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -237,6 +251,7 @@ bool ParseProfilesParameters( NAPI_CALL_BASE(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL), false); if (argc != DISTURB_PROFILES_PARA) { ANS_LOGE("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return false; } napi_valuetype valuetype = napi_undefined; @@ -244,12 +259,16 @@ bool ParseProfilesParameters( napi_is_array(env, argv[PARAM0], &isArray); if (!isArray) { ANS_LOGE("Wrong argument type. Array expected."); + std::string msg = "Incorrect parameter types.The type of param must be array."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return false; } uint32_t length = 0; napi_get_array_length(env, argv[PARAM0], &length); if (length == 0) { ANS_LOGD("The array is empty."); + std::string msg = "Mandatory parameters are left unspecified. The array is empty."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return false; } for (size_t index = 0; index < length; index++) { @@ -258,6 +277,8 @@ bool ParseProfilesParameters( NAPI_CALL_BASE(env, napi_typeof(env, nProfile, &valuetype), false); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return false; } sptr profile = new (std::nothrow) NotificationDoNotDisturbProfile(); diff --git a/frameworks/js/napi/src/enable_notification.cpp b/frameworks/js/napi/src/enable_notification.cpp index d71c9ce11de4819406e4c6e367b1fb9cd55fb94b..5f5d9bc9517d77d51c91713a85c1e7d655089a07 100644 --- a/frameworks/js/napi/src/enable_notification.cpp +++ b/frameworks/js/napi/src/enable_notification.cpp @@ -39,6 +39,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < ENABLE_NOTIFICATION_MIN_PARA) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -47,11 +48,14 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Parameter type error. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -59,6 +63,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_boolean) { ANS_LOGW("Wrong argument type. Bool expected."); + std::string msg = "Incorrect parameter types.The type of param must be boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); @@ -100,6 +106,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } params.hasBundleOption = true; diff --git a/frameworks/js/napi/src/manager/local_live_view_subscribe.cpp b/frameworks/js/napi/src/manager/local_live_view_subscribe.cpp index 26bb7fb2b4ba354bb8d395a2407ff8b3632f78b1..2804b1d19d42270073810e53eaf4d9702e2c4155 100644 --- a/frameworks/js/napi/src/manager/local_live_view_subscribe.cpp +++ b/frameworks/js/napi/src/manager/local_live_view_subscribe.cpp @@ -15,7 +15,7 @@ #include "local_live_view_subscribe.h" #include "notification_button_option.h" - +#include "ans_inner_errors.h" #include #include @@ -206,6 +206,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, onResponse, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, onResponse, 1, &result); @@ -266,6 +268,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < 1) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -275,6 +278,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type for arg0. LocalLiveViewButton object expected."); + std::string msg = "Incorrect parameter types.The type of param must be LocalLiveViewButton."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } @@ -282,6 +287,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, if (!HasNotificationSubscriber(env, argv[PARAM0], subscriberInstancesInfo)) { if (GetNotificationSubscriber(env, argv[PARAM0], subscriberInstancesInfo) == nullptr) { ANS_LOGE("LocalLiveViewButton parse failed"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); if (subscriberInstancesInfo.subscriber) { delete subscriberInstancesInfo.subscriber; subscriberInstancesInfo.subscriber = nullptr; @@ -290,6 +296,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, } if (!AddSubscriberInstancesInfo(env, subscriberInstancesInfo)) { ANS_LOGE("AddSubscriberInstancesInfo add failed"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); if (subscriberInstancesInfo.subscriber) { delete subscriberInstancesInfo.subscriber; subscriberInstancesInfo.subscriber = nullptr; diff --git a/frameworks/js/napi/src/manager/napi_display_badge.cpp b/frameworks/js/napi/src/manager/napi_display_badge.cpp index 86fc33e563fb5e783a11131b245100e01e50ba1f..a48f94a3a41ceb16c189314eaf63441a79d42ec2 100644 --- a/frameworks/js/napi/src/manager/napi_display_badge.cpp +++ b/frameworks/js/napi/src/manager/napi_display_badge.cpp @@ -177,6 +177,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < SET_BADGE_NUMBER_MIN_PARA) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -187,6 +188,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, if (valuetype == napi_object) { if (argc != SET_BADGE_NUMBER_BY_BUNDLE_PARA) { ANS_LOGE("Wrong number of arguments. Expect exactly two."); + std::string msg = "Mandatory parameters are left unspecified. Expect exactly two."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } Common::GetBundleOption(env, argv[PARAM0], params.option); @@ -194,6 +197,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_number) { ANS_LOGE("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_int32(env, argv[PARAM1], ¶ms.badgeNumber); @@ -202,6 +207,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // case2: setBadgeNumber(badgeNumber) if (valuetype != napi_number) { ANS_LOGW("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_int32(env, argv[PARAM0], ¶ms.badgeNumber); @@ -296,7 +303,7 @@ napi_value NapiSetBadgeNumberByBundle(napi_env env, napi_callback_info info) AsyncCallbackSetBadgeNumber *asyncCallbackInfo = new (std::nothrow) AsyncCallbackSetBadgeNumber {.env = env, .asyncWork = nullptr, .params = params}; if (asyncCallbackInfo == nullptr) { - Common::NapiThrow(env, ERROR_PARAM_INVALID); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return Common::NapiGetUndefined(env); } napi_value promise = nullptr; diff --git a/frameworks/js/napi/src/manager/napi_distributed_enable.cpp b/frameworks/js/napi/src/manager/napi_distributed_enable.cpp index 8c787ca17d574ad5ed6cc7fe3ec938f4e9057b24..51201d61cb92de613278119a268c1f5f307a76fd 100644 --- a/frameworks/js/napi/src/manager/napi_distributed_enable.cpp +++ b/frameworks/js/napi/src/manager/napi_distributed_enable.cpp @@ -35,6 +35,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < SET_DISTRIBUTED_ENABLE_MIN_PARA) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -43,11 +44,14 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Parameter type error. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -55,6 +59,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_string) { ANS_LOGW("Wrong argument type. Bool expected."); + std::string msg = "Incorrect parameter types.The type of param must be boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } char str[STR_MAX_SIZE] = {0}; @@ -62,6 +68,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_get_value_string_utf8(env, argv[PARAM1], str, STR_MAX_SIZE - 1, &strLen); if (std::strlen(str) == 0) { ANS_LOGE("Property deviceType is empty"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } params.deviceType = str; @@ -71,6 +78,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); if (valuetype != napi_boolean) { ANS_LOGW("Wrong argument type. Bool expected."); + std::string msg = "Incorrect parameter types.The type of param must be boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_bool(env, argv[PARAM2], ¶ms.enable); @@ -171,6 +180,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < SET_SMART_REMINDER_ENABLE_MIN_PARA) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -179,6 +189,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_string) { ANS_LOGW("Wrong argument type. String expected."); + std::string msg = "Incorrect parameter types.The type of param must be string."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } char str[STR_MAX_SIZE] = {0}; @@ -186,6 +198,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, napi_get_value_string_utf8(env, argv[PARAM0], str, STR_MAX_SIZE - 1, &strLen); if (std::strlen(str) == 0) { ANS_LOGE("Property deviceType is empty"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } params.deviceType = str; @@ -195,6 +208,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_boolean) { ANS_LOGW("Wrong argument type. Bool expected."); + std::string msg = "Incorrect parameter types.The type of param must be boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_bool(env, argv[PARAM1], ¶ms.enable); diff --git a/frameworks/js/napi/src/manager/napi_disturb_mode.cpp b/frameworks/js/napi/src/manager/napi_disturb_mode.cpp index 4c73a1d80c09dd178fba5ab222e8e398d6d44845..b37508f04e430af7ac0ad2a8b938b50d4273ed75 100644 --- a/frameworks/js/napi/src/manager/napi_disturb_mode.cpp +++ b/frameworks/js/napi/src/manager/napi_disturb_mode.cpp @@ -150,7 +150,7 @@ napi_value NapiRemoveDoNotDisturbProfiles(napi_env env, napi_callback_info info) // Asynchronous function call napi_create_async_work(env, nullptr, resourceName, [](napi_env env, void *data) { - ANS_LOGE("Napi remove do not disturb profiles work excute."); + ANS_LOGD("Napi remove do not disturb profiles work excute."); AsyncCallbackInfoDoNotDisturbProfile *asynccallbackinfo = static_cast(data); if (asynccallbackinfo) { @@ -159,7 +159,7 @@ napi_value NapiRemoveDoNotDisturbProfiles(napi_env env, napi_callback_info info) } }, [](napi_env env, napi_status status, void *data) { - ANS_LOGE("Napi remove do not disturb profiles work complete."); + ANS_LOGD("Napi remove do not disturb profiles work complete."); AsyncCallbackInfoDoNotDisturbProfile *asynccallbackinfo = static_cast(data); if (asynccallbackinfo) { diff --git a/frameworks/js/napi/src/manager/napi_enable_notification.cpp b/frameworks/js/napi/src/manager/napi_enable_notification.cpp index c085a8066c6c22a6c560064e36a51db9cdbf46b2..cb98d1009c86549ca4fb7e3410008f70286bc5d3 100644 --- a/frameworks/js/napi/src/manager/napi_enable_notification.cpp +++ b/frameworks/js/napi/src/manager/napi_enable_notification.cpp @@ -362,6 +362,8 @@ napi_value ParseRequestEnableParameters(const napi_env &env, const napi_callback params.hasCallerToken = true; } else { ANS_LOGE("Only support stage mode"); + std::string msg = "Incorrect parameter types.Only support stage mode."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } } else { diff --git a/frameworks/js/napi/src/manager/napi_get_active.cpp b/frameworks/js/napi/src/manager/napi_get_active.cpp index 99a30d5c2e628d6093a78b2fd9b7a2bfdbf29464..7d73cf03b7b818dfdf21fc677a1072ca2476f268 100644 --- a/frameworks/js/napi/src/manager/napi_get_active.cpp +++ b/frameworks/js/napi/src/manager/napi_get_active.cpp @@ -342,16 +342,20 @@ napi_value ParseGetLiveViewParams(const napi_env &env, const napi_callback_info NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); if (argc < ARGS_ONE) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } // argv[0] : filter if (!AppExecFwk::IsTypeForNapiValue(env, argv[0], napi_object)) { ANS_LOGE("Wrong filter type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } if (ParseGetLiveViewFilter(env, argv[0], filter) == nullptr) { ANS_LOGE("Parse filter from param failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } diff --git a/frameworks/js/napi/src/manager/napi_local_live_view.cpp b/frameworks/js/napi/src/manager/napi_local_live_view.cpp index 1f55e7715490b6bac399e4f0d31cd507b81fa01e..174b3da0f7b7771cc5585f8ddba914c325d4032d 100644 --- a/frameworks/js/napi/src/manager/napi_local_live_view.cpp +++ b/frameworks/js/napi/src/manager/napi_local_live_view.cpp @@ -119,6 +119,7 @@ napi_value ParseTriggerParameters(const napi_env &env, const napi_callback_info NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc != TRIGGER_PARA) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -128,6 +129,7 @@ napi_value ParseTriggerParameters(const napi_env &env, const napi_callback_info auto retValue = Common::GetBundleOption(env, argv[PARAM0], asynccallbackinfo->bundleOption); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -135,6 +137,8 @@ napi_value ParseTriggerParameters(const napi_env &env, const napi_callback_info NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_number) { ANS_LOGE("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_int32(env, argv[PARAM1], ¬ificationId); @@ -145,6 +149,7 @@ napi_value ParseTriggerParameters(const napi_env &env, const napi_callback_info retValue = Common::GetButtonOption(env, argv[PARAM2], asynccallbackinfo->buttonOption); if (retValue == nullptr) { ANS_LOGE("GetButtonOption failed"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } return Common::NapiGetNull(env); diff --git a/frameworks/js/napi/src/manager/napi_remove_group.cpp b/frameworks/js/napi/src/manager/napi_remove_group.cpp index c340db6078f4bb3855da4e6cf598d317217e0bc0..07845ea4727f5611d41a72f95900815089934c53 100644 --- a/frameworks/js/napi/src/manager/napi_remove_group.cpp +++ b/frameworks/js/napi/src/manager/napi_remove_group.cpp @@ -36,6 +36,7 @@ napi_value ParseParameters( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < REMOVE_GROUP_BY_BUNDLE_MIN_PARA) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -43,11 +44,14 @@ napi_value ParseParameters( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Argument type error. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -55,6 +59,8 @@ napi_value ParseParameters( NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_string && valuetype != napi_number && valuetype != napi_boolean) { ANS_LOGW("Wrong argument type. String number boolean expected."); + std::string msg = "Incorrect parameter types.The type of param must be string or number or boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } if (valuetype == napi_string) { diff --git a/frameworks/js/napi/src/manager/napi_sync_config.cpp b/frameworks/js/napi/src/manager/napi_sync_config.cpp index 9e571c45c7fa78fbeb57a44ef0474d2394d87d5e..b0eb5b3f5a6f8f0dcf710f5c88eaf8622f537291 100644 --- a/frameworks/js/napi/src/manager/napi_sync_config.cpp +++ b/frameworks/js/napi/src/manager/napi_sync_config.cpp @@ -50,6 +50,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < SETADDITION_CONFIG_NUM) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -58,6 +59,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_string) { ANS_LOGW("Argument type error. String expected."); + std::string msg = "Incorrect parameter types.The type of param must be string."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } char keyStr[STR_MAX_SIZE] = {0}; @@ -67,6 +70,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, if (std::strlen(keyStr) == 0 || (strcmp(keyStr, KEY_NAME) != 0 && strcmp(keyStr, RING_LIST_KEY_NAME) != 0)) { ANS_LOGW("Argument type error. String expected."); + std::string msg = "Incorrect parameter types.The type of param must be string."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } @@ -74,6 +79,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_string) { ANS_LOGW("Argument type error. String expected."); + std::string msg = "Incorrect parameter types.The type of param must be string."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } diff --git a/frameworks/js/napi/src/publish.cpp b/frameworks/js/napi/src/publish.cpp index 17b6d9b869d9335ad6dbb4b3709cee73268eb64d..74a187cd332ae7306ef8f0de4e4b2fee11d3d332 100644 --- a/frameworks/js/napi/src/publish.cpp +++ b/frameworks/js/napi/src/publish.cpp @@ -18,6 +18,7 @@ #include "ans_const_define.h" #include "js_native_api_types.h" #include "want_agent_helper.h" +#include "ans_inner_errors.h" namespace OHOS { namespace NotificationNapi { @@ -54,6 +55,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); if (argc < 1) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -61,6 +63,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Argument type error. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } @@ -195,6 +199,8 @@ napi_value GetStringProperty( NAPI_CALL(env, napi_typeof(env, value, &valuetype)); if (valuetype != napi_string) { ANS_LOGW("Wrong argument type. String expected."); + std::string msg = "Incorrect parameter types.The type of param must be string."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } NAPI_CALL(env, napi_get_value_string_utf8(env, value, str, STR_MAX_SIZE - 1, &strLen)); @@ -217,6 +223,8 @@ napi_value GetObjectProperty( NAPI_CALL(env, napi_typeof(env, result, &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } return Common::NapiGetNull(env); @@ -231,6 +239,7 @@ napi_value ParseShowOptions(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); if (argc == 0) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -239,6 +248,8 @@ napi_value ParseShowOptions(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } @@ -367,6 +378,7 @@ napi_value ParsePublishAsBundleParameters( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); if (argc < 1) { ANS_LOGW("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } // argv[0] : NotificationRequest / bundleOption @@ -374,6 +386,8 @@ napi_value ParsePublishAsBundleParameters( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } @@ -386,6 +400,7 @@ napi_value ParsePublishAsBundleParameters( auto retValue = Common::GetBundleOption(env, argv[PARAM0], option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } params.request.SetOwnerBundleName(option.GetBundleName()); @@ -397,6 +412,8 @@ napi_value ParsePublishAsBundleParameters( NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_string && valuetype != napi_number && valuetype != napi_boolean && valuetype != napi_object) { ANS_LOGW("Error argument type. String number boolean object expected."); + std::string msg = "Incorrect parameter types.The type of param must be string or number or boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } if (argc > PUBLISH_AS_BUNDLEOPTION_MAX) { @@ -425,6 +442,8 @@ napi_value ParsePublishAsBundleParameters( NAPI_CALL(env, napi_typeof(env, argv[PARAM2], &valuetype)); if (valuetype != napi_number) { ANS_LOGW("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } int32_t userId = 0; diff --git a/frameworks/js/napi/src/remove.cpp b/frameworks/js/napi/src/remove.cpp index 21c472d5dc7231f3aa7f4261cb5c39bf55b98ba1..c17195a3578be82a6905a1f531c049f72fce9680 100644 --- a/frameworks/js/napi/src/remove.cpp +++ b/frameworks/js/napi/src/remove.cpp @@ -15,6 +15,7 @@ #include #include "remove.h" +#include "ans_inner_errors.h" namespace OHOS { namespace NotificationNapi { @@ -137,6 +138,7 @@ bool ParseParameters(const napi_env &env, const napi_callback_info &info, Remove NAPI_CALL_BASE(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL), false); if (argc < REMOVE_MIN_PARA) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return false; } bool isArray = false; @@ -146,6 +148,8 @@ bool ParseParameters(const napi_env &env, const napi_callback_info &info, Remove if ((valueType != napi_string) && (valueType != napi_object) && (valueType != napi_number) && (valueType != napi_boolean) && !isArray) { ANS_LOGW("Wrong argument type. String or object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object or string."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return false; } if ((valueType == napi_string) || (valueType == napi_number) || (valueType == napi_boolean) || isArray) { @@ -179,6 +183,7 @@ napi_value ParseParametersByRemoveAll(const napi_env &env, const napi_callback_i auto retValue = Common::GetBundleOption(env, argv[PARAM0], bundleandKeyInfo.option); if (retValue == nullptr) { ANS_LOGW("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } params.bundleAndKeyInfo = bundleandKeyInfo; @@ -214,6 +219,7 @@ napi_value ParseParameters( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < REMOVE_GROUP_BY_BUNDLE_MIN_PARA) { ANS_LOGW("Error number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -221,11 +227,14 @@ napi_value ParseParameters( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Valuetype is not object."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -233,6 +242,8 @@ napi_value ParseParameters( NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_string && valuetype != napi_number && valuetype != napi_boolean) { ANS_LOGW("Error argument type. String number boolean anticipate."); + std::string msg = "Incorrect parameter types.The type of param must be string or number or boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } if (valuetype == napi_string) { diff --git a/frameworks/js/napi/src/slot.cpp b/frameworks/js/napi/src/slot.cpp index 2ecca95aca3e57e0192eb0e347b47119d2cb6f6f..bb21ed657b6bdff2efd29b36231acd9ca524fa36 100644 --- a/frameworks/js/napi/src/slot.cpp +++ b/frameworks/js/napi/src/slot.cpp @@ -16,6 +16,7 @@ #include "slot.h" #include "common.h" #include "napi_common_util.h" +#include "ans_inner_errors.h" namespace OHOS { namespace NotificationNapi { @@ -214,6 +215,7 @@ napi_value ParseParametersByAddSlot(const napi_env &env, const napi_callback_inf NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < 1) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -222,6 +224,8 @@ napi_value ParseParametersByAddSlot(const napi_env &env, const napi_callback_inf NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object && valuetype != napi_number) { ANS_LOGE("Wrong argument type. Object or number expected."); + std::string msg = "Incorrect parameter types.The type of param must be object or number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } if (valuetype == napi_number) { @@ -261,6 +265,7 @@ napi_value ParseParametersByAddSlots(const napi_env &env, const napi_callback_in NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < 1) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -270,12 +275,16 @@ napi_value ParseParametersByAddSlots(const napi_env &env, const napi_callback_in napi_is_array(env, argv[PARAM0], &isArray); if (!isArray) { ANS_LOGE("Wrong argument type. Array expected."); + std::string msg = "Incorrect parameter types.The type of param must be array."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } uint32_t length = 0; napi_get_array_length(env, argv[PARAM0], &length); if (length == 0) { ANS_LOGE("The array is empty."); + std::string msg = "Mandatory parameters are left unspecified. The array is empty."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } for (size_t i = 0; i < length; i++) { @@ -284,6 +293,8 @@ napi_value ParseParametersByAddSlots(const napi_env &env, const napi_callback_in NAPI_CALL(env, napi_typeof(env, nSlot, &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } NotificationSlot slot; @@ -318,6 +329,7 @@ napi_value ParseParametersSetSlotByBundle( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < SET_SLOT_AS_BUNDLE_MAX_PARA - 1) { ANS_LOGE("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -325,11 +337,14 @@ napi_value ParseParametersSetSlotByBundle( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Argument type error. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -337,6 +352,8 @@ napi_value ParseParametersSetSlotByBundle( NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } NotificationSlot slot; @@ -350,6 +367,8 @@ napi_value ParseParametersSetSlotByBundle( sptr slotPtr = new (std::nothrow) NotificationSlot(vec); if (slotPtr == nullptr) { ANS_LOGE("Failed to create NotificationSlot ptr"); + std::string msg = "Parameter verification failed. Failed to create NotificationSlot ptr"; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } params.slots.emplace_back(slotPtr); @@ -377,6 +396,7 @@ napi_value ParseParametersByGetSlot(const napi_env &env, const napi_callback_inf NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < 1) { ANS_LOGE("Error number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -385,6 +405,8 @@ napi_value ParseParametersByGetSlot(const napi_env &env, const napi_callback_inf NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_number) { ANS_LOGE("Error argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } int32_t slotType = 0; @@ -417,6 +439,7 @@ napi_value ParseParametersGetSlotNumByBundle( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < GET_SLOT_NUM_AS_BUNDLE_MAX_PARA - 1) { ANS_LOGE("Error number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -424,11 +447,14 @@ napi_value ParseParametersGetSlotNumByBundle( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Argument type is error. Object anticipate."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -458,6 +484,7 @@ napi_value ParseParametersSetSlotFlagsByBundle( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < SET_SLOT_AS_BUNDLE_MAX_PARA - 1) { ANS_LOGE("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -465,11 +492,14 @@ napi_value ParseParametersSetSlotFlagsByBundle( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Argument type error. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -507,6 +537,7 @@ napi_value ParseParametersGetSlotFlagsByBundle( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < GET_SLOTS_AS_BUNDLE_MAX_PARA - 1) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -514,11 +545,14 @@ napi_value ParseParametersGetSlotFlagsByBundle( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -547,6 +581,7 @@ napi_value ParseParametersGetSlotsByBundle( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < GET_SLOTS_AS_BUNDLE_MAX_PARA - 1) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -554,11 +589,14 @@ napi_value ParseParametersGetSlotsByBundle( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -587,6 +625,7 @@ napi_value ParseParametersGetSlotByBundle( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < GET_SLOT_AS_BUNDLE_MAX_PARA - 1) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -594,11 +633,14 @@ napi_value ParseParametersGetSlotByBundle( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -606,6 +648,8 @@ napi_value ParseParametersGetSlotByBundle( NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_number) { ANS_LOGW("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } int slotType = 0; @@ -637,6 +681,7 @@ napi_value ParseParametersByRemoveSlot( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < 1) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -645,6 +690,8 @@ napi_value ParseParametersByRemoveSlot( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_number) { ANS_LOGE("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } int32_t slotType = 0; @@ -1337,23 +1384,29 @@ napi_value ParseParametersEnableSlot( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); if (argc < SET_ENABLE_SLOT_MIN_PARA) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } // argv[0]: bundle if (!OHOS::AppExecFwk::IsTypeForNapiValue(env, argv[PARAM0], napi_object)) { ANS_LOGE("Parameter type is error. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } // argv[1]: SlotType if (!OHOS::AppExecFwk::IsTypeForNapiValue(env, argv[PARAM1], napi_number)) { ANS_LOGE("Parameter type error. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } int slotType = 0; @@ -1365,6 +1418,8 @@ napi_value ParseParametersEnableSlot( // argv[2]: enable if (!OHOS::AppExecFwk::IsTypeForNapiValue(env, argv[PARAM2], napi_boolean)) { ANS_LOGE("Wrong argument type. Bool expected."); + std::string msg = "Incorrect parameter types.The type of param must be boolean."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_get_value_bool(env, argv[PARAM2], ¶ms.enable); @@ -1464,6 +1519,7 @@ napi_value ParseParametersIsEnableSlot( NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < GET_ENABLE_SLOT_MAX_PARA - 1) { ANS_LOGW("Wrong number of arguments."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -1471,11 +1527,14 @@ napi_value ParseParametersIsEnableSlot( NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGW("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } auto retValue = Common::GetBundleOption(env, argv[PARAM0], params.option); if (retValue == nullptr) { ANS_LOGE("GetBundleOption failed."); + Common::NapiThrow(env, ERROR_PARAM_INVALID, PARAMETER_VERIFICATION_FAILED); return nullptr; } @@ -1483,6 +1542,8 @@ napi_value ParseParametersIsEnableSlot( NAPI_CALL(env, napi_typeof(env, argv[PARAM1], &valuetype)); if (valuetype != napi_number) { ANS_LOGW("Wrong argument type. Number expected."); + std::string msg = "Incorrect parameter types.The type of param must be number."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } int slotType = 0; diff --git a/frameworks/js/napi/src/subscribe.cpp b/frameworks/js/napi/src/subscribe.cpp index a99949a030caa1b22764331d70751523b806144b..72c161775cd03db8b6a615bf9ceb2caf8c2654ce 100644 --- a/frameworks/js/napi/src/subscribe.cpp +++ b/frameworks/js/napi/src/subscribe.cpp @@ -1277,6 +1277,8 @@ napi_value GetNotificationSubscriber( subscriberInfo.subscriber = new (std::nothrow) SubscriberInstance(); if (subscriberInfo.subscriber == nullptr) { ANS_LOGE("subscriber is null"); + std::string msg = "Mandatory parameters are left unspecified. subscriber is null"; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } @@ -1290,6 +1292,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnConsumed, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnConsumed, 1, &result); @@ -1303,6 +1307,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnCanceled, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnCanceled, 1, &result); @@ -1316,6 +1322,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnUpdate, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnUpdate, 1, &result); @@ -1329,6 +1337,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnConnected, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnConnected, 1, &result); @@ -1342,6 +1352,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnDisConnect, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnDisConnect, 1, &result); @@ -1355,6 +1367,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnDied, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnDied, 1, &result); @@ -1368,6 +1382,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnDisturbModeChanged, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnDisturbModeChanged, 1, &result); @@ -1382,6 +1398,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnDisturbDateChanged, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnDisturbDateChanged, 1, &result); @@ -1396,6 +1414,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnDoNotDisturbChanged, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnDoNotDisturbChanged, 1, &result); @@ -1410,6 +1430,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnEnabledNotificationChanged, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnEnabledNotificationChanged, 1, &result); @@ -1424,6 +1446,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnBadgeChanged, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnBadgeChanged, 1, &result); @@ -1438,6 +1462,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, nOnBadgeEnabledChanged, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, nOnBadgeEnabledChanged, 1, &result); @@ -1452,6 +1478,8 @@ napi_value GetNotificationSubscriber( NAPI_CALL(env, napi_typeof(env, onBatchCancel, &valuetype)); if (valuetype != napi_function) { ANS_LOGE("Wrong argument type. Function expected."); + std::string msg = "Incorrect parameter types.The type of param must be function."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } napi_create_reference(env, onBatchCancel, 1, &result); @@ -1512,6 +1540,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); if (argc < 1) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -1521,6 +1550,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type for arg0. NotificationSubscriber object expected."); + std::string msg = "Incorrect parameter types.The type of param must be NotificationSubscriber."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } diff --git a/frameworks/js/napi/src/unsubscribe.cpp b/frameworks/js/napi/src/unsubscribe.cpp index 1d0eccfb8107e89f666318d85f23e9c71c57765b..36e6e29ec10da0d76dfe2968fa27a84ee96edec7 100644 --- a/frameworks/js/napi/src/unsubscribe.cpp +++ b/frameworks/js/napi/src/unsubscribe.cpp @@ -30,6 +30,7 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); if (argc < 1) { ANS_LOGE("Wrong number of arguments"); + Common::NapiThrow(env, ERROR_PARAM_INVALID, MANDATORY_PARAMETER_ARE_LEFT_UNSPECIFIED); return nullptr; } @@ -38,6 +39,8 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, NAPI_CALL(env, napi_typeof(env, argv[PARAM0], &valuetype)); if (valuetype != napi_object) { ANS_LOGE("Wrong argument type. Object expected."); + std::string msg = "Incorrect parameter types.The type of param must be object."; + Common::NapiThrow(env, ERROR_PARAM_INVALID, msg); return nullptr; } diff --git a/frameworks/test/moduletest/BUILD.gn b/frameworks/test/moduletest/BUILD.gn index 459c4e0280497e0fb3ee7a48720a15276e116ae0..83c5b849c08d1dd22af218d7273aef9c43a9cce6 100644 --- a/frameworks/test/moduletest/BUILD.gn +++ b/frameworks/test/moduletest/BUILD.gn @@ -190,8 +190,10 @@ ohos_moduletest("ans_innerkits_module_slot_test") { ] sources = [ + "${test_path}/mock/mock_tokenid_kit.cpp", "ans_innerkits_module_slot_test.cpp", "mock/distributed_kv_data_manager.cpp", + "mock/mock_accesstoken_kit.cpp", "mock/mock_bundle_manager.cpp", "mock/mock_bundle_manager_helper.cpp", "mock/mock_ipc.cpp", diff --git a/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp index a77174290127889d5c7726d9ff98973a6e5049a3..1076fa0aee97482e6f199a11caddad33802cd6cf 100644 --- a/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -33,10 +33,14 @@ #include "want_agent_info.h" #include "want_agent_helper.h" #include "want_params.h" +#include "accesstoken_kit.h" using namespace testing::ext; +using namespace OHOS::Security::AccessToken; namespace OHOS { namespace Notification { +extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet); + static sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); bool g_onConsumedReceived = false; @@ -65,6 +69,7 @@ const int32_t CASE_SEVENTEEN = 17; const int32_t CASE_EIGHTEEN = 18; const int32_t CASE_NINETEEN = 19; const int32_t CASE_TWENTY = 20; +const int32_t CASE_TWENTY_ONE = 21; const int32_t PIXEL_MAP_TEST_WIDTH = 32; const int32_t PIXEL_MAP_TEST_HEIGHT = 32; @@ -178,6 +183,8 @@ public: CheckCaseSixteenResult(notificationRequest); } else if (CASE_SEVENTEEN == notificationRequest.GetNotificationId()) { CheckCaseSeventeenResult(notificationRequest); + } else if (CASE_TWENTY_ONE == notificationRequest.GetNotificationId()) { + CheckCaseTwentyOneResult(notificationRequest); } else { GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish::OnConsumed do nothing!!!!!"; } @@ -410,9 +417,9 @@ private: { std::shared_ptr notiTemplate = notificationRequest.GetTemplate(); if (notiTemplate != nullptr) { - EXPECT_EQ("downloadTemplate", notiTemplate->GetTemplateName()); + EXPECT_EQ("downloadTemplate1", notiTemplate->GetTemplateName()); std::shared_ptr param = notiTemplate->GetTemplateData(); - int value = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(param->GetParam("downloadTemplate"))); + int value = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(param->GetParam("downloadTemplate1"))); EXPECT_EQ(20, value); // 20 test input } EXPECT_EQ(NotificationConstant::OTHER, notificationRequest.GetSlotType()); @@ -422,8 +429,8 @@ private: { std::shared_ptr notiFlags = notificationRequest.GetFlags(); if (notiFlags != nullptr) { - EXPECT_EQ(NotificationConstant::FlagStatus::CLOSE, notiFlags->IsSoundEnabled()); - EXPECT_EQ(NotificationConstant::FlagStatus::CLOSE, notiFlags->IsVibrationEnabled()); + EXPECT_EQ(NotificationConstant::FlagStatus::NONE, notiFlags->IsSoundEnabled()); + EXPECT_EQ(NotificationConstant::FlagStatus::NONE, notiFlags->IsVibrationEnabled()); } } @@ -442,6 +449,15 @@ private: notificationRequest.GetRemovalWantAgent(); EXPECT_NE(removalWantAgent, nullptr); } + + void CheckCaseTwentyOneResult(NotificationRequest notificationRequest) + { + std::shared_ptr notiFlags = notificationRequest.GetFlags(); + if (notiFlags != nullptr) { + EXPECT_EQ(NotificationConstant::FlagStatus::NONE, notiFlags->IsSoundEnabled()); + EXPECT_EQ(NotificationConstant::FlagStatus::NONE, notiFlags->IsVibrationEnabled()); + } + } }; class CompletedCallbackTest : public AbilityRuntime::WantAgent::CompletedCallback { @@ -490,7 +506,9 @@ void AnsInnerKitsModulePublishTest::TearDownTestCase() } void AnsInnerKitsModulePublishTest::SetUp() -{} +{ + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); +} void AnsInnerKitsModulePublishTest::TearDown() { @@ -1208,20 +1226,11 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_07000, Function */ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_GetActiveNotifications_00100, Function | MediumTest | Level1) { - auto subscriber = TestAnsSubscriber(); - NotificationSubscribeInfo info = NotificationSubscribeInfo(); - info.AddAppName("bundleName"); - info.AddAppUserId(SUBSCRIBE_USER_ALL); - g_subscribe_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber, info)); - WaitOnSubscribeResult(); std::shared_ptr implContent = std::make_shared(); EXPECT_NE(implContent, nullptr); std::shared_ptr content = std::make_shared(implContent); EXPECT_NE(content, nullptr); EXPECT_EQ((int)ERR_OK, (int)NotificationHelper::CancelAllNotifications()); - sleep(SLEEP_TIME); - EXPECT_EQ(g_onCanceledReceived, true); uint64_t countBefor = 0; EXPECT_EQ((int)ERR_OK, NotificationHelper::GetActiveNotificationNums(countBefor)); EXPECT_EQ(0, countBefor); @@ -1230,19 +1239,16 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_GetActiveNotifications_ req1.SetLabel(label1); req1.SetContent(content); req1.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN); - g_consumed_mtx.lock(); + req1.SetCreatorUid(100); + EXPECT_EQ(0, NotificationHelper::PublishNotification(req1)); - WaitOnConsumed(); - g_onConsumedReceived = false; - g_consumed_mtx.unlock(); std::string label2 = "Label2"; NotificationRequest req2(0); req2.SetLabel(label2); req2.SetContent(content); req2.SetCreatorUserId(SUBSCRIBE_USER_SYSTEM_BEGIN); - g_consumed_mtx.lock(); + req2.SetCreatorUid(100); EXPECT_EQ(0, NotificationHelper::PublishNotification(req2)); - WaitOnConsumed(); uint64_t countAfter = 0; EXPECT_EQ((int)ERR_OK, NotificationHelper::GetActiveNotificationNums(countAfter)); EXPECT_EQ(ACTIVE_NUMS, countAfter); @@ -1252,13 +1258,8 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_GetActiveNotifications_ EXPECT_EQ("Label2", requests[1]->GetLabel()); EXPECT_EQ((int)ERR_OK, (int)NotificationHelper::RemoveNotifications(SUBSCRIBE_USER_SYSTEM_BEGIN)); sleep(SLEEP_TIME); - EXPECT_EQ(g_onCanceledReceived, true); EXPECT_EQ((int)ERR_OK, NotificationHelper::GetActiveNotificationNums(countAfter)); EXPECT_EQ(0, countAfter); - g_unsubscribe_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(subscriber)); - WaitOnUnsubscribeResult(); - g_onCanceledReceived = false; } /** @@ -1354,12 +1355,14 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_04000, Function std::shared_ptr notiTemplate = std::make_shared(); EXPECT_NE(notiTemplate, nullptr); - notiTemplate->SetTemplateName("downloadTemplate"); - // [{'downloadTemplate':20}] + notiTemplate->SetTemplateName("downloadTemplate1"); + AAFwk::WantParams wantParams; - std::string key("downloadTemplate"); + std::string key("downloadTemplate1"); int resultValue = 20; - wantParams.SetParam(key, AAFwk::Integer::Box(resultValue)); + wantParams.SetParam(key, AAFwk::Integer::Box(resultValue)); + wantParams.SetParam("fileName", AAFwk::Integer::Box(resultValue)); + wantParams.SetParam("title", AAFwk::Integer::Box(resultValue)); notiTemplate->SetTemplateData(std::make_shared(wantParams)); GTEST_LOG_(INFO) << "ANS_Interface_MT_Publish_04000::notiTemplate::" << notiTemplate->Dump(); std::shared_ptr normalContent = std::make_shared(); @@ -1477,7 +1480,6 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_05000, Function NotificationRequest req; req.SetContent(content); req.SetFlags(notiFlags); - req.SetSlotType(NotificationConstant::OTHER); req.SetNotificationId(CASE_FIFTEEN); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); @@ -1512,7 +1514,7 @@ HWTEST_F(AnsInnerKitsModulePublishTest, ANS_Interface_MT_Publish_06000, Function NotificationRequest req; req.SetContent(content); req.SetSlotType(NotificationConstant::OTHER); - req.SetNotificationId(CASE_SIXTEEN); + req.SetNotificationId(CASE_TWENTY_ONE); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); WaitOnConsumed(); diff --git a/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp b/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp index 2bfbdfc5f96fcbdb97d3b6c4b87a2f5650497cd6..eec23b7a164963d6fbd2f93ae7d5ef401b9d3ba8 100644 --- a/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp +++ b/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp @@ -26,10 +26,16 @@ #include "notification_helper.h" #include "remote_native_token.h" #include "system_ability_definition.h" +#include "accesstoken_kit.h" using namespace testing::ext; +using namespace OHOS::Security::AccessToken; + namespace OHOS { namespace Notification { +extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet); +extern void MockIsSystemApp(bool isSystemApp); + const int32_t SLEEP_TIME = 1; static sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -62,6 +68,8 @@ void AnsInnerKitsModuleSlotTest::TearDownTestCase() void AnsInnerKitsModuleSlotTest::SetUp() { + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); + MockIsSystemApp(true); NotificationHelper::RemoveAllSlots(); } diff --git a/frameworks/test/moduletest/mock/mock_accesstoken_kit.cpp b/frameworks/test/moduletest/mock/mock_accesstoken_kit.cpp index 3805efb681ccb3697a6a0db934fcb85d4131ea17..07e5b2f657fe0623b427b98e6392e02b4a82773b 100644 --- a/frameworks/test/moduletest/mock/mock_accesstoken_kit.cpp +++ b/frameworks/test/moduletest/mock/mock_accesstoken_kit.cpp @@ -14,7 +14,22 @@ */ #include "accesstoken_kit.h" +#include "ans_log_wrapper.h" +#include "ipc_skeleton.h" +using namespace OHOS::Security::AccessToken; +namespace OHOS { +namespace Notification { +namespace { +ATokenTypeEnum g_mockGetTokenTypeFlagRet = ATokenTypeEnum::TOKEN_INVALID; +} + +void MockGetTokenTypeFlag(ATokenTypeEnum mockRet) +{ + g_mockGetTokenTypeFlagRet = mockRet; +} +} +} namespace OHOS { namespace Security { namespace AccessToken { @@ -25,7 +40,7 @@ int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID) { - return TOKEN_HAP; + return Notification::g_mockGetTokenTypeFlagRet; } } // namespace AccessToken } // namespace Security diff --git a/interfaces/inner_api/badge_number_callback_data.h b/interfaces/inner_api/badge_number_callback_data.h index 27cf29aa895ca7786256d942498cdef9f985d1fb..1d8000ed35f9e5e3401d4cf9cbd4be442306739f 100644 --- a/interfaces/inner_api/badge_number_callback_data.h +++ b/interfaces/inner_api/badge_number_callback_data.h @@ -36,6 +36,15 @@ public: */ BadgeNumberCallbackData(const std::string &bundle, int32_t uid, int32_t badgeNumber); + /** + * A constructor used to create a BadgeNumberCallbackData instance with the input parameters passed. + * @param bundle Indicates the name of the application. + * @param uid Indicates the uid of the application. + * @param badgeNumber badge number. + * @param badgeNumber application instance key. + */ + BadgeNumberCallbackData(const std::string &bundle, int32_t uid, int32_t badgeNumber, int32_t instanceKey); + /** * Default deconstructor used to deconstruct. */ @@ -53,6 +62,10 @@ public: int32_t GetBadgeNumber() const; + void SetInstanceKey(int32_t key); + + int32_t GetInstanceKey() const; + /** * Returns a string representation of the BadgeNumberCallbackData object. */ @@ -76,6 +89,7 @@ private: std::string bundle_; int32_t uid_; int32_t badgeNumber_; + int32_t instanceKey_; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/notification.h b/interfaces/inner_api/notification.h index c2d95c524a244f178242b658ab937d83b72c52de..25c523f7b746e91340d510b06e3dd5a51dcf7dee 100644 --- a/interfaces/inner_api/notification.h +++ b/interfaces/inner_api/notification.h @@ -235,6 +235,13 @@ public: */ int32_t GetRecvUserId() const; + /** + * @brief Obtains the instance key of the notification creator. + * + * @return Returns the instance key of the notification creator. + */ + int32_t GetInstanceKey() const; + /** * @brief Dumps a string representation of the object. * diff --git a/interfaces/inner_api/notification_bundle_option.h b/interfaces/inner_api/notification_bundle_option.h index edc2887102dd0fc86858e84e5120d906760ddc03..56fd66a32a23c2fab5487f5adb81fff23cdd337a 100644 --- a/interfaces/inner_api/notification_bundle_option.h +++ b/interfaces/inner_api/notification_bundle_option.h @@ -63,6 +63,20 @@ public: */ int32_t GetUid() const; + /** + * @brief Sets the application instance key. + * + * @param uid Indicates the application instance key. + */ + void SetInstanceKey(const int32_t key); + + /** + * @brief Obtains the application instance key. + * + * @return Returns the application instance key. + */ + int32_t GetInstanceKey() const; + /** * @brief Returns a string representation of the object. * @@ -114,6 +128,7 @@ private: private: std::string bundleName_ {}; int32_t uid_ {}; + int32_t instanceKey_ {}; }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/notification_request.h b/interfaces/inner_api/notification_request.h index 8928d001c55f1c7ed45d2d23661f002251ff117e..541f8529434e844b219a1884f67dc058e02a9b52 100644 --- a/interfaces/inner_api/notification_request.h +++ b/interfaces/inner_api/notification_request.h @@ -733,6 +733,13 @@ public: */ int64_t GetCreateTime() const; + /** + * @brief Sets the time to create a notification. + * + * @param createTime Indicates the time in milliseconds. + */ + void SetCreateTime(int64_t createTime); + /** * @brief Checks whether the notification creation time is displayed as a stopwatch. * @@ -1070,6 +1077,20 @@ public: */ int32_t GetCreatorUserId() const; + /** + * @brief Sets the InstanceKey of the notification creator. + * + * @param userId Indicates the InstanceKey of the notification creator. + */ + void SetCreatorInstanceKey(int32_t key); + + /** + * @brief Obtains the InstanceKey of the notification creator. + * + * @return Returns the InstanceKey of the notification creator. + */ + int32_t GetCreatorInstanceKey() const; + /** * @brief Sets the UserId of the notification owner. * @@ -1433,6 +1454,7 @@ private: int32_t creatorUserId_ {SUBSCRIBE_USER_INIT}; int32_t ownerUserId_ {SUBSCRIBE_USER_INIT}; int32_t receiverUserId_ {SUBSCRIBE_USER_INIT}; + int32_t creatorInstanceKey_ {DEFAULT_UID}; std::string settingsText_ {}; std::string creatorBundleName_ {}; diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index b74b30d784165c1afa5844a873cc03b75d3cc9a8..e540593903ab55e971ae1937596c7d6dd16045f2 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -86,6 +86,7 @@ ohos_shared_library("libans") { "src/reminder_event_manager.cpp", "src/reminder_swing_decision_center.cpp", "src/reminder_timer_info.cpp", + "src/system_dialog_connect_stb.cpp", "src/system_event_observer.cpp", ] @@ -121,6 +122,7 @@ ohos_shared_library("libans") { "ability_runtime:ability_manager", "ability_runtime:app_manager", "ability_runtime:dataobs_manager", + "ability_runtime:extension_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", diff --git a/services/ans/include/advanced_datashare_helper.h b/services/ans/include/advanced_datashare_helper.h index f5f0fd8cbd2334d45e04441eb18e2cd4b0fa1d66..192eca0e5b8b07a8c28e68fb71730799aa01a2a9 100644 --- a/services/ans/include/advanced_datashare_helper.h +++ b/services/ans/include/advanced_datashare_helper.h @@ -39,8 +39,7 @@ public: std::string GetUnifiedGroupEnableUri() const; private: - void CreateDataShareHelper(); - std::shared_ptr dataShareHelper_ = nullptr; + std::shared_ptr CreateDataShareHelper(); }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index 0bfc56bd1b5df705604c93c4b67c7fac3402b87a..63bca6dbacd7533d7fa74dbbea97bb9425b087c8 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -106,16 +106,18 @@ public: * * @param notificationId Indicates the ID of the notification to cancel. * @param label Indicates the label of the notification to cancel. + * @param instanceKey Indicates the application instance key. * @return Returns cancel notification result. */ - ErrCode Cancel(int32_t notificationId, const std::string &label) override; + ErrCode Cancel(int32_t notificationId, const std::string &label, int32_t instanceKey) override; /** * @brief Cancels all the published notifications. * + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - ErrCode CancelAll() override; + ErrCode CancelAll(int32_t instanceKey) override; /** * @brief Cancels a published agent notification. @@ -217,9 +219,10 @@ public: * @brief Obtains active notifications of the current application in the system. * * @param notifications Indicates active NotificationRequest objects of the current application. + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - ErrCode GetActiveNotifications(std::vector> ¬ifications) override; + ErrCode GetActiveNotifications(std::vector> ¬ifications, int32_t instanceKey) override; /** * @brief Obtains the number of active notifications of the current application in the system. @@ -593,9 +596,10 @@ public: * @brief Cancel notifications according to group. * * @param groupName Indicates the group name. + * @param instanceKey Indicates the application instance key. * @return Returns ERR_OK on success, others on failure. */ - ErrCode CancelGroup(const std::string &groupName) override; + ErrCode CancelGroup(const std::string &groupName, int32_t instanceKey) override; /** * @brief Delete notifications according to bundle and group. @@ -917,9 +921,10 @@ public: * @brief Set badge number. * * @param badgeNumber The badge number. + * @param instanceKey The application instance key. * @return Returns set badge number result. */ - ErrCode SetBadgeNumber(int32_t badgeNumber) override; + ErrCode SetBadgeNumber(int32_t badgeNumber, int32_t instanceKey) override; /** * @brief Set badge number by bundle. @@ -1013,6 +1018,12 @@ public: * @return Returns set result. */ ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) override; + + /** + * @brief clear notification when aggregate local switch close. + */ + void ClearAllNotificationGroupInfo(std::string localSwitch); + /** * @brief Reset pushcallback proxy */ @@ -1321,7 +1332,7 @@ private: static std::mutex pushMutex_; static std::map> pushCallBacks_; static std::map> checkRequests_; - + bool aggregateLocalSwitch_ = false; std::shared_ptr runner_ = nullptr; std::shared_ptr handler_ = nullptr; std::list> notificationList_; diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index 027d7ba442b36e4d48fa53366ae04cdd2da4a314..61a6bf7946b7d11744c0ddfdb4cc9e4af8d25617 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -239,7 +239,7 @@ private: bool PutBundlePropertyValueToDisturbeDB(const NotificationPreferencesInfo::BundleInfo &bundleInfo); template int32_t PutBundlePropertyToDisturbeDB( - const std::string &bundleKey, const BundleType &type, const T &t); + const std::string &bundleKey, const BundleType &type, const T &t, const int32_t &bundleUid); template int32_t PutDataToDB(const std::string &key, const T &t, const int32_t &userId); bool PutBundleToDisturbeDB( diff --git a/services/ans/include/os_account_manager_helper.h b/services/ans/include/os_account_manager_helper.h index a6551b03fc8006fad5d004cab6c6fb451eee5940..f1f294817d3b3805b8169cbc0d07cb8479b47857 100644 --- a/services/ans/include/os_account_manager_helper.h +++ b/services/ans/include/os_account_manager_helper.h @@ -18,6 +18,7 @@ #include "errors.h" #include "singleton.h" +#include namespace OHOS { namespace Notification { @@ -32,6 +33,11 @@ public: */ static OsAccountManagerHelper &GetInstance(); + /** + * @brief check is system account + */ + static bool IsSystemAccount(int32_t userId); + /** * Gets operating system account local ID from uid. * @@ -64,6 +70,14 @@ public: * @return Returns result. */ bool CheckUserExists(const int32_t &userId); + + /** + * Get All os account userIds. + * + * @param userId Indicates the current active account ID. + * @return Returns result. + */ + ErrCode GetAllOsAccount(std::vector &userIds); }; } // namespace OHOS } // namespace Notification diff --git a/services/ans/include/system_dialog_connect_stb.h b/services/ans/include/system_dialog_connect_stb.h new file mode 100644 index 0000000000000000000000000000000000000000..25764a8a373c799ddd9e3489f70bf1224ba0ddae --- /dev/null +++ b/services/ans/include/system_dialog_connect_stb.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_SYSTEM_DIALOG_CONNECT_STB_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_SYSTEM_DIALOG_CONNECT_STB_H + +#include "ability_connect_callback_interface.h" +#include "ability_connect_callback_stub.h" +#include "iremote_object.h" +#include "iremote_proxy.h" +#include "message_parcel.h" +#include "nocopyable.h" + +namespace OHOS { +namespace Notification { +class SystemDialogConnectStb : public AAFwk::AbilityConnectionStub { +public: + SystemDialogConnectStb(const std::string commandStr) + { + commandStr_ = commandStr; + } + + virtual ~SystemDialogConnectStb() = default; + + void OnAbilityConnectDone(const AppExecFwk::ElementName &element, + const sptr &remoteObject, int32_t resultCode) override; + void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override; + + void SendCrashEvent(); + +private: + std::string commandStr_; +}; +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_SYSTEM_DIALOG_CONNECT_STB_H \ No newline at end of file diff --git a/services/ans/src/advanced_aggregation_data_roaming_observer.cpp b/services/ans/src/advanced_aggregation_data_roaming_observer.cpp index 4bd9f3f78fffda20c32356050d1e14f6ee6a7d2e..584f18ce768b451ffb0bb209c12f10bd82f99dba 100644 --- a/services/ans/src/advanced_aggregation_data_roaming_observer.cpp +++ b/services/ans/src/advanced_aggregation_data_roaming_observer.cpp @@ -29,13 +29,14 @@ void AdvancedAggregationDataRoamingObserver::OnChange() { string enable = ""; AdvancedNotificationService::GetInstance()->GetUnifiedGroupInfoFromDb(enable); - ANS_LOGI("fengyunfei GetUnifiedGroupInfoFromDb enter, enable:%{public}s", enable.c_str()); + ANS_LOGI("GetUnifiedGroupInfoFromDb enter, enable:%{public}s", enable.c_str()); #ifdef ENABLE_ANS_EXT_WRAPPER EXTENTION_WRAPPER->SetlocalSwitch(enable); + AdvancedNotificationService::GetInstance()->ClearAllNotificationGroupInfo(enable); #else ANS_LOGD("Not enabled ans_ext"); #endif } } // namespace Telephony -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/ans/src/advanced_datashare_helper.cpp b/services/ans/src/advanced_datashare_helper.cpp index 473471d7e8e300c86e13e01b029e5fad7424c153..67989bcb07c1c49b399680ec2d4477f6510d0ce7 100644 --- a/services/ans/src/advanced_datashare_helper.cpp +++ b/services/ans/src/advanced_datashare_helper.cpp @@ -42,38 +42,41 @@ AdvancedDatashareHelper::AdvancedDatashareHelper() CreateDataShareHelper(); } -void AdvancedDatashareHelper::CreateDataShareHelper() +std::shared_ptr AdvancedDatashareHelper::CreateDataShareHelper() { sptr saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (saManager == nullptr) { ANS_LOGE("The sa manager is nullptr."); - return; + return nullptr; } sptr remoteObj = saManager->GetSystemAbility(ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID); if (remoteObj == nullptr) { ANS_LOGE("The remoteObj is nullptr."); - return; + return nullptr; } - dataShareHelper_ = DataShare::DataShareHelper::Creator(remoteObj, SETTINGS_DATA_EXT_URI); + return DataShare::DataShareHelper::Creator(remoteObj, SETTINGS_DATA_EXT_URI); } bool AdvancedDatashareHelper::Query(Uri &uri, const std::string &key, std::string &value) { - if (dataShareHelper_ == nullptr) { + std::shared_ptr dataShareHelper = CreateDataShareHelper(); + if (dataShareHelper == nullptr) { ANS_LOGE("The data share helper is nullptr."); return false; } DataShare::DataSharePredicates predicates; std::vector columns; predicates.EqualTo(ADVANCED_DATA_COLUMN_KEYWORD, key); - auto result = dataShareHelper_->Query(uri, predicates, columns); + auto result = dataShareHelper->Query(uri, predicates, columns); if (result == nullptr) { ANS_LOGE("Query error, result is null."); + dataShareHelper->Release(); return false; } if (result->GoToFirstRow() != DataShare::E_OK) { ANS_LOGE("Query failed, go to first row error."); result->Close(); + dataShareHelper->Release(); return false; } int32_t columnIndex; @@ -81,6 +84,7 @@ bool AdvancedDatashareHelper::Query(Uri &uri, const std::string &key, std::strin result->GetString(columnIndex, value); result->Close(); ANS_LOGD("Query success, value[%{public}s]", value.c_str()); + dataShareHelper->Release(); return true; } diff --git a/services/ans/src/advanced_datashare_observer.cpp b/services/ans/src/advanced_datashare_observer.cpp index e577ef7b87548c0c2ccbfe93d8e70c56f3355d1b..13e8ead264591e245b14ddfe7467ccd5e81102e9 100644 --- a/services/ans/src/advanced_datashare_observer.cpp +++ b/services/ans/src/advanced_datashare_observer.cpp @@ -62,7 +62,7 @@ void AdvancedDatashareObserver::UnRegisterSettingsObserver( void AdvancedDatashareObserver::RegisterSettingsObserver( const Uri &uri, const sptr &dataObserver) { - ANS_LOGI("fengyunfei AdvancedDatashareObserver::RegisterSettingsObserver enter"); + ANS_LOGD("AdvancedDatashareObserver::RegisterSettingsObserver enter"); std::shared_ptr settingHelper = CreateDataShareHelper(); if (settingHelper == nullptr) { ANS_LOGE("Register settings observer by nullptr"); @@ -84,4 +84,4 @@ void AdvancedDatashareObserver::NotifyChange(const Uri &uri) } } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/ans/src/advanced_notification_inline.cpp b/services/ans/src/advanced_notification_inline.cpp index 5f4665ae53439459c5acbc3acd9b328a0488eabb..4fd473a045bb739bdf83d286c9f052c53fa61c91 100644 --- a/services/ans/src/advanced_notification_inline.cpp +++ b/services/ans/src/advanced_notification_inline.cpp @@ -76,15 +76,15 @@ inline ErrCode CheckPictureSize(const sptr &request) return result; } - if (request->CheckImageOverSizeForPixelMap(request->GetLittleIcon(), MAX_ICON_SIZE)) { + if (request->CheckImageOverSizeForPixelMap(request->GetLittleIcon(), MAX_ICON_ENLARGE_SIZE)) { return ERR_ANS_ICON_OVER_SIZE; } - if (request->CheckImageOverSizeForPixelMap(request->GetBigIcon(), MAX_ICON_SIZE)) { + if (request->CheckImageOverSizeForPixelMap(request->GetBigIcon(), MAX_ICON_ENLARGE_SIZE)) { return ERR_ANS_ICON_OVER_SIZE; } - if (request->CheckImageOverSizeForPixelMap(request->GetOverlayIcon(), MAX_ICON_SIZE)) { + if (request->CheckImageOverSizeForPixelMap(request->GetOverlayIcon(), MAX_ICON_ENLARGE_SIZE)) { return ERR_ANS_ICON_OVER_SIZE; } diff --git a/services/ans/src/advanced_notification_live_view_service.cpp b/services/ans/src/advanced_notification_live_view_service.cpp index 974f8f7640d3b8c7c2697a213d664cfea7ef49de..b34fbe48a10976a944f0f6882f9a04a6cd024d15 100644 --- a/services/ans/src/advanced_notification_live_view_service.cpp +++ b/services/ans/src/advanced_notification_live_view_service.cpp @@ -282,13 +282,19 @@ int32_t AdvancedNotificationService::GetNotificationRequestFromDb( int32_t AdvancedNotificationService::GetBatchNotificationRequestsFromDb(std::vector &requests) { std::unordered_map dbRecords; - int32_t userId = -1; - OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId); - int32_t result = - NotificationPreferences::GetInstance().GetBatchKvsFromDb(REQUEST_STORAGE_KEY_PREFIX, dbRecords, userId); - if (result != ERR_OK) { - ANS_LOGE("Get batch notification request failed."); - return result; + std::vector userIds; + int32_t ret = OsAccountManagerHelper::GetInstance().GetAllOsAccount(userIds); + if (ret != ERR_OK) { + ANS_LOGE("Get all os account failed."); + return ret; + } + for (const int32_t userId : userIds) { + int32_t result = + NotificationPreferences::GetInstance().GetBatchKvsFromDb(REQUEST_STORAGE_KEY_PREFIX, dbRecords, userId); + if (result != ERR_OK) { + ANS_LOGE("Get batch notification request failed."); + return result; + } } for (const auto &iter : dbRecords) { auto jsonObject = nlohmann::json::parse(iter.second); diff --git a/services/ans/src/advanced_notification_publish/base_publish_process.cpp b/services/ans/src/advanced_notification_publish/base_publish_process.cpp index 62aa57ba60614ce8bcdfb7bb0734a3d21890cd79..2bdb66797e1cd4bd5776307e4a7bd10ca785f38b 100644 --- a/services/ans/src/advanced_notification_publish/base_publish_process.cpp +++ b/services/ans/src/advanced_notification_publish/base_publish_process.cpp @@ -44,8 +44,8 @@ ErrCode BasePublishProcess::PublishPreWork(const sptr &requ request->SetRemoveAllowed(true); } } - if (request->GetReceiverUserId() >= 0) { - if (OsAccountManagerHelper::GetInstance().CheckUserExists(request->GetReceiverUserId())) { + if (OsAccountManagerHelper::IsSystemAccount(request->GetReceiverUserId())) { + if (!OsAccountManagerHelper::GetInstance().CheckUserExists(request->GetReceiverUserId())) { return ERROR_USER_NOT_EXIST; } } diff --git a/services/ans/src/advanced_notification_publish/live_publish_process.cpp b/services/ans/src/advanced_notification_publish/live_publish_process.cpp index 1a80a1594ebd5cfdbb67d3e7035d36011629d8d9..d3afb8ea6f4dafb91b7900ceb4dd7d5e74d2e81a 100644 --- a/services/ans/src/advanced_notification_publish/live_publish_process.cpp +++ b/services/ans/src/advanced_notification_publish/live_publish_process.cpp @@ -60,8 +60,8 @@ ErrCode LivePublishProcess::PublishPreWork(const sptr &requ request->SetRemoveAllowed(true); } } - if (request->GetReceiverUserId() >= 0) { - if (OsAccountManagerHelper::GetInstance().CheckUserExists(request->GetReceiverUserId())) { + if (OsAccountManagerHelper::IsSystemAccount(request->GetReceiverUserId())) { + if (!OsAccountManagerHelper::GetInstance().CheckUserExists(request->GetReceiverUserId())) { return ERROR_USER_NOT_EXIST; } } diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index bde3be2a1d02782d452365c423314dbec8548a9b..5b0cbc755c69ac2aa12684234639091ef66c7779 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -93,6 +93,8 @@ ErrCode AdvancedNotificationService::Publish(const std::string &label, const spt return ERR_ANS_NO_MEMORY; } + request->SetCreateTime(GetCurrentTime()); + bool isUpdateByOwnerAllowed = IsUpdateSystemLiveviewByOwner(request); ErrCode result = publishProcess_[request->GetSlotType()]->PublishPreWork(request, isUpdateByOwnerAllowed); if (result != ERR_OK) { @@ -174,15 +176,16 @@ bool AdvancedNotificationService::InitPublishProcess() return true; } -ErrCode AdvancedNotificationService::Cancel(int32_t notificationId, const std::string &label) +ErrCode AdvancedNotificationService::Cancel(int32_t notificationId, const std::string &label, int32_t instanceKey) { ANS_LOGD("%{public}s", __FUNCTION__); sptr bundleOption = GenerateBundleOption(); + bundleOption->SetInstanceKey(instanceKey); return CancelPreparedNotification(notificationId, label, bundleOption); } -ErrCode AdvancedNotificationService::CancelAll() +ErrCode AdvancedNotificationService::CancelAll(int32_t instanceKey) { ANS_LOGD("%{public}s", __FUNCTION__); @@ -190,6 +193,7 @@ ErrCode AdvancedNotificationService::CancelAll() if (bundleOption == nullptr) { return ERR_ANS_INVALID_BUNDLE; } + bundleOption->SetInstanceKey(instanceKey); if (notificationSvrQueue_ == nullptr) { ANS_LOGE("Serial queue is invalidated."); @@ -1116,12 +1120,22 @@ ErrCode AdvancedNotificationService::TriggerLocalLiveView(const 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 (record->request->GetAgentBundle() != nullptr) { + if ((record->request->GetAgentBundle()->GetBundleName() == bundle->GetBundleName()) && + (record->request->GetAgentBundle()->GetUid() == bundle->GetUid()) && + (record->notification->GetId() == notificationId)) { + notification = record->notification; + result = ERR_OK; + break; + } + } else { + if ((record->bundleOption->GetBundleName() == bundle->GetBundleName()) && + (record->bundleOption->GetUid() == bundle->GetUid()) && + (record->notification->GetId() == notificationId)) { + notification = record->notification; + result = ERR_OK; + break; + } } } @@ -1411,7 +1425,7 @@ ErrCode AdvancedNotificationService::RemoveNotificationBySlot(const sptrSetInstanceKey(instanceKey); if (notificationSvrQueue_ == nullptr) { ANS_LOGE("Serial queue is invalid."); @@ -1817,6 +1832,7 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptrbundleOption = new (std::nothrow) NotificationBundleOption(bundle, uid); } + record->bundleOption->SetInstanceKey(request->GetCreatorInstanceKey()); sptr bundleOption = new (std::nothrow) NotificationBundleOption(bundle, uid); if (record->bundleOption == nullptr || bundleOption == nullptr) { ANS_LOGE("Failed to create bundleOption"); @@ -1881,7 +1897,7 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptr badgeData = new (std::nothrow) BadgeNumberCallbackData( - bundleName, callingUid, badgeNumber); + bundleName, callingUid, badgeNumber, instanceKey); if (badgeData == nullptr) { ANS_LOGE("Failed to create BadgeNumberCallbackData."); return ERR_ANS_NO_MEMORY; @@ -2185,5 +2201,24 @@ ErrCode AdvancedNotificationService::SetTargetDeviceStatus(const std::string &de deviceType.c_str(), DelayedSingleton::GetInstance()->GetDeviceStatus(deviceType)); return ret; } + +void AdvancedNotificationService::ClearAllNotificationGroupInfo(std::string localSwitch) +{ + ANS_LOGD("ClearNotification enter."); + bool status = (localSwitch == "true"); + if (notificationSvrQueue_ == nullptr) { + ANS_LOGE("ClearNotification Serial queue is invalid."); + return; + } + + ffrt::task_handle handler = notificationSvrQueue_->submit_h([=]() { + if (aggregateLocalSwitch_ && !status) { + for (const auto& item : notificationList_) { + item->notification->GetNotificationRequestPoint()->SetUnifiedGroupInfo(nullptr); + } + } + aggregateLocalSwitch_ = status; + }); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/advanced_notification_reminder_service.cpp b/services/ans/src/advanced_notification_reminder_service.cpp index 303327aaef6dd662e82397f2335d496e523402e9..b7f0a86447cff22fb8292a55570fb38ad2144f24 100644 --- a/services/ans/src/advanced_notification_reminder_service.cpp +++ b/services/ans/src/advanced_notification_reminder_service.cpp @@ -51,6 +51,7 @@ inline bool AdvancedNotificationService::CheckReminderPermission() ErrCode AdvancedNotificationService::PublishReminder(sptr &reminder) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); ANSR_LOGI("Publish reminder"); if (!reminder) { ANSR_LOGE("ReminderRequest object is nullptr"); @@ -107,6 +108,7 @@ ErrCode AdvancedNotificationService::PublishReminder(sptr &remi ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); ANSR_LOGI("Cancel Reminder"); if (!CheckReminderPermission()) { ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); @@ -126,6 +128,7 @@ ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) ErrCode AdvancedNotificationService::CancelAllReminders() { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); ANSR_LOGI("Cancel all reminders"); if (!CheckReminderPermission()) { ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); @@ -148,6 +151,7 @@ ErrCode AdvancedNotificationService::CancelAllReminders() ErrCode AdvancedNotificationService::GetValidReminders(std::vector> &reminders) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); ANSR_LOGI("GetValidReminders"); if (!CheckReminderPermission()) { ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); @@ -170,6 +174,7 @@ ErrCode AdvancedNotificationService::GetValidReminders(std::vector& dates) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); ANSR_LOGI("Get Exclude Dates"); if (!CheckReminderPermission()) { ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 21a2f7abc43978617306e729fb68b79180a6720d..586ec7fd91bb34c0c5cb8b9aed6828aca0a3afc7 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -346,6 +346,7 @@ ErrCode AdvancedNotificationService::AssignToNotificationList(const std::shared_ { ErrCode result = ERR_OK; if (!IsNotificationExists(record->notification->GetKey())) { + record->request->SetCreateTime(GetCurrentTime()); result = PublishFlowControl(record); } else { if (record->request->IsAlertOneTime()) { @@ -563,6 +564,9 @@ std::shared_ptr AdvancedNotificationService::MakeNotificatio ANS_LOGE("Failed to create notification."); return nullptr; } + if (bundleOption != nullptr) { + bundleOption->SetInstanceKey(request->GetCreatorInstanceKey()); + } record->bundleOption = bundleOption; SetNotificationRemindType(record->notification, true); return record; @@ -938,7 +942,8 @@ void AdvancedNotificationService::StopFilters() } } -ErrCode AdvancedNotificationService::GetActiveNotifications(std::vector> ¬ifications) +ErrCode AdvancedNotificationService::GetActiveNotifications( + std::vector> ¬ifications, int32_t instanceKey) { ANS_LOGD("%{public}s", __FUNCTION__); @@ -946,6 +951,7 @@ ErrCode AdvancedNotificationService::GetActiveNotifications(std::vectorSetInstanceKey(instanceKey); if (notificationSvrQueue_ == nullptr) { ANS_LOGE("Serial queue is invalidated."); @@ -1048,7 +1054,7 @@ ErrCode AdvancedNotificationService::GetUnifiedGroupInfoFromDb(std::string &enab Uri enableUri(datashareHelper->GetUnifiedGroupEnableUri()); bool ret = datashareHelper->Query(enableUri, KEY_UNIFIED_GROUP_ENABLE, enable); if (!ret) { - ANS_LOGE("Query focus mode enable fail."); + ANS_LOGE("Query smart aggregation switch failed."); return -1; } @@ -1061,7 +1067,8 @@ std::vector AdvancedNotificationService::GetNotificationKeys( std::vector keys; for (auto record : notificationList_) { - if ((bundleOption != nullptr) && (record->bundleOption->GetUid() != bundleOption->GetUid())) { + if ((bundleOption != nullptr) && + (record->bundleOption->GetUid() != bundleOption->GetUid())) { continue; } keys.push_back(record->notification->GetKey()); diff --git a/services/ans/src/notification_dialog.cpp b/services/ans/src/notification_dialog.cpp index b68d7612fe046368149f6990c4b2b7652f51aa68..a3ae297c5532b46c608ed80ab6bc4e1073468038 100644 --- a/services/ans/src/notification_dialog.cpp +++ b/services/ans/src/notification_dialog.cpp @@ -21,9 +21,12 @@ #include "bundle_manager_helper.h" #include "in_process_call_wrapper.h" #include "os_account_manager.h" +#include "system_dialog_connect_stb.h" +#include "extension_manager_client.h" namespace OHOS { namespace Notification { +constexpr int32_t DEFAULT_VALUE = -1; int32_t NotificationDialog::GetActiveUserId() { std::vector activeUserId; @@ -62,12 +65,38 @@ ErrCode NotificationDialog::StartEnableNotificationDialogAbility( } AAFwk::Want want; - want.SetElementName(serviceBundleName, serviceAbilityName); - want.SetParam("from", appBundleName); - if (callerToken != nullptr) { - want.SetParam("callerToken", callerToken); + + std::string bundleName = "com.ohos.sceneboard"; + std::string abilityName = "com.ohos.sceneboard.systemdialog"; + want.SetElementName(bundleName, abilityName); + + nlohmann::json root; + std::string uiExtensionType = "sysDialog/common"; + root["from"] = appBundleName; + root["ability.want.params.uiExtensionType"] = uiExtensionType; + std::string command = root.dump(); + + auto connection_ = sptr(new (std::nothrow) SystemDialogConnectStb(command)); + if (connection_ == nullptr) { + ANS_LOGD("new connection error."); + return ERR_NO_MEMORY; + } + + std::string identity = IPCSkeleton::ResetCallingIdentity(); + + auto result = AAFwk::ExtensionManagerClient::GetInstance().ConnectServiceExtensionAbility(want, + connection_, nullptr, DEFAULT_VALUE); + if (result != ERR_OK) { + ANS_LOGD("connect sceneboard systemdiaolog fail, result = %{public}d", result); + bundleName = "com.ohos.systemui"; + abilityName = "com.ohos.systemui.dialog"; + want.SetElementName(bundleName, abilityName); + result = AAFwk::ExtensionManagerClient::GetInstance().ConnectServiceExtensionAbility(want, connection_, nullptr, + DEFAULT_VALUE); } - auto result = IN_PROCESS_CALL(AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want)); + + IPCSkeleton::SetCallingIdentity(identity); + ANS_LOGD("End, result = %{public}d", result); return result; } diff --git a/services/ans/src/notification_extension_wrapper.cpp b/services/ans/src/notification_extension_wrapper.cpp index 4460e4721a3dc46179a1ef29f54caf4cd0ecc194..d2b9bb54a0249c3ee62c36b608b0c3fde9c30548 100644 --- a/services/ans/src/notification_extension_wrapper.cpp +++ b/services/ans/src/notification_extension_wrapper.cpp @@ -89,13 +89,13 @@ void ExtensionWrapper::SetlocalSwitch(std::string &enable) void ExtensionWrapper::RegisterDataSettingObserver() { - ANS_LOGI("fengyunfei ExtensionWrapper::RegisterDataSettingObserver enter"); + ANS_LOGD("ExtensionWrapper::RegisterDataSettingObserver enter"); if (aggregationRoamingObserver_ == nullptr) { aggregationRoamingObserver_ = new (std::nothrow) AdvancedAggregationDataRoamingObserver(); } if (aggregationRoamingObserver_ == nullptr) { - ANS_LOGI("aggregationRoamingObserver_ is null"); + ANS_LOGE("aggregationRoamingObserver_ is null"); return; } @@ -119,7 +119,7 @@ void ExtensionWrapper::UpdateByCancel(const std::vector>& not return; } int32_t deleteType = convertToDelType(deleteReason); - updateByCancel_(notifications, deleteReason); + updateByCancel_(notifications, deleteType); } ErrCode ExtensionWrapper::GetUnifiedGroupInfo(const sptr &request) diff --git a/services/ans/src/notification_local_live_view_subscriber_manager.cpp b/services/ans/src/notification_local_live_view_subscriber_manager.cpp index bcb89711932d7e5c906080640c05f61bf8129bc6..d345f091d8b1c6cbf83f5167f352fadf161d10a2 100644 --- a/services/ans/src/notification_local_live_view_subscriber_manager.cpp +++ b/services/ans/src/notification_local_live_view_subscriber_manager.cpp @@ -259,10 +259,17 @@ void NotificationLocalLiveViewSubscriberManager::NotifyTriggerResponseInner( ANS_LOGD("ffrt enter!"); HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); - int32_t sendUserId = notification->GetUid(); - std::string bundleName = notification->GetBundleName(); - ANS_LOGD("%{public}s notification->GetUserId <%{public}d>, bundlename <%{public}s>", - __FUNCTION__, notification->GetUid(), bundleName.c_str()); + int32_t sendUserId; + std::string bundleName; + if (notification->GetNotificationRequestPoint()->GetAgentBundle() != nullptr) { + sendUserId = notification->GetNotificationRequestPoint()->GetAgentBundle()->GetUid(); + bundleName = notification->GetNotificationRequestPoint()->GetAgentBundle()->GetBundleName(); + } else { + sendUserId = notification->GetUid(); + bundleName = notification->GetBundleName(); + } + ANS_LOGD("%{public}s sendUserId <%{public}d>, bundlename <%{public}s>", + __FUNCTION__, sendUserId, bundleName.c_str()); for (auto record : buttonRecordList_) { ANS_LOGD("%{public}s record->userId = <%{public}d>, bundlename <%{public}s>", diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index d122c7bf6ed8c13bba40b0bc39847540a9da19f9..05f1c5ae92077137291028b834f8e856ba9c2199 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -450,8 +450,8 @@ bool NotificationPreferencesDatabase::PutShowBadge( } std::string bundleKey = GenerateBundleLablel(bundleInfo); - int32_t result = - PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_SHOW_BADGE_TYPE, enable); + int32_t result = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_SHOW_BADGE_TYPE, enable, + bundleInfo.GetBundleUid()); return (result == NativeRdb::E_OK); } @@ -468,8 +468,8 @@ bool NotificationPreferencesDatabase::PutImportance( } std::string bundleKey = GenerateBundleLablel(bundleInfo); - int32_t result = - PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_IMPORTANCE_TYPE, importance); + int32_t result = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_IMPORTANCE_TYPE, importance, + bundleInfo.GetBundleUid()); return (result == NativeRdb::E_OK); } @@ -485,8 +485,8 @@ bool NotificationPreferencesDatabase::PutTotalBadgeNums( return false; } std::string bundleKey = GenerateBundleLablel(bundleInfo); - int32_t result = - PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_BADGE_TOTAL_NUM_TYPE, totalBadgeNum); + int32_t result = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_BADGE_TOTAL_NUM_TYPE, totalBadgeNum, + bundleInfo.GetBundleUid()); return (result == NativeRdb::E_OK); } @@ -504,8 +504,8 @@ bool NotificationPreferencesDatabase::PutNotificationsEnabledForBundle( } std::string bundleKey = GenerateBundleLablel(bundleInfo); - int32_t result = - PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_ENABLE_NOTIFICATION_TYPE, enabled); + int32_t result = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_ENABLE_NOTIFICATION_TYPE, enabled, + bundleInfo.GetBundleUid()); return (result == NativeRdb::E_OK); } @@ -536,7 +536,8 @@ bool NotificationPreferencesDatabase::PutSlotFlags(NotificationPreferencesInfo:: } std::string bundleKey = GenerateBundleLablel(bundleInfo); - int32_t result = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags); + int32_t result = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_SLOTFLGS_TYPE, slotFlags, + bundleInfo.GetBundleUid()); return (result == NativeRdb::E_OK); } @@ -553,8 +554,8 @@ bool NotificationPreferencesDatabase::PutHasPoppedDialog( } std::string bundleKey = GenerateBundleLablel(bundleInfo); - int32_t result = - PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_POPPED_DIALOG_TYPE, hasPopped); + int32_t result = PutBundlePropertyToDisturbeDB(bundleKey, BundleType::BUNDLE_POPPED_DIALOG_TYPE, hasPopped, + bundleInfo.GetBundleUid()); return (result == NativeRdb::E_OK); } @@ -781,11 +782,11 @@ bool NotificationPreferencesDatabase::ParseFromDisturbeDB(NotificationPreference ANS_LOGE("RdbStore is nullptr."); return false; } - std::unordered_map values; std::vector activeUserId; OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeUserId); for (auto iter : activeUserId) { + std::unordered_map values; int32_t result = rdbDataManager_->QueryDataBeginWithKey(KEY_BUNDLE_LABEL, values, iter); if (result == NativeRdb::E_ERROR) { ANS_LOGE("Get Bundle Info failed."); @@ -982,7 +983,7 @@ bool NotificationPreferencesDatabase::RemoveAllSlotsFromDisturbeDB( template int32_t NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( - const std::string &bundleKey, const BundleType &type, const T &t) + const std::string &bundleKey, const BundleType &type, const T &t, const int32_t &bundleUid) { std::string keyStr; switch (type) { @@ -1013,10 +1014,10 @@ int32_t NotificationPreferencesDatabase::PutBundlePropertyToDisturbeDB( ANS_LOGE("RdbStore is nullptr."); return false; } - int32_t callingUserId = -1; - OsAccountManagerHelper::GetInstance().GetCurrentCallingUserId(callingUserId); + int32_t userId = -1; + OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(bundleUid, userId); std::string valueStr = std::to_string(t); - int32_t result = rdbDataManager_->InsertData(keyStr, valueStr, callingUserId); + int32_t result = rdbDataManager_->InsertData(keyStr, valueStr, userId); return result; } @@ -1027,11 +1028,11 @@ bool NotificationPreferencesDatabase::PutBundleToDisturbeDB( ANS_LOGE("RdbStore is nullptr."); return false; } - int32_t callingUserId = -1; - OsAccountManagerHelper::GetInstance().GetCurrentCallingUserId(callingUserId); + int32_t userId = -1; + OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(bundleInfo.GetBundleUid(), userId); ANS_LOGD("Key not fund, so create a bundle, bundle key is %{public}s.", bundleKey.c_str()); - int32_t result = rdbDataManager_->InsertData(bundleKey, GenerateBundleLablel(bundleInfo), callingUserId); + int32_t result = rdbDataManager_->InsertData(bundleKey, GenerateBundleLablel(bundleInfo), userId); if (result != NativeRdb::E_OK) { ANS_LOGE("Store bundle name to db is failed."); return false; diff --git a/services/ans/src/notification_rdb_data_mgr.cpp b/services/ans/src/notification_rdb_data_mgr.cpp index 4d3c8b7d159bbb6c3b885801de00b6334e4b00c2..4f544d05921887917b0f6650d40659d020185d7d 100644 --- a/services/ans/src/notification_rdb_data_mgr.cpp +++ b/services/ans/src/notification_rdb_data_mgr.cpp @@ -15,6 +15,7 @@ #include "notification_rdb_data_mgr.h" #include "ans_log_wrapper.h" +#include "os_account_manager_helper.h" #include "rdb_errno.h" #include #include @@ -242,7 +243,7 @@ int32_t NotificationDataMgr::DeleteData(const std::string tableName, const std:: absRdbPredicates.EqualTo(NOTIFICATION_KEY, key); int32_t ret = rdbStore_->Delete(rowId, absRdbPredicates); if (ret != NativeRdb::E_OK) { - ANS_LOGE("Delete operation failed from %{public}s, result: %{public}d, key=%{public}s.", + ANS_LOGW("Delete operation failed from %{public}s, result: %{public}d, key=%{public}s.", tableName.c_str(), ret, key.c_str()); return NativeRdb::E_ERROR; } @@ -297,13 +298,13 @@ int32_t NotificationDataMgr::QueryData(const std::string tableName, const std::s absRdbPredicates.EqualTo(NOTIFICATION_KEY, key); auto absSharedResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (absSharedResultSet == nullptr) { - ANS_LOGD("absSharedResultSet failed from %{public}s table.", tableName.c_str()); + ANS_LOGE("absSharedResultSet failed from %{public}s table.", tableName.c_str()); return NativeRdb::E_ERROR; } int32_t ret = absSharedResultSet->GoToFirstRow(); if (ret != NativeRdb::E_OK) { - ANS_LOGE("GoToFirstRow failed from %{public}s table. It is empty!, key=%{public}s", + ANS_LOGW("GoToFirstRow failed from %{public}s table. It is empty!, key=%{public}s", tableName.c_str(), key.c_str()); return NativeRdb::E_EMPTY_VALUES_BUCKET; } @@ -337,13 +338,13 @@ int32_t NotificationDataMgr::QueryData(const std::string tableName, const std::s absRdbPredicates.EqualTo(NOTIFICATION_KEY, key); auto absSharedResultSet = rdbStore_->Query(absRdbPredicates, std::vector()); if (absSharedResultSet == nullptr) { - ANS_LOGD("absSharedResultSet failed from %{public}s table.", tableName.c_str()); + ANS_LOGE("absSharedResultSet failed from %{public}s table.", tableName.c_str()); return NativeRdb::E_ERROR; } int32_t ret = absSharedResultSet->GoToFirstRow(); if (ret != NativeRdb::E_OK) { - ANS_LOGE("GoToFirstRow failed from %{public}s table. It is empty!, key=%{public}s", + ANS_LOGW("GoToFirstRow failed from %{public}s table. It is empty!, key=%{public}s", tableName.c_str(), key.c_str()); return NativeRdb::E_EMPTY_VALUES_BUCKET; } @@ -371,7 +372,10 @@ int32_t NotificationDataMgr::QueryDataBeginWithKey( int32_t ret = QueryDataBeginWithKey(tableName, key, values); int32_t ret2 = QueryDataBeginWithKey(notificationRdbConfig_.tableName, key, values); if (ret != NativeRdb::E_OK && ret2 != NativeRdb::E_OK) { - ANS_LOGE("Query data begin with key failed."); + if (ret == NativeRdb::E_EMPTY_VALUES_BUCKET && ret2 == NativeRdb::E_EMPTY_VALUES_BUCKET) { + ANS_LOGW("Query data begin with key failed. It is empty!"); + return NativeRdb::E_EMPTY_VALUES_BUCKET; + } return NativeRdb::E_ERROR; } } @@ -391,7 +395,7 @@ int32_t NotificationDataMgr::QueryDataBeginWithKey( int32_t ret = absSharedResultSet->GoToFirstRow(); if (ret != NativeRdb::E_OK) { - ANS_LOGE("GoToFirstRow failed from %{public}s table.It is empty!, key=%{public}s", + ANS_LOGW("GoToFirstRow failed from %{public}s table.It is empty!, key=%{public}s", tableName.c_str(), key.c_str()); return NativeRdb::E_EMPTY_VALUES_BUCKET; } @@ -431,7 +435,10 @@ int32_t NotificationDataMgr::QueryAllData(std::unordered_mapGoToFirstRow(); if (ret != NativeRdb::E_OK) { - ANS_LOGE("GoToFirstRow failed from %{public}s table. It is empty!", tableName.c_str()); + ANS_LOGW("GoToFirstRow failed from %{public}s table. It is empty!", tableName.c_str()); return NativeRdb::E_EMPTY_VALUES_BUCKET; } @@ -502,7 +509,7 @@ int32_t NotificationDataMgr::DropUserTable(const int32_t userId) std::string NotificationDataMgr::GetUserTableName(const int32_t &userId) { - if (userId == -1) { + if (!OsAccountManagerHelper::IsSystemAccount(userId)) { return notificationRdbConfig_.tableName; } diff --git a/services/ans/src/os_account_manager_helper.cpp b/services/ans/src/os_account_manager_helper.cpp index bf1b1f76d35cc1dd102144283e4de7a01c86ad4c..55a3baa29b72122a800a6d94b61827b0b39d2337 100644 --- a/services/ans/src/os_account_manager_helper.cpp +++ b/services/ans/src/os_account_manager_helper.cpp @@ -12,10 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "ans_log_wrapper.h" #include "os_account_manager_helper.h" +#include "errors.h" +#include "os_account_constants.h" #include "ipc_skeleton.h" +#include "os_account_info.h" #include "os_account_manager.h" +#include namespace OHOS { namespace Notification { @@ -35,7 +40,16 @@ ErrCode OsAccountManagerHelper::GetCurrentActiveUserId(int32_t &id) int32_t ret = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeUserId); if (activeUserId.size() > 0) { id = activeUserId[0]; - return ret; + } + return ret; +} + +ErrCode OsAccountManagerHelper::GetAllOsAccount(std::vector &userIds) +{ + std::vector accounts; + int32_t ret = OHOS::AccountSA::OsAccountManager::QueryAllCreatedOsAccounts(accounts); + for (auto item : accounts) { + userIds.emplace_back(item.GetLocalId()); } return ret; } @@ -43,7 +57,10 @@ ErrCode OsAccountManagerHelper::GetCurrentActiveUserId(int32_t &id) bool OsAccountManagerHelper::CheckUserExists(const int32_t &userId) { bool isAccountExists = false; - OHOS::AccountSA::OsAccountManager::IsOsAccountExists(userId, isAccountExists); + int32_t ret = OHOS::AccountSA::OsAccountManager::IsOsAccountExists(userId, isAccountExists); + if (ret != ERR_OK) { + ANS_LOGE("Failed to call AccountSA::IsOsAccountExists, code is %{public}d", ret); + } return isAccountExists; } @@ -52,5 +69,10 @@ OsAccountManagerHelper &OsAccountManagerHelper::GetInstance() return DelayedRefSingleton::GetInstance(); } + +bool OsAccountManagerHelper::IsSystemAccount(int32_t userId) +{ + return userId >= AccountSA::Constants::START_USER_ID && userId <= AccountSA::Constants::MAX_USER_ID; +} } } \ No newline at end of file diff --git a/services/ans/src/reminder_data_manager.cpp b/services/ans/src/reminder_data_manager.cpp index 09d12afea18e17d2933de9777474bdef8b040053..7db7360eecb3dc5e0c99ba99d36c7deae67f4b52 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/ans/src/reminder_data_manager.cpp @@ -45,6 +45,7 @@ #include "app_mgr_constants.h" #include "iservice_registry.h" #include "config_policy_utils.h" +#include "hitrace_meter_adapter.h" namespace OHOS { namespace Notification { @@ -83,6 +84,7 @@ ReminderDataManager::~ReminderDataManager() = default; ErrCode ReminderDataManager::PublishReminder(const sptr &reminder, const sptr &bundleOption) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); uint32_t callerTokenId = IPCSkeleton::GetCallingTokenID(); if (callerTokenId == 0) { ANSR_LOGE("pushlish failed, callerTokenId is 0"); @@ -107,6 +109,7 @@ ErrCode ReminderDataManager::PublishReminder(const sptr &remind ErrCode ReminderDataManager::CancelReminder( const int32_t &reminderId, const sptr &bundleOption) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); ANSR_LOGI("cancel reminder id: %{public}d", reminderId); sptr reminder = FindReminderRequestLocked(reminderId, bundleOption->GetBundleName()); if (reminder == nullptr) { @@ -135,6 +138,7 @@ ErrCode ReminderDataManager::CancelReminder( ErrCode ReminderDataManager::CancelAllReminders(const std::string &packageName, const int32_t &userId) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); ANSR_LOGD("CancelAllReminders, userId=%{private}d, pkgName=%{public}s", userId, packageName.c_str()); CancelRemindersImplLocked(packageName, userId); @@ -164,6 +168,7 @@ sptr ReminderDataManager::CheckExcludeDateParam(const int32_t r ErrCode ReminderDataManager::AddExcludeDate(const int32_t reminderId, const uint64_t date, const sptr &bundleOption) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); sptr reminder = CheckExcludeDateParam(reminderId, bundleOption); if (reminder == nullptr) { return ERR_REMINDER_NOT_EXIST; @@ -180,6 +185,7 @@ ErrCode ReminderDataManager::AddExcludeDate(const int32_t reminderId, const uint ErrCode ReminderDataManager::DelExcludeDates(const int32_t reminderId, const sptr &bundleOption) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); sptr reminder = CheckExcludeDateParam(reminderId, bundleOption); if (reminder == nullptr) { return ERR_REMINDER_NOT_EXIST; @@ -196,6 +202,7 @@ ErrCode ReminderDataManager::DelExcludeDates(const int32_t reminderId, ErrCode ReminderDataManager::GetExcludeDates(const int32_t reminderId, const sptr &bundleOption, std::vector& dates) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); sptr reminder = CheckExcludeDateParam(reminderId, bundleOption); if (reminder == nullptr) { return ERR_REMINDER_NOT_EXIST; @@ -211,6 +218,7 @@ ErrCode ReminderDataManager::GetExcludeDates(const int32_t reminderId, void ReminderDataManager::GetValidReminders( const sptr &bundleOption, std::vector> &reminders) { + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); std::lock_guard lock(ReminderDataManager::MUTEX); for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { if ((*it)->IsExpired()) { @@ -1353,7 +1361,7 @@ void ReminderDataManager::HandleImmediatelyShow( { bool isAlerting = false; for (auto it = showImmediately.begin(); it != showImmediately.end(); ++it) { - if (!isAlerting) { + if (((*it)->GetRingDuration() > 0) && !isAlerting) { ShowReminder((*it), true, false, isSysTimeChanged, true); isAlerting = true; } else { diff --git a/services/ans/src/system_dialog_connect_stb.cpp b/services/ans/src/system_dialog_connect_stb.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f879774e0f5c93207f991979ea6a1fbac6cf02a4 --- /dev/null +++ b/services/ans/src/system_dialog_connect_stb.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 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 "system_dialog_connect_stb.h" +#include "ability_connect_callback_interface.h" +#include "ability_manager_client.h" +#include "ans_log_wrapper.h" +#include "ans_inner_errors.h" +#include "common_event_manager.h" + +constexpr int32_t SIGNAL_NUM = 3; +constexpr int32_t DIALOG_CRASH_CODE = 2; +const static std::string DIALOG_CRASH_EVENT = "OnNotificationServiceDialogClicked"; + +namespace OHOS { +namespace Notification { + +void SystemDialogConnectStb::OnAbilityConnectDone(const AppExecFwk::ElementName &element, + const sptr &remoteObject, int32_t resultCode) +{ + ANS_LOGI("on ability connected"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInt32(SIGNAL_NUM); + data.WriteString16(u"bundleName"); + data.WriteString16(u"com.ohos.notificationdialog"); + data.WriteString16(u"abilityName"); + data.WriteString16(u"EnableNotificationDialog"); + data.WriteString16(u"parameters"); + data.WriteString16(Str8ToStr16(commandStr_)); + + int32_t errCode = remoteObject->SendRequest(IAbilityConnection::ON_ABILITY_CONNECT_DONE, data, reply, option); + ANS_LOGI("AbilityConnectionWrapperProxy::OnAbilityConnectDone result %{public}d", errCode); + if (errCode != ERR_OK) { + ANS_LOGD("send Request to SytemDialog fail"); + SendCrashEvent(); + } +} + +void SystemDialogConnectStb::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, + int32_t resultCode) +{ + ANS_LOGI("on ability disconnected"); +} + +void SystemDialogConnectStb::SendCrashEvent() +{ + EventFwk::Want want; + want.SetAction(DIALOG_CRASH_EVENT); + + EventFwk::CommonEventData commonData; + commonData.SetWant(want); + commonData.SetCode(DIALOG_CRASH_CODE); + nlohmann::json root = nlohmann::json::parse(commandStr_); + std::string from = root["from"]; + commonData.SetData(from); + if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData)) { + ANS_LOGE("Publish Dialog Crash failed"); + } +} + +} +} \ No newline at end of file diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index abc135fd1b515ba7d294107cd01e6914048616bd..218408469ee56639ee4303b7773932738184a3a7 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -670,6 +670,7 @@ ohos_unittest("notification_preferences_database_branch_test") { "${services_path}/ans/src/notification_preferences_database.cpp", "${services_path}/ans/src/notification_preferences_info.cpp", "${services_path}/ans/src/os_account_manager_helper.cpp", + "notification_dialog_test/mock_os_account_manager_annex.cpp", "notification_preferences_database_branch_test/mock_notification_rdb_data_mgr.cpp", "notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp", ] diff --git a/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp b/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp index 074fbc1a2150fc193594e13f7cb9ccd675b1db4a..5145504bc7e0e506574bfb471395ada46056fa03 100644 --- a/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_live_view_service_test.cpp @@ -81,7 +81,7 @@ void AnsLiveViewServiceTest::SetUp() advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService(); NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings(); - advancedNotificationService_->CancelAll(); + advancedNotificationService_->CancelAll(0); MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); MockIsSystemApp(true); GTEST_LOG_(INFO) << "SetUp end"; @@ -182,6 +182,7 @@ HWTEST_F(AnsLiveViewServiceTest, GetNotificationRequestFromDb_00002, Function | sptr request = new (std::nothrow) NotificationRequest(); request->SetSlotType(slotType); request->SetNotificationId(1); + request->SetReceiverUserId(100); auto liveContent = std::make_shared(); auto content = std::make_shared(liveContent); request->SetContent(content); diff --git a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp index 33a53563e3707a5a3ee89dbf7f81ee8479094b4e..e2a5588a2b1ec594695545177db6b2caef72977a 100644 --- a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp @@ -69,7 +69,7 @@ void AnsPublishServiceTest::SetUp() advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService(); NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings(); - advancedNotificationService_->CancelAll(); + advancedNotificationService_->CancelAll(0); MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); MockIsSystemApp(true); GTEST_LOG_(INFO) << "SetUp end"; @@ -219,10 +219,58 @@ HWTEST_F(AnsPublishServiceTest, Publish_00004, Function | SmallTest | Level1) NotificationConstant::SlotType slotType = NotificationConstant::SlotType::LIVE_VIEW; ret = advancedNotificationService_->GetSlotByType(slotType, slot); EXPECT_EQ(ret, (int)ERR_OK); - EXPECT_EQ(1, slot->GetAuthorizedStatus()); + EXPECT_EQ(0, slot->GetAuthorizedStatus()); EXPECT_EQ(2, slot->GetAuthHintCnt()); } +/** + * @tc.name: Publish_00005 + * @tc.desc: Publish test receiver user and checkUserExists is true + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(AnsPublishServiceTest, Publish_00005, Function | SmallTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(); + std::string label = ""; + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + request->SetNotificationId(1); + request->SetReceiverUserId(101); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + MockIsOsAccountExists(true); + RegisterPushCheck(); + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); + MockIsSystemApp(true); + MockIsVerfyPermisson(false); + + auto ret = advancedNotificationService_->Publish(label, request); + EXPECT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED); +} + +/** + * @tc.name: Publish_00006 + * @tc.desc: Publish test receiver user and checkUserExists is false + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(AnsPublishServiceTest, Publish_00006, Function | SmallTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(); + std::string label = ""; + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + request->SetNotificationId(1); + request->SetReceiverUserId(101); + auto liveContent = std::make_shared(); + auto content = std::make_shared(liveContent); + request->SetContent(content); + MockIsOsAccountExists(false); + + auto ret = advancedNotificationService_->Publish(label, request); + EXPECT_EQ(ret, (int)ERROR_USER_NOT_EXIST); +} + /** * @tc.name: DeleteByBundle_00001 * @tc.desc: Test DeleteByBundle @@ -382,6 +430,7 @@ HWTEST_F(AnsPublishServiceTest, RequestEnableNotification_00002, Function | Smal auto ret = advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true); EXPECT_EQ(ret, (int)ERR_OK); + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); ret = advancedNotificationService_->RequestEnableNotification(deviceId, client, callerToken); EXPECT_EQ(ret, (int)ERR_OK); } @@ -403,6 +452,8 @@ HWTEST_F(AnsPublishServiceTest, RequestEnableNotification_00003, Function | Smal auto ret = advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), false); EXPECT_EQ(ret, (int)ERR_OK); + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); + auto bundle = advancedNotificationService_->GenerateBundleOption(); NotificationPreferences::GetInstance().SetHasPoppedDialog(bundle, true); @@ -628,13 +679,13 @@ HWTEST_F(AnsPublishServiceTest, NotificationSvrQueue_00001, Function | SmallTest advancedNotificationService_->notificationSvrQueue_ = nullptr; auto bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID); - auto ret = advancedNotificationService_->CancelAll(); + auto ret = advancedNotificationService_->CancelAll(0); EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); ret = advancedNotificationService_->Delete("", 1); EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); - ret = advancedNotificationService_->CancelGroup("group"); + ret = advancedNotificationService_->CancelGroup("group", 0); EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); ret = advancedNotificationService_->RemoveGroupByBundle(bundle, "group"); @@ -652,7 +703,7 @@ HWTEST_F(AnsPublishServiceTest, NotificationSvrQueue_00001, Function | SmallTest ret = advancedNotificationService_->GetEnabledForBundleSlot(bundle, slotType, enabled); EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); - ret = advancedNotificationService_->SetBadgeNumber(1); + ret = advancedNotificationService_->SetBadgeNumber(1, 0); EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); ret = advancedNotificationService_->SubscribeLocalLiveView(nullptr, nullptr, true); diff --git a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp index 34eb11533d6f7d67c328cad9d86b1530ada1ff48..d60370b39ea5c03432d523e321917a53638eacb2 100644 --- a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp @@ -83,7 +83,7 @@ void AnsBranchTest::SetUp() IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings(); - advancedNotificationService_->CancelAll(); + advancedNotificationService_->CancelAll(0); MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); MockIsSystemApp(true); GTEST_LOG_(INFO) << "SetUp end"; diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index eb048f7b4d85b3fdee14ec560d6e4863ae56885d..53504ae15a4c2287b331f5c997b956c90bb22989 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -76,7 +76,10 @@ private: sptr AdvancedNotificationServiceTest::advancedNotificationService_ = nullptr; -void AdvancedNotificationServiceTest::SetUpTestCase() {} +void AdvancedNotificationServiceTest::SetUpTestCase() +{ + MockIsOsAccountExists(true); +} void AdvancedNotificationServiceTest::TearDownTestCase() {} @@ -88,9 +91,8 @@ void AdvancedNotificationServiceTest::SetUp() IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings(); IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); - advancedNotificationService_->CancelAll(); + advancedNotificationService_->CancelAll(0); MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); - MockIsOsAccountExists(true); GTEST_LOG_(INFO) << "SetUp end"; } @@ -675,7 +677,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02800, HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02900, Function | SmallTest | Level1) { std::vector> notifications; - EXPECT_EQ((int)advancedNotificationService_->GetActiveNotifications(notifications), (int)ERR_OK); + EXPECT_EQ((int)advancedNotificationService_->GetActiveNotifications(notifications, 0), (int)ERR_OK); } /** @@ -809,7 +811,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04700, req->SetCreatorUid(1); EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK); } - EXPECT_EQ(advancedNotificationService_->Cancel(1, label), (int)ERR_OK); + EXPECT_EQ(advancedNotificationService_->Cancel(1, label, 0), (int)ERR_OK); } /** @@ -821,7 +823,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04800, { int32_t notificationId = 0; std::string label = "testLabel"; - EXPECT_EQ((int)advancedNotificationService_->Cancel(notificationId, label), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); + EXPECT_EQ((int)advancedNotificationService_->Cancel( + notificationId, label, 0), (int)ERR_ANS_NOTIFICATION_NOT_EXISTS); } /** @@ -834,7 +837,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04900, TestAddSlot(NotificationConstant::SlotType::OTHER); sptr req = new NotificationRequest(1); req->SetSlotType(NotificationConstant::OTHER); - EXPECT_EQ(advancedNotificationService_->CancelAll(), (int)ERR_OK); + EXPECT_EQ(advancedNotificationService_->CancelAll(0), (int)ERR_OK); } /** @@ -855,7 +858,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05000, req->SetUnremovable(true); req->SetCreatorUid(1); EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK); - EXPECT_EQ(advancedNotificationService_->Cancel(notificationId, label), (int)ERR_OK); + EXPECT_EQ(advancedNotificationService_->Cancel(notificationId, label, 0), (int)ERR_OK); } /** @@ -1002,7 +1005,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06900, HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_07000, Function | SmallTest | Level1) { std::vector> notifications; - EXPECT_EQ((int)advancedNotificationService_->GetActiveNotifications(notifications), (int)ERR_OK); + EXPECT_EQ((int)advancedNotificationService_->GetActiveNotifications(notifications, 0), (int)ERR_OK); } /** @@ -1341,7 +1344,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10300, std::string groupName = "group"; req->SetGroupName(groupName); EXPECT_EQ(advancedNotificationService_->Publish("label", req), (int)ERR_OK); - EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), (int)ERR_OK); + EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName, 0), (int)ERR_OK); SleepForFC(); } @@ -1700,6 +1703,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12300, std::shared_ptr content = std::make_shared(normalContent); EXPECT_NE(content, nullptr); req->SetContent(content); + + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_ANS_INVALID_UID); SleepForFC(); @@ -2415,7 +2420,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16900, MockIsNonBundleName(true); MockSystemApp(); std::vector> notifications; - EXPECT_EQ(advancedNotificationService_->GetActiveNotifications(notifications), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->GetActiveNotifications(notifications, 0), ERR_ANS_INVALID_BUNDLE); uint64_t num = 1; EXPECT_EQ(advancedNotificationService_->GetActiveNotificationNums(num), ERR_ANS_INVALID_BUNDLE); EXPECT_EQ(advancedNotificationService_->SetNotificationBadgeNum(num), ERR_ANS_INVALID_BUNDLE); @@ -2450,7 +2455,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16900, ERR_ANS_INVALID_BUNDLE); std::string groupName = "name"; - EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), ERR_ANS_INVALID_BUNDLE); + EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName, 0), ERR_ANS_INVALID_BUNDLE); bool enabled = true; EXPECT_EQ(advancedNotificationService_->EnableDistributedSelf(enabled), ERR_ANS_INVALID_BUNDLE); @@ -2897,7 +2902,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18900, GTEST_LOG_(INFO) << "CancelGroup_1000 test start"; std::string groupName = ""; - EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName), ERR_ANS_INVALID_PARAM); + EXPECT_EQ(advancedNotificationService_->CancelGroup(groupName, 0), ERR_ANS_INVALID_PARAM); GTEST_LOG_(INFO) << "CancelGroup_1000 test end"; } @@ -3586,7 +3591,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00004, { GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_00004 test start"; int32_t badgeNumber = 1; - EXPECT_EQ(advancedNotificationService_->SetBadgeNumber(badgeNumber), ERR_OK); + EXPECT_EQ(advancedNotificationService_->SetBadgeNumber(badgeNumber, 0), ERR_OK); GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_00004 test end"; } @@ -3603,7 +3608,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00005, advancedNotificationService_->runner_ = OHOS::AppExecFwk::EventRunner::Create("NotificationSvrMain"); advancedNotificationService_->handler_ = std::make_shared(advancedNotificationService_->runner_); - EXPECT_EQ(advancedNotificationService_->SetBadgeNumber(badgeNumber), ERR_OK); + EXPECT_EQ(advancedNotificationService_->SetBadgeNumber(badgeNumber, 0), ERR_OK); GTEST_LOG_(INFO) << "AdvancedNotificationServiceTest_00005 test end"; } @@ -4397,7 +4402,7 @@ HWTEST_F(AdvancedNotificationServiceTest, NotificationSvrQueue_00001, Function | EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); std::vector> requests; - ret = advancedNotificationService_->GetActiveNotifications(requests); + ret = advancedNotificationService_->GetActiveNotifications(requests, 0); EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); uint64_t num = 0; diff --git a/services/ans/test/unittest/advanced_notification_slot_service_test.cpp b/services/ans/test/unittest/advanced_notification_slot_service_test.cpp index fc3b5e5a368007f8f897f0301d1eff2e5564947d..1dfda287ab1755475e07c97b66f2bb43f8b3ef10 100644 --- a/services/ans/test/unittest/advanced_notification_slot_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_slot_service_test.cpp @@ -64,7 +64,7 @@ void AnsSlotServiceTest::SetUp() advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService(); NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings(); - advancedNotificationService_->CancelAll(); + advancedNotificationService_->CancelAll(0); MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); MockIsSystemApp(true); GTEST_LOG_(INFO) << "SetUp end"; diff --git a/services/ans/test/unittest/advanced_notification_utils_test.cpp b/services/ans/test/unittest/advanced_notification_utils_test.cpp index 92ef86b99fc41bf20188f90782ab74df756639c6..4a37c3132ee81be965e2f973ec22e2f6b39e6bdc 100644 --- a/services/ans/test/unittest/advanced_notification_utils_test.cpp +++ b/services/ans/test/unittest/advanced_notification_utils_test.cpp @@ -75,7 +75,7 @@ void AnsUtilsTest::SetUp() advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService(); NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings(); - advancedNotificationService_->CancelAll(); + advancedNotificationService_->CancelAll(0); MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); MockIsSystemApp(true); GTEST_LOG_(INFO) << "SetUp end"; diff --git a/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp b/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp index 5897fa66e25d676c420e82817a46b2e7b2093fe4..cd1f4fbda74427a57f7966f7f8c3fc320d1d40c5 100755 --- a/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp +++ b/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp @@ -544,7 +544,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0310 BundleType type = BundleType::BUNDLE_BADGE_TOTAL_NUM_TYPE; // test PutBundlePropertyToDisturbeDB function std::string bundleKey = ""; - EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), false); + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true, 0), false); } /** @@ -560,7 +560,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0320 BundleType type = BundleType::BUNDLE_IMPORTANCE_TYPE; // test PutBundlePropertyToDisturbeDB function std::string bundleKey = ""; - EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), false); + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true, 0), false); } /** @@ -576,7 +576,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0330 BundleType type = BundleType::BUNDLE_SHOW_BADGE_TYPE; // test PutBundlePropertyToDisturbeDB function std::string bundleKey = ""; - EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), false); + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true, 0), false); } /** @@ -592,7 +592,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0350 BundleType type = BundleType::BUNDLE_ENABLE_NOTIFICATION_TYPE; // test PutBundlePropertyToDisturbeDB function std::string bundleKey = ""; - EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), false); + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true, 0), false); } /** @@ -608,7 +608,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0360 BundleType type = BundleType::BUNDLE_POPPED_DIALOG_TYPE; // test PutBundlePropertyToDisturbeDB function std::string bundleKey = ""; - EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), false); + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true, 0), false); } /** @@ -624,7 +624,7 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_0370 BundleType type = BundleType::BUNDLE_NAME_TYPE; // test PutBundlePropertyToDisturbeDB function std::string bundleKey = ""; - EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), false); + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true, 0), false); } /** diff --git a/services/ans/test/unittest/os_account_manager_helper_test.cpp b/services/ans/test/unittest/os_account_manager_helper_test.cpp index bd46d57cbef36f7ded3de87ac4b6f26e11229c8f..2ff4547da9cb622ba32148a9ca69ccdaef3fc3ee 100644 --- a/services/ans/test/unittest/os_account_manager_helper_test.cpp +++ b/services/ans/test/unittest/os_account_manager_helper_test.cpp @@ -86,5 +86,49 @@ HWTEST_F(OsAccountManagerHelperTest, CheckUserExists_00200, Function | SmallTest int32_t userId = 1099; EXPECT_EQ(false, OsAccountManagerHelper::GetInstance().CheckUserExists(userId)); } + +/** + * @tc.number : IsSystemAccount_0100 + * @tc.name : IsSystemAccount_0100 + * @tc.desc : test IsSystemAccount function, 100 is true(100 <= userId <= 1099) + */ +HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0100, Function | SmallTest | Level1) +{ + int32_t userId = 100; + EXPECT_EQ(true, OsAccountManagerHelper::IsSystemAccount(userId)); +} + +/** + * @tc.number : IsSystemAccount_0200 + * @tc.name : IsSystemAccount_0200 + * @tc.desc : test IsSystemAccount function, 1100 is false(100 <= userId <= 1099) + */ +HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0200, Function | SmallTest | Level1) +{ + int32_t userId = 1100; + EXPECT_EQ(false, OsAccountManagerHelper::IsSystemAccount(userId)); +} + +/** + * @tc.number : IsSystemAccount_0300 + * @tc.name : IsSystemAccount_0300 + * @tc.desc : test IsSystemAccount function, 0 is false(100 <= userId <= 1099) + */ +HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0300, Function | SmallTest | Level1) +{ + int32_t userId = 0; + EXPECT_EQ(false, OsAccountManagerHelper::IsSystemAccount(userId)); +} + +/** + * @tc.number : IsSystemAccount_0400 + * @tc.name : IsSystemAccount_0400 + * @tc.desc : test IsSystemAccount function, 1099 is true(100 <= userId <= 1099) + */ +HWTEST_F(OsAccountManagerHelperTest, IsSystemAccount_0400, Function | SmallTest | Level1) +{ + int32_t userId = 1099; + EXPECT_EQ(true, OsAccountManagerHelper::IsSystemAccount(userId)); +} } } \ No newline at end of file diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/ans/test/unittest/reminder_data_manager_test.cpp index df1905a61f8d95c01a3f50126db7330169196d3d..4b3268e88a9ac89030e82fb676eb9d03533ce6b3 100644 --- a/services/ans/test/unittest/reminder_data_manager_test.cpp +++ b/services/ans/test/unittest/reminder_data_manager_test.cpp @@ -709,8 +709,6 @@ HWTEST_F(ReminderDataManagerTest, OnLanguageChanged_0001, Level1) */ HWTEST_F(ReminderDataManagerTest, ExcludeDate_0001, Level1) { - manager->reminderVector_.clear(); - std::vector dates; auto result = manager->CheckExcludeDateParam(9999, nullptr); EXPECT_TRUE(result == nullptr); @@ -754,8 +752,6 @@ HWTEST_F(ReminderDataManagerTest, ExcludeDate_0001, Level1) ret = manager->GetExcludeDates(100, option, dates); EXPECT_TRUE(ret == ERR_OK); - - manager->reminderVector_.clear(); } /** diff --git a/services/dialog_ui/enable_notification_dialog/AppScope/app.json b/services/dialog_ui/enable_notification_dialog/AppScope/app.json index 9d9d3273853cdd21dd7495949eb5a48c4aefb6eb..6d68189dce4485b0b764a4b26c2926d786350b6c 100644 --- a/services/dialog_ui/enable_notification_dialog/AppScope/app.json +++ b/services/dialog_ui/enable_notification_dialog/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.notificationdialog", "vendor": "example", - "versionCode": 1000001, - "versionName": "1.0.1", + "versionCode": 1000002, + "versionName": "1.0.2", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true, diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts index 5566ae8573acb401baacb3ddd0074f098c8a39cd..3cf9ce95f9cae19d0779302be7c819cde32d9b93 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/ServiceExtAbility/NotificationServiceExtAbility.ts @@ -19,6 +19,12 @@ import extension from '@ohos.app.ability.ServiceExtensionAbility'; import window from '@ohos.window'; import CommonEventManager from '@ohos.commonEventManager'; import type Want from '@ohos.app.ability.Want'; +import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import uiExtensionHost from '@ohos.uiExtensionHost'; +import StartOptions from '@ohos.app.ability.StartOptions'; + + const TAG = 'NotificationDialog_Service '; @@ -55,12 +61,14 @@ export class EnableNotificationDialog { id: number; want: Want; window: window.Window; + extensionWindow:uiExtensionHost.UIExtensionHostWindowProxy; storage: LocalStorage; constructor(id: number, want: Want) { this.id = id; this.want = want; this.window = undefined; + this.extensionWindow = undefined; } async createWindow(windowType: window.WindowType, context, displayRect): Promise { @@ -106,6 +114,30 @@ export class EnableNotificationDialog { } } + + async createUiExtensionWindow(session: UIExtensionContentSession): Promise { + try { + let extensionWindow = session.getUIExtensionHostWindowProxy(); + this.extensionWindow = extensionWindow; + let shouldHide = true; + + this.storage = new LocalStorage({ + 'dialog': this, + 'session': session + }); + await session.loadContent(EnableNotificationDialog.DIALOG_PATH, this.storage); + try { + await extensionWindow.hideNonSecureWindows(shouldHide); + } catch (err) { + console.error(TAG, 'window hideNonSecureWindows failed!'); + } + await session.setWindowBackgroundColor(EnableNotificationDialog.TRANSPARANT_COLOR); + } catch (err) { + console.error(TAG, 'window create failed!'); + throw new Error('Failed to create window'); + } + } + async publishButtonClickedEvent(enabled: boolean): Promise { CommonEventManager.publish( COMMON_EVENT_NAME, @@ -118,15 +150,7 @@ export class EnableNotificationDialog { } async destroyException(): Promise { - if (this.window !== undefined) { - emitter.emit(enableNotificationDialogDestroyedEvent, { - data: { - 'id': this.id - } - }); - await handleDialogQuitException(this.want); - await this.destroyWindow(); - } + await handleDialogQuitException(this.want); } async destroy(): Promise { @@ -147,71 +171,43 @@ export class EnableNotificationDialog { }; -class NotificationDialogServiceExtensionAbility extends extension { - static MAX_DIALOG_NUM = 10; - dialogs: Array = []; +class NotificationDialogServiceExtensionAbility extends UIExtensionAbility { - onCreate(want: Want): void { - console.info(TAG, `onCreate, want: ${JSON.stringify(want)}`); + onCreate() { + console.log(TAG, `UIExtAbility onCreate`); AppStorage.SetOrCreate('context', this.context); - emitter.on(enableNotificationDialogDestroyedEvent, (data) => { - let did = data.data.id; - this.dialogs = this.dialogs.filter((dialog: EnableNotificationDialog) => { - return dialog.id !== did; - }); - console.info(TAG, `Dialog ${did} destroyed.`); - if (this.dialogs.length === 0) { - this.context.terminateSelf(); - console.info(TAG, 'terminated'); - } - }); + } - async onRequest(want: Want, startId: number): Promise { - console.log(TAG, `onRequest ${startId}`); + async onSessionCreate(want: Want, session: UIExtensionContentSession) { + console.log(TAG, `UIExtAbility onSessionCreate`); try { - await this.removeExceededDialog(); - let dialog = new EnableNotificationDialog(startId, want); - let winType = want.parameters.callerToken !== undefined ? - window.WindowType.TYPE_DIALOG : window.WindowType.TYPE_FLOAT; - let dis = display.getDefaultDisplaySync(); - let navigationBarRect = { - left: 0, - top: 0, - width: dis.width, - height: dis.height - }; - await dialog.createWindow(winType, this.context, navigationBarRect); - this.dialogs.push(dialog); + let dialog = new EnableNotificationDialog(1, want); + await dialog.createUiExtensionWindow(session); } catch (err) { - console.error(TAG, `Failed to handle request ${startId}.`); + console.error(TAG, `Failed to handle onSessionCreate`); await handleDialogQuitException(want); } } - onDestroy(): void { - console.info(TAG, 'onDestroy.'); - CommonEventManager.publish( - COMMON_EVENT_NAME, - { - code: DialogStatus.DIALOG_SERVICE_DESTROYED - } as CommonEventManager.CommonEventPublishData, - () => { console.info(TAG, 'publish DIALOG_SERVICE_DESTROYED succeeded'); } - ); + onForeground() { + console.log(TAG, `UIExtAbility onForeground`); } - private async removeExceededDialog(): Promise { - if (this.dialogs.length >= NotificationDialogServiceExtensionAbility.MAX_DIALOG_NUM) { - // remove dialogs by creating time - let removed = this.dialogs.splice(0, - this.dialogs.length - NotificationDialogServiceExtensionAbility.MAX_DIALOG_NUM + 1); - for (let dialog of removed) { - await handleDialogQuitException(dialog.want); - await dialog.destroyWindow(); - } - } + onBackground() { + console.log(TAG, `UIExtAbility onBackground`); } -}; + + onSessionDestroy(session: UIExtensionContentSession) { + console.log(TAG, `UIExtAbility onSessionDestroy`); + } + + onDestroy() { + console.info(TAG, 'UIExtAbility onDestroy.'); + this.context.terminateSelf(); + } +} + export default NotificationDialogServiceExtensionAbility; diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/common/constant.ets b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/common/constant.ets index e0b9d971a970289520aec3094cca326cac04ffb9..7f02cbec204e50eeb099d8b2500870595eae21e4 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/common/constant.ets +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/common/constant.ets @@ -14,130 +14,131 @@ */ export default class Constants { - // grid useSizeType - static GUTTER = 0; - static XS_COLUMNS = 2; - static XS_SPAN = 2; - static XS_OFFSET = 0; - static SM_COLUMNS = 4; - static SM_SPAN = 4; - static SM_OFFSET = 0; - static MD_COLUMNS = 8; - static MD_SPAN = 8; - static MD_OFFSET = 0; - static LG_COLUMNS = 12; - static LG_SPAN = 8; - static LG_OFFSET = 2; + // grid useSizeType + static GUTTER = 0; + static XS_COLUMNS = 2; + static XS_SPAN = 2; + static XS_OFFSET = 0; + static SM_COLUMNS = 4; + static SM_SPAN = 4; + static SM_OFFSET = 0; + static MD_COLUMNS = 8; + static MD_SPAN = 8; + static MD_OFFSET = 0; + static LG_COLUMNS = 12; + static LG_SPAN = 8; + static LG_OFFSET = 2; - static DIALOG_GUTTER = 16; - static DIALOG_MARGIN = 16; - static DIALOG_MARGIN_VERTICAL = 12; - static DIALOG_MD_SPAN = 4; - static DIALOG_MD_OFFSET = 2; - static DIALOG_LG_SPAN = 4; - static DIALOG_LG_OFFSET = 4; + static DIALOG_GUTTER = 16; + static DIALOG_MARGIN = 16; + static DIALOG_MARGIN_VERTICAL = 12; + static DIALOG_MD_SPAN = 4; + static DIALOG_MD_OFFSET = 2; + static DIALOG_LG_SPAN = 4; + static DIALOG_LG_OFFSET = 4; - // 100% width,height - static FULL_WIDTH = '100%'; - static FULL_HEIGHT = '100%'; + // 100% width,height + static FULL_WIDTH = '100%'; + static FULL_HEIGHT = '100%'; - // public property style - static PERMISSION = 1; - static APPLICATION = 0; - static LAYOUT_WEIGHT = 1; - static FLEX_GROW = 1; - static TEXT_BIG_FONT_SIZE = 20; - static TEXT_MIDDLE_FONT_SIZE = 16; - static TEXT_SMALL_FONT_SIZE = 14; - static TEXT_SMALLER_FONT_SIZE = 12; - static TEXT_LINE_HEIGHT = 22; - static TEXT_BIG_LINE_HEIGHT = 28; - static TEXT_SMALL_LINE_HEIGHT = 19; - static CONSTRAINTSIZE_MINHEIGHT = 48; - static LISTITEM_ROW_HEIGHT = 48; - static LISTITEM_PADDING_LEFT = 24; - static LIST_PADDING_LEFT = 12 - static LISTITEM_PADDING_RIGHT = 24; - static LISTITEM_PADDING_LEFT_RECORD = 32; - static LISTITEM_PADDING_RIGHT_RECORD = 50; - static LISTITEM_MARGIN_BOTTOM = 12; - static LISTITEM_HEIGHT_PERMISSION = 64; - static LISTITEM_HEIGHT_APPLICATION = 72; - static IMAGE_HEIGHT = 24; - static IMAGE_WIDTH = 12; - static IMAGE_HEIGHT_RECORD = 12; - static IMAGE_WIDTH_RECORD = 24; - static IMAGE_HEIGHT_RECORD_APPLICATION = 16; - static IMAGE_WIDTH_RECORD_APPLICATION = 16; - static TITLE_MARGIN_BOTTOM = 16; - static SUBTITLE_MIN_HEIGHT = 48; - static SUBTITLE_LINE_HEIGHT = 24; - static SUBTITLE_PADDING_TOP = 16; - static SUBTITLE_PADDING_BOTTOM = 8; - static TAB_HEIGHT = 56; - static TAB_LINE_HEIGHT = 100; - static TAB_INNER_PADDING = 8; - static TAB_DECORATION_HEIGHT = 2; - static TAB_DECORATION_POSITION_Y = 6; - static DEFAULT_PADDING_START = 12; - static DEFAULT_PADDING_END = 12; - static DEFAULT_PADDING_TOP = 12; - static DEFAULT_PADDING_BOTTOM = 12; - static DEFAULT_MARGIN_START = 12; - static DEFAULT_MARGIN_END = 12; - static DEFAULT_MARGIN_TOP = 12; - static DEFAULT_MARGIN_BOTTOM = 12; - static DEFAULT_SLIDER_WIDTH = 60; - static DEFAULT_SLIDER_HEIGHT = 40; - static OFFSET = 100; - static CLICK_SHADOW_LENGTH = 48; - static DIVIDER = '1px'; - static DIVIDER_HEIGHT = 24; - static DIVIDER_MARGIN_RIGHT_PERMISSION = 52; - static DIVIDER_MARGIN_RIGHT_APPLICATION = 68; + // public property style + static PERMISSION = 1; + static APPLICATION = 0; + static LAYOUT_WEIGHT = 1; + static FLEX_GROW = 1; + static TEXT_BIG_FONT_SIZE = 20; + static TEXT_MIDDLE_FONT_SIZE = 16; + static TEXT_SMALL_FONT_SIZE = 14; + static TEXT_SMALLER_FONT_SIZE = 12; + static TEXT_LINE_HEIGHT = 22; + static TEXT_BIG_LINE_HEIGHT = 28; + static TEXT_SMALL_LINE_HEIGHT = 19; + static CONSTRAINTSIZE_MINHEIGHT = 48; + static LISTITEM_ROW_HEIGHT = 48; + static LISTITEM_PADDING_LEFT = 24; + static LIST_PADDING_LEFT = 12 + static LISTITEM_PADDING_RIGHT = 24; + static LISTITEM_PADDING_LEFT_RECORD = 32; + static LISTITEM_PADDING_RIGHT_RECORD = 50; + static LISTITEM_MARGIN_BOTTOM = 12; + static LISTITEM_HEIGHT_PERMISSION = 64; + static LISTITEM_HEIGHT_APPLICATION = 72; + static IMAGE_HEIGHT = 24; + static IMAGE_WIDTH = 12; + static IMAGE_HEIGHT_RECORD = 12; + static IMAGE_WIDTH_RECORD = 24; + static IMAGE_HEIGHT_RECORD_APPLICATION = 16; + static IMAGE_WIDTH_RECORD_APPLICATION = 16; + static TITLE_MARGIN_BOTTOM = 16; + static SUBTITLE_MIN_HEIGHT = 48; + static SUBTITLE_LINE_HEIGHT = 24; + static SUBTITLE_PADDING_TOP = 16; + static SUBTITLE_PADDING_BOTTOM = 8; + static TAB_HEIGHT = 56; + static TAB_LINE_HEIGHT = 100; + static TAB_INNER_PADDING = 8; + static TAB_DECORATION_HEIGHT = 2; + static TAB_DECORATION_POSITION_Y = 6; + static DEFAULT_PADDING_START = 12; + static DEFAULT_PADDING_END = 12; + static DEFAULT_PADDING_TOP = 12; + static DEFAULT_PADDING_BOTTOM = 12; + static DEFAULT_MARGIN_START = 12; + static DEFAULT_MARGIN_END = 12; + static DEFAULT_MARGIN_TOP = 12; + static DEFAULT_MARGIN_BOTTOM = 12; + static DEFAULT_SLIDER_WIDTH = 60; + static DEFAULT_SLIDER_HEIGHT = 40; + static OFFSET = 100; + static CLICK_SHADOW_LENGTH = 48; + static DIVIDER = '1px'; + static DIVIDER_HEIGHT = 40; + static DIVIDER_MARGIN_RIGHT_PERMISSION = 52; + static DIVIDER_MARGIN_RIGHT_APPLICATION = 68; - static START_SUBSCRIPT = 0; - static END_SUBSCRIPT = 500; - static MAXIMUM_HEADER_LINES = 1; - static MAXIMUM_HEADER_WIDTH = 200; - static MAXIMUM_HEADER_HEIGHT = 500; - static MAXIMUM_HEADER_LENGTH = 1000; + static START_SUBSCRIPT = 0; + static END_SUBSCRIPT = 500; + static MAXIMUM_HEADER_LINES = 1; + static MAXIMUM_HEADER_WIDTH = 200; + static MAXIMUM_HEADER_HEIGHT = 500; + static MAXIMUM_HEADER_LENGTH = 1000; - static RECORD_PADDING_BOTTOM = '20%'; + static RECORD_PADDING_BOTTOM = '20%'; - // icon of dialog - static DIALOG_ICON_WIDTH = 24; - static DIALOG_ICON_HEIGHT = 24; - static DIALOG_ICON_MARGIN_TOP = 23; + // icon of dialog + static DIALOG_ICON_WIDTH = 32; + static DIALOG_ICON_HEIGHT = 32; + static DIALOG_ICON_MARGIN_TOP = 24; - // label text of dialog - static DIALOG_LABEL_FONT_SIZE = 10; - static DIALOG_LABEL_MARGIN_TOP = 2; - static DIALOG_LABEL_LINE_HEIGHT = 14; + // label text of dialog + static DIALOG_LABEL_FONT_SIZE = 10; + static DIALOG_LABEL_MARGIN_TOP = 2; + static DIALOG_LABEL_LINE_HEIGHT = 14; - // request text of dialog - static DIALOG_REQ_FONT_SIZE = 16; - static DIALOG_REQ_MARGIN_TOP = 16; - static DIALOG_REQ_MARGIN_LEFT = 24; - static DIALOG_REQ_MARGIN_RIGHT = 24; - static DIALOG_REQ_LINE_HEIGHT = 22; + // request text of dialog + static DIALOG_REQ_FONT_SIZE = 20; + static DIALOG_REQ_MARGIN_TOP = 18; + static DIALOG_REQ_MARGIN_BUTTOM = 18; + static DIALOG_REQ_MARGIN_LEFT = 24; + static DIALOG_REQ_MARGIN_RIGHT = 24; + static DIALOG_REQ_LINE_HEIGHT = 27; - // description text of dialog - static DIALOG_DESP_FONT_SIZE = 14; - static DIALOG_DESP_MARGIN_TOP = 2; - static DIALOG_DESP_MARGIN_LEFT = 24; - static DIALOG_DESP_MARGIN_RIGHT = 24; - static DIALOG_DESP_MARGIN_BOTTOM = 8; - static DIALOG_DESP_LINE_HEIGHT = 19; + // description text of dialog + static DIALOG_DESP_FONT_SIZE = 16; + static DIALOG_DESP_MARGIN_TOP = 0; + static DIALOG_DESP_MARGIN_LEFT = 24; + static DIALOG_DESP_MARGIN_RIGHT = 24; + static DIALOG_DESP_MARGIN_BOTTOM = 12; + static DIALOG_DESP_LINE_HEIGHT = 21; - static BUTTON_MARGIN_TOP = 8; - static BUTTON_MARGIN_LEFT = 16; - static BUTTON_MARGIN_RIGHT = 16; - static BUTTON_HEIGHT = 40; + static BUTTON_MARGIN_TOP = 8; + static BUTTON_MARGIN_LEFT = 16; + static BUTTON_MARGIN_RIGHT = 16; + static BUTTON_HEIGHT = 40; - static DIALOG_PRIVACY_BORDER_RADIUS = 32; - static DIALOG_PADDING_BOTTOM = 16; + static DIALOG_PRIVACY_BORDER_RADIUS = 32; + static DIALOG_PADDING_BOTTOM = 16; - // ccm config path - static CCM_CONFIG_PATH = "etc/notification/notification_config.json"; + // ccm config path + static CCM_CONFIG_PATH = "etc/notification/notification_config.json"; } diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets index f0409887774aa1a817274332e3f460b51a1561f6..28e34759f44c7710e01f295d3eef602674b0f764 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/ets/pages/notificationDialog.ets @@ -22,6 +22,7 @@ import fs from '@ohos.file.fs'; import configPolicy from '@ohos.configPolicy'; import { EnableNotificationDialog } from '../ServiceExtAbility/NotificationServiceExtAbility'; import { Callback} from '@ohos.base'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; const TAG = 'NotificationDialog_Service '; const permission: Record = { @@ -72,6 +73,7 @@ struct PermissionDialog { @State isBottomPopover: boolean = true; @Link @Watch('updateOnPageShow') isUpdate: number; dialog?: EnableNotificationDialog; + session?: UIExtensionContentSession; controller?: CustomDialogController; build() { @@ -83,14 +85,13 @@ struct PermissionDialog { Image(permission.icon) .width(Constants.DIALOG_ICON_WIDTH) .height(Constants.DIALOG_ICON_HEIGHT) - .fillColor($r('sys.color.ohos_id_color_text_primary')) .margin({ top: Constants.DIALOG_ICON_MARGIN_TOP }) Scroll() { Column() { Row() { - Flex({ justifyContent: FlexAlign.Start }) { + Flex({ justifyContent: FlexAlign.Center }) { Text() { Span($r('app.string.whether_to_allow')) Span(this.appName) @@ -99,10 +100,11 @@ struct PermissionDialog { } .fontSize(Constants.DIALOG_REQ_FONT_SIZE) .fontColor($r('sys.color.ohos_id_color_text_primary')) - .fontWeight(FontWeight.Medium) + .fontWeight(FontWeight.Bold) .lineHeight(Constants.DIALOG_REQ_LINE_HEIGHT) .margin({ top: Constants.DIALOG_REQ_MARGIN_TOP, + bottom:Constants.DIALOG_REQ_MARGIN_BUTTOM, left: Constants.DIALOG_REQ_MARGIN_LEFT, right: Constants.DIALOG_REQ_MARGIN_RIGHT }) @@ -114,7 +116,8 @@ struct PermissionDialog { Span(permission.reason) } .fontSize(Constants.DIALOG_DESP_FONT_SIZE) - .fontColor($r('sys.color.ohos_id_color_text_secondary')) + .fontWeight(FontWeight.Regular) + .fontColor($r('sys.color.ohos_id_color_text_primary')) .lineHeight(Constants.DIALOG_DESP_LINE_HEIGHT) .margin({ top: Constants.DIALOG_DESP_MARGIN_TOP, @@ -131,7 +134,7 @@ struct PermissionDialog { Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { Button($r('app.string.BAN')) .onClick(async (): Promise => { - await this.enableNotification(false); + await this.enableNotification(false); }) .customizeButton() Divider() @@ -183,13 +186,13 @@ struct PermissionDialog { updateAvoidWindow(): void { let type = window.AvoidAreaType.TYPE_SYSTEM; try { - this.dialog?.window.on('avoidAreaChange', (data): void => { + this.dialog?.extensionWindow.on('avoidAreaChange', (data): void => { if (data.type == window.AvoidAreaType.TYPE_SYSTEM) { console.info(TAG, `avoidAreaChange: ${JSON.stringify(data)}`); this.naviHeight = data.area.bottomRect.height; } }); - let avoidArea = this.dialog?.window.getWindowAvoidArea(type); + let avoidArea = this.dialog?.extensionWindow.getWindowAvoidArea(type); if (avoidArea != undefined){ console.info(TAG, `avoidArea: ${JSON.stringify(avoidArea)}`); this.naviHeight = avoidArea.bottomRect.height; @@ -253,15 +256,14 @@ struct PermissionDialog { async aboutToAppear(): Promise { this.dialog = storage.get('dialog') as EnableNotificationDialog; + this.session = storage.get('session') as UIExtensionContentSession; this.updateAvoidWindow(); try { await this.updateStatus(); } catch (err) { console.error(TAG, `aboutToAppear error : + ${JSON.stringify(err)}`); await this.dialog?.destroyException(); - } - if (display.isFoldable()) { - await this.registerFoldableCallback(); + await this.session?.terminateSelf(); } } @@ -285,7 +287,6 @@ struct PermissionDialog { } async aboutToDisappear(): Promise { - await this.dialog?.destroyWindow(); } async enableNotification(enabled: boolean): Promise { @@ -294,8 +295,9 @@ struct PermissionDialog { await this.dialog?.publishButtonClickedEvent(enabled); } catch (err) { console.error(TAG, `NotificationDialog enable error, code is ${err?.code}`); + await this.dialog?.destroyException(); } finally { - await this.dialog?.destroy(); + this.session?.terminateSelf(); } } } diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/module.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/module.json index f40dc18158f152abc268c0393e12eda63b892395..84fcecbab6fd89eaa4969ed0983562e8b8d38c8d 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/module.json +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/module.json @@ -22,7 +22,8 @@ "icon": "$media:icon", "label": "$string:NotificationServiceExtAbility_label", "visible": false, - "type": "service" + "exported":true, + "type": "sysDialog/common" } ], "requestPermissions": [ diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json index ff42825db5ce7e12251f123a50a35348cc633087..44f80e7843493846f4203bab1817f57d555574bb 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/element/string.json @@ -30,7 +30,7 @@ }, { "name": "reason", - "value": "These may include banner notifications, lock screen notifications, notification sounds, and more. You can change this in Settings." + "value": "These may include lock screen notifications, notification sounds, and more. You can change this in Settings." }, { "name": "ALLOW", diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/media/ic_public_ring.svg b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/media/ic_public_ring.svg index beec8f08c49630ca58b75326c3e166c350d89011..af5112b88a940632b115cc41ab442b0215999d46 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/media/ic_public_ring.svg +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/base/media/ic_public_ring.svg @@ -1,13 +1,11 @@ - - Public/ic_public_ring - - - - - - - - + + ic_public_ring + + + + + + \ No newline at end of file diff --git a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_CN/element/string.json b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_CN/element/string.json index 5ab3cb3ac95200766c1cfb8a4f635c5463067be3..2055de3c677078c37d26236c7390f535712ba4e0 100644 --- a/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_CN/element/string.json +++ b/services/dialog_ui/enable_notification_dialog/entry/src/main/resources/zh_CN/element/string.json @@ -30,7 +30,7 @@ }, { "name": "reason", - "value": "包括横幅、锁屏、铃声等。可前往“设置”>“通知和状态栏”更改。" + "value": "包括锁屏、铃声等。可前往“设置”>“通知和状态栏”更改。" }, { "name": "ALLOW", diff --git a/services/test/moduletest/ans_module_test.cpp b/services/test/moduletest/ans_module_test.cpp index c594f265b163098535604762f1e59d85504cdfc5..137850947e2783f7218db51fff5fae5457910b4e 100644 --- a/services/test/moduletest/ans_module_test.cpp +++ b/services/test/moduletest/ans_module_test.cpp @@ -156,9 +156,9 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_001, Function | SmallTest | Level1) EXPECT_EQ((int)g_advancedNotificationService->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK); EXPECT_EQ((int)g_advancedNotificationService->Publish(label, req), (int)ERR_OK); EXPECT_EQ((int)g_advancedNotificationService->Publish(label, req1), (int)ERR_OK); - EXPECT_EQ((int)g_advancedNotificationService->Cancel(1, label), (int)ERR_OK); + EXPECT_EQ((int)g_advancedNotificationService->Cancel(1, label, 0), (int)ERR_OK); EXPECT_TRUE(passed); - g_advancedNotificationService->CancelAll(); + g_advancedNotificationService->CancelAll(0); EXPECT_EQ((int)g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), info), (int)ERR_OK); passed = false; } @@ -185,14 +185,14 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_002, Function | SmallTest | Level1) EXPECT_EQ((int)g_advancedNotificationService->Publish(label, req), (int)ERR_OK); EXPECT_EQ((int)g_advancedNotificationService->Publish(label, req1), (int)ERR_OK); EXPECT_EQ((int)g_advancedNotificationService->Publish("testLabel1", req2), (int)ERR_OK); - EXPECT_EQ((int)g_advancedNotificationService->GetActiveNotifications(notificationsReqs), (int)ERR_OK); + EXPECT_EQ((int)g_advancedNotificationService->GetActiveNotifications(notificationsReqs, 0), (int)ERR_OK); uint64_t num; g_advancedNotificationService->GetActiveNotificationNums(num); EXPECT_EQ(num, 3); - EXPECT_EQ((int)g_advancedNotificationService->Cancel(2, "testLabel1"), (int)ERR_OK); + EXPECT_EQ((int)g_advancedNotificationService->Cancel(2, "testLabel1", 0), (int)ERR_OK); EXPECT_EQ((int)g_advancedNotificationService->GetAllActiveNotifications(notifications), (int)ERR_OK); EXPECT_EQ((int)notifications.size(), (int)2); - EXPECT_EQ((int)g_advancedNotificationService->CancelAll(), (int)ERR_OK); + EXPECT_EQ((int)g_advancedNotificationService->CancelAll(0), (int)ERR_OK); } /** @@ -832,7 +832,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0035, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); - g_advancedNotificationService->Cancel(0, label); + g_advancedNotificationService->Cancel(0, label, 0); std::this_thread::sleep_for(std::chrono::milliseconds(200)); EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); @@ -874,7 +874,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0036, Function | SmallTest | Level1) // publish request g_advancedNotificationService->Publish(label, req); - g_advancedNotificationService->CancelAll(); + g_advancedNotificationService->CancelAll(0); EXPECT_TRUE(passed); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } @@ -2598,7 +2598,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0131, Function | SmallTest | Level1) subscriber->canceledCb_ = [](const std::shared_ptr &request, const std::shared_ptr &sortingMap, int deleteReason) { passed = true; }; - g_advancedNotificationService->Cancel(1, "1"); + g_advancedNotificationService->Cancel(1, "1", 0); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); EXPECT_EQ(false, passed); } diff --git a/test/bechmarktest/notification_services_test/notification_service_test.cpp b/test/bechmarktest/notification_services_test/notification_service_test.cpp index 35d98aff423e6bf03eb8fff50642b09bdd52237e..e465f3e33ea7386784e09223c4ede00d07d34640 100644 --- a/test/bechmarktest/notification_services_test/notification_service_test.cpp +++ b/test/bechmarktest/notification_services_test/notification_service_test.cpp @@ -244,7 +244,7 @@ BENCHMARK_F(BenchmarkNotificationService, CancelNotificationTestCase001)(benchma if (errCode != ERR_OK) { state.SkipWithError("CancelNotificationTestCase001 publish failed."); } - advancedNotificationService_->Cancel(id, label); + advancedNotificationService_->Cancel(id, label, 0); } } diff --git a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp index e75d8d39a25ecd979c6dce7261ee323614795c87..bc3f328f25dd500d864c4d89849b913a60659bbb 100644 --- a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp @@ -34,8 +34,8 @@ namespace OHOS { sptr notification = new Notification::NotificationRequest(); advancedNotificationService.Publish(stringData, notification); int notificationId = static_cast(GetU32Data(data)); - advancedNotificationService.Cancel(notificationId, stringData); - advancedNotificationService.CancelAll(); + advancedNotificationService.Cancel(notificationId, stringData, 0); + advancedNotificationService.CancelAll(0); int32_t userId = static_cast(GetU32Data(data)); advancedNotificationService.CancelAsBundle(notificationId, stringData, userId); uint8_t type = *data % SLOT_TYPE_NUM; @@ -52,7 +52,7 @@ namespace OHOS { uint64_t num = static_cast(GetU32Data(data)); advancedNotificationService.GetSlotNumAsBundle(bundleOption, num); std::vector> notifications; - advancedNotificationService.GetActiveNotifications(notifications); + advancedNotificationService.GetActiveNotifications(notifications, 0); advancedNotificationService.GetActiveNotificationNums(num); std::vector> notificationss; advancedNotificationService.GetAllActiveNotifications(notificationss); @@ -91,7 +91,7 @@ namespace OHOS { advancedNotificationService.IsAllowedNotify(allowed); advancedNotificationService.IsAllowedNotifySelf(allowed); advancedNotificationService.IsSpecialBundleAllowedNotify(bundleOption, allowed); - advancedNotificationService.CancelGroup(stringData); + advancedNotificationService.CancelGroup(stringData, 0); advancedNotificationService.RemoveGroupByBundle(bundleOption, stringData); sptr date = new Notification::NotificationDoNotDisturbDate(); advancedNotificationService.SetDoNotDisturbDate(date); @@ -135,7 +135,7 @@ namespace OHOS { advancedNotificationService.SetSyncNotificationEnabledWithoutApp(userId, enabled); advancedNotificationService.GetSyncNotificationEnabledWithoutApp(userId, enabled); int32_t badgeNum = static_cast(GetU32Data(data)); - advancedNotificationService.SetBadgeNumber(badgeNum); + advancedNotificationService.SetBadgeNumber(badgeNum, 0); sptr dialogCallback = NULL; sptr callerToken = NULL; advancedNotificationService.RequestEnableNotification(stringData, dialogCallback, callerToken); diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index ce0562760e0b2ca4ec3fedb71fc3ae9d8f9fc904..d12a67148a644f69fddcc9ed1d82e71ac60498f6 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -109,8 +109,8 @@ namespace OHOS { sptr notification = new Notification::NotificationRequest(); ansManagerStub.Publish(stringData, notification); int notificationId = static_cast(GetU32Data(data)); - ansManagerStub.Cancel(notificationId, stringData); - ansManagerStub.CancelAll(); + ansManagerStub.Cancel(notificationId, stringData, 0); + ansManagerStub.CancelAll(0); int32_t userId = static_cast(GetU32Data(data)); ansManagerStub.CancelAsBundle(notificationId, stringData, userId); uint8_t type = *data % SLOT_TYPE_NUM; @@ -127,7 +127,7 @@ namespace OHOS { uint64_t num = static_cast(GetU32Data(data)); ansManagerStub.GetSlotNumAsBundle(bundleOption, num); std::vector> notifications; - ansManagerStub.GetActiveNotifications(notifications); + ansManagerStub.GetActiveNotifications(notifications, 0); ansManagerStub.GetActiveNotificationNums(num); std::vector> notificationss; ansManagerStub.GetAllActiveNotifications(notificationss); @@ -163,7 +163,7 @@ namespace OHOS { bool allowed = *data % ENABLE; ansManagerStub.IsAllowedNotify(allowed); ansManagerStub.IsSpecialBundleAllowedNotify(bundleOption, allowed); - ansManagerStub.CancelGroup(stringData); + ansManagerStub.CancelGroup(stringData, 0); ansManagerStub.RemoveGroupByBundle(bundleOption, stringData); sptr date = new Notification::NotificationDoNotDisturbDate(); ansManagerStub.SetDoNotDisturbDate(date); diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp index 9d36e9e4bec06f49126e92d75349b9f5eb80bcd8..af374371c749b408124333ed79a860c6d30395f1 100644 --- a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp @@ -49,7 +49,7 @@ namespace OHOS { ansManagerStub.IsAllowedNotify(allow); ansManagerStub.IsAllowedNotifySelf(allow); ansManagerStub.IsSpecialBundleAllowedNotify(bundleOption, allow); - ansManagerStub.CancelGroup(stringData); + ansManagerStub.CancelGroup(stringData, 0); ansManagerStub.RemoveGroupByBundle(bundleOption, stringData); ansManagerStub.DoesSupportDoNotDisturbMode(allow); ansManagerStub.IsDistributedEnabled(allow); diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp index e475ab2f17fa66b14b64c327131f9366e34d0f04..9b9ceda9df4442cfeb47f8485a0dca059e807a9d 100644 --- a/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp @@ -37,8 +37,8 @@ namespace OHOS { sptr notification = new Notification::NotificationRequest(); ansManagerStub.Publish(stringData, notification); int notificationId = 1; - ansManagerStub.Cancel(notificationId, stringData); - ansManagerStub.CancelAll(); + ansManagerStub.Cancel(notificationId, stringData, 0); + ansManagerStub.CancelAll(0); int32_t notificationIds = static_cast(GetU32Data(data)); int32_t userId = static_cast(GetU32Data(data)); ansManagerStub.CancelAsBundle(notificationIds, stringData, userId); @@ -59,7 +59,7 @@ namespace OHOS { sptr notificationer = new Notification::NotificationRequest(); std::vector> notifications; notifications.emplace_back(notificationer); - ansManagerStub.GetActiveNotifications(notifications); + ansManagerStub.GetActiveNotifications(notifications, 0); ansManagerStub.GetActiveNotificationNums(num); sptr notificatione = new Notification::Notification(); std::vector> notificationes;