1 /*
2 * Copyright (c) 2021-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 #include "feature_ability_constant.h"
16
17 #include <cstring>
18 #include <vector>
19
20 #include "hilog_tag_wrapper.h"
21 #include "securec.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
FAConstantInit(napi_env env,napi_value exports)25 napi_value FAConstantInit(napi_env env, napi_value exports)
26 {
27 const int Window_Configuration_Zero = 100;
28 const int Window_Configuration_One = 101;
29 const int Window_Configuration_Two = 102;
30 const int NO_ERROR = 0;
31 const int INVALID_PARAMETER = -1;
32 const int ABILITY_NOT_FOUND = -2;
33 const int PERMISSION_DENY = -3;
34 TAG_LOGD(AAFwkTag::FA, "called");
35 napi_value abilityStartSetting = nullptr;
36 napi_value abilityWindowConfiguration = nullptr;
37 napi_value errorCode = nullptr;
38 napi_create_object(env, &abilityStartSetting);
39 napi_create_object(env, &abilityWindowConfiguration);
40 napi_create_object(env, &errorCode);
41
42 SetNamedProperty(env, abilityStartSetting, "abilityBounds", "BOUNDS_KEY");
43 SetNamedProperty(env, abilityStartSetting, "windowMode", "WINDOW_MODE_KEY");
44 SetNamedProperty(env, abilityStartSetting, "displayId", "DISPLAY_ID_KEY");
45
46 SetNamedProperty(env, abilityWindowConfiguration, 0, "WINDOW_MODE_UNDEFINED");
47 SetNamedProperty(env, abilityWindowConfiguration, 1, "WINDOW_MODE_FULLSCREEN");
48 SetNamedProperty(env, abilityWindowConfiguration, Window_Configuration_Zero, "WINDOW_MODE_SPLIT_PRIMARY");
49 SetNamedProperty(env, abilityWindowConfiguration, Window_Configuration_One, "WINDOW_MODE_SPLIT_SECONDARY");
50 SetNamedProperty(env, abilityWindowConfiguration, Window_Configuration_Two, "WINDOW_MODE_FLOATING");
51
52 SetNamedProperty(env, errorCode, NO_ERROR, "NO_ERROR");
53 SetNamedProperty(env, errorCode, INVALID_PARAMETER, "INVALID_PARAMETER");
54 SetNamedProperty(env, errorCode, ABILITY_NOT_FOUND, "ABILITY_NOT_FOUND");
55 SetNamedProperty(env, errorCode, PERMISSION_DENY, "PERMISSION_DENY");
56
57 napi_property_descriptor exportFuncs[] = {
58 DECLARE_NAPI_PROPERTY("AbilityStartSetting", abilityStartSetting),
59 DECLARE_NAPI_PROPERTY("AbilityWindowConfiguration", abilityWindowConfiguration),
60 DECLARE_NAPI_PROPERTY("ErrorCode", errorCode),
61 };
62 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
63
64 return exports;
65 }
66
SetNamedProperty(napi_env env,napi_value dstObj,const char * objName,const char * propName)67 void SetNamedProperty(napi_env env, napi_value dstObj, const char *objName, const char *propName)
68 {
69 TAG_LOGD(AAFwkTag::FA, "called");
70 napi_value prop = nullptr;
71 napi_create_string_utf8(env, objName, NAPI_AUTO_LENGTH, &prop);
72 napi_set_named_property(env, dstObj, propName, prop);
73 }
74
SetNamedProperty(napi_env env,napi_value dstObj,const int32_t objValue,const char * propName)75 void SetNamedProperty(napi_env env, napi_value dstObj, const int32_t objValue, const char *propName)
76 {
77 TAG_LOGD(AAFwkTag::FA, "end");
78 napi_value prop = nullptr;
79 napi_create_int32(env, objValue, &prop);
80 napi_set_named_property(env, dstObj, propName, prop);
81 }
82 } // namespace AppExecFwk
83 } // namespace OHOS
84