From f86d30c57dea5e056293a2f6959d24fdf6b381a5 Mon Sep 17 00:00:00 2001 From: kilimanjro Date: Fri, 30 May 2025 17:22:51 +0800 Subject: [PATCH 1/4] =?UTF-8?q?ani=E6=8E=A5=E5=8F=A3=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kilimanjro --- frameworks/ets/ani/BUILD.gn | 5 + .../manager/ani_disable_notification.h | 27 +++ .../ani/include/manager/ani_set_additional.h | 26 +++ .../ani/include/manager/ani_set_distributed.h | 32 ++++ .../include/manager/ani_set_smart_reminder.h | 26 +++ .../ets/ani/include/manager/ani_set_target.h | 27 +++ .../ets/ani/include/subscribe/ani_remove.h | 2 + .../src/manager/ani_disable_notification.cpp | 52 ++++++ .../ets/ani/src/manager/ani_manager.cpp | 15 +- .../ani/src/manager/ani_set_additional.cpp | 58 ++++++ .../ani/src/manager/ani_set_distributed.cpp | 174 ++++++++++++++++++ .../src/manager/ani_set_smart_reminder.cpp | 78 ++++++++ .../ets/ani/src/manager/ani_set_target.cpp | 49 +++++ .../ets/ani/src/subscribe/ani_remove.cpp | 32 ++++ .../ets/ani/src/subscribe/ani_subscribe.cpp | 5 + .../ets/ets/@ohos.notificationManager.ets | 160 ++++++++++++++++ .../ets/ets/@ohos.notificationSubscribe.ets | 84 +++++++++ 17 files changed, 851 insertions(+), 1 deletion(-) create mode 100644 frameworks/ets/ani/include/manager/ani_disable_notification.h create mode 100644 frameworks/ets/ani/include/manager/ani_set_additional.h create mode 100644 frameworks/ets/ani/include/manager/ani_set_distributed.h create mode 100644 frameworks/ets/ani/include/manager/ani_set_smart_reminder.h create mode 100644 frameworks/ets/ani/include/manager/ani_set_target.h create mode 100644 frameworks/ets/ani/src/manager/ani_disable_notification.cpp create mode 100644 frameworks/ets/ani/src/manager/ani_set_additional.cpp create mode 100644 frameworks/ets/ani/src/manager/ani_set_distributed.cpp create mode 100644 frameworks/ets/ani/src/manager/ani_set_smart_reminder.cpp create mode 100644 frameworks/ets/ani/src/manager/ani_set_target.cpp diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index fa0771b8a..50f238125 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -56,6 +56,11 @@ ohos_shared_library("notification_manager_ani") { "./src/manager/ani_manager.cpp", "./src/manager/ani_request_enable.cpp", "./src/manager/ani_ans_dialog_callback.cpp", + "./src/manager/ani_disable_notification.cpp", + "./src/manager/ani_set_additional.cpp", + "./src/manager/ani_set_distributed.cpp", + "./src/manager/ani_set_smart_reminder.cpp", + "./src/manager/ani_set_target.cpp", ] cflags = [] diff --git a/frameworks/ets/ani/include/manager/ani_disable_notification.h b/frameworks/ets/ani/include/manager/ani_disable_notification.h new file mode 100644 index 000000000..f3b952ff2 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_disable_notification.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DISABLE_NOTIFICATION_H + #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DISABLE_NOTIFICATION_H + #include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { + + void disableNotificationFeature(ani_env *env,ani_boolean disabled, ani_object bundleList); + +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_set_additional.h b/frameworks/ets/ani/include/manager/ani_set_additional.h new file mode 100644 index 000000000..1c408c79f --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_set_additional.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_ADDITIONAL_H + #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_ADDITIONAL_H + #include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { + + ani_int setAdditionalConfig(ani_env *env, ani_string key ,ani_string value); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_set_distributed.h b/frameworks/ets/ani/include/manager/ani_set_distributed.h new file mode 100644 index 000000000..f3e48fc21 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_set_distributed.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_DISTRIBUTED_H + #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_DISTRIBUTED_H + #include "ani.h" + + void setDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enable) + +namespace OHOS { +namespace NotificationManagerSts { + void setDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enable); + void setDistributedEnabledByBundle(ani_env *env, ani_object obj, ani_string deviceType, ani_boolean enable); + void setDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType, ani_boolean enable); + ani_boolean isDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType); + ani_boolean isDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType); + +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_set_smart_reminder.h b/frameworks/ets/ani/include/manager/ani_set_smart_reminder.h new file mode 100644 index 000000000..89e61ed33 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_set_smart_reminder.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_SMART_REMINDER_H + #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_SMART_REMINDER_H + #include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { + ani_boolean isSmartReminderEnabled(ani_env *env, ani_string deviceType); + void setSmartReminderEnabled(ani_env *env, ani_string deviceType, ani_boolean enable); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_set_target.h b/frameworks/ets/ani/include/manager/ani_set_target.h new file mode 100644 index 000000000..b51a23440 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_set_target.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_TARGET_H + #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_TARGET_H + #include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { + const int32_t DISTURB_DEFAULT_FLAG = 13; + void setTargetDeviceStatus(ani_env* env, ani_string deviceType, ani_double status); + +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/subscribe/ani_remove.h b/frameworks/ets/ani/include/subscribe/ani_remove.h index a60aa5ab8..1ba0265fa 100644 --- a/frameworks/ets/ani/include/subscribe/ani_remove.h +++ b/frameworks/ets/ani/include/subscribe/ani_remove.h @@ -22,6 +22,8 @@ namespace NotificationSubScribeSts { void AniRemoveForBundle(ani_env *env, ani_object bundle, ani_object notificationKey, ani_object reasonEnum); void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEnum); void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reasonEnum); +void RemoveAllForUserId(ani_env *env, ani_double userId); +void RemoveAllForBundle(ani_env *env, ani_object bundle); } } #endif \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_disable_notification.cpp b/frameworks/ets/ani/src/manager/ani_disable_notification.cpp new file mode 100644 index 000000000..e51bdb019 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_disable_notification.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 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 "ani_disable_notification.h" + +#include "inner_errors.h" +#include "notification_helper.h" +#include "ans_log_wrapper.h" +#include "sts_throw_erro.h" +#include "sts_common.h" +#include "sts_bundle_option.h" +#include "sts_notification_manager.h" + +namespace OHOS { +namespace NotificationManagerSts { + +void disableNotificationFeature(ani_env *env,ani_boolean disabled, ani_object bundleList) +{ + ANS_LOGD("disableNotificationFeature enter"); + std::vector bundleListStd; + if (ANI_OK != NotificationSts::GetStringArrayByAniObj(env, bundleList, bundleListStd)) { + ANS_LOGE("bundleList is invalid"); + std::string msg = "Invalid bundleList: must be an array of strings."; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + Notification::NotificationDisable param; + param.SetDisabled(NotificationSts::AniBooleanToBool(disabled)); + param.SetBundleList(bundleListStd); + + int returncode = 0; + returncode = Notification::NotificationHelper::DisableNotificationFeature(param); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != 0) { + ANS_LOGE("disableNotificationFeature error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } +} + +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_manager.cpp b/frameworks/ets/ani/src/manager/ani_manager.cpp index 4cc8d56c2..c330a87b3 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -24,7 +24,11 @@ #include "ani_publish.h" #include "ani_local_live_view.h" #include "ani_request_enable.h" - +#include "ani_disable_notification.h" +#include "ani_set_additional.h" +#include "ani_set_distributed.h" +#include "ani_set_smart_reminder.h" +#include "ani_set_target.h" namespace OHOS { namespace NotificationManagerSts { static std::array kitManagerFunctions = { @@ -72,6 +76,15 @@ static std::array kitManagerFunctions = { ani_native_function {"nativeRequestEnableNotification", "Lapplication/UIAbilityContext/UIAbilityContext;:Lstd/core/Promise;", reinterpret_cast(AniRequestEnableNotification)}, + ani_native_function {"nativesetTargetDeviceStatus", nullptr, reinterpret_cast(setTargetDeviceStatus)}, + ani_native_function {"nativesetDistributedEnabledByBundle", nullptr, reinterpret_cast(setDistributedEnabledByBundle)}, + ani_native_function {"nativesetSmartReminderEnabled", nullptr, reinterpret_cast(setSmartReminderEnabled)}, + ani_native_function {"nativeisSmartReminderEnabled", nullptr, reinterpret_cast(isSmartReminderEnabled)}, + ani_native_function {"nativesetDistributedEnabledBySlot", nullptr, reinterpret_cast(setDistributedEnabledBySlot)}, + ani_native_function {"nativeisDistributedEnabledBySlot", nullptr, reinterpret_cast(isDistributedEnabledBySlot)}, + ani_native_function {"nativesetAdditionalConfig", nullptr, reinterpret_cast(setAdditionalConfig)}, + ani_native_function {"nativesetDistributedEnableByBundle",nullptr,reinterpret_cast(setDistributedEnableByBundle)}, + ani_native_function {"nativedisableNotificationFeature",nullptr,reinterpret_cast(disableNotificationFeature)}, }; void AniNotificationManagerRegistryInit(ani_env *env) diff --git a/frameworks/ets/ani/src/manager/ani_set_additional.cpp b/frameworks/ets/ani/src/manager/ani_set_additional.cpp new file mode 100644 index 000000000..c5cee5b04 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_set_additional.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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 "ani_set_additional.h" + +#include "inner_errors.h" +#include "notification_helper.h" +#include "ans_log_wrapper.h" +#include "sts_throw_erro.h" +#include "sts_common.h" +#include "sts_bundle_option.h" +#include "sts_notification_manager.h" + +namespace OHOS { +namespace NotificationManagerSts { + +ani_int setAdditionalConfig(ani_env *env, ani_string key ,ani_string value) +{ + ANS_LOGD("sts getSlotFlagsByBundle call"); + std::string keyStr; + if (env == nullptr || key == nullptr) { + ANS_LOGE("Invalid env or key is null"); + return ANI_FALSE; + } + if (ANI_OK != NotificationSts::GetStringByAniString(env, key, keyStr)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return ANI_FALSE; + } + std::string valueStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, value, valueStr)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return ANI_FALSE; + } + uint32_t slotFlags = 0; + int returncode = Notification::NotificationHelper::SetAdditionConfig(keyStr,valueStr); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != 0) { + ANS_LOGE("setAdditionalConfig -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + return slotFlags; +} + +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_set_distributed.cpp b/frameworks/ets/ani/src/manager/ani_set_distributed.cpp new file mode 100644 index 000000000..cc8283447 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_set_distributed.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2025 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 "ani_set_distributed.h" + +#include "inner_errors.h" +#include "notification_helper.h" +#include "ans_log_wrapper.h" +#include "sts_throw_erro.h" +#include "sts_common.h" +#include "sts_bundle_option.h" +#include "sts_notification_manager.h" + +namespace OHOS { +namespace NotificationManagerSts { + +void setDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enable) +{ + ANS_LOGD("setDistributedEnableByBundle call"); + int returncode = 0; + Notification::NotificationBundleOption option; + bool bFlag = NotificationSts::UnwrapBundleOption(env, obj, option); + ANS_LOGD("sts setDistributedEnableByBundle option bundleName: %{public}s, uid: %{public}d, bFlag: %{public}d", option.GetBundleName().c_str(), + option.GetUid(), bFlag); + if(bFlag) { + returncode = Notification::NotificationHelper::EnableDistributedByBundle(option,NotificationSts::AniBooleanToBool(enable)); + } else { + OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); + ANS_LOGE("sts setDistributedEnableByBundle ERROR_INTERNAL_ERROR"); + return; + } + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode,NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("sts setDistributedEnableByBundle error, errorCode: %{public}d", externalCode); + return; + } + ANS_LOGD("sts setDistributedEnableByBundle end, ret: %{public}d", externalCode); +} + +void setDistributedEnabledByBundle(ani_env *env, ani_object obj, ani_string deviceType, ani_boolean enable) +{ + ANS_LOGD("sts setDistributedEnabledByBundle call"); + std::string deviceTypeStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + int returncode = 0; + Notification::NotificationBundleOption option; + bool bFlag = NotificationSts::UnwrapBundleOption(env, obj, option); + ANS_LOGD("sts setDistributedEnabledByBundle option bundleName: %{public}s, uid: %{public}d, bFlag: %{public}d", option.GetBundleName().c_str(), + option.GetUid(), bFlag); + if(bFlag) { + returncode = Notification::NotificationHelper::SetDistributedEnabledByBundle(option,deviceTypeStr,NotificationSts::AniBooleanToBool(enable)); + } else { + OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); + ANS_LOGE("sts setDistributedEnabledByBundle ERROR_INTERNAL_ERROR"); + return; + } + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode,NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("sts setDistributedEnabledByBundle error, errorCode: %{public}d", externalCode); + return; + } + ANS_LOGD("sts setDistributedEnabledByBundle end, ret: %{public}d", externalCode); +} + + +void setDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType, ani_boolean enable) +{ + ANS_LOGD("setDistributedEnabledBySlot enter "); + std::string deviceTypeStr; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (!NotificationSts::SlotTypeEtsToC(env, slot, slotType)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + if (env == nullptr || deviceType == nullptr) { + ANS_LOGE("Invalid env or deviceType is null"); + return; + } + if (ANI_OK != NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + int returncode = 0; + returncode = Notification::NotificationHelper::SetDistributedEnabledBySlot(slotType,deviceTypeStr,NotificationSts::AniBooleanToBool(enable)); + + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != 0) { + ANS_LOGE("setDistributedEnabledBySlot error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } +} + +ani_boolean isDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType) +{ + ANS_LOGD("isDistributedEnabledBySlot enter"); + std::string deviceTypeStr; + + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (!NotificationSts::SlotTypeEtsToC(env, slot, slotType)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return ANI_FALSE; + } + if (env == nullptr || deviceType == nullptr) { + ANS_LOGE("Invalid env or deviceType is null"); + return ANI_FALSE; + } + if (ANI_OK != NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return ANI_FALSE; + } + bool isEnable = false; + int returncode = Notification::NotificationHelper::IsDistributedEnabledBySlot(slotType, deviceTypeStr, isEnable); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != 0) { + ANS_LOGE("isDistributedEnabledBySlot -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + return isEnable ? ANI_TRUE : ANI_FALSE; +} + +ani_boolean isDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType) +{ + ANS_LOGD("isDistributedEnabledBySlot enter"); + std::string deviceTypeStr; + + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (!NotificationSts::SlotTypeEtsToC(env, slot, slotType)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return ANI_FALSE; + } + if (env == nullptr || deviceType == nullptr) { + ANS_LOGE("Invalid env or deviceType is null"); + return ANI_FALSE; + } + if (ANI_OK != NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return ANI_FALSE; + } + bool isEnable = false; + int returncode = Notification::NotificationHelper::IsDistributedEnabledBySlot(slotType, deviceTypeStr, isEnable); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != 0) { + ANS_LOGE("isDistributedEnabledBySlot -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + return isEnable ? ANI_TRUE : ANI_FALSE; +} +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_set_smart_reminder.cpp b/frameworks/ets/ani/src/manager/ani_set_smart_reminder.cpp new file mode 100644 index 000000000..d4f8949f2 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_set_smart_reminder.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 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 "ani_set_smart_reminder.h" + +#include "inner_errors.h" +#include "notification_helper.h" +#include "ans_log_wrapper.h" +#include "sts_throw_erro.h" +#include "sts_common.h" +#include "sts_bundle_option.h" +#include "sts_notification_manager.h" + +namespace OHOS { +namespace NotificationManagerSts { + +ani_boolean isSmartReminderEnabled(ani_env *env, ani_string deviceType) +{ + ANS_LOGD("isSmartReminderEnabled call"); + bool allowed = false; + std::string deviceTypeStr; + if (env == nullptr || deviceType == nullptr) { + ANS_LOGE("Invalid env or deviceType is null"); + return ANI_FALSE; + } + if (ANI_OK != NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return ANI_FALSE; + } + int returncode = Notification::NotificationHelper::IsSmartReminderEnabled(deviceTypeStr, allowed); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != 0) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("isSmartReminderEnabled -> error, errorCode: %{public}d", externalCode); + } + ANS_LOGD("isSmartReminderEnabled end"); + return NotificationSts::BoolToAniBoolean(allowed); +} + + +void setSmartReminderEnabled(ani_env *env, ani_string deviceType, ani_boolean enable) +{ + ANS_LOGD("setSmartReminderEnabled call"); + std::string deviceTypeStr; + if (env == nullptr || deviceType == nullptr) { + ANS_LOGE("Invalid env or deviceType is null"); + return; + } + + if (ANI_OK != NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + int returncode = Notification::NotificationHelper::SetSmartReminderEnabled(deviceTypeStr, + NotificationSts::AniBooleanToBool(enable)); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != 0) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("setSmartReminderEnabled -> error, errorCode: %{public}d", externalCode); + } + ANS_LOGD("setSmartReminderEnabled end"); +} + +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_set_target.cpp b/frameworks/ets/ani/src/manager/ani_set_target.cpp new file mode 100644 index 000000000..ae6f55efd --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_set_target.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 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 "ani_set_target.h" + +#include "inner_errors.h" +#include "notification_helper.h" +#include "ans_log_wrapper.h" +#include "sts_throw_erro.h" +#include "sts_common.h" +#include "sts_bundle_option.h" +#include "sts_notification_manager.h" + +namespace OHOS { +namespace NotificationManagerSts { + +void setTargetDeviceStatus(ani_env* env, ani_string deviceType, ani_double status) +{ + ANS_LOGD("sts setTargetDeviceStatus call, id:%{public}lf", status); + std::string deviceTypeStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr)) { + std::string msg = "Parameter verification failed"; + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + ANS_LOGD("sts setTargetDeviceStatus id:%{public}lf deviceType:%{public}s", status, deviceTypeStr.c_str()); + int32_t ret = Notification::NotificationHelper::SetTargetDeviceStatus(deviceTypeStr, status, DISTURB_DEFAULT_FLAG); + int externalCode = CJSystemapi::Notification::ErrorToExternal(ret); + if (externalCode != ERR_OK) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("sts setTargetDeviceStatus error, errorCode: %{public}d", externalCode); + return; + } + ANS_LOGD("sts setTargetDeviceStatus end, externalCode: %{public}d", externalCode); +} + +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/subscribe/ani_remove.cpp b/frameworks/ets/ani/src/subscribe/ani_remove.cpp index 7f04ae109..a21e6addd 100644 --- a/frameworks/ets/ani/src/subscribe/ani_remove.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_remove.cpp @@ -130,5 +130,37 @@ void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reason OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } } + +void RemoveAllForBundle(ani_env *env, ani_object bundle) +{ + ANS_LOGD("removeAll enter"); + BundleOption option; + if (!NotificationSts::UnwrapBundleOption(env, bundle, option)) { + ANS_LOGE("bundle is valid"); + std::string msg = "UnwrapBundleOption faild"; + OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); + return; + } + int ret = NotificationHelper::RemoveAllNotifications(option); + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); + if (ret != ERR_OK) { + std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); + } +} + +void RemoveAllForUserId(ani_env *env, ani_double userId) +{ + ANS_LOGD("removeAll enter"); + ANS_LOGD("sts RemoveAll call, userId:%{public}lf", userId); + int ret = NotificationHelper::RemoveNotifications(userId); + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); + if (ret != ERR_OK) { + std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); + } +} } } diff --git a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp index 03f5caef5..6210af902 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -39,6 +39,9 @@ static const char *SUBSCRIBE_SIGNATURE = "Lnotification/notificationSubscribeInfo/NotificationSubscribeInfo;:V"; static const char *UNSUBSCRIBE_SIGNATURE = "Lnotification/notificationSubscriber/NotificationSubscriber;:V"; +static const char *REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE = + "Lnotification/NotificationCommonDef/BundleOption;:V"; +static const char *REMOVEALL_FOR_USERID_STGNATURE ="D:V"; ani_object AniDistributeOperation(ani_env *env, ani_string hashcode, ani_object operationInfo) { @@ -110,6 +113,8 @@ void AniSubScribeRegistryInit(ani_env *env) DISTRIBUTE_OPERATION_SIGNATURE, reinterpret_cast(AniDistributeOperation)}, ani_native_function {"nativeSubscribe", SUBSCRIBE_SIGNATURE, reinterpret_cast(AniSubscribe)}, ani_native_function {"nativeUnSubscribe", UNSUBSCRIBE_SIGNATURE, reinterpret_cast(AniUnSubscribe)}, + ani_native_function {"nativeRemoveAll", REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE, reinterpret_cast(RemoveAllForBundle)}, + ani_native_function {"nativeRemoveAll", REMOVEALL_FOR_USERID_STGNATURE,reinterpret_cast(RemoveAllForUserId)}, }; ANS_LOGD("Start bind native methods to '%{public}s'", npName); diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index 999fa9b11..b602e31fe 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -158,6 +158,15 @@ export default namespace notificationManager { export native function nativeIsNotificationEnabledWithBundleOption(bundleOption: BundleOption): boolean; export native function nativeSetNotificationEnable(bundle: BundleOption, enable: boolean): void; export native function nativeRequestEnableNotification(content: UIAbilityContext): Promise; + export native function nativesetTargetDeviceStatus(deviceType: string, status: number): void; + export native function nativesetDistributedEnabledByBundle(bundle: BundleOption, deviceType: string, enable: boolean): void; + export native function nativesetSmartReminderEnabled(deviceType: string, enable: boolean): void; + export native function nativeisSmartReminderEnabled(deviceType: string): boolean; + export native function nativesetDistributedEnabledBySlot(slot: SlotType, deviceType: string, enabled: boolean): void; + export native function nativeisDistributedEnabledBySlot(slot: SlotType, deviceType: string): boolean; + export native function nativesetAdditionalConfig(key: string, value: string): int; + export native function nativesetDistributedEnableByBundle(bundle: BundleOption, enable: boolean):void; + export native function nativedisableNotificationFeature(disabled:boolean, bundleList: Array):void; function isInvalidParameter(bundle: BundleOption): BusinessError { @@ -1302,4 +1311,155 @@ export default namespace notificationManager { } ) } + + export function setTargetDeviceStatus(deviceType: string, status: number): Promise { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativesetTargetDeviceStatus(deviceType,status); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setDistributedEnabledByBundle(bundle: BundleOption, deviceType: string, enable: boolean): Promise + { + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== 0) { + throw error; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativesetDistributedEnabledByBundle(bundle, deviceType, enable); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + + export function setDistributedEnableByBundle(bundle: BundleOption, enable: boolean): Promise + { + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== 0) { + throw error; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativesetDistributedEnableByBundle(bundle, enable); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setSmartReminderEnabled(deviceType: string, enable: boolean): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativesetSmartReminderEnabled(deviceType, enable); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function isSmartReminderEnabled(deviceType: string): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): boolean => { return nativeisSmartReminderEnabled(deviceType); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setDistributedEnabledBySlot(slot: SlotType, deviceType: string, enabled: boolean): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { + return nativesetDistributedEnabledBySlot(slot, deviceType, enabled); + }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function isDistributedEnabledBySlot(slot: SlotType, deviceType: string): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): boolean => { return nativeisDistributedEnabledBySlot(slot, deviceType); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setAdditionalConfig(key: string, value: string): Promise{ + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): number => { return nativesetAdditionalConfig(key,value); }); + p.then((data: NullishType): void => { + let ret : Double = data as Double; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function disableNotificationFeature(disabled:boolean, bundleList: Array): Promise { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { + return nativedisableNotificationFeature(disabled,bundleList); + }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setDistributedEnableByBundle(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void + { + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== 0) { + throw error; + } + if (callback == null) { + error.code = 401; + error.message = "callback must be not null"; + throw error; + } + let p = taskpool.execute((): void => { return nativesetDistributedEnableByBundle(bundle, enable); }); + p.then((data: NullishType): void => { + let err: BusinessError = {code: 0, data: undefined}; + callback(err, undefined); + }, (error: Object): void => { + let err: BusinessError = error as BusinessError; + callback(err, undefined); + }); + } } \ No newline at end of file diff --git a/frameworks/ets/ets/@ohos.notificationSubscribe.ets b/frameworks/ets/ets/@ohos.notificationSubscribe.ets index b6f139162..b7433396c 100644 --- a/frameworks/ets/ets/@ohos.notificationSubscribe.ets +++ b/frameworks/ets/ets/@ohos.notificationSubscribe.ets @@ -58,6 +58,8 @@ export default namespace notificationSubscribe { export native function nativeSleep(seconds: int): void; export native function nativeSubscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): void; export native function nativeUnSubscribe(subscriber: NotificationSubscriber): void + export native function nativeRemoveAll(bundle?: BundleOption): void; + export native function nativeRemoveAll(userId: number): void; export function subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback): void { if (subscriber == undefined || callback == undefined) { @@ -294,6 +296,88 @@ export default namespace notificationSubscribe { return pPromise; } + export function removeAll(bundle: BundleOption, callback: AsyncCallback): void { + if ( bundle == undefined || callback == undefined) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { + return notificationSubscribe.nativeRemoveAll(bundle); + }); + p.then( + (e: NullishType): void => { + let err: BusinessError = {code: 0, data: undefined}; + callback(err, undefined); + }, (error: Object): void => { + let err: BusinessError = error as BusinessError; + callback(err, undefined); + } + ) + } + + export function removeAll(bundle?: BundleOption): Promise + { + if (bundle == undefined) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return notificationSubscribe.nativeRemoveAll(bundle); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function removeAll(callback: AsyncCallback): void { + if (callback == undefined) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { + return notificationSubscribe.nativeRemoveAll(); + }); + p.then( + (e: NullishType): void => { + let err: BusinessError = {code: 0, data: undefined}; + callback(err, undefined); + }, (error: Object): void => { + let err: BusinessError = error as BusinessError; + callback(err, undefined); + } + ) + } + + export function removeAll(userId: number, callback: AsyncCallback): void { + if (callback == undefined) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { + return notificationSubscribe.nativeRemoveAll(userId); + }); + p.then( + (e: NullishType): void => { + let err: BusinessError = {code: 0, data: undefined}; + callback(err, undefined); + }, (error: Object): void => { + let err: BusinessError = error as BusinessError; + callback(err, undefined); + } + ) + } + + export function removeAll(userId: number): Promise { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return notificationSubscribe.nativeRemoveAll(userId); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + export interface OperationInfo { actionName?: string; userInput?: string; -- Gitee From 9b8318907196c601e5651a66ed129ad1293cbca4 Mon Sep 17 00:00:00 2001 From: kilimanjro Date: Tue, 3 Jun 2025 11:20:47 +0800 Subject: [PATCH 2/4] =?UTF-8?q?ani=E6=8E=A5=E5=8F=A3=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kilimanjro --- .../manager/ani_disable_notification.h | 3 +- .../ani/include/manager/ani_set_additional.h | 2 +- .../ani/include/manager/ani_set_distributed.h | 2 - .../ets/ani/include/manager/ani_set_target.h | 6 +-- .../src/manager/ani_disable_notification.cpp | 5 +- .../ets/ani/src/manager/ani_manager.cpp | 27 ++++++---- .../ani/src/manager/ani_set_additional.cpp | 4 +- .../ani/src/manager/ani_set_distributed.cpp | 54 +++++-------------- .../ets/ani/src/subscribe/ani_subscribe.cpp | 8 +-- 9 files changed, 45 insertions(+), 66 deletions(-) diff --git a/frameworks/ets/ani/include/manager/ani_disable_notification.h b/frameworks/ets/ani/include/manager/ani_disable_notification.h index f3b952ff2..d6c621197 100644 --- a/frameworks/ets/ani/include/manager/ani_disable_notification.h +++ b/frameworks/ets/ani/include/manager/ani_disable_notification.h @@ -19,8 +19,7 @@ namespace OHOS { namespace NotificationManagerSts { - - void disableNotificationFeature(ani_env *env,ani_boolean disabled, ani_object bundleList); + void disableNotificationFeature(ani_env *env, ani_boolean disabled, ani_object bundleList); } // namespace NotificationManagerSts } // namespace OHOS diff --git a/frameworks/ets/ani/include/manager/ani_set_additional.h b/frameworks/ets/ani/include/manager/ani_set_additional.h index 1c408c79f..fa36cb9f6 100644 --- a/frameworks/ets/ani/include/manager/ani_set_additional.h +++ b/frameworks/ets/ani/include/manager/ani_set_additional.h @@ -20,7 +20,7 @@ namespace OHOS { namespace NotificationManagerSts { - ani_int setAdditionalConfig(ani_env *env, ani_string key ,ani_string value); + ani_int setAdditionalConfig(ani_env *env, ani_string key, ani_string value); } // namespace NotificationManagerSts } // namespace OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_set_distributed.h b/frameworks/ets/ani/include/manager/ani_set_distributed.h index f3e48fc21..a654395cd 100644 --- a/frameworks/ets/ani/include/manager/ani_set_distributed.h +++ b/frameworks/ets/ani/include/manager/ani_set_distributed.h @@ -25,8 +25,6 @@ namespace NotificationManagerSts { void setDistributedEnabledByBundle(ani_env *env, ani_object obj, ani_string deviceType, ani_boolean enable); void setDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType, ani_boolean enable); ani_boolean isDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType); - ani_boolean isDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType); - } // namespace NotificationManagerSts } // namespace OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_set_target.h b/frameworks/ets/ani/include/manager/ani_set_target.h index b51a23440..8d8fbfb97 100644 --- a/frameworks/ets/ani/include/manager/ani_set_target.h +++ b/frameworks/ets/ani/include/manager/ani_set_target.h @@ -13,9 +13,9 @@ * limitations under the License. */ - #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_TARGET_H - #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_TARGET_H - #include "ani.h" +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_TARGET_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_TARGET_H +#include "ani.h" namespace OHOS { namespace NotificationManagerSts { diff --git a/frameworks/ets/ani/src/manager/ani_disable_notification.cpp b/frameworks/ets/ani/src/manager/ani_disable_notification.cpp index e51bdb019..26865f9f4 100644 --- a/frameworks/ets/ani/src/manager/ani_disable_notification.cpp +++ b/frameworks/ets/ani/src/manager/ani_disable_notification.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ #include "ani_disable_notification.h" - #include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" @@ -25,7 +24,7 @@ namespace OHOS { namespace NotificationManagerSts { -void disableNotificationFeature(ani_env *env,ani_boolean disabled, ani_object bundleList) +void disableNotificationFeature(ani_env *env, ani_boolean disabled, ani_object bundleList) { ANS_LOGD("disableNotificationFeature enter"); std::vector bundleListStd; @@ -37,7 +36,7 @@ void disableNotificationFeature(ani_env *env,ani_boolean disabled, ani_object bu } Notification::NotificationDisable param; param.SetDisabled(NotificationSts::AniBooleanToBool(disabled)); - param.SetBundleList(bundleListStd); + param.SetBundleList(bundleListStd); int returncode = 0; returncode = Notification::NotificationHelper::DisableNotificationFeature(param); diff --git a/frameworks/ets/ani/src/manager/ani_manager.cpp b/frameworks/ets/ani/src/manager/ani_manager.cpp index c330a87b3..044e4e054 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -76,15 +76,24 @@ static std::array kitManagerFunctions = { ani_native_function {"nativeRequestEnableNotification", "Lapplication/UIAbilityContext/UIAbilityContext;:Lstd/core/Promise;", reinterpret_cast(AniRequestEnableNotification)}, - ani_native_function {"nativesetTargetDeviceStatus", nullptr, reinterpret_cast(setTargetDeviceStatus)}, - ani_native_function {"nativesetDistributedEnabledByBundle", nullptr, reinterpret_cast(setDistributedEnabledByBundle)}, - ani_native_function {"nativesetSmartReminderEnabled", nullptr, reinterpret_cast(setSmartReminderEnabled)}, - ani_native_function {"nativeisSmartReminderEnabled", nullptr, reinterpret_cast(isSmartReminderEnabled)}, - ani_native_function {"nativesetDistributedEnabledBySlot", nullptr, reinterpret_cast(setDistributedEnabledBySlot)}, - ani_native_function {"nativeisDistributedEnabledBySlot", nullptr, reinterpret_cast(isDistributedEnabledBySlot)}, - ani_native_function {"nativesetAdditionalConfig", nullptr, reinterpret_cast(setAdditionalConfig)}, - ani_native_function {"nativesetDistributedEnableByBundle",nullptr,reinterpret_cast(setDistributedEnableByBundle)}, - ani_native_function {"nativedisableNotificationFeature",nullptr,reinterpret_cast(disableNotificationFeature)}, + ani_native_function {"nativesetTargetDeviceStatus", nullptr, + reinterpret_cast(setTargetDeviceStatus)}, + ani_native_function {"nativesetDistributedEnabledByBundle", nullptr, + reinterpret_cast(setDistributedEnabledByBundle)}, + ani_native_function {"nativesetSmartReminderEnabled", nullptr, + reinterpret_cast(setSmartReminderEnabled)}, + ani_native_function {"nativeisSmartReminderEnabled", nullptr, + reinterpret_cast(isSmartReminderEnabled)}, + ani_native_function {"nativesetDistributedEnabledBySlot", nullptr, + reinterpret_cast(setDistributedEnabledBySlot)}, + ani_native_function {"nativeisDistributedEnabledBySlot", nullptr, + reinterpret_cast(isDistributedEnabledBySlot)}, + ani_native_function {"nativesetAdditionalConfig", nullptr, + reinterpret_cast(setAdditionalConfig)}, + ani_native_function {"nativesetDistributedEnableByBundle", + nullptr,reinterpret_cast(setDistributedEnableByBundle)}, + ani_native_function {"nativedisableNotificationFeature", + nullptr,reinterpret_cast(disableNotificationFeature)}, }; void AniNotificationManagerRegistryInit(ani_env *env) diff --git a/frameworks/ets/ani/src/manager/ani_set_additional.cpp b/frameworks/ets/ani/src/manager/ani_set_additional.cpp index c5cee5b04..1d2126b9a 100644 --- a/frameworks/ets/ani/src/manager/ani_set_additional.cpp +++ b/frameworks/ets/ani/src/manager/ani_set_additional.cpp @@ -25,7 +25,7 @@ namespace OHOS { namespace NotificationManagerSts { -ani_int setAdditionalConfig(ani_env *env, ani_string key ,ani_string value) +ani_int setAdditionalConfig(ani_env * env, ani_string key, ani_string value) { ANS_LOGD("sts getSlotFlagsByBundle call"); std::string keyStr; @@ -45,7 +45,7 @@ ani_int setAdditionalConfig(ani_env *env, ani_string key ,ani_string value) return ANI_FALSE; } uint32_t slotFlags = 0; - int returncode = Notification::NotificationHelper::SetAdditionConfig(keyStr,valueStr); + int returncode = Notification::NotificationHelper::SetAdditionConfig(keyStr, valueStr); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); if (externalCode != 0) { ANS_LOGE("setAdditionalConfig -> error, errorCode: %{public}d", externalCode); diff --git a/frameworks/ets/ani/src/manager/ani_set_distributed.cpp b/frameworks/ets/ani/src/manager/ani_set_distributed.cpp index cc8283447..34b6acb7d 100644 --- a/frameworks/ets/ani/src/manager/ani_set_distributed.cpp +++ b/frameworks/ets/ani/src/manager/ani_set_distributed.cpp @@ -31,10 +31,11 @@ void setDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enab int returncode = 0; Notification::NotificationBundleOption option; bool bFlag = NotificationSts::UnwrapBundleOption(env, obj, option); - ANS_LOGD("sts setDistributedEnableByBundle option bundleName: %{public}s, uid: %{public}d, bFlag: %{public}d", option.GetBundleName().c_str(), - option.GetUid(), bFlag); - if(bFlag) { - returncode = Notification::NotificationHelper::EnableDistributedByBundle(option,NotificationSts::AniBooleanToBool(enable)); + ANS_LOGD("sts setDistributedEnableByBundle option bundleName: %{public}s, uid: %{public}d, bFlag: %{public}d", + option.GetBundleName().c_str(),option.GetUid(), bFlag); + if (bFlag) { + returncode = Notification::NotificationHelper::EnableDistributedByBundle( + option,NotificationSts::AniBooleanToBool(enable)); } else { OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); @@ -43,7 +44,7 @@ void setDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enab } int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); if (externalCode != ERR_OK) { - OHOS::AbilityRuntime::ThrowStsError(env, externalCode,NotificationSts::FindAnsErrMsg(externalCode)); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("sts setDistributedEnableByBundle error, errorCode: %{public}d", externalCode); return; } @@ -62,10 +63,11 @@ void setDistributedEnabledByBundle(ani_env *env, ani_object obj, ani_string devi int returncode = 0; Notification::NotificationBundleOption option; bool bFlag = NotificationSts::UnwrapBundleOption(env, obj, option); - ANS_LOGD("sts setDistributedEnabledByBundle option bundleName: %{public}s, uid: %{public}d, bFlag: %{public}d", option.GetBundleName().c_str(), - option.GetUid(), bFlag); - if(bFlag) { - returncode = Notification::NotificationHelper::SetDistributedEnabledByBundle(option,deviceTypeStr,NotificationSts::AniBooleanToBool(enable)); + ANS_LOGD("sts setDistributedEnabledByBundle option bundleName: %{public}s, uid: %{public}d, bFlag: %{public}d", + option.GetBundleName().c_str(),option.GetUid(), bFlag); + if (bFlag) { + returncode = Notification::NotificationHelper::SetDistributedEnabledByBundle( + option, deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); } else { OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); @@ -74,7 +76,7 @@ void setDistributedEnabledByBundle(ani_env *env, ani_object obj, ani_string devi } int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); if (externalCode != ERR_OK) { - OHOS::AbilityRuntime::ThrowStsError(env, externalCode,NotificationSts::FindAnsErrMsg(externalCode)); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("sts setDistributedEnabledByBundle error, errorCode: %{public}d", externalCode); return; } @@ -102,7 +104,7 @@ void setDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string de return; } int returncode = 0; - returncode = Notification::NotificationHelper::SetDistributedEnabledBySlot(slotType,deviceTypeStr,NotificationSts::AniBooleanToBool(enable)); + returncode = Notification::NotificationHelper::SetDistributedEnabledBySlot(slotType, deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); if (externalCode != 0) { @@ -111,36 +113,6 @@ void setDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string de } } -ani_boolean isDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType) -{ - ANS_LOGD("isDistributedEnabledBySlot enter"); - std::string deviceTypeStr; - - Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; - if (!NotificationSts::SlotTypeEtsToC(env, slot, slotType)) { - std::string msg = "Parameter verification failed"; - OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); - return ANI_FALSE; - } - if (env == nullptr || deviceType == nullptr) { - ANS_LOGE("Invalid env or deviceType is null"); - return ANI_FALSE; - } - if (ANI_OK != NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr)) { - std::string msg = "Parameter verification failed"; - OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); - return ANI_FALSE; - } - bool isEnable = false; - int returncode = Notification::NotificationHelper::IsDistributedEnabledBySlot(slotType, deviceTypeStr, isEnable); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { - ANS_LOGE("isDistributedEnabledBySlot -> error, errorCode: %{public}d", externalCode); - AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); - } - return isEnable ? ANI_TRUE : ANI_FALSE; -} - ani_boolean isDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType) { ANS_LOGD("isDistributedEnabledBySlot enter"); diff --git a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp index 6210af902..1bcf8f22f 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -41,7 +41,7 @@ static const char *UNSUBSCRIBE_SIGNATURE = "Lnotification/notificationSubscriber/NotificationSubscriber;:V"; static const char *REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE = "Lnotification/NotificationCommonDef/BundleOption;:V"; -static const char *REMOVEALL_FOR_USERID_STGNATURE ="D:V"; +static const char *REMOVEALL_FOR_USERID_STGNATURE = "D:V"; ani_object AniDistributeOperation(ani_env *env, ani_string hashcode, ani_object operationInfo) { @@ -113,8 +113,10 @@ void AniSubScribeRegistryInit(ani_env *env) DISTRIBUTE_OPERATION_SIGNATURE, reinterpret_cast(AniDistributeOperation)}, ani_native_function {"nativeSubscribe", SUBSCRIBE_SIGNATURE, reinterpret_cast(AniSubscribe)}, ani_native_function {"nativeUnSubscribe", UNSUBSCRIBE_SIGNATURE, reinterpret_cast(AniUnSubscribe)}, - ani_native_function {"nativeRemoveAll", REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE, reinterpret_cast(RemoveAllForBundle)}, - ani_native_function {"nativeRemoveAll", REMOVEALL_FOR_USERID_STGNATURE,reinterpret_cast(RemoveAllForUserId)}, + ani_native_function {"nativeRemoveAll", + REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE, reinterpret_cast(RemoveAllForBundle)}, + ani_native_function {"nativeRemoveAll", + REMOVEALL_FOR_USERID_STGNATURE,reinterpret_cast(RemoveAllForUserId)}, }; ANS_LOGD("Start bind native methods to '%{public}s'", npName); -- Gitee From 2788913806d4a9991424a4a06897a45e398af8b3 Mon Sep 17 00:00:00 2001 From: kilimanjro Date: Tue, 3 Jun 2025 12:59:11 +0800 Subject: [PATCH 3/4] =?UTF-8?q?ani=E6=8E=A5=E5=8F=A3=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kilimanjro --- .../ets/ani/include/manager/ani_disable_notification.h | 6 +++--- frameworks/ets/ani/include/manager/ani_set_additional.h | 6 +++--- frameworks/ets/ani/include/manager/ani_set_distributed.h | 8 +++----- .../ets/ani/include/manager/ani_set_smart_reminder.h | 6 +++--- frameworks/ets/ani/src/manager/ani_manager.cpp | 8 ++++---- frameworks/ets/ani/src/manager/ani_set_distributed.cpp | 9 +++++---- frameworks/ets/ani/src/subscribe/ani_subscribe.cpp | 4 ++-- 7 files changed, 23 insertions(+), 24 deletions(-) diff --git a/frameworks/ets/ani/include/manager/ani_disable_notification.h b/frameworks/ets/ani/include/manager/ani_disable_notification.h index d6c621197..be057d612 100644 --- a/frameworks/ets/ani/include/manager/ani_disable_notification.h +++ b/frameworks/ets/ani/include/manager/ani_disable_notification.h @@ -13,9 +13,9 @@ * limitations under the License. */ - #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DISABLE_NOTIFICATION_H - #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DISABLE_NOTIFICATION_H - #include "ani.h" +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DISABLE_NOTIFICATION_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DISABLE_NOTIFICATION_H +#include "ani.h" namespace OHOS { namespace NotificationManagerSts { diff --git a/frameworks/ets/ani/include/manager/ani_set_additional.h b/frameworks/ets/ani/include/manager/ani_set_additional.h index fa36cb9f6..a0e8b7504 100644 --- a/frameworks/ets/ani/include/manager/ani_set_additional.h +++ b/frameworks/ets/ani/include/manager/ani_set_additional.h @@ -13,9 +13,9 @@ * limitations under the License. */ - #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_ADDITIONAL_H - #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_ADDITIONAL_H - #include "ani.h" +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_ADDITIONAL_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_ADDITIONAL_H +#include "ani.h" namespace OHOS { namespace NotificationManagerSts { diff --git a/frameworks/ets/ani/include/manager/ani_set_distributed.h b/frameworks/ets/ani/include/manager/ani_set_distributed.h index a654395cd..b4ba93997 100644 --- a/frameworks/ets/ani/include/manager/ani_set_distributed.h +++ b/frameworks/ets/ani/include/manager/ani_set_distributed.h @@ -13,11 +13,9 @@ * limitations under the License. */ - #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_DISTRIBUTED_H - #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_DISTRIBUTED_H - #include "ani.h" - - void setDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enable) +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_DISTRIBUTED_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_DISTRIBUTED_H +#include "ani.h" namespace OHOS { namespace NotificationManagerSts { diff --git a/frameworks/ets/ani/include/manager/ani_set_smart_reminder.h b/frameworks/ets/ani/include/manager/ani_set_smart_reminder.h index 89e61ed33..7a68527f6 100644 --- a/frameworks/ets/ani/include/manager/ani_set_smart_reminder.h +++ b/frameworks/ets/ani/include/manager/ani_set_smart_reminder.h @@ -13,9 +13,9 @@ * limitations under the License. */ - #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_SMART_REMINDER_H - #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_SMART_REMINDER_H - #include "ani.h" +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_SMART_REMINDER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SET_SMART_REMINDER_H +#include "ani.h" namespace OHOS { namespace NotificationManagerSts { diff --git a/frameworks/ets/ani/src/manager/ani_manager.cpp b/frameworks/ets/ani/src/manager/ani_manager.cpp index 044e4e054..c7583b1fa 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -90,10 +90,10 @@ static std::array kitManagerFunctions = { reinterpret_cast(isDistributedEnabledBySlot)}, ani_native_function {"nativesetAdditionalConfig", nullptr, reinterpret_cast(setAdditionalConfig)}, - ani_native_function {"nativesetDistributedEnableByBundle", - nullptr,reinterpret_cast(setDistributedEnableByBundle)}, - ani_native_function {"nativedisableNotificationFeature", - nullptr,reinterpret_cast(disableNotificationFeature)}, + ani_native_function {"nativesetDistributedEnableByBundle", + nullptr, reinterpret_cast(setDistributedEnableByBundle)}, + ani_native_function {"nativedisableNotificationFeature", + nullptr, reinterpret_cast(disableNotificationFeature)}, }; void AniNotificationManagerRegistryInit(ani_env *env) diff --git a/frameworks/ets/ani/src/manager/ani_set_distributed.cpp b/frameworks/ets/ani/src/manager/ani_set_distributed.cpp index 34b6acb7d..77ae518dd 100644 --- a/frameworks/ets/ani/src/manager/ani_set_distributed.cpp +++ b/frameworks/ets/ani/src/manager/ani_set_distributed.cpp @@ -32,10 +32,10 @@ void setDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enab Notification::NotificationBundleOption option; bool bFlag = NotificationSts::UnwrapBundleOption(env, obj, option); ANS_LOGD("sts setDistributedEnableByBundle option bundleName: %{public}s, uid: %{public}d, bFlag: %{public}d", - option.GetBundleName().c_str(),option.GetUid(), bFlag); + option.GetBundleName().c_str(), option.GetUid(), bFlag); if (bFlag) { returncode = Notification::NotificationHelper::EnableDistributedByBundle( - option,NotificationSts::AniBooleanToBool(enable)); + option, NotificationSts::AniBooleanToBool(enable)); } else { OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); @@ -64,7 +64,7 @@ void setDistributedEnabledByBundle(ani_env *env, ani_object obj, ani_string devi Notification::NotificationBundleOption option; bool bFlag = NotificationSts::UnwrapBundleOption(env, obj, option); ANS_LOGD("sts setDistributedEnabledByBundle option bundleName: %{public}s, uid: %{public}d, bFlag: %{public}d", - option.GetBundleName().c_str(),option.GetUid(), bFlag); + option.GetBundleName().c_str(), option.GetUid(), bFlag); if (bFlag) { returncode = Notification::NotificationHelper::SetDistributedEnabledByBundle( option, deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); @@ -104,7 +104,8 @@ void setDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string de return; } int returncode = 0; - returncode = Notification::NotificationHelper::SetDistributedEnabledBySlot(slotType, deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); + returncode = Notification::NotificationHelper::SetDistributedEnabledBySlot( + slotType, deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); if (externalCode != 0) { diff --git a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp index 1bcf8f22f..4571258eb 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -115,8 +115,8 @@ void AniSubScribeRegistryInit(ani_env *env) ani_native_function {"nativeUnSubscribe", UNSUBSCRIBE_SIGNATURE, reinterpret_cast(AniUnSubscribe)}, ani_native_function {"nativeRemoveAll", REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE, reinterpret_cast(RemoveAllForBundle)}, - ani_native_function {"nativeRemoveAll", - REMOVEALL_FOR_USERID_STGNATURE,reinterpret_cast(RemoveAllForUserId)}, + ani_native_function {"nativeRemoveAll", + REMOVEALL_FOR_USERID_STGNATURE, reinterpret_cast(RemoveAllForUserId)}, }; ANS_LOGD("Start bind native methods to '%{public}s'", npName); -- Gitee From 5416beec96ebe1e217c86153a8e6b99d5f6658d9 Mon Sep 17 00:00:00 2001 From: kilimanjro Date: Tue, 3 Jun 2025 15:38:27 +0800 Subject: [PATCH 4/4] =?UTF-8?q?ani=E6=8E=A5=E5=8F=A3=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kilimanjro --- frameworks/ets/ani/src/manager/ani_manager.cpp | 2 +- frameworks/ets/ani/src/manager/ani_set_smart_reminder.cpp | 2 +- frameworks/ets/ani/src/subscribe/ani_subscribe.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/ets/ani/src/manager/ani_manager.cpp b/frameworks/ets/ani/src/manager/ani_manager.cpp index c7583b1fa..de8ddd79e 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -88,7 +88,7 @@ static std::array kitManagerFunctions = { reinterpret_cast(setDistributedEnabledBySlot)}, ani_native_function {"nativeisDistributedEnabledBySlot", nullptr, reinterpret_cast(isDistributedEnabledBySlot)}, - ani_native_function {"nativesetAdditionalConfig", nullptr, + ani_native_function {"nativesetAdditionalConfig", nullptr, reinterpret_cast(setAdditionalConfig)}, ani_native_function {"nativesetDistributedEnableByBundle", nullptr, reinterpret_cast(setDistributedEnableByBundle)}, diff --git a/frameworks/ets/ani/src/manager/ani_set_smart_reminder.cpp b/frameworks/ets/ani/src/manager/ani_set_smart_reminder.cpp index d4f8949f2..74978d8ef 100644 --- a/frameworks/ets/ani/src/manager/ani_set_smart_reminder.cpp +++ b/frameworks/ets/ani/src/manager/ani_set_smart_reminder.cpp @@ -70,7 +70,7 @@ void setSmartReminderEnabled(ani_env *env, ani_string deviceType, ani_boolean en if (externalCode != 0) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("setSmartReminderEnabled -> error, errorCode: %{public}d", externalCode); - } + } ANS_LOGD("setSmartReminderEnabled end"); } diff --git a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp index 4571258eb..de0ff1905 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -113,7 +113,7 @@ void AniSubScribeRegistryInit(ani_env *env) DISTRIBUTE_OPERATION_SIGNATURE, reinterpret_cast(AniDistributeOperation)}, ani_native_function {"nativeSubscribe", SUBSCRIBE_SIGNATURE, reinterpret_cast(AniSubscribe)}, ani_native_function {"nativeUnSubscribe", UNSUBSCRIBE_SIGNATURE, reinterpret_cast(AniUnSubscribe)}, - ani_native_function {"nativeRemoveAll", + ani_native_function {"nativeRemoveAll", REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE, reinterpret_cast(RemoveAllForBundle)}, ani_native_function {"nativeRemoveAll", REMOVEALL_FOR_USERID_STGNATURE, reinterpret_cast(RemoveAllForUserId)}, -- Gitee