diff --git a/frameworks/ets/ani/BUILD.gn b/frameworks/ets/ani/BUILD.gn index fa0771b8a5952d3a86a2e53fd77acdcd52fd59dc..46336e3a10f08cac02050894918af79048deadd1 100644 --- a/frameworks/ets/ani/BUILD.gn +++ b/frameworks/ets/ani/BUILD.gn @@ -45,6 +45,11 @@ ohos_shared_library("notification_manager_ani") { "./src/sts_notification_content.cpp", "./src/sts_template.cpp", "./src/sts_request.cpp", + "./src/sts_subscribe.cpp", + "./src/sts_subscriber.cpp", + "./src/sts_sorting_map.cpp", + "./src/sts_subscribe_info.cpp", + "./src/sts_sorting.cpp", "./src/manager/ani_local_live_view.cpp", "./src/manager/ani_publish.cpp", "./src/manager/ani_display_badge.cpp", @@ -52,10 +57,18 @@ ohos_shared_library("notification_manager_ani") { "./src/manager/ani_cance.cpp", "./src/manager/ani_notification_enable.cpp", "./src/manager/ani_do_not_disturb_profile.cpp", + "./src/manager/ani_do_not_disturb_date.cpp", "./src/manager/ani_get_active.cpp", "./src/manager/ani_manager.cpp", "./src/manager/ani_request_enable.cpp", "./src/manager/ani_ans_dialog_callback.cpp", + "./src/manager/ani_on.cpp", + "./src/manager/ani_push_callback.cpp", + "./src/manager/ani_support_template.cpp", + "./src/manager/ani_distributed_enable.cpp", + "./src/manager/ani_remove_group.cpp", + "./src/manager/ani_open_settings.cpp", + "./src/manager/ani_sync_config.cpp", ] cflags = [] @@ -68,6 +81,12 @@ ohos_shared_library("notification_manager_ani") { "${frameworks_path}/cj/ffi:cj_notification_manager_ffi", ] + defines = [] + + if (distributed_notification_service_feature_local_liveview) { + defines += [ "ANS_FEATURE_LIVEVIEW_LOCAL_LIVEVIEW" ] + } + external_deps = [ "c_utils:utils", "hilog:libhilog", @@ -87,6 +106,7 @@ ohos_shared_library("notification_manager_ani") { "ability_runtime:abilitykit_native", "ability_runtime:app_context", "ace_engine:ace_uicontent", + "access_token:libtokenid_sdk", ] innerapi_tags = [ "platformsdk" ] diff --git a/frameworks/ets/ani/include/manager/ani_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_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_enable.h b/frameworks/ets/ani/include/manager/ani_distributed_enable.h new file mode 100755 index 0000000000000000000000000000000000000000..385c801ac758916f36e3efe9d5347a8e50ee52cb --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_distributed_enable.h @@ -0,0 +1,36 @@ +/* + * 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 { +const int32_t DISTURB_DEFAULT_FLAG = 13; + +ani_boolean AniIsDistributedEnabled(ani_env* env); +ani_boolean AniIsDistributedEnabledByBundle(ani_env* env, ani_object obj); +ani_boolean AniIsDistributedEnabledByBundleType(ani_env* env, ani_object obj, ani_string deviceType); +void AniSetDistributedEnable(ani_env* env, ani_boolean enabled); +void AniSetDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enable); +void AniSetDistributedEnableByBundleAndType(ani_env *env, ani_object obj, ani_string deviceType, ani_boolean enable); +void AniSetTargetDeviceStatus(ani_env* env, ani_string deviceType, ani_double status); +ani_boolean AniIsSmartReminderEnabled(ani_env *env, ani_string deviceType); +void AniSetSmartReminderEnable(ani_env *env, ani_string deviceType, ani_boolean enable); +void AniSetDistributedEnableBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType, ani_boolean enable); +ani_boolean AniIsDistributedEnabledBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_do_not_disturb_date.h b/frameworks/ets/ani/include/manager/ani_do_not_disturb_date.h new file mode 100644 index 0000000000000000000000000000000000000000..721ba1d523602e14576322ac06efb5e16de73520 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_do_not_disturb_date.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DO_NOT_DISTURB_DATA_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_DO_NOT_DISTURB_DATA_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +void AniSetDoNotDisturbDate(ani_env *env, ani_object date); +void AniSetDoNotDisturbDateWithId(ani_env *env, ani_object date, ani_double userId); +ani_object AniGetDoNotDisturbDate(ani_env *env); +ani_object AniGetDoNotDisturbDateWithId(ani_env *env, ani_double userId); +ani_boolean AniIsSupportDoNotDisturbMode(ani_env *env); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_do_not_disturb_profile.h b/frameworks/ets/ani/include/manager/ani_do_not_disturb_profile.h index 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 3fdb7013da4c1a01c51a57f6390d418cef5fd2f9..bb657a6e239da1362e1b72077b12874c8211205e 100644 --- a/frameworks/ets/ani/include/manager/ani_notification_enable.h +++ b/frameworks/ets/ani/include/manager/ani_notification_enable.h @@ -23,6 +23,11 @@ ani_boolean AniIsNotificationEnabled(ani_env *env); ani_boolean AniIsNotificationEnabledWithId(ani_env *env, ani_double userId); ani_boolean AniIsNotificationEnabledWithBundleOption(ani_env *env, ani_object bundleOption); void AniSetNotificationEnable(ani_env *env, ani_object bundleOption, ani_boolean enable); +void AniSetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId, ani_boolean enabled); +ani_boolean AniIsNotificationEnabledSync(ani_env *env); +ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId); +ani_object AniGetAllNotificationEnabledBundles(ani_env *env); +void AniDisableNotificationFeature(ani_env *env, ani_boolean disabled, ani_object bundleList); } // namespace NotificationManagerSts } // namespace OHOS #endif diff --git a/frameworks/ets/ani/include/manager/ani_on.h b/frameworks/ets/ani/include/manager/ani_on.h new file mode 100755 index 0000000000000000000000000000000000000000..911d45fd82d0d120adcc18f871814d1929e35041 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_on.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_ON_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_ON_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +ani_int AniOn(ani_env *env, ani_string type, ani_fn_object fn, ani_object checkRequestObj); +ani_int AniOff(ani_env *env, ani_string type, ani_fn_object fn); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif + diff --git a/frameworks/ets/ani/include/manager/ani_open_settings.h b/frameworks/ets/ani/include/manager/ani_open_settings.h new file mode 100644 index 0000000000000000000000000000000000000000..1617ec391c70a5acd47828ecc4e62b7b3e9c2041 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_open_settings.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_OPEN_SETTINGS_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_OPEN_SETTINGS_H + +#include "ani.h" +#include "ani_base_context.h" +#include "ans_dialog_host_client.h" +#include "ability.h" +#include "ability_context.h" +#include "ui_content.h" + +namespace OHOS { +namespace NotificationManagerSts { +class SettingsModalExtensionCallback; +struct OpenSettingsInfo { + int32_t errorCode = ANI_OK; + std::shared_ptr context = nullptr; + ani_resolver resolver {}; +}; + +ani_object AniOpenNotificationSettings(ani_env *env, ani_object content); +bool GetOpenSettingsInfo(ani_env *env, ani_object content, std::shared_ptr &info); +bool CreateSettingsUIExtension(std::shared_ptr context, std::string &bundleName, + ani_env *env, std::shared_ptr &info); +void StsAsyncCompleteCallbackOpenSettings(ani_env *env, std::shared_ptr info); + +using StsSettingsModalExtensionCallbackComplete = void(ani_env *env, std::shared_ptr info); +void ProcessStatusChanged(int32_t code); +bool CreateUiExtCallback(ani_env *env, std::shared_ptr& uiExtCallback, + Ace::ModalUIExtensionCallbacks& uiExtensionCallbacks, std::shared_ptr &info, + std::shared_ptr& abilityContext, std::string &bundleName); +class SettingsModalExtensionCallback { +public: + SettingsModalExtensionCallback(); + ~SettingsModalExtensionCallback(); + void OnRelease(int32_t releaseCode); + void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result); + void OnReceive(const OHOS::AAFwk::WantParams& request); + void OnError(int32_t code, const std::string& name, const std::string &message); + void OnRemoteReady(const std::shared_ptr &uiProxy); + void OnDestroy(); + void SetSessionId(int32_t sessionId); + void SetBundleName(std::string bundleName); + void SetAbilityContext(std::shared_ptr abilityContext); + void ReleaseOrErrorHandle(int32_t code); + bool Init(ani_env *env, std::shared_ptr info, + StsSettingsModalExtensionCallbackComplete *complete); + void ProcessStatusChanged(int32_t code, bool isAsync); +private: + int32_t sessionId_ = 0; + std::string bundleName_; + std::shared_ptr abilityContext_; + ani_vm *vm_ = nullptr; + std::shared_ptr info_ = nullptr; + StsSettingsModalExtensionCallbackComplete *complete_ = nullptr; +}; +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_publish.h b/frameworks/ets/ani/include/manager/ani_publish.h index 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_push_callback.h b/frameworks/ets/ani/include/manager/ani_push_callback.h new file mode 100755 index 0000000000000000000000000000000000000000..fcaf53782ec62ab0afa68cd848be72d9d31d95a2 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_push_callback.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_PUSH_CALLBACK_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_PUSH_CALLBACK_H +#include +#include +#include "ani.h" +#include "push_callback_stub.h" +#include "notification_constant.h" + +namespace OHOS { +namespace NotificationManagerSts { +using namespace OHOS::Notification; +class StsPushCallBack : public PushCallBackStub { +public: + struct ResultParam { + int32_t code = -1; + std::string msg = ""; + }; + + StsPushCallBack(ani_env *env); + virtual ~StsPushCallBack(); + int32_t OnCheckNotification( + const std::string ¬ificationData, const std::shared_ptr &pushCallBackParam) override; + void SetJsPushCallBackObject(ani_env *env, NotificationConstant::SlotType slotType, ani_ref pushCallBackObject); + void HandleCheckCallback( + ani_env *env, ani_fn_object fn, ani_object value, const std::shared_ptr &pushCallBackParam); + +private: + int32_t CheckNotification( + ani_env *env, + const std::string ¬ificationData, + const std::shared_ptr &pushCallBackParam); + static bool WarpFunctionResult(ani_env *env, ani_object funcResult, ResultParam &result); + ani_vm *vm_ = nullptr; + std::map pushCallBackObjects_; + std::mutex mutexlock; +}; + +} // namespace NotificationManagerSts +} // namespace OHOS +#endif + diff --git a/frameworks/ets/ani/include/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_slot.h b/frameworks/ets/ani/include/manager/ani_slot.h index 044d5a877020672a7c216bd0f332379010bc95c3..eecf03272219636acbc2e1099e75a32c8ca50c57 100644 --- a/frameworks/ets/ani/include/manager/ani_slot.h +++ b/frameworks/ets/ani/include/manager/ani_slot.h @@ -27,6 +27,15 @@ ani_boolean AniIsNotificationSlotEnabled(ani_env *env, ani_object bundleOption, void AniSetNotificationEnableSlot(ani_env *env, ani_object bundleOption, ani_enum_item type, ani_boolean enable); void AniSetNotificationEnableSlotWithForce(ani_env *env, ani_object bundleOption, ani_enum_item type, ani_boolean enable, ani_boolean isForceControl); +void AniAddSlotByNotificationSlot(ani_env *env, ani_object notificationSlotObj); +void AniAddSlotBySlotType(ani_env *env, ani_enum_item enumObj); +void AniAddSlots(ani_env *env, ani_object notificationSlotArrayObj); +ani_object AniGetSlot(ani_env *env, ani_enum_item enumObj); +ani_object AniGetSlots(ani_env *env); +void AniRemoveSlot(ani_env *env, ani_enum_item enumObj); +void AniRemoveAllSlots(ani_env *env); +void AniSetSlotByBundle(ani_env *env, ani_object bundleOptionObj, ani_object slotObj); +ani_double AniGetSlotNumByBundle(ani_env *env, ani_object bundleOption); } // namespace NotificationManagerSts } // namespace OHOS #endif diff --git a/frameworks/ets/ani/include/manager/ani_support_template.h b/frameworks/ets/ani/include/manager/ani_support_template.h new file mode 100755 index 0000000000000000000000000000000000000000..5be565d995c1793687386b5ce4ef383727abae38 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_support_template.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SUPPORT_TEMPLATE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SUPPORT_TEMPLATE_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +ani_boolean AniIsSupportTemplate(ani_env* env, ani_string templateName); +ani_object AniGetDeviceRemindType(ani_env *env); + +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/manager/ani_sync_config.h b/frameworks/ets/ani/include/manager/ani_sync_config.h new file mode 100644 index 0000000000000000000000000000000000000000..a337aed87ef81cedbccd6be725c5f3eeae8991b4 --- /dev/null +++ b/frameworks/ets/ani/include/manager/ani_sync_config.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SYNC_CONFIG_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ETS_ANI_INCLUDE_ANI_SYNC_CONFIG_H +#include "ani.h" + +namespace OHOS { +namespace NotificationManagerSts { +ani_double AniSetAdditionalConfig(ani_env *env, ani_string key, ani_string value); +} // namespace NotificationManagerSts +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/sts_bundle_option.h b/frameworks/ets/ani/include/sts_bundle_option.h index a1bc560614f52b47a3bd2f6464ceb0834b9c16eb..5bda338dd90f47bcb45d2a2706874f5f4d980bbf 100644 --- a/frameworks/ets/ani/include/sts_bundle_option.h +++ b/frameworks/ets/ani/include/sts_bundle_option.h @@ -26,6 +26,7 @@ bool WrapBundleOption(ani_env* env, const std::shared_ptr &bundleOption, ani_object &bundleObject); bool UnwrapArrayBundleOption(ani_env *env, ani_ref arrayObj, std::vector& options); +ani_object GetAniArrayBundleOption(ani_env* env, const std::vector &bundleOptions); } } diff --git a/frameworks/ets/ani/include/sts_common.h b/frameworks/ets/ani/include/sts_common.h index 10a56d84a53dded1bd208b31684fd801e5a3368a..35f9d908fda7a293c91956d901a128f6e1d35e69 100644 --- a/frameworks/ets/ani/include/sts_common.h +++ b/frameworks/ets/ani/include/sts_common.h @@ -24,6 +24,12 @@ namespace OHOS { namespace NotificationSts { +constexpr int32_t STR_MAX_SIZE = 204; +constexpr int32_t LONG_STR_MAX_SIZE = 1028; +constexpr int32_t COMMON_TEXT_SIZE = 3074; +constexpr int32_t SHORT_TEXT_SIZE = 1026; +std::string GetResizeStr(std::string instr, int32_t length); + bool IsUndefine(ani_env *env, const ani_object &obj); ani_object CreateBoolean(ani_env *env, bool value); ani_object CreateDouble(ani_env *env, ani_double value); @@ -47,6 +53,8 @@ ani_status GetPropertyRef(ani_env *env, ani_object obj, const char *name, ani_boolean &isUndefined, ani_ref &outRef); ani_status GetPropertyStringArray(ani_env *env, ani_object param, const char *name, ani_boolean &isUndefined, std::vector &res); +ani_status GetPropertyNumberArray(ani_env *env, ani_object param, const char *name, + ani_boolean &isUndefined, std::vector &res); bool SetFieldString(ani_env *env, ani_class cls, ani_object &object, const std::string fieldName, const std::string value); diff --git a/frameworks/ets/ani/include/sts_disturb_mode.h b/frameworks/ets/ani/include/sts_disturb_mode.h index eb208a289c002213ba9a23d28c7da886c2767efb..491450d9fcebf2771a166c2c3b53b103d2ec7615 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 8c9a089fbe2c90916a1f9448c00526b2fa316ead..f2d72b257cf02e81b5dfa3b12ab0833c9518ca00 100644 --- a/frameworks/ets/ani/include/sts_notification_manager.h +++ b/frameworks/ets/ani/include/sts_notification_manager.h @@ -18,10 +18,12 @@ #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" #include "sts_runtime.h" +#include "notification_check_info.h" namespace OHOS { namespace NotificationSts { @@ -31,6 +33,16 @@ using SlotLevel = OHOS::Notification::NotificationSlot::NotificationLevel; using ContentType = OHOS::Notification::NotificationContent::Type; using ButtonOption = OHOS::Notification::NotificationButtonOption; using NotificationDoNotDisturbDate = OHOS::Notification::NotificationDoNotDisturbDate; +using RemindType = OHOS::Notification::NotificationConstant::RemindType; +using NotificationConstant = OHOS::Notification::NotificationConstant; + +enum STSDoNotDisturbType { + TYPE_NONE = 0, + TYPE_ONCE = 1, + TYPE_DAILY = 2, + TYPE_CLEARLY = 3, +}; + enum STSSlotType { UNKNOWN_TYPE = 0, SOCIAL_COMMUNICATION = 1, @@ -60,6 +72,19 @@ enum STSContentType { NOTIFICATION_CONTENT_LIVE_VIEW, }; +enum class STSRemindType { + IDLE_DONOT_REMIND, + IDLE_REMIND, + ACTIVE_DONOT_REMIND, + ACTIVE_REMIND +}; + +class StsDoNotDisturbTypeUtils { +public: +static bool StsToC(const STSDoNotDisturbType inType, + OHOS::Notification::NotificationConstant::DoNotDisturbType &outType); +}; + class StsSlotTypeUtils { public: static bool StsToC(const STSSlotType inType, SlotType &outType); @@ -78,6 +103,12 @@ static bool StsToC(const STSContentType inType, ContentType &outType); static bool CToSts(const ContentType inType, STSContentType &outType); }; +class StsRemindTypeUtils { +public: +static bool StsToC(const STSRemindType inType, RemindType &outType); +static bool CToSts(const RemindType inType, STSRemindType &outType); +}; + class StsNotificationLocalLiveViewSubscriber : public NotificationLocalLiveViewSubscriber { public: StsNotificationLocalLiveViewSubscriber(); @@ -132,12 +163,20 @@ bool SlotLevelCToEts(ani_env *env, SlotLevel slotLevel, ani_enum_item &enumItem) bool ContentTypeEtsToC(ani_env *env, ani_enum_item enumItem, ContentType &contentType); bool ContentTypeCToEts(ani_env *env, ContentType contentType, ani_enum_item &enumItem); +bool DeviceRemindTypeCToEts(ani_env *env, RemindType remindType, ani_enum_item &enumItem); +bool DeviceRemindTypeEtsToC(ani_env *env, ani_enum_item enumItem, RemindType &remindType); ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonOptionObj, ButtonOption &buttonOption); ani_object WarpNotificationButtonOption(ani_env *env, sptr buttonOption); + +bool UnWarpNotificationDoNotDisturbDate(ani_env* env, const ani_object doNotDisturbDateObj, + NotificationDoNotDisturbDate& doNotDisturbDate); bool WarpNotificationDoNotDisturbDate( ani_env *env, const std::shared_ptr &date, ani_object &outObj); + +bool WarpNotificationCheckInfo( + ani_env *env, const std::shared_ptr &data, ani_object &outObj); } // namespace NotificationSts } // OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/sts_request.h b/frameworks/ets/ani/include/sts_request.h index 893d6ce463e01424c842ffe8f46bf1c2b1bed263..c35fee773d5eed331e3e3d0efdf19ade94d5345e 100644 --- a/frameworks/ets/ani/include/sts_request.h +++ b/frameworks/ets/ani/include/sts_request.h @@ -41,6 +41,9 @@ bool WarpNotificationRequest( ani_env *env, const NotificationRequest *notificationRequest, ani_class &cls, ani_object &outAniObj); ani_object GetAniNotificationRequestArray(ani_env *env, std::vector> requests); ani_object GetAniNotificationRequestArrayByNotifocations(ani_env *env, std::vector> requests); + +bool UnWarpNotificationCheckRequest(ani_env *env, ani_object obj, sptr &checkRequest); +bool UnWarpNotificationFilter(ani_env *env, ani_object obj, LiveViewFilter& filter); } // namespace NotificationSts } // OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/sts_slot.h b/frameworks/ets/ani/include/sts_slot.h index f9d311058a7829a0575d7f22b3bb515238beb825..2c4da3de6ef8f6a2398637633471154a34ceb0b2 100644 --- a/frameworks/ets/ani/include/sts_slot.h +++ b/frameworks/ets/ani/include/sts_slot.h @@ -33,6 +33,11 @@ bool SetOptionalFieldSlotLevel(ani_env *env, const ani_class cls, ani_object &ob bool WrapNotificationSlot(ani_env *env, sptr slot, ani_object &outAniObj); bool WrapNotificationSlotArray(ani_env *env, const std::vector>& slots, ani_object &outAniObj); +bool ParseNotificationSlotByBasicType(ani_env *env, ani_object notificationSlotObj, + NotificationSlot &slot); +bool UnwrapNotificationSlot(ani_env *env, ani_object notificationSlotObj, NotificationSlot &slot); +bool UnwrapNotificationSlotArrayByAniObj(ani_env *env, ani_object notificationSlotArrayObj, + std::vector &slots); } // namespace NotificationSts } // OHOS #endif \ No newline at end of file diff --git a/frameworks/ets/ani/include/sts_subscribe.h b/frameworks/ets/ani/include/sts_subscribe.h index 9f948df7ee4adf9f9929beaae1ff62e58e3e3859..bfa5abf0745482bc9385e45de8cca119aeb04d91 100644 --- a/frameworks/ets/ani/include/sts_subscribe.h +++ b/frameworks/ets/ani/include/sts_subscribe.h @@ -112,6 +112,7 @@ public: void DelDeletingSubscriber(std::shared_ptr subscriber); bool Subscribe(ani_env *env, ani_object subscriber, ani_object info); + bool SubscribeSelf(ani_env *env, ani_object subscriber); bool UnSubscribe(ani_env *env, ani_object subscriber); private: SubscriberInstanceManager() {} diff --git a/frameworks/ets/ani/include/sts_throw_erro.h b/frameworks/ets/ani/include/sts_throw_erro.h index 6bd3d6d5ae07398bea4cb79adfccdddbaf703de3..b24125a28294e00883fd0fb6db8f0c2be5acb82b 100644 --- a/frameworks/ets/ani/include/sts_throw_erro.h +++ b/frameworks/ets/ani/include/sts_throw_erro.h @@ -56,11 +56,66 @@ static const std::unordered_map ERROR_CODE_TO_MESSAGE { {ERROR_DISTRIBUTED_OPERATION_TIMEOUT, "Distributed operation timeout"}, }; +static const std::vector> ERRORS_CONVERT = { + {ERR_ANS_PERMISSION_DENIED, ERROR_PERMISSION_DENIED}, + {ERR_ANS_NON_SYSTEM_APP, ERROR_NOT_SYSTEM_APP}, + {ERR_ANS_NOT_SYSTEM_SERVICE, ERROR_NOT_SYSTEM_APP}, + {ERR_ANS_INVALID_PARAM, ERROR_PARAM_INVALID}, + {ERR_ANS_INVALID_UID, ERROR_PARAM_INVALID}, + {ERR_ANS_ICON_OVER_SIZE, ERROR_PARAM_INVALID}, + {ERR_ANS_PICTURE_OVER_SIZE, ERROR_PARAM_INVALID}, + {ERR_ANS_PUSH_CHECK_EXTRAINFO_INVALID, ERROR_PARAM_INVALID}, + {ERR_ANS_NO_MEMORY, ERROR_NO_MEMORY}, + {ERR_ANS_TASK_ERR, ERROR_INTERNAL_ERROR}, + {ERR_ANS_PARCELABLE_FAILED, ERROR_IPC_ERROR}, + {ERR_ANS_TRANSACT_FAILED, ERROR_IPC_ERROR}, + {ERR_ANS_REMOTE_DEAD, ERROR_IPC_ERROR}, + {ERR_ANS_SERVICE_NOT_READY, ERROR_SERVICE_CONNECT_ERROR}, + {ERR_ANS_SERVICE_NOT_CONNECTED, ERROR_SERVICE_CONNECT_ERROR}, + {ERR_ANS_NOT_ALLOWED, ERROR_NOTIFICATION_CLOSED}, + {ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, ERROR_SLOT_CLOSED}, + {ERR_ANS_NOTIFICATION_IS_UNREMOVABLE, ERROR_NOTIFICATION_UNREMOVABLE}, + {ERR_ANS_NOTIFICATION_NOT_EXISTS, ERROR_NOTIFICATION_NOT_EXIST}, + {ERR_ANS_GET_ACTIVE_USER_FAILED, ERROR_USER_NOT_EXIST}, + {ERR_ANS_INVALID_PID, ERROR_BUNDLE_NOT_FOUND}, + {ERR_ANS_INVALID_BUNDLE, ERROR_BUNDLE_NOT_FOUND}, + {ERR_ANS_OVER_MAX_ACTIVE_PERSECOND, ERROR_OVER_MAX_NUM_PER_SECOND}, + {ERR_ANS_OVER_MAX_UPDATE_PERSECOND, ERROR_OVER_MAX_NUM_PER_SECOND}, + {ERR_ANS_DISTRIBUTED_OPERATION_FAILED, ERROR_DISTRIBUTED_OPERATION_FAILED}, + {ERR_ANS_DISTRIBUTED_GET_INFO_FAILED, ERROR_DISTRIBUTED_OPERATION_FAILED}, + {ERR_ANS_PREFERENCES_NOTIFICATION_READ_TEMPLATE_CONFIG_FAILED, ERROR_READ_TEMPLATE_CONFIG_FAILED}, + {ERR_ANS_REPEAT_CREATE, ERROR_REPEAT_SET}, + {ERR_ANS_END_NOTIFICATION, ERROR_REPEAT_SET}, + {ERR_ANS_EXPIRED_NOTIFICATION, ERROR_EXPIRED_NOTIFICATION}, + {ERR_ANS_PUSH_CHECK_FAILED, ERROR_NO_RIGHT}, + {ERR_ANS_PUSH_CHECK_UNREGISTERED, ERROR_NO_RIGHT}, + {ERR_ANS_PUSH_CHECK_NETWORK_UNREACHABLE, ERROR_NETWORK_UNREACHABLE}, + {ERR_ANS_NO_AGENT_SETTING, ERROR_NO_AGENT_SETTING}, + {ERR_ANS_DIALOG_IS_POPPING, ERROR_DIALOG_IS_POPPING}, + {ERR_ANS_NO_PROFILE_TEMPLATE, ERROR_NO_PROFILE_TEMPLATE}, + {ERR_ANS_REJECTED_WITH_DISABLE_NOTIFICATION, ERROR_REJECTED_WITH_DISABLE_NOTIFICATION}, + {ERR_ANS_OPERATION_TIMEOUT, ERROR_DISTRIBUTED_OPERATION_TIMEOUT}, +}; + + +inline int32_t GetExternalCode(uint32_t errCode) +{ + int32_t ExternalCode = ERROR_INTERNAL_ERROR; + for (const auto &errorConvert : ERRORS_CONVERT) { + if (errCode == errorConvert.first) { + ExternalCode = errorConvert.second; + break; + } + } + ANS_LOGI("internal errorCode[%{public}u] to external errorCode[%{public}d]", errCode, ExternalCode); + return ExternalCode; +}; + inline std::string FindAnsErrMsg(const int32_t errCode) { auto findMsg = ERROR_CODE_TO_MESSAGE.find(errCode); if (findMsg == ERROR_CODE_TO_MESSAGE.end()) { - ANSR_LOGE("FindAnsErrMsg Inner error."); + ANS_LOGE("FindAnsErrMsg Inner error."); return "Inner error."; } return findMsg->second; @@ -68,9 +123,22 @@ inline std::string FindAnsErrMsg(const int32_t errCode) inline void ThrowStsErroWithMsg(ani_env *env, std::string logMsg) { + ANS_LOGE("%{public}s", logMsg.c_str()); OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); } + +inline void ThrowStsErrorWithCode(ani_env *env, const int32_t errCode, std::string msg = "") +{ + if (env == nullptr) return; + OHOS::AbilityRuntime::ThrowStsError(env, errCode, msg.empty() ? FindAnsErrMsg(errCode) : msg); +} + +inline void ThrowStsErrorWithInvalidParam(ani_env *env) +{ + ThrowStsErrorWithCode(env, ERROR_PARAM_INVALID); +} + } // namespace NotificationSts } // OHOS #endif diff --git a/frameworks/ets/ani/include/subscribe/ani_remove.h b/frameworks/ets/ani/include/subscribe/ani_remove.h index a60aa5ab895341aa33e0008a048746903b51c7c0..5b7680a876645227d41956ac49e73a84c5619682 100644 --- a/frameworks/ets/ani/include/subscribe/ani_remove.h +++ b/frameworks/ets/ani/include/subscribe/ani_remove.h @@ -22,6 +22,9 @@ 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); +void AniRemoveAll(ani_env *env); } } #endif \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_ans_dialog_callback.cpp b/frameworks/ets/ani/src/manager/ani_ans_dialog_callback.cpp index b288966f2b1e6d246b08f8f58f9fd5cecf87accf..88ce9d3bd290d46421190db29cb8acd9b7748efe 100755 --- a/frameworks/ets/ani/src/manager/ani_ans_dialog_callback.cpp +++ b/frameworks/ets/ani/src/manager/ani_ans_dialog_callback.cpp @@ -14,6 +14,7 @@ */ #include "ani_ans_dialog_callback.h" + #include "ans_log_wrapper.h" #include "inner_errors.h" #include "notification_helper.h" diff --git a/frameworks/ets/ani/src/manager/ani_cance.cpp b/frameworks/ets/ani/src/manager/ani_cance.cpp index 180bedaac1e604c1f00d66df5984e4cf0889b063..bc48b59e9000bc86eec919e5be469496df8fa25a 100644 --- a/frameworks/ets/ani/src/manager/ani_cance.cpp +++ b/frameworks/ets/ani/src/manager/ani_cance.cpp @@ -14,7 +14,6 @@ */ #include "ani_cance.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -27,8 +26,8 @@ void AniCancelAll(ani_env* env) { ANS_LOGD("AniCancelAll notifications call"); int returncode = Notification::NotificationHelper::CancelAllNotifications(); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniCancelAll -> error, errorCode: %{public}d", externalCode); } @@ -39,8 +38,8 @@ void AniCancelWithId(ani_env* env, ani_double id) { ANS_LOGD("AniCancelWithId call,id : %{public}lf", id); int returncode = Notification::NotificationHelper::CancelNotification(static_cast(id)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniCancelWithId -> error, errorCode: %{public}d", externalCode); } @@ -50,16 +49,16 @@ void AniCancelWithId(ani_env* env, ani_double id) void AniCancelWithIdLabel(ani_env* env, ani_double id, ani_string label) { ANS_LOGD("AniCancelWithIdLabel call"); - std::string labelStr; - if (ANI_OK != NotificationSts::GetStringByAniString(env, label, labelStr)) { + std::string tempStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, label, tempStr)) { NotificationSts::ThrowStsErroWithMsg(env, "Label parse failed!"); return; } - + std::string labelStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); ANS_LOGD("Cancel by label id:%{public}lf label:%{public}s", id, labelStr.c_str()); int returncode = Notification::NotificationHelper::CancelNotification(labelStr, static_cast(id)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniCancelWithIdLabel -> error, errorCode: %{public}d", externalCode); } @@ -78,8 +77,8 @@ void AniCancelWithBundle(ani_env* env, ani_object bundleObj, ani_double id) ANS_LOGD("Cancel by bundle:%{public}s id:%{public}lf", option.GetBundleName().c_str(), id); int returncode = Notification::NotificationHelper::CancelAsBundle(option, static_cast(id)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniCancelWithBundle -> error, errorCode: %{public}d", externalCode); } @@ -96,17 +95,18 @@ void AniCancelWithIdOptinalLabel(ani_env* env, ani_double id, ani_string label) ANS_LOGE("sts AniCancelWithIdOptinalLabel the label is undefined"); ret = Notification::NotificationHelper::CancelNotification(static_cast(id)); } else { - std::string labelStr; - if (ANI_OK != NotificationSts::GetStringByAniString(env, label, labelStr)) { + std::string tempStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, label, tempStr)) { OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); ANS_LOGE("sts AniCancelWithIdOptinalLabel ERROR_INTERNAL_ERROR"); return; } + std::string labelStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); ANS_LOGD("sts AniCancelWithIdOptinalLabel id:%{public}lf label:%{public}s", id, labelStr.c_str()); ret = Notification::NotificationHelper::CancelNotification(labelStr, id); } - int externalCode = CJSystemapi::Notification::ErrorToExternal(ret); + int externalCode = NotificationSts::GetExternalCode(ret); if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("sts AniCancelWithIdOptinalLabel error, errorCode: %{public}d", externalCode); @@ -114,5 +114,77 @@ 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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 tempStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, groupName, tempStr)) { + NotificationSts::ThrowStsErroWithMsg(env, "AniCancelGroup: groupName parse failed!"); + return; + } + std::string groupNameStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); + ANS_LOGD("AniCancelGroup groupNameStr: %{public}s", groupNameStr.c_str()); + int returncode = Notification::NotificationHelper::CancelGroup(groupNameStr); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniCancelGroup: CancelAsBundle retern erro. returncode: %{public}d, externalCode: %{public}d", + returncode, externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniCancelGroup end"); +} } // namespace NotificationManagerSts } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_display_badge.cpp b/frameworks/ets/ani/src/manager/ani_display_badge.cpp index 7cba58762886d3307d263768c29931a6892f6f85..d1a4d6532467523afd025d0a781576b82d849bb0 100644 --- a/frameworks/ets/ani/src/manager/ani_display_badge.cpp +++ b/frameworks/ets/ani/src/manager/ani_display_badge.cpp @@ -19,7 +19,6 @@ #include "sts_throw_erro.h" #include "sts_error_utils.h" #include "sts_common.h" -#include "inner_errors.h" #include "notification_helper.h" #include "notification_bundle_option.h" @@ -40,8 +39,8 @@ void AniDisplayBadge(ani_env *env, ani_object obj, ani_boolean enable) ANS_LOGE("sts DisplayBadge ERROR_INTERNAL_ERROR"); return; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("sts DisplayBadge error, errorCode: %{public}d", externalCode); return; @@ -68,8 +67,8 @@ ani_boolean AniIsBadgeDisplayed(ani_env *env, ani_object obj) } } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("sts IsBadgeDisplayed error, errorCode: %{public}d", externalCode); return NotificationSts::BoolToAniBoolean(false); @@ -78,5 +77,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 = NotificationSts::GetExternalCode(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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("sts AniSetBadgeNumberByBundle error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniSetBadgeNumberByBundle end, ret: %{public}d", externalCode); +} } } \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4d8ce628ae7c2c87254ad44db1e9c0d566e4fb67 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_distributed_enable.cpp @@ -0,0 +1,291 @@ +/* + * 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 "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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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); +} + +void AniSetDistributedEnableByBundle(ani_env *env, ani_object obj, ani_boolean enable) +{ + ANS_LOGD("setDistributedEnableByBundle call"); + int returncode = ERR_OK; + Notification::NotificationBundleOption option; + bool bFlag = NotificationSts::UnwrapBundleOption(env, obj, option); + if (bFlag) { + returncode = Notification::NotificationHelper::EnableDistributedByBundle( + option, NotificationSts::AniBooleanToBool(enable)); + } else { + ANS_LOGE("sts setDistributedEnableByBundle ERROR_INTERNAL_ERROR"); + OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); + return; + } + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("sts setDistributedEnableByBundle error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("sts setDistributedEnableByBundle end, ret: %{public}d", externalCode); +} + +void AniSetDistributedEnableByBundleAndType(ani_env *env, + ani_object obj, ani_string deviceType, ani_boolean enable) +{ + ANS_LOGD("sts setDistributedEnabledByBundle call"); + std::string deviceTypeStr; + if (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + int returncode = ERR_OK; + Notification::NotificationBundleOption option; + bool bFlag = NotificationSts::UnwrapBundleOption(env, obj, option); + if (bFlag) { + returncode = Notification::NotificationHelper::SetDistributedEnabledByBundle(option, + deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); + } else { + ANS_LOGE("sts setDistributedEnabledByBundle ERROR_INTERNAL_ERROR"); + OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, + NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); + return; + } + int externalCode = NotificationSts::GetExternalCode(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 = NotificationSts::GetExternalCode(ret); + if (externalCode != ERR_OK) { + ANS_LOGE("sts setTargetDeviceStatus error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("sts setTargetDeviceStatus end, externalCode: %{public}d", externalCode); +} + +ani_boolean AniIsSmartReminderEnabled(ani_env *env, ani_string deviceType) +{ + ANS_LOGD("isSmartReminderEnabled call"); + bool allowed = false; + std::string deviceTypeStr; + if (env == nullptr || deviceType == nullptr) { + ANS_LOGE("Invalid env or deviceType is null"); + return ANI_FALSE; + } + if (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return ANI_FALSE; + } + int returncode = Notification::NotificationHelper::IsSmartReminderEnabled(deviceTypeStr, allowed); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("isSmartReminderEnabled -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("isSmartReminderEnabled end"); + return NotificationSts::BoolToAniBoolean(allowed); +} + + +void AniSetSmartReminderEnable(ani_env *env, ani_string deviceType, ani_boolean enable) +{ + ANS_LOGD("setSmartReminderEnabled call"); + std::string deviceTypeStr; + if (env == nullptr || deviceType == nullptr) { + ANS_LOGE("Invalid env or deviceType is null"); + return; + } + + if (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + int returncode = Notification::NotificationHelper::SetSmartReminderEnabled(deviceTypeStr, + NotificationSts::AniBooleanToBool(enable)); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("setSmartReminderEnabled -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("setSmartReminderEnabled end"); +} + +void AniSetDistributedEnableBySlot(ani_env *env, ani_enum_item slot, ani_string deviceType, ani_boolean enable) +{ + ANS_LOGD("setDistributedEnabledBySlot enter "); + std::string deviceTypeStr; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (!NotificationSts::SlotTypeEtsToC(env, slot, slotType)) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("SlotTypeEtsToC failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + if (env == nullptr || deviceType == nullptr) { + ANS_LOGE("Invalid env or deviceType is null"); + return; + } + if (NotificationSts::GetStringByAniString(env, deviceType, deviceTypeStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return; + } + int returncode = ERR_OK; + returncode = Notification::NotificationHelper::SetDistributedEnabledBySlot(slotType, + deviceTypeStr, NotificationSts::AniBooleanToBool(enable)); + + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("isDistributedEnabledBySlot -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + return isEnable ? ANI_TRUE : ANI_FALSE; +} +} +} \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_do_not_disturb_date.cpp b/frameworks/ets/ani/src/manager/ani_do_not_disturb_date.cpp new file mode 100644 index 0000000000000000000000000000000000000000..226e42790b886dfda5c50fef378e35337b258f57 --- /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 "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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("DoesSupportDoNotDisturbMode error. returncode: %{public}d, externalCode: %{public}d", + returncode, externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return ANI_FALSE; + } + ANS_LOGD("DoesSupportDoNotDisturbMode returncode: %{public}d", supportDoNotDisturbMode); + ANS_LOGD("AniIsSupportDoNotDisturbMode end"); + return NotificationSts::BoolToAniBoolean(supportDoNotDisturbMode); +} + +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp b/frameworks/ets/ani/src/manager/ani_do_not_disturb_profile.cpp index 0d7158d5f6d064520851b864d83e5fc771a20b27..6d32f3bf5cbf62360220549e2cc09bace059d6d0 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 @@ -14,12 +14,12 @@ */ #include "ani_do_not_disturb_profile.h" -#include "inner_errors.h" #include "notification_helper.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 { @@ -36,8 +36,8 @@ void AniAddDoNotDisturbProfile(ani_env *env, ani_object obj) ANS_LOGE("AniAddDoNotDisturbProfile failed : ERROR_INTERNAL_ERROR"); return; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniAddDoNotDisturbProfile error, errorCode: %{public}d", externalCode); } @@ -57,12 +57,46 @@ void AniRemoveDoNotDisturbProfile(ani_env *env, ani_object obj) ANS_LOGE("AniRemoveDoNotDisturbProfile failed : ERROR_INTERNAL_ERROR"); return; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniRemoveDoNotDisturbProfile error, errorCode: %{public}d", externalCode); } 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniSetDoNotDisturbDateWithId error, errorCode: %{public}d, returncode: %{public}d", + externalCode, returncode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + + 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..b22e684055e1c67ec738e9f3b934a84078fa123f 100644 --- a/frameworks/ets/ani/src/manager/ani_get_active.cpp +++ b/frameworks/ets/ani/src/manager/ani_get_active.cpp @@ -14,7 +14,6 @@ */ #include "ani_get_active.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -30,8 +29,8 @@ ani_double AniGetActiveNotificationCount(ani_env *env) int returncode = OHOS::Notification::NotificationHelper::GetActiveNotificationNums(num); ANS_LOGD("sts GetActiveNotificationCount end, num: %{public}llu", num); ani_double retNum = static_cast(num); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniSetNotificationEnableSlotSync error, errorCode: %{public}d", externalCode); return 0; @@ -44,8 +43,8 @@ ani_object AniGetAllActiveNotifications(ani_env *env) ANS_LOGD("sts AniGetAllActiveNotifications call"); std::vector> notifications; int returncode = OHOS::Notification::NotificationHelper::GetAllActiveNotifications(notifications); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniGetAllActiveNotifications error, errorCode: %{public}d", externalCode); return nullptr; @@ -70,8 +69,8 @@ ani_object AniGetActiveNotifications(ani_env *env) ANS_LOGD("sts AniGetActiveNotifications call"); std::vector> requests; int returncode = OHOS::Notification::NotificationHelper::GetActiveNotifications(requests); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniGetActiveNotifications error, errorCode: %{public}d", externalCode); return nullptr; @@ -90,5 +89,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 = NotificationSts::GetExternalCode(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_local_live_view.cpp b/frameworks/ets/ani/src/manager/ani_local_live_view.cpp index d2b76a4ed6f59b7f8fd6ea95e3ad18af0e98f9b4..5d7179c5f6a2fff432bd06ab72215bcc5ffd66d0 100644 --- a/frameworks/ets/ani/src/manager/ani_local_live_view.cpp +++ b/frameworks/ets/ani/src/manager/ani_local_live_view.cpp @@ -14,7 +14,6 @@ */ #include "ani_local_live_view.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -36,7 +35,7 @@ void AniTriggerSystemLiveView( return; } NotificationSts::ButtonOption buttonOption; - if (!NotificationSts::UnWarpNotificationButtonOption(env, buttonOptionsObj, buttonOption)) { + if (NotificationSts::UnWarpNotificationButtonOption(env, buttonOptionsObj, buttonOption) != ANI_OK) { OHOS::AbilityRuntime::ThrowStsError(env, OHOS::Notification::ERROR_INTERNAL_ERROR, NotificationSts::FindAnsErrMsg(OHOS::Notification::ERROR_INTERNAL_ERROR)); ANS_LOGE("AniTriggerSystemLiveView buttonOption ERROR_INTERNAL_ERROR"); @@ -44,8 +43,8 @@ void AniTriggerSystemLiveView( } int returncode = OHOS::Notification::NotificationHelper::TriggerLocalLiveView(bundleOption, static_cast(notificationId), buttonOption); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniTriggerSystemLiveView error, errorCode: %{public}d", externalCode); } @@ -60,8 +59,8 @@ void AniSubscribeSystemLiveView(ani_env *env, ani_object subscriberObj) localLiveViewSubscriber->SetStsNotificationLocalLiveViewSubscriber(env, subscriberObj); int returncode = OHOS::Notification::NotificationHelper::SubscribeLocalLiveViewNotification(*localLiveViewSubscriber, false); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniSubscribeSystemLiveView error, errorCode: %{public}d", externalCode); } diff --git a/frameworks/ets/ani/src/manager/ani_manager.cpp b/frameworks/ets/ani/src/manager/ani_manager.cpp index 4cc8d56c2e881480a0a0e1556cbe7b39905a3e5c..7cecd702155edb49de00b2480c098c4eb3328a38 100644 --- a/frameworks/ets/ani/src/manager/ani_manager.cpp +++ b/frameworks/ets/ani/src/manager/ani_manager.cpp @@ -19,11 +19,18 @@ #include "ani_slot.h" #include "ani_cance.h" #include "ani_notification_enable.h" +#include "ani_do_not_disturb_date.h" #include "ani_do_not_disturb_profile.h" #include "ani_get_active.h" #include "ani_publish.h" #include "ani_local_live_view.h" #include "ani_request_enable.h" +#include "ani_on.h" +#include "ani_support_template.h" +#include "ani_distributed_enable.h" +#include "ani_remove_group.h" +#include "ani_open_settings.h" +#include "ani_sync_config.h" namespace OHOS { namespace NotificationManagerSts { @@ -72,6 +79,92 @@ 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;" + "Lnotification/notificationRequest/NotificationCheckRequest;" + ":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, + reinterpret_cast(AniAddSlotBySlotType)}, + ani_native_function {"nativeAddSlots", nullptr, + reinterpret_cast(AniAddSlots)}, + ani_native_function {"nativeGetSlot", nullptr, + reinterpret_cast(AniGetSlot)}, + ani_native_function {"nativeGetSlots", nullptr, + reinterpret_cast(AniGetSlots)}, + ani_native_function {"nativeRemoveSlot", nullptr, + reinterpret_cast(AniRemoveSlot)}, + ani_native_function {"nativeRemoveAllSlots", nullptr, + reinterpret_cast(AniRemoveAllSlots)}, + ani_native_function {"nativeSetSlotByBundle", nullptr, + reinterpret_cast(AniSetSlotByBundle)}, + ani_native_function {"nativeGetSlotNumByBundle", nullptr, + reinterpret_cast(AniGetSlotNumByBundle)}, + ani_native_function {"nativeOpenNotificationSettings", + "Lapplication/UIAbilityContext/UIAbilityContext;:Lstd/core/Promise;", + reinterpret_cast(AniOpenNotificationSettings)}, + ani_native_function {"nativesetTargetDeviceStatus", nullptr, + reinterpret_cast(AniSetTargetDeviceStatus)}, + ani_native_function {"nativesetDistributedEnabledByBundle", nullptr, + reinterpret_cast(AniSetDistributedEnableByBundleAndType)}, + ani_native_function {"nativesetSmartReminderEnabled", nullptr, + reinterpret_cast(AniSetSmartReminderEnable)}, + ani_native_function {"nativeisSmartReminderEnabled", nullptr, + reinterpret_cast(AniIsSmartReminderEnabled)}, + ani_native_function {"nativesetDistributedEnabledBySlot", nullptr, + reinterpret_cast(AniSetDistributedEnableBySlot)}, + ani_native_function {"nativeisDistributedEnabledBySlot", nullptr, + reinterpret_cast(AniIsDistributedEnabledBySlot)}, + ani_native_function {"nativesetAdditionalConfig", nullptr, + reinterpret_cast(AniSetAdditionalConfig)}, + ani_native_function {"nativesetDistributedEnableByBundle", nullptr, + reinterpret_cast(AniSetDistributedEnableByBundle)}, + ani_native_function {"nativedisableNotificationFeature", nullptr, + reinterpret_cast(AniDisableNotificationFeature)}, + ani_native_function {"nativeIsSupportTemplate", nullptr, reinterpret_cast(AniIsSupportTemplate)}, + ani_native_function {"nativeSetDistributedEnable", nullptr, reinterpret_cast(AniSetDistributedEnable)}, + ani_native_function {"nativeIsDistributedEnabled", nullptr, reinterpret_cast(AniIsDistributedEnabled)}, + ani_native_function {"nativeIsDistributedEnabledByBundle", nullptr, + reinterpret_cast(AniIsDistributedEnabledByBundle)}, + ani_native_function {"nativeIsDistributedEnabledByBundleType", nullptr, + reinterpret_cast(AniIsDistributedEnabledByBundleType)}, + ani_native_function {"nativeGetDeviceRemindType", nullptr, reinterpret_cast(AniGetDeviceRemindType)}, + ani_native_function {"nativeGetSyncNotificationEnabledWithoutApp", nullptr, + reinterpret_cast(AniGetSyncNotificationEnabledWithoutApp)}, + ani_native_function {"nativeSetSyncNotificationEnabledWithoutApp", nullptr, + reinterpret_cast(AniSetSyncNotificationEnabledWithoutApp)}, }; void AniNotificationManagerRegistryInit(ani_env *env) diff --git a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp index 9c987eedcbca2af5079f22b884be541b1a4f5cd8..aae5494da4fd58939bba0fade5bee772e6e0322d 100644 --- a/frameworks/ets/ani/src/manager/ani_notification_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_notification_enable.cpp @@ -14,7 +14,6 @@ */ #include "ani_notification_enable.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -27,9 +26,9 @@ ani_boolean AniIsNotificationEnabled(ani_env *env) { ANS_LOGD("AniIsNotificationEnabled call"); bool allowed = false; - int returncode = Notification::NotificationHelper::IsAllowedNotify(allowed); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int returncode = Notification::NotificationHelper::IsAllowedNotifySelf(allowed); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsNotificationEnabled -> error, errorCode: %{public}d", externalCode); } @@ -42,8 +41,8 @@ ani_boolean AniIsNotificationEnabledWithId(ani_env *env, ani_double userId) ANS_LOGD("AniIsNotificationEnabledWithId call"); bool allowed = false; int returncode = Notification::NotificationHelper::IsAllowedNotify(userId, allowed); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsNotificationEnabledWithId -> error, errorCode: %{public}d", externalCode); } @@ -54,7 +53,7 @@ ani_boolean AniIsNotificationEnabledWithId(ani_env *env, ani_double userId) ani_boolean AniIsNotificationEnabledWithBundleOption(ani_env *env, ani_object bundleOption) { ANS_LOGD("AniIsNotificationEnabledWithBundleOption call"); - int returncode = 0; + int returncode = ERR_OK; bool allowed = false; BundleOption option; if (NotificationSts::UnwrapBundleOption(env, bundleOption, option)) { @@ -64,8 +63,8 @@ ani_boolean AniIsNotificationEnabledWithBundleOption(ani_env *env, ani_object bu return ANI_FALSE; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniIsNotificationEnabledWithBundleOption -> error, errorCode: %{public}d", externalCode); return ANI_FALSE; @@ -85,12 +84,99 @@ void AniSetNotificationEnable(ani_env *env, ani_object bundleOption, ani_boolean std::string deviceId {""}; int returncode = Notification::NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(option, deviceId, NotificationSts::AniBooleanToBool(enable)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); ANS_LOGE("AniSetNotificationEnable -> error, errorCode: %{public}d", externalCode); } ANS_LOGD("AniSetNotificationEnable end"); } + +ani_object AniGetAllNotificationEnabledBundles(ani_env *env) +{ + ANS_LOGD("AniGetAllNotificationEnabledBundles call"); + std::vector bundleOptions = {}; + int returncode = Notification::NotificationHelper::GetAllNotificationEnabledBundles(bundleOptions); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniGetAllNotificationEnabledBundles -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return nullptr; + } + ani_object arrayBundles = NotificationSts::GetAniArrayBundleOption(env, bundleOptions); + if (arrayBundles == nullptr) { + ANS_LOGE("GetAniArrayBundleOption filed,arrayBundles is nullptr"); + NotificationSts::ThrowStsErroWithMsg(env, "GetAniArrayBundleOption ERROR_INTERNAL_ERROR"); + return nullptr; + } + return arrayBundles; +} + +ani_boolean AniIsNotificationEnabledSync(ani_env *env) +{ + ANS_LOGD("AniIsNotificationEnabledSync call"); + bool allowed = false; + int returncode = Notification::NotificationHelper::IsAllowedNotifySelf(allowed); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniIsNotificationEnabledSync -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return NotificationSts::BoolToAniBoolean(false); + } + return NotificationSts::BoolToAniBoolean(allowed); +} + +ani_boolean AniGetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId) +{ + ANS_LOGD("AniGetSyncNotificationEnabledWithoutApp call"); + bool enabled = false; + int returncode = Notification::NotificationHelper::GetSyncNotificationEnabledWithoutApp( + static_cast(userId), enabled); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniGetSyncNotificationEnabledWithoutApp -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return NotificationSts::BoolToAniBoolean(false); + } + ANS_LOGD("End success, enabled: %{public}d, returncode: %{public}d", enabled, externalCode); + return NotificationSts::BoolToAniBoolean(enabled); +} + +void AniSetSyncNotificationEnabledWithoutApp(ani_env* env, ani_double userId, ani_boolean enabled) +{ + ANS_LOGD("AniSetSyncNotificationEnabledWithoutApp call,enable : %{public}d", enabled); + int returncode = Notification::NotificationHelper::SetSyncNotificationEnabledWithoutApp( + static_cast(userId), NotificationSts::AniBooleanToBool(enabled)); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniSetSyncNotificationEnabledWithoutApp -> error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniSetSyncNotificationEnabledWithoutApp end"); +} + +void AniDisableNotificationFeature(ani_env *env, ani_boolean disabled, ani_object bundleList) +{ + ANS_LOGD("AniDisableNotificationFeature enter"); + std::vector bundleListStd; + if (!NotificationSts::GetStringArrayByAniObj(env, bundleList, bundleListStd)) { + 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 = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniDisableNotificationFeature error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } +} } // namespace NotificationManagerSts } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_on.cpp b/frameworks/ets/ani/src/manager/ani_on.cpp new file mode 100755 index 0000000000000000000000000000000000000000..8bbab66b12e4e456c406441a4b04149e8c10aa92 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_on.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_on.h" +#include "ans_log_wrapper.h" +#include "sts_common.h" +#include "sts_throw_erro.h" +#include "sts_request.h" +#include "ani_push_callback.h" +#include "ipc_skeleton.h" +#include "tokenid_kit.h" +#include "notification_helper.h" + +constexpr const char* TYPE_STRING = "checkNotification"; +namespace OHOS { +namespace NotificationManagerSts { +using namespace OHOS::Notification; + +bool CheckCallerIsSystemApp() +{ + auto selfToken = IPCSkeleton::GetSelfTokenID(); + if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) { + ANS_LOGE("current app is not system app, not allow."); + return false; + } + return true; +} + +ani_int AniOn(ani_env *env, ani_string type, ani_fn_object fn, ani_object checkRequestObj) +{ + ANS_LOGD("enter"); +#ifdef ANS_FEATURE_LIVEVIEW_LOCAL_LIVEVIEW + std::string typeStr = ""; + ani_status status = OHOS::NotificationSts::GetStringByAniString(env, type, typeStr); + if (status != ANI_OK || typeStr.compare(TYPE_STRING)) { + ANS_LOGE("InvalidParam 'type'"); + int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; + OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + return errCode; + } + if (OHOS::NotificationSts::IsUndefine(env, checkRequestObj)) { + ANS_LOGI("Old function param, don't need register."); + return ERR_OK; + } + sptr checkRequest = new NotificationCheckRequest(); + if (!OHOS::NotificationSts::UnWarpNotificationCheckRequest(env, checkRequestObj, checkRequest)) { + ANS_LOGE("InvalidParam 'checkRequest'"); + int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; + OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + return errCode; + } + if (!CheckCallerIsSystemApp()) { + OHOS::NotificationSts::ThrowStsErrorWithCode(env, ERROR_NOT_SYSTEM_APP); + return ERROR_NOT_SYSTEM_APP; + } + + sptr stsPushCallBack_ = new (std::nothrow) StsPushCallBack(env); + if (stsPushCallBack_ == nullptr) { + ANS_LOGE("new stsPushCallBack_ failed"); + OHOS::NotificationSts::ThrowStsErrorWithCode(env, ERROR_INTERNAL_ERROR); + return ERROR_INTERNAL_ERROR; + } + NotificationConstant::SlotType outSlotType = checkRequest->GetSlotType(); + stsPushCallBack_->SetJsPushCallBackObject(env, outSlotType, fn); + auto result = NotificationHelper::RegisterPushCallback(stsPushCallBack_->AsObject(), checkRequest); + if (result != ERR_OK) { + int32_t externalCode = ERR_OK ? ERR_OK : NotificationSts::GetExternalCode(result); + ANS_LOGE("Register failed, result is %{public}d", externalCode); + OHOS::NotificationSts::ThrowStsErrorWithCode(env, externalCode); + return externalCode; + } + ANS_LOGD("done"); + return result; +#else + int32_t errCode = OHOS::Notification::ERROR_SYSTEM_CAP_ERROR; + OHOS::NotificationSts::ThrowStsErrorWithCode(env, errCode); + return errCode; +#endif +} + +ani_int AniOff(ani_env *env, ani_string type, ani_fn_object fn) +{ + ANS_LOGD("enter"); +#ifdef ANS_FEATURE_LIVEVIEW_LOCAL_LIVEVIEW + std::string typeStr = ""; + ani_status status = OHOS::NotificationSts::GetStringByAniString(env, type, typeStr); + if (status != ANI_OK || typeStr.compare(TYPE_STRING)) { + ANS_LOGE("InvalidParam 'type'"); + int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; + OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + return errCode; + } + if (!CheckCallerIsSystemApp()) { + OHOS::NotificationSts::ThrowStsErrorWithCode(env, ERROR_NOT_SYSTEM_APP); + return ERROR_NOT_SYSTEM_APP; + } + if (!OHOS::NotificationSts::IsUndefine(env, fn)) { + int32_t errCode = OHOS::Notification::ERROR_PARAM_INVALID; + OHOS::NotificationSts::ThrowStsErrorWithInvalidParam(env); + return errCode; + } + int32_t ret = NotificationHelper::UnregisterPushCallback(); + ANS_LOGD("done. ret %{public}d", ret); + return ERR_OK; +#else + int32_t errCode = OHOS::Notification::ERROR_SYSTEM_CAP_ERROR; + OHOS::NotificationSts::ThrowStsErrorWithCode(env, errCode); + return errCode; +#endif +} +} +} \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_open_settings.cpp b/frameworks/ets/ani/src/manager/ani_open_settings.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0fbb71964d47eeef5ce9cb51ce22f126d2d90552 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_open_settings.cpp @@ -0,0 +1,351 @@ +/* + * 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 "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 : NotificationSts::GetExternalCode(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..674d6b945551edd4d828e30efa128ed596eb2903 100644 --- a/frameworks/ets/ani/src/manager/ani_publish.cpp +++ b/frameworks/ets/ani/src/manager/ani_publish.cpp @@ -14,9 +14,9 @@ */ #include "ani_publish.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" +#include "sts_bundle_option.h" #include "sts_throw_erro.h" #include "sts_common.h" #include "sts_request.h" @@ -36,9 +36,8 @@ void AniPublish(ani_env *env, ani_object obj) return; } int returncode = NotificationHelper::PublishNotification(*notificationRequest); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { - ANS_LOGE("AniPublish error, errorCode: %{public}d", externalCode); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } ANS_LOGD("AniPublish end"); @@ -50,18 +49,74 @@ void AniPublishWithId(ani_env *env, ani_object obj, ani_double userId) //NotificationRequest request; std::shared_ptr notificationRequest = std::make_shared(); if (NotificationSts::UnWarpNotificationRequest(env, obj, notificationRequest) != ANI_OK) { - ANS_LOGE("UnWarpNotificationRequest failed"); NotificationSts::ThrowStsErroWithMsg(env, "AniPublishWithId ERROR_INTERNAL_ERROR"); return; } notificationRequest->SetOwnerUserId(static_cast(userId)); int returncode = NotificationHelper::PublishNotification(*notificationRequest); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniPublishWithId error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } ANS_LOGD("AniPublishWithId end"); } + +void AniPublishAsBundle(ani_env *env, ani_object request, ani_string representativeBundle, ani_double userId) +{ + ANS_LOGD("AniPublishAsBundle enter"); + std::string bundleStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, representativeBundle, bundleStr)) { + NotificationSts::ThrowStsErroWithMsg(env, "AniPublishAsBundle ERROR_INTERNAL_ERROR"); + return; + } + + std::shared_ptr notificationRequest = std::make_shared(); + if (NotificationSts::UnWarpNotificationRequest(env, request, notificationRequest) != ANI_OK) { + ANS_LOGE("AniPublishAsBundle failed"); + NotificationSts::ThrowStsErroWithMsg(env, "AniPublishAsBundle ERROR_INTERNAL_ERROR"); + return; + } + notificationRequest->SetOwnerUserId(static_cast(userId)); + notificationRequest->SetOwnerBundleName(bundleStr); + int returncode = NotificationHelper::PublishNotification(*notificationRequest); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniPublishAsBundle: PublishNotificationerror, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + + ANS_LOGD("AniPublishAsBundle end"); +} + +void AniPublishAsBundleWithBundleOption(ani_env *env, ani_object representativeBundle, ani_object request) +{ + ANS_LOGE("AniPublishAsBundleWithBundleOption enter"); + std::shared_ptr notificationRequest = std::make_shared(); + if (NotificationSts::UnWarpNotificationRequest(env, request, notificationRequest) != ANI_OK) { + NotificationSts::ThrowStsErroWithMsg(env, "AniPublishAsBundleWithBundleOption ERROR_INTERNAL_ERROR"); + return; + } + + BundleOption option; + if (NotificationSts::UnwrapBundleOption(env, representativeBundle, option) != true) { + NotificationSts::ThrowStsErroWithMsg(env, "UnwrapBundleOption ERROR_INTERNAL_ERROR"); + return; + } + + ANS_LOGD("AniPublishAsBundleWithBundleOption: bundle %{public}s uid: %{public}d", + option.GetBundleName().c_str(), option.GetUid()); + notificationRequest->SetOwnerBundleName(option.GetBundleName()); + notificationRequest->SetOwnerUid(option.GetUid()); + notificationRequest->SetIsAgentNotification(true); + + int returncode = NotificationHelper::PublishNotification(*notificationRequest); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniPublishAsBundleWithBundleOption error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniPublishAsBundleWithBundleOption end"); +} } // namespace NotificationManagerSts } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_push_callback.cpp b/frameworks/ets/ani/src/manager/ani_push_callback.cpp new file mode 100755 index 0000000000000000000000000000000000000000..b20c33fbd4d7d51d4bf3db96f6834e3b1d4ebe3a --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_push_callback.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_push_callback.h" +#include "ans_log_wrapper.h" +#include "sts_notification_manager.h" +#include "sts_common.h" + +namespace OHOS { +namespace NotificationManagerSts { +using namespace OHOS::Notification; +using namespace OHOS::NotificationSts; +StsPushCallBack::StsPushCallBack(ani_env *env) +{ + if (env == nullptr || env->GetVM(&vm_) != ANI_OK) { + ANS_LOGE("InvalidParam 'env'"); + } +} + +StsPushCallBack::~StsPushCallBack() +{ +} + +int32_t StsPushCallBack::OnCheckNotification( + const std::string ¬ificationData, const std::shared_ptr &pushCallBackParam) +{ + ANS_LOGD("enter"); + std::lock_guard l(mutexlock); + if (vm_ == nullptr || pushCallBackParam == nullptr) { + ANS_LOGE("InvalidParam"); + return ERR_INVALID_STATE; + } + ani_env* env; + ani_status aniResult = ANI_ERROR; + if (ANI_OK != (aniResult = vm_->GetEnv(ANI_VERSION_1, &env))) { + ANS_LOGD("GetEnv error. result: %{public}d.", aniResult); + return ERR_INVALID_STATE; + } + return CheckNotification(env, notificationData, pushCallBackParam); +} + +void StsPushCallBack::SetJsPushCallBackObject( + ani_env *env, NotificationConstant::SlotType slotType, ani_ref pushCallBackObject) +{ + ANS_LOGD("enter"); + if (env == nullptr || pushCallBackObject == nullptr) { + ANS_LOGE("InvalidParam"); + return; + } + ani_ref pushCheckObject; + ani_status status = ANI_OK; + if (ANI_OK != (status = env->GlobalReference_Create(pushCallBackObject, &pushCheckObject))) { + ANS_LOGE("GlobalReference_Create pushCallBackObject faild. status %{public}d", status); + return; + } + pushCallBackObjects_.insert_or_assign(slotType, pushCheckObject); +} + +void StsPushCallBack::HandleCheckCallback( + ani_env *env, ani_fn_object fn, ani_object value, const std::shared_ptr &pushCallBackParam) +{ + ANS_LOGD("enter"); + if (env == nullptr || fn == nullptr || value == nullptr || pushCallBackParam == nullptr) { + ANS_LOGE("pushCallBackObjects is nullptr"); + return; + } + std::vector vec; + vec.push_back(value); + ani_ref funcResult; + ani_status status = ANI_OK; + if (ANI_OK != (status = env->FunctionalObject_Call(fn, vec.size(), vec.data(), &funcResult))) { + ANS_LOGE("FunctionalObject_Call faild. status %{public}d", status); + return; + } + ResultParam result; + if (!WarpFunctionResult(env, static_cast(funcResult), result)) { + ANS_LOGE("WarpFunctionResult faild"); + return; + } + std::unique_lock uniqueLock(pushCallBackParam->callBackMutex); + pushCallBackParam->result = result.code; + pushCallBackParam->ready = true; + pushCallBackParam->callBackCondition.notify_all(); + ANS_LOGD("done"); +} + +int32_t StsPushCallBack::CheckNotification( + ani_env *env, + const std::string ¬ificationData, + const std::shared_ptr &pushCallBackParam) +{ + ANS_LOGD("enter"); + auto checkInfo = std::make_shared(); + checkInfo->ConvertJsonStringToValue(notificationData); + NotificationConstant::SlotType outSlotType = static_cast(checkInfo->GetSlotType()); + if (pushCallBackObjects_.find(outSlotType) == pushCallBackObjects_.end()) { + ANS_LOGE("pushCallBackObjects is nullptr"); + return ERR_INVALID_STATE; + } + ani_object checkInfoObj; + if (!WarpNotificationCheckInfo(env, checkInfo, checkInfoObj) || checkInfoObj == nullptr) { + ANS_LOGE("WarpNotificationCheckInfo faild"); + return ERR_INVALID_STATE; + } + HandleCheckCallback( + env, static_cast(pushCallBackObjects_[outSlotType]), checkInfoObj, pushCallBackParam); + return ERR_OK; +} + +bool StsPushCallBack::WarpFunctionResult(ani_env *env, ani_object obj, ResultParam &result) +{ + ANS_LOGD("enter"); + if (env == nullptr || obj == nullptr) return false; + ani_status status = ANI_OK; + ani_double code; + ani_ref msg; + std::string message = ""; + if (ANI_OK != (status = env->Object_GetPropertyByName_Double(obj, "code", &code))) { + ANS_LOGE("WarpFunctionResult. code faild. status %{public}d", status); + return false; + } + if (ANI_OK != (status = env->Object_GetPropertyByName_Ref(obj, "message", &msg))) { + ANS_LOGE("WarpFunctionResult. message faild. status %{public}d", status); + return false; + } + if (ANI_OK != (status = GetStringByAniString(env, static_cast(msg), message))) { + ANS_LOGE("GetStringByAniString faild. status %{public}d", status); + return false; + } + result.code = code; + result.msg = message; + ANS_LOGD("WarpFunctionResult: code %{public}d message %{public}s", result.code, result.msg.c_str()); + return true; +} +} +} \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_remove_group.cpp b/frameworks/ets/ani/src/manager/ani_remove_group.cpp new file mode 100644 index 0000000000000000000000000000000000000000..33d90ca765ef11f424bda7533493add5f56765ce --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_remove_group.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ani_remove_group.h" + +#include "ans_log_wrapper.h" +#include "sts_error_utils.h" +#include "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 tempStr = ""; + ani_status status = NotificationSts::GetStringByAniString(env, groupName, tempStr); + if (status != ANI_OK) { + NotificationSts::ThrowStsErroWithMsg(env, "sts AniRemoveGroupByBundle ERROR_INTERNAL_ERROR"); + return ; + } + std::string groupNameStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); + int returncode = OHOS::Notification::NotificationHelper::RemoveGroupByBundle(option, groupNameStr); + int externalCode = NotificationSts::GetExternalCode(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_request_enable.cpp b/frameworks/ets/ani/src/manager/ani_request_enable.cpp index 910cac486064a992279034197f35b2b263ac4eb1..2dab900305bb64cf7cab4fbde891d4fdb060c36f 100755 --- a/frameworks/ets/ani/src/manager/ani_request_enable.cpp +++ b/frameworks/ets/ani/src/manager/ani_request_enable.cpp @@ -17,7 +17,6 @@ #include "ani_ans_dialog_callback.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" @@ -54,9 +53,13 @@ void RequestEnableExecute(std::shared_ptr &info) { ANS_LOGD("enter"); sptr client = nullptr; - AnsDialogHostClient::CreateIfNullptr(client); - if (client == nullptr) { + if (!AnsDialogHostClient::CreateIfNullptr(client)) { ANS_LOGD("create client fail"); + info->errorCode = ERR_ANS_DIALOG_IS_POPPING; + return; + } + if (client == nullptr) { + ANS_LOGD("client is nullptr"); info->errorCode = ERROR_INTERNAL_ERROR; return; } @@ -86,7 +89,7 @@ void StsAsyncCompleteCallbackRequestEnableNotification(ani_env *env, std::shared if (env == nullptr || info == nullptr) return; ani_status status; int32_t errorCode = info->errorCode == - ERR_OK ? ERR_OK : CJSystemapi::Notification::ErrorToExternal(info->errorCode); + ERR_OK ? ERR_OK : NotificationSts::GetExternalCode(info->errorCode); if (errorCode == ERR_OK) { ANS_LOGD("Resolve. errorCode %{public}d", errorCode); ani_object ret = OHOS::AppExecFwk::createInt(env, errorCode); diff --git a/frameworks/ets/ani/src/manager/ani_slot.cpp b/frameworks/ets/ani/src/manager/ani_slot.cpp index 86224ee2b86aa0b91b11372090831d61a39822b4..d0d49fc533b04de66bacf17daf16536a09e92ef3 100644 --- a/frameworks/ets/ani/src/manager/ani_slot.cpp +++ b/frameworks/ets/ani/src/manager/ani_slot.cpp @@ -18,7 +18,6 @@ #include "sts_throw_erro.h" #include "sts_error_utils.h" #include "sts_common.h" -#include "inner_errors.h" #include "notification_helper.h" #include "sts_bundle_option.h" #include "sts_slot.h" @@ -27,11 +26,14 @@ namespace OHOS { namespace NotificationManagerSts { +namespace { +constexpr int32_t RETURN_EXCEPTION_VALUE = -1; +} // namespace ani_object AniGetSlotsByBundle(ani_env *env, ani_object bundleOption) { ANS_LOGD("sts GetSlotsByBundle enter"); - int returncode = 0; + int returncode = ERR_OK; std::vector> slots; BundleOption option; if (NotificationSts::UnwrapBundleOption(env, bundleOption, option)) { @@ -41,8 +43,8 @@ ani_object AniGetSlotsByBundle(ani_env *env, ani_object bundleOption) return nullptr; } - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("sts GetSlotsByBundle error, errorCode: %{public}d", externalCode); OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return nullptr; @@ -56,6 +58,204 @@ ani_object AniGetSlotsByBundle(ani_env *env, ani_object bundleOption) return outAniObj; } +void AniAddSlots(ani_env *env, ani_object notificationSlotArrayObj) +{ + ANS_LOGD("AniAddSlots enter"); + std::vector slots; + if (!NotificationSts::UnwrapNotificationSlotArrayByAniObj(env, notificationSlotArrayObj, slots)) { + ANS_LOGE("UnwrapNotificationSlotArrayByAniObj failed"); + NotificationSts::ThrowStsErroWithMsg(env, "sts AddSlots ERROR_INTERNAL_ERROR"); + return; + } + int returncode = Notification::NotificationHelper::AddNotificationSlots(slots); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniAddSlots -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniAddSlots leave"); +} + +void AniAddSlotByNotificationSlot(ani_env *env, ani_object notificationSlotObj) +{ + ANS_LOGD("AniAddSlotByNotificationSlot enter"); + int returncode = ERR_OK; + Notification::NotificationSlot slot; + if (NotificationSts::UnwrapNotificationSlot(env, notificationSlotObj, slot)) { + returncode = Notification::NotificationHelper::AddNotificationSlot(slot); + } else { + NotificationSts::ThrowStsErroWithMsg(env, "sts AddSlot ERROR_INTERNAL_ERROR"); + return; + } + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("sts AddSlot error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniAddSlotByNotificationSlot leave"); +} + +void AniAddSlotBySlotType(ani_env *env, ani_enum_item enumObj) +{ + ANS_LOGD("AniAddSlotBySlotType enter"); + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (!NotificationSts::SlotTypeEtsToC(env, enumObj, slotType)) { + NotificationSts::ThrowStsErroWithMsg(env, "AddSlotByType ERROR_INTERNAL_ERROR"); + return; + } + int returncode = Notification::NotificationHelper::AddSlotByType(slotType); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniAddSlotBySlotType -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + ANS_LOGD("AniAddSlotBySlotType leave"); + return; +} + +ani_object AniGetSlot(ani_env *env, ani_enum_item enumObj) +{ + ANS_LOGD("AniGetSlot enter"); + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (!NotificationSts::SlotTypeEtsToC(env, enumObj, slotType)) { + ANS_LOGE("SlotTypeEtsToC failed"); + NotificationSts::ThrowStsErroWithMsg(env, "sts GetSlot ERROR_INTERNAL_ERROR"); + return nullptr; + } + sptr slot = nullptr; + int returncode = Notification::NotificationHelper::GetNotificationSlot(slotType, slot); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniGetSlot -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + } + if (slot == nullptr) { + ANS_LOGD("AniGetSlot -> slot is nullptr"); + AbilityRuntime::ThrowStsError(env, RETURN_EXCEPTION_VALUE, "slot is null"); + return nullptr; + } + ani_object slotObj; + if (!NotificationSts::WrapNotificationSlot(env, slot, slotObj)) { + ANS_LOGE("WrapNotificationSlot faild"); + NotificationSts::ThrowStsErroWithMsg(env, "sts GetSlot ERROR_INTERNAL_ERROR"); + return nullptr; + } + ANS_LOGD("AniGetSlot leave"); + return slotObj; +} + +ani_object AniGetSlots(ani_env *env) +{ + ANS_LOGD("AniGetSlots enter"); + std::vector> slots; + int returncode = Notification::NotificationHelper::GetNotificationSlots(slots); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniGetSlots -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return nullptr; + } + ani_object outAniObj; + if (!NotificationSts::WrapNotificationSlotArray(env, slots, outAniObj)) { + ANS_LOGE("WrapNotificationSlotArray faild"); + NotificationSts::ThrowStsErroWithMsg(env, "AniGetSlots:failed to WrapNotificationSlotArray"); + return nullptr; + } + ANS_LOGD("AniGetSlots leave"); + return outAniObj; +} + +void AniRemoveSlot(ani_env *env, ani_enum_item enumObj) +{ + ANS_LOGD("AniRemoveSlot enter"); + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (!NotificationSts::SlotTypeEtsToC(env, enumObj, slotType)) { + ANS_LOGE("SlotTypeEtsToC failed"); + NotificationSts::ThrowStsErroWithMsg(env, "sts GetSlot ERROR_INTERNAL_ERROR"); + return; + } + int returncode = Notification::NotificationHelper::RemoveNotificationSlot(slotType); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniRemoveSlot -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniRemoveSlot leave"); +} + +void AniRemoveAllSlots(ani_env *env) +{ + ANS_LOGD("AniRemoveAllSlots enter"); + int returncode = Notification::NotificationHelper::RemoveAllSlots(); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("AniRemoveAllSlots -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniRemoveAllSlots leave"); +} + +void AniSetSlotByBundle(ani_env *env, ani_object bundleOptionObj, ani_object slotObj) +{ + ANS_LOGD("AniSetSlotByBundle enter"); + Notification::NotificationBundleOption option; + if (!NotificationSts::UnwrapBundleOption(env, bundleOptionObj, option)) { + ANS_LOGE("UnwrapBundleOption failed"); + NotificationSts::ThrowStsErroWithMsg(env, "AniSetNotificationEnableSlot ERROR_INTERNAL_ERROR"); + return; + } + + Notification::NotificationSlot slot; + if (!NotificationSts::UnwrapNotificationSlot(env, slotObj, slot)) { + ANS_LOGE("UnwrapNotificationSlot failed"); + NotificationSts::ThrowStsErroWithMsg(env, "sts SetSlotByBundle ERROR_INTERNAL_ERROR"); + return; + } + + std::vector> slotsVct; + sptr slotPtr = new (std::nothrow) Notification::NotificationSlot(slot); + if (slotPtr == nullptr) { + ANS_LOGE("Failed to create NotificationSlot ptr"); + NotificationSts::ThrowStsErroWithMsg(env, "sts AniSetSlotByBundle ERROR_INTERNAL_ERROR"); + return; + } + slotsVct.emplace_back(slotPtr); + + int returncode = Notification::NotificationHelper::UpdateNotificationSlots(option, slotsVct); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("sts SetSlotByBundle error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return; + } + ANS_LOGD("AniSetSlotByBundle leave"); +} + +ani_double AniGetSlotNumByBundle(ani_env *env, ani_object bundleOption) +{ + ANS_LOGD("AniGetSlotNumByBundle enter"); + Notification::NotificationBundleOption option; + if (!NotificationSts::UnwrapBundleOption(env, bundleOption, option)) { + ANS_LOGE("UnwrapBundleOption failed"); + NotificationSts::ThrowStsErroWithMsg(env, "AniGetSlotNumByBundle ERROR_INTERNAL_ERROR"); + return RETURN_EXCEPTION_VALUE; + } + uint64_t num = 0; + int returncode = Notification::NotificationHelper::GetNotificationSlotNumAsBundle(option, num); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("sts GetSlotNumByBundle error, errorCode: %{public}d", externalCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return RETURN_EXCEPTION_VALUE; + } + ani_double retNum = static_cast(num); + ANS_LOGD("AniGetSlotNumByBundle leave"); + return retNum; +} void AniSetNotificationEnableSlot(ani_env *env, ani_object bundleOption, ani_enum_item type, ani_boolean enable) { ANS_LOGD("AniSetNotificationEnableSlot enter "); @@ -74,8 +274,8 @@ void AniSetNotificationEnableSlot(ani_env *env, ani_object bundleOption, ani_enu returncode = Notification::NotificationHelper::SetEnabledForBundleSlot(option, slotType, NotificationSts::AniBooleanToBool(enable), isForceControl); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniSetNotificationEnableSlot error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); return; @@ -99,8 +299,8 @@ void AniSetNotificationEnableSlotWithForce(ani_env *env, returncode = Notification::NotificationHelper::SetEnabledForBundleSlot(option, slotType, NotificationSts::AniBooleanToBool(enable), NotificationSts::AniBooleanToBool(isForceControl)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniSetNotificationEnableSlotSync error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -119,8 +319,8 @@ ani_boolean AniIsNotificationSlotEnabled(ani_env *env, ani_object bundleOption, bool isEnable = false; int returncode = Notification::NotificationHelper::GetEnabledForBundleSlot(option, slotType, isEnable); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("IsNotificationSlotEnabled -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -137,8 +337,8 @@ ani_int AniGetSlotFlagsByBundle(ani_env *env, ani_object obj) } uint32_t slotFlags = 0; int returncode = Notification::NotificationHelper::GetNotificationSlotFlagsAsBundle(option, slotFlags); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniGetSlotFlagsByBundle -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } @@ -155,8 +355,8 @@ void AniSetSlotFlagsByBundle(ani_env *env, ani_object obj, ani_double slotFlags) } int returncode = Notification::NotificationHelper::SetNotificationSlotFlagsAsBundle(option, static_cast(slotFlags)); - int externalCode = CJSystemapi::Notification::ErrorToExternal(returncode); - if (externalCode != 0) { + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { ANS_LOGE("AniSetSlotFlagsByBundle -> error, errorCode: %{public}d", externalCode); AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); } diff --git a/frameworks/ets/ani/src/manager/ani_support_template.cpp b/frameworks/ets/ani/src/manager/ani_support_template.cpp new file mode 100755 index 0000000000000000000000000000000000000000..b79ef22eb7b6d2de6b1c42b1b9796dd50ebba75e --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_support_template.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ani_support_template.h" + +#include "notification_helper.h" +#include "ans_log_wrapper.h" +#include "sts_throw_erro.h" +#include "sts_common.h" +#include "sts_bundle_option.h" +#include "sts_notification_manager.h" + +namespace OHOS { +namespace NotificationManagerSts { +ani_boolean AniIsSupportTemplate(ani_env* env, ani_string templateName) +{ + ANS_LOGD("AniIsSupportTemplate call"); + std::string tempStr; + if (NotificationSts::GetStringByAniString(env, templateName, tempStr) != ANI_OK) { + NotificationSts::ThrowStsErroWithMsg(env, "templateName parse failed!"); + return NotificationSts::BoolToAniBoolean(false); + } + std::string templateNameStr = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); + ANS_LOGD("AniIsSupportTemplate by templateName:%{public}s", templateNameStr.c_str()); + bool support = false; + int returncode = Notification::NotificationHelper::IsSupportTemplate(templateNameStr, support); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("AniIsSupportTemplate -> error, errorCode: %{public}d", externalCode); + return NotificationSts::BoolToAniBoolean(false); + } + ANS_LOGD("AniIsSupportTemplate end, support: %{public}d, returncode: %{public}d", support, externalCode); + return NotificationSts::BoolToAniBoolean(support); +} + +ani_object AniGetDeviceRemindType(ani_env *env) +{ + ANS_LOGD("AniGetDeviceRemindType enter"); + + Notification::NotificationConstant::RemindType remindType = + Notification::NotificationConstant::RemindType::DEVICE_IDLE_REMIND; + int returncode = Notification::NotificationHelper::GetDeviceRemindType(remindType); + + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + OHOS::AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + ANS_LOGE("AniGetDeviceRemindType error, errorCode: %{public}d", externalCode); + return nullptr; + } + ani_enum_item remindTypeItem {}; + if (!NotificationSts::DeviceRemindTypeCToEts(env, remindType, remindTypeItem)) { + NotificationSts::ThrowStsErroWithMsg(env, "AniGetDeviceRemindType:failed to WrapNotificationSlotArray"); + return nullptr; + } + ANS_LOGD("AniGetDeviceRemindType end, ret: %{public}d", externalCode); + return remindTypeItem; +} +} +} \ No newline at end of file diff --git a/frameworks/ets/ani/src/manager/ani_sync_config.cpp b/frameworks/ets/ani/src/manager/ani_sync_config.cpp new file mode 100644 index 0000000000000000000000000000000000000000..edf00e43c30ab56a5923732aac1b09f5660cc756 --- /dev/null +++ b/frameworks/ets/ani/src/manager/ani_sync_config.cpp @@ -0,0 +1,60 @@ +/* + * 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 "notification_helper.h" +#include "ans_log_wrapper.h" +#include "sts_throw_erro.h" +#include "sts_common.h" +#include "sts_bundle_option.h" +#include "sts_notification_manager.h" + +namespace OHOS { +namespace NotificationManagerSts { +const double RESULT_OK = 0.0; +const double RESULT_FAILED = 1.0; + +ani_double AniSetAdditionalConfig(ani_env *env, ani_string key, ani_string value) +{ + ANS_LOGD("sts setAdditionalConfig call"); + if (env == nullptr || key == nullptr) { + ANS_LOGE("Invalid env or key is null"); + return RESULT_FAILED; + } + std::string keyStr; + if (NotificationSts::GetStringByAniString(env, key, keyStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return RESULT_FAILED; + } + std::string valueStr; + if (NotificationSts::GetStringByAniString(env, value, valueStr) != ANI_OK) { + std::string msg = "Parameter verification failed"; + ANS_LOGE("GetStringByAniString failed. msg: %{public}s", msg.c_str()); + OHOS::AbilityRuntime::ThrowStsError(env, Notification::ERROR_PARAM_INVALID, msg); + return RESULT_FAILED; + } + int returncode = Notification::NotificationHelper::SetAdditionConfig(keyStr, valueStr); + int externalCode = NotificationSts::GetExternalCode(returncode); + if (externalCode != ERR_OK) { + ANS_LOGE("setAdditionalConfig -> error, errorCode: %{public}d", externalCode); + AbilityRuntime::ThrowStsError(env, externalCode, NotificationSts::FindAnsErrMsg(externalCode)); + return RESULT_FAILED; + } + return RESULT_OK; +} +} // namespace NotificationManagerSts +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ets/ani/src/sts_action_button.cpp b/frameworks/ets/ani/src/sts_action_button.cpp index 7b5288f74e1412953c6b393c2103d499c43f0bba..26968f75212054c1f282168c47704b7abc5b803d 100644 --- a/frameworks/ets/ani/src/sts_action_button.cpp +++ b/frameworks/ets/ani/src/sts_action_button.cpp @@ -146,7 +146,7 @@ bool SetNotificationActionButtonByRequiredParameter( } ani_string stringValue; // title: string; - if (!GetAniStringByString(env, actionButton->GetTitle(), stringValue)) { + if (ANI_OK != GetAniStringByString(env, actionButton->GetTitle(), stringValue)) { ANS_LOGE("SetActionButtonByRequiredParameter: Get title failed"); return false; } diff --git a/frameworks/ets/ani/src/sts_bundle_option.cpp b/frameworks/ets/ani/src/sts_bundle_option.cpp index 938b388b38d91323e3dcccb9020ae91628b93e18..edcf1645495710ae8de1fadee5032a3bfba7660f 100644 --- a/frameworks/ets/ani/src/sts_bundle_option.cpp +++ b/frameworks/ets/ani/src/sts_bundle_option.cpp @@ -26,12 +26,13 @@ bool UnwrapBundleOption(ani_env *env, ani_object obj, Notification::Notification ANS_LOGE("UnwrapBundleOption failed, has nullptr"); return false; } - std::string bundleName; + std::string tempStr; ani_boolean isUndefined = ANI_TRUE; - if (GetPropertyString(env, obj, "bundle", isUndefined, bundleName) !=ANI_OK || isUndefined == ANI_TRUE) { + if (GetPropertyString(env, obj, "bundle", isUndefined, tempStr) !=ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("UnwrapBundleOption Get bundle failed"); return false; } + std::string bundleName = GetResizeStr(tempStr, STR_MAX_SIZE); option.SetBundleName(bundleName); ani_double result = 0.0; if (GetPropertyDouble(env, obj, "uid", isUndefined, result) == ANI_OK && isUndefined == ANI_FALSE) { @@ -44,6 +45,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; + } + int32_t 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) { @@ -95,7 +127,7 @@ bool WrapBundleOption(ani_env* env, } // bundle: string; ani_string stringValue = nullptr; - if (!GetAniStringByString(env, bundleOption->GetBundleName(), stringValue) + if (ANI_OK != GetAniStringByString(env, bundleOption->GetBundleName(), stringValue) || !CallSetter(env, bundleCls, bundleObject, "bundle", stringValue)) { ANS_LOGE("WrapBundleOption: set bundle failed"); return false; diff --git a/frameworks/ets/ani/src/sts_common.cpp b/frameworks/ets/ani/src/sts_common.cpp index 44ecf2cc0be067316254b140c8c2442c27934633..54e5d0e470eb4a6843257efb2dd53d8902ba4165 100644 --- a/frameworks/ets/ani/src/sts_common.cpp +++ b/frameworks/ets/ani/src/sts_common.cpp @@ -22,6 +22,10 @@ namespace NotificationSts { constexpr const char* CLASSNAME_BOOLEAN = "Lstd/core/Boolean;"; constexpr const char* CLASSNAME_DOUBLE = "Lstd/core/Double;"; constexpr const char* CLASSNAME_INT = "Lstd/core/Int;"; +std::string GetResizeStr(std::string instr, int32_t length) +{ + return instr.length() <= length ? instr : instr.substr(0, length); +} bool IsUndefine(ani_env *env, const ani_object &obj) { @@ -93,8 +97,8 @@ bool GetStringArrayByAniObj(ani_env *env, const ani_object ani_obj, std::vector< return false; } std::string std_string; - if (!GetStringByAniString(env, static_cast(stringEntryRef), std_string)) { - ANS_LOGE("GetStdString faild"); + if (ANI_OK != (status = GetStringByAniString(env, static_cast(stringEntryRef), std_string))) { + ANS_LOGE("GetStdString faild. status %{public}d", status); return false; } stdVString.emplace_back(std_string); @@ -255,6 +259,44 @@ ani_status GetPropertyStringArray(ani_env *env, ani_object param, const char *na return status; } +ani_status GetPropertyNumberArray(ani_env *env, ani_object param, const char *name, + ani_boolean &isUndefined, std::vector &res) +{ + ANS_LOGD("GetPropertyNumberArray enter"); + ani_ref arrayObj = nullptr; + ani_status status; + ani_double length; + if ((status = GetPropertyRef(env, param, name, isUndefined, arrayObj)) != ANI_OK || isUndefined == ANI_TRUE) { + return ANI_INVALID_ARGS; + } + + status = env->Object_GetPropertyByName_Double(static_cast(arrayObj), "length", &length); + if (status != ANI_OK) { + ANS_LOGI("status : %{public}d", status); + return status; + } + + for (int i = 0; i < static_cast(length); i++) { + ani_ref numEntryRef; + status = env->Object_CallMethodByName_Ref(static_cast(arrayObj), + "$_get", "I:Lstd/core/Object;", &numEntryRef, (ani_int)i); + if (status != ANI_OK) { + ANS_LOGI("status : %{public}d, index: %{public}d", status, i); + return status; + } + ani_double doubleValue = 0.0; + status = env->Object_CallMethodByName_Double(static_cast(numEntryRef), "unboxed", + ":D", &doubleValue); + if (status != ANI_OK) { + ANS_LOGI("Object_CallMethodByName_Double uid fail, status: %{public}d", status); + return status; + } + res.push_back(static_cast(doubleValue)); + } + ANS_LOGD("GetPropertyNumberArray leave"); + return status; +} + ani_object GetAniStringArrayByVectorString(ani_env *env, std::vector &strs) { if (env == nullptr || strs.empty()) { @@ -477,8 +519,8 @@ ani_object newRecordClass(ani_env *env) ani_object ConvertArrayDoubleToAniObj(ani_env *env, const std::vector values) { - if (env == nullptr || values.empty()) { - ANS_LOGE("ConvertArrayDoubleToAniObj fail, env is nullptr or values is empty"); + if (env == nullptr) { + ANS_LOGE("ConvertArrayDoubleToAniObj fail, env is nullptr"); return nullptr; } ani_object arrayObj = newArrayClass(env, values.size()); diff --git a/frameworks/ets/ani/src/sts_convert_other.cpp b/frameworks/ets/ani/src/sts_convert_other.cpp index b316a48594fa7bf8090eed59351f212da8b2b151..f85af200b84a6ffc29b7f2a864ba8f943e344028 100644 --- a/frameworks/ets/ani/src/sts_convert_other.cpp +++ b/frameworks/ets/ani/src/sts_convert_other.cpp @@ -51,19 +51,20 @@ ani_status UnwrapResource(ani_env *env, ani_object obj, ResourceManager::Resourc return ANI_ERROR; } ani_status status = ANI_ERROR; - std::string bundleName = ""; + std::string tempStr = ""; ani_boolean isUndefined = ANI_TRUE; - if ((status = GetPropertyString(env, obj, "bundleName", isUndefined, bundleName)) != ANI_OK + if ((status = GetPropertyString(env, obj, "bundleName", isUndefined, tempStr)) != ANI_OK || isUndefined == ANI_TRUE) { return ANI_INVALID_ARGS; } + std::string bundleName = GetResizeStr(tempStr, STR_MAX_SIZE); resource.bundleName = bundleName; - std::string moduleName = ""; - if ((status = GetPropertyString(env, obj, "moduleName", isUndefined, moduleName)) != ANI_OK + if ((status = GetPropertyString(env, obj, "moduleName", isUndefined, tempStr)) != ANI_OK || isUndefined == ANI_TRUE) { return ANI_INVALID_ARGS; } + std::string moduleName = GetResizeStr(tempStr, STR_MAX_SIZE); resource.moduleName = moduleName; ani_double idAni = 0.0; diff --git a/frameworks/ets/ani/src/sts_disturb_mode.cpp b/frameworks/ets/ani/src/sts_disturb_mode.cpp index a24e389b81a86b1d135b60866bf0b88ac69a3007..1cc2f7c285f947b872331c17355a377d1f02140e 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; + } + + int32_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 : 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_content.cpp b/frameworks/ets/ani/src/sts_notification_content.cpp index b3aa635f9f0594c9b5abd4d43187bba6c0389a64..8e3b5764aa0424f39e0939ba380fde357f646a20 100644 --- a/frameworks/ets/ani/src/sts_notification_content.cpp +++ b/frameworks/ets/ani/src/sts_notification_content.cpp @@ -268,11 +268,12 @@ ani_status UnWarpNotificationIconButton(ani_env *env, ani_object obj, Notificati } ani_status status = ANI_ERROR; ani_boolean isUndefined = ANI_TRUE; - std::string name = ""; - if ((status = GetPropertyString(env, obj, "name", isUndefined, name)) != ANI_OK || isUndefined == ANI_TRUE) { + std::string tempStr = ""; + if ((status = GetPropertyString(env, obj, "name", isUndefined, tempStr)) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("UnWarpNotificationIconButton: get name failed, status = %{public}d", status); return ANI_INVALID_ARGS; } + std::string name = GetResizeStr(tempStr, STR_MAX_SIZE); iconButton.SetName(name); ani_ref iconRef = {}; if ((status = GetPropertyRef(env, obj, "iconResource", isUndefined, iconRef)) != ANI_OK @@ -291,8 +292,8 @@ ani_status UnWarpNotificationIconButton(ani_env *env, ani_object obj, Notificati } iconButton.SetIconImage(pixelMap); } - std::string text = ""; - if (GetPropertyString(env, obj, "text", isUndefined, text) == ANI_OK && isUndefined == ANI_FALSE) { + if (GetPropertyString(env, obj, "text", isUndefined, tempStr) == ANI_OK && isUndefined == ANI_FALSE) { + std::string text = GetResizeStr(tempStr, STR_MAX_SIZE); iconButton.SetName(text); } else { ANS_LOGD("UnWarpNotificationIconButton: get text failed"); @@ -362,7 +363,7 @@ void UnWarpNotificationLocalLiveViewButton(ani_env *env, ani_object obj, // names?: Array if (GetPropertyStringArray(env, obj, "names", isUndefined, names) == ANI_OK && isUndefined == ANI_FALSE) { for (auto name: names) { - button.addSingleButtonName(name); + button.addSingleButtonName(GetResizeStr(name, STR_MAX_SIZE)); } } else { ANS_LOGD("UnWarpNotificationLocalLiveViewButton get names failed."); @@ -479,7 +480,7 @@ void UnWarpNotificationCapsule(ani_env *env, ani_object obj, NotificationCapsule ani_boolean isUndefined = ANI_TRUE; std::string title = ""; if (GetPropertyString(env, obj, "title", isUndefined, title) == ANI_OK && isUndefined == ANI_FALSE) { - capsule.SetTitle(title); + capsule.SetTitle(GetResizeStr(title, STR_MAX_SIZE)); } else { ANS_LOGE("UnWarpNotificationCapsule: get title failed"); } @@ -487,14 +488,14 @@ void UnWarpNotificationCapsule(ani_env *env, ani_object obj, NotificationCapsule isUndefined = ANI_TRUE; if (GetPropertyString(env, obj, "backgroundColor", isUndefined, backgroundColor) == ANI_OK && isUndefined == ANI_FALSE) { - capsule.SetBackgroundColor(backgroundColor); + capsule.SetBackgroundColor(GetResizeStr(backgroundColor, STR_MAX_SIZE)); } else { ANS_LOGE("UnWarpNotificationCapsule: get backgroundColor failed"); } std::string content = ""; isUndefined = ANI_TRUE; if (GetPropertyString(env, obj, "content", isUndefined, content) == ANI_OK && isUndefined == ANI_FALSE) { - capsule.SetContent(content); + capsule.SetContent(GetResizeStr(content, STR_MAX_SIZE)); } else { ANS_LOGE("UnWarpNotificationCapsule: get content failed"); } @@ -652,17 +653,17 @@ ani_status UnWarpNotificationBasicContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationBasicContent: get title failed, status = %{public}d", status); return ANI_INVALID_ARGS; } - basicContent->SetTitle(title); + basicContent->SetTitle(GetResizeStr(title, SHORT_TEXT_SIZE)); std::string text; if ((status = GetPropertyString(env, obj, "text", isUndefined, text)) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("UnWarpNotificationBasicContent: get text failed, status = %{public}d", status); return ANI_INVALID_ARGS; } - basicContent->SetText(text); + basicContent->SetText(GetResizeStr(text, COMMON_TEXT_SIZE)); std::string additionalText; if (GetPropertyString(env, obj, "additionalText", isUndefined, additionalText) == ANI_OK && isUndefined == ANI_FALSE) { - basicContent->SetAdditionalText(additionalText); + basicContent->SetAdditionalText(GetResizeStr(additionalText, COMMON_TEXT_SIZE)); } else { ANS_LOGD("UnWarpNotificationBasicContent: get additionalText failed"); } @@ -719,21 +720,21 @@ ani_status UnWarpNotificationLongTextContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationLongTextContent:get longText failed"); return ANI_INVALID_ARGS; } - longTextContent->SetLongText(longText); + longTextContent->SetLongText(GetResizeStr(longText, COMMON_TEXT_SIZE)); std::string briefText; if ((status = GetPropertyString(env, obj, "briefText", isUndefined, briefText)) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("UnWarpNotificationLongTextContent:get briefText failed"); return ANI_INVALID_ARGS; } - longTextContent->SetBriefText(briefText); + longTextContent->SetBriefText(GetResizeStr(briefText, SHORT_TEXT_SIZE)); std::string expandedTitle; if ((status = GetPropertyString(env, obj, "expandedTitle", isUndefined, expandedTitle)) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGE("UnWarpNotificationLongTextContent:get expandedTitle failed"); return ANI_INVALID_ARGS; } - longTextContent->SetExpandedTitle(expandedTitle); + longTextContent->SetExpandedTitle(GetResizeStr(expandedTitle, SHORT_TEXT_SIZE)); ANS_LOGD("UnWarpNotificationLongTextContent end"); return status; } @@ -758,7 +759,7 @@ ani_status UnWarpNotificationMultiLineContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationMultiLineContent: get longTitle failed"); return ANI_INVALID_ARGS; } - multiLineContent->SetExpandedTitle(longTitle); + multiLineContent->SetExpandedTitle(GetResizeStr(longTitle, SHORT_TEXT_SIZE)); std::string briefText; isUndefined = ANI_TRUE; @@ -767,7 +768,7 @@ ani_status UnWarpNotificationMultiLineContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationMultiLineContent: get briefText failed"); return ANI_INVALID_ARGS; } - multiLineContent->SetBriefText(briefText); + multiLineContent->SetBriefText(GetResizeStr(briefText, SHORT_TEXT_SIZE)); std::vector lines = {}; isUndefined = ANI_TRUE; @@ -777,7 +778,7 @@ ani_status UnWarpNotificationMultiLineContent(ani_env *env, ani_object obj, return ANI_INVALID_ARGS; } for (auto line : lines) { - multiLineContent->AddSingleLine(line); + multiLineContent->AddSingleLine(GetResizeStr(line, SHORT_TEXT_SIZE)); } ANS_LOGD("UnWarpNotificationMultiLineContent end"); return status; @@ -803,7 +804,7 @@ ani_status UnWarpNotificationPictureContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationPictureContent: get expandedTitle failed"); return ANI_INVALID_ARGS; } - pictureContent->SetExpandedTitle(expandedTitle); + pictureContent->SetExpandedTitle(GetResizeStr(expandedTitle, SHORT_TEXT_SIZE)); std::string briefText; if ((status = GetPropertyString(env, obj, "briefText", isUndefined, briefText)) != ANI_OK @@ -811,7 +812,7 @@ ani_status UnWarpNotificationPictureContent(ani_env *env, ani_object obj, ANS_LOGE("UnWarpNotificationPictureContent: get briefText failed"); return ANI_INVALID_ARGS; } - pictureContent->SetBriefText(briefText); + pictureContent->SetBriefText(GetResizeStr(briefText, SHORT_TEXT_SIZE)); ani_ref pictureRef = {}; if ((status = GetPropertyRef(env, obj, "picture", isUndefined, pictureRef)) != ANI_OK || isUndefined == ANI_TRUE || pictureRef == nullptr) { diff --git a/frameworks/ets/ani/src/sts_notification_manager.cpp b/frameworks/ets/ani/src/sts_notification_manager.cpp index 45e711814f704a249c5d975c509ffa394e54864a..965ba2664c72a995e54b2e1387bcd7d9c323732e 100644 --- a/frameworks/ets/ani/src/sts_notification_manager.cpp +++ b/frameworks/ets/ani/src/sts_notification_manager.cpp @@ -15,6 +15,7 @@ #include "sts_notification_manager.h" #include "sts_common.h" #include "ani_common_util.h" +#include "ani_common_want.h" namespace OHOS { namespace NotificationSts { @@ -217,6 +218,74 @@ 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) { + case STSRemindType::IDLE_DONOT_REMIND: + outType = RemindType::DEVICE_IDLE_DONOT_REMIND; + break; + case STSRemindType::IDLE_REMIND: + outType = RemindType::DEVICE_IDLE_REMIND; + break; + case STSRemindType::ACTIVE_DONOT_REMIND: + outType = RemindType::DEVICE_ACTIVE_DONOT_REMIND; + break; + case STSRemindType::ACTIVE_REMIND: + outType = RemindType::DEVICE_ACTIVE_REMIND; + break; + default: + ANS_LOGE("STSRemindType %{public}d is an invalid value", inType); + return false; + } + return true; +} + +bool StsRemindTypeUtils::CToSts(const RemindType inType, STSRemindType &outType) +{ + switch (inType) { + case RemindType::NONE: + case RemindType::DEVICE_IDLE_DONOT_REMIND: + outType = STSRemindType::IDLE_DONOT_REMIND; + break; + case RemindType::DEVICE_IDLE_REMIND: + outType = STSRemindType::IDLE_REMIND; + break; + case RemindType::DEVICE_ACTIVE_DONOT_REMIND: + outType = STSRemindType::ACTIVE_DONOT_REMIND; + break; + case RemindType::DEVICE_ACTIVE_REMIND: + outType = STSRemindType::ACTIVE_REMIND; + break; + default: + ANS_LOGE("RemindType %{public}d is an invalid value", inType); + return false; + } + return true; +} + StsNotificationLocalLiveViewSubscriber::StsNotificationLocalLiveViewSubscriber() {} @@ -382,6 +451,38 @@ 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; + StsRemindTypeUtils::CToSts(remindType, stsRemindType); + EnumConvertNativeToAni(env, + "L@ohos/notificationManager/notificationManager/RemindType;", stsRemindType, enumItem); + return true; +} + +bool DeviceRemindTypeEtsToC(ani_env *env, ani_enum_item enumItem, RemindType &remindType) +{ + STSRemindType stsRemindType = STSRemindType::IDLE_DONOT_REMIND; + if (EnumConvertAniToNative(env, enumItem, stsRemindType)) { + StsRemindTypeUtils::StsToC(stsRemindType, remindType); + return true; + } + return false; +} + ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonOptionObj, ButtonOption &buttonOption) { @@ -398,7 +499,7 @@ ani_status UnWarpNotificationButtonOption(ani_env *env, const ani_object buttonO ANS_LOGE("UnWarpNotificationButtonOption: get buttonName failed"); return ANI_INVALID_ARGS; } - buttonOption.SetButtonName(buttonName); + buttonOption.SetButtonName(GetResizeStr(buttonName, STR_MAX_SIZE)); ANS_LOGD("UnWarpNotificationButtonOption end"); return status; } @@ -462,5 +563,208 @@ bool WarpNotificationDoNotDisturbDate( ANS_LOGD("WarpNotificationDoNotDisturbDate end"); return true; } + +bool SetCheckInfoContentType(ani_env *env, ani_object &obj, const std::string &name, ContentType type) +{ + if (env == nullptr || obj == nullptr || name.empty()) { + ANS_LOGE("InvalidParam"); + return false; + } + STSContentType stsType = NOTIFICATION_CONTENT_BASIC_TEXT; + ani_enum_item item; + if (!StsContentTypeUtils::CToSts(type, stsType)) { + ANS_LOGE("CToSts 'contentType' faild."); + return false; + } + if (!EnumConvertNativeToAni(env, "L@ohos/notificationManager/notificationManager/ContentType;", stsType, item)) { + ANS_LOGE("EnumConvertNativeToAni 'contentType' faild."); + return false; + } + if (!SetPropertyByRef(env, obj, name.c_str(), static_cast(item))) { + ANS_LOGE("SetPropertyByRef 'contentType' faild."); + return false; + } + return true; +} + +bool SetCheckInfoSlotType(ani_env *env, ani_object &obj, const std::string &name, SlotType type) +{ + if (env == nullptr || obj == nullptr || name.empty()) { + ANS_LOGE("InvalidParam"); + return false; + } + STSSlotType stsType = UNKNOWN_TYPE; + ani_enum_item item; + if (!StsSlotTypeUtils::CToSts(type, stsType)) { + ANS_LOGE("CToSts 'slotType' faild."); + return false; + } + if (!EnumConvertNativeToAni(env, "L@ohos/notificationManager/notificationManager/SlotType;", stsType, item)) { + ANS_LOGE("EnumConvertNativeToAni 'slotType' faild."); + return false; + } + if (!SetPropertyByRef(env, obj, name.c_str(), static_cast(item))) { + ANS_LOGE("SetPropertyByRef 'slotType' faild."); + return false; + } + return true; +} + +bool SetNotificationCheckInfoNumber( + ani_env *env, const std::shared_ptr &data, ani_object &outObj) +{ + ani_status status = ANI_OK; + // notificationId: number; + if (ANI_OK != (status = env->Object_SetPropertyByName_Double( + outObj, "notificationId", static_cast(data->GetNotifyId())))) { + ANS_LOGE("WarpNotificationCheckInfo. set 'notificationId' faild. status %{public}d", status); + return false; + } + // creatorUserId: number; + if (ANI_OK != (status = env->Object_SetPropertyByName_Double( + outObj, "creatorUserId", static_cast(data->GetCreatorUserId())))) { + ANS_LOGE("WarpNotificationCheckInfo. set 'creatorUserId' faild. status %{public}d", status); + return false; + } + return true; +} + +bool SetNotificationCheckInfoString( + ani_env *env, const std::shared_ptr &data, ani_object &outObj) +{ + // bundleName: string; + if (!SetPropertyOptionalByString(env, outObj, "bundleName", data->GetPkgName())) { + ANS_LOGE("WarpNotificationCheckInfo set 'bundleName' faild"); + return false; + } + // label?: string; + if (!data->GetLabel().empty() && !SetPropertyOptionalByString(env, outObj, "label", data->GetLabel())) { + ANS_LOGE("WarpNotificationCheckInfo set 'label' faild"); + return false; + } + return true; +} + +bool SetNotificationCheckInfoEnum( + ani_env *env, const std::shared_ptr &data, ani_object &outObj) +{ + // contentType: ContentType; + if (!SetCheckInfoContentType(env, outObj, "contentType", static_cast(data->GetContentType()))) { + ANS_LOGE("WarpNotificationCheckInfo set 'contentType' faild"); + return false; + } + // slotType: SlotType; + if (!SetCheckInfoSlotType(env, outObj, "slotType", static_cast(data->GetSlotType()))) { + ANS_LOGE("WarpNotificationCheckInfo set 'slotType' faild"); + return false; + } + return true; +} + +bool SetNotificationCheckInfo( + ani_env *env, const std::shared_ptr &data, ani_object &outObj) +{ + if (!SetNotificationCheckInfoNumber(env, data, outObj)) { + ANS_LOGE("SetNotificationCheckInfoNumber faild"); + return false; + } + if (!SetNotificationCheckInfoString(env, data, outObj)) { + ANS_LOGE("SetNotificationCheckInfoString faild"); + return false; + } + if (!SetNotificationCheckInfoEnum(env, data, outObj)) { + ANS_LOGE("SetNotificationCheckInfoEnum faild"); + return false; + } + // extraInfos?: Record; + if (data->GetExtraInfo() != nullptr) { + ani_ref extraInfos = OHOS::AppExecFwk::WrapWantParams(env, *(data->GetExtraInfo())); + if (extraInfos == nullptr) { + ANS_LOGE("WrapWantParams 'extraInfos' faild"); + return false; + } + if (!SetPropertyByRef(env, outObj, "extraInfos", extraInfos)) { + ANS_LOGE("WarpNotificationCheckInfo set 'extraInfos' faild"); + return false; + } + } + return true; +} + +bool WarpNotificationCheckInfo( + ani_env *env, const std::shared_ptr &data, ani_object &outObj) +{ + ani_object obj; + ani_class cls; + if (env == nullptr || data == nullptr) { + ANS_LOGE("InvalidParam"); + return false; + } + if (!CreateClassObjByClassName( + env, "L@ohos/notificationManager/notificationManager/NotificationCheckInfoInner;", cls, obj)) { + ANS_LOGE("WarpNotificationCheckInfo create faild"); + return false; + } + if (!SetNotificationCheckInfo(env, data, obj)) { + ANS_LOGE("SetNotificationCheckInfo faild"); + return false; + } + outObj = obj; + return true; +} + +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"); + 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 7c9cc45d9c6aab0de6126a1d22f3b7206b807c26..ed343a70577483391da6f524c4f08835dc21c234 100644 --- a/frameworks/ets/ani/src/sts_request.cpp +++ b/frameworks/ets/ani/src/sts_request.cpp @@ -25,13 +25,14 @@ #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 { using namespace OHOS::AAFwk; using namespace OHOS::AppExecFwk; -constexpr int32_t STR_MAX_SIZE = 204; void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOptions distributedOptions) { ANS_LOGD("UnWarpDistributedOptions start"); @@ -49,19 +50,27 @@ void UnWarpDistributedOptions(ani_env *env, ani_object obj, StsDistributedOption ANS_LOGD("UnWarpDistributedOptions: isDistributed get failed"); } // supportDisplayDevices?: Array; - std::vector supportDisplayDevices = {}; + std::vector tempStrings = {}; isUndefined = ANI_TRUE; - if (GetPropertyStringArray(env, obj, "supportDisplayDevices", isUndefined, supportDisplayDevices) == ANI_OK + if (GetPropertyStringArray(env, obj, "supportDisplayDevices", isUndefined, tempStrings) == ANI_OK && isUndefined == ANI_FALSE) { + std::vector supportDisplayDevices = {}; + for (auto device: tempStrings) { + supportDisplayDevices.emplace_back(GetResizeStr(device, STR_MAX_SIZE)); + } distributedOptions.supportDisplayDevices = supportDisplayDevices; } else { ANS_LOGD("UnWarpDistributedOptions: supportDisplayDevices get failed"); } // supportOperateDevices?: Array; - std::vector supportOperateDevices = {}; + tempStrings.clear(); isUndefined = ANI_TRUE; - if (GetPropertyStringArray(env, obj, "supportOperateDevices", isUndefined, supportOperateDevices) == ANI_OK + if (GetPropertyStringArray(env, obj, "supportOperateDevices", isUndefined, tempStrings) == ANI_OK && isUndefined == ANI_FALSE) { + std::vector supportOperateDevices = {}; + for (auto device: tempStrings) { + supportOperateDevices.emplace_back(GetResizeStr(device, STR_MAX_SIZE)); + } distributedOptions.supportOperateDevices = supportOperateDevices; } else { ANS_LOGD("UnWarpDistributedOptions: supportOperateDevices get failed"); @@ -230,25 +239,16 @@ void GetNotificationRequestByString(ani_env *env, ani_object obj, std::string mString = ""; ani_boolean isUndefined = ANI_TRUE; if (ANI_OK == GetPropertyString(env, obj, "classification", isUndefined, mString) && isUndefined == ANI_FALSE) { - if (mString.length() > STR_MAX_SIZE) { - mString.resize(STR_MAX_SIZE); - } - request->SetClassification(mString); + request->SetClassification(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, obj, "appMessageId", isUndefined, mString) && isUndefined == ANI_FALSE) { request->SetAppMessageId(mString); } if (ANI_OK == GetPropertyString(env, obj, "label", isUndefined, mString) && isUndefined == ANI_FALSE) { - if (mString.length() > STR_MAX_SIZE) { - mString.resize(STR_MAX_SIZE); - } - request->SetLabel(mString); + request->SetLabel(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, obj, "groupName", isUndefined, mString) && isUndefined == ANI_FALSE) { - if (mString.length() > STR_MAX_SIZE) { - mString.resize(STR_MAX_SIZE); - } - request->SetGroupName(mString); + request->SetGroupName(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, obj, "sound", isUndefined, mString) && isUndefined == ANI_FALSE) { request->SetSound(mString); @@ -671,19 +671,19 @@ void GetNotificationUnifiedGroupInfo(ani_env *env, ani_object obj, std::string mString = ""; if (ANI_OK == GetPropertyString(env, static_cast(infoRef), "key", isUndefind, mString) && isUndefind == ANI_FALSE) { - unifiedGroupInfo->SetKey(mString); + unifiedGroupInfo->SetKey(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, static_cast(infoRef), "title", isUndefind, mString) && isUndefind == ANI_FALSE) { - unifiedGroupInfo->SetTitle(mString); + unifiedGroupInfo->SetTitle(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, static_cast(infoRef), "content", isUndefind, mString) && isUndefind == ANI_FALSE) { - unifiedGroupInfo->SetContent(mString); + unifiedGroupInfo->SetContent(GetResizeStr(mString, STR_MAX_SIZE)); } if (ANI_OK == GetPropertyString(env, static_cast(infoRef), "sceneName", isUndefind, mString) && isUndefind == ANI_FALSE) { - unifiedGroupInfo->SetSceneName(mString); + unifiedGroupInfo->SetSceneName(GetResizeStr(mString, STR_MAX_SIZE)); } ani_ref extraInfoRef = {}; status = GetPropertyRef(env, static_cast(infoRef), "extraInfo", isUndefind, extraInfoRef); @@ -1146,10 +1146,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 +1171,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"); @@ -1203,5 +1195,126 @@ ani_object GetAniNotificationRequestArrayByNotifocations(ani_env *env, std::vect } return arrayObj; } + +bool GetCheckRequestContent(ani_env *env, ani_object obj, NotificationContent::Type &outContentType) +{ + ani_status status = ANI_OK; + ani_ref contentAniType; + STSContentType contentType = NOTIFICATION_CONTENT_BASIC_TEXT; + if (ANI_OK != (status = env->Object_GetPropertyByName_Ref(obj, "contentType", &contentAniType))) { + ANS_LOGE("GetCheckRequestContent get contentType faild. status %{public}d", status); + return false; + } + if (contentAniType == nullptr || + !EnumConvertAniToNative(env, static_cast(contentAniType), contentType)) { + ANS_LOGE("EnumConvertAniToNative contentType faild"); + return false; + } + if (!StsContentTypeUtils::StsToC(contentType, outContentType)) { + ANS_LOGE("StsToC contentType faild"); + return false; + } + return true; +} + +bool GetCheckRequestSlotType(ani_env *env, ani_object obj, NotificationConstant::SlotType &outSlotType) +{ + ani_status status = ANI_OK; + ani_ref slotAniType; + STSSlotType slotType = UNKNOWN_TYPE; + if (ANI_OK != (status = env->Object_GetPropertyByName_Ref(obj, "slotType", &slotAniType))) { + ANS_LOGE("UnWarpNotificationCheckRequest get slotType faild. status %{public}d", status); + return false; + } + if (slotAniType == nullptr || !EnumConvertAniToNative(env, static_cast(slotAniType), slotType)) { + ANS_LOGE("EnumConvertAniToNative slotType faild"); + return false; + } + if (!StsSlotTypeUtils::StsToC(slotType, outSlotType)) { + ANS_LOGE("StsToC slotType faild"); + return false; + } + return true; +} + +bool UnWarpNotificationCheckRequest(ani_env *env, ani_object obj, sptr &checkRequest) +{ + if (env == nullptr || obj == nullptr || checkRequest == nullptr) { + ANS_LOGE("UnWarpNotificationCheckRequest invalid parameters"); + return false; + } + ani_status status = ANI_OK; + ani_ref extraInfoKeysObj; + NotificationContent::Type outContentType = NotificationContent::Type::NONE; + NotificationConstant::SlotType outSlotType = NotificationConstant::SlotType::OTHER; + std::vector extraInfoKeys; + // contentType: notificationManager.ContentType; + if (!GetCheckRequestContent(env, obj, outContentType)) { + ANS_LOGE("GetCheckRequestContent faild."); + return false; + } + checkRequest->SetContentType(outContentType); + // slotType: notificationManager.SlotType; + if (!GetCheckRequestSlotType(env, obj, outSlotType)) { + ANS_LOGE("GetCheckRequestSlotType faild."); + return false; + } + checkRequest->SetSlotType(outSlotType); + // extraInfoKeys: Array; + if (ANI_OK != (status = env->Object_GetPropertyByName_Ref(obj, "extraInfoKeys", &extraInfoKeysObj))) { + ANS_LOGE("UnWarpNotificationCheckRequest get extraInfoKeys faild. status %{public}d", status); + return false; + } + if (!GetStringArrayByAniObj(env, static_cast(extraInfoKeysObj), extraInfoKeys)) { + ANS_LOGE("UnWarpNotificationCheckRequest. extraInfoKeys GetStringArrayByAniObj faild."); + return false; + } + checkRequest->SetExtraKeys(extraInfoKeys); + ANS_LOGD("contentType %{public}d slotType %{public}d", + checkRequest->GetContentType(), checkRequest->GetSlotType()); + for (auto &it : checkRequest->GetExtraKeys()) { + ANS_LOGD("extrakey %{public}s", it.c_str()); + } + return true; +} + +bool UnWarpNotificationFilter(ani_env *env, ani_object obj, LiveViewFilter& filter) +{ + ANS_LOGD("UnWarpNotificationFilter call"); + if (env == nullptr || obj == nullptr) { + ANS_LOGE("UnWarpNotificationFilter failed, has nullptr"); + return false; + } + + ani_status status = ANI_OK; + ani_boolean isUndefined = ANI_TRUE; + ani_ref bundleObj = {}; + if (ANI_OK != (status = GetPropertyRef(env, obj, "bundle", isUndefined, bundleObj)) + || isUndefined == ANI_TRUE) { + ANS_LOGE("UnWarpNotificationFilter:get bundle failed. status %{public}d", status); + return false; + } + if (!OHOS::NotificationSts::UnwrapBundleOption(env, static_cast(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_slot.cpp b/frameworks/ets/ani/src/sts_slot.cpp index 69bd7e210ee55608dfbb5fdb9e89b005dc9ad1ee..88af70b02bbc72c1645d8a28f39728aa6b152bba 100644 --- a/frameworks/ets/ani/src/sts_slot.cpp +++ b/frameworks/ets/ani/src/sts_slot.cpp @@ -21,18 +21,31 @@ namespace OHOS { namespace NotificationSts { -bool CheckOptionalFieldSlotTypeParam(const ani_env *env, const ani_class cls, const ani_object &object) +bool SetOptionalFieldSlotLevel( + ani_env *env, const ani_class cls, ani_object &object, const std::string fieldName, const SlotLevel value) { - if (env == nullptr) { - ANS_LOGE("env is null"); + ANS_LOGD("SetOptionalFieldSlotLevel call"); + if (env == nullptr || cls == nullptr || object == nullptr) { + ANS_LOGE("SetOptionalFieldSlotLevel failed, has nullptr"); return false; } - if (cls == nullptr) { - ANS_LOGE("cls is null"); + ani_field field = nullptr; + ani_status status = env->Class_FindField(cls, fieldName.c_str(), &field); + if (status != ANI_OK || field == nullptr) { + ANS_LOGE("Class_FindField failed or null field, status=%{public}d, fieldName=%{public}s", + status, fieldName.c_str()); return false; } - if (object == nullptr) { - ANS_LOGE("object is null"); + ani_enum_item enumItem = nullptr; + NotificationSts::SlotLevelCToEts(env, value, enumItem); + if (enumItem == nullptr) { + ANS_LOGE("null enumItem"); + return false; + } + status = env->Object_SetField_Ref(object, field, enumItem); + if (status != ANI_OK) { + ANS_LOGE("Object_SetField_Ref failed, status=%{public}d, fieldName=%{public}s", + status, fieldName.c_str()); return false; } return true; @@ -41,9 +54,9 @@ bool CheckOptionalFieldSlotTypeParam(const ani_env *env, const ani_class cls, co bool SetOptionalFieldSlotType( ani_env *env, const ani_class cls, ani_object &object, const std::string fieldName, const SlotType value) { - ANS_LOGD("WrapNotificationSlot call"); - if (!CheckOptionalFieldSlotTypeParam(env, cls, object)) { - ANS_LOGE("WrapNotificationSlot failed, has nullptr"); + ANS_LOGD("SetOptionalFieldSlotType call"); + if (env == nullptr || cls == nullptr || object == nullptr) { + ANS_LOGE("SetOptionalFieldSlotType failed, has nullptr"); return false; } ani_field field = nullptr; @@ -141,10 +154,19 @@ bool WrapNotificationSlot(ani_env *env, sptr slo ANS_LOGE("CreateClassObjByClassName fail"); return false; } + if (cls == nullptr || outAniObj == nullptr) { + ANS_LOGE("Create class failed"); + return false; + } + if (!SetOptionalFieldSlotType(env, cls, outAniObj, "notificationType", slot->GetType())) { ANS_LOGE("Set notificationType fail"); return false; } + if (!SetOptionalFieldSlotLevel(env, cls, outAniObj, "notificationLevel", slot->GetLevel())) { + ANS_LOGE("Set notificationLevel fail"); + return false; + } if (!WrapNotificationSlotByBoolean(env, slot, outAniObj)) { ANS_LOGE("set Boolean params fail"); return false; @@ -157,41 +179,11 @@ bool WrapNotificationSlot(ani_env *env, sptr slo ANS_LOGE("set String params fail"); return false; } - if (slot->GetVibrationStyle().size() != 0 - && !SetOptionalFieldArrayDouble(env, cls, outAniObj, "vibrationValues", slot->GetVibrationStyle())) { - ANS_LOGE("Set vibrationValues fail"); - return false; - } - ANS_LOGD("WrapNotificationSlot end"); - return true; -} - -bool SetOptionalFieldSlotLevel(ani_env *env, const ani_class cls, ani_object &object, const std::string fieldName, - const SlotLevel value) -{ - ANS_LOGD("SetOptionalFieldSlotLevel call"); - if (env == nullptr) { - ANS_LOGE("SetOptionalFieldSlotLevel failed, env is nullptr"); - return false; - } - ani_field field = nullptr; - ani_status status = env->Class_FindField(cls, fieldName.c_str(), &field); - if (status != ANI_OK || field == nullptr) { - ANS_LOGE("Class_FindField failed or null field, status=%{public}d, fieldName=%{public}s", - status, fieldName.c_str()); - return false; - } - ani_enum_item enumItem = nullptr; - if (!NotificationSts::SlotLevelCToEts(env, value, enumItem) || enumItem == nullptr) { - ANS_LOGE("get enumItem failed"); - return false; - } - status = env->Object_SetField_Ref(object, field, enumItem); - if (status != ANI_OK) { - ANS_LOGE("Object_SetField_Ref failed, status=%{public}d, fieldName=%{public}s", - status, fieldName.c_str()); + if (!SetOptionalFieldArrayDouble(env, cls, outAniObj, "vibrationValues", slot->GetVibrationStyle())) { + ANS_LOGE("Set vibrationValues fail"); return false; } + ANS_LOGD("WrapNotificationSlot end"); return true; } @@ -199,10 +191,6 @@ bool WrapNotificationSlotArray(ani_env *env, const std::vector(doubleValue))); + } + if (GetPropertyDouble(env, notificationSlotObj, "lightColor", isUndefined, doubleValue) == ANI_OK + && isUndefined == ANI_FALSE) { + slot.SetLedLightColor(static_cast(doubleValue)); + } + bool boolValue = true; + if (GetPropertyBool(env, notificationSlotObj, "badgeFlag", isUndefined, boolValue) == ANI_OK + && isUndefined == ANI_FALSE) { + slot.EnableBadge(boolValue); + } + if (GetPropertyBool(env, notificationSlotObj, "bypassDnd", isUndefined, boolValue) == ANI_OK + && isUndefined == ANI_FALSE) { + slot.EnableBypassDnd(boolValue); + } + if (GetPropertyBool(env, notificationSlotObj, "lightEnabled", isUndefined, boolValue) == ANI_OK + && isUndefined == ANI_FALSE) { + slot.SetEnableLight(boolValue); + } + if (GetPropertyBool(env, notificationSlotObj, "vibrationEnabled", isUndefined, boolValue) == ANI_OK + && isUndefined == ANI_FALSE) { + slot.SetEnableVibration(boolValue); + } + return true; +} + +bool UnwrapNotificationSlot(ani_env *env, ani_object notificationSlotObj, NotificationSlot &slot) +{ + ANS_LOGD("UnwrapNotificationSlot enter"); + if (notificationSlotObj == nullptr) { + ANS_LOGE("notificationSlotObj is null"); + return false; + } + ani_status status = ANI_ERROR; + ani_boolean isUndefined = ANI_TRUE; + ani_ref notificationTypeRef = {}; + status = GetPropertyRef(env, notificationSlotObj, "notificationType", isUndefined, notificationTypeRef); + if (status == ANI_OK && isUndefined == ANI_FALSE) { + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType::OTHER; + if (SlotTypeEtsToC(env, static_cast(notificationTypeRef), slotType)) { + slot.SetType(slotType); + } + } + status = GetPropertyRef(env, notificationSlotObj, "notificationLevel", isUndefined, notificationTypeRef); + if (status == ANI_OK && isUndefined == ANI_FALSE) { + NotificationSlot::NotificationLevel outLevel {NotificationSlot::NotificationLevel::LEVEL_NONE}; + if (SlotLevelEtsToC(env, static_cast(notificationTypeRef), outLevel)) { + slot.SetLevel(outLevel); + } + } + if (!ParseNotificationSlotByBasicType(env, notificationSlotObj, slot)) { + ANS_LOGE("ParseNotificationSlotByBasicType failed"); + return false; + } + std::vector vibrationValues; + if (GetPropertyNumberArray(env, notificationSlotObj, "vibrationValues", isUndefined, vibrationValues) == ANI_OK && + isUndefined == ANI_FALSE) { + slot.SetVibrationStyle(vibrationValues); + } + ANS_LOGD("UnwrapNotificationSlot leave"); + return true; +} + +bool UnwrapNotificationSlotArrayByAniObj(ani_env *env, ani_object notificationSlotArrayObj, + std::vector &slots) +{ + ANS_LOGD("UnwrapNotificationSlotArrayByAniObj enter"); + if (notificationSlotArrayObj == nullptr) { + ANS_LOGE("notificationSlotArrayObj is null"); + return false; + } + ani_double length; + ani_status status = env->Object_GetPropertyByName_Double(notificationSlotArrayObj, "length", &length); + if (status != ANI_OK) { + ANS_LOGE("Object_GetPropertyByName_Double faild. status : %{public}d", status); + return false; + } + for (int i = 0; i < int(length); i++) { + ani_ref notificationSlotEntryRef; + status = env->Object_CallMethodByName_Ref(notificationSlotArrayObj, + "$_get", "I:Lstd/core/Object;", ¬ificationSlotEntryRef, (ani_int)i); + if (status != ANI_OK) { + ANS_LOGE("Object_CallMethodByName_Ref faild. status : %{public}d", status); + } + NotificationSlot slot; + if (!UnwrapNotificationSlot(env, static_cast(notificationSlotEntryRef), slot)) { + ANS_LOGE("UnwrapNotificationSlot faild"); + return false; + } + slots.emplace_back(slot); + } + ANS_LOGD("UnwrapNotificationSlotArrayByAniObj leave"); + return true; +} } // namespace NotificationSts } // OHOS diff --git a/frameworks/ets/ani/src/sts_subscribe.cpp b/frameworks/ets/ani/src/sts_subscribe.cpp index 11f2dd82c54a9897ad67b6c8f62a790e883657b8..5d6797b4a22e45b6807c336c76b6ccbbfc08fc76 100644 --- a/frameworks/ets/ani/src/sts_subscribe.cpp +++ b/frameworks/ets/ani/src/sts_subscribe.cpp @@ -15,7 +15,6 @@ #include "sts_subscribe.h" #include "ans_log_wrapper.h" -#include "inner_errors.h" #include "notification_helper.h" #include "sts_throw_erro.h" #include "sts_common.h" @@ -63,9 +62,8 @@ void StsDistributedOperationCallback::OnStsOperationCallback(ani_env *env, const return; } ani_status status = ANI_OK; - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(operationResult); - externalErrorCode = - (externalErrorCode == CJSystemapi::Notification::SUCCESS_CODE) ? operationResult : externalErrorCode; + int32_t externalErrorCode = GetExternalCode(operationResult); + externalErrorCode = (externalErrorCode == ERR_OK) ? operationResult : externalErrorCode; ANS_LOGD("operationResult %{public}d, externalCode %{public}d", operationResult, externalErrorCode); if (externalErrorCode == 0) { @@ -481,9 +479,9 @@ bool StsSubscriberInstance::CallFunction(ani_env *env, const char *func, std::ve ANS_LOGD("enter"); if (env == nullptr) return false; ani_ref fn_ref; - ani_status aniResult = env->Object_GetFieldByName_Ref(static_cast(ref_), func, &fn_ref); + ani_status aniResult = env->Object_GetPropertyByName_Ref(static_cast(ref_), func, &fn_ref); if (ANI_OK != aniResult) { - ANS_LOGD("Object_GetFieldByName_Ref '%{public}s' error. result: %{public}d.", func, aniResult); + ANS_LOGD("Object_GetPropertyByName_Ref '%{public}s' error. result: %{public}d.", func, aniResult); return false; } ani_boolean IsUndefined = ANI_FALSE; @@ -609,16 +607,15 @@ bool SubscriberInstanceManager::Subscribe(ani_env *env, ani_object subscriber, a return false; } } - ErrCode status = 0; + ErrCode status = ERR_OK; if (!isInfoUndefine) { status = NotificationHelper::SubscribeNotification(stsSubscriber, SubscribeInfo); } else { status = NotificationHelper::SubscribeNotification(stsSubscriber); } - if (status != 0) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(status); - externalErrorCode = - (externalErrorCode == CJSystemapi::Notification::SUCCESS_CODE) ? status : externalErrorCode; + if (status != ERR_OK) { + int32_t externalErrorCode = GetExternalCode(status); + externalErrorCode = (externalErrorCode == ERR_OK) ? status : externalErrorCode; ANS_LOGD("SubscribeNotification faild. status %{public}d ErrorToExternal %{public}d", status, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); @@ -647,10 +644,9 @@ bool SubscriberInstanceManager::UnSubscribe(ani_env *env, ani_object subscriber) bool ret = AddDeletingSubscriber(stsSubscriber); if (ret) { int32_t status = NotificationHelper::UnSubscribeNotification(stsSubscriber); - if (status != 0) { - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(status); - externalErrorCode = - (externalErrorCode == CJSystemapi::Notification::SUCCESS_CODE) ? status : externalErrorCode; + if (status != ERR_OK) { + int32_t externalErrorCode = GetExternalCode(status); + externalErrorCode = (externalErrorCode == ERR_OK) ? status : externalErrorCode; ANS_LOGD("UnSubscribe faild. status %{public}d ErrorToExternal %{public}d", status, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); @@ -665,6 +661,42 @@ bool SubscriberInstanceManager::UnSubscribe(ani_env *env, ani_object subscriber) return true; } +bool SubscriberInstanceManager::SubscribeSelf(ani_env *env, ani_object subscriber) +{ + ANS_LOGD("enter"); + bool isSubscribeUndefine = IsUndefine(env, subscriber); + if (isSubscribeUndefine) { + ANS_LOGD("subscriber is undefine"); + OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, "subscriber is undefine"); + return false; + } + std::shared_ptr stsSubscriber = nullptr; + if (!HasNotificationSubscriber(env, subscriber, stsSubscriber)) { + if (!GetNotificationSubscriber(env, subscriber, stsSubscriber)) { + ANS_LOGD("GetNotificationSubscriber faild"); + OHOS::AbilityRuntime::ThrowStsError(env, ERROR_INTERNAL_ERROR, "GetNotificationSubscriber faild"); + return false; + } + if (!AddSubscriberInstancesInfo(env, stsSubscriber)) { + ANS_LOGD("AddSubscriberInstancesInfo faild"); + OHOS::AbilityRuntime::ThrowStsError(env, ERROR_INTERNAL_ERROR, "GetNotificationSubscriber faild"); + return false; + } + } + ErrCode status = ERR_OK; + status = NotificationHelper::SubscribeNotificationSelf(stsSubscriber); + if (status != ERR_OK) { + int32_t externalErrorCode = GetExternalCode(status); + externalErrorCode = (externalErrorCode == ERR_OK) ? 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) { @@ -723,7 +755,7 @@ bool UnWarpNotificationKey(ani_env *env, const ani_object obj, NotificationKey & ANS_LOGD("UnWarpNotificationKey GetPropertyString label fail"); return false; } - OutObj.label = label; + OutObj.label = GetResizeStr(label, STR_MAX_SIZE); ANS_LOGD("UnWarpNotificationKey id: %{public}d, label: %{public}s", OutObj.id, OutObj.label.c_str()); return true; } @@ -737,14 +769,12 @@ bool UnwarpOperationInfo(ani_env *env, const ani_object obj, StsNotificationOper ANS_LOGD("ConvertOperationInfoToNative GetStringOrUndefined actionName fail"); return false; } - outObj.SetActionName(actionName); + outObj.SetActionName(GetResizeStr(actionName, STR_MAX_SIZE)); if (GetPropertyString(env, obj, "userInput", isUndefined, userInput) != ANI_OK || isUndefined == ANI_TRUE) { ANS_LOGD("ConvertOperationInfoToNative GetStringOrUndefined userInput fail"); return false; } - outObj.SetUserInput(actionName); - ANS_LOGD("ConvertOperationInfoToNative actionName: %{public}s, userInput: %{public}s", - outObj.GetActionName().c_str(), outObj.GetUserInput().c_str()); + outObj.SetUserInput(GetResizeStr(userInput, LONG_STR_MAX_SIZE)); return true; } diff --git a/frameworks/ets/ani/src/sts_subscribe_info.cpp b/frameworks/ets/ani/src/sts_subscribe_info.cpp index 4b5c4a891b9274af120fa3b13f583db05de47ebb..9b1dd67a2bf394892a16df2d4362ac22b616e7df 100644 --- a/frameworks/ets/ani/src/sts_subscribe_info.cpp +++ b/frameworks/ets/ani/src/sts_subscribe_info.cpp @@ -26,7 +26,7 @@ bool UnwarpNotificationSubscribeInfo(ani_env *env, ani_object value, Notificatio ANS_LOGE("invalid parameter value"); return false; } - std::vector res; + std::vector res = {}; ani_double userId = 0.0; ani_double filterLimit = 0.0; std::string deviceType; @@ -36,6 +36,10 @@ bool UnwarpNotificationSubscribeInfo(ani_env *env, ani_object value, Notificatio || res.empty()) { ANS_LOGE("UnWarpStringArrayOrUndefinedByProperty faild"); } + std::vector bundleNames = {}; + for (auto bundleName : res) { + bundleNames.emplace_back(GetResizeStr(bundleName, STR_MAX_SIZE)); + } if (ANI_OK != GetPropertyDouble(env, value, "userId", isUndefined, userId) || isUndefined == ANI_TRUE) { ANS_LOGE("GetDoubleOrUndefined faild"); } @@ -45,10 +49,10 @@ bool UnwarpNotificationSubscribeInfo(ani_env *env, ani_object value, Notificatio if (ANI_OK != GetPropertyDouble(env, value, "filterLimit", isUndefined, filterLimit) || isUndefined == ANI_TRUE) { ANS_LOGE("GetDoubleOrUndefined faild"); } - info.AddAppNames(res); + info.AddAppNames(bundleNames); info.AddAppUserId(static_cast(userId)); info.SetFilterType(static_cast(filterLimit)); - info.AddDeviceType(deviceType); + info.AddDeviceType(GetResizeStr(deviceType, STR_MAX_SIZE)); ANS_LOGD("userId %{public}d deviceType %{public}s filterLimit %{public}d", info.GetAppUserId(), info.GetDeviceType().c_str(), info.GetFilterType()); return true; diff --git a/frameworks/ets/ani/src/sts_user_input.cpp b/frameworks/ets/ani/src/sts_user_input.cpp index 1c56a0c669aadef44f1ae3488b6b6c9726e4ef38..5868a70459f7ac7fe9d6d524b30a8557559c165a 100644 --- a/frameworks/ets/ani/src/sts_user_input.cpp +++ b/frameworks/ets/ani/src/sts_user_input.cpp @@ -33,7 +33,7 @@ ani_status UnwrapNotificationUserInput(ani_env *env, ani_object param, ANS_LOGE("GetPropertyString 'inputKey' faild"); return ANI_INVALID_ARGS; } - userInput = Notification::NotificationUserInput::Create(inputKey); + userInput = Notification::NotificationUserInput::Create(GetResizeStr(inputKey, STR_MAX_SIZE)); return status; } diff --git a/frameworks/ets/ani/src/subscribe/ani_remove.cpp b/frameworks/ets/ani/src/subscribe/ani_remove.cpp index 7f04ae1091d5e27e4efb9353cb2dfcaf6b4df557..b73c1b74466929a950a6a2fe84bbe8ae674f4900 100644 --- a/frameworks/ets/ani/src/subscribe/ani_remove.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_remove.cpp @@ -14,7 +14,6 @@ */ #include "ani_remove.h" -#include "inner_errors.h" #include "notification_helper.h" #include "ans_log_wrapper.h" #include "sts_throw_erro.h" @@ -35,19 +34,19 @@ void AniRemoveForBundle(ani_env *env, ani_object bundle, ani_object notification int32_t reasonType = 0; if (!NotificationSts::UnwrapBundleOption(env, bundle, option)) { ANS_LOGE("bundle is valid"); - std::string msg = "UnwrapBundleOption faild"; + std::string msg = "UnwrapBundleOption failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } if (!NotificationSts::UnWarpNotificationKey(env, notificationKey, key)) { ANS_LOGE("notificationKey is valid"); - std::string msg = "UnWarpNotificationKey faild"; + std::string msg = "UnWarpNotificationKey failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); - std::string msg = "UnWarpReasonEnum faild"; + std::string msg = "UnWarpReasonEnum failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } @@ -58,9 +57,9 @@ void AniRemoveForBundle(ani_env *env, ani_object bundle, ani_object notification return; } int ret = NotificationHelper::RemoveNotification(option, key.id, key.label, reasonType); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } @@ -70,16 +69,17 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn { ANS_LOGD("AniRemoveForHashCode enter"); int32_t reasonType = -1; - std::string hashCodeStd; - if (ANI_OK != NotificationSts::GetStringByAniString(env, hashCode, hashCodeStd)) { + std::string tempStr; + if (ANI_OK != NotificationSts::GetStringByAniString(env, hashCode, tempStr)) { ANS_LOGE("hashCode is valid"); std::string msg = "hashCode is valid"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } + std::string hashCodeStd = NotificationSts::GetResizeStr(tempStr, NotificationSts::STR_MAX_SIZE); if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); - std::string msg = "UnWarpReasonEnum faild"; + std::string msg = "UnWarpReasonEnum failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } @@ -91,9 +91,9 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn } ANS_LOGD("hashCode: %{public}s, reasonType: %{public}d", hashCodeStd.c_str(), reasonType); int ret = NotificationHelper::RemoveNotification(hashCodeStd, reasonType); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForHashCode ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); + ANS_LOGD("StsRemoveForHashCode ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } @@ -102,17 +102,21 @@ void AniRemoveForHashCode(ani_env *env, ani_string hashCode, ani_object reasonEn void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reasonEnum) { ANS_LOGD("StsRemoveForHashCodes enter"); - std::vector hashCodesStd; + std::vector hashCodesTemp = {}; int32_t reasonType; - if (ANI_OK != NotificationSts::GetStringArrayByAniObj(env, hashCodes, hashCodesStd)) { + if (!NotificationSts::GetStringArrayByAniObj(env, hashCodes, hashCodesTemp)) { ANS_LOGE("hashCodes is valid"); std::string msg = "hashCodes is valid"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } + std::vector hashCodesStd = {}; + for (auto hashcode : hashCodesStd) { + hashCodesStd.emplace_back(NotificationSts::GetResizeStr(hashcode, NotificationSts::STR_MAX_SIZE)); + } if (!NotificationSts::UnWarpReasonEnum(env, reasonEnum, reasonType)) { ANS_LOGE("enum convert failed"); - std::string msg = "UnWarpReasonEnum faild"; + std::string msg = "UnWarpReasonEnum failed"; OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); return; } @@ -123,9 +127,52 @@ void AniRemoveForHashCodes(ani_env *env, ani_object hashCodes, ani_object reason return; } int ret = NotificationHelper::RemoveNotifications(hashCodesStd, reasonType); - int32_t externalErrorCode = CJSystemapi::Notification::ErrorToExternal(ret); - ANS_LOGD("StsRemoveForHashCodes ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); if (ret != ERR_OK) { + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); + ANS_LOGD("StsRemoveForHashCodes ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); + std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); + } +} + +void AniRemoveAll(ani_env *env) +{ + ANS_LOGD("removeAll enter"); + int ret = NotificationHelper::RemoveNotifications(); + if (ret != ERR_OK) { + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); + ANS_LOGD("AniRemoveAll ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); + std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); + } +} + +void AniRemoveAllForBundle(ani_env *env, ani_object bundle) +{ + ANS_LOGD("AniRemoveAllForBundle enter"); + BundleOption option; + if (!NotificationSts::UnwrapBundleOption(env, bundle, option)) { + ANS_LOGE("bundle is valid"); + std::string msg = "UnwrapBundleOption failed"; + OHOS::AbilityRuntime::ThrowStsError(env, ERROR_PARAM_INVALID, msg); + return; + } + int ret = NotificationHelper::RemoveAllNotifications(option); + if (ret != ERR_OK) { + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); + std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); + OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); + } +} + +void AniRemoveAllForUserId(ani_env *env, ani_double userId) +{ + ANS_LOGD("AniRemoveAllForUserId enter"); + int ret = NotificationHelper::RemoveNotifications(userId); + if (ret != ERR_OK) { + int32_t externalErrorCode = NotificationSts::GetExternalCode(ret); + ANS_LOGD("StsRemoveForBundle ret %{public}d. ErrorToExternal %{public}d", ret, externalErrorCode); std::string msg = OHOS::NotificationSts::FindAnsErrMsg(externalErrorCode); OHOS::AbilityRuntime::ThrowStsError(env, externalErrorCode, msg); } diff --git a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp index 03f5caef50e9d191218e4c5b9aabc725d0234386..aa4939ad745e41b6babd00b9dbcd0dd250515e59 100644 --- a/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp +++ b/frameworks/ets/ani/src/subscribe/ani_subscribe.cpp @@ -16,11 +16,11 @@ #include #include -#include "inner_errors.h" #include "notification_helper.h" #include "ani_remove.h" #include "ans_log_wrapper.h" #include "sts_subscribe.h" +#include "sts_throw_erro.h" namespace OHOS { namespace NotificationSubScribeSts { @@ -39,6 +39,10 @@ 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"; +static const char *REMOVEALL_SIGNATURE = ":V"; ani_object AniDistributeOperation(ani_env *env, ani_string hashcode, ani_object operationInfo) { @@ -46,7 +50,7 @@ ani_object AniDistributeOperation(ani_env *env, ani_string hashcode, ani_object ani_object aniPromise {}; ani_resolver aniResolver {}; if (ANI_OK != env->Promise_New(&aniResolver, &aniPromise)) { - ANS_LOGD("Promise_New faild"); + ANS_LOGE("Promise_New faild"); return nullptr; } bool noWithOperationInfo = false; @@ -71,7 +75,7 @@ ani_object AniDistributeOperation(ani_env *env, ani_string hashcode, ani_object callback->SetVm(vm); int32_t result = Notification::NotificationHelper::DistributeOperation(info, callback); ANS_LOGD("StsDistributeOperation ret %{public}d. ErrorToExternal %{public}d", - result, CJSystemapi::Notification::ErrorToExternal(result)); + result, NotificationSts::GetExternalCode(result)); if (result != ERR_OK || noWithOperationInfo) { callback->OnStsOperationCallback(env, result); } @@ -90,6 +94,12 @@ void AniUnSubscribe(ani_env *env, ani_object obj) OHOS::NotificationSts::SubscriberInstanceManager::GetInstance()->UnSubscribe(env, obj); } +void AniSubscribeSelf(ani_env *env, ani_object obj) +{ + ANS_LOGD("StsSubscribeSelf enter"); + OHOS::NotificationSts::SubscriberInstanceManager::GetInstance()->SubscribeSelf(env, obj); +} + void AniSubScribeRegistryInit(ani_env *env) { ANS_LOGD("AniSubScribeRegistryInit call"); @@ -101,7 +111,8 @@ void AniSubScribeRegistryInit(ani_env *env) } std::array methods = { - ani_native_function {"nativeRemove", REMOVE_FOR_BUNDLE_SIGNATURE, reinterpret_cast(AniRemoveForBundle)}, + ani_native_function {"nativeRemove", + REMOVE_FOR_BUNDLE_SIGNATURE, reinterpret_cast(AniRemoveForBundle)}, ani_native_function {"nativeRemove", REMOVE_FOR_HASHCODE_SIGNATURE, reinterpret_cast(AniRemoveForHashCode)}, ani_native_function {"nativeRemove", @@ -110,6 +121,12 @@ 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)}, + ani_native_function {"nativeRemoveAll", REMOVEALL_SIGNATURE, reinterpret_cast(AniRemoveAll)}, }; 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 999fa9b11c237c3ef3ae41cfa6fe072d1826c208..28d9704539abf460512e510f9f8a6c5c0bc0a526 100644 --- a/frameworks/ets/ets/@ohos.notificationManager.ets +++ b/frameworks/ets/ets/@ohos.notificationManager.ets @@ -16,7 +16,7 @@ import { BundleOption } from 'notification.NotificationCommonDef'; import { BusinessError, AsyncCallback } from '@ohos.base'; import { NotificationSlot } from 'notification.notificationSlot'; -import { NotificationRequest } from 'notification.notificationRequest'; +import { NotificationRequest, NotificationCheckRequest } from 'notification.notificationRequest'; import UIAbilityContext from 'application.UIAbilityContext'; import { NotificationBasicContent } from 'notification.notificationContent'; import { NotificationLongTextContent } from 'notification.notificationContent'; @@ -27,10 +27,13 @@ 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; -type RejectCallback = (err: Object) => void; +type RejectCallback = (err: Error) => void; +type CallbackForCheckInfo = + (checkInfo: notificationManager.NotificationCheckInfo)=> notificationManager.NotificationCheckResult; const ERROR_OK = 0; const ERROR_PARAM_INVALID = 401; @@ -120,6 +123,13 @@ export default namespace notificationManager { onResponse?: (notificationId: number, buttonOptions: ButtonOptions) => void; } + export enum DeviceRemindType { + IDLE_DONOT_REMIND = 0, + IDLE_REMIND = 1, + ACTIVE_DONOT_REMIND = 2, + ACTIVE_REMIND = 3, + } + export native function nativeCancelAll(): void; export native function nativeCancelWithId(id: number): void; export native function nativeCancelWithIdLabel(id: number, label: string): void; @@ -128,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; @@ -158,25 +171,106 @@ 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; - function isInvalidParameter(bundle: BundleOption): BusinessError + export native function nativeRemoveGroupByBundle(bundle: BundleOption, groupName: string): void; + + export native function nativeAddSlotByNotificationSlot(slot: NotificationSlot): void; + export native function nativeAddSlotBySlotType(type: SlotType): void; + export native function nativeAddSlots(slots: Array): void; + export native function nativeGetSlot(slotType: SlotType): NotificationSlot; + export native function nativeGetSlots(): Array; + export native function nativeRemoveSlot(slotType: SlotType): void; + export native function nativeRemoveAllSlots(): void; + export native function nativeSetSlotByBundle(bundle: BundleOption, slot: NotificationSlot): void; + export native function nativeGetSlotNumByBundle(bundle: BundleOption): number; + export native function nativeIsSupportTemplate(templateName: string): boolean; + export native function nativeSetDistributedEnable(enable: boolean): void; + export native function nativeIsDistributedEnabled(): boolean; + export native function nativeIsDistributedEnabledByBundle(bundle: BundleOption): boolean; + export native function nativeIsDistributedEnabledByBundleType(bundle: BundleOption, deviceType: string): boolean; + export native function nativeGetDeviceRemindType(): DeviceRemindType; + export native function nativeSetSyncNotificationEnabledWithoutApp(userId: number, enable: boolean): void; + export native function nativeGetSyncNotificationEnabledWithoutApp(userId: number): boolean; + + export native function 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 = { - code: 0, - message: "" + let error: BusinessError = successCallbackError + if (doNotDisturbDate == null) { + error = errorParamInvalid + return error; } - if (bundle == null) { - error = { - code: 401, - message: "BundleOption must be not Null" + return error; + } + + function isInvalidParameter(slot: NotificationSlot): BusinessError + { + if (slot == null) { + return errorParamInvalid; + } + if (slot.lockscreenVisibility !== undefined && typeof slot.lockscreenVisibility === 'number') { + const num = slot.lockscreenVisibility ?? -1; + if (num < 0) { + return errorParamInvalid; + } + } + if (slot.lightColor !== undefined && typeof slot.lightColor === 'number') { + const num = slot.lightColor ?? -1; + if (num < 0) { + return errorParamInvalid; } + } + if (slot.desc !== undefined && slot.desc?.trim() === '') { + return errorParamInvalid; + } + if (slot.sound !== undefined && slot.sound?.trim() === '') { + return errorParamInvalid; + } + if (slot.vibrationValues !== undefined && slot.vibrationValues?.length === 0) { + return errorParamInvalid; + } + return successCallbackError; + } + + export native function nativeOn( + type: 'checkNotification', callback: CallbackForCheckInfo, checkRequest?: NotificationCheckRequest): int; + export native function nativeOff( + type: 'checkNotification', callback?: CallbackForCheckInfo): int; + + function isInvalidParameter(bundle: BundleOption): BusinessError + { + let error: BusinessError = successCallbackError + if (bundle == 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; @@ -184,226 +278,283 @@ 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 { if (normal === null) { - return false; - } - if (!normal?.title || normal?.title?.trim() === '') { - return false; - } - if (!normal?.text || normal?.text?.trim() === '') { - return false; - } - if (normal?.additionalText !== undefined && normal?.additionalText?.trim() === '') { - return false; - } - if (normal?.lockscreenPicture != undefined && !(normal?.lockscreenPicture instanceof image.PixelMap)) { - return false; - } - + return false; + } + if (!normal?.title || normal?.title?.trim() === '') { + return false; + } + if (!normal?.text || normal?.text?.trim() === '') { + return false; + } + if (normal?.additionalText !== undefined && normal?.additionalText?.trim() === '') { + return false; + } + if (normal?.lockscreenPicture != undefined && !(normal?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } return true; } function isInvalidLongText(longText?: NotificationLongTextContent): boolean { if (longText === null) { - return false; - } - if (!longText?.longText || longText?.longText?.trim() === '') { - return false; - } - if (!longText?.briefText || longText?.briefText?.trim() === '') { - return false; - } - if (!longText?.expandedTitle || longText?.expandedTitle?.trim() === '') { - return false; - } + return false; + } + if (!longText?.title || longText?.title?.trim() === '') { + return false; + } + if (!longText?.text || longText?.text?.trim() === '') { + return false; + } + if (longText?.additionalText !== undefined && longText?.additionalText?.trim() === '') { + return false; + } + if (longText?.lockscreenPicture != undefined && !(longText?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } + if (!longText?.longText || longText?.longText?.trim() === '') { + return false; + } + if (!longText?.briefText || longText?.briefText?.trim() === '') { + return false; + } + if (!longText?.expandedTitle || longText?.expandedTitle?.trim() === '') { + return false; + } return true; } function isInvalidMultiLine(multiLine?: NotificationMultiLineContent): boolean { if (multiLine === null) { - return false - } - if (!multiLine?.briefText || multiLine?.briefText.trim() === '') { - return false; - } - if (!multiLine?.longTitle || multiLine?.longTitle.trim() === '') { - return false; - } - if (multiLine?.lines?.length === 0) { - return false; - } - + return false + } + if (!multiLine?.title || multiLine?.title?.trim() === '') { + return false; + } + if (!multiLine?.text || multiLine?.text?.trim() === '') { + return false; + } + if (multiLine?.additionalText !== undefined && multiLine?.additionalText?.trim() === '') { + return false; + } + if (multiLine?.lockscreenPicture != undefined && !(multiLine?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } + if (!multiLine?.briefText || multiLine?.briefText.trim() === '') { + return false; + } + if (!multiLine?.longTitle || multiLine?.longTitle.trim() === '') { + return false; + } + if (multiLine?.lines?.length === 0) { + return false; + } return true; } function isInvalidPicture(picture?: NotificationPictureContent): boolean { if (picture === null) { - return false; - } - if (!picture?.briefText || picture?.briefText?.trim() === '') { - return false; - } - if (!picture?.expandedTitle || picture?.expandedTitle?.trim() === '') { - return false; - } - if (!(picture?.picture instanceof image.PixelMap)) { - return false; - } + return false; + } + if (!picture?.title || picture?.title?.trim() === '') { + return false; + } + if (!picture?.text || picture?.text?.trim() === '') { + return false; + } + if (picture?.additionalText !== undefined && picture?.additionalText?.trim() === '') { + return false; + } + if (picture?.lockscreenPicture != undefined && !(picture?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } + if (!picture?.briefText || picture?.briefText?.trim() === '') { + return false; + } + if (!picture?.expandedTitle || picture?.expandedTitle?.trim() === '') { + return false; + } + if (!(picture?.picture instanceof image.PixelMap)) { + return false; + } return true; } function isInvalidSystemLiveView(systemLiveView?: NotificationSystemLiveViewContent): boolean { if (systemLiveView === null) { - return false - } - if (systemLiveView?.capsule !== undefined && systemLiveView?.capsule === null) { - return false - } - if (systemLiveView?.capsule?.title !== undefined && systemLiveView?.capsule?.title?.trim() === '') { - return false; - } - if (systemLiveView?.capsule?.icon != undefined && !(systemLiveView?.capsule?.icon instanceof image.PixelMap)) { - return false; - } - if (systemLiveView?.capsule?.backgroundColor != undefined && systemLiveView?.capsule?.backgroundColor?.trim() === '') { - return false; - } - if (systemLiveView?.capsule?.content != undefined && systemLiveView?.capsule?.content?.trim() === '') { - return false; - } - if (systemLiveView?.capsule?.capsuleButtons != undefined && systemLiveView?.capsule?.capsuleButtons?.length === 0) { - return false; - } - if (systemLiveView?.button !== undefined && systemLiveView?.button === null) { - return false; - } - if (systemLiveView?.button?.names != undefined && systemLiveView?.button?.names?.length === 0) { - return false; - } - if (systemLiveView?.button?.icons != undefined && systemLiveView?.button?.icons?.length === 0) { - return false; - } - if (systemLiveView?.button?.iconsResource != undefined && systemLiveView?.button?.iconsResource?.length === 0) { - return false; - } - - if (systemLiveView?.cardButtons !== undefined && systemLiveView?.cardButtons?.length === 0) { - return false; - } + return false + } + if (!systemLiveView?.title || systemLiveView?.title?.trim() === '') { + return false; + } + if (!systemLiveView?.text || systemLiveView?.text?.trim() === '') { + return false; + } + if (systemLiveView?.additionalText !== undefined && systemLiveView?.additionalText?.trim() === '') { + return false; + } + if (systemLiveView?.lockscreenPicture != undefined && !(systemLiveView?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } + if (systemLiveView?.capsule !== undefined && systemLiveView?.capsule === null) { + return false + } + if (systemLiveView?.capsule?.title !== undefined && systemLiveView?.capsule?.title?.trim() === '') { + return false; + } + if (systemLiveView?.capsule?.icon != undefined && !(systemLiveView?.capsule?.icon instanceof image.PixelMap)) { + return false; + } + if (systemLiveView?.capsule?.backgroundColor != undefined && systemLiveView?.capsule?.backgroundColor?.trim() === '') { + return false; + } + if (systemLiveView?.capsule?.content != undefined && systemLiveView?.capsule?.content?.trim() === '') { + return false; + } + if (systemLiveView?.capsule?.capsuleButtons != undefined && systemLiveView?.capsule?.capsuleButtons?.length === 0) { + return false; + } + if (systemLiveView?.button !== undefined && systemLiveView?.button === null) { + return false; + } + if (systemLiveView?.button?.names != undefined && systemLiveView?.button?.names?.length === 0) { + return false; + } + if (systemLiveView?.button?.icons != undefined && systemLiveView?.button?.icons?.length === 0) { + return false; + } + if (systemLiveView?.button?.iconsResource != undefined && systemLiveView?.button?.iconsResource?.length === 0) { + return false; + } + if (systemLiveView?.cardButtons !== undefined && systemLiveView?.cardButtons?.length === 0) { + return false; + } return true; } function isInvalidLiveView(liveView?: NotificationLiveViewContent): boolean { if (liveView === null) { - return false; - } - if (liveView?.extraInfo !== undefined && liveView?.extraInfo === null) { - return false; - } - if (liveView?.pictureInfo !== undefined && liveView?.pictureInfo === null) { - return false; - } + return false; + } + if (!liveView?.title || liveView?.title?.trim() === '') { + return false; + } + if (!liveView?.text || liveView?.text?.trim() === '') { + return false; + } + if (liveView?.additionalText !== undefined && liveView?.additionalText?.trim() === '') { + return false; + } + if (liveView?.lockscreenPicture != undefined && !(liveView?.lockscreenPicture instanceof image.PixelMap)) { + return false; + } + if (liveView?.extraInfo !== undefined && liveView?.extraInfo === null) { + return false; + } + if (liveView?.pictureInfo !== undefined && liveView?.pictureInfo === null) { + return false; + } return true; } function isInvalidTemplate(template?: NotificationTemplate): boolean { if (template === null) { - return false; - } - if (template?.name != undefined && template?.name?.trim() === '') { - return false; - } - if (template?.data != undefined && template?.data === null) { - return false; - } + return false; + } + if (template?.name != undefined && template?.name?.trim() === '') { + return false; + } + if (template?.data != undefined && template?.data === null) { + return false; + } return true; } function isInvalidDistributedOption(distributedOption?: DistributedOptions): boolean { if (distributedOption === null) { - return false - } - if (distributedOption?.supportDisplayDevices != undefined && distributedOption?.supportDisplayDevices?.length === 0) { - return false; - } - if (distributedOption?.supportOperateDevices != undefined && distributedOption?.supportOperateDevices?.length === 0) { - return false; - } + return false + } + if (distributedOption?.supportDisplayDevices != undefined && distributedOption?.supportDisplayDevices?.length === 0) { + return false; + } + if (distributedOption?.supportOperateDevices != undefined && distributedOption?.supportOperateDevices?.length === 0) { + return false; + } return true; } function isInvalidUnifiedGroupInfo(unifiedGroupInfo?: UnifiedGroupInfo): boolean { if (unifiedGroupInfo === null) { - return false; - } - if (unifiedGroupInfo?.key != undefined && unifiedGroupInfo?.key?.trim() === '') { - return false; - } - if (unifiedGroupInfo?.title != undefined && unifiedGroupInfo?.title?.trim() === '') { - return false; - } - if (unifiedGroupInfo?.content != undefined && unifiedGroupInfo?.content?.trim() === '') { - return false; - } - if (unifiedGroupInfo?.sceneName != undefined && unifiedGroupInfo?.sceneName?.trim() === '') { - return false; - } - if (unifiedGroupInfo?.extraInfo != undefined && unifiedGroupInfo?.extraInfo == null) { - return false; - } + return false; + } + if (unifiedGroupInfo?.key != undefined && unifiedGroupInfo?.key?.trim() === '') { + return false; + } + if (unifiedGroupInfo?.title != undefined && unifiedGroupInfo?.title?.trim() === '') { + return false; + } + if (unifiedGroupInfo?.content != undefined && unifiedGroupInfo?.content?.trim() === '') { + return false; + } + if (unifiedGroupInfo?.sceneName != undefined && unifiedGroupInfo?.sceneName?.trim() === '') { + return false; + } + if (unifiedGroupInfo?.extraInfo != undefined && unifiedGroupInfo?.extraInfo == null) { + return false; + } return true; } function isInvalidBundleOption(bundleOption?: BundleOption): boolean { if (bundleOption === null) { - return false; - } - if (bundleOption?.bundle != undefined && bundleOption?.bundle?.trim() === '') { - return false; - } + return false; + } + if (bundleOption?.bundle != undefined && bundleOption?.bundle?.trim() === '') { + return false; + } return true; } function isInvalidParameter(request: NotificationRequest): BusinessError { - 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)) { @@ -502,36 +653,34 @@ 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 => { let p = taskpool.execute((): void => { return nativeSetNotificationEnable(bundle, enable); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); return pPromise; } - + export function setNotificationEnable(bundle: BundleOption, enable: boolean, callback: AsyncCallback): void { let error: BusinessError = isInvalidParameter(bundle); - 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 => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -540,20 +689,18 @@ 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 => { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -563,7 +710,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 => { @@ -573,7 +720,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -583,18 +730,14 @@ export default namespace notificationManager { export function isNotificationEnabled(userId: number, callback: AsyncCallback): void { if (callback == null) { - let error: BusinessError = { - code: 410, - message : "callback must be not null" - } - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): boolean => { return nativeIsNotificationEnabledWithId(userId); }); p.then((data: NullishType): void => { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -608,7 +751,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -618,18 +761,14 @@ export default namespace notificationManager { export function isNotificationEnabled(callback: AsyncCallback): void { if (callback == null) { - let error: BusinessError = { - code: 410, - message : "callback must be not null" - } - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): boolean => { return nativeIsNotificationEnabled(); }); p.then((data: NullishType): void => { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -643,7 +782,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -658,13 +797,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); @@ -672,7 +809,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -682,7 +819,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; @@ -695,7 +832,7 @@ export default namespace notificationManager { }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -706,19 +843,17 @@ 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 => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) @@ -727,7 +862,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 => { @@ -735,7 +870,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -745,20 +880,18 @@ 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 => { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); @@ -768,30 +901,28 @@ 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 => { let slots : Array = data as Array; let err: BusinessError = {code: 0, data: undefined}; callback(err, slots); - }, (error: Object): void => { + }, (error: Error): void => { let slots : Array = []; let err: BusinessError = error as BusinessError; callback(err, slots); - }) + }) } - + export function getSlotsByBundle(bundle: BundleOption): Promise> { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise>( @@ -800,7 +931,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let slots : Array = data as Array; resolve(slots); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -809,14 +940,14 @@ 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 => { let p = taskpool.execute((): void => { return nativeSetSlotFlagsByBundle(bundle, slotFlags); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -825,7 +956,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 => { @@ -833,7 +964,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : Double = data as Double; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -842,19 +973,17 @@ 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 => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }); @@ -862,14 +991,14 @@ 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 => { let p = taskpool.execute((): void => { return nativePublish(request); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -878,34 +1007,32 @@ 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 => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) } - + export function publish(request: NotificationRequest, userId: number): Promise { let error: BusinessError = isInvalidParameter(request); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { return nativePublishWithUserId(request, userId); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -916,20 +1043,20 @@ 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 => { let p = taskpool.execute((): void => { - return nativeTriggerSystemLiveView(bundle, notificationId, buttonOptions); + return nativeTriggerSystemLiveView(bundle, notificationId, buttonOptions); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -945,7 +1072,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeSubscribeSystemLiveView(subscriber); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -954,17 +1081,13 @@ 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); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -973,17 +1096,13 @@ 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); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -992,18 +1111,14 @@ 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 => { let ret : Array = data as Array; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let retData : Array = []; let err: BusinessError = error as BusinessError; callback(err, retData); @@ -1018,7 +1133,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : Array = data as Array; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1031,7 +1146,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : Array = data as Array; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1040,31 +1155,43 @@ 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 => { let ret : Array = data as Array; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let retData : Array = []; let err: BusinessError = error as BusinessError; callback(err, retData); }) } + 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(); }); p.then((data :NullishType): void => { let ret : number = data as number; resolve(ret); - }, (err:Object): void => { + }, (err:Error): void => { reject(err); }); }); @@ -1073,34 +1200,32 @@ 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 => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) } - + export function displayBadge(bundle: BundleOption, enable: boolean): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { let p = taskpool.execute((): void => { return nativeDisplayBadge(bundle, enable); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1109,7 +1234,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); }); @@ -1117,16 +1242,16 @@ export default namespace notificationManager { let ret : boolean = data as boolean; let err: BusinessError = {code: 0, data: undefined}; callback(err, ret); - }, (error: Object): void => { + }, (error: Error): void => { let ret : boolean = false; let err: BusinessError = error as BusinessError; callback(err, ret); }) } - + export function isBadgeDisplayed(bundle: BundleOption): Promise { let error: BusinessError = isInvalidParameter(bundle); - if (error.code !== 0) { + if (error.code !== ERROR_OK) { throw error; } let pPromise = new Promise((resolve: ResolveCallback, reject: RejectCallback): void => { @@ -1134,7 +1259,7 @@ export default namespace notificationManager { p.then((data: NullishType): void => { let ret : boolean = data as boolean; resolve(ret); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1143,14 +1268,14 @@ 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 => { let p = taskpool.execute((): void => { return nativeCancelWithBundle(bundle, id); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1159,17 +1284,13 @@ 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); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1178,24 +1299,16 @@ 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) { - let error: BusinessError = { - code: 410, - message : "callback must be not null" - } - throw error; + throw errorParamInvalid; } let p = taskpool.execute((): void => { return nativeCancelWithIdLabel(id, label); }); p.then((data: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) @@ -1203,17 +1316,13 @@ 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 => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) @@ -1224,7 +1333,7 @@ export default namespace notificationManager { let p = taskpool.execute((): void => { return nativeCancelAll(); }); p.then((data: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); }); }); @@ -1233,17 +1342,13 @@ 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 => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); }) @@ -1269,7 +1374,7 @@ export default namespace notificationManager { } } }, - (error: Object): void => { + (error: Error): void => { reject(error); } ) @@ -1296,10 +1401,84 @@ export default namespace notificationManager { } } }, - (error: Object): void => { + (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } ) } + + export interface NotificationCheckResult { + code: number; + message: string; + } + + class NotificationCheckResultInner implements NotificationCheckResult { + public code: number = -1; + public message: string = ''; + } + + export interface NotificationCheckInfo { + bundleName: string; + notificationId: number; + label?: string; + contentType: ContentType; + creatorUserId: number; + slotType: SlotType; + extraInfos?: Record; + } + + class NotificationCheckInfoInner implements NotificationCheckInfo { + public bundleName: string = ''; + public notificationId: number = -1; + public label?: string; + public contentType: ContentType = ContentType.NOTIFICATION_CONTENT_BASIC_TEXT; + public creatorUserId: number = -1; + public slotType: SlotType = SlotType.UNKNOWN_TYPE; + public extraInfos?: Record; + } + + 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 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: Error): 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: Error): void => { + reject(error); + }); + }); + return pPromise; + } } \ No newline at end of file diff --git a/frameworks/ets/ets/@ohos.notificationSubscribe.ets b/frameworks/ets/ets/@ohos.notificationSubscribe.ets index b6f13916283b7d13f561d645c822027451a7d2e8..bb9c8a174af78b1cd3b059e7760b0529972f0815 100644 --- a/frameworks/ets/ets/@ohos.notificationSubscribe.ets +++ b/frameworks/ets/ets/@ohos.notificationSubscribe.ets @@ -19,7 +19,7 @@ import { NotificationSubscribeInfo } from 'notification.notificationSubscribeInf import { NotificationSubscriber } from 'notification.notificationSubscriber'; type ResolveCallback = (data: T) => void; -type RejectCallback = (err: Object) => void; +type RejectCallback = (err: Error) => void; const ERROR_OK = 0; const ERROR_PARAM_INVALID = 401; @@ -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,10 @@ 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 native function nativeRemoveAll(): void; export function subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback): void { if (subscriber == undefined || callback == undefined) { @@ -68,7 +93,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -87,7 +112,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -102,7 +127,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -119,7 +144,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -135,7 +160,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -159,7 +184,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -181,7 +206,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -200,7 +225,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -218,7 +243,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -237,7 +262,7 @@ export default namespace notificationSubscribe { (e: NullishType): void => { let err: BusinessError = {code: 0, data: undefined}; callback(err, undefined); - }, (error: Object): void => { + }, (error: Error): void => { let err: BusinessError = error as BusinessError; callback(err, undefined); } @@ -255,7 +280,7 @@ export default namespace notificationSubscribe { p.then( (e: NullishType): void => { resolve(undefined); - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -286,7 +311,7 @@ export default namespace notificationSubscribe { } else { resolve(undefined); } - }, (error: Object): void => { + }, (error: Error): void => { reject(error); } ) @@ -303,4 +328,4 @@ export default namespace notificationSubscribe { public actionName?: string; public userInput?: string; } -} \ No newline at end of file +} diff --git a/frameworks/ets/ets/notification/notificationRequest.ets b/frameworks/ets/ets/notification/notificationRequest.ets index 5b1993bd1cb6aa35a4d6964adc251c800c98a5b1..b990da8d56f06a96bf3348824e1385cc17b9a942 100644 --- a/frameworks/ets/ets/notification/notificationRequest.ets +++ b/frameworks/ets/ets/notification/notificationRequest.ets @@ -108,7 +108,6 @@ export interface NotificationRequest { readonly creatorUid?: number; readonly creatorPid?: number; readonly creatorUserId?: number; - readonly creatorInstanceKey?: number; sound?: string; classification?: string; readonly hashCode?: string; @@ -160,7 +159,6 @@ class NotificationRequestInner implements NotificationRequest { public readonly creatorUid?: number | undefined; public readonly creatorPid?: number | undefined; public readonly creatorUserId?: number | undefined; - public readonly creatorInstanceKey?: number | undefined; public sound?: string | undefined; public classification?: string | undefined; public readonly hashCode?: string | undefined;