1 /* 2 * Copyright 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.libraries.testing.deviceshadower; 18 19 import android.os.ParcelUuid; 20 21 /** 22 * User interface for mocking and simulation of a Bluetooth device. 23 */ 24 public interface Bluelet { 25 26 /** 27 * See {@link #setCreateBondOutcome}. 28 */ 29 enum CreateBondOutcome { 30 SUCCESS, 31 FAILURE, 32 TIMEOUT 33 } 34 35 /** 36 * See {@link #setIoCapabilities}. Note that Bluetooth specifies a few more choices, but this is 37 * all DeviceShadower currently supports. 38 */ 39 enum IoCapabilities { 40 NO_INPUT_NO_OUTPUT, 41 DISPLAY_YES_NO, 42 KEYBOARD_ONLY 43 } 44 45 /** 46 * See {@link #setFetchUuidsTiming}. 47 */ 48 enum FetchUuidsTiming { 49 BEFORE_BONDING, 50 AFTER_BONDING, 51 NEVER 52 } 53 54 /** 55 * Set the initial state of the local Bluetooth adapter at the beginning of the test. 56 * <p>This method is not associated with broadcast event and is intended to be called at the 57 * beginning of the test. Allowed states: 58 * 59 * @see android.bluetooth.BluetoothAdapter#STATE_OFF 60 * @see android.bluetooth.BluetoothAdapter#STATE_ON 61 * </p> 62 */ setAdapterInitialState(int state)63 Bluelet setAdapterInitialState(int state) throws IllegalArgumentException; 64 65 /** 66 * Set the bluetooth class of the local Bluetooth device at the beginning of the test. 67 * <p> 68 * 69 * @see android.bluetooth.BluetoothClass.Device 70 * @see android.bluetooth.BluetoothClass.Service 71 */ setBluetoothClass(int bluetoothClass)72 Bluelet setBluetoothClass(int bluetoothClass); 73 74 /** 75 * Set the scan mode of the local Bluetooth device at the beginning of the test. 76 */ setScanMode(int scanMode)77 Bluelet setScanMode(int scanMode); 78 79 /** 80 * Set the Bluetooth profiles supported by this device (e.g. A2DP Sink). 81 */ setProfileUuids(ParcelUuid... profileUuids)82 Bluelet setProfileUuids(ParcelUuid... profileUuids); 83 84 /** 85 * Makes bond attempts with this device succeed or fail. 86 * 87 * @param failureReason Ignored unless outcome is {@link CreateBondOutcome#FAILURE}. This is 88 * delivered in the intent that indicates bond state has changed to BOND_NONE. Values: 89 * https://cs.corp.google.com/android/frameworks/base/core/java/android/bluetooth/BluetoothDevice.java?rcl=38d9ee4cd661c10e012f71051d23644c65607eed&l=472 90 */ setCreateBondOutcome(CreateBondOutcome outcome, int failureReason)91 Bluelet setCreateBondOutcome(CreateBondOutcome outcome, int failureReason); 92 93 /** 94 * Sets the IO capabilities of this device. When bonding, a device states its IO capabilities in 95 * the pairing request. The pairing variant used depends on the IO capabilities of both devices 96 * (e.g. Just Works is the only available option for a NoInputNoOutput device, while Numeric 97 * Comparison aka Passkey Confirmation is used if both devices have a display and the ability to 98 * confirm/deny). 99 * 100 * @see <a href="https://blog.bluetooth.com/bluetooth-pairing-part-4">Bluetooth blog</a> 101 */ setIoCapabilities(IoCapabilities ioCapabilities)102 Bluelet setIoCapabilities(IoCapabilities ioCapabilities); 103 104 /** 105 * Make the device refuse connections. By default, connections are accepted. 106 * 107 * @param refuse Connections are refused if True. 108 */ setRefuseConnections(boolean refuse)109 Bluelet setRefuseConnections(boolean refuse); 110 111 /** 112 * Make the device refuse GATT connections. By default. connections are accepted. 113 * 114 * @param refuse GATT connections are refused if true. 115 */ setRefuseGattConnections(boolean refuse)116 Bluelet setRefuseGattConnections(boolean refuse); 117 118 /** 119 * When to send the ACTION_UUID broadcast. This can be {@link FetchUuidsTiming#BEFORE_BONDING}, 120 * {@link FetchUuidsTiming#AFTER_BONDING}, or {@link FetchUuidsTiming#NEVER}. The default is 121 * {@link FetchUuidsTiming#AFTER_BONDING}. 122 */ setFetchUuidsTiming(FetchUuidsTiming fetchUuidsTiming)123 Bluelet setFetchUuidsTiming(FetchUuidsTiming fetchUuidsTiming); 124 125 /** 126 * Adds a bonded device to the BluetoothAdapter. 127 */ addBondedDevice(String address)128 Bluelet addBondedDevice(String address); 129 130 /** 131 * Enables the CVE-2019-2225 represents that the pairing variant will switch from Just Works to 132 * Consent when local device's io capability is Display Yes/No and remote is NoInputNoOutput. 133 * 134 * @see <a href="https://source.android.com/security/bulletin/2019-12-01#system">the security 135 * bulletin at 2019-12-01</a> 136 */ enableCVE20192225(boolean value)137 Bluelet enableCVE20192225(boolean value); 138 } 139