ohos-nfcManager Interface Report
Overview
ohos-nfcManager is a CLI tool for querying and controlling device NFC function status. It provides NFC state query and control capabilities through the NfcController singleton interface.
Target Users: LLM Agent / Automation scripts
Use Cases: NFC state query, switch control, operation and maintenance inspection
Interface Source
Selected Layer: NfcController singleton class in interfaces/inner_api/controller/nfc_controller.h
Selection Reasons:
- This class encapsulates IDL proxy calls and provides synchronous interfaces
- It is the official entry point for system NFC control
- No need to handle underlying IPC details
- Clear interface signatures, suitable for CLI encapsulation
Related Files:
| File |
Description |
interfaces/inner_api/controller/nfc_controller.h |
Header file |
interfaces/inner_api/controller/idl/INfcController.idl |
IDL definition |
interfaces/inner_api/controller/nfc_controller.cpp |
Implementation |
Architecture
ohos-nfcManager (CLI Entry)
|
v
main.cpp
|
v
NfcController::GetInstance() ---> NfcService (SA)
|
v
Synchronous IPC Call
Flow Description
- CLI receives action argument from command line
- Lookup action in
ACTION_TABLE dispatch table
- Call corresponding handler function
- Handler invokes
NfcController singleton method
NfcController makes synchronous IPC call to NfcService
- Return result via JSON output to stdout
CLI Subcommand Mapping
| CLI Subcommand |
Corresponding Interface |
Description |
get-state |
NfcController::GetNfcState() |
Get current NFC state |
turn-on |
NfcController::TurnOn() |
Turn on NFC |
turn-off |
NfcController::TurnOff() |
Turn off NFC |
is-available |
NfcController::IsNfcAvailable() |
Check if device supports NFC |
Unencapsulated Interfaces
| Interface Name |
Reason for Not Encapsulating |
RegListener |
Callback interface, requires event loop support, not suitable for CLI |
UnregListener |
Callback interface, used with RegListener |
RegNdefMsgCb |
Callback interface, used for NDEF message subscription |
GetTagServiceIface |
Returns IRemoteObject, non-atomic data, not suitable for direct CLI output |
GetHceServiceIface |
Returns IRemoteObject, non-atomic data |
Usage
Syntax
ohos-nfcManager <action>
Examples
Get NFC State
ohos-nfcManager get-state
Turn On NFC
ohos-nfcManager turn-on
Turn Off NFC
ohos-nfcManager turn-off
Check Device NFC Support
ohos-nfcManager is-available
Error Response Example
ohos-nfcManager turn-on
Help
ohos-nfcManager --help
ohos-nfcManager -h
ohos-nfcManager help
Success Response
{"type":"result","status":"success","data":{...}}
Error Response
{"type":"result","status":"failed","errCode":"<error_code>","errMsg":"<error_message>","suggestion":"<suggestion>"}
Error Codes
| Code |
Description |
E_NFC_SA_UNAVAILABLE |
NFC service unavailable |
E_NFC_OPERATION_FAILED |
NFC operation failed |
E_INVALID_ACTION |
Invalid action parameter |
E_TIMEOUT |
Operation timeout (15 seconds) |
Behavior Constraints
- Timeout Protection: 15 second timeout using alarm signal
- No Interactive Confirmation: All operations are non-interactive
- Idempotent Design: Repeated calls return current state without side effects
- Output Channels: stdout for JSON output, stderr for error logs
NFC State Codes
| Code |
State |
Description |
| 1 |
off |
NFC is turned off |
| 2 |
turning_on |
NFC is turning on |
| 3 |
on |
NFC is turned on |
| 4 |
turning_off |
NFC is turning off |
File List
| File Path |
Description |
tools/ohos-nfcManager/src/main.cpp |
Main program implementation |
tools/ohos-nfcManager/BUILD.gn |
Build configuration |
tools/ohos-nfcManager/ohos-nfcManager.json |
CLI configuration file |
tools/ohos-nfcManager/docs/README.md |
This document |
tools/ohos-nfcManager/docs/USAGE.md |
Usage guide |
Dependencies
deps = [
"//foundation/communication/nfc/interfaces/inner_api/controller:nfc_inner_kits_controller",
]
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",
"samgr:samgr_proxy",
]