1600cc4afSopenharmony_ci/*
2600cc4afSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3600cc4afSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4600cc4afSopenharmony_ci * you may not use this file except in compliance with the License.
5600cc4afSopenharmony_ci * You may obtain a copy of the License at
6600cc4afSopenharmony_ci *
7600cc4afSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8600cc4afSopenharmony_ci *
9600cc4afSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10600cc4afSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11600cc4afSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12600cc4afSopenharmony_ci * See the License for the specific language governing permissions and
13600cc4afSopenharmony_ci * limitations under the License.
14600cc4afSopenharmony_ci */
15600cc4afSopenharmony_ci
16600cc4afSopenharmony_ci#include <unordered_map>
17600cc4afSopenharmony_ci
18600cc4afSopenharmony_ci#include "installer.h"
19600cc4afSopenharmony_ci
20600cc4afSopenharmony_ci#include "appexecfwk_errors.h"
21600cc4afSopenharmony_ci#include "app_log_wrapper.h"
22600cc4afSopenharmony_ci#include "bundle_errors.h"
23600cc4afSopenharmony_ci#include "bundle_death_recipient.h"
24600cc4afSopenharmony_ci#include "bundle_mgr_interface.h"
25600cc4afSopenharmony_ci#include "bundle_mgr_proxy.h"
26600cc4afSopenharmony_ci#include "business_error.h"
27600cc4afSopenharmony_ci#include "common_func.h"
28600cc4afSopenharmony_ci#include "if_system_ability_manager.h"
29600cc4afSopenharmony_ci#include "installer_callback.h"
30600cc4afSopenharmony_ci#include "napi_arg.h"
31600cc4afSopenharmony_ci#include "napi_constants.h"
32600cc4afSopenharmony_ci#include "system_ability_definition.h"
33600cc4afSopenharmony_ci#include "ipc_skeleton.h"
34600cc4afSopenharmony_ci
35600cc4afSopenharmony_cinamespace OHOS {
36600cc4afSopenharmony_cinamespace AppExecFwk {
37600cc4afSopenharmony_cinamespace {
38600cc4afSopenharmony_ci// resource name
39600cc4afSopenharmony_ciconst char* RESOURCE_NAME_OF_GET_BUNDLE_INSTALLER = "GetBundleInstaller";
40600cc4afSopenharmony_ciconst char* RESOURCE_NAME_OF_GET_BUNDLE_INSTALLER_SYNC = "GetBundleInstallerSync";
41600cc4afSopenharmony_ciconst char* RESOURCE_NAME_OF_INSTALL = "Install";
42600cc4afSopenharmony_ciconst char* RESOURCE_NAME_OF_UNINSTALL = "Uninstall";
43600cc4afSopenharmony_ciconst char* RESOURCE_NAME_OF_RECOVER = "Recover";
44600cc4afSopenharmony_ciconst char* RESOURCE_NAME_OF_UPDATE_BUNDLE_FOR_SELF = "UpdateBundleForSelf";
45600cc4afSopenharmony_ciconst char* RESOURCE_NAME_OF_UNINSTALL_AND_RECOVER = "UninstallAndRecover";
46600cc4afSopenharmony_ciconst char* EMPTY_STRING = "";
47600cc4afSopenharmony_ci// install message
48600cc4afSopenharmony_ciconstexpr const char* INSTALL_PERMISSION =
49600cc4afSopenharmony_ci    "ohos.permission.INSTALL_BUNDLE or "
50600cc4afSopenharmony_ci    "ohos.permission.INSTALL_ENTERPRISE_BUNDLE or "
51600cc4afSopenharmony_ci    "ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE or "
52600cc4afSopenharmony_ci    "ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE or "
53600cc4afSopenharmony_ci    "ohos.permission.INSTALL_INTERNALTESTING_BUNDLE";
54600cc4afSopenharmony_ciconstexpr const char* UNINSTALL_PERMISSION = "ohos.permission.INSTALL_BUNDLE or ohos.permission.UNINSTALL_BUNDLE";
55600cc4afSopenharmony_ciconstexpr const char* RECOVER_PERMISSION = "ohos.permission.INSTALL_BUNDLE or ohos.permission.RECOVER_BUNDLE";
56600cc4afSopenharmony_ciconstexpr const char* INSTALL_SELF_PERMISSION = "ohos.permission.INSTALL_SELF_BUNDLE";
57600cc4afSopenharmony_ciconstexpr const char* PARAMETERS = "parameters";
58600cc4afSopenharmony_ciconstexpr const char* CORRESPONDING_TYPE = "corresponding type";
59600cc4afSopenharmony_ciconstexpr const char* FUNCTION_TYPE = "napi_function";
60600cc4afSopenharmony_ciconstexpr const char* CALLBACK = "callback";
61600cc4afSopenharmony_ci// property name
62600cc4afSopenharmony_ciconst char* USER_ID = "userId";
63600cc4afSopenharmony_ciconst char* INSTALL_FLAG = "installFlag";
64600cc4afSopenharmony_ciconst char* IS_KEEP_DATA = "isKeepData";
65600cc4afSopenharmony_ciconst char* CROWD_TEST_DEADLINE = "crowdtestDeadline";
66600cc4afSopenharmony_ciconst char* MODULE_NAME = "moduleName";
67600cc4afSopenharmony_ciconst char* HASH_VALUE = "hashValue";
68600cc4afSopenharmony_ciconst char* HASH_PARAMS = "hashParams";
69600cc4afSopenharmony_ciconst char* BUNDLE_NAME = "bundleName";
70600cc4afSopenharmony_ciconst char* APP_INDEX = "appIndex";
71600cc4afSopenharmony_ciconst char* FILE_PATH = "filePath";
72600cc4afSopenharmony_ciconst char* ADD_EXT_RESOURCE = "AddExtResource";
73600cc4afSopenharmony_ciconst char* REMOVE_EXT_RESOURCE = "RemoveExtResource";
74600cc4afSopenharmony_ciconst char* VERSION_CODE = "versionCode";
75600cc4afSopenharmony_ciconst char* SHARED_BUNDLE_DIR_PATHS = "sharedBundleDirPaths";
76600cc4afSopenharmony_ciconst char* SPECIFIED_DISTRIBUTION_TYPE = "specifiedDistributionType";
77600cc4afSopenharmony_ciconst char* ADDITIONAL_INFO = "additionalInfo";
78600cc4afSopenharmony_ciconst char* VERIFY_CODE_PARAM = "verifyCodeParams";
79600cc4afSopenharmony_ciconst char* SIGNATURE_FILE_PATH = "signatureFilePath";
80600cc4afSopenharmony_ciconst char* PGO_PARAM = "pgoParams";
81600cc4afSopenharmony_ciconst char* PGO_FILE_PATH = "pgoFilePath";
82600cc4afSopenharmony_ciconst char* HAPS_FILE_NEEDED =
83600cc4afSopenharmony_ci    "BusinessError 401: Parameter error. parameter hapFiles is needed for code signature";
84600cc4afSopenharmony_ciconst char* CREATE_APP_CLONE = "CreateAppClone";
85600cc4afSopenharmony_ciconst char* DESTROY_APP_CLONE = "destroyAppClone";
86600cc4afSopenharmony_ciconst char* INSTALL_PREEXISTING_APP = "installPreexistingApp";
87600cc4afSopenharmony_ciconstexpr int32_t FIRST_PARAM = 0;
88600cc4afSopenharmony_ciconstexpr int32_t SECOND_PARAM = 1;
89600cc4afSopenharmony_ci
90600cc4afSopenharmony_ciconstexpr int32_t SPECIFIED_DISTRIBUTION_TYPE_MAX_SIZE = 128;
91600cc4afSopenharmony_ciconstexpr int32_t ADDITIONAL_INFO_MAX_SIZE = 3000;
92600cc4afSopenharmony_ciconstexpr int32_t ILLEGAL_APP_INDEX = -1;
93600cc4afSopenharmony_ci} // namespace
94600cc4afSopenharmony_cinapi_ref thread_local g_classBundleInstaller;
95600cc4afSopenharmony_cibool g_isSystemApp = false;
96600cc4afSopenharmony_ci
97600cc4afSopenharmony_ciAsyncInstallCallbackInfo::~AsyncInstallCallbackInfo()
98600cc4afSopenharmony_ci{
99600cc4afSopenharmony_ci    if (callback) {
100600cc4afSopenharmony_ci        napi_delete_reference(env, callback);
101600cc4afSopenharmony_ci        callback = nullptr;
102600cc4afSopenharmony_ci    }
103600cc4afSopenharmony_ci    if (asyncWork) {
104600cc4afSopenharmony_ci        napi_delete_async_work(env, asyncWork);
105600cc4afSopenharmony_ci        asyncWork = nullptr;
106600cc4afSopenharmony_ci    }
107600cc4afSopenharmony_ci}
108600cc4afSopenharmony_ci
109600cc4afSopenharmony_ciAsyncGetBundleInstallerCallbackInfo::~AsyncGetBundleInstallerCallbackInfo()
110600cc4afSopenharmony_ci{
111600cc4afSopenharmony_ci    if (callback) {
112600cc4afSopenharmony_ci        napi_delete_reference(env, callback);
113600cc4afSopenharmony_ci        callback = nullptr;
114600cc4afSopenharmony_ci    }
115600cc4afSopenharmony_ci    if (asyncWork) {
116600cc4afSopenharmony_ci        napi_delete_async_work(env, asyncWork);
117600cc4afSopenharmony_ci        asyncWork = nullptr;
118600cc4afSopenharmony_ci    }
119600cc4afSopenharmony_ci}
120600cc4afSopenharmony_ci
121600cc4afSopenharmony_civoid GetBundleInstallerCompleted(napi_env env, napi_status status, void *data)
122600cc4afSopenharmony_ci{
123600cc4afSopenharmony_ci    AsyncGetBundleInstallerCallbackInfo *asyncCallbackInfo =
124600cc4afSopenharmony_ci        reinterpret_cast<AsyncGetBundleInstallerCallbackInfo *>(data);
125600cc4afSopenharmony_ci    std::unique_ptr<AsyncGetBundleInstallerCallbackInfo> callbackPtr {asyncCallbackInfo};
126600cc4afSopenharmony_ci
127600cc4afSopenharmony_ci    napi_value m_classBundleInstaller = nullptr;
128600cc4afSopenharmony_ci    NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, g_classBundleInstaller,
129600cc4afSopenharmony_ci        &m_classBundleInstaller));
130600cc4afSopenharmony_ci    napi_value result[CALLBACK_PARAM_SIZE] = {0};
131600cc4afSopenharmony_ci    auto iBundleMgr = CommonFunc::GetBundleMgr();
132600cc4afSopenharmony_ci    if (iBundleMgr == nullptr) {
133600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleMgr");
134600cc4afSopenharmony_ci        return;
135600cc4afSopenharmony_ci    }
136600cc4afSopenharmony_ci    if (!g_isSystemApp && !iBundleMgr->VerifySystemApi(Constants::INVALID_API_VERSION)) {
137600cc4afSopenharmony_ci        APP_LOGE("non-system app calling system api");
138600cc4afSopenharmony_ci        result[0] = BusinessError::CreateCommonError(
139600cc4afSopenharmony_ci            env, ERROR_NOT_SYSTEM_APP, RESOURCE_NAME_OF_GET_BUNDLE_INSTALLER, INSTALL_PERMISSION);
140600cc4afSopenharmony_ci        if (callbackPtr->deferred) {
141600cc4afSopenharmony_ci            NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, asyncCallbackInfo->deferred, result[0]));
142600cc4afSopenharmony_ci        } else {
143600cc4afSopenharmony_ci            napi_value callback = nullptr;
144600cc4afSopenharmony_ci            napi_value placeHolder = nullptr;
145600cc4afSopenharmony_ci            NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, asyncCallbackInfo->callback, &callback));
146600cc4afSopenharmony_ci            NAPI_CALL_RETURN_VOID(env, napi_call_function(env, nullptr, callback,
147600cc4afSopenharmony_ci                sizeof(result) / sizeof(result[0]), result, &placeHolder));
148600cc4afSopenharmony_ci        }
149600cc4afSopenharmony_ci        return;
150600cc4afSopenharmony_ci    }
151600cc4afSopenharmony_ci    g_isSystemApp = true;
152600cc4afSopenharmony_ci    NAPI_CALL_RETURN_VOID(env, napi_new_instance(env, m_classBundleInstaller, 0, nullptr, &result[SECOND_PARAM]));
153600cc4afSopenharmony_ci
154600cc4afSopenharmony_ci    if (callbackPtr->deferred) {
155600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, callbackPtr->deferred, result[SECOND_PARAM]));
156600cc4afSopenharmony_ci    } else {
157600cc4afSopenharmony_ci        napi_value callback = CommonFunc::WrapVoidToJS(env);
158600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, callbackPtr->callback, &callback));
159600cc4afSopenharmony_ci        napi_value undefined = CommonFunc::WrapVoidToJS(env);
160600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined));
161600cc4afSopenharmony_ci        napi_value callResult = CommonFunc::WrapVoidToJS(env);
162600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, CALLBACK_PARAM_SIZE,
163600cc4afSopenharmony_ci            &result[FIRST_PARAM], &callResult));
164600cc4afSopenharmony_ci    }
165600cc4afSopenharmony_ci}
166600cc4afSopenharmony_ci
167600cc4afSopenharmony_ci/**
168600cc4afSopenharmony_ci * Promise and async callback
169600cc4afSopenharmony_ci */
170600cc4afSopenharmony_cinapi_value GetBundleInstaller(napi_env env, napi_callback_info info)
171600cc4afSopenharmony_ci{
172600cc4afSopenharmony_ci    APP_LOGI_NOFUNC("napi GetBundleInstaller called");
173600cc4afSopenharmony_ci    NapiArg args(env, info);
174600cc4afSopenharmony_ci    if (!args.Init(FIRST_PARAM, SECOND_PARAM)) {
175600cc4afSopenharmony_ci        APP_LOGE("GetBundleInstaller args init failed");
176600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
177600cc4afSopenharmony_ci        return nullptr;
178600cc4afSopenharmony_ci    }
179600cc4afSopenharmony_ci    std::unique_ptr<AsyncGetBundleInstallerCallbackInfo> callbackPtr =
180600cc4afSopenharmony_ci        std::make_unique<AsyncGetBundleInstallerCallbackInfo>(env);
181600cc4afSopenharmony_ci
182600cc4afSopenharmony_ci    auto argc = args.GetMaxArgc();
183600cc4afSopenharmony_ci    APP_LOGD("GetBundleInstaller argc = [%{public}zu]", argc);
184600cc4afSopenharmony_ci    // check param
185600cc4afSopenharmony_ci    if (argc == SECOND_PARAM) {
186600cc4afSopenharmony_ci        napi_value arg = args.GetArgv(argc - SECOND_PARAM);
187600cc4afSopenharmony_ci        if (arg == nullptr) {
188600cc4afSopenharmony_ci            APP_LOGE("the param is nullptr");
189600cc4afSopenharmony_ci            BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
190600cc4afSopenharmony_ci            return nullptr;
191600cc4afSopenharmony_ci        }
192600cc4afSopenharmony_ci        napi_valuetype valuetype = napi_undefined;
193600cc4afSopenharmony_ci        NAPI_CALL(env, napi_typeof(env, arg, &valuetype));
194600cc4afSopenharmony_ci        if (valuetype != napi_function) {
195600cc4afSopenharmony_ci            APP_LOGE("the param type is invalid");
196600cc4afSopenharmony_ci            BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, CALLBACK, FUNCTION_TYPE);
197600cc4afSopenharmony_ci            return nullptr;
198600cc4afSopenharmony_ci        }
199600cc4afSopenharmony_ci        NAPI_CALL(env, napi_create_reference(env, arg, NAPI_RETURN_ONE, &callbackPtr->callback));
200600cc4afSopenharmony_ci    }
201600cc4afSopenharmony_ci
202600cc4afSopenharmony_ci    auto executeFunc = [](napi_env env, void *data) {};
203600cc4afSopenharmony_ci    napi_value promise = CommonFunc::AsyncCallNativeMethod(
204600cc4afSopenharmony_ci        env,
205600cc4afSopenharmony_ci        callbackPtr.get(),
206600cc4afSopenharmony_ci        RESOURCE_NAME_OF_GET_BUNDLE_INSTALLER,
207600cc4afSopenharmony_ci        executeFunc,
208600cc4afSopenharmony_ci        GetBundleInstallerCompleted);
209600cc4afSopenharmony_ci    callbackPtr.release();
210600cc4afSopenharmony_ci    APP_LOGI_NOFUNC("call GetBundleInstaller done");
211600cc4afSopenharmony_ci    return promise;
212600cc4afSopenharmony_ci}
213600cc4afSopenharmony_ci
214600cc4afSopenharmony_cinapi_value GetBundleInstallerSync(napi_env env, napi_callback_info info)
215600cc4afSopenharmony_ci{
216600cc4afSopenharmony_ci    APP_LOGI("NAPI GetBundleInstallerSync called");
217600cc4afSopenharmony_ci    napi_value m_classBundleInstaller = nullptr;
218600cc4afSopenharmony_ci    NAPI_CALL(env, napi_get_reference_value(env, g_classBundleInstaller,
219600cc4afSopenharmony_ci        &m_classBundleInstaller));
220600cc4afSopenharmony_ci    auto iBundleMgr = CommonFunc::GetBundleMgr();
221600cc4afSopenharmony_ci    if (iBundleMgr == nullptr) {
222600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleMgr");
223600cc4afSopenharmony_ci        return nullptr;
224600cc4afSopenharmony_ci    }
225600cc4afSopenharmony_ci    if (!g_isSystemApp && !iBundleMgr->VerifySystemApi(Constants::INVALID_API_VERSION)) {
226600cc4afSopenharmony_ci        APP_LOGE("non-system app calling system api");
227600cc4afSopenharmony_ci        napi_value businessError = BusinessError::CreateCommonError(
228600cc4afSopenharmony_ci            env, ERROR_NOT_SYSTEM_APP, RESOURCE_NAME_OF_GET_BUNDLE_INSTALLER_SYNC, INSTALL_PERMISSION);
229600cc4afSopenharmony_ci        napi_throw(env, businessError);
230600cc4afSopenharmony_ci        return nullptr;
231600cc4afSopenharmony_ci    }
232600cc4afSopenharmony_ci    g_isSystemApp = true;
233600cc4afSopenharmony_ci    napi_value nBundleInstaller = nullptr;
234600cc4afSopenharmony_ci    NAPI_CALL(env, napi_new_instance(env, m_classBundleInstaller, 0, nullptr, &nBundleInstaller));
235600cc4afSopenharmony_ci    APP_LOGD("call GetBundleInstallerSync done");
236600cc4afSopenharmony_ci    return nBundleInstaller;
237600cc4afSopenharmony_ci    APP_LOGI("call GetBundleInstallerSync done");
238600cc4afSopenharmony_ci}
239600cc4afSopenharmony_ci
240600cc4afSopenharmony_cistatic void CreateErrCodeMap(std::unordered_map<int32_t, int32_t> &errCodeMap)
241600cc4afSopenharmony_ci{
242600cc4afSopenharmony_ci    errCodeMap = {
243600cc4afSopenharmony_ci        { IStatusReceiver::SUCCESS, SUCCESS},
244600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR, ERROR_BUNDLE_SERVICE_EXCEPTION },
245600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_HOST_INSTALLER_FAILED, ERROR_BUNDLE_SERVICE_EXCEPTION },
246600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALLD_PARAM_ERROR, ERROR_BUNDLE_SERVICE_EXCEPTION },
247600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALLD_GET_PROXY_ERROR, ERROR_BUNDLE_SERVICE_EXCEPTION },
248600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_INSTALLD_SERVICE_ERROR, ERROR_BUNDLE_SERVICE_EXCEPTION },
249600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR, ERROR_BUNDLE_SERVICE_EXCEPTION },
250600cc4afSopenharmony_ci        { IStatusReceiver::ERR_FAILED_SERVICE_DIED, ERROR_BUNDLE_SERVICE_EXCEPTION },
251600cc4afSopenharmony_ci        { IStatusReceiver::ERR_FAILED_GET_INSTALLER_PROXY, ERROR_BUNDLE_SERVICE_EXCEPTION },
252600cc4afSopenharmony_ci        { IStatusReceiver::ERR_USER_CREATE_FAILED, ERROR_BUNDLE_SERVICE_EXCEPTION },
253600cc4afSopenharmony_ci        { IStatusReceiver::ERR_USER_REMOVE_FAILED, ERROR_BUNDLE_SERVICE_EXCEPTION },
254600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_KILLING_APP_ERROR, ERROR_BUNDLE_SERVICE_EXCEPTION },
255600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_GENERATE_UID_ERROR, ERROR_BUNDLE_SERVICE_EXCEPTION },
256600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_STATE_ERROR, ERROR_BUNDLE_SERVICE_EXCEPTION },
257600cc4afSopenharmony_ci        { IStatusReceiver::ERR_RECOVER_NOT_ALLOWED, ERROR_BUNDLE_SERVICE_EXCEPTION },
258600cc4afSopenharmony_ci        { IStatusReceiver::ERR_RECOVER_GET_BUNDLEPATH_ERROR, ERROR_BUNDLE_SERVICE_EXCEPTION },
259600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_AND_RECOVER_NOT_PREINSTALLED_BUNDLE, ERROR_BUNDLE_NOT_PREINSTALLED },
260600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_SYSTEM_APP_ERROR, ERROR_UNINSTALL_PREINSTALL_APP_FAILED },
261600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_FAILED, ERROR_INSTALL_PARSE_FAILED },
262600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_UNEXPECTED, ERROR_INSTALL_PARSE_FAILED },
263600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_MISSING_BUNDLE, ERROR_INSTALL_PARSE_FAILED },
264600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_NO_PROFILE, ERROR_INSTALL_PARSE_FAILED },
265600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_BAD_PROFILE, ERROR_INSTALL_PARSE_FAILED },
266600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_PROFILE_PROP_TYPE_ERROR, ERROR_INSTALL_PARSE_FAILED },
267600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_PROFILE_MISSING_PROP, ERROR_INSTALL_PARSE_FAILED },
268600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_PERMISSION_ERROR, ERROR_INSTALL_PARSE_FAILED },
269600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_PROFILE_PROP_CHECK_ERROR, ERROR_INSTALL_PARSE_FAILED },
270600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_RPCID_FAILED, ERROR_INSTALL_PARSE_FAILED },
271600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_NATIVE_SO_FAILED, ERROR_INSTALL_PARSE_FAILED },
272600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_AN_FAILED, ERROR_INSTALL_PARSE_FAILED },
273600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_MISSING_ABILITY, ERROR_INSTALL_PARSE_FAILED },
274600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_PROFILE_PARSE_FAIL, ERROR_INSTALL_PARSE_FAILED },
275600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_VERIFICATION_FAILED, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
276600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_INCOMPATIBLE_SIGNATURE, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
277600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_INVALID_SIGNATURE_FILE_PATH, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
278600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_BAD_BUNDLE_SIGNATURE_FILE, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
279600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_NO_BUNDLE_SIGNATURE, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
280600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_VERIFY_APP_PKCS7_FAIL, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
281600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_APP_SOURCE_NOT_TRUESTED, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
282600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_BAD_DIGEST, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
283600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_BUNDLE_INTEGRITY_VERIFICATION_FAILURE,
284600cc4afSopenharmony_ci            ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
285600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_BAD_PUBLICKEY, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
286600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_BAD_BUNDLE_SIGNATURE, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
287600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_NO_PROFILE_BLOCK_FAIL, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
288600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_BUNDLE_SIGNATURE_VERIFICATION_FAILURE,
289600cc4afSopenharmony_ci            ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
290600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_VERIFY_SOURCE_INIT_FAIL, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
291600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_SINGLETON_INCOMPATIBLE, ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
292600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_INCONSISTENT_SIGNATURE, ERROR_INSTALL_FAILED_INCONSISTENT_SIGNATURE },
293600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARAM_ERROR, ERROR_BUNDLE_NOT_EXIST },
294600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_PARAM_ERROR, ERROR_BUNDLE_NOT_EXIST },
295600cc4afSopenharmony_ci        { IStatusReceiver::ERR_RECOVER_INVALID_BUNDLE_NAME, ERROR_BUNDLE_NOT_EXIST },
296600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_INVALID_NAME, ERROR_BUNDLE_NOT_EXIST },
297600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_INVALID_BUNDLE_FILE, ERROR_INSTALL_HAP_FILEPATH_INVALID },
298600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_MODULE_NAME_EMPTY, ERROR_MODULE_NOT_EXIST },
299600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_MODULE_NAME_DUPLICATE, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
300600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_CHECK_HAP_HASH_PARAM, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
301600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_MISSING_INSTALLED_BUNDLE, ERROR_BUNDLE_NOT_EXIST },
302600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_MISSING_INSTALLED_MODULE, ERROR_MODULE_NOT_EXIST },
303600cc4afSopenharmony_ci        { IStatusReceiver::ERR_USER_NOT_INSTALL_HAP, ERROR_BUNDLE_NOT_EXIST },
304600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FILE_PATH_INVALID, ERROR_INSTALL_HAP_FILEPATH_INVALID },
305600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PERMISSION_DENIED, ERROR_PERMISSION_DENIED_ERROR },
306600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_PERMISSION_DENIED, ERROR_PERMISSION_DENIED_ERROR },
307600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_GRANT_REQUEST_PERMISSIONS_FAILED, ERROR_INSTALL_PERMISSION_CHECK_ERROR },
308600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_UPDATE_HAP_TOKEN_FAILED, ERROR_INSTALL_PERMISSION_CHECK_ERROR },
309600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALLD_CREATE_DIR_FAILED, ERROR_BUNDLE_SERVICE_EXCEPTION },
310600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALLD_CHOWN_FAILED, ERROR_BUNDLE_SERVICE_EXCEPTION },
311600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALLD_CREATE_DIR_EXIST, ERROR_BUNDLE_SERVICE_EXCEPTION },
312600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALLD_REMOVE_DIR_FAILED, ERROR_BUNDLE_SERVICE_EXCEPTION },
313600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALLD_EXTRACT_FILES_FAILED, ERROR_BUNDLE_SERVICE_EXCEPTION },
314600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALLD_RNAME_DIR_FAILED, ERROR_BUNDLE_SERVICE_EXCEPTION },
315600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALLD_CLEAN_DIR_FAILED, ERROR_BUNDLE_SERVICE_EXCEPTION },
316600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_ENTRY_ALREADY_EXIST, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
317600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_ALREADY_EXIST, ERROR_INSTALL_ALREADY_EXIST },
318600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_BUNDLENAME_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
319600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_VERSIONCODE_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
320600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_VERSIONNAME_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
321600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_MINCOMPATIBLE_VERSIONCODE_NOT_SAME,
322600cc4afSopenharmony_ci            ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
323600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_VENDOR_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
324600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_RELEASETYPE_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
325600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_RELEASETYPE_TARGET_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
326600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_RELEASETYPE_COMPATIBLE_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
327600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_SINGLETON_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
328600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_ZERO_USER_WITH_NO_SINGLETON, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
329600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_CHECK_SYSCAP_FAILED, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
330600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_APPTYPE_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
331600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_URI_DUPLICATE, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
332600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_VERSION_NOT_COMPATIBLE, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
333600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_APP_DISTRIBUTION_TYPE_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
334600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_APP_PROVISION_TYPE_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
335600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_SO_INCOMPATIBLE, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
336600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_AN_INCOMPATIBLE, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
337600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_TYPE_ERROR, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
338600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_TYPE_ERROR, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
339600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_NOT_UNIQUE_DISTRO_MODULE_NAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
340600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_INCONSISTENT_MODULE_NAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
341600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_INVALID_NUMBER_OF_ENTRY_HAP, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
342600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_ASAN_ENABLED_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
343600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_ASAN_ENABLED_NOT_SUPPORT, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT},
344600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_BUNDLE_TYPE_NOT_SAME, ERROR_INSTALL_PARSE_FAILED},
345600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_DISK_MEM_INSUFFICIENT, ERROR_INSTALL_NO_DISK_SPACE_LEFT },
346600cc4afSopenharmony_ci        { IStatusReceiver::ERR_USER_NOT_EXIST, ERROR_INVALID_USER_ID },
347600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_VERSION_DOWNGRADE, ERROR_INSTALL_VERSION_DOWNGRADE },
348600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_DEVICE_TYPE_NOT_SUPPORTED, ERROR_INSTALL_PARSE_FAILED },
349600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_CHECK_SYSCAP_FAILED_AND_DEVICE_TYPE_NOT_SUPPORTED, ERROR_INSTALL_PARSE_FAILED },
350600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_PARSE_PROFILE_PROP_SIZE_CHECK_ERROR, ERROR_INSTALL_PARSE_FAILED },
351600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_DEPENDENT_MODULE_NOT_EXIST, ERROR_INSTALL_DEPENDENT_MODULE_NOT_EXIST },
352600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_SHARE_APP_LIBRARY_NOT_ALLOWED, ERROR_INSTALL_SHARE_APP_LIBRARY_NOT_ALLOWED },
353600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_COMPATIBLE_POLICY_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
354600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FILE_IS_SHARED_LIBRARY, ERROR_INSTALL_FILE_IS_SHARED_LIBRARY },
355600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_INTERNAL_ERROR, ERROR_BUNDLE_SERVICE_EXCEPTION },
356600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_INVALID_BUNDLE_NAME, ERROR_BUNDLE_NOT_EXIST },
357600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_INVALID_MODULE_NAME, ERROR_MODULE_NOT_EXIST},
358600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_ERROR_HAP_TYPE, ERROR_INVALID_TYPE },
359600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_ERROR_BUNDLE_TYPE, ERROR_INVALID_TYPE },
360600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_TARGET_BUNDLE_NAME_MISSED, ERROR_INSTALL_PARSE_FAILED },
361600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_TARGET_MODULE_NAME_MISSED, ERROR_INSTALL_PARSE_FAILED },
362600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_TARGET_BUNDLE_NAME_NOT_SAME,
363600cc4afSopenharmony_ci            ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
364600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_INTERNAL_EXTERNAL_OVERLAY_EXISTED_SIMULTANEOUSLY,
365600cc4afSopenharmony_ci            ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
366600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_TARGET_PRIORITY_NOT_SAME,
367600cc4afSopenharmony_ci            ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
368600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_INVALID_PRIORITY, ERROR_INSTALL_PARSE_FAILED },
369600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_INCONSISTENT_VERSION_CODE,
370600cc4afSopenharmony_ci            ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
371600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_SERVICE_EXCEPTION, ERROR_BUNDLE_SERVICE_EXCEPTION },
372600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_BUNDLE_NAME_SAME_WITH_TARGET_BUNDLE_NAME,
373600cc4afSopenharmony_ci            ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT},
374600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_NO_SYSTEM_APPLICATION_FOR_EXTERNAL_OVERLAY,
375600cc4afSopenharmony_ci            ERROR_INSTALL_HAP_OVERLAY_CHECK_FAILED },
376600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_DIFFERENT_SIGNATURE_CERTIFICATE,
377600cc4afSopenharmony_ci            ERROR_INSTALL_VERIFY_SIGNATURE_FAILED },
378600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_TARGET_BUNDLE_IS_OVERLAY_BUNDLE,
379600cc4afSopenharmony_ci            ERROR_INSTALL_HAP_OVERLAY_CHECK_FAILED },
380600cc4afSopenharmony_ci        {IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_TARGET_MODULE_IS_OVERLAY_MODULE,
381600cc4afSopenharmony_ci            ERROR_INSTALL_HAP_OVERLAY_CHECK_FAILED },
382600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_OVERLAY_TYPE_NOT_SAME,
383600cc4afSopenharmony_ci            ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
384600cc4afSopenharmony_ci        { IStatusReceiver::ERR_OVERLAY_INSTALLATION_FAILED_INVALID_BUNDLE_DIR, ERROR_BUNDLE_SERVICE_EXCEPTION },
385600cc4afSopenharmony_ci        { IStatusReceiver::ERR_APPEXECFWK_UNINSTALL_SHARE_APP_LIBRARY_IS_NOT_EXIST,
386600cc4afSopenharmony_ci            ERROR_UNINSTALL_SHARE_APP_LIBRARY_IS_NOT_EXIST},
387600cc4afSopenharmony_ci        { IStatusReceiver::ERR_APPEXECFWK_UNINSTALL_SHARE_APP_LIBRARY_IS_RELIED,
388600cc4afSopenharmony_ci            ERROR_UNINSTALL_SHARE_APP_LIBRARY_IS_RELIED},
389600cc4afSopenharmony_ci        { IStatusReceiver::ERR_APPEXECFWK_UNINSTALL_BUNDLE_IS_SHARED_LIBRARY,
390600cc4afSopenharmony_ci            ERROR_UNINSTALL_BUNDLE_IS_SHARED_BUNDLE},
391600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSATLL_CHECK_PROXY_DATA_URI_FAILED,
392600cc4afSopenharmony_ci            ERROR_INSTALL_WRONG_DATA_PROXY_URI},
393600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSATLL_CHECK_PROXY_DATA_PERMISSION_FAILED,
394600cc4afSopenharmony_ci            ERROR_INSTALL_WRONG_DATA_PROXY_PERMISSION},
395600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_FAILED_DEBUG_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT },
396600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_DISALLOWED, ERROR_DISALLOW_INSTALL},
397600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_ISOLATION_MODE_FAILED, ERROR_INSTALL_WRONG_MODE_ISOLATION },
398600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_DISALLOWED, ERROR_DISALLOW_UNINSTALL },
399600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_CODE_SIGNATURE_FAILED, ERROR_INSTALL_CODE_SIGNATURE_FAILED },
400600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_CODE_SIGNATURE_FILE_IS_INVALID, ERROR_INSTALL_CODE_SIGNATURE_FAILED},
401600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_FROM_BMS_EXTENSION_FAILED, ERROR_BUNDLE_NOT_EXIST},
402600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_SELF_UPDATE_NOT_MDM, ERROR_INSTALL_SELF_UPDATE_NOT_MDM},
403600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_ENTERPRISE_BUNDLE_NOT_ALLOWED, ERROR_INSTALL_ENTERPRISE_BUNDLE_NOT_ALLOWED},
404600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_EXISTED_ENTERPRISE_BUNDLE_NOT_ALLOWED,
405600cc4afSopenharmony_ci            ERROR_INSTALL_EXISTED_ENTERPRISE_NOT_ALLOWED_ERROR},
406600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_SELF_UPDATE_BUNDLENAME_NOT_SAME, ERROR_INSTALL_SELF_UPDATE_BUNDLENAME_NOT_SAME},
407600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_GWP_ASAN_ENABLED_NOT_SAME, ERROR_INSTALL_MULTIPLE_HAP_INFO_INCONSISTENT},
408600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_DEBUG_BUNDLE_NOT_ALLOWED, ERROR_INSTALL_DEBUG_BUNDLE_NOT_ALLOWED},
409600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_CHECK_ENCRYPTION_FAILED, ERROR_INSTALL_CODE_SIGNATURE_FAILED },
410600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_CODE_SIGNATURE_DELIVERY_FILE_FAILED, ERROR_INSTALL_CODE_SIGNATURE_FAILED},
411600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_CODE_SIGNATURE_REMOVE_FILE_FAILED, ERROR_INSTALL_CODE_SIGNATURE_FAILED},
412600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_CODE_APP_CONTROLLED_FAILED, ERROR_INSTALL_FAILED_CONTROLLED},
413600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_NATIVE_FAILED, ERROR_INSTALL_NATIVE_FAILED},
414600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_NATIVE_FAILED, ERROR_UNINSTALL_NATIVE_FAILED},
415600cc4afSopenharmony_ci        { IStatusReceiver::ERR_NATIVE_HNP_EXTRACT_FAILED, ERROR_INSTALL_NATIVE_FAILED},
416600cc4afSopenharmony_ci        { IStatusReceiver::ERR_UNINSTALL_CONTROLLED, ERROR_BUNDLE_CAN_NOT_BE_UNINSTALLED },
417600cc4afSopenharmony_ci        { IStatusReceiver::ERR_INSTALL_DEBUG_ENCRYPTED_BUNDLE_FAILED, ERROR_INSTALL_PARSE_FAILED }
418600cc4afSopenharmony_ci    };
419600cc4afSopenharmony_ci}
420600cc4afSopenharmony_ci
421600cc4afSopenharmony_cistatic void ConvertInstallResult(InstallResult &installResult)
422600cc4afSopenharmony_ci{
423600cc4afSopenharmony_ci    APP_LOGD("ConvertInstallResult msg %{public}s, errCode is %{public}d", installResult.resultMsg.c_str(),
424600cc4afSopenharmony_ci        installResult.resultCode);
425600cc4afSopenharmony_ci    std::unordered_map<int32_t, int32_t> errCodeMap;
426600cc4afSopenharmony_ci    CreateErrCodeMap(errCodeMap);
427600cc4afSopenharmony_ci    auto iter = errCodeMap.find(installResult.resultCode);
428600cc4afSopenharmony_ci    if (iter != errCodeMap.end()) {
429600cc4afSopenharmony_ci        installResult.resultCode = iter->second;
430600cc4afSopenharmony_ci        return;
431600cc4afSopenharmony_ci    }
432600cc4afSopenharmony_ci    installResult.resultCode = ERROR_BUNDLE_SERVICE_EXCEPTION;
433600cc4afSopenharmony_ci}
434600cc4afSopenharmony_ci
435600cc4afSopenharmony_cistatic bool ParseHashParam(napi_env env, napi_value args, std::string &key, std::string &value)
436600cc4afSopenharmony_ci{
437600cc4afSopenharmony_ci    APP_LOGD("start to parse moduleName");
438600cc4afSopenharmony_ci    bool ret = CommonFunc::ParseStringPropertyFromObject(env, args, MODULE_NAME, true, key);
439600cc4afSopenharmony_ci    if (!ret || key.empty()) {
440600cc4afSopenharmony_ci        APP_LOGE("param string moduleName is empty");
441600cc4afSopenharmony_ci        return false;
442600cc4afSopenharmony_ci    }
443600cc4afSopenharmony_ci    APP_LOGD("ParseHashParam moduleName=%{public}s", key.c_str());
444600cc4afSopenharmony_ci
445600cc4afSopenharmony_ci    APP_LOGD("start to parse hashValue");
446600cc4afSopenharmony_ci    ret = CommonFunc::ParseStringPropertyFromObject(env, args, HASH_VALUE, true, value);
447600cc4afSopenharmony_ci    if (!ret || value.empty()) {
448600cc4afSopenharmony_ci        APP_LOGE("param string hashValue is empty");
449600cc4afSopenharmony_ci        return false;
450600cc4afSopenharmony_ci    }
451600cc4afSopenharmony_ci    APP_LOGD("ParseHashParam hashValue=%{public}s", value.c_str());
452600cc4afSopenharmony_ci    return true;
453600cc4afSopenharmony_ci}
454600cc4afSopenharmony_ci
455600cc4afSopenharmony_cistatic bool ParseHashParams(napi_env env, napi_value args, std::map<std::string, std::string> &hashParams)
456600cc4afSopenharmony_ci{
457600cc4afSopenharmony_ci    APP_LOGD("start to parse hashParams");
458600cc4afSopenharmony_ci    std::vector<napi_value> valueVec;
459600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyArray(env, args, HASH_PARAMS, valueVec);
460600cc4afSopenharmony_ci    if (!res) {
461600cc4afSopenharmony_ci        APP_LOGW("hashParams type error,using default value");
462600cc4afSopenharmony_ci        return true;
463600cc4afSopenharmony_ci    }
464600cc4afSopenharmony_ci    if (valueVec.empty()) {
465600cc4afSopenharmony_ci        APP_LOGW("hashParams is empty,using default value");
466600cc4afSopenharmony_ci        return true;
467600cc4afSopenharmony_ci    }
468600cc4afSopenharmony_ci    for (const auto &property : valueVec) {
469600cc4afSopenharmony_ci        std::string key;
470600cc4afSopenharmony_ci        std::string value;
471600cc4afSopenharmony_ci        if (!ParseHashParam(env, property, key, value)) {
472600cc4afSopenharmony_ci            APP_LOGE("parse hash param failed");
473600cc4afSopenharmony_ci            return false;
474600cc4afSopenharmony_ci        }
475600cc4afSopenharmony_ci        if (hashParams.find(key) != hashParams.end()) {
476600cc4afSopenharmony_ci            APP_LOGE("moduleName(%{public}s) is duplicate", key.c_str());
477600cc4afSopenharmony_ci            return false;
478600cc4afSopenharmony_ci        }
479600cc4afSopenharmony_ci        hashParams.emplace(key, value);
480600cc4afSopenharmony_ci    }
481600cc4afSopenharmony_ci    return true;
482600cc4afSopenharmony_ci}
483600cc4afSopenharmony_ci
484600cc4afSopenharmony_cistatic bool ParseVerifyCodeParam(napi_env env, napi_value args, std::string &key, std::string &value)
485600cc4afSopenharmony_ci{
486600cc4afSopenharmony_ci    APP_LOGD("start to parse moduleName");
487600cc4afSopenharmony_ci    bool ret = CommonFunc::ParseStringPropertyFromObject(env, args, MODULE_NAME, true, key);
488600cc4afSopenharmony_ci    if (!ret || key.empty()) {
489600cc4afSopenharmony_ci        APP_LOGE("param string moduleName is empty");
490600cc4afSopenharmony_ci        return false;
491600cc4afSopenharmony_ci    }
492600cc4afSopenharmony_ci    APP_LOGD("ParseVerifyCodeParam moduleName is %{public}s", key.c_str());
493600cc4afSopenharmony_ci
494600cc4afSopenharmony_ci    APP_LOGD("start to parse signatureFilePath");
495600cc4afSopenharmony_ci    ret = CommonFunc::ParseStringPropertyFromObject(env, args, SIGNATURE_FILE_PATH, true, value);
496600cc4afSopenharmony_ci    if (!ret || value.empty()) {
497600cc4afSopenharmony_ci        APP_LOGE("param string signatureFilePath is empty");
498600cc4afSopenharmony_ci        return false;
499600cc4afSopenharmony_ci    }
500600cc4afSopenharmony_ci    APP_LOGD("ParseVerifyCodeParam signatureFilePath is %{public}s", value.c_str());
501600cc4afSopenharmony_ci    return true;
502600cc4afSopenharmony_ci}
503600cc4afSopenharmony_ci
504600cc4afSopenharmony_cistatic bool ParseVerifyCodeParams(napi_env env, napi_value args, std::map<std::string, std::string> &verifyCodeParams)
505600cc4afSopenharmony_ci{
506600cc4afSopenharmony_ci    APP_LOGD("start to parse verifyCodeParams");
507600cc4afSopenharmony_ci    std::vector<napi_value> valueVec;
508600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyArray(env, args, VERIFY_CODE_PARAM, valueVec);
509600cc4afSopenharmony_ci    if (!res) {
510600cc4afSopenharmony_ci        APP_LOGW("verifyCodeParams type error, using default value");
511600cc4afSopenharmony_ci        return true;
512600cc4afSopenharmony_ci    }
513600cc4afSopenharmony_ci    if (valueVec.empty()) {
514600cc4afSopenharmony_ci        APP_LOGW("verifyCodeParams is empty, using default value");
515600cc4afSopenharmony_ci        return true;
516600cc4afSopenharmony_ci    }
517600cc4afSopenharmony_ci    for (const auto &property : valueVec) {
518600cc4afSopenharmony_ci        std::string key;
519600cc4afSopenharmony_ci        std::string value;
520600cc4afSopenharmony_ci        if (!ParseVerifyCodeParam(env, property, key, value)) {
521600cc4afSopenharmony_ci            APP_LOGE("parse verify code param failed");
522600cc4afSopenharmony_ci            return false;
523600cc4afSopenharmony_ci        }
524600cc4afSopenharmony_ci        if (verifyCodeParams.find(key) != verifyCodeParams.end()) {
525600cc4afSopenharmony_ci            APP_LOGE("moduleName(%{public}s) is duplicate", key.c_str());
526600cc4afSopenharmony_ci            return false;
527600cc4afSopenharmony_ci        }
528600cc4afSopenharmony_ci        verifyCodeParams.emplace(key, value);
529600cc4afSopenharmony_ci    }
530600cc4afSopenharmony_ci    return true;
531600cc4afSopenharmony_ci}
532600cc4afSopenharmony_ci
533600cc4afSopenharmony_cistatic bool ParsePgoParam(napi_env env, napi_value args, std::string &key, std::string &value)
534600cc4afSopenharmony_ci{
535600cc4afSopenharmony_ci    APP_LOGD("start to parse moduleName");
536600cc4afSopenharmony_ci    bool ret = CommonFunc::ParseStringPropertyFromObject(env, args, MODULE_NAME, true, key);
537600cc4afSopenharmony_ci    if (!ret || key.empty()) {
538600cc4afSopenharmony_ci        APP_LOGE("param string moduleName is empty");
539600cc4afSopenharmony_ci        return false;
540600cc4afSopenharmony_ci    }
541600cc4afSopenharmony_ci    APP_LOGD("ParsePgoParam moduleName is %{public}s", key.c_str());
542600cc4afSopenharmony_ci
543600cc4afSopenharmony_ci    APP_LOGD("start to parse pgoFilePath");
544600cc4afSopenharmony_ci    ret = CommonFunc::ParseStringPropertyFromObject(env, args, PGO_FILE_PATH, true, value);
545600cc4afSopenharmony_ci    if (!ret || value.empty()) {
546600cc4afSopenharmony_ci        APP_LOGE("param string pgoFilePath is empty");
547600cc4afSopenharmony_ci        return false;
548600cc4afSopenharmony_ci    }
549600cc4afSopenharmony_ci    APP_LOGD("ParsePgoParam pgoFilePath is %{public}s", value.c_str());
550600cc4afSopenharmony_ci    return true;
551600cc4afSopenharmony_ci}
552600cc4afSopenharmony_ci
553600cc4afSopenharmony_cistatic bool ParsePgoParams(napi_env env, napi_value args, std::map<std::string, std::string> &pgoParams)
554600cc4afSopenharmony_ci{
555600cc4afSopenharmony_ci    APP_LOGD("start to parse pgoParams");
556600cc4afSopenharmony_ci    std::vector<napi_value> valueVec;
557600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyArray(env, args, PGO_PARAM, valueVec);
558600cc4afSopenharmony_ci    if (!res) {
559600cc4afSopenharmony_ci        APP_LOGW("pgoParams type error, using default value");
560600cc4afSopenharmony_ci        return true;
561600cc4afSopenharmony_ci    }
562600cc4afSopenharmony_ci    if (valueVec.empty()) {
563600cc4afSopenharmony_ci        APP_LOGW("pgoParams is empty, using default value");
564600cc4afSopenharmony_ci        return true;
565600cc4afSopenharmony_ci    }
566600cc4afSopenharmony_ci    for (const auto &property : valueVec) {
567600cc4afSopenharmony_ci        std::string key;
568600cc4afSopenharmony_ci        std::string value;
569600cc4afSopenharmony_ci        if (!ParsePgoParam(env, property, key, value)) {
570600cc4afSopenharmony_ci            APP_LOGW("parse pgo param failed");
571600cc4afSopenharmony_ci            continue;
572600cc4afSopenharmony_ci        }
573600cc4afSopenharmony_ci        pgoParams.emplace(key, value);
574600cc4afSopenharmony_ci    }
575600cc4afSopenharmony_ci    return true;
576600cc4afSopenharmony_ci}
577600cc4afSopenharmony_ci
578600cc4afSopenharmony_cistatic bool ParseBundleName(napi_env env, napi_value args, std::string &bundleName)
579600cc4afSopenharmony_ci{
580600cc4afSopenharmony_ci    APP_LOGD("start to parse bundleName");
581600cc4afSopenharmony_ci    PropertyInfo propertyInfo = {
582600cc4afSopenharmony_ci        .propertyName = BUNDLE_NAME,
583600cc4afSopenharmony_ci        .isNecessary = true,
584600cc4afSopenharmony_ci        .propertyType = napi_string
585600cc4afSopenharmony_ci    };
586600cc4afSopenharmony_ci    napi_value property = nullptr;
587600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyFromObject(env, args, propertyInfo, property);
588600cc4afSopenharmony_ci    if (!res) {
589600cc4afSopenharmony_ci        APP_LOGE("parse bundleName failed, bundleName is %{public}s", bundleName.c_str());
590600cc4afSopenharmony_ci        return res;
591600cc4afSopenharmony_ci    }
592600cc4afSopenharmony_ci    if (property != nullptr) {
593600cc4afSopenharmony_ci        if (!CommonFunc::ParseString(env, property, bundleName)) {
594600cc4afSopenharmony_ci            APP_LOGE("ParseString failed");
595600cc4afSopenharmony_ci            return false;
596600cc4afSopenharmony_ci        }
597600cc4afSopenharmony_ci    }
598600cc4afSopenharmony_ci    APP_LOGD("param bundleName is %{public}s", bundleName.c_str());
599600cc4afSopenharmony_ci    return true;
600600cc4afSopenharmony_ci}
601600cc4afSopenharmony_ci
602600cc4afSopenharmony_cistatic bool ParseModuleName(napi_env env, napi_value args, std::string &moduleName)
603600cc4afSopenharmony_ci{
604600cc4afSopenharmony_ci    APP_LOGD("start to parse moduleName");
605600cc4afSopenharmony_ci    PropertyInfo propertyInfo = {
606600cc4afSopenharmony_ci        .propertyName = MODULE_NAME,
607600cc4afSopenharmony_ci        .isNecessary = false,
608600cc4afSopenharmony_ci        .propertyType = napi_string
609600cc4afSopenharmony_ci    };
610600cc4afSopenharmony_ci    napi_value property = nullptr;
611600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyFromObject(env, args, propertyInfo, property);
612600cc4afSopenharmony_ci    if (!res) {
613600cc4afSopenharmony_ci        APP_LOGE("parse moduleName failed");
614600cc4afSopenharmony_ci        return res;
615600cc4afSopenharmony_ci    }
616600cc4afSopenharmony_ci    if (property != nullptr) {
617600cc4afSopenharmony_ci        if (!CommonFunc::ParseString(env, property, moduleName)) {
618600cc4afSopenharmony_ci            APP_LOGE("ParseString failed");
619600cc4afSopenharmony_ci            return false;
620600cc4afSopenharmony_ci        }
621600cc4afSopenharmony_ci    }
622600cc4afSopenharmony_ci    return true;
623600cc4afSopenharmony_ci}
624600cc4afSopenharmony_ci
625600cc4afSopenharmony_cistatic bool ParseVersionCode(napi_env env, napi_value args, int32_t &versionCode)
626600cc4afSopenharmony_ci{
627600cc4afSopenharmony_ci    APP_LOGD("start to parse versionCode");
628600cc4afSopenharmony_ci    PropertyInfo propertyInfo = {
629600cc4afSopenharmony_ci        .propertyName = VERSION_CODE,
630600cc4afSopenharmony_ci        .isNecessary = false,
631600cc4afSopenharmony_ci        .propertyType = napi_number
632600cc4afSopenharmony_ci    };
633600cc4afSopenharmony_ci    napi_value property = nullptr;
634600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyFromObject(env, args, propertyInfo, property);
635600cc4afSopenharmony_ci    if (!res) {
636600cc4afSopenharmony_ci        APP_LOGE("parse versionCode failed");
637600cc4afSopenharmony_ci        return res;
638600cc4afSopenharmony_ci    }
639600cc4afSopenharmony_ci    if (property != nullptr) {
640600cc4afSopenharmony_ci        PARSE_PROPERTY(env, property, int32, versionCode);
641600cc4afSopenharmony_ci    }
642600cc4afSopenharmony_ci    APP_LOGD("param versionCode is %{public}d", versionCode);
643600cc4afSopenharmony_ci    return true;
644600cc4afSopenharmony_ci}
645600cc4afSopenharmony_ci
646600cc4afSopenharmony_cistatic bool ParseUserId(napi_env env, napi_value args, int32_t &userId)
647600cc4afSopenharmony_ci{
648600cc4afSopenharmony_ci    APP_LOGD("start to parse userId");
649600cc4afSopenharmony_ci    PropertyInfo propertyInfo = {
650600cc4afSopenharmony_ci        .propertyName = USER_ID,
651600cc4afSopenharmony_ci        .isNecessary = false,
652600cc4afSopenharmony_ci        .propertyType = napi_number
653600cc4afSopenharmony_ci    };
654600cc4afSopenharmony_ci    napi_value property = nullptr;
655600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyFromObject(env, args, propertyInfo, property);
656600cc4afSopenharmony_ci    if (!res) {
657600cc4afSopenharmony_ci        APP_LOGE("parse userId failed");
658600cc4afSopenharmony_ci        return res;
659600cc4afSopenharmony_ci    }
660600cc4afSopenharmony_ci    if (property != nullptr) {
661600cc4afSopenharmony_ci        PARSE_PROPERTY(env, property, int32, userId);
662600cc4afSopenharmony_ci    }
663600cc4afSopenharmony_ci    APP_LOGD("param userId is %{public}d", userId);
664600cc4afSopenharmony_ci    return true;
665600cc4afSopenharmony_ci}
666600cc4afSopenharmony_ci
667600cc4afSopenharmony_cistatic bool ParseAppIndex(napi_env env, napi_value args, int32_t &appIndex)
668600cc4afSopenharmony_ci{
669600cc4afSopenharmony_ci    APP_LOGD("start to parse appIndex");
670600cc4afSopenharmony_ci    PropertyInfo propertyInfo = {
671600cc4afSopenharmony_ci        .propertyName = APP_INDEX,
672600cc4afSopenharmony_ci        .isNecessary = true,
673600cc4afSopenharmony_ci        .propertyType = napi_number
674600cc4afSopenharmony_ci    };
675600cc4afSopenharmony_ci    napi_value property = nullptr;
676600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyFromObject(env, args, propertyInfo, property);
677600cc4afSopenharmony_ci    if (!res) {
678600cc4afSopenharmony_ci        APP_LOGE("parse appIndex failed");
679600cc4afSopenharmony_ci        return res;
680600cc4afSopenharmony_ci    }
681600cc4afSopenharmony_ci    if (property != nullptr) {
682600cc4afSopenharmony_ci        PARSE_PROPERTY(env, property, int32, appIndex);
683600cc4afSopenharmony_ci    }
684600cc4afSopenharmony_ci    APP_LOGD("param appIndex is %{public}d", appIndex);
685600cc4afSopenharmony_ci    return true;
686600cc4afSopenharmony_ci}
687600cc4afSopenharmony_ci
688600cc4afSopenharmony_cistatic bool ParseInstallFlag(napi_env env, napi_value args, InstallFlag &installFlag)
689600cc4afSopenharmony_ci{
690600cc4afSopenharmony_ci    APP_LOGD("start to parse installFlag");
691600cc4afSopenharmony_ci    PropertyInfo propertyInfo = {
692600cc4afSopenharmony_ci        .propertyName = INSTALL_FLAG,
693600cc4afSopenharmony_ci        .isNecessary = false,
694600cc4afSopenharmony_ci        .propertyType = napi_number
695600cc4afSopenharmony_ci    };
696600cc4afSopenharmony_ci    napi_value property = nullptr;
697600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyFromObject(env, args, propertyInfo, property);
698600cc4afSopenharmony_ci    if (!res) {
699600cc4afSopenharmony_ci        APP_LOGE("parse installFlag failed");
700600cc4afSopenharmony_ci        return res;
701600cc4afSopenharmony_ci    }
702600cc4afSopenharmony_ci
703600cc4afSopenharmony_ci    if (property != nullptr) {
704600cc4afSopenharmony_ci        int32_t flag = 0;
705600cc4afSopenharmony_ci        PARSE_PROPERTY(env, property, int32, flag);
706600cc4afSopenharmony_ci        APP_LOGD("param installFlag is %{public}d", flag);
707600cc4afSopenharmony_ci        if ((flag != static_cast<int32_t>(OHOS::AppExecFwk::InstallFlag::NORMAL)) &&
708600cc4afSopenharmony_ci            (flag != static_cast<int32_t>(OHOS::AppExecFwk::InstallFlag::REPLACE_EXISTING)) &&
709600cc4afSopenharmony_ci            (flag != static_cast<int32_t>(OHOS::AppExecFwk::InstallFlag::FREE_INSTALL))) {
710600cc4afSopenharmony_ci            APP_LOGE("invalid installFlag param");
711600cc4afSopenharmony_ci            return false;
712600cc4afSopenharmony_ci        }
713600cc4afSopenharmony_ci        installFlag = static_cast<OHOS::AppExecFwk::InstallFlag>(flag);
714600cc4afSopenharmony_ci    }
715600cc4afSopenharmony_ci    return true;
716600cc4afSopenharmony_ci}
717600cc4afSopenharmony_ci
718600cc4afSopenharmony_cistatic bool ParseIsKeepData(napi_env env, napi_value args, bool &isKeepData)
719600cc4afSopenharmony_ci{
720600cc4afSopenharmony_ci    APP_LOGD("start to parse isKeepData");
721600cc4afSopenharmony_ci    PropertyInfo propertyInfo = {
722600cc4afSopenharmony_ci        .propertyName = IS_KEEP_DATA,
723600cc4afSopenharmony_ci        .isNecessary = false,
724600cc4afSopenharmony_ci        .propertyType = napi_boolean
725600cc4afSopenharmony_ci    };
726600cc4afSopenharmony_ci    napi_value property = nullptr;
727600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyFromObject(env, args, propertyInfo, property);
728600cc4afSopenharmony_ci    if (!res) {
729600cc4afSopenharmony_ci        APP_LOGE("parse isKeepData failed");
730600cc4afSopenharmony_ci        return res;
731600cc4afSopenharmony_ci    }
732600cc4afSopenharmony_ci    if (property != nullptr) {
733600cc4afSopenharmony_ci        PARSE_PROPERTY(env, property, bool, isKeepData);
734600cc4afSopenharmony_ci    }
735600cc4afSopenharmony_ci    APP_LOGD("param isKeepData is %{public}d", isKeepData);
736600cc4afSopenharmony_ci    return true;
737600cc4afSopenharmony_ci}
738600cc4afSopenharmony_ci
739600cc4afSopenharmony_cistatic bool ParseCrowdtestDeadline(napi_env env, napi_value args, int64_t &crowdtestDeadline)
740600cc4afSopenharmony_ci{
741600cc4afSopenharmony_ci    APP_LOGD("start to parse crowdtestDeadline");
742600cc4afSopenharmony_ci    PropertyInfo propertyInfo = {
743600cc4afSopenharmony_ci        .propertyName = CROWD_TEST_DEADLINE,
744600cc4afSopenharmony_ci        .isNecessary = false,
745600cc4afSopenharmony_ci        .propertyType = napi_number
746600cc4afSopenharmony_ci    };
747600cc4afSopenharmony_ci    napi_value property = nullptr;
748600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyFromObject(env, args, propertyInfo, property);
749600cc4afSopenharmony_ci    if (!res) {
750600cc4afSopenharmony_ci        APP_LOGE("parse crowdtestDeadline failed");
751600cc4afSopenharmony_ci        return res;
752600cc4afSopenharmony_ci    }
753600cc4afSopenharmony_ci    if (property != nullptr) {
754600cc4afSopenharmony_ci        PARSE_PROPERTY(env, property, int64, crowdtestDeadline);
755600cc4afSopenharmony_ci    }
756600cc4afSopenharmony_ci    return true;
757600cc4afSopenharmony_ci}
758600cc4afSopenharmony_ci
759600cc4afSopenharmony_cistatic bool ParseSharedBundleDirPaths(napi_env env, napi_value args, std::vector<std::string> &sharedBundleDirPaths)
760600cc4afSopenharmony_ci{
761600cc4afSopenharmony_ci    APP_LOGD("start to parse sharedBundleDirPaths");
762600cc4afSopenharmony_ci    std::vector<napi_value> valueVec;
763600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyArray(env, args, SHARED_BUNDLE_DIR_PATHS, valueVec);
764600cc4afSopenharmony_ci    if (!res) {
765600cc4afSopenharmony_ci        APP_LOGE("parse sharedBundleDirPaths failed");
766600cc4afSopenharmony_ci        return res;
767600cc4afSopenharmony_ci    }
768600cc4afSopenharmony_ci    if (valueVec.empty()) {
769600cc4afSopenharmony_ci        APP_LOGD("sharedBundleDirPaths is empty");
770600cc4afSopenharmony_ci        return true;
771600cc4afSopenharmony_ci    }
772600cc4afSopenharmony_ci    for (const auto &value : valueVec) {
773600cc4afSopenharmony_ci        std::string path;
774600cc4afSopenharmony_ci        if (!CommonFunc::ParseString(env, value, path)) {
775600cc4afSopenharmony_ci            APP_LOGE("parse sharedBundleDirPaths element failed");
776600cc4afSopenharmony_ci            return false;
777600cc4afSopenharmony_ci        }
778600cc4afSopenharmony_ci        sharedBundleDirPaths.emplace_back(path);
779600cc4afSopenharmony_ci    }
780600cc4afSopenharmony_ci    return true;
781600cc4afSopenharmony_ci}
782600cc4afSopenharmony_ci
783600cc4afSopenharmony_cistatic bool ParseSpecifiedDistributionType(napi_env env, napi_value args, std::string &specifiedDistributionType)
784600cc4afSopenharmony_ci{
785600cc4afSopenharmony_ci    APP_LOGD("start to parse specifiedDistributionType");
786600cc4afSopenharmony_ci    PropertyInfo propertyInfo = {
787600cc4afSopenharmony_ci        .propertyName = SPECIFIED_DISTRIBUTION_TYPE,
788600cc4afSopenharmony_ci        .isNecessary = false,
789600cc4afSopenharmony_ci        .propertyType = napi_string
790600cc4afSopenharmony_ci    };
791600cc4afSopenharmony_ci    napi_value property = nullptr;
792600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyFromObject(env, args, propertyInfo, property);
793600cc4afSopenharmony_ci    if (!res) {
794600cc4afSopenharmony_ci        APP_LOGE("parse specifiedDistributionType failed");
795600cc4afSopenharmony_ci        return res;
796600cc4afSopenharmony_ci    }
797600cc4afSopenharmony_ci    if (property != nullptr) {
798600cc4afSopenharmony_ci        if (!CommonFunc::ParseString(env, property, specifiedDistributionType)) {
799600cc4afSopenharmony_ci            APP_LOGE("ParseString failed");
800600cc4afSopenharmony_ci            return false;
801600cc4afSopenharmony_ci        }
802600cc4afSopenharmony_ci    }
803600cc4afSopenharmony_ci    APP_LOGD("param specifiedDistributionType is %{public}s", specifiedDistributionType.c_str());
804600cc4afSopenharmony_ci    return true;
805600cc4afSopenharmony_ci}
806600cc4afSopenharmony_ci
807600cc4afSopenharmony_cistatic bool ParseAdditionalInfo(napi_env env, napi_value args, std::string &additionalInfo)
808600cc4afSopenharmony_ci{
809600cc4afSopenharmony_ci    APP_LOGD("start to parse the additionalInfo");
810600cc4afSopenharmony_ci    PropertyInfo propertyInfo = {
811600cc4afSopenharmony_ci        .propertyName = ADDITIONAL_INFO,
812600cc4afSopenharmony_ci        .isNecessary = false,
813600cc4afSopenharmony_ci        .propertyType = napi_string
814600cc4afSopenharmony_ci    };
815600cc4afSopenharmony_ci    napi_value property = nullptr;
816600cc4afSopenharmony_ci    bool res = CommonFunc::ParsePropertyFromObject(env, args, propertyInfo, property);
817600cc4afSopenharmony_ci    if (!res) {
818600cc4afSopenharmony_ci        APP_LOGE("parse additionalInfo failed");
819600cc4afSopenharmony_ci        return res;
820600cc4afSopenharmony_ci    }
821600cc4afSopenharmony_ci    if (property != nullptr) {
822600cc4afSopenharmony_ci        if (!CommonFunc::ParseString(env, property, additionalInfo)) {
823600cc4afSopenharmony_ci            APP_LOGE("ParseString failed");
824600cc4afSopenharmony_ci            return false;
825600cc4afSopenharmony_ci        }
826600cc4afSopenharmony_ci    }
827600cc4afSopenharmony_ci    APP_LOGD("param additionalInfo is %{public}s", additionalInfo.c_str());
828600cc4afSopenharmony_ci    return true;
829600cc4afSopenharmony_ci}
830600cc4afSopenharmony_ci
831600cc4afSopenharmony_cistatic bool CheckInstallParam(napi_env env, InstallParam &installParam)
832600cc4afSopenharmony_ci{
833600cc4afSopenharmony_ci    if (installParam.specifiedDistributionType.size() > SPECIFIED_DISTRIBUTION_TYPE_MAX_SIZE) {
834600cc4afSopenharmony_ci        APP_LOGE("Parse specifiedDistributionType size failed");
835600cc4afSopenharmony_ci        BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR,
836600cc4afSopenharmony_ci            "BusinessError 401: The size of specifiedDistributionType is greater than 128");
837600cc4afSopenharmony_ci        return false;
838600cc4afSopenharmony_ci    }
839600cc4afSopenharmony_ci    if (installParam.additionalInfo.size() > ADDITIONAL_INFO_MAX_SIZE) {
840600cc4afSopenharmony_ci        APP_LOGE("Parse additionalInfo size failed");
841600cc4afSopenharmony_ci        BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR,
842600cc4afSopenharmony_ci            "BusinessError 401: The size of additionalInfo is greater than 3000");
843600cc4afSopenharmony_ci        return false;
844600cc4afSopenharmony_ci    }
845600cc4afSopenharmony_ci    return true;
846600cc4afSopenharmony_ci}
847600cc4afSopenharmony_ci
848600cc4afSopenharmony_cistatic bool ParseInstallParam(napi_env env, napi_value args, InstallParam &installParam)
849600cc4afSopenharmony_ci{
850600cc4afSopenharmony_ci    if (!ParseHashParams(env, args, installParam.hashParams)) {
851600cc4afSopenharmony_ci        return false;
852600cc4afSopenharmony_ci    }
853600cc4afSopenharmony_ci    if (!ParseVerifyCodeParams(env, args, installParam.verifyCodeParams)) {
854600cc4afSopenharmony_ci        return false;
855600cc4afSopenharmony_ci    }
856600cc4afSopenharmony_ci    if (!ParsePgoParams(env, args, installParam.pgoParams)) {
857600cc4afSopenharmony_ci        return false;
858600cc4afSopenharmony_ci    }
859600cc4afSopenharmony_ci    if (!ParseUserId(env, args, installParam.userId)) {
860600cc4afSopenharmony_ci        APP_LOGW("Parse userId failed,using default value");
861600cc4afSopenharmony_ci    }
862600cc4afSopenharmony_ci    if (!ParseInstallFlag(env, args, installParam.installFlag)) {
863600cc4afSopenharmony_ci        APP_LOGW("Parse installFlag failed,using default value");
864600cc4afSopenharmony_ci    }
865600cc4afSopenharmony_ci    if (!ParseIsKeepData(env, args, installParam.isKeepData)) {
866600cc4afSopenharmony_ci        APP_LOGW("Parse isKeepData failed,using default value");
867600cc4afSopenharmony_ci    }
868600cc4afSopenharmony_ci    if (!ParseCrowdtestDeadline(env, args, installParam.crowdtestDeadline)) {
869600cc4afSopenharmony_ci        APP_LOGW("Parse crowdtestDeadline failed,using default value");
870600cc4afSopenharmony_ci    }
871600cc4afSopenharmony_ci    if (!ParseSharedBundleDirPaths(env, args, installParam.sharedBundleDirPaths)) {
872600cc4afSopenharmony_ci        APP_LOGW("Parse sharedBundleDirPaths failed,using default value");
873600cc4afSopenharmony_ci    }
874600cc4afSopenharmony_ci    if (!ParseSpecifiedDistributionType(env, args, installParam.specifiedDistributionType)) {
875600cc4afSopenharmony_ci        APP_LOGW("Parse specifiedDistributionType failed,using default value");
876600cc4afSopenharmony_ci    }
877600cc4afSopenharmony_ci    if (!ParseAdditionalInfo(env, args, installParam.additionalInfo)) {
878600cc4afSopenharmony_ci        APP_LOGW("Parse additionalInfo failed,using default value");
879600cc4afSopenharmony_ci    }
880600cc4afSopenharmony_ci    return true;
881600cc4afSopenharmony_ci}
882600cc4afSopenharmony_ci
883600cc4afSopenharmony_cistatic bool ParseUninstallParam(napi_env env, napi_value args, UninstallParam &uninstallParam)
884600cc4afSopenharmony_ci{
885600cc4afSopenharmony_ci    if (!ParseBundleName(env, args, uninstallParam.bundleName) ||
886600cc4afSopenharmony_ci        !ParseModuleName(env, args, uninstallParam.moduleName) ||
887600cc4afSopenharmony_ci        !ParseVersionCode(env, args, uninstallParam.versionCode) ||
888600cc4afSopenharmony_ci        !ParseUserId(env, args, uninstallParam.userId)) {
889600cc4afSopenharmony_ci            APP_LOGE("Parse UninstallParam faied");
890600cc4afSopenharmony_ci            return false;
891600cc4afSopenharmony_ci    }
892600cc4afSopenharmony_ci    return true;
893600cc4afSopenharmony_ci}
894600cc4afSopenharmony_ci
895600cc4afSopenharmony_cistatic void CreateProxyErrCode(std::unordered_map<int32_t, int32_t> &errCodeMap)
896600cc4afSopenharmony_ci{
897600cc4afSopenharmony_ci    errCodeMap = {
898600cc4afSopenharmony_ci        { ERR_APPEXECFWK_INSTALL_PARAM_ERROR, IStatusReceiver::ERR_INSTALL_PARAM_ERROR },
899600cc4afSopenharmony_ci        { ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR, IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR },
900600cc4afSopenharmony_ci        { ERR_APPEXECFWK_INSTALL_FILE_PATH_INVALID, IStatusReceiver::ERR_INSTALL_FILE_PATH_INVALID },
901600cc4afSopenharmony_ci        { ERR_APPEXECFWK_INSTALL_DISK_MEM_INSUFFICIENT, IStatusReceiver::ERR_INSTALL_DISK_MEM_INSUFFICIENT },
902600cc4afSopenharmony_ci        { ERR_BUNDLEMANAGER_INSTALL_CODE_SIGNATURE_FILE_IS_INVALID,
903600cc4afSopenharmony_ci            IStatusReceiver::ERR_INSTALL_CODE_SIGNATURE_FILE_IS_INVALID}
904600cc4afSopenharmony_ci    };
905600cc4afSopenharmony_ci}
906600cc4afSopenharmony_ci
907600cc4afSopenharmony_civoid InstallExecuter(napi_env env, void *data)
908600cc4afSopenharmony_ci{
909600cc4afSopenharmony_ci    AsyncInstallCallbackInfo *asyncCallbackInfo = reinterpret_cast<AsyncInstallCallbackInfo *>(data);
910600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
911600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is nullptr");
912600cc4afSopenharmony_ci        return;
913600cc4afSopenharmony_ci    }
914600cc4afSopenharmony_ci    const std::vector<std::string> bundleFilePath = asyncCallbackInfo->hapFiles;
915600cc4afSopenharmony_ci    InstallResult &installResult = asyncCallbackInfo->installResult;
916600cc4afSopenharmony_ci    if (bundleFilePath.empty() && asyncCallbackInfo->installParam.sharedBundleDirPaths.empty()) {
917600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_INSTALL_FILE_PATH_INVALID);
918600cc4afSopenharmony_ci        return;
919600cc4afSopenharmony_ci    }
920600cc4afSopenharmony_ci    auto iBundleInstaller = CommonFunc::GetBundleInstaller();
921600cc4afSopenharmony_ci    if ((iBundleInstaller == nullptr) || (iBundleInstaller->AsObject() == nullptr)) {
922600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleInstaller");
923600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR);
924600cc4afSopenharmony_ci        return;
925600cc4afSopenharmony_ci    }
926600cc4afSopenharmony_ci
927600cc4afSopenharmony_ci    sptr<InstallerCallback> callback = new (std::nothrow) InstallerCallback();
928600cc4afSopenharmony_ci    sptr<BundleDeathRecipient> recipient(new (std::nothrow) BundleDeathRecipient(callback));
929600cc4afSopenharmony_ci    if (callback == nullptr || recipient == nullptr) {
930600cc4afSopenharmony_ci        APP_LOGE("callback or death recipient is nullptr");
931600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR);
932600cc4afSopenharmony_ci        return;
933600cc4afSopenharmony_ci    }
934600cc4afSopenharmony_ci    iBundleInstaller->AsObject()->AddDeathRecipient(recipient);
935600cc4afSopenharmony_ci
936600cc4afSopenharmony_ci    ErrCode res = iBundleInstaller->StreamInstall(bundleFilePath, asyncCallbackInfo->installParam, callback);
937600cc4afSopenharmony_ci    if (res == ERR_OK) {
938600cc4afSopenharmony_ci        installResult.resultCode = callback->GetResultCode();
939600cc4afSopenharmony_ci        APP_LOGD("InnerInstall resultCode %{public}d", installResult.resultCode);
940600cc4afSopenharmony_ci        installResult.resultMsg = callback->GetResultMsg();
941600cc4afSopenharmony_ci        APP_LOGD("InnerInstall resultMsg %{public}s", installResult.resultMsg.c_str());
942600cc4afSopenharmony_ci        return;
943600cc4afSopenharmony_ci    }
944600cc4afSopenharmony_ci    APP_LOGE("install failed due to %{public}d", res);
945600cc4afSopenharmony_ci    std::unordered_map<int32_t, int32_t> proxyErrCodeMap;
946600cc4afSopenharmony_ci    CreateProxyErrCode(proxyErrCodeMap);
947600cc4afSopenharmony_ci    if (proxyErrCodeMap.find(res) != proxyErrCodeMap.end()) {
948600cc4afSopenharmony_ci        installResult.resultCode = proxyErrCodeMap.at(res);
949600cc4afSopenharmony_ci    } else {
950600cc4afSopenharmony_ci        installResult.resultCode = IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR;
951600cc4afSopenharmony_ci    }
952600cc4afSopenharmony_ci}
953600cc4afSopenharmony_ci
954600cc4afSopenharmony_cistatic std::string GetFunctionName(const InstallOption &option)
955600cc4afSopenharmony_ci{
956600cc4afSopenharmony_ci    if (option == InstallOption::INSTALL) {
957600cc4afSopenharmony_ci        return RESOURCE_NAME_OF_INSTALL;
958600cc4afSopenharmony_ci    } else if (option == InstallOption::RECOVER) {
959600cc4afSopenharmony_ci        return RESOURCE_NAME_OF_RECOVER;
960600cc4afSopenharmony_ci    } else if (option == InstallOption::UNINSTALL) {
961600cc4afSopenharmony_ci        return RESOURCE_NAME_OF_UNINSTALL;
962600cc4afSopenharmony_ci    } else if (option == InstallOption::UPDATE_BUNDLE_FOR_SELF) {
963600cc4afSopenharmony_ci        return RESOURCE_NAME_OF_UPDATE_BUNDLE_FOR_SELF;
964600cc4afSopenharmony_ci    } else if (option == InstallOption::UNINSTALL_AND_RECOVER) {
965600cc4afSopenharmony_ci        return RESOURCE_NAME_OF_UNINSTALL_AND_RECOVER;
966600cc4afSopenharmony_ci    }
967600cc4afSopenharmony_ci    return EMPTY_STRING;
968600cc4afSopenharmony_ci}
969600cc4afSopenharmony_ci
970600cc4afSopenharmony_civoid OperationCompleted(napi_env env, napi_status status, void *data)
971600cc4afSopenharmony_ci{
972600cc4afSopenharmony_ci    AsyncInstallCallbackInfo *asyncCallbackInfo = reinterpret_cast<AsyncInstallCallbackInfo *>(data);
973600cc4afSopenharmony_ci    std::unique_ptr<AsyncInstallCallbackInfo> callbackPtr {asyncCallbackInfo};
974600cc4afSopenharmony_ci    napi_value result[CALLBACK_PARAM_SIZE] = {0};
975600cc4afSopenharmony_ci    ConvertInstallResult(callbackPtr->installResult);
976600cc4afSopenharmony_ci    if (callbackPtr->installResult.resultCode != SUCCESS) {
977600cc4afSopenharmony_ci        switch (callbackPtr->option) {
978600cc4afSopenharmony_ci            case InstallOption::INSTALL:
979600cc4afSopenharmony_ci                result[FIRST_PARAM] = BusinessError::CreateCommonError(env, callbackPtr->installResult.resultCode,
980600cc4afSopenharmony_ci                    RESOURCE_NAME_OF_INSTALL, INSTALL_PERMISSION);
981600cc4afSopenharmony_ci                break;
982600cc4afSopenharmony_ci            case InstallOption::RECOVER:
983600cc4afSopenharmony_ci                result[FIRST_PARAM] = BusinessError::CreateCommonError(env, callbackPtr->installResult.resultCode,
984600cc4afSopenharmony_ci                    RESOURCE_NAME_OF_RECOVER, RECOVER_PERMISSION);
985600cc4afSopenharmony_ci                break;
986600cc4afSopenharmony_ci            case InstallOption::UNINSTALL:
987600cc4afSopenharmony_ci                result[FIRST_PARAM] = BusinessError::CreateCommonError(env, callbackPtr->installResult.resultCode,
988600cc4afSopenharmony_ci                    RESOURCE_NAME_OF_UNINSTALL, UNINSTALL_PERMISSION);
989600cc4afSopenharmony_ci                break;
990600cc4afSopenharmony_ci            case InstallOption::UPDATE_BUNDLE_FOR_SELF:
991600cc4afSopenharmony_ci                result[FIRST_PARAM] = BusinessError::CreateCommonError(env, callbackPtr->installResult.resultCode,
992600cc4afSopenharmony_ci                    RESOURCE_NAME_OF_UPDATE_BUNDLE_FOR_SELF, INSTALL_SELF_PERMISSION);
993600cc4afSopenharmony_ci                break;
994600cc4afSopenharmony_ci            case InstallOption::UNINSTALL_AND_RECOVER:
995600cc4afSopenharmony_ci                result[FIRST_PARAM] = BusinessError::CreateCommonError(env, callbackPtr->installResult.resultCode,
996600cc4afSopenharmony_ci                    RESOURCE_NAME_OF_UNINSTALL_AND_RECOVER, UNINSTALL_PERMISSION);
997600cc4afSopenharmony_ci                break;
998600cc4afSopenharmony_ci            default:
999600cc4afSopenharmony_ci                break;
1000600cc4afSopenharmony_ci        }
1001600cc4afSopenharmony_ci    } else {
1002600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[FIRST_PARAM]));
1003600cc4afSopenharmony_ci    }
1004600cc4afSopenharmony_ci    callbackPtr->err = callbackPtr->installResult.resultCode;
1005600cc4afSopenharmony_ci    APP_LOGI("installer callback");
1006600cc4afSopenharmony_ci    CommonFunc::NapiReturnDeferred<AsyncInstallCallbackInfo>(env, asyncCallbackInfo, result, ARGS_SIZE_ONE);
1007600cc4afSopenharmony_ci}
1008600cc4afSopenharmony_ci
1009600cc4afSopenharmony_ci/**
1010600cc4afSopenharmony_ci * Promise and async callback
1011600cc4afSopenharmony_ci */
1012600cc4afSopenharmony_cinapi_value Install(napi_env env, napi_callback_info info)
1013600cc4afSopenharmony_ci{
1014600cc4afSopenharmony_ci    APP_LOGI("Install called");
1015600cc4afSopenharmony_ci    // obtain arguments of install interface
1016600cc4afSopenharmony_ci    NapiArg args(env, info);
1017600cc4afSopenharmony_ci    if (!args.Init(ARGS_SIZE_ONE, ARGS_SIZE_THREE)) {
1018600cc4afSopenharmony_ci        APP_LOGE("init param failed");
1019600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1020600cc4afSopenharmony_ci        return nullptr;
1021600cc4afSopenharmony_ci    }
1022600cc4afSopenharmony_ci    auto argc = args.GetMaxArgc();
1023600cc4afSopenharmony_ci    APP_LOGD("the number of argc is  %{public}zu", argc);
1024600cc4afSopenharmony_ci    if (argc < ARGS_SIZE_ONE) {
1025600cc4afSopenharmony_ci        APP_LOGE("the params number is incorrect");
1026600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1027600cc4afSopenharmony_ci        return nullptr;
1028600cc4afSopenharmony_ci    }
1029600cc4afSopenharmony_ci    std::unique_ptr<AsyncInstallCallbackInfo> callbackPtr = std::make_unique<AsyncInstallCallbackInfo>(env);
1030600cc4afSopenharmony_ci    callbackPtr->option = InstallOption::INSTALL;
1031600cc4afSopenharmony_ci    for (size_t i = 0; i < argc; ++i) {
1032600cc4afSopenharmony_ci        napi_valuetype valueType = napi_undefined;
1033600cc4afSopenharmony_ci        napi_typeof(env, args[i], &valueType);
1034600cc4afSopenharmony_ci        if (i == ARGS_POS_ZERO) {
1035600cc4afSopenharmony_ci            if (!CommonFunc::ParseStringArray(env, callbackPtr->hapFiles, args[i])) {
1036600cc4afSopenharmony_ci                APP_LOGE("Flags %{public}s invalid", callbackPtr->bundleName.c_str());
1037600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1038600cc4afSopenharmony_ci                return nullptr;
1039600cc4afSopenharmony_ci            }
1040600cc4afSopenharmony_ci        } else if (i == ARGS_POS_ONE) {
1041600cc4afSopenharmony_ci            if (valueType == napi_function) {
1042600cc4afSopenharmony_ci                NAPI_CALL(env, napi_create_reference(env, args[i], NAPI_RETURN_ONE, &callbackPtr->callback));
1043600cc4afSopenharmony_ci                break;
1044600cc4afSopenharmony_ci            }
1045600cc4afSopenharmony_ci            if (valueType == napi_object && !ParseInstallParam(env, args[i], callbackPtr->installParam)) {
1046600cc4afSopenharmony_ci                APP_LOGE("Parse installParam failed");
1047600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1048600cc4afSopenharmony_ci                return nullptr;
1049600cc4afSopenharmony_ci            }
1050600cc4afSopenharmony_ci        } else if (i == ARGS_POS_TWO) {
1051600cc4afSopenharmony_ci            if (valueType == napi_function) {
1052600cc4afSopenharmony_ci                NAPI_CALL(env, napi_create_reference(env, args[i], NAPI_RETURN_ONE, &callbackPtr->callback));
1053600cc4afSopenharmony_ci                break;
1054600cc4afSopenharmony_ci            }
1055600cc4afSopenharmony_ci        } else {
1056600cc4afSopenharmony_ci            APP_LOGE("param check error");
1057600cc4afSopenharmony_ci            BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1058600cc4afSopenharmony_ci            return nullptr;
1059600cc4afSopenharmony_ci        }
1060600cc4afSopenharmony_ci    }
1061600cc4afSopenharmony_ci    if (!CheckInstallParam(env, callbackPtr->installParam)) {
1062600cc4afSopenharmony_ci        return nullptr;
1063600cc4afSopenharmony_ci    }
1064600cc4afSopenharmony_ci    if (callbackPtr->hapFiles.empty() && !callbackPtr->installParam.verifyCodeParams.empty()) {
1065600cc4afSopenharmony_ci        BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, HAPS_FILE_NEEDED);
1066600cc4afSopenharmony_ci        return nullptr;
1067600cc4afSopenharmony_ci    }
1068600cc4afSopenharmony_ci    auto promise = CommonFunc::AsyncCallNativeMethod(env, callbackPtr.get(), RESOURCE_NAME_OF_INSTALL, InstallExecuter,
1069600cc4afSopenharmony_ci        OperationCompleted);
1070600cc4afSopenharmony_ci    callbackPtr.release();
1071600cc4afSopenharmony_ci    APP_LOGI("call Install done");
1072600cc4afSopenharmony_ci    return promise;
1073600cc4afSopenharmony_ci}
1074600cc4afSopenharmony_ci
1075600cc4afSopenharmony_civoid UninstallOrRecoverExecuter(napi_env env, void *data)
1076600cc4afSopenharmony_ci{
1077600cc4afSopenharmony_ci    AsyncInstallCallbackInfo *asyncCallbackInfo = reinterpret_cast<AsyncInstallCallbackInfo *>(data);
1078600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1079600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is nullptr");
1080600cc4afSopenharmony_ci        return;
1081600cc4afSopenharmony_ci    }
1082600cc4afSopenharmony_ci    const std::string bundleName = asyncCallbackInfo->bundleName;
1083600cc4afSopenharmony_ci    InstallResult &installResult = asyncCallbackInfo->installResult;
1084600cc4afSopenharmony_ci    if (bundleName.empty()) {
1085600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_RECOVER_INVALID_BUNDLE_NAME);
1086600cc4afSopenharmony_ci        return;
1087600cc4afSopenharmony_ci    }
1088600cc4afSopenharmony_ci    auto iBundleInstaller = CommonFunc::GetBundleInstaller();
1089600cc4afSopenharmony_ci    if ((iBundleInstaller == nullptr) || (iBundleInstaller->AsObject() == nullptr)) {
1090600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleInstaller");
1091600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR);
1092600cc4afSopenharmony_ci        return;
1093600cc4afSopenharmony_ci    }
1094600cc4afSopenharmony_ci
1095600cc4afSopenharmony_ci    sptr<InstallerCallback> callback = new (std::nothrow) InstallerCallback();
1096600cc4afSopenharmony_ci    sptr<BundleDeathRecipient> recipient(new (std::nothrow) BundleDeathRecipient(callback));
1097600cc4afSopenharmony_ci    if (callback == nullptr || recipient == nullptr) {
1098600cc4afSopenharmony_ci        APP_LOGE("callback or death recipient is nullptr");
1099600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR);
1100600cc4afSopenharmony_ci        return;
1101600cc4afSopenharmony_ci    }
1102600cc4afSopenharmony_ci    iBundleInstaller->AsObject()->AddDeathRecipient(recipient);
1103600cc4afSopenharmony_ci    if (asyncCallbackInfo->option == InstallOption::RECOVER) {
1104600cc4afSopenharmony_ci        iBundleInstaller->Recover(bundleName, asyncCallbackInfo->installParam, callback);
1105600cc4afSopenharmony_ci    } else if (asyncCallbackInfo->option == InstallOption::UNINSTALL) {
1106600cc4afSopenharmony_ci        iBundleInstaller->Uninstall(bundleName, asyncCallbackInfo->installParam, callback);
1107600cc4afSopenharmony_ci    } else {
1108600cc4afSopenharmony_ci        APP_LOGE("error install option");
1109600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR);
1110600cc4afSopenharmony_ci        return;
1111600cc4afSopenharmony_ci    }
1112600cc4afSopenharmony_ci    installResult.resultMsg = callback->GetResultMsg();
1113600cc4afSopenharmony_ci    APP_LOGD("InnerRecover resultMsg %{public}s", installResult.resultMsg.c_str());
1114600cc4afSopenharmony_ci    installResult.resultCode = callback->GetResultCode();
1115600cc4afSopenharmony_ci    APP_LOGD("InnerRecover resultCode %{public}d", installResult.resultCode);
1116600cc4afSopenharmony_ci}
1117600cc4afSopenharmony_ci
1118600cc4afSopenharmony_civoid UninstallByUninstallParamExecuter(napi_env env, void* data)
1119600cc4afSopenharmony_ci{
1120600cc4afSopenharmony_ci    AsyncInstallCallbackInfo *asyncCallbackInfo = reinterpret_cast<AsyncInstallCallbackInfo *>(data);
1121600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1122600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is nullptr");
1123600cc4afSopenharmony_ci        return;
1124600cc4afSopenharmony_ci    }
1125600cc4afSopenharmony_ci    const std::string bundleName = asyncCallbackInfo->uninstallParam.bundleName;
1126600cc4afSopenharmony_ci    InstallResult &installResult = asyncCallbackInfo->installResult;
1127600cc4afSopenharmony_ci    if (bundleName.empty()) {
1128600cc4afSopenharmony_ci        installResult.resultCode =
1129600cc4afSopenharmony_ci            static_cast<int32_t>(IStatusReceiver::ERR_APPEXECFWK_UNINSTALL_SHARE_APP_LIBRARY_IS_NOT_EXIST);
1130600cc4afSopenharmony_ci        return;
1131600cc4afSopenharmony_ci    }
1132600cc4afSopenharmony_ci    auto iBundleInstaller = CommonFunc::GetBundleInstaller();
1133600cc4afSopenharmony_ci    if ((iBundleInstaller == nullptr) || (iBundleInstaller->AsObject() == nullptr)) {
1134600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleInstaller");
1135600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR);
1136600cc4afSopenharmony_ci        return;
1137600cc4afSopenharmony_ci    }
1138600cc4afSopenharmony_ci    sptr<InstallerCallback> callback = new (std::nothrow) InstallerCallback();
1139600cc4afSopenharmony_ci    sptr<BundleDeathRecipient> recipient(new (std::nothrow) BundleDeathRecipient(callback));
1140600cc4afSopenharmony_ci    if (callback == nullptr || recipient == nullptr) {
1141600cc4afSopenharmony_ci        APP_LOGE("callback or death recipient is nullptr");
1142600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR);
1143600cc4afSopenharmony_ci        return;
1144600cc4afSopenharmony_ci    }
1145600cc4afSopenharmony_ci    iBundleInstaller->AsObject()->AddDeathRecipient(recipient);
1146600cc4afSopenharmony_ci    iBundleInstaller->Uninstall(asyncCallbackInfo->uninstallParam, callback);
1147600cc4afSopenharmony_ci    installResult.resultMsg = callback->GetResultMsg();
1148600cc4afSopenharmony_ci    installResult.resultCode = callback->GetResultCode();
1149600cc4afSopenharmony_ci}
1150600cc4afSopenharmony_ci
1151600cc4afSopenharmony_cinapi_value UninstallByUninstallParam(napi_env env, napi_callback_info info,
1152600cc4afSopenharmony_ci    std::unique_ptr<AsyncInstallCallbackInfo> &callbackPtr)
1153600cc4afSopenharmony_ci{
1154600cc4afSopenharmony_ci    NapiArg args(env, info);
1155600cc4afSopenharmony_ci    if (!args.Init(ARGS_SIZE_ONE, ARGS_SIZE_TWO)) {
1156600cc4afSopenharmony_ci        APP_LOGE("init param failed");
1157600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1158600cc4afSopenharmony_ci        return nullptr;
1159600cc4afSopenharmony_ci    }
1160600cc4afSopenharmony_ci    for (size_t i = 0; i < args.GetMaxArgc(); ++i) {
1161600cc4afSopenharmony_ci        napi_valuetype valueType = napi_undefined;
1162600cc4afSopenharmony_ci        napi_typeof(env, args[i], &valueType);
1163600cc4afSopenharmony_ci        if (i == ARGS_POS_ZERO) {
1164600cc4afSopenharmony_ci            if (!ParseUninstallParam(env, args[i], callbackPtr->uninstallParam)) {
1165600cc4afSopenharmony_ci                APP_LOGE("parse uninstallParam failed");
1166600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1167600cc4afSopenharmony_ci                return nullptr;
1168600cc4afSopenharmony_ci            }
1169600cc4afSopenharmony_ci        } else if ((i == ARGS_POS_ONE) && (valueType == napi_function)) {
1170600cc4afSopenharmony_ci            NAPI_CALL(env, napi_create_reference(env, args[i], NAPI_RETURN_ONE, &callbackPtr->callback));
1171600cc4afSopenharmony_ci            break;
1172600cc4afSopenharmony_ci        } else {
1173600cc4afSopenharmony_ci            APP_LOGE("param check error");
1174600cc4afSopenharmony_ci            BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1175600cc4afSopenharmony_ci            return nullptr;
1176600cc4afSopenharmony_ci        }
1177600cc4afSopenharmony_ci    }
1178600cc4afSopenharmony_ci    auto promise = CommonFunc::AsyncCallNativeMethod(env, callbackPtr.get(), GetFunctionName(callbackPtr->option),
1179600cc4afSopenharmony_ci        UninstallByUninstallParamExecuter, OperationCompleted);
1180600cc4afSopenharmony_ci    callbackPtr.release();
1181600cc4afSopenharmony_ci    return promise;
1182600cc4afSopenharmony_ci}
1183600cc4afSopenharmony_ci
1184600cc4afSopenharmony_cinapi_value UninstallOrRecover(napi_env env, napi_callback_info info,
1185600cc4afSopenharmony_ci    std::unique_ptr<AsyncInstallCallbackInfo> &callbackPtr)
1186600cc4afSopenharmony_ci{
1187600cc4afSopenharmony_ci    APP_LOGD("UninstallOrRecover by bundleName called");
1188600cc4afSopenharmony_ci    // obtain arguments of install interface
1189600cc4afSopenharmony_ci    NapiArg args(env, info);
1190600cc4afSopenharmony_ci    if (!args.Init(ARGS_SIZE_ONE, ARGS_SIZE_THREE)) {
1191600cc4afSopenharmony_ci        APP_LOGE("init param failed");
1192600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1193600cc4afSopenharmony_ci        return nullptr;
1194600cc4afSopenharmony_ci    }
1195600cc4afSopenharmony_ci
1196600cc4afSopenharmony_ci    auto argc = args.GetMaxArgc();
1197600cc4afSopenharmony_ci    APP_LOGD("the number of argc is  %{public}zu", argc);
1198600cc4afSopenharmony_ci    if (argc < ARGS_SIZE_ONE) {
1199600cc4afSopenharmony_ci        APP_LOGE("the params number is incorrect");
1200600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1201600cc4afSopenharmony_ci        return nullptr;
1202600cc4afSopenharmony_ci    }
1203600cc4afSopenharmony_ci
1204600cc4afSopenharmony_ci    for (size_t i = 0; i < args.GetMaxArgc(); ++i) {
1205600cc4afSopenharmony_ci        napi_valuetype valueType = napi_undefined;
1206600cc4afSopenharmony_ci        napi_typeof(env, args[i], &valueType);
1207600cc4afSopenharmony_ci        if (i == ARGS_POS_ZERO) {
1208600cc4afSopenharmony_ci            if (!CommonFunc::ParseString(env, args[i], callbackPtr->bundleName)) {
1209600cc4afSopenharmony_ci                APP_LOGE("Flags %{public}s invalid", callbackPtr->bundleName.c_str());
1210600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1211600cc4afSopenharmony_ci                return nullptr;
1212600cc4afSopenharmony_ci            }
1213600cc4afSopenharmony_ci        } else if (i == ARGS_POS_ONE) {
1214600cc4afSopenharmony_ci            if (valueType == napi_function) {
1215600cc4afSopenharmony_ci                NAPI_CALL(env, napi_create_reference(env, args[i], NAPI_RETURN_ONE, &callbackPtr->callback));
1216600cc4afSopenharmony_ci                break;
1217600cc4afSopenharmony_ci            }
1218600cc4afSopenharmony_ci            if (valueType == napi_object && !ParseInstallParam(env, args[i], callbackPtr->installParam)) {
1219600cc4afSopenharmony_ci                APP_LOGE("Parse installParam.hashParams failed");
1220600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1221600cc4afSopenharmony_ci                return nullptr;
1222600cc4afSopenharmony_ci            }
1223600cc4afSopenharmony_ci        } else if (i == ARGS_POS_TWO) {
1224600cc4afSopenharmony_ci            if (valueType == napi_function) {
1225600cc4afSopenharmony_ci                NAPI_CALL(env, napi_create_reference(env, args[i], NAPI_RETURN_ONE, &callbackPtr->callback));
1226600cc4afSopenharmony_ci                break;
1227600cc4afSopenharmony_ci            }
1228600cc4afSopenharmony_ci        } else {
1229600cc4afSopenharmony_ci            APP_LOGE("param check error");
1230600cc4afSopenharmony_ci            BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1231600cc4afSopenharmony_ci            return nullptr;
1232600cc4afSopenharmony_ci        }
1233600cc4afSopenharmony_ci    }
1234600cc4afSopenharmony_ci
1235600cc4afSopenharmony_ci    auto promise = CommonFunc::AsyncCallNativeMethod(env, callbackPtr.get(), GetFunctionName(callbackPtr->option),
1236600cc4afSopenharmony_ci        UninstallOrRecoverExecuter, OperationCompleted);
1237600cc4afSopenharmony_ci    callbackPtr.release();
1238600cc4afSopenharmony_ci    return promise;
1239600cc4afSopenharmony_ci}
1240600cc4afSopenharmony_ci
1241600cc4afSopenharmony_cinapi_value Recover(napi_env env, napi_callback_info info)
1242600cc4afSopenharmony_ci{
1243600cc4afSopenharmony_ci    APP_LOGI("Recover called");
1244600cc4afSopenharmony_ci    std::unique_ptr<AsyncInstallCallbackInfo> callbackPtr = std::make_unique<AsyncInstallCallbackInfo>(env);
1245600cc4afSopenharmony_ci    callbackPtr->option = InstallOption::RECOVER;
1246600cc4afSopenharmony_ci    APP_LOGI("call Recover done");
1247600cc4afSopenharmony_ci    return UninstallOrRecover(env, info, callbackPtr);
1248600cc4afSopenharmony_ci}
1249600cc4afSopenharmony_ci
1250600cc4afSopenharmony_cinapi_value Uninstall(napi_env env, napi_callback_info info)
1251600cc4afSopenharmony_ci{
1252600cc4afSopenharmony_ci    APP_LOGI_NOFUNC("Uninstall called");
1253600cc4afSopenharmony_ci    std::unique_ptr<AsyncInstallCallbackInfo> callbackPtr = std::make_unique<AsyncInstallCallbackInfo>(env);
1254600cc4afSopenharmony_ci    callbackPtr->option = InstallOption::UNINSTALL;
1255600cc4afSopenharmony_ci    // uninstall uninstallParam
1256600cc4afSopenharmony_ci    NapiArg args(env, info);
1257600cc4afSopenharmony_ci    args.Init(ARGS_SIZE_ONE, ARGS_SIZE_THREE);
1258600cc4afSopenharmony_ci    napi_valuetype firstType = napi_undefined;
1259600cc4afSopenharmony_ci    napi_typeof(env, args[FIRST_PARAM], &firstType);
1260600cc4afSopenharmony_ci    if (firstType == napi_object) {
1261600cc4afSopenharmony_ci        return UninstallByUninstallParam(env, info, callbackPtr);
1262600cc4afSopenharmony_ci    }
1263600cc4afSopenharmony_ci    APP_LOGI_NOFUNC("call Uninstall done");
1264600cc4afSopenharmony_ci    return UninstallOrRecover(env, info, callbackPtr);
1265600cc4afSopenharmony_ci}
1266600cc4afSopenharmony_ci
1267600cc4afSopenharmony_cinapi_value BundleInstallerConstructor(napi_env env, napi_callback_info info)
1268600cc4afSopenharmony_ci{
1269600cc4afSopenharmony_ci    napi_value jsthis = nullptr;
1270600cc4afSopenharmony_ci    NAPI_CALL(env, napi_get_cb_info(env, info, nullptr, nullptr, &jsthis, nullptr));
1271600cc4afSopenharmony_ci    return jsthis;
1272600cc4afSopenharmony_ci}
1273600cc4afSopenharmony_ci
1274600cc4afSopenharmony_ci/**
1275600cc4afSopenharmony_ci * Promise and async callback
1276600cc4afSopenharmony_ci */
1277600cc4afSopenharmony_cinapi_value UpdateBundleForSelf(napi_env env, napi_callback_info info)
1278600cc4afSopenharmony_ci{
1279600cc4afSopenharmony_ci    APP_LOGI("UpdateBundleForSelf called");
1280600cc4afSopenharmony_ci    // obtain arguments of install interface
1281600cc4afSopenharmony_ci    NapiArg args(env, info);
1282600cc4afSopenharmony_ci    if (!args.Init(ARGS_SIZE_TWO, ARGS_SIZE_THREE)) {
1283600cc4afSopenharmony_ci        APP_LOGE("init param failed");
1284600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1285600cc4afSopenharmony_ci        return nullptr;
1286600cc4afSopenharmony_ci    }
1287600cc4afSopenharmony_ci    auto argc = args.GetMaxArgc();
1288600cc4afSopenharmony_ci    std::unique_ptr<AsyncInstallCallbackInfo> callbackPtr = std::make_unique<AsyncInstallCallbackInfo>(env);
1289600cc4afSopenharmony_ci    callbackPtr->option = InstallOption::UPDATE_BUNDLE_FOR_SELF;
1290600cc4afSopenharmony_ci    for (size_t i = 0; i < argc; ++i) {
1291600cc4afSopenharmony_ci        napi_valuetype valueType = napi_undefined;
1292600cc4afSopenharmony_ci        napi_typeof(env, args[i], &valueType);
1293600cc4afSopenharmony_ci        if (i == ARGS_POS_ZERO) {
1294600cc4afSopenharmony_ci            if (!CommonFunc::ParseStringArray(env, callbackPtr->hapFiles, args[i])) {
1295600cc4afSopenharmony_ci                APP_LOGE("Flags %{public}s invalid", callbackPtr->bundleName.c_str());
1296600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1297600cc4afSopenharmony_ci                return nullptr;
1298600cc4afSopenharmony_ci            }
1299600cc4afSopenharmony_ci        } else if (i == ARGS_POS_ONE) {
1300600cc4afSopenharmony_ci            if (valueType == napi_function) {
1301600cc4afSopenharmony_ci                NAPI_CALL(env, napi_create_reference(env, args[i], NAPI_RETURN_ONE, &callbackPtr->callback));
1302600cc4afSopenharmony_ci                break;
1303600cc4afSopenharmony_ci            }
1304600cc4afSopenharmony_ci            if (valueType == napi_object && !ParseInstallParam(env, args[i], callbackPtr->installParam)) {
1305600cc4afSopenharmony_ci                APP_LOGE("Parse installParam failed");
1306600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1307600cc4afSopenharmony_ci                return nullptr;
1308600cc4afSopenharmony_ci            }
1309600cc4afSopenharmony_ci        } else if (i == ARGS_POS_TWO) {
1310600cc4afSopenharmony_ci            if (valueType == napi_function) {
1311600cc4afSopenharmony_ci                NAPI_CALL(env, napi_create_reference(env, args[i], NAPI_RETURN_ONE, &callbackPtr->callback));
1312600cc4afSopenharmony_ci                break;
1313600cc4afSopenharmony_ci            }
1314600cc4afSopenharmony_ci        } else {
1315600cc4afSopenharmony_ci            APP_LOGE("param check error");
1316600cc4afSopenharmony_ci            BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, PARAMETERS, CORRESPONDING_TYPE);
1317600cc4afSopenharmony_ci            return nullptr;
1318600cc4afSopenharmony_ci        }
1319600cc4afSopenharmony_ci    }
1320600cc4afSopenharmony_ci    if (!CheckInstallParam(env, callbackPtr->installParam)) {
1321600cc4afSopenharmony_ci        return nullptr;
1322600cc4afSopenharmony_ci    }
1323600cc4afSopenharmony_ci    if (callbackPtr->hapFiles.empty() && !callbackPtr->installParam.verifyCodeParams.empty()) {
1324600cc4afSopenharmony_ci        BusinessError::ThrowError(env, ERROR_PARAM_CHECK_ERROR, HAPS_FILE_NEEDED);
1325600cc4afSopenharmony_ci        return nullptr;
1326600cc4afSopenharmony_ci    }
1327600cc4afSopenharmony_ci    callbackPtr->installParam.isSelfUpdate = true;
1328600cc4afSopenharmony_ci    auto promise = CommonFunc::AsyncCallNativeMethod(env, callbackPtr.get(), RESOURCE_NAME_OF_INSTALL, InstallExecuter,
1329600cc4afSopenharmony_ci        OperationCompleted);
1330600cc4afSopenharmony_ci    callbackPtr.release();
1331600cc4afSopenharmony_ci    APP_LOGI("call UpdateBundleForSelf done");
1332600cc4afSopenharmony_ci    return promise;
1333600cc4afSopenharmony_ci}
1334600cc4afSopenharmony_ci
1335600cc4afSopenharmony_civoid UninstallAndRecoverExecuter(napi_env env, void *data)
1336600cc4afSopenharmony_ci{
1337600cc4afSopenharmony_ci    AsyncInstallCallbackInfo *asyncCallbackInfo = reinterpret_cast<AsyncInstallCallbackInfo *>(data);
1338600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1339600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is nullptr");
1340600cc4afSopenharmony_ci        return;
1341600cc4afSopenharmony_ci    }
1342600cc4afSopenharmony_ci    const std::string bundleName = asyncCallbackInfo->bundleName;
1343600cc4afSopenharmony_ci    InstallResult &installResult = asyncCallbackInfo->installResult;
1344600cc4afSopenharmony_ci    if (bundleName.empty()) {
1345600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_RECOVER_INVALID_BUNDLE_NAME);
1346600cc4afSopenharmony_ci        return;
1347600cc4afSopenharmony_ci    }
1348600cc4afSopenharmony_ci    auto iBundleInstaller = CommonFunc::GetBundleInstaller();
1349600cc4afSopenharmony_ci    if ((iBundleInstaller == nullptr) || (iBundleInstaller->AsObject() == nullptr)) {
1350600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleInstaller");
1351600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR);
1352600cc4afSopenharmony_ci        return;
1353600cc4afSopenharmony_ci    }
1354600cc4afSopenharmony_ci    sptr<InstallerCallback> callback = new (std::nothrow) InstallerCallback();
1355600cc4afSopenharmony_ci    sptr<BundleDeathRecipient> recipient(new (std::nothrow) BundleDeathRecipient(callback));
1356600cc4afSopenharmony_ci    if (callback == nullptr || recipient == nullptr) {
1357600cc4afSopenharmony_ci        APP_LOGE("callback or death recipient is nullptr");
1358600cc4afSopenharmony_ci        installResult.resultCode = static_cast<int32_t>(IStatusReceiver::ERR_INSTALL_INTERNAL_ERROR);
1359600cc4afSopenharmony_ci        return;
1360600cc4afSopenharmony_ci    }
1361600cc4afSopenharmony_ci    iBundleInstaller->AsObject()->AddDeathRecipient(recipient);
1362600cc4afSopenharmony_ci    iBundleInstaller->UninstallAndRecover(bundleName, asyncCallbackInfo->installParam, callback);
1363600cc4afSopenharmony_ci    installResult.resultMsg = callback->GetResultMsg();
1364600cc4afSopenharmony_ci    installResult.resultCode = callback->GetResultCode();
1365600cc4afSopenharmony_ci}
1366600cc4afSopenharmony_ci
1367600cc4afSopenharmony_cinapi_value UninstallAndRecover(napi_env env, napi_callback_info info)
1368600cc4afSopenharmony_ci{
1369600cc4afSopenharmony_ci    APP_LOGI("UninstallAndRecover called");
1370600cc4afSopenharmony_ci    NapiArg args(env, info);
1371600cc4afSopenharmony_ci    if (!args.Init(ARGS_SIZE_ONE, ARGS_SIZE_TWO)) {
1372600cc4afSopenharmony_ci        APP_LOGE("init param failed");
1373600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1374600cc4afSopenharmony_ci        return nullptr;
1375600cc4afSopenharmony_ci    }
1376600cc4afSopenharmony_ci    std::unique_ptr<AsyncInstallCallbackInfo> callbackPtr = std::make_unique<AsyncInstallCallbackInfo>(env);
1377600cc4afSopenharmony_ci    callbackPtr->option = InstallOption::UNINSTALL_AND_RECOVER;
1378600cc4afSopenharmony_ci    for (size_t i = 0; i < args.GetArgc(); ++i) {
1379600cc4afSopenharmony_ci        napi_valuetype valueType = napi_undefined;
1380600cc4afSopenharmony_ci        napi_typeof(env, args[i], &valueType);
1381600cc4afSopenharmony_ci        if (i == ARGS_POS_ZERO) {
1382600cc4afSopenharmony_ci            if (!CommonFunc::ParseString(env, args[i], callbackPtr->bundleName)) {
1383600cc4afSopenharmony_ci                APP_LOGE("bundleName %{public}s invalid!", callbackPtr->bundleName.c_str());
1384600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING);
1385600cc4afSopenharmony_ci                return nullptr;
1386600cc4afSopenharmony_ci            }
1387600cc4afSopenharmony_ci        } else if (i == ARGS_POS_ONE) {
1388600cc4afSopenharmony_ci            if (valueType != napi_object || !ParseInstallParam(env, args[i], callbackPtr->installParam)) {
1389600cc4afSopenharmony_ci                APP_LOGW("Parse installParam failed");
1390600cc4afSopenharmony_ci            }
1391600cc4afSopenharmony_ci        } else {
1392600cc4afSopenharmony_ci            APP_LOGE("The number of parameters is incorrect.");
1393600cc4afSopenharmony_ci            BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1394600cc4afSopenharmony_ci            return nullptr;
1395600cc4afSopenharmony_ci        }
1396600cc4afSopenharmony_ci    }
1397600cc4afSopenharmony_ci    auto promise = CommonFunc::AsyncCallNativeMethod(env, callbackPtr.get(), RESOURCE_NAME_OF_UNINSTALL_AND_RECOVER,
1398600cc4afSopenharmony_ci        UninstallAndRecoverExecuter, OperationCompleted);
1399600cc4afSopenharmony_ci    callbackPtr.release();
1400600cc4afSopenharmony_ci    APP_LOGI("call UninstallAndRecover done");
1401600cc4afSopenharmony_ci    return promise;
1402600cc4afSopenharmony_ci}
1403600cc4afSopenharmony_ci
1404600cc4afSopenharmony_ciErrCode InnerAddExtResource(
1405600cc4afSopenharmony_ci    const std::string &bundleName, const std::vector<std::string> &filePaths)
1406600cc4afSopenharmony_ci{
1407600cc4afSopenharmony_ci    auto extResourceManager = CommonFunc::GetExtendResourceManager();
1408600cc4afSopenharmony_ci    if (extResourceManager == nullptr) {
1409600cc4afSopenharmony_ci        APP_LOGE("extResourceManager is null");
1410600cc4afSopenharmony_ci        return ERROR_BUNDLE_SERVICE_EXCEPTION;
1411600cc4afSopenharmony_ci    }
1412600cc4afSopenharmony_ci
1413600cc4afSopenharmony_ci    std::vector<std::string> destFiles;
1414600cc4afSopenharmony_ci    ErrCode ret = extResourceManager->CopyFiles(filePaths, destFiles);
1415600cc4afSopenharmony_ci    if (ret != ERR_OK) {
1416600cc4afSopenharmony_ci        APP_LOGE("CopyFiles failed");
1417600cc4afSopenharmony_ci        return CommonFunc::ConvertErrCode(ret);
1418600cc4afSopenharmony_ci    }
1419600cc4afSopenharmony_ci
1420600cc4afSopenharmony_ci    ret = extResourceManager->AddExtResource(bundleName, destFiles);
1421600cc4afSopenharmony_ci    if (ret != ERR_OK) {
1422600cc4afSopenharmony_ci        APP_LOGE("AddExtResource failed");
1423600cc4afSopenharmony_ci    }
1424600cc4afSopenharmony_ci
1425600cc4afSopenharmony_ci    return CommonFunc::ConvertErrCode(ret);
1426600cc4afSopenharmony_ci}
1427600cc4afSopenharmony_ci
1428600cc4afSopenharmony_civoid AddExtResourceExec(napi_env env, void *data)
1429600cc4afSopenharmony_ci{
1430600cc4afSopenharmony_ci    ExtResourceCallbackInfo *asyncCallbackInfo = reinterpret_cast<ExtResourceCallbackInfo *>(data);
1431600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1432600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1433600cc4afSopenharmony_ci        return;
1434600cc4afSopenharmony_ci    }
1435600cc4afSopenharmony_ci    asyncCallbackInfo->err = InnerAddExtResource(
1436600cc4afSopenharmony_ci        asyncCallbackInfo->bundleName, asyncCallbackInfo->filePaths);
1437600cc4afSopenharmony_ci}
1438600cc4afSopenharmony_ci
1439600cc4afSopenharmony_civoid AddExtResourceComplete(napi_env env, napi_status status, void *data)
1440600cc4afSopenharmony_ci{
1441600cc4afSopenharmony_ci    ExtResourceCallbackInfo *asyncCallbackInfo = reinterpret_cast<ExtResourceCallbackInfo *>(data);
1442600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1443600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1444600cc4afSopenharmony_ci        return;
1445600cc4afSopenharmony_ci    }
1446600cc4afSopenharmony_ci
1447600cc4afSopenharmony_ci    std::unique_ptr<ExtResourceCallbackInfo> callbackPtr {asyncCallbackInfo};
1448600cc4afSopenharmony_ci    napi_value result[ARGS_POS_TWO] = {0};
1449600cc4afSopenharmony_ci    if (asyncCallbackInfo->err == NO_ERROR) {
1450600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[0]));
1451600cc4afSopenharmony_ci    } else {
1452600cc4afSopenharmony_ci        result[0] = BusinessError::CreateCommonError(
1453600cc4afSopenharmony_ci            env, asyncCallbackInfo->err, ADD_EXT_RESOURCE, Constants::PERMISSION_INSTALL_BUNDLE);
1454600cc4afSopenharmony_ci    }
1455600cc4afSopenharmony_ci
1456600cc4afSopenharmony_ci    CommonFunc::NapiReturnDeferred<ExtResourceCallbackInfo>(
1457600cc4afSopenharmony_ci        env, asyncCallbackInfo, result, ARGS_SIZE_ONE);
1458600cc4afSopenharmony_ci}
1459600cc4afSopenharmony_ci
1460600cc4afSopenharmony_cinapi_value AddExtResource(napi_env env, napi_callback_info info)
1461600cc4afSopenharmony_ci{
1462600cc4afSopenharmony_ci    APP_LOGD("AddExtResource called");
1463600cc4afSopenharmony_ci    NapiArg args(env, info);
1464600cc4afSopenharmony_ci    ExtResourceCallbackInfo *asyncCallbackInfo = new (std::nothrow) ExtResourceCallbackInfo(env);
1465600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1466600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1467600cc4afSopenharmony_ci        return nullptr;
1468600cc4afSopenharmony_ci    }
1469600cc4afSopenharmony_ci    std::unique_ptr<ExtResourceCallbackInfo> callbackPtr {asyncCallbackInfo};
1470600cc4afSopenharmony_ci    if (!args.Init(ARGS_SIZE_TWO, ARGS_SIZE_TWO)) {
1471600cc4afSopenharmony_ci        APP_LOGE("param count invalid");
1472600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1473600cc4afSopenharmony_ci        return nullptr;
1474600cc4afSopenharmony_ci    }
1475600cc4afSopenharmony_ci    for (size_t i = 0; i < args.GetArgc(); ++i) {
1476600cc4afSopenharmony_ci        napi_valuetype valueType = napi_undefined;
1477600cc4afSopenharmony_ci        napi_typeof(env, args[i], &valueType);
1478600cc4afSopenharmony_ci        if (i == ARGS_POS_ZERO) {
1479600cc4afSopenharmony_ci            if (!CommonFunc::ParseString(env, args[i], asyncCallbackInfo->bundleName)) {
1480600cc4afSopenharmony_ci                APP_LOGE("bundleName invalid");
1481600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(
1482600cc4afSopenharmony_ci                    env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING);
1483600cc4afSopenharmony_ci                return nullptr;
1484600cc4afSopenharmony_ci            }
1485600cc4afSopenharmony_ci        } else if (i == ARGS_POS_ONE) {
1486600cc4afSopenharmony_ci            if (CommonFunc::ParseStringArray(env, asyncCallbackInfo->filePaths, args[i]) == nullptr) {
1487600cc4afSopenharmony_ci                APP_LOGE("filePaths invalid");
1488600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(
1489600cc4afSopenharmony_ci                    env, ERROR_PARAM_CHECK_ERROR, FILE_PATH, TYPE_ARRAY);
1490600cc4afSopenharmony_ci                return nullptr;
1491600cc4afSopenharmony_ci            }
1492600cc4afSopenharmony_ci        }
1493600cc4afSopenharmony_ci    }
1494600cc4afSopenharmony_ci    auto promise = CommonFunc::AsyncCallNativeMethod<ExtResourceCallbackInfo>(
1495600cc4afSopenharmony_ci        env, asyncCallbackInfo, "AddExtResource", AddExtResourceExec, AddExtResourceComplete);
1496600cc4afSopenharmony_ci    callbackPtr.release();
1497600cc4afSopenharmony_ci    APP_LOGD("call AddExtResource done");
1498600cc4afSopenharmony_ci    return promise;
1499600cc4afSopenharmony_ci}
1500600cc4afSopenharmony_ci
1501600cc4afSopenharmony_ciErrCode InnerRemoveExtResource(
1502600cc4afSopenharmony_ci    const std::string &bundleName, const std::vector<std::string> &moduleNames)
1503600cc4afSopenharmony_ci{
1504600cc4afSopenharmony_ci    auto extResourceManager = CommonFunc::GetExtendResourceManager();
1505600cc4afSopenharmony_ci    if (extResourceManager == nullptr) {
1506600cc4afSopenharmony_ci        APP_LOGE("extResourceManager is null");
1507600cc4afSopenharmony_ci        return ERROR_BUNDLE_SERVICE_EXCEPTION;
1508600cc4afSopenharmony_ci    }
1509600cc4afSopenharmony_ci
1510600cc4afSopenharmony_ci    ErrCode ret = extResourceManager->RemoveExtResource(bundleName, moduleNames);
1511600cc4afSopenharmony_ci    if (ret != ERR_OK) {
1512600cc4afSopenharmony_ci        APP_LOGE("RemoveExtResource failed");
1513600cc4afSopenharmony_ci    }
1514600cc4afSopenharmony_ci
1515600cc4afSopenharmony_ci    return CommonFunc::ConvertErrCode(ret);
1516600cc4afSopenharmony_ci}
1517600cc4afSopenharmony_ci
1518600cc4afSopenharmony_civoid RemoveExtResourceExec(napi_env env, void *data)
1519600cc4afSopenharmony_ci{
1520600cc4afSopenharmony_ci    ExtResourceCallbackInfo *asyncCallbackInfo = reinterpret_cast<ExtResourceCallbackInfo *>(data);
1521600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1522600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1523600cc4afSopenharmony_ci        return;
1524600cc4afSopenharmony_ci    }
1525600cc4afSopenharmony_ci    asyncCallbackInfo->err = InnerRemoveExtResource(
1526600cc4afSopenharmony_ci        asyncCallbackInfo->bundleName, asyncCallbackInfo->moduleNames);
1527600cc4afSopenharmony_ci}
1528600cc4afSopenharmony_ci
1529600cc4afSopenharmony_civoid RemoveExtResourceComplete(napi_env env, napi_status status, void *data)
1530600cc4afSopenharmony_ci{
1531600cc4afSopenharmony_ci    ExtResourceCallbackInfo *asyncCallbackInfo = reinterpret_cast<ExtResourceCallbackInfo *>(data);
1532600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1533600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1534600cc4afSopenharmony_ci        return;
1535600cc4afSopenharmony_ci    }
1536600cc4afSopenharmony_ci
1537600cc4afSopenharmony_ci    std::unique_ptr<ExtResourceCallbackInfo> callbackPtr {asyncCallbackInfo};
1538600cc4afSopenharmony_ci    napi_value result[ARGS_POS_TWO] = {0};
1539600cc4afSopenharmony_ci    if (asyncCallbackInfo->err == NO_ERROR) {
1540600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[0]));
1541600cc4afSopenharmony_ci    } else {
1542600cc4afSopenharmony_ci        result[0] = BusinessError::CreateCommonError(
1543600cc4afSopenharmony_ci            env, asyncCallbackInfo->err, REMOVE_EXT_RESOURCE, Constants::PERMISSION_INSTALL_BUNDLE);
1544600cc4afSopenharmony_ci    }
1545600cc4afSopenharmony_ci
1546600cc4afSopenharmony_ci    CommonFunc::NapiReturnDeferred<ExtResourceCallbackInfo>(
1547600cc4afSopenharmony_ci        env, asyncCallbackInfo, result, ARGS_SIZE_ONE);
1548600cc4afSopenharmony_ci}
1549600cc4afSopenharmony_ci
1550600cc4afSopenharmony_cinapi_value RemoveExtResource(napi_env env, napi_callback_info info)
1551600cc4afSopenharmony_ci{
1552600cc4afSopenharmony_ci    APP_LOGD("RemoveExtResource called");
1553600cc4afSopenharmony_ci    NapiArg args(env, info);
1554600cc4afSopenharmony_ci    ExtResourceCallbackInfo *asyncCallbackInfo = new (std::nothrow) ExtResourceCallbackInfo(env);
1555600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1556600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1557600cc4afSopenharmony_ci        return nullptr;
1558600cc4afSopenharmony_ci    }
1559600cc4afSopenharmony_ci    std::unique_ptr<ExtResourceCallbackInfo> callbackPtr {asyncCallbackInfo};
1560600cc4afSopenharmony_ci    if (!args.Init(ARGS_SIZE_TWO, ARGS_SIZE_TWO)) {
1561600cc4afSopenharmony_ci        APP_LOGE("param count invalid");
1562600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1563600cc4afSopenharmony_ci        return nullptr;
1564600cc4afSopenharmony_ci    }
1565600cc4afSopenharmony_ci    for (size_t i = 0; i < args.GetArgc(); ++i) {
1566600cc4afSopenharmony_ci        napi_valuetype valueType = napi_undefined;
1567600cc4afSopenharmony_ci        napi_typeof(env, args[i], &valueType);
1568600cc4afSopenharmony_ci        if (i == ARGS_POS_ZERO) {
1569600cc4afSopenharmony_ci            if (!CommonFunc::ParseString(env, args[i], asyncCallbackInfo->bundleName)) {
1570600cc4afSopenharmony_ci                APP_LOGE("bundleName invalid");
1571600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(
1572600cc4afSopenharmony_ci                    env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING);
1573600cc4afSopenharmony_ci                return nullptr;
1574600cc4afSopenharmony_ci            }
1575600cc4afSopenharmony_ci        } else if (i == ARGS_POS_ONE) {
1576600cc4afSopenharmony_ci            if (CommonFunc::ParseStringArray(env, asyncCallbackInfo->moduleNames, args[i]) == nullptr) {
1577600cc4afSopenharmony_ci                APP_LOGE("moduleNames invalid");
1578600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(
1579600cc4afSopenharmony_ci                    env, ERROR_PARAM_CHECK_ERROR, MODULE_NAME, TYPE_ARRAY);
1580600cc4afSopenharmony_ci                return nullptr;
1581600cc4afSopenharmony_ci            }
1582600cc4afSopenharmony_ci        }
1583600cc4afSopenharmony_ci    }
1584600cc4afSopenharmony_ci    auto promise = CommonFunc::AsyncCallNativeMethod<ExtResourceCallbackInfo>(
1585600cc4afSopenharmony_ci        env, asyncCallbackInfo, "RemoveExtResource", RemoveExtResourceExec, RemoveExtResourceComplete);
1586600cc4afSopenharmony_ci    callbackPtr.release();
1587600cc4afSopenharmony_ci    APP_LOGD("call RemoveExtResource done");
1588600cc4afSopenharmony_ci    return promise;
1589600cc4afSopenharmony_ci}
1590600cc4afSopenharmony_ci
1591600cc4afSopenharmony_cistatic ErrCode InnerCreateAppClone(std::string &bundleName, int32_t userId, int32_t &appIndex)
1592600cc4afSopenharmony_ci{
1593600cc4afSopenharmony_ci    auto iBundleMgr = CommonFunc::GetBundleMgr();
1594600cc4afSopenharmony_ci    if (iBundleMgr == nullptr) {
1595600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleMgr");
1596600cc4afSopenharmony_ci        return ERROR_BUNDLE_SERVICE_EXCEPTION;
1597600cc4afSopenharmony_ci    }
1598600cc4afSopenharmony_ci    auto iBundleInstaller = iBundleMgr->GetBundleInstaller();
1599600cc4afSopenharmony_ci    if ((iBundleInstaller == nullptr) || (iBundleInstaller->AsObject() == nullptr)) {
1600600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleInstaller");
1601600cc4afSopenharmony_ci        return ERROR_BUNDLE_SERVICE_EXCEPTION;
1602600cc4afSopenharmony_ci    }
1603600cc4afSopenharmony_ci    ErrCode result = iBundleInstaller->InstallCloneApp(bundleName, userId, appIndex);
1604600cc4afSopenharmony_ci    APP_LOGD("InstallCloneApp result is %{public}d", result);
1605600cc4afSopenharmony_ci    return result;
1606600cc4afSopenharmony_ci}
1607600cc4afSopenharmony_ci
1608600cc4afSopenharmony_civoid CreateAppCloneExec(napi_env env, void *data)
1609600cc4afSopenharmony_ci{
1610600cc4afSopenharmony_ci    CreateAppCloneCallbackInfo *asyncCallbackInfo = reinterpret_cast<CreateAppCloneCallbackInfo *>(data);
1611600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1612600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1613600cc4afSopenharmony_ci        return;
1614600cc4afSopenharmony_ci    }
1615600cc4afSopenharmony_ci    APP_LOGD("CreateAppCloneExec param: bundleName = %{public}s, userId = %{public}d, appIndex = %{public}d",
1616600cc4afSopenharmony_ci        asyncCallbackInfo->bundleName.c_str(),
1617600cc4afSopenharmony_ci        asyncCallbackInfo->userId,
1618600cc4afSopenharmony_ci        asyncCallbackInfo->appIndex);
1619600cc4afSopenharmony_ci    asyncCallbackInfo->err =
1620600cc4afSopenharmony_ci        InnerCreateAppClone(asyncCallbackInfo->bundleName, asyncCallbackInfo->userId, asyncCallbackInfo->appIndex);
1621600cc4afSopenharmony_ci}
1622600cc4afSopenharmony_ci
1623600cc4afSopenharmony_civoid CreateAppCloneComplete(napi_env env, napi_status status, void *data)
1624600cc4afSopenharmony_ci{
1625600cc4afSopenharmony_ci    CreateAppCloneCallbackInfo *asyncCallbackInfo = reinterpret_cast<CreateAppCloneCallbackInfo *>(data);
1626600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1627600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1628600cc4afSopenharmony_ci        return;
1629600cc4afSopenharmony_ci    }
1630600cc4afSopenharmony_ci    std::unique_ptr<CreateAppCloneCallbackInfo> callbackPtr {asyncCallbackInfo};
1631600cc4afSopenharmony_ci    asyncCallbackInfo->err = CommonFunc::ConvertErrCode(asyncCallbackInfo->err);
1632600cc4afSopenharmony_ci    APP_LOGD("CreateAppCloneComplete err is %{public}d, appIndex is %{public}d",
1633600cc4afSopenharmony_ci        asyncCallbackInfo->err,
1634600cc4afSopenharmony_ci        asyncCallbackInfo->appIndex);
1635600cc4afSopenharmony_ci    napi_value result[ARGS_SIZE_TWO] = {0};
1636600cc4afSopenharmony_ci    if (asyncCallbackInfo->err == SUCCESS) {
1637600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[FIRST_PARAM]));
1638600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, asyncCallbackInfo->appIndex, &result[SECOND_PARAM]));
1639600cc4afSopenharmony_ci    } else {
1640600cc4afSopenharmony_ci        result[FIRST_PARAM] = BusinessError::CreateCommonError(env, asyncCallbackInfo->err,
1641600cc4afSopenharmony_ci            CREATE_APP_CLONE, Constants::PERMISSION_INSTALL_CLONE_BUNDLE);
1642600cc4afSopenharmony_ci    }
1643600cc4afSopenharmony_ci    CommonFunc::NapiReturnDeferred<CreateAppCloneCallbackInfo>(env, asyncCallbackInfo, result, ARGS_SIZE_TWO);
1644600cc4afSopenharmony_ci}
1645600cc4afSopenharmony_ci
1646600cc4afSopenharmony_civoid ParseAppCloneParam(napi_env env, napi_value args, int32_t &userId, int32_t &appIndex)
1647600cc4afSopenharmony_ci{
1648600cc4afSopenharmony_ci    if (!ParseUserId(env, args, userId)) {
1649600cc4afSopenharmony_ci        APP_LOGI("parse userId failed. assign a default value = %{public}d", userId);
1650600cc4afSopenharmony_ci    }
1651600cc4afSopenharmony_ci    if (ParseAppIndex(env, args, appIndex)) {
1652600cc4afSopenharmony_ci        if (appIndex == 0) {
1653600cc4afSopenharmony_ci            APP_LOGI("parse appIndex success, but appIndex is 0, assign a value: %{public}d", ILLEGAL_APP_INDEX);
1654600cc4afSopenharmony_ci            appIndex = ILLEGAL_APP_INDEX;
1655600cc4afSopenharmony_ci        }
1656600cc4afSopenharmony_ci    } else {
1657600cc4afSopenharmony_ci        APP_LOGI("parse appIndex failed. assign a default value = %{public}d", appIndex);
1658600cc4afSopenharmony_ci    }
1659600cc4afSopenharmony_ci}
1660600cc4afSopenharmony_ci
1661600cc4afSopenharmony_cinapi_value CreateAppClone(napi_env env, napi_callback_info info)
1662600cc4afSopenharmony_ci{
1663600cc4afSopenharmony_ci    APP_LOGI("begin to CreateAppClone");
1664600cc4afSopenharmony_ci    NapiArg args(env, info);
1665600cc4afSopenharmony_ci    std::unique_ptr<CreateAppCloneCallbackInfo> asyncCallbackInfo = std::make_unique<CreateAppCloneCallbackInfo>(env);
1666600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1667600cc4afSopenharmony_ci        APP_LOGW("asyncCallbackInfo is null");
1668600cc4afSopenharmony_ci        return nullptr;
1669600cc4afSopenharmony_ci    }
1670600cc4afSopenharmony_ci    if (!args.Init(ARGS_SIZE_ONE, ARGS_SIZE_TWO)) {
1671600cc4afSopenharmony_ci        APP_LOGW("param count invalid");
1672600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1673600cc4afSopenharmony_ci        return nullptr;
1674600cc4afSopenharmony_ci    }
1675600cc4afSopenharmony_ci    size_t argc = args.GetMaxArgc();
1676600cc4afSopenharmony_ci    for (size_t i = 0; i < argc; ++i) {
1677600cc4afSopenharmony_ci        napi_valuetype valueType = napi_undefined;
1678600cc4afSopenharmony_ci        napi_typeof(env, args[i], &valueType);
1679600cc4afSopenharmony_ci        if (i == ARGS_POS_ZERO) {
1680600cc4afSopenharmony_ci            if (!CommonFunc::ParseString(env, args[i], asyncCallbackInfo->bundleName)) {
1681600cc4afSopenharmony_ci                APP_LOGW("parse bundleName failed");
1682600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING);
1683600cc4afSopenharmony_ci                return nullptr;
1684600cc4afSopenharmony_ci            }
1685600cc4afSopenharmony_ci        } else if (i == ARGS_POS_ONE) {
1686600cc4afSopenharmony_ci            if (valueType == napi_object) {
1687600cc4afSopenharmony_ci                ParseAppCloneParam(env, args[i], asyncCallbackInfo->userId, asyncCallbackInfo->appIndex);
1688600cc4afSopenharmony_ci            }
1689600cc4afSopenharmony_ci        } else {
1690600cc4afSopenharmony_ci            APP_LOGW("The number of parameters is incorrect");
1691600cc4afSopenharmony_ci            BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1692600cc4afSopenharmony_ci            return nullptr;
1693600cc4afSopenharmony_ci        }
1694600cc4afSopenharmony_ci    }
1695600cc4afSopenharmony_ci    if (asyncCallbackInfo->userId == Constants::UNSPECIFIED_USERID) {
1696600cc4afSopenharmony_ci        asyncCallbackInfo->userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE;
1697600cc4afSopenharmony_ci    }
1698600cc4afSopenharmony_ci    auto promise = CommonFunc::AsyncCallNativeMethod<CreateAppCloneCallbackInfo>(
1699600cc4afSopenharmony_ci        env, asyncCallbackInfo.get(), CREATE_APP_CLONE, CreateAppCloneExec, CreateAppCloneComplete);
1700600cc4afSopenharmony_ci    asyncCallbackInfo.release();
1701600cc4afSopenharmony_ci    APP_LOGI("call napi CreateAppClone done");
1702600cc4afSopenharmony_ci    return promise;
1703600cc4afSopenharmony_ci}
1704600cc4afSopenharmony_ci
1705600cc4afSopenharmony_cistatic ErrCode InnerDestroyAppClone(std::string &bundleName, int32_t userId, int32_t appIndex)
1706600cc4afSopenharmony_ci{
1707600cc4afSopenharmony_ci    auto iBundleMgr = CommonFunc::GetBundleMgr();
1708600cc4afSopenharmony_ci    if (iBundleMgr == nullptr) {
1709600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleMgr");
1710600cc4afSopenharmony_ci        return ERROR_BUNDLE_SERVICE_EXCEPTION;
1711600cc4afSopenharmony_ci    }
1712600cc4afSopenharmony_ci    auto iBundleInstaller = iBundleMgr->GetBundleInstaller();
1713600cc4afSopenharmony_ci    if ((iBundleInstaller == nullptr) || (iBundleInstaller->AsObject() == nullptr)) {
1714600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleInstaller");
1715600cc4afSopenharmony_ci        return ERROR_BUNDLE_SERVICE_EXCEPTION;
1716600cc4afSopenharmony_ci    }
1717600cc4afSopenharmony_ci    ErrCode result = iBundleInstaller->UninstallCloneApp(bundleName, userId, appIndex);
1718600cc4afSopenharmony_ci    APP_LOGD("UninstallCloneApp result is %{public}d", result);
1719600cc4afSopenharmony_ci    return result;
1720600cc4afSopenharmony_ci}
1721600cc4afSopenharmony_ci
1722600cc4afSopenharmony_civoid DestroyAppCloneExec(napi_env env, void *data)
1723600cc4afSopenharmony_ci{
1724600cc4afSopenharmony_ci    CreateAppCloneCallbackInfo *asyncCallbackInfo = reinterpret_cast<CreateAppCloneCallbackInfo *>(data);
1725600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1726600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1727600cc4afSopenharmony_ci        return;
1728600cc4afSopenharmony_ci    }
1729600cc4afSopenharmony_ci    APP_LOGD("DestroyAppCloneExec param: bundleName = %{public}s, userId = %{public}d, appIndex = %{public}d",
1730600cc4afSopenharmony_ci        asyncCallbackInfo->bundleName.c_str(),
1731600cc4afSopenharmony_ci        asyncCallbackInfo->userId,
1732600cc4afSopenharmony_ci        asyncCallbackInfo->appIndex);
1733600cc4afSopenharmony_ci    asyncCallbackInfo->err =
1734600cc4afSopenharmony_ci        InnerDestroyAppClone(asyncCallbackInfo->bundleName, asyncCallbackInfo->userId, asyncCallbackInfo->appIndex);
1735600cc4afSopenharmony_ci}
1736600cc4afSopenharmony_ci
1737600cc4afSopenharmony_civoid DestroyAppCloneComplete(napi_env env, napi_status status, void *data)
1738600cc4afSopenharmony_ci{
1739600cc4afSopenharmony_ci    CreateAppCloneCallbackInfo *asyncCallbackInfo = reinterpret_cast<CreateAppCloneCallbackInfo *>(data);
1740600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1741600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1742600cc4afSopenharmony_ci        return;
1743600cc4afSopenharmony_ci    }
1744600cc4afSopenharmony_ci    std::unique_ptr<CreateAppCloneCallbackInfo> callbackPtr {asyncCallbackInfo};
1745600cc4afSopenharmony_ci    asyncCallbackInfo->err = CommonFunc::ConvertErrCode(asyncCallbackInfo->err);
1746600cc4afSopenharmony_ci    APP_LOGD("DestroyAppCloneComplete err is %{public}d, appIndex is %{public}d",
1747600cc4afSopenharmony_ci        asyncCallbackInfo->err,
1748600cc4afSopenharmony_ci        asyncCallbackInfo->appIndex);
1749600cc4afSopenharmony_ci    napi_value result[ARGS_SIZE_TWO] = {0};
1750600cc4afSopenharmony_ci    if (asyncCallbackInfo->err == SUCCESS) {
1751600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[FIRST_PARAM]));
1752600cc4afSopenharmony_ci    } else {
1753600cc4afSopenharmony_ci        result[FIRST_PARAM] = BusinessError::CreateCommonError(env, asyncCallbackInfo->err,
1754600cc4afSopenharmony_ci            DESTROY_APP_CLONE, Constants::PERMISSION_UNINSTALL_CLONE_BUNDLE);
1755600cc4afSopenharmony_ci    }
1756600cc4afSopenharmony_ci    CommonFunc::NapiReturnDeferred<CreateAppCloneCallbackInfo>(env, asyncCallbackInfo, result, ARGS_SIZE_ONE);
1757600cc4afSopenharmony_ci}
1758600cc4afSopenharmony_ci
1759600cc4afSopenharmony_cinapi_value DestroyAppClone(napi_env env, napi_callback_info info)
1760600cc4afSopenharmony_ci{
1761600cc4afSopenharmony_ci    APP_LOGI("begin to destroyAppClone");
1762600cc4afSopenharmony_ci    NapiArg args(env, info);
1763600cc4afSopenharmony_ci    std::unique_ptr<CreateAppCloneCallbackInfo> asyncCallbackInfo = std::make_unique<CreateAppCloneCallbackInfo>(env);
1764600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1765600cc4afSopenharmony_ci        APP_LOGW("asyncCallbackInfo is null");
1766600cc4afSopenharmony_ci        return nullptr;
1767600cc4afSopenharmony_ci    }
1768600cc4afSopenharmony_ci    if (!args.Init(ARGS_SIZE_TWO, ARGS_SIZE_THREE)) {
1769600cc4afSopenharmony_ci        APP_LOGW("param count invalid");
1770600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1771600cc4afSopenharmony_ci        return nullptr;
1772600cc4afSopenharmony_ci    }
1773600cc4afSopenharmony_ci    size_t argc = args.GetMaxArgc();
1774600cc4afSopenharmony_ci    for (size_t i = 0; i < argc; ++i) {
1775600cc4afSopenharmony_ci        napi_valuetype valueType = napi_undefined;
1776600cc4afSopenharmony_ci        napi_typeof(env, args[i], &valueType);
1777600cc4afSopenharmony_ci        if (i == ARGS_POS_ZERO) {
1778600cc4afSopenharmony_ci            if (!CommonFunc::ParseString(env, args[i], asyncCallbackInfo->bundleName)) {
1779600cc4afSopenharmony_ci                APP_LOGW("parse bundleName failed");
1780600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING);
1781600cc4afSopenharmony_ci                return nullptr;
1782600cc4afSopenharmony_ci            }
1783600cc4afSopenharmony_ci        } else if (i == ARGS_POS_ONE) {
1784600cc4afSopenharmony_ci            if (!CommonFunc::ParseInt(env, args[i], asyncCallbackInfo->appIndex)) {
1785600cc4afSopenharmony_ci                APP_LOGW("parse appIndex failed");
1786600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, APP_INDEX, TYPE_NUMBER);
1787600cc4afSopenharmony_ci                return nullptr;
1788600cc4afSopenharmony_ci            }
1789600cc4afSopenharmony_ci        } else if (i == ARGS_POS_TWO) {
1790600cc4afSopenharmony_ci            if (!CommonFunc::ParseInt(env, args[i], asyncCallbackInfo->userId)) {
1791600cc4afSopenharmony_ci                APP_LOGW("Parse userId failed, set this parameter to the caller userId");
1792600cc4afSopenharmony_ci            }
1793600cc4afSopenharmony_ci        } else {
1794600cc4afSopenharmony_ci            APP_LOGE("The number of parameters is incorrect");
1795600cc4afSopenharmony_ci            BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1796600cc4afSopenharmony_ci            return nullptr;
1797600cc4afSopenharmony_ci        }
1798600cc4afSopenharmony_ci    }
1799600cc4afSopenharmony_ci    if (asyncCallbackInfo->userId == Constants::UNSPECIFIED_USERID) {
1800600cc4afSopenharmony_ci        asyncCallbackInfo->userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE;
1801600cc4afSopenharmony_ci    }
1802600cc4afSopenharmony_ci    auto promise = CommonFunc::AsyncCallNativeMethod<CreateAppCloneCallbackInfo>(
1803600cc4afSopenharmony_ci        env, asyncCallbackInfo.get(), DESTROY_APP_CLONE, DestroyAppCloneExec, DestroyAppCloneComplete);
1804600cc4afSopenharmony_ci    asyncCallbackInfo.release();
1805600cc4afSopenharmony_ci    APP_LOGI("call napi destroyAppTwin done");
1806600cc4afSopenharmony_ci    return promise;
1807600cc4afSopenharmony_ci}
1808600cc4afSopenharmony_ci
1809600cc4afSopenharmony_cistatic ErrCode InnerInstallPreexistingApp(std::string &bundleName, int32_t userId)
1810600cc4afSopenharmony_ci{
1811600cc4afSopenharmony_ci    auto iBundleMgr = CommonFunc::GetBundleMgr();
1812600cc4afSopenharmony_ci    if (iBundleMgr == nullptr) {
1813600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleMgr");
1814600cc4afSopenharmony_ci        return ERROR_BUNDLE_SERVICE_EXCEPTION;
1815600cc4afSopenharmony_ci    }
1816600cc4afSopenharmony_ci    auto iBundleInstaller = iBundleMgr->GetBundleInstaller();
1817600cc4afSopenharmony_ci    if ((iBundleInstaller == nullptr) || (iBundleInstaller->AsObject() == nullptr)) {
1818600cc4afSopenharmony_ci        APP_LOGE("can not get iBundleInstaller");
1819600cc4afSopenharmony_ci        return ERROR_BUNDLE_SERVICE_EXCEPTION;
1820600cc4afSopenharmony_ci    }
1821600cc4afSopenharmony_ci    ErrCode result = iBundleInstaller->InstallExisted(bundleName, userId);
1822600cc4afSopenharmony_ci    APP_LOGD("result is %{public}d", result);
1823600cc4afSopenharmony_ci    return result;
1824600cc4afSopenharmony_ci}
1825600cc4afSopenharmony_ci
1826600cc4afSopenharmony_civoid InstallPreexistingAppExec(napi_env env, void *data)
1827600cc4afSopenharmony_ci{
1828600cc4afSopenharmony_ci    InstallPreexistingAppCallbackInfo *asyncCallbackInfo = reinterpret_cast<InstallPreexistingAppCallbackInfo *>(data);
1829600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1830600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1831600cc4afSopenharmony_ci        return;
1832600cc4afSopenharmony_ci    }
1833600cc4afSopenharmony_ci    APP_LOGD("param: bundleName = %{public}s, userId = %{public}d",
1834600cc4afSopenharmony_ci        asyncCallbackInfo->bundleName.c_str(),
1835600cc4afSopenharmony_ci        asyncCallbackInfo->userId);
1836600cc4afSopenharmony_ci    asyncCallbackInfo->err =
1837600cc4afSopenharmony_ci        InnerInstallPreexistingApp(asyncCallbackInfo->bundleName, asyncCallbackInfo->userId);
1838600cc4afSopenharmony_ci}
1839600cc4afSopenharmony_ci
1840600cc4afSopenharmony_civoid InstallPreexistingAppComplete(napi_env env, napi_status status, void *data)
1841600cc4afSopenharmony_ci{
1842600cc4afSopenharmony_ci    InstallPreexistingAppCallbackInfo *asyncCallbackInfo = reinterpret_cast<InstallPreexistingAppCallbackInfo *>(data);
1843600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1844600cc4afSopenharmony_ci        APP_LOGE("asyncCallbackInfo is null");
1845600cc4afSopenharmony_ci        return;
1846600cc4afSopenharmony_ci    }
1847600cc4afSopenharmony_ci    std::unique_ptr<InstallPreexistingAppCallbackInfo> callbackPtr {asyncCallbackInfo};
1848600cc4afSopenharmony_ci    asyncCallbackInfo->err = CommonFunc::ConvertErrCode(asyncCallbackInfo->err);
1849600cc4afSopenharmony_ci    APP_LOGD("err is %{public}d", asyncCallbackInfo->err);
1850600cc4afSopenharmony_ci
1851600cc4afSopenharmony_ci    napi_value result[ARGS_SIZE_ONE] = {0};
1852600cc4afSopenharmony_ci    if (asyncCallbackInfo->err == SUCCESS) {
1853600cc4afSopenharmony_ci        NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[FIRST_PARAM]));
1854600cc4afSopenharmony_ci    } else {
1855600cc4afSopenharmony_ci        result[FIRST_PARAM] = BusinessError::CreateCommonError(env, asyncCallbackInfo->err,
1856600cc4afSopenharmony_ci            INSTALL_PREEXISTING_APP, Constants::PERMISSION_INSTALL_BUNDLE);
1857600cc4afSopenharmony_ci    }
1858600cc4afSopenharmony_ci    CommonFunc::NapiReturnDeferred<InstallPreexistingAppCallbackInfo>(env, asyncCallbackInfo, result, ARGS_SIZE_ONE);
1859600cc4afSopenharmony_ci}
1860600cc4afSopenharmony_ci
1861600cc4afSopenharmony_cinapi_value InstallPreexistingApp(napi_env env, napi_callback_info info)
1862600cc4afSopenharmony_ci{
1863600cc4afSopenharmony_ci    APP_LOGI("begin");
1864600cc4afSopenharmony_ci    NapiArg args(env, info);
1865600cc4afSopenharmony_ci    std::unique_ptr<InstallPreexistingAppCallbackInfo> asyncCallbackInfo
1866600cc4afSopenharmony_ci        = std::make_unique<InstallPreexistingAppCallbackInfo>(env);
1867600cc4afSopenharmony_ci    if (asyncCallbackInfo == nullptr) {
1868600cc4afSopenharmony_ci        APP_LOGW("asyncCallbackInfo is null");
1869600cc4afSopenharmony_ci        return nullptr;
1870600cc4afSopenharmony_ci    }
1871600cc4afSopenharmony_ci    if (!args.Init(ARGS_SIZE_ONE, ARGS_SIZE_TWO)) {
1872600cc4afSopenharmony_ci        APP_LOGW("param count invalid");
1873600cc4afSopenharmony_ci        BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1874600cc4afSopenharmony_ci        return nullptr;
1875600cc4afSopenharmony_ci    }
1876600cc4afSopenharmony_ci    size_t argc = args.GetMaxArgc();
1877600cc4afSopenharmony_ci    for (size_t i = 0; i < argc; ++i) {
1878600cc4afSopenharmony_ci        if (i == ARGS_POS_ZERO) {
1879600cc4afSopenharmony_ci            if (!CommonFunc::ParseString(env, args[i], asyncCallbackInfo->bundleName)) {
1880600cc4afSopenharmony_ci                APP_LOGW("parse bundleName failed");
1881600cc4afSopenharmony_ci                BusinessError::ThrowParameterTypeError(env, ERROR_PARAM_CHECK_ERROR, BUNDLE_NAME, TYPE_STRING);
1882600cc4afSopenharmony_ci                return nullptr;
1883600cc4afSopenharmony_ci            }
1884600cc4afSopenharmony_ci        } else if (i == ARGS_POS_ONE) {
1885600cc4afSopenharmony_ci            if (!CommonFunc::ParseInt(env, args[i], asyncCallbackInfo->userId)) {
1886600cc4afSopenharmony_ci                APP_LOGW("parse userId failed");
1887600cc4afSopenharmony_ci            }
1888600cc4afSopenharmony_ci        } else {
1889600cc4afSopenharmony_ci            APP_LOGW("The number of parameters is incorrect");
1890600cc4afSopenharmony_ci            BusinessError::ThrowTooFewParametersError(env, ERROR_PARAM_CHECK_ERROR);
1891600cc4afSopenharmony_ci            return nullptr;
1892600cc4afSopenharmony_ci        }
1893600cc4afSopenharmony_ci    }
1894600cc4afSopenharmony_ci    if (asyncCallbackInfo->userId == Constants::UNSPECIFIED_USERID) {
1895600cc4afSopenharmony_ci        asyncCallbackInfo->userId = IPCSkeleton::GetCallingUid() / Constants::BASE_USER_RANGE;
1896600cc4afSopenharmony_ci    }
1897600cc4afSopenharmony_ci    auto promise = CommonFunc::AsyncCallNativeMethod<InstallPreexistingAppCallbackInfo>(
1898600cc4afSopenharmony_ci        env, asyncCallbackInfo.get(), INSTALL_PREEXISTING_APP,
1899600cc4afSopenharmony_ci        InstallPreexistingAppExec, InstallPreexistingAppComplete);
1900600cc4afSopenharmony_ci    asyncCallbackInfo.release();
1901600cc4afSopenharmony_ci    APP_LOGI("call napi done");
1902600cc4afSopenharmony_ci    return promise;
1903600cc4afSopenharmony_ci}
1904600cc4afSopenharmony_ci} // AppExecFwk
1905600cc4afSopenharmony_ci} // OHOS