示例#1
0
 /**
  * Allow or disallow incoming connection
  *
  * @param device Sink
  * @param value True / False
  * @return Success or Failure of the binder call.
  */
 public boolean allowIncomingConnect(BluetoothDevice device, boolean value) {
   if (DBG) log("allowIncomingConnect(" + device + ":" + value + ")");
   try {
     return mService.allowIncomingConnect(device, value);
   } catch (RemoteException e) {
     Log.e(TAG, "", e);
     return false;
   }
 }
示例#2
0
 /**
  * Set priority of a2dp sink. Priority is a non-negative integer. By default paired sinks will
  * have a priority of PRIORITY_AUTO, and unpaired headset PRIORITY_NONE (0). Sinks with priority
  * greater than zero will accept incoming connections (if no sink is currently connected).
  * Priority for unpaired sink must be PRIORITY_NONE.
  *
  * @param device Paired sink
  * @param priority Integer priority, for example PRIORITY_AUTO or PRIORITY_NONE
  * @return true if priority is set, false on error
  */
 public boolean setSinkPriority(BluetoothDevice device, int priority) {
   if (DBG) log("setSinkPriority(" + device + ", " + priority + ")");
   try {
     return mService.setSinkPriority(device, priority);
   } catch (RemoteException e) {
     Log.e(TAG, "", e);
     return false;
   }
 }
示例#3
0
 /**
  * Get priority of a2dp sink.
  *
  * @param device Sink
  * @return non-negative priority, or negative error code on error.
  */
 public int getSinkPriority(BluetoothDevice device) {
   if (DBG) log("getSinkPriority(" + device + ")");
   try {
     return mService.getSinkPriority(device);
   } catch (RemoteException e) {
     Log.e(TAG, "", e);
     return PRIORITY_OFF;
   }
 }
示例#4
0
 /**
  * Initiate disconnect from an A2DP sink. Listen for SINK_STATE_CHANGED_ACTION to find out when
  * disconnect is completed.
  *
  * @param device Remote BT device.
  * @return false on immediate error, true otherwise
  * @hide
  */
 public boolean disconnectSink(BluetoothDevice device) {
   if (DBG) log("disconnectSink(" + device + ")");
   try {
     return mService.disconnectSink(device);
   } catch (RemoteException e) {
     Log.e(TAG, "", e);
     return false;
   }
 }
示例#5
0
 /**
  * Get the state of an A2DP sink
  *
  * @param device Remote BT device.
  * @return State code, one of STATE_
  * @hide
  */
 public int getSinkState(BluetoothDevice device) {
   if (DBG) log("getSinkState(" + device + ")");
   try {
     return mService.getSinkState(device);
   } catch (RemoteException e) {
     Log.e(TAG, "", e);
     return BluetoothA2dp.STATE_DISCONNECTED;
   }
 }
示例#6
0
 /**
  * Check if any A2DP sink is in Non Disconnected state i.e playing, connected, connecting,
  * disconnecting.
  *
  * @return a unmodifiable set of connected A2DP sinks, or null on error.
  * @hide
  */
 public Set<BluetoothDevice> getNonDisconnectedSinks() {
   if (DBG) log("getNonDisconnectedSinks()");
   try {
     return Collections.unmodifiableSet(
         new HashSet<BluetoothDevice>(Arrays.asList(mService.getNonDisconnectedSinks())));
   } catch (RemoteException e) {
     Log.e(TAG, "", e);
     return null;
   }
 }
示例#7
0
 /**
  * Get the priority of the profile.
  *
  * <p>The priority can be any of: {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF}, {@link
  * #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
  *
  * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
  *
  * @param device Bluetooth device
  * @return priority of the device
  * @hide
  */
 public int getPriority(BluetoothDevice device) {
   if (DBG) log("getPriority(" + device + ")");
   if (mService != null && isEnabled() && isValidDevice(device)) {
     try {
       return mService.getPriority(device);
     } catch (RemoteException e) {
       Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
       return BluetoothProfile.PRIORITY_OFF;
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return BluetoothProfile.PRIORITY_OFF;
 }
示例#8
0
 /** {@inheritDoc} */
 public int getConnectionState(BluetoothDevice device) {
   if (DBG) log("getState(" + device + ")");
   if (mService != null && isEnabled() && isValidDevice(device)) {
     try {
       return mService.getConnectionState(device);
     } catch (RemoteException e) {
       Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
       return BluetoothProfile.STATE_DISCONNECTED;
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return BluetoothProfile.STATE_DISCONNECTED;
 }
示例#9
0
 /** {@inheritDoc} */
 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
   if (DBG) log("getDevicesMatchingStates()");
   if (mService != null && isEnabled()) {
     try {
       return mService.getDevicesMatchingConnectionStates(states);
     } catch (RemoteException e) {
       Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
       return new ArrayList<BluetoothDevice>();
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return new ArrayList<BluetoothDevice>();
 }
示例#10
0
 /**
  * Initiate disconnection from a profile
  *
  * <p>This API will return false in scenarios like the profile on the Bluetooth device is not in
  * connected state etc. When this API returns, true, it is guaranteed that the connection state
  * change intent will be broadcasted with the state. Users can get the disconnection state of the
  * profile from this intent.
  *
  * <p>If the disconnection is initiated by a remote device, the state will transition from {@link
  * #STATE_CONNECTED} to {@link #STATE_DISCONNECTED}. If the disconnect is initiated by the host
  * (local) device the state will transition from {@link #STATE_CONNECTED} to state {@link
  * #STATE_DISCONNECTING} to state {@link #STATE_DISCONNECTED}. The transition to {@link
  * #STATE_DISCONNECTING} can be used to distinguish between the two scenarios.
  *
  * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
  *
  * @param device Remote Bluetooth Device
  * @return false on immediate error, true otherwise
  * @hide
  */
 public boolean disconnect(BluetoothDevice device) {
   if (DBG) log("disconnect(" + device + ")");
   if (mService != null && isEnabled() && isValidDevice(device)) {
     try {
       return mService.disconnect(device);
     } catch (RemoteException e) {
       Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
       return false;
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return false;
 }
示例#11
0
 /**
  * Set priority of the profile
  *
  * <p>The device should already be paired. Priority can be one of {@link #PRIORITY_ON} or {@link
  * #PRIORITY_OFF},
  *
  * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
  *
  * @param device Paired bluetooth device
  * @param priority
  * @return true if priority is set, false on error
  * @hide
  */
 public boolean setPriority(BluetoothDevice device, int priority) {
   if (DBG) log("setPriority(" + device + ", " + priority + ")");
   if (mService != null && isEnabled() && isValidDevice(device)) {
     if (priority != BluetoothProfile.PRIORITY_OFF && priority != BluetoothProfile.PRIORITY_ON) {
       return false;
     }
     try {
       return mService.setPriority(device, priority);
     } catch (RemoteException e) {
       Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
       return false;
     }
   }
   if (mService == null) Log.w(TAG, "Proxy not attached to service");
   return false;
 }
示例#12
0
 /**
  * Check if a specified A2DP sink is connected.
  *
  * @param device Remote BT device.
  * @return True if connected (or playing), false otherwise and on error.
  * @hide
  */
 public boolean isSinkConnected(BluetoothDevice device) {
   if (DBG) log("isSinkConnected(" + device + ")");
   int state = getSinkState(device);
   return state == STATE_CONNECTED || state == STATE_PLAYING;
 }