diff --git a/api/@ohos.nfc.cardEmulation.d.ts b/api/@ohos.nfc.cardEmulation.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..505b3626541da02b08e77fa90e2e684296e0518d --- /dev/null +++ b/api/@ohos.nfc.cardEmulation.d.ts @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Provides methods to operate or manage NFC card emulation. + * + * @import import cardEmulation from '@ohos.nfc.cardEmulation'; + * + * @since 6 + * @syscap SystemCapability.Communication.NFC.Core + */ +declare namespace cardEmulation { + enum Featuretype { + /** This constant is used to check whether HCE card emulation is supported. */ + HCE = 0, + + /** This constant is used to check whether SIM card emulation is supported. */ + UICC = 1, + + /** This constant is used to check whether eSE card emulation is supported. */ + ESE = 2, + } + + /** + * Checks whether a specified type of card emulation is supported. + * + *

This method is used to check Whether the host or secure element supports card emulation. + * + * @param feature Indicates the card emulation type, {@code HCE}, {@code UICC}, or {@code ESE}. + * @return Returns {@code true} if the specified type of card emulation is supported; returns + * {@code false} otherwise. + * + * @since 6 + */ + function isSupported(feature: number):boolean; + + /** + * A class for NFC host application. + * + *

The NFC host application use this class, then Nfc service can access the application + * installation information and connect to services of the application. + * + * @since 8 + * @syscap SystemCapability.Communication.NFC.Core + */ + export class HceService { + /** + * start HCE + * + * @return Returns {@code true} if HCE is enabled or has been enabled; returns {@code false} otherwise. + * @permission ohos.permission.NFC_CARD_EMULATION + * + * @since 8 + */ + startHCE(aidList: string[]): boolean; + + /** + * stop HCE + * + * @return Returns {@code true} if HCE is disabled or has been disabled; returns {@code false} otherwise. + * @permission ohos.permission.NFC_CARD_EMULATION + * + * @since 8 + */ + stopHCE(): boolean; + + + /** + * register HCE event to receive the APDU data. + * + * @param type the type to register. + * @param callback Callback used to listen for HCE data device received. + * @permission ohos.permission.NFC_CARD_EMULATION + * + * @since 8 + */ + + on(type: "hceCmd", callback: AsyncCallback): void; + + /** + * Sends a response APDU to the remote device. + * + *

This method is used by a host application when swiping card. + * + * @param responseApdu Indicates the response, which is a byte array. + * @permission ohos.permission.NFC_CARD_EMULATION + * + * @since 8 + */ + sendResponse(responseApdu: number[]): void; + } +} +export default cardEmulation; diff --git a/api/@ohos.nfc.controller.d.ts b/api/@ohos.nfc.controller.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..35c767cb74618c89ea51714b075c0c164d8ad750 --- /dev/null +++ b/api/@ohos.nfc.controller.d.ts @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Callback } from './basic'; + +/** + * Provides methods to operate or manage NFC. + * + * @import import controller from '@ohos.nfc.controller'; + * + * @since 7 + * @syscap SystemCapability.Communication.NFC.Core + */ +declare namespace nfcController { + enum NfcState { + /** Indicates that NFC is disabled. */ + STATE_OFF = 1, + + /** Indicates that NFC is being enabled. */ + STATE_TURNING_ON = 2, + + /** Indicates that NFC is enabled. */ + STATE_ON = 3, + + /** Indicates that NFC is being disabled. */ + STATE_TURNING_OFF = 4, + } + + /** + * Checks whether a device supports NFC. + * + * @return Returns {@code true} if the device supports NFC; returns {@code false} otherwise. + * + * @since 7 + */ + function isNfcAvailable(): boolean + + /** + * register nfc state changed event. + * + * @param type the type to register. + * @param callback Callback used to listen for the nfc state changed event. + * + * @since 7 + */ + + function on(type: "nfcStateChange", callback: Callback): void + + /** + * unregister nfc state changed event. + * + * @param type the type to unregister. + * @param callback Callback used to listen for the nfc state changed event. + * + * @since 7 + */ + + function off(type: "nfcStateChange", callback?: Callback): void + + /** + * Enables NFC. + * + * @return Returns {@code true} if NFC is enabled or has been enabled; returns {@code false} otherwise. + * @permission ohos.permission.MANAGE_SECURE_SETTINGS + * + * @since 7 + */ + function openNfc(): boolean + + /** + * Disables NFC. + * + * @return Returns {@code true} if NFC is disabled or has been disabled; returns {@code false} otherwise. + * @permission ohos.permission.MANAGE_SECURE_SETTINGS + * + * @since 7 + */ + function closeNfc(): boolean + + /** + * Checks whether NFC is enabled. + * + * @return Returns {@code true} if NFC is enabled; returns {@code false} otherwise. + * + * @since 7 + */ + function isNfcOpen(): boolean + + /** + * Obtains the NFC status. + * + *

The NFC status can be any of the following:

+ * + * @return Returns the NFC status. + * + * @since 7 + */ + function getNfcState(): boolean +} + +export default nfcController; \ No newline at end of file diff --git a/api/@ohos.nfc.tag.d.ts b/api/@ohos.nfc.tag.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..78ec3e6702cef7f4ee06df2694a3091ad41dafea --- /dev/null +++ b/api/@ohos.nfc.tag.d.ts @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { NfcATag, NfcBTag, NfcFTag, NfcVTag } from './tag/nfctech'; + +/** + * Provides methods to operate or manage NFC tag. + * + * @import import tag from '@ohos.nfc.tag'; + * + * @since 7 + * @sysCap SystemCapability.Communication.NFC.Core + */ +declare namespace tag { + /** Indicates an NFC-A tag. */ + const NFC_A = 1; + + /** Indicates an NFC-B tag. */ + const NFC_B = 2; + + /** Indicates an ISO-DEP tag. */ + const ISO_DEP = 3; + + /** Indicates an NFC-F tag. */ + const NFC_F = 4; + + /** Indicates an NFC-V tag. */ + const NFC_V = 5; + + /** Indicated an NDEF tag. */ + const NDEF = 6; + + /** Indicates a MifareClassic tag. */ + const MIFARE_CLASSIC = 8; + + /** Indicates a MifareUltralight tag. */ + const MIFARE_ULTRALIGHT = 9; + + /** + * Obtains an {@code NfcATag} object based on the tag information. + * + *

During tag reading, if the tag supports the NFC-A technology, an {@code NfcATag} object + * will be created based on the tag information. + * + * @param tagInfo Indicates the tag information. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + function getNfcATag(tagInfo: TagInfo): NfcATag + + /** + * Obtains an {@code NfcBTag} object based on the tag information. + * + *

During tag reading, if the tag supports the NFC-B technology, an {@code NfcBTag} object + * will be created based on the tag information. + * + * @param tagInfo Indicates the tag information. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + function getNfcBTag(tagInfo: TagInfo): NfcBTag + + /** + * Obtains an {@code NfcFTag} object based on the tag information. + * + *

During tag reading, if the tag supports the NFC-F technology, an {@code NfcFTag} object + * will be created based on the tag information. + * + * @param tagInfo Indicates the tag information. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + function getNfcFTag(tagInfo: TagInfo): NfcFTag + + /** + * Obtains an {@code NfcVTag} object based on the tag information. + * + *

During tag reading, if the tag supports the NFC-V technology, an {@code NfcVTag} object + * will be created based on the tag information. + * + * @param tagInfo Indicates the tag information. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + function getNfcVTag(tagInfo: TagInfo): NfcVTag + + + /** + * Provides tag information. + * + *

This class provides the technology a tag supports, for example, NFC-A. Applications can create + * different tags based on the supported technology. + * + * @since 7 + * @syscap SystemCapability.Communication.NFC.Core + * @permission ohos.permission.NFC_TAG + */ + export interface TagInfo { + supportedProfiles: number[]; + } +} +export default tag; \ No newline at end of file diff --git a/api/tag/nfctech.d.ts b/api/tag/nfctech.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..fbcc5f289705884a21a3b70516a96e72a2e9cd6e --- /dev/null +++ b/api/tag/nfctech.d.ts @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { TagSession } form './tagSession'; + +/** + * Provides interfaces to control the read and write of tags that support the NFC-A technology. + * + *

This class is inherited from the {@link TagSession} abstract class, and provides methods to create + * {@code NfcATag} objects and obtain the ATQA and SAK. + * + * @since 7 + * @syscap SystemCapability.Communication.NFC.Core + */ +export interface NfcATag extends TagSession{ + /** + * Obtains the SAK of an NFC-A tag. + * + * @return Returns the SAK of the NFC-A tag. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getSak():number; + + /** + * Obtains the ATQA of an NFC-A tag. + * + * @return Returns the ATQA of the NFC-A tag. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getAtqa():number[]; +} + +/** + * Provides interfaces to create an {@code NfcBTag} and perform I/O operations on the tag. + * + *

This class inherits from the {@link TagSession} abstract class and provides interfaces to create an + * {@code NfcBTag} and obtain the tag information. + * + * @since 7 + * @syscap SystemCapability.Communication.NFC.Core + */ +export interface NfcBTag extends TagSession{ + /** + * Obtains the application data of a tag. + * + * @return Returns the application data of the tag. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getRespAppData():number[]; + + /** + * Obtains the protocol information of a tag. + * + * @return Returns the protocol information of the tag. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getRespProtocol():number[]; +} + +/** + * Provides methods for creating an NFC-F tag, obtaining tag information, and controlling tag read and write. + * + *

This class inherits from the {@link TagSession} abstract class and provides interfaces to create an + * {@code NfcFTag} and obtain the tag information. + * + * @since 7 + * @syscap SystemCapability.Communication.NFC.Core + */ +export interface NfcFTag extends TagSession{ + /** + * Obtains the system code from this {@code NfcFTag} instance. + * + * @return Returns the system code. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getSystemCode():number[]; + + /** + * Obtains the PMm (consisting of the IC code and manufacturer parameters) from this {@code NfcFTag} instance. + * + * @return Returns the PMm. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getPmm():number[]; +} + +/** + * Provides methods for creating an NFC-V tag, obtaining tag information, and controlling tag read and write. + * + *

This class inherits from the {@link TagSession} abstract class and provides interfaces to create an + * {@code NfcVTag} and obtain the tag information. + * + * @since 7 + * @syscap SystemCapability.Communication.NFC.Core + */ +export interface NfcVTag extends TagSession{ + /** + * Obtains the response flags from this {@code NfcVTag} instance. + * + * @return Returns the response flags. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getResponseFlags():number; + + /** + * Obtains the data storage format identifier (DSFID) from this {@code NfcVTag} instance. + * + * @return Returns the DSFID. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getDsfId():number; +} diff --git a/api/tag/tagSession.d.ts b/api/tag/tagSession.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..c50deecbf24d84f28553ac5c17e9d41e8e703c15 --- /dev/null +++ b/api/tag/tagSession.d.ts @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import tag from '../ohos.nfc.tag'; +import { AsyncCallback } form './basic'; + +/** + * Controls tag read and write. + * + *

Classes for different types of tags inherit from this abstract class to control connections to + * tags, read data from tags, and write data to tags. + * + * @since 7 + * @syscap SystemCapability.Communication.NFC.Core + */ +export interface TagSession { + /** + * Obtains the tag information. + * + * @return Returns the tag information, which is a {@link TagInfo} object. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getTagInfo(): tag.TagInfo; + + /** + * Connects to a tag. + * + *

This method must be called before data is read from or written to the tag. + * + * @return Returns {@code true} if the connection is set up; returns {@code false} otherwise. + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + connectTag(): boolean; + + /** + * Resets a connection with a tag and restores the default timeout duration for writing data to the tag. + * + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + reset(): void; + + /** + * Checks whether a connection has been set up with a tag. + * + * @return Returns {@code true} if a connection has been set up with the tag; + * returns {@code false} otherwise. + * + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + isTagConnected(); boolean; + + /** + * Sets the timeout duration (ms) for sending data to a tag. + * + *

If data is not sent to the tag within the duration, data sending fails. + * + * @param timeout Indicates the timeout duration to be set. + * @return Returns {@code true} if the setting is successful; returns {@code false} otherwise. + * + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + setSendDataTimeout(timeout: number): boolean; + + /** + * Queries the timeout duration (ms) for sending data to a tag. + * + * @return Returns the timeout duration. + * + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getSendDataTimeout(): number; + + /** + * Writes data to a tag. + * + * @param data Indicates the data to be written to the tag. + * @return Returns bytes received in response. Or bytes with a length of 0 if the + * data fails to be written to the tag. + * + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + sendData(data: number[]): Promise; + + /** + * Writes data to a tag. + * + * @param data Indicates the data to be written to the tag. + * @return Returns bytes received in response. Or bytes with a length of 0 if the + * data fails to be written to the tag. + * + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + sendData(data: number[], callback: AsyncCallback): void; + + /** + * Queries the maximum length of data that can be sent to a tag. + * + * @return Returns the maximum length of the data to be sent to the tag. + * + * @permission ohos.permission.NFC_TAG + * + * @since 7 + */ + getMaxSendLength(): number; +} \ No newline at end of file