/** * 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; } }
/** * 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; } }
/** * 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; } }
/** * 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; } }
/** * 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; } }
/** * 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; } }
/** * 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; }
/** {@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; }
/** {@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>(); }
/** * 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; }
/** * 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; }
/** * 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; }