RemoteDevices.java revision fd1da115cbf09b7dd9bca3c7d3a4fb816a835dc5
1ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh/* 2ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * Copyright (C) 2012 Google Inc. 3ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 4ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 5ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshpackage com.android.bluetooth.btservice; 6ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 7ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport android.bluetooth.BluetoothAdapter; 8ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport android.bluetooth.BluetoothClass; 9ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport android.bluetooth.BluetoothDevice; 10ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport android.content.Context; 11ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport android.content.Intent; 12ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport android.os.Handler; 13ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport android.os.Message; 14ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport android.os.ParcelUuid; 15ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport android.util.Log; 16ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 17ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport com.android.bluetooth.Utils; 18ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport com.android.bluetooth.btservice.RemoteDevices.DeviceProperties; 19ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 20ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport java.util.ArrayList; 21ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport java.util.HashMap; 22ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshimport java.util.LinkedList; 23ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 24ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 25ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganeshfinal class RemoteDevices { 26fd1da115cbf09b7dd9bca3c7d3a4fb816a835dc5Matthew Xie private static final boolean DBG = false; 27ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private static final String TAG = "BluetoothRemoteDevices"; 28ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 2974ae04c73312403e89db0f8e9bd9601d403b4783fredc 30ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private static BluetoothAdapter mAdapter; 31ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private static AdapterService mAdapterService; 32ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private static ArrayList<BluetoothDevice> mSdpTracker; 33ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 34ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private Object mObject = new Object(); 35ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 36ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private static final int UUID_INTENT_DELAY = 6000; 37ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private static final int MESSAGE_UUID_INTENT = 1; 38ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 39ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private HashMap<BluetoothDevice, DeviceProperties> mDevices; 40ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 4174ae04c73312403e89db0f8e9bd9601d403b4783fredc RemoteDevices(AdapterService service) { 42ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mAdapter = BluetoothAdapter.getDefaultAdapter(); 43ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mAdapterService = service; 44ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mSdpTracker = new ArrayList<BluetoothDevice>(); 45ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mDevices = new HashMap<BluetoothDevice, DeviceProperties>(); 46ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 47ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 48ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 4974ae04c73312403e89db0f8e9bd9601d403b4783fredc void cleanup() { 5015d36984a79d6e35c659edb0efdf929f0b526bd5Fred if (mSdpTracker !=null) 5115d36984a79d6e35c659edb0efdf929f0b526bd5Fred mSdpTracker.clear(); 5215d36984a79d6e35c659edb0efdf929f0b526bd5Fred 5315d36984a79d6e35c659edb0efdf929f0b526bd5Fred if (mDevices != null) 5415d36984a79d6e35c659edb0efdf929f0b526bd5Fred mDevices.clear(); 556654f5c903de510a70f9e72cd5ad7837b615d93ffredc } 566654f5c903de510a70f9e72cd5ad7837b615d93ffredc 57ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh public Object Clone() throws CloneNotSupportedException { 58ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh throw new CloneNotSupportedException(); 59ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 60ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 61ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties getDeviceProperties(BluetoothDevice device) { 62ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mDevices) { 63ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mDevices.get(device); 64ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 65ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 66ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 67ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice getDevice(byte[] address) { 68ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh for (BluetoothDevice dev : mDevices.keySet()) { 69ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (dev.getAddress().equals(Utils.getAddressStringFromByte(address))) { 70ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return dev; 71ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 72ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 73ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return null; 74ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 75ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 76ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties addDeviceProperties(byte[] address) { 77ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mDevices) { 78ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties prop = new DeviceProperties(); 79ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice device = 80ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mAdapter.getRemoteDevice(Utils.getAddressStringFromByte(address)); 8174a598e0a8d50343227e3f96bbe56c6be1c240f9Ganesh Ganapathi Batta prop.mAddress = address; 82ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mDevices.put(device, prop); 83ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return prop; 84ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 85ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 86ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 87ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh class DeviceProperties { 88ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private String mName; 89ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private byte[] mAddress; 90ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private int mBluetoothClass; 91ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private short mRssi; 92ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private ParcelUuid[] mUuids; 93ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private int mDeviceType; 94ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private String mAlias; 95ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private int mBondState; 96ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 97ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties() { 98ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mBondState = BluetoothDevice.BOND_NONE; 99ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 100ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 101ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 102ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @return the mName 103ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 104ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh String getName() { 105ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 106ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mName; 107ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 108ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 109ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 110ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 111ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @return the mClass 112ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 113ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int getBluetoothClass() { 114ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 115ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mBluetoothClass; 116ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 117ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 118ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 119ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 120ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @return the mUuids 121ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 122ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh ParcelUuid[] getUuids() { 123ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 124ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mUuids; 125ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 126ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 127ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 128ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 129ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @return the mAddress 130ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 131ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh byte[] getAddress() { 132ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 133ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mAddress; 134ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 135ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 136ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 137ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 138ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @return mRssi 139ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 140ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh short getRssi() { 141ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 142ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mRssi; 143ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 144ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 145ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 146ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 147ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * 148ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @return mDeviceType 149ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 150ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int getDeviceType() { 151ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 152ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mDeviceType; 153ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 154ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 155ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 156ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 157ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @return the mAlias 158ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 159ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh String getAlias() { 160ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 161ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mAlias; 162ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 163ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 164ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 165ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 166ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @param mAlias the mAlias to set 167ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 168ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh void setAlias(String mAlias) { 169ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 170ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mAdapterService.setDevicePropertyNative(mAddress, 171ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh AbstractionLayer.BT_PROPERTY_REMOTE_FRIENDLY_NAME, mAlias.getBytes()); 172ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 173ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 174ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 175ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 176ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @param mBondState the mBondState to set 177ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 178ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh void setBondState(int mBondState) { 179ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 180ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh this.mBondState = mBondState; 181d807ba48ed4418c1a60549abe1c3a98ced8c428dSreenidhi T if (mBondState == BluetoothDevice.BOND_NONE) 182d807ba48ed4418c1a60549abe1c3a98ced8c428dSreenidhi T { 183d807ba48ed4418c1a60549abe1c3a98ced8c428dSreenidhi T /* Clearing the Uuids local copy when the device is unpaired. If not cleared, 184d807ba48ed4418c1a60549abe1c3a98ced8c428dSreenidhi T cachedBluetoothDevice issued a connect using the local cached copy of uuids, 185d807ba48ed4418c1a60549abe1c3a98ced8c428dSreenidhi T without waiting for the ACTION_UUID intent. 186d807ba48ed4418c1a60549abe1c3a98ced8c428dSreenidhi T This was resulting in multiple calls to connect().*/ 187d807ba48ed4418c1a60549abe1c3a98ced8c428dSreenidhi T mUuids = null; 188d807ba48ed4418c1a60549abe1c3a98ced8c428dSreenidhi T } 189ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 190ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 191ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 192ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 193ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @return the mBondState 194ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 195ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int getBondState() { 196ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 197ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mBondState; 198ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 199ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 200ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 201ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 202ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 203ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private void sendUuidIntent(BluetoothDevice device) { 204ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties prop = getDeviceProperties(device); 205ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Intent intent = new Intent(BluetoothDevice.ACTION_UUID); 206ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); 207c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc intent.putExtra(BluetoothDevice.EXTRA_UUID, prop == null? null: prop.mUuids); 20874ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_ADMIN_PERM); 209c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc 210c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc //Remove the outstanding UUID request 211c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc mSdpTracker.remove(device); 212ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 213ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 2146de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera private void sendDisplayPinIntent(byte[] address, int pin) { 2156de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); 2166de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera intent.putExtra(BluetoothDevice.EXTRA_DEVICE, getDevice(address)); 2176de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera intent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pin); 2186de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, 2196de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN); 22074ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_ADMIN_PERM); 2216de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera } 2226de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera 223ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh void devicePropertyChangedCallback(byte[] address, int[] types, byte[][] values) { 224ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Intent intent; 225ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh byte[] val; 226ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int type; 227ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice bdDevice = getDevice(address); 228ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties device; 229ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (bdDevice == null) { 230ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device = addDeviceProperties(address); 231ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh bdDevice = getDevice(address); 232ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } else { 233ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device = getDeviceProperties(bdDevice); 234ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 235ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 236ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh for (int j = 0; j < types.length; j++) { 237ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh type = types[j]; 238ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh val = values[j]; 239caa3723eaa20e57aac086d54a41106108503debczzy if(val.length <= 0) 240caa3723eaa20e57aac086d54a41106108503debczzy errorLog("devicePropertyChangedCallback: bdDevice: " + bdDevice + ", value is empty for type: " + type); 241caa3723eaa20e57aac086d54a41106108503debczzy else { 242caa3723eaa20e57aac086d54a41106108503debczzy synchronized(mObject) { 243caa3723eaa20e57aac086d54a41106108503debczzy switch (type) { 244caa3723eaa20e57aac086d54a41106108503debczzy case AbstractionLayer.BT_PROPERTY_BDNAME: 245caa3723eaa20e57aac086d54a41106108503debczzy device.mName = new String(val); 246caa3723eaa20e57aac086d54a41106108503debczzy intent = new Intent(BluetoothDevice.ACTION_NAME_CHANGED); 247caa3723eaa20e57aac086d54a41106108503debczzy intent.putExtra(BluetoothDevice.EXTRA_DEVICE, bdDevice); 248caa3723eaa20e57aac086d54a41106108503debczzy intent.putExtra(BluetoothDevice.EXTRA_NAME, device.mName); 249caa3723eaa20e57aac086d54a41106108503debczzy intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 250caa3723eaa20e57aac086d54a41106108503debczzy mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM); 251caa3723eaa20e57aac086d54a41106108503debczzy debugLog("Remote Device name is: " + device.mName); 252caa3723eaa20e57aac086d54a41106108503debczzy break; 253caa3723eaa20e57aac086d54a41106108503debczzy case AbstractionLayer.BT_PROPERTY_REMOTE_FRIENDLY_NAME: 254caa3723eaa20e57aac086d54a41106108503debczzy if (device.mAlias != null) { 255caa3723eaa20e57aac086d54a41106108503debczzy System.arraycopy(val, 0, device.mAlias, 0, val.length); 256caa3723eaa20e57aac086d54a41106108503debczzy } 2570322ae1f5e8ea55c391145e7925cb5962a97c11fGanesh Ganapathi Batta else { 2580322ae1f5e8ea55c391145e7925cb5962a97c11fGanesh Ganapathi Batta device.mAlias = new String(val); 2590322ae1f5e8ea55c391145e7925cb5962a97c11fGanesh Ganapathi Batta } 260caa3723eaa20e57aac086d54a41106108503debczzy break; 261caa3723eaa20e57aac086d54a41106108503debczzy case AbstractionLayer.BT_PROPERTY_BDADDR: 262caa3723eaa20e57aac086d54a41106108503debczzy device.mAddress = val; 263caa3723eaa20e57aac086d54a41106108503debczzy debugLog("Remote Address is:" + Utils.getAddressStringFromByte(val)); 264caa3723eaa20e57aac086d54a41106108503debczzy break; 265caa3723eaa20e57aac086d54a41106108503debczzy case AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE: 266caa3723eaa20e57aac086d54a41106108503debczzy device.mBluetoothClass = Utils.byteArrayToInt(val); 267caa3723eaa20e57aac086d54a41106108503debczzy intent = new Intent(BluetoothDevice.ACTION_CLASS_CHANGED); 268caa3723eaa20e57aac086d54a41106108503debczzy intent.putExtra(BluetoothDevice.EXTRA_DEVICE, bdDevice); 269caa3723eaa20e57aac086d54a41106108503debczzy intent.putExtra(BluetoothDevice.EXTRA_CLASS, 270caa3723eaa20e57aac086d54a41106108503debczzy new BluetoothClass(device.mBluetoothClass)); 271caa3723eaa20e57aac086d54a41106108503debczzy intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 272caa3723eaa20e57aac086d54a41106108503debczzy mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM); 273caa3723eaa20e57aac086d54a41106108503debczzy debugLog("Remote class is:" + device.mBluetoothClass); 274caa3723eaa20e57aac086d54a41106108503debczzy break; 275caa3723eaa20e57aac086d54a41106108503debczzy case AbstractionLayer.BT_PROPERTY_UUIDS: 276caa3723eaa20e57aac086d54a41106108503debczzy int numUuids = val.length/AbstractionLayer.BT_UUID_SIZE; 277caa3723eaa20e57aac086d54a41106108503debczzy device.mUuids = Utils.byteArrayToUuid(val); 278caa3723eaa20e57aac086d54a41106108503debczzy sendUuidIntent(bdDevice); 279caa3723eaa20e57aac086d54a41106108503debczzy break; 280caa3723eaa20e57aac086d54a41106108503debczzy case AbstractionLayer.BT_PROPERTY_TYPE_OF_DEVICE: 281caa3723eaa20e57aac086d54a41106108503debczzy device.mDeviceType = Utils.byteArrayToInt(val); 282caa3723eaa20e57aac086d54a41106108503debczzy break; 283caa3723eaa20e57aac086d54a41106108503debczzy case AbstractionLayer.BT_PROPERTY_REMOTE_RSSI: 284caa3723eaa20e57aac086d54a41106108503debczzy device.mRssi = Utils.byteArrayToShort(val); 285caa3723eaa20e57aac086d54a41106108503debczzy break; 286caa3723eaa20e57aac086d54a41106108503debczzy } 287ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 288ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 289ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 290ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 291ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 292ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh void deviceFoundCallback(byte[] address) { 293ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh // The device properties are already registered - we can send the intent 294ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh // now 295ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice device = getDevice(address); 296ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh debugLog("deviceFoundCallback: Remote Address is:" + device); 297ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties deviceProp = getDeviceProperties(device); 298ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (deviceProp == null) { 299ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh errorLog("Device Properties is null for Device:" + device); 300ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return; 301ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 302ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 303ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Intent intent = new Intent(BluetoothDevice.ACTION_FOUND); 304ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); 305ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_CLASS, 306ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh new BluetoothClass(Integer.valueOf(deviceProp.mBluetoothClass))); 307ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_RSSI, deviceProp.mRssi); 308ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_NAME, deviceProp.mName); 309ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 31074ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM); 311ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 312ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 313ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh void pinRequestCallback(byte[] address, byte[] name, int cod) { 314ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh //TODO(BT): Get wakelock and update name and cod 3151444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh BluetoothDevice bdDevice = getDevice(address); 3161444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh if (bdDevice == null) { 3171444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh addDeviceProperties(address); 3181444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh } 3196de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera BluetoothClass btClass = bdDevice.getBluetoothClass(); 3206de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera int btDeviceClass = btClass.getDeviceClass(); 3216de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera if (btDeviceClass == BluetoothClass.Device.PERIPHERAL_KEYBOARD || 3226de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera btDeviceClass == BluetoothClass.Device.PERIPHERAL_KEYBOARD_POINTING) { 3236de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera // Its a keyboard. Follow the HID spec recommendation of creating the 3246de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera // passkey and displaying it to the user. If the keyboard doesn't follow 3256de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera // the spec recommendation, check if the keyboard has a fixed PIN zero 3266de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera // and pair. 3276de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera //TODO: Add sFixedPinZerosAutoPairKeyboard() and maintain list of devices that have fixed pin 3286de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera /*if (mAdapterService.isFixedPinZerosAutoPairKeyboard(address)) { 3296de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera mAdapterService.setPin(address, BluetoothDevice.convertPinToBytes("0000")); 3306de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera return; 3316de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera }*/ 3326de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera // Generate a variable PIN. This is not truly random but good enough. 3336de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera int pin = (int) Math.floor(Math.random() * 1000000); 3346de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera sendDisplayPinIntent(address, pin); 3356de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera return; 3366de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera } 337ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh infoLog("pinRequestCallback: " + address + " name:" + name + " cod:" + 338ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh cod); 339ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); 340ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_DEVICE, getDevice(address)); 341ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, 342ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice.PAIRING_VARIANT_PIN); 34374ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_ADMIN_PERM); 344ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return; 345ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 346ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 347ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh void sspRequestCallback(byte[] address, byte[] name, int cod, int pairingVariant, 348ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int passkey) { 349ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh //TODO(BT): Get wakelock and update name and cod 3501444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh BluetoothDevice bdDevice = getDevice(address); 3511444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh if (bdDevice == null) { 3521444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh addDeviceProperties(address); 3531444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh } 3541444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh 355ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh infoLog("sspRequestCallback: " + address + " name: " + name + " cod: " + 356ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh cod + " pairingVariant " + pairingVariant + " passkey: " + passkey); 357ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int variant; 358ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh boolean displayPasskey = false; 359ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (pairingVariant == AbstractionLayer.BT_SSP_VARIANT_PASSKEY_CONFIRMATION) { 360ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh variant = BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION; 361ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh displayPasskey = true; 362ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } else if (pairingVariant == AbstractionLayer.BT_SSP_VARIANT_CONSENT) { 363b01cf4299897d227c7dbcbe4981b63a1ffe4ffcaSreenidhi T variant = BluetoothDevice.PAIRING_VARIANT_CONSENT; 364ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } else if (pairingVariant == AbstractionLayer.BT_SSP_VARIANT_PASSKEY_ENTRY) { 365ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh variant = BluetoothDevice.PAIRING_VARIANT_PASSKEY; 366b7e70fcf8923b9452074b2b4ee685da424cc7d93Kausik Sinnaswamy } else if (pairingVariant == AbstractionLayer.BT_SSP_VARIANT_PASSKEY_NOTIFICATION) { 367581bb31a8165ff0f9c7d638cfe4a81aaaafa2dedJaikumar Ganesh variant = BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY; 368581bb31a8165ff0f9c7d638cfe4a81aaaafa2dedJaikumar Ganesh displayPasskey = true; 369ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } else { 370ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh errorLog("SSP Pairing variant not present"); 371ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return; 372ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 373ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice device = getDevice(address); 374ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (device == null) { 375ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh warnLog("Device is not known for:" + Utils.getAddressStringFromByte(address)); 376ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh addDeviceProperties(address); 377ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device = getDevice(address); 378ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 379ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); 380ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); 381ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (displayPasskey) { 382ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, passkey); 383ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 384ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, variant); 38574ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_ADMIN_PERM); 386ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 387ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 38801a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy void aclStateChangeCallback(int status, byte[] address, int newState) { 38901a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy BluetoothDevice device = getDevice(address); 39001a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy 39101a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy if (device == null) { 39201a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy errorLog("aclStateChangeCallback: Device is NULL"); 39301a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy return; 39401a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy } 39501a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy 39601a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy Intent intent = null; 39701a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy if (newState == AbstractionLayer.BT_ACL_STATE_CONNECTED) { 39801a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy intent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED); 39901a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy debugLog("aclStateChangeCallback: State:Connected to Device:" + device); 40001a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy } else { 40101a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED); 40201a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy debugLog("aclStateChangeCallback: State:DisConnected to Device:" + device); 40301a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy } 40401a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); 40501a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 40674ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM); 40701a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy } 408ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 409c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc void fetchUuids(BluetoothDevice device) { 410ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (mSdpTracker.contains(device)) return; 411ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mSdpTracker.add(device); 412ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 413ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Message message = mHandler.obtainMessage(MESSAGE_UUID_INTENT); 414ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh message.obj = device; 415ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mHandler.sendMessageDelayed(message, UUID_INTENT_DELAY); 416ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 417c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc //mAdapterService.getDevicePropertyNative(Utils.getBytesFromAddress(device.getAddress()), AbstractionLayer.BT_PROPERTY_UUIDS); 418c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc mAdapterService.getRemoteServicesNative(Utils.getBytesFromAddress(device.getAddress())); 419ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 420ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 421ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private final Handler mHandler = new Handler() { 422ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh @Override 423ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh public void handleMessage(Message msg) { 424ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh switch (msg.what) { 425ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh case MESSAGE_UUID_INTENT: 426ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice device = (BluetoothDevice)msg.obj; 427ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (device != null) { 428ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh sendUuidIntent(device); 429ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 430ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh break; 431ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 432ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 433ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh }; 434ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 435ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private void errorLog(String msg) { 436ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Log.e(TAG, msg); 437ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 438ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 439ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private void debugLog(String msg) { 4406458cffaca286611e898c75ad86e2d98c89008b6Matthew Xie if (DBG) Log.d(TAG, msg); 441ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 442ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 443ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private void infoLog(String msg) { 444ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (DBG) Log.i(TAG, msg); 445ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 446ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 447ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private void warnLog(String msg) { 448ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Log.w(TAG, msg); 449ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 45074ae04c73312403e89db0f8e9bd9601d403b4783fredc 451ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh} 452