• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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 { NfcATag as _NfcATag,
17         NfcBTag as _NfcBTag,
18         NfcFTag as _NfcFTag,
19         NfcVTag as _NfcVTag } from './tag/nfctech';
20import { IsoDepTag as _IsoDepTag,
21         NdefTag as _NdefTag,
22         MifareClassicTag as _MifareClassicTag,
23         MifareUltralightTag as _MifareUltralightTag,
24         NdefFormatableTag as _NdefFormatableTag} from './tag/nfctech';
25import { NdefMessage as _NdefMessage } from './tag/nfctech';
26import { TagSession as _TagSession } from './tag/tagSession';
27import { PacMap } from "./ability/dataAbilityHelper";
28import rpc from "./@ohos.rpc";
29import { AsyncCallback, Callback } from './basic';
30import Want from './@ohos.app.ability.Want';
31
32/**
33 * Provides methods to operate or manage NFC tag.
34 *
35 * @since 7
36 * @syscap SystemCapability.Communication.NFC.Tag
37 */
38declare namespace tag {
39  /** Indicates an NFC-A tag. */
40  const NFC_A = 1;
41
42  /** Indicates an NFC-B tag. */
43  const NFC_B = 2;
44
45  /** Indicates an ISO-DEP tag. */
46  const ISO_DEP = 3;
47
48  /** Indicates an NFC-F tag. */
49  const NFC_F = 4;
50
51  /** Indicates an NFC-V tag. */
52  const NFC_V = 5;
53
54  /** Indicates an NDEF tag. */
55  const NDEF = 6;
56
57  /**
58   * Indicates an NDEF Formatable tag.
59   *
60   * @since 9
61   */
62  const NDEF_FORMATABLE = 7;
63
64  /** Indicates a MIFARE Classic tag. */
65  const MIFARE_CLASSIC = 8;
66
67  /** Indicates a MIFARE Ultralight tag. */
68  const MIFARE_ULTRALIGHT = 9;
69
70  /**
71   * TNF types definitions, see NFCForum-TS-NDEF_1.0.
72   *
73   * @since 9
74   * @syscap SystemCapability.Communication.NFC.Tag
75   */
76   enum TnfType {
77    /** Empty */
78    TNF_EMPTY = 0x0,
79
80    /** NFC Forum well-known type [NFC RTD] */
81    TNF_WELL_KNOWN = 0x1,
82
83    /** Media-type as defined in RFC 2046 [RFC 2046] */
84    TNF_MEDIA = 0x2,
85
86    /** Absolute URI as defined in RFC 3986 [RFC 3986] */
87    TNF_ABSOLUTE_URI = 0x3,
88
89    /** NFC Forum external type [NFC RTD] */
90    TNF_EXT_APP = 0x4,
91
92    /** Unknown */
93    TNF_UNKNOWN = 0x5,
94
95    /** Unchanged (see section 2.3.3) */
96    TNF_UNCHANGED = 0x6,
97  }
98
99  /**
100   * NfcForum Type definition. The NDEF tag may use one of them.
101   *
102   * @since 9
103   * @syscap SystemCapability.Communication.NFC.Tag
104   */
105  enum NfcForumType {
106    /** NFC FORUM TYPE 1 */
107    NFC_FORUM_TYPE_1 = 1,
108
109    /** NFC FORUM TYPE 2 */
110    NFC_FORUM_TYPE_2 = 2,
111
112    /** NFC FORUM TYPE 3 */
113    NFC_FORUM_TYPE_3 = 3,
114
115    /** NFC FORUM TYPE 4 */
116    NFC_FORUM_TYPE_4 = 4,
117
118    /** Mifare Classic */
119    MIFARE_CLASSIC = 101,
120  }
121
122  /**
123   * RTD type TEXT, see NFC Record Type Definition (RTD) Specification.
124   *
125   * @since 9
126   */
127  const RTD_TEXT: number[];
128
129  /**
130   * RTD type URI, see NFC Record Type Definition (RTD) Specification.
131   *
132   * @since 9
133   */
134  const RTD_URI: number[];
135
136  /**
137   * MifareClassic Type definition
138   *
139   * @since 9
140   * @syscap SystemCapability.Communication.NFC.Tag
141   */
142  enum MifareClassicType {
143    /** Mifare Type unknown */
144    TYPE_UNKNOWN = 0,
145
146    /** Mifare Classic */
147    TYPE_CLASSIC = 1,
148
149    /** Mifare Plus */
150    TYPE_PLUS = 2,
151
152    /** Mifare Pro */
153    TYPE_PRO = 3,
154  }
155
156  /**
157   * MifareClassic Tag size.
158   *
159   * @since 9
160   * @syscap SystemCapability.Communication.NFC.Tag
161   */
162  enum MifareClassicSize {
163    /** 5 sectors per tag, 4 blocks per sector */
164    MC_SIZE_MINI = 320,
165
166    /** 16 sectors per tag, 4 blocks per sector */
167    MC_SIZE_1K = 1024,
168
169    /** 32 sectors per tag, 4 blocks per sector */
170    MC_SIZE_2K = 2048,
171
172    /** 40 sectors per tag, 4 blocks per sector */
173    MC_SIZE_4K = 4096,
174  }
175
176  /**
177   * MifareUltralight Type definition
178   *
179   * @since 9
180   * @syscap SystemCapability.Communication.NFC.Tag
181   */
182  enum MifareUltralightType {
183    /** Mifare Type unknown */
184    TYPE_UNKNOWN = 0,
185
186    /** Mifare Ultralight */
187    TYPE_ULTRALIGHT = 1,
188
189    /** Mifare UltralightC */
190    TYPE_ULTRALIGHT_C = 2
191  }
192
193  /**
194   * Obtains an {@link NfcATag} object based on the tag information.
195   *
196   * <p>During tag reading, if the tag supports the NFC-A technology, an {@link NfcATag} object
197   * will be created based on the tag information.
198   *
199   * @param tagInfo Indicates the tag information.
200   * @since 7
201   * @deprecated since 9
202   * @useinstead ohos.nfc.tag/tag#getNfcA
203   */
204  function getNfcATag(tagInfo: TagInfo): NfcATag
205
206  /**
207   * Obtains an {@link NfcATag} object based on the tag information.
208   *
209   * During tag reading, if the tag supports the NFC-A technology, an {@link NfcATag} object
210   * will be created based on the tag information.
211   *
212   * @param { TagInfo } tagInfo - Indicates the dispatched tag information.
213   * @throws { BusinessError } 401 - The parameter check failed.
214   * @throws { BusinessError } 801 - Capability not supported.
215   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
216   * @syscap SystemCapability.Communication.NFC.Tag
217   * @since 9
218   */
219   function getNfcA(tagInfo: TagInfo): NfcATag
220
221  /**
222   * Obtains an {@link NfcBTag} object based on the tag information.
223   *
224   * <p>During tag reading, if the tag supports the NFC-B technology, an {@link NfcBTag} object
225   * will be created based on the tag information.
226   *
227   * @param tagInfo Indicates the tag information.
228   * @since 7
229   * @deprecated since 9
230   * @useinstead ohos.nfc.tag/tag#getNfcB
231   */
232  function getNfcBTag(tagInfo: TagInfo): NfcBTag
233
234  /**
235   * Obtains an {@link NfcBTag} object based on the tag information.
236   *
237   * During tag reading, if the tag supports the NFC-B technology, an {@link NfcBTag} object
238   * will be created based on the tag information.
239   *
240   * @param { TagInfo } tagInfo - Indicates the dispatched tag information.
241   * @throws { BusinessError } 401 - The parameter check failed.
242   * @throws { BusinessError } 801 - Capability not supported.
243   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
244   * @syscap SystemCapability.Communication.NFC.Tag
245   * @since 9
246   */
247   function getNfcB(tagInfo: TagInfo): NfcBTag
248
249  /**
250   * Obtains an {@link NfcFTag} object based on the tag information.
251   *
252   * <p>During tag reading, if the tag supports the NFC-F technology, an {@link NfcFTag} object
253   * will be created based on the tag information.
254   *
255   * @param tagInfo Indicates the tag information.
256   * @since 7
257   * @deprecated since 9
258   * @useinstead ohos.nfc.tag/tag#getNfcF
259   */
260  function getNfcFTag(tagInfo: TagInfo): NfcFTag
261
262  /**
263   * Obtains an {@link NfcFTag} object based on the tag information.
264   *
265   * During tag reading, if the tag supports the NFC-F technology, an {@link NfcFTag} object
266   * will be created based on the tag information.
267   *
268   * @param { TagInfo } tagInfo - Indicates the dispatched tag information.
269   * @throws { BusinessError } 401 - The parameter check failed.
270   * @throws { BusinessError } 801 - Capability not supported.
271   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
272   * @syscap SystemCapability.Communication.NFC.Tag
273   * @since 9
274   */
275   function getNfcF(tagInfo: TagInfo): NfcFTag
276
277  /**
278   * Obtains an {@link NfcVTag} object based on the tag information.
279   *
280   * <p>During tag reading, if the tag supports the NFC-V technology, an {@link NfcVTag} object
281   * will be created based on the tag information.
282   *
283   * @param tagInfo Indicates the tag information.
284   * @since 7
285   * @deprecated since 9
286   * @useinstead ohos.nfc.tag/tag#getNfcV
287   */
288  function getNfcVTag(tagInfo: TagInfo): NfcVTag
289
290  /**
291   * Obtains an {@link NfcVTag} object based on the tag information.
292   *
293   * During tag reading, if the tag supports the NFC-V technology, an {@link NfcVTag} object
294   * will be created based on the tag information.
295   *
296   * @param { TagInfo } tagInfo - Indicates the dispatched tag information.
297   * @throws { BusinessError } 401 - The parameter check failed.
298   * @throws { BusinessError } 801 - Capability not supported.
299   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
300   * @syscap SystemCapability.Communication.NFC.Tag
301   * @since 9
302   */
303   function getNfcV(tagInfo: TagInfo): NfcVTag
304
305  /**
306   * Obtains an {@link IsoDepTag} object based on the tag information.
307   *
308   * During tag reading, if the tag supports the IsoDep technology, an {@link IsoDepTag} object
309   * will be created based on the tag information.
310   *
311   * @param { TagInfo } tagInfo - Indicates the dispatched tag information.
312   * @throws { BusinessError } 401 - The parameter check failed.
313   * @throws { BusinessError } 801 - Capability not supported.
314   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
315   * @syscap SystemCapability.Communication.NFC.Tag
316   * @since 9
317   */
318  function getIsoDep(tagInfo: TagInfo): IsoDepTag
319
320  /**
321   * Obtains an {@link NdefTag} object based on the tag information.
322   *
323   * During tag reading, if the tag supports the NDEF technology, an {@link NdefTag} object
324   * will be created based on the tag information.
325   *
326   * @param { TagInfo } tagInfo - Indicates the dispatched tag information.
327   * @throws { BusinessError } 401 - The parameter check failed.
328   * @throws { BusinessError } 801 - Capability not supported.
329   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
330   * @syscap SystemCapability.Communication.NFC.Tag
331   * @since 9
332   */
333  function getNdef(tagInfo: TagInfo): NdefTag
334
335  /**
336   * Obtains an {@link MifareClassicTag} object based on the tag information.
337   *
338   * During tag reading, if the tag supports the MIFARE Classic technology,
339   * an {@link MifareClassicTag} object will be created based on the tag information.
340   *
341   * @param { TagInfo } tagInfo - Indicates the dispatched tag information.
342   * @throws { BusinessError } 401 - The parameter check failed.
343   * @throws { BusinessError } 801 - Capability not supported.
344   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
345   * @syscap SystemCapability.Communication.NFC.Tag
346   * @since 9
347   */
348  function getMifareClassic(tagInfo: TagInfo): MifareClassicTag
349
350   /**
351   * Obtains an {@link MifareUltralightTag} object based on the tag information.
352   *
353   * During tag reading, if the tag supports the MIFARE Ultralight technology,
354   * an {@link MifareUltralightTag} object will be created based on the tag information.
355   *
356   * @param { TagInfo } tagInfo - Indicates the dispatched tag information.
357   * @throws { BusinessError } 401 - The parameter check failed.
358   * @throws { BusinessError } 801 - Capability not supported.
359   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
360   * @syscap SystemCapability.Communication.NFC.Tag
361   * @since 9
362   */
363  function getMifareUltralight(tagInfo: TagInfo): MifareUltralightTag
364
365  /**
366   * Obtains an {@link NdefFormatableTag} object based on the tag information.
367   *
368   * During tag reading, if the tag supports the NDEF Formatable technology,
369   * an {@link NdefFormatableTag} object will be created based on the tag information.
370   *
371   * @param { TagInfo } tagInfo - Indicates the dispatched tag information.
372   * @throws { BusinessError } 401 - The parameter check failed.
373   * @throws { BusinessError } 801 - Capability not supported.
374   * @throws { BusinessError } 3100201 - Tag running state is abnormal in service.
375   * @syscap SystemCapability.Communication.NFC.Tag
376   * @since 9
377   */
378  function getNdefFormatable(tagInfo: TagInfo): NdefFormatableTag
379
380  /**
381   * Parse a {@link TagInfo} object from Want.
382   *
383   * @param { Want } want - The want object that contains the values of TagInfo.
384   * @throws { BusinessError } 401 - The parameter check failed.
385   * @throws { BusinessError } 801 - Capability not supported.
386   * @syscap SystemCapability.Communication.NFC.Tag
387   * @since 9
388   */
389  function getTagInfo(want: Want): TagInfo
390
391  /**
392   * Provides tag information.
393   *
394   * <p>This class provides the technology a tag supports, for example, NFC-A. Applications can create
395   * different tags based on the supported technology.
396   *
397   * @since 7
398   * @syscap SystemCapability.Communication.NFC.Tag
399   * @permission ohos.permission.NFC_TAG
400   */
401  export interface TagInfo {
402   /**
403    * The uid of this tag, it.
404    *
405    * @since 9
406    */
407    uid: number[];
408
409   /**
410    * The supported technology list of this tag.
411    *
412    * @since 9
413    */
414    technology: number[];
415
416   /**
417    * The extra data for each technology of this tag.
418    *
419    * @since 9
420    * @systemapi hide for inner use.
421    */
422    extrasData: PacMap[];
423
424   /**
425    * The the RF discovery id of this tag.
426    *
427    * @since 9
428    * @systemapi hide for inner use.
429    */
430    tagRfDiscId: number;
431
432   /**
433    * The extra data for the technology of this tag.
434    *
435    * @since 9
436    * @systemapi hide for inner use.
437    */
438    remoteTagService: rpc.RemoteObject;
439
440   /**
441    * The supported technology list of this tag.
442    *
443    * @since 7
444    * @deprecated since 9
445    * @useinstead ohos.nfc.tag/tag.TagInfo#technology
446    */
447    supportedProfiles: number[];
448  }
449
450  /**
451   * NDEF records definition, see NFCForum-TS-NDEF_1.0.
452   *
453   * @since 9
454   * @syscap SystemCapability.Communication.NFC.Tag
455   */
456  export interface NdefRecord {
457    /** tnf of NdefRecord */
458    tnf: number;
459
460    /** RTD type of NdefRecord */
461    rtdType: number[];
462
463    /** id of NdefRecord */
464    id: number[];
465
466    /** payload of NdefRecord */
467    payload: number[];
468  }
469
470  namespace ndef {
471  /**
472    * Creates an NDEF record with uri data.
473    *
474    * @param { string } uri - Uri data for new NDEF record.
475    * @returns { NdefRecord } The instance of NdefRecord.
476    * @throws { BusinessError } 401 - The parameter check failed.
477    * @syscap SystemCapability.Communication.NFC.Tag
478    * @since 9
479    */
480    function makeUriRecord(uri: string): NdefRecord;
481
482  /**
483    * Creates an NDEF record with text data.
484    *
485    * @param { string } text - Text data for new an NDEF record.
486    * @param { string } locale - Language code for the NDEF record. if locale is null, use default locale.
487    * @returns { NdefRecord } The instance of NdefRecord.
488    * @throws { BusinessError } 401 - The parameter check failed.
489    * @syscap SystemCapability.Communication.NFC.Tag
490    * @since 9
491    */
492    function makeTextRecord(text: string, locale: string): NdefRecord;
493
494  /**
495    * Creates an NDEF record with mime data.
496    *
497    * @param { string } mimeType type of mime data for new an NDEF record.
498    * @param { string } mimeData mime data for new an NDEF record.
499    * @returns { NdefRecord } The instance of NdefRecord.
500    * @throws { BusinessError } 401 - The parameter check failed.
501    * @syscap SystemCapability.Communication.NFC.Tag
502    * @since 9
503    */
504    function makeMimeRecord(mimeType: string, mimeData: number[]): NdefRecord;
505
506  /**
507    * Creates an NDEF record with external data.
508    *
509    * @param { string } domainName - Domain name of issuing organization for the external data.
510    * @param { string } type - Domain specific type of data for the external data.
511    * @param { number[] } externalData - Data payload of an NDEF record.
512    * @returns { NdefRecord } The instance of NdefRecord.
513    * @throws { BusinessError } 401 - The parameter check failed.
514    * @syscap SystemCapability.Communication.NFC.Tag
515    * @since 9
516    */
517    function makeExternalRecord(domainName: string, type: string, externalData: number[]): NdefRecord;
518  /**
519    * Creates an NDEF message with raw bytes.
520    *
521    * @param { number[] } data - The raw bytes to parse NDEF message.
522    * @returns { NdefMessage } The instance of NdefMessage.
523    * @throws { BusinessError } 401 - The parameter check failed.
524    * @syscap SystemCapability.Communication.NFC.Tag
525    * @since 9
526    */
527    function createNdefMessage(data: number[]): NdefMessage;
528
529  /**
530    * Creates an NDEF message with record list.
531    *
532    * @param { NdefRecord[] } ndefRecords - The NDEF records to parse NDEF message.
533    * @returns { NdefMessage } The instance of NdefMessage.
534    * @throws { BusinessError } 401 - The parameter check failed.
535    * @syscap SystemCapability.Communication.NFC.Tag
536    * @since 9
537    */
538    function createNdefMessage(ndefRecords: NdefRecord[]): NdefMessage;
539
540  /**
541    * Parses an NDEF message into raw bytes.
542    *
543    * @param { NdefMessage } ndefMessage - An NDEF message to parse.
544    * @returns { number[] } Returns the raw bytes of an NDEF message.
545    * @throws { BusinessError } 401 - The parameter check failed.
546    * @syscap SystemCapability.Communication.NFC.Tag
547    * @since 9
548    */
549    function messageToBytes(ndefMessage: NdefMessage): number[];
550  }
551
552  export type NfcATag = _NfcATag
553  export type NfcBTag = _NfcBTag
554  export type NfcFTag = _NfcFTag
555  export type NfcVTag = _NfcVTag
556  export type IsoDepTag = _IsoDepTag
557  export type NdefTag = _NdefTag
558  export type MifareClassicTag = _MifareClassicTag
559  export type MifareUltralightTag = _MifareUltralightTag
560  export type NdefFormatableTag = _NdefFormatableTag
561  export type NdefMessage = _NdefMessage
562  export type TagSession = _TagSession
563}
564export default tag;