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 } 201 - Permission denied. 136 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 137 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 138 * @syscap SystemCapability.Ability.AbilityRuntime.Core 139 * @systemapi 140 * @StageModelOnly 141 * @since 9 142 */ 143 createBundleContext(bundleName: string): Context; 144 145 /** 146 * Create a module context 147 * @param { string } moduleName - Indicates the module name. 148 * @returns { Context } Returns the application context. 149 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 150 * @syscap SystemCapability.Ability.AbilityRuntime.Core 151 * @StageModelOnly 152 * @since 9 153 */ 154 createModuleContext(moduleName: string): Context; 155 156 /** 157 * Create a module context 158 * @param { string } bundleName - Indicates the bundle name. 159 * @param { string } moduleName - Indicates the module name. 160 * @returns { Context } Returns the application context. 161 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 162 * @syscap SystemCapability.Ability.AbilityRuntime.Core 163 * @systemapi 164 * @StageModelOnly 165 * @since 9 166 */ 167 createModuleContext(bundleName: string, moduleName: string): Context; 168 169 /** 170 * Get application context 171 * @returns { ApplicationContext } Returns the application context. 172 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 173 * @syscap SystemCapability.Ability.AbilityRuntime.Core 174 * @StageModelOnly 175 * @since 9 176 */ 177 getApplicationContext(): ApplicationContext; 178} 179