1 /* 2 * Copyright (c) 2023-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 #ifndef INTERFACES_KITS_ACCOUNT_MANAGER_INCLUDE_ACCOUNT_MANAGER_ADDON_H 17 #define INTERFACES_KITS_ACCOUNT_MANAGER_INCLUDE_ACCOUNT_MANAGER_ADDON_H 18 19 #ifdef OS_ACCOUNT_EDM_ENABLE 20 #include "account_info.h" 21 #include "os_account_info.h" 22 #endif 23 #include "account_manager_proxy.h" 24 #include "domain_account_policy.h" 25 #include "edm_errors.h" 26 #include "napi_edm_error.h" 27 #include "napi_edm_common.h" 28 #include "napi/native_common.h" 29 #include "napi/native_node_api.h" 30 #include "napi/native_api.h" 31 #include "want.h" 32 33 namespace OHOS { 34 namespace EDM { 35 struct AsyncDisallowAddLocalAccountCallbackInfo : AsyncCallbackInfo { 36 OHOS::AppExecFwk::ElementName elementName; 37 bool isDisallow; 38 }; 39 #ifdef OS_ACCOUNT_EDM_ENABLE 40 struct AsyncAddOsAccountCallbackInfo : AsyncCallbackInfo { 41 OHOS::AppExecFwk::ElementName elementName; 42 std::string name; 43 int32_t type; 44 OHOS::AccountSA::OsAccountInfo accountInfo; 45 }; 46 #endif 47 class AccountManagerAddon { 48 public: 49 AccountManagerAddon(); 50 ~AccountManagerAddon() = default; 51 52 static napi_value Init(napi_env env, napi_value exports); 53 private: 54 static napi_value DisallowAddLocalAccount(napi_env env, napi_callback_info info); 55 static void NativeDisallowAddLocalAccount(napi_env env, void *data); 56 static napi_value DisallowAddOsAccountByUser(napi_env env, napi_callback_info info); 57 static napi_value IsAddOsAccountByUserDisallowed(napi_env env, napi_callback_info info); 58 static napi_value AddOsAccount(napi_env env, napi_callback_info info); 59 static bool CheckOsAccountType(int32_t type); 60 static napi_value MakeArrayToJs(napi_env env, const std::vector<std::string> &constraints, napi_value jsArray); 61 #ifdef OS_ACCOUNT_EDM_ENABLE 62 static napi_value CreateJsDomainInfo(napi_env env, const OHOS::AccountSA::DomainAccountInfo &info, 63 napi_value &result); 64 static napi_value ConvertOsAccountInfoToJs(napi_env env, OHOS::AccountSA::OsAccountInfo &info); 65 static napi_value AddOsAccountCommon(napi_env env, napi_callback_info info, 66 AsyncAddOsAccountCallbackInfo* callbackInfo); 67 static void NativeAddOsAccount(napi_env env, void *data); 68 static void NativeAddOsAccountCallbackComplete(napi_env env, napi_status status, void *data); 69 #endif 70 static napi_value DisallowAddOsAccount(napi_env env, napi_callback_info info); 71 static napi_value IsAddOsAccountDisallowed(napi_env env, napi_callback_info info); 72 static napi_value AddOsAccountAsync(napi_env env, napi_callback_info info); 73 static napi_value SetDomainAccountPolicy(napi_env env, napi_callback_info info); 74 static napi_value GetDomainAccountPolicy(napi_env env, napi_callback_info info); 75 static napi_value ConvertDomainAccountPolicyToJs(napi_env env, DomainAccountPolicy &domainAccountPolicy); 76 static bool ParseDomainAccountPolicy(napi_env env, DomainAccountPolicy &domainAccountPolicy, napi_value args); 77 #if defined(FEATURE_PC_ONLY) && defined(OS_ACCOUNT_EDM_ENABLE) 78 static bool ParseDomainAccountInfo(napi_env env, OHOS::AccountSA::DomainAccountInfo &domainAccountInfo, 79 napi_value args); 80 #endif 81 }; 82 } // namespace EDM 83 } // namespace OHOS 84 85 #endif // INTERFACES_KITS_ACCOUNT_MANAGER_INCLUDE_ACCOUNT_MANAGER_ADDON_H 86