• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 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 } from '../@ohos.base';
17import Context from './Context';
18import AbilityLifecycleCallback from '../@ohos.app.ability.AbilityLifecycleCallback';
19import EnvironmentCallback from '../@ohos.app.ability.EnvironmentCallback';
20import type ApplicationStateChangeCallback from '../@ohos.app.ability.ApplicationStateChangeCallback';
21import { ProcessInformation } from './ProcessInformation';
22import type ConfigurationConstant from '../@ohos.app.ability.ConfigurationConstant';
23
24/**
25 * The context of an application. It allows access to application-specific resources.
26 *
27 * @extends Context
28 * @syscap SystemCapability.Ability.AbilityRuntime.Core
29 * @StageModelOnly
30 * @since 9
31 */
32/**
33 * The context of an application. It allows access to application-specific resources.
34 *
35 * @extends Context
36 * @syscap SystemCapability.Ability.AbilityRuntime.Core
37 * @StageModelOnly
38 * @crossplatform
39 * @since 10
40 */
41/**
42 * The context of an application. It allows access to application-specific resources.
43 *
44 * @extends Context
45 * @syscap SystemCapability.Ability.AbilityRuntime.Core
46 * @StageModelOnly
47 * @crossplatform
48 * @atomicservice
49 * @since 11
50 */
51export default class ApplicationContext extends Context {
52  /**
53   * Register ability lifecycle callback.
54   *
55   * @param { 'abilityLifecycle' } type - abilityLifecycle.
56   * @param { AbilityLifecycleCallback } callback - The ability lifecycle callback.
57   * @returns { number } Returns the number code of the callback.
58   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
59   * @syscap SystemCapability.Ability.AbilityRuntime.Core
60   * @StageModelOnly
61   * @since 9
62   */
63  /**
64   * Register ability lifecycle callback.
65   *
66   * @param { 'abilityLifecycle' } type - abilityLifecycle.
67   * @param { AbilityLifecycleCallback } callback - The ability lifecycle callback.
68   * @returns { number } Returns the number code of the callback.
69   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
70   * @syscap SystemCapability.Ability.AbilityRuntime.Core
71   * @StageModelOnly
72   * @crossplatform
73   * @since 10
74   */
75  /**
76   * Register ability lifecycle callback.
77   *
78   * @param { 'abilityLifecycle' } type - abilityLifecycle.
79   * @param { AbilityLifecycleCallback } callback - The ability lifecycle callback.
80   * @returns { number } Returns the number code of the callback.
81   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
82   * @syscap SystemCapability.Ability.AbilityRuntime.Core
83   * @StageModelOnly
84   * @crossplatform
85   * @atomicservice
86   * @since 11
87   */
88  on(type: 'abilityLifecycle', callback: AbilityLifecycleCallback): number;
89
90  /**
91   * Unregister ability lifecycle callback.
92   *
93   * @param { 'abilityLifecycle' } type - abilityLifecycle.
94   * @param { number } callbackId - Indicates the number code of the callback.
95   * @param { AsyncCallback<void> } callback - The callback of off.
96   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
97   * @syscap SystemCapability.Ability.AbilityRuntime.Core
98   * @StageModelOnly
99   * @since 9
100   */
101  /**
102   * Unregister ability lifecycle callback.
103   *
104   * @param { 'abilityLifecycle' } type - abilityLifecycle.
105   * @param { number } callbackId - Indicates the number code of the callback.
106   * @param { AsyncCallback<void> } callback - The callback of off.
107   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
108   * @syscap SystemCapability.Ability.AbilityRuntime.Core
109   * @StageModelOnly
110   * @crossplatform
111   * @since 10
112   */
113  /**
114   * Unregister ability lifecycle callback.
115   *
116   * @param { 'abilityLifecycle' } type - abilityLifecycle.
117   * @param { number } callbackId - Indicates the number code of the callback.
118   * @param { AsyncCallback<void> } callback - The callback of off.
119   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
120   * @syscap SystemCapability.Ability.AbilityRuntime.Core
121   * @StageModelOnly
122   * @crossplatform
123   * @atomicservice
124   * @since 11
125   */
126  off(type: 'abilityLifecycle', callbackId: number, callback: AsyncCallback<void>): void;
127
128  /**
129   * Unregister ability lifecycle callback.
130   *
131   * @param { 'abilityLifecycle' } type - abilityLifecycle.
132   * @param { number } callbackId - Indicates the number code of the callback.
133   * @returns { Promise<void> } The promise returned by the function.
134   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
135   * @syscap SystemCapability.Ability.AbilityRuntime.Core
136   * @StageModelOnly
137   * @since 9
138   */
139  /**
140   * Unregister ability lifecycle callback.
141   *
142   * @param { 'abilityLifecycle' } type - abilityLifecycle.
143   * @param { number } callbackId - Indicates the number code of the callback.
144   * @returns { Promise<void> } The promise returned by the function.
145   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
146   * @syscap SystemCapability.Ability.AbilityRuntime.Core
147   * @StageModelOnly
148   * @atomicservice
149   * @since 11
150   */
151  off(type: 'abilityLifecycle', callbackId: number): Promise<void>;
152
153  /**
154   * Register environment callback.
155   *
156   * @param { 'environment' } type - environment.
157   * @param { EnvironmentCallback } callback - The environment callback.
158   * @returns { number } Returns the number code of the callback.
159   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
160   * @syscap SystemCapability.Ability.AbilityRuntime.Core
161   * @StageModelOnly
162   * @since 9
163   */
164  /**
165   * Register environment callback.
166   *
167   * @param { 'environment' } type - environment.
168   * @param { EnvironmentCallback } callback - The environment callback.
169   * @returns { number } Returns the number code of the callback.
170   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
171   * @syscap SystemCapability.Ability.AbilityRuntime.Core
172   * @StageModelOnly
173   * @atomicservice
174   * @since 11
175   */
176  on(type: 'environment', callback: EnvironmentCallback): number;
177
178  /**
179   * Unregister environment callback.
180   *
181   * @param { 'environment' } type - environment.
182   * @param { number } callbackId - Indicates the number code of the callback.
183   * @param { AsyncCallback<void> } callback - The callback of unregisterEnvironmentCallback.
184   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
185   * @syscap SystemCapability.Ability.AbilityRuntime.Core
186   * @StageModelOnly
187   * @since 9
188   */
189  /**
190   * Unregister environment callback.
191   *
192   * @param { 'environment' } type - environment.
193   * @param { number } callbackId - Indicates the number code of the callback.
194   * @param { AsyncCallback<void> } callback - The callback of unregisterEnvironmentCallback.
195   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
196   * @syscap SystemCapability.Ability.AbilityRuntime.Core
197   * @StageModelOnly
198   * @atomicservice
199   * @since 11
200   */
201  off(type: 'environment', callbackId: number, callback: AsyncCallback<void>): void;
202
203  /**
204   * Unregister environment callback.
205   *
206   * @param { 'environment' } type - environment.
207   * @param { number } callbackId - Indicates the number code of the callback.
208   * @returns { Promise<void> } The promise returned by the function.
209   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
210   * @syscap SystemCapability.Ability.AbilityRuntime.Core
211   * @StageModelOnly
212   * @since 9
213   */
214  /**
215   * Unregister environment callback.
216   *
217   * @param { 'environment' } type - environment.
218   * @param { number } callbackId - Indicates the number code of the callback.
219   * @returns { Promise<void> } The promise returned by the function.
220   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
221   * @syscap SystemCapability.Ability.AbilityRuntime.Core
222   * @StageModelOnly
223   * @atomicservice
224   * @since 11
225   */
226  off(type: 'environment', callbackId: number): Promise<void>;
227
228  /**
229   * Register applicationStateChange callback.
230   *
231   * @param { 'applicationStateChange' } type - applicationStateChange.
232   * @param { ApplicationStateChangeCallback } callback - The applicationStateChange callback.
233   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
234   * @syscap SystemCapability.Ability.AbilityRuntime.Core
235   * @StageModelOnly
236   * @since 10
237   */
238  /**
239   * Register applicationStateChange callback.
240   *
241   * @param { 'applicationStateChange' } type - applicationStateChange.
242   * @param { ApplicationStateChangeCallback } callback - The applicationStateChange callback.
243   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
244   * @syscap SystemCapability.Ability.AbilityRuntime.Core
245   * @StageModelOnly
246   * @atomicservice
247   * @since 11
248   */
249  on(type: 'applicationStateChange', callback: ApplicationStateChangeCallback): void;
250
251  /**
252   * Unregister applicationStateChange callback.
253   *
254   * @param { 'applicationStateChange' } type - applicationStateChange.
255   * @param { ApplicationStateChangeCallback } [callback] - The applicationStateChange callback.
256   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
257   * @syscap SystemCapability.Ability.AbilityRuntime.Core
258   * @StageModelOnly
259   * @since 10
260   */
261  /**
262   * Unregister applicationStateChange callback.
263   *
264   * @param { 'applicationStateChange' } type - applicationStateChange.
265   * @param { ApplicationStateChangeCallback } [callback] - The applicationStateChange callback.
266   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
267   * @syscap SystemCapability.Ability.AbilityRuntime.Core
268   * @StageModelOnly
269   * @atomicservice
270   * @since 11
271   */
272  off(type: 'applicationStateChange', callback?: ApplicationStateChangeCallback): void;
273
274  /**
275   * Get information about running processes
276   *
277   * @returns { Promise<Array<ProcessInformation>> } Returns the array of {@link ProcessInformation}.
278   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
279   * @throws { BusinessError } 16000011 - The context does not exist.
280   * @throws { BusinessError } 16000050 - Internal error.
281   * @syscap SystemCapability.Ability.AbilityRuntime.Core
282   * @StageModelOnly
283   * @since 9
284   */
285  /**
286   * Get information about running processes
287   *
288   * @returns { Promise<Array<ProcessInformation>> } Returns the array of {@link ProcessInformation}.
289   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
290   * @throws { BusinessError } 16000011 - The context does not exist.
291   * @throws { BusinessError } 16000050 - Internal error.
292   * @syscap SystemCapability.Ability.AbilityRuntime.Core
293   * @StageModelOnly
294   * @crossplatform
295   * @since 10
296   */
297  /**
298   * Get information about running processes
299   *
300   * @returns { Promise<Array<ProcessInformation>> } Returns the array of {@link ProcessInformation}.
301   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
302   * @throws { BusinessError } 16000011 - The context does not exist.
303   * @throws { BusinessError } 16000050 - Internal error.
304   * @syscap SystemCapability.Ability.AbilityRuntime.Core
305   * @StageModelOnly
306   * @crossplatform
307   * @atomicservice
308   * @since 11
309   */
310  getRunningProcessInformation(): Promise<Array<ProcessInformation>>;
311
312  /**
313   * Get information about running processes
314   *
315   * @param { AsyncCallback<Array<ProcessInformation>> } callback - The callback is used to return the array of {@link ProcessInformation}.
316   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
317   * @throws { BusinessError } 16000011 - The context does not exist.
318   * @throws { BusinessError } 16000050 - Internal error.
319   * @syscap SystemCapability.Ability.AbilityRuntime.Core
320   * @StageModelOnly
321   * @since 9
322   */
323  /**
324   * Get information about running processes
325   *
326   * @param { AsyncCallback<Array<ProcessInformation>> } callback - The callback is used to return the array of {@link ProcessInformation}.
327   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
328   * @throws { BusinessError } 16000011 - The context does not exist.
329   * @throws { BusinessError } 16000050 - Internal error.
330   * @syscap SystemCapability.Ability.AbilityRuntime.Core
331   * @StageModelOnly
332   * @crossplatform
333   * @since 10
334   */
335  /**
336   * Get information about running processes
337   *
338   * @param { AsyncCallback<Array<ProcessInformation>> } callback - The callback is used to return the array of {@link ProcessInformation}.
339   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
340   * @throws { BusinessError } 16000011 - The context does not exist.
341   * @throws { BusinessError } 16000050 - Internal error.
342   * @syscap SystemCapability.Ability.AbilityRuntime.Core
343   * @StageModelOnly
344   * @crossplatform
345   * @atomicservice
346   * @since 11
347   */
348  getRunningProcessInformation(callback: AsyncCallback<Array<ProcessInformation>>): void;
349
350  /**
351   * Kill all processes of the application
352   *
353   * @returns { Promise<void> } The promise returned by the function.
354   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
355   * @throws { BusinessError } 16000011 - The context does not exist.
356   * @syscap SystemCapability.Ability.AbilityRuntime.Core
357   * @StageModelOnly
358   * @since 9
359   */
360  /**
361   * Kill all processes of the application
362   *
363   * @returns { Promise<void> } The promise returned by the function.
364   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
365   * @throws { BusinessError } 16000011 - The context does not exist.
366   * @syscap SystemCapability.Ability.AbilityRuntime.Core
367   * @StageModelOnly
368   * @atomicservice
369   * @since 11
370   */
371  killAllProcesses(): Promise<void>;
372
373  /**
374   * Kill all processes of the application
375   *
376   * @param { AsyncCallback<void> } callback - The callback of killAllProcesses.
377   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
378   * @throws { BusinessError } 16000011 - The context does not exist.
379   * @syscap SystemCapability.Ability.AbilityRuntime.Core
380   * @StageModelOnly
381   * @since 9
382   */
383  /**
384   * Kill all processes of the application
385   *
386   * @param { AsyncCallback<void> } callback - The callback of killAllProcesses.
387   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
388   * @throws { BusinessError } 16000011 - The context does not exist.
389   * @syscap SystemCapability.Ability.AbilityRuntime.Core
390   * @StageModelOnly
391   * @atomicservice
392   * @since 11
393   */
394  killAllProcesses(callback: AsyncCallback<void>);
395
396  /**
397   * Set colorMode of the application
398   *
399   * @param { ConfigurationConstant.ColorMode } colorMode - Color mode.
400   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
401   * @throws { BusinessError } 16000011 - The context does not exist.
402   * @syscap SystemCapability.Ability.AbilityRuntime.Core
403   * @StageModelOnly
404   * @atomicservice
405   * @since 11
406   */
407  setColorMode(colorMode: ConfigurationConstant.ColorMode): void;
408
409  /**
410   * Set language of the application
411   *
412   * @param { string } language - Language.
413   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
414   * @throws { BusinessError } 16000011 - The context does not exist.
415   * @syscap SystemCapability.Ability.AbilityRuntime.Core
416   * @StageModelOnly
417   * @atomicservice
418   * @since 11
419   */
420  setLanguage(language: string): void;
421
422  /**
423   * Clear up application data by app self
424   *
425   * @returns { Promise<void> } The promise returned by the function.
426   * @throws { BusinessError } 16000011 - The context does not exist.
427   * @throws { BusinessError } 16000050 - Internal error.
428   * @syscap SystemCapability.Ability.AbilityRuntime.Core
429   * @StageModelOnly
430   * @since 11
431   */
432  clearUpApplicationData(): Promise<void>;
433
434  /**
435   * Clear up application data by app self
436   *
437   * @param { AsyncCallback<void> } callback - The callback of clearUpApplicationData.
438   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
439   * @throws { BusinessError } 16000011 - The context does not exist.
440   * @throws { BusinessError } 16000050 - Internal error.
441   * @syscap SystemCapability.Ability.AbilityRuntime.Core
442   * @StageModelOnly
443   * @since 11
444   */
445  clearUpApplicationData(callback: AsyncCallback<void>): void;
446}
447