Skip to content

Commit

Permalink
feat: Add a method to control NFC adapter state (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed May 9, 2024
1 parent 6dba9e4 commit 5c6556f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/tools/adb-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,26 @@ methods.setBluetoothOn = async function setBluetoothOn (on) {
await this.shell(['cmd', 'bluetooth_manager', on ? 'enable' : 'disable']);
};

/**
* Change the state of the NFC service on the device under test.
*
* @this {import('../adb.js').ADB}
* @param {boolean} on - True to enable NFC service and false to disable it.
* @throws {Error} If there was an error while changing the service state
*/
methods.setNfcOn = async function setNfcOn (on) {
const {stdout, stderr} = await this.shell(['svc', 'nfc', on ? 'enable' : 'disable'], {
outputFormat: 'full'
});
const output = stderr || stdout;
log.debug(output);
if (output.includes('null NfcAdapter')) {
throw new Error(
`Cannot turn ${on ? 'on' : 'off'} the NFC adapter. Does the device under test have it?`
);
}
};

/**
* Broadcast the state of Airplane mode on the device under test.
* This method should be called after {@link #setAirplaneMode}, otherwise
Expand Down

0 comments on commit 5c6556f

Please sign in to comment.