1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "notification_manager_ffi.h"
17 #include "macro.h"
18
19 using namespace OHOS::FFI;
20
21 namespace OHOS {
22 namespace CJSystemapi {
23 namespace Notification {
24
25 extern "C" {
FfiOHOSNotificationManagerPublish(CNotificationRequest request)26 int32_t FfiOHOSNotificationManagerPublish(CNotificationRequest request)
27 {
28 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerPublish start");
29 auto code = NotificationManagerImpl::Publish(request);
30 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerPublish success");
31 return code;
32 }
33
FfiOHOSNotificationManagerCancel(int32_t id,const char * label)34 int32_t FfiOHOSNotificationManagerCancel(int32_t id, const char* label)
35 {
36 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerCancel start");
37 auto code = NotificationManagerImpl::Cancel(id, label);
38 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerCancel success");
39 return code;
40 }
41
FfiOHOSNotificationManagerCancelAll()42 int32_t FfiOHOSNotificationManagerCancelAll()
43 {
44 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerCancelAll start");
45 auto code = NotificationManagerImpl::CancelAll();
46 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerCancelAll success");
47 return code;
48 }
49
FfiOHOSNotificationManagerAddSlot(int32_t type)50 int32_t FfiOHOSNotificationManagerAddSlot(int32_t type)
51 {
52 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerAddSlot start");
53 auto code = NotificationManagerImpl::AddSlot(type);
54 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerAddSlot success");
55 return code;
56 }
57
FfiOHOSNotificationManagerIsNotificationEnabled()58 RetDataBool FfiOHOSNotificationManagerIsNotificationEnabled()
59 {
60 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerIsNotificationEnabled start");
61 RetDataBool ret = { .code = ERR_INVALID_INSTANCE_CODE, .data = 0 };
62 auto [status, enabledStatus] = NotificationManagerImpl::IsNotificationEnabled();
63 if (status != SUCCESS_CODE) {
64 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerIsNotificationEnabled error");
65 ret.code = status;
66 ret.data = false;
67 return ret;
68 }
69 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerIsNotificationEnabled success");
70 ret.code = status;
71 ret.data = enabledStatus;
72 return ret;
73 }
74
FfiOHOSNotificationManagerSetBadgeNumber(int32_t badgeNumber)75 int32_t FfiOHOSNotificationManagerSetBadgeNumber(int32_t badgeNumber)
76 {
77 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerSetBadgeNumber start");
78 auto code = NotificationManagerImpl::SetBadgeNumber(badgeNumber);
79 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerSetBadgeNumber success");
80 return code;
81 }
82
FfiOHOSNotificationManagerRequestEnableNotification()83 int32_t FfiOHOSNotificationManagerRequestEnableNotification()
84 {
85 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerRequestEnableNotification start");
86 auto code = NotificationManagerImpl::RequestEnableNotification();
87 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerRequestEnableNotification success");
88 return code;
89 }
90
FfiOHOSNotificationManagerRequestEnableNotificationWithContext(int64_t id)91 int32_t FfiOHOSNotificationManagerRequestEnableNotificationWithContext(int64_t id)
92 {
93 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerRequestEnableNotificationWithContext start");
94 auto context = FFIData::GetData<AbilityRuntime::CJAbilityContext>(id);
95 if (context == nullptr) {
96 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerRequestEnableNotificationWithContext error");
97 return ERROR_PARAM_INVALID;
98 }
99 auto code = NotificationManagerImpl::RequestEnableNotificationWithContext(context);
100 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerRequestEnableNotificationWithContext success");
101 return code;
102 }
103
FfiOHOSNotificationManagerIsDistributedEnabled()104 RetDataBool FfiOHOSNotificationManagerIsDistributedEnabled()
105 {
106 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerIsDistributedEnabled start");
107 RetDataBool ret = { .code = ERR_INVALID_INSTANCE_CODE, .data = 0 };
108 auto [status, enabledStatus] = NotificationManagerImpl::IsDistributedEnabled();
109 if (status != SUCCESS_CODE) {
110 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerIsDistributedEnabled error");
111 ret.code = status;
112 ret.data = false;
113 return ret;
114 }
115 LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerIsDistributedEnabled success");
116 ret.code = status;
117 ret.data = enabledStatus;
118 return ret;
119 }
120 }
121
122 } // namespace Notification
123 } // namespace CJSystemapi
124 } // namespace OHOS