liangliang6768 a00ac8b17c change api16 to 18
Signed-off-by: liangliang6768 <xuliang110@huawei.com>
2025-03-02 09:37:24 +08:00

606 lines
17 KiB
TypeScript

/*
* 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
*/
import { ApplicationInfo } from '../bundleManager/ApplicationInfo';
import type { AsyncCallback } from '../@ohos.base';
import resmgr from '../@ohos.resourceManager';
import BaseContext from './BaseContext';
import EventHub from './EventHub';
import ApplicationContext from './ApplicationContext';
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 base context of an ability or an application. It allows access to
* application-specific resources.
*
* @extends BaseContext
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @crossplatform
* @atomicservice
* @since 11
*/
export default 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
*/
/**
* Indicates the capability of accessing application resources.
*
* @type { resmgr.ResourceManager }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @crossplatform
* @atomicservice
* @since 11
*/
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
*/
/**
* Indicates configuration information about an application.
*
* @type { ApplicationInfo }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @crossplatform
* @atomicservice
* @since 11
*/
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
*/
/**
* Indicates app cache dir.
*
* @type { string }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @crossplatform
* @atomicservice
* @since 11
*/
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
*/
/**
* Indicates app temp dir.
*
* @type { string }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @crossplatform
* @atomicservice
* @since 11
*/
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
*/
/**
* Indicates app files dir.
*
* @type { string }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @crossplatform
* @atomicservice
* @since 11
*/
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
*/
/**
* Indicates app database dir.
*
* @type { string }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @crossplatform
* @atomicservice
* @since 11
*/
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
*/
/**
* Indicates app preferences dir.
*
* @type { string }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @crossplatform
* @atomicservice
* @since 11
*/
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
*/
/**
* Indicates app bundle code dir.
*
* @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
*/
/**
* Indicates app distributed files dir.
*
* @type { string }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @atomicservice
* @since 11
*/
distributedFilesDir: string;
/**
* Indicates app bundle resource dir.
*
* @type { string }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @crossplatform
* @atomicservice
* @since 11
*/
resourceDir: string;
/**
* Indicates app cloud storage files dir.
*
* @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
*/
/**
* Indicates event hub.
*
* @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
*/
/**
* Indicates file area.
*
* @type { contextConstant.AreaMode }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @atomicservice
* @since 11
*/
area: contextConstant.AreaMode;
/**
* Indicates process name.
*
* @type { string }
* @syscap SystemCapability.Ability.AbilityRuntime.Core
* @stagemodelonly
* @crossplatform
* @atomicservice
* @since 18
*/
processName: string;
/**
* Create a bundle context
*
* @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
* @param { string } bundleName - Indicates the bundle name.
* @returns { Context } Returns the application context.
* @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
*/
/**
* 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
* @atomicservice
* @since 11
* @deprecated since 12
* @useinstead ohos.app.ability.application/application#createModuleContext
*/
createModuleContext(moduleName: string): Context;
/**
* Create a module context
*
* @param { string } bundleName - Indicates the bundle name.
* @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
* @systemapi
* @stagemodelonly
* @since 9
* @deprecated since 12
* @useinstead ohos.app.ability.application/application#createModuleContext
*/
createModuleContext(bundleName: string, moduleName: string): Context;
/**
* Create a system HSP module resource manager.
*
* @param { string } bundleName - Indicates the bundle name.
* @param { string } moduleName - Indicates the 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 - If the input bundleName is not 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
*/
/**
* 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
* @atomicservice
* @since 11
*/
getApplicationContext(): ApplicationContext;
/**
* Get group dir by the groupId.
*
* @param { string } dataGroupID - Indicates the groupId.
* @param { AsyncCallback<string> } 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
*/
/**
* Get group dir by the groupId.
*
* @param { string } dataGroupID - Indicates the groupId.
* @param { AsyncCallback<string> } 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
* @atomicservice
* @since 11
*/
getGroupDir(dataGroupID: string, callback: AsyncCallback<string>): void;
/**
* Get group dir by the groupId.
*
* @param { string } dataGroupID - Indicates the groupId.
* @returns { Promise<string> } 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
*/
/**
* Get group dir by the groupId.
*
* @param { string } dataGroupID - Indicates the groupId.
* @returns { Promise<string> } 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
* @atomicservice
* @since 11
*/
getGroupDir(dataGroupID: string): Promise<string>;
/**
* Create a module resource manager.
*
* @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
* @param { string } bundleName - Indicates the bundle name.
* @param { string } moduleName - Indicates the module name.
* @returns { resmgr.ResourceManager } Returns the module resource manager.
* @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 11
*/
createModuleResourceManager(bundleName: string, moduleName: string): resmgr.ResourceManager;
/**
* Create a area mode context.This context uses the same resourceManager as the original context.
*
* @param { contextConstant.AreaMode } areaMode - Indicates the area mode.
* @returns { Context } Returns the context with the specified area mode.
* @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 18
*/
createAreaModeContext(areaMode: contextConstant.AreaMode): Context;
/**
* Create a context by displayId. This Context updates the density and direction properties based on the displayId,
* while other property values remain the same as in the original Context.
*
* @param { number } displayId - Indicates the displayId.
* @returns { Context } Returns the context with the specified displayId.
* @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;
}