• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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/**
17 * @file
18 * @kit AbilityKit
19 */
20
21import { AsyncCallback, BusinessError } from '@ohos.base';
22
23namespace installer {
24  loadLibrary("ani_bundle_installer.z");
25
26  export native function getBundleInstallerNative(isSync: boolean): BundleInstaller;
27
28  function getBundleInstaller(callback: AsyncCallback<BundleInstaller>): void {
29    let execFun = (): BundleInstaller => {
30      return installer.getBundleInstallerNative(false);
31    };
32    let p1 = taskpool.execute(execFun);
33    p1.then((e: NullishType) => {
34      let installer: BundleInstaller = e as BundleInstaller;
35      callback(null, installer);
36    }, (err: Object): void => {
37    });
38  }
39
40  function getBundleInstaller(): Promise<BundleInstaller> {
41    let p = new Promise<BundleInstaller>((resolve: (bundleInstaller: BundleInstaller) => void, reject: (error: Error) => void) => {
42      let execFun = (): BundleInstaller => {
43        return installer.getBundleInstallerNative(false);
44      };
45      let p1 = taskpool.execute(execFun);
46        p1.then((e: NullishType) => {
47          let installer: BundleInstaller = e as BundleInstaller;
48          resolve(installer);
49        }, (err: Error): void => {
50            let br = err as BusinessError<void>;
51            reject(br);
52        });
53    });
54    return p;
55  }
56
57  function getBundleInstallerSync(): BundleInstaller {
58    return installer.getBundleInstallerNative(true);
59  }
60
61  interface BundleInstaller {
62
63    install(hapFilePaths: Array<string>, installParam: InstallParam, callback: AsyncCallback<void>): void;
64
65    install(hapFilePaths: Array<string>, callback: AsyncCallback<void>): void;
66
67    install(hapFilePaths: Array<string>, installParam?: InstallParam): Promise<void>;
68
69    uninstall(bundleName: string, installParam: InstallParam, callback: AsyncCallback<void>): void;
70
71    uninstall(bundleName: string, callback: AsyncCallback<void>): void;
72
73    uninstall(bundleName: string, installParam?: InstallParam): Promise<void>;
74
75    recover(bundleName: string, installParam: InstallParam, callback: AsyncCallback<void>): void;
76
77    recover(bundleName: string, callback: AsyncCallback<void>): void;
78
79    recover(bundleName: string, installParam?: InstallParam): Promise<void>;
80
81    uninstall(uninstallParam: UninstallParam, callback: AsyncCallback<void>): void;
82
83    uninstall(uninstallParam: UninstallParam): Promise<void>;
84
85    updateBundleForSelf(hapFilePaths: Array<string>, installParam: InstallParam, callback: AsyncCallback<void>): void;
86
87    updateBundleForSelf(hapFilePaths: Array<string>, callback: AsyncCallback<void>): void;
88
89    updateBundleForSelf(hapFilePaths: Array<string>, installParam?: InstallParam): Promise<void>;
90
91    uninstallUpdates(bundleName: string, installParam?: InstallParam): Promise<void>;
92
93    addExtResource(bundleName: string, filePaths: Array<string>): Promise<void>;
94
95    removeExtResource(bundleName: string, moduleNames: Array<string>): Promise<void>;
96
97    createAppClone(bundleName: string, createAppCloneParam?: CreateAppCloneParam): Promise<number>;
98
99    destroyAppClone(bundleName: string, appIndex: number, options?: number | DestroyAppCloneParam): Promise<void>;
100
101    installPreexistingApp(bundleName: string, userId?: number): Promise<void>;
102
103    installPlugin(hostBundleName: string, pluginFilePaths: Array<string>, pluginParam?: PluginParam): Promise<void>;
104
105    uninstallPlugin(hostBundleName: string, pluginBundleName: string, pluginParam?: PluginParam): Promise<void>;
106  }
107
108  export interface HashParam {
109    moduleName: string;
110    hashValue: string;
111  }
112
113  export interface PGOParam {
114    moduleName: string;
115    pgoFilePath: string;
116  }
117
118  export interface Parameters {
119    key: string;
120    value: string;
121  }
122
123  export interface InstallParam {
124    userId?: number;
125    installFlag?: number;
126    isKeepData?: boolean;
127    hashParams?: Array<HashParam>;
128    crowdtestDeadline?: number;
129    sharedBundleDirPaths?: Array<string>;
130    specifiedDistributionType?: string;
131    additionalInfo?: string;
132    pgoParams?: Array<PGOParam>;
133    parameters?: Array<Parameters>;
134  }
135
136  export interface UninstallParam {
137    bundleName: string;
138    versionCode?: number;
139  }
140
141  export interface CreateAppCloneParam {
142    userId?: number;
143    appIndex?: number;
144  }
145
146  export interface DestroyAppCloneParam {
147    userId?: number;
148    parameters?: Array<Parameters>;
149  }
150
151  export interface PluginParam {
152    userId?: number;
153    parameters?: Array<Parameters>;
154  }
155}
156
157export default installer;
158