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 "install_param.h" 20 #include "napi/native_api.h" 21 #include "napi/native_common.h" 22 #include "napi/native_node_api.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 extern thread_local napi_ref g_classBundleInstaller; 27 28 struct InstallResult { 29 int32_t resultCode = 0; 30 std::string resultMsg; 31 }; 32 33 enum class InstallOption { 34 INSTALL = 0, 35 RECOVER = 1, 36 UNINSTALL = 2, 37 UPDATE_BUNDLE_FOR_SELF = 3, 38 UNKNOWN = 4 39 }; 40 41 struct AsyncInstallCallbackInfo { AsyncInstallCallbackInfoAsyncInstallCallbackInfo42 explicit AsyncInstallCallbackInfo(napi_env napiEnv) : env(napiEnv) {} 43 ~AsyncInstallCallbackInfo(); 44 45 std::vector<std::string> hapFiles; 46 std::string bundleName; 47 std::string param; 48 OHOS::AppExecFwk::InstallParam installParam; 49 OHOS::AppExecFwk::UninstallParam uninstallParam; 50 InstallResult installResult; 51 int32_t err = 0; 52 InstallOption option = InstallOption::UNKNOWN; 53 54 napi_env env; 55 napi_async_work asyncWork = nullptr; 56 napi_deferred deferred = nullptr; 57 napi_ref callback = nullptr; 58 }; 59 60 struct AsyncGetBundleInstallerCallbackInfo { AsyncGetBundleInstallerCallbackInfoAsyncGetBundleInstallerCallbackInfo61 explicit AsyncGetBundleInstallerCallbackInfo(napi_env napiEnv) : env(napiEnv) {} 62 ~AsyncGetBundleInstallerCallbackInfo(); 63 64 napi_env env; 65 napi_async_work asyncWork = nullptr; 66 napi_deferred deferred = nullptr; 67 napi_ref callback = nullptr; 68 }; 69 70 napi_value GetBundleInstaller(napi_env env, napi_callback_info info); 71 napi_value GetBundleInstallerSync(napi_env env, napi_callback_info info); 72 napi_value Install(napi_env env, napi_callback_info info); 73 napi_value Recover(napi_env env, napi_callback_info info); 74 napi_value Uninstall(napi_env env, napi_callback_info info); 75 napi_value BundleInstallerConstructor(napi_env env, napi_callback_info info); 76 napi_value UpdateBundleForSelf(napi_env env, napi_callback_info info); 77 } // AppExecFwk 78 } // OHOS 79 #endif // FOUNDATION_BUNDLEMGR_SERVICES_KITS_INCLUDE_INSTALLER_H