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