RemoteDevices.java revision 74ae04c73312403e89db0f8e9bd9601d403b4783
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 { 26ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private static final boolean DBG = true; 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() { 506654f5c903de510a70f9e72cd5ad7837b615d93ffredc mSdpTracker.clear(); 5131ba132491053bc86d419a7d51fc04af3299c076fredc mSdpTracker = null; 526654f5c903de510a70f9e72cd5ad7837b615d93ffredc mDevices.clear(); 5331ba132491053bc86d419a7d51fc04af3299c076fredc mDevices = null; 5431ba132491053bc86d419a7d51fc04af3299c076fredc mAdapterService = null; 5531ba132491053bc86d419a7d51fc04af3299c076fredc mAdapter= null; 566654f5c903de510a70f9e72cd5ad7837b615d93ffredc } 576654f5c903de510a70f9e72cd5ad7837b615d93ffredc 58ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh public Object Clone() throws CloneNotSupportedException { 59ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh throw new CloneNotSupportedException(); 60ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 61ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 62ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties getDeviceProperties(BluetoothDevice device) { 63ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mDevices) { 64ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mDevices.get(device); 65ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 66ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 67ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 68ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice getDevice(byte[] address) { 69ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh for (BluetoothDevice dev : mDevices.keySet()) { 70ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (dev.getAddress().equals(Utils.getAddressStringFromByte(address))) { 71ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return dev; 72ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 73ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 74ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return null; 75ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 76ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 77ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties addDeviceProperties(byte[] address) { 78ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mDevices) { 79ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties prop = new DeviceProperties(); 80ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice device = 81ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mAdapter.getRemoteDevice(Utils.getAddressStringFromByte(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; 181ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 182ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 183ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 184ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh /** 185ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh * @return the mBondState 186ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh */ 187ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int getBondState() { 188ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized (mObject) { 189ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return mBondState; 190ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 191ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 192ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 193ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 194ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 195ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private void sendUuidIntent(BluetoothDevice device) { 196ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties prop = getDeviceProperties(device); 197ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Intent intent = new Intent(BluetoothDevice.ACTION_UUID); 198ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); 199c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc intent.putExtra(BluetoothDevice.EXTRA_UUID, prop == null? null: prop.mUuids); 20074ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_ADMIN_PERM); 201c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc 202c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc //Remove the outstanding UUID request 203c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc mSdpTracker.remove(device); 204ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 205ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 2066de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera private void sendDisplayPinIntent(byte[] address, int pin) { 2076de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); 2086de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera intent.putExtra(BluetoothDevice.EXTRA_DEVICE, getDevice(address)); 2096de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera intent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pin); 2106de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, 2116de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN); 21274ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_ADMIN_PERM); 2136de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera } 2146de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera 215ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh void devicePropertyChangedCallback(byte[] address, int[] types, byte[][] values) { 216ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Intent intent; 217ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh byte[] val; 218ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int type; 219ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice bdDevice = getDevice(address); 220ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties device; 221ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (bdDevice == null) { 222ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device = addDeviceProperties(address); 223ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh bdDevice = getDevice(address); 224ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } else { 225ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device = getDeviceProperties(bdDevice); 226ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 227ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 228ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh for (int j = 0; j < types.length; j++) { 229ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh type = types[j]; 230ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh val = values[j]; 231ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh synchronized(mObject) { 232ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh switch (type) { 233ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh case AbstractionLayer.BT_PROPERTY_BDNAME: 234ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device.mName = new String(val); 235ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent = new Intent(BluetoothDevice.ACTION_NAME_CHANGED); 236ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_DEVICE, bdDevice); 237ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_NAME, device.mName); 238ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 23974ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM); 24019da573973557408b1b7398a2c3a167d8da9527dSrikanth Uppala debugLog("Remote Device name is: " + device.mName); 241ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh break; 242ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh case AbstractionLayer.BT_PROPERTY_REMOTE_FRIENDLY_NAME: 2438826b161f865350f306e8f287aaca615e2f1e4a3Matthew Xie // TODO(BT) is null device.mAlias a valid senario? 2448826b161f865350f306e8f287aaca615e2f1e4a3Matthew Xie if (device.mAlias != null) { 2458826b161f865350f306e8f287aaca615e2f1e4a3Matthew Xie System.arraycopy(val, 0, device.mAlias, 0, val.length); 2468826b161f865350f306e8f287aaca615e2f1e4a3Matthew Xie } 247ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh break; 248ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh case AbstractionLayer.BT_PROPERTY_BDADDR: 249ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device.mAddress = val; 250ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh debugLog("Remote Address is:" + Utils.getAddressStringFromByte(val)); 251ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh break; 252ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh case AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE: 253ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device.mBluetoothClass = Utils.byteArrayToInt(val); 254ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent = new Intent(BluetoothDevice.ACTION_CLASS_CHANGED); 255ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_DEVICE, bdDevice); 256ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_CLASS, 257ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh new BluetoothClass(device.mBluetoothClass)); 258ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 25974ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM); 260ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh debugLog("Remote class is:" + device.mBluetoothClass); 261ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh break; 262ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh case AbstractionLayer.BT_PROPERTY_UUIDS: 263ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int numUuids = val.length/AbstractionLayer.BT_UUID_SIZE; 264ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device.mUuids = Utils.byteArrayToUuid(val); 265ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh sendUuidIntent(bdDevice); 266ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh break; 267ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh case AbstractionLayer.BT_PROPERTY_TYPE_OF_DEVICE: 268ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device.mDeviceType = Utils.byteArrayToInt(val); 269ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh break; 270ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh case AbstractionLayer.BT_PROPERTY_REMOTE_RSSI: 271ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device.mRssi = Utils.byteArrayToShort(val); 272ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh break; 273ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 274ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 275ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 276ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 277ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 278ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh void deviceFoundCallback(byte[] address) { 279ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh // The device properties are already registered - we can send the intent 280ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh // now 281ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice device = getDevice(address); 282ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh debugLog("deviceFoundCallback: Remote Address is:" + device); 283ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh DeviceProperties deviceProp = getDeviceProperties(device); 284ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (deviceProp == null) { 285ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh errorLog("Device Properties is null for Device:" + device); 286ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return; 287ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 288ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 289ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Intent intent = new Intent(BluetoothDevice.ACTION_FOUND); 290ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); 291ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_CLASS, 292ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh new BluetoothClass(Integer.valueOf(deviceProp.mBluetoothClass))); 293ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_RSSI, deviceProp.mRssi); 294ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_NAME, deviceProp.mName); 295ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 29674ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM); 297ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 298ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 299ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh void pinRequestCallback(byte[] address, byte[] name, int cod) { 300ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh //TODO(BT): Get wakelock and update name and cod 3011444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh BluetoothDevice bdDevice = getDevice(address); 3021444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh if (bdDevice == null) { 3031444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh addDeviceProperties(address); 3041444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh } 3056de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera BluetoothClass btClass = bdDevice.getBluetoothClass(); 3066de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera int btDeviceClass = btClass.getDeviceClass(); 3076de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera if (btDeviceClass == BluetoothClass.Device.PERIPHERAL_KEYBOARD || 3086de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera btDeviceClass == BluetoothClass.Device.PERIPHERAL_KEYBOARD_POINTING) { 3096de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera // Its a keyboard. Follow the HID spec recommendation of creating the 3106de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera // passkey and displaying it to the user. If the keyboard doesn't follow 3116de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera // the spec recommendation, check if the keyboard has a fixed PIN zero 3126de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera // and pair. 3136de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera //TODO: Add sFixedPinZerosAutoPairKeyboard() and maintain list of devices that have fixed pin 3146de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera /*if (mAdapterService.isFixedPinZerosAutoPairKeyboard(address)) { 3156de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera mAdapterService.setPin(address, BluetoothDevice.convertPinToBytes("0000")); 3166de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera return; 3176de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera }*/ 3186de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera // Generate a variable PIN. This is not truly random but good enough. 3196de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera int pin = (int) Math.floor(Math.random() * 1000000); 3206de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera sendDisplayPinIntent(address, pin); 3216de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera return; 3226de8229571ce56dcb0010c63cbef65e01ecd5c2aPriti Aghera } 323ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh infoLog("pinRequestCallback: " + address + " name:" + name + " cod:" + 324ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh cod); 325ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); 326ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_DEVICE, getDevice(address)); 327ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, 328ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice.PAIRING_VARIANT_PIN); 32974ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_ADMIN_PERM); 330ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return; 331ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 332ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 333ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh void sspRequestCallback(byte[] address, byte[] name, int cod, int pairingVariant, 334ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int passkey) { 335ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh //TODO(BT): Get wakelock and update name and cod 3361444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh BluetoothDevice bdDevice = getDevice(address); 3371444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh if (bdDevice == null) { 3381444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh addDeviceProperties(address); 3391444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh } 3401444b5b09d07b1ad5ec2ce89b4267484be25e8bfJaikumar Ganesh 341ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh infoLog("sspRequestCallback: " + address + " name: " + name + " cod: " + 342ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh cod + " pairingVariant " + pairingVariant + " passkey: " + passkey); 343ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh int variant; 344ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh boolean displayPasskey = false; 345ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (pairingVariant == AbstractionLayer.BT_SSP_VARIANT_PASSKEY_CONFIRMATION) { 346ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh variant = BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION; 347ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh displayPasskey = true; 348ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } else if (pairingVariant == AbstractionLayer.BT_SSP_VARIANT_CONSENT) { 349b01cf4299897d227c7dbcbe4981b63a1ffe4ffcaSreenidhi T variant = BluetoothDevice.PAIRING_VARIANT_CONSENT; 350ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } else if (pairingVariant == AbstractionLayer.BT_SSP_VARIANT_PASSKEY_ENTRY) { 351ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh variant = BluetoothDevice.PAIRING_VARIANT_PASSKEY; 352b7e70fcf8923b9452074b2b4ee685da424cc7d93Kausik Sinnaswamy } else if (pairingVariant == AbstractionLayer.BT_SSP_VARIANT_PASSKEY_NOTIFICATION) { 353581bb31a8165ff0f9c7d638cfe4a81aaaafa2dedJaikumar Ganesh variant = BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY; 354581bb31a8165ff0f9c7d638cfe4a81aaaafa2dedJaikumar Ganesh displayPasskey = true; 355ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } else { 356ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh errorLog("SSP Pairing variant not present"); 357ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh return; 358ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 359ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice device = getDevice(address); 360ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (device == null) { 361ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh warnLog("Device is not known for:" + Utils.getAddressStringFromByte(address)); 362ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh addDeviceProperties(address); 363ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh device = getDevice(address); 364ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 365ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST); 366ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); 367ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (displayPasskey) { 368ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, passkey); 369ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 370ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, variant); 37174ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_ADMIN_PERM); 372ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 373ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 37401a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy void aclStateChangeCallback(int status, byte[] address, int newState) { 37501a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy BluetoothDevice device = getDevice(address); 37601a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy 37701a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy if (device == null) { 37801a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy errorLog("aclStateChangeCallback: Device is NULL"); 37901a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy return; 38001a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy } 38101a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy 38201a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy Intent intent = null; 38301a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy if (newState == AbstractionLayer.BT_ACL_STATE_CONNECTED) { 38401a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy intent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED); 38501a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy debugLog("aclStateChangeCallback: State:Connected to Device:" + device); 38601a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy } else { 38701a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED); 38801a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy debugLog("aclStateChangeCallback: State:DisConnected to Device:" + device); 38901a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy } 39001a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); 39101a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 39274ae04c73312403e89db0f8e9bd9601d403b4783fredc mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM); 39301a8cf98f070a6996b2e8974edc229ac402f3f0cKausik Sinnaswamy } 394ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 395c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc void fetchUuids(BluetoothDevice device) { 396ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (mSdpTracker.contains(device)) return; 397ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mSdpTracker.add(device); 398ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 399ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Message message = mHandler.obtainMessage(MESSAGE_UUID_INTENT); 400ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh message.obj = device; 401ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh mHandler.sendMessageDelayed(message, UUID_INTENT_DELAY); 402ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 403c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc //mAdapterService.getDevicePropertyNative(Utils.getBytesFromAddress(device.getAddress()), AbstractionLayer.BT_PROPERTY_UUIDS); 404c55ac7d42cf2d78c7edc67abf6c66813245b2c93fredc mAdapterService.getRemoteServicesNative(Utils.getBytesFromAddress(device.getAddress())); 405ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 406ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 407ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private final Handler mHandler = new Handler() { 408ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh @Override 409ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh public void handleMessage(Message msg) { 410ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh switch (msg.what) { 411ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh case MESSAGE_UUID_INTENT: 412ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh BluetoothDevice device = (BluetoothDevice)msg.obj; 413ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (device != null) { 414ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh sendUuidIntent(device); 415ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 416ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh break; 417ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 418ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 419ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh }; 420ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 421ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private void errorLog(String msg) { 422ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Log.e(TAG, msg); 423ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 424ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 425ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private void debugLog(String msg) { 426ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (DBG) Log.e(TAG, msg); 427ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 428ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 429ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private void infoLog(String msg) { 430ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh if (DBG) Log.i(TAG, msg); 431ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 432ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh 433ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh private void warnLog(String msg) { 434ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh Log.w(TAG, msg); 435ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh } 43674ae04c73312403e89db0f8e9bd9601d403b4783fredc 437ff4f17bf64978d0738c66e1b6dd70be8664efc24Jaikumar Ganesh} 438