From 27b6211133a03c6017a7abdb09975efae4928a8d Mon Sep 17 00:00:00 2001 From: z30053788 Date: Fri, 9 Aug 2024 10:50:10 +0800 Subject: [PATCH 1/9] cherry pick 1d46944 from https://gitee.com/zhaobaoxin1/notification_distributed_notification_service/pulls/2003 update Signed-off-by: z30053788 Change-Id: I0b81337eb9b1f6d35a7c91047e172e501d7bd29e --- frameworks/js/napi/src/publish.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/frameworks/js/napi/src/publish.cpp b/frameworks/js/napi/src/publish.cpp index 74a187cd3..64a02fe10 100644 --- a/frameworks/js/napi/src/publish.cpp +++ b/frameworks/js/napi/src/publish.cpp @@ -239,7 +239,6 @@ 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; } @@ -248,8 +247,6 @@ 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; } -- Gitee From ca08921971703b658babf844aea768e92251b210 Mon Sep 17 00:00:00 2001 From: xdongs Date: Thu, 8 Aug 2024 14:23:49 +0800 Subject: [PATCH 2/9] =?UTF-8?q?errorCode=20=EF=BC=88cherry=20picked=20comm?= =?UTF-8?q?it=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/js/napi/src/common_utils.cpp | 4 +++- frameworks/js/napi/src/manager/napi_enable_notification.cpp | 4 ++-- services/ans/src/advanced_notification_publish_service.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frameworks/js/napi/src/common_utils.cpp b/frameworks/js/napi/src/common_utils.cpp index 74568771c..148fbd8ab 100644 --- a/frameworks/js/napi/src/common_utils.cpp +++ b/frameworks/js/napi/src/common_utils.cpp @@ -49,6 +49,7 @@ static const std::unordered_map ERROR_CODE_MESSAGE { {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"}, + {ERROR_DIALOG_IS_POPPING, "Dialog is popping"}, }; } @@ -313,7 +314,8 @@ int32_t Common::ErrorToExternal(uint32_t errCode) {ERR_ANS_PUSH_CHECK_FAILED, ERROR_NO_RIGHT}, {ERR_ANS_PUSH_CHECK_UNREGISTERED, ERROR_NO_RIGHT}, {ERR_ANS_PUSH_CHECK_NETWORK_UNREACHABLE, ERROR_NETWORK_UNREACHABLE}, - {ERR_ANS_NO_AGENT_SETTING, ERROR_NO_AGENT_SETTING} + {ERR_ANS_NO_AGENT_SETTING, ERROR_NO_AGENT_SETTING}, + {ERR_ANS_DIALOG_IS_POPPING, ERROR_DIALOG_IS_POPPING} }; int32_t ExternalCode = ERROR_INTERNAL_ERROR; diff --git a/frameworks/js/napi/src/manager/napi_enable_notification.cpp b/frameworks/js/napi/src/manager/napi_enable_notification.cpp index 7b7f7ac7f..67a0fbd4f 100644 --- a/frameworks/js/napi/src/manager/napi_enable_notification.cpp +++ b/frameworks/js/napi/src/manager/napi_enable_notification.cpp @@ -253,7 +253,7 @@ void NapiAsyncCompleteCallbackRequestEnableNotification(napi_env env, void *data napi_value NapiRequestEnableNotification(napi_env env, napi_callback_info info) { - ANS_LOGI("enter"); + ANS_LOGI("NapiRequestEnableNotification enter"); IsEnableParams params {}; if (ParseRequestEnableParameters(env, info, params) == nullptr) { Common::NapiThrow(env, ERROR_PARAM_INVALID); @@ -617,7 +617,7 @@ void ModalExtensionCallback::OnReceive(const AAFwk::WantParams& receive) */ void ModalExtensionCallback::OnRelease(int32_t releaseCode) { - ANS_LOGD("OnRelease"); + ANS_LOGI("OnRelease"); ReleaseOrErrorHandle(releaseCode); } diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 0b95ab3ce..60c1825b7 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -963,7 +963,7 @@ ErrCode AdvancedNotificationService::CanPopEnableNotificationDialog( return ERROR_INTERNAL_ERROR; } if (hasPopped) { - return ERR_OK; + return ERR_ANS_NOT_ALLOWED; } if (!CreateDialogManager()) { -- Gitee From 5bb48807adbdfd07ba03e90dbd8c50f950b04e24 Mon Sep 17 00:00:00 2001 From: xdongs Date: Thu, 8 Aug 2024 15:59:00 +0800 Subject: [PATCH 3/9] merge Signed-off-by: xdongs --- services/ans/src/advanced_notification_utils.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index decf7240d..0b1c2694e 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -1201,8 +1201,10 @@ std::vector AdvancedNotificationService::GetLocalNotificationKeys( std::vector keys; for (auto record : notificationList_) { - if ((bundleOption != nullptr) && (record->bundleOption->GetBundleName() != bundleOption->GetBundleName()) && - (record->bundleOption->GetUid() != bundleOption->GetUid()) && record->deviceId.empty()) { + if ((bundleOption != nullptr) && + ((record->bundleOption->GetBundleName() != bundleOption->GetBundleName()) || + (record->bundleOption->GetUid() != bundleOption->GetUid())) && + record->deviceId.empty()) { continue; } keys.push_back(record->notification->GetKey()); -- Gitee From d9066cf7aa05fccfe5bf41c0ab88b4e9c9a12ebe Mon Sep 17 00:00:00 2001 From: xdongs Date: Mon, 12 Aug 2024 10:24:38 +0800 Subject: [PATCH 4/9] =?UTF-8?q?unsubscribe=20=EF=BC=88cherry=20picked=20co?= =?UTF-8?q?mmit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/js/napi/src/subscribe.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frameworks/js/napi/src/subscribe.cpp b/frameworks/js/napi/src/subscribe.cpp index ee3b923d2..043c7549a 100644 --- a/frameworks/js/napi/src/subscribe.cpp +++ b/frameworks/js/napi/src/subscribe.cpp @@ -509,7 +509,7 @@ void ThreadSafeOnDisconnected(napi_env env, napi_value jsCallback, void* context } Common::SetCallback(dataWorkerData->env, dataWorkerData->ref, Common::NapiGetNull(dataWorkerData->env)); - + DelSubscriberInstancesInfo(dataWorkerData->env, dataWorkerData->subscriber); delete dataWorkerData; dataWorkerData = nullptr; } @@ -541,7 +541,6 @@ void SubscriberInstance::OnDisconnected() napi_acquire_threadsafe_function(unsubscribeCallbackInfo_.tsfn); napi_call_threadsafe_function(unsubscribeCallbackInfo_.tsfn, dataWorker, napi_tsfn_nonblocking); napi_release_threadsafe_function(unsubscribeCallbackInfo_.tsfn, napi_tsfn_abort); - DelSubscriberInstancesInfo(dataWorker->env, dataWorker->subscriber); } void ThreadSafeOnDestroy(napi_env env, napi_value jsCallback, void* context, void* data) -- Gitee From ecef1c99e565eeb10248206f0f3a623c0f04ca74 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Tue, 13 Aug 2024 17:16:06 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E4=B8=89=E6=96=B9=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E4=B8=ADRemovalWantAgent=E7=9A=84operationType=E5=8F=AA?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E4=B8=BA4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- .../ans/src/advanced_notification_publish_service.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 0b95ab3ce..77ae09d07 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -52,6 +52,7 @@ constexpr int32_t HOURS_IN_ONE_DAY = 24; const static std::string NOTIFICATION_EVENT_PUSH_AGENT = "notification.event.PUSH_AGENT"; constexpr int32_t RSS_PID = 3051; constexpr int32_t TYPE_CODE_DOWNLOAD = 8; +constexpr int32_t OPERATION_TYPE_COMMON_EVENT = 4; ErrCode AdvancedNotificationService::SetDefaultNotificationEnabled( const sptr &bundleOption, bool enabled) @@ -111,7 +112,15 @@ ErrCode AdvancedNotificationService::Publish(const std::string &label, const spt if (isSubsystem) { return PublishNotificationBySa(request); } - + if (request->GetRemovalWantAgent() != nullptr) { + uint32_t operationType = (uint32_t)(request->GetRemovalWantAgent()->GetPendingWant() + ->GetType(request->GetRemovalWantAgent()->GetPendingWant()->GetTarget())); + bool isSystemApp = AccessTokenHelper::IsSystemApp(); + if (!isSubsystem && !isSystemApp && operationType != OPERATION_TYPE_COMMON_EVENT) { + ANS_LOGI("SetRemovalWantAgent as nullptr"); + request->SetRemovalWantAgent(nullptr); + } + } do { result = publishProcess_[request->GetSlotType()]->PublishNotificationByApp(request); if (result != ERR_OK) { -- Gitee From 20d5141028d73ffb6529691d5fba4c82fb6f5e33 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Wed, 21 Aug 2024 09:25:51 +0800 Subject: [PATCH 6/9] fix ut Signed-off-by: gaojiaqi --- services/ans/test/unittest/reminder_data_manager_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/ans/test/unittest/reminder_data_manager_test.cpp index 431381ff9..75dec8469 100644 --- a/services/ans/test/unittest/reminder_data_manager_test.cpp +++ b/services/ans/test/unittest/reminder_data_manager_test.cpp @@ -44,6 +44,7 @@ public: { ReminderDataManager::InitInstance(nullptr); manager = ReminderDataManager::GetInstance(); + manager->Init(false); } static void TearDownTestCase() { -- Gitee From f398445494bee31ab8d1c2dae9017a8df6707a42 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Thu, 22 Aug 2024 11:18:07 +0800 Subject: [PATCH 7/9] update reminder Signed-off-by: gaojiaqi --- ...advanced_notification_reminder_service.cpp | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/services/ans/src/advanced_notification_reminder_service.cpp b/services/ans/src/advanced_notification_reminder_service.cpp index 96bb1905e..d73740f75 100644 --- a/services/ans/src/advanced_notification_reminder_service.cpp +++ b/services/ans/src/advanced_notification_reminder_service.cpp @@ -59,11 +59,14 @@ ErrCode AdvancedNotificationService::PublishReminder(sptr &remi } std::string bundle = GetClientBundleName(); - if (!CheckReminderPermission() || !AllowUseReminder(bundle)) { - ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER" - "or not allowed use reminder"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); return ERR_REMINDER_PERMISSION_DENIED; } + if (!AllowUseReminder(bundle)) { + ANSR_LOGW("The number of reminders exceeds the limit[0]."); + return ERR_REMINDER_NUMBER_OVERLOAD; + } ANSR_LOGD("is system app: %{public}d", AccessTokenHelper::IsSystemApp()); reminder->SetSystemApp(AccessTokenHelper::IsSystemApp()); sptr notificationRequest = reminder->GetNotificationRequest(); @@ -113,9 +116,8 @@ ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); ANSR_LOGI("Cancel Reminder"); std::string bundleName = GetClientBundleName(); - if (!CheckReminderPermission() || !AllowUseReminder(bundleName)) { - ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER" - "or not allowed use reminder"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); return ERR_REMINDER_PERMISSION_DENIED; } @@ -135,9 +137,8 @@ ErrCode AdvancedNotificationService::CancelAllReminders() HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); ANSR_LOGI("Cancel all reminders"); std::string bundleName = GetClientBundleName(); - if (!CheckReminderPermission() || !AllowUseReminder(bundleName)) { - ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER" - "or not allowed use reminder"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); return ERR_REMINDER_PERMISSION_DENIED; } @@ -160,9 +161,8 @@ ErrCode AdvancedNotificationService::GetValidReminders(std::vector Date: Wed, 14 Aug 2024 18:56:18 +0800 Subject: [PATCH 8/9] cherry pick 6dcb244 from https://gitee.com/zhaobaoxin1/notification_distributed_notification_service/pulls/2023 update Signed-off-by: z30053788 Change-Id: I38aec99dac095a0863adda7437e3122bbafcbd69 --- .../ans/src/advanced_notification_utils.cpp | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index 0b1c2694e..104c63943 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -644,36 +644,21 @@ void AdvancedNotificationService::OnBundleDataUpdate(const sptrGetHasPoppedDialog(bundleOption, hasPopped); - if (errCode != ERR_OK) { - ANS_LOGD("Get notification user option fail, need to insert data"); - errCode = NotificationPreferences::GetInstance()->SetNotificationsEnabledForBundle( - bundleOption, bundleInfo.applicationInfo.allowEnableNotification); - if (errCode != ERR_OK) { - ANS_LOGE("Set notification enable error! code: %{public}d", errCode); - } - SetSlotFlagsTrustlistsAsBundle(bundleOption); - errCode = NotificationPreferences::GetInstance()->SetShowBadge(bundleOption, true); - if (errCode != ERR_OK) { - ANS_LOGE("Set badge enable error! code: %{public}d", errCode); + bool enabled = false; + auto errCode = NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle( + bundleOption, enabled); + if (bundleOption->GetBundleName().compare("com.ohos.mms") == 0) { + uint32_t slotFlags = 63; + auto ret = NotificationPreferences::GetInstance()->GetNotificationSlotFlagsForBundle(bundleOption, slotFlags); + if (ret != ERR_OK) { + ANS_LOGE("Failed to get slotflags for bundle, use default slotflags."); } - return; + UpdateSlotReminderModeBySlotFlags(bundleOption, slotFlags); } - - if (hasPopped) { - ANS_LOGI("The user has made changes, subject to the user's selection"); - return; - } - - errCode = NotificationPreferences::GetInstance()->SetNotificationsEnabledForBundle( - bundleOption, bundleInfo.applicationInfo.allowEnableNotification); if (errCode != ERR_OK) { - ANS_LOGE("Set notification enable error! code: %{public}d", errCode); - } - errCode = NotificationPreferences::GetInstance()->SetShowBadge(bundleOption, true); - if (errCode != ERR_OK) { - ANS_LOGE("Set badge enable error! code: %{public}d", errCode); + ANS_LOGD("Get notification user option fail, need to insert data"); + OnBundleDataAdd(bundleOption); + return; } }; -- Gitee From 5f6afb3e83d7ad022356388e5d154ad4521cd767 Mon Sep 17 00:00:00 2001 From: xdongs Date: Tue, 20 Aug 2024 18:24:18 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E5=85=AC=E7=A4=BA1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xdongs --- .../enable_notification_dialog/publicity.xml | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/services/dialog_ui/enable_notification_dialog/publicity.xml b/services/dialog_ui/enable_notification_dialog/publicity.xml index ba2e4eea9..e65a1ccf4 100644 --- a/services/dialog_ui/enable_notification_dialog/publicity.xml +++ b/services/dialog_ui/enable_notification_dialog/publicity.xml @@ -1,18 +1,18 @@ -/* - * 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. - */ + \ No newline at end of file -- Gitee