/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"), * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file * @kit AbilityKit */ /*** if arkts 1.1 */ import type { AsyncCallback } from '../@ohos.base'; import EventHub from './EventHub'; /*** endif */ import { ApplicationInfo } from '../bundleManager/ApplicationInfo'; import ApplicationContext from './ApplicationContext'; import BaseContext from './BaseContext'; import resmgr from '../@ohos.resourceManager'; import contextConstant from '../@ohos.app.ability.contextConstant'; /** * The base context of an ability or an application. It allows access to * application-specific resources. * * @extends BaseContext * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * The base context of an ability or an application. It allows access to * application-specific resources. * * @extends BaseContext * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * The Context module, inherited frome {@link BaseContext}, provides context for abilities or applications, including * access to application-specific resources. * * @extends BaseContext * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since arkts {'1.1':'11', '1.2':'20'} * @arkts 1.1&1.2 */ declare class Context extends BaseContext { /** * Indicates the capability of accessing application resources. * * @type { resmgr.ResourceManager } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Indicates the capability of accessing application resources. * * @type { resmgr.ResourceManager } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * Object for resource management. * * @type { resmgr.ResourceManager } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since arkts {'1.1':'11', '1.2':'20'} * @arkts 1.1&1.2 */ resourceManager: resmgr.ResourceManager; /** * Indicates configuration information about an application. * * @type { ApplicationInfo } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Indicates configuration information about an application. * * @type { ApplicationInfo } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * Application information. * * @type { ApplicationInfo } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since arkts {'1.1':'11', '1.2':'20'} * @arkts 1.1&1.2 */ applicationInfo: ApplicationInfo; /** * Indicates app cache dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Indicates app cache dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * Cache directory. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since arkts {'1.1':'11', '1.2':'20'} * @arkts 1.1&1.2 */ cacheDir: string; /** * Indicates app temp dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Indicates app temp dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * Temporary directory. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since arkts {'1.1':'11', '1.2':'20'} * @arkts 1.1&1.2 */ tempDir: string; /** * Indicates app files dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Indicates app files dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * File directory. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since arkts {'1.1':'11', '1.2':'20'} * @arkts 1.1&1.2 */ filesDir: string; /** * Indicates app database dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Indicates app database dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * Database directory. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since arkts {'1.1':'11', '1.2':'20'} * @arkts 1.1&1.2 */ databaseDir: string; /** * Indicates app preferences dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Indicates app preferences dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * Preferences directory. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since arkts {'1.1':'11', '1.2':'20'} * @arkts 1.1&1.2 */ preferencesDir: string; /** * Indicates app bundle code dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Indicates app bundle code dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * Bundle code directory. * *

**NOTE**: *
Do not access resource files using concatenated paths. Use @ohos.resourceManager instead. *

* * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since 11 */ bundleCodeDir: string; /** * Indicates app distributed files dir. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Distributed file directory. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @atomicservice * @since 11 */ distributedFilesDir: string; /** * Resource directory. * *

**NOTE**: *
You are required to manually create the resfile directory in \resource. The resfile * directory can be accessed only in read-only mode. *

* * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since 11 */ resourceDir: string; /** * Cloud file directory. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @atomicservice * @since 12 */ cloudFileDir: string; /** * Indicates event hub. * * @type { EventHub } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Indicates event hub. * * @type { EventHub } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @atomicservice * @since 11 */ /** * Event hub that implements event subscription, unsubscription, and triggering. * * @type { EventHub } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since 12 */ eventHub: EventHub; /** * Indicates file area. * * @type { contextConstant.AreaMode } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Encryption level of the directory. * * @type { contextConstant.AreaMode } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @atomicservice * @since 11 */ area: contextConstant.AreaMode; /** * Get encryption level of the directory. * * @return { contextConstant.AreaMode } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @atomicservice * @since 20 * @arkts 1.2 */ get area(): contextConstant.AreaMode; /** * Set encryption level of the directory. * * @param { contextConstant.AreaMode } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @atomicservice * @since 20 * @arkts 1.2 */ set area(mode: contextConstant.AreaMode); /** * Process name of the current application. * * @type { string } * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since 18 */ processName: string; /** * Creates the context based on the bundle name. * *

**NOTE**: *
If there are multiple modules in the stage model, resource ID conflicts may occur. You are advised to * use application.createModuleContext instead. *
This API is deprecated since API version 12. You are advised to use application.createBundleContext instead. *

* * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED * @param { string } bundleName - Bundle name. * @returns { Context } Context created. * @throws { BusinessError } 201 - Permission denied. * @throws { BusinessError } 202 - Permission denied, non-system app called system api. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. * 2.Incorrect parameter types. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @systemapi * @stagemodelonly * @since 9 * @deprecated since 12 * @useinstead ohos.app.ability.application/application#createBundleContext */ createBundleContext(bundleName: string): Context; /** * Create a module context * * @param { string } moduleName - Indicates the module name. * @returns { Context } Returns the application context. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Create a module context * * @param { string } moduleName - Indicates the module name. * @returns { Context } Returns the application context. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * Creates the context based on the module name. * *

**NOTE**: *
This API is deprecated since API version 12. You are advised to use application.createModuleContext instead. *

* * @param { string } moduleName - Module name. * @returns { Context } Context created. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. * 2.Incorrect parameter types. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since 11 * @deprecated since 12 * @useinstead ohos.app.ability.application/application#createModuleContext */ createModuleContext(moduleName: string): Context; /** * Creates the context based on the bundle name and module name. * *

**NOTE**: *
This API is deprecated since API version 12. You are advised to use application.createModuleContext instead. *

* * @param { string } bundleName - Bundle name. * @param { string } moduleName - Module name. * @returns { Context } Context created. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. * 2.Incorrect parameter types. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @systemapi * @stagemodelonly * @since 9 * @deprecated since 12 * @useinstead ohos.app.ability.application/application#createModuleContext */ createModuleContext(bundleName: string, moduleName: string): Context; /** * This API allows OEM manufacturers to set up their own ResourceManager in the pre-installed system HSP. * * @param { string } bundleName - Bundle name. * @param { string } moduleName - Module name. * @returns { resmgr.ResourceManager } Returns the system HSP module resource manager. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. * 2.Incorrect parameter types. * @throws { BusinessError } 16400001 - The input bundleName is not a system HSP. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @systemapi * @stagemodelonly * @since 12 */ createSystemHspModuleResourceManager(bundleName: string, moduleName: string): resmgr.ResourceManager; /** * Get application context * * @returns { ApplicationContext } Returns the application context. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 9 */ /** * Get application context * * @returns { ApplicationContext } Returns the application context. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @since 10 */ /** * Obtains the context of this application. * * @returns { ApplicationContext } Application context obtained. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @crossplatform * @atomicservice * @since arkts {'1.1':'11', '1.2':'20'} * @arkts 1.1&1.2 */ getApplicationContext(): ApplicationContext; /** * Get group dir by the groupId. * * @param { string } dataGroupID - Indicates the groupId. * @param { AsyncCallback } callback - The callback of getGroupDir. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. * @throws { BusinessError } 16000011 - The context does not exist. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 10 */ /** * Obtains the shared directory based on a group ID. * This API uses an asynchronous callback to return the result. * * @param { string } dataGroupID - Group ID, which is assigned by the system when an atomic service project * is created. * @param { AsyncCallback } callback - Group ID, which is assigned by the system when an atomic service * project is created. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. * 2.Incorrect parameter types. * @throws { BusinessError } 16000011 - The context does not exist. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @atomicservice * @since 11 */ getGroupDir(dataGroupID: string, callback: AsyncCallback): void; /** * Get group dir by the groupId. * * @param { string } dataGroupID - Indicates the groupId. * @returns { Promise } The promise returned by the function. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. * @throws { BusinessError } 16000011 - The context does not exist. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @since 10 */ /** * Obtains the shared directory based on a group ID. * This API uses a promise to return the result. * * @param { string } dataGroupID - Group ID, which is assigned by the system when an atomic service project * is created. * @returns { Promise } Promise used to return the result. If no shared directory exists, null is returned. * Only the encryption level EL2 is supported. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. * @throws { BusinessError } 16000011 - The context does not exist. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @atomicservice * @since 11 */ getGroupDir(dataGroupID: string): Promise; /** * Creates a resource management object for a module. * * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED * @param { string } bundleName - Bundle name. * @param { string } moduleName - Module name. * @returns { resmgr.ResourceManager } Object for resource management. * @throws { BusinessError } 201 - Permission denied. * @throws { BusinessError } 202 - Permission denied, non-system app called system api. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. * 2.Incorrect parameter types. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @systemapi * @stagemodelonly * @since arkts {'1.1':'11', '1.2':'20'} * @arkts 1.1&1.2 */ createModuleResourceManager(bundleName: string, moduleName: string): resmgr.ResourceManager; /** * Creates the context for this application based on a data encryption level. * This is required when an application needs to store different types of information in different directories. * The application can obtain the corresponding directory. * * @param { contextConstant.AreaMode } areaMode - Data encryption level. * @returns { Context } Context created based on the data encryption level. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @atomicservice * @since 18 */ createAreaModeContext(areaMode: contextConstant.AreaMode): Context; /** * Creates the context based on the specified display ID, so as to obtain and use other application contexts with * screen information (including ScreenDensity and Direction). * * @param { number } displayId - Display ID. * @returns { Context } Context with the specified screen information. * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. * 2.Incorrect parameter types. * @syscap SystemCapability.Ability.AbilityRuntime.Core * @stagemodelonly * @atomicservice * @since 15 */ createDisplayContext(displayId: number): Context; } export default Context;