diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index 34ea02605198fdebb9480ea0e45dc6f0fe51c474..9931da8c7624e67b5993231b931b74e44b72bf5e 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_support_template.cpp", + "./src/manager/ani_distributed_enable.cpp", "./src/manager/ani_on.cpp", "./src/manager/ani_push_callback.cpp", ] 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 0000000000000000000000000000000000000000..4a712316f03ebb725c389e09f59b7dcf35b1724f --- /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 3fdb7013da4c1a01c51a57f6390d418cef5fd2f9..93dee434858cc6e9c97dcc0a8529d90decc8c629 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 0000000000000000000000000000000000000000..9d739c02289934a6c785a59b1514d25866aaa601 --- /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 GetDeviceRemindType(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 f40c521150dd48980804906fa21e7f3e56b185fe..bf9cba1126b61f0356286a7489aa5f35d85a402a 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 0000000000000000000000000000000000000000..95e4815c405603a520ac32027d22e10166b9a700 --- /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 != 0) { + 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 != 0) { + 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 != 0) { + 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 (ANI_OK != NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr)) { + 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 != 0) { + 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 ed6f74a8d3d02e5f15a71414af7c1f0afda5f2cb..f99a7cacff6b17d5454c2175229f845da9e37899 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -24,6 +24,8 @@ #include "ani_publish.h" #include "ani_local_live_view.h" #include "ani_request_enable.h" +#include "ani_support_template.h" +#include "ani_distributed_enable.h" #include "ani_on.h" namespace OHOS { @@ -73,6 +75,18 @@ static std::array kitManagerFunctions = { ani_native_function {"nativeRequestEnableNotification", "Lapplication/UIAbilityContext/UIAbilityContext;:Lstd/core/Promise;", reinterpret_cast(AniRequestEnableNotification)}, + 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(GetDeviceRemindType)}, + ani_native_function {"nativeGetSyncNotificationEnabledWithoutApp", nullptr, + reinterpret_cast(AniGetSyncNotificationEnabledWithoutApp)}, + ani_native_function {"nativeSetSyncNotificationEnabledWithoutApp", nullptr, + reinterpret_cast(AniSetSyncNotificationEnabledWithoutApp)}, ani_native_function {"nativeOn", "Lstd/core/String;" "Lstd/core/Function1;" diff --git a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp index 9c987eedcbca2af5079f22b884be541b1a4f5cd8..1789e7ceb9db916702bc7ae47d2a18d6e0010726 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 != 0) { + 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 != 0) { + 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 0000000000000000000000000000000000000000..3c3beb537f16fca4a3d05d63f4381fb7ecccc8d1 --- /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 (ANI_OK != NotificationSts::GetStringByAniString(env, templateName, templateNameStr)) { + 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 != 0) { + 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 GetDeviceRemindType(ani_env *env) +{ + ANS_LOGD("GetDeviceRemindType 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 != 0) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("GetDeviceRemindType error, errorCode: %{public}d", externalCode); + return nullptr; + } + ani_enum_item remindTypeItem {}; + if (!NotificationSts::DeviceRemindTypeCToEts(env, remindType, remindTypeItem)) { + NotificationSts::ThrowStsErroWithMsg(env, "GetDeviceRemindType:failed to WrapNotificationSlotArray"); + return nullptr; + } + ANS_LOGD("GetDeviceRemindType 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 dfd92189c5599dd90fa29e13cc8d2a6537e071ba..8a7763d06513bf31cf5244f6d91adda7a7b325c6 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 7dcb4589e447c25129cef4777c099a865c6d7054..ca2cf1f168a0700ecc8c84133412d5fdb043c155 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; @@ -160,6 +167,15 @@ export default namespace notificationManager { export native function nativeIsNotificationEnabledWithBundleOption(bundleOption: BundleOption): boolean; export native function nativeSetNotificationEnable(bundle: BundleOption, enable: boolean): void; export native function nativeRequestEnableNotification(content: UIAbilityContext): Promise; + export native function 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; + export native function nativeOn( type: 'checkNotification', callback: CallbackForCheckInfo, checkRequest?: NotificationCheckRequest): int; @@ -1310,6 +1326,274 @@ export default namespace notificationManager { ) } + 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) { + let error: BusinessError = { + code: 410, + message : "callback must be not null" + } + throw error; + } + 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) { + let error: BusinessError = { + code: 410, + message : "callback must be not null" + } + throw error; + } + 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) { + let error: BusinessError = { + code: 410, + message : "callback must be not null" + } + throw error; + } + 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) { + let error: BusinessError = { + code: 410, + message : "callback must be not null" + } + throw error; + } + 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) { + let error: BusinessError = { + code: 410, + message : "callback must be not null" + } + throw error; + } + 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) { + let error: BusinessError = { + code: 410, + message : "callback must be not null" + } + throw error; + } + 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) { + let error: BusinessError = { + code: 410, + message : "callback must be not null" + } + throw error; + } + 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); + }) export interface NotificationCheckResult { code: number; message: string;