1/* 2 * Copyright (c) 2023-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 MDMKit 19 */ 20 21import type { AsyncCallback } from './@ohos.base'; 22import type Want from './@ohos.app.ability.Want'; 23 24/** 25 * This module provides the capability to manage the usb of the enterprise devices. 26 * 27 * @namespace usbManager 28 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 29 * @since 10 30 */ 31declare namespace usbManager { 32 /** 33 * Usb policy 34 * 35 * @enum { number } 36 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 37 * @stagemodelonly 38 * @since 12 39 */ 40 export enum UsbPolicy { 41 /** 42 * Policy read write 43 * 44 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 45 * @stagemodelonly 46 * @since 12 47 */ 48 READ_WRITE = 0, 49 50 /** 51 * Policy read only 52 * 53 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 54 * @stagemodelonly 55 * @since 12 56 */ 57 READ_ONLY = 1, 58 59 /** 60 * Policy disabled 61 * 62 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 63 * @stagemodelonly 64 * @since 12 65 */ 66 DISABLED = 2 67 } 68 69 /** 70 * USB device ID. 71 * 72 * @typedef UsbDeviceId 73 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 74 * @stagemodelonly 75 * @since 12 76 */ 77 export interface UsbDeviceId { 78 /** 79 * The vendor ID of the USB device. 80 * 81 * @type { number } 82 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 83 * @stagemodelonly 84 * @since 12 85 */ 86 vendorId: number; 87 88 /** 89 * The product ID of the USB device. 90 * 91 * @type { number } 92 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 93 * @stagemodelonly 94 * @since 12 95 */ 96 productId: number; 97 } 98 99 /** 100 * USB Descriptor 101 * 102 * @enum { number } 103 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 104 * @stagemodelonly 105 * @since 14 106 */ 107 enum Descriptor { 108 /** 109 * Interface descriptor 110 * 111 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 112 * @stagemodelonly 113 * @since 14 114 */ 115 INTERFACE = 0, 116 117 /** 118 * Device descriptor 119 * 120 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 121 * @stagemodelonly 122 * @since 14 123 */ 124 DEVICE = 1 125 } 126 127 /** 128 * USB device Type. 129 * 130 * @typedef UsbDeviceType 131 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 132 * @stagemodelonly 133 * @since 14 134 */ 135 export interface UsbDeviceType { 136 /** 137 * The base class in USB class code information. 138 * 139 * @type { number } 140 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 141 * @stagemodelonly 142 * @since 14 143 */ 144 baseClass: number; 145 146 /** 147 * The subclass in USB class code information. 148 * 149 * @type { number } 150 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 151 * @stagemodelonly 152 * @since 14 153 */ 154 subClass: number; 155 156 /** 157 * The protocol in USB class code information. 158 * 159 * @type { number } 160 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 161 * @stagemodelonly 162 * @since 14 163 */ 164 protocol: number; 165 166 /** 167 * The descriptor that the class code is used in. 168 * 169 * @type { Descriptor } 170 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 171 * @stagemodelonly 172 * @since 14 173 */ 174 descriptor: Descriptor; 175 } 176 177 /** 178 * Set usb policy by {@link UsbPolicy}. 179 * This function can be called by a super administrator. 180 * 181 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 182 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 183 * The admin must have the corresponding permission. 184 * @param { UsbPolicy } usbPolicy - usb policy code. 185 * @param { AsyncCallback<void> } callback - the callback of setUsbPolicy. 186 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 187 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 188 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 189 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 190 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 191 * 2. Incorrect parameter types; 3. Parameter verification failed. 192 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 193 * @systemapi 194 * @stagemodelonly 195 * @since 10 196 */ 197 function setUsbPolicy(admin: Want, usbPolicy: UsbPolicy, callback: AsyncCallback<void>): void; 198 199 /** 200 * Set usb policy by {@link UsbPolicy}. 201 * This function can be called by a super administrator. 202 * 203 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 204 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 205 * The admin must have the corresponding permission. 206 * @param { UsbPolicy } usbPolicy - usb policy code. 207 * @returns { Promise<void> } the promise returned setUsbPolicy. 208 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 209 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 210 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 211 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 212 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 213 * 2. Incorrect parameter types; 3. Parameter verification failed. 214 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 215 * @systemapi 216 * @stagemodelonly 217 * @since 10 218 */ 219 function setUsbPolicy(admin: Want, usbPolicy: UsbPolicy): Promise<void>; 220 221 /** 222 * Disables USB. 223 * This function can be called by a super administrator. 224 * 225 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 226 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 227 * The admin must have the corresponding permission. 228 * @param { boolean } disable - true if disable USB, otherwise false. 229 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 230 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 231 * @throws { BusinessError } 9200010 - A conflict policy has been configured. 232 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 233 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 234 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 235 * 2. Incorrect parameter types; 3. Parameter verification failed. 236 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 237 * @systemapi 238 * @stagemodelonly 239 * @since 11 240 */ 241 function disableUsb(admin: Want, disable: boolean): void; 242 243 /** 244 * Queries whether USB is disabled. 245 * This function can be called by a super administrator. 246 * 247 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 248 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 249 * If the admin is not empty, it must have the corresponding permission. 250 * @returns { boolean } true if USB is disabled, otherwise false. 251 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 252 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 253 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 254 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 255 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 256 * 2. Incorrect parameter types; 3. Parameter verification failed. 257 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 258 * @systemapi 259 * @stagemodelonly 260 * @since 11 261 */ 262 function isUsbDisabled(admin: Want): boolean; 263 264 /** 265 * Adds the available USB device trust list by {@link UsbDeviceId} array. 266 * This function can be called by a super administrator. 267 * 268 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 269 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 270 * The admin must have the corresponding permission. 271 * @param { Array<UsbDeviceId> } usbDeviceIds - an array of added USB device ids. 272 * The size of the array after setting cannot be greater 1000. 273 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 274 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 275 * @throws { BusinessError } 9200010 - A conflict policy has been configured. 276 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 277 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 278 * 2. Incorrect parameter types; 3. Parameter verification failed. 279 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 280 * @stagemodelonly 281 * @since 12 282 */ 283 function addAllowedUsbDevices(admin: Want, usbDeviceIds: Array<UsbDeviceId>): void; 284 285 /** 286 * Removes the available USB device trust list by {@link UsbDeviceId} array. 287 * This function can be called by a super administrator. 288 * 289 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 290 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 291 * The admin must have the corresponding permission. 292 * @param { Array<UsbDeviceId> } usbDeviceIds - an array of removed USB device ids. 293 * The size of the array after setting cannot be greater 1000. 294 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 295 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 296 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 297 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 298 * 2. Incorrect parameter types; 3. Parameter verification failed. 299 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 300 * @stagemodelonly 301 * @since 12 302 */ 303 function removeAllowedUsbDevices(admin: Want, usbDeviceIds: Array<UsbDeviceId>): void; 304 305 /** 306 * Gets the available USB device trust list. 307 * This function can be called by a super administrator. 308 * 309 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 310 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 311 * The admin must have the corresponding permission. 312 * @returns { Array<UsbDeviceId> } an array of the available USB device trust list. 313 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 314 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 315 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 316 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 317 * 2. Incorrect parameter types; 3. Parameter verification failed. 318 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 319 * @stagemodelonly 320 * @since 12 321 */ 322 function getAllowedUsbDevices(admin: Want): Array<UsbDeviceId>; 323 324 /** 325 * Sets USB storage device access policy by {@link UsbPolicy}. 326 * This function can be called by a super administrator. 327 * 328 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 329 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 330 * The admin must have the corresponding permission. 331 * @param { UsbPolicy } usbPolicy - USB policy of storage device. 332 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 333 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 334 * @throws { BusinessError } 9200010 - A conflict policy has been configured. 335 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 336 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 337 * 2. Incorrect parameter types; 3. Parameter verification failed. 338 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 339 * @stagemodelonly 340 * @since 12 341 */ 342 function setUsbStorageDeviceAccessPolicy(admin: Want, usbPolicy: UsbPolicy): void; 343 344 /** 345 * Gets USB storage device access policy. 346 * This function can be called by a super administrator. 347 * 348 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 349 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 350 * The admin must have the corresponding permission. 351 * @returns { UsbPolicy } USB policy of storage device. 352 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 353 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 354 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 355 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 356 * 2. Incorrect parameter types; 3. Parameter verification failed. 357 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 358 * @stagemodelonly 359 * @since 12 360 */ 361 function getUsbStorageDeviceAccessPolicy(admin: Want): UsbPolicy; 362 363 /** 364 * Adds disallowed USB devices by {@link UsbDeviceType} array. 365 * This function can be called by a super administrator. 366 * 367 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 368 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 369 * The admin must have the corresponding permission. 370 * @param { Array<UsbDeviceType> } usbDevices - list of USB device types. 371 * The size of the array after setting cannot be greater 1000. 372 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 373 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 374 * @throws { BusinessError } 9200010 - A conflict policy has been configured. 375 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 376 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 377 * 2. Incorrect parameter types; 3. Parameter verification failed. 378 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 379 * @stagemodelonly 380 * @since 14 381 */ 382 function addDisallowedUsbDevices(admin: Want, usbDevices: Array<UsbDeviceType>): void; 383 384 /** 385 * Removes disallowed USB devices by {@link UsbDeviceType} array. 386 * This function can be called by a super administrator. 387 * 388 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 389 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 390 * The admin must have the corresponding permission. 391 * @param { Array<UsbDeviceType> } usbDevices - list of USB device types. 392 * The size of the array after setting cannot be greater 1000. 393 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 394 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 395 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 396 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 397 * 2. Incorrect parameter types; 3. Parameter verification failed. 398 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 399 * @stagemodelonly 400 * @since 14 401 */ 402 function removeDisallowedUsbDevices(admin: Want, usbDevices: Array<UsbDeviceType>): void; 403 404 /** 405 * Gets the disallowed USB devices list. 406 * This function can be called by a super administrator. 407 * 408 * @permission ohos.permission.ENTERPRISE_MANAGE_USB 409 * @param { Want } admin - admin indicates the enterprise admin extension ability information. 410 * The admin must have the corresponding permission. 411 * @returns { Array<UsbDeviceType> } USB device types that are disallowed. 412 * @throws { BusinessError } 9200001 - The application is not an administrator application of the device. 413 * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device. 414 * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 415 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 416 * 2. Incorrect parameter types; 3. Parameter verification failed. 417 * @syscap SystemCapability.Customization.EnterpriseDeviceManager 418 * @stagemodelonly 419 * @since 14 420 */ 421 function getDisallowedUsbDevices(admin: Want): Array<UsbDeviceType>; 422} 423 424export default usbManager; 425