1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#ifndef FOUNDATION_BUNDLEMGR_SERVICES_KITS_INCLUDE_INSTALLER_H 17#define FOUNDATION_BUNDLEMGR_SERVICES_KITS_INCLUDE_INSTALLER_H 18 19#include "base_cb_info.h" 20#include "install_param.h" 21#include "napi/native_api.h" 22#include "napi/native_common.h" 23#include "napi/native_node_api.h" 24 25namespace OHOS { 26namespace AppExecFwk { 27extern thread_local napi_ref g_classBundleInstaller; 28 29struct InstallResult { 30 int32_t resultCode = 0; 31 std::string resultMsg; 32}; 33 34enum class InstallOption { 35 INSTALL = 0, 36 RECOVER = 1, 37 UNINSTALL = 2, 38 UPDATE_BUNDLE_FOR_SELF = 3, 39 UNKNOWN = 4, 40 UNINSTALL_AND_RECOVER = 5, 41}; 42 43struct AsyncInstallCallbackInfo { 44 explicit AsyncInstallCallbackInfo(napi_env napiEnv) : env(napiEnv) {} 45 ~AsyncInstallCallbackInfo(); 46 47 std::vector<std::string> hapFiles; 48 std::string bundleName; 49 std::string param; 50 OHOS::AppExecFwk::InstallParam installParam; 51 OHOS::AppExecFwk::UninstallParam uninstallParam; 52 InstallResult installResult; 53 int32_t err = 0; 54 InstallOption option = InstallOption::UNKNOWN; 55 56 napi_env env; 57 napi_async_work asyncWork = nullptr; 58 napi_deferred deferred = nullptr; 59 napi_ref callback = nullptr; 60}; 61 62struct AsyncGetBundleInstallerCallbackInfo { 63 explicit AsyncGetBundleInstallerCallbackInfo(napi_env napiEnv) : env(napiEnv) {} 64 ~AsyncGetBundleInstallerCallbackInfo(); 65 66 napi_env env; 67 napi_async_work asyncWork = nullptr; 68 napi_deferred deferred = nullptr; 69 napi_ref callback = nullptr; 70}; 71 72struct ExtResourceCallbackInfo : public BaseCallbackInfo { 73 explicit ExtResourceCallbackInfo(napi_env env) : BaseCallbackInfo(env) {} 74 std::string bundleName; 75 std::vector<std::string> moduleNames; 76 std::vector<std::string> filePaths; 77}; 78 79struct CreateAppCloneCallbackInfo : public BaseCallbackInfo { 80 explicit CreateAppCloneCallbackInfo(napi_env napiEnv) : BaseCallbackInfo(napiEnv) {} 81 std::string bundleName; 82 int32_t userId = Constants::UNSPECIFIED_USERID; 83 int32_t appIndex = Constants::INITIAL_APP_INDEX; 84}; 85 86struct InstallPreexistingAppCallbackInfo : public BaseCallbackInfo { 87 explicit InstallPreexistingAppCallbackInfo(napi_env napiEnv) : BaseCallbackInfo(napiEnv) {} 88 std::string bundleName; 89 int32_t userId = Constants::UNSPECIFIED_USERID; 90}; 91 92napi_value GetBundleInstaller(napi_env env, napi_callback_info info); 93napi_value GetBundleInstallerSync(napi_env env, napi_callback_info info); 94napi_value Install(napi_env env, napi_callback_info info); 95napi_value Recover(napi_env env, napi_callback_info info); 96napi_value Uninstall(napi_env env, napi_callback_info info); 97napi_value BundleInstallerConstructor(napi_env env, napi_callback_info info); 98napi_value UpdateBundleForSelf(napi_env env, napi_callback_info info); 99napi_value UninstallAndRecover(napi_env env, napi_callback_info info); 100napi_value AddExtResource(napi_env env, napi_callback_info info); 101napi_value RemoveExtResource(napi_env env, napi_callback_info info); 102napi_value CreateAppClone(napi_env env, napi_callback_info info); 103napi_value DestroyAppClone(napi_env env, napi_callback_info info); 104napi_value InstallPreexistingApp(napi_env env, napi_callback_info info); 105} // AppExecFwk 106} // OHOS 107#endif // FOUNDATION_BUNDLEMGR_SERVICES_KITS_INCLUDE_INSTALLER_H