• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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 { ApplicationInfo } from "../bundleManager/ApplicationInfo";
17import resmgr from "../@ohos.resourceManager";
18import BaseContext from "./BaseContext";
19import EventHub from "./EventHub";
20import ApplicationContext from "./ApplicationContext";
21import contextConstant from "../@ohos.app.ability.contextConstant"
22
23/**
24 * The base context of an ability or an application. It allows access to
25 * application-specific resources.
26 * @syscap SystemCapability.Ability.AbilityRuntime.Core
27 * @StageModelOnly
28 * @since 9
29 */
30export default class Context extends BaseContext {
31    /**
32     * Indicates the capability of accessing application resources.
33     * @type { resmgr.ResourceManager }
34     * @syscap SystemCapability.Ability.AbilityRuntime.Core
35     * @StageModelOnly
36     * @since 9
37     */
38    resourceManager: resmgr.ResourceManager;
39
40    /**
41     * Indicates configuration information about an application.
42     * @type { ApplicationInfo }
43     * @syscap SystemCapability.Ability.AbilityRuntime.Core
44     * @StageModelOnly
45     * @since 9
46     */
47    applicationInfo: ApplicationInfo;
48
49    /**
50     * Indicates app cache dir.
51     * @type { string }
52     * @syscap SystemCapability.Ability.AbilityRuntime.Core
53     * @StageModelOnly
54     * @since 9
55     */
56    cacheDir: string;
57
58    /**
59     * Indicates app temp dir.
60     * @type { string }
61     * @syscap SystemCapability.Ability.AbilityRuntime.Core
62     * @StageModelOnly
63     * @since 9
64     */
65    tempDir: string;
66
67    /**
68     * Indicates app files dir.
69     * @type { string }
70     * @syscap SystemCapability.Ability.AbilityRuntime.Core
71     * @StageModelOnly
72     * @since 9
73     */
74    filesDir: string;
75
76    /**
77     * Indicates app database dir.
78     * @type { string }
79     * @syscap SystemCapability.Ability.AbilityRuntime.Core
80     * @StageModelOnly
81     * @since 9
82     */
83    databaseDir: string;
84
85    /**
86     * Indicates app preferences dir.
87     * @type { string }
88     * @syscap SystemCapability.Ability.AbilityRuntime.Core
89     * @StageModelOnly
90     * @since 9
91     */
92    preferencesDir: string;
93
94    /**
95     * Indicates app bundle code dir.
96     * @type { string }
97     * @syscap SystemCapability.Ability.AbilityRuntime.Core
98     * @StageModelOnly
99     * @since 9
100     */
101    bundleCodeDir: string;
102
103    /**
104     * Indicates app distributed files dir.
105     * @type { string }
106     * @syscap SystemCapability.Ability.AbilityRuntime.Core
107     * @StageModelOnly
108     * @since 9
109     */
110    distributedFilesDir: string;
111
112    /**
113     * Indicates event hub.
114     * @type { EventHub }
115     * @syscap SystemCapability.Ability.AbilityRuntime.Core
116     * @StageModelOnly
117     * @since 9
118     */
119    eventHub: EventHub;
120
121    /**
122     * Indicates file area.
123     * @type { AreaMode }
124     * @syscap SystemCapability.Ability.AbilityRuntime.Core
125     * @StageModelOnly
126     * @since 9
127     */
128    area: contextConstant.AreaMode;
129
130    /**
131     * Create a bundle context
132     * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
133     * @param { string } bundleName - Indicates the bundle name.
134     * @returns { Context } Returns the application context.
135     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
136     * @syscap SystemCapability.Ability.AbilityRuntime.Core
137     * @systemapi
138     * @StageModelOnly
139     * @since 9
140     */
141    createBundleContext(bundleName: string): Context;
142
143    /**
144     * Create a module context
145     * @param { string } moduleName - Indicates the module name.
146     * @returns { Context } Returns the application context.
147     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
148     * @syscap SystemCapability.Ability.AbilityRuntime.Core
149     * @StageModelOnly
150     * @since 9
151     */
152    createModuleContext(moduleName: string): Context;
153
154    /**
155     * Create a module context
156     * @param { string } bundleName - Indicates the bundle name.
157     * @param { string } moduleName - Indicates the module name.
158     * @returns { Context } Returns the application context.
159     * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
160     * @syscap SystemCapability.Ability.AbilityRuntime.Core
161     * @systemapi
162     * @StageModelOnly
163     * @since 9
164     */
165    createModuleContext(bundleName: string, moduleName: string): Context;
166
167    /**
168     * Get application context
169     * @returns { ApplicationContext } Returns the application context.
170     * @syscap SystemCapability.Ability.AbilityRuntime.Core
171     * @StageModelOnly
172     * @since 9
173     */
174    getApplicationContext(): ApplicationContext;
175}
176