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