1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit ConnectivityKit 19 */ 20 21import { Callback } from './@ohos.base'; 22 23/** 24 * Provides methods to operate or manage NFC. 25 * 26 * @namespace nfcController 27 * @syscap SystemCapability.Communication.NFC.Core 28 * @since 7 29 */ 30/** 31 * Provides methods to operate or manage NFC. 32 * 33 * @namespace nfcController 34 * @syscap SystemCapability.Communication.NFC.Core 35 * @atomicservice 36 * @since 12 37 */ 38declare namespace nfcController { 39 /** 40 * NFC changed states. 41 * 42 * @enum { number } 43 * @syscap SystemCapability.Communication.NFC.Core 44 * @since 7 45 */ 46 /** 47 * NFC changed states. 48 * 49 * @enum { number } 50 * @syscap SystemCapability.Communication.NFC.Core 51 * @atomicservice 52 * @since 12 53 */ 54 enum NfcState { 55 /** 56 * Indicates that NFC is disabled. 57 * 58 * @syscap SystemCapability.Communication.NFC.Core 59 * @since 7 60 */ 61 /** 62 * Indicates that NFC is disabled. 63 * 64 * @syscap SystemCapability.Communication.NFC.Core 65 * @atomicservice 66 * @since 12 67 */ 68 STATE_OFF = 1, 69 70 /** 71 * Indicates that NFC is being enabled. 72 * 73 * @syscap SystemCapability.Communication.NFC.Core 74 * @since 7 75 */ 76 /** 77 * Indicates that NFC is being enabled. 78 * 79 * @syscap SystemCapability.Communication.NFC.Core 80 * @atomicservice 81 * @since 12 82 */ 83 STATE_TURNING_ON = 2, 84 85 /** 86 * Indicates that NFC is enabled. 87 * 88 * @syscap SystemCapability.Communication.NFC.Core 89 * @since 7 90 */ 91 /** 92 * Indicates that NFC is enabled. 93 * 94 * @syscap SystemCapability.Communication.NFC.Core 95 * @atomicservice 96 * @since 12 97 */ 98 STATE_ON = 3, 99 100 /** 101 * Indicates that NFC is being disabled. 102 * 103 * @syscap SystemCapability.Communication.NFC.Core 104 * @since 7 105 */ 106 /** 107 * Indicates that NFC is being disabled. 108 * 109 * @syscap SystemCapability.Communication.NFC.Core 110 * @atomicservice 111 * @since 12 112 */ 113 STATE_TURNING_OFF = 4 114 } 115 116 /** 117 * Checks whether a device supports NFC. 118 * 119 * @returns { boolean } Returns {@code true} if the device supports NFC; returns {@code false} otherwise. 120 * @syscap SystemCapability.Communication.NFC.Core 121 * @since 7 122 * @deprecated since 9 123 * @useinstead global#canIUse("SystemCapability.Communication.NFC.Core") 124 */ 125 function isNfcAvailable(): boolean; 126 127 /** 128 * register nfc state changed event. 129 * 130 * @param { 'nfcStateChange' } type The type to register. 131 * @param { Callback<NfcState> } callback Callback used to listen to the nfc state changed event. 132 * @syscap SystemCapability.Communication.NFC.Core 133 * @since 7 134 */ 135 /** 136 * register nfc state changed event. 137 * 138 * @param { 'nfcStateChange' } type The type to register. 139 * @param { Callback<NfcState> } callback Callback used to listen to the nfc state changed event. 140 * @syscap SystemCapability.Communication.NFC.Core 141 * @atomicservice 142 * @since 12 143 */ 144 function on(type: 'nfcStateChange', callback: Callback<NfcState>): void; 145 146 /** 147 * unregister nfc state changed event. 148 * 149 * @param { 'nfcStateChange' } type The type to unregister. 150 * @param { Callback<NfcState> } callback Callback used to listen to the nfc state changed event. 151 * @syscap SystemCapability.Communication.NFC.Core 152 * @since 7 153 */ 154 /** 155 * unregister nfc state changed event. 156 * 157 * @param { 'nfcStateChange' } type The type to unregister. 158 * @param { Callback<NfcState> } callback Callback used to listen to the nfc state changed event. 159 * @syscap SystemCapability.Communication.NFC.Core 160 * @atomicservice 161 * @since 12 162 */ 163 function off(type: 'nfcStateChange', callback?: Callback<NfcState>): void; 164 165 /** 166 * Enables NFC. 167 * 168 * @permission ohos.permission.MANAGE_SECURE_SETTINGS 169 * @returns { boolean } Returns {@code true} if NFC is enabled or has been enabled; returns {@code false} otherwise. 170 * @syscap SystemCapability.Communication.NFC.Core 171 * @since 7 172 * @deprecated since 9 173 * @useinstead ohos.nfc.controller/nfcController#enableNfc 174 */ 175 function openNfc(): boolean; 176 177 /** 178 * Enables NFC. 179 * This API can be called only by system applications 180 * 181 * @permission ohos.permission.MANAGE_SECURE_SETTINGS 182 * @throws { BusinessError } 201 - Permission denied. 183 * @throws { BusinessError } 801 - Capability not supported. 184 * @throws { BusinessError } 3100101 - The NFC state is abnormal in the service. 185 * @syscap SystemCapability.Communication.NFC.Core 186 * @since 9 187 */ 188 function enableNfc(): void; 189 190 /** 191 * Disables NFC. 192 * 193 * @permission ohos.permission.MANAGE_SECURE_SETTINGS 194 * @returns { boolean } Returns {@code true} if NFC is disabled or has been disabled; returns {@code false} otherwise. 195 * @syscap SystemCapability.Communication.NFC.Core 196 * @since 7 197 * @deprecated since 9 198 * @useinstead ohos.nfc.controller/nfcController#disableNfc 199 */ 200 function closeNfc(): boolean; 201 202 /** 203 * Disables NFC. 204 * This API can be called only by system applications 205 * 206 * @permission ohos.permission.MANAGE_SECURE_SETTINGS 207 * @throws { BusinessError } 201 - Permission denied. 208 * @throws { BusinessError } 801 - Capability not supported. 209 * @throws { BusinessError } 3100101 - The NFC state is abnormal in the service. 210 * @syscap SystemCapability.Communication.NFC.Core 211 * @since 9 212 */ 213 function disableNfc(): void; 214 215 /** 216 * Checks whether NFC is enabled. 217 * 218 * @returns { boolean } Returns {@code true} if NFC is enabled; returns {@code false} otherwise. 219 * @syscap SystemCapability.Communication.NFC.Core 220 * @since 7 221 */ 222 /** 223 * Checks whether NFC is enabled. 224 * 225 * @returns { boolean } Returns {@code true} if NFC is enabled; returns {@code false} otherwise. 226 * @syscap SystemCapability.Communication.NFC.Core 227 * @atomicservice 228 * @since 12 229 */ 230 function isNfcOpen(): boolean; 231 232 /** 233 * Obtains the NFC status. 234 * <p>The NFC status can be any of the following: <ul><li>{@link #STATE_OFF}: Indicates that NFC 235 * is disabled. <li>{@link #STATE_TURNING_ON}: Indicates that NFC is being enabled. 236 * <li>{@link #STATE_ON}: Indicates that NFC is enabled. <li>{@link #STATE_TURNING_OFF}: Indicates 237 * that NFC is being disabled.</ul> 238 * 239 * @returns { NfcState } Returns the NFC status. 240 * @syscap SystemCapability.Communication.NFC.Core 241 * @since 7 242 */ 243 /** 244 * Obtains the NFC status. 245 * <p>The NFC status can be any of the following: <ul><li>{@link #STATE_OFF}: Indicates that NFC 246 * is disabled. <li>{@link #STATE_TURNING_ON}: Indicates that NFC is being enabled. 247 * <li>{@link #STATE_ON}: Indicates that NFC is enabled. <li>{@link #STATE_TURNING_OFF}: Indicates 248 * that NFC is being disabled.</ul> 249 * 250 * @returns { NfcState } Returns the NFC status. 251 * @syscap SystemCapability.Communication.NFC.Core 252 * @atomicservice 253 * @since 12 254 */ 255 function getNfcState(): NfcState; 256} 257 258export default nfcController; 259