• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.secureElement (SE Management)
2
3The **secureElement** module provides APIs for managing secure elements (SEs). SEs include the Embedded SE (eSE) and SIM on a device. The SE service mentioned in this topic is an **SEService** instance. For details, see [newSEService](#secureelementnewseservice).
4
5The instances of the following types are mentioned in this topic:
6
7| Type   | Description                                          |
8| ------- | ---------------------------------------------- |
9| Reader  | SE supported by the device. If eSE and SIM are supported, two instances will be returned.|
10| Session | Session created on an SE **Reader** instance.|
11| Channel | Channel set up by a **Session** instance. The channel can be a basic channel or a logical channel.  |
12
13> **NOTE**
14>
15> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
16
17## **Modules to Import**
18
19```js
20import secureElement from '@ohos.secureElement';
21```
22
23## secureElement.ServiceState
24
25Enumerates the SE service stats.
26
27**System capability**: SystemCapability.Communication.SecureElement
28
29| Name        | Value  | Description              |
30| ------------ | ---- | ------------------ |
31| DISCONNECTED | 0    | The SE service is disconnected.|
32| CONNECTED    | 1    | The SE service is connected.|
33
34## secureElement.newSEService
35
36newSEService(type: 'serviceState', callback: Callback<[ServiceState](#secureelementservicestate)>): SEService
37
38Creates an **SEService** instance for connecting to all available SEs in the system. The connection is time-consuming. Therefore, this API supports only the asynchronous mode.
39
40The returned **SEService** instance is available only when **true** is returned by the specified callback or [isConnected](#seserviceisconnected).
41
42**System capability**: SystemCapability.Communication.SecureElement
43
44**Parameters**
45
46| **Name**| **Type**                                            | **Mandatory**| **Description**            |
47| ---------- | ---------------------------------------------------- | ------ | -------------------- |
48| type       | string                                               | Yes     | Type of the SE service to create. It has a fixed value of **'serviceState'**.     |
49| callback   | Callback<[ServiceState](#secureelementservicestate)> | Yes     | Callback invoked to return the SE service state.|
50
51**Return value**
52
53| **Type** | **Description**  |
54| :-------- | :--------- |
55| SEService | **SEService** instance created.|
56
57**Example**
58
59```js
60import secureElement from '@ohos.secureElement';
61import { BusinessError } from '@ohos.base';
62
63try {
64    let nfcSEService = secureElement.newSEService("serviceState", (state) => {
65        if (state == secureElement.ServiceState.DISCONNECTED) {
66            console.log("Service state is Disconnected");
67        } else {
68            console.log("Service state is Connected");
69        }
70    });
71} catch (e) {
72    console.error("newSEService occurs " + "exception: ${(e : BusinessError).message}");
73}
74```
75
76## SEService.getReaders
77
78getReaders(): Reader[]
79
80Obtains available SE readers, which include all the SEs on the device.
81
82**System capability**: SystemCapability.Communication.SecureElement
83
84**Return value**
85
86| **Type**| **Description**              |
87| :------- | :--------------------- |
88| Reader[] | Available readers obtained.|
89
90**Example**
91
92```js
93import omapi from '@ohos.secureElement';
94import secureElement from '@ohos.secureElement';
95import { BusinessError } from '@ohos.base';
96
97let nfcSEService : omapi.SEService | null = null;
98let nfcOmaReaderList : omapi.Reader[] | null = null;
99
100try {
101    nfcSEService = secureElement.newSEService("serviceState", (state) => {
102        if (state == secureElement.ServiceState.DISCONNECTED) {
103            console.log("Service state is Disconnected");
104        } else {
105            console.log("Service state is Connected");
106        }
107    });
108} catch (e) {
109    console.error("newSEService " + "excpetion: ${(e : BusinessError).message}");
110}
111
112try {
113    if (nfcSEService != null) {
114        nfcOmaReaderList = nfcSEService.getReaders();
115    }
116    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
117        console.log("get reader successfully");
118    } else {
119        console.error("get reader failed");
120    }
121} catch (e) {
122    console.error("getReaders " + "exception: ${(e : BusinessError).message}");
123}
124```
125
126## SEService.isConnected
127
128isConnected(): boolean
129
130Checks whether this SE service is connected.
131
132**System capability**: SystemCapability.Communication.SecureElement
133
134**Return value**
135
136| **Type**| **Description**                                      |
137| :------- | :--------------------------------------------- |
138| boolean  | Returns **true** if the SE service is connected; returns **false** otherwise.|
139
140**Example**
141
142```JS
143import omapi from '@ohos.secureElement';
144import secureElement from '@ohos.secureElement';
145import { BusinessError } from '@ohos.base';
146
147let nfcSEService : omapi.SEService | null = null;
148
149try {
150    nfcSEService = secureElement.newSEService("serviceState", (state) => {
151        if (state == secureElement.ServiceState.DISCONNECTED) {
152            console.log("Service state is Disconnected");
153        } else {
154            console.log("Service state is Connected");
155        }
156    });
157} catch (e) {
158    console.error("newSEService" + "exception: ${(e : BusinessError).message}");
159}
160
161try {
162    let ret: boolean = false;
163    // Refer to newSEService for this.nfcSEService.
164    if (nfcSEService != null) {
165        ret = nfcSEService.isConnected();
166    }
167    if (ret) {
168        console.log("get state: connected");
169    } else {
170        console.log("get state: not connected");
171    }
172} catch (e) {
173    console.error("isConnected " + "exception: ${(e : BusinessError).message}");
174}
175```
176
177## SEService.shutdown
178
179shutdown(): void
180
181Releases all SE resources allocated to this SE service. After that, [isConnected](#seserviceisconnected) returns **false**.
182
183**System capability**: SystemCapability.Communication.SecureElement
184
185**Example**
186
187```js
188import omapi from '@ohos.secureElement';
189import secureElement from '@ohos.secureElement';
190import { BusinessError } from '@ohos.base';
191
192let nfcSEService : omapi.SEService | null = null;
193
194try {
195    nfcSEService = secureElement.newSEService("serviceState", (state) => {
196        if (state == secureElement.ServiceState.DISCONNECTED) {
197            console.log("Service state is Disconnected");
198        } else {
199            console.log("Service state is Connected");
200        }
201    });
202} catch (e) {
203    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
204}
205
206try {
207    // Refer to newSEService for this.nfcSEService.
208    if (nfcSEService != null) {
209        nfcSEService.shutdown();
210    }
211    console.log("shutdown successfully");
212} catch (e) {
213    console.error("shutdown exception:" + "exception: ${(e : BusinessError).message}");
214}
215```
216
217## SEService.getVersion
218
219getVersion(): string
220
221Obtains the version of the Open Mobile API (OMAPI) specification used.
222
223**System capability**: SystemCapability.Communication.SecureElement
224
225**Return value**
226
227| **Type**| **Description**                                          |
228| -------- | -------------------------------------------------- |
229| string   | OMAPI version obtained. For example, **3.3** indicates Open Mobile API Specification v3.3.|
230
231**Example**
232
233```JS
234import omapi from '@ohos.secureElement';
235import secureElement from '@ohos.secureElement';
236import { BusinessError } from '@ohos.base';
237
238let nfcSEService : omapi.SEService | null = null;
239
240try {
241    nfcSEService = secureElement.newSEService("serviceState", (state) => {
242        if (state == secureElement.ServiceState.DISCONNECTED) {
243            console.log("Service state is Disconnected");
244        } else {
245            console.log("Service state is Connected");
246        }
247    });
248} catch (e) {
249    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
250}
251
252try {
253    // Refer to newSEService for this.nfcSEService.
254    if (nfcSEService != null) {
255        console.log("version: " + nfcSEService.getVersion());
256    }
257} catch (e) {
258    console.error("getVersion " + "exception: ${(e : BusinessError).message}");
259}
260```
261
262## Reader.getName
263
264getName(): string
265
266Obtains the name of this reader. The name is **SIM[*Slot*]** for a SIM reader and **eSE** for an eSE.
267
268**System capability**: SystemCapability.Communication.SecureElement
269
270**Return value**
271
272| **Type**| **Description**  |
273| -------- | ---------- |
274| string   | Reader name obtained.|
275
276**Example**
277
278```js
279import omapi from '@ohos.secureElement';
280import secureElement from '@ohos.secureElement';
281import { BusinessError } from '@ohos.base';
282
283let nfcSEService : omapi.SEService | null = null;
284let nfcOmaReaderList : omapi.Reader[] | null = null;
285
286try {
287    nfcSEService = secureElement.newSEService("serviceState", (state) => {
288        if (state == secureElement.ServiceState.DISCONNECTED) {
289            console.log("Service state is Disconnected");
290        } else {
291            console.log("Service state is Connected");
292        }
293    });
294} catch (e) {
295    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
296}
297
298try {
299    if (nfcSEService != null) {
300        nfcOmaReaderList = nfcSEService.getReaders();
301    }
302    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
303        console.log(nfcOmaReaderList[0].getName());
304    } else {
305        console.error("getName failed");
306    }
307} catch (e) {
308    console.error("getName " + "exception: ${(e : BusinessError).message}");
309}
310```
311
312## Reader.isSecureElementPresent
313
314isSecureElementPresent(): boolean
315
316Checks whether the SE corresponding to this reader is available.
317
318**System capability**: SystemCapability.Communication.SecureElement
319
320**Return value**
321
322| **Type**| **Description**                                    |
323| -------- | -------------------------------------------- |
324| boolean  | Returns **true** if the SE is available; returns **false** otherwise.|
325
326**Error codes**
327
328For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
329
330| ID| Error Message                        |
331| -------- | -------------------------------- |
332| 3300101  | IllegalStateError, service state exception. |
333
334**Example**
335
336```js
337
338import omapi from '@ohos.secureElement';
339import secureElement from '@ohos.secureElement';
340import { BusinessError } from '@ohos.base';
341
342let nfcSEService : omapi.SEService | null = null;
343let nfcOmaReaderList : omapi.Reader[] | null = null;
344
345try {
346    nfcSEService = secureElement.newSEService("serviceState", (state) => {
347        if (state == secureElement.ServiceState.DISCONNECTED) {
348            console.log("Service state is Disconnected");
349        } else {
350            console.log("Service state is Connected");
351        }
352    });
353} catch (e) {
354    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
355}
356
357try {
358    if (nfcSEService != null) {
359        nfcOmaReaderList = nfcSEService.getReaders();
360    }
361    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
362        if (nfcOmaReaderList[0].isSecureElementPresent()) {
363            console.log("isSecureElementPresent success");
364        } else {
365            console.log("isSecureElementPresent failed");
366        }
367    } else {
368        console.error("isSecureElementPresent failed");
369    }
370} catch (e) {
371    console.error("isSecureElementPresent " + "exception: ${(e : BusinessError).message}");
372}
373```
374
375## Reader.openSession
376
377 openSession(): Session
378
379Opens a session to connect to an SE in this reader. Multiple sessions can be opened on a reader at the same time.
380
381**System capability**: SystemCapability.Communication.SecureElement
382
383**Return value**
384
385| **Type**| **Description**                      |
386| -------- | ------------------------------ |
387| Session  | Session instance opened.|
388
389**Error codes**
390
391For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
392
393| ID| Error Message                        |
394| -------- | -------------------------------- |
395| 3300101  | IllegalStateError, service state exception. |
396| 3300104  | IOError, there is a communication problem to the reader or the SE.     |
397
398**Example**
399
400```js
401import omapi from '@ohos.secureElement';
402import secureElement from '@ohos.secureElement';
403import { BusinessError } from '@ohos.base';
404
405let nfcSEService : omapi.SEService | null = null;
406let nfcOmaReaderList : omapi.Reader[] | null = null;
407
408try {
409    nfcSEService = secureElement.newSEService("serviceState", (state) => {
410        if (state == secureElement.ServiceState.DISCONNECTED) {
411            console.log("Service state is Disconnected");
412        } else {
413            console.log("Service state is Connected");
414        }
415    });
416} catch (e) {
417    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
418}
419
420try {
421    if (nfcSEService != null) {
422        nfcOmaReaderList = nfcSEService.getReaders();
423    }
424    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
425        if (nfcOmaReaderList[0].openSession()) {
426            console.log("get session successfully");
427        } else {
428            console.log("get session failed");
429        }
430    } else {
431        console.error("OpenSession failed");
432    }
433} catch (e) {
434    console.error("OpenSession " + "exception: ${(e : BusinessError).message}");
435}
436```
437
438## Reader.closeSessions
439
440 closeSessions(): void
441
442Closes all sessions opened on this reader. All channels opened by these sessions will be closed.
443
444**System capability**: SystemCapability.Communication.SecureElement
445
446**Error codes**
447
448For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
449
450| ID| Error Message                        |
451| -------- | -------------------------------- |
452| 3300101  | IllegalStateError, service state exception. |
453
454**Example**
455
456```js
457import omapi from '@ohos.secureElement';
458import secureElement from '@ohos.secureElement';
459import { BusinessError } from '@ohos.base';
460
461let nfcSEService : omapi.SEService | null = null;
462let nfcOmaReaderList : omapi.Reader[] | null = null;
463
464try {
465    nfcSEService = secureElement.newSEService("serviceState", (state) => {
466        if (state == secureElement.ServiceState.DISCONNECTED) {
467            console.log("Service state is Disconnected");
468        } else {
469            console.log("Service state is Connected");
470        }
471    });
472} catch (e) {
473    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
474}
475
476try {
477    if (nfcSEService != null) {
478        nfcOmaReaderList = nfcSEService.getReaders();
479    }
480    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
481        nfcOmaReaderList[0].closeSessions();
482        console.log("closeSessions successfully");
483    } else {
484        console.error("closeSessions failed");
485    }
486} catch (e) {
487    console.error("closeSessions " + "exception: ${(e : BusinessError).message}");
488}
489```
490
491## Session.getReader
492
493getReader(): Reader
494
495Obtains the reader that provides this session.
496
497**System capability**: SystemCapability.Communication.SecureElement
498
499**Return value**
500
501| **Type**| **Description**                   |
502| -------- | --------------------------- |
503| Reader   | Reader instance obtained.|
504
505**Example**
506
507```js
508import omapi from '@ohos.secureElement';
509import secureElement from '@ohos.secureElement';
510import { BusinessError } from '@ohos.base';
511
512let nfcSEService : omapi.SEService | null = null;
513let nfcOmaReaderList : omapi.Reader[] | null = null;
514let omaSession : omapi.Session | null = null;
515
516try {
517    nfcSEService = secureElement.newSEService("serviceState", (state) => {
518        if (state == secureElement.ServiceState.DISCONNECTED) {
519            console.log("Service state is Disconnected");
520        } else {
521            console.log("Service state is Connected");
522        }
523    });
524} catch (e) {
525    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
526}
527
528try {
529    if (nfcSEService != null) {
530        nfcOmaReaderList = nfcSEService.getReaders();
531    }
532    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
533        omaSession = nfcOmaReaderList[0].openSession();
534        if (omaSession.getReader() != null) {
535            console.log("get reader successfully");
536        } else {
537            console.error("get reader failed");
538        }
539    } else {
540        console.error("getReader failed");
541    }
542} catch (e) {
543    console.error("getReader " + "exception: ${(e : BusinessError).message}");
544}
545```
546
547## Session.getATR
548
549getATR(): number[]
550
551Obtains the Answer to Reset (ATR) of this SE. If the ATR of this SE is not available, an empty array will be returned.
552
553**System capability**: SystemCapability.Communication.SecureElement
554
555**Return value**
556
557| **Type**| **Description**                                    |
558| -------- | -------------------------------------------- |
559| number[] | Returns the ATR obtained if the SE has an available ATR; returns an empty array otherwise.|
560
561**Error codes**
562
563For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
564
565| ID| Error Message                        |
566| -------- | -------------------------------- |
567| 3300101  | IllegalStateError, service state exception. |
568
569**Example**
570
571```js
572import omapi from '@ohos.secureElement';
573import secureElement from '@ohos.secureElement';
574import { BusinessError } from '@ohos.base';
575
576let nfcSEService : omapi.SEService | null = null;
577let nfcOmaReaderList : omapi.Reader[] | null = null;
578let omaSession : omapi.Session | null = null;
579let omaATR : number[] | null = null;
580let str : string = "";
581
582try {
583    nfcSEService = secureElement.newSEService("serviceState", (state) => {
584        if (state == secureElement.ServiceState.DISCONNECTED) {
585            console.log("Service state is Disconnected");
586        } else {
587            console.log("Service state is Connected");
588        }
589    });
590} catch (e) {
591    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
592}
593
594try {
595    if (nfcSEService != null) {
596        nfcOmaReaderList = nfcSEService.getReaders();
597    }
598    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
599        omaSession = nfcOmaReaderList[0].openSession();
600        if (omaSession != null) {
601            omaATR = omaSession.getATR();
602        } else {
603            console.error("getATR failed");
604        }
605    }
606    if (omaATR != null && omaATR.length > 0) {
607        str = 'getATR result:[';
608        for (let i = 0; i < omaATR.length; ++i) {
609            str += omaATR[i];
610            str += ' ';
611        }
612        str += ']';
613        console.log(str);
614    } else {
615        console.error("getATR failed");
616    }
617} catch (e) {
618    console.error("getATR " + "exception: ${(e : BusinessError).message}");
619}
620```
621
622## Session.close
623
624close(): void
625
626Closes the session with the SE. All channels opened by this session will be closed.
627
628**System capability**: SystemCapability.Communication.SecureElement
629
630**Error codes**
631
632For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
633
634| ID| Error Message                        |
635| -------- | -------------------------------- |
636| 3300101  | IllegalStateError, service state exception. |
637
638**Example**
639
640```js
641import omapi from '@ohos.secureElement';
642import secureElement from '@ohos.secureElement';
643import { BusinessError } from '@ohos.base';
644
645let nfcSEService : omapi.SEService | null = null;
646let nfcOmaReaderList : omapi.Reader[] | null = null;
647let omaSession : omapi.Session | null = null;
648
649try {
650    nfcSEService = secureElement.newSEService("serviceState", (state) => {
651        if (state == secureElement.ServiceState.DISCONNECTED) {
652            console.log("Service state is Disconnected");
653        } else {
654            console.log("Service state is Connected");
655        }
656    });
657} catch (e) {
658    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
659}
660
661try {
662    if (nfcSEService != null) {
663        nfcOmaReaderList = nfcSEService.getReaders();
664    }
665    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
666        omaSession = nfcOmaReaderList[0].openSession();
667        if (omaSession != null) {
668            omaSession.close();
669        } else {
670            console.error("close failed");
671        }
672    }
673} catch (e) {
674    console.error("close " + "exception: ${(e : BusinessError).message}");
675}
676
677```
678
679## Session. isClosed
680
681isClosed(): boolean
682
683Checks whether this session is closed.
684
685**System capability**: SystemCapability.Communication.SecureElement
686
687**Return value**
688
689| **Type**| **Description**                            |
690| -------- | ------------------------------------ |
691| boolean  | Returns **true** if the session is closed; returns **false** otherwise.|
692
693**Error codes**
694
695For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
696
697**Example**
698
699```Js
700import omapi from '@ohos.secureElement';
701import secureElement from '@ohos.secureElement';
702import { BusinessError } from '@ohos.base';
703
704let nfcSEService : omapi.SEService | null = null;
705let nfcOmaReaderList : omapi.Reader[] | null = null;
706let omaSession : omapi.Session | null = null;
707
708try {
709    nfcSEService = secureElement.newSEService("serviceState", (state) => {
710        if (state == secureElement.ServiceState.DISCONNECTED) {
711            console.log("Service state is Disconnected");
712        } else {
713            console.log("Service state is Connected");
714        }
715    });
716} catch (e) {
717    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
718}
719
720try {
721    if (nfcSEService != null) {
722      nfcOmaReaderList = nfcSEService.getReaders();
723    }
724    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
725        omaSession = nfcOmaReaderList[0].openSession();
726        if (omaSession != null) {
727            console.log("openSession success");
728            if (omaSession.isClosed()) {
729                console.log("session is closed");
730            }
731        } else {
732            console.error("openSession failed");
733        }
734    }
735} catch (e) {
736    console.error("isClosed " + "exception: ${(e : BusinessError).message}");
737}
738```
739
740## Session.closeChannels
741
742closeChannels(): void
743
744Closes all channels opened on this session.
745
746**System capability**: SystemCapability.Communication.SecureElement
747
748**Error codes**
749
750For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
751
752| ID| Error Message                        |
753| -------- | -------------------------------- |
754| 3300101  | IllegalStateError, service state exception. |
755
756**Example**
757
758```js
759import omapi from '@ohos.secureElement';
760import secureElement from '@ohos.secureElement';
761import { BusinessError } from '@ohos.base';
762
763let nfcSEService : omapi.SEService | null = null;
764let nfcOmaReaderList : omapi.Reader[] | null = null;
765let omaSession : omapi.Session | null = null;
766
767try {
768    nfcSEService = secureElement.newSEService("serviceState", (state) => {
769        if (state == secureElement.ServiceState.DISCONNECTED) {
770            console.log("Service state is Disconnected");
771        } else {
772            console.log("Service state is Connected");
773        }
774    });
775} catch (e) {
776    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
777}
778
779try {
780    if (nfcSEService != null) {
781      nfcOmaReaderList = nfcSEService.getReaders();
782    }
783    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
784        omaSession = nfcOmaReaderList[0].openSession();
785        if (omaSession != null) {
786            omaSession.closeChannels();
787            console.log("closeChannels success");
788        } else {
789            console.error("closeChannels failed");
790        }
791    }
792} catch (e) {
793    console.error("closeChannels " + "exception: ${(e : BusinessError).message}");
794}
795```
796
797## Session.openBasicChannel
798
799openBasicChannel(aid: number[]): Promise\<Channel>
800
801Opens a basic channel, as defined in ISO/IEC 7816-4. This API uses a promise to return the result. If the SE cannot provide the basic channel or the application does not have the permission to access the SE, null is returned.
802
803**System capability**: SystemCapability.Communication.SecureElement
804
805**Parameters**
806
807| **Name**| **Type**| **Mandatory**| **Description**                                                    |
808| ---------- | -------- | ------ | ------------------------------------------------------------ |
809| aid        | number[] | Yes     |AID of the Applet to be selected on this channel as a byte array, or an empty array if no Applet is to be selected.|
810
811**Return value**
812
813| **Type**| **Description**             |
814| -------- | --------------------- |
815| Channel  | Promise used to return the basic channel instance obtained.|
816
817**Error codes**
818
819For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
820
821| ID| Error Message                        |
822| -------- | -------------------------------- |
823| 3300101  | IllegalStateError, an attempt is made to use an SE session that has been closed. |
824| 3300102  | NoSuchElementError, the AID on the SE is not available or cannot be selected.       |
825| 3300103  | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session.   |
826| 3300104  | IOError, there is a communication problem to the reader or the SE.     |
827
828**Example**
829
830```js
831import omapi from '@ohos.secureElement';
832import secureElement from '@ohos.secureElement';
833import { BusinessError } from '@ohos.base';
834
835let nfcSEService : omapi.SEService | null = null;
836let nfcOmaReaderList : omapi.Reader[] | null = null;
837let omaSession : omapi.Session | null = null;
838let aidArray : number[] = [720, 1080];
839let getPromise : Promise<omapi.Channel> | null = null;
840
841try {
842    nfcSEService = secureElement.newSEService("serviceState", (state) => {
843        if (state == secureElement.ServiceState.DISCONNECTED) {
844            console.log("Service state is Disconnected");
845        } else {
846            console.log("Service state is Connected");
847        }
848    });
849} catch (e) {
850    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
851}
852
853try {
854    if (nfcSEService != null) {
855      nfcOmaReaderList = nfcSEService.getReaders();
856    }
857    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
858        omaSession = nfcOmaReaderList[0].openSession();
859        if (omaSession != null) {
860            getPromise = omaSession.openBasicChannel(aidArray);
861        } else {
862            console.error("openBasicChannel1 failed");
863        }
864    }
865    if (getPromise != null) {
866        console.log("openBasicChannel1 get channel successfully");
867    }
868} catch (e) {
869    console.error("openBasicChannel1 " + "exception: ${(e : BusinessError).message}");
870}
871```
872
873## Session.openBasicChannel
874
875 openBasicChannel(aid: number[], callback: AsyncCallback\<Channel>): void
876
877Opens a basic channel, as defined in ISO/IEC 7816-4. This API uses an asynchronous callback to return the result. If the SE cannot provide the basic channel or the application does not have the permission to access the SE, null is returned.
878
879**System capability**: SystemCapability.Communication.SecureElement
880
881**Parameters**
882
883| **Name**| **Type**              | **Mandatory**| **Description**                                                    |
884| ---------- | ---------------------- | ------ | ------------------------------------------------------------ |
885| aid        | number[]               | Yes     | AID of the Applet to be selected on this channel as a byte array, or an empty array if no Applet is to be selected.|
886| callback   | AsyncCallback\<Channel> | Yes     | Callback invoked to return the basic channel instance obtained.                           |
887
888**Error codes**
889
890For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
891
892| ID| Error Message                        |
893| -------- | -------------------------------- |
894| 3300101  | IllegalStateError, an attempt is made to use an SE session that has been closed. |
895| 3300102  | NoSuchElementError, the AID on the SE is not available or cannot be selected.       |
896| 3300103  | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session.   |
897| 3300104  | IOError, there is a communication problem to the reader or the SE.     |
898
899**Example**
900
901```js
902import omapi from '@ohos.secureElement';
903import secureElement from '@ohos.secureElement';
904import { BusinessError } from '@ohos.base';
905
906let nfcSEService : omapi.SEService | null = null;
907let nfcOmaReaderList : omapi.Reader[] | null = null;
908let omaSession : omapi.Session | null = null;
909let aidArray : number[] = [720, 1080];
910
911try {
912    nfcSEService = secureElement.newSEService("serviceState", (state) => {
913        if (state == secureElement.ServiceState.DISCONNECTED) {
914            console.log("Service state is Disconnected");
915        } else {
916            console.log("Service state is Connected");
917        }
918    });
919} catch (e) {
920    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
921}
922
923try {
924    if (nfcSEService != null) {
925      nfcOmaReaderList = nfcSEService.getReaders();
926    }
927    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
928        omaSession = nfcOmaReaderList[0].openSession();
929        if (omaSession != null) {
930            omaSession.openBasicChannel(aidArray, (error, data) => {
931                if (error) {
932                    console.error("openBasicChannel2 failed:" + JSON.stringify(error));
933                    return;
934                }
935                console.log("openBasicChannel2 get channel successfully");
936            });
937        }
938    }
939} catch (e) {
940    console.error("openBasicChannel2 " + "exception: ${(e : BusinessError).message}");
941}
942```
943
944## Session.openBasicChannel
945
946openBasicChannel(aid: number[], p2: number): Promise\<Channel>
947
948Opens a basic channel, as defined in ISO/IEC 7816-4. This API uses a promise to return the result. If the SE cannot provide the basic channel or the application does not have the permission to access the SE, null is returned.
949
950**System capability**: SystemCapability.Communication.SecureElement
951
952**Parameters**
953
954| **Name**| **Type**| **Mandatory**| **Description**                                                    |
955| ---------- | -------- | ------ | ------------------------------------------------------------ |
956| aid        | number[] | Yes      | AID of the Applet to be selected on this channel as a byte array, or an empty array if no Applet is to be selected.|
957| p2         | number   | Yes      |P2 parameter of the **SELECT APDU** command executed on this channel.                    |
958
959**Return value**
960
961| **Type**| **Description**             |
962| -------- | --------------------- |
963| Channel  | Promise used to return the basic channel instance obtained.|
964
965**Error codes**
966
967For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
968
969| ID| Error Message                        |
970| -------- | -------------------------------- |
971| 3300101  | IllegalStateError, an attempt is made to use an SE session that has been closed. |
972| 3300102  | NoSuchElementError, the AID on the SE is not available or cannot be selected.       |
973| 3300103  | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session.   |
974| 3300104  | IOError, there is a communication problem to the reader or the SE.     |
975
976**Example**
977
978```js
979import omapi from '@ohos.secureElement';
980import secureElement from '@ohos.secureElement';
981import { BusinessError } from '@ohos.base';
982
983let nfcSEService : omapi.SEService | null = null;
984let nfcOmaReaderList : omapi.Reader[] | null = null;
985let omaSession : omapi.Session | null = null;
986let getPromise : Promise<omapi.Channel> | null = null;
987let nfcOmaChannel : omapi.Channel | null = null;
988let aidArray : number[] = [720, 1080];
989let p2 : number = 0x00;
990
991try {
992    nfcSEService = secureElement.newSEService("serviceState", (state) => {
993        if (state == secureElement.ServiceState.DISCONNECTED) {
994            console.log("Service state is Disconnected");
995        } else {
996            console.log("Service state is Connected");
997        }
998    });
999} catch (e) {
1000    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1001}
1002
1003try {
1004    if (nfcSEService != null) {
1005      nfcOmaReaderList = nfcSEService.getReaders();
1006    }
1007    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1008        omaSession = nfcOmaReaderList[0].openSession();
1009    }
1010    if (omaSession != null) {
1011        getPromise = omaSession.openBasicChannel(aidArray, p2);
1012        getPromise.then((channel) => {
1013            nfcOmaChannel = channel;
1014            console.log("openBasicChannel3 get channel successfully");
1015        })
1016    }
1017} catch (e) {
1018    console.error("openBasicChannel3 " + "exception: ${(e : BusinessError).message}");
1019}
1020```
1021
1022## Session.openBasicChannel
1023
1024openBasicChannel(aid: number[], p2:number, callback: AsyncCallback\<Channel>): void
1025
1026Opens a basic channel, as defined in ISO/IEC 7816-4. This API uses an asynchronous callback to return the result. If the SE cannot provide the basic channel or the application does not have the permission to access the SE, null is returned.
1027
1028**System capability**: SystemCapability.Communication.SecureElement
1029
1030**Parameters**
1031
1032| **Name**| **Type**              | **Mandatory**| **Description**                                                    |
1033| ---------- | ---------------------- | ------ | ------------------------------------------------------------ |
1034| aid        | number[]               | Yes     | AID of the Applet to be selected on this channel as a byte array, or an empty array if no Applet is to be selected.|
1035| p2         | number                 | Yes     | P2 parameter of the **SELECT APDU** command executed on this channel.                    |
1036| callback   | AsyncCallback\<Channel> | Yes     | Callback invoked to return the basic channel instance obtained.                           |
1037
1038**Error codes**
1039
1040For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
1041
1042| ID| Error Message                        |
1043| -------- | -------------------------------- |
1044| 3300101  | IllegalStateError, an attempt is made to use an SE session that has been closed. |
1045| 3300102  | NoSuchElementError, the AID on the SE is not available or cannot be selected.      |
1046| 3300103  | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session.   |
1047| 3300104  | IOError, there is a communication problem to the reader or the SE.     |
1048
1049**Example**
1050
1051```js
1052import omapi from '@ohos.secureElement';
1053import secureElement from '@ohos.secureElement';
1054import { BusinessError } from '@ohos.base';
1055
1056let nfcSEService : omapi.SEService | null = null;
1057let nfcOmaReaderList : omapi.Reader[] | null = null;
1058let omaSession : omapi.Session | null = null;
1059let nfcOmaChannel : omapi.Channel | null = null;
1060let aidArray : number[] = [720, 1080];
1061let p2 : number = 0x00;
1062
1063try {
1064    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1065        if (state == secureElement.ServiceState.DISCONNECTED) {
1066            console.log("Service state is Disconnected");
1067        } else {
1068            console.log("Service state is Connected");
1069        }
1070    });
1071} catch (e) {
1072    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1073}
1074
1075try {
1076    if (nfcSEService != null) {
1077        nfcOmaReaderList = nfcSEService.getReaders();
1078    }
1079    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1080        omaSession = nfcOmaReaderList[0].openSession();
1081    }
1082    if (omaSession != null) {
1083        omaSession.openBasicChannel(aidArray, p2, (error , data) => {
1084            if (error) {
1085                console.error("openBasicChannel4 failed:" + JSON.stringify(error));
1086                return;
1087            }
1088            nfcOmaChannel = data;
1089            console.log("openBasicChannel4 get channel successfully");
1090        });
1091    }
1092} catch (e) {
1093    console.error("openBasicChannel4 " + "exception: ${(e : BusinessError).message}");
1094}
1095```
1096
1097## Session.openLogicalChannel
1098
1099openLogicalChannel(aid: number[]): Promise\<Channel>
1100
1101Opens a logical channel, as defined in ISO/IEC 7816-4. This API uses a promise to return the result. If the SE cannot provide the logical channel or the application does not have the permission to access the SE, null is returned.
1102
1103**System capability**: SystemCapability.Communication.SecureElement
1104
1105**Parameters**
1106
1107| **Name**| **Type**| **Mandatory**| **Description**                               |
1108| ---------- | -------- | ------ | --------------------------------------- |
1109| aid        | number[] | Yes     | AID of the Applet to be selected on this channel as a byte array, or an empty array if no Applet is to be selected.|
1110
1111**Return value**
1112
1113| **Type**| **Description**                                                    |
1114| -------- | ------------------------------------------------------------ |
1115| Channel  | Promise used to return the logical channel instance obtained.|
1116
1117**Error codes**
1118
1119For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
1120
1121| ID| Error Message                        |
1122| -------- | -------------------------------- |
1123| 3300101  | IllegalStateError, an attempt is made to use an SE session that has been closed. |
1124| 3300102  | NoSuchElementError, the AID on the SE is not available or cannot be selected.       |
1125| 3300103  | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session.   |
1126| 3300104  | IOError, there is a communication problem to the reader or the SE.     |
1127
1128**Example**
1129
1130```js
1131import omapi from '@ohos.secureElement';
1132import secureElement from '@ohos.secureElement';
1133import { BusinessError } from '@ohos.base';
1134
1135let nfcSEService : omapi.SEService | null = null;
1136let nfcOmaReaderList : omapi.Reader[] | null = null;
1137let omaSession : omapi.Session | null = null;
1138let aidArray : number[] = [720, 1080];
1139let getPromise : Promise<omapi.Channel> | null = null;
1140
1141try {
1142    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1143        if (state == secureElement.ServiceState.DISCONNECTED) {
1144            console.log("Service state is Disconnected");
1145        } else {
1146            console.log("Service state is Connected");
1147        }
1148    });
1149} catch (e) {
1150    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1151}
1152
1153try {
1154    if (nfcSEService != null) {
1155      nfcOmaReaderList = nfcSEService.getReaders();
1156    }
1157    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1158        omaSession = nfcOmaReaderList[0].openSession();
1159        if (omaSession != null) {
1160            getPromise = omaSession.openLogicalChannel(aidArray);
1161        } else {
1162            console.error("openLogicalChannel1 failed");
1163        }
1164    }
1165    if (getPromise != null) {
1166        console.log("openLogicalChannel1 get channel successfully");
1167    }
1168} catch (e) {
1169    console.error("openLogicalChannel1 " + "exception: ${(e : BusinessError).message}");
1170}
1171```
1172
1173## Session.openLogicalChannel
1174
1175 openLogicalChannel(aid: number[], callback: AsyncCallback\<Channel>): void
1176
1177Opens a logical channel, as defined in ISO/IEC 7816-4. This API uses an asynchronous callback to return the result. If the SE cannot provide the logical channel or the application does not have the permission to access the SE, null is returned.
1178
1179**System capability**: SystemCapability.Communication.SecureElement
1180
1181**Parameters**
1182
1183| **Name**| **Type**              | **Mandatory**| **Description**                                                    |
1184| ---------- | ---------------------- | ------ | ------------------------------------------------------------ |
1185| aid        | number[]               | Yes     | AID of the Applet to be selected on this channel as a byte array, or an empty array if no Applet is to be selected.|
1186| callback   | AsyncCallback\<Channel> | Yes     | Callback invoked to return the logical channel instance obtained.|
1187
1188**Error codes**
1189
1190For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
1191
1192| ID| Error Message                        |
1193| -------- | -------------------------------- |
1194| 3300101  | IllegalStateError, an attempt is made to use an SE session that has been closed. |
1195| 3300102  | NoSuchElementError, the AID on the SE is not available or cannot be selected.      |
1196| 3300103  | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session.   |
1197| 3300104  | IOError, there is a communication problem to the reader or the SE.    |
1198
1199**Example**
1200
1201```js
1202import omapi from '@ohos.secureElement';
1203import secureElement from '@ohos.secureElement';
1204import { BusinessError } from '@ohos.base';
1205
1206let nfcSEService : omapi.SEService | null = null;
1207let nfcOmaReaderList : omapi.Reader[] | null = null;
1208let omaSession : omapi.Session | null = null;
1209let aidArray : number[] = [720, 1080];
1210
1211try {
1212    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1213        if (state == secureElement.ServiceState.DISCONNECTED) {
1214            console.log("Service state is Disconnected");
1215        } else {
1216            console.log("Service state is Connected");
1217        }
1218    });
1219} catch (e) {
1220    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1221}
1222
1223try {
1224    if (nfcSEService != null) {
1225      nfcOmaReaderList = nfcSEService.getReaders();
1226    }
1227    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1228        omaSession = nfcOmaReaderList[0].openSession();
1229    }
1230    if (omaSession != null) {
1231        omaSession.openLogicalChannel(aidArray, (error, data) => {
1232            if (error) {
1233                console.error("openLogicalChannel2 failed:" + JSON.stringify(error));
1234                return;
1235            }
1236            console.log("openLogicalChannel2 get channel successfully");
1237        });
1238    }
1239} catch (e) {
1240    console.error("openLogicalChannel2 " + "exception: ${(e : BusinessError).message}");
1241}
1242```
1243
1244## Session.openLogicalChannel
1245
1246openLogicalChannel(aid: number[], p2: number): Promise\<Channel>
1247
1248Opens a logical channel, as defined in ISO/IEC 7816-4. This API uses a promise to return the result. If the SE cannot provide the logical channel or the application does not have the permission to access the SE, null is returned.
1249
1250**System capability**: SystemCapability.Communication.SecureElement
1251
1252**Parameters**
1253
1254| **Name**| **Type**| **Mandatory**| **Description**                                 |
1255| ---------- | -------- | ------ | ----------------------------------------- |
1256| aid        | number[] | Yes     | AID of the Applet to be selected on this channel as a byte array, or an empty array if no Applet is to be selected.|
1257| p2         | number   | Yes     | P2 parameter of the **SELECT APDU** command executed on this channel. |
1258
1259**Return value**
1260
1261| **Type**| **Description**      |
1262| -------- | -------------- |
1263| Channel | Promise used to return the logical channel instance obtained.|
1264
1265**Error codes**
1266
1267For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
1268
1269| ID| Error Message                        |
1270| -------- | -------------------------------- |
1271| 3300101  | IllegalStateError, an attempt is made to use an SE session that has been closed. |
1272| 3300102  | NoSuchElementError, the AID on the SE is not available or cannot be selected.      |
1273| 3300103  | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session.   |
1274| 3300104  | IOError, there is a communication problem to the reader or the SE.     |
1275
1276**Example**
1277
1278```js
1279import omapi from '@ohos.secureElement';
1280import secureElement from '@ohos.secureElement';
1281import { BusinessError } from '@ohos.base';
1282
1283let nfcSEService : omapi.SEService | null = null;
1284let nfcOmaReaderList : omapi.Reader[] | null = null;
1285let omaSession : omapi.Session | null = null;
1286let getPromise : Promise<omapi.Channel> | null = null;
1287let nfcOmaChannel : omapi.Channel | null = null;
1288let aidArray : number[] = [720, 1080];
1289let p2 : number = 0x00;
1290
1291try {
1292    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1293        if (state == secureElement.ServiceState.DISCONNECTED) {
1294            console.log("Service state is Disconnected");
1295        } else {
1296            console.log("Service state is Connected");
1297        }
1298    });
1299} catch (e) {
1300    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1301}
1302
1303try {
1304    if (nfcSEService != null) {
1305      nfcOmaReaderList = nfcSEService.getReaders();
1306    }
1307    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1308        omaSession = nfcOmaReaderList[0].openSession();
1309    }
1310    if (omaSession != null) {
1311        getPromise = omaSession.openLogicalChannel(aidArray, p2);
1312        getPromise.then((channel) => {
1313            nfcOmaChannel = channel;
1314            console.log("openLogicalChannel3 get channel successfully");
1315        })
1316    }
1317} catch (e) {
1318    console.error("openLogicalChannel3 " + "exception: ${(e : BusinessError).message}");
1319}
1320```
1321
1322## Session.openLogicalChannel
1323
1324openLogicalChannel(aid: number[], p2: number, callback: AsyncCallback\<Channel>):void
1325
1326Opens a logical channel, as defined in ISO/IEC 7816-4. This API uses an asynchronous callback to return the result. If the SE cannot provide the logical channel or the application does not have the permission to access the SE, null is returned.
1327
1328**System capability**: SystemCapability.Communication.SecureElement
1329
1330**Parameters**
1331
1332| **Name**| **Type**              | **Mandatory**| **Description**                                                    |
1333| ---------- | ---------------------- | ------ | ------------------------------------------------------------ |
1334| aid        | number[]               | Yes     | AID of the Applet to be selected on this channel as a byte array, or an empty array if no Applet is to be selected.|
1335| p2         | number                 | Yes     | P2 parameter of the **SELECT APDU** command executed on this channel.|
1336| callback   | AsyncCallback\<Channel> | Yes     | Callback invoked to return the logical channel instance obtained.|
1337
1338**Error codes**
1339
1340For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
1341
1342| ID| Error Message                        |
1343| -------- | -------------------------------- |
1344| 3300101  | IllegalStateError, an attempt is made to use an SE session that has been closed. |
1345| 3300102  | NoSuchElementError, the AID on the SE is not available or cannot be selected.       |
1346| 3300103  | SecurityError, the calling application cannot be granted access to this AID or the default applet on this session.   |
1347| 3300104  | IOError, there is a communication problem to the reader or the SE.     |
1348
1349**Example**
1350
1351```js
1352import omapi from '@ohos.secureElement';
1353import secureElement from '@ohos.secureElement';
1354import { BusinessError } from '@ohos.base';
1355
1356let nfcSEService : omapi.SEService | null = null;
1357let nfcOmaReaderList : omapi.Reader[] | null = null;
1358let omaSession : omapi.Session | null = null;
1359let nfcOmaChannel : omapi.Channel | null = null;
1360let aidArray : number[] = [720, 1080];
1361let p2 : number = 0x00;
1362
1363try {
1364    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1365        if (state == secureElement.ServiceState.DISCONNECTED) {
1366            console.log("Service state is Disconnected");
1367        } else {
1368            console.log("Service state is Connected");
1369        }
1370    });
1371} catch (e) {
1372    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1373}
1374
1375try {
1376    if (nfcSEService != null) {
1377        nfcOmaReaderList = nfcSEService.getReaders();
1378    }
1379    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1380        omaSession = nfcOmaReaderList[0].openSession();
1381    }
1382    if (omaSession != null) {
1383        omaSession.openLogicalChannel(aidArray, p2, (error, data) => {
1384            if (error) {
1385                console.error("openLogicalChannel4 failed:" + JSON.stringify(error));
1386                return;
1387            }
1388            nfcOmaChannel = data;
1389            console.log("openLogicalChannel4 get channel successfully");
1390        });
1391    }
1392} catch (e) {
1393    console.error("openLogicalChannel4 " + "exception: ${(e : BusinessError).message}");
1394}
1395```
1396
1397## Channel. getSession
1398
1399 getSession(): Session
1400
1401Obtains the session used to open this channel.
1402
1403**System capability**: SystemCapability.Communication.SecureElement
1404
1405**Return value**
1406
1407| **Type**| **Description**                     |
1408| -------- | ----------------------------- |
1409| Session  | Session instance obtained.|
1410
1411**Example**
1412
1413```js
1414import omapi from '@ohos.secureElement';
1415import secureElement from '@ohos.secureElement';
1416import { BusinessError } from '@ohos.base';
1417
1418let nfcSEService : omapi.SEService | null = null;
1419let nfcOmaReaderList : omapi.Reader[] | null = null;
1420let omaSession : omapi.Session | null = null;
1421let getPromise : Promise<omapi.Channel> | null = null;
1422let aidArray : number[] = [720, 1080];
1423let p2 : number = 0x00;
1424let mySession : omapi.Session | null = null;
1425
1426try {
1427    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1428        if (state == secureElement.ServiceState.DISCONNECTED) {
1429            console.log("Service state is Disconnected");
1430        } else {
1431            console.log("Service state is Connected");
1432        }
1433    });
1434} catch (e) {
1435    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1436}
1437
1438try {
1439    if (nfcSEService != null) {
1440        nfcOmaReaderList = nfcSEService.getReaders();
1441    }
1442    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1443        omaSession = nfcOmaReaderList[0].openSession();
1444    }
1445    if (omaSession != null) {
1446        getPromise = omaSession.openLogicalChannel(aidArray, p2);
1447        getPromise.then((channel) => {
1448            mySession = channel.getSession();
1449            console.log("openLogicalChannel get channel successfully");
1450        })
1451    }
1452    if (mySession != null) {
1453        console.log("get session successfully");
1454    } else {
1455        console.error("get session failed");
1456    }
1457} catch (e) {
1458    console.error("get session " + "exception: ${(e : BusinessError).message}");
1459}
1460```
1461
1462## Channel. close
1463
1464close(): void
1465
1466Closes this channel.
1467
1468**System capability**: SystemCapability.Communication.SecureElement
1469
1470**Example**
1471
1472```js
1473import omapi from '@ohos.secureElement';
1474import secureElement from '@ohos.secureElement';
1475import { BusinessError } from '@ohos.base';
1476
1477let nfcSEService : omapi.SEService | null = null;
1478let nfcOmaReaderList : omapi.Reader[] | null = null;
1479let omaSession : omapi.Session | null = null;
1480let getPromise : Promise<omapi.Channel> | null = null;
1481let aidArray : number[] = [720, 1080];
1482let p2 : number = 0x00;
1483
1484try {
1485    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1486        if (state == secureElement.ServiceState.DISCONNECTED) {
1487            console.log("Service state is Disconnected");
1488        } else {
1489            console.log("Service state is Connected");
1490        }
1491    });
1492} catch (e) {
1493    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1494}
1495
1496try {
1497    if (nfcSEService != null) {
1498        nfcOmaReaderList = nfcSEService.getReaders();
1499    }
1500    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1501        omaSession = nfcOmaReaderList[0].openSession();
1502    }
1503    if (omaSession != null) {
1504        getPromise = omaSession.openLogicalChannel(aidArray, p2);
1505        getPromise.then((channel) => {
1506            channel.close();
1507            console.log("channel close successfully");
1508        })
1509    }
1510} catch (e) {
1511    console.error("channel close " + "exception: ${(e : BusinessError).message}");
1512}
1513```
1514
1515## Channel. isBasicChannel
1516
1517isBasicChannel(): boolean
1518
1519Checks whether this channel is a basic channel.
1520
1521**System capability**: SystemCapability.Communication.SecureElement
1522
1523**Return value**
1524
1525| **Type**| **Description**                                                    |
1526| -------- | ------------------------------------------------------------ |
1527| boolean  | Returns **true** if the channel is a basic channel; returns **false** otherwise.|
1528
1529**Example**
1530
1531```js
1532import omapi from '@ohos.secureElement';
1533import secureElement from '@ohos.secureElement';
1534import { BusinessError } from '@ohos.base';
1535
1536let nfcSEService : omapi.SEService | null = null;
1537let nfcOmaReaderList : omapi.Reader[] | null = null;
1538let omaSession : omapi.Session | null = null;
1539let getPromise : Promise<omapi.Channel> | null = null;
1540let aidArray : number[] = [720, 1080];
1541let p2 : number = 0x00;
1542let ret : boolean = false;
1543
1544try {
1545    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1546        if (state == secureElement.ServiceState.DISCONNECTED) {
1547            console.log("Service state is Disconnected");
1548        } else {
1549            console.log("Service state is Connected");
1550        }
1551    });
1552} catch (e) {
1553    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1554}
1555
1556try {
1557    if (nfcSEService != null) {
1558        nfcOmaReaderList = nfcSEService.getReaders();
1559    }
1560    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1561        omaSession = nfcOmaReaderList[0].openSession();
1562    }
1563    if (omaSession != null) {
1564        getPromise = omaSession.openLogicalChannel(aidArray, p2);
1565        getPromise.then((channel) => {
1566            ret = channel.isBasicChannel();
1567        })
1568    }
1569    if (ret) {
1570        console.log("isBasicChannel TRUE");
1571    } else {
1572        console.log("isBasicChannel FALSE");
1573    }
1574} catch (e) {
1575    console.error("isBasicChannel " + "exception: ${(e : BusinessError).message}");
1576}
1577```
1578
1579## Channel. isClosed
1580
1581isClosed(): boolean
1582
1583Checks whether this channel is closed.
1584
1585**System capability**: SystemCapability.Communication.SecureElement
1586
1587**Return value**
1588
1589| **Type**| **Description**                                     |
1590| -------- | --------------------------------------------- |
1591| boolean  | Returns **true** if the channel is closed; returns **false** otherwise.|
1592
1593**Example**
1594
1595```js
1596import omapi from '@ohos.secureElement';
1597import secureElement from '@ohos.secureElement';
1598import { BusinessError } from '@ohos.base';
1599
1600let nfcSEService : omapi.SEService | null = null;
1601let nfcOmaReaderList : omapi.Reader[] | null = null;
1602let omaSession : omapi.Session | null = null;
1603let getPromise : Promise<omapi.Channel> | null = null;
1604let aidArray : number[] = [720, 1080];
1605let p2 : number = 0x00;
1606let ret : boolean = false;
1607
1608try {
1609    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1610        if (state == secureElement.ServiceState.DISCONNECTED) {
1611            console.log("Service state is Disconnected");
1612        } else {
1613            console.log("Service state is Connected");
1614        }
1615    });
1616} catch (e) {
1617    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1618}
1619
1620try {
1621    if (nfcSEService != null) {
1622      nfcOmaReaderList = nfcSEService.getReaders();
1623    }
1624    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1625        omaSession = nfcOmaReaderList[0].openSession();
1626    }
1627    if (omaSession != null) {
1628        getPromise = omaSession.openLogicalChannel(aidArray, p2);
1629        getPromise.then((channel) => {
1630            ret = channel.isClosed();
1631        })
1632    }
1633    if (ret) {
1634        console.log("channel isClosed TRUE");
1635    } else {
1636        console.log("channel isClosed False");
1637    }
1638} catch (e) {
1639    console.error("isBasicChannel " + "exception: ${(e : BusinessError).message}");
1640}
1641```
1642
1643## Channel. getSelectResponse
1644
1645getSelectResponse():number[]
1646
1647Obtains the response data including the status word of **SELECT Applet**.
1648
1649**System capability**: SystemCapability.Communication.SecureElement
1650
1651**Return value**
1652
1653| **Type**| **Description**                                                    |
1654| -------- | ------------------------------------------------------------ |
1655| number[] | Response data including the status word obtained.|
1656
1657**Error codes**
1658
1659For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
1660
1661**Example**
1662
1663```js
1664import omapi from '@ohos.secureElement';
1665import secureElement from '@ohos.secureElement';
1666import { BusinessError } from '@ohos.base';
1667
1668let nfcSEService : omapi.SEService | null = null;
1669let nfcOmaReaderList : omapi.Reader[] | null = null;
1670let omaSession : omapi.Session | null = null;
1671let getPromise : Promise<omapi.Channel> | null = null;
1672let aidArray : number[] = [720, 1080];
1673let p2 : number = 0x00;
1674let responseArray : number[] = [720, 1080];
1675let str : string = "";
1676
1677try {
1678    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1679        if (state == secureElement.ServiceState.DISCONNECTED) {
1680            console.log("Service state is Disconnected");
1681        } else {
1682            console.log("Service state is Connected");
1683        }
1684    });
1685} catch (e) {
1686    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1687}
1688
1689try {
1690    if (nfcSEService != null) {
1691        nfcOmaReaderList = nfcSEService.getReaders();
1692    }
1693    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1694        omaSession = nfcOmaReaderList[0].openSession();
1695    }
1696    if (omaSession != null) {
1697        getPromise = omaSession.openLogicalChannel(aidArray, p2);
1698        getPromise.then((channel) => {
1699            responseArray = channel.getSelectResponse();
1700        })
1701    }
1702    if (responseArray) {
1703        str = "getSelectResponse result:[";
1704        for (let i = 0; i < responseArray.length; ++i) {
1705            str += responseArray[i];
1706            str += ' ';
1707        }
1708        str += ']';
1709        console.log(str);
1710    } else {
1711        console.error("getSelectResponse result is null");
1712    }
1713} catch (e) {
1714    console.error("isBasicChannel " + "exception: ${(e : BusinessError).message}");
1715}
1716```
1717
1718## Channel. transmit
1719
1720transmit(command: number[]): Promise\<number[]>
1721
1722Transmits APDU data (as per ISO/IEC 7816) to the SE.
1723
1724**System capability**: SystemCapability.Communication.SecureElement
1725
1726**Parameters**
1727
1728| **Name**| **Type**| **Mandatory**| **Description**                             |
1729| ---------- | -------- | ------ | ------------------------------------- |
1730| command    | number[] | Yes     | APDU data to send.|
1731
1732**Return value**
1733
1734| **Type**| **Description**      |
1735| -------- | -------------- |
1736| number[] | Promise used to return the response received, in a number array.|
1737
1738**Error codes**
1739
1740For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
1741
1742| ID| Error Message                        |
1743| -------- | -------------------------------- |
1744| 3300101  | IllegalStateError, an attempt is made to use an SE session or channel that has been closed. |
1745| 3300103  | SecurityError, the command is filtered by the security policy. |
1746| 3300104  | IOError, there is a communication problem to the reader or the SE.     |
1747
1748**Example**
1749
1750```js
1751import omapi from '@ohos.secureElement';
1752import secureElement from '@ohos.secureElement';
1753import { BusinessError } from '@ohos.base';
1754
1755let nfcSEService : omapi.SEService | null = null;
1756let nfcOmaReaderList : omapi.Reader[] | null = null;
1757let omaSession : omapi.Session | null = null;
1758let getPromise : Promise<omapi.Channel> | null = null;
1759let aidArray : number[] = [720, 1080];
1760let p2 : number = 0x00;
1761let responseArray : Promise<number[]> | null = null;
1762
1763try {
1764    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1765        if (state == secureElement.ServiceState.DISCONNECTED) {
1766            console.log("Service state is Disconnected");
1767        } else {
1768            console.log("Service state is Connected");
1769        }
1770    });
1771} catch (e) {
1772    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1773}
1774
1775try {
1776    if (nfcSEService != null) {
1777        nfcOmaReaderList = nfcSEService.getReaders();
1778    }
1779    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1780        omaSession = nfcOmaReaderList[0].openSession();
1781    }
1782    if (omaSession != null) {
1783        getPromise = omaSession.openLogicalChannel(aidArray, p2);
1784        getPromise.then((channel) => {
1785            let command: number[] = [100, 200];
1786            // Refer to Session.openBasicChannel for this.nfcOmaChannel.
1787            responseArray = channel.transmit(command);
1788        })
1789    }
1790    if (responseArray != null) {
1791        console.log("transmit1 success");
1792    } else {
1793        console.error("transmit1 failed");
1794    }
1795} catch (e) {
1796    console.error("transmit1 " + "exception: ${(e : BusinessError).message}");
1797}
1798```
1799
1800## Channel. transmit
1801
1802transmit(command: number[], callback: AsyncCallback\<number[]>): void
1803
1804Transmits APDU data (as per ISO/IEC 7816) to the SE.
1805
1806**System capability**: SystemCapability.Communication.SecureElement
1807
1808**Parameters**
1809
1810| **Name**| **Type**               | **Mandatory**| **Description**                             |
1811| ---------- | ----------------------- | ------ | ------------------------------------- |
1812| command    | number[]                | Yes     | APDU data to send.|
1813| callback   | AsyncCallback\<number[]> | Yes     | Callback invoked to return the response received, in a number array. |
1814
1815**Error codes**
1816
1817For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.md).
1818
1819| ID| Error Message                        |
1820| -------- | -------------------------------- |
1821| 3300101  | IllegalStateError, an attempt is made to use an SE session or channel that has been closed. |
1822| 3300103  | SecurityError, the command is filtered by the security policy. |
1823| 3300104  | IOError, there is a communication problem to the reader or the SE.     |
1824
1825**Example**
1826
1827```js
1828import omapi from '@ohos.secureElement';
1829import secureElement from '@ohos.secureElement';
1830import { BusinessError } from '@ohos.base';
1831
1832let nfcSEService : omapi.SEService | null = null;
1833let nfcOmaReaderList : omapi.Reader[] | null = null;
1834let omaSession : omapi.Session | null = null;
1835let getPromise : Promise<omapi.Channel> | null = null;
1836let aidArray : number[] = [720, 1080];
1837let p2 : number = 0x00;
1838let str : string = "";
1839
1840try {
1841    nfcSEService = secureElement.newSEService("serviceState", (state) => {
1842        if (state == secureElement.ServiceState.DISCONNECTED) {
1843            console.log("Service state is Disconnected");
1844        } else {
1845            console.log("Service state is Connected");
1846        }
1847    });
1848} catch (e) {
1849    console.error("newSEService " + "exception: ${(e : BusinessError).message}");
1850}
1851
1852try {
1853    if (nfcSEService != null) {
1854        nfcOmaReaderList = nfcSEService.getReaders();
1855    }
1856    if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
1857        omaSession = nfcOmaReaderList[0].openSession();
1858    }
1859    if (omaSession != null) {
1860        getPromise = omaSession.openLogicalChannel(aidArray, p2);
1861        getPromise.then((channel) => {
1862            let command: number[] = [100, 200];
1863            // Refer to Session.openBasicChannel for this.nfcOmaChannel.
1864            channel.transmit(command, (error, data) => {
1865                if (error) {
1866                    console.error("transmit2 exception:" + JSON.stringify(error));
1867                    return;
1868                }
1869                str = "transmit2 result:[";
1870                for (let i = 0; i < data.length; ++i) {
1871                    str += data[i];
1872                    str += " ";
1873                }
1874                str += "]";
1875                console.log(str)
1876            });
1877        })
1878    }
1879} catch (e) {
1880    console.error("transmit2 " + "exception: ${(e : BusinessError).message}");
1881}
1882```
1883