diff --git a/frameworks/js/napi/src/common_utils.cpp b/frameworks/js/napi/src/common_utils.cpp index 74568771c0caf52930f7d2ccefb22e8129465c48..148fbd8ab73d6818cd31c4032cced821cdeffde1 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 7b7f7ac7fdcacc6273509696186616cedbc7c676..67a0fbd4f7637a3973c366cfc9076545170d5a53 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/frameworks/js/napi/src/publish.cpp b/frameworks/js/napi/src/publish.cpp index 74a187cd332ae7306ef8f0de4e4b2fee11d3d332..64a02fe1055062882cd7544566a12a087ceb9aea 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; } diff --git a/frameworks/js/napi/src/subscribe.cpp b/frameworks/js/napi/src/subscribe.cpp index ee3b923d2339d7a7ebc8ee846e146f2f1763a2c8..043c7549a3fb24165c26c0f43d632d248df8f9c9 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) diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 0b95ab3cee8b61419878f40d89993d3608953856..ea8d6c9cce7b89848c3348709db1b8bc3144a9bc 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) { @@ -963,7 +972,7 @@ ErrCode AdvancedNotificationService::CanPopEnableNotificationDialog( return ERROR_INTERNAL_ERROR; } if (hasPopped) { - return ERR_OK; + return ERR_ANS_NOT_ALLOWED; } if (!CreateDialogManager()) { diff --git a/services/ans/src/advanced_notification_reminder_service.cpp b/services/ans/src/advanced_notification_reminder_service.cpp index 96bb1905ea22914666a3fe6a006e6092bc46b341..d73740f7581ead558fff9b8628ed15308d27b26c 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::vectorGetHasPoppedDialog(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; } }; @@ -1201,8 +1186,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()); diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/ans/test/unittest/reminder_data_manager_test.cpp index 431381ff9efe3c6e065ee168b84dec73bdb55c51..75dec8469e1879d03301a64473d9577306b0e88d 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() { diff --git a/services/dialog_ui/enable_notification_dialog/publicity.xml b/services/dialog_ui/enable_notification_dialog/publicity.xml index ba2e4eea972d60c03643fff19b7dc2c7df1362b7..e65a1ccf42fc690e4ec609e9d51e7ea3f15cf23b 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