1 /*
2 * Copyright (c) 2021 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 #include "feature_ability_constant.h"
16
17 #include <cstring>
18 #include <vector>
19
20 #include "hilog_wrapper.h"
21 #include "securec.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 /**
26 * @brief FeatureAbilityConstantInit NAPI module registration.
27 *
28 * @param env The environment that the Node-API call is invoked under.
29 * @param exports An empty object via the exports parameter as a convenience.
30 *
31 * @return The return value from Init is treated as the exports object for the module.
32 */
FAConstantInit(napi_env env,napi_value exports)33 napi_value FAConstantInit(napi_env env, napi_value exports)
34 {
35 const int Window_Configuration_Zero = 100;
36 const int Window_Configuration_One = 101;
37 const int Window_Configuration_Two = 102;
38 const int NO_ERROR = 0;
39 const int INVALID_PARAMETER = -1;
40 const int ABILITY_NOT_FOUND = -2;
41 const int PERMISSION_DENY = -3;
42 HILOG_DEBUG("called");
43 napi_value abilityStartSetting = nullptr;
44 napi_value abilityWindowConfiguration = nullptr;
45 napi_value errorCode = nullptr;
46 napi_create_object(env, &abilityStartSetting);
47 napi_create_object(env, &abilityWindowConfiguration);
48 napi_create_object(env, &errorCode);
49
50 SetNamedProperty(env, abilityStartSetting, "abilityBounds", "BOUNDS_KEY");
51 SetNamedProperty(env, abilityStartSetting, "windowMode", "WINDOW_MODE_KEY");
52 SetNamedProperty(env, abilityStartSetting, "displayId", "DISPLAY_ID_KEY");
53
54 SetNamedProperty(env, abilityWindowConfiguration, 0, "WINDOW_MODE_UNDEFINED");
55 SetNamedProperty(env, abilityWindowConfiguration, 1, "WINDOW_MODE_FULLSCREEN");
56 SetNamedProperty(env, abilityWindowConfiguration, Window_Configuration_Zero, "WINDOW_MODE_SPLIT_PRIMARY");
57 SetNamedProperty(env, abilityWindowConfiguration, Window_Configuration_One, "WINDOW_MODE_SPLIT_SECONDARY");
58 SetNamedProperty(env, abilityWindowConfiguration, Window_Configuration_Two, "WINDOW_MODE_FLOATING");
59
60 SetNamedProperty(env, errorCode, NO_ERROR, "NO_ERROR");
61 SetNamedProperty(env, errorCode, INVALID_PARAMETER, "INVALID_PARAMETER");
62 SetNamedProperty(env, errorCode, ABILITY_NOT_FOUND, "ABILITY_NOT_FOUND");
63 SetNamedProperty(env, errorCode, PERMISSION_DENY, "PERMISSION_DENY");
64
65 napi_property_descriptor exportFuncs[] = {
66 DECLARE_NAPI_PROPERTY("AbilityStartSetting", abilityStartSetting),
67 DECLARE_NAPI_PROPERTY("AbilityWindowConfiguration", abilityWindowConfiguration),
68 DECLARE_NAPI_PROPERTY("ErrorCode", errorCode),
69 };
70 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
71
72 return exports;
73 }
74
SetNamedProperty(napi_env env,napi_value dstObj,const char * objName,const char * propName)75 void SetNamedProperty(napi_env env, napi_value dstObj, const char *objName, const char *propName)
76 {
77 HILOG_DEBUG("SetNamedProperty start");
78 napi_value prop = nullptr;
79 napi_create_string_utf8(env, objName, NAPI_AUTO_LENGTH, &prop);
80 napi_set_named_property(env, dstObj, propName, prop);
81 }
82
SetNamedProperty(napi_env env,napi_value dstObj,const int32_t objValue,const char * propName)83 void SetNamedProperty(napi_env env, napi_value dstObj, const int32_t objValue, const char *propName)
84 {
85 HILOG_DEBUG("SetNamedProperty start");
86 napi_value prop = nullptr;
87 napi_create_int32(env, objValue, &prop);
88 napi_set_named_property(env, dstObj, propName, prop);
89 }
90 } // namespace AppExecFwk
91 } // namespace OHOS
92