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 './basic'; 17import { BundleInfo } from './bundleManager/BundleInfo'; 18import { ElementName } from './bundleManager/ElementName'; 19 20/** 21 * Default application manager. 22 * @namespace defaultAppManager 23 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 24 * @since 9 25 */ 26declare namespace defaultAppManager { 27 /** 28 * The constant for application type. 29 * @enum {number} 30 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 31 * @since 9 32 */ 33 export enum ApplicationType { 34 /** 35 * Default browser identifier. 36 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 37 * @since 9 38 */ 39 BROWSER = "Web Browser", 40 /** 41 * Default image identifier. 42 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 43 * @since 9 44 */ 45 IMAGE = "Image Gallery", 46 /** 47 * Default audio identifier. 48 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 49 * @since 9 50 */ 51 AUDIO = "Audio Player", 52 /** 53 * Default video identifier. 54 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 55 * @since 9 56 */ 57 VIDEO = "Video Player", 58 /** 59 * Default PDF identifier. 60 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 61 * @since 9 62 */ 63 PDF = "PDF Viewer", 64 /** 65 * Default word identifier. 66 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 67 * @since 9 68 */ 69 WORD = "Word Viewer", 70 /** 71 * Default excel identifier. 72 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 73 * @since 9 74 */ 75 EXCEL = "Excel Viewer", 76 /** 77 * Default PPT identifier. 78 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 79 * @since 9 80 */ 81 PPT = "PPT Viewer", 82 } 83 84 /** 85 * Query whether the caller is default application based on type. 86 * @param { string } type - Application type or a file type that conforms to media type format. 87 * @param { AsyncCallback<boolean> } callback - The callback of querying default application result. 88 * @throws { BusinessError } 401 - The parameter check failed. 89 * @throws { BusinessError } 801 - Capability not supported. 90 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 91 * @since 9 92 */ 93 function isDefaultApplication(type: string, callback: AsyncCallback<boolean>) : void; 94 95 /** 96 * Query whether the caller is default application based on type. 97 * @param { string } type - Application type or a file type that conforms to media type format. 98 * @returns { Promise<boolean> } Return true if caller is default application; return false otherwise. 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) : Promise<boolean>; 105 106 /** 107 * Get default application based on type. 108 * @permission ohos.permission.GET_DEFAULT_APPLICATION 109 * @param { string } type - Application type or a file type that conforms to media type format. 110 * @param { number } userId - Indicates the id for the user. 111 * @param { AsyncCallback<BundleInfo> } callback - The callback of the BundleInfo object result. 112 * @throws { BusinessError } 201 - Permission denied. 113 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 114 * @throws { BusinessError } 401 - The parameter check failed. 115 * @throws { BusinessError } 801 - Capability not supported. 116 * @throws { BusinessError } 17700004 - The specified user ID is not found. 117 * @throws { BusinessError } 17700023 - The specified default app does not exist. 118 * @throws { BusinessError } 17700025 - The specified type is invalid. 119 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 120 * @systemapi 121 * @since 9 122 */ 123 function getDefaultApplication(type: string, userId: number, callback: AsyncCallback<BundleInfo>) : void; 124 function getDefaultApplication(type: string, callback: AsyncCallback<BundleInfo>) : void; 125 126 /** 127 * Get default application based on type. 128 * @permission ohos.permission.GET_DEFAULT_APPLICATION 129 * @param { string } type - Application type or a file type that conforms to media type format. 130 * @param { number } userId - Indicates the id for the user. 131 * @returns { Promise<BundleInfo> } Return the BundleInfo object. 132 * @throws { BusinessError } 201 - Permission denied. 133 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 134 * @throws { BusinessError } 401 - The parameter check failed. 135 * @throws { BusinessError } 801 - Capability not supported. 136 * @throws { BusinessError } 17700004 - The specified user ID is not found. 137 * @throws { BusinessError } 17700023 - The specified default app does not exist. 138 * @throws { BusinessError } 17700025 - The specified type is invalid. 139 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 140 * @systemapi 141 * @since 9 142 */ 143 function getDefaultApplication(type: string, userId?: number) : Promise<BundleInfo>; 144 145 /** 146 * Set default application based on type. 147 * @permission ohos.permission.SET_DEFAULT_APPLICATION 148 * @param { string } type - Application type or a file type that conforms to media type format. 149 * @param { ElementName } elementName - Uniquely identifies an ability or extensionAbility. 150 * @param { number } userId - Indicates the id for the user. 151 * @param { AsyncCallback<void> } callback - The callback of setting default application result. 152 * @throws { BusinessError } 201 - Permission denied. 153 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 154 * @throws { BusinessError } 401 - The parameter check failed. 155 * @throws { BusinessError } 801 - Capability not supported. 156 * @throws { BusinessError } 17700004 - The specified user ID is not found. 157 * @throws { BusinessError } 17700025 - The specified type is invalid. 158 * @throws { BusinessError } 17700028 - The specified ability does not match the type. 159 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 160 * @systemapi 161 * @since 9 162 */ 163 function setDefaultApplication(type: string, elementName: ElementName, userId: number, callback: AsyncCallback<void>) : void; 164 function setDefaultApplication(type: string, elementName: ElementName, callback: AsyncCallback<void>) : void; 165 166 /** 167 * Set default application based on type. 168 * @permission ohos.permission.SET_DEFAULT_APPLICATION 169 * @param { string } type - Application type or a file type that conforms to media type format. 170 * @param { ElementName } elementName - Uniquely identifies an ability or extensionAbility. 171 * @param { number } userId - Indicates the id for the user. 172 * @returns { Promise<void> } The result of setting default application. 173 * @throws { BusinessError } 201 - Permission denied. 174 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 175 * @throws { BusinessError } 401 - The parameter check failed. 176 * @throws { BusinessError } 801 - Capability not supported. 177 * @throws { BusinessError } 17700004 - The specified user ID is not found. 178 * @throws { BusinessError } 17700025 - The specified type is invalid. 179 * @throws { BusinessError } 17700028 - The specified ability does not match the type. 180 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 181 * @systemapi 182 * @since 9 183 */ 184 function setDefaultApplication(type: string, elementName: ElementName, userId?: number) : Promise<void>; 185 186 /** 187 * Reset default application based on type. 188 * @permission ohos.permission.SET_DEFAULT_APPLICATION 189 * @param { string } type - Application type or a file type that conforms to media type format. 190 * @param { number } userId - Indicates the id for the user. 191 * @param { AsyncCallback<void> } callback - The callback of resetting default application result. 192 * @throws { BusinessError } 201 - Permission denied. 193 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 194 * @throws { BusinessError } 401 - The parameter check failed. 195 * @throws { BusinessError } 801 - Capability not supported. 196 * @throws { BusinessError } 17700004 - The specified user ID is not found. 197 * @throws { BusinessError } 17700025 - The specified type is invalid. 198 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 199 * @systemapi 200 * @since 9 201 */ 202 function resetDefaultApplication(type: string, userId: number, callback: AsyncCallback<void>) : void; 203 function resetDefaultApplication(type: string, callback: AsyncCallback<void>) : void; 204 205 /** 206 * Reset default application based on type. 207 * @permission ohos.permission.SET_DEFAULT_APPLICATION 208 * @param { string } type - Application type or a file type that conforms to media type format. 209 * @param { number } userId - Indicates the id for the user. 210 * @returns { Promise<void> } The result of resetting default application. 211 * @throws { BusinessError } 201 - Permission denied. 212 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 213 * @throws { BusinessError } 401 - The parameter check failed. 214 * @throws { BusinessError } 801 - Capability not supported. 215 * @throws { BusinessError } 17700004 - The specified user ID is not found. 216 * @throws { BusinessError } 17700025 - The specified type is invalid. 217 * @syscap SystemCapability.BundleManager.BundleFramework.DefaultApp 218 * @systemapi 219 * @since 9 220 */ 221 function resetDefaultApplication(type: string, userId?: number) : Promise<void>; 222} 223 224export default defaultAppManager;