• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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
16import { AsyncCallback, Callback } from './basic';
17import { ApplicationInfo } from './bundle/applicationInfo';
18import { BundleInfo } from './bundle/bundleInfo';
19import { AbilityInfo } from './bundle/abilityInfo';
20import { Want } from './ability/want';
21import { BundleInstaller } from './bundle/bundleInstaller';
22import { PermissionDef } from  './bundle/PermissionDef';
23import image from './@ohos.multimedia.image';
24
25/**
26 * bundle.
27 * @name bundle
28 * @since 7
29 * @syscap SystemCapability.BundleManager.BundleFramework
30 * @permission NA
31 */
32declare namespace bundle {
33
34/**
35 * @name BundleFlag
36 * @since 7
37 * @syscap SystemCapability.BundleManager.BundleFramework
38 * @import NA
39 * @permission NA
40 */
41  enum BundleFlag {
42    GET_BUNDLE_DEFAULT = 0x00000000,
43    GET_BUNDLE_WITH_ABILITIES = 0x00000001,
44    GET_ABILITY_INFO_WITH_PERMISSION = 0x00000002,
45    GET_ABILITY_INFO_WITH_APPLICATION = 0x00000004,
46    GET_APPLICATION_INFO_WITH_PERMISSION = 0x00000008,
47    GET_BUNDLE_WITH_REQUESTED_PERMISSION = 0x00000010,
48    GET_ALL_APPLICATION_INFO = 0xFFFF0000,
49    /**
50     * @since 8
51     */
52    GET_ABILITY_INFO_WITH_METADATA = 0x00000020,
53    /**
54     * @since 8
55     */
56     GET_APPLICATION_INFO_WITH_METADATA = 0x00000040,
57    /**
58     * @since 8
59     */
60    GET_ABILITY_INFO_SYSTEMAPP_ONLY = 0x00000080,
61    /**
62     * @since 8
63     */
64    GET_ABILITY_INFO_WITH_DISABLE = 0x00000100,
65    /**
66     * @since 8
67     */
68    GET_APPLICATION_INFO_WITH_DISABLE = 0x00000200,
69  }
70
71/**
72 * @name ColorMode
73 * @since 7
74 * @syscap SystemCapability.BundleManager.BundleFramework
75 * @import NA
76 * @permission NA
77 */
78  export enum ColorMode {
79    AUTO_MODE = -1,
80    DARK_MODE = 0,
81    LIGHT_MODE = 1,
82  }
83
84/**
85 * @name GrantStatus
86 * @since 7
87 * @syscap SystemCapability.BundleManager.BundleFramework
88 * @import NA
89 * @permission NA
90 */
91  export enum GrantStatus {
92    PERMISSION_DENIED = -1,
93    PERMISSION_GRANTED = 0,
94  }
95
96  /**
97   * @name AbilityType
98   * @since 7
99   * @syscap SystemCapability.BundleManager.BundleFramework
100   * @import NA
101   * @permission NA
102   */
103  export enum AbilityType {
104    /**
105     * @default Indicates an unknown ability type
106     * @since 7
107     * @syscap SystemCapability.BundleManager.BundleFramework
108     */
109    UNKNOWN,
110
111    /**
112     * @default Indicates that the ability has a UI
113     * @since 7
114     * @syscap SystemCapability.BundleManager.BundleFramework
115     */
116    PAGE,
117
118    /**
119     * @default Indicates that the ability does not have a UI
120     * @since 7
121     * @syscap SystemCapability.BundleManager.BundleFramework
122     */
123    SERVICE,
124
125    /**
126     * @default Indicates that the ability is used to provide data access services
127     * @since 7
128     * @syscap SystemCapability.BundleManager.BundleFramework
129     */
130    DATA,
131  }
132
133  /**
134   * @name AbilitySubType
135   * @since 7
136   * @syscap SystemCapability.BundleManager.BundleFramework
137   * @import NA
138   * @permission NA
139   */
140  export enum AbilitySubType {
141    UNSPECIFIED = 0,
142    CA = 1,
143  }
144
145  /**
146   * @name DisplayOrientation
147   * @since 7
148   * @syscap SystemCapability.BundleManager.BundleFramework
149   * @import NA
150   * @permission NA
151   */
152  export enum DisplayOrientation {
153    /**
154     * @default Indicates that the system automatically determines the display orientation
155     * @since 7
156     * @syscap SystemCapability.BundleManager.BundleFramework
157     */
158    UNSPECIFIED,
159
160    /**
161     * @default Indicates the landscape orientation
162     * @since 7
163     * @syscap SystemCapability.BundleManager.BundleFramework
164     */
165    LANDSCAPE,
166
167    /**
168     * @default Indicates the portrait orientation
169     * @since 7
170     * @syscap SystemCapability.BundleManager.BundleFramework
171     */
172    PORTRAIT,
173
174    /**
175     * @default Indicates the page ability orientation is the same as that of the nearest ability in the stack
176     * @since 7
177     * @syscap SystemCapability.BundleManager.BundleFramework
178     */
179    FOLLOW_RECENT,
180  }
181
182  /**
183   * @name LaunchMode
184   * @since 7
185   * @syscap SystemCapability.BundleManager.BundleFramework
186   * @import NA
187   * @permission NA
188   */
189  export enum LaunchMode {
190    /**
191     * @default Indicates that the ability has only one instance
192     * @since 7
193     * @syscap SystemCapability.BundleManager.BundleFramework
194     */
195    SINGLETON = 0,
196
197    /**
198     * @default Indicates that the ability can have multiple instances
199     * @since 7
200     * @syscap SystemCapability.BundleManager.BundleFramework
201     */
202    STANDARD = 1,
203  }
204
205  /**
206   * @name BundleOptions
207   * @since 7
208   * @syscap SystemCapability.BundleManager.BundleFramework
209   * @import NA
210   * @permission NA
211   */
212  export interface BundleOptions {
213    /**
214     * @default Indicates the user id
215     * @since 7
216     * @syscap SystemCapability.BundleManager.BundleFramework
217     */
218    userId?: number;
219  }
220
221  /**
222   * @name InstallErrorCode
223   * @since 7
224   * @syscap SystemCapability.BundleManager.BundleFramework
225   * @import NA
226   * @permission NA
227   */
228  export enum InstallErrorCode{
229    SUCCESS = 0,
230    STATUS_INSTALL_FAILURE = 1,
231    STATUS_INSTALL_FAILURE_ABORTED = 2,
232    STATUS_INSTALL_FAILURE_INVALID = 3,
233    STATUS_INSTALL_FAILURE_CONFLICT = 4,
234    STATUS_INSTALL_FAILURE_STORAGE = 5,
235    STATUS_INSTALL_FAILURE_INCOMPATIBLE = 6,
236    STATUS_UNINSTALL_FAILURE = 7,
237    STATUS_UNINSTALL_FAILURE_BLOCKED = 8,
238    STATUS_UNINSTALL_FAILURE_ABORTED = 9,
239    STATUS_UNINSTALL_FAILURE_CONFLICT = 10,
240    STATUS_INSTALL_FAILURE_DOWNLOAD_TIMEOUT = 0x0B,
241    STATUS_INSTALL_FAILURE_DOWNLOAD_FAILED = 0x0C,
242    /**
243      * @since 8
244      */
245    STATUS_RECOVER_FAILURE_INVALID = 0x0D,
246    /**
247      * @since 7
248      */
249    STATUS_ABILITY_NOT_FOUND = 0x40,
250    /**
251      * @since 7
252      */
253    STATUS_BMS_SERVICE_ERROR = 0x41,
254    /**
255      * @since 8
256      */
257    STATUS_FAILED_NO_SPACE_LEFT = 0x42,
258    /**
259      * @since 8
260      */
261    STATUS_GRANT_REQUEST_PERMISSIONS_FAILED = 0x43,
262    /**
263     * @since 8
264     */
265    STATUS_INSTALL_PERMISSION_DENIED = 0x44,
266    /**
267     * @since 8
268     */
269    STATUS_UNINSTALL_PERMISSION_DENIED = 0x45,
270  }
271
272  /**
273   * Obtains bundleInfo based on bundleName, bundleFlags and options.
274   *
275   * @since 7
276   * @syscap SystemCapability.BundleManager.BundleFramework
277   * @param bundleName Indicates the application bundle name to be queried.
278   * @param bundleFlags Indicates the application bundle flags to be queried.
279   * @param options Indicates the bundle options object.
280   * @return Returns the BundleInfo object.
281   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
282   */
283   function getBundleInfo(bundleName: string, bundleFlags: number, options: BundleOptions, callback: AsyncCallback<BundleInfo>): void;
284   function getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback<BundleInfo>): void;
285   function getBundleInfo(bundleName: string, bundleFlags: number, options?: BundleOptions): Promise<BundleInfo>;
286
287  /**
288   * Obtains the interface used to install bundles.
289   *
290   * @since 7
291   * @syscap SystemCapability.BundleManager.BundleFramework
292   * @return Returns the IBundleInstaller interface.
293   * @permission ohos.permission.INSTALL_BUNDLE
294   * @systemapi Hide this for inner system use
295   */
296  function getBundleInstaller(callback: AsyncCallback<BundleInstaller>): void;
297  function getBundleInstaller(): Promise<BundleInstaller>;
298
299  /**
300   * Obtains information about the current ability.
301   *
302   * @since 7
303   * @syscap SystemCapability.BundleManager.BundleFramework
304   * @param bundleName Indicates the application bundle name to be queried.
305   * @param abilityName Indicates the ability name.
306   * @return Returns the AbilityInfo object for the current ability.
307   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
308   */
309  function getAbilityInfo(bundleName: string, abilityName: string, callback: AsyncCallback<AbilityInfo>): void;
310  function getAbilityInfo(bundleName: string, abilityName: string): Promise<AbilityInfo>;
311
312  /**
313   * Obtains based on a given bundle name.
314   *
315   * @since 7
316   * @syscap SystemCapability.BundleManager.BundleFramework
317   * @param bundleName Indicates the application bundle name to be queried.
318   * @param bundleFlags Indicates the flag used to specify information contained in the ApplicationInfo object
319   *              that will be returned.
320   * @param userId Indicates the user ID or do not pass user ID.
321   * @return Returns the ApplicationInfo object.
322   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
323   */
324  function getApplicationInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback<ApplicationInfo>) : void;
325  function getApplicationInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback<ApplicationInfo>) : void;
326  function getApplicationInfo(bundleName: string, bundleFlags: number, userId?: number) : Promise<ApplicationInfo>;
327
328  /**
329   * Query the AbilityInfo by the given Want.
330   *
331   * @since 7
332   * @syscap SystemCapability.BundleManager.BundleFramework
333   * @param want Indicates the Want containing the application bundle name to
334   *               be queried.
335   * @param bundleFlags Indicates the flag used to specify information contained in the AbilityInfo objects that
336   *              will be returned.
337   * @param userId Indicates the user ID.
338   * @return Returns a list of AbilityInfo objects.
339   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
340   */
341  function queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback<Array<AbilityInfo>>): void;
342  function queryAbilityByWant(want: Want, bundleFlags: number, callback: AsyncCallback<Array<AbilityInfo>>): void;
343  function queryAbilityByWant(want: Want, bundleFlags: number, userId?:number): Promise<Array<AbilityInfo>>;
344
345  /**
346   * Obtains BundleInfo of all bundles available in the system.
347   *
348   * @since 7
349   * @syscap SystemCapability.BundleManager.BundleFramework
350   * @param bundleFlag Indicates the flag used to specify information contained in the BundleInfo that will be
351   *              returned.
352   * @param userId Indicates the user id.
353   * @return Returns a list of BundleInfo objects.
354   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
355   */
356  function getAllBundleInfo(bundleFlag: BundleFlag, userId: number, callback: AsyncCallback<Array<BundleInfo>>) : void;
357  function getAllBundleInfo(bundleFlag: BundleFlag, callback: AsyncCallback<Array<BundleInfo>>) : void;
358  function getAllBundleInfo(bundleFlag: BundleFlag, userId?: number) : Promise<Array<BundleInfo>>;
359
360  /**
361   * Obtains information about all installed applications of a specified user.
362   *
363   * @since 7
364   * @syscap SystemCapability.BundleManager.BundleFramework
365   * @param bundleFlags Indicates the flag used to specify information contained in the ApplicationInfo objects
366   *              that will be returned.
367   * @param userId Indicates the user ID or do not pass user ID.
368   * @return Returns a list of ApplicationInfo objects.
369   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
370   */
371  function getAllApplicationInfo(bundleFlags: number, userId: number, callback: AsyncCallback<Array<ApplicationInfo>>) : void;
372  function getAllApplicationInfo(bundleFlags: number, callback: AsyncCallback<Array<ApplicationInfo>>) : void;
373  function getAllApplicationInfo(bundleFlags: number, userId?: number) : Promise<Array<ApplicationInfo>>;
374
375  /**
376   * Obtains bundle name by the given uid.
377   *
378   * @since 8
379   * @syscap SystemCapability.BundleManager.BundleFramework
380   * @param uid Indicates the UID of an application.
381   * @return Returns the bundle name.
382   */
383   function getNameForUid(uid: number, callback: AsyncCallback<string>) : void
384   function getNameForUid(uid: number) : Promise<string>;
385
386  /**
387   * Obtains information about an application bundle contained in an ohos Ability Package (HAP).
388   *
389   * @since 7
390   * @syscap SystemCapability.BundleManager.BundleFramework
391   * @param hapFilePath Indicates the path storing the HAP. The path should be the relative path to the data
392   *                    directory of the current application.
393   * @param bundleFlags Indicates the flag used to specify information contained in the BundleInfo object to be
394   *              returned.
395   * @return Returns the BundleInfo object.
396   */
397  function getBundleArchiveInfo(hapFilePath: string, bundleFlags: number, callback: AsyncCallback<BundleInfo>) : void
398  function getBundleArchiveInfo(hapFilePath: string, bundleFlags: number) : Promise<BundleInfo>;
399
400  /**
401   * Obtains the Want for starting the main ability of an application based on the
402   * given bundle name. The main ability of an application is the ability that has the
403   * #ACTION_HOME and #ENTITY_HOME Want
404   * filters set in the application's <b>config.json</b> file.
405   *
406   * @since 7
407   * @syscap SystemCapability.BundleManager.BundleFramework
408   * @param bundleName Indicates the bundle name of the application.
409   * @return Returns the Want for starting the application's main ability if any; returns null if
410   *         the given bundle does not exist or does not contain any main ability.
411   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
412   */
413  function getLaunchWantForBundle(bundleName: string, callback: AsyncCallback<Want>): void;
414  function getLaunchWantForBundle(bundleName: string): Promise<Want>;
415
416  /**
417   * Clears cache data of a specified application.
418   *
419   * @since 8
420   * @syscap SystemCapability.BundleManager.BundleFramework
421   * @param bundleName Indicates the bundle name of the application whose cache data is to be cleared.
422   * @param callback Indicates the callback to be invoked for returning the operation result.
423   * @permission ohos.permission.REMOVE_CACHE_FILES
424   * @systemapi Hide this for inner system use
425   */
426  function cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback<void>): void;
427  function cleanBundleCacheFiles(bundleName: string): Promise<void>;
428
429  /**
430   * Sets whether to enable a specified application.
431   *
432   * @since 8
433   * @syscap SystemCapability.BundleManager.BundleFramework
434   * @param bundleName Indicates the bundle name of the application.
435   * @param isEnabled Specifies whether to enable the application. The value true means to enable it, and the
436   *                  value false means to disable it.
437   * @permission ohos.permission.CHANGE_ABILITY_ENABLED_STATE
438   * @systemapi Hide this for inner system use
439   */
440  function setApplicationEnabled(bundleName: string, isEnable: boolean, callback: AsyncCallback<void>): void;
441  function setApplicationEnabled(bundleName: string, isEnable: boolean): Promise<void>;
442
443  /**
444   * Sets whether to enable a specified ability.
445   *
446   * @since 8
447   * @syscap SystemCapability.BundleManager.BundleFramework
448   * @param abilityInfo Indicates information about the ability to set.
449   * @param isEnabled Specifies whether to enable the ability. The value true means to enable it, and the
450   *                  value false means to disable it..
451   * @permission ohos.permission.CHANGE_ABILITY_ENABLED_STATE
452   * @systemapi Hide this for inner system use
453   */
454  function setAbilityEnabled(info: AbilityInfo, isEnable: boolean, callback: AsyncCallback<void>): void;
455  function setAbilityEnabled(info: AbilityInfo, isEnable: boolean): Promise<void>;
456
457  /**
458   * Get the permission details by permissionName.
459   *
460   * @since 8
461   * @syscap SystemCapability.BundleManager.BundleFramework
462   * @param permissionName Indicates permission name.
463   * @return Returns permissionDef object.
464   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
465   * @systemapi
466   */
467  function getPermissionDef(permissionName: string, callback: AsyncCallback<PermissionDef>): void;
468  function getPermissionDef(permissionName: string): Promise<PermissionDef>;
469
470  /**
471   * Obtains the label of a specified ability.
472   *
473   * @since 8
474   * @syscap SystemCapability.BundleManager.BundleFramework
475   * @param bundleName Indicates the bundle name of the application to which the ability belongs.
476   * @param abilityName Indicates the ability name.
477   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
478   * @return Returns the label representing the label of the specified ability.
479   */
480  function getAbilityLabel(bundleName: string, abilityName: string, callback: AsyncCallback<string>): void;
481  function getAbilityLabel(bundleName: string, abilityName: string): Promise<string>;
482
483  /**
484    * Obtains the icon of a specified ability.
485    *
486    * @since 8
487    * @syscap SystemCapability.BundleManager.BundleFramework
488    * @param bundleName Indicates the bundle name of the application to which the ability belongs.
489    * @param abilityName Indicates the ability name.
490    * @return Returns the PixelMap object representing the icon of the specified ability.
491    * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
492    */
493  function getAbilityIcon(bundleName: string, abilityName: string, callback: AsyncCallback<image.PixelMap>): void;
494  function getAbilityIcon(bundleName: string, abilityName: string): Promise<image.PixelMap>;
495
496  /**
497    * Checks whether a specified ability is enabled.
498    *
499    * @since 8
500    * @syscap SystemCapability.BundleManager.BundleFramework
501    * @param info Indicates information about the ability to check.
502    * @returns Returns true if the ability is enabled; returns false otherwise.
503    */
504  function isAbilityEnabled(info: AbilityInfo, callback: AsyncCallback<boolean>): void;
505  function isAbilityEnabled(info: AbilityInfo): Promise<boolean>;
506
507  /**
508    * Checks whether a specified application is enabled.
509    *
510    * @since 8
511    * @syscap SystemCapability.BundleManager.BundleFramework
512    * @param bundleName Indicates the bundle name of the application.
513    * @returns Returns true if the application is enabled; returns false otherwise.
514    */
515  function isApplicationEnabled(bundleName: string, callback: AsyncCallback<boolean>): void;
516  function isApplicationEnabled(bundleName: string): Promise<boolean>;
517}
518
519export default bundle;
520