Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 088248a2 authored by William Escande's avatar William Escande
Browse files

Cts Tests: Moved adapter utils to kotlin

Test: atest CtsBluetoothTests
Flag: TEST_ONLY
Bug: 339585576
Change-Id: I93f3a72863d55862968d3f13de71f46dc8145436
parent 540af4be
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -26,7 +26,10 @@ java_library {
        "compatibility-device-util-axt",
        "junit",
    ],
    srcs: ["src/**/*.java"],
    srcs: [
        "src/**/*.java",
        "src/BlockingBluetoothAdapter.kt",
    ],
    sdk_version: "test_current",
    // Keep it public for now to avoid merge conflicts
    visibility: ["//visibility:public"],
+291 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -13,283 +13,279 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.bluetooth.test_utils;

import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;

import android.app.UiAutomation;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;

import java.time.Duration;
import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
package android.bluetooth.test_utils

import android.Manifest.permission
import android.app.UiAutomation
import android.bluetooth.BluetoothAdapter
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.util.Log
import java.time.Duration
import java.util.concurrent.TimeUnit
import java.util.concurrent.locks.Condition
import java.util.concurrent.locks.ReentrantLock

/** Utility for controlling the Bluetooth adapter from CTS test. */
public class BluetoothAdapterUtils {
    private static final String TAG = BluetoothAdapterUtils.class.getSimpleName();
object BlockingBluetoothAdapter {
    private val TAG: String = BlockingBluetoothAdapter::class.java.getSimpleName()

    /**
     * ADAPTER_ENABLE_TIMEOUT_MS = AdapterState.BLE_START_TIMEOUT_DELAY +
     * AdapterState.BREDR_START_TIMEOUT_DELAY + (10 seconds of additional delay)
     */
    private static final Duration ADAPTER_ENABLE_TIMEOUT = Duration.ofSeconds(18);
    private val ADAPTER_ENABLE_TIMEOUT = Duration.ofSeconds(18)

    /**
     * ADAPTER_DISABLE_TIMEOUT_MS = AdapterState.BLE_STOP_TIMEOUT_DELAY +
     * AdapterState.BREDR_STOP_TIMEOUT_DELAY
     */
    private static final Duration ADAPTER_DISABLE_TIMEOUT = Duration.ofSeconds(5);

    /** Redefined from {@link BluetoothAdapter} because of hidden APIs */
    public static final int STATE_BLE_TURNING_ON = 14;

    public static final int STATE_BLE_TURNING_OFF = 16;
    private val ADAPTER_DISABLE_TIMEOUT = Duration.ofSeconds(5)

    private static final HashMap<Integer, Duration> sStateTimeouts = new HashMap<>();
    /** Redefined from [BluetoothAdapter] because of hidden APIs */
    const val STATE_BLE_TURNING_ON = 14
    const val STATE_BLE_TURNING_OFF = 16
    private val sStateTimeouts = HashMap<Int, Duration>()

    static {
        sStateTimeouts.put(BluetoothAdapter.STATE_OFF, ADAPTER_DISABLE_TIMEOUT);
        sStateTimeouts.put(BluetoothAdapter.STATE_TURNING_ON, ADAPTER_ENABLE_TIMEOUT);
        sStateTimeouts.put(BluetoothAdapter.STATE_ON, ADAPTER_ENABLE_TIMEOUT);
        sStateTimeouts.put(BluetoothAdapter.STATE_TURNING_OFF, ADAPTER_DISABLE_TIMEOUT);
        sStateTimeouts.put(STATE_BLE_TURNING_ON, ADAPTER_ENABLE_TIMEOUT);
        sStateTimeouts.put(BluetoothAdapter.STATE_BLE_ON, ADAPTER_ENABLE_TIMEOUT);
        sStateTimeouts.put(STATE_BLE_TURNING_OFF, ADAPTER_DISABLE_TIMEOUT);
    init {
        sStateTimeouts.put(BluetoothAdapter.STATE_OFF, ADAPTER_DISABLE_TIMEOUT)
        sStateTimeouts.put(BluetoothAdapter.STATE_TURNING_ON, ADAPTER_ENABLE_TIMEOUT)
        sStateTimeouts.put(BluetoothAdapter.STATE_ON, ADAPTER_ENABLE_TIMEOUT)
        sStateTimeouts.put(BluetoothAdapter.STATE_TURNING_OFF, ADAPTER_DISABLE_TIMEOUT)
        sStateTimeouts.put(STATE_BLE_TURNING_ON, ADAPTER_ENABLE_TIMEOUT)
        sStateTimeouts.put(BluetoothAdapter.STATE_BLE_ON, ADAPTER_ENABLE_TIMEOUT)
        sStateTimeouts.put(STATE_BLE_TURNING_OFF, ADAPTER_DISABLE_TIMEOUT)
    }

    private static boolean sAdapterVarsInitialized;
    private static ReentrantLock sBluetoothAdapterLock;
    private static Condition sConditionAdapterStateReached;
    private static int sDesiredState;
    private static int sAdapterState;

    /** Handles BluetoothAdapter state changes and signals when we have reached a desired state */
    private static class BluetoothAdapterReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (BluetoothAdapter.ACTION_BLE_STATE_CHANGED.equals(action)) {
                int newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
                Log.d(TAG, "Bluetooth adapter state changed: " + newState);

                // Signal if the state is set to the one we are waiting on
                sBluetoothAdapterLock.lock();
                try {
                    sAdapterState = newState;
                    if (sDesiredState == newState) {
                        Log.d(TAG, "Adapter has reached desired state: " + sDesiredState);
                        sConditionAdapterStateReached.signal();
                    }
                } finally {
                    sBluetoothAdapterLock.unlock();
                }
            }
        }
    }
    private var sAdapterVarsInitialized = false
    private var sBluetoothAdapterLock: ReentrantLock? = null
    private var sConditionAdapterStateReached: Condition? = null
    private var sDesiredState = 0
    private var sAdapterState = 0

    /** Initialize all static state variables */
    private static void initAdapterStateVariables(Context context) {
        Log.d(TAG, "Initializing adapter state variables");
        BluetoothAdapterReceiver sAdapterReceiver = new BluetoothAdapterReceiver();
        sBluetoothAdapterLock = new ReentrantLock();
        sConditionAdapterStateReached = sBluetoothAdapterLock.newCondition();
        sDesiredState = -1;
        sAdapterState = -1;
        IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_BLE_STATE_CHANGED);
        context.registerReceiver(sAdapterReceiver, filter);
        sAdapterVarsInitialized = true;
    private fun initAdapterStateVariables(context: Context) {
        Log.d(TAG, "Initializing adapter state variables")
        val sAdapterReceiver = BluetoothAdapterReceiver()
        sBluetoothAdapterLock = ReentrantLock()
        sConditionAdapterStateReached = sBluetoothAdapterLock!!.newCondition()
        sDesiredState = -1
        sAdapterState = -1
        val filter: IntentFilter = IntentFilter(BluetoothAdapter.ACTION_BLE_STATE_CHANGED)
        context.registerReceiver(sAdapterReceiver, filter)
        sAdapterVarsInitialized = true
    }

    /**
     * Helper method to wait for the bluetooth adapter to be in a given state
     *
     * <p>Assumes all state variables are initialized. Assumes it's being run with
     * Assumes all state variables are initialized. Assumes it's being run with
     * sBluetoothAdapterLock in the locked state.
     */
    private static boolean waitForAdapterStateLocked(int desiredState, BluetoothAdapter adapter)
            throws InterruptedException {
        Duration timeout = sStateTimeouts.getOrDefault(desiredState, ADAPTER_ENABLE_TIMEOUT);

        Log.d(TAG, "Waiting for adapter state " + desiredState);
        sDesiredState = desiredState;
    @kotlin.Throws(InterruptedException::class)
    private fun waitForAdapterStateLocked(desiredState: Int, adapter: BluetoothAdapter): Boolean {
        val timeout = sStateTimeouts.getOrDefault(desiredState, ADAPTER_ENABLE_TIMEOUT)
        Log.d(TAG, "Waiting for adapter state $desiredState")
        sDesiredState = desiredState

        // Wait until we have reached the desired state
        // Handle spurious wakeup
        while (desiredState != sAdapterState) {
            if (sConditionAdapterStateReached.await(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
            if (sConditionAdapterStateReached!!.await(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
                // Handle spurious wakeup
                continue;
                continue
            }
            // Handle timeout cases
            // Case 1: situation where state change occurs, but we don't receive the broadcast
            if (desiredState >= BluetoothAdapter.STATE_OFF
                    && desiredState <= BluetoothAdapter.STATE_TURNING_OFF) {
                int currentState = adapter.getState();
                Log.d(TAG, "desiredState: " + desiredState + ", currentState: " + currentState);
                return desiredState == currentState;
            if (
                desiredState >= BluetoothAdapter.STATE_OFF &&
                    desiredState <= BluetoothAdapter.STATE_TURNING_OFF
            ) {
                val currentState = adapter.state
                Log.d(TAG, "desiredState: $desiredState, currentState: $currentState")
                return desiredState == currentState
            } else if (desiredState == BluetoothAdapter.STATE_BLE_ON) {
                Log.d(TAG, "adapter isLeEnabled: " + adapter.isLeEnabled());
                return adapter.isLeEnabled();
                Log.d(TAG, "adapter isLeEnabled: " + adapter.isLeEnabled())
                return adapter.isLeEnabled()
            }
            // Case 2: Actual timeout
            Log.e(
                TAG,
                    "Timeout while waiting for Bluetooth adapter state "
                            + desiredState
                            + " while current state is "
                            + sAdapterState);
            break;
                "Timeout while waiting for Bluetooth adapter state " +
                    desiredState +
                    " while current state is " +
                    sAdapterState,
            )
            break
        }

        Log.d(TAG, "Final state while waiting: " + sAdapterState);
        return sAdapterState == desiredState;
        Log.d(TAG, "Final state while waiting: " + sAdapterState)
        return sAdapterState == desiredState
    }

    /** Utility method to wait on any specific adapter state */
    public static boolean waitForAdapterState(int desiredState, BluetoothAdapter adapter) {
        sBluetoothAdapterLock.lock();
    fun waitForAdapterState(desiredState: Int, adapter: BluetoothAdapter): Boolean {
        sBluetoothAdapterLock!!.lock()
        try {
            return waitForAdapterStateLocked(desiredState, adapter);
        } catch (InterruptedException e) {
            Log.w(TAG, "waitForAdapterState(): interrupted", e);
            return waitForAdapterStateLocked(desiredState, adapter)
        } catch (e: InterruptedException) {
            Log.w(TAG, "waitForAdapterState(): interrupted", e)
        } finally {
            sBluetoothAdapterLock.unlock();
            sBluetoothAdapterLock!!.unlock()
        }
        return false;
        return false
    }

    /** Enables Bluetooth to a Low Energy only mode */
    public static boolean enableBLE(BluetoothAdapter bluetoothAdapter, Context context) {
    @JvmStatic
    fun enableBLE(bluetoothAdapter: BluetoothAdapter, context: Context): Boolean {
        if (!sAdapterVarsInitialized) {
            initAdapterStateVariables(context);
            initAdapterStateVariables(context)
        }

        if (bluetoothAdapter.isLeEnabled()) {
            return true;
            return true
        }

        sBluetoothAdapterLock.lock();
        sBluetoothAdapterLock!!.lock()
        try {
            Log.d(TAG, "Enabling Bluetooth low energy only mode");
            Log.d(TAG, "Enabling Bluetooth low energy only mode")
            if (!bluetoothAdapter.enableBLE()) {
                Log.e(TAG, "Unable to enable Bluetooth low energy only mode");
                return false;
                Log.e(TAG, "Unable to enable Bluetooth low energy only mode")
                return false
            }
            return waitForAdapterStateLocked(BluetoothAdapter.STATE_BLE_ON, bluetoothAdapter);
        } catch (InterruptedException e) {
            Log.w(TAG, "enableBLE(): interrupted", e);
            return waitForAdapterStateLocked(BluetoothAdapter.STATE_BLE_ON, bluetoothAdapter)
        } catch (e: InterruptedException) {
            Log.w(TAG, "enableBLE(): interrupted", e)
        } finally {
            sBluetoothAdapterLock.unlock();
            sBluetoothAdapterLock!!.unlock()
        }
        return false;
        return false
    }

    /** Disable Bluetooth Low Energy mode */
    public static boolean disableBLE(BluetoothAdapter bluetoothAdapter, Context context) {
    @JvmStatic
    fun disableBLE(bluetoothAdapter: BluetoothAdapter, context: Context): Boolean {
        if (!sAdapterVarsInitialized) {
            initAdapterStateVariables(context);
            initAdapterStateVariables(context)
        }

        if (bluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
            return true;
        if (bluetoothAdapter.state == BluetoothAdapter.STATE_OFF) {
            return true
        }

        sBluetoothAdapterLock.lock();
        sBluetoothAdapterLock!!.lock()
        try {
            Log.d(TAG, "Disabling Bluetooth low energy");
            bluetoothAdapter.disableBLE();
            return waitForAdapterStateLocked(BluetoothAdapter.STATE_OFF, bluetoothAdapter);
        } catch (InterruptedException e) {
            Log.w(TAG, "disableBLE(): interrupted", e);
            Log.d(TAG, "Disabling Bluetooth low energy")
            bluetoothAdapter.disableBLE()
            return waitForAdapterStateLocked(BluetoothAdapter.STATE_OFF, bluetoothAdapter)
        } catch (e: InterruptedException) {
            Log.w(TAG, "disableBLE(): interrupted", e)
        } finally {
            sBluetoothAdapterLock.unlock();
            sBluetoothAdapterLock!!.unlock()
        }
        return false;
        return false
    }

    /** Enables the Bluetooth Adapter. Return true if it is already enabled or is enabled. */
    public static boolean enableAdapter(BluetoothAdapter bluetoothAdapter, Context context) {
    @JvmStatic
    fun enableAdapter(bluetoothAdapter: BluetoothAdapter, context: Context): Boolean {
        if (!sAdapterVarsInitialized) {
            initAdapterStateVariables(context);
        }

        if (bluetoothAdapter.isEnabled()) {
            return true;
            initAdapterStateVariables(context)
        }

        Set<String> permissionsAdopted = TestUtils.getAdoptedShellPermissions();
        String[] permissionArray = permissionsAdopted.toArray(String[]::new);
        if (UiAutomation.ALL_PERMISSIONS.equals(permissionsAdopted)) {
            permissionArray = null;
        if (bluetoothAdapter.isEnabled) {
            return true
        }

        sBluetoothAdapterLock.lock();
        val permissionsAdopted: Set<String> = TestUtils.getAdoptedShellPermissions()
        sBluetoothAdapterLock!!.lock()
        try {
            Log.d(TAG, "Enabling Bluetooth adapter");
            TestUtils.dropPermissionAsShellUid();
            TestUtils.adoptPermissionAsShellUid(BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED);
            bluetoothAdapter.enable();
            return waitForAdapterStateLocked(BluetoothAdapter.STATE_ON, bluetoothAdapter);
        } catch (InterruptedException e) {
            Log.w(TAG, "enableAdapter(): interrupted", e);
            Log.d(TAG, "Enabling Bluetooth adapter")
            TestUtils.dropPermissionAsShellUid()
            TestUtils.adoptPermissionAsShellUid(
                permission.BLUETOOTH_CONNECT,
                permission.BLUETOOTH_PRIVILEGED,
            )
            bluetoothAdapter.enable()
            return waitForAdapterStateLocked(BluetoothAdapter.STATE_ON, bluetoothAdapter)
        } catch (e: InterruptedException) {
            Log.w(TAG, "enableAdapter(): interrupted", e)
        } finally {
            TestUtils.dropPermissionAsShellUid();
            TestUtils.adoptPermissionAsShellUid(permissionArray);
            sBluetoothAdapterLock.unlock();
            TestUtils.dropPermissionAsShellUid()
            if (UiAutomation.ALL_PERMISSIONS.equals(permissionsAdopted)) {
                TestUtils.adoptPermissionAsShellUid()
            } else {
                TestUtils.adoptPermissionAsShellUid(*permissionsAdopted.map { it }.toTypedArray())
            }
            sBluetoothAdapterLock!!.unlock()
        }
        return false;
        return false
    }

    /** Disable the Bluetooth Adapter. Return true if it is already disabled or is disabled. */
    public static boolean disableAdapter(BluetoothAdapter bluetoothAdapter, Context context) {
        return disableAdapter(bluetoothAdapter, true, context);
    @JvmStatic
    fun disableAdapter(bluetoothAdapter: BluetoothAdapter, context: Context): Boolean {
        return disableAdapter(bluetoothAdapter, true, context)
    }

    /**
     * Disable the Bluetooth Adapter with then option to persist the off state or not.
     *
     * <p>Returns true if the adapter is already disabled or was disabled.
     * Returns true if the adapter is already disabled or was disabled.
     */
    public static boolean disableAdapter(
            BluetoothAdapter bluetoothAdapter, boolean persist, Context context) {
    @JvmStatic
    fun disableAdapter(
        bluetoothAdapter: BluetoothAdapter,
        persist: Boolean,
        context: Context,
    ): Boolean {
        if (!sAdapterVarsInitialized) {
            initAdapterStateVariables(context);
            initAdapterStateVariables(context)
        }

        if (bluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
            return true;
        if (bluetoothAdapter.state == BluetoothAdapter.STATE_OFF) {
            return true
        }

        Set<String> permissionsAdopted = TestUtils.getAdoptedShellPermissions();
        String[] permissionArray = permissionsAdopted.toArray(String[]::new);
        val permissionsAdopted: Set<String> = TestUtils.getAdoptedShellPermissions()
        sBluetoothAdapterLock!!.lock()
        try {
            Log.d(TAG, "Disabling Bluetooth adapter, persist=$persist")
            TestUtils.dropPermissionAsShellUid()
            TestUtils.adoptPermissionAsShellUid(
                permission.BLUETOOTH_CONNECT,
                permission.BLUETOOTH_PRIVILEGED,
            )
            bluetoothAdapter.disable(persist)
            return waitForAdapterStateLocked(BluetoothAdapter.STATE_OFF, bluetoothAdapter)
        } catch (e: InterruptedException) {
            Log.w(TAG, "disableAdapter(persist=$persist): interrupted", e)
        } finally {
            TestUtils.dropPermissionAsShellUid()
            if (UiAutomation.ALL_PERMISSIONS.equals(permissionsAdopted)) {
            permissionArray = null;
                TestUtils.adoptPermissionAsShellUid()
            } else {
                TestUtils.adoptPermissionAsShellUid(*permissionsAdopted.map { it }.toTypedArray())
            }
            sBluetoothAdapterLock!!.unlock()
        }
        return false
    }

        sBluetoothAdapterLock.lock();
    /** Handles BluetoothAdapter state changes and signals when we have reached a desired state */
    private class BluetoothAdapterReceiver : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            val action = intent.action
            if (BluetoothAdapter.ACTION_BLE_STATE_CHANGED.equals(action)) {
                val newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1)
                Log.d(TAG, "Bluetooth adapter state changed: $newState")

                // Signal if the state is set to the one we are waiting on
                sBluetoothAdapterLock!!.lock()
                try {
            Log.d(TAG, "Disabling Bluetooth adapter, persist=" + persist);
            TestUtils.dropPermissionAsShellUid();
            TestUtils.adoptPermissionAsShellUid(BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED);
            bluetoothAdapter.disable(persist);
            return waitForAdapterStateLocked(BluetoothAdapter.STATE_OFF, bluetoothAdapter);
        } catch (InterruptedException e) {
            Log.w(TAG, "disableAdapter(persist=" + persist + "): interrupted", e);
                    sAdapterState = newState
                    if (sDesiredState == newState) {
                        Log.d(TAG, "Adapter has reached desired state: " + sDesiredState)
                        sConditionAdapterStateReached!!.signal()
                    }
                } finally {
            TestUtils.dropPermissionAsShellUid();
            TestUtils.adoptPermissionAsShellUid(permissionArray);
            sBluetoothAdapterLock.unlock();
                    sBluetoothAdapterLock!!.unlock()
                }
            }
        }
        return false;
    }
}
+51 −2
Original line number Diff line number Diff line
@@ -16,6 +16,55 @@

package android.bluetooth.cts;

import android.bluetooth.test_utils.BluetoothAdapterUtils;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.test_utils.BlockingBluetoothAdapter;
import android.content.Context;

public class BTAdapterUtils extends BluetoothAdapterUtils {}
/**
 * @deprecated see {@link android.bluetooth.test_utils.BlockingBluetoothAdapter}
 */
@Deprecated
public class BTAdapterUtils {
    private BTAdapterUtils() {}

    /**
     * @deprecated see {@link android.bluetooth.test_utils.BlockingBluetoothAdapter#enable}
     */
    @Deprecated
    public static final boolean enableAdapter(BluetoothAdapter adapter, Context ctx) {
        return BlockingBluetoothAdapter.enableAdapter(adapter, ctx);
    }

    /**
     * @deprecated see {@link android.bluetooth.test_utils.BlockingBluetoothAdapter#disable}
     */
    @Deprecated
    public static final boolean disableAdapter(BluetoothAdapter adapter, Context ctx) {
        return BlockingBluetoothAdapter.disableAdapter(adapter, ctx);
    }

    /**
     * @deprecated see {@link android.bluetooth.test_utils.BlockingBluetoothAdapter#disable}
     */
    @Deprecated
    public static final boolean disableAdapter(
            BluetoothAdapter adapter, boolean persist, Context ctx) {
        return BlockingBluetoothAdapter.disableAdapter(adapter, persist, ctx);
    }

    /**
     * @deprecated see {@link android.bluetooth.test_utils.BlockingBluetoothAdapter#enableBLE}
     */
    @Deprecated
    public static final boolean enableBLE(BluetoothAdapter adapter, Context ctx) {
        return BlockingBluetoothAdapter.enableBLE(adapter, ctx);
    }

    /**
     * @deprecated see {@link android.bluetooth.test_utils.BlockingBluetoothAdapter#disableBLE}
     */
    @Deprecated
    public static final boolean disableBLE(BluetoothAdapter adapter, Context ctx) {
        return BlockingBluetoothAdapter.disableBLE(adapter, ctx);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -77,11 +77,11 @@ public class EnableBluetoothRule extends BeforeAfterRule {
    }

    private void enableBluetoothAdapter() {
        assertThat(BluetoothAdapterUtils.enableAdapter(mBluetoothAdapter, mContext)).isTrue();
        assertThat(BlockingBluetoothAdapter.enableAdapter(mBluetoothAdapter, mContext)).isTrue();
    }

    private void disableBluetoothAdapter() {
        assertThat(BluetoothAdapterUtils.disableAdapter(mBluetoothAdapter, mContext)).isTrue();
        assertThat(BlockingBluetoothAdapter.disableAdapter(mBluetoothAdapter, mContext)).isTrue();
    }

    private void enableBluetoothTestMode() {