diff --git a/api/@ohos.application.Ability.d.ts b/api/@ohos.application.Ability.d.ts deleted file mode 100755 index 38a08deac1f37bee7e06977a44ea7dae7242a401..0000000000000000000000000000000000000000 --- a/api/@ohos.application.Ability.d.ts +++ /dev/null @@ -1,251 +0,0 @@ -/* - * 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 AbilityConstant from "./@ohos.application.AbilityConstant"; -import AbilityContext from "./application/AbilityContext"; -import Want from './@ohos.application.Want'; -import window from './@ohos.window'; -import { Configuration } from './@ohos.application.Configuration'; -import rpc from '/@ohos.rpc'; - -/** - * The interface of a Caller. - * - * @since 9 - * @sysCap AAFwk - * @devices phone, tablet, tv, wearable, car - * @permission N/A - * @StageModelOnly - */ - interface Caller { - /** - * Notify the server of Sequenceable type data. - * - * @since 9 - * @sysCap AAFwk - * @StageModelOnly - */ - call(method: string, data: rpc.Sequenceable): Promise; - - /** - * Notify the server of Sequenceable type data and return the notification result. - * - * @since 9 - * @sysCap AAFwk - * return Sequenceable data - * @StageModelOnly - */ - callWithResult(method: string, data: rpc.Sequenceable): Promise; - - /** - * Clear service records. - * - * @since 9 - * @sysCap AAFwk - * return Sequenceable data - * @StageModelOnly - */ - release(): void; - - /** - * Register death listener notification callback. - * - * @since 9 - * @sysCap AAFwk - * return Sequenceable data - * @StageModelOnly - */ - onRelease(callback: function): void; - } - - /** - * The interface of a Callee. - * - * @since 9 - * @sysCap AAFwk - * @devices phone, tablet, tv, wearable, car - * @permission N/A - * @StageModelOnly - */ - interface Callee { - - /** - * Register data listener callback. - * - * @since 9 - * @sysCap AAFwk - * @StageModelOnly - */ - on(method: string, callback: function): void; - - /** - * Unregister data listener callback. - * - * @since 9 - * @sysCap AAFwk - * @StageModelOnly - */ - off(method: string): void; - } - -/** - * The class of an ability. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @permission N/A - * @StageModelOnly - */ -export default class Ability { - /** - * Indicates configuration information about an ability context. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @StageModelOnly - */ - context: AbilityContext; - - /** - * Indicates ability launch want. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @StageModelOnly - */ - launchWant: Want; - - /** - * Indicates ability last request want. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @StageModelOnly - */ - lastRequestWant: Want; - - /** - * Call Service Stub Object. - * - * @since 9 - * @sysCap AAFwk - * @StageModelOnly - */ - callee: Callee; - - /** - * Called back when an ability is started for initialization. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @return - - * @StageModelOnly - */ - onCreate(want: Want, param: AbilityConstant.LaunchParam): void; - - /** - * Called back when an ability window stage is created. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @return - - * @StageModelOnly - */ - onWindowStageCreate(windowStage: window.WindowStage): void; - - /** - * Called back when an ability window stage is destroyed. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @return - - * @StageModelOnly - */ - onWindowStageDestroy(): void; - - /** - * Called back when an ability window stage is restored. - * - * @since 9 - * @syscap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @param windowStage window stage to restore - * @return - - * @StageModelOnly - */ - onWindowStageRestore(windowStage: window.WindowStage): void; - - /** - * Called back before an ability is destroyed. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @return - - * @StageModelOnly - */ - onDestroy(): void; - - /** - * Called back when the state of an ability changes to foreground. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @return - - * @StageModelOnly - */ - onForeground(): void; - - /** - * Called back when the state of an ability changes to background. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @return - - * @StageModelOnly - */ - onBackground(): void; - - /** - * Called back when an ability prepares to migrate. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.AbilityCore - * @return true if ability agrees to migrate and saves data successfully, otherwise false. - * @StageModelOnly - */ - onContinue(wantParam : {[key: string]: any}): boolean; - - /** - * Called when the launch mode of an ability is set to singleton. - * This happens when you re-launch an ability that has been at the top of the ability stack. - * - * @devices phone, tablet, tv, wearable, car - * @since 9 - * @sysCap AAFwk - * @return - - * @StageModelOnly - */ - onNewWant(want: Want): void; - - /** - * Called when the system configuration is updated. - * - * @devices phone, tablet, tv, wearable, car - * @since 9 - * @sysCap AAFwk - * @return - - * @StageModelOnly - */ - onConfigurationUpdated(config: Configuration): void; -} diff --git a/api/@ohos.nfc.cardEmulation.js b/api/@ohos.nfc.cardEmulation.js new file mode 100755 index 0000000000000000000000000000000000000000..505b3626541da02b08e77fa90e2e684296e0518d --- /dev/null +++ b/api/@ohos.nfc.cardEmulation.js @@ -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.js b/api/@ohos.nfc.controller.js new file mode 100755 index 0000000000000000000000000000000000000000..35c767cb74618c89ea51714b075c0c164d8ad750 --- /dev/null +++ b/api/@ohos.nfc.controller.js @@ -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.js b/api/@ohos.nfc.tag.js new file mode 100755 index 0000000000000000000000000000000000000000..78ec3e6702cef7f4ee06df2694a3091ad41dafea --- /dev/null +++ b/api/@ohos.nfc.tag.js @@ -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/application/AbilityContext.d.ts b/api/application/AbilityContext.d.ts deleted file mode 100755 index 3238ae439e9705e45d5b9424109e4c5d0bd4b95e..0000000000000000000000000000000000000000 --- a/api/application/AbilityContext.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2021 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 { AbilityInfo } from "../bundle/abilityInfo"; -import { AbilityResult } from "../ability/abilityResult"; -import { AsyncCallback } from "../basic"; -import { ConnectOptions } from "../ability/connectOptions"; -import { HapModuleInfo } from "../bundle/hapModuleInfo"; -import Context from "./Context"; -import Want from "../@ohos.application.Want"; -import StartOptions from "../@ohos.application.StartOptions"; -import PermissionRequestResult from "./PermissionRequestResult"; -import { Configuration } from '../@ohos.application.Configuration'; -import Caller from '../@ohos.application.Ability'; -import { ContentStorage } from '../@internal/component/ets/state_management'; - -/** - * The context of an ability. It allows access to ability-specific resources. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @permission N/A - * @StageModelOnly - */ -export default class AbilityContext extends Context { - /** - * Indicates configuration information about an ability. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @StageModelOnly - */ - abilityInfo: AbilityInfo; - - /** - * Indicates configuration information about an module. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @StageModelOnly - */ - currentHapModuleInfo: HapModuleInfo; - - /** - * Indicates configuration information. - * - * @since 9 - * @sysCap AAFwk - * @StageModelOnly - */ - config: Configuration; - - /** - * Starts a new ability. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @param parameter Indicates the ability to start. - * @return - - * @StageModelOnly - */ - startAbility(want: Want, callback: AsyncCallback): void; - startAbility(want: Want, options: StartOptions, callback: AsyncCallback): void; - startAbility(want: Want, options?: StartOptions): Promise; - - /** - * Get the caller object of the startup capability - * - * @devices phone, tablet, tv, wearable, car - * @since 9 - * @sysCap AAFwk - * @param parameter Indicates the ability to start. - * @return Caller - * @StageModelOnly - */ - startAbilityByCall(want: Want): Promise; - - /** - * Starts a new ability with account. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @param want Indicates the want info to start. - * @param want Indicates the account to start. - * @systemapi hide for inner use. - * @return - - * @StageModelOnly - */ - startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback): void; - startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback): void; - startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions): Promise; - - /** - * Starts an ability and returns the execution result when the ability is destroyed. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @param parameter Indicates the ability to start. - * @return Returns the {@link AbilityResult}. - * @StageModelOnly - */ - startAbilityForResult(want: Want, callback: AsyncCallback): void; - startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback): void; - startAbilityForResult(want: Want, options?: StartOptions): Promise; - - /** - * Starts an ability and returns the execution result when the ability is destroyed with account. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @param want Indicates the want info to start. - * @param want Indicates the account to start. - * @systemapi hide for inner use. - * @return Returns the {@link AbilityResult}. - * @StageModelOnly - */ - startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncCallback): void; - startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOptions, callback: AsyncCallback): void; - startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartOptions): Promise; - - /** - * Destroys this Page ability. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @return - - * @StageModelOnly - */ - terminateSelf(callback: AsyncCallback): void; - terminateSelf(): Promise; - - /** - * Sets the result code and data to be returned by this Page ability to the caller - * and destroys this Page ability. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @param parameter Indicates the result to return. - * @return - - * @StageModelOnly - */ - terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback): void; - terminateSelfWithResult(parameter: AbilityResult): Promise; - - /** - * Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @param want The element name of the service ability - * @param options The remote object instance - * @hide hide for inner use. - * @return Returns the number code of the ability connected - * @StageModelOnly - */ - connectAbility(want: Want, options: ConnectOptions): number; - - /** - * Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template with account. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @param want The element name of the service ability - * @param options The remote object instance - * @param accountId The account to connect - * @systemapi hide for inner use. - * @return Returns the number code of the ability connected - * @StageModelOnly - */ - connectAbilityWithAccount(want: Want, accountId: number, options: ConnectOptions): number; - - /** - * The callback interface was connect successfully. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @param connection The number code of the ability connected - * @hide hide for inner use. - * @StageModelOnly - */ - disconnectAbility(connection: number, callback:AsyncCallback): void; - disconnectAbility(connection: number): Promise; - - /** - * Set mission label of current ability. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @param label The label of ability that showed in recent missions. - * @StageModelOnly - */ - setMissionLabel(label: string, callback:AsyncCallback): void; - setMissionLabel(label: string): Promise; - - /** - * Requests certain permissions from the system. - * - * @since 9 - * @sysCap SystemCapability.Ability.AbilityRuntime.Core - * @param permissions Indicates the list of permissions to be requested. This parameter cannot be null or empty. - * @StageModelOnly - */ - requestPermissionsFromUser(permissions: Array, requestCallback: AsyncCallback) : void; - requestPermissionsFromUser(permissions: Array) : Promise; - - /** - * Restore window stage data in ability continuation - * - * @since 9 - * @syscap SystemCapability.Ability.AbilityRuntime.Core - * @param contentStorage the storage data used to restore window stage - * @StageModelOnly - */ - restoreWindowStage(contentStorage: ContentStorage) : void; - -} \ No newline at end of file diff --git a/api/tag/nfctech.js b/api/tag/nfctech.js new file mode 100755 index 0000000000000000000000000000000000000000..fbcc5f289705884a21a3b70516a96e72a2e9cd6e --- /dev/null +++ b/api/tag/nfctech.js @@ -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.js b/api/tag/tagSession.js new file mode 100755 index 0000000000000000000000000000000000000000..c50deecbf24d84f28553ac5c17e9d41e8e703c15 --- /dev/null +++ b/api/tag/tagSession.js @@ -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