• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 "../basic";
17import Context from "./Context";
18import AbilityLifecycleCallback from "../@ohos.app.ability.AbilityLifecycleCallback";
19import EnvironmentCallback from "../@ohos.app.ability.EnvironmentCallback";
20import { ProcessInformation } from "./ProcessInformation";
21
22/**
23 * The context of an application. It allows access to application-specific resources.
24 * @syscap SystemCapability.Ability.AbilityRuntime.Core
25 * @StageModelOnly
26 * @since 9
27 */
28export default class ApplicationContext extends Context {
29    /**
30     * Register ability lifecycle callback.
31     * @param { string } type - abilityLifecycle.
32     * @param { AbilityLifecycleCallback } callback - The ability lifecycle callback.
33     * @returns { number } Returns the number code of the callback.
34     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
35     * @syscap SystemCapability.Ability.AbilityRuntime.Core
36     * @StageModelOnly
37     * @since 9
38     */
39    on(type: "abilityLifecycle", callback: AbilityLifecycleCallback): number;
40
41    /**
42     * Unregister ability lifecycle callback.
43     * @param { string } type - abilityLifecycle.
44     * @param { number } callbackId - Indicates the number code of the callback.
45     * @param { AsyncCallback<void> } callback - The callback of off.
46     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
47     * @syscap SystemCapability.Ability.AbilityRuntime.Core
48     * @StageModelOnly
49     * @since 9
50     */
51    off(type: "abilityLifecycle", callbackId: number, callback: AsyncCallback<void>): void;
52
53    /**
54     * Unregister ability lifecycle callback.
55     * @param { string } type - abilityLifecycle.
56     * @param { number } callbackId - Indicates the number code of the callback.
57     * @returns { Promise<void> } The promise returned by the function.
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    off(type: "abilityLifecycle", callbackId: number): Promise<void>;
64
65    /**
66     * Register environment callback.
67     * @param { string } type - environment.
68     * @param { EnvironmentCallback } callback - The environment callback.
69     * @returns { number } Returns the number code of the callback.
70     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
71     * @syscap SystemCapability.Ability.AbilityRuntime.Core
72     * @StageModelOnly
73     * @since 9
74     */
75    on(type: "environment", callback: EnvironmentCallback): number;
76
77    /**
78     * Unregister environment callback.
79     * @param { string } type - environment.
80     * @param { number } callbackId - Indicates the number code of the callback.
81     * @param { AsyncCallback<void> } callback - The callback of unregisterEnvironmentCallback.
82     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
83     * @syscap SystemCapability.Ability.AbilityRuntime.Core
84     * @StageModelOnly
85     * @since 9
86     */
87    off(type: "environment", callbackId: number, callback: AsyncCallback<void>): void;
88
89    /**
90     * Unregister environment callback.
91     * @param { string } type - environment.
92     * @param { number } callbackId - Indicates the number code of the callback.
93     * @returns { Promise<void> } The promise returned by the function.
94     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
95     * @syscap SystemCapability.Ability.AbilityRuntime.Core
96     * @StageModelOnly
97     * @since 9
98     */
99    off(type: "environment", callbackId: number): Promise<void>;
100
101    /**
102     * Get information about running processes
103     * @returns { Promise<Array<ProcessInformation>> } Returns the array of {@link ProcessInformation}.
104     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
105     * @throws { BusinessError } 16000011 - The context does not exist.
106     * @throws { BusinessError } 16000050 - Internal error.
107     * @syscap SystemCapability.Ability.AbilityRuntime.Core
108     * @StageModelOnly
109     * @since 9
110     */
111    getRunningProcessInformation(): Promise<Array<ProcessInformation>>;
112
113    /**
114     * Get information about running processes
115     * @param { AsyncCallback<Array<ProcessInformation>> } callback - The callback is used to return the array of {@link ProcessInformation}.
116     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
117     * @throws { BusinessError } 16000011 - The context does not exist.
118     * @throws { BusinessError } 16000050 - Internal error.
119     * @syscap SystemCapability.Ability.AbilityRuntime.Core
120     * @StageModelOnly
121     * @since 9
122     */
123    getRunningProcessInformation(callback: AsyncCallback<Array<ProcessInformation>>): void;
124
125    /**
126     * Kill all processes of the application
127     * @returns { Promise<void> } The promise returned by the function.
128     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
129     * @throws { BusinessError } 16000011 - The context does not exist.
130     * @syscap SystemCapability.Ability.AbilityRuntime.Core
131     * @StageModelOnly
132     * @since 9
133     */
134    killAllProcesses(): Promise<void>;
135
136    /**
137     * Kill all processes of the application
138     * @param { AsyncCallback<void> } callback - The callback of killAllProcesses.
139     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
140     * @throws { BusinessError } 16000011 - The context does not exist.
141     * @syscap SystemCapability.Ability.AbilityRuntime.Core
142     * @StageModelOnly
143     * @since 9
144     */
145    killAllProcesses(callback: AsyncCallback<void>);
146}
147