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_napi.h"
17 #include "ans_inner_errors.h"
18 #include "location_log.h"
19 #include "js_native_api.h"
20 #include "js_native_api_types.h"
21 #include "napi_common.h"
22 #include "napi_common_util.h"
23 #include "notification_action_button.h"
24 #include "notification_capsule.h"
25 #include "notification_constant.h"
26 #include "notification_local_live_view_content.h"
27 #include "notification_progress.h"
28 #include "notification_time.h"
29 #include "pixel_map_napi.h"
30
31 namespace OHOS {
32 namespace Location {
GetNotificationRequestDistributedOptions(const napi_env & env,const napi_value & value,NotificationRequest & request)33 napi_value NotificationNapi::GetNotificationRequestDistributedOptions(const napi_env &env,
34 const napi_value &value, NotificationRequest &request)
35 {
36 LBSLOGD(NAPI_UTILS, "enter");
37 napi_valuetype valuetype = napi_undefined;
38 napi_value result = nullptr;
39 bool hasProperty = false;
40
41 // distributedOption?: DistributedOptions
42 NAPI_CALL(env, napi_has_named_property(env, value, "distributedOption", &hasProperty));
43 if (hasProperty) {
44 napi_get_named_property(env, value, "distributedOption", &result);
45 NAPI_CALL(env, napi_typeof(env, result, &valuetype));
46 if (valuetype != napi_object) {
47 LBSLOGE(NAPI_UTILS, "Wrong argument type. Object expected.");
48 return nullptr;
49 }
50
51 // isDistributed?: boolean
52 if (GetNotificationIsDistributed(env, result, request) == nullptr) {
53 return nullptr;
54 }
55
56 // supportDisplayDevices?: Array<string>
57 if (GetNotificationSupportDisplayDevices(env, result, request) == nullptr) {
58 return nullptr;
59 }
60
61 // supportOperateDevices?: Array<string>
62 if (GetNotificationSupportOperateDevices(env, result, request) == nullptr) {
63 return nullptr;
64 }
65 }
66
67 return NapiGetNull(env);
68 }
69
GetNotificationIsDistributed(const napi_env & env,const napi_value & value,NotificationRequest & request)70 napi_value NotificationNapi::GetNotificationIsDistributed(
71 const napi_env &env, const napi_value &value, NotificationRequest &request)
72 {
73 LBSLOGD(NAPI_UTILS, "enter");
74
75 napi_valuetype valuetype = napi_undefined;
76 napi_value result = nullptr;
77 bool hasProperty = false;
78 bool isDistributed = false;
79
80 NAPI_CALL(env, napi_has_named_property(env, value, "isDistributed", &hasProperty));
81 if (hasProperty) {
82 napi_get_named_property(env, value, "isDistributed", &result);
83 NAPI_CALL(env, napi_typeof(env, result, &valuetype));
84 if (valuetype != napi_boolean) {
85 LBSLOGE(NAPI_UTILS, "Wrong argument type. Bool expected.");
86 return nullptr;
87 }
88 napi_get_value_bool(env, result, &isDistributed);
89 request.SetDistributed(isDistributed);
90 }
91
92 return NapiGetNull(env);
93 }
94 }
95 }
96