• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2020 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
18declare namespace deviceManager {
19  /**
20   * DeviceInfo
21   */
22  interface DeviceInfo {
23    /**
24     * DeviceId ID.
25     */
26    deviceId: string;
27
28    /**
29     * Device name of the device.
30     */
31    deviceName: string;
32
33    /**
34     * Device type of the device.
35     */
36    deviceType: DeviceType;
37  }
38
39  /**
40   * Device Type definitions
41   */
42  enum DeviceType {
43    /**
44     * Indicates an unknown device type.
45     */
46    UNKNOWN_TYPE = 0,
47
48    /**
49     * Indicates a speaker.
50     */
51    SPEAKER = 0x0A,
52
53    /**
54     * Indicates a smartphone.
55     */
56    PHONE = 0x0E,
57
58    /**
59     * Indicates a tablet.
60     */
61    TABLET = 0x11,
62
63    /**
64     * Indicates a smart watch.
65     */
66    WEARABLE = 0x6D,
67
68    /**
69     * Indicates a car.
70     */
71    CAR = 0x83,
72
73    /**
74     * Indicates a smart TV.
75     */
76    TV = 0x9C
77  }
78
79  /**
80   * Device state change event definition
81   */
82  enum DeviceStateChangeAction {
83    /**
84     * device online action
85     */
86    ONLINE = 0,
87
88    /**
89     * device ready action, the device information synchronization was completed.
90     */
91    READY = 1,
92
93    /**
94     * device offline action
95     */
96    OFFLINE = 2,
97
98    /**
99     * device change action
100     */
101    CHANGE = 3
102  }
103
104  /**
105   * Service subscribe info for device discover
106   *
107   * @systemapi this method can be used only by system applications.
108   */
109  interface SubscribeInfo {
110    /**
111     * Service subscribe ID, the value is in scope [0, 65535], should be unique for each discover process
112     */
113    subscribeId: number;
114
115    /**
116     * Discovery mode for service subscription.
117     */
118    mode: DiscoverMode;
119
120    /**
121     * Service subscription medium.
122     */
123    medium: ExchangeMedium;
124
125    /**
126     * Service subscription frequency.
127     */
128    freq: ExchangeFreq;
129
130    /**
131     * only find the device with the same account.
132     */
133    isSameAccount: boolean;
134
135    /**
136     * find the sleeping devices.
137     */
138    isWakeRemote: boolean;
139
140    /**
141     * Subscribe capability.
142     */
143    capability: SubscribeCap;
144  }
145
146  /**
147   * device discover mode
148   *
149   * @systemapi this method can be used only by system applications.
150   */
151  enum DiscoverMode {
152    /**
153     * Passive
154     */
155    DISCOVER_MODE_PASSIVE = 0x55,
156
157    /**
158     * Proactive
159     */
160    DISCOVER_MODE_ACTIVE = 0xAA
161  }
162
163  /**
164   * device discover medium
165   *
166   * @systemapi this method can be used only by system applications.
167   */
168  enum ExchangeMedium {
169    /**
170     * Automatic medium selection
171     */
172    AUTO = 0,
173
174    /**
175     * Bluetooth
176     */
177    BLE = 1,
178
179    /**
180     * Wi-Fi
181     */
182    COAP = 2,
183
184    /**
185     * USB
186     */
187    USB = 3
188  }
189
190  /**
191   * device discover freq
192   *
193   * @systemapi this method can be used only by system applications.
194   */
195  enum ExchangeFreq {
196    /**
197     * Low
198     */
199    LOW = 0,
200
201    /**
202     * Medium
203     */
204    MID = 1,
205
206    /**
207     * High
208     */
209    HIGH = 2,
210
211    /**
212     * Super-high
213     */
214    SUPER_HIGH = 3
215  }
216
217  /**
218   * device discover capability
219   *
220   * @systemapi this method can be used only by system applications.
221   */
222  enum SubscribeCap {
223    /**
224     * ddmpCapability, will be discarded later. Currently, it will be converted to OSD capability inner.
225     */
226    SUBSCRIBE_CAPABILITY_DDMP = 0,
227
228    /**
229     * One Super Device Capability
230     */
231    SUBSCRIBE_CAPABILITY_OSD = 1
232  }
233
234  /**
235   * Device Authentication param
236   *
237   * @systemapi this method can be used only by system applications
238   */
239  interface AuthParam {
240    /**
241     * Authentication type, 1 for pin code.
242     */
243    authType: number;
244
245    /**
246     * App application Icon.
247     */
248    appIcon?: Uint8Array;
249
250    /**
251     * App application thumbnail.
252     */
253    appThumbnail?: Uint8Array;
254
255    /**
256     * Authentication extra infos.
257     */
258    extraInfo: {[key:string] : any};
259  }
260
261  /**
262   * Device auth info.
263   *
264   * @systemapi this method can be used only by system applications
265   */
266  interface AuthInfo {
267    /**
268     * Authentication type, 1 for pin code.
269     */
270    authType: number;
271
272    /**
273     * the token used for this authentication.
274     */
275    token: number;
276
277    /**
278     * Authentication extra infos.
279     */
280    extraInfo: {[key:string] : any};
281  }
282
283  /**
284   * Creates a {@code DeviceManager} instance.
285   *
286   * <p>To manage devices, you must first call this method to obtain a {@code DeviceManager} instance and then
287   * use this instance to call other device management methods.
288   *
289   * @param bundleName Indicates the bundle name of the application.
290   * @param callback Indicates the callback to be invoked upon {@code DeviceManager} instance creation.
291   */
292  function createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void;
293
294  /**
295   * Provides methods for managing devices.
296   */
297  interface DeviceManager {
298    /**
299     * Releases the {@code DeviceManager} instance after the methods for device management are no longer used.
300     */
301    release(): void;
302
303    /**
304     * Obtains a list of trusted devices.
305     *
306     * @param options Indicates the extra parameters to be passed to this method for device filtering or sorting.
307     * This parameter can be null. For details about available values, see {@link #TARGET_PACKAGE_NAME} and
308     * {@link #SORT_TYPE}.
309     * @return Returns a list of trusted devices.
310     */
311    getTrustedDeviceListSync(): Array<DeviceInfo>;
312
313    /**
314     * Start to discover device.
315     *
316     * @param subscribeInfo subscribe info to discovery device
317     * @systemapi this method can be used only by system applications.
318     */
319    startDeviceDiscovery(subscribeInfo: SubscribeInfo): void;
320
321    /**
322     * Stop to discover device.
323     *
324     * @param subscribeId Service subscribe ID
325     * @systemapi this method can be used only by system applications.
326     */
327    stopDeviceDiscovery(subscribeId: number): void;
328
329    /**
330     * Authenticate the specified device.
331     *
332     * @param deviceInfo deviceInfo of device to authenticate
333     * @param authparam authparam of device to authenticate
334     * @param callback Indicates the callback to be invoked upon authenticateDevice
335     * @systemapi this method can be used only by system applications.
336     */
337    authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback<{deviceId: string, pinTone ?: number}>): void;
338
339     /**
340     * verify auth info, such as pin code.
341     *
342     * @param authInfo device auth info o verify
343     * @param callback Indicates the callback to be invoked upon verifyAuthInfo
344     * @systemapi this method can be used only by system applications.
345     */
346    verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void;
347
348
349    /**
350     * Register a device state callback so that the application can be notified upon device state changes based on
351     * the application bundle name.
352     *
353     * @param bundleName Indicates the bundle name of the application.
354     * @param callback Indicates the device state callback to register.
355     */
356    on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
357
358    /**
359     * UnRegister device state callback based on the application bundle name.
360     *
361     * @param bundleName Indicates the bundle name of the application.
362     * @param callback Indicates the device state callback to register.
363     */
364    off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
365
366    /**
367     * Register a device found callback so that the application can be notified when the device was found
368     *
369     * @param callback Indicates the device found callback to register.
370     * @systemapi this method can be used only by system applications.
371     */
372    on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
373
374    /**
375     * UnRegister a device found callback so that the application can be notified when the device was found
376     *
377     * @param callback Indicates the device found callback to register.
378     * @systemapi this method can be used only by system applications.
379     */
380    off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
381
382    /**
383     * Register a device found result callback so that the application can be notified when the device discover was failed
384     *
385     * @param callback Indicates the device found result callback to register.
386     * @systemapi this method can be used only by system applications.
387     */
388    on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void;
389
390    /**
391     * UnRegister a device found result callback so that the application can be notified when the device discover was failed
392     *
393     * @param callback Indicates the device found result callback to register.
394     * @systemapi this method can be used only by system applications.
395     */
396    off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason: number }>): void;
397
398    /**
399     * Register a serviceError callback so that the application can be notified when devicemanager service died
400     *
401     * @param callback Indicates the service error callback to register.
402     */
403    on(type: 'serviceDie', callback: () => void): void;
404
405    /**
406     * UnRegister a serviceError callback so that the application can be notified when devicemanager service died
407     *
408     * @param callback Indicates the service error callback to register.
409     */
410    off(type: 'serviceDie', callback?: () => void): void;
411  }
412}
413
414export default deviceManager;
415