• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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 { ApplicationInfo } from '../bundleManager/ApplicationInfo';
17import type { AsyncCallback } from '../@ohos.base';
18import resmgr from '../@ohos.resourceManager';
19import BaseContext from './BaseContext';
20import EventHub from './EventHub';
21import ApplicationContext from './ApplicationContext';
22import contextConstant from '../@ohos.app.ability.contextConstant';
23
24/**
25 * The base context of an ability or an application. It allows access to
26 * application-specific resources.
27 *
28 * @extends BaseContext
29 * @syscap SystemCapability.Ability.AbilityRuntime.Core
30 * @StageModelOnly
31 * @since 9
32 */
33/**
34 * The base context of an ability or an application. It allows access to
35 * application-specific resources.
36 *
37 * @extends BaseContext
38 * @syscap SystemCapability.Ability.AbilityRuntime.Core
39 * @StageModelOnly
40 * @crossplatform
41 * @since 10
42 */
43/**
44 * The base context of an ability or an application. It allows access to
45 * application-specific resources.
46 *
47 * @extends BaseContext
48 * @syscap SystemCapability.Ability.AbilityRuntime.Core
49 * @StageModelOnly
50 * @crossplatform
51 * @atomicservice
52 * @since 11
53 */
54export default class Context extends BaseContext {
55  /**
56   * Indicates the capability of accessing application resources.
57   *
58   * @type { resmgr.ResourceManager }
59   * @syscap SystemCapability.Ability.AbilityRuntime.Core
60   * @StageModelOnly
61   * @since 9
62   */
63  /**
64   * Indicates the capability of accessing application resources.
65   *
66   * @type { resmgr.ResourceManager }
67   * @syscap SystemCapability.Ability.AbilityRuntime.Core
68   * @StageModelOnly
69   * @crossplatform
70   * @since 10
71   */
72  /**
73   * Indicates the capability of accessing application resources.
74   *
75   * @type { resmgr.ResourceManager }
76   * @syscap SystemCapability.Ability.AbilityRuntime.Core
77   * @StageModelOnly
78   * @crossplatform
79   * @atomicservice
80   * @since 11
81   */
82  resourceManager: resmgr.ResourceManager;
83
84  /**
85   * Indicates configuration information about an application.
86   *
87   * @type { ApplicationInfo }
88   * @syscap SystemCapability.Ability.AbilityRuntime.Core
89   * @StageModelOnly
90   * @since 9
91   */
92  /**
93   * Indicates configuration information about an application.
94   *
95   * @type { ApplicationInfo }
96   * @syscap SystemCapability.Ability.AbilityRuntime.Core
97   * @StageModelOnly
98   * @crossplatform
99   * @since 10
100   */
101  /**
102   * Indicates configuration information about an application.
103   *
104   * @type { ApplicationInfo }
105   * @syscap SystemCapability.Ability.AbilityRuntime.Core
106   * @StageModelOnly
107   * @crossplatform
108   * @atomicservice
109   * @since 11
110   */
111  applicationInfo: ApplicationInfo;
112
113  /**
114   * Indicates app cache dir.
115   *
116   * @type { string }
117   * @syscap SystemCapability.Ability.AbilityRuntime.Core
118   * @StageModelOnly
119   * @since 9
120   */
121  /**
122   * Indicates app cache dir.
123   *
124   * @type { string }
125   * @syscap SystemCapability.Ability.AbilityRuntime.Core
126   * @StageModelOnly
127   * @crossplatform
128   * @since 10
129   */
130  /**
131   * Indicates app cache dir.
132   *
133   * @type { string }
134   * @syscap SystemCapability.Ability.AbilityRuntime.Core
135   * @StageModelOnly
136   * @crossplatform
137   * @atomicservice
138   * @since 11
139   */
140  cacheDir: string;
141
142  /**
143   * Indicates app temp dir.
144   *
145   * @type { string }
146   * @syscap SystemCapability.Ability.AbilityRuntime.Core
147   * @StageModelOnly
148   * @since 9
149   */
150  /**
151   * Indicates app temp dir.
152   *
153   * @type { string }
154   * @syscap SystemCapability.Ability.AbilityRuntime.Core
155   * @StageModelOnly
156   * @crossplatform
157   * @since 10
158   */
159  /**
160   * Indicates app temp dir.
161   *
162   * @type { string }
163   * @syscap SystemCapability.Ability.AbilityRuntime.Core
164   * @StageModelOnly
165   * @crossplatform
166   * @atomicservice
167   * @since 11
168   */
169  tempDir: string;
170
171  /**
172   * Indicates app files dir.
173   *
174   * @type { string }
175   * @syscap SystemCapability.Ability.AbilityRuntime.Core
176   * @StageModelOnly
177   * @since 9
178   */
179  /**
180   * Indicates app files dir.
181   *
182   * @type { string }
183   * @syscap SystemCapability.Ability.AbilityRuntime.Core
184   * @StageModelOnly
185   * @crossplatform
186   * @since 10
187   */
188  /**
189   * Indicates app files dir.
190   *
191   * @type { string }
192   * @syscap SystemCapability.Ability.AbilityRuntime.Core
193   * @StageModelOnly
194   * @crossplatform
195   * @atomicservice
196   * @since 11
197   */
198  filesDir: string;
199
200  /**
201   * Indicates app database dir.
202   *
203   * @type { string }
204   * @syscap SystemCapability.Ability.AbilityRuntime.Core
205   * @StageModelOnly
206   * @since 9
207   */
208  /**
209   * Indicates app database dir.
210   *
211   * @type { string }
212   * @syscap SystemCapability.Ability.AbilityRuntime.Core
213   * @StageModelOnly
214   * @crossplatform
215   * @since 10
216   */
217  /**
218   * Indicates app database dir.
219   *
220   * @type { string }
221   * @syscap SystemCapability.Ability.AbilityRuntime.Core
222   * @StageModelOnly
223   * @crossplatform
224   * @atomicservice
225   * @since 11
226   */
227  databaseDir: string;
228
229  /**
230   * Indicates app preferences dir.
231   *
232   * @type { string }
233   * @syscap SystemCapability.Ability.AbilityRuntime.Core
234   * @StageModelOnly
235   * @since 9
236   */
237  /**
238   * Indicates app preferences dir.
239   *
240   * @type { string }
241   * @syscap SystemCapability.Ability.AbilityRuntime.Core
242   * @StageModelOnly
243   * @crossplatform
244   * @since 10
245   */
246  /**
247   * Indicates app preferences dir.
248   *
249   * @type { string }
250   * @syscap SystemCapability.Ability.AbilityRuntime.Core
251   * @StageModelOnly
252   * @crossplatform
253   * @atomicservice
254   * @since 11
255   */
256  preferencesDir: string;
257
258  /**
259   * Indicates app bundle code dir.
260   *
261   * @type { string }
262   * @syscap SystemCapability.Ability.AbilityRuntime.Core
263   * @StageModelOnly
264   * @since 9
265   */
266  /**
267   * Indicates app bundle code dir.
268   *
269   * @type { string }
270   * @syscap SystemCapability.Ability.AbilityRuntime.Core
271   * @StageModelOnly
272   * @crossplatform
273   * @since 10
274   */
275  /**
276   * Indicates app bundle code dir.
277   *
278   * @type { string }
279   * @syscap SystemCapability.Ability.AbilityRuntime.Core
280   * @StageModelOnly
281   * @crossplatform
282   * @atomicservice
283   * @since 11
284   */
285  bundleCodeDir: string;
286
287  /**
288   * Indicates app distributed files dir.
289   *
290   * @type { string }
291   * @syscap SystemCapability.Ability.AbilityRuntime.Core
292   * @StageModelOnly
293   * @since 9
294   */
295  /**
296   * Indicates app distributed files dir.
297   *
298   * @type { string }
299   * @syscap SystemCapability.Ability.AbilityRuntime.Core
300   * @StageModelOnly
301   * @atomicservice
302   * @since 11
303   */
304  distributedFilesDir: string;
305
306  /**
307   * Indicates app bundle resource dir.
308   *
309   * @type { string }
310   * @syscap SystemCapability.Ability.AbilityRuntime.Core
311   * @StageModelOnly
312   * @crossplatform
313   * @atomicservice
314   * @since 11
315   */
316  resourceDir: string;
317
318  /**
319   * Indicates event hub.
320   *
321   * @type { EventHub }
322   * @syscap SystemCapability.Ability.AbilityRuntime.Core
323   * @StageModelOnly
324   * @since 9
325   */
326  /**
327   * Indicates event hub.
328   *
329   * @type { EventHub }
330   * @syscap SystemCapability.Ability.AbilityRuntime.Core
331   * @StageModelOnly
332   * @atomicservice
333   * @since 11
334   */
335  eventHub: EventHub;
336
337  /**
338   * Indicates file area.
339   *
340   * @type { contextConstant.AreaMode }
341   * @syscap SystemCapability.Ability.AbilityRuntime.Core
342   * @StageModelOnly
343   * @since 9
344   */
345  /**
346   * Indicates file area.
347   *
348   * @type { contextConstant.AreaMode }
349   * @syscap SystemCapability.Ability.AbilityRuntime.Core
350   * @StageModelOnly
351   * @atomicservice
352   * @since 11
353   */
354  area: contextConstant.AreaMode;
355
356  /**
357   * Create a bundle context
358   *
359   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
360   * @param { string } bundleName - Indicates the bundle name.
361   * @returns { Context } Returns the application context.
362   * @throws { BusinessError } 201 - Permission denied.
363   * @throws { BusinessError } 202 - Permission denied, non-system app called system api.
364   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
365   * @syscap SystemCapability.Ability.AbilityRuntime.Core
366   * @systemapi
367   * @StageModelOnly
368   * @since 9
369   */
370  createBundleContext(bundleName: string): Context;
371
372  /**
373   * Create a module context
374   *
375   * @param { string } moduleName - Indicates the module name.
376   * @returns { Context } Returns the application context.
377   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
378   * @syscap SystemCapability.Ability.AbilityRuntime.Core
379   * @StageModelOnly
380   * @since 9
381   */
382  /**
383   * Create a module context
384   *
385   * @param { string } moduleName - Indicates the module name.
386   * @returns { Context } Returns the application context.
387   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
388   * @syscap SystemCapability.Ability.AbilityRuntime.Core
389   * @StageModelOnly
390   * @crossplatform
391   * @since 10
392   */
393  /**
394   * Create a module context
395   *
396   * @param { string } moduleName - Indicates the module name.
397   * @returns { Context } Returns the application context.
398   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
399   * @syscap SystemCapability.Ability.AbilityRuntime.Core
400   * @StageModelOnly
401   * @crossplatform
402   * @atomicservice
403   * @since 11
404   */
405  createModuleContext(moduleName: string): Context;
406
407  /**
408   * Create a module context
409   *
410   * @param { string } bundleName - Indicates the bundle name.
411   * @param { string } moduleName - Indicates the module name.
412   * @returns { Context } Returns the application context.
413   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
414   * @syscap SystemCapability.Ability.AbilityRuntime.Core
415   * @systemapi
416   * @StageModelOnly
417   * @since 9
418   */
419  createModuleContext(bundleName: string, moduleName: string): Context;
420
421  /**
422   * Get application context
423   *
424   * @returns { ApplicationContext } Returns the application context.
425   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
426   * @syscap SystemCapability.Ability.AbilityRuntime.Core
427   * @StageModelOnly
428   * @since 9
429   */
430  /**
431   * Get application context
432   *
433   * @returns { ApplicationContext } Returns the application context.
434   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
435   * @syscap SystemCapability.Ability.AbilityRuntime.Core
436   * @StageModelOnly
437   * @crossplatform
438   * @since 10
439   */
440  /**
441   * Get application context
442   *
443   * @returns { ApplicationContext } Returns the application context.
444   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
445   * @syscap SystemCapability.Ability.AbilityRuntime.Core
446   * @StageModelOnly
447   * @crossplatform
448   * @atomicservice
449   * @since 11
450   */
451  getApplicationContext(): ApplicationContext;
452
453  /**
454   * Get group dir by the groupId.
455   *
456   * @param { string } dataGroupID - Indicates the groupId.
457   * @param { AsyncCallback<string> } callback - The callback of getGroupDir.
458   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
459   * @throws { BusinessError } 16000011 - The context does not exist.
460   * @syscap SystemCapability.Ability.AbilityRuntime.Core
461   * @StageModelOnly
462   * @since 10
463   */
464  /**
465   * Get group dir by the groupId.
466   *
467   * @param { string } dataGroupID - Indicates the groupId.
468   * @param { AsyncCallback<string> } callback - The callback of getGroupDir.
469   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
470   * @throws { BusinessError } 16000011 - The context does not exist.
471   * @syscap SystemCapability.Ability.AbilityRuntime.Core
472   * @StageModelOnly
473   * @atomicservice
474   * @since 11
475   */
476  getGroupDir(dataGroupID: string, callback: AsyncCallback<string>): void;
477
478  /**
479   * Get group dir by the groupId.
480   *
481   * @param { string } dataGroupID - Indicates the groupId.
482   * @returns { Promise<string> } The promise returned by the function.
483   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
484   * @throws { BusinessError } 16000011 - The context does not exist.
485   * @syscap SystemCapability.Ability.AbilityRuntime.Core
486   * @StageModelOnly
487   * @since 10
488   */
489  /**
490   * Get group dir by the groupId.
491   *
492   * @param { string } dataGroupID - Indicates the groupId.
493   * @returns { Promise<string> } The promise returned by the function.
494   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
495   * @throws { BusinessError } 16000011 - The context does not exist.
496   * @syscap SystemCapability.Ability.AbilityRuntime.Core
497   * @StageModelOnly
498   * @atomicservice
499   * @since 11
500   */
501  getGroupDir(dataGroupID: string): Promise<string>;
502
503  /**
504   * Create a module resource manager.
505   *
506   * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
507   * @param { string } bundleName - Indicates the bundle name.
508   * @param { string } moduleName - Indicates the module name.
509   * @returns { resmgr.ResourceManager } Returns the module resource manager.
510   * @throws { BusinessError } 201 - Permission denied.
511   * @throws { BusinessError } 202 - Permission denied, non-system app called system api.
512   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
513   * @syscap SystemCapability.Ability.AbilityRuntime.Core
514   * @systemapi
515   * @StageModelOnly
516   * @since 11
517   */
518  createModuleResourceManager(bundleName: string, moduleName: string): resmgr.ResourceManager;
519}
520