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.internal.bluetooth; 18 19 /** 20 * A class to hold Bluetooth constants. 21 */ 22 public class BluetoothConstants { 23 24 /*** Bluetooth Adapter State ***/ 25 // Must be identical to BluetoothAdapter hidden field STATE_BLE_TURNING_ON 26 public static final int STATE_BLE_TURNING_ON = 14; 27 28 // Must be identical to BluetoothAdapter hidden field STATE_BLE_ON 29 public static final int STATE_BLE_ON = 15; 30 31 // Must be identical to BluetoothAdapter hidden field STATE_BLE_TURNING_OFF 32 public static final int STATE_BLE_TURNING_OFF = 16; 33 34 // Must be identical to BluetoothAdapter hidden field ACTION_BLE_STATE_CHANGED 35 public static final String ACTION_BLE_STATE_CHANGED = 36 "android.bluetooth.adapter.action.BLE_STATE_CHANGED"; 37 38 /*** Rfcomm Socket ***/ 39 // Must be identical to BluetoothSocket field TYPE_RFCOMM. 40 // The field was package-private before M. 41 public static final int TYPE_RFCOMM = 1; 42 43 public static final int SOCKET_CLOSE = -10000; 44 45 // Android Bluetooth use -1 as port when creating server socket with uuid 46 public static final int SERVER_SOCKET_CHANNEL_AUTO_ASSIGN = -1; 47 48 // Android Bluetooth use -1 as port when creating socket with a uuid 49 public static final int SOCKET_CHANNEL_CONNECT_WITH_UUID = -1; 50 51 /*** BLE Advertise/Scan ***/ 52 // Must be identical to AdvertiseCallback hidden field ADVERTISE_SUCCESS. 53 public static final int ADVERTISE_SUCCESS = 0; 54 55 // Must be identical to ScanRecord field DATA_TYPE_FLAGS. 56 public static final int DATA_TYPE_FLAGS = 0x01; 57 58 // Must be identical to ScanRecord field DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE. 59 public static final int DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE = 0x07; 60 61 // Must be identical to ScanRecord field DATA_TYPE_LOCAL_NAME_COMPLETE. 62 public static final int DATA_TYPE_LOCAL_NAME_COMPLETE = 0x09; 63 64 // Must be identical to ScanRecord field DATA_TYPE_TX_POWER_LEVEL. 65 public static final int DATA_TYPE_TX_POWER_LEVEL = 0x0A; 66 67 // Must be identical to ScanRecord field DATA_TYPE_SERVICE_DATA. 68 public static final int DATA_TYPE_SERVICE_DATA = 0x16; 69 70 // Must be identical to ScanRecord field DATA_TYPE_MANUFACTURER_SPECIFIC_DATA. 71 public static final int DATA_TYPE_MANUFACTURER_SPECIFIC_DATA = 0xFF; 72 73 /** 74 * @see #DATA_TYPE_FLAGS 75 */ 76 public interface Flags { 77 78 byte LE_LIMITED_DISCOVERABLE_MODE = 1; 79 byte LE_GENERAL_DISCOVERABLE_MODE = 1 << 1; 80 byte BR_EDR_NOT_SUPPORTED = 1 << 2; 81 byte SIMULTANEOUS_LE_AND_BR_EDR_CONTROLLER = 1 << 3; 82 byte SIMULTANEOUS_LE_AND_BR_EDR_HOST = 1 << 4; 83 } 84 85 /** 86 * Observed that Android sets this for {@link #DATA_TYPE_FLAGS} when a packet is connectable (on 87 * a Nexus 6P running 7.1.2). 88 */ 89 public static final byte FLAGS_IN_CONNECTABLE_PACKETS = 90 Flags.BR_EDR_NOT_SUPPORTED 91 | Flags.LE_GENERAL_DISCOVERABLE_MODE 92 | Flags.SIMULTANEOUS_LE_AND_BR_EDR_CONTROLLER 93 | Flags.SIMULTANEOUS_LE_AND_BR_EDR_HOST; 94 } 95