From 71c0d84243794ac0e70257d59ad4d6ec52930783 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 7 May 2024 20:58:26 +0200 Subject: [PATCH] feat: Add a helper method to enable/disable bluetooth (#737) --- lib/tools/adb-commands.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/tools/adb-commands.js b/lib/tools/adb-commands.js index d4e1c642..700d5e18 100644 --- a/lib/tools/adb-commands.js +++ b/lib/tools/adb-commands.js @@ -867,6 +867,20 @@ methods.setAirplaneMode = async function setAirplaneMode (on) { await this.shell(['cmd', 'connectivity', 'airplane-mode', on ? 'enable' : 'disable']); }; +/** + * Change the state of the bluetooth service on the device under test. + * + * @this {import('../adb.js').ADB} + * @param {boolean} on - True to enable bluetooth service and false to disable it. + */ +methods.setBluetoothOn = async function setBluetoothOn (on) { + if (await this.getApiLevel() < 30) { + throw new Error('Changing of the bluetooth state is not supported on your device'); + } + + await this.shell(['cmd', 'bluetooth_manager', on ? 'enable' : 'disable']); +}; + /** * Broadcast the state of Airplane mode on the device under test. * This method should be called after {@link #setAirplaneMode}, otherwise