diff --git a/bundle.json b/bundle.json index f5b9386e49686cc4ac015772d8907c336f597961..5f30cebba8ac75384d03998c0a38e7cc4d4abc8f 100644 --- a/bundle.json +++ b/bundle.json @@ -104,7 +104,8 @@ "fwk_group": [ "//base/notification/distributed_notification_service/frameworks/ans:ans_client", "//base/notification/distributed_notification_service/frameworks/js/napi:napi_notification", - "//base/notification/distributed_notification_service/frameworks/js/napi:napi_reminder" + "//base/notification/distributed_notification_service/frameworks/js/napi:napi_reminder", + "//base/notification/distributed_notification_service/interfaces/ndk:ohnotification" ], "service_group": [ "//base/notification/distributed_notification_service/sa_profile:ans_sa_profile", diff --git a/interfaces/ndk/BUILD.gn b/interfaces/ndk/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b5763690c6cde9e08780fdff4e52420b9b1c8bf7 --- /dev/null +++ b/interfaces/ndk/BUILD.gn @@ -0,0 +1,68 @@ +# Copyright (c) 2021-2022 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") + +cflags = [] + +config("notification_ndk_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${inner_api_path}", + "${notification_ndk_path}/include", + ] + + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } +} + +config("notification_ndk_public_config") { + visibility = [ ":*" ] + + include_dirs = [ "${notification_ndk_path}/include" ] +} + +ohos_shared_library("ohnotification") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + configs = [ ":notification_ndk_config" ] + + public_configs = [ ":notification_ndk_public_config" ] + + sources = [ "src/notification.cpp" ] + + deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + + external_deps = [ + "ability_base:base", + "ability_base:zuri", + "c_utils:utils", + "hilog:libhilog", + "relational_store:native_rdb", + ] + output_extension = "so" + innerapi_tags = [ "ndk" ] + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} diff --git a/interfaces/ndk/include/notification.h b/interfaces/ndk/include/notification.h new file mode 100644 index 0000000000000000000000000000000000000000..236608ca53d3ebd599a9b2877a36da6d4c06cf82 --- /dev/null +++ b/interfaces/ndk/include/notification.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 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. + */ + +/** + * @addtogroup NOTIFICATION + * @{ + * + * @brief Provides the definition of the C interface for the notification service. + * + * @since 14 + */ +/** + * @file notification.h + * + * @brief Declares the APIs of notification service. + * + * @library libohnotification.so + * @kit NotificationKit + * @syscap SystemCapability.Notification.Notification + * @since 14 + */ + +#ifndef OH_NOTIFICATION_H +#define OH_NOTIFICATION_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Checks whether this application is allowed to publish notifications. + * + * @return true - This application is allowed to publish notifications. + * false - This application is not allowed to publish notifications. + * @since 14 + */ +bool OH_Notification_IsNotificationEnabled(void); + +#ifdef __cplusplus +} +#endif +#endif // OH_NOTIFICATION_H +/** @} */ diff --git a/interfaces/ndk/src/notification.cpp b/interfaces/ndk/src/notification.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b1fe73aa82a2799763bbe13cb7577c7dab04adc --- /dev/null +++ b/interfaces/ndk/src/notification.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 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 "notification.h" + +#include "notification_helper.h" +#include "ans_log_wrapper.h" + +#ifdef __cplusplus +extern "C" { +#endif + +bool OH_Notification_IsNotificationEnabled(void) +{ + bool isEnable = false; + int32_t result = OHOS::Notification::NotificationHelper::IsAllowedNotifySelf(isEnable); + if (result != OHOS::ERR_OK) { + ANS_LOGW("Get notification enable failed %{public}d", result); + return false; + } + return isEnable; +} + +#ifdef __cplusplus +} +#endif diff --git a/notification.gni b/notification.gni index 434f0811f0d4165e10d28ea15eda54245c5ed9b2..1659de9e7244799d67ab07d374118e84818188c4 100644 --- a/notification.gni +++ b/notification.gni @@ -27,6 +27,7 @@ frameworks_path = "${component_path}/frameworks" frameworks_module_ans_path = "${frameworks_path}/ans" interfaces_path = "${component_path}/interfaces" inner_api_path = "${interfaces_path}/inner_api" +notification_ndk_path = "${interfaces_path}/ndk" core_path = "${frameworks_path}/core" test_path = "${component_path}/test" tools_path = "${component_path}/tools"