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