1/* 2 * Copyright (c) 2022-2024 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 16/** 17 * @file 18 * @kit AbilityKit 19 */ 20 21import { AsyncCallback } from './@ohos.base'; 22import { BundleInfo } from './bundleManager/BundleInfo'; 23import { ElementName } from './bundleManager/ElementName'; 24 25/** 26 * Default application manager. 27 * 28 * @namespace defaultAppManager 29 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 30 * @since 9 31 */ 32declare namespace defaultAppManager { 33 /** 34 * The constant for application type. 35 * 36 * @enum { number } 37 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 38 * @since 9 39 */ 40 export enum ApplicationType { 41 /** 42 * Default browser identifier. 43 * 44 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 45 * @since 9 46 */ 47 BROWSER = 'Web Browser', 48 /** 49 * Default image identifier. 50 * 51 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 52 * @since 9 53 */ 54 IMAGE = 'Image Gallery', 55 /** 56 * Default audio identifier. 57 * 58 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 59 * @since 9 60 */ 61 AUDIO = 'Audio Player', 62 /** 63 * Default video identifier. 64 * 65 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 66 * @since 9 67 */ 68 VIDEO = 'Video Player', 69 /** 70 * Default PDF identifier. 71 * 72 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 73 * @since 9 74 */ 75 PDF = 'PDF Viewer', 76 /** 77 * Default word identifier. 78 * 79 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 80 * @since 9 81 */ 82 WORD = 'Word Viewer', 83 /** 84 * Default excel identifier. 85 * 86 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 87 * @since 9 88 */ 89 EXCEL = 'Excel Viewer', 90 /** 91 * Default PPT identifier. 92 * 93 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 94 * @since 9 95 */ 96 PPT = 'PPT Viewer', 97 /** 98 * Default email identifier. 99 * 100 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 101 * @since 12 102 */ 103 EMAIL = 'Email' 104 } 105 106 /** 107 * Query whether the caller is default application based on type. 108 * 109 * @param { string } type - Application type or a file type that conforms to media type format. 110 * @param { AsyncCallback<boolean> } callback - The callback of querying default application result. 111 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 112 * @throws { BusinessError } 801 - Capability not supported. 113 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 114 * @since 9 115 */ 116 function isDefaultApplication(type: string, callback: AsyncCallback<boolean>): void; 117 118 /** 119 * Query whether the caller is default application based on type. 120 * 121 * @param { string } type - Application type or a file type that conforms to media type format. 122 * @returns { Promise<boolean> } Return true if caller is default application; return false otherwise. 123 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 124 * @throws { BusinessError } 801 - Capability not supported. 125 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 126 * @since 9 127 */ 128 function isDefaultApplication(type: string): Promise<boolean>; 129 130 /** 131 * Query whether the caller is default application based on type. 132 * 133 * @param { string } type - Application type or a file type that conforms to media type format. 134 * @returns { boolean } Return true if caller is default application; return false otherwise. 135 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 136 * @throws { BusinessError } 801 - Capability not supported. 137 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 138 * @since 10 139 */ 140 function isDefaultApplicationSync(type: string): boolean; 141 142 /** 143 * Get default application based on type. 144 * 145 * @permission ohos.permission.GET_DEFAULT_APPLICATION 146 * @param { string } type - Application type or a file type that conforms to media type format. 147 * @param { number } userId - Indicates the id for the user. 148 * @param { AsyncCallback<BundleInfo> } callback - The callback of the BundleInfo object result. 149 * @throws { BusinessError } 201 - Permission denied. 150 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 151 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 152 * @throws { BusinessError } 801 - Capability not supported. 153 * @throws { BusinessError } 17700004 - The specified user ID is not found. 154 * @throws { BusinessError } 17700023 - The specified default app does not exist. 155 * @throws { BusinessError } 17700025 - The specified type is invalid. 156 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 157 * @systemapi 158 * @since 9 159 */ 160 function getDefaultApplication(type: string, userId: number, callback: AsyncCallback<BundleInfo>): void; 161 162 /** 163 * Get default application based on type. 164 * 165 * @permission ohos.permission.GET_DEFAULT_APPLICATION 166 * @param { string } type - Application type or a file type that conforms to media type format. 167 * @param { AsyncCallback<BundleInfo> } callback - The callback of the BundleInfo object result. 168 * @throws { BusinessError } 201 - Permission denied. 169 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 170 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 171 * @throws { BusinessError } 801 - Capability not supported. 172 * @throws { BusinessError } 17700023 - The specified default app does not exist. 173 * @throws { BusinessError } 17700025 - The specified type is invalid. 174 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 175 * @systemapi 176 * @since 9 177 */ 178 function getDefaultApplication(type: string, callback: AsyncCallback<BundleInfo>): void; 179 180 /** 181 * Get default application based on type. 182 * 183 * @permission ohos.permission.GET_DEFAULT_APPLICATION 184 * @param { string } type - Application type or a file type that conforms to media type format. 185 * @param { number } userId - Indicates the id for the user. 186 * @returns { Promise<BundleInfo> } Return the BundleInfo object. 187 * @throws { BusinessError } 201 - Permission denied. 188 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 189 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 190 * @throws { BusinessError } 801 - Capability not supported. 191 * @throws { BusinessError } 17700004 - The specified user ID is not found. 192 * @throws { BusinessError } 17700023 - The specified default app does not exist. 193 * @throws { BusinessError } 17700025 - The specified type is invalid. 194 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 195 * @systemapi 196 * @since 9 197 */ 198 function getDefaultApplication(type: string, userId?: number): Promise<BundleInfo>; 199 200 /** 201 * Get default application based on type. 202 * 203 * @permission ohos.permission.GET_DEFAULT_APPLICATION 204 * @param { string } type - Application type or a file type that conforms to media type format. 205 * @param { number } userId - Indicates the id for the user. 206 * @returns { BundleInfo } Return the BundleInfo object. 207 * @throws { BusinessError } 201 - Permission denied. 208 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 209 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 210 * @throws { BusinessError } 801 - Capability not supported. 211 * @throws { BusinessError } 17700004 - The specified user ID is not found. 212 * @throws { BusinessError } 17700023 - The specified default app does not exist. 213 * @throws { BusinessError } 17700025 - The specified type is invalid. 214 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 215 * @systemapi 216 * @since 10 217 */ 218 function getDefaultApplicationSync(type: string, userId?: number): BundleInfo; 219 220 /** 221 * Set default application based on type. 222 * 223 * @permission ohos.permission.SET_DEFAULT_APPLICATION 224 * @param { string } type - Application type or a file type that conforms to media type format. 225 * @param { ElementName } elementName - Uniquely identifies an ability or extensionAbility. 226 * @param { number } userId - Indicates the id for the user. 227 * @param { AsyncCallback<void> } callback - The callback of setting default application result. 228 * @throws { BusinessError } 201 - Permission denied. 229 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 230 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 231 * @throws { BusinessError } 801 - Capability not supported. 232 * @throws { BusinessError } 17700004 - The specified user ID is not found. 233 * @throws { BusinessError } 17700025 - The specified type is invalid. 234 * @throws { BusinessError } 17700028 - The specified ability does not match the type. 235 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 236 * @systemapi 237 * @since 9 238 */ 239 function setDefaultApplication(type: string, 240 elementName: ElementName, userId: number, callback: AsyncCallback<void>): void; 241 242 /** 243 * Set default application based on type. 244 * 245 * @permission ohos.permission.SET_DEFAULT_APPLICATION 246 * @param { string } type - Application type or a file type that conforms to media type format. 247 * @param { ElementName } elementName - Uniquely identifies an ability or extensionAbility. 248 * @param { AsyncCallback<void> } callback - The callback of setting default application result. 249 * @throws { BusinessError } 201 - Permission denied. 250 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 251 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 252 * @throws { BusinessError } 801 - Capability not supported. 253 * @throws { BusinessError } 17700025 - The specified type is invalid. 254 * @throws { BusinessError } 17700028 - The specified ability does not match the type. 255 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 256 * @systemapi 257 * @since 9 258 */ 259 function setDefaultApplication(type: string, elementName: ElementName, callback: AsyncCallback<void>): void; 260 261 /** 262 * Set default application based on type. 263 * 264 * @permission ohos.permission.SET_DEFAULT_APPLICATION 265 * @param { string } type - Application type or a file type that conforms to media type format. 266 * @param { ElementName } elementName - Uniquely identifies an ability or extensionAbility. 267 * @param { number } userId - Indicates the id for the user. 268 * @returns { Promise<void> } The result of setting default application. 269 * @throws { BusinessError } 201 - Permission denied. 270 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 271 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 272 * @throws { BusinessError } 801 - Capability not supported. 273 * @throws { BusinessError } 17700004 - The specified user ID is not found. 274 * @throws { BusinessError } 17700025 - The specified type is invalid. 275 * @throws { BusinessError } 17700028 - The specified ability does not match the type. 276 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 277 * @systemapi 278 * @since 9 279 */ 280 function setDefaultApplication(type: string, elementName: ElementName, userId?: number): Promise<void>; 281 282 /** 283 * Set default application based on type. 284 * 285 * @permission ohos.permission.SET_DEFAULT_APPLICATION 286 * @param { string } type - Application type or a file type that conforms to media type format. 287 * @param { ElementName } elementName - Uniquely identifies an ability or extensionAbility. 288 * @param { number } userId - Indicates the id for the user. 289 * @throws { BusinessError } 201 - Permission denied. 290 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 291 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 292 * @throws { BusinessError } 801 - Capability not supported. 293 * @throws { BusinessError } 17700004 - The specified user ID is not found. 294 * @throws { BusinessError } 17700025 - The specified type is invalid. 295 * @throws { BusinessError } 17700028 - The specified ability does not match the type. 296 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 297 * @systemapi 298 * @since 10 299 */ 300 function setDefaultApplicationSync(type: string, elementName: ElementName, userId?: number): void; 301 302 /** 303 * Reset default application based on type. 304 * 305 * @permission ohos.permission.SET_DEFAULT_APPLICATION 306 * @param { string } type - Application type or a file type that conforms to media type format. 307 * @param { number } userId - Indicates the id for the user. 308 * @param { AsyncCallback<void> } callback - The callback of resetting default application result. 309 * @throws { BusinessError } 201 - Permission denied. 310 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 311 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 312 * @throws { BusinessError } 801 - Capability not supported. 313 * @throws { BusinessError } 17700004 - The specified user ID is not found. 314 * @throws { BusinessError } 17700025 - The specified type is invalid. 315 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 316 * @systemapi 317 * @since 9 318 */ 319 function resetDefaultApplication(type: string, userId: number, callback: AsyncCallback<void>): void; 320 321 /** 322 * Reset default application based on type. 323 * 324 * @permission ohos.permission.SET_DEFAULT_APPLICATION 325 * @param { string } type - Application type or a file type that conforms to media type format. 326 * @param { AsyncCallback<void> } callback - The callback of resetting default application result. 327 * @throws { BusinessError } 201 - Permission denied. 328 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 329 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 330 * @throws { BusinessError } 801 - Capability not supported. 331 * @throws { BusinessError } 17700025 - The specified type is invalid. 332 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 333 * @systemapi 334 * @since 9 335 */ 336 function resetDefaultApplication(type: string, callback: AsyncCallback<void>): void; 337 338 /** 339 * Reset default application based on type. 340 * 341 * @permission ohos.permission.SET_DEFAULT_APPLICATION 342 * @param { string } type - Application type or a file type that conforms to media type format. 343 * @param { number } userId - Indicates the id for the user. 344 * @returns { Promise<void> } The result of resetting default application. 345 * @throws { BusinessError } 201 - Permission denied. 346 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 347 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 348 * @throws { BusinessError } 801 - Capability not supported. 349 * @throws { BusinessError } 17700004 - The specified user ID is not found. 350 * @throws { BusinessError } 17700025 - The specified type is invalid. 351 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 352 * @systemapi 353 * @since 9 354 */ 355 function resetDefaultApplication(type: string, userId?: number): Promise<void>; 356 357 /** 358 * Reset default application based on type. 359 * 360 * @permission ohos.permission.SET_DEFAULT_APPLICATION 361 * @param { string } type - Application type or a file type that conforms to media type format. 362 * @param { number } userId - Indicates the id for the user. 363 * @throws { BusinessError } 201 - Permission denied. 364 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 365 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 366 * @throws { BusinessError } 801 - Capability not supported. 367 * @throws { BusinessError } 17700004 - The specified user ID is not found. 368 * @throws { BusinessError } 17700025 - The specified type is invalid. 369 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 370 * @systemapi 371 * @since 10 372 */ 373 function resetDefaultApplicationSync(type: string, userId?: number): void; 374} 375 376export default defaultAppManager; 377