• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   * Set usb policy by {@link UsbPolicy}.
101   * This function can be called by a super administrator.
102   *
103   * @permission ohos.permission.ENTERPRISE_MANAGE_USB
104   * @param { Want } admin - admin indicates the enterprise admin extension ability information.
105   *                         The admin must have the corresponding permission.
106   * @param { UsbPolicy } usbPolicy - usb policy code.
107   * @param { AsyncCallback<void> } callback - the callback of setUsbPolicy.
108   * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.
109   * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device.
110   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
111   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
112   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
113   *                                 2. Incorrect parameter types; 3. Parameter verification failed.
114   * @syscap SystemCapability.Customization.EnterpriseDeviceManager
115   * @systemapi
116   * @stagemodelonly
117   * @since 10
118   */
119  function setUsbPolicy(admin: Want, usbPolicy: UsbPolicy, callback: AsyncCallback<void>): void;
120
121  /**
122   * Set usb policy by {@link UsbPolicy}.
123   * This function can be called by a super administrator.
124   *
125   * @permission ohos.permission.ENTERPRISE_MANAGE_USB
126   * @param { Want } admin - admin indicates the enterprise admin extension ability information.
127   *                         The admin must have the corresponding permission.
128   * @param { UsbPolicy } usbPolicy - usb policy code.
129   * @returns { Promise<void> } the promise returned setUsbPolicy.
130   * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.
131   * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device.
132   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
133   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
134   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
135   *                                 2. Incorrect parameter types; 3. Parameter verification failed.
136   * @syscap SystemCapability.Customization.EnterpriseDeviceManager
137   * @systemapi
138   * @stagemodelonly
139   * @since 10
140   */
141  function setUsbPolicy(admin: Want, usbPolicy: UsbPolicy): Promise<void>;
142
143  /**
144   * Disables USB.
145   * This function can be called by a super administrator.
146   *
147   * @permission ohos.permission.ENTERPRISE_MANAGE_USB
148   * @param { Want } admin - admin indicates the enterprise admin extension ability information.
149   *                         The admin must have the corresponding permission.
150   * @param { boolean } disable - true if disable USB, otherwise false.
151   * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.
152   * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device.
153   * @throws { BusinessError } 9200010 - A conflict policy has been configured.
154   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
155   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
156   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
157   *                                 2. Incorrect parameter types; 3. Parameter verification failed.
158   * @syscap SystemCapability.Customization.EnterpriseDeviceManager
159   * @systemapi
160   * @stagemodelonly
161   * @since 11
162   */
163  function disableUsb(admin: Want, disable: boolean): void;
164
165  /**
166   * Queries whether USB is disabled.
167   * This function can be called by a super administrator.
168   *
169   * @permission ohos.permission.ENTERPRISE_MANAGE_USB
170   * @param { Want } admin - admin indicates the enterprise admin extension ability information.
171   *                         If the admin is not empty, it must have the corresponding permission.
172   * @returns { boolean } true if USB is disabled, otherwise false.
173   * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.
174   * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device.
175   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
176   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
177   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
178   *                                 2. Incorrect parameter types; 3. Parameter verification failed.
179   * @syscap SystemCapability.Customization.EnterpriseDeviceManager
180   * @systemapi
181   * @stagemodelonly
182   * @since 11
183   */
184  function isUsbDisabled(admin: Want): boolean;
185
186  /**
187   * Adds the available USB device trust list by {@link UsbDeviceId} array.
188   * This function can be called by a super administrator.
189   *
190   * @permission ohos.permission.ENTERPRISE_MANAGE_USB
191   * @param { Want } admin - admin indicates the enterprise admin extension ability information.
192   *                         The admin must have the corresponding permission.
193   * @param { Array<UsbDeviceId> } usbDeviceIds - an array of added USB device ids.
194   *                                              The size of the array after setting cannot be greater 1000.
195   * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.
196   * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device.
197   * @throws { BusinessError } 9200010 - A conflict policy has been configured.
198   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
199   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
200   *                                 2. Incorrect parameter types; 3. Parameter verification failed.
201   * @syscap SystemCapability.Customization.EnterpriseDeviceManager
202   * @stagemodelonly
203   * @since 12
204   */
205  function addAllowedUsbDevices(admin: Want, usbDeviceIds: Array<UsbDeviceId>): void;
206
207  /**
208   * Removes the available USB device trust list by {@link UsbDeviceId} array.
209   * This function can be called by a super administrator.
210   *
211   * @permission ohos.permission.ENTERPRISE_MANAGE_USB
212   * @param { Want } admin - admin indicates the enterprise admin extension ability information.
213   *                         The admin must have the corresponding permission.
214   * @param { Array<UsbDeviceId> } usbDeviceIds - an array of removed USB device ids.
215   *                                              The size of the array after setting cannot be greater 1000.
216   * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.
217   * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device.
218   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
219   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
220   *                                 2. Incorrect parameter types; 3. Parameter verification failed.
221   * @syscap SystemCapability.Customization.EnterpriseDeviceManager
222   * @stagemodelonly
223   * @since 12
224   */
225  function removeAllowedUsbDevices(admin: Want, usbDeviceIds: Array<UsbDeviceId>): void;
226
227  /**
228   * Gets the available USB device trust list.
229   * This function can be called by a super administrator.
230   *
231   * @permission ohos.permission.ENTERPRISE_MANAGE_USB
232   * @param { Want } admin - admin indicates the enterprise admin extension ability information.
233   *                         The admin must have the corresponding permission.
234   * @returns { Array<UsbDeviceId> } an array of the available USB device trust list.
235   * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.
236   * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device.
237   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
238   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
239   *                                 2. Incorrect parameter types; 3. Parameter verification failed.
240   * @syscap SystemCapability.Customization.EnterpriseDeviceManager
241   * @stagemodelonly
242   * @since 12
243   */
244  function getAllowedUsbDevices(admin: Want): Array<UsbDeviceId>;
245
246  /**
247   * Sets USB storage device access policy by {@link UsbPolicy}.
248   * This function can be called by a super administrator.
249   *
250   * @permission ohos.permission.ENTERPRISE_MANAGE_USB
251   * @param { Want } admin - admin indicates the enterprise admin extension ability information.
252   *                         The admin must have the corresponding permission.
253   * @param { UsbPolicy } usbPolicy - USB policy of storage device.
254   * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.
255   * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device.
256   * @throws { BusinessError } 9200010 - A conflict policy has been configured.
257   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
258   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
259   *                                 2. Incorrect parameter types; 3. Parameter verification failed.
260   * @syscap SystemCapability.Customization.EnterpriseDeviceManager
261   * @stagemodelonly
262   * @since 12
263   */
264  function setUsbStorageDeviceAccessPolicy(admin: Want, usbPolicy: UsbPolicy): void;
265
266  /**
267   * Gets USB storage device access policy.
268   * This function can be called by a super administrator.
269   *
270   * @permission ohos.permission.ENTERPRISE_MANAGE_USB
271   * @param { Want } admin - admin indicates the enterprise admin extension ability information.
272   *                         The admin must have the corresponding permission.
273   * @returns { UsbPolicy } USB policy of storage device.
274   * @throws { BusinessError } 9200001 - The application is not an administrator application of the device.
275   * @throws { BusinessError } 9200002 - The administrator application does not have permission to manage the device.
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 getUsbStorageDeviceAccessPolicy(admin: Want): UsbPolicy;
284}
285
286export default usbManager;
287