private CachedBluetoothDevice getCachedBluetoothDevice(BluetoothDevice device) {
   CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
   if (cachedDevice == null) {
     cachedDevice = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, device);
   }
   return cachedDevice;
 }
  /**
   * @return true user had made a choice, this method replies to the request according to user's
   *     previous decision false user hadnot made any choice on this device
   */
  private boolean checkUserChoice() {
    boolean processed = false;

    // we only remember PHONEBOOK permission
    if (mRequestType != BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
      return processed;
    }

    LocalBluetoothManager bluetoothManager = LocalBluetoothManager.getInstance(mContext);
    CachedBluetoothDeviceManager cachedDeviceManager = bluetoothManager.getCachedDeviceManager();
    CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(mDevice);

    if (cachedDevice == null) {
      cachedDevice =
          cachedDeviceManager.addDevice(
              bluetoothManager.getBluetoothAdapter(),
              bluetoothManager.getProfileManager(),
              mDevice);
    }

    int phonebookPermission = cachedDevice.getPhonebookPermissionChoice();

    if (phonebookPermission == CachedBluetoothDevice.PHONEBOOK_ACCESS_UNKNOWN) {
      return processed;
    }

    String intentName = BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY;
    if (phonebookPermission == CachedBluetoothDevice.PHONEBOOK_ACCESS_ALLOWED) {
      sendIntentToReceiver(intentName, true, BluetoothDevice.EXTRA_ALWAYS_ALLOWED, true);
      processed = true;
    } else if (phonebookPermission == CachedBluetoothDevice.PHONEBOOK_ACCESS_REJECTED) {
      sendIntentToReceiver(
          intentName, false, null, false // dummy value, no effect since previous param is null
          );
      processed = true;
    } else {
      Log.e(TAG, "Bad phonebookPermission: " + phonebookPermission);
    }
    return processed;
  }
  synchronized boolean hasOtherConnectedDevices(BluetoothDevice dock) {
    Collection<CachedBluetoothDevice> cachedDevices = mDeviceManager.getCachedDevicesCopy();
    Set<BluetoothDevice> btDevices = mLocalAdapter.getBondedDevices();
    if (btDevices == null || cachedDevices == null || btDevices.isEmpty()) {
      return false;
    }
    if (DEBUG) {
      Log.d(TAG, "btDevices = " + btDevices.size());
      Log.d(TAG, "cachedDeviceUIs = " + cachedDevices.size());
    }

    for (CachedBluetoothDevice deviceUI : cachedDevices) {
      BluetoothDevice btDevice = deviceUI.getDevice();
      if (!btDevice.equals(dock) && btDevices.contains(btDevice) && deviceUI.isConnected()) {
        if (DEBUG) Log.d(TAG, "connected deviceUI = " + deviceUI.getName());
        return true;
      }
    }
    return false;
  }