diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index 627f97101a87babd09b04e2394b3e6b6ba6c4289..546a571ad7c65bd38cff626545f4a021b43c87d5 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", @@ -56,8 +61,14 @@ 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_do_not_disturb_date.cpp", "./src/manager/ani_on.cpp", "./src/manager/ani_push_callback.cpp", + "./src/manager/ani_remove_group.cpp", + "./src/manager/ani_open_settings.cpp", + "./src/manager/ani_disable_notification.cpp", + "./src/manager/ani_sync_config.cpp", + "./src/manager/ani_distributed.cpp", "./src/manager/ani_support_template.cpp", "./src/manager/ani_distributed_enable.cpp", ] diff --git a/frameworks/ets/ani/include/manager/ani_cance.h b/frameworks/ets/ani/include/manager/ani_cance.h index 5e3f19fd6e1347c8614b21f402ee4452e578beea..485c27fa7feb912326e53cc5559ef0106537b73b 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_disable_notification.h b/frameworks/ets/ani/include/manager/ani_disable_notification.h new file mode 100644 index 0000000000000000000000000000000000000000..70f736518296a7cb51da4356ef05642277aaeb46 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_disable_notification.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DISABLE_NOTIFICATION_H + #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DISABLE_NOTIFICATION_H + #include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { + + void AniDisableNotificationFeature(ani_env *env,ani_boolean disabled, ani_object bundleList); + +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_display_badge.h b/frameworks/ets/ani/include/manager/ani_display_badge.h index a9489f60b5f1bf4b067e6f0f71d28eb30ba1283b..a292920bfbab2b1d55cc648bd023ac3086857c21 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.h b/frameworks/ets/ani/include/manager/ani_distributed.h new file mode 100644 index 0000000000000000000000000000000000000000..d1f3c2bb6d034cd30436b351c834255b1ebec776 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_distributed.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_DISTRIBUTED_H + #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DISTRIBUTED_H + #include "ani.h" +namespace OHOS { +namespace NotificationManagerSts { + const int32_t DISTURB_DEFAULT_FLAG = 13; + void AniSetDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enable); + void AniSetDistributedEnabledByBundle(ani_env *env, ani_object obj, ani_string deviceType, ani_boolean enable); + void AniSetTargetDeviceStatus(ani_env* env, ani_string deviceType, ani_double status); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_distributed_enable.h b/frameworks/ets/ani/include/manager/ani_distributed_enable.h old mode 100755 new mode 100644 index 4a712316f03ebb725c389e09f59b7dcf35b1724f..1520012f3e8e740837c0dc5f1783f05059a24cc1 --- a/frameworks/ets/ani/include/manager/ani_distributed_enable.h +++ b/frameworks/ets/ani/include/manager/ani_distributed_enable.h @@ -1,28 +1,32 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_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 +/* + * 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); +ani_boolean AniIsSmartReminderEnabled(ani_env *env, ani_string deviceType); +void AniSetSmartReminderEnabled(ani_env *env, ani_string deviceType, ani_boolean enable); +void AniSetDistributedEnabledBySlot(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 100755 index 0000000000000000000000000000000000000000..edbf81027a55e8a1173d2b56709840cb4736675e --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_do_not_disturb_date.h @@ -0,0 +1,30 @@ +/* + * 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 + 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 b4a0ac9974a8d60b27df4f62e42d1fc972b90ee5..c5e9b03c1852126ee277b0bdc2b61a4a76e8d0cf 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 b2d18712d9539477d0ec34866afa130233cb4378..3d8861090ad05acd61b3b09e194dbd8df996b339 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 93dee434858cc6e9c97dcc0a8529d90decc8c629..bc6f74bf77ed96c306c81ccbf8fd907a41c44534 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); +ani_boolean AniIsNotificationEnabledSync(ani_env *env); +ani_object AniGetAllNotificationEnabledBundles(ani_env *env); void AniSetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId, ani_boolean enabled); ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId); } // namespace NotificationManagerSts 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 0000000000000000000000000000000000000000..7da3291e7fb94646fb78f59c202ef0dd16429695 --- /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 +#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 fd18fc59cb1cc0228cdf5aeadb46858874e205b0..33a018c6aa3a14c25c66f3f91786a508b0cb2626 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 0000000000000000000000000000000000000000..1ec3dbe0865779d0a7958cecdb4adf0b5537e340 --- /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 0000000000000000000000000000000000000000..8a3451a598196c8dcdb663f4eac8721600c904a7 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_sync_config.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_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_int 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 a1bc560614f52b47a3bd2f6464ceb0834b9c16eb..ce21d7dddb7bb78745b60864f49d64c0726c9ea9 100644 --- a/frameworks/ets/ani/include/sts_bundle_option.h +++ b/frameworks/ets/ani/include/sts_bundle_option.h @@ -24,7 +24,8 @@ namespace NotificationSts { bool UnwrapBundleOption(ani_env *env, ani_object param, BundleOption& option); bool WrapBundleOption(ani_env* env, const std::shared_ptr &bundleOption, ani_object &bundleObject); - +ani_object GetAniArrayBundleOption(ani_env* env, + const std::vector &bundleOptions); bool UnwrapArrayBundleOption(ani_env *env, ani_ref arrayObj, std::vector& options); } } diff --git a/frameworks/ets/ani/include/sts_disturb_mode.h b/frameworks/ets/ani/include/sts_disturb_mode.h index eb208a289c002213ba9a23d28c7da886c2767efb..c5a6f627dc4be1c0b72550d2adba6bbd495f62e9 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 bf9cba1126b61f0356286a7489aa5f35d85a402a..bc183769cee7e3de6757c713865dc133d688a66c 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" @@ -32,6 +33,15 @@ using SlotLevel = OHOS::Notification::NotificationSlot::NotificationLevel; using ContentType = OHOS::Notification::NotificationContent::Type; using ButtonOption = OHOS::Notification::NotificationButtonOption; using NotificationDoNotDisturbDate = OHOS::Notification::NotificationDoNotDisturbDate; +using NotificationConstant = OHOS::Notification::NotificationConstant; + +enum STSDoNotDisturbType { + TYPE_NONE = 0, + TYPE_ONCE = 1, + TYPE_DAILY = 2, + TYPE_CLEARLY = 3, +}; + using RemindType = OHOS::Notification::NotificationConstant::RemindType; enum STSSlotType { UNKNOWN_TYPE = 0, @@ -87,6 +97,11 @@ static bool StsToC(const STSContentType inType, ContentType &outType); static bool CToSts(const ContentType inType, STSContentType &outType); }; +class StsDoNotDisturbTypeUtils { +public: +static bool StsToC(const STSDoNotDisturbType inType, + OHOS::Notification::NotificationConstant::DoNotDisturbType &outType); +}; class StsRemindTypeUtils { public: static bool StsToC(const STSRemindType inType, RemindType &outType); @@ -147,6 +162,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 UnWarpNotificationDoNotDisturbDate(ani_env* env, const ani_object doNotDisturbDateObj, + NotificationDoNotDisturbDate& doNotDisturbDate); bool DeviceRemindTypeCToEts(ani_env *env, RemindType remindType, ani_enum_item &enumItem); bool DeviceRemindTypeEtsToC(ani_env *env, ani_enum_item enumItem, RemindType &remindType); diff --git a/frameworks/ets/ani/include/sts_request.h b/frameworks/ets/ani/include/sts_request.h index 02a69f21dac9036e845ca397e2fda3772dba9c70..cd8e83ce5b40e688224e945b23abc81e9bbaa616 100644 --- a/frameworks/ets/ani/include/sts_request.h +++ b/frameworks/ets/ani/include/sts_request.h @@ -34,7 +34,7 @@ struct StsDistributedOptions { void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOptions distributedOptions); bool WarpNotificationUnifiedGroupInfo(ani_env* env, const std::shared_ptr &groupInfo, ani_object &groupInfoObject); - +bool UnWarpNotificationFilter(ani_env *env, ani_object obj, LiveViewFilter& filter); ani_status UnWarpNotificationRequest( ani_env *env, ani_object obj, std::shared_ptr ¬ificationRequest); bool WarpNotificationRequest( diff --git a/frameworks/ets/ani/include/sts_subscribe.h b/frameworks/ets/ani/include/sts_subscribe.h index 9f948df7ee4adf9f9929beaae1ff62e58e3e3859..7088a0988ee03aa8b90499cbb21f2381a6689707 100644 --- a/frameworks/ets/ani/include/sts_subscribe.h +++ b/frameworks/ets/ani/include/sts_subscribe.h @@ -113,6 +113,7 @@ public: bool Subscribe(ani_env *env, ani_object subscriber, ani_object info); bool UnSubscribe(ani_env *env, ani_object subscriber); + bool SubscribeSelf(ani_env *env, ani_object subscriber); private: SubscriberInstanceManager() {} diff --git a/frameworks/ets/ani/include/subscribe/ani_remove.h b/frameworks/ets/ani/include/subscribe/ani_remove.h index a60aa5ab895341aa33e0008a048746903b51c7c0..c10e15dc4aef6d01dc1a76ed416bb38a7047457c 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 180bedaac1e604c1f00d66df5984e4cf0889b063..600558eff0052d46de28f884795021bc72bc3f8b 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_disable_notification.cpp b/frameworks/ets/ani/src/manager/ani_disable_notification.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a00ad24425d66050b9c011413cc1e754009a5045 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_disable_notification.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_disable_notification.h" + +#include "inner_errors.h" +#include "notification_helper.h" +#include "ans_log_wrapper.h" +#include "sts_throw_erro.h" +#include "sts_common.h" +#include "sts_bundle_option.h" +#include "sts_notification_manager.h" + +namespace OHOS { +namespace NotificationManagerSts { + +void AniDisableNotificationFeature(ani_env *env,ani_boolean disabled, ani_object bundleList) +{ + ANS_LOGD("disableNotificationFeature enter"); + std::vector bundleListStd; + if (NotificationSts::GetStringArrayByAniObj(env, bundleList, bundleListStd) != ANI_OK) { + ANS_LOGE("bundleList is invalid"); + 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 != CJSystemapi::Notification::SUCCESS_CODE) { + ANS_LOGE("disableNotificationFeature error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } +} + +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_display_badge.cpp b/frameworks/ets/ani/src/manager/ani_display_badge.cpp index 7cba58762886d3307d263768c29931a6892f6f85..ed01c043a4b222fc50caf9a261a80602b443a487 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.cpp b/frameworks/ets/ani/src/manager/ani_distributed.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6aedae0fe1505718b4c01e41d67da0e323c42771 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_distributed.cpp @@ -0,0 +1,106 @@ +/* + * 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.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 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); + ANS_LOGD("sts setDistributedEnableByBundle option bundleName: %{public}s, uid: %{public}d, bFlag: %{public}d", option.GetBundleName().c_str(), + option.GetUid(), bFlag); + if(bFlag) { + returncode = Notification::NotificationHelper::EnableDistributedByBundle(option,NotificationSts::AniBooleanToBool(enable)); + } else { + 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 AniSetDistributedEnabledByBundle(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); + ANS_LOGD("sts setDistributedEnabledByBundle option bundleName: %{public}s, uid: %{public}d, bFlag: %{public}d", option.GetBundleName().c_str(), + option.GetUid(), bFlag); + if(bFlag) { + returncode = Notification::NotificationHelper::SetDistributedEnabledByBundle(option,deviceTypeStr,NotificationSts::AniBooleanToBool(enable)); + } else { + 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); +} +} // namespace NotificationManagerSts +} // namespace OHOS \ 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 old mode 100755 new mode 100644 index fa63aae21f7f54a9556096adcb97535ebd5046fe..de662556664bf74d6583643a19125ee144993691 --- a/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp @@ -1,100 +1,214 @@ -/* - * 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 +/* + * 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) { + ANS_LOGE("AniSetDistributedEnable -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(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) { + ANS_LOGE("AniIsDistributedEnabled -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(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) { + ANS_LOGE("AniIsDistributedEnabledByBundle -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(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) { + ANS_LOGE("AniIsDistributedEnabledByBundle -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniIsDistributedEnabledByBundle end, enabled: %{public}d, returncode: %{public}d", enabled, externalCode); + return NotificationSts::BoolToAniBoolean(enabled); +} + +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 AniSetSmartReminderEnabled(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 AniSetDistributedEnabledBySlot(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; +} +} +} 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 100755 index 0000000000000000000000000000000000000000..2e9555f8eb1538f906bab06bac429a45f71863cf --- /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 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 0d7158d5f6d064520851b864d83e5fc771a20b27..75e29714e55bf8695de40b10e987eab6cfc12683 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 @@ -13,13 +13,14 @@ * limitations under the License. */ #include "ani_do_not_disturb_profile.h" - #include "inner_errors.h" #include "notification_helper.h" +#include "notification_do_not_disturb_date.h" #include "ans_log_wrapper.h" #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 74e1ccd83dbfdfe7890bc9aae3ce631471b10ab3..93c02e57210c57e14c623bc6b71a00719444e6a3 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 d5679284e4593fcd971da3741f3c33750c4c13f5..cd9455e4822e9172e06f87bb1c5c66aae3aa8184 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -20,11 +20,17 @@ #include "ani_cance.h" #include "ani_notification_enable.h" #include "ani_do_not_disturb_profile.h" +#include "ani_do_not_disturb_date.h" #include "ani_get_active.h" #include "ani_publish.h" #include "ani_local_live_view.h" #include "ani_request_enable.h" #include "ani_on.h" +#include "ani_remove_group.h" +#include "ani_open_settings.h" +#include "ani_disable_notification.h" +#include "ani_sync_config.h" +#include "ani_distributed.h" #include "ani_support_template.h" #include "ani_distributed_enable.h" @@ -75,6 +81,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 +104,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 +134,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(AniSetDistributedEnabledByBundle)}, + ani_native_function {"nativesetSmartReminderEnabled", nullptr, + reinterpret_cast(AniSetSmartReminderEnabled)}, + ani_native_function {"nativeisSmartReminderEnabled", nullptr, + reinterpret_cast(AniIsSmartReminderEnabled)}, + ani_native_function {"nativesetDistributedEnabledBySlot", nullptr, + reinterpret_cast(AniSetDistributedEnabledBySlot)}, + 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 daaa2baefa175dcef1003722bbbdb8b91a78d261..54647dac8dbed7e126117a700be8078872b57719 100644 --- a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp @@ -27,7 +27,7 @@ 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) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); @@ -65,7 +65,7 @@ ani_boolean AniIsNotificationEnabledWithBundleOption(ani_env *env, ani_object bu } int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + if (externalCode != CJSystemapi::Notification::SUCCESS_CODE) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsNotificationEnabledWithBundleOption -> error, errorCode: %{public}d", externalCode); return ANI_FALSE; @@ -86,13 +86,42 @@ 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 != CJSystemapi::Notification::SUCCESS_CODE) { 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("AniGetAllNotificationEnabledBundles call"); + bool allowed = false; + auto ret = Notification::NotificationHelper::IsAllowedNotifySelf(allowed); + ANS_LOGD("AniGetAllNotificationEnabledBundles end, ret: %{public}d", ret); + return NotificationSts::BoolToAniBoolean(allowed); +} + ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId) { ANS_LOGD("AniGetSyncNotificationEnabledWithoutApp call"); @@ -101,8 +130,8 @@ ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double use 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); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return NotificationSts::BoolToAniBoolean(false); } ANS_LOGD("End success, enabled: %{public}d,returncode: %{public}d", enabled, externalCode); @@ -116,8 +145,8 @@ void AniSetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId, an 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); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; } ANS_LOGD("AniSetSyncNotificationEnabledWithoutApp end"); 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 0000000000000000000000000000000000000000..5a589a28f6a35ddbccd5cd4022afac63a61b5590 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_open_settings.cpp @@ -0,0 +1,356 @@ +/* + * 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 225be2cd112a5f1b375df74c74d21f458ce1b3fc..5829ce0b1334abba588bb5d9b2c63eca96d43757 100644 --- a/frameworks/ets/ani/src/manager/ani_publish.cpp +++ b/frameworks/ets/ani/src/manager/ani_publish.cpp @@ -19,6 +19,7 @@ #include "ans_log_wrapper.h" #include "sts_throw_erro.h" #include "sts_common.h" +#include "sts_bundle_option.h" #include "sts_request.h" #include "notification_request.h" @@ -63,5 +64,65 @@ void AniPublishWithId(ani_env *env, ani_object obj, ani_double userId) } 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 != CJSystemapi::Notification::SUCCESS_CODE) { + 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) { + ANS_LOGE("AniPublishAsBundleWithBundleOption: UnWarpNotificationRequest failed"); + NotificationSts::ThrowStsErroWithMsg(env, "AniPublishWithId ERROR_INTERNAL_ERROR"); + return; + } + + BundleOption option; + if (NotificationSts::UnwrapBundleOption(env, representativeBundle, option) != true) { + ANS_LOGE("AniPublishAsBundleWithBundleOption UnwrapBundleOption fail"); + 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 != CJSystemapi::Notification::SUCCESS_CODE) { + 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 0000000000000000000000000000000000000000..d1b1d03ac38fe5f822fb417091d24c3f53527d56 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_remove_group.cpp @@ -0,0 +1,54 @@ +/* + * 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 0000000000000000000000000000000000000000..bc796fa7c0e7533f1817a53f5d15361e18f06a00 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_sync_config.cpp @@ -0,0 +1,59 @@ +/* + * 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 { + +ani_int AniSetAdditionalConfig(ani_env *env, ani_string key ,ani_string value) +{ + ANS_LOGD("sts setAdditionalConfig call"); + std::string keyStr; + if (env == nullptr || key == nullptr) { + ANS_LOGE("Invalid env or key is null"); + return ANI_FALSE; + } + 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 ANI_FALSE; + } + 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 ANI_FALSE; + } + 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 ANI_TRUE; +} + +} // 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 ecc112188c8ddc48215f2134f4ac695343d498d5..5f89307c847a276f4c372c8e3de3fa8755fc679a 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 a24e389b81a86b1d135b60866bf0b88ac69a3007..66eba7a0045ba2cf2cd8fbf47cd1d636329ca7dd 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 afc5f6c1b68c925b2c34a144890c7d00491ac243..df2757f87ffcb82000c2237210771137c53f38e3 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,64 @@ 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 ed25b307bb2806fb679465364ae0e75abfd8597f..ed3de90e93ef280828b63b2f1f0a5e857a91ef28 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 441e053c15b8a2f3fe4367b91c359d7c6f7730dd..54dd672836f778c9dc014300b5561656387ed849 100644 --- a/frameworks/ets/ani/src/sts_subscribe.cpp +++ b/frameworks/ets/ani/src/sts_subscribe.cpp @@ -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 = 0; + status = NotificationHelper::SubscribeNotificationSelf(stsSubscriber); + if (status != 0) { + 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 be660d9fb26be701c01aac5d7bf653b9429f0e40..8db7371bd4f5264f60385f70b7a168c68e32dd8f 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 03f5caef50e9d191218e4c5b9aabc725d0234386..bb41cdb401d119a8b2d4059106b0407909e5011d 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"); @@ -110,6 +119,9 @@ 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 ee23075728288c05da4fb12ea1b367fbc6faa913..f621dcb2f81deb5b9f92c8c3937743588ff32b09 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 b6f13916283b7d13f561d645c822027451a7d2e8..21a9c6bc188ba493344057426395ef579f26ee7a 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