private boolean addDevicePreference(CachedBluetoothDevice cachedDevice) {
    ParcelUuid[] uuids = cachedDevice.getDevice().getUuids();
    BluetoothClass bluetoothClass = cachedDevice.getDevice().getBluetoothClass();

    switch (mFilterType) {
      case BluetoothDevicePicker.FILTER_TYPE_TRANSFER:
        if (uuids != null)
          if (BluetoothUuid.containsAnyUuid(uuids, LocalBluetoothProfileManager.OPP_PROFILE_UUIDS))
            return true;
        if (bluetoothClass != null && bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_OPP)) {
          return true;
        }
        break;
      case BluetoothDevicePicker.FILTER_TYPE_AUDIO:
        if (uuids != null) {
          if (BluetoothUuid.containsAnyUuid(uuids, LocalBluetoothProfileManager.A2DP_PROFILE_UUIDS))
            return true;

          if (BluetoothUuid.containsAnyUuid(
              uuids, LocalBluetoothProfileManager.HEADSET_PROFILE_UUIDS)) return true;
        } else if (bluetoothClass != null) {
          if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) return true;

          if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) return true;
        }
        break;
      default:
        return true;
    }
    return false;
  }
  synchronized List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
    List<BluetoothDevice> deviceList = new ArrayList<BluetoothDevice>();
    Set<BluetoothDevice> bondedDevices = mAdapter.getBondedDevices();
    int connectionState;

    for (BluetoothDevice device : bondedDevices) {
      ParcelUuid[] featureUuids = device.getUuids();
      if (!BluetoothUuid.containsAnyUuid(featureUuids, A2DP_UUIDS)) {
        continue;
      }
      connectionState = getConnectionState(device);
      for (int i = 0; i < states.length; i++) {
        if (connectionState == states[i]) {
          deviceList.add(device);
        }
      }
    }
    return deviceList;
  }
Example #3
0
  public boolean connect(BluetoothDevice device) {
    enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");

    if (getPriority(device) == BluetoothProfile.PRIORITY_OFF) {
      return false;
    }
    ParcelUuid[] featureUuids = device.getUuids();
    if ((BluetoothUuid.containsAnyUuid(featureUuids, A2DP_SOURCE_UUID))
        && !(BluetoothUuid.containsAllUuids(featureUuids, A2DP_SOURCE_SINK_UUIDS))) {
      Log.e(TAG, "Remote does not have A2dp Sink UUID");
      return false;
    }

    int connectionState = mStateMachine.getConnectionState(device);
    if (connectionState == BluetoothProfile.STATE_CONNECTED
        || connectionState == BluetoothProfile.STATE_CONNECTING) {
      return false;
    }

    mStateMachine.sendMessage(A2dpStateMachine.CONNECT, device);
    return true;
  }