• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "notification_manager_impl.h"
18 #include "macro.h"
19 
20 using namespace OHOS::FFI;
21 
22 namespace OHOS {
23 namespace CJSystemapi {
24 namespace Notification {
25 
26 extern "C" {
FfiOHOSNotificationManagerPublishV2(CNotificationRequestV2 request)27 int32_t FfiOHOSNotificationManagerPublishV2(CNotificationRequestV2 request)
28 {
29     auto code = NotificationManagerImplV2::Publish(request);
30     return code;
31 }
32 
FfiOHOSNotificationManagerCancelV2(int32_t id,const char * label)33 int32_t FfiOHOSNotificationManagerCancelV2(int32_t id, const char* label)
34 {
35     auto code = NotificationManagerImplV2::Cancel(id, label);
36     return code;
37 }
38 
FfiOHOSNotificationManagerCancelAllV2()39 int32_t FfiOHOSNotificationManagerCancelAllV2()
40 {
41     auto code = NotificationManagerImplV2::CancelAll();
42     return code;
43 }
44 
FfiOHOSNotificationManagerAddSlotV2(int32_t type)45 int32_t FfiOHOSNotificationManagerAddSlotV2(int32_t type)
46 {
47     auto code = NotificationManagerImplV2::AddSlot(type);
48     return code;
49 }
50 
FfiOHOSNotificationManagerGetSlot(int32_t type,int32_t * errCode)51 CNotificationSlotV2 FfiOHOSNotificationManagerGetSlot(int32_t type, int32_t* errCode)
52 {
53     CNotificationSlotV2 ret = NotificationManagerImplV2::GetSlot(type, *errCode);
54     return ret;
55 }
56 
FfiOHOSNotificationManagerGetSlots(int32_t * errCode)57 CArrayNotificationSlotsV2 FfiOHOSNotificationManagerGetSlots(int32_t* errCode)
58 {
59     CArrayNotificationSlotsV2 ret = NotificationManagerImplV2::GetSlots(*errCode);
60     return ret;
61 }
62 
FfiOHOSNotificationManagerRemoveSlot(int32_t type)63 int32_t FfiOHOSNotificationManagerRemoveSlot(int32_t type)
64 {
65     auto code = NotificationManagerImplV2::RemoveSlot(type);
66     return code;
67 }
68 
FfiOHOSNotificationManagerRemoveAllSlots()69 int32_t FfiOHOSNotificationManagerRemoveAllSlots()
70 {
71     auto code = NotificationManagerImplV2::RemoveAllSlots();
72     return code;
73 }
74 
FfiOHOSNotificationManagerGetActiveNotificationCount()75 RetDataUI32 FfiOHOSNotificationManagerGetActiveNotificationCount()
76 {
77     RetDataUI32 ret = NotificationManagerImplV2::GetActiveNotificationCount();
78     return ret;
79 }
80 
FfiOHOSNotificationManagerGetActiveNotifications(int32_t * errCode)81 CArrayNotificationRequestV2 FfiOHOSNotificationManagerGetActiveNotifications(int32_t* errCode)
82 {
83     CArrayNotificationRequestV2 ret = NotificationManagerImplV2::GetActiveNotifications(*errCode);
84     return ret;
85 }
86 
FfiOHOSNotificationManagerCancelGroup(const char * cGroupName)87 int32_t FfiOHOSNotificationManagerCancelGroup(const char* cGroupName)
88 {
89     auto code = NotificationManagerImplV2::CancelGroup(cGroupName);
90     return code;
91 }
92 
FfiOHOSNotificationManagerIsSupportTemplate(const char * cTemplateName)93 RetDataBool FfiOHOSNotificationManagerIsSupportTemplate(const char* cTemplateName)
94 {
95     RetDataBool ret =  NotificationManagerImplV2::IsSupportTemplate(cTemplateName);
96     return ret;
97 }
98 
FfiOHOSNotificationManagerSetNotificationEnable(CNotificationBundleOptionV2 option,bool enable)99 int32_t FfiOHOSNotificationManagerSetNotificationEnable(CNotificationBundleOptionV2 option, bool enable)
100 {
101     auto code = NotificationManagerImplV2::SetNotificationEnable(option, enable);
102     return code;
103 }
104 
FfiOHOSNotificationManagerDisplayBadge(CNotificationBundleOptionV2 option,bool enable)105 int32_t FfiOHOSNotificationManagerDisplayBadge(CNotificationBundleOptionV2 option, bool enable)
106 {
107     auto code = NotificationManagerImplV2::DisplayBadge(option, enable);
108     return code;
109 }
110 
FfiOHOSNotificationManagerIsBadgeDisplayed(CNotificationBundleOptionV2 option)111 RetDataBool FfiOHOSNotificationManagerIsBadgeDisplayed(CNotificationBundleOptionV2 option)
112 {
113     RetDataBool ret =  NotificationManagerImplV2::IsBadgeDisplayed(option);
114     return ret;
115 }
116 
FfiOHOSNotificationManagerSetSlotFlagsByBundle(CNotificationBundleOptionV2 option,int32_t slotFlags)117 int32_t FfiOHOSNotificationManagerSetSlotFlagsByBundle(
118     CNotificationBundleOptionV2 option,
119     int32_t slotFlags)
120 {
121     auto code = NotificationManagerImplV2::SetSlotFlagsByBundle(option, slotFlags);
122     return code;
123 }
124 
FfiOHOSNotificationManagerGetSlotFlagsByBundle(CNotificationBundleOptionV2 option)125 RetDataUI32 FfiOHOSNotificationManagerGetSlotFlagsByBundle(CNotificationBundleOptionV2 option)
126 {
127     RetDataUI32 ret = NotificationManagerImplV2::GetSlotFlagsByBundle(option);
128     return ret;
129 }
130 
FfiOHOSNotificationManagerGetSlotNumByBundle(CNotificationBundleOptionV2 option)131 RetDataUI32 FfiOHOSNotificationManagerGetSlotNumByBundle(CNotificationBundleOptionV2 option)
132 {
133     RetDataUI32 ret = NotificationManagerImplV2::GetSlotNumByBundle(option);
134     return ret;
135 }
136 
FfiOHOSNotificationManagerRemoveGroupByBundle(CNotificationBundleOptionV2 option,const char * cGroupName)137 int32_t FfiOHOSNotificationManagerRemoveGroupByBundle(
138     CNotificationBundleOptionV2 option,
139     const char* cGroupName)
140 {
141     auto code = NotificationManagerImplV2::RemoveGroupByBundle(option, cGroupName);
142     return code;
143 }
144 
FfiOHOSNotificationManagerIsNotificationEnabledV2()145 RetDataBool FfiOHOSNotificationManagerIsNotificationEnabledV2()
146 {
147     RetDataBool ret = { .code = ERR_INVALID_INSTANCE_CODE, .data = 0 };
148     auto [status, enabledStatus] = NotificationManagerImplV2::IsNotificationEnabled();
149     if (status != SUCCESS_CODE) {
150         LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerIsNotificationEnabled error");
151         ret.code = status;
152         ret.data = false;
153         return ret;
154     }
155     ret.code = status;
156     ret.data = enabledStatus;
157     return ret;
158 }
159 
FfiOHOSNotificationManagerSetBadgeNumberV2(int32_t badgeNumber)160 int32_t FfiOHOSNotificationManagerSetBadgeNumberV2(int32_t badgeNumber)
161 {
162     auto code = NotificationManagerImplV2::SetBadgeNumber(badgeNumber);
163     return code;
164 }
165 
FfiOHOSNotificationManagerRequestEnableNotificationV2()166 int32_t FfiOHOSNotificationManagerRequestEnableNotificationV2()
167 {
168     auto code = NotificationManagerImplV2::RequestEnableNotification();
169     return code;
170 }
171 
FfiOHOSNotificationManagerRequestEnableNotificationWithContextV2(int64_t id)172 int32_t FfiOHOSNotificationManagerRequestEnableNotificationWithContextV2(int64_t id)
173 {
174     auto context = FFIData::GetData<AbilityRuntime::CJAbilityContext>(id);
175     if (context == nullptr) {
176         LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerRequestEnableNotificationWithContext error");
177         return ERROR_PARAM_INVALID;
178     }
179     auto code = NotificationManagerImplV2::RequestEnableNotificationWithContext(context);
180     return code;
181 }
182 
FfiOHOSNotificationManagerIsDistributedEnabledV2()183 RetDataBool FfiOHOSNotificationManagerIsDistributedEnabledV2()
184 {
185     RetDataBool ret = { .code = ERR_INVALID_INSTANCE_CODE, .data = 0 };
186     auto [status, enabledStatus] = NotificationManagerImplV2::IsDistributedEnabled();
187     if (status != SUCCESS_CODE) {
188         LOGI("NOTIFICATION_TEST::FfiOHOSNotificationManagerIsDistributedEnabled error");
189         ret.code = status;
190         ret.data = false;
191         return ret;
192     }
193     ret.code = status;
194     ret.data = enabledStatus;
195     return ret;
196 }
197 }
198 
199 } // namespace Notification
200 } // namespace CJSystemapi
201 } // namespace OHOS