• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, Callback } from './basic';
17
18/**
19 * Providers interfaces to creat a {@link deviceManager} instances.
20 *
21 * @since 7
22 * @Syscap SystemCapability.DISTRIBUTEDHARDWARE.deviceManager
23 *
24 */
25declare namespace deviceManager {
26  /**
27   * DeviceInfo
28   *
29   * @systemapi this method can be used only by system applications.
30   */
31  interface DeviceInfo {
32    /**
33     * DeviceId ID.
34     */
35    deviceId: string;
36
37    /**
38     * Device name of the device.
39     */
40    deviceName: string;
41
42    /**
43     * Device type of the device.
44     */
45    deviceType: DeviceType;
46
47    /**
48     * NetworkId of the device.
49     *
50     * @since 8
51     */
52    networkId: string;
53  }
54
55  /**
56   * Device Type definitions
57   */
58  enum DeviceType {
59    /**
60     * Indicates an unknown device type.
61     */
62    UNKNOWN_TYPE = 0,
63
64    /**
65     * Indicates a speaker.
66     */
67    SPEAKER = 0x0A,
68
69    /**
70     * Indicates a smartphone.
71     */
72    PHONE = 0x0E,
73
74    /**
75     * Indicates a tablet.
76     */
77    TABLET = 0x11,
78
79    /**
80     * Indicates a smart watch.
81     */
82    WEARABLE = 0x6D,
83
84    /**
85     * Indicates a car.
86     */
87    CAR = 0x83,
88
89    /**
90     * Indicates a smart TV.
91     */
92    TV = 0x9C
93  }
94
95  /**
96   * Device state change event definition
97   *
98   * @systemapi this method can be used only by system applications.
99   */
100  enum DeviceStateChangeAction {
101    /**
102     * device online action
103     */
104    ONLINE = 0,
105
106    /**
107     * device ready action, the device information synchronization was completed.
108     */
109    READY = 1,
110
111    /**
112     * device offline action
113     */
114    OFFLINE = 2,
115
116    /**
117     * device change action
118     */
119    CHANGE = 3
120  }
121
122  /**
123   * Service subscribe info for device discover
124   *
125   * @systemapi this method can be used only by system applications.
126   */
127  interface SubscribeInfo {
128    /**
129     * Service subscribe ID, the value is in scope [0, 65535], should be unique for each discover process
130     */
131    subscribeId: number;
132
133    /**
134     * Discovery mode for service subscription.
135     */
136    mode: DiscoverMode;
137
138    /**
139     * Service subscription medium.
140     */
141    medium: ExchangeMedium;
142
143    /**
144     * Service subscription frequency.
145     */
146    freq: ExchangeFreq;
147
148    /**
149     * only find the device with the same account.
150     */
151    isSameAccount: boolean;
152
153    /**
154     * find the sleeping devices.
155     */
156    isWakeRemote: boolean;
157
158    /**
159     * Subscribe capability.
160     */
161    capability: SubscribeCap;
162  }
163
164  /**
165   * device discover mode
166   *
167   * @systemapi this method can be used only by system applications.
168   */
169  enum DiscoverMode {
170    /**
171     * Passive
172     */
173    DISCOVER_MODE_PASSIVE = 0x55,
174
175    /**
176     * Proactive
177     */
178    DISCOVER_MODE_ACTIVE = 0xAA
179  }
180
181  /**
182   * device discover medium
183   *
184   * @systemapi this method can be used only by system applications.
185   */
186  enum ExchangeMedium {
187    /**
188     * Automatic medium selection
189     */
190    AUTO = 0,
191
192    /**
193     * Bluetooth
194     */
195    BLE = 1,
196
197    /**
198     * Wi-Fi
199     */
200    COAP = 2,
201
202    /**
203     * USB
204     */
205    USB = 3
206  }
207
208  /**
209   * device discover freq
210   *
211   * @systemapi this method can be used only by system applications.
212   */
213  enum ExchangeFreq {
214    /**
215     * Low
216     */
217    LOW = 0,
218
219    /**
220     * Medium
221     */
222    MID = 1,
223
224    /**
225     * High
226     */
227    HIGH = 2,
228
229    /**
230     * Super-high
231     */
232    SUPER_HIGH = 3
233  }
234
235  /**
236   * device discover capability
237   *
238   * @systemapi this method can be used only by system applications.
239   */
240  enum SubscribeCap {
241    /**
242     * ddmpCapability, will be discarded later. Currently, it will be converted to OSD capability inner.
243     */
244    SUBSCRIBE_CAPABILITY_DDMP = 0,
245
246    /**
247     * One Super Device Capability
248     */
249    SUBSCRIBE_CAPABILITY_OSD = 1
250  }
251
252  /**
253   * Device Authentication param
254   *
255   * @systemapi this method can be used only by system applications
256   */
257  interface AuthParam {
258    /**
259     * Authentication type, 1 for pin code.
260     */
261    authType: number;
262
263    /**
264     * Authentication extra infos.
265     */
266    extraInfo: {[key:string] : any};
267  }
268
269  /**
270   * Device auth info.
271   *
272   * @systemapi this method can be used only by system applications
273   */
274  interface AuthInfo {
275    /**
276     * Authentication type, 1 for pin code.
277     */
278    authType: number;
279
280    /**
281     * the token used for this authentication.
282     */
283    token: number;
284
285    /**
286     * Authentication extra infos.
287     */
288    extraInfo: {[key:string] : any};
289  }
290
291  /**
292   * Creates a {@code DeviceManager} instance.
293   *
294   * <p>To manage devices, you must first call this method to obtain a {@code DeviceManager} instance and then
295   * use this instance to call other device management methods.
296   *
297   * @param bundleName Indicates the bundle name of the application.
298   * @param callback Indicates the callback to be invoked upon {@code DeviceManager} instance creation.
299   * @systemapi this method can be used only by system applications.
300   */
301  function createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void;
302
303  /**
304   * Provides methods for managing devices.
305   */
306  interface DeviceManager {
307    /**
308     * Releases the {@code DeviceManager} instance after the methods for device management are no longer used.
309     *
310     * @systemapi this method can be used only by system applications.
311     */
312    release(): void;
313
314    /**
315     * Obtains a list of trusted devices.
316     *
317     * @return Returns a list of trusted devices.
318     * @systemapi this method can be used only by system applications.
319     */
320    getTrustedDeviceListSync(): Array<DeviceInfo>;
321
322    /**
323     * Obtains a list of trusted devices.
324     *
325     * @since 8
326     * @param callback Indicates the callback to be invoked upon getTrustedDeviceList
327     * @return Returns a list of trusted devices.
328     * @systemapi this method can be used only by system applications.
329     */
330    getTrustedDeviceList(callback:AsyncCallback<Array<DeviceInfo>>): void;
331
332    /**
333     * Obtains a list of trusted devices.
334     *
335     * @since 8
336     * @return Returns a list of trusted devices.
337     * @systemapi this method can be used only by system applications.
338     */
339    getTrustedDeviceList(): Promise<Array<DeviceInfo>>;
340
341    /**
342     * Obtains local device info
343     *
344     * @since 8
345     * @return Returns local device info.
346     * @systemapi this method can be used only by system applications.
347     */
348    getLocalDeviceInfoSync(): DeviceInfo;
349
350    /**
351     * Obtains local device info
352     *
353     * @since 8
354     * @param callback Indicates the callback to be invoked upon getLocalDeviceInfo
355     * @return Returns local device info.
356     * @systemapi this method can be used only by system applications.
357     */
358    getLocalDeviceInfo(callback:AsyncCallback<DeviceInfo>): void;
359
360    /**
361     * Obtains local device info
362     *
363     * @since 8
364     * @return Returns local device info.
365     * @systemapi this method can be used only by system applications.
366     */
367    getLocalDeviceInfo(): Promise<DeviceInfo>;
368
369    /**
370     * Start to discover device.
371     *
372     * @param subscribeInfo subscribe info to discovery device
373     * @systemapi this method can be used only by system applications.
374     */
375    startDeviceDiscovery(subscribeInfo: SubscribeInfo): void;
376
377    /**
378     * Stop to discover device.
379     *
380     * @param subscribeId Service subscribe ID
381     * @systemapi this method can be used only by system applications.
382     */
383    stopDeviceDiscovery(subscribeId: number): void;
384
385    /**
386     * Authenticate the specified device.
387     *
388     * @param deviceInfo deviceInfo of device to authenticate
389     * @param authParam authParam of device to authenticate
390     * @param callback Indicates the callback to be invoked upon authenticateDevice
391     * @systemapi this method can be used only by system applications.
392     */
393    authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback<{deviceId: string, pinTone ?: number}>): void;
394
395    /**
396     * unAuthenticate the specified device.
397     *
398     * @since 8
399     * @param deviceInfo deviceInfo of device to unAuthenticate
400     * @systemapi this method can be used only by system applications.
401     */
402    unAuthenticateDevice(deviceInfo: DeviceInfo): void
403
404     /**
405     * verify auth info, such as pin code.
406     *
407     * @param authInfo device auth info o verify
408     * @param callback Indicates the callback to be invoked upon verifyAuthInfo
409     * @systemapi this method can be used only by system applications.
410     */
411    verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void;
412
413    /**
414     * Set user Operation from devicemanager ui, this interface can only be used by devicemanager ui.
415     *
416     * @since 9
417     * @param operateAction User Operation Actions.
418     *        operateAction = 0 - allow authentication
419     *        operateAction = 1 - cancel authentication
420     *        operateAction = 2 - user operation timeout for authentication confirm
421     *        operateAction = 3 - cancel pincode display
422     *        operateAction = 4 - cancel pincode input
423     *        operateAction = 5 - confirm pincode input
424     * @param params Indicates the input param of the user.
425     * @throws {BusinessError} 401 - Input parameter error.
426     * @systemapi this method can be used only by system applications.
427     */
428    setUserOperation(operateAction: number, params: string): void;
429
430    /**
431    * Register a callback from deviceManager service so that the devicemanager ui can be notified when ui statue
432    * changes.
433    *
434    * @since 9
435    * @param callback Indicates the devicemanager ui state to register.
436    * @throws {BusinessError} 401 - Input parameter error.
437    * @systemapi this method can be used only by system applications.
438    */
439    on(type: 'uiStateChange', callback: Callback<{ param: string}>): void;
440
441    /**
442     * Unregister uiStatueChange, this interface can only be used by devicemanager ui.
443     *
444     * @since 9
445     * @param callback Indicates the devicemanager ui state to unregister.
446     * @throws {BusinessError} 401 - Input parameter error.
447     * @systemapi this method can be used only by system applications.
448     */
449    off(type: 'uiStateChange', callback?: Callback<{ param: string}>): void;
450
451    /**
452     * Register a device state callback so that the application can be notified upon device state changes based on
453     * the application bundle name.
454     *
455     * @param bundleName Indicates the bundle name of the application.
456     * @param callback Indicates the device state callback to register.
457     * @systemapi this method can be used only by system applications.
458     */
459    on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
460
461    /**
462     * UnRegister device state callback based on the application bundle name.
463     *
464     * @param bundleName Indicates the bundle name of the application.
465     * @param callback Indicates the device state callback to register.
466     * @systemapi this method can be used only by system applications.
467     */
468    off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
469
470    /**
471     * Register a device found callback so that the application can be notified when the device was found
472     *
473     * @param callback Indicates the device found callback to register.
474     * @systemapi this method can be used only by system applications.
475     */
476    on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
477
478    /**
479     * UnRegister a device found callback so that the application can be notified when the device was found
480     *
481     * @param callback Indicates the device found callback to register.
482     * @systemapi this method can be used only by system applications.
483     */
484    off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
485
486    /**
487     * Register a device found result callback so that the application can be notified when the device discover was failed
488     *
489     * @param callback Indicates the device found result callback to register.
490     * @systemapi this method can be used only by system applications.
491     */
492    on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void;
493
494    /**
495     * UnRegister a device found result callback so that the application can be notified when the device discover was failed
496     *
497     * @param callback Indicates the device found result callback to register.
498     * @systemapi this method can be used only by system applications.
499     */
500    off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason: number }>): void;
501
502    /**
503     * Register a serviceError callback so that the application can be notified when devicemanager service died
504     *
505     * @param callback Indicates the service error callback to register.
506     * @systemapi this method can be used only by system applications.
507     */
508    on(type: 'serviceDie', callback: () => void): void;
509
510    /**
511     * UnRegister a serviceError callback so that the application can be notified when devicemanager service died
512     *
513     * @param callback Indicates the service error callback to register.
514     * @systemapi this method can be used only by system applications.
515     */
516    off(type: 'serviceDie', callback?: () => void): void;
517  }
518}
519
520export default deviceManager;
521