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