• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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 ApplicationContext from './application/ApplicationContext';
22import Context from './application/Context';
23
24/**
25 * This module provides application basic functions.
26 *
27 * @namespace application
28 * @syscap SystemCapability.Ability.AbilityRuntime.Core
29 * @stagemodelonly
30 * @atomicservice
31 * @since arkts {'1.1':'12', '1.2':'20'}
32 * @arkts 1.1&1.2
33 */
34declare namespace application {
35  /**
36   * Create a module context
37   *
38   * @param { Context } context - Indicates current context.
39   * @param { string } moduleName - Indicates the module name.
40   * @returns { Promise<Context> } Returns the application context.
41   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
42   * @syscap SystemCapability.Ability.AbilityRuntime.Core
43   * @stagemodelonly
44   * @atomicservice
45   * @since arkts {'1.1':'12', '1.2':'20'}
46   * @arkts 1.1&1.2
47   */
48  export function createModuleContext(context: Context, moduleName: string): Promise<Context>;
49
50  /**
51   * Create a module context
52   *
53   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
54   * @param { Context } context - Indicates current context.
55   * @param { string } bundleName - Indicates the bundle name.
56   * @param { string } moduleName - Indicates the module name.
57   * @returns { Promise<Context> } Returns the application context.
58   * @throws { BusinessError } 201 - Permission denied.
59   * @throws { BusinessError } 202 - Permission denied, non-system app called system api.
60   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
61   * @syscap SystemCapability.Ability.AbilityRuntime.Core
62   * @systemapi
63   * @stagemodelonly
64   * @since arkts {'1.1':'12', '1.2':'20'}
65   * @arkts 1.1&1.2
66   */
67  export function createModuleContext(context: Context, bundleName: string, moduleName: string): Promise<Context>;
68
69  /**
70   * Create a module context of plugin.
71   *
72   * @param { Context } context - Indicates current context.
73   * @param { string } pluginBundleName - Indicates the bundle name of plugin.
74   * @param { string } pluginModuleName - Indicates the module name of plugin.
75   * @returns { Promise<Context> } Returns the module context of plugin.
76   * @syscap SystemCapability.Ability.AbilityRuntime.Core
77   * @stagemodelonly
78   * @since 19
79   */
80  export function createPluginModuleContext(context: Context, pluginBundleName: string, pluginModuleName: string): Promise<Context>;
81
82  /**
83   *  Create a context for a specified plugin module under the host application.
84   *
85   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
86   * @param { Context } context - Indicates current context.
87   * @param { string } pluginBundleName - Indicates the bundle name of plugin.
88   * @param { string } pluginModuleName - Indicates the module name of plugin.
89   * @param { string } hostBundleName - Indicates the bundle name of host application.
90   * @returns { Promise<Context> } Returns the module context of plugin.
91   * @throws { BusinessError } 201 - Permission denied.
92   * @throws { BusinessError } 202 - Permission denied, non-system app called system api.
93   * @syscap SystemCapability.Ability.AbilityRuntime.Core
94   * @systemapi
95   * @stagemodelonly
96   * @since 20
97   */
98  export function createPluginModuleContextForHostBundle(context: Context, pluginBundleName: string, pluginModuleName: string, hostBundleName: string): Promise<Context>;
99
100  /**
101   * Create a bundle context
102   *
103   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
104   * @param { Context } context - Indicates current context.
105   * @param { string } bundleName - Indicates the bundle name.
106   * @returns { Promise<Context> } Returns the application context.
107   * @throws { BusinessError } 201 - Permission denied.
108   * @throws { BusinessError } 202 - Permission denied, non-system app called system api.
109   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types.
110   * @syscap SystemCapability.Ability.AbilityRuntime.Core
111   * @systemapi
112   * @stagemodelonly
113   * @since arkts {'1.1':'12', '1.2':'20'}
114   * @arkts 1.1&1.2
115   */
116  export function createBundleContext(context: Context, bundleName: string): Promise<Context>;
117
118  /**
119   * Get application context.
120   *
121   * @returns { ApplicationContext } Returns the application context.
122   * @throws { BusinessError } 16000050 - Internal error.
123   * @syscap SystemCapability.Ability.AbilityRuntime.Core
124   * @stagemodelonly
125   * @atomicservice
126   * @since 14
127   */
128  export function getApplicationContext(): ApplicationContext;
129
130  /**
131   * Elevate the current process to be a candidate master process.
132   * If UIAbility or UIExtension component within the application is configured with "isolationProcess",launching an
133   * instance of such UIAbility or UIExtension will trigger a callback to the master process's "onNewProcessRequest".
134   * The "onNewProcessRequest" callback return value determines whether the new instance starts in a new process or an existing one.
135   * After successfully invoking this interface, the current process becomes a candidate master process. If the original master process
136   * is destroyed, the candidate process with the highest priority will be selected as the new master process.
137   *
138   * @param { boolean } insertToHead - Whether inset current process to the head of candidates master process list.
139   * @returns { Promise<void> } The promise returned by the function.
140   * @throws { BusinessError } 801 - Capability not supported.
141   * @throws { BusinessError } 16000115 - The current process is not running a component configured with "isolationProcess"
142   *                                      and cannot be set as a candidate master process.
143   * @syscap SystemCapability.Ability.AbilityRuntime.Core
144   * @stagemodelonly
145   * @since 20
146   */
147  export function promoteCurrentToCandidateMasterProcess(insertToHead: boolean): Promise<void>;
148
149  /**
150   * Revoke current process as a candidate master process.
151   *
152   * @returns { Promise<void> } The promise returned by the function.
153   * @throws { BusinessError } 801 - Capability not supported.
154   * @throws { BusinessError } 16000116 - The current process is already a master process and does not support cancellation.
155   * @throws { BusinessError } 16000117 - The current process is not a candidate master process and does not support cancellation.
156   * @syscap SystemCapability.Ability.AbilityRuntime.Core
157   * @stagemodelonly
158   * @since 20
159   */
160  export function demoteCurrentFromCandidateMasterProcess(): Promise<void>;
161}
162
163export default application;