• 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 */
15import { AsyncCallback } from './basic';
16import { ElementName }  from './bundleManager/ElementName';
17
18/**
19 * Provides methods to operate or manage NFC card emulation.
20 *
21 * @since 6
22 * @syscap SystemCapability.Communication.NFC.CardEmulation
23 */
24declare namespace cardEmulation {
25  /**
26   * Defines the capability type.
27   *
28   * @since 6
29   * @deprecated since 9
30   * @useinstead ohos.nfc.cardEmulation/cardEmulation#hasHceCapability
31   */
32  enum FeatureType {
33    /** This constant is used to check whether HCE card emulation is supported. */
34    HCE = 0,
35
36    /** This constant is used to check whether SIM card emulation is supported. */
37    UICC = 1,
38
39    /** This constant is used to check whether eSE card emulation is supported. */
40    ESE = 2,
41  }
42
43  /**
44   * Define the card emulation type, payment or other.
45   *
46   * @since 9
47   */
48  enum CardType {
49    /** Payment type of card emulation */
50    PAYMENT = "payment",
51
52    /** Other type of card emulation */
53    OTHER = "other",
54  }
55
56  /**
57   * Checks whether a specified type of card emulation is supported.
58   *
59   * <p>This method is used to check Whether the host or secure element supports card emulation.
60   *
61   * @param feature Indicates the card emulation type, {@code HCE}, {@code UICC}, or {@code ESE}.
62   * @returns Returns {@code true} if the specified type of card emulation is supported; returns
63   * {@code false} otherwise.
64   * @since 6
65   * @deprecated since 9
66   * @useinstead ohos.nfc.cardEmulation/cardEmulation#hasHceCapability
67   */
68  function isSupported(feature: number): boolean;
69
70  /**
71   * Checks whether Host Card Emulation(HCE) capability is supported.
72   *
73   * @returns { boolean } Returns true if HCE is supported, otherwise false.
74   * @permission ohos.permission.NFC_CARD_EMULATION
75   * @throws { BusinessError } 201 - Permission denied.
76   * @throws { BusinessError } 801 - Capability not supported.
77   * @since 9
78   */
79  function hasHceCapability(): boolean;
80
81  /**
82   * Checks whether a service is default for given type.
83   *
84   * @param { ElementName } elementName - The element name of the service ability
85   * @param { CardType } type - The type to query, pyament or other.
86   * @returns { boolean } Returns true if the service is default, otherwise false.
87   * @permission ohos.permission.NFC_CARD_EMULATION
88   * @throws { BusinessError } 201 - Permission denied.
89   * @throws { BusinessError } 401 - The parameter check failed.
90   * @throws { BusinessError } 801 - Capability not supported.
91   * @since 9
92   */
93  function isDefaultService(elementName: ElementName, type: CardType): boolean;
94
95  /**
96   * A class for NFC host application.
97   *
98   * <p>The NFC host application use this class, then Nfc service can access the application
99   * installation information and connect to services of the application.
100   *
101   * @since 8
102   * @syscap SystemCapability.Communication.NFC.CardEmulation
103   */
104  export class HceService {
105    /**
106     * start HCE
107     *
108     * @returns Returns {@code true} if HCE is enabled or has been enabled; returns {@code false} otherwise.
109     * @permission ohos.permission.NFC_CARD_EMULATION
110     * @since 8
111     * @deprecated since 9
112     * @useinstead ohos.nfc.cardEmulation/cardEmulation.HceService#start
113     */
114    startHCE(aidList: string[]): boolean;
115
116    /**
117     * Starts the HCE, regitser more aids and allows this application to be preferred while in foreground.
118     *
119     * @param { ElementName } elementName - The element name of the service ability
120     * @param { string[] } aidList - The aid list to be registered by this service, allowed to be empty.
121     * @throws { BusinessError } 201 - Permission denied.
122     * @throws { BusinessError } 401 - The parameter check failed.
123     * @throws { BusinessError } 801 - Capability not supported.
124     * @throws { BusinessError } 3100301 - Card emulation running state is abnormal in service.
125     * @permission ohos.permission.NFC_CARD_EMULATION
126     * @since 9
127     */
128     start(elementName: ElementName, aidList: string[]): void
129
130    /**
131     * stop HCE
132     *
133     * @returns Returns {@code true} if HCE is disabled or has been disabled; returns {@code false} otherwise.
134     * @permission ohos.permission.NFC_CARD_EMULATION
135     * @since 8
136     * @deprecated since 9
137     * @useinstead ohos.nfc.cardEmulation/cardEmulation.HceService#stop
138     */
139    stopHCE(): boolean;
140
141    /**
142     * Stops the HCE, and unset the preferred service while in foreground.
143     *
144     * @param { ElementName } elementName - The element name of the service ability
145     * @throws { BusinessError } 201 - Permission denied.
146     * @throws { BusinessError } 401 - The parameter check failed.
147     * @throws { BusinessError } 801 - Capability not supported.
148     * @throws { BusinessError } 3100301 - Card emulation running state is abnormal in service.
149     * @permission ohos.permission.NFC_CARD_EMULATION
150     * @since 9
151     */
152    stop(elementName: ElementName): void
153
154    /**
155     * register HCE event to receive the APDU data.
156     *
157     * @param type the type to register.
158     * @param callback Callback used to listen to HCE data that local device received.
159     * @permission ohos.permission.NFC_CARD_EMULATION
160     * @since 8
161     */
162    on(type: "hceCmd", callback: AsyncCallback<number[]>): void;
163
164    /**
165     * Sends a response APDU to the remote device.
166     *
167     * <p>This method is used by a host application when swiping card.
168     *
169     * @param responseApdu Indicates the response, which is a byte array.
170     * @permission ohos.permission.NFC_CARD_EMULATION
171     * @since 8
172     * @deprecated since 9
173     * @useinstead ohos.nfc.cardEmulation/cardEmulation.HceService#transmit
174     */
175    sendResponse(responseApdu: number[]): void;
176
177    /**
178     * Sends a response APDU to the remote device.
179     *
180     * @param response Indicates the response to send, which is a byte array.
181     * @throws { BusinessError } 201 - Permission denied.
182     * @throws { BusinessError } 401 - The parameter check failed.
183     * @throws { BusinessError } 801 - Capability not supported.
184     * @throws { BusinessError } 3100301 - Card emulation running state is abnormal in service.
185     * @permission ohos.permission.NFC_CARD_EMULATION
186     * @since 9
187     */
188    transmit(response: number[]): Promise<void>;
189    transmit(response: number[], callback: AsyncCallback<void>): void;
190  }
191}
192export default cardEmulation;
193