• 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     * @syscap SystemCapability.Ability.AbilityRuntime.Core
106     * @StageModelOnly
107     * @since 9
108     */
109    getRunningProcessInformation(): Promise<Array<ProcessInformation>>;
110
111    /**
112     * Get information about running processes
113     * @param { AsyncCallback<Array<ProcessInformation>> } callback - The callback is used to return the array of {@link ProcessInformation}.
114     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
115     * @syscap SystemCapability.Ability.AbilityRuntime.Core
116     * @StageModelOnly
117     * @since 9
118     */
119    getRunningProcessInformation(callback: AsyncCallback<Array<ProcessInformation>>): void;
120
121    /**
122     * Kill all processes of the application
123     * @returns { Promise<void> } The promise returned by the function.
124     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
125     * @syscap SystemCapability.Ability.AbilityRuntime.Core
126     * @StageModelOnly
127     * @since 9
128     */
129    killAllProcesses(): Promise<void>;
130
131    /**
132     * Kill all processes of the application
133     * @param { AsyncCallback<void> } callback - The callback of killAllProcesses.
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    killAllProcesses(callback: AsyncCallback<void>);
140}
141