예제 #1
0
  /* package */ void handleAccessPermissionResult(Intent intent) {
    if (!mCheckingAccessPermission) {
      return;
    }

    HeadsetBase headset = mHandsfree.getHeadset();
    // ASSERT: (headset != null) && headSet.isConnected()
    // REASON: mCheckingAccessPermission is true, otherwise resetAtState
    //         has set mCheckingAccessPermission to false

    if (intent.getAction().equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY)) {

      if (intent.getIntExtra(
              BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT, BluetoothDevice.CONNECTION_ACCESS_NO)
          == BluetoothDevice.CONNECTION_ACCESS_YES) {
        BluetoothDevice remoteDevice = headset.getRemoteDevice();
        if (intent.getBooleanExtra(BluetoothDevice.EXTRA_ALWAYS_ALLOWED, false)) {
          remoteDevice.setTrust(true);
        }

        AtCommandResult cpbrResult = processCpbrCommand();
        headset.sendURC(cpbrResult.toString());
      } else {
        headset.sendURC("ERROR");
      }
    }
    mCpbrIndex1 = mCpbrIndex2 = -1;
    mCheckingAccessPermission = false;
  }
        public boolean disconnectHeadsetInternal(BluetoothDevice device) {
          synchronized (BluetoothHeadsetService.this) {
            BluetoothRemoteHeadset remoteHeadset = mRemoteHeadsets.get(device);
            if (remoteHeadset == null) return false;

            if (remoteHeadset.mState == BluetoothHeadset.STATE_CONNECTED) {
              // Send a dummy battery level message to force headset
              // out of sniff mode so that it will immediately notice
              // the disconnection. We are currently sending it for
              // handsfree only.
              // TODO: Call hci_conn_enter_active_mode() from
              // rfcomm_send_disc() in the kernel instead.
              // See http://b/1716887
              HeadsetBase headset = remoteHeadset.mHeadset;
              if (remoteHeadset.mHeadsetType == BluetoothHandsfree.TYPE_HANDSFREE) {
                headset.sendURC("+CIEV: 7,3");
              }

              if (headset != null) {
                headset.disconnect();
                headset = null;
              }
              setState(
                  device,
                  BluetoothHeadset.STATE_DISCONNECTED,
                  BluetoothHeadset.RESULT_CANCELED,
                  BluetoothHeadset.LOCAL_DISCONNECT);
              return true;
            } else if (remoteHeadset.mState == BluetoothHeadset.STATE_CONNECTING) {
              // The state machine would have canceled the connect thread.
              // Just set the state here.
              setState(
                  device,
                  BluetoothHeadset.STATE_DISCONNECTED,
                  BluetoothHeadset.RESULT_CANCELED,
                  BluetoothHeadset.LOCAL_DISCONNECT);
              return true;
            }
            return false;
          }
        }