From 819956dd68c98ac0e17cd88f37678329f64f90f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E6=89=94?= Date: Tue, 3 Jun 2025 09:51:31 +0800 Subject: [PATCH 01/14] add on/off MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 一扔 --- frameworks/ets/ani/BUILD.gn | 9 ++ frameworks/ets/ani/include/manager/ani_on.h | 27 ++++ .../ani/include/manager/ani_push_callback.h | 56 +++++++ .../ani/include/sts_notification_manager.h | 3 + frameworks/ets/ani/include/sts_request.h | 2 + frameworks/ets/ani/include/sts_throw_erro.h | 12 ++ .../ets/ani/src/manager/ani_manager.cpp | 8 + frameworks/ets/ani/src/manager/ani_on.cpp | 125 +++++++++++++++ .../ets/ani/src/manager/ani_push_callback.cpp | 148 +++++++++++++++++ frameworks/ets/ani/src/sts_action_button.cpp | 2 +- frameworks/ets/ani/src/sts_bundle_option.cpp | 2 +- frameworks/ets/ani/src/sts_common.cpp | 4 +- .../ets/ani/src/sts_notification_manager.cpp | 150 ++++++++++++++++++ frameworks/ets/ani/src/sts_request.cpp | 82 ++++++++++ frameworks/ets/ani/src/sts_subscribe.cpp | 4 +- .../ets/ets/@ohos.notificationManager.ets | 96 ++++++++++- 16 files changed, 723 insertions(+), 7 deletions(-) create mode 100755 frameworks/ets/ani/include/manager/ani_on.h create mode 100755 frameworks/ets/ani/include/manager/ani_push_callback.h create mode 100755 frameworks/ets/ani/src/manager/ani_on.cpp create mode 100755 frameworks/ets/ani/src/manager/ani_push_callback.cpp diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index fa0771b8a..34ea02605 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -56,6 +56,8 @@ 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_on.cpp", + "./src/manager/ani_push_callback.cpp", ] cflags = [] @@ -68,6 +70,12 @@ ohos_shared_library("notification_manager_ani") { "${frameworks_path}/cj/ffi:cj_notification_manager_ffi", ] + defines = [] + + if (distributed_notification_service_feature_local_liveview) { + defines += [ "ANS_FEATURE_LIVEVIEW_LOCAL_LIVEVIEW" ] + } + external_deps = [ "c_utils:utils", "hilog:libhilog", @@ -87,6 +95,7 @@ ohos_shared_library("notification_manager_ani") { "ability_runtime:abilitykit_native", "ability_runtime:app_context", "ace_engine:ace_uicontent", + "access_token:libtokenid_sdk", ] innerapi_tags = [ "platformsdk" ] diff --git a/frameworks/ets/ani/include/manager/ani_on.h b/frameworks/ets/ani/include/manager/ani_on.h new file mode 100755 index 000000000..911d45fd8 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_on.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_ON_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_ON_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +ani_int AniOn(ani_env *env, ani_string type, ani_fn_object fn, ani_object checkRequestObj); +ani_int AniOff(ani_env *env, ani_string type, ani_fn_object fn); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif + diff --git a/frameworks/ets/ani/include/manager/ani_push_callback.h b/frameworks/ets/ani/include/manager/ani_push_callback.h new file mode 100755 index 000000000..fcaf53782 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_push_callback.h @@ -0,0 +1,56 @@ +/* + * 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_PUSH_CALLBACK_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_PUSH_CALLBACK_H +#include +#include +#include "ani.h" +#include "push_callback_stub.h" +#include "notification_constant.h" + +namespace OHOS { +namespace NotificationManagerSts { +using namespace OHOS::Notification; +class StsPushCallBack : public PushCallBackStub { +public: + struct ResultParam { + int32_t code = -1; + std::string msg = ""; + }; + + StsPushCallBack(ani_env *env); + virtual ~StsPushCallBack(); + int32_t OnCheckNotification( + const std::string ¬ificationData, const std::shared_ptr &pushCallBackParam) override; + void SetJsPushCallBackObject(ani_env *env, NotificationConstant::SlotType slotType, ani_ref pushCallBackObject); + void HandleCheckCallback( + ani_env *env, ani_fn_object fn, ani_object value, const std::shared_ptr &pushCallBackParam); + +private: + int32_t CheckNotification( + ani_env *env, + const std::string ¬ificationData, + const std::shared_ptr &pushCallBackParam); + static bool WarpFunctionResult(ani_env *env, ani_object funcResult, ResultParam &result); + ani_vm *vm_ = nullptr; + std::map pushCallBackObjects_; + std::mutex mutexlock; +}; + +} // namespace NotificationManagerSts +} // namespace OHOS +#endif + diff --git a/frameworks/ets/ani/include/sts_notification_manager.h b/frameworks/ets/ani/include/sts_notification_manager.h index 8c9a089fb..f40c52115 100644 --- a/frameworks/ets/ani/include/sts_notification_manager.h +++ b/frameworks/ets/ani/include/sts_notification_manager.h @@ -22,6 +22,7 @@ #include "notification_button_option.h" #include "notification_local_live_view_subscriber.h" #include "sts_runtime.h" +#include "notification_check_info.h" namespace OHOS { namespace NotificationSts { @@ -138,6 +139,8 @@ ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonO ani_object WarpNotificationButtonOption(ani_env *env, sptr buttonOption); bool WarpNotificationDoNotDisturbDate( ani_env *env, const std::shared_ptr &date, ani_object &outObj); +bool WarpNotificationCheckInfo( + ani_env *env, const std::shared_ptr &data, ani_object &outObj); } // namespace NotificationSts } // OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/sts_request.h b/frameworks/ets/ani/include/sts_request.h index 893d6ce46..02a69f21d 100644 --- a/frameworks/ets/ani/include/sts_request.h +++ b/frameworks/ets/ani/include/sts_request.h @@ -41,6 +41,8 @@ bool WarpNotificationRequest( ani_env *env, const NotificationRequest *notificationRequest, ani_class &cls, ani_object &outAniObj); ani_object GetAniNotificationRequestArray(ani_env *env, std::vector> requests); ani_object GetAniNotificationRequestArrayByNotifocations(ani_env *env, std::vector> requests); + +bool UnWarpNotificationCheckRequest(ani_env *env, ani_object obj, sptr &checkRequest); } // namespace NotificationSts } // OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/sts_throw_erro.h b/frameworks/ets/ani/include/sts_throw_erro.h index 6bd3d6d5a..44f75ae9b 100644 --- a/frameworks/ets/ani/include/sts_throw_erro.h +++ b/frameworks/ets/ani/include/sts_throw_erro.h @@ -71,6 +71,18 @@ inline void ThrowStsErroWithMsg(ani_env *env, std::string logMsg) OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); } + +inline void ThrowStsErrorWithCode(ani_env *env, const int32_t errCode, std::string msg = "") +{ + if (env == nullptr) return; + OHOS::AbilityRuntime::ThrowStsError(env, errCode, msg.empty() ? FindAnsErrMsg(errCode) : msg); +} + +inline void ThrowStsErrorWithInvalidParam(ani_env *env) +{ + ThrowStsErrorWithCode(env, ERROR_PARAM_INVALID); +} + } // namespace NotificationSts } // OHOS #endif diff --git a/frameworks/ets/ani/src/manager/ani_manager.cpp b/frameworks/ets/ani/src/manager/ani_manager.cpp index 4cc8d56c2..ed6f74a8d 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -24,6 +24,7 @@ #include "ani_publish.h" #include "ani_local_live_view.h" #include "ani_request_enable.h" +#include "ani_on.h" namespace OHOS { namespace NotificationManagerSts { @@ -72,6 +73,13 @@ static std::array kitManagerFunctions = { ani_native_function {"nativeRequestEnableNotification", "Lapplication/UIAbilityContext/UIAbilityContext;:Lstd/core/Promise;", reinterpret_cast(AniRequestEnableNotification)}, + ani_native_function {"nativeOn", + "Lstd/core/String;" + "Lstd/core/Function1;" + "Lnotification/notificationRequest/NotificationCheckRequest;" + ":I", + reinterpret_cast(AniOn)}, + ani_native_function {"nativeOff", "Lstd/core/String;Lstd/core/Function1;:I", reinterpret_cast(AniOff)}, }; void AniNotificationManagerRegistryInit(ani_env *env) diff --git a/frameworks/ets/ani/src/manager/ani_on.cpp b/frameworks/ets/ani/src/manager/ani_on.cpp new file mode 100755 index 000000000..8d4da2c64 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_on.cpp @@ -0,0 +1,125 @@ +/* + * 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_on.h" +#include "ans_log_wrapper.h" +#include "sts_common.h" +#include "sts_throw_erro.h" +#include "sts_request.h" +#include "ani_push_callback.h" +#include "ipc_skeleton.h" +#include "tokenid_kit.h" +#include "notification_helper.h" +#include "inner_errors.h" + +constexpr const char* TYPE_STRING = "checkNotification"; +namespace OHOS { +namespace NotificationManagerSts { +using namespace OHOS::Notification; + +bool CheckCallerIsSystemApp() +{ + auto selfToken = IPCSkeleton::GetSelfTokenID(); + if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) { + ANS_LOGE("current app is not system app, not allow."); + return false; + } + return true; +} + +ani_int AniOn(ani_env *env, ani_string type, ani_fn_object fn, ani_object checkRequestObj) +{ + ANS_LOGD("enter"); +#ifdef ANS_FEATURE_LIVEVIEW_LOCAL_LIVEVIEW + std::string typeStr = ""; + ani_status status = OHOS::NotificationSts::GetStringByAniString(env, type, typeStr); + if (status != ANI_OK || typeStr.compare(TYPE_STRING)) { + ANS_LOGE("InvalidParam 'type'"); + int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; + OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + return errCode; + } + if (OHOS::NotificationSts::IsUndefine(env, checkRequestObj)) { + ANS_LOGI("Old function param, don't need register."); + return ERR_OK; + } + sptr checkRequest = new NotificationCheckRequest(); + if (!OHOS::NotificationSts::UnWarpNotificationCheckRequest(env, checkRequestObj, checkRequest)) { + ANS_LOGE("InvalidParam 'checkRequest'"); + int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; + OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + return errCode; + } + if (!CheckCallerIsSystemApp()) { + OHOS::NotificationSts::ThrowStsErrorWithCode(env, ERROR_NOT_SYSTEM_APP); + return ERROR_NOT_SYSTEM_APP; + } + + sptr stsPushCallBack_ = new (std::nothrow) StsPushCallBack(env); + if (stsPushCallBack_ == nullptr) { + ANS_LOGE("new stsPushCallBack_ failed"); + OHOS::NotificationSts::ThrowStsErrorWithCode(env, ERROR_INTERNAL_ERROR); + return ERROR_INTERNAL_ERROR; + } + NotificationConstant::SlotType outSlotType = checkRequest->GetSlotType(); + stsPushCallBack_->SetJsPushCallBackObject(env, outSlotType, fn); + auto result = NotificationHelper::RegisterPushCallback(stsPushCallBack_->AsObject(), checkRequest); + if (result != ERR_OK) { + int32_t externalCode = ERR_OK ? ERR_OK : CJSystemapi::Notification::ErrorToExternal(result); + ANS_LOGE("Register failed, result is %{public}d", externalCode); + OHOS::NotificationSts::ThrowStsErrorWithCode(env, externalCode); + return externalCode; + } + ANS_LOGD("done"); + return result; +#else + int32_t errCode = OHOS::Notification::ERROR_SYSTEM_CAP_ERROR; + OHOS::NotificationSts::ThrowStsErrorWithCode(env, errCode); + return errCode; +#endif +} + +ani_int AniOff(ani_env *env, ani_string type, ani_fn_object fn) +{ + ANS_LOGD("enter"); +#ifdef ANS_FEATURE_LIVEVIEW_LOCAL_LIVEVIEW + std::string typeStr = ""; + ani_status status = OHOS::NotificationSts::GetStringByAniString(env, type, typeStr); + if (status != ANI_OK || typeStr.compare(TYPE_STRING)) { + ANS_LOGE("InvalidParam 'type'"); + int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; + OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + return errCode; + } + if (!CheckCallerIsSystemApp()) { + OHOS::NotificationSts::ThrowStsErrorWithCode(env, ERROR_NOT_SYSTEM_APP); + return ERROR_NOT_SYSTEM_APP; + } + if (!OHOS::NotificationSts::IsUndefine(env, fn)) { + int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; + OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + return errCode; + } + int32_t ret = NotificationHelper::UnregisterPushCallback(); + ANS_LOGD("done. ret %{public}d", ret); + return ERR_OK; +#else + int32_t errCode = OHOS::Notification::ERROR_SYSTEM_CAP_ERROR; + OHOS::NotificationSts::ThrowStsErrorWithCode(env, errCode); + return errCode; +#endif +} +} +} \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_push_callback.cpp b/frameworks/ets/ani/src/manager/ani_push_callback.cpp new file mode 100755 index 000000000..b20c33fbd --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_push_callback.cpp @@ -0,0 +1,148 @@ +/* + * 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_push_callback.h" +#include "ans_log_wrapper.h" +#include "sts_notification_manager.h" +#include "sts_common.h" + +namespace OHOS { +namespace NotificationManagerSts { +using namespace OHOS::Notification; +using namespace OHOS::NotificationSts; +StsPushCallBack::StsPushCallBack(ani_env *env) +{ + if (env == nullptr || env->GetVM(&vm_) != ANI_OK) { + ANS_LOGE("InvalidParam 'env'"); + } +} + +StsPushCallBack::~StsPushCallBack() +{ +} + +int32_t StsPushCallBack::OnCheckNotification( + const std::string ¬ificationData, const std::shared_ptr &pushCallBackParam) +{ + ANS_LOGD("enter"); + std::lock_guard l(mutexlock); + if (vm_ == nullptr || pushCallBackParam == nullptr) { + ANS_LOGE("InvalidParam"); + return ERR_INVALID_STATE; + } + ani_env* env; + ani_status aniResult = ANI_ERROR; + if (ANI_OK != (aniResult = vm_->GetEnv(ANI_VERSION_1, &env))) { + ANS_LOGD("GetEnv error. result: %{public}d.", aniResult); + return ERR_INVALID_STATE; + } + return CheckNotification(env, notificationData, pushCallBackParam); +} + +void StsPushCallBack::SetJsPushCallBackObject( + ani_env *env, NotificationConstant::SlotType slotType, ani_ref pushCallBackObject) +{ + ANS_LOGD("enter"); + if (env == nullptr || pushCallBackObject == nullptr) { + ANS_LOGE("InvalidParam"); + return; + } + ani_ref pushCheckObject; + ani_status status = ANI_OK; + if (ANI_OK != (status = env->GlobalReference_Create(pushCallBackObject, &pushCheckObject))) { + ANS_LOGE("GlobalReference_Create pushCallBackObject faild. status %{public}d", status); + return; + } + pushCallBackObjects_.insert_or_assign(slotType, pushCheckObject); +} + +void StsPushCallBack::HandleCheckCallback( + ani_env *env, ani_fn_object fn, ani_object value, const std::shared_ptr &pushCallBackParam) +{ + ANS_LOGD("enter"); + if (env == nullptr || fn == nullptr || value == nullptr || pushCallBackParam == nullptr) { + ANS_LOGE("pushCallBackObjects is nullptr"); + return; + } + std::vector vec; + vec.push_back(value); + ani_ref funcResult; + ani_status status = ANI_OK; + if (ANI_OK != (status = env->FunctionalObject_Call(fn, vec.size(), vec.data(), &funcResult))) { + ANS_LOGE("FunctionalObject_Call faild. status %{public}d", status); + return; + } + ResultParam result; + if (!WarpFunctionResult(env, static_cast(funcResult), result)) { + ANS_LOGE("WarpFunctionResult faild"); + return; + } + std::unique_lock uniqueLock(pushCallBackParam->callBackMutex); + pushCallBackParam->result = result.code; + pushCallBackParam->ready = true; + pushCallBackParam->callBackCondition.notify_all(); + ANS_LOGD("done"); +} + +int32_t StsPushCallBack::CheckNotification( + ani_env *env, + const std::string ¬ificationData, + const std::shared_ptr &pushCallBackParam) +{ + ANS_LOGD("enter"); + auto checkInfo = std::make_shared(); + checkInfo->ConvertJsonStringToValue(notificationData); + NotificationConstant::SlotType outSlotType = static_cast(checkInfo->GetSlotType()); + if (pushCallBackObjects_.find(outSlotType) == pushCallBackObjects_.end()) { + ANS_LOGE("pushCallBackObjects is nullptr"); + return ERR_INVALID_STATE; + } + ani_object checkInfoObj; + if (!WarpNotificationCheckInfo(env, checkInfo, checkInfoObj) || checkInfoObj == nullptr) { + ANS_LOGE("WarpNotificationCheckInfo faild"); + return ERR_INVALID_STATE; + } + HandleCheckCallback( + env, static_cast(pushCallBackObjects_[outSlotType]), checkInfoObj, pushCallBackParam); + return ERR_OK; +} + +bool StsPushCallBack::WarpFunctionResult(ani_env *env, ani_object obj, ResultParam &result) +{ + ANS_LOGD("enter"); + if (env == nullptr || obj == nullptr) return false; + ani_status status = ANI_OK; + ani_double code; + ani_ref msg; + std::string message = ""; + if (ANI_OK != (status = env->Object_GetPropertyByName_Double(obj, "code", &code))) { + ANS_LOGE("WarpFunctionResult. code faild. status %{public}d", status); + return false; + } + if (ANI_OK != (status = env->Object_GetPropertyByName_Ref(obj, "message", &msg))) { + ANS_LOGE("WarpFunctionResult. message faild. status %{public}d", status); + return false; + } + if (ANI_OK != (status = GetStringByAniString(env, static_cast(msg), message))) { + ANS_LOGE("GetStringByAniString faild. status %{public}d", status); + return false; + } + result.code = code; + result.msg = message; + ANS_LOGD("WarpFunctionResult: code %{public}d message %{public}s", result.code, result.msg.c_str()); + return true; +} +} +} \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_action_button.cpp b/frameworks/ets/ani/src/sts_action_button.cpp index 7b5288f74..26968f752 100644 --- a/frameworks/ets/ani/src/sts_action_button.cpp +++ b/frameworks/ets/ani/src/sts_action_button.cpp @@ -146,7 +146,7 @@ bool SetNotificationActionButtonByRequiredParameter( } ani_string stringValue; // title: string; - if (!GetAniStringByString(env, actionButton->GetTitle(), stringValue)) { + if (ANI_OK != GetAniStringByString(env, actionButton->GetTitle(), stringValue)) { ANS_LOGE("SetActionButtonByRequiredParameter: Get title failed"); return false; } diff --git a/frameworks/ets/ani/src/sts_bundle_option.cpp b/frameworks/ets/ani/src/sts_bundle_option.cpp index 4da10d202..c2e8937b8 100644 --- a/frameworks/ets/ani/src/sts_bundle_option.cpp +++ b/frameworks/ets/ani/src/sts_bundle_option.cpp @@ -95,7 +95,7 @@ bool WrapBundleOption(ani_env* env, } // bundle: string; ani_string stringValue = nullptr; - if (!GetAniStringByString(env, bundleOption->GetBundleName(), stringValue) + if (ANI_OK != GetAniStringByString(env, bundleOption->GetBundleName(), stringValue) || !CallSetter(env, bundleCls, bundleObject, "bundle", stringValue)) { ANS_LOGE("WrapBundleOption: set bundle failed"); return false; diff --git a/frameworks/ets/ani/src/sts_common.cpp b/frameworks/ets/ani/src/sts_common.cpp index 44ecf2cc0..f8f25b2f7 100644 --- a/frameworks/ets/ani/src/sts_common.cpp +++ b/frameworks/ets/ani/src/sts_common.cpp @@ -93,8 +93,8 @@ bool GetStringArrayByAniObj(ani_env *env, const ani_object ani_obj, std::vector< return false; } std::string std_string; - if (!GetStringByAniString(env, static_cast(stringEntryRef), std_string)) { - ANS_LOGE("GetStdString faild"); + if (ANI_OK != (status = GetStringByAniString(env, static_cast(stringEntryRef), std_string))) { + ANS_LOGE("GetStdString faild. status %{public}d", status); return false; } stdVString.emplace_back(std_string); diff --git a/frameworks/ets/ani/src/sts_notification_manager.cpp b/frameworks/ets/ani/src/sts_notification_manager.cpp index 45e711814..dfd92189c 100644 --- a/frameworks/ets/ani/src/sts_notification_manager.cpp +++ b/frameworks/ets/ani/src/sts_notification_manager.cpp @@ -15,6 +15,7 @@ #include "sts_notification_manager.h" #include "sts_common.h" #include "ani_common_util.h" +#include "ani_common_want.h" namespace OHOS { namespace NotificationSts { @@ -462,5 +463,154 @@ bool WarpNotificationDoNotDisturbDate( ANS_LOGD("WarpNotificationDoNotDisturbDate end"); return true; } + +bool SetCheckInfoContentType(ani_env *env, ani_object &obj, const std::string &name, ContentType type) +{ + if (env == nullptr || obj == nullptr || name.empty()) { + ANS_LOGE("InvalidParam"); + return false; + } + STSContentType stsType = NOTIFICATION_CONTENT_BASIC_TEXT; + ani_enum_item item; + if (!StsContentTypeUtils::CToSts(type, stsType)) { + ANS_LOGE("CToSts 'contentType' faild."); + return false; + } + if (!EnumConvertNativeToAni(env, "L@ohos/notificationManager/notificationManager/ContentType;", stsType, item)) { + ANS_LOGE("EnumConvertNativeToAni 'contentType' faild."); + return false; + } + if (!SetPropertyByRef(env, obj, name.c_str(), static_cast(item))) { + ANS_LOGE("SetPropertyByRef 'contentType' faild."); + return false; + } + return true; +} + +bool SetCheckInfoSlotType(ani_env *env, ani_object &obj, const std::string &name, SlotType type) +{ + if (env == nullptr || obj == nullptr || name.empty()) { + ANS_LOGE("InvalidParam"); + return false; + } + STSSlotType stsType = UNKNOWN_TYPE; + ani_enum_item item; + if (!StsSlotTypeUtils::CToSts(type, stsType)) { + ANS_LOGE("CToSts 'slotType' faild."); + return false; + } + if (!EnumConvertNativeToAni(env, "L@ohos/notificationManager/notificationManager/SlotType;", stsType, item)) { + ANS_LOGE("EnumConvertNativeToAni 'slotType' faild."); + return false; + } + if (!SetPropertyByRef(env, obj, name.c_str(), static_cast(item))) { + ANS_LOGE("SetPropertyByRef 'slotType' faild."); + return false; + } + return true; +} + +bool SetNotificationCheckInfoNumber( + ani_env *env, const std::shared_ptr &data, ani_object &outObj) +{ + ani_status status = ANI_OK; + // notificationId: number; + if (ANI_OK != (status = env->Object_SetPropertyByName_Double( + outObj, "notificationId", static_cast(data->GetNotifyId())))) { + ANS_LOGE("WarpNotificationCheckInfo. set 'notificationId' faild. status %{public}d", status); + return false; + } + // creatorUserId: number; + if (ANI_OK != (status = env->Object_SetPropertyByName_Double( + outObj, "creatorUserId", static_cast(data->GetCreatorUserId())))) { + ANS_LOGE("WarpNotificationCheckInfo. set 'creatorUserId' faild. status %{public}d", status); + return false; + } + return true; +} + +bool SetNotificationCheckInfoString( + ani_env *env, const std::shared_ptr &data, ani_object &outObj) +{ + // bundleName: string; + if (!SetPropertyOptionalByString(env, outObj, "bundleName", data->GetPkgName())) { + ANS_LOGE("WarpNotificationCheckInfo set 'bundleName' faild"); + return false; + } + // label?: string; + if (!data->GetLabel().empty() && !SetPropertyOptionalByString(env, outObj, "label", data->GetLabel())) { + ANS_LOGE("WarpNotificationCheckInfo set 'label' faild"); + return false; + } + return true; +} + +bool SetNotificationCheckInfoEnum( + ani_env *env, const std::shared_ptr &data, ani_object &outObj) +{ + // contentType: ContentType; + if (!SetCheckInfoContentType(env, outObj, "contentType", static_cast(data->GetContentType()))) { + ANS_LOGE("WarpNotificationCheckInfo set 'contentType' faild"); + return false; + } + // slotType: SlotType; + if (!SetCheckInfoSlotType(env, outObj, "slotType", static_cast(data->GetSlotType()))) { + ANS_LOGE("WarpNotificationCheckInfo set 'slotType' faild"); + return false; + } + return true; +} + +bool SetNotificationCheckInfo( + ani_env *env, const std::shared_ptr &data, ani_object &outObj) +{ + if (!SetNotificationCheckInfoNumber(env, data, outObj)) { + ANS_LOGE("SetNotificationCheckInfoNumber faild"); + return false; + } + if (!SetNotificationCheckInfoString(env, data, outObj)) { + ANS_LOGE("SetNotificationCheckInfoString faild"); + return false; + } + if (!SetNotificationCheckInfoEnum(env, data, outObj)) { + ANS_LOGE("SetNotificationCheckInfoEnum faild"); + return false; + } + // extraInfos?: Record; + if (data->GetExtraInfo() != nullptr) { + ani_ref extraInfos = OHOS::AppExecFwk::WrapWantParams(env, *(data->GetExtraInfo())); + if (extraInfos == nullptr) { + ANS_LOGE("WrapWantParams 'extraInfos' faild"); + return false; + } + if (!SetPropertyByRef(env, outObj, "extraInfos", extraInfos)) { + ANS_LOGE("WarpNotificationCheckInfo set 'extraInfos' faild"); + return false; + } + } + return true; +} + +bool WarpNotificationCheckInfo( + ani_env *env, const std::shared_ptr &data, ani_object &outObj) +{ + ani_object obj; + ani_class cls; + if (env == nullptr || data == nullptr) { + ANS_LOGE("InvalidParam"); + return false; + } + if (!CreateClassObjByClassName( + env, "L@ohos/notificationManager/notificationManager/NotificationCheckInfoInner;", cls, obj)) { + ANS_LOGE("WarpNotificationCheckInfo create faild"); + return false; + } + if (!SetNotificationCheckInfo(env, data, obj)) { + ANS_LOGE("SetNotificationCheckInfo faild"); + return false; + } + outObj = obj; + return true; +} } // namespace NotificationSts } // OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_request.cpp b/frameworks/ets/ani/src/sts_request.cpp index 7c9cc45d9..ed25b307b 100644 --- a/frameworks/ets/ani/src/sts_request.cpp +++ b/frameworks/ets/ani/src/sts_request.cpp @@ -1203,5 +1203,87 @@ ani_object GetAniNotificationRequestArrayByNotifocations(ani_env *env, std::vect } return arrayObj; } + +bool GetCheckRequestContent(ani_env *env, ani_object obj, NotificationContent::Type &outContentType) +{ + ani_status status = ANI_OK; + ani_ref contentAniType; + STSContentType contentType = NOTIFICATION_CONTENT_BASIC_TEXT; + if (ANI_OK != (status = env->Object_GetPropertyByName_Ref(obj, "contentType", &contentAniType))) { + ANS_LOGE("GetCheckRequestContent get contentType faild. status %{public}d", status); + return false; + } + if (contentAniType == nullptr || + !EnumConvertAniToNative(env, static_cast(contentAniType), contentType)) { + ANS_LOGE("EnumConvertAniToNative contentType faild"); + return false; + } + if (!StsContentTypeUtils::StsToC(contentType, outContentType)) { + ANS_LOGE("StsToC contentType faild"); + return false; + } + return true; +} + +bool GetCheckRequestSlotType(ani_env *env, ani_object obj, NotificationConstant::SlotType &outSlotType) +{ + ani_status status = ANI_OK; + ani_ref slotAniType; + STSSlotType slotType = UNKNOWN_TYPE; + if (ANI_OK != (status = env->Object_GetPropertyByName_Ref(obj, "slotType", &slotAniType))) { + ANS_LOGE("UnWarpNotificationCheckRequest get slotType faild. status %{public}d", status); + return false; + } + if (slotAniType == nullptr || !EnumConvertAniToNative(env, static_cast(slotAniType), slotType)) { + ANS_LOGE("EnumConvertAniToNative slotType faild"); + return false; + } + if (!StsSlotTypeUtils::StsToC(slotType, outSlotType)) { + ANS_LOGE("StsToC slotType faild"); + return false; + } + return true; +} + +bool UnWarpNotificationCheckRequest(ani_env *env, ani_object obj, sptr &checkRequest) +{ + if (env == nullptr || obj == nullptr || checkRequest == nullptr) { + ANS_LOGE("UnWarpNotificationCheckRequest invalid parameters"); + return false; + } + ani_status status = ANI_OK; + ani_ref extraInfoKeysObj; + NotificationContent::Type outContentType = NotificationContent::Type::NONE; + NotificationConstant::SlotType outSlotType = NotificationConstant::SlotType::OTHER; + std::vector extraInfoKeys; + // contentType: notificationManager.ContentType; + if (!GetCheckRequestContent(env, obj, outContentType)) { + ANS_LOGE("GetCheckRequestContent faild."); + return false; + } + checkRequest->SetContentType(outContentType); + // slotType: notificationManager.SlotType; + if (!GetCheckRequestSlotType(env, obj, outSlotType)) { + ANS_LOGE("GetCheckRequestSlotType faild."); + return false; + } + checkRequest->SetSlotType(outSlotType); + // extraInfoKeys: Array; + if (ANI_OK != (status = env->Object_GetPropertyByName_Ref(obj, "extraInfoKeys", &extraInfoKeysObj))) { + ANS_LOGE("UnWarpNotificationCheckRequest get extraInfoKeys faild. status %{public}d", status); + return false; + } + if (!GetStringArrayByAniObj(env, static_cast(extraInfoKeysObj), extraInfoKeys)) { + ANS_LOGE("UnWarpNotificationCheckRequest. extraInfoKeys GetStringArrayByAniObj faild."); + return false; + } + checkRequest->SetExtraKeys(extraInfoKeys); + ANS_LOGD("contentType %{public}d slotType %{public}d", + checkRequest->GetContentType(), checkRequest->GetSlotType()); + for (auto &it : checkRequest->GetExtraKeys()) { + ANS_LOGD("extrakey %{public}s", it.c_str()); + } + return true; +} } // namespace NotificationSts } // OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_subscribe.cpp b/frameworks/ets/ani/src/sts_subscribe.cpp index 11f2dd82c..441e053c1 100644 --- a/frameworks/ets/ani/src/sts_subscribe.cpp +++ b/frameworks/ets/ani/src/sts_subscribe.cpp @@ -481,9 +481,9 @@ bool StsSubscriberInstance::CallFunction(ani_env *env, const char *func, std::ve ANS_LOGD("enter"); if (env == nullptr) return false; ani_ref fn_ref; - ani_status aniResult = env->Object_GetFieldByName_Ref(static_cast(ref_), func, &fn_ref); + ani_status aniResult = env->Object_GetPropertyByName_Ref(static_cast(ref_), func, &fn_ref); if (ANI_OK != aniResult) { - ANS_LOGD("Object_GetFieldByName_Ref '%{public}s' error. result: %{public}d.", func, aniResult); + ANS_LOGD("Object_GetPropertyByName_Ref '%{public}s' error. result: %{public}d.", func, aniResult); return false; } ani_boolean IsUndefined = ANI_FALSE; diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index 999fa9b11..7dcb4589e 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -16,7 +16,7 @@ import { BundleOption } from 'notification.NotificationCommonDef'; import { BusinessError, AsyncCallback } from '@ohos.base'; import { NotificationSlot } from 'notification.notificationSlot'; -import { NotificationRequest } from 'notification.notificationRequest'; +import { NotificationRequest, NotificationCheckRequest } from 'notification.notificationRequest'; import UIAbilityContext from 'application.UIAbilityContext'; import { NotificationBasicContent } from 'notification.notificationContent'; import { NotificationLongTextContent } from 'notification.notificationContent'; @@ -31,6 +31,8 @@ import image from '@ohos.multimedia.image'; type ResolveCallback = (data: T) => void; type RejectCallback = (err: Object) => void; +type CallbackForCheckInfo = + (checkInfo: notificationManager.NotificationCheckInfo)=> notificationManager.NotificationCheckResult; const ERROR_OK = 0; const ERROR_PARAM_INVALID = 401; @@ -159,6 +161,11 @@ export default namespace notificationManager { export native function nativeSetNotificationEnable(bundle: BundleOption, enable: boolean): void; export native function nativeRequestEnableNotification(content: UIAbilityContext): Promise; + export native function nativeOn( + type: 'checkNotification', callback: CallbackForCheckInfo, checkRequest?: NotificationCheckRequest): int; + export native function nativeOff( + type: 'checkNotification', callback?: CallbackForCheckInfo): int; + function isInvalidParameter(bundle: BundleOption): BusinessError { let error: BusinessError = { @@ -1302,4 +1309,91 @@ export default namespace notificationManager { } ) } + + export interface NotificationCheckResult { + code: number; + message: string; + } + + class NotificationCheckResultInner implements NotificationCheckResult { + public code: number = -1; + public message: string = ''; + } + + export function on( + type: 'checkNotification', callback: (checkInfo: NotificationCheckInfo) => NotificationCheckResult): void + { + let errCode = nativeOn(type, callback); + if (errCode != 0) { + const error: BusinessError = {code: errCode, message: "unknown error"}; + throw error; + } + } + + export function on(type: 'checkNotification', checkRequest: NotificationCheckRequest, + callback: (checkInfo: NotificationCheckInfo) => Promise): void + { + let onFuncCallback: CallbackForCheckInfo = + (checkInfo: notificationManager.NotificationCheckInfo): notificationManager.NotificationCheckResult => { + let result: notificationManager.NotificationCheckResult = { + code: -1, + message: 'unknown error' + }; + let p = callback(checkInfo); + await p.then( + (e: NullishType): void => { + result = e as notificationManager.NotificationCheckResult; + }, (error: Object): void => { + let err: BusinessError = error as BusinessError; + result = { + code: err.code, + message: err.message + }; + } + ); + return result; + }; + let errCode = nativeOn(type, onFuncCallback, checkRequest); + if (errCode != 0) { + const error: BusinessError = {code: errCode, message: "unknown error"}; + throw error; + } + } + + export function off( + type: 'checkNotification', + callback?: (checkInfo: NotificationCheckInfo) => NotificationCheckResult + ): void + { + let errCode = -1; + if (callback === undefined) { + errCode = nativeOff(type); + } else { + errCode = nativeOff(type, callback); + } + if (errCode != 0) { + const error: BusinessError = {code: errCode, message: "unknown error"}; + throw error; + } + } + + export interface NotificationCheckInfo { + bundleName: string; + notificationId: number; + label?: string; + contentType: ContentType; + creatorUserId: number; + slotType: SlotType; + extraInfos?: Record; + } + + class NotificationCheckInfoInner implements NotificationCheckInfo { + public bundleName: string = ''; + public notificationId: number = -1; + public label?: string; + public contentType: ContentType = ContentType.NOTIFICATION_CONTENT_BASIC_TEXT; + public creatorUserId: number = -1; + public slotType: SlotType = SlotType.UNKNOWN_TYPE; + public extraInfos?: Record; + } } \ No newline at end of file -- Gitee From 1ec7af07e02e2fb0bcbbe241b03d4500bcec917a Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Tue, 3 Jun 2025 15:46:04 +0800 Subject: [PATCH 02/14] =?UTF-8?q?ans=E6=A8=A1=E5=9D=97ani=E5=8C=96?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: YOUR_NAME Change-Id: Ifa9add16e9d952c4eaedaa23529554f2be90963d --- frameworks/ets/ani/include/manager/ani_slot.h | 9 + frameworks/ets/ani/include/sts_common.h | 2 + frameworks/ets/ani/include/sts_slot.h | 5 + .../ani/src/manager/ani_local_live_view.cpp | 2 +- .../ets/ani/src/manager/ani_manager.cpp | 18 + frameworks/ets/ani/src/manager/ani_slot.cpp | 210 ++++++++++- frameworks/ets/ani/src/sts_common.cpp | 38 ++ frameworks/ets/ani/src/sts_slot.cpp | 115 ++++++ .../ets/ani/src/subscribe/ani_remove.cpp | 2 +- .../ets/ets/@ohos.notificationManager.ets | 338 +++++++++++++++++- 10 files changed, 715 insertions(+), 24 deletions(-) diff --git a/frameworks/ets/ani/include/manager/ani_slot.h b/frameworks/ets/ani/include/manager/ani_slot.h index 044d5a877..eecf03272 100644 --- a/frameworks/ets/ani/include/manager/ani_slot.h +++ b/frameworks/ets/ani/include/manager/ani_slot.h @@ -27,6 +27,15 @@ ani_boolean AniIsNotificationSlotEnabled(ani_env *env, ani_object bundleOption, void AniSetNotificationEnableSlot(ani_env *env, ani_object bundleOption, ani_enum_item type, ani_boolean enable); void AniSetNotificationEnableSlotWithForce(ani_env *env, ani_object bundleOption, ani_enum_item type, ani_boolean enable, ani_boolean isForceControl); +void AniAddSlotByNotificationSlot(ani_env *env, ani_object notificationSlotObj); +void AniAddSlotBySlotType(ani_env *env, ani_enum_item enumObj); +void AniAddSlots(ani_env *env, ani_object notificationSlotArrayObj); +ani_object AniGetSlot(ani_env *env, ani_enum_item enumObj); +ani_object AniGetSlots(ani_env *env); +void AniRemoveSlot(ani_env *env, ani_enum_item enumObj); +void AniRemoveAllSlots(ani_env *env); +void AniSetSlotByBundle(ani_env *env, ani_object bundleOptionObj, ani_object slotObj); +ani_double AniGetSlotNumByBundle(ani_env *env, ani_object bundleOption); } // namespace NotificationManagerSts } // namespace OHOS #endif diff --git a/frameworks/ets/ani/include/sts_common.h b/frameworks/ets/ani/include/sts_common.h index 10a56d84a..8bfe1dac6 100644 --- a/frameworks/ets/ani/include/sts_common.h +++ b/frameworks/ets/ani/include/sts_common.h @@ -47,6 +47,8 @@ ani_status GetPropertyRef(ani_env *env, ani_object obj, const char *name, ani_boolean &isUndefined, ani_ref &outRef); ani_status GetPropertyStringArray(ani_env *env, ani_object param, const char *name, ani_boolean &isUndefined, std::vector &res); +ani_status GetPropertyNumberArray(ani_env *env, ani_object param, const char *name, + ani_boolean &isUndefined, std::vector &res); bool SetFieldString(ani_env *env, ani_class cls, ani_object &object, const std::string fieldName, const std::string value); diff --git a/frameworks/ets/ani/include/sts_slot.h b/frameworks/ets/ani/include/sts_slot.h index f9d311058..2c4da3de6 100644 --- a/frameworks/ets/ani/include/sts_slot.h +++ b/frameworks/ets/ani/include/sts_slot.h @@ -33,6 +33,11 @@ bool SetOptionalFieldSlotLevel(ani_env *env, const ani_class cls, ani_object &ob bool WrapNotificationSlot(ani_env *env, sptr slot, ani_object &outAniObj); bool WrapNotificationSlotArray(ani_env *env, const std::vector>& slots, ani_object &outAniObj); +bool ParseNotificationSlotByBasicType(ani_env *env, ani_object notificationSlotObj, + NotificationSlot &slot); +bool UnwrapNotificationSlot(ani_env *env, ani_object notificationSlotObj, NotificationSlot &slot); +bool UnwrapNotificationSlotArrayByAniObj(ani_env *env, ani_object notificationSlotArrayObj, + std::vector &slots); } // namespace NotificationSts } // OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_local_live_view.cpp b/frameworks/ets/ani/src/manager/ani_local_live_view.cpp index d2b76a4ed..d3c4203c8 100644 --- a/frameworks/ets/ani/src/manager/ani_local_live_view.cpp +++ b/frameworks/ets/ani/src/manager/ani_local_live_view.cpp @@ -36,7 +36,7 @@ void AniTriggerSystemLiveView( return; } NotificationSts::ButtonOption buttonOption; - if (!NotificationSts::UnWarpNotificationButtonOption(env, buttonOptionsObj, buttonOption)) { + if (NotificationSts::UnWarpNotificationButtonOption(env, buttonOptionsObj, buttonOption) != ANI_OK) { OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); ANS_LOGE("AniTriggerSystemLiveView buttonOption ERROR_INTERNAL_ERROR"); diff --git a/frameworks/ets/ani/src/manager/ani_manager.cpp b/frameworks/ets/ani/src/manager/ani_manager.cpp index ed6f74a8d..3d312623c 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -80,6 +80,24 @@ static std::array kitManagerFunctions = { ":I", reinterpret_cast(AniOn)}, ani_native_function {"nativeOff", "Lstd/core/String;Lstd/core/Function1;:I", reinterpret_cast(AniOff)}, + ani_native_function {"nativeAddSlotByNotificationSlot", nullptr, + reinterpret_cast(AniAddSlotByNotificationSlot)}, + ani_native_function {"nativeAddSlotBySlotType", nullptr, + reinterpret_cast(AniAddSlotBySlotType)}, + ani_native_function {"nativeAddSlots", nullptr, + reinterpret_cast(AniAddSlots)}, + ani_native_function {"nativeGetSlot", nullptr, + reinterpret_cast(AniGetSlot)}, + ani_native_function {"nativeGetSlots", nullptr, + reinterpret_cast(AniGetSlots)}, + ani_native_function {"nativeRemoveSlot", nullptr, + reinterpret_cast(AniRemoveSlot)}, + ani_native_function {"nativeRemoveAllSlots", nullptr, + reinterpret_cast(AniRemoveAllSlots)}, + ani_native_function {"nativeSetSlotByBundle", nullptr, + reinterpret_cast(AniSetSlotByBundle)}, + ani_native_function {"nativeGetSlotNumByBundle", nullptr, + reinterpret_cast(AniGetSlotNumByBundle)}, }; void AniNotificationManagerRegistryInit(ani_env *env) diff --git a/frameworks/ets/ani/src/manager/ani_slot.cpp b/frameworks/ets/ani/src/manager/ani_slot.cpp index 86224ee2b..622984eea 100644 --- a/frameworks/ets/ani/src/manager/ani_slot.cpp +++ b/frameworks/ets/ani/src/manager/ani_slot.cpp @@ -27,11 +27,14 @@ namespace OHOS { namespace NotificationManagerSts { +namespace { +constexpr int32_t RETURN_EXCEPTION_VALUE = -1; +} // namespace ani_object AniGetSlotsByBundle(ani_env *env, ani_object bundleOption) { ANS_LOGD("sts GetSlotsByBundle enter"); - int returncode = 0; + int returncode = CJSystemapi::Notification::SUCCESS_CODE; std::vector> slots; BundleOption option; if (NotificationSts::UnwrapBundleOption(env, bundleOption, option)) { @@ -42,7 +45,7 @@ ani_object AniGetSlotsByBundle(ani_env *env, ani_object bundleOption) } int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { ANS_LOGE("sts GetSlotsByBundle error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return nullptr; @@ -56,6 +59,199 @@ ani_object AniGetSlotsByBundle(ani_env *env, ani_object bundleOption) return outAniObj; } +void AniAddSlots(ani_env *env, ani_object notificationSlotArrayObj) +{ + ANS_LOGD("AniAddSlots enter"); + std::vector slots; + if (!NotificationSts::UnwrapNotificationSlotArrayByAniObj(env, notificationSlotArrayObj, slots)) { + ANS_LOGE("UnwrapNotificationSlotArrayByAniObj failed"); + NotificationSts::ThrowStsErroWithMsg(env, "sts AddSlots ERROR_INTERNAL_ERROR"); + return; + } + int returncode = Notification::NotificationHelper::AddNotificationSlots(slots); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("AniAddSlots -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniAddSlots leave"); +} + +void AniAddSlotByNotificationSlot(ani_env *env, ani_object notificationSlotObj) +{ + ANS_LOGD("AniAddSlotByNotificationSlot enter"); + int returncode = CJSystemapi::Notification::SUCCESS_CODE; + Notification::NotificationSlot slot; + if (NotificationSts::UnwrapNotificationSlot(env, notificationSlotObj, slot)) { + returncode = Notification::NotificationHelper::AddNotificationSlot(slot); + } else { + NotificationSts::ThrowStsErroWithMsg(env, "sts AddSlot ERROR_INTERNAL_ERROR"); + return; + } + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("sts AddSlot error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniAddSlotByNotificationSlot leave"); +} + +void AniAddSlotBySlotType(ani_env *env, ani_enum_item enumObj) +{ + ANS_LOGD("AniAddSlotBySlotType enter"); + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (!NotificationSts::SlotTypeEtsToC(env, enumObj, slotType)) { + NotificationSts::ThrowStsErroWithMsg(env, "AddSlotByType ERROR_INTERNAL_ERROR"); + return; + } + int returncode = Notification::NotificationHelper::AddSlotByType(slotType); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("AniAddSlotBySlotType -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniAddSlotBySlotType leave"); + return; +} + +ani_object AniGetSlot(ani_env *env, ani_enum_item enumObj) +{ + ANS_LOGD("AniGetSlot enter"); + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (!NotificationSts::SlotTypeEtsToC(env, enumObj, slotType)) { + ANS_LOGE("SlotTypeEtsToC failed"); + NotificationSts::ThrowStsErroWithMsg(env, "sts GetSlot ERROR_INTERNAL_ERROR"); + return nullptr; + } + sptr slot = nullptr; + int returncode = Notification::NotificationHelper::GetNotificationSlot(slotType, slot); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("AniGetSlot -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ani_object slotObj; + if (!NotificationSts::WrapNotificationSlot(env, slot, slotObj)) { + ANS_LOGE("WrapNotificationSlot faild"); + NotificationSts::ThrowStsErroWithMsg(env, "sts GetSlot ERROR_INTERNAL_ERROR"); + return nullptr; + } + ANS_LOGD("AniGetSlot leave"); + return slotObj; +} + +ani_object AniGetSlots(ani_env *env) +{ + ANS_LOGD("AniGetSlots enter"); + std::vector> slots; + int returncode = Notification::NotificationHelper::GetNotificationSlots(slots); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("AniGetSlots -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return nullptr; + } + ani_object outAniObj; + if (!NotificationSts::WrapNotificationSlotArray(env, slots, outAniObj)) { + ANS_LOGE("WrapNotificationSlotArray faild"); + NotificationSts::ThrowStsErroWithMsg(env, "AniGetSlots:failed to WrapNotificationSlotArray"); + return nullptr; + } + ANS_LOGD("AniGetSlots leave"); + return outAniObj; +} + +void AniRemoveSlot(ani_env *env, ani_enum_item enumObj) +{ + ANS_LOGD("AniRemoveSlot enter"); + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (!NotificationSts::SlotTypeEtsToC(env, enumObj, slotType)) { + ANS_LOGE("SlotTypeEtsToC failed"); + NotificationSts::ThrowStsErroWithMsg(env, "sts GetSlot ERROR_INTERNAL_ERROR"); + return; + } + int returncode = Notification::NotificationHelper::RemoveNotificationSlot(slotType); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("AniRemoveSlot -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniRemoveSlot leave"); +} + +void AniRemoveAllSlots(ani_env *env) +{ + ANS_LOGD("AniRemoveAllSlots enter"); + int returncode = Notification::NotificationHelper::RemoveAllSlots(); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("AniRemoveAllSlots -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniRemoveAllSlots leave"); +} + +void AniSetSlotByBundle(ani_env *env, ani_object bundleOptionObj, ani_object slotObj) +{ + ANS_LOGD("AniSetSlotByBundle enter"); + Notification::NotificationBundleOption option; + if (!NotificationSts::UnwrapBundleOption(env, bundleOptionObj, option)) { + ANS_LOGE("UnwrapBundleOption failed"); + NotificationSts::ThrowStsErroWithMsg(env, "AniSetNotificationEnableSlot ERROR_INTERNAL_ERROR"); + return; + } + + Notification::NotificationSlot slot; + if (!NotificationSts::UnwrapNotificationSlot(env, slotObj, slot)) { + ANS_LOGE("UnwrapNotificationSlot failed"); + NotificationSts::ThrowStsErroWithMsg(env, "sts SetSlotByBundle ERROR_INTERNAL_ERROR"); + return; + } + + std::vector> slotsVct; + sptr slotPtr = new (std::nothrow) Notification::NotificationSlot(slot); + if (slotPtr == nullptr) { + ANS_LOGE("Failed to create NotificationSlot ptr"); + NotificationSts::ThrowStsErroWithMsg(env, "sts AniSetSlotByBundle ERROR_INTERNAL_ERROR"); + return; + } + slotsVct.emplace_back(slotPtr); + + int returncode = Notification::NotificationHelper::UpdateNotificationSlots(option, slotsVct); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("sts SetSlotByBundle error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniSetSlotByBundle leave"); +} + +ani_double AniGetSlotNumByBundle(ani_env *env, ani_object bundleOption) +{ + ANS_LOGD("AniGetSlotNumByBundle enter"); + Notification::NotificationBundleOption option; + if (!NotificationSts::UnwrapBundleOption(env, bundleOption, option)) { + ANS_LOGE("UnwrapBundleOption failed"); + NotificationSts::ThrowStsErroWithMsg(env, "AniGetSlotNumByBundle ERROR_INTERNAL_ERROR"); + return RETURN_EXCEPTION_VALUE; + } + uint64_t num = 0; + int returncode = Notification::NotificationHelper::GetNotificationSlotNumAsBundle(option, num); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("sts GetSlotNumByBundle error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return RETURN_EXCEPTION_VALUE; + } + ani_double retNum = static_cast(num); + ANS_LOGD("AniGetSlotNumByBundle leave"); + return retNum; +} void AniSetNotificationEnableSlot(ani_env *env, ani_object bundleOption, ani_enum_item type, ani_boolean enable) { ANS_LOGD("AniSetNotificationEnableSlot enter "); @@ -75,7 +271,7 @@ void AniSetNotificationEnableSlot(ani_env *env, ani_object bundleOption, ani_enu NotificationSts::AniBooleanToBool(enable), isForceControl); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { ANS_LOGE("AniSetNotificationEnableSlot error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; @@ -100,7 +296,7 @@ void AniSetNotificationEnableSlotWithForce(ani_env *env, NotificationSts::AniBooleanToBool(enable), NotificationSts::AniBooleanToBool(isForceControl)); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { ANS_LOGE("AniSetNotificationEnableSlotSync error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -120,7 +316,7 @@ ani_boolean AniIsNotificationSlotEnabled(ani_env *env, ani_object bundleOption, bool isEnable = false; int returncode = Notification::NotificationHelper::GetEnabledForBundleSlot(option, slotType, isEnable); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { ANS_LOGE("IsNotificationSlotEnabled -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -138,7 +334,7 @@ ani_int AniGetSlotFlagsByBundle(ani_env *env, ani_object obj) uint32_t slotFlags = 0; int returncode = Notification::NotificationHelper::GetNotificationSlotFlagsAsBundle(option, slotFlags); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { ANS_LOGE("AniGetSlotFlagsByBundle -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -156,7 +352,7 @@ void AniSetSlotFlagsByBundle(ani_env *env, ani_object obj, ani_double slotFlags) int returncode = Notification::NotificationHelper::SetNotificationSlotFlagsAsBundle(option, static_cast(slotFlags)); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { ANS_LOGE("AniSetSlotFlagsByBundle -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } diff --git a/frameworks/ets/ani/src/sts_common.cpp b/frameworks/ets/ani/src/sts_common.cpp index f8f25b2f7..253a124d3 100644 --- a/frameworks/ets/ani/src/sts_common.cpp +++ b/frameworks/ets/ani/src/sts_common.cpp @@ -255,6 +255,44 @@ ani_status GetPropertyStringArray(ani_env *env, ani_object param, const char *na return status; } +ani_status GetPropertyNumberArray(ani_env *env, ani_object param, const char *name, + ani_boolean &isUndefined, std::vector &res) +{ + ANS_LOGD("GetPropertyNumberArray enter"); + ani_ref arrayObj = nullptr; + ani_status status; + ani_double length; + if ((status = GetPropertyRef(env, param, name, isUndefined, arrayObj)) != ANI_OK || isUndefined == ANI_TRUE) { + return ANI_INVALID_ARGS; + } + + status = env->Object_GetPropertyByName_Double(static_cast(arrayObj), "length", &length); + if (status != ANI_OK) { + ANS_LOGI("status : %{public}d", status); + return status; + } + + for (int i = 0; i < static_cast(length); i++) { + ani_ref numEntryRef; + status = env->Object_CallMethodByName_Ref(static_cast(arrayObj), + "$_get", "I:Lstd/core/Object;", &numEntryRef, (ani_int)i); + if (status != ANI_OK) { + ANS_LOGI("status : %{public}d, index: %{public}d", status, i); + return status; + } + ani_double doubleValue = 0.0; + status = env->Object_CallMethodByName_Double(static_cast(numEntryRef), "unboxed", + ":D", &doubleValue); + if (status != ANI_OK) { + ANS_LOGI("Object_CallMethodByName_Double uid fail, status: %{public}d", status); + return status; + } + res.push_back(static_cast(doubleValue)); + } + ANS_LOGD("GetPropertyNumberArray leave"); + return status; +} + ani_object GetAniStringArrayByVectorString(ani_env *env, std::vector &strs) { if (env == nullptr || strs.empty()) { diff --git a/frameworks/ets/ani/src/sts_slot.cpp b/frameworks/ets/ani/src/sts_slot.cpp index 69bd7e210..7202f92ab 100644 --- a/frameworks/ets/ani/src/sts_slot.cpp +++ b/frameworks/ets/ani/src/sts_slot.cpp @@ -224,5 +224,120 @@ bool WrapNotificationSlotArray(ani_env *env, const std::vector(doubleValue))); + } + if (GetPropertyDouble(env, notificationSlotObj, "lightColor", isUndefined, doubleValue) == ANI_OK + && isUndefined == ANI_FALSE) { + slot.SetLedLightColor(static_cast(doubleValue)); + } + bool boolValue = true; + if (GetPropertyBool(env, notificationSlotObj, "badgeFlag", isUndefined, boolValue) == ANI_OK + && isUndefined == ANI_FALSE) { + slot.EnableBadge(boolValue); + } + if (GetPropertyBool(env, notificationSlotObj, "bypassDnd", isUndefined, boolValue) == ANI_OK + && isUndefined == ANI_FALSE) { + slot.EnableBypassDnd(boolValue); + } + if (GetPropertyBool(env, notificationSlotObj, "lightEnabled", isUndefined, boolValue) == ANI_OK + && isUndefined == ANI_FALSE) { + slot.SetEnableLight(boolValue); + } + if (GetPropertyBool(env, notificationSlotObj, "vibrationEnabled", isUndefined, boolValue) == ANI_OK + && isUndefined == ANI_FALSE) { + slot.SetEnableVibration(boolValue); + } + return true; +} + +bool UnwrapNotificationSlot(ani_env *env, ani_object notificationSlotObj, NotificationSlot &slot) +{ + ANS_LOGD("UnwrapNotificationSlot enter"); + if (notificationSlotObj == nullptr) { + ANS_LOGE("notificationSlotObj is null"); + return false; + } + ani_status status = ANI_ERROR; + ani_boolean isUndefined = ANI_TRUE; + ani_ref notificationTypeRef = {}; + status = GetPropertyRef(env, notificationSlotObj, "notificationType", isUndefined, notificationTypeRef); + if (status == ANI_OK && isUndefined == ANI_FALSE) { + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (SlotTypeEtsToC(env, static_cast(notificationTypeRef), slotType)) { + slot.SetType(slotType); + } + } + status = GetPropertyRef(env, notificationSlotObj, "notificationLevel", isUndefined, notificationTypeRef); + if (status == ANI_OK && isUndefined == ANI_FALSE) { + NotificationSlot::NotificationLevel outLevel {NotificationSlot::NotificationLevel::LEVEL_NONE}; + if (SlotLevelEtsToC(env, static_cast(notificationTypeRef), outLevel)) { + slot.SetLevel(outLevel); + } + } + if (!ParseNotificationSlotByBasicType(env, notificationSlotObj, slot)) { + ANS_LOGE("ParseNotificationSlotByBasicType failed"); + return false; + } + std::vector vibrationValues; + if (GetPropertyNumberArray(env, notificationSlotObj, "vibrationValues", isUndefined, vibrationValues) == ANI_OK && + isUndefined == ANI_FALSE) { + slot.SetVibrationStyle(vibrationValues); + } + ANS_LOGD("UnwrapNotificationSlot leave"); + return true; +} + +bool UnwrapNotificationSlotArrayByAniObj(ani_env *env, ani_object notificationSlotArrayObj, + std::vector &slots) +{ + ANS_LOGD("UnwrapNotificationSlotArrayByAniObj enter"); + if (notificationSlotArrayObj == nullptr) { + ANS_LOGE("notificationSlotArrayObj is null"); + return false; + } + ani_double length; + ani_status status = env->Object_GetPropertyByName_Double(notificationSlotArrayObj, "length", &length); + if (status != ANI_OK) { + ANS_LOGE("Object_GetPropertyByName_Double faild. status : %{public}d", status); + return false; + } + for (int i = 0; i < int(length); i++) { + ani_ref notificationSlotEntryRef; + status = env->Object_CallMethodByName_Ref(notificationSlotArrayObj, + "$_get", "I:Lstd/core/Object;", ¬ificationSlotEntryRef, (ani_int)i); + if (status != ANI_OK) { + ANS_LOGE("Object_CallMethodByName_Ref faild. status : %{public}d", status); + } + NotificationSlot slot; + if (!UnwrapNotificationSlot(env, static_cast(notificationSlotEntryRef), slot)) { + ANS_LOGE("UnwrapNotificationSlot faild"); + return false; + } + slots.emplace_back(slot); + } + ANS_LOGD("UnwrapNotificationSlotArrayByAniObj leave"); + return true; +} } // namespace NotificationSts } // OHOS diff --git a/frameworks/ets/ani/src/subscribe/ani_remove.cpp b/frameworks/ets/ani/src/subscribe/ani_remove.cpp index 7f04ae109..be660d9fb 100644 --- a/frameworks/ets/ani/src/subscribe/ani_remove.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_remove.cpp @@ -104,7 +104,7 @@ void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reason ANS_LOGD("StsRemoveForHashCodes enter"); std::vector hashCodesStd; int32_t reasonType; - if (ANI_OK != NotificationSts::GetStringArrayByAniObj(env, hashCodes, hashCodesStd)) { + if (!NotificationSts::GetStringArrayByAniObj(env, hashCodes, hashCodesStd)) { ANS_LOGE("hashCodes is valid"); std::string msg = "hashCodes is valid"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index 7dcb4589e..88c88458f 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -160,6 +160,45 @@ 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 nativeAddSlotByNotificationSlot(slot: NotificationSlot): void; + export native function nativeAddSlotBySlotType(type: SlotType): void; + export native function nativeAddSlots(slots: Array): void; + export native function nativeGetSlot(slotType: SlotType): NotificationSlot; + export native function nativeGetSlots(): Array; + export native function nativeRemoveSlot(slotType: SlotType): void; + export native function nativeRemoveAllSlots(): void; + export native function nativeSetSlotByBundle(bundle: BundleOption, slot: NotificationSlot): void; + export native function nativeGetSlotNumByBundle(bundle: BundleOption): number; + + function isInvalidParameter(slot: NotificationSlot): BusinessError + { + if (slot == null) { + return errorParamInvalid; + } + if (slot.lockscreenVisibility !== undefined && typeof slot.lockscreenVisibility === 'number') { + const num = slot.lockscreenVisibility ?? -1; + if (num < 0) { + return errorParamInvalid; + } + } + if (slot.lightColor !== undefined && typeof slot.lightColor === 'number') { + const num = slot.lightColor ?? -1; + if (num < 0) { + return errorParamInvalid; + } + } + if (slot.desc !== undefined && slot.desc?.trim() === '') { + return errorParamInvalid; + } + if (slot.sound !== undefined && slot.sound?.trim() === '') { + return errorParamInvalid; + } + if (slot.vibrationValues !== undefined && slot.vibrationValues?.length === 0) { + return errorParamInvalid; + } + return successCallbackError; + } export native function nativeOn( type: 'checkNotification', callback: CallbackForCheckInfo, checkRequest?: NotificationCheckRequest): int; @@ -505,6 +544,287 @@ export default namespace notificationManager { } return error; } + + export function getSlotNumByBundle(bundle: BundleOption): 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((): number => { return nativeGetSlotNumByBundle(bundle); }); + p.then((data: NullishType): void => { + let ret : number = data as number; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback): void { + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== 0) { + throw error; + } + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): number => { return nativeGetSlotNumByBundle(bundle); }); + p.then((data: NullishType): void => { + let ret : number = data as number; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let ret: number = -1; + let err: BusinessError = error as BusinessError; + callback(err, ret); + }); + } + + export function setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback): void { + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== 0) { + throw error; + } + let slotError: BusinessError = isInvalidParameter(slot); + if (slotError.code !== 0) { + throw slotError; + } + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeSetSlotByBundle(bundle, slot); }); + 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 function setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise { + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== 0) { + throw error; + } + let slotError: BusinessError = isInvalidParameter(slot); + if (slotError.code !== 0) { + throw slotError; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeSetSlotByBundle(bundle, slot); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function removeAllSlots(callback: AsyncCallback): void { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeRemoveAllSlots(); }); + 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 function removeAllSlots(): Promise { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeRemoveAllSlots(); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function removeSlot(slotType: SlotType, callback: AsyncCallback): void { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeRemoveSlot(slotType); }); + 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 function removeSlot(slotType: SlotType): Promise { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeRemoveSlot(slotType); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getSlots(): Promise> { + let pPromise = new Promise>((resolve: ResolveCallback>, reject: RejectCallback): void => { + let p = taskpool.execute((): Array => { return nativeGetSlots(); }); + p.then((data: NullishType): void => { + let ret : Array = data as Array; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getSlots(callback: AsyncCallback>): void { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): Array => { return nativeGetSlots(); }); + p.then((data: NullishType): void => { + let ret : Array = data as Array; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let ret : Array = []; + let err: BusinessError = error as BusinessError; + callback(err, ret); + }); + } + + export function getSlot(slotType: SlotType): Promise { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): NotificationSlot => { return nativeGetSlot(slotType); }); + p.then((data: NullishType): void => { + let ret : NotificationSlot = data as NotificationSlot; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getSlot(slotType: SlotType, callback: AsyncCallback): void { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): NotificationSlot => { return nativeGetSlot(slotType); }); + p.then((data: NullishType): void => { + let ret : NotificationSlot = data as NotificationSlot; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let ret : NotificationSlot = { enabled: false, reminderMode: 0, authorizedStatus: 0 } as NotificationSlot; + let err: BusinessError = error as BusinessError; + callback(err, ret); + }); + } + + export function addSlots(slots: Array): Promise { + if (!slots || slots.length === 0) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeAddSlots(slots); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function addSlots(slots: Array, callback: AsyncCallback): void { + if (!slots || slots.length === 0) { + throw errorParamInvalid; + } + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeAddSlots(slots); }); + 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 function addSlot(slot: NotificationSlot): Promise { + let slotError: BusinessError = isInvalidParameter(slot); + if (slotError.code !== 0) { + throw slotError; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeAddSlotByNotificationSlot(slot); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function addSlot(slot: NotificationSlot, callback: AsyncCallback): void { + let slotError: BusinessError = isInvalidParameter(slot); + if (slotError.code !== 0) { + throw slotError; + } + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeAddSlotByNotificationSlot(slot); }); + 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 function addSlot(type: SlotType, callback: AsyncCallback): void { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeAddSlotBySlotType(type); }); + 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 function addSlot(type: SlotType): Promise { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeAddSlotBySlotType(type); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } export function setNotificationEnable(bundle: BundleOption, enable: boolean): Promise { @@ -590,11 +910,7 @@ export default namespace notificationManager { export function isNotificationEnabled(userId: number, callback: AsyncCallback): void { if (callback == null) { - let error: BusinessError = { - code: 410, - message : "callback must be not null" - } - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): boolean => { return nativeIsNotificationEnabledWithId(userId); }); p.then((data: NullishType): void => { @@ -625,11 +941,7 @@ export default namespace notificationManager { export function isNotificationEnabled(callback: AsyncCallback): void { if (callback == null) { - let error: BusinessError = { - code: 410, - message : "callback must be not null" - } - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): boolean => { return nativeIsNotificationEnabled(); }); p.then((data: NullishType): void => { @@ -1192,11 +1504,7 @@ export default namespace notificationManager { throw error; } if (callback == null) { - let error: BusinessError = { - code: 410, - message : "callback must be not null" - } - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): void => { return nativeCancelWithIdLabel(id, label); }); p.then((data: NullishType): void => { -- Gitee From 71716191cccf2019e53084f0fc197678f4b2f2e9 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Wed, 4 Jun 2025 16:12:46 +0800 Subject: [PATCH 03/14] =?UTF-8?q?ans=E6=A8=A1=E5=9D=97ani=E5=8C=96?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: YOUR_NAME Change-Id: I2265ab1e658aa5d56d2f91c303238af3d5167251 --- frameworks/ets/ani/BUILD.gn | 2 + .../include/manager/ani_distributed_enable.h | 28 ++ .../include/manager/ani_notification_enable.h | 2 + .../include/manager/ani_support_template.h | 27 ++ .../ani/include/sts_notification_manager.h | 16 ++ .../src/manager/ani_distributed_enable.cpp | 100 +++++++ .../ets/ani/src/manager/ani_manager.cpp | 14 + .../src/manager/ani_notification_enable.cpp | 30 ++ .../ani/src/manager/ani_support_template.cpp | 72 +++++ .../ets/ani/src/sts_notification_manager.cpp | 64 +++++ .../ets/ets/@ohos.notificationManager.ets | 257 ++++++++++++++++++ 11 files changed, 612 insertions(+) create mode 100755 frameworks/ets/ani/include/manager/ani_distributed_enable.h create mode 100755 frameworks/ets/ani/include/manager/ani_support_template.h create mode 100755 frameworks/ets/ani/src/manager/ani_distributed_enable.cpp create mode 100755 frameworks/ets/ani/src/manager/ani_support_template.cpp diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index 34ea02605..627f97101 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -58,6 +58,8 @@ ohos_shared_library("notification_manager_ani") { "./src/manager/ani_ans_dialog_callback.cpp", "./src/manager/ani_on.cpp", "./src/manager/ani_push_callback.cpp", + "./src/manager/ani_support_template.cpp", + "./src/manager/ani_distributed_enable.cpp", ] cflags = [] diff --git a/frameworks/ets/ani/include/manager/ani_distributed_enable.h b/frameworks/ets/ani/include/manager/ani_distributed_enable.h new file mode 100755 index 000000000..4a712316f --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_distributed_enable.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_DISTRIBUTED_ENBLE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DISTRIBUTED_ENBLE_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +void AniSetDistributedEnable(ani_env* env, ani_boolean enabled); +ani_boolean AniIsDistributedEnabled(ani_env* env); +ani_boolean AniIsDistributedEnabledByBundle(ani_env* env, ani_object obj); +ani_boolean AniIsDistributedEnabledByBundleType(ani_env* env, ani_object obj, ani_string deviceType); + +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_notification_enable.h b/frameworks/ets/ani/include/manager/ani_notification_enable.h index 3fdb7013d..93dee4348 100644 --- a/frameworks/ets/ani/include/manager/ani_notification_enable.h +++ b/frameworks/ets/ani/include/manager/ani_notification_enable.h @@ -23,6 +23,8 @@ ani_boolean AniIsNotificationEnabled(ani_env *env); ani_boolean AniIsNotificationEnabledWithId(ani_env *env, ani_double userId); ani_boolean AniIsNotificationEnabledWithBundleOption(ani_env *env, ani_object bundleOption); void AniSetNotificationEnable(ani_env *env, ani_object bundleOption, ani_boolean enable); +void AniSetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId, ani_boolean enabled); +ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId); } // namespace NotificationManagerSts } // namespace OHOS #endif diff --git a/frameworks/ets/ani/include/manager/ani_support_template.h b/frameworks/ets/ani/include/manager/ani_support_template.h new file mode 100755 index 000000000..5be565d99 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_support_template.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_SUPPORT_TEMPLATE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SUPPORT_TEMPLATE_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +ani_boolean AniIsSupportTemplate(ani_env* env, ani_string templateName); +ani_object AniGetDeviceRemindType(ani_env *env); + +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/sts_notification_manager.h b/frameworks/ets/ani/include/sts_notification_manager.h index f40c52115..bf9cba112 100644 --- a/frameworks/ets/ani/include/sts_notification_manager.h +++ b/frameworks/ets/ani/include/sts_notification_manager.h @@ -32,6 +32,7 @@ using SlotLevel = OHOS::Notification::NotificationSlot::NotificationLevel; using ContentType = OHOS::Notification::NotificationContent::Type; using ButtonOption = OHOS::Notification::NotificationButtonOption; using NotificationDoNotDisturbDate = OHOS::Notification::NotificationDoNotDisturbDate; +using RemindType = OHOS::Notification::NotificationConstant::RemindType; enum STSSlotType { UNKNOWN_TYPE = 0, SOCIAL_COMMUNICATION = 1, @@ -61,6 +62,13 @@ enum STSContentType { NOTIFICATION_CONTENT_LIVE_VIEW, }; +enum class STSRemindType { + IDLE_DONOT_REMIND, + IDLE_REMIND, + ACTIVE_DONOT_REMIND, + ACTIVE_REMIND +}; + class StsSlotTypeUtils { public: static bool StsToC(const STSSlotType inType, SlotType &outType); @@ -79,6 +87,12 @@ static bool StsToC(const STSContentType inType, ContentType &outType); static bool CToSts(const ContentType inType, STSContentType &outType); }; +class StsRemindTypeUtils { +public: +static bool StsToC(const STSRemindType inType, RemindType &outType); +static bool CToSts(const RemindType inType, STSRemindType &outType); +}; + class StsNotificationLocalLiveViewSubscriber : public NotificationLocalLiveViewSubscriber { public: StsNotificationLocalLiveViewSubscriber(); @@ -133,6 +147,8 @@ bool SlotLevelCToEts(ani_env *env, SlotLevel slotLevel, ani_enum_item &enumItem) bool ContentTypeEtsToC(ani_env *env, ani_enum_item enumItem, ContentType &contentType); bool ContentTypeCToEts(ani_env *env, ContentType contentType, ani_enum_item &enumItem); +bool DeviceRemindTypeCToEts(ani_env *env, RemindType remindType, ani_enum_item &enumItem); +bool DeviceRemindTypeEtsToC(ani_env *env, ani_enum_item enumItem, RemindType &remindType); ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonOptionObj, ButtonOption &buttonOption); diff --git a/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp new file mode 100755 index 000000000..fa63aae21 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp @@ -0,0 +1,100 @@ +/* + * 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_distributed_enable.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 AniSetDistributedEnable(ani_env* env, ani_boolean enabled) +{ + ANS_LOGD("AniSetDistributedEnable call,enable : %{public}d", enabled); + int returncode = Notification::NotificationHelper::EnableDistributed(NotificationSts::AniBooleanToBool(enabled)); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("AniSetDistributedEnable -> error, errorCode: %{public}d", externalCode); + return; + } + ANS_LOGD("AniSetDistributedEnable end"); +} + +ani_boolean AniIsDistributedEnabled(ani_env* env) +{ + ANS_LOGD("AniIsDistributedEnabled call"); + bool enabled = false; + int returncode = Notification::NotificationHelper::IsDistributedEnabled(enabled); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("AniIsDistributedEnabled -> error, errorCode: %{public}d", externalCode); + return NotificationSts::BoolToAniBoolean(false); + } + ANS_LOGD("AniIsDistributedEnabled end, enabled: %{public}d, returncode: %{public}d", enabled, externalCode); + return NotificationSts::BoolToAniBoolean(enabled); +} + +ani_boolean AniIsDistributedEnabledByBundle(ani_env* env, ani_object obj) +{ + ANS_LOGD("AniIsDistributedEnabledByBundle call"); + Notification::NotificationBundleOption option; + if (!NotificationSts::UnwrapBundleOption(env, obj, option)) { + NotificationSts::ThrowStsErroWithMsg(env, "AniIsDistributedEnabledByBundle : erro arguments."); + return NotificationSts::BoolToAniBoolean(false); + } + bool enabled = false; + int returncode = Notification::NotificationHelper::IsDistributedEnableByBundle(option, enabled); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("AniIsDistributedEnabledByBundle -> error, errorCode: %{public}d", externalCode); + } + ANS_LOGD("AniIsDistributedEnabledByBundle end, enabled: %{public}d, returncode: %{public}d", enabled, externalCode); + return NotificationSts::BoolToAniBoolean(enabled); +} + +ani_boolean AniIsDistributedEnabledByBundleType(ani_env* env, ani_object obj, ani_string deviceType) +{ + ANS_LOGD("AniIsDistributedEnabledByBundleType call"); + Notification::NotificationBundleOption option; + if (!NotificationSts::UnwrapBundleOption(env, obj, option)) { + NotificationSts::ThrowStsErroWithMsg(env, "AniIsDistributedEnabledByBundleType : erro arguments."); + return NotificationSts::BoolToAniBoolean(false); + } + std::string deviceTypeStr; + if (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + NotificationSts::ThrowStsErroWithMsg(env, "deviceType parse failed!"); + return NotificationSts::BoolToAniBoolean(false); + } + ANS_LOGD("Cancel by deviceType:%{public}s", deviceTypeStr.c_str()); + + bool enabled = false; + int returncode = Notification::NotificationHelper::IsDistributedEnabledByBundle(option, deviceTypeStr, enabled); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("AniIsDistributedEnabledByBundle -> error, errorCode: %{public}d", externalCode); + } + ANS_LOGD("AniIsDistributedEnabledByBundle end, enabled: %{public}d, returncode: %{public}d", enabled, externalCode); + return NotificationSts::BoolToAniBoolean(enabled); +} +} +} \ 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 3d312623c..d5679284e 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -25,6 +25,8 @@ #include "ani_local_live_view.h" #include "ani_request_enable.h" #include "ani_on.h" +#include "ani_support_template.h" +#include "ani_distributed_enable.h" namespace OHOS { namespace NotificationManagerSts { @@ -98,6 +100,18 @@ static std::array kitManagerFunctions = { reinterpret_cast(AniSetSlotByBundle)}, ani_native_function {"nativeGetSlotNumByBundle", nullptr, reinterpret_cast(AniGetSlotNumByBundle)}, + ani_native_function {"nativeIsSupportTemplate", nullptr, reinterpret_cast(AniIsSupportTemplate)}, + ani_native_function {"nativeSetDistributedEnable", nullptr, reinterpret_cast(AniSetDistributedEnable)}, + ani_native_function {"nativeIsDistributedEnabled", nullptr, reinterpret_cast(AniIsDistributedEnabled)}, + ani_native_function {"nativeIsDistributedEnabledByBundle", nullptr, + reinterpret_cast(AniIsDistributedEnabledByBundle)}, + ani_native_function {"nativeIsDistributedEnabledByBundleType", nullptr, + reinterpret_cast(AniIsDistributedEnabledByBundleType)}, + ani_native_function {"nativeGetDeviceRemindType", nullptr, reinterpret_cast(AniGetDeviceRemindType)}, + ani_native_function {"nativeGetSyncNotificationEnabledWithoutApp", nullptr, + reinterpret_cast(AniGetSyncNotificationEnabledWithoutApp)}, + ani_native_function {"nativeSetSyncNotificationEnabledWithoutApp", nullptr, + reinterpret_cast(AniSetSyncNotificationEnabledWithoutApp)}, }; void AniNotificationManagerRegistryInit(ani_env *env) diff --git a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp index 9c987eedc..daaa2baef 100644 --- a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp @@ -92,5 +92,35 @@ void AniSetNotificationEnable(ani_env *env, ani_object bundleOption, ani_boolean } ANS_LOGD("AniSetNotificationEnable end"); } + +ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId) +{ + ANS_LOGD("AniGetSyncNotificationEnabledWithoutApp call"); + bool enabled = false; + int returncode = Notification::NotificationHelper::GetSyncNotificationEnabledWithoutApp( + static_cast(userId), enabled); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("AniGetSyncNotificationEnabledWithoutApp -> error, errorCode: %{public}d", externalCode); + return NotificationSts::BoolToAniBoolean(false); + } + ANS_LOGD("End success, enabled: %{public}d,returncode: %{public}d", enabled, externalCode); + return NotificationSts::BoolToAniBoolean(enabled); +} + +void AniSetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId, ani_boolean enabled) +{ + ANS_LOGD("AniSetSyncNotificationEnabledWithoutApp call,enable : %{public}d", enabled); + int returncode = Notification::NotificationHelper::SetSyncNotificationEnabledWithoutApp( + static_cast(userId), NotificationSts::AniBooleanToBool(enabled)); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("AniSetSyncNotificationEnabledWithoutApp -> error, errorCode: %{public}d", externalCode); + return; + } + ANS_LOGD("AniSetSyncNotificationEnabledWithoutApp end"); +} } // namespace NotificationManagerSts } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_support_template.cpp b/frameworks/ets/ani/src/manager/ani_support_template.cpp new file mode 100755 index 000000000..461787a31 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_support_template.cpp @@ -0,0 +1,72 @@ +/* + * 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_support_template.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 AniIsSupportTemplate(ani_env* env, ani_string templateName) +{ + ANS_LOGD("AniIsSupportTemplate call"); + std::string templateNameStr; + if (NotificationSts::GetStringByAniString(env, templateName, templateNameStr) != ANI_OK) { + NotificationSts::ThrowStsErroWithMsg(env, "templateName parse failed!"); + return NotificationSts::BoolToAniBoolean(false); + } + + ANS_LOGD("AniIsSupportTemplate by templateName:%{public}s", templateNameStr.c_str()); + bool support = false; + int returncode = Notification::NotificationHelper::IsSupportTemplate(templateNameStr, support); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("AniIsSupportTemplate -> error, errorCode: %{public}d", externalCode); + return NotificationSts::BoolToAniBoolean(false); + } + ANS_LOGD("AniIsSupportTemplate end, support: %{public}d, returncode: %{public}d", support, externalCode); + return NotificationSts::BoolToAniBoolean(support); +} + +ani_object AniGetDeviceRemindType(ani_env *env) +{ + ANS_LOGD("AniGetDeviceRemindType enter"); + + Notification::NotificationConstant::RemindType remindType = + Notification::NotificationConstant::RemindType::DEVICE_IDLE_REMIND; + int returncode = Notification::NotificationHelper::GetDeviceRemindType(remindType); + + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("AniGetDeviceRemindType error, errorCode: %{public}d", externalCode); + return nullptr; + } + ani_enum_item remindTypeItem {}; + if (!NotificationSts::DeviceRemindTypeCToEts(env, remindType, remindTypeItem)) { + NotificationSts::ThrowStsErroWithMsg(env, "AniGetDeviceRemindType:failed to WrapNotificationSlotArray"); + return nullptr; + } + ANS_LOGD("AniGetDeviceRemindType end, ret: %{public}d", externalCode); + return remindTypeItem; +} +} +} \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_notification_manager.cpp b/frameworks/ets/ani/src/sts_notification_manager.cpp index dfd92189c..afc5f6c1b 100644 --- a/frameworks/ets/ani/src/sts_notification_manager.cpp +++ b/frameworks/ets/ani/src/sts_notification_manager.cpp @@ -218,6 +218,51 @@ bool StsSlotLevelUtils::StsToC(const STSSlotLevel inLevel, SlotLevel &outLevel) return true; } +bool StsRemindTypeUtils::StsToC(const STSRemindType inType, RemindType &outType) +{ + switch (inType) { + case STSRemindType::IDLE_DONOT_REMIND: + outType = RemindType::DEVICE_IDLE_DONOT_REMIND; + break; + case STSRemindType::IDLE_REMIND: + outType = RemindType::DEVICE_IDLE_REMIND; + break; + case STSRemindType::ACTIVE_DONOT_REMIND: + outType = RemindType::DEVICE_ACTIVE_DONOT_REMIND; + break; + case STSRemindType::ACTIVE_REMIND: + outType = RemindType::DEVICE_ACTIVE_REMIND; + break; + default: + ANS_LOGE("STSRemindType %{public}d is an invalid value", inType); + return false; + } + return true; +} + +bool StsRemindTypeUtils::CToSts(const RemindType inType, STSRemindType &outType) +{ + switch (inType) { + case RemindType::NONE: + case RemindType::DEVICE_IDLE_DONOT_REMIND: + outType = STSRemindType::IDLE_DONOT_REMIND; + break; + case RemindType::DEVICE_IDLE_REMIND: + outType = STSRemindType::IDLE_REMIND; + break; + case RemindType::DEVICE_ACTIVE_DONOT_REMIND: + outType = STSRemindType::ACTIVE_DONOT_REMIND; + break; + case RemindType::DEVICE_ACTIVE_REMIND: + outType = STSRemindType::ACTIVE_REMIND; + break; + default: + ANS_LOGE("RemindType %{public}d is an invalid value", inType); + return false; + } + return true; +} + StsNotificationLocalLiveViewSubscriber::StsNotificationLocalLiveViewSubscriber() {} @@ -383,6 +428,25 @@ bool ContentTypeCToEts(ani_env *env, ContentType contentType, ani_enum_item &enu return true; } +bool DeviceRemindTypeCToEts(ani_env *env, RemindType remindType, ani_enum_item &enumItem) +{ + STSRemindType stsRemindType = STSRemindType::IDLE_DONOT_REMIND; + StsRemindTypeUtils::CToSts(remindType, stsRemindType); + EnumConvertNativeToAni(env, + "L@ohos/notificationManager/notificationManager/RemindType;", stsRemindType, enumItem); + return true; +} + +bool DeviceRemindTypeEtsToC(ani_env *env, ani_enum_item enumItem, RemindType &remindType) +{ + STSRemindType stsRemindType = STSRemindType::IDLE_DONOT_REMIND; + if (EnumConvertAniToNative(env, enumItem, stsRemindType)) { + StsRemindTypeUtils::StsToC(stsRemindType, remindType); + return true; + } + return false; +} + ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonOptionObj, ButtonOption &buttonOption) { diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index 88c88458f..ee2307572 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -122,6 +122,13 @@ export default namespace notificationManager { onResponse?: (notificationId: number, buttonOptions: ButtonOptions) => void; } + export enum DeviceRemindType { + IDLE_DONOT_REMIND = 0, + IDLE_REMIND = 1, + ACTIVE_DONOT_REMIND = 2, + ACTIVE_REMIND = 3, + } + export native function nativeCancelAll(): void; export native function nativeCancelWithId(id: number): void; export native function nativeCancelWithIdLabel(id: number, label: string): void; @@ -170,6 +177,14 @@ export default namespace notificationManager { export native function nativeRemoveAllSlots(): void; export native function nativeSetSlotByBundle(bundle: BundleOption, slot: NotificationSlot): void; export native function nativeGetSlotNumByBundle(bundle: BundleOption): number; + export native function nativeIsSupportTemplate(templateName: string): boolean; + export native function nativeSetDistributedEnable(enable: boolean): void; + export native function nativeIsDistributedEnabled(): boolean; + export native function nativeIsDistributedEnabledByBundle(bundle: BundleOption): boolean; + export native function nativeIsDistributedEnabledByBundleType(bundle: BundleOption, deviceType: string): boolean; + export native function nativeGetDeviceRemindType(): DeviceRemindType; + export native function nativeSetSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): void; + export native function nativeGetSyncNotificationEnabledWithoutApp(userId: number): boolean; function isInvalidParameter(slot: NotificationSlot): BusinessError { @@ -1704,4 +1719,246 @@ export default namespace notificationManager { public slotType: SlotType = SlotType.UNKNOWN_TYPE; public extraInfos?: Record; } + + export function isSupportTemplate(templateName: string): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): boolean => { return nativeIsSupportTemplate(templateName); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function isSupportTemplate(templateName: string, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): boolean => { return nativeIsSupportTemplate(templateName); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let ret : boolean = false; + let err: BusinessError = error as BusinessError; + callback(err, ret); + }) + } + + export function setDistributedEnable(enable: boolean, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeSetDistributedEnable(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 function setDistributedEnable(enable: boolean): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeSetDistributedEnable(enable); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function isDistributedEnabled(): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): boolean => { return nativeIsDistributedEnabled(); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function isDistributedEnabled(callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): boolean => { return nativeIsDistributedEnabled(); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let ret : boolean = false; + let err: BusinessError = error as BusinessError; + callback(err, ret); + }) + } + + export function isDistributedEnabledByBundle(bundle: BundleOption): 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((): boolean => { return nativeIsDistributedEnabledByBundle(bundle); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback): void + { + + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== 0) { + throw error; + } + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): boolean => { return nativeIsDistributedEnabledByBundle(bundle); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let ret : boolean = false; + let err: BusinessError = error as BusinessError; + callback(err, ret); + }) + } + + export function isDistributedEnabledByBundle(bundle: BundleOption, deviceType: string): 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((): boolean => { return nativeIsDistributedEnabledByBundleType(bundle, deviceType); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getDeviceRemindType(): Promise + { + let pPromise = new Promise( + (resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): DeviceRemindType => { return nativeGetDeviceRemindType(); }); + p.then((data: NullishType): void => { + let ret : DeviceRemindType = data as DeviceRemindType; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getDeviceRemindType(callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): DeviceRemindType => { return nativeGetDeviceRemindType(); }); + p.then((data: NullishType): void => { + let ret : DeviceRemindType = data as DeviceRemindType; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + const defaultRemindType: DeviceRemindType = DeviceRemindType.IDLE_DONOT_REMIND; + let err: BusinessError = error as BusinessError; + callback(err, defaultRemindType); + }) + } + + export function setSyncNotificationEnabledWithoutApp + (userId: number, enable: boolean, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => + { return nativeSetSyncNotificationEnabledWithoutApp(userId, 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 function setSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => + { return nativeSetSyncNotificationEnabledWithoutApp(userId, enable); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getSyncNotificationEnabledWithoutApp(userId: number): Promise { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): boolean => + { return nativeGetSyncNotificationEnabledWithoutApp(userId); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getSyncNotificationEnabledWithoutApp(userId: number, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): boolean => { return nativeGetSyncNotificationEnabledWithoutApp(userId); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let ret : boolean = false; + let err: BusinessError = error as BusinessError; + callback(err, ret); + }) + } } \ No newline at end of file -- Gitee From 878f395e22e41ec3c31aa4b126b22d75b7a7031f Mon Sep 17 00:00:00 2001 From: heguokai Date: Thu, 5 Jun 2025 23:54:50 +0800 Subject: [PATCH 04/14] =?UTF-8?q?ans=E6=A8=A1=E5=9D=97=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3ani=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: heguokai --- frameworks/ets/ani/BUILD.gn | 9 + .../ets/ani/include/manager/ani_cance.h | 3 + .../ani/include/manager/ani_display_badge.h | 2 + .../include/manager/ani_distributed_enable.h | 12 +- .../include/manager/ani_do_not_disturb_date.h | 29 + .../manager/ani_do_not_disturb_profile.h | 1 + .../ets/ani/include/manager/ani_get_active.h | 1 + .../include/manager/ani_notification_enable.h | 3 + .../ani/include/manager/ani_open_settings.h | 73 ++ .../ets/ani/include/manager/ani_publish.h | 2 + .../ani/include/manager/ani_remove_group.h | 25 + .../ets/ani/include/manager/ani_sync_config.h | 24 + .../ets/ani/include/sts_bundle_option.h | 1 + frameworks/ets/ani/include/sts_disturb_mode.h | 1 + .../ani/include/sts_notification_manager.h | 20 + frameworks/ets/ani/include/sts_request.h | 1 + frameworks/ets/ani/include/sts_subscribe.h | 1 + frameworks/ets/ani/include/sts_throw_erro.h | 3 +- .../ets/ani/include/subscribe/ani_remove.h | 2 + frameworks/ets/ani/src/manager/ani_cance.cpp | 71 ++ .../ets/ani/src/manager/ani_display_badge.cpp | 34 + .../src/manager/ani_distributed_enable.cpp | 192 ++++ .../src/manager/ani_do_not_disturb_date.cpp | 138 +++ .../manager/ani_do_not_disturb_profile.cpp | 37 + .../ets/ani/src/manager/ani_get_active.cpp | 29 + .../ets/ani/src/manager/ani_manager.cpp | 53 + .../src/manager/ani_notification_enable.cpp | 79 +- .../ets/ani/src/manager/ani_open_settings.cpp | 352 +++++++ .../ets/ani/src/manager/ani_publish.cpp | 64 +- .../ets/ani/src/manager/ani_remove_group.cpp | 53 + .../ets/ani/src/manager/ani_sync_config.cpp | 61 ++ frameworks/ets/ani/src/sts_bundle_option.cpp | 31 + frameworks/ets/ani/src/sts_disturb_mode.cpp | 69 ++ .../ets/ani/src/sts_notification_manager.cpp | 91 ++ frameworks/ets/ani/src/sts_request.cpp | 49 +- frameworks/ets/ani/src/sts_subscribe.cpp | 43 +- .../ets/ani/src/subscribe/ani_remove.cpp | 41 + .../ets/ani/src/subscribe/ani_subscribe.cpp | 17 +- .../ets/ets/@ohos.notificationManager.ets | 959 +++++++++++++++--- .../ets/ets/@ohos.notificationSubscribe.ets | 131 +++ 40 files changed, 2629 insertions(+), 178 deletions(-) create mode 100644 frameworks/ets/ani/include/manager/ani_do_not_disturb_date.h create mode 100644 frameworks/ets/ani/include/manager/ani_open_settings.h create mode 100644 frameworks/ets/ani/include/manager/ani_remove_group.h create mode 100644 frameworks/ets/ani/include/manager/ani_sync_config.h create mode 100644 frameworks/ets/ani/src/manager/ani_do_not_disturb_date.cpp create mode 100644 frameworks/ets/ani/src/manager/ani_open_settings.cpp create mode 100644 frameworks/ets/ani/src/manager/ani_remove_group.cpp create mode 100644 frameworks/ets/ani/src/manager/ani_sync_config.cpp diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index 627f97101..46336e3a1 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -45,6 +45,11 @@ ohos_shared_library("notification_manager_ani") { "./src/sts_notification_content.cpp", "./src/sts_template.cpp", "./src/sts_request.cpp", + "./src/sts_subscribe.cpp", + "./src/sts_subscriber.cpp", + "./src/sts_sorting_map.cpp", + "./src/sts_subscribe_info.cpp", + "./src/sts_sorting.cpp", "./src/manager/ani_local_live_view.cpp", "./src/manager/ani_publish.cpp", "./src/manager/ani_display_badge.cpp", @@ -52,6 +57,7 @@ ohos_shared_library("notification_manager_ani") { "./src/manager/ani_cance.cpp", "./src/manager/ani_notification_enable.cpp", "./src/manager/ani_do_not_disturb_profile.cpp", + "./src/manager/ani_do_not_disturb_date.cpp", "./src/manager/ani_get_active.cpp", "./src/manager/ani_manager.cpp", "./src/manager/ani_request_enable.cpp", @@ -60,6 +66,9 @@ ohos_shared_library("notification_manager_ani") { "./src/manager/ani_push_callback.cpp", "./src/manager/ani_support_template.cpp", "./src/manager/ani_distributed_enable.cpp", + "./src/manager/ani_remove_group.cpp", + "./src/manager/ani_open_settings.cpp", + "./src/manager/ani_sync_config.cpp", ] cflags = [] diff --git a/frameworks/ets/ani/include/manager/ani_cance.h b/frameworks/ets/ani/include/manager/ani_cance.h index 5e3f19fd6..485c27fa7 100644 --- a/frameworks/ets/ani/include/manager/ani_cance.h +++ b/frameworks/ets/ani/include/manager/ani_cance.h @@ -24,6 +24,9 @@ void AniCancelWithId(ani_env* env, ani_double id); void AniCancelWithIdLabel(ani_env* env, ani_double id, ani_string label); void AniCancelWithBundle(ani_env* env, ani_object bundleObj, ani_double id); void AniCancelWithIdOptinalLabel(ani_env* env, ani_double id, ani_string label); +void AniCancelAsBundle(ani_env *env, ani_double id, ani_string representativeBundle, ani_double userId); +void AniCancelAsBundleWithBundleOption(ani_env *env, ani_object representativeBundle, ani_double id); +void AniCancelGroup(ani_env *env, ani_string groupName); } // namespace NotificationManagerSts } // namespace OHOS #endif diff --git a/frameworks/ets/ani/include/manager/ani_display_badge.h b/frameworks/ets/ani/include/manager/ani_display_badge.h index a9489f60b..a292920bf 100644 --- a/frameworks/ets/ani/include/manager/ani_display_badge.h +++ b/frameworks/ets/ani/include/manager/ani_display_badge.h @@ -21,6 +21,8 @@ namespace OHOS { namespace NotificationManagerSts { void AniDisplayBadge(ani_env *env, ani_object obj, ani_boolean enable); ani_boolean AniIsBadgeDisplayed(ani_env *env, ani_object obj); +void AniSetBadgeNumber(ani_env *env, ani_double badgeNumber); +void AniSetBadgeNumberByBundle(ani_env *env, ani_object obj, ani_double badgeNumber); } } #endif diff --git a/frameworks/ets/ani/include/manager/ani_distributed_enable.h b/frameworks/ets/ani/include/manager/ani_distributed_enable.h index 4a712316f..385c801ac 100755 --- a/frameworks/ets/ani/include/manager/ani_distributed_enable.h +++ b/frameworks/ets/ani/include/manager/ani_distributed_enable.h @@ -18,11 +18,19 @@ namespace OHOS { namespace NotificationManagerSts { -void AniSetDistributedEnable(ani_env* env, ani_boolean enabled); +const int32_t DISTURB_DEFAULT_FLAG = 13; + ani_boolean AniIsDistributedEnabled(ani_env* env); ani_boolean AniIsDistributedEnabledByBundle(ani_env* env, ani_object obj); ani_boolean AniIsDistributedEnabledByBundleType(ani_env* env, ani_object obj, ani_string deviceType); - +void AniSetDistributedEnable(ani_env* env, ani_boolean enabled); +void AniSetDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enable); +void AniSetDistributedEnableByBundleAndType(ani_env *env, ani_object obj, ani_string deviceType, ani_boolean enable); +void AniSetTargetDeviceStatus(ani_env* env, ani_string deviceType, ani_double status); +ani_boolean AniIsSmartReminderEnabled(ani_env *env, ani_string deviceType); +void AniSetSmartReminderEnable(ani_env *env, ani_string deviceType, ani_boolean enable); +void AniSetDistributedEnableBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType, ani_boolean enable); +ani_boolean AniIsDistributedEnabledBySlot(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_do_not_disturb_date.h b/frameworks/ets/ani/include/manager/ani_do_not_disturb_date.h new file mode 100644 index 000000000..721ba1d52 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_do_not_disturb_date.h @@ -0,0 +1,29 @@ +/* + * 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_DO_NOT_DISTURB_DATA_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DO_NOT_DISTURB_DATA_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +void AniSetDoNotDisturbDate(ani_env *env, ani_object date); +void AniSetDoNotDisturbDateWithId(ani_env *env, ani_object date, ani_double userId); +ani_object AniGetDoNotDisturbDate(ani_env *env); +ani_object AniGetDoNotDisturbDateWithId(ani_env *env, ani_double userId); +ani_boolean AniIsSupportDoNotDisturbMode(ani_env *env); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_do_not_disturb_profile.h b/frameworks/ets/ani/include/manager/ani_do_not_disturb_profile.h index b4a0ac997..c5e9b03c1 100644 --- a/frameworks/ets/ani/include/manager/ani_do_not_disturb_profile.h +++ b/frameworks/ets/ani/include/manager/ani_do_not_disturb_profile.h @@ -21,6 +21,7 @@ namespace OHOS { namespace NotificationManagerSts { void AniAddDoNotDisturbProfile(ani_env *env, ani_object obj); void AniRemoveDoNotDisturbProfile(ani_env *env, ani_object obj); +ani_object AniGetDoNotDisturbProfile(ani_env *env, ani_double id); } } #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_get_active.h b/frameworks/ets/ani/include/manager/ani_get_active.h index b2d18712d..3d8861090 100644 --- a/frameworks/ets/ani/include/manager/ani_get_active.h +++ b/frameworks/ets/ani/include/manager/ani_get_active.h @@ -22,6 +22,7 @@ namespace NotificationManagerSts { ani_double AniGetActiveNotificationCount(ani_env *env); ani_object AniGetAllActiveNotifications(ani_env *env); ani_object AniGetActiveNotifications(ani_env *env); +ani_object AniGetActiveNotificationByFilter(ani_env *env, ani_object obj); } // namespace NotificationManagerSts } // namespace OHOS #endif diff --git a/frameworks/ets/ani/include/manager/ani_notification_enable.h b/frameworks/ets/ani/include/manager/ani_notification_enable.h index 93dee4348..bb657a6e2 100644 --- a/frameworks/ets/ani/include/manager/ani_notification_enable.h +++ b/frameworks/ets/ani/include/manager/ani_notification_enable.h @@ -24,7 +24,10 @@ ani_boolean AniIsNotificationEnabledWithId(ani_env *env, ani_double userId); ani_boolean AniIsNotificationEnabledWithBundleOption(ani_env *env, ani_object bundleOption); void AniSetNotificationEnable(ani_env *env, ani_object bundleOption, ani_boolean enable); void AniSetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId, ani_boolean enabled); +ani_boolean AniIsNotificationEnabledSync(ani_env *env); ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId); +ani_object AniGetAllNotificationEnabledBundles(ani_env *env); +void AniDisableNotificationFeature(ani_env *env, ani_boolean disabled, ani_object bundleList); } // namespace NotificationManagerSts } // namespace OHOS #endif diff --git a/frameworks/ets/ani/include/manager/ani_open_settings.h b/frameworks/ets/ani/include/manager/ani_open_settings.h new file mode 100644 index 000000000..1617ec391 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_open_settings.h @@ -0,0 +1,73 @@ +/* + * 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_OPEN_SETTINGS_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_OPEN_SETTINGS_H + +#include "ani.h" +#include "ani_base_context.h" +#include "ans_dialog_host_client.h" +#include "ability.h" +#include "ability_context.h" +#include "ui_content.h" + +namespace OHOS { +namespace NotificationManagerSts { +class SettingsModalExtensionCallback; +struct OpenSettingsInfo { + int32_t errorCode = ANI_OK; + std::shared_ptr context = nullptr; + ani_resolver resolver {}; +}; + +ani_object AniOpenNotificationSettings(ani_env *env, ani_object content); +bool GetOpenSettingsInfo(ani_env *env, ani_object content, std::shared_ptr &info); +bool CreateSettingsUIExtension(std::shared_ptr context, std::string &bundleName, + ani_env *env, std::shared_ptr &info); +void StsAsyncCompleteCallbackOpenSettings(ani_env *env, std::shared_ptr info); + +using StsSettingsModalExtensionCallbackComplete = void(ani_env *env, std::shared_ptr info); +void ProcessStatusChanged(int32_t code); +bool CreateUiExtCallback(ani_env *env, std::shared_ptr& uiExtCallback, + Ace::ModalUIExtensionCallbacks& uiExtensionCallbacks, std::shared_ptr &info, + std::shared_ptr& abilityContext, std::string &bundleName); +class SettingsModalExtensionCallback { +public: + SettingsModalExtensionCallback(); + ~SettingsModalExtensionCallback(); + void OnRelease(int32_t releaseCode); + void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result); + void OnReceive(const OHOS::AAFwk::WantParams& request); + void OnError(int32_t code, const std::string& name, const std::string &message); + void OnRemoteReady(const std::shared_ptr &uiProxy); + void OnDestroy(); + void SetSessionId(int32_t sessionId); + void SetBundleName(std::string bundleName); + void SetAbilityContext(std::shared_ptr abilityContext); + void ReleaseOrErrorHandle(int32_t code); + bool Init(ani_env *env, std::shared_ptr info, + StsSettingsModalExtensionCallbackComplete *complete); + void ProcessStatusChanged(int32_t code, bool isAsync); +private: + int32_t sessionId_ = 0; + std::string bundleName_; + std::shared_ptr abilityContext_; + ani_vm *vm_ = nullptr; + std::shared_ptr info_ = nullptr; + StsSettingsModalExtensionCallbackComplete *complete_ = nullptr; +}; +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_publish.h b/frameworks/ets/ani/include/manager/ani_publish.h index fd18fc59c..33a018c6a 100644 --- a/frameworks/ets/ani/include/manager/ani_publish.h +++ b/frameworks/ets/ani/include/manager/ani_publish.h @@ -21,6 +21,8 @@ namespace OHOS { namespace NotificationManagerSts { void AniPublish(ani_env *env, ani_object obj); void AniPublishWithId(ani_env *env, ani_object obj, ani_double userId); +void AniPublishAsBundle(ani_env *env, ani_object request, ani_string representativeBundle, ani_double userId); +void AniPublishAsBundleWithBundleOption(ani_env *env, ani_object representativeBundle, ani_object request); } // namespace NotificationManagerSts } // namespace OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_remove_group.h b/frameworks/ets/ani/include/manager/ani_remove_group.h new file mode 100644 index 000000000..1ec3dbe08 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_remove_group.h @@ -0,0 +1,25 @@ +/* + * 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_REMOVE_GROUP_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_REMOVE_GROUP_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +void AniRemoveGroupByBundle(ani_env *env, ani_object bundleOption, ani_string groupName); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_sync_config.h b/frameworks/ets/ani/include/manager/ani_sync_config.h new file mode 100644 index 000000000..a337aed87 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_sync_config.h @@ -0,0 +1,24 @@ +/* + * 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_SYNC_CONFIG_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SYNC_CONFIG_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +ani_double AniSetAdditionalConfig(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/sts_bundle_option.h b/frameworks/ets/ani/include/sts_bundle_option.h index a1bc56061..5bda338dd 100644 --- a/frameworks/ets/ani/include/sts_bundle_option.h +++ b/frameworks/ets/ani/include/sts_bundle_option.h @@ -26,6 +26,7 @@ bool WrapBundleOption(ani_env* env, const std::shared_ptr &bundleOption, ani_object &bundleObject); bool UnwrapArrayBundleOption(ani_env *env, ani_ref arrayObj, std::vector& options); +ani_object GetAniArrayBundleOption(ani_env* env, const std::vector &bundleOptions); } } diff --git a/frameworks/ets/ani/include/sts_disturb_mode.h b/frameworks/ets/ani/include/sts_disturb_mode.h index eb208a289..491450d9f 100644 --- a/frameworks/ets/ani/include/sts_disturb_mode.h +++ b/frameworks/ets/ani/include/sts_disturb_mode.h @@ -25,6 +25,7 @@ bool UnwrapDoNotDisturbProfile(ani_env *env, ani_object param, sptr &profile); bool UnwrapArrayDoNotDisturbProfile(ani_env *env, ani_object arrayObj, std::vector> &profiles); +bool WrapDoNotDisturbProfile(ani_env* env, sptr profile, ani_object& outObj); } // namespace NotificationSts } // OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/sts_notification_manager.h b/frameworks/ets/ani/include/sts_notification_manager.h index bf9cba112..f2d72b257 100644 --- a/frameworks/ets/ani/include/sts_notification_manager.h +++ b/frameworks/ets/ani/include/sts_notification_manager.h @@ -18,6 +18,7 @@ #include "ani.h" #include "notification_constant.h" #include "notification_content.h" +#include "notification_do_not_disturb_date.h" #include "notification_slot.h" #include "notification_button_option.h" #include "notification_local_live_view_subscriber.h" @@ -33,6 +34,15 @@ using ContentType = OHOS::Notification::NotificationContent::Type; using ButtonOption = OHOS::Notification::NotificationButtonOption; using NotificationDoNotDisturbDate = OHOS::Notification::NotificationDoNotDisturbDate; using RemindType = OHOS::Notification::NotificationConstant::RemindType; +using NotificationConstant = OHOS::Notification::NotificationConstant; + +enum STSDoNotDisturbType { + TYPE_NONE = 0, + TYPE_ONCE = 1, + TYPE_DAILY = 2, + TYPE_CLEARLY = 3, +}; + enum STSSlotType { UNKNOWN_TYPE = 0, SOCIAL_COMMUNICATION = 1, @@ -69,6 +79,12 @@ enum class STSRemindType { ACTIVE_REMIND }; +class StsDoNotDisturbTypeUtils { +public: +static bool StsToC(const STSDoNotDisturbType inType, + OHOS::Notification::NotificationConstant::DoNotDisturbType &outType); +}; + class StsSlotTypeUtils { public: static bool StsToC(const STSSlotType inType, SlotType &outType); @@ -153,8 +169,12 @@ bool DeviceRemindTypeEtsToC(ani_env *env, ani_enum_item enumItem, RemindType &re ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonOptionObj, ButtonOption &buttonOption); ani_object WarpNotificationButtonOption(ani_env *env, sptr buttonOption); + +bool UnWarpNotificationDoNotDisturbDate(ani_env* env, const ani_object doNotDisturbDateObj, + NotificationDoNotDisturbDate& doNotDisturbDate); bool WarpNotificationDoNotDisturbDate( ani_env *env, const std::shared_ptr &date, ani_object &outObj); + bool WarpNotificationCheckInfo( ani_env *env, const std::shared_ptr &data, ani_object &outObj); } // namespace NotificationSts diff --git a/frameworks/ets/ani/include/sts_request.h b/frameworks/ets/ani/include/sts_request.h index 02a69f21d..c35fee773 100644 --- a/frameworks/ets/ani/include/sts_request.h +++ b/frameworks/ets/ani/include/sts_request.h @@ -43,6 +43,7 @@ ani_object GetAniNotificationRequestArray(ani_env *env, std::vector> requests); bool UnWarpNotificationCheckRequest(ani_env *env, ani_object obj, sptr &checkRequest); +bool UnWarpNotificationFilter(ani_env *env, ani_object obj, LiveViewFilter& filter); } // namespace NotificationSts } // OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/sts_subscribe.h b/frameworks/ets/ani/include/sts_subscribe.h index 9f948df7e..bfa5abf07 100644 --- a/frameworks/ets/ani/include/sts_subscribe.h +++ b/frameworks/ets/ani/include/sts_subscribe.h @@ -112,6 +112,7 @@ public: void DelDeletingSubscriber(std::shared_ptr subscriber); bool Subscribe(ani_env *env, ani_object subscriber, ani_object info); + bool SubscribeSelf(ani_env *env, ani_object subscriber); bool UnSubscribe(ani_env *env, ani_object subscriber); private: SubscriberInstanceManager() {} diff --git a/frameworks/ets/ani/include/sts_throw_erro.h b/frameworks/ets/ani/include/sts_throw_erro.h index 44f75ae9b..642ed3b42 100644 --- a/frameworks/ets/ani/include/sts_throw_erro.h +++ b/frameworks/ets/ani/include/sts_throw_erro.h @@ -60,7 +60,7 @@ inline std::string FindAnsErrMsg(const int32_t errCode) { auto findMsg = ERROR_CODE_TO_MESSAGE.find(errCode); if (findMsg == ERROR_CODE_TO_MESSAGE.end()) { - ANSR_LOGE("FindAnsErrMsg Inner error."); + ANS_LOGE("FindAnsErrMsg Inner error."); return "Inner error."; } return findMsg->second; @@ -68,6 +68,7 @@ inline std::string FindAnsErrMsg(const int32_t errCode) inline void ThrowStsErroWithMsg(ani_env *env, std::string logMsg) { + ANS_LOGE("%{public}s", logMsg.c_str()); OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); } diff --git a/frameworks/ets/ani/include/subscribe/ani_remove.h b/frameworks/ets/ani/include/subscribe/ani_remove.h index a60aa5ab8..c10e15dc4 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 AniRemoveAllForUserId(ani_env *env, ani_double userId); +void AniRemoveAllForBundle(ani_env *env, ani_object bundle); } } #endif \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_cance.cpp b/frameworks/ets/ani/src/manager/ani_cance.cpp index 180bedaac..600558eff 100644 --- a/frameworks/ets/ani/src/manager/ani_cance.cpp +++ b/frameworks/ets/ani/src/manager/ani_cance.cpp @@ -114,5 +114,76 @@ void AniCancelWithIdOptinalLabel(ani_env* env, ani_double id, ani_string label) } ANS_LOGD("sts AniCancelWithIdOptinalLabel end, externalCode: %{public}d", externalCode); } + +void AniCancelAsBundle(ani_env *env, ani_double id, ani_string representativeBundle, ani_double userId) +{ + ANS_LOGD("AniCancelAsBundle enter"); + int32_t convertedId = static_cast(id); + int32_t UserId = static_cast(userId); + std::string bundleStr; + + if (ANI_OK != NotificationSts::GetStringByAniString(env, representativeBundle, bundleStr)) { + ANS_LOGE("AniCancelAsBundle:: representativeBundle parse failed!"); + NotificationSts::ThrowStsErroWithMsg(env, "representativeBundle parse failed!"); + return; + } + ANS_LOGD("AniCancelAsBundle, convertedId: %{public}d, UserId: %{public}d, bundleStr: %{public}s", + convertedId, UserId, bundleStr.c_str()); + + int returncode = Notification::NotificationHelper::CancelAsBundle(convertedId, bundleStr, UserId); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("AniCancelAsBundle: CancelAsBundle retern erro. returncode: %{public}d, externalCode: %{public}d", + returncode, externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + + ANS_LOGD("AniCancelAsBundle end"); +} + +void AniCancelAsBundleWithBundleOption(ani_env *env, ani_object representativeBundle, ani_double id) +{ + ANS_LOGD("AniCancelAsBundleWithBundleOption enter"); + int32_t idTest = static_cast(id); + BundleOption option; + if (NotificationSts::UnwrapBundleOption(env, representativeBundle, option) != true) { + ANS_LOGE("AniPublishAsBundleWithBundleOption BundleOption parse failed!"); + NotificationSts::ThrowStsErroWithMsg(env, "AniPublishAsBundleWithBundleOption BundleOption parse failed!"); + return; + } + + ANS_LOGD("AniPublishAsBundleWithBundleOption: bundle %{public}s, uid: %{public}d, id: %{public}d", + option.GetBundleName().c_str(), option.GetUid(), idTest); + + int returncode = Notification::NotificationHelper::CancelAsBundle(option, idTest); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("CancelAsBundle retern error. returncode: %{public}d, externalCode: %{public}d", + returncode, externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + + ANS_LOGD("AniCancelAsBundleWithBundleOption end"); +} + +void AniCancelGroup(ani_env *env, ani_string groupName) +{ + ANS_LOGD("AniCancelGroup enter"); + + std::string groupNameStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, groupName, groupNameStr)) { + NotificationSts::ThrowStsErroWithMsg(env, "AniCancelGroup: groupName parse failed!"); + return; + } + ANS_LOGD("AniCancelGroup groupNameStr: %{public}s", groupNameStr.c_str()); + int returncode = Notification::NotificationHelper::CancelGroup(groupNameStr); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("AniCancelGroup: CancelAsBundle retern erro. returncode: %{public}d, externalCode: %{public}d", + returncode, externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniCancelGroup end"); +} } // namespace NotificationManagerSts } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_display_badge.cpp b/frameworks/ets/ani/src/manager/ani_display_badge.cpp index 7cba58762..ed01c043a 100644 --- a/frameworks/ets/ani/src/manager/ani_display_badge.cpp +++ b/frameworks/ets/ani/src/manager/ani_display_badge.cpp @@ -78,5 +78,39 @@ ani_boolean AniIsBadgeDisplayed(ani_env *env, ani_object obj) externalCode); return NotificationSts::BoolToAniBoolean(isDisplayed); } + +void AniSetBadgeNumber(ani_env *env, ani_double badgeNumber) +{ + ANS_LOGD("sts AniSetBadgeNumber call, BadgeNumber: %{public}lf", badgeNumber); + int returncode = Notification::NotificationHelper::SetBadgeNumber(static_cast(badgeNumber)); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("sts AniSetBadgeNumber error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("sts AniSetBadgeNumber end"); +} + +void AniSetBadgeNumberByBundle(ani_env *env, ani_object obj, ani_double badgeNumber) +{ + ANS_LOGD("AniSetBadgeNumberByBundle call, badgeNumber: %{public}lf", badgeNumber); + int returncode = ERR_OK; + BundleOption option; + if (NotificationSts::UnwrapBundleOption(env, obj, option)) { + returncode = Notification::NotificationHelper::SetBadgeNumberByBundle(option, + static_cast(badgeNumber)); + } else { + ANS_LOGE("sts AniSetBadgeNumberByBundle ERROR_INTERNAL_ERROR"); + OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); + return; + } + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("sts AniSetBadgeNumberByBundle error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniSetBadgeNumberByBundle end, ret: %{public}d", externalCode); +} } } \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp index fa63aae21..4beb262fd 100755 --- a/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp @@ -96,5 +96,197 @@ ani_boolean AniIsDistributedEnabledByBundleType(ani_env* env, ani_object obj, an ANS_LOGD("AniIsDistributedEnabledByBundle end, enabled: %{public}d, returncode: %{public}d", enabled, externalCode); return NotificationSts::BoolToAniBoolean(enabled); } + +void AniSetDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enable) +{ + ANS_LOGD("setDistributedEnableByBundle call"); + int returncode = ERR_OK; + Notification::NotificationBundleOption option; + bool bFlag = NotificationSts::UnwrapBundleOption(env, obj, option); + if (bFlag) { + returncode = Notification::NotificationHelper::EnableDistributedByBundle( + option, NotificationSts::AniBooleanToBool(enable)); + } else { + ANS_LOGE("sts setDistributedEnableByBundle ERROR_INTERNAL_ERROR"); + OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); + return; + } + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("sts setDistributedEnableByBundle error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("sts setDistributedEnableByBundle end, ret: %{public}d", externalCode); +} + +void AniSetDistributedEnableByBundleAndType(ani_env *env, + ani_object obj, ani_string deviceType, ani_boolean enable) +{ + ANS_LOGD("sts setDistributedEnabledByBundle call"); + std::string deviceTypeStr; + if (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + int returncode = ERR_OK; + Notification::NotificationBundleOption option; + bool bFlag = NotificationSts::UnwrapBundleOption(env, obj, option); + if (bFlag) { + returncode = Notification::NotificationHelper::SetDistributedEnabledByBundle(option, + deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); + } else { + ANS_LOGE("sts setDistributedEnabledByBundle ERROR_INTERNAL_ERROR"); + OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); + return; + } + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("sts setDistributedEnabledByBundle error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("sts setDistributedEnabledByBundle end, ret: %{public}d", externalCode); +} + +void AniSetTargetDeviceStatus(ani_env* env, ani_string deviceType, ani_double status) +{ + ANS_LOGD("sts setTargetDeviceStatus call, id:%{public}lf", status); + std::string deviceTypeStr; + if (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + 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) { + ANS_LOGE("sts setTargetDeviceStatus error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("sts setTargetDeviceStatus end, externalCode: %{public}d", externalCode); +} + +ani_boolean AniIsSmartReminderEnabled(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 (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + 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 != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("isSmartReminderEnabled -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("isSmartReminderEnabled end"); + return NotificationSts::BoolToAniBoolean(allowed); +} + + +void AniSetSmartReminderEnable(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 (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + 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 != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("setSmartReminderEnabled -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("setSmartReminderEnabled end"); +} + +void AniSetDistributedEnableBySlot(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"; + ANS_LOGE("SlotTypeEtsToC failed. msg: %{public}s", msg.c_str()); + 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 (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + int returncode = ERR_OK; + returncode = Notification::NotificationHelper::SetDistributedEnabledBySlot(slotType, + deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); + + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("setDistributedEnabledBySlot error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } +} + +ani_boolean AniIsDistributedEnabledBySlot(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"; + ANS_LOGE("SlotTypeEtsToC failed. msg: %{public}s", msg.c_str()); + 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 (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + 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 != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("isDistributedEnabledBySlot -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + return isEnable ? ANI_TRUE : ANI_FALSE; +} } } \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_do_not_disturb_date.cpp b/frameworks/ets/ani/src/manager/ani_do_not_disturb_date.cpp new file mode 100644 index 000000000..7d09b4241 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_do_not_disturb_date.cpp @@ -0,0 +1,138 @@ +/* + * 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_do_not_disturb_date.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" +#include "sts_request.h" + +namespace OHOS { +namespace NotificationManagerSts { +void AniSetDoNotDisturbDate(ani_env *env, ani_object date) +{ + ANS_LOGD("AniSetDoNotDisturbDate enter"); + Notification::NotificationDoNotDisturbDate doNotDisturbDate; + if (NotificationSts::UnWarpNotificationDoNotDisturbDate(env, date, doNotDisturbDate)) { + ANS_LOGE("AniSetDoNotDisturbDate UnWarpNotificationDoNotDisturbDate ERROR_INTERNAL_ERROR"); + NotificationSts::ThrowStsErroWithMsg(env, "UnWarpNotificationDoNotDisturbDate ERROR_INTERNAL_ERROR"); + return; + } + + int returncode = Notification::NotificationHelper::SetDoNotDisturbDate(doNotDisturbDate); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("SetDoNotDisturbDate error. returncode: %{public}d, externalCode: %{public}d", + returncode, externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniSetDoNotDisturbDate end"); +} + +void AniSetDoNotDisturbDateWithId(ani_env *env, ani_object date, ani_double userId) +{ + ANS_LOGD("AniSetDoNotDisturbDateWithId enter"); + Notification::NotificationDoNotDisturbDate doNotDisturbDate; + if (NotificationSts::UnWarpNotificationDoNotDisturbDate(env, date, doNotDisturbDate)) { + ANS_LOGE("AniSetDoNotDisturbDateWithId UnWarpNotificationDoNotDisturbDate ERROR_INTERNAL_ERROR"); + NotificationSts::ThrowStsErroWithMsg(env, "UnWarpNotificationDoNotDisturbDate ERROR_INTERNAL_ERROR"); + return; + } + + const int32_t id = static_cast(userId); + int returncode = Notification::NotificationHelper::SetDoNotDisturbDate(id, doNotDisturbDate); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("SetDoNotDisturbDate erro. returncode: %{public}d, externalCode: %{public}d", + returncode, externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + + ANS_LOGD("AniSetDoNotDisturbDateWithId end"); +} + +ani_object AniGetDoNotDisturbDate(ani_env *env) +{ + ani_object data = nullptr; + Notification::NotificationDoNotDisturbDate doNotDisturbDate; + + ANS_LOGD("AniGetDoNotDisturbDate enter"); + int returncode = Notification::NotificationHelper::GetDoNotDisturbDate(doNotDisturbDate); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("GetDoNotDisturbDate retern erro. returncode: %{public}d, externalCode: %{public}d", + returncode, externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return data; + } + + auto datePtr = std::make_shared(doNotDisturbDate); + if (NotificationSts::WarpNotificationDoNotDisturbDate(env, datePtr, data) == false) { + ANS_LOGE("WarpNotificationDoNotDisturbDate faild"); + NotificationSts::ThrowStsErroWithMsg(env, "AniGetDoNotDisturbDate ERROR_INTERNAL_ERROR"); + } + + ANS_LOGD("AniGetDoNotDisturbDate end"); + return data; +} + +ani_object AniGetDoNotDisturbDateWithId(ani_env *env, ani_double userId) +{ + ani_object data = nullptr; + Notification::NotificationDoNotDisturbDate doNotDisturbDate; + + ANS_LOGD("AniGetDoNotDisturbDateWithId enter"); + + const int32_t id = static_cast(userId); + int returncode = Notification::NotificationHelper::GetDoNotDisturbDate(id, doNotDisturbDate); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("GetDoNotDisturbDate erro. returncode: %{public}d, externalCode: %{public}d", + returncode, externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return data; + } + + auto datePtr = std::make_shared(doNotDisturbDate); + if (NotificationSts::WarpNotificationDoNotDisturbDate(env, datePtr, data) == false) { + ANS_LOGE("AniGetDoNotDisturbDateWithId WarpNotificationDoNotDisturbDate faild"); + } + + ANS_LOGD("AniGetDoNotDisturbDateWithId end"); + return data; +} + +ani_boolean AniIsSupportDoNotDisturbMode(ani_env *env) +{ + bool supportDoNotDisturbMode = false; + ANS_LOGD("AniIsSupportDoNotDisturbMode enter"); + int returncode = Notification::NotificationHelper::DoesSupportDoNotDisturbMode(supportDoNotDisturbMode); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("DoesSupportDoNotDisturbMode error. returncode: %{public}d, externalCode: %{public}d", + returncode, externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return ANI_FALSE; + } + ANS_LOGD("DoesSupportDoNotDisturbMode returncode: %{public}d", supportDoNotDisturbMode); + ANS_LOGD("AniIsSupportDoNotDisturbMode end"); + return NotificationSts::BoolToAniBoolean(supportDoNotDisturbMode); +} + +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp b/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp index 0d7158d5f..0bd98152f 100644 --- a/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp +++ b/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp @@ -20,6 +20,7 @@ #include "sts_common.h" #include "sts_throw_erro.h" #include "sts_disturb_mode.h" +#include "sts_bundle_option.h" namespace OHOS { namespace NotificationManagerSts { @@ -64,5 +65,41 @@ void AniRemoveDoNotDisturbProfile(ani_env *env, ani_object obj) } ANS_LOGD("AniRemoveDoNotDisturbProfile end"); } + +ani_object AniGetDoNotDisturbProfile(ani_env *env, ani_double id) +{ + ani_object profile; + ANS_LOGD("AniGetDoNotDisturbProfile enter"); + + sptr doNotDisturbProfile = new (std::nothrow) NotificationDoNotDisturbProfile(); + if (doNotDisturbProfile == nullptr) { + ANS_LOGE("Failed to create NotificationDoNotDisturbProfile."); + OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); + return nullptr; + } + + int32_t idTest = static_cast(id); + ANS_LOGD("AniGetDoNotDisturbProfile: idTest: %{public}d", idTest); + int returncode = Notification::NotificationHelper::GetDoNotDisturbProfile(idTest, doNotDisturbProfile); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("AniSetDoNotDisturbDateWithId error, errorCode: %{public}d, returncode: %{public}d", + externalCode, returncode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + + ANS_LOGD("doNotDisturbProfile ProfileId: %{public}lld, ProfileName %{public}s", + doNotDisturbProfile->GetProfileId(), doNotDisturbProfile->GetProfileName().c_str()); + if (!NotificationSts::WrapDoNotDisturbProfile(env, doNotDisturbProfile, profile)) { + ANS_LOGE("AniGetDoNotDisturbProfile WrapDoNotDisturbProfile failed"); + OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); + return nullptr; + } + + ANS_LOGD("AniGetDoNotDisturbProfile end"); + return profile; +} } } \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_get_active.cpp b/frameworks/ets/ani/src/manager/ani_get_active.cpp index 74e1ccd83..93c02e572 100644 --- a/frameworks/ets/ani/src/manager/ani_get_active.cpp +++ b/frameworks/ets/ani/src/manager/ani_get_active.cpp @@ -90,5 +90,34 @@ ani_object AniGetActiveNotifications(ani_env *env) ANS_LOGD("sts AniGetActiveNotifications end"); return arrayRequestObj; } + +ani_object AniGetActiveNotificationByFilter(ani_env *env, ani_object obj) +{ + ANS_LOGD("AniGetActiveNotificationByFilter call"); + Notification::LiveViewFilter filter; + if (!OHOS::NotificationSts::UnWarpNotificationFilter(env, obj, filter)) { + NotificationSts::ThrowStsErroWithMsg(env, "sts UnWarpNotificationFilter ERROR_INTERNAL_ERROR"); + return nullptr; + } + sptr notificationRequest = nullptr; + int returncode = Notification::NotificationHelper::GetActiveNotificationByFilter(filter, notificationRequest); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniGetActiveNotificationByFilter -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return nullptr; + } + + ani_object requestObj = nullptr; + ani_class requestCls; + if (!NotificationSts::WarpNotificationRequest(env, notificationRequest.GetRefPtr(), requestCls, requestObj) + || requestObj == nullptr) { + NotificationSts::ThrowStsErroWithMsg(env, "sts UnWarpNotificationFilter ERROR_INTERNAL_ERROR"); + ANS_LOGE("AniGetActiveNotificationByFilter WarpNotificationRequest faild"); + return nullptr; + } + ANS_LOGD("AniGetActiveNotificationByFilter end"); + return requestObj; +} } // 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 d5679284e..7cecd7021 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -19,6 +19,7 @@ #include "ani_slot.h" #include "ani_cance.h" #include "ani_notification_enable.h" +#include "ani_do_not_disturb_date.h" #include "ani_do_not_disturb_profile.h" #include "ani_get_active.h" #include "ani_publish.h" @@ -27,6 +28,9 @@ #include "ani_on.h" #include "ani_support_template.h" #include "ani_distributed_enable.h" +#include "ani_remove_group.h" +#include "ani_open_settings.h" +#include "ani_sync_config.h" namespace OHOS { namespace NotificationManagerSts { @@ -75,6 +79,22 @@ static std::array kitManagerFunctions = { ani_native_function {"nativeRequestEnableNotification", "Lapplication/UIAbilityContext/UIAbilityContext;:Lstd/core/Promise;", reinterpret_cast(AniRequestEnableNotification)}, + ani_native_function {"nativePublishAsBundle", nullptr, reinterpret_cast(AniPublishAsBundle)}, + ani_native_function {"nativePublishAsBundleWithBundleOption", nullptr, + reinterpret_cast(AniPublishAsBundleWithBundleOption)}, + ani_native_function {"nativeCancelAsBundle", nullptr, reinterpret_cast(AniCancelAsBundle)}, + ani_native_function {"nativeCancelAsBundleWithBundleOption", nullptr, + reinterpret_cast(AniCancelAsBundleWithBundleOption)}, + ani_native_function {"nativeCancelGroup", nullptr, reinterpret_cast(AniCancelGroup)}, + ani_native_function {"nativeSetDoNotDisturbDate", nullptr, reinterpret_cast(AniSetDoNotDisturbDate)}, + ani_native_function {"nativeSetDoNotDisturbDateWithId", nullptr, + reinterpret_cast(AniSetDoNotDisturbDateWithId)}, + ani_native_function {"nativeGetDoNotDisturbDate", nullptr, reinterpret_cast(AniGetDoNotDisturbDate)}, + ani_native_function {"nativeGetDoNotDisturbDateWithId", nullptr, + reinterpret_cast(AniGetDoNotDisturbDateWithId)}, + ani_native_function {"nativeIsSupportDoNotDisturbMode", nullptr, + reinterpret_cast(AniIsSupportDoNotDisturbMode)}, + ani_native_function {"nativeGetDoNotDisturbProfile", nullptr, reinterpret_cast(AniGetDoNotDisturbProfile)}, ani_native_function {"nativeOn", "Lstd/core/String;" "Lstd/core/Function1;" @@ -82,6 +102,18 @@ static std::array kitManagerFunctions = { ":I", reinterpret_cast(AniOn)}, ani_native_function {"nativeOff", "Lstd/core/String;Lstd/core/Function1;:I", reinterpret_cast(AniOff)}, + ani_native_function {"nativeGetAllNotificationEnabledBundles", nullptr, + reinterpret_cast(AniGetAllNotificationEnabledBundles)}, + ani_native_function {"nativeIsNotificationEnabledSync", nullptr, + reinterpret_cast(AniIsNotificationEnabledSync)}, + ani_native_function {"nativeSetBadgeNumber", "D:V", + reinterpret_cast(AniSetBadgeNumber)}, + ani_native_function {"nativeSetBadgeNumberByBundle", nullptr, + reinterpret_cast(AniSetBadgeNumberByBundle)}, + ani_native_function {"nativeGetActiveNotificationByFilter", nullptr, + reinterpret_cast(AniGetActiveNotificationByFilter)}, + ani_native_function {"nativeRemoveGroupByBundle", nullptr, + reinterpret_cast(AniRemoveGroupByBundle)}, ani_native_function {"nativeAddSlotByNotificationSlot", nullptr, reinterpret_cast(AniAddSlotByNotificationSlot)}, ani_native_function {"nativeAddSlotBySlotType", nullptr, @@ -100,6 +132,27 @@ static std::array kitManagerFunctions = { reinterpret_cast(AniSetSlotByBundle)}, ani_native_function {"nativeGetSlotNumByBundle", nullptr, reinterpret_cast(AniGetSlotNumByBundle)}, + ani_native_function {"nativeOpenNotificationSettings", + "Lapplication/UIAbilityContext/UIAbilityContext;:Lstd/core/Promise;", + reinterpret_cast(AniOpenNotificationSettings)}, + ani_native_function {"nativesetTargetDeviceStatus", nullptr, + reinterpret_cast(AniSetTargetDeviceStatus)}, + ani_native_function {"nativesetDistributedEnabledByBundle", nullptr, + reinterpret_cast(AniSetDistributedEnableByBundleAndType)}, + ani_native_function {"nativesetSmartReminderEnabled", nullptr, + reinterpret_cast(AniSetSmartReminderEnable)}, + ani_native_function {"nativeisSmartReminderEnabled", nullptr, + reinterpret_cast(AniIsSmartReminderEnabled)}, + ani_native_function {"nativesetDistributedEnabledBySlot", nullptr, + reinterpret_cast(AniSetDistributedEnableBySlot)}, + ani_native_function {"nativeisDistributedEnabledBySlot", nullptr, + reinterpret_cast(AniIsDistributedEnabledBySlot)}, + ani_native_function {"nativesetAdditionalConfig", nullptr, + reinterpret_cast(AniSetAdditionalConfig)}, + ani_native_function {"nativesetDistributedEnableByBundle", nullptr, + reinterpret_cast(AniSetDistributedEnableByBundle)}, + ani_native_function {"nativedisableNotificationFeature", nullptr, + reinterpret_cast(AniDisableNotificationFeature)}, ani_native_function {"nativeIsSupportTemplate", nullptr, reinterpret_cast(AniIsSupportTemplate)}, ani_native_function {"nativeSetDistributedEnable", nullptr, reinterpret_cast(AniSetDistributedEnable)}, ani_native_function {"nativeIsDistributedEnabled", nullptr, reinterpret_cast(AniIsDistributedEnabled)}, diff --git a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp index daaa2baef..c2b2529bd 100644 --- a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp @@ -27,9 +27,9 @@ ani_boolean AniIsNotificationEnabled(ani_env *env) { ANS_LOGD("AniIsNotificationEnabled call"); bool allowed = false; - int returncode = Notification::NotificationHelper::IsAllowedNotify(allowed); + int returncode = Notification::NotificationHelper::IsAllowedNotifySelf(allowed); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsNotificationEnabled -> error, errorCode: %{public}d", externalCode); } @@ -43,7 +43,7 @@ ani_boolean AniIsNotificationEnabledWithId(ani_env *env, ani_double userId) bool allowed = false; int returncode = Notification::NotificationHelper::IsAllowedNotify(userId, allowed); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsNotificationEnabledWithId -> error, errorCode: %{public}d", externalCode); } @@ -54,7 +54,7 @@ ani_boolean AniIsNotificationEnabledWithId(ani_env *env, ani_double userId) ani_boolean AniIsNotificationEnabledWithBundleOption(ani_env *env, ani_object bundleOption) { ANS_LOGD("AniIsNotificationEnabledWithBundleOption call"); - int returncode = 0; + int returncode = ERR_OK; bool allowed = false; BundleOption option; if (NotificationSts::UnwrapBundleOption(env, bundleOption, option)) { @@ -65,7 +65,7 @@ ani_boolean AniIsNotificationEnabledWithBundleOption(ani_env *env, ani_object bu } int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsNotificationEnabledWithBundleOption -> error, errorCode: %{public}d", externalCode); return ANI_FALSE; @@ -86,13 +86,47 @@ void AniSetNotificationEnable(ani_env *env, ani_object bundleOption, ani_boolean int returncode = Notification::NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(option, deviceId, NotificationSts::AniBooleanToBool(enable)); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniSetNotificationEnable -> error, errorCode: %{public}d", externalCode); } ANS_LOGD("AniSetNotificationEnable end"); } +ani_object AniGetAllNotificationEnabledBundles(ani_env *env) +{ + ANS_LOGD("AniGetAllNotificationEnabledBundles call"); + std::vector bundleOptions = {}; + int returncode = Notification::NotificationHelper::GetAllNotificationEnabledBundles(bundleOptions); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniGetAllNotificationEnabledBundles -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return nullptr; + } + ani_object arrayBundles = NotificationSts::GetAniArrayBundleOption(env, bundleOptions); + if (arrayBundles == nullptr) { + ANS_LOGE("GetAniArrayBundleOption filed,arrayBundles is nullptr"); + NotificationSts::ThrowStsErroWithMsg(env, "GetAniArrayBundleOption ERROR_INTERNAL_ERROR"); + return nullptr; + } + return arrayBundles; +} + +ani_boolean AniIsNotificationEnabledSync(ani_env *env) +{ + ANS_LOGD("AniIsNotificationEnabledSync call"); + bool allowed = false; + int returncode = Notification::NotificationHelper::IsAllowedNotifySelf(allowed); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniIsNotificationEnabledSync -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return NotificationSts::BoolToAniBoolean(false); + } + return NotificationSts::BoolToAniBoolean(allowed); +} + ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId) { ANS_LOGD("AniGetSyncNotificationEnabledWithoutApp call"); @@ -100,12 +134,12 @@ ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double use int returncode = Notification::NotificationHelper::GetSyncNotificationEnabledWithoutApp( static_cast(userId), enabled); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { - OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + if (externalCode != ERR_OK) { ANS_LOGE("AniGetSyncNotificationEnabledWithoutApp -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return NotificationSts::BoolToAniBoolean(false); } - ANS_LOGD("End success, enabled: %{public}d,returncode: %{public}d", enabled, externalCode); + ANS_LOGD("End success, enabled: %{public}d, returncode: %{public}d", enabled, externalCode); return NotificationSts::BoolToAniBoolean(enabled); } @@ -115,12 +149,35 @@ void AniSetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId, an int returncode = Notification::NotificationHelper::SetSyncNotificationEnabledWithoutApp( static_cast(userId), NotificationSts::AniBooleanToBool(enabled)); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { - OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + if (externalCode != ERR_OK) { ANS_LOGE("AniSetSyncNotificationEnabledWithoutApp -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; } ANS_LOGD("AniSetSyncNotificationEnabledWithoutApp end"); } + +void AniDisableNotificationFeature(ani_env *env, ani_boolean disabled, ani_object bundleList) +{ + ANS_LOGD("AniDisableNotificationFeature enter"); + std::vector bundleListStd; + if (NotificationSts::GetStringArrayByAniObj(env, bundleList, bundleListStd) != ANI_OK) { + std::string msg = "Invalid bundleList: must be an array of strings."; + ANS_LOGE("GetStringArrayByAniObj failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + Notification::NotificationDisable param; + param.SetDisabled(NotificationSts::AniBooleanToBool(disabled)); + param.SetBundleList(bundleListStd); + + int returncode = ERR_OK; + returncode = Notification::NotificationHelper::DisableNotificationFeature(param); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniDisableNotificationFeature 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_open_settings.cpp b/frameworks/ets/ani/src/manager/ani_open_settings.cpp new file mode 100644 index 000000000..962e28e77 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_open_settings.cpp @@ -0,0 +1,352 @@ +/* + * 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_open_settings.h" + +#include "ans_log_wrapper.h" +#include "sts_error_utils.h" +#include "inner_errors.h" +#include "notification_helper.h" +#include "ani_common_util.h" +#include "sts_throw_erro.h" +#include "ani_ans_dialog_callback.h" + +namespace OHOS { +namespace NotificationManagerSts { +using namespace OHOS::Notification; +static std::atomic isExist = false; +const int32_t ERR__INVALID_WANT = 1011; +bool GetOpenSettingsInfo(ani_env *env, ani_object content, std::shared_ptr &info) +{ + ANS_LOGD("enter"); + + ani_status status = ANI_OK; + ani_boolean stageMode = ANI_FALSE; + status = OHOS::AbilityRuntime::IsStageContext(env, content, stageMode); + ANS_LOGD("status %{public}d, stageMode %{public}d", status, stageMode); + if (ANI_OK != status || stageMode != ANI_TRUE) { + ANS_LOGE("Only support stage mode"); + std::string msg = "Incorrect parameter types.Only support stage mode."; + ANS_LOGE("sts GetOpenSettingsInfo ERROR_PARAM_INVALID"); + OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); + return false; + } + info->context = OHOS::AbilityRuntime::GetStageModeContext(env, content); + return true; +} + +bool CreateUiExtCallback(ani_env *env, std::shared_ptr& uiExtCallback, + Ace::ModalUIExtensionCallbacks& uiExtensionCallbacks, std::shared_ptr &info, + std::shared_ptr& abilityContext, std::string &bundleName) +{ + if (!uiExtCallback->Init(env, info, StsAsyncCompleteCallbackOpenSettings)) { + ANS_LOGE("error"); + info->errorCode = OHOS::Notification::ERROR_INTERNAL_ERROR; + StsAsyncCompleteCallbackOpenSettings(env, info); + return false; + } + uiExtCallback->SetAbilityContext(abilityContext); + uiExtCallback->SetBundleName(bundleName); + uiExtensionCallbacks = { + .onRelease = + std::bind(&SettingsModalExtensionCallback::OnRelease, uiExtCallback, std::placeholders::_1), + .onResult = std::bind(&SettingsModalExtensionCallback::OnResult, uiExtCallback, + std::placeholders::_1, std::placeholders::_2), + .onReceive = + std::bind(&SettingsModalExtensionCallback::OnReceive, uiExtCallback, std::placeholders::_1), + .onError = std::bind(&SettingsModalExtensionCallback::OnError, uiExtCallback, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), + .onRemoteReady = + std::bind(&SettingsModalExtensionCallback::OnRemoteReady, uiExtCallback, std::placeholders::_1), + .onDestroy = std::bind(&SettingsModalExtensionCallback::OnDestroy, uiExtCallback), + }; + return true; +} + +bool CreateSettingsUIExtension(std::shared_ptr context, std::string &bundleName, + ani_env *env, std::shared_ptr &info) +{ + if (context == nullptr) { + ANS_LOGE("Get context failed"); + return false; + } + + std::shared_ptr abilityContext = + OHOS::AbilityRuntime::Context::ConvertTo(context); + if (abilityContext == nullptr) { + ANS_LOGE("abilityContext is null"); + return false; + } + auto uiContent = abilityContext->GetUIContent(); + if (uiContent == nullptr) { + ANS_LOGE("uiContent is null"); + return false; + } + + AAFwk::Want want; + std::string targetBundleName = "com.ohos.sceneboard"; + std::string targetAbilityName = "NotificationManangerUIExtensionAbility"; + want.SetElementName(targetBundleName, targetAbilityName); + + std::string typeKey = "ability.want.params.uiExtensionType"; + std::string typeValue = "sys/commonUI"; + want.SetParam(typeKey, typeValue); + + auto uiExtCallback = std::make_shared(); + Ace::ModalUIExtensionCallbacks uiExtensionCallbacks; + if (!CreateUiExtCallback(env, uiExtCallback, uiExtensionCallbacks, info, abilityContext, + bundleName)) { + ANS_LOGE("CreateUiExtCallback fail"); + return false; + } + + Ace::ModalUIExtensionConfig config; + config.isProhibitBack = true; + + int32_t sessionId = uiContent->CreateModalUIExtension(want, uiExtensionCallbacks, config); + ANS_LOGI("Create end, sessionId: %{public}d", sessionId); + if (sessionId == 0) { + ANS_LOGE("Create component failed, sessionId is 0"); + return false; + } + uiExtCallback->SetSessionId(sessionId); + return true; +} + +void StsAsyncCompleteCallbackOpenSettings(ani_env *env, std::shared_ptr info) +{ + ANS_LOGD("enter"); + if (env == nullptr) { + ANS_LOGD("env is null"); + return; + } + ani_status status; + int32_t errorCode = ERR_OK; + if (info->errorCode == OHOS::Notification::ERROR_SETTING_WINDOW_EXIST) { + errorCode = OHOS::Notification::ERROR_SETTING_WINDOW_EXIST; + } else if (info->errorCode == ERR__INVALID_WANT) { + errorCode = ERR__INVALID_WANT; + } else { + errorCode = info->errorCode == + ERR_OK ? ERR_OK : CJSystemapi::Notification::ErrorToExternal(info->errorCode); + } + + if (errorCode == ERR_OK) { + ANS_LOGD("Resolve. errorCode %{public}d", errorCode); + ani_object ret = OHOS::AppExecFwk::createInt(env, errorCode); + if (ret == nullptr) { + ANS_LOGD("createInt faild"); + NotificationSts::ThrowStsErroWithMsg(env, ""); + return; + } + if (ANI_OK != (status = env->PromiseResolver_Resolve(info->resolver, static_cast(ret)))) { + ANS_LOGD("PromiseResolver_Resolve faild. status %{public}d", status); + NotificationSts::ThrowStsErroWithMsg(env, ""); + } + } else { + std::string errMsg = OHOS::NotificationSts::FindAnsErrMsg(errorCode); + ANS_LOGD("reject. errorCode %{public}d errMsg %{public}s", errorCode, errMsg.c_str()); + ani_error rejection = static_cast(OHOS::AbilityRuntime::CreateStsError(env, errorCode, errMsg)); + if (ANI_OK != (status = env->PromiseResolver_Reject(info->resolver, rejection))) { + ANS_LOGD("PromiseResolver_Resolve faild. status %{public}d", status); + NotificationSts::ThrowStsErroWithMsg(env, ""); + } + } +} + +ani_object AniOpenNotificationSettings(ani_env *env, ani_object content) +{ + ANS_LOGD("sts AniOpenNotificationSettings call"); + std::shared_ptr info = std::make_shared(); + if (!GetOpenSettingsInfo(env, content, info)) { + ANS_LOGE("sts AniOpenNotificationSettings GetOpenSettingsInfo fail"); + return nullptr; + } + if (info->context == nullptr) { + ANS_LOGE("sts AniOpenNotificationSettings context is null"); + NotificationSts::ThrowStsErroWithMsg(env, ""); + return nullptr; + } + std::string bundleName {""}; + if (isExist.exchange(true)) { + ANS_LOGE("sts AniOpenNotificationSettings ERROR_SETTING_WINDOW_EXIST"); + OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_SETTING_WINDOW_EXIST, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_SETTING_WINDOW_EXIST)); + return nullptr; + } + ani_object aniPromise {}; + ani_resolver aniResolver {}; + if (ANI_OK != env->Promise_New(&aniResolver, &aniPromise)) { + ANS_LOGD("Promise_New faild"); + return nullptr; + } + info->resolver = aniResolver; + bool success = CreateSettingsUIExtension(info->context, bundleName, env, info); + if (success) { + info->errorCode = OHOS::Notification::ERR_ANS_DIALOG_POP_SUCCEEDED; + } else { + info->errorCode = OHOS::Notification::ERROR_INTERNAL_ERROR; + } + if (info->errorCode != ERR_ANS_DIALOG_POP_SUCCEEDED) { + ANS_LOGE("error, code is %{public}d.", info->errorCode); + StsAsyncCompleteCallbackOpenSettings(env, info); + isExist.store(false); + return nullptr; + } + ANS_LOGD("sts AniOpenNotificationSettings end"); + + return aniPromise; +} + +SettingsModalExtensionCallback::SettingsModalExtensionCallback() +{} + +SettingsModalExtensionCallback::~SettingsModalExtensionCallback() +{} + +bool SettingsModalExtensionCallback::Init(ani_env *env, std::shared_ptr info, + StsSettingsModalExtensionCallbackComplete *complete) +{ + if (env == nullptr || info == nullptr || complete == nullptr) { + ANS_LOGE("invalid data"); + return false; + } + ani_status status = ANI_OK; + if ((status = env->GetVM(&vm_)) != ANI_OK) { + ANS_LOGD("GetVM faild. status %{public}d", status); + return false; + } + info_ = info; + complete_ = complete; + return true; +} + +void SettingsModalExtensionCallback::ProcessStatusChanged(int32_t code, bool isAsync) +{ + ANS_LOGD("enter"); + if (vm_ == nullptr || info_ == nullptr || complete_ == nullptr) { + ANS_LOGE("invalid data"); + AnsDialogHostClient::Destroy(); + return; + } + info_->errorCode = code; + + ani_env* env; + ani_status aniResult = ANI_ERROR; + ani_options aniArgs { 0, nullptr }; + if (isAsync) { + aniResult = vm_->AttachCurrentThread(&aniArgs, ANI_VERSION_1, &env); + } else { + aniResult = vm_->GetEnv(ANI_VERSION_1, &env); + } + if (aniResult != ANI_OK) { + ANS_LOGD("AttachCurrentThread error. result: %{public}d.", aniResult); + return; + } + if (complete_) { + complete_(env, info_); + } + if (isAsync && (aniResult = vm_->DetachCurrentThread()) != ANI_OK) { + ANS_LOGD("DetachCurrentThread error. result: %{public}d.", aniResult); + return; + } +} + +/* + * when UIExtensionAbility use terminateSelfWithResult + */ +void SettingsModalExtensionCallback::OnResult(int32_t resultCode, const AAFwk::Want& result) +{ + ANS_LOGD("OnResult"); +} + +/* + * when UIExtensionAbility send message to UIExtensionComponent + */ +void SettingsModalExtensionCallback::OnReceive(const AAFwk::WantParams& receive) +{ + ANS_LOGD("OnReceive"); +} + +/* + * when UIExtensionAbility disconnect or use terminate or process die + * releaseCode is 0 when process normal exit + */ +void SettingsModalExtensionCallback::OnRelease(int32_t releaseCode) +{ + ANS_LOGD("OnRelease"); + ReleaseOrErrorHandle(releaseCode); +} + +/* + * when UIExtensionComponent init or turn to background or destroy UIExtensionAbility occur error + */ +void SettingsModalExtensionCallback::OnError(int32_t code, const std::string& name, const std::string& message) +{ + ANS_LOGE("OnError, code = %{public}d,name = %{public}s, message = %{public}s", code, name.c_str(), message.c_str()); + ReleaseOrErrorHandle(code); + ProcessStatusChanged(code, false); +} + +/* + * when UIExtensionComponent connect to UIExtensionAbility, ModalUIExtensionProxy will init, + * UIExtensionComponent can send message to UIExtensionAbility by ModalUIExtensionProxy + */ +void SettingsModalExtensionCallback::OnRemoteReady(const std::shared_ptr& uiProxy) +{ + ANS_LOGI("OnRemoteReady"); + ProcessStatusChanged(0, true); +} + +/* + * when UIExtensionComponent destructed + */ +void SettingsModalExtensionCallback::OnDestroy() +{ + ANS_LOGI("OnDestroy"); + isExist.store(false); +} + + +void SettingsModalExtensionCallback::SetSessionId(int32_t sessionId) +{ + this->sessionId_ = sessionId; +} + +void SettingsModalExtensionCallback::SetBundleName(std::string bundleName) +{ + this->bundleName_ = bundleName; +} + +void SettingsModalExtensionCallback::SetAbilityContext( + std::shared_ptr abilityContext) +{ + this->abilityContext_ = abilityContext; +} + +void SettingsModalExtensionCallback::ReleaseOrErrorHandle(int32_t code) +{ + ANS_LOGD("ReleaseOrErrorHandle start"); + Ace::UIContent* uiContent = this->abilityContext_->GetUIContent(); + if (uiContent == nullptr) { + ANS_LOGE("uiContent is null"); + return; + } + uiContent->CloseModalUIExtension(this->sessionId_); + ANS_LOGD("ReleaseOrErrorHandle end"); + return; +} +} +} \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_publish.cpp b/frameworks/ets/ani/src/manager/ani_publish.cpp index 225be2cd1..ba7f1f4f8 100644 --- a/frameworks/ets/ani/src/manager/ani_publish.cpp +++ b/frameworks/ets/ani/src/manager/ani_publish.cpp @@ -17,6 +17,7 @@ #include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" +#include "sts_bundle_option.h" #include "sts_throw_erro.h" #include "sts_common.h" #include "sts_request.h" @@ -37,8 +38,7 @@ void AniPublish(ani_env *env, ani_object obj) } int returncode = NotificationHelper::PublishNotification(*notificationRequest); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { - ANS_LOGE("AniPublish error, errorCode: %{public}d", externalCode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } ANS_LOGD("AniPublish end"); @@ -50,18 +50,74 @@ void AniPublishWithId(ani_env *env, ani_object obj, ani_double userId) //NotificationRequest request; std::shared_ptr notificationRequest = std::make_shared(); if (NotificationSts::UnWarpNotificationRequest(env, obj, notificationRequest) != ANI_OK) { - ANS_LOGE("UnWarpNotificationRequest failed"); NotificationSts::ThrowStsErroWithMsg(env, "AniPublishWithId ERROR_INTERNAL_ERROR"); return; } notificationRequest->SetOwnerUserId(static_cast(userId)); int returncode = NotificationHelper::PublishNotification(*notificationRequest); int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != ERR_OK) { ANS_LOGE("AniPublishWithId error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } ANS_LOGD("AniPublishWithId end"); } + +void AniPublishAsBundle(ani_env *env, ani_object request, ani_string representativeBundle, ani_double userId) +{ + ANS_LOGD("AniPublishAsBundle enter"); + std::string bundleStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, representativeBundle, bundleStr)) { + NotificationSts::ThrowStsErroWithMsg(env, "AniPublishAsBundle ERROR_INTERNAL_ERROR"); + return; + } + + std::shared_ptr notificationRequest = std::make_shared(); + if (NotificationSts::UnWarpNotificationRequest(env, request, notificationRequest) != ANI_OK) { + ANS_LOGE("AniPublishAsBundle failed"); + NotificationSts::ThrowStsErroWithMsg(env, "AniPublishAsBundle ERROR_INTERNAL_ERROR"); + return; + } + notificationRequest->SetOwnerUserId(static_cast(userId)); + notificationRequest->SetOwnerBundleName(bundleStr); + int returncode = NotificationHelper::PublishNotification(*notificationRequest); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniPublishAsBundle: PublishNotificationerror, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + + ANS_LOGD("AniPublishAsBundle end"); +} + +void AniPublishAsBundleWithBundleOption(ani_env *env, ani_object representativeBundle, ani_object request) +{ + ANS_LOGE("AniPublishAsBundleWithBundleOption enter"); + std::shared_ptr notificationRequest = std::make_shared(); + if (NotificationSts::UnWarpNotificationRequest(env, request, notificationRequest) != ANI_OK) { + NotificationSts::ThrowStsErroWithMsg(env, "AniPublishAsBundleWithBundleOption ERROR_INTERNAL_ERROR"); + return; + } + + BundleOption option; + if (NotificationSts::UnwrapBundleOption(env, representativeBundle, option) != true) { + NotificationSts::ThrowStsErroWithMsg(env, "UnwrapBundleOption ERROR_INTERNAL_ERROR"); + return; + } + + ANS_LOGD("AniPublishAsBundleWithBundleOption: bundle %{public}s uid: %{public}d", + option.GetBundleName().c_str(), option.GetUid()); + notificationRequest->SetOwnerBundleName(option.GetBundleName()); + notificationRequest->SetOwnerUid(option.GetUid()); + notificationRequest->SetIsAgentNotification(true); + + int returncode = NotificationHelper::PublishNotification(*notificationRequest); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniPublishAsBundleWithBundleOption error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniPublishAsBundleWithBundleOption end"); +} } // namespace NotificationManagerSts } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_remove_group.cpp b/frameworks/ets/ani/src/manager/ani_remove_group.cpp new file mode 100644 index 000000000..b916af197 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_remove_group.cpp @@ -0,0 +1,53 @@ +/* + * 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_remove_group.h" + +#include "ans_log_wrapper.h" +#include "sts_error_utils.h" +#include "inner_errors.h" +#include "notification_helper.h" +#include "sts_common.h" +#include "sts_throw_erro.h" +#include "sts_bundle_option.h" +#include "notification_helper.h" + +namespace OHOS { +namespace NotificationManagerSts { + +void AniRemoveGroupByBundle(ani_env *env, ani_object bundleOption, ani_string groupName) +{ + ANS_LOGD("AniRemoveGroupByBundle call"); + OHOS::Notification::NotificationBundleOption option; + if (!OHOS::NotificationSts::UnwrapBundleOption(env, bundleOption, option)) { + NotificationSts::ThrowStsErroWithMsg(env, "sts AniRemoveGroupByBundle ERROR_INTERNAL_ERROR"); + return ; + } + std::string groupNameStr = ""; + ani_status status = NotificationSts::GetStringByAniString(env, groupName, groupNameStr); + if (status != ANI_OK) { + NotificationSts::ThrowStsErroWithMsg(env, "sts AniRemoveGroupByBundle ERROR_INTERNAL_ERROR"); + return ; + } + int returncode = OHOS::Notification::NotificationHelper::RemoveGroupByBundle(option, groupNameStr); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniRemoveGroupByBundle -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniRemoveGroupByBundle end"); +} +} +} \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_sync_config.cpp b/frameworks/ets/ani/src/manager/ani_sync_config.cpp new file mode 100644 index 000000000..5a05c28f7 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_sync_config.cpp @@ -0,0 +1,61 @@ +/* + * 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_sync_config.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 { +const double RESULT_OK = 0.0; +const double RESULT_FAILED = 1.0; + +ani_double AniSetAdditionalConfig(ani_env *env, ani_string key, ani_string value) +{ + ANS_LOGD("sts setAdditionalConfig call"); + if (env == nullptr || key == nullptr) { + ANS_LOGE("Invalid env or key is null"); + return RESULT_FAILED; + } + std::string keyStr; + if (NotificationSts::GetStringByAniString(env, key, keyStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return RESULT_FAILED; + } + std::string valueStr; + if (NotificationSts::GetStringByAniString(env, value, valueStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return RESULT_FAILED; + } + int returncode = Notification::NotificationHelper::SetAdditionConfig(keyStr, valueStr); + int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("setAdditionalConfig -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return RESULT_FAILED; + } + return RESULT_OK; +} +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_bundle_option.cpp b/frameworks/ets/ani/src/sts_bundle_option.cpp index ecc112188..5f89307c8 100644 --- a/frameworks/ets/ani/src/sts_bundle_option.cpp +++ b/frameworks/ets/ani/src/sts_bundle_option.cpp @@ -44,6 +44,37 @@ bool UnwrapBundleOption(ani_env *env, ani_object obj, Notification::Notification return true; } +ani_object GetAniArrayBundleOption(ani_env* env, + const std::vector &bundleOptions) +{ + ANS_LOGD("GetAniArrayActionButton call"); + if (env == nullptr) { + ANS_LOGE("GetAniArrayActionButton failed, has nullptr"); + return nullptr; + } + ani_object arrayObj = newArrayClass(env, bundleOptions.size()); + if (arrayObj == nullptr) { + ANS_LOGE("GetAniArrayActionButton: arrayObj is nullptr"); + return nullptr; + } + ani_size index = 0; + for (auto &option : bundleOptions) { + std::shared_ptr optSp = std::make_shared(option); + ani_object item; + if (!WrapBundleOption(env, optSp, item) || item == nullptr) { + ANS_LOGE("GetAniArrayActionButton: item is nullptr"); + return nullptr; + } + if (ANI_OK != env->Object_CallMethodByName_Void(arrayObj, "$_set", "ILstd/core/Object;:V", index, item)) { + ANS_LOGE("GetAniArrayActionButton: Object_CallMethodByName_Void failed"); + return nullptr; + } + index ++; + } + ANS_LOGD("GetAniArrayActionButton end"); + return arrayObj; +} + bool UnwrapArrayBundleOption(ani_env *env, ani_ref arrayObj, std::vector& options) { diff --git a/frameworks/ets/ani/src/sts_disturb_mode.cpp b/frameworks/ets/ani/src/sts_disturb_mode.cpp index a24e389b8..1aca78724 100644 --- a/frameworks/ets/ani/src/sts_disturb_mode.cpp +++ b/frameworks/ets/ani/src/sts_disturb_mode.cpp @@ -88,5 +88,74 @@ bool UnwrapArrayDoNotDisturbProfile(ani_env *env, ani_object arrayObj, ANS_LOGD("UnwrapArrayDoNotDisturbProfile end"); return true; } + +bool WrapProfileTrustList(ani_env* env, sptr profile, + ani_object &outObj) +{ + ani_status status = ANI_OK; + const auto& trustList = profile->GetProfileTrustList(); + if (trustList.empty()) { + ANS_LOGE("WrapProfileTrustList trustlist is nullptr"); + return true; + } + ani_object arrayObj = newArrayClass(env, trustList.size()); + if (arrayObj == nullptr) { + ANS_LOGE("WrapProfileTrustList Failed to create trustlist array"); + return false; + } + + size_t index = 0; + for (const auto& bundle : trustList) { + auto bundlePtr = std::make_shared(bundle); + ani_object bundleObj = nullptr; + if (!WrapBundleOption(env, bundlePtr, bundleObj)) { + ANS_LOGE("WrapProfileTrustList WrapBundleOption failed"); + return false; + } + if (ANI_OK != (status = env->Object_CallMethodByName_Void(arrayObj, "$_set", + "ILstd/core/Object;:V", index, bundleObj))) { + ANS_LOGE("WrapProfileTrustList set object faild. index %{public}d status %{public}d", + index, status); + return false; + } + index++; + } + ani_ref arrayRef = arrayObj; + if (!SetPropertyByRef(env, outObj, "trustlist", arrayRef)) { + ANS_LOGE("WrapProfileTrustList Failed to set trustlist property"); + return false; + } + return true; +} + +bool WrapDoNotDisturbProfile(ani_env* env, sptr profile, + ani_object &outObj) +{ + ani_status status = ANI_OK; + ani_class cls = nullptr; + if (env == nullptr) { + ANS_LOGE("WrapDoNotDisturbProfile: Invalid input parameters"); + return false; + } + const char* className = "L@ohos/notificationManager/notificationManager/DoNotDisturbProfileInner;"; + if (!CreateClassObjByClassName(env, className, cls, outObj) || outObj == nullptr) { + ANS_LOGE("WrapDoNotDisturbProfile: Failed to create profile class object"); + return false; + } + ani_double id = static_cast(profile->GetProfileId()); + if (ANI_OK != (status = env->Object_SetPropertyByName_Double(outObj, "id", id))) { + ANS_LOGE("WrapDoNotDisturbProfile ddd set reason faild. status %{public}d", status); + return false; + } + if (!SetPropertyOptionalByString(env, outObj, "name", profile->GetProfileName())) { + ANS_LOGE("WrapDoNotDisturbProfile: set name failed"); + return false; + } + if (!WrapProfileTrustList(env, profile, outObj)) { + ANS_LOGE("WrapDoNotDisturbProfile: set trustList failed"); + return false; + } + return true; +} } // namespace NotificationSts } // OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_notification_manager.cpp b/frameworks/ets/ani/src/sts_notification_manager.cpp index afc5f6c1b..acde5ca6a 100644 --- a/frameworks/ets/ani/src/sts_notification_manager.cpp +++ b/frameworks/ets/ani/src/sts_notification_manager.cpp @@ -218,6 +218,29 @@ bool StsSlotLevelUtils::StsToC(const STSSlotLevel inLevel, SlotLevel &outLevel) return true; } +bool StsDoNotDisturbTypeUtils::StsToC(const STSDoNotDisturbType inType, + OHOS::Notification::NotificationConstant::DoNotDisturbType &outType) +{ + switch (inType) { + case STSDoNotDisturbType::TYPE_NONE: + outType = Notification::NotificationConstant::DoNotDisturbType::NONE; + break; + case STSDoNotDisturbType::TYPE_ONCE: + outType = Notification::NotificationConstant::DoNotDisturbType::ONCE; + break; + case STSDoNotDisturbType::TYPE_DAILY: + outType = Notification::NotificationConstant::DoNotDisturbType::DAILY; + break; + case STSDoNotDisturbType::TYPE_CLEARLY: + outType = Notification::NotificationConstant::DoNotDisturbType::CLEARLY; + break; + default: + ANS_LOGE("STSDoNotDisturbType %{public}d is an invalid value", inType); + return false; + } + return true; +} + bool StsRemindTypeUtils::StsToC(const STSRemindType inType, RemindType &outType) { switch (inType) { @@ -428,6 +451,19 @@ bool ContentTypeCToEts(ani_env *env, ContentType contentType, ani_enum_item &enu return true; } +bool DoNotDisturbTypeEtsToC(ani_env *env, ani_enum_item enumItem, + Notification::NotificationConstant::DoNotDisturbType &doNotDisturbType) +{ + ANS_LOGD("DoNotDisturbTypeEtsToC call"); + STSDoNotDisturbType stsDoNotDisturbType = TYPE_NONE; + if (!EnumConvertAniToNative(env, enumItem, stsDoNotDisturbType) + || !StsDoNotDisturbTypeUtils::StsToC(stsDoNotDisturbType, doNotDisturbType)) { + ANS_LOGE("DoNotDisturbTypeEtsToC failed"); + return false; + } + return true; +} + bool DeviceRemindTypeCToEts(ani_env *env, RemindType remindType, ani_enum_item &enumItem) { STSRemindType stsRemindType = STSRemindType::IDLE_DONOT_REMIND; @@ -676,5 +712,60 @@ bool WarpNotificationCheckInfo( outObj = obj; return true; } + +void GetDoNotDisturbDateByDoNotDisturbType(ani_env *env, ani_object obj, NotificationDoNotDisturbDate &doNotDisturbDate) +{ + ANS_LOGD("GetDoNotDisturbDateByDoNotDisturbType start"); + if (env == nullptr || obj == nullptr) { + ANS_LOGE("GetDoNotDisturbDateByDoNotDisturbType failed, has nullptr"); + return; + } + ani_status status = ANI_ERROR; + ani_boolean isUndefined = ANI_OK; + ani_ref doNotDisturbTypeRef = {}; + if (ANI_OK != (status = GetPropertyRef(env, obj, "doNotDisturbType", isUndefined, doNotDisturbTypeRef)) + || isUndefined == ANI_TRUE || doNotDisturbTypeRef == nullptr) { + ANS_LOGE("GetDoNotDisturbDateByDoNotDisturbType: get Ref failed"); + return; + } + NotificationConstant::DoNotDisturbType type = NotificationConstant::DoNotDisturbType::NONE; + + if (!DoNotDisturbTypeEtsToC(env, static_cast(doNotDisturbTypeRef), type)) { + ANS_LOGE("GetDoNotDisturbDateByDoNotDisturbType: SlotTypeEtsToC failed"); + return; + } + doNotDisturbDate.SetDoNotDisturbType(type); + ANS_LOGD("GetDoNotDisturbDateByDoNotDisturbType end"); +} + +bool UnWarpNotificationDoNotDisturbDate( + ani_env* env, + const ani_object doNotDisturbDateObj, + NotificationDoNotDisturbDate& doNotDisturbDate) +{ + ani_boolean isUndefined = false; + ani_double mDouble = 0.0; + if (env == nullptr) { + ANS_LOGE("UnWarpNotificationDoNotDisturbDate: Invalid input parameters"); + return false; + } + GetDoNotDisturbDateByDoNotDisturbType(env, doNotDisturbDateObj, doNotDisturbDate); + + if (ANI_OK == GetPropertyDouble(env, doNotDisturbDateObj, "begin", isUndefined, mDouble) + && isUndefined == ANI_FALSE) { + doNotDisturbDate.SetBeginDate(static_cast(mDouble)); + } + if (ANI_OK == GetPropertyDouble(env, doNotDisturbDateObj, "end", isUndefined, mDouble) + && isUndefined == ANI_FALSE) { + doNotDisturbDate.SetEndDate(static_cast(mDouble)); + } + if (doNotDisturbDate.GetBeginDate() >= doNotDisturbDate.GetEndDate()) { + ANS_LOGE("Invalid time range: begin(%{public}lld) >= end(%{public}lld)", + doNotDisturbDate.GetBeginDate(), doNotDisturbDate.GetEndDate()); + return false; + } + ANS_LOGD("Successfully parsed DoNotDisturbDate"); + return true; +} } // namespace NotificationSts } // OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_request.cpp b/frameworks/ets/ani/src/sts_request.cpp index ed25b307b..ed3de90e9 100644 --- a/frameworks/ets/ani/src/sts_request.cpp +++ b/frameworks/ets/ani/src/sts_request.cpp @@ -25,6 +25,8 @@ #include "ans_log_wrapper.h" #include "want_params.h" #include "ani_common_want.h" +#include "sts_bundle_option.h" +#include "sts_subscribe.h" namespace OHOS { namespace NotificationSts { @@ -1146,10 +1148,6 @@ bool WarpNotificationRequest(ani_env *env, const OHOS::Notification::Notificatio ani_object GetAniNotificationRequestArray(ani_env *env, std::vector> requests) { - if (requests.empty()) { - ANS_LOGE("actionButtons is empty"); - return nullptr; - } ani_object arrayObj = newArrayClass(env, requests.size()); if (arrayObj == nullptr) { ANS_LOGE("arrayObj is nullptr"); @@ -1175,10 +1173,6 @@ ani_object GetAniNotificationRequestArray(ani_env *env, std::vector> requests) { - if (requests.empty()) { - ANS_LOGE("actionButtons is empty"); - return nullptr; - } ani_object arrayObj = newArrayClass(env, requests.size()); if (arrayObj == nullptr) { ANS_LOGE("arrayObj is nullptr"); @@ -1285,5 +1279,44 @@ bool UnWarpNotificationCheckRequest(ani_env *env, ani_object obj, sptr(bundleObj), filter.bundle)) { + ANS_LOGE("UnWarpNotificationFilter:UnwrapBundleOption failed"); + return false; + } + + ani_ref notificationKeyObj = {}; + if (ANI_OK != (status = GetPropertyRef(env, obj, "notificationKey", isUndefined, notificationKeyObj)) + || isUndefined == ANI_TRUE) { + ANS_LOGE("UnWarpNotificationFilter:get notificationKey failed. status %{public}d", status); + return false; + } + + if (OHOS::NotificationSts::UnWarpNotificationKey(env, static_cast(notificationKeyObj), + filter.notificationKey)) { + ANS_LOGD("UnWarpNotificationFilter:UnWarpNotificationKey label is undefined"); + } + + if (ANI_OK != (status = GetPropertyStringArray(env, obj, "extraInfoKeys", isUndefined, filter.extraInfoKeys))) { + ANS_LOGD("UnWarpNotificationFilter:get extraInfoKeysObj failed. status %{public}d", status); + } + return true; +} } // namespace NotificationSts } // OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_subscribe.cpp b/frameworks/ets/ani/src/sts_subscribe.cpp index 441e053c1..1fd46299f 100644 --- a/frameworks/ets/ani/src/sts_subscribe.cpp +++ b/frameworks/ets/ani/src/sts_subscribe.cpp @@ -609,13 +609,13 @@ bool SubscriberInstanceManager::Subscribe(ani_env *env, ani_object subscriber, a return false; } } - ErrCode status = 0; + ErrCode status = ERR_OK; if (!isInfoUndefine) { status = NotificationHelper::SubscribeNotification(stsSubscriber, SubscribeInfo); } else { status = NotificationHelper::SubscribeNotification(stsSubscriber); } - if (status != 0) { + if (status != ERR_OK) { int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(status); externalErrorCode = (externalErrorCode == CJSystemapi::Notification::SUCCESS_CODE) ? status : externalErrorCode; @@ -647,7 +647,7 @@ bool SubscriberInstanceManager::UnSubscribe(ani_env *env, ani_object subscriber) bool ret = AddDeletingSubscriber(stsSubscriber); if (ret) { int32_t status = NotificationHelper::UnSubscribeNotification(stsSubscriber); - if (status != 0) { + if (status != ERR_OK) { int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(status); externalErrorCode = (externalErrorCode == CJSystemapi::Notification::SUCCESS_CODE) ? status : externalErrorCode; @@ -665,6 +665,43 @@ bool SubscriberInstanceManager::UnSubscribe(ani_env *env, ani_object subscriber) return true; } +bool SubscriberInstanceManager::SubscribeSelf(ani_env *env, ani_object subscriber) +{ + ANS_LOGD("enter"); + bool isSubscribeUndefine = IsUndefine(env, subscriber); + if (isSubscribeUndefine) { + ANS_LOGD("subscriber is undefine"); + OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, "subscriber is undefine"); + return false; + } + std::shared_ptr stsSubscriber = nullptr; + if (!HasNotificationSubscriber(env, subscriber, stsSubscriber)) { + if (!GetNotificationSubscriber(env, subscriber, stsSubscriber)) { + ANS_LOGD("GetNotificationSubscriber faild"); + OHOS::AbilityRuntime::ThrowStsError(env, ERROR_INTERNAL_ERROR, "GetNotificationSubscriber faild"); + return false; + } + if (!AddSubscriberInstancesInfo(env, stsSubscriber)) { + ANS_LOGD("AddSubscriberInstancesInfo faild"); + OHOS::AbilityRuntime::ThrowStsError(env, ERROR_INTERNAL_ERROR, "GetNotificationSubscriber faild"); + return false; + } + } + ErrCode status = ERR_OK; + status = NotificationHelper::SubscribeNotificationSelf(stsSubscriber); + if (status != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(status); + externalErrorCode = + (externalErrorCode == CJSystemapi::Notification::SUCCESS_CODE) ? status : externalErrorCode; + ANS_LOGD("SubscribeNotificationSelf faild. status %{public}d ErrorToExternal %{public}d", + status, externalErrorCode); + std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); + return false; + } + return true; +} + bool GetDoubleValueByClassName( ani_env *env, ani_object param, const char *className, const char *name, ani_double &value) { diff --git a/frameworks/ets/ani/src/subscribe/ani_remove.cpp b/frameworks/ets/ani/src/subscribe/ani_remove.cpp index be660d9fb..8db7371bd 100644 --- a/frameworks/ets/ani/src/subscribe/ani_remove.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_remove.cpp @@ -130,5 +130,46 @@ void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reason OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } } + +void AniRemoveAllForBundle(ani_env *env, ani_object bundle) +{ + ANS_LOGD("removeAll enter"); + int retcode = ERR_OK; + bool isForBundleUndefine = NotificationSts::IsUndefine(env, bundle); + if (isForBundleUndefine) { + retcode = NotificationHelper::RemoveNotifications(); + std::string msg = "IsUndefine falid"; + ANS_LOGE("IsUndefine is falid"); + OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); + return; + } + 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 AniRemoveAllForUserId(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..0bc5efab4 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) { @@ -90,6 +93,12 @@ void AniUnSubscribe(ani_env *env, ani_object obj) OHOS::NotificationSts::SubscriberInstanceManager::GetInstance()->UnSubscribe(env, obj); } +void AniSubscribeSelf(ani_env *env, ani_object obj) +{ + ANS_LOGD("StsSubscribeSelf enter"); + OHOS::NotificationSts::SubscriberInstanceManager::GetInstance()->SubscribeSelf(env, obj); +} + void AniSubScribeRegistryInit(ani_env *env) { ANS_LOGD("AniSubScribeRegistryInit call"); @@ -101,7 +110,8 @@ void AniSubScribeRegistryInit(ani_env *env) } std::array methods = { - ani_native_function {"nativeRemove", REMOVE_FOR_BUNDLE_SIGNATURE, reinterpret_cast(AniRemoveForBundle)}, + ani_native_function {"nativeRemove", + REMOVE_FOR_BUNDLE_SIGNATURE, reinterpret_cast(AniRemoveForBundle)}, ani_native_function {"nativeRemove", REMOVE_FOR_HASHCODE_SIGNATURE, reinterpret_cast(AniRemoveForHashCode)}, ani_native_function {"nativeRemove", @@ -110,6 +120,11 @@ 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 {"nativeSubscribeSelf", UNSUBSCRIBE_SIGNATURE, reinterpret_cast(AniSubscribeSelf)}, + ani_native_function {"nativeRemoveAllForBundle", + REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE, reinterpret_cast(AniRemoveAllForBundle)}, + ani_native_function {"nativeRemoveAllForUserId", + REMOVEALL_FOR_USERID_STGNATURE,reinterpret_cast(AniRemoveAllForUserId)}, }; 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 ee2307572..f621dcb2f 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -27,6 +27,7 @@ import { NotificationTemplate } from 'notification.notificationTemplate'; import { DistributedOptions } from 'notification.notificationRequest'; import { NotificationLiveViewContent } from 'notification.notificationContent'; import { UnifiedGroupInfo } from 'notification.notificationRequest'; +import { NotificationFilter } from 'notification.notificationRequest'; import image from '@ohos.multimedia.image'; type ResolveCallback = (data: T) => void; @@ -137,10 +138,13 @@ export default namespace notificationManager { export native function nativeDisplayBadge(bundle: BundleOption, enable: boolean): void; export native function nativeIsBadgeDisplayed(bundle: BundleOption): boolean; + export native function nativeSetBadgeNumber(badgeNumber: number): void; + export native function nativeSetBadgeNumberByBundle(bundle: BundleOption, badgeNumber: number): void; export native function nativeGetActiveNotificationCount(): number; export native function nativeGetActiveNotifications():Array; export native function nativeGetAllActiveNotifications():Array; + export native function nativeGetActiveNotificationByFilter(filter: NotificationFilter): NotificationRequest; export native function nativeAddDoNotDisturbProfile(templates: Array): void; export native function nativeRemoveDoNotDisturbProfile(templates: Array): void; @@ -167,6 +171,10 @@ 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 nativeGetAllNotificationEnabledBundles(): Array; + export native function nativeIsNotificationEnabledSync(): boolean; + + export native function nativeRemoveGroupByBundle(bundle: BundleOption, groupName: string): void; export native function nativeAddSlotByNotificationSlot(slot: NotificationSlot): void; export native function nativeAddSlotBySlotType(type: SlotType): void; @@ -186,6 +194,40 @@ export default namespace notificationManager { export native function nativeSetSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): void; export native function nativeGetSyncNotificationEnabledWithoutApp(userId: number): boolean; + export native function nativePublishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): void; + export native function nativePublishAsBundleWithBundleOption(representativeBundle: BundleOption, request: NotificationRequest): void; + export native function nativeCancelAsBundle(id: number, representativeBundle: string, userId: number): void; + export native function nativeCancelAsBundleWithBundleOption(representativeBundle: BundleOption, id: number): void; + export native function nativeCancelGroup(groupName: string): void; + export native function nativeSetDoNotDisturbDate(date: DoNotDisturbDate): void; + export native function nativeSetDoNotDisturbDateWithId(date: DoNotDisturbDate, userId: number): void; + export native function nativeGetDoNotDisturbDate(): DoNotDisturbDate; + export native function nativeGetDoNotDisturbDateWithId(userId: number): DoNotDisturbDate; + export native function nativeIsSupportDoNotDisturbMode(): boolean; + export native function nativeGetDoNotDisturbProfile(id: number): DoNotDisturbProfile; + + export native function nativeOpenNotificationSettings(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(doNotDisturbDate: DoNotDisturbDate): BusinessError + { + let error: BusinessError = successCallbackError + if (doNotDisturbDate == null) { + error = errorParamInvalid + return error; + } + return error; + } + function isInvalidParameter(slot: NotificationSlot): BusinessError { if (slot == null) { @@ -222,22 +264,13 @@ export default namespace notificationManager { function isInvalidParameter(bundle: BundleOption): BusinessError { - let error: BusinessError = { - code: 0, - message: "" - } + let error: BusinessError = successCallbackError if (bundle == null) { - error = { - code: 401, - message: "BundleOption must be not Null" - } + error = errorParamInvalid return error; } if (bundle.bundle == null || bundle.bundle?.length === 0) { - error = { - code: 401, - message: "Incorrect parameter types. The type of bundle must be string." - } + error = errorParamInvalid return error; } return error; @@ -245,24 +278,33 @@ export default namespace notificationManager { function isInvalidParameter(option: ButtonOptions): BusinessError { - let error: BusinessError = { - code: 0, - message: "" - } + let error: BusinessError = successCallbackError if (option == null) { - error = { - code: 401, - message: "ButtonOptions must be not Null" - } + error = errorParamInvalid return error; } if (option.buttonName == null || option.buttonName?.length === 0) { - error = { - code: 401, - message: "Incorrect parameter types. The type of buttonName must be string." - } + error = errorParamInvalid + return error; + } + return error; + } + function isInvalidParameter(filter: NotificationFilter): BusinessError + { + let error: BusinessError = successCallbackError; + if (filter == null) { + return errorParamInvalid; + } + error = isInvalidParameter(filter.bundle); + if (error.code != 0) { return error; } + if (filter.notificationKey?.label !== undefined && filter.notificationKey?.label?.trim() === '') { + return errorParamInvalid; + } + if (filter?.extraInfoKeys !== undefined && filter?.extraInfoKeys?.length === 0) { + return errorParamInvalid; + } return error; } function isInvalidContent(normal?: NotificationBasicContent): boolean @@ -449,22 +491,13 @@ export default namespace notificationManager { } function isInvalidParameter(request: NotificationRequest): BusinessError { - let error: BusinessError = { - code: 0, - message: "" - } + let error: BusinessError = successCallbackError if (request == null) { - error = { - code: 401, - message: "request must be not Null" - } + error = errorParamInvalid return error; } if (request.content == null || request.content == undefined) { - error = { - code: 401, - message: "request.content must be not Null" - } + error = errorParamInvalid return error; } if (request.content?.normal !== undefined && !isInvalidContent(request.content.normal)) { @@ -562,7 +595,7 @@ export default namespace notificationManager { export function getSlotNumByBundle(bundle: BundleOption): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -579,7 +612,7 @@ export default namespace notificationManager { export function getSlotNumByBundle(bundle: BundleOption, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { @@ -599,11 +632,11 @@ export default namespace notificationManager { export function setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let slotError: BusinessError = isInvalidParameter(slot); - if (slotError.code !== 0) { + if (slotError.code !== ERROR_OK) { throw slotError; } if (callback == null) { @@ -621,11 +654,11 @@ export default namespace notificationManager { export function setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let slotError: BusinessError = isInvalidParameter(slot); - if (slotError.code !== 0) { + if (slotError.code !== ERROR_OK) { throw slotError; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -783,7 +816,7 @@ export default namespace notificationManager { export function addSlot(slot: NotificationSlot): Promise { let slotError: BusinessError = isInvalidParameter(slot); - if (slotError.code !== 0) { + if (slotError.code !== ERROR_OK) { throw slotError; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -799,7 +832,7 @@ export default namespace notificationManager { export function addSlot(slot: NotificationSlot, callback: AsyncCallback): void { let slotError: BusinessError = isInvalidParameter(slot); - if (slotError.code !== 0) { + if (slotError.code !== ERROR_OK) { throw slotError; } if (callback == null) { @@ -844,7 +877,7 @@ export default namespace notificationManager { export function setNotificationEnable(bundle: BundleOption, enable: boolean): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -861,13 +894,11 @@ export default namespace notificationManager { export function setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { - error.code = 401; - error.message = "callback must be not null"; - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): void => { return nativeSetNotificationEnable(bundle, enable); }); p.then((data: NullishType): void => { @@ -882,13 +913,11 @@ export default namespace notificationManager { export function isNotificationEnabled(bundleOption: BundleOption, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundleOption); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { - error.code = 401; - error.message = "callback must be not null"; - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): boolean => { return nativeIsNotificationEnabledWithBundleOption(bundleOption); }); p.then((data: NullishType): void => { @@ -905,7 +934,7 @@ export default namespace notificationManager { export function isNotificationEnabled(bundleOption: BundleOption): Promise { let error: BusinessError = isInvalidParameter(bundleOption); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -992,13 +1021,11 @@ export default namespace notificationManager { callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { - error.code = 401; - error.message = "callback must be not null"; - throw error; + throw errorParamInvalid; } let p = taskpool.execute( (): void => { return nativeSetNotificationEnableSlotWithForce(bundle, type, enable, isForceControl); @@ -1016,7 +1043,7 @@ export default namespace notificationManager { bundle: BundleOption, type: SlotType, enable: boolean, isForceControl?: boolean): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let forceControl: boolean = false; @@ -1040,13 +1067,11 @@ export default namespace notificationManager { bundle: BundleOption, type: SlotType, enable: boolean, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { - error.code = 401; - error.message = "callback must be not null"; - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): void => { return nativeSetNotificationEnableSlot(bundle, type, enable); }); p.then((data: NullishType): void => { @@ -1061,7 +1086,7 @@ export default namespace notificationManager { export function isNotificationSlotEnabled(bundle: BundleOption, type: SlotType): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1079,13 +1104,11 @@ export default namespace notificationManager { export function isNotificationSlotEnabled(bundle: BundleOption, type: SlotType, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { - error.code = 401; - error.message = "callback must be not null"; - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): boolean => { return nativeIsNotificationSlotEnabled(bundle, type); }); p.then((data: NullishType): void => { @@ -1102,13 +1125,11 @@ export default namespace notificationManager { export function getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback>): void { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { - error.code = 401; - error.message = "callback must be not null"; - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): Array => { return nativeGetSlotsByBundle(bundle); }); p.then((data: NullishType): void => { @@ -1125,7 +1146,7 @@ export default namespace notificationManager { export function getSlotsByBundle(bundle: BundleOption): Promise> { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise>( @@ -1143,7 +1164,7 @@ export default namespace notificationManager { export function setSlotFlagsByBundle(bundle: BundleOption, slotFlags: number): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1159,7 +1180,7 @@ export default namespace notificationManager { export function getSlotFlagsByBundle(bundle: BundleOption): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1176,13 +1197,11 @@ export default namespace notificationManager { export function publish(request: NotificationRequest, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(request); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { - error.code = 401; - error.message = "callback must be not null"; - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): void => { return nativePublish(request); }); p.then((data: NullishType): void => { @@ -1196,7 +1215,7 @@ export default namespace notificationManager { export function publish(request: NotificationRequest): Promise { let error: BusinessError = isInvalidParameter(request); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1212,13 +1231,11 @@ export default namespace notificationManager { export function publish(request: NotificationRequest, userId: number, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(request); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { - error.code = 401; - error.message = "callback must be not null"; - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): void => { return nativePublishWithUserId(request, userId); }); p.then((data: NullishType): void => { @@ -1232,7 +1249,7 @@ export default namespace notificationManager { export function publish(request: NotificationRequest, userId: number): Promise { let error: BusinessError = isInvalidParameter(request); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1250,11 +1267,11 @@ export default namespace notificationManager { bundle: BundleOption, notificationId: number, buttonOptions: ButtonOptions): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } error = isInvalidParameter(buttonOptions); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1288,11 +1305,7 @@ export default namespace notificationManager { export function removeDoNotDisturbProfile(templates: Array): Promise { if (!templates || templates.length === 0) { - let error: BusinessError = { - code: 401, - message: "templates must be not null" - } - throw error; + throw errorParamInvalid; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { return nativeRemoveDoNotDisturbProfile(templates); }); @@ -1307,11 +1320,7 @@ export default namespace notificationManager { export function addDoNotDisturbProfile(templates: Array): Promise { if (!templates || templates.length === 0) { - let error: BusinessError = { - code: 401, - message: "templates must be not null" - } - throw error; + throw errorParamInvalid; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { return nativeAddDoNotDisturbProfile(templates); }); @@ -1326,11 +1335,7 @@ export default namespace notificationManager { export function getAllActiveNotifications(callback: AsyncCallback>): void { if (!callback) { - let error: BusinessError = { - code: 401, - message: "callback must be not null" - } - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): Array => { return nativeGetAllActiveNotifications(); }); p.then((data: NullishType): void => { @@ -1374,11 +1379,7 @@ export default namespace notificationManager { export function getActiveNotifications(callback: AsyncCallback>): void { if (!callback) { - let error: BusinessError = { - code: 401, - message: "callback must be not null" - } - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): Array => { return nativeGetActiveNotifications(); }); p.then((data: NullishType): void => { @@ -1392,6 +1393,22 @@ export default namespace notificationManager { }) } + export function getActiveNotificationCount(callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): number => { return nativeGetActiveNotificationCount(); }); + p.then((data: NullishType): void => { + let ret : number = data as number; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let err: BusinessError = error as BusinessError; + callback(err, -1); + }) + } + export function getActiveNotificationCount(): Promise { let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback):void => { let p = taskpool.execute((): number => { return nativeGetActiveNotificationCount(); }); @@ -1407,13 +1424,11 @@ export default namespace notificationManager { export function displayBadge(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { - error.code = 401; - error.message = "callback must be not null"; - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): void => { return nativeDisplayBadge(bundle, enable); }); p.then((e: NullishType): void => { @@ -1427,7 +1442,7 @@ export default namespace notificationManager { export function displayBadge(bundle: BundleOption, enable: boolean): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1443,7 +1458,7 @@ export default namespace notificationManager { export function isBadgeDisplayed(bundle: BundleOption, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let p = taskpool.execute((): boolean => { return nativeIsBadgeDisplayed(bundle); }); @@ -1460,7 +1475,7 @@ export default namespace notificationManager { export function isBadgeDisplayed(bundle: BundleOption): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1477,7 +1492,7 @@ export default namespace notificationManager { export function cancel(bundle: BundleOption, id: number): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1493,11 +1508,7 @@ export default namespace notificationManager { export function cancel(id: number, label?: string): Promise { if (label == null || label?.length === 0) { - let error: BusinessError = { - code: 401, - message: "Incorrect parameter types. The type of label must be string." - } - throw error; + throw errorParamInvalid; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { return nativeCancelWithIdOptionalLabel(id, label); }); @@ -1512,11 +1523,7 @@ export default namespace notificationManager { export function cancel(id: number, label: string, callback: AsyncCallback): void { if (label == null || label?.length === 0) { - let error: BusinessError = { - code: 401, - message: "Incorrect parameter types. The type of label must be string." - } - throw error; + throw errorParamInvalid; } if (callback == null) { throw errorParamInvalid; @@ -1533,11 +1540,7 @@ export default namespace notificationManager { export function cancel(id: number, callback: AsyncCallback): void { if (callback == null) { - let error: BusinessError = { - code: 410, - message : "callback must be not null" - } - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): void => { return nativeCancelWithId(id); }); p.then((data: NullishType): void => { @@ -1563,11 +1566,7 @@ export default namespace notificationManager { export function cancelAll(callback: AsyncCallback): void { if (callback == null) { - let error: BusinessError = { - code: 410, - message : "callback must be not null" - } - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): void => { return nativeCancelAll(); }); p.then((data: NullishType): void => { @@ -1719,6 +1718,122 @@ export default namespace notificationManager { public slotType: SlotType = SlotType.UNKNOWN_TYPE; public extraInfos?: Record; } + + export function getAllNotificationEnabledBundles(): Promise> + { + let pPromise = new Promise>( + (resolve: ResolveCallback>, reject: RejectCallback): void => { + let p = taskpool.execute((): Array => { return nativeGetAllNotificationEnabledBundles(); }); + p.then((data: NullishType): void => { + let options : Array = data as Array; + resolve(options); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function isNotificationEnabledSync(): boolean + { + return nativeIsNotificationEnabledSync(); + } + + export function setBadgeNumber(badgeNumber: number, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeSetBadgeNumber(badgeNumber); }); + 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 function setBadgeNumber(badgeNumber: number): Promise { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeSetBadgeNumber(badgeNumber); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setBadgeNumberByBundle(bundle: BundleOption, badgeNumber: number): Promise + { + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== ERROR_OK) { + throw error; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeSetBadgeNumberByBundle(bundle, badgeNumber); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getActiveNotificationByFilter(filter: NotificationFilter, callback: AsyncCallback): void + { + let error: BusinessError = isInvalidParameter(filter); + if (error.code !== ERROR_OK) { + throw error; + } + if (callback === null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): NotificationRequest => { return nativeGetActiveNotificationByFilter(filter); }); + p.then((data: NullishType): void => { + let ret : NotificationRequest = data as NotificationRequest; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let retData: NotificationRequest = { + content:{}, + creatorBundleName: undefined, + creatorUid:undefined, + creatorPid:undefined, + creatorUserId:undefined, + hashCode:undefined, + notificationFlags:undefined, + source : undefined, + deviceId : undefined, + agentBundle : undefined, + appInstanceKey : undefined, + badgeNumber : undefined + }; + let err: BusinessError = error as BusinessError; + callback(err, retData); + }) + } + + export function getActiveNotificationByFilter(filter: NotificationFilter): Promise + { + let error: BusinessError = isInvalidParameter(filter); + if (error.code !== ERROR_OK) { + throw error; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): NotificationRequest => { return nativeGetActiveNotificationByFilter(filter); }); + p.then((data: NullishType): void => { + let ret : NotificationRequest = data as NotificationRequest; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } export function isSupportTemplate(templateName: string): Promise { @@ -1734,36 +1849,584 @@ export default namespace notificationManager { return pPromise; } - export function isSupportTemplate(templateName: string, callback: AsyncCallback): void + export function removeGroupByBundle(bundle: BundleOption, groupName: string, callback: AsyncCallback): void { - if (callback == null) { + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== ERROR_OK) { + throw error; + } + if (groupName === '') { throw errorParamInvalid; } - let p = taskpool.execute((): boolean => { return nativeIsSupportTemplate(templateName); }); + if (!callback) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeRemoveGroupByBundle(bundle, groupName); }); p.then((data: NullishType): void => { - let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; - callback(err, ret); + callback(err, undefined); }, (error: Object): void => { - let ret : boolean = false; let err: BusinessError = error as BusinessError; - callback(err, ret); + callback(err, undefined); }) } - export function setDistributedEnable(enable: boolean, callback: AsyncCallback): void + export function removeGroupByBundle(bundle: BundleOption, groupName: string): Promise + { + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== ERROR_OK) { + throw error; + } + if (groupName === '') { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeRemoveGroupByBundle(bundle, groupName); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number, callback: AsyncCallback): void + { + let error: BusinessError = isInvalidParameter(request); + if (error.code !== ERROR_OK) { + throw error; + } + + if (callback == null) { + throw errorParamInvalid; + } + if (representativeBundle == null || representativeBundle?.length === 0) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativePublishAsBundle(request, representativeBundle, userId); }); + 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 function publishAsBundle(request: NotificationRequest, representativeBundle: string, userId: number): Promise + { + let error: BusinessError = isInvalidParameter(request); + if (error.code !== ERROR_OK) { + throw error; + } + if (representativeBundle == null || representativeBundle?.length === 0) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativePublishAsBundle(request, representativeBundle, userId); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function publishAsBundle(representativeBundle: BundleOption, request: NotificationRequest): Promise + { + let error: BusinessError = isInvalidParameter(request); + if (error.code !== ERROR_OK) { + throw error; + } + let err: BusinessError = isInvalidParameter(representativeBundle); + if (err.code !== ERROR_OK) { + throw err; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativePublishAsBundleWithBundleOption(representativeBundle, request); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function cancelAsBundle(id: number, representativeBundle: string, userId: number, callback: AsyncCallback): void { if (callback == null) { throw errorParamInvalid; } - let p = taskpool.execute((): void => { return nativeSetDistributedEnable(enable); }); + if (representativeBundle == null || representativeBundle?.length === 0) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeCancelAsBundle(id, representativeBundle, userId); }); 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 function cancelAsBundle(id: number, representativeBundle: string, userId: number): Promise + { + if (representativeBundle == null || representativeBundle?.length === 0) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeCancelAsBundle(id, representativeBundle, userId); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function cancelAsBundle(representativeBundle: BundleOption, id: number): Promise + { + let error: BusinessError = isInvalidParameter(representativeBundle); + if (error.code !== ERROR_OK) { + throw error; + } + + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeCancelAsBundleWithBundleOption(representativeBundle, id); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function cancelGroup(groupName: string, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + if (groupName == null || groupName?.length === 0) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeCancelGroup(groupName); }); + 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 function cancelGroup(groupName: string): Promise + { + if (groupName == null || groupName?.length === 0) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeCancelGroup(groupName); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let error: BusinessError = isInvalidParameter(date); + if (error.code !== ERROR_OK) { + throw error; + } + let p = taskpool.execute((): void => { return nativeSetDoNotDisturbDate(date); }); + 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 function setDoNotDisturbDate(date: DoNotDisturbDate): Promise + { + let error: BusinessError = isInvalidParameter(date); + if (error.code !== ERROR_OK) { + throw error; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeSetDoNotDisturbDate(date); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let error: BusinessError = isInvalidParameter(date); + if (error.code !== ERROR_OK) { + throw error; + } + let p = taskpool.execute((): void => { return nativeSetDoNotDisturbDateWithId(date, userId); }); + 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 function setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise + { + let error: BusinessError = isInvalidParameter(date); + if (error.code !== ERROR_OK) { + throw error; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { return nativeSetDoNotDisturbDateWithId(date, userId); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getDoNotDisturbDate(callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): DoNotDisturbDate => { return nativeGetDoNotDisturbDate(); }); + p.then((data: NullishType): void => { + let doNotDisturbDate : DoNotDisturbDate = data as DoNotDisturbDate; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, doNotDisturbDate); + }, (error: Object): void => { + let doNotDisturbDate : DoNotDisturbDate = {}; + let err: BusinessError = error as BusinessError; + callback(err, doNotDisturbDate); + }) + } + + export function getDoNotDisturbDate(): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): DoNotDisturbDate => { return nativeGetDoNotDisturbDate(); }); + p.then((data: NullishType): void => { + let doNotDisturbDate : DoNotDisturbDate = data as DoNotDisturbDate; + resolve(doNotDisturbDate); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getDoNotDisturbDate(userId: number, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): DoNotDisturbDate => { return nativeGetDoNotDisturbDateWithId(userId); }); + p.then((data: NullishType): void => { + let doNotDisturbDate : DoNotDisturbDate = data as DoNotDisturbDate; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, doNotDisturbDate); + }, (error: Object): void => { + let doNotDisturbDate : DoNotDisturbDate = {}; + let err: BusinessError = error as BusinessError; + callback(err, doNotDisturbDate); + }); + } + + export function getDoNotDisturbDate(userId: number): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): DoNotDisturbDate => { return nativeGetDoNotDisturbDateWithId(userId); }); + p.then((data: NullishType): void => { + let doNotDisturbDate : DoNotDisturbDate = data as DoNotDisturbDate; + resolve(doNotDisturbDate); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function isSupportDoNotDisturbMode(callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): boolean => { return nativeIsSupportDoNotDisturbMode(); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let ret : boolean = false; + let err: BusinessError = error as BusinessError; + callback(err, ret); + }) + } + + export function isSupportTemplate(templateName: string, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): boolean => { return nativeIsSupportTemplate(templateName); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + let err: BusinessError = {code: 0, data: undefined}; + callback(err, ret); + }, (error: Object): void => { + let ret : boolean = false; + let err: BusinessError = error as BusinessError; + callback(err, ret); + }) + } + + export function isSupportDoNotDisturbMode(): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): boolean => { return nativeIsSupportDoNotDisturbMode(); }); + p.then((data: NullishType): void => { + let ret : boolean = data as boolean; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function getDoNotDisturbProfile(id: number): Promise + { + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): DoNotDisturbProfile => { return nativeGetDoNotDisturbProfile(id); }); + p.then((data: NullishType): void => { + let ret : DoNotDisturbProfile = data as DoNotDisturbProfile; + resolve(ret); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } + + export function openNotificationSettings(context: UIAbilityContext): Promise + { + if (context == undefined || context === null) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): Promise => { return nativeOpenNotificationSettings(context); }); + p.then( + (data: NullishType): void => { + if (data == undefined) { + reject(rejectInternalError); + } else { + let result: int = data as int; + if (result == 0) { + resolve(undefined); + } else { + reject(rejectInternalError); + } + } + }, + (error: Object): void => { + reject(error); + } + ) + }); + return pPromise; + } + + 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 !== ERROR_OK) { + 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 !== ERROR_OK) { + 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 !== ERROR_OK) { + throw error; + } + if (callback == null) { + throw errorParamInvalid; + } + 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 function setDistributedEnable(enable: boolean, callback: AsyncCallback): void + { + if (callback == null) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { return nativeSetDistributedEnable(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 function setDistributedEnable(enable: boolean): Promise @@ -1813,7 +2476,7 @@ export default namespace notificationManager { export function isDistributedEnabledByBundle(bundle: BundleOption): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1832,7 +2495,7 @@ export default namespace notificationManager { { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == null) { @@ -1853,7 +2516,7 @@ export default namespace notificationManager { export function isDistributedEnabledByBundle(bundle: BundleOption, deviceType: string): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { diff --git a/frameworks/ets/ets/@ohos.notificationSubscribe.ets b/frameworks/ets/ets/@ohos.notificationSubscribe.ets index b6f139162..21a9c6bc1 100644 --- a/frameworks/ets/ets/@ohos.notificationSubscribe.ets +++ b/frameworks/ets/ets/@ohos.notificationSubscribe.ets @@ -31,6 +31,27 @@ const successCallbackError: BusinessError = {code: ERROR_OK, data: undefined}; const errorParamInvalid: BusinessError = {code: ERROR_PARAM_INVALID, data: "Invalid parameter"}; +function isInvalidParameter(bundle: BundleOption): BusinessError +{ + let error: BusinessError = { + code: ERROR_OK, + message: "" + } + + let errorCode: BusinessError = { + code: ERROR_PARAM_INVALID, + message: "Invalid parameter" + } + + if (bundle == null) { + return errorCode; + } + if (bundle.bundle == null || bundle.bundle?.length === 0) { + return errorCode; + } + return error; +} + export default namespace notificationSubscribe { loadLibrary("notification_subscribe_ani.z") export interface NotificationKey { @@ -58,6 +79,9 @@ 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 nativeSubscribeSelf(subscriber: NotificationSubscriber): void + export native function nativeRemoveAllForBundle(bundle?: BundleOption): void; + export native function nativeRemoveAllForUserId(userId: number): void; export function subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback): void { if (subscriber == undefined || callback == undefined) { @@ -303,4 +327,111 @@ export default namespace notificationSubscribe { public actionName?: string; public userInput?: string; } + + export function subscribeSelf(subscriber: NotificationSubscriber): Promise { + if (subscriber == undefined) { + throw errorParamInvalid; + } + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void =>{ + let p = taskpool.execute((): void => { notificationSubscribe.nativeSubscribeSelf(subscriber)}); + p.then( + (e: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + } + ) + }); + return pPromise; + } + + export function removeAll(bundle: BundleOption, callback: AsyncCallback): void { + let error: BusinessError = isInvalidParameter(bundle); + if (error.code !== 0) { + throw error; + } + if (callback == undefined) { + throw errorParamInvalid; + } + let p = taskpool.execute((): void => { + return notificationSubscribe.nativeRemoveAllForBundle(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 + { + + let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { + let p = taskpool.execute((): void => { + if (bundle == undefined) { + return notificationSubscribe.nativeRemoveAllForBundle(); + } else { + return notificationSubscribe.nativeRemoveAllForBundle(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.nativeRemoveAllForBundle(); + }); + 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.nativeRemoveAllForUserId(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.nativeRemoveAllForUserId(userId); }); + p.then((data: NullishType): void => { + resolve(undefined); + }, (error: Object): void => { + reject(error); + }); + }); + return pPromise; + } } \ No newline at end of file -- Gitee From cda580bcb5f59cc893e77c4aeb5deac5786c034b Mon Sep 17 00:00:00 2001 From: heguokai Date: Fri, 6 Jun 2025 00:55:22 +0800 Subject: [PATCH 05/14] modify Signed-off-by: heguokai --- frameworks/ets/ani/src/sts_disturb_mode.cpp | 2 +- frameworks/ets/ani/src/subscribe/ani_subscribe.cpp | 2 +- frameworks/ets/ets/@ohos.notificationSubscribe.ets | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/ets/ani/src/sts_disturb_mode.cpp b/frameworks/ets/ani/src/sts_disturb_mode.cpp index 1aca78724..0b9924ebd 100644 --- a/frameworks/ets/ani/src/sts_disturb_mode.cpp +++ b/frameworks/ets/ani/src/sts_disturb_mode.cpp @@ -144,7 +144,7 @@ bool WrapDoNotDisturbProfile(ani_env* env, sptr } ani_double id = static_cast(profile->GetProfileId()); if (ANI_OK != (status = env->Object_SetPropertyByName_Double(outObj, "id", id))) { - ANS_LOGE("WrapDoNotDisturbProfile ddd set reason faild. status %{public}d", status); + ANS_LOGE("WrapDoNotDisturbProfile : set reason faild. status %{public}d", status); return false; } if (!SetPropertyOptionalByString(env, outObj, "name", profile->GetProfileName())) { diff --git a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp index 0bc5efab4..b951b75f1 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -124,7 +124,7 @@ void AniSubScribeRegistryInit(ani_env *env) ani_native_function {"nativeRemoveAllForBundle", REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE, reinterpret_cast(AniRemoveAllForBundle)}, ani_native_function {"nativeRemoveAllForUserId", - REMOVEALL_FOR_USERID_STGNATURE,reinterpret_cast(AniRemoveAllForUserId)}, + REMOVEALL_FOR_USERID_STGNATURE, reinterpret_cast(AniRemoveAllForUserId)}, }; ANS_LOGD("Start bind native methods to '%{public}s'", npName); diff --git a/frameworks/ets/ets/@ohos.notificationSubscribe.ets b/frameworks/ets/ets/@ohos.notificationSubscribe.ets index 21a9c6bc1..9bad8d255 100644 --- a/frameworks/ets/ets/@ohos.notificationSubscribe.ets +++ b/frameworks/ets/ets/@ohos.notificationSubscribe.ets @@ -347,7 +347,7 @@ export default namespace notificationSubscribe { export function removeAll(bundle: BundleOption, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } if (callback == undefined) { -- Gitee From 9f91a640893115c999d3c3bea1cbac9d9a3b728c Mon Sep 17 00:00:00 2001 From: heguokai Date: Fri, 6 Jun 2025 11:02:58 +0800 Subject: [PATCH 06/14] modify Signed-off-by: heguokai --- frameworks/ets/ani/src/manager/ani_notification_enable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp index c2b2529bd..ba521c2dc 100644 --- a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp @@ -161,7 +161,7 @@ void AniDisableNotificationFeature(ani_env *env, ani_boolean disabled, ani_objec { ANS_LOGD("AniDisableNotificationFeature enter"); std::vector bundleListStd; - if (NotificationSts::GetStringArrayByAniObj(env, bundleList, bundleListStd) != ANI_OK) { + if (!NotificationSts::GetStringArrayByAniObj(env, bundleList, bundleListStd)) { std::string msg = "Invalid bundleList: must be an array of strings."; ANS_LOGE("GetStringArrayByAniObj failed. msg: %{public}s", msg.c_str()); OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); -- Gitee From 73872d09c84dee753fa758c1649a6089317611ea Mon Sep 17 00:00:00 2001 From: heguokai Date: Mon, 9 Jun 2025 20:44:45 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: heguokai --- .../ets/ets/@ohos.notificationManager.ets | 327 ++++++++++-------- .../ets/notification/notificationRequest.ets | 2 - 2 files changed, 192 insertions(+), 137 deletions(-) diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index f621dcb2f..ab484c2cb 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -246,11 +246,11 @@ export default namespace notificationManager { } } if (slot.desc !== undefined && slot.desc?.trim() === '') { - return errorParamInvalid; - } + return errorParamInvalid; + } if (slot.sound !== undefined && slot.sound?.trim() === '') { - return errorParamInvalid; - } + return errorParamInvalid; + } if (slot.vibrationValues !== undefined && slot.vibrationValues?.length === 0) { return errorParamInvalid; } @@ -310,183 +310,240 @@ export default namespace notificationManager { function isInvalidContent(normal?: NotificationBasicContent): boolean { if (normal === null) { - return false; - } - if (!normal?.title || normal?.title?.trim() === '') { - return false; - } - if (!normal?.text || normal?.text?.trim() === '') { - return false; - } - if (normal?.additionalText !== undefined && normal?.additionalText?.trim() === '') { - return false; - } - if (normal?.lockscreenPicture != undefined && !(normal?.lockscreenPicture instanceof image.PixelMap)) { - return false; - } - + return false; + } + if (!normal?.title || normal?.title?.trim() === '') { + return false; + } + if (!normal?.text || normal?.text?.trim() === '') { + return false; + } + if (normal?.additionalText !== undefined && normal?.additionalText?.trim() === '') { + return false; + } + if (normal?.lockscreenPicture != undefined && !(normal?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } return true; } function isInvalidLongText(longText?: NotificationLongTextContent): boolean { if (longText === null) { - return false; - } - if (!longText?.longText || longText?.longText?.trim() === '') { - return false; - } - if (!longText?.briefText || longText?.briefText?.trim() === '') { - return false; - } - if (!longText?.expandedTitle || longText?.expandedTitle?.trim() === '') { - return false; - } + return false; + } + if (!longText?.title || longText?.title?.trim() === '') { + return false; + } + if (!longText?.text || longText?.text?.trim() === '') { + return false; + } + if (longText?.additionalText !== undefined && longText?.additionalText?.trim() === '') { + return false; + } + if (longText?.lockscreenPicture != undefined && !(longText?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } + if (!longText?.longText || longText?.longText?.trim() === '') { + return false; + } + if (!longText?.briefText || longText?.briefText?.trim() === '') { + return false; + } + if (!longText?.expandedTitle || longText?.expandedTitle?.trim() === '') { + return false; + } return true; } function isInvalidMultiLine(multiLine?: NotificationMultiLineContent): boolean { if (multiLine === null) { - return false - } - if (!multiLine?.briefText || multiLine?.briefText.trim() === '') { - return false; - } - if (!multiLine?.longTitle || multiLine?.longTitle.trim() === '') { - return false; - } - if (multiLine?.lines?.length === 0) { - return false; - } - + return false + } + if (!multiLine?.title || multiLine?.title?.trim() === '') { + return false; + } + if (!multiLine?.text || multiLine?.text?.trim() === '') { + return false; + } + if (multiLine?.additionalText !== undefined && multiLine?.additionalText?.trim() === '') { + return false; + } + if (multiLine?.lockscreenPicture != undefined && !(multiLine?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } + if (!multiLine?.briefText || multiLine?.briefText.trim() === '') { + return false; + } + if (!multiLine?.longTitle || multiLine?.longTitle.trim() === '') { + return false; + } + if (multiLine?.lines?.length === 0) { + return false; + } return true; } function isInvalidPicture(picture?: NotificationPictureContent): boolean { if (picture === null) { - return false; - } - if (!picture?.briefText || picture?.briefText?.trim() === '') { - return false; - } - if (!picture?.expandedTitle || picture?.expandedTitle?.trim() === '') { - return false; - } - if (!(picture?.picture instanceof image.PixelMap)) { - return false; - } + return false; + } + if (!picture?.title || picture?.title?.trim() === '') { + return false; + } + if (!picture?.text || picture?.text?.trim() === '') { + return false; + } + if (picture?.additionalText !== undefined && picture?.additionalText?.trim() === '') { + return false; + } + if (picture?.lockscreenPicture != undefined && !(picture?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } + if (!picture?.briefText || picture?.briefText?.trim() === '') { + return false; + } + if (!picture?.expandedTitle || picture?.expandedTitle?.trim() === '') { + return false; + } + if (!(picture?.picture instanceof image.PixelMap)) { + return false; + } return true; } function isInvalidSystemLiveView(systemLiveView?: NotificationSystemLiveViewContent): boolean { if (systemLiveView === null) { - return false - } - if (systemLiveView?.capsule !== undefined && systemLiveView?.capsule === null) { - return false - } - if (systemLiveView?.capsule?.title !== undefined && systemLiveView?.capsule?.title?.trim() === '') { - return false; - } - if (systemLiveView?.capsule?.icon != undefined && !(systemLiveView?.capsule?.icon instanceof image.PixelMap)) { - return false; - } - if (systemLiveView?.capsule?.backgroundColor != undefined && systemLiveView?.capsule?.backgroundColor?.trim() === '') { - return false; - } - if (systemLiveView?.capsule?.content != undefined && systemLiveView?.capsule?.content?.trim() === '') { - return false; - } - if (systemLiveView?.capsule?.capsuleButtons != undefined && systemLiveView?.capsule?.capsuleButtons?.length === 0) { - return false; - } - if (systemLiveView?.button !== undefined && systemLiveView?.button === null) { - return false; - } - if (systemLiveView?.button?.names != undefined && systemLiveView?.button?.names?.length === 0) { - return false; - } - if (systemLiveView?.button?.icons != undefined && systemLiveView?.button?.icons?.length === 0) { - return false; - } - if (systemLiveView?.button?.iconsResource != undefined && systemLiveView?.button?.iconsResource?.length === 0) { - return false; - } - - if (systemLiveView?.cardButtons !== undefined && systemLiveView?.cardButtons?.length === 0) { - return false; - } + return false + } + if (!systemLiveView?.title || systemLiveView?.title?.trim() === '') { + return false; + } + if (!systemLiveView?.text || systemLiveView?.text?.trim() === '') { + return false; + } + if (systemLiveView?.additionalText !== undefined && systemLiveView?.additionalText?.trim() === '') { + return false; + } + if (systemLiveView?.lockscreenPicture != undefined && !(systemLiveView?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } + if (systemLiveView?.capsule !== undefined && systemLiveView?.capsule === null) { + return false + } + if (systemLiveView?.capsule?.title !== undefined && systemLiveView?.capsule?.title?.trim() === '') { + return false; + } + if (systemLiveView?.capsule?.icon != undefined && !(systemLiveView?.capsule?.icon instanceof image.PixelMap)) { + return false; + } + if (systemLiveView?.capsule?.backgroundColor != undefined && systemLiveView?.capsule?.backgroundColor?.trim() === '') { + return false; + } + if (systemLiveView?.capsule?.content != undefined && systemLiveView?.capsule?.content?.trim() === '') { + return false; + } + if (systemLiveView?.capsule?.capsuleButtons != undefined && systemLiveView?.capsule?.capsuleButtons?.length === 0) { + return false; + } + if (systemLiveView?.button !== undefined && systemLiveView?.button === null) { + return false; + } + if (systemLiveView?.button?.names != undefined && systemLiveView?.button?.names?.length === 0) { + return false; + } + if (systemLiveView?.button?.icons != undefined && systemLiveView?.button?.icons?.length === 0) { + return false; + } + if (systemLiveView?.button?.iconsResource != undefined && systemLiveView?.button?.iconsResource?.length === 0) { + return false; + } + if (systemLiveView?.cardButtons !== undefined && systemLiveView?.cardButtons?.length === 0) { + return false; + } return true; } function isInvalidLiveView(liveView?: NotificationLiveViewContent): boolean { if (liveView === null) { - return false; - } - if (liveView?.extraInfo !== undefined && liveView?.extraInfo === null) { - return false; - } - if (liveView?.pictureInfo !== undefined && liveView?.pictureInfo === null) { - return false; - } + return false; + } + if (!liveView?.title || liveView?.title?.trim() === '') { + return false; + } + if (!liveView?.text || liveView?.text?.trim() === '') { + return false; + } + if (liveView?.additionalText !== undefined && liveView?.additionalText?.trim() === '') { + return false; + } + if (liveView?.lockscreenPicture != undefined && !(liveView?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } + if (liveView?.extraInfo !== undefined && liveView?.extraInfo === null) { + return false; + } + if (liveView?.pictureInfo !== undefined && liveView?.pictureInfo === null) { + return false; + } return true; } function isInvalidTemplate(template?: NotificationTemplate): boolean { if (template === null) { - return false; - } - if (template?.name != undefined && template?.name?.trim() === '') { - return false; - } - if (template?.data != undefined && template?.data === null) { - return false; - } + return false; + } + if (template?.name != undefined && template?.name?.trim() === '') { + return false; + } + if (template?.data != undefined && template?.data === null) { + return false; + } return true; } function isInvalidDistributedOption(distributedOption?: DistributedOptions): boolean { if (distributedOption === null) { - return false - } - if (distributedOption?.supportDisplayDevices != undefined && distributedOption?.supportDisplayDevices?.length === 0) { - return false; - } - if (distributedOption?.supportOperateDevices != undefined && distributedOption?.supportOperateDevices?.length === 0) { - return false; - } + return false + } + if (distributedOption?.supportDisplayDevices != undefined && distributedOption?.supportDisplayDevices?.length === 0) { + return false; + } + if (distributedOption?.supportOperateDevices != undefined && distributedOption?.supportOperateDevices?.length === 0) { + return false; + } return true; } function isInvalidUnifiedGroupInfo(unifiedGroupInfo?: UnifiedGroupInfo): boolean { if (unifiedGroupInfo === null) { - return false; - } - if (unifiedGroupInfo?.key != undefined && unifiedGroupInfo?.key?.trim() === '') { - return false; - } - if (unifiedGroupInfo?.title != undefined && unifiedGroupInfo?.title?.trim() === '') { - return false; - } - if (unifiedGroupInfo?.content != undefined && unifiedGroupInfo?.content?.trim() === '') { - return false; - } - if (unifiedGroupInfo?.sceneName != undefined && unifiedGroupInfo?.sceneName?.trim() === '') { - return false; - } - if (unifiedGroupInfo?.extraInfo != undefined && unifiedGroupInfo?.extraInfo == null) { - return false; - } + return false; + } + if (unifiedGroupInfo?.key != undefined && unifiedGroupInfo?.key?.trim() === '') { + return false; + } + if (unifiedGroupInfo?.title != undefined && unifiedGroupInfo?.title?.trim() === '') { + return false; + } + if (unifiedGroupInfo?.content != undefined && unifiedGroupInfo?.content?.trim() === '') { + return false; + } + if (unifiedGroupInfo?.sceneName != undefined && unifiedGroupInfo?.sceneName?.trim() === '') { + return false; + } + if (unifiedGroupInfo?.extraInfo != undefined && unifiedGroupInfo?.extraInfo == null) { + return false; + } return true; } function isInvalidBundleOption(bundleOption?: BundleOption): boolean { if (bundleOption === null) { - return false; - } - if (bundleOption?.bundle != undefined && bundleOption?.bundle?.trim() === '') { - return false; - } + return false; + } + if (bundleOption?.bundle != undefined && bundleOption?.bundle?.trim() === '') { + return false; + } return true; } function isInvalidParameter(request: NotificationRequest): BusinessError diff --git a/frameworks/ets/ets/notification/notificationRequest.ets b/frameworks/ets/ets/notification/notificationRequest.ets index 5b1993bd1..b990da8d5 100644 --- a/frameworks/ets/ets/notification/notificationRequest.ets +++ b/frameworks/ets/ets/notification/notificationRequest.ets @@ -108,7 +108,6 @@ export interface NotificationRequest { readonly creatorUid?: number; readonly creatorPid?: number; readonly creatorUserId?: number; - readonly creatorInstanceKey?: number; sound?: string; classification?: string; readonly hashCode?: string; @@ -160,7 +159,6 @@ class NotificationRequestInner implements NotificationRequest { public readonly creatorUid?: number | undefined; public readonly creatorPid?: number | undefined; public readonly creatorUserId?: number | undefined; - public readonly creatorInstanceKey?: number | undefined; public sound?: string | undefined; public classification?: string | undefined; public readonly hashCode?: string | undefined; -- Gitee From 2d967d993350a773fcc1d73a52e9495c8e244255 Mon Sep 17 00:00:00 2001 From: heguokai Date: Mon, 9 Jun 2025 20:53:18 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: heguokai --- frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp | 2 -- frameworks/ets/ani/src/sts_bundle_option.cpp | 2 +- frameworks/ets/ani/src/sts_disturb_mode.cpp | 2 +- frameworks/ets/ani/src/sts_notification_manager.cpp | 3 +-- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp b/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp index 0bd98152f..71f94dd19 100644 --- a/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp +++ b/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp @@ -89,8 +89,6 @@ ani_object AniGetDoNotDisturbProfile(ani_env *env, ani_double id) OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } - ANS_LOGD("doNotDisturbProfile ProfileId: %{public}lld, ProfileName %{public}s", - doNotDisturbProfile->GetProfileId(), doNotDisturbProfile->GetProfileName().c_str()); if (!NotificationSts::WrapDoNotDisturbProfile(env, doNotDisturbProfile, profile)) { ANS_LOGE("AniGetDoNotDisturbProfile WrapDoNotDisturbProfile failed"); OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, diff --git a/frameworks/ets/ani/src/sts_bundle_option.cpp b/frameworks/ets/ani/src/sts_bundle_option.cpp index 5f89307c8..2cf67a9bf 100644 --- a/frameworks/ets/ani/src/sts_bundle_option.cpp +++ b/frameworks/ets/ani/src/sts_bundle_option.cpp @@ -57,7 +57,7 @@ ani_object GetAniArrayBundleOption(ani_env* env, ANS_LOGE("GetAniArrayActionButton: arrayObj is nullptr"); return nullptr; } - ani_size index = 0; + int32_t index = 0; for (auto &option : bundleOptions) { std::shared_ptr optSp = std::make_shared(option); ani_object item; diff --git a/frameworks/ets/ani/src/sts_disturb_mode.cpp b/frameworks/ets/ani/src/sts_disturb_mode.cpp index 0b9924ebd..1cc2f7c28 100644 --- a/frameworks/ets/ani/src/sts_disturb_mode.cpp +++ b/frameworks/ets/ani/src/sts_disturb_mode.cpp @@ -104,7 +104,7 @@ bool WrapProfileTrustList(ani_env* env, sptr pr return false; } - size_t index = 0; + int32_t index = 0; for (const auto& bundle : trustList) { auto bundlePtr = std::make_shared(bundle); ani_object bundleObj = nullptr; diff --git a/frameworks/ets/ani/src/sts_notification_manager.cpp b/frameworks/ets/ani/src/sts_notification_manager.cpp index acde5ca6a..eb0116381 100644 --- a/frameworks/ets/ani/src/sts_notification_manager.cpp +++ b/frameworks/ets/ani/src/sts_notification_manager.cpp @@ -760,8 +760,7 @@ bool UnWarpNotificationDoNotDisturbDate( doNotDisturbDate.SetEndDate(static_cast(mDouble)); } if (doNotDisturbDate.GetBeginDate() >= doNotDisturbDate.GetEndDate()) { - ANS_LOGE("Invalid time range: begin(%{public}lld) >= end(%{public}lld)", - doNotDisturbDate.GetBeginDate(), doNotDisturbDate.GetEndDate()); + ANS_LOGE("Invalid time range"); return false; } ANS_LOGD("Successfully parsed DoNotDisturbDate"); -- Gitee From 31749be97aa1e902119f0387155bcd7d48207f8f Mon Sep 17 00:00:00 2001 From: Martin Sajti Date: Wed, 28 May 2025 10:59:13 +0200 Subject: [PATCH 09/14] Fix invlid code after primitive type refactor Change-Id: I0615ceabceb8503b09b036dbbb595fe63eda1bc7 Signed-off-by: Martin Sajti --- .../ets/ets/@ohos.notificationManager.ets | 224 +++++++++--------- .../ets/ets/@ohos.notificationSubscribe.ets | 34 +-- 2 files changed, 129 insertions(+), 129 deletions(-) diff --git a/frameworks/ets/ets/@ohos.notificationManager.ets b/frameworks/ets/ets/@ohos.notificationManager.ets index ab484c2cb..1bd0e6d84 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -31,7 +31,7 @@ import { NotificationFilter } from 'notification.notificationRequest'; import image from '@ohos.multimedia.image'; type ResolveCallback = (data: T) => void; -type RejectCallback = (err: Object) => void; +type RejectCallback = (err: Error) => void; type CallbackForCheckInfo = (checkInfo: notificationManager.NotificationCheckInfo)=> notificationManager.NotificationCheckResult; @@ -649,7 +649,7 @@ export default namespace notificationManager { } return error; } - + export function getSlotNumByBundle(bundle: BundleOption): Promise { let error: BusinessError = isInvalidParameter(bundle); if (error.code !== ERROR_OK) { @@ -660,7 +660,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : number = data as number; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -680,7 +680,7 @@ export default namespace notificationManager { let ret : number = data as number; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret: number = -1; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -703,7 +703,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -722,7 +722,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeSetSlotByBundle(bundle, slot); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -737,7 +737,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -748,7 +748,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeRemoveAllSlots(); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -763,7 +763,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -774,7 +774,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeRemoveSlot(slotType); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -787,7 +787,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : Array = data as Array; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -803,7 +803,7 @@ export default namespace notificationManager { let ret : Array = data as Array; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : Array = []; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -816,7 +816,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : NotificationSlot = data as NotificationSlot; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -832,7 +832,7 @@ export default namespace notificationManager { let ret : NotificationSlot = data as NotificationSlot; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : NotificationSlot = { enabled: false, reminderMode: 0, authorizedStatus: 0 } as NotificationSlot; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -847,7 +847,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeAddSlots(slots); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -865,7 +865,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -880,7 +880,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeAddSlotByNotificationSlot(slot); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -899,7 +899,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -913,7 +913,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -924,7 +924,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeAddSlotBySlotType(type); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -941,13 +941,13 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeSetNotificationEnable(bundle, enable); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); return pPromise; } - + export function setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); @@ -961,7 +961,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -981,7 +981,7 @@ export default namespace notificationManager { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -1001,7 +1001,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1018,7 +1018,7 @@ export default namespace notificationManager { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -1032,7 +1032,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1049,7 +1049,7 @@ export default namespace notificationManager { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -1063,7 +1063,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1090,7 +1090,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -1113,7 +1113,7 @@ export default namespace notificationManager { }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1134,7 +1134,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) @@ -1151,7 +1151,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1172,7 +1172,7 @@ export default namespace notificationManager { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -1193,13 +1193,13 @@ export default namespace notificationManager { let slots : Array = data as Array; let err: BusinessError = {code: 0, data: undefined}; callback(err, slots); - }, (error: Object): void => { + }, (error: Error): void => { let slots : Array = []; let err: BusinessError = error as BusinessError; callback(err, slots); - }) + }) } - + export function getSlotsByBundle(bundle: BundleOption): Promise> { let error: BusinessError = isInvalidParameter(bundle); @@ -1212,7 +1212,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let slots : Array = data as Array; resolve(slots); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1228,7 +1228,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeSetSlotFlagsByBundle(bundle, slotFlags); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1245,7 +1245,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : Double = data as Double; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1264,7 +1264,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -1279,7 +1279,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativePublish(request); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1298,12 +1298,12 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) } - + export function publish(request: NotificationRequest, userId: number): Promise { let error: BusinessError = isInvalidParameter(request); if (error.code !== ERROR_OK) { @@ -1313,7 +1313,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativePublishWithUserId(request, userId); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1333,11 +1333,11 @@ export default namespace notificationManager { } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { - return nativeTriggerSystemLiveView(bundle, notificationId, buttonOptions); + return nativeTriggerSystemLiveView(bundle, notificationId, buttonOptions); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1353,7 +1353,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeSubscribeSystemLiveView(subscriber); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1368,7 +1368,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeRemoveDoNotDisturbProfile(templates); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1383,7 +1383,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeAddDoNotDisturbProfile(templates); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1399,7 +1399,7 @@ export default namespace notificationManager { let ret : Array = data as Array; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let retData : Array = []; let err: BusinessError = error as BusinessError; callback(err, retData); @@ -1414,7 +1414,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : Array = data as Array; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1427,7 +1427,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : Array = data as Array; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1443,7 +1443,7 @@ export default namespace notificationManager { let ret : Array = data as Array; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let retData : Array = []; let err: BusinessError = error as BusinessError; callback(err, retData); @@ -1472,7 +1472,7 @@ export default namespace notificationManager { p.then((data :NullishType): void => { let ret : number = data as number; resolve(ret); - }, (err:Object): void => { + }, (err:Error): void => { reject(err); }); }); @@ -1491,12 +1491,12 @@ export default namespace notificationManager { p.then((e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) } - + export function displayBadge(bundle: BundleOption, enable: boolean): Promise { let error: BusinessError = isInvalidParameter(bundle); if (error.code !== ERROR_OK) { @@ -1506,7 +1506,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeDisplayBadge(bundle, enable); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1523,13 +1523,13 @@ export default namespace notificationManager { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); }) } - + export function isBadgeDisplayed(bundle: BundleOption): Promise { let error: BusinessError = isInvalidParameter(bundle); if (error.code !== ERROR_OK) { @@ -1540,7 +1540,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1556,7 +1556,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeCancelWithBundle(bundle, id); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1571,7 +1571,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeCancelWithIdOptionalLabel(id, label); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1589,7 +1589,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) @@ -1603,7 +1603,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) @@ -1614,7 +1614,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeCancelAll(); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1629,7 +1629,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) @@ -1655,7 +1655,7 @@ export default namespace notificationManager { } } }, - (error: Object): void => { + (error: Error): void => { reject(error); } ) @@ -1682,7 +1682,7 @@ export default namespace notificationManager { } } }, - (error: Object): void => { + (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -1722,7 +1722,7 @@ export default namespace notificationManager { await p.then( (e: NullishType): void => { result = e as notificationManager.NotificationCheckResult; - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; result = { code: err.code, @@ -1784,7 +1784,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let options : Array = data as Array; resolve(options); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1816,7 +1816,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeSetBadgeNumber(badgeNumber); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1833,7 +1833,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeSetBadgeNumberByBundle(bundle, badgeNumber); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1885,7 +1885,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : NotificationRequest = data as NotificationRequest; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1899,7 +1899,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1922,7 +1922,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) @@ -1941,7 +1941,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeRemoveGroupByBundle(bundle, groupName); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1984,7 +1984,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativePublishAsBundle(request, representativeBundle, userId); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2005,7 +2005,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativePublishAsBundleWithBundleOption(representativeBundle, request); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2024,7 +2024,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -2039,7 +2039,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeCancelAsBundle(id, representativeBundle, userId); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2057,7 +2057,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeCancelAsBundleWithBundleOption(representativeBundle, id); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2091,7 +2091,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeCancelGroup(groupName); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2127,7 +2127,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeSetDoNotDisturbDate(date); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2163,7 +2163,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeSetDoNotDisturbDateWithId(date, userId); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2194,7 +2194,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let doNotDisturbDate : DoNotDisturbDate = data as DoNotDisturbDate; resolve(doNotDisturbDate); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2225,7 +2225,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let doNotDisturbDate : DoNotDisturbDate = data as DoNotDisturbDate; resolve(doNotDisturbDate); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2273,7 +2273,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2287,7 +2287,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : DoNotDisturbProfile = data as DoNotDisturbProfile; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2314,7 +2314,7 @@ export default namespace notificationManager { } } }, - (error: Object): void => { + (error: Error): void => { reject(error); } ) @@ -2327,7 +2327,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativesetTargetDeviceStatus(deviceType,status); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2344,7 +2344,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativesetDistributedEnabledByBundle(bundle, deviceType, enable); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2362,7 +2362,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativesetDistributedEnableByBundle(bundle, enable); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2375,7 +2375,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativesetSmartReminderEnabled(deviceType, enable); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2389,7 +2389,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2404,7 +2404,7 @@ export default namespace notificationManager { }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2418,7 +2418,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2431,7 +2431,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : Double = data as Double; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2445,7 +2445,7 @@ export default namespace notificationManager { }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2492,7 +2492,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeSetDistributedEnable(enable); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2506,7 +2506,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2523,7 +2523,7 @@ export default namespace notificationManager { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -2541,7 +2541,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2563,7 +2563,7 @@ export default namespace notificationManager { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -2581,7 +2581,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2596,7 +2596,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : DeviceRemindType = data as DeviceRemindType; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2613,7 +2613,7 @@ export default namespace notificationManager { let ret : DeviceRemindType = data as DeviceRemindType; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { const defaultRemindType: DeviceRemindType = DeviceRemindType.IDLE_DONOT_REMIND; let err: BusinessError = error as BusinessError; callback(err, defaultRemindType); @@ -2631,7 +2631,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) @@ -2644,7 +2644,7 @@ export default namespace notificationManager { { return nativeSetSyncNotificationEnabledWithoutApp(userId, enable); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2658,7 +2658,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -2675,10 +2675,10 @@ export default namespace notificationManager { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); }) } -} \ No newline at end of file +} diff --git a/frameworks/ets/ets/@ohos.notificationSubscribe.ets b/frameworks/ets/ets/@ohos.notificationSubscribe.ets index 9bad8d255..81e911475 100644 --- a/frameworks/ets/ets/@ohos.notificationSubscribe.ets +++ b/frameworks/ets/ets/@ohos.notificationSubscribe.ets @@ -19,7 +19,7 @@ import { NotificationSubscribeInfo } from 'notification.notificationSubscribeInf import { NotificationSubscriber } from 'notification.notificationSubscriber'; type ResolveCallback = (data: T) => void; -type RejectCallback = (err: Object) => void; +type RejectCallback = (err: Error) => void; const ERROR_OK = 0; const ERROR_PARAM_INVALID = 401; @@ -92,7 +92,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -111,7 +111,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -126,7 +126,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -143,7 +143,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -159,7 +159,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -183,7 +183,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -205,7 +205,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -224,7 +224,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -242,7 +242,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -261,7 +261,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -279,7 +279,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -310,7 +310,7 @@ export default namespace notificationSubscribe { } else { resolve(undefined); } - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -337,7 +337,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -380,7 +380,7 @@ export default namespace notificationSubscribe { }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -428,10 +428,10 @@ export default namespace notificationSubscribe { let p = taskpool.execute((): void => { return notificationSubscribe.nativeRemoveAllForUserId(userId); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); return pPromise; } -} \ No newline at end of file +} -- Gitee From 16116503e0b7e3774cbf153502d93938b730aa77 Mon Sep 17 00:00:00 2001 From: heguokai Date: Mon, 16 Jun 2025 00:12:28 +0800 Subject: [PATCH 10/14] fixed for getSlot & getSlots Signed-off-by: heguokai --- frameworks/ets/ani/src/manager/ani_slot.cpp | 5 ++ frameworks/ets/ani/src/sts_common.cpp | 4 +- frameworks/ets/ani/src/sts_slot.cpp | 82 ++++++++----------- .../ets/ani/src/subscribe/ani_subscribe.cpp | 2 +- 4 files changed, 43 insertions(+), 50 deletions(-) diff --git a/frameworks/ets/ani/src/manager/ani_slot.cpp b/frameworks/ets/ani/src/manager/ani_slot.cpp index 622984eea..8790b0a3b 100644 --- a/frameworks/ets/ani/src/manager/ani_slot.cpp +++ b/frameworks/ets/ani/src/manager/ani_slot.cpp @@ -132,6 +132,11 @@ ani_object AniGetSlot(ani_env *env, ani_enum_item enumObj) ANS_LOGE("AniGetSlot -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } + if (slot == nullptr) { + ANS_LOGD("AniGetSlot -> slot is nullptr"); + AbilityRuntime::ThrowStsError(env, RETURN_EXCEPTION_VALUE, "slot is null"); + return nullptr; + } ani_object slotObj; if (!NotificationSts::WrapNotificationSlot(env, slot, slotObj)) { ANS_LOGE("WrapNotificationSlot faild"); diff --git a/frameworks/ets/ani/src/sts_common.cpp b/frameworks/ets/ani/src/sts_common.cpp index 253a124d3..31f5b6b53 100644 --- a/frameworks/ets/ani/src/sts_common.cpp +++ b/frameworks/ets/ani/src/sts_common.cpp @@ -515,8 +515,8 @@ ani_object newRecordClass(ani_env *env) ani_object ConvertArrayDoubleToAniObj(ani_env *env, const std::vector values) { - if (env == nullptr || values.empty()) { - ANS_LOGE("ConvertArrayDoubleToAniObj fail, env is nullptr or values is empty"); + if (env == nullptr) { + ANS_LOGE("ConvertArrayDoubleToAniObj fail, env is nullptr"); return nullptr; } ani_object arrayObj = newArrayClass(env, values.size()); diff --git a/frameworks/ets/ani/src/sts_slot.cpp b/frameworks/ets/ani/src/sts_slot.cpp index 7202f92ab..844c3fc89 100644 --- a/frameworks/ets/ani/src/sts_slot.cpp +++ b/frameworks/ets/ani/src/sts_slot.cpp @@ -21,18 +21,31 @@ namespace OHOS { namespace NotificationSts { -bool CheckOptionalFieldSlotTypeParam(const ani_env *env, const ani_class cls, const ani_object &object) +bool SetOptionalFieldSlotLevel( + ani_env *env, const ani_class cls, ani_object &object, const std::string fieldName, const SlotLevel value) { - if (env == nullptr) { - ANS_LOGE("env is null"); + ANS_LOGD("SetOptionalFieldSlotLevel call"); + if (env == nullptr || cls == nullptr || object == nullptr) { + ANS_LOGE("SetOptionalFieldSlotLevel failed, has nullptr"); return false; } - if (cls == nullptr) { - ANS_LOGE("cls is null"); + ani_field field = nullptr; + ani_status status = env->Class_FindField(cls, fieldName.c_str(), &field); + if (status != ANI_OK || field == nullptr) { + ANS_LOGE("Class_FindField failed or null field, status=%{public}d, fieldName=%{public}s", + status, fieldName.c_str()); return false; } - if (object == nullptr) { - ANS_LOGE("object is null"); + ani_enum_item enumItem = nullptr; + NotificationSts::SlotLevelCToEts(env, value, enumItem); + if (enumItem == nullptr) { + ANS_LOGE("null enumItem"); + return false; + } + status = env->Object_SetField_Ref(object, field, enumItem); + if (status != ANI_OK) { + ANS_LOGE("Object_SetField_Ref failed, status=%{public}d, fieldName=%{public}s", + status, fieldName.c_str()); return false; } return true; @@ -41,9 +54,9 @@ bool CheckOptionalFieldSlotTypeParam(const ani_env *env, const ani_class cls, co bool SetOptionalFieldSlotType( ani_env *env, const ani_class cls, ani_object &object, const std::string fieldName, const SlotType value) { - ANS_LOGD("WrapNotificationSlot call"); - if (!CheckOptionalFieldSlotTypeParam(env, cls, object)) { - ANS_LOGE("WrapNotificationSlot failed, has nullptr"); + ANS_LOGD("SetOptionalFieldSlotType call"); + if (env == nullptr || cls == nullptr || object == nullptr) { + ANS_LOGE("SetOptionalFieldSlotType failed, has nullptr"); return false; } ani_field field = nullptr; @@ -141,10 +154,19 @@ bool WrapNotificationSlot(ani_env *env, sptr slo ANS_LOGE("CreateClassObjByClassName fail"); return false; } + if (cls == nullptr || outAniObj == nullptr) { + ANS_LOGE("Create class failed"); + return false; + } + if (!SetOptionalFieldSlotType(env, cls, outAniObj, "notificationType", slot->GetType())) { ANS_LOGE("Set notificationType fail"); return false; } + if (!SetOptionalFieldSlotLevel(env, cls, outAniObj, "notificationLevel", slot->GetLevel())) { + ANS_LOGE("Set notificationLevel fail"); + return false; + } if (!WrapNotificationSlotByBoolean(env, slot, outAniObj)) { ANS_LOGE("set Boolean params fail"); return false; @@ -157,41 +179,11 @@ bool WrapNotificationSlot(ani_env *env, sptr slo ANS_LOGE("set String params fail"); return false; } - if (slot->GetVibrationStyle().size() != 0 - && !SetOptionalFieldArrayDouble(env, cls, outAniObj, "vibrationValues", slot->GetVibrationStyle())) { - ANS_LOGE("Set vibrationValues fail"); - return false; - } - ANS_LOGD("WrapNotificationSlot end"); - return true; -} - -bool SetOptionalFieldSlotLevel(ani_env *env, const ani_class cls, ani_object &object, const std::string fieldName, - const SlotLevel value) -{ - ANS_LOGD("SetOptionalFieldSlotLevel call"); - if (env == nullptr) { - ANS_LOGE("SetOptionalFieldSlotLevel failed, env is nullptr"); - return false; - } - ani_field field = nullptr; - ani_status status = env->Class_FindField(cls, fieldName.c_str(), &field); - if (status != ANI_OK || field == nullptr) { - ANS_LOGE("Class_FindField failed or null field, status=%{public}d, fieldName=%{public}s", - status, fieldName.c_str()); - return false; - } - ani_enum_item enumItem = nullptr; - if (!NotificationSts::SlotLevelCToEts(env, value, enumItem) || enumItem == nullptr) { - ANS_LOGE("get enumItem failed"); - return false; - } - status = env->Object_SetField_Ref(object, field, enumItem); - if (status != ANI_OK) { - ANS_LOGE("Object_SetField_Ref failed, status=%{public}d, fieldName=%{public}s", - status, fieldName.c_str()); + if (!SetOptionalFieldArrayDouble(env, cls, outAniObj, "vibrationValues", slot->GetVibrationStyle())) { + ANS_LOGE("Set vibrationValues fail"); return false; } + ANS_LOGD("WrapNotificationSlot end"); return true; } @@ -199,10 +191,6 @@ bool WrapNotificationSlotArray(ani_env *env, const std::vectorPromise_New(&aniResolver, &aniPromise)) { - ANS_LOGD("Promise_New faild"); + ANS_LOGE("Promise_New faild"); return nullptr; } bool noWithOperationInfo = false; -- Gitee From 4a1e93eb14b9a398c44784e505b66f1adeb8b254 Mon Sep 17 00:00:00 2001 From: heguokai Date: Tue, 17 Jun 2025 19:18:57 +0800 Subject: [PATCH 11/14] fixed function for RemoveAll Signed-off-by: heguokai --- .../ets/ani/include/subscribe/ani_remove.h | 1 + .../ets/ani/src/subscribe/ani_remove.cpp | 56 ++++++++++--------- .../ets/ani/src/subscribe/ani_subscribe.cpp | 2 + 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/frameworks/ets/ani/include/subscribe/ani_remove.h b/frameworks/ets/ani/include/subscribe/ani_remove.h index c10e15dc4..5b7680a87 100644 --- a/frameworks/ets/ani/include/subscribe/ani_remove.h +++ b/frameworks/ets/ani/include/subscribe/ani_remove.h @@ -24,6 +24,7 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reasonEnum); void AniRemoveAllForUserId(ani_env *env, ani_double userId); void AniRemoveAllForBundle(ani_env *env, ani_object bundle); +void AniRemoveAll(ani_env *env); } } #endif \ 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 8db7371bd..64e59665d 100644 --- a/frameworks/ets/ani/src/subscribe/ani_remove.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_remove.cpp @@ -35,19 +35,19 @@ void AniRemoveForBundle(ani_env *env, ani_object bundle, ani_object notification int32_t reasonType = 0; if (!NotificationSts::UnwrapBundleOption(env, bundle, option)) { ANS_LOGE("bundle is valid"); - std::string msg = "UnwrapBundleOption faild"; + std::string msg = "UnwrapBundleOption failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } if (!NotificationSts::UnWarpNotificationKey(env, notificationKey, key)) { ANS_LOGE("notificationKey is valid"); - std::string msg = "UnWarpNotificationKey faild"; + std::string msg = "UnWarpNotificationKey failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); - std::string msg = "UnWarpReasonEnum faild"; + std::string msg = "UnWarpReasonEnum failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } @@ -58,9 +58,9 @@ void AniRemoveForBundle(ani_env *env, ani_object bundle, ani_object notification return; } int ret = NotificationHelper::RemoveNotification(option, key.id, key.label, reasonType); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } @@ -79,7 +79,7 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn } if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); - std::string msg = "UnWarpReasonEnum faild"; + std::string msg = "UnWarpReasonEnum failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } @@ -91,9 +91,9 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn } ANS_LOGD("hashCode: %{public}s, reasonType: %{public}d", hashCodeStd.c_str(), reasonType); int ret = NotificationHelper::RemoveNotification(hashCodeStd, reasonType); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForHashCode ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForHashCode ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } @@ -112,7 +112,7 @@ void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reason } if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); - std::string msg = "UnWarpReasonEnum faild"; + std::string msg = "UnWarpReasonEnum failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } @@ -123,37 +123,40 @@ void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reason return; } int ret = NotificationHelper::RemoveNotifications(hashCodesStd, reasonType); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForHashCodes ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForHashCodes ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } } -void AniRemoveAllForBundle(ani_env *env, ani_object bundle) +void AniRemoveAll(ani_env *env) { ANS_LOGD("removeAll enter"); - int retcode = ERR_OK; - bool isForBundleUndefine = NotificationSts::IsUndefine(env, bundle); - if (isForBundleUndefine) { - retcode = NotificationHelper::RemoveNotifications(); - std::string msg = "IsUndefine falid"; - ANS_LOGE("IsUndefine is falid"); - OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); - return; + int ret = NotificationHelper::RemoveNotifications(); + if (ret != ERR_OK) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("AniRemoveAll ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); + std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } +} + +void AniRemoveAllForBundle(ani_env *env, ani_object bundle) +{ + ANS_LOGD("AniRemoveAllForBundle enter"); BundleOption option; if (!NotificationSts::UnwrapBundleOption(env, bundle, option)) { ANS_LOGE("bundle is valid"); - std::string msg = "UnwrapBundleOption faild"; + std::string msg = "UnwrapBundleOption failed"; 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) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } @@ -161,12 +164,11 @@ void AniRemoveAllForBundle(ani_env *env, ani_object bundle) void AniRemoveAllForUserId(ani_env *env, ani_double userId) { - ANS_LOGD("removeAll enter"); - ANS_LOGD("sts RemoveAll call, userId:%{public}lf", userId); + ANS_LOGD("AniRemoveAllForUserId enter"); 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) { + int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); 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 26bfbad84..00bea6b3e 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -42,6 +42,7 @@ static const char *UNSUBSCRIBE_SIGNATURE = static const char *REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE = "Lnotification/NotificationCommonDef/BundleOption;:V"; static const char *REMOVEALL_FOR_USERID_STGNATURE = "D:V"; +static const char *REMOVEALL_SIGNATURE =":V"; ani_object AniDistributeOperation(ani_env *env, ani_string hashcode, ani_object operationInfo) { @@ -125,6 +126,7 @@ void AniSubScribeRegistryInit(ani_env *env) REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE, reinterpret_cast(AniRemoveAllForBundle)}, ani_native_function {"nativeRemoveAllForUserId", REMOVEALL_FOR_USERID_STGNATURE, reinterpret_cast(AniRemoveAllForUserId)}, + ani_native_function {"nativeRemoveAll", REMOVEALL_SIGNATURE, reinterpret_cast(AniRemoveAll)}, }; ANS_LOGD("Start bind native methods to '%{public}s'", npName); -- Gitee From 1eb28f92930f101d913096287c8d43535b3e2e8d Mon Sep 17 00:00:00 2001 From: heguokai Date: Tue, 17 Jun 2025 19:29:34 +0800 Subject: [PATCH 12/14] add ets Signed-off-by: heguokai --- frameworks/ets/ets/@ohos.notificationSubscribe.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/ets/ets/@ohos.notificationSubscribe.ets b/frameworks/ets/ets/@ohos.notificationSubscribe.ets index 9bad8d255..00a67dd0e 100644 --- a/frameworks/ets/ets/@ohos.notificationSubscribe.ets +++ b/frameworks/ets/ets/@ohos.notificationSubscribe.ets @@ -82,6 +82,7 @@ export default namespace notificationSubscribe { export native function nativeSubscribeSelf(subscriber: NotificationSubscriber): void export native function nativeRemoveAllForBundle(bundle?: BundleOption): void; export native function nativeRemoveAllForUserId(userId: number): void; + export native function nativeRemoveAll(): void; export function subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback): void { if (subscriber == undefined || callback == undefined) { @@ -369,11 +370,10 @@ export default namespace notificationSubscribe { export function removeAll(bundle?: BundleOption): Promise { - let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { if (bundle == undefined) { - return notificationSubscribe.nativeRemoveAllForBundle(); + return notificationSubscribe.nativeRemoveAll(); } else { return notificationSubscribe.nativeRemoveAllForBundle(bundle); } @@ -392,7 +392,7 @@ export default namespace notificationSubscribe { throw errorParamInvalid; } let p = taskpool.execute((): void => { - return notificationSubscribe.nativeRemoveAllForBundle(); + return notificationSubscribe.nativeRemoveAll(); }); p.then( (e: NullishType): void => { -- Gitee From b665e6c04427d7433745823aa20737f58c8cf266 Mon Sep 17 00:00:00 2001 From: heguokai Date: Tue, 17 Jun 2025 11:44:49 +0000 Subject: [PATCH 13/14] update frameworks/ets/ani/src/subscribe/ani_subscribe.cpp. Signed-off-by: heguokai --- frameworks/ets/ani/src/subscribe/ani_subscribe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp index 00bea6b3e..f73b6c60b 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -42,7 +42,7 @@ static const char *UNSUBSCRIBE_SIGNATURE = static const char *REMOVEALL_FOR_BUNDLEOPTION_SIGNATURE = "Lnotification/NotificationCommonDef/BundleOption;:V"; static const char *REMOVEALL_FOR_USERID_STGNATURE = "D:V"; -static const char *REMOVEALL_SIGNATURE =":V"; +static const char *REMOVEALL_SIGNATURE = ":V"; ani_object AniDistributeOperation(ani_env *env, ani_string hashcode, ani_object operationInfo) { -- Gitee From 8495d11d4f0136b0d697f01766d7ffe9d8d3d982 Mon Sep 17 00:00:00 2001 From: cheerful_ricky Date: Thu, 27 Mar 2025 11:43:01 +0800 Subject: [PATCH 14/14] add notificationExtensionWrapper unit test Signed-off-by: cheerful_ricky --- services/ans/test/unittest/BUILD.gn | 47 +++ .../notification_extension_wrapper_test.cpp | 385 ++++++++++++++++++ 2 files changed, 432 insertions(+) create mode 100644 services/ans/test/unittest/notification_extension_wrapper_test.cpp diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 19aad802a..098cd250c 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -1341,6 +1341,52 @@ ohos_unittest("advanced_datashare_observer_unit_test") { part_name = "${component_name}" } +ohos_unittest("notification_extension_wrapper_unit_test") { + module_out_path = module_output_path + include_dirs = [ + ".", + "include", + "/${services_path}/ans/include", + "${services_path}/ans/test/unittest/mock/include", + ] + defines = [] + + sources = [ "notification_extension_wrapper_test.cpp" ] + + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:libans", + ] + + external_deps = [ + "ability_runtime:dataobs_manager", + "c_utils:utils", + "googletest:gtest_main", + "hilog:libhilog", + ] + + if (distributed_notification_service_feature_summary || + distributed_notification_service_feature_additional_control || + distributed_notification_service_feature_privileged_message) { + defines += [ "ENABLE_ANS_EXT_WRAPPER" ] + } + + if (distributed_notification_service_feature_privileged_message) { + defines += [ "ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER" ] + } + + if (distributed_notification_service_feature_additional_control) { + defines += [ "ENABLE_ANS_ADDITIONAL_CONTROL" ] + } + + if (distributed_notification_service_feature_summary) { + defines += [ "ENABLE_ANS_AGGREGATION" ] + } + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + ohos_unittest("advanced_notification_service_unit_test") { sanitize = { integer_overflow = true @@ -1407,6 +1453,7 @@ group("unittest") { ":disturb_manager_unit_test", ":notification_config_parse_test", ":notification_dialog_test", + ":notification_extension_wrapper_unit_test", ":notification_preferences_database_branch_test", ":notification_preferences_database_test", ":notification_preferences_test", diff --git a/services/ans/test/unittest/notification_extension_wrapper_test.cpp b/services/ans/test/unittest/notification_extension_wrapper_test.cpp new file mode 100644 index 000000000..9c6fe14e5 --- /dev/null +++ b/services/ans/test/unittest/notification_extension_wrapper_test.cpp @@ -0,0 +1,385 @@ +/* + * 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 "gtest/gtest.h" +#define private public +#include "notification_extension_wrapper.h" +#undef private + +using namespace testing; +using namespace testing::ext; +namespace OHOS { +namespace Notification { +const int32_t ACTIVE_DELETE = 0; +const int32_t PASSITIVE_DELETE = 1; + +static bool g_mockCalled = false; +static bool g_mockLocalSwitch = false; +static int g_mockUpdateByCancelReason = 0; + +static void MockSetLocalSwitch(bool status) +{ + g_mockCalled = true; + g_mockLocalSwitch = status; +} + +static void MockUpdateByCancel(const std::vector>& notifications, int deleteType) +{ + g_mockCalled = true; + g_mockUpdateByCancelReason = deleteType; +} + +class NotificationExtensionWrapperTest : public ::testing::Test { +protected: + void SetUp() override {} + void TearDown() override {} + static void SetUpTestCas() + { + g_mockCalled = false; + g_mockLocalSwitch = false; + g_mockUpdateByCancelReason = 0; + } + static void TearDownTestCase() {}; +}; + +HWTEST_F(NotificationExtensionWrapperTest, InitExtentionWrapper_Test, TestSize.Level0) +{ + OHOS::Notification::ExtensionWrapper extensionWrapper; + extensionWrapper.InitExtentionWrapper(); +#ifdef ENABLE_ANS_EXT_WRAPPER + // 验证extensionWrapperHandle_是否被正确初始化 + EXPECT_NE(extensionWrapper.extensionWrapperHandle_, nullptr); + + // 验证syncAdditionConfig_是否被正确初始化 + EXPECT_NE(extensionWrapper.syncAdditionConfig_, nullptr); +#else + EXPECT_EQ(extensionWrapper.extensionWrapperHandle_, nullptr); + EXPECT_EQ(extensionWrapper.syncAdditionConfig_, nullptr); +#endif + + // 验证localControl_、reminderControl_、bannerControl_是否被正确初始化 +#ifdef ENABLE_ANS_ADDITIONAL_CONTROL + EXPECT_NE(extensionWrapper.localControl_, nullptr); + EXPECT_NE(extensionWrapper.reminderControl_, nullptr); + EXPECT_NE(extensionWrapper.bannerControl_, nullptr); +#endif + + // 验证modifyReminderFlags_是否被正确初始化 +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER + EXPECT_NE(extensionWrapper.modifyReminderFlags_, nullptr); +#endif + + // 验证initSummary_是否被正确初始化 +#ifdef ENABLE_ANS_AGGREGATION + EXPECT_NE(extensionWrapper.initSummary_, nullptr); +#endif +} + + +HWTEST_F(NotificationExtensionWrapperTest, CheckIfSetlocalSwitch_001, TestSize.Level0) +{ + // 创建ExtensionWrapper对象 + ExtensionWrapper extensionWrapper; + // 设置extensionWrapperHandle_为nullptr + extensionWrapper.extensionWrapperHandle_ = nullptr; + // 调用待测函数 + extensionWrapper.CheckIfSetlocalSwitch(); + // 验证extensionWrapperHandle_仍然为nullptr + EXPECT_EQ(extensionWrapper.extensionWrapperHandle_, nullptr); +} + +HWTEST_F(NotificationExtensionWrapperTest, CheckIfSetlocalSwitch_002, TestSize.Level0) +{ + // 创建ExtensionWrapper对象 + ExtensionWrapper extensionWrapper; + // 设置extensionWrapperHandle_不为nullptr + extensionWrapper.extensionWrapperHandle_ = new int; + // 设置isRegisterDataSettingObserver为false + extensionWrapper.isRegisterDataSettingObserver = false; + // 调用待测函数 + extensionWrapper.CheckIfSetlocalSwitch(); + // 验证isRegisterDataSettingObserver为true + EXPECT_EQ(extensionWrapper.isRegisterDataSettingObserver, true); +} + +HWTEST_F(NotificationExtensionWrapperTest, CheckIfSetlocalSwitch_003, TestSize.Level0) +{ + // 创建ExtensionWrapper对象 + ExtensionWrapper extensionWrapper; + // 设置extensionWrapperHandle_不为nullptr + extensionWrapper.extensionWrapperHandle_ = new int; + // 设置isRegisterDataSettingObserver为true + extensionWrapper.isRegisterDataSettingObserver = true; + // 调用待测函数 + extensionWrapper.CheckIfSetlocalSwitch(); + // 验证isRegisterDataSettingObserver仍然为true + EXPECT_EQ(extensionWrapper.isRegisterDataSettingObserver, true); +} + +HWTEST_F(NotificationExtensionWrapperTest, SetlocalSwitch_False_Test, TestSize.Level0) +{ + OHOS::Notification::ExtensionWrapper extensionWrapper; + std::string enable = "false"; + extensionWrapper.setLocalSwitch_ = reinterpret_cast(&MockSetLocalSwitch); + + extensionWrapper.SetlocalSwitch(enable); + + EXPECT_TRUE(g_mockCalled); + EXPECT_FALSE(g_mockLocalSwitch); +} + +HWTEST_F(NotificationExtensionWrapperTest, SetlocalSwitch_True_Test, TestSize.Level0) +{ + OHOS::Notification::ExtensionWrapper extensionWrapper; + std::string enable = "true"; + extensionWrapper.setLocalSwitch_ = reinterpret_cast(&MockSetLocalSwitch); + + extensionWrapper.SetlocalSwitch(enable); + + EXPECT_TRUE(g_mockCalled); + EXPECT_TRUE(g_mockLocalSwitch); +} + +HWTEST_F(NotificationExtensionWrapperTest, SyncAdditionConfig_NullSyncAdditionConfig, TestSize.Level0) +{ + ExtensionWrapper extensionWrapper; + ErrCode result = extensionWrapper.SyncAdditionConfig("key", "value"); + EXPECT_EQ(result, 0); +} + +HWTEST_F(NotificationExtensionWrapperTest, SyncAdditionConfig_ValidSyncAdditionConfig, TestSize.Level0) +{ + ExtensionWrapper extensionWrapper; + extensionWrapper.syncAdditionConfig_ = [](const std::string& key, const std::string& value) { + return 1; + }; + ErrCode result = extensionWrapper.SyncAdditionConfig("key", "value"); + EXPECT_EQ(result, 1); +} + +HWTEST_F(NotificationExtensionWrapperTest, UpdateByCancel_NullUpdateByCancel, TestSize.Level0) +{ + // Arrange + ExtensionWrapper wrapper; + std::vector> notifications; + int deleteReason = 1; + int expectedReason = 0; + + wrapper.UpdateByCancel(notifications, deleteReason); + + EXPECT_NE(expectedReason, deleteReason); +} + +HWTEST_F(NotificationExtensionWrapperTest, UpdateByCancel_Normal_Test, TestSize.Level0) { + ExtensionWrapper wrapper; + wrapper.updateByCancel_ = reinterpret_cast(&MockUpdateByCancel); + + std::vector> notifications; + int deleteReason = 5; + + wrapper.UpdateByCancel(notifications, deleteReason); + + EXPECT_TRUE(g_mockCalled); + EXPECT_EQ(g_mockUpdateByCancelReason, 1); +} + +HWTEST_F(NotificationExtensionWrapperTest, GetUnifiedGroupInfo_NullFunction, TestSize.Level0) +{ + OHOS::Notification::ExtensionWrapper extensionWrapper; + OHOS::sptr request = nullptr; + EXPECT_EQ(extensionWrapper.GetUnifiedGroupInfo(request), 0); +} + +HWTEST_F(NotificationExtensionWrapperTest, GetUnifiedGroupInfo_ValidFunction, TestSize.Level0) +{ + OHOS::Notification::ExtensionWrapper extensionWrapper; + OHOS::sptr request = new OHOS::Notification::NotificationRequest(); + extensionWrapper.getUnifiedGroupInfo_ = [](const OHOS::sptr &request) { + return 1; + }; + EXPECT_EQ(extensionWrapper.GetUnifiedGroupInfo(request), 1); +} + + +HWTEST_F(NotificationExtensionWrapperTest, ReminderControl_NullReminderControl, TestSize.Level0) +{ + OHOS::Notification::ExtensionWrapper extensionWrapper; + std::string bundleName = "testBundle"; + int32_t result = extensionWrapper.ReminderControl(bundleName); + EXPECT_EQ(result, 0); +} + +HWTEST_F(NotificationExtensionWrapperTest, ReminderControl_ValidReminderControl, TestSize.Level0) +{ + OHOS::Notification::ExtensionWrapper extensionWrapper; + std::string bundleName = "testBundle"; + extensionWrapper.reminderControl_ = [](const std::string &bundleName) { return 1; }; + int32_t result = extensionWrapper.ReminderControl(bundleName); + EXPECT_EQ(result, 1); +} + +HWTEST_F(NotificationExtensionWrapperTest, BannerControl_NullBannerControl, TestSize.Level0) +{ + // Arrange + ExtensionWrapper wrapper; + std::string bundleName = "testBundle"; + + // Act + int32_t result = wrapper.BannerControl(bundleName); + + // Assert + EXPECT_EQ(-1, result); +} + +HWTEST_F(NotificationExtensionWrapperTest, BannerControl_ValidBannerControl, TestSize.Level0) +{ + // Arrange + ExtensionWrapper wrapper; + std::string bundleName = "testBundle"; + auto mockBannerControl = [](const std::string &bundleName) { return 0; }; + wrapper.bannerControl_ = mockBannerControl; + + // Act + int32_t result = wrapper.BannerControl(bundleName); + + // Assert + EXPECT_EQ(0, result); +} + +#ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER +HWTEST_F(NotificationExtensionWrapperTest, ModifyReminderFlags_NullCase, TestSize.Level0) { + // Arrange + OHOS::Notification::ExtensionWrapper wrapper; + wrapper.modifyReminderFlags_ = nullptr; + auto request = new NotificationRequest(); + + // Act + bool result = wrapper.ModifyReminderFlags(request); + + // Assert + ASSERT_FALSE(result); +} + +HWTEST_F(NotificationExtensionWrapperTest, ModifyReminderFlags_SuccessCase, TestSize.Level0) { + // Arrange + OHOS::Notification::ExtensionWrapper wrapper; + bool (*mockFunc)(const sptr &) = [](const sptr &req) { + return true; + }; + wrapper.modifyReminderFlags_ = mockFunc; + auto request = new NotificationRequest(); + + // Act + bool result = wrapper.ModifyReminderFlags(request); + + // Assert + ASSERT_TRUE(result); +} +#endif +HWTEST_F(NotificationExtensionWrapperTest, LocalControl_NullCase, TestSize.Level0) { + // Arrange + OHOS::Notification::ExtensionWrapper wrapper; + wrapper.localControl_ = nullptr; + auto request = new NotificationRequest(); + + // Act + int32_t result = wrapper.LocalControl(request); + + // Assert + ASSERT_EQ(0, result); // 预期返回 0 +} + +HWTEST_F(NotificationExtensionWrapperTest, LocalControl_SuccessCase, TestSize.Level0) { + // Arrange + OHOS::Notification::ExtensionWrapper wrapper; + int32_t (*mockFunc)(const sptr &) = [](const sptr &req) { + return 1; + }; + wrapper.localControl_ = mockFunc; + auto request = new NotificationRequest(); + + // Act + int32_t result = wrapper.LocalControl(request); + + // Assert + ASSERT_EQ(1, result); +} + +HWTEST_F(NotificationExtensionWrapperTest, convertToDelType_ActiveDelete, TestSize.Level0) +{ + // Arrange + int32_t deleteReason = NotificationConstant::PACKAGE_CHANGED_REASON_DELETE + 1; + int32_t expectedDelType = ACTIVE_DELETE; + + // Act + int32_t actualDelType = OHOS::Notification::ExtensionWrapper::convertToDelType(deleteReason); + + // Assert + ASSERT_EQ(expectedDelType, actualDelType); +} + +HWTEST_F(NotificationExtensionWrapperTest, convertToDelType_PassiveDelete, TestSize.Level0) +{ + // Arrange + int32_t deleteReason = NotificationConstant::PACKAGE_CHANGED_REASON_DELETE; + int32_t expectedDelType = PASSITIVE_DELETE; + + // Act + int32_t actualDelType = OHOS::Notification::ExtensionWrapper::convertToDelType(deleteReason); + + // Assert + ASSERT_EQ(expectedDelType, actualDelType); +} + +HWTEST_F(NotificationExtensionWrapperTest, convertToDelType_UserRemovedReasonDelete, TestSize.Level0) +{ + // Arrange + int32_t deleteReason = NotificationConstant::USER_REMOVED_REASON_DELETE; + int32_t expectedDelType = PASSITIVE_DELETE; + + // Act + int32_t actualDelType = OHOS::Notification::ExtensionWrapper::convertToDelType(deleteReason); + + // Assert + ASSERT_EQ(expectedDelType, actualDelType); +} + +HWTEST_F(NotificationExtensionWrapperTest, convertToDelType_DisableSlotReasonDelete, TestSize.Level0) +{ + // Arrange + int32_t deleteReason = NotificationConstant::DISABLE_SLOT_REASON_DELETE; + int32_t expectedDelType = PASSITIVE_DELETE; + + // Act + int32_t actualDelType = OHOS::Notification::ExtensionWrapper::convertToDelType(deleteReason); + + // Assert + ASSERT_EQ(expectedDelType, actualDelType); +} + +HWTEST_F(NotificationExtensionWrapperTest, convertToDelType_DisableNotificationReasonDelete, TestSize.Level0) +{ + // Arrange + int32_t deleteReason = NotificationConstant::DISABLE_NOTIFICATION_REASON_DELETE; + int32_t expectedDelType = PASSITIVE_DELETE; + + // Act + int32_t actualDelType = OHOS::Notification::ExtensionWrapper::convertToDelType(deleteReason); + + // Assert + ASSERT_EQ(expectedDelType, actualDelType); +} +} //namespace Notification +} //namespace OHOS \ No newline at end of file -- Gitee