1600cc4afSopenharmony_ci/*
2600cc4afSopenharmony_ci * Copyright (c) 2022 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#ifndef FOUNDATION_BUNDLEMGR_SERVICES_KITS_INCLUDE_INSTALLER_H
17600cc4afSopenharmony_ci#define FOUNDATION_BUNDLEMGR_SERVICES_KITS_INCLUDE_INSTALLER_H
18600cc4afSopenharmony_ci
19600cc4afSopenharmony_ci#include "base_cb_info.h"
20600cc4afSopenharmony_ci#include "install_param.h"
21600cc4afSopenharmony_ci#include "napi/native_api.h"
22600cc4afSopenharmony_ci#include "napi/native_common.h"
23600cc4afSopenharmony_ci#include "napi/native_node_api.h"
24600cc4afSopenharmony_ci
25600cc4afSopenharmony_cinamespace OHOS {
26600cc4afSopenharmony_cinamespace AppExecFwk {
27600cc4afSopenharmony_ciextern thread_local napi_ref g_classBundleInstaller;
28600cc4afSopenharmony_ci
29600cc4afSopenharmony_cistruct InstallResult {
30600cc4afSopenharmony_ci    int32_t resultCode = 0;
31600cc4afSopenharmony_ci    std::string resultMsg;
32600cc4afSopenharmony_ci};
33600cc4afSopenharmony_ci
34600cc4afSopenharmony_cienum class InstallOption {
35600cc4afSopenharmony_ci    INSTALL = 0,
36600cc4afSopenharmony_ci    RECOVER = 1,
37600cc4afSopenharmony_ci    UNINSTALL = 2,
38600cc4afSopenharmony_ci    UPDATE_BUNDLE_FOR_SELF = 3,
39600cc4afSopenharmony_ci    UNKNOWN = 4,
40600cc4afSopenharmony_ci    UNINSTALL_AND_RECOVER = 5,
41600cc4afSopenharmony_ci};
42600cc4afSopenharmony_ci
43600cc4afSopenharmony_cistruct AsyncInstallCallbackInfo {
44600cc4afSopenharmony_ci    explicit AsyncInstallCallbackInfo(napi_env napiEnv) : env(napiEnv) {}
45600cc4afSopenharmony_ci    ~AsyncInstallCallbackInfo();
46600cc4afSopenharmony_ci
47600cc4afSopenharmony_ci    std::vector<std::string> hapFiles;
48600cc4afSopenharmony_ci    std::string bundleName;
49600cc4afSopenharmony_ci    std::string param;
50600cc4afSopenharmony_ci    OHOS::AppExecFwk::InstallParam installParam;
51600cc4afSopenharmony_ci    OHOS::AppExecFwk::UninstallParam uninstallParam;
52600cc4afSopenharmony_ci    InstallResult installResult;
53600cc4afSopenharmony_ci    int32_t err = 0;
54600cc4afSopenharmony_ci    InstallOption option = InstallOption::UNKNOWN;
55600cc4afSopenharmony_ci
56600cc4afSopenharmony_ci    napi_env env;
57600cc4afSopenharmony_ci    napi_async_work asyncWork = nullptr;
58600cc4afSopenharmony_ci    napi_deferred deferred = nullptr;
59600cc4afSopenharmony_ci    napi_ref callback = nullptr;
60600cc4afSopenharmony_ci};
61600cc4afSopenharmony_ci
62600cc4afSopenharmony_cistruct AsyncGetBundleInstallerCallbackInfo {
63600cc4afSopenharmony_ci    explicit AsyncGetBundleInstallerCallbackInfo(napi_env napiEnv) : env(napiEnv) {}
64600cc4afSopenharmony_ci    ~AsyncGetBundleInstallerCallbackInfo();
65600cc4afSopenharmony_ci
66600cc4afSopenharmony_ci    napi_env env;
67600cc4afSopenharmony_ci    napi_async_work asyncWork = nullptr;
68600cc4afSopenharmony_ci    napi_deferred deferred = nullptr;
69600cc4afSopenharmony_ci    napi_ref callback = nullptr;
70600cc4afSopenharmony_ci};
71600cc4afSopenharmony_ci
72600cc4afSopenharmony_cistruct ExtResourceCallbackInfo : public BaseCallbackInfo {
73600cc4afSopenharmony_ci    explicit ExtResourceCallbackInfo(napi_env env) : BaseCallbackInfo(env) {}
74600cc4afSopenharmony_ci    std::string bundleName;
75600cc4afSopenharmony_ci    std::vector<std::string> moduleNames;
76600cc4afSopenharmony_ci    std::vector<std::string> filePaths;
77600cc4afSopenharmony_ci};
78600cc4afSopenharmony_ci
79600cc4afSopenharmony_cistruct CreateAppCloneCallbackInfo : public BaseCallbackInfo {
80600cc4afSopenharmony_ci    explicit CreateAppCloneCallbackInfo(napi_env napiEnv) : BaseCallbackInfo(napiEnv) {}
81600cc4afSopenharmony_ci    std::string bundleName;
82600cc4afSopenharmony_ci    int32_t userId = Constants::UNSPECIFIED_USERID;
83600cc4afSopenharmony_ci    int32_t appIndex = Constants::INITIAL_APP_INDEX;
84600cc4afSopenharmony_ci};
85600cc4afSopenharmony_ci
86600cc4afSopenharmony_cistruct InstallPreexistingAppCallbackInfo : public BaseCallbackInfo {
87600cc4afSopenharmony_ci    explicit InstallPreexistingAppCallbackInfo(napi_env napiEnv) : BaseCallbackInfo(napiEnv) {}
88600cc4afSopenharmony_ci    std::string bundleName;
89600cc4afSopenharmony_ci    int32_t userId = Constants::UNSPECIFIED_USERID;
90600cc4afSopenharmony_ci};
91600cc4afSopenharmony_ci
92600cc4afSopenharmony_cinapi_value GetBundleInstaller(napi_env env, napi_callback_info info);
93600cc4afSopenharmony_cinapi_value GetBundleInstallerSync(napi_env env, napi_callback_info info);
94600cc4afSopenharmony_cinapi_value Install(napi_env env, napi_callback_info info);
95600cc4afSopenharmony_cinapi_value Recover(napi_env env, napi_callback_info info);
96600cc4afSopenharmony_cinapi_value Uninstall(napi_env env, napi_callback_info info);
97600cc4afSopenharmony_cinapi_value BundleInstallerConstructor(napi_env env, napi_callback_info info);
98600cc4afSopenharmony_cinapi_value UpdateBundleForSelf(napi_env env, napi_callback_info info);
99600cc4afSopenharmony_cinapi_value UninstallAndRecover(napi_env env, napi_callback_info info);
100600cc4afSopenharmony_cinapi_value AddExtResource(napi_env env, napi_callback_info info);
101600cc4afSopenharmony_cinapi_value RemoveExtResource(napi_env env, napi_callback_info info);
102600cc4afSopenharmony_cinapi_value CreateAppClone(napi_env env, napi_callback_info info);
103600cc4afSopenharmony_cinapi_value DestroyAppClone(napi_env env, napi_callback_info info);
104600cc4afSopenharmony_cinapi_value InstallPreexistingApp(napi_env env, napi_callback_info info);
105600cc4afSopenharmony_ci} // AppExecFwk
106600cc4afSopenharmony_ci} // OHOS
107600cc4afSopenharmony_ci#endif // FOUNDATION_BUNDLEMGR_SERVICES_KITS_INCLUDE_INSTALLER_H