boolean disconnect(BluetoothDevice device) {
    enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");
    int connectionState = mStateMachine.getConnectionState(device);
    if (connectionState != BluetoothProfile.STATE_CONNECTED
        && connectionState != BluetoothProfile.STATE_CONNECTING) {
      return false;
    }

    mStateMachine.sendMessage(A2dpStateMachine.DISCONNECT, device);
    return true;
  }
 protected boolean stop() {
   if (mStateMachine != null) {
     mStateMachine.doQuit();
   }
   if (mAvrcp != null) {
     mAvrcp.doQuit();
   }
   return true;
 }
 protected boolean cleanup() {
   if (mStateMachine != null) {
     mStateMachine.cleanup();
   }
   if (mAvrcp != null) {
     mAvrcp.cleanup();
     mAvrcp = null;
   }
   clearA2dpService();
   return true;
 }
  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;
  }
  public boolean setPriority(BluetoothDevice device, int priority) {
    enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");

    if ((mStateMachine.isConnectedSrc(device))
        && (priority == BluetoothProfile.PRIORITY_AUTO_CONNECT)) {
      if (DBG) Log.d(TAG, "Peer Device is SRC Ignore AutoConnect");
      return false;
    }
    Settings.Global.putInt(
        getContentResolver(),
        Settings.Global.getBluetoothA2dpSinkPriorityKey(device.getAddress()),
        priority);
    if (DBG) Log.d(TAG, "Saved priority " + device + " = " + priority);
    return true;
  }
 protected boolean start() {
   mAvrcp = Avrcp.make(this);
   mStateMachine = A2dpStateMachine.make(this, this);
   setA2dpService(this);
   return true;
 }
 synchronized boolean isA2dpPlaying(BluetoothDevice device) {
   enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
   if (DBG) Log.d(TAG, "isA2dpPlaying(" + device + ")");
   return mStateMachine.isPlaying(device);
 }
 int getConnectionState(BluetoothDevice device) {
   enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
   return mStateMachine.getConnectionState(device);
 }
 List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
   enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
   return mStateMachine.getDevicesMatchingConnectionStates(states);
 }
 public List<BluetoothDevice> getConnectedDevices() {
   enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
   return mStateMachine.getConnectedDevices();
 }
 static A2dpStateMachine make(A2dpService svc, Context context) {
   Log.d("A2dpStateMachine", "make");
   A2dpStateMachine a2dpSm = new A2dpStateMachine(svc, context);
   a2dpSm.start();
   return a2dpSm;
 }