diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index 34ea02605198fdebb9480ea0e45dc6f0fe51c474..4f31202e99ab136e2baad936a23c2a2ff92cef53 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", "./src/manager/ani_on.cpp", "./src/manager/ani_push_callback.cpp", ] 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 0000000000000000000000000000000000000000..be057d612d1ebb5d77e5445e4b8e58c155e3174d --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_disable_notification.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_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 0000000000000000000000000000000000000000..a0e8b7504299529efdaa6fc6b5f82f5758b8b822 --- /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 0000000000000000000000000000000000000000..b4ba93997c78bf3927e117c4bc30a65b7b5a49d7 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_set_distributed.h @@ -0,0 +1,28 @@ +/* + * 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" + +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); +} // 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 0000000000000000000000000000000000000000..7a68527f61b4e090d48ed38adcaeee0ea36e9ba6 --- /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 0000000000000000000000000000000000000000..8d8fbfb97d9d9818495058ba91eb64d0f469b8b9 --- /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 a60aa5ab895341aa33e0008a048746903b51c7c0..1ba0265fa7faa87de542144c9bfb1c9bed1dd3ca 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 0000000000000000000000000000000000000000..26865f9f4112e1ebdc840be70341ef2895bd7255 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_disable_notification.cpp @@ -0,0 +1,51 @@ +/* + * 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 ed6f74a8d3d02e5f15a71414af7c1f0afda5f2cb..d98ef7602c3a57b1291e7b30647a62b418377fae 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -24,6 +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" #include "ani_on.h" namespace OHOS { @@ -73,6 +78,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 {"nativeOn", "Lstd/core/String;" "Lstd/core/Function1;" 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 0000000000000000000000000000000000000000..1d2126b9a5c696b46b0cba07c285cde8e997de36 --- /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 0000000000000000000000000000000000000000..77ae518dd8390255a32d2bc9ed2435103165a687 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_set_distributed.cpp @@ -0,0 +1,147 @@ +/* + * 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; +} +} // 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 0000000000000000000000000000000000000000..74978d8ef0a82930bc1e126514e25251100a6c4b --- /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 0000000000000000000000000000000000000000..ae6f55efd564fbb222247a60b80aea4d7a3d632d --- /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 7f04ae1091d5e27e4efb9353cb2dfcaf6b4df557..a21e6addd24804f03d45ae7d8f10f0713dd140dd 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 03f5caef50e9d191218e4c5b9aabc725d0234386..de0ff19054fbfad124f7c957554d71c05fef4a5f 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,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)}, }; 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 7dcb4589e447c25129cef4777c099a865c6d7054..69d47e7b1854048e11a798a2e04103f2c24a839d 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -160,6 +160,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; export native function nativeOn( type: 'checkNotification', callback: CallbackForCheckInfo, checkRequest?: NotificationCheckRequest): int; @@ -1310,6 +1319,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); + }); export interface NotificationCheckResult { code: number; message: string; diff --git a/frameworks/ets/ets/@ohos.notificationSubscribe.ets b/frameworks/ets/ets/@ohos.notificationSubscribe.ets index b6f13916283b7d13f561d645c822027451a7d2e8..b7433396c82f207954e273db30b3bb3f843fff47 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;