• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef ENTERPRISE_DEVICE_MGR_ADDON_H
17 #define ENTERPRISE_DEVICE_MGR_ADDON_H
18 
19 #include "admin_type.h"
20 #include "device_settings_manager.h"
21 #include "edm_errors.h"
22 #include "element_name.h"
23 #include "ent_info.h"
24 #include "enterprise_device_mgr_proxy.h"
25 #include "ienterprise_device_mgr.h"
26 #include "napi/native_common.h"
27 #include "napi/native_node_api.h"
28 #include "napi/native_api.h"
29 #include "ohos/aafwk/content/want.h"
30 
31 namespace OHOS {
32 namespace EDM {
33 struct AsyncCallbackInfo {
34     napi_env env;
35     napi_async_work asyncWork;
36     napi_deferred deferred;
37     napi_ref callback = 0;
38     int32_t ret;
39     bool boolRet = true;
40     int32_t err = 0;
41 };
42 
43 struct AsyncActivateAdminCallbackInfo : AsyncCallbackInfo {
44     OHOS::AppExecFwk::ElementName elementName;
45     EntInfo entInfo;
46     int32_t adminType = 0;
47 };
48 
49 struct AsyncDeactivateAdminCallbackInfo : AsyncCallbackInfo {
50     OHOS::AppExecFwk::ElementName elementName;
51 };
52 
53 struct AsyncDeactivateSuperAdminCallbackInfo : AsyncCallbackInfo {
54     std::string bundleName;
55 };
56 
57 struct AsyncGetEnterpriseInfoCallbackInfo : AsyncCallbackInfo {
58     OHOS::AppExecFwk::ElementName elementName;
59     EntInfo entInfo;
60 };
61 
62 struct AsyncSetDateTimeCallbackInfo : AsyncCallbackInfo {
63     OHOS::AppExecFwk::ElementName elementName;
64     int64_t time;
65 };
66 
67 struct AsyncSetEnterpriseInfoCallbackInfo : AsyncCallbackInfo {
68     OHOS::AppExecFwk::ElementName elementName;
69     EntInfo entInfo;
70 };
71 
72 struct AsyncIsSuperAdminCallbackInfo : AsyncCallbackInfo {
73     std::string bundleName;
74 };
75 
76 struct AsyncIsAdminActiveCallbackInfo : AsyncCallbackInfo {
77     OHOS::AppExecFwk::ElementName elementName;
78 };
79 
80 struct AsyncGetDeviceSettingsManagerCallbackInfo : AsyncCallbackInfo {
81     napi_env env;
82     napi_async_work asyncWork;
83     napi_deferred deferred;
84     napi_ref callback = 0;
85 };
86 
87 class EnterpriseDeviceManagerAddon {
88 public:
89     EnterpriseDeviceManagerAddon();
90     ~EnterpriseDeviceManagerAddon() = default;
91     static thread_local napi_ref g_classDeviceSettingsManager;
92 
93     static napi_value Init(napi_env env, napi_value exports);
94     static napi_value ActivateAdmin(napi_env env, napi_callback_info info);
95     static napi_value DeactivateAdmin(napi_env env, napi_callback_info info);
96     static napi_value DeactivateSuperAdmin(napi_env env, napi_callback_info info);
97     static napi_value GetEnterpriseInfo(napi_env env, napi_callback_info info);
98     static napi_value SetEnterpriseInfo(napi_env env, napi_callback_info info);
99     static napi_value IsSuperAdmin(napi_env env, napi_callback_info info);
100     static napi_value IsAdminAppActive(napi_env env, napi_callback_info info);
101     static napi_value HandleAsyncWork(napi_env env, AsyncCallbackInfo *context, std::string workName,
102         napi_async_execute_callback execute, napi_async_complete_callback complete);
103     static napi_value CreateAdminTypeObject(napi_env env);
104     static std::string GetStringFromNAPI(napi_env env, napi_value value);
105     static napi_value GetDeviceSettingsManager(napi_env env, napi_callback_info info);
106     static napi_value SetDateTime(napi_env env, napi_callback_info info);
107 
108     static void NativeActivateAdmin(napi_env env, void *data);
109     static void NativeDeactivateSuperAdmin(napi_env env, void *data);
110     static void NativeDeactivateAdmin(napi_env env, void *data);
111     static void NativeGetEnterpriseInfo(napi_env env, void *data);
112     static void NativeSetEnterpriseInfo(napi_env env, void *data);
113     static void NativeIsSuperAdmin(napi_env env, void *data);
114     static void NativeIsAdminActive(napi_env env, void *data);
115     static void NativeSetDateTime(napi_env env, void *data);
116 
117     static void NativeBoolCallbackComplete(napi_env env, napi_status status, void *data);
118     static void NativeGetEnterpriseInfoComplete(napi_env env, napi_status status, void *data);
119 
120     static void ConvertEnterpriseInfo(napi_env env, napi_value objEntInfo, EntInfo &entInfo);
121     static bool ParseEnterpriseInfo(napi_env env, EntInfo &enterpriseInfo, napi_value args);
122     static napi_value ParseString(napi_env env, std::string &param, napi_value args);
123     static napi_value CreateErrorMessage(napi_env env, std::string msg);
124     static bool ParseElementName(napi_env env, OHOS::AppExecFwk::ElementName &elementName, napi_value args);
125     static napi_value ParseStringArray(napi_env env, std::vector<std::string> &hapFiles, napi_value args);
126     static bool MatchValueType(napi_env env, napi_value value, napi_valuetype targetType);
127     static void CreateAdminTypeObject(napi_env env, napi_value value);
128     static napi_value CreateUndefined(napi_env env);
129     static napi_value ParseInt(napi_env env, int32_t &param, napi_value args);
130     static napi_value ParseLong(napi_env env, int64_t &param, napi_value args);
131 
132     static napi_value DeviceSettingsManagerConstructor(napi_env env, napi_callback_info info);
133 
134 private:
135     static std::shared_ptr<EnterpriseDeviceMgrProxy> proxy_;
136     static std::shared_ptr<DeviceSettingsManager> deviceSettingsManager_;
137 };
138 } // namespace EDM
139 } // namespace OHOS
140 
141 #endif /* ENTERPRISE_DEVICE_MGR_ADDON_H */
142