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 */ 43export default class Context extends BaseContext { 44 /** 45 * Indicates the capability of accessing application resources. 46 * 47 * @type { resmgr.ResourceManager } 48 * @syscap SystemCapability.Ability.AbilityRuntime.Core 49 * @StageModelOnly 50 * @since 9 51 */ 52 /** 53 * Indicates the capability of accessing application resources. 54 * 55 * @type { resmgr.ResourceManager } 56 * @syscap SystemCapability.Ability.AbilityRuntime.Core 57 * @StageModelOnly 58 * @crossplatform 59 * @since 10 60 */ 61 resourceManager: resmgr.ResourceManager; 62 63 /** 64 * Indicates configuration information about an application. 65 * 66 * @type { ApplicationInfo } 67 * @syscap SystemCapability.Ability.AbilityRuntime.Core 68 * @StageModelOnly 69 * @since 9 70 */ 71 /** 72 * Indicates configuration information about an application. 73 * 74 * @type { ApplicationInfo } 75 * @syscap SystemCapability.Ability.AbilityRuntime.Core 76 * @StageModelOnly 77 * @crossplatform 78 * @since 10 79 */ 80 applicationInfo: ApplicationInfo; 81 82 /** 83 * Indicates app cache dir. 84 * 85 * @type { string } 86 * @syscap SystemCapability.Ability.AbilityRuntime.Core 87 * @StageModelOnly 88 * @since 9 89 */ 90 /** 91 * Indicates app cache dir. 92 * 93 * @type { string } 94 * @syscap SystemCapability.Ability.AbilityRuntime.Core 95 * @StageModelOnly 96 * @crossplatform 97 * @since 10 98 */ 99 cacheDir: string; 100 101 /** 102 * Indicates app temp dir. 103 * 104 * @type { string } 105 * @syscap SystemCapability.Ability.AbilityRuntime.Core 106 * @StageModelOnly 107 * @since 9 108 */ 109 /** 110 * Indicates app temp dir. 111 * 112 * @type { string } 113 * @syscap SystemCapability.Ability.AbilityRuntime.Core 114 * @StageModelOnly 115 * @crossplatform 116 * @since 10 117 */ 118 tempDir: string; 119 120 /** 121 * Indicates app files dir. 122 * 123 * @type { string } 124 * @syscap SystemCapability.Ability.AbilityRuntime.Core 125 * @StageModelOnly 126 * @since 9 127 */ 128 /** 129 * Indicates app files dir. 130 * 131 * @type { string } 132 * @syscap SystemCapability.Ability.AbilityRuntime.Core 133 * @StageModelOnly 134 * @crossplatform 135 * @since 10 136 */ 137 filesDir: string; 138 139 /** 140 * Indicates app database dir. 141 * 142 * @type { string } 143 * @syscap SystemCapability.Ability.AbilityRuntime.Core 144 * @StageModelOnly 145 * @since 9 146 */ 147 /** 148 * Indicates app database dir. 149 * 150 * @type { string } 151 * @syscap SystemCapability.Ability.AbilityRuntime.Core 152 * @StageModelOnly 153 * @crossplatform 154 * @since 10 155 */ 156 databaseDir: string; 157 158 /** 159 * Indicates app preferences dir. 160 * 161 * @type { string } 162 * @syscap SystemCapability.Ability.AbilityRuntime.Core 163 * @StageModelOnly 164 * @since 9 165 */ 166 /** 167 * Indicates app preferences dir. 168 * 169 * @type { string } 170 * @syscap SystemCapability.Ability.AbilityRuntime.Core 171 * @StageModelOnly 172 * @crossplatform 173 * @since 10 174 */ 175 preferencesDir: string; 176 177 /** 178 * Indicates app bundle code dir. 179 * 180 * @type { string } 181 * @syscap SystemCapability.Ability.AbilityRuntime.Core 182 * @StageModelOnly 183 * @since 9 184 */ 185 /** 186 * Indicates app bundle code dir. 187 * 188 * @type { string } 189 * @syscap SystemCapability.Ability.AbilityRuntime.Core 190 * @StageModelOnly 191 * @crossplatform 192 * @since 10 193 */ 194 bundleCodeDir: string; 195 196 /** 197 * Indicates app distributed files dir. 198 * 199 * @type { string } 200 * @syscap SystemCapability.Ability.AbilityRuntime.Core 201 * @StageModelOnly 202 * @since 9 203 */ 204 distributedFilesDir: string; 205 206 /** 207 * Indicates event hub. 208 * 209 * @type { EventHub } 210 * @syscap SystemCapability.Ability.AbilityRuntime.Core 211 * @StageModelOnly 212 * @since 9 213 */ 214 eventHub: EventHub; 215 216 /** 217 * Indicates file area. 218 * 219 * @type { contextConstant.AreaMode } 220 * @syscap SystemCapability.Ability.AbilityRuntime.Core 221 * @StageModelOnly 222 * @since 9 223 */ 224 area: contextConstant.AreaMode; 225 226 /** 227 * Create a bundle context 228 * 229 * @permission ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 230 * @param { string } bundleName - Indicates the bundle name. 231 * @returns { Context } Returns the application context. 232 * @throws { BusinessError } 201 - Permission denied. 233 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 234 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 235 * @syscap SystemCapability.Ability.AbilityRuntime.Core 236 * @systemapi 237 * @StageModelOnly 238 * @since 9 239 */ 240 createBundleContext(bundleName: string): Context; 241 242 /** 243 * Create a module context 244 * 245 * @param { string } moduleName - Indicates the module name. 246 * @returns { Context } Returns the application context. 247 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 248 * @syscap SystemCapability.Ability.AbilityRuntime.Core 249 * @StageModelOnly 250 * @since 9 251 */ 252 /** 253 * Create a module context 254 * 255 * @param { string } moduleName - Indicates the module name. 256 * @returns { Context } Returns the application context. 257 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 258 * @syscap SystemCapability.Ability.AbilityRuntime.Core 259 * @StageModelOnly 260 * @crossplatform 261 * @since 10 262 */ 263 createModuleContext(moduleName: string): Context; 264 265 /** 266 * Create a module context 267 * 268 * @param { string } bundleName - Indicates the bundle name. 269 * @param { string } moduleName - Indicates the module name. 270 * @returns { Context } Returns the application context. 271 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 272 * @syscap SystemCapability.Ability.AbilityRuntime.Core 273 * @systemapi 274 * @StageModelOnly 275 * @since 9 276 */ 277 createModuleContext(bundleName: string, moduleName: string): Context; 278 279 /** 280 * Get application context 281 * 282 * @returns { ApplicationContext } Returns the application context. 283 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 284 * @syscap SystemCapability.Ability.AbilityRuntime.Core 285 * @StageModelOnly 286 * @since 9 287 */ 288 /** 289 * Get application context 290 * 291 * @returns { ApplicationContext } Returns the application context. 292 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 293 * @syscap SystemCapability.Ability.AbilityRuntime.Core 294 * @StageModelOnly 295 * @crossplatform 296 * @since 10 297 */ 298 getApplicationContext(): ApplicationContext; 299 300 /** 301 * Get group dir by the groupId. 302 * 303 * @param { string } dataGroupID - Indicates the groupId. 304 * @param { AsyncCallback<string> } callback - The callback of getGroupDir. 305 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 306 * @throws { BusinessError } 16000011 - The context does not exist. 307 * @syscap SystemCapability.Ability.AbilityRuntime.Core 308 * @StageModelOnly 309 * @since 10 310 */ 311 getGroupDir(dataGroupID: string, callback: AsyncCallback<string>): void; 312 313 /** 314 * Get group dir by the groupId. 315 * 316 * @param { string } dataGroupID - Indicates the groupId. 317 * @returns { Promise<string> } The promise returned by the function. 318 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 319 * @throws { BusinessError } 16000011 - The context does not exist. 320 * @syscap SystemCapability.Ability.AbilityRuntime.Core 321 * @StageModelOnly 322 * @since 10 323 */ 324 getGroupDir(dataGroupID: string): Promise<string>; 325} 326