• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2020-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 create 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     * @since 9
56     * The distance of dicovered device, in centimeters(cm).
57     */
58    range: number;
59  }
60
61  /**
62   * Device Type definitions
63   */
64  enum DeviceType {
65    /**
66     * Indicates an unknown device type.
67     */
68    UNKNOWN_TYPE = 0,
69
70    /**
71     * Indicates a speaker.
72     */
73    SPEAKER = 0x0A,
74
75    /**
76     * Indicates a smartphone.
77     */
78    PHONE = 0x0E,
79
80    /**
81     * Indicates a tablet.
82     */
83    TABLET = 0x11,
84
85    /**
86     * Indicates a smart watch.
87     */
88    WEARABLE = 0x6D,
89
90    /**
91     * Indicates a car.
92     */
93    CAR = 0x83,
94
95    /**
96     * Indicates a smart TV.
97     */
98    TV = 0x9C
99  }
100
101  /**
102   * Device state change event definition
103   *
104   * @systemapi this method can be used only by system applications.
105   */
106  enum DeviceStateChangeAction {
107    /**
108     * device online action
109     */
110    ONLINE = 0,
111
112    /**
113     * device ready action, the device information synchronization was completed.
114     */
115    READY = 1,
116
117    /**
118     * device offline action
119     */
120    OFFLINE = 2,
121
122    /**
123     * device change action
124     */
125    CHANGE = 3
126  }
127
128  /**
129   * Service subscribe info for device discover
130   *
131   * @systemapi this method can be used only by system applications.
132   */
133  interface SubscribeInfo {
134    /**
135     * Service subscribe ID, the value is in scope [0, 65535], should be unique for each discover process
136     */
137    subscribeId: number;
138
139    /**
140     * Discovery mode for service subscription.
141     */
142    mode: DiscoverMode;
143
144    /**
145     * Service subscription medium.
146     */
147    medium: ExchangeMedium;
148
149    /**
150     * Service subscription frequency.
151     */
152    freq: ExchangeFreq;
153
154    /**
155     * only find the device with the same account.
156     */
157    isSameAccount: boolean;
158
159    /**
160     * find the sleeping devices.
161     */
162    isWakeRemote: boolean;
163
164    /**
165     * Subscribe capability.
166     */
167    capability: SubscribeCap;
168  }
169
170  /**
171   * Service publish info for device discover
172   * @since 9
173   * @systemapi this method can be used only by system applications.
174   */
175  interface PublishInfo {
176    /**
177     * Service publish ID, the value is in scope [0, 65535], should be unique for each publish process
178     */
179    publishId: number;
180
181    /**
182     * Discovery mode for service subscription.
183     */
184    mode: DiscoverMode;
185
186    /**
187     * Service subscription frequency.
188     */
189    freq: ExchangeFreq;
190
191    /**
192     *  Whether the device should be ranged by discoverers.
193     */
194    ranging : boolean;
195  }
196
197  /**
198   * device discover mode
199   *
200   * @systemapi this method can be used only by system applications.
201   */
202  enum DiscoverMode {
203    /**
204     * when using this key at client side, it means discovering for available nearby devices by
205     * calling @startDeviceDiscovery function, while using this key at server side indicating that
206     * a device publication or advertisement by calling @publishDeviceDiscovery.
207     */
208    DISCOVER_MODE_PASSIVE = 0x55,
209
210    /**
211     * when using this key at server side, it means discovering for available nearby devices by
212     * calling @startDeviceDiscovery function, while using this key at client side indicating that
213     * a device publication or advertisement by calling @publishDeviceDiscovery.
214     */
215    DISCOVER_MODE_ACTIVE = 0xAA
216  }
217
218  /**
219   * device discover medium
220   *
221   * @systemapi this method can be used only by system applications.
222   */
223  enum ExchangeMedium {
224    /**
225     * Automatic medium selection
226     */
227    AUTO = 0,
228
229    /**
230     * Bluetooth
231     */
232    BLE = 1,
233
234    /**
235     * Wi-Fi
236     */
237    COAP = 2,
238
239    /**
240     * USB
241     */
242    USB = 3
243  }
244
245  /**
246   * device discover freq
247   *
248   * @systemapi this method can be used only by system applications.
249   */
250  enum ExchangeFreq {
251    /**
252     * Low
253     */
254    LOW = 0,
255
256    /**
257     * Medium
258     */
259    MID = 1,
260
261    /**
262     * High
263     */
264    HIGH = 2,
265
266    /**
267     * Super-high
268     */
269    SUPER_HIGH = 3
270  }
271
272  /**
273   * device discover capability
274   *
275   * @systemapi this method can be used only by system applications.
276   */
277  enum SubscribeCap {
278    /**
279     * ddmpCapability, will be discarded later. Currently, it will be converted to OSD capability inner.
280     */
281    SUBSCRIBE_CAPABILITY_DDMP = 0,
282
283    /**
284     * One Super Device Capability
285     */
286    SUBSCRIBE_CAPABILITY_OSD = 1
287  }
288
289  /**
290   * Device Authentication param
291   *
292   * @systemapi this method can be used only by system applications
293   */
294  interface AuthParam {
295    /**
296     * Authentication type, 1 for pin code.
297     */
298    authType: number;
299
300    /**
301     * Authentication extra infos.
302     */
303    extraInfo: {[key:string] : any};
304  }
305
306  /**
307   * Device auth info.
308   *
309   * @systemapi this method can be used only by system applications
310   */
311  interface AuthInfo {
312    /**
313     * Authentication type, 1 for pin code.
314     */
315    authType: number;
316
317    /**
318     * the token used for this authentication.
319     */
320    token: number;
321
322    /**
323     * Authentication extra infos.
324     */
325    extraInfo: {[key:string] : any};
326  }
327
328  /**
329   * Creates a {@code DeviceManager} instance.
330   *
331   * <p>To manage devices, you must first call this method to obtain a {@code DeviceManager} instance and then
332   * use this instance to call other device management methods.
333   *
334   * @param bundleName Indicates the bundle name of the application.
335   * @param callback Indicates the callback to be invoked upon {@code DeviceManager} instance creation.
336   * @systemapi this method can be used only by system applications.
337   */
338  function createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void;
339
340  /**
341   * Provides methods for managing devices.
342   */
343  interface DeviceManager {
344    /**
345     * Releases the {@code DeviceManager} instance after the methods for device management are no longer used.
346     *
347     * @systemapi this method can be used only by system applications.
348     */
349    release(): void;
350
351    /**
352     * Obtains a list of trusted devices.
353     *
354     * @return Returns a list of trusted devices.
355     * @systemapi this method can be used only by system applications.
356     */
357    getTrustedDeviceListSync(): Array<DeviceInfo>;
358
359    /**
360     * Obtains a list of trusted devices.
361     *
362     * @since 8
363     * @param callback Indicates the callback to be invoked upon getTrustedDeviceList
364     * @return Returns a list of trusted devices.
365     * @systemapi this method can be used only by system applications.
366     */
367    getTrustedDeviceList(callback:AsyncCallback<Array<DeviceInfo>>): void;
368
369    /**
370     * Obtains a list of trusted devices.
371     *
372     * @since 8
373     * @return Returns a list of trusted devices.
374     * @systemapi this method can be used only by system applications.
375     */
376    getTrustedDeviceList(): Promise<Array<DeviceInfo>>;
377
378    /**
379     * Obtains local device info
380     *
381     * @since 8
382     * @return Returns local device info.
383     * @systemapi this method can be used only by system applications.
384     */
385    getLocalDeviceInfoSync(): DeviceInfo;
386
387    /**
388     * Obtains local device info
389     *
390     * @since 8
391     * @param callback Indicates the callback to be invoked upon getLocalDeviceInfo
392     * @return Returns local device info.
393     * @systemapi this method can be used only by system applications.
394     */
395    getLocalDeviceInfo(callback:AsyncCallback<DeviceInfo>): void;
396
397    /**
398     * Obtains local device info
399     *
400     * @since 8
401     * @return Returns local device info.
402     * @systemapi this method can be used only by system applications.
403     */
404    getLocalDeviceInfo(): Promise<DeviceInfo>;
405
406    /**
407     * Start to discover device.
408     *
409     * @since 8
410     * @param subscribeInfo subscribe info to discovery device
411     * @systemapi this method can be used only by system applications.
412     */
413    startDeviceDiscovery(subscribeInfo: SubscribeInfo): void;
414
415    /**
416     * Start to discover device.
417     *
418     * @since 9
419     * @param subscribeInfo subscribe info to discovery device
420     * @param filterOptions filterOptions to filter discovery device
421     * @systemapi this method can be used only by system applications.
422     */
423    startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void;
424
425    /**
426     * Stop to discover device.
427     *
428     * @param subscribeId Service subscribe ID
429     * @systemapi this method can be used only by system applications.
430     */
431    stopDeviceDiscovery(subscribeId: number): void;
432
433    /**
434     * Publish discover device.
435     * @since 9
436     * @param publishInfo publish info to Publish discovery device
437     * @systemapi this method can be used only by system applications.
438     */
439    publishDeviceDiscovery(publishInfo: PublishInfo): void;
440
441    /**
442     * UnPublish discover device.
443     * @since 9
444     * @param publishId Service publish ID, identify a publish operation, should be a unique id in package range
445     * @systemapi this method can be used only by system applications.
446     */
447    unPublishDeviceDiscovery(publishId: number): void;
448
449    /**
450     * Authenticate the specified device.
451     *
452     * @param deviceInfo deviceInfo of device to authenticate
453     * @param authParam authParam of device to authenticate
454     * @param callback Indicates the callback to be invoked upon authenticateDevice
455     * @systemapi this method can be used only by system applications.
456     */
457    authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback<{deviceId: string, pinTone ?: number}>): void;
458
459    /**
460     * unAuthenticate the specified device.
461     *
462     * @since 8
463     * @param deviceInfo deviceInfo of device to unAuthenticate
464     * @systemapi this method can be used only by system applications.
465     */
466    unAuthenticateDevice(deviceInfo: DeviceInfo): void
467
468     /**
469     * verify auth info, such as pin code.
470     *
471     * @param authInfo device auth info o verify
472     * @param callback Indicates the callback to be invoked upon verifyAuthInfo
473     * @systemapi this method can be used only by system applications.
474     */
475    verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void;
476
477    /**
478     * Set user Operation from devicemanager ui, this interface can only be used by devicemanager ui.
479     *
480     * @since 9
481     * @param operateAction User Operation Actions.
482     *        operateAction = 0 - allow authentication
483     *        operateAction = 1 - cancel authentication
484     *        operateAction = 2 - user operation timeout for authentication confirm
485     *        operateAction = 3 - cancel pincode display
486     *        operateAction = 4 - cancel pincode input
487     *        operateAction = 5 - confirm pincode input
488     * @param params Indicates the input param of the user.
489     * @throws {BusinessError} 401 - Input parameter error.
490     * @systemapi this method can be used only by system applications.
491     */
492    setUserOperation(operateAction: number, params: string): void;
493
494    /**
495    * Register a callback from deviceManager service so that the devicemanager ui can be notified when ui statue
496    * changes.
497    *
498    * @since 9
499    * @param callback Indicates the devicemanager ui state to register.
500    * @throws {BusinessError} 401 - Input parameter error.
501    * @systemapi this method can be used only by system applications.
502    */
503    on(type: 'uiStateChange', callback: Callback<{ param: string}>): void;
504
505    /**
506     * Unregister uiStatueChange, this interface can only be used by devicemanager ui.
507     *
508     * @since 9
509     * @param callback Indicates the devicemanager ui state to unregister.
510     * @throws {BusinessError} 401 - Input parameter error.
511     * @systemapi this method can be used only by system applications.
512     */
513    off(type: 'uiStateChange', callback?: Callback<{ param: string}>): void;
514
515    /**
516     * Register a device state callback so that the application can be notified upon device state changes based on
517     * the application bundle name.
518     *
519     * @param bundleName Indicates the bundle name of the application.
520     * @param callback Indicates the device state callback to register.
521     * @systemapi this method can be used only by system applications.
522     */
523    on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
524
525    /**
526     * UnRegister device state callback based on the application bundle name.
527     *
528     * @param bundleName Indicates the bundle name of the application.
529     * @param callback Indicates the device state callback to register.
530     * @systemapi this method can be used only by system applications.
531     */
532    off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
533
534    /**
535     * Register a device found callback so that the application can be notified when the device was found
536     *
537     * @param callback Indicates the device found callback to register.
538     * @systemapi this method can be used only by system applications.
539     */
540    on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
541
542    /**
543     * UnRegister a device found callback so that the application can be notified when the device was found
544     *
545     * @param callback Indicates the device found callback to register.
546     * @systemapi this method can be used only by system applications.
547     */
548    off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
549
550    /**
551     * Register a device found result callback so that the application can be notified when the device discover was failed
552     *
553     * @param callback Indicates the device found result callback to register.
554     * @systemapi this method can be used only by system applications.
555     */
556    on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void;
557
558    /**
559     * UnRegister a device found result callback so that the application can be notified when the device discover was failed
560     *
561     * @param callback Indicates the device found result callback to register.
562     * @systemapi this method can be used only by system applications.
563     */
564    off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason: number }>): void;
565
566    /**
567     * Register a device publish result callback so that the application can be notified when the device publish success
568     *
569     * @since 9
570     * @param callback Indicates the device publish result callback to register.
571     * @systemapi this method can be used only by system applications.
572     */
573     on(type: 'publishSuccess', callback: Callback<{ publishId: number }>): void;
574
575    /**
576     * UnRegister a device publish result callback so that the application can be notified when the device publish was failed
577     *
578     * @since 9
579     * @param callback Indicates the device publish result callback to register.
580     * @systemapi this method can be used only by system applications.
581     */
582     off(type: 'publishSuccess', callback?: Callback<{ publishId: number }>): void;
583
584    /**
585     * Register a device publish result callback so that the application can be notified when the device publish was failed
586     *
587     * @since 9
588     * @param callback Indicates the device publish result callback to register.
589     * @systemapi this method can be used only by system applications.
590     */
591     on(type: 'publishFail', callback: Callback<{ publishId: number, reason: number }>): void;
592
593    /**
594     * UnRegister a device publish result callback so that the application can be notified when the device publish was failed
595     *
596     * @since 9
597     * @param callback Indicates the device publish result callback to register.
598     * @systemapi this method can be used only by system applications.
599     */
600     off(type: 'publishFail', callback?: Callback<{ publishId: number, reason: number }>): void;
601
602    /**
603     * Register a serviceError callback so that the application can be notified when devicemanager service died
604     *
605     * @param callback Indicates the service error callback to register.
606     * @systemapi this method can be used only by system applications.
607     */
608    on(type: 'serviceDie', callback: () => void): void;
609
610    /**
611     * UnRegister a serviceError callback so that the application can be notified when devicemanager service died
612     *
613     * @param callback Indicates the service error callback to register.
614     * @systemapi this method can be used only by system applications.
615     */
616    off(type: 'serviceDie', callback?: () => void): void;
617  }
618}
619
620export default deviceManager;
621