public synchronized void onScanningStateChanged(boolean started) { // If starting a new scan, clear old visibility // Iterate in reverse order since devices may be removed. for (int i = mCachedDevices.size() - 1; i >= 0; i--) { CachedBluetoothDevice cachedDevice = mCachedDevices.get(i); if (started) { cachedDevice.setVisible(false); } else if (!started && cachedDevice.getBondState() == BluetoothDevice.BOND_NONE && cachedDevice.isRemovable()) { mCachedDevices.remove(cachedDevice); } } }
public synchronized void onBluetoothStateChanged(int bluetoothState) { // When Bluetooth is turning off, we need to clear the non-bonded devices // Otherwise, they end up showing up on the next BT enable if (bluetoothState == BluetoothAdapter.STATE_TURNING_OFF) { for (int i = mCachedDevices.size() - 1; i >= 0; i--) { CachedBluetoothDevice cachedDevice = mCachedDevices.get(i); if (cachedDevice.getBondState() != BluetoothDevice.BOND_BONDED) { cachedDevice.setVisible(false); mCachedDevices.remove(i); } else { // For bonded devices, we need to clear the connection status so that // when BT is enabled next time, device connection status shall be retrieved // by making a binder call. cachedDevice.clearProfileConnectionState(); } } } }
public static boolean onDeviceDisappeared(CachedBluetoothDevice cachedDevice) { cachedDevice.setVisible(false); return cachedDevice.getBondState() == BluetoothDevice.BOND_NONE; }