1 /*
2 * Copyright (c) 2021-2022 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 "init.h"
17 #include "ans_template.h"
18 #include "cancel.h"
19 #include "constant.h"
20 #include "display_badge.h"
21 #include "distributed.h"
22 #include "disturb_mode.h"
23 #include "enable_notification.h"
24 #include "get_active.h"
25 #include "pixel_map_napi.h"
26 #include "publish.h"
27 #include "remove.h"
28 #include "slot.h"
29 #include "subscribe.h"
30 #include "unsubscribe.h"
31
32 namespace OHOS {
33 namespace NotificationNapi {
34 using namespace OHOS::Notification;
35
36 EXTERN_C_START
37
NotificationInit(napi_env env,napi_value exports)38 napi_value NotificationInit(napi_env env, napi_value exports)
39 {
40 napi_property_descriptor desc[] = {
41 DECLARE_NAPI_FUNCTION("subscribe", Subscribe),
42 DECLARE_NAPI_FUNCTION("unsubscribe", Unsubscribe),
43 DECLARE_NAPI_FUNCTION("publish", Publish),
44 DECLARE_NAPI_FUNCTION("publishAsBundle", PublishAsBundle),
45 DECLARE_NAPI_FUNCTION("remove", Remove),
46 DECLARE_NAPI_FUNCTION("removeAll", RemoveAll),
47 DECLARE_NAPI_FUNCTION("getAllActiveNotifications", GetAllActiveNotifications),
48 DECLARE_NAPI_FUNCTION("getActiveNotifications", GetActiveNotifications),
49 DECLARE_NAPI_FUNCTION("getActiveNotificationCount", GetActiveNotificationCount),
50 DECLARE_NAPI_FUNCTION("cancel", Cancel),
51 DECLARE_NAPI_FUNCTION("cancelAll", CancelAll),
52 DECLARE_NAPI_FUNCTION("cancelGroup", CancelGroup),
53 DECLARE_NAPI_FUNCTION("cancelAsBundle", CancelAsBundle),
54 DECLARE_NAPI_FUNCTION("addSlot", AddSlot),
55 DECLARE_NAPI_FUNCTION("addSlots", AddSlots),
56 DECLARE_NAPI_FUNCTION("getSlot", GetSlot),
57 DECLARE_NAPI_FUNCTION("getSlots", GetSlots),
58 DECLARE_NAPI_FUNCTION("removeSlot", RemoveSlot),
59 DECLARE_NAPI_FUNCTION("removeAllSlots", RemoveAllSlots),
60 DECLARE_NAPI_FUNCTION("removeGroupByBundle", RemoveGroupByBundle),
61 DECLARE_NAPI_FUNCTION("enableNotification", EnableNotification),
62 DECLARE_NAPI_FUNCTION("isNotificationEnabled", IsNotificationEnabled),
63 DECLARE_NAPI_FUNCTION("enableNotificationSlot", EnableNotificationSlot),
64 DECLARE_NAPI_FUNCTION("isSupportTemplate", IsSupportTemplate),
65 DECLARE_NAPI_FUNCTION("requestEnableNotification", RequestEnableNotification),
66
67 #ifdef ANS_FEATURE_BADGE_MANAGER
68 DECLARE_NAPI_FUNCTION("displayBadge", DisplayBadge),
69 DECLARE_NAPI_FUNCTION("isBadgeDisplayed", IsBadgeDisplayed),
70 #else
71 DECLARE_NAPI_FUNCTION("displayBadge", Common::NapiReturnCapErrCb),
72 DECLARE_NAPI_FUNCTION("isBadgeDisplayed", Common::NapiReturnCapErrCb),
73 #endif
74
75 #ifdef ANS_FEATURE_LIVEVIEW_LOCAL_LIVEVIEW
76 DECLARE_NAPI_FUNCTION("show", ShowNotification),
77 #else
78 DECLARE_NAPI_FUNCTION("show", Common::NapiReturnCapErr),
79 #endif
80
81 #ifdef ANS_FEATURE_DISTRIBUTED_DB
82 DECLARE_NAPI_FUNCTION("isDistributedEnabled", IsDistributedEnabled),
83 DECLARE_NAPI_FUNCTION("enableDistributed", EnableDistributed),
84 DECLARE_NAPI_FUNCTION("enableDistributedByBundle", EnableDistributedByBundle),
85 DECLARE_NAPI_FUNCTION("enableDistributedSelf", EnableDistributedSelf),
86 DECLARE_NAPI_FUNCTION("isDistributedEnabledByBundle", IsDistributedEnableByBundle),
87 DECLARE_NAPI_FUNCTION("getDeviceRemindType", GetDeviceRemindType),
88 DECLARE_NAPI_FUNCTION("setSyncNotificationEnabledWithoutApp", SetSyncNotificationEnabledWithoutApp),
89 DECLARE_NAPI_FUNCTION("getSyncNotificationEnabledWithoutApp", GetSyncNotificationEnabledWithoutApp),
90 #else
91 DECLARE_NAPI_FUNCTION("isDistributedEnabled", Common::NapiReturnFalseCb),
92 DECLARE_NAPI_FUNCTION("enableDistributed", Common::NapiReturnCapErrCb),
93 DECLARE_NAPI_FUNCTION("enableDistributedByBundle", Common::NapiReturnCapErrCb),
94 DECLARE_NAPI_FUNCTION("enableDistributedSelf", Common::NapiReturnCapErrCb),
95 DECLARE_NAPI_FUNCTION("isDistributedEnabledByBundle", Common::NapiReturnCapErrCb),
96 DECLARE_NAPI_FUNCTION("getDeviceRemindType", Common::NapiReturnCapErrCb),
97 DECLARE_NAPI_FUNCTION("setSyncNotificationEnabledWithoutApp", Common::NapiReturnCapErrCb),
98 DECLARE_NAPI_FUNCTION("getSyncNotificationEnabledWithoutApp", Common::NapiReturnCapErrCb),
99 #endif
100
101 #ifdef ANS_FEATURE_DISTURB_MANAGER
102 DECLARE_NAPI_FUNCTION("setDoNotDisturbDate", SetDoNotDisturbDate),
103 DECLARE_NAPI_FUNCTION("getDoNotDisturbDate", GetDoNotDisturbDate),
104 DECLARE_NAPI_FUNCTION("supportDoNotDisturbMode", SupportDoNotDisturbMode),
105 #else
106 DECLARE_NAPI_FUNCTION("setDoNotDisturbDate", Common::NapiReturnCapErrCb),
107 DECLARE_NAPI_FUNCTION("getDoNotDisturbDate", Common::NapiReturnCapErrCb),
108 DECLARE_NAPI_FUNCTION("supportDoNotDisturbMode", Common::NapiReturnCapErrCb),
109 #endif
110
111 #ifdef ANS_FEATURE_SLOT_MANAGER
112 DECLARE_NAPI_FUNCTION("isNotificationSlotEnabled", IsEnableNotificationSlot),
113 DECLARE_NAPI_FUNCTION("getSlotsByBundle", GetSlotsByBundle),
114 DECLARE_NAPI_FUNCTION("getSlotNumByBundle", GetSlotNumByBundle),
115 DECLARE_NAPI_FUNCTION("setSlotByBundle", SetSlotByBundle),
116 #else
117 DECLARE_NAPI_FUNCTION("isNotificationSlotEnabled", Common::NapiReturnCapErrCb),
118 DECLARE_NAPI_FUNCTION("getSlotsByBundle", Common::NapiReturnCapErrCb),
119 DECLARE_NAPI_FUNCTION("getSlotNumByBundle", Common::NapiReturnCapErrCb),
120 DECLARE_NAPI_FUNCTION("setSlotByBundle", Common::NapiReturnCapErrCb),
121 #endif
122 };
123
124 NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
125
126 return exports;
127 }
128
129 /*
130 * Module export function
131 */
Init(napi_env env,napi_value exports)132 static napi_value Init(napi_env env, napi_value exports)
133 {
134 /*
135 * Propertise define
136 */
137 ANS_LOGI("libnotification Init start");
138 NotificationInit(env, exports);
139 ConstantInit(env, exports);
140
141 return exports;
142 }
143
144 /*
145 * Module register function
146 */
RegisterModule(void)147 __attribute__((constructor)) void RegisterModule(void)
148 {
149 ANS_LOGI("libnotification register start");
150 napi_module_register(&_module);
151 }
152 EXTERN_C_END
153 } // namespace NotificationNapi
154 } // namespace OHOS