Loading framework/java/android/bluetooth/BluetoothA2dpSink.java +28 −75 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ package android.bluetooth; import android.Manifest; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.annotation.UnsupportedAppUsage; import android.content.Context; Loading @@ -39,6 +41,7 @@ import java.util.List; * * @hide */ @SystemApi public final class BluetoothA2dpSink implements BluetoothProfile { private static final String TAG = "BluetoothA2dpSink"; private static final boolean DBG = true; Loading @@ -59,71 +62,14 @@ public final class BluetoothA2dpSink implements BluetoothProfile { * {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, * {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTING}. * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to * receive. * @hide */ @SystemApi @SuppressLint("ActionValue") @RequiresPermission(Manifest.permission.BLUETOOTH) public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.a2dp-sink.profile.action.CONNECTION_STATE_CHANGED"; /** * Intent used to broadcast the change in the Playing state of the A2DP Sink * profile. * * <p>This intent will have 3 extras: * <ul> * <li> {@link #EXTRA_STATE} - The current state of the profile. </li> * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile. </li> * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> * </ul> * * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of * {@link #STATE_PLAYING}, {@link #STATE_NOT_PLAYING}, * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to * receive. */ public static final String ACTION_PLAYING_STATE_CHANGED = "android.bluetooth.a2dp-sink.profile.action.PLAYING_STATE_CHANGED"; /** * A2DP sink device is streaming music. This state can be one of * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of * {@link #ACTION_PLAYING_STATE_CHANGED} intent. */ public static final int STATE_PLAYING = 10; /** * A2DP sink device is NOT streaming music. This state can be one of * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of * {@link #ACTION_PLAYING_STATE_CHANGED} intent. */ public static final int STATE_NOT_PLAYING = 11; /** * Intent used to broadcast the change in the Playing state of the A2DP Sink * profile. * * <p>This intent will have 3 extras: * <ul> * <li> {@link #EXTRA_AUDIO_CONFIG} - The audio configuration for the remote device. </li> * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> * </ul> * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to * receive. */ public static final String ACTION_AUDIO_CONFIG_CHANGED = "android.bluetooth.a2dp-sink.profile.action.AUDIO_CONFIG_CHANGED"; /** * Extra for the {@link #ACTION_AUDIO_CONFIG_CHANGED} intent. * * This extra represents the current audio configuration of the A2DP source device. * {@see BluetoothAudioConfig} */ public static final String EXTRA_AUDIO_CONFIG = "android.bluetooth.a2dp-sink.profile.extra.AUDIO_CONFIG"; private BluetoothAdapter mAdapter; private final BluetoothProfileConnector<IBluetoothA2dpSink> mProfileConnector = new BluetoothProfileConnector(this, BluetoothProfile.A2DP_SINK, Loading Loading @@ -170,13 +116,11 @@ public final class BluetoothA2dpSink implements BluetoothProfile { * the state. Users can get the connection state of the profile * from this intent. * * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} * permission. * * @param device Remote Bluetooth Device * @return false on immediate error, true otherwise * @hide */ @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public boolean connect(BluetoothDevice device) { if (DBG) log("connect(" + device + ")"); final IBluetoothA2dpSink service = getService(); Loading Loading @@ -210,14 +154,12 @@ public final class BluetoothA2dpSink implements BluetoothProfile { * {@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 */ @UnsupportedAppUsage @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public boolean disconnect(BluetoothDevice device) { if (DBG) log("disconnect(" + device + ")"); final IBluetoothA2dpSink service = getService(); Loading @@ -235,6 +177,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { /** * {@inheritDoc} * * @hide */ @Override public List<BluetoothDevice> getConnectedDevices() { Loading @@ -254,6 +198,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { /** * {@inheritDoc} * * @hide */ @Override public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { Loading @@ -273,6 +219,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { /** * {@inheritDoc} * * @hide */ @Override public int getConnectionState(BluetoothDevice device) { Loading Loading @@ -300,6 +248,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { * @return audio configuration for the device, or null * * {@see BluetoothAudioConfig} * * @hide */ public BluetoothAudioConfig getAudioConfig(BluetoothDevice device) { if (VDBG) log("getAudioConfig(" + device + ")"); Loading Loading @@ -347,7 +297,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile { */ @SystemApi @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) { public boolean setConnectionPolicy(@Nullable BluetoothDevice device, int connectionPolicy) { if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")"); final IBluetoothA2dpSink service = getService(); if (service != null && isEnabled() && isValidDevice(device)) { Loading Loading @@ -395,7 +345,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile { */ @SystemApi @RequiresPermission(Manifest.permission.BLUETOOTH) public int getConnectionPolicy(BluetoothDevice device) { public int getConnectionPolicy(@Nullable BluetoothDevice device) { if (VDBG) log("getConnectionPolicy(" + device + ")"); final IBluetoothA2dpSink service = getService(); if (service != null && isEnabled() && isValidDevice(device)) { Loading @@ -411,13 +361,16 @@ public final class BluetoothA2dpSink implements BluetoothProfile { } /** * Check if A2DP profile is streaming music. * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. * Check if audio is playing on the bluetooth device (A2DP profile is streaming music). * * @param device BluetoothDevice device * @return true if audio is playing (A2dp is streaming music), false otherwise * * @hide */ public boolean isA2dpPlaying(BluetoothDevice device) { @SystemApi @RequiresPermission(Manifest.permission.BLUETOOTH) public boolean isAudioPlaying(@Nullable BluetoothDevice device) { final IBluetoothA2dpSink service = getService(); if (service != null && isEnabled() && isValidDevice(device)) { try { Loading Loading @@ -448,9 +401,9 @@ public final class BluetoothA2dpSink implements BluetoothProfile { return "connected"; case STATE_DISCONNECTING: return "disconnecting"; case STATE_PLAYING: case BluetoothA2dp.STATE_PLAYING: return "playing"; case STATE_NOT_PLAYING: case BluetoothA2dp.STATE_NOT_PLAYING: return "not playing"; default: return "<unknown state " + state + ">"; Loading Loading
framework/java/android/bluetooth/BluetoothA2dpSink.java +28 −75 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ package android.bluetooth; import android.Manifest; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.annotation.UnsupportedAppUsage; import android.content.Context; Loading @@ -39,6 +41,7 @@ import java.util.List; * * @hide */ @SystemApi public final class BluetoothA2dpSink implements BluetoothProfile { private static final String TAG = "BluetoothA2dpSink"; private static final boolean DBG = true; Loading @@ -59,71 +62,14 @@ public final class BluetoothA2dpSink implements BluetoothProfile { * {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, * {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTING}. * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to * receive. * @hide */ @SystemApi @SuppressLint("ActionValue") @RequiresPermission(Manifest.permission.BLUETOOTH) public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.a2dp-sink.profile.action.CONNECTION_STATE_CHANGED"; /** * Intent used to broadcast the change in the Playing state of the A2DP Sink * profile. * * <p>This intent will have 3 extras: * <ul> * <li> {@link #EXTRA_STATE} - The current state of the profile. </li> * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile. </li> * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> * </ul> * * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of * {@link #STATE_PLAYING}, {@link #STATE_NOT_PLAYING}, * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to * receive. */ public static final String ACTION_PLAYING_STATE_CHANGED = "android.bluetooth.a2dp-sink.profile.action.PLAYING_STATE_CHANGED"; /** * A2DP sink device is streaming music. This state can be one of * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of * {@link #ACTION_PLAYING_STATE_CHANGED} intent. */ public static final int STATE_PLAYING = 10; /** * A2DP sink device is NOT streaming music. This state can be one of * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of * {@link #ACTION_PLAYING_STATE_CHANGED} intent. */ public static final int STATE_NOT_PLAYING = 11; /** * Intent used to broadcast the change in the Playing state of the A2DP Sink * profile. * * <p>This intent will have 3 extras: * <ul> * <li> {@link #EXTRA_AUDIO_CONFIG} - The audio configuration for the remote device. </li> * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> * </ul> * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to * receive. */ public static final String ACTION_AUDIO_CONFIG_CHANGED = "android.bluetooth.a2dp-sink.profile.action.AUDIO_CONFIG_CHANGED"; /** * Extra for the {@link #ACTION_AUDIO_CONFIG_CHANGED} intent. * * This extra represents the current audio configuration of the A2DP source device. * {@see BluetoothAudioConfig} */ public static final String EXTRA_AUDIO_CONFIG = "android.bluetooth.a2dp-sink.profile.extra.AUDIO_CONFIG"; private BluetoothAdapter mAdapter; private final BluetoothProfileConnector<IBluetoothA2dpSink> mProfileConnector = new BluetoothProfileConnector(this, BluetoothProfile.A2DP_SINK, Loading Loading @@ -170,13 +116,11 @@ public final class BluetoothA2dpSink implements BluetoothProfile { * the state. Users can get the connection state of the profile * from this intent. * * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} * permission. * * @param device Remote Bluetooth Device * @return false on immediate error, true otherwise * @hide */ @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public boolean connect(BluetoothDevice device) { if (DBG) log("connect(" + device + ")"); final IBluetoothA2dpSink service = getService(); Loading Loading @@ -210,14 +154,12 @@ public final class BluetoothA2dpSink implements BluetoothProfile { * {@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 */ @UnsupportedAppUsage @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public boolean disconnect(BluetoothDevice device) { if (DBG) log("disconnect(" + device + ")"); final IBluetoothA2dpSink service = getService(); Loading @@ -235,6 +177,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { /** * {@inheritDoc} * * @hide */ @Override public List<BluetoothDevice> getConnectedDevices() { Loading @@ -254,6 +198,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { /** * {@inheritDoc} * * @hide */ @Override public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { Loading @@ -273,6 +219,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { /** * {@inheritDoc} * * @hide */ @Override public int getConnectionState(BluetoothDevice device) { Loading Loading @@ -300,6 +248,8 @@ public final class BluetoothA2dpSink implements BluetoothProfile { * @return audio configuration for the device, or null * * {@see BluetoothAudioConfig} * * @hide */ public BluetoothAudioConfig getAudioConfig(BluetoothDevice device) { if (VDBG) log("getAudioConfig(" + device + ")"); Loading Loading @@ -347,7 +297,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile { */ @SystemApi @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) { public boolean setConnectionPolicy(@Nullable BluetoothDevice device, int connectionPolicy) { if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")"); final IBluetoothA2dpSink service = getService(); if (service != null && isEnabled() && isValidDevice(device)) { Loading Loading @@ -395,7 +345,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile { */ @SystemApi @RequiresPermission(Manifest.permission.BLUETOOTH) public int getConnectionPolicy(BluetoothDevice device) { public int getConnectionPolicy(@Nullable BluetoothDevice device) { if (VDBG) log("getConnectionPolicy(" + device + ")"); final IBluetoothA2dpSink service = getService(); if (service != null && isEnabled() && isValidDevice(device)) { Loading @@ -411,13 +361,16 @@ public final class BluetoothA2dpSink implements BluetoothProfile { } /** * Check if A2DP profile is streaming music. * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. * Check if audio is playing on the bluetooth device (A2DP profile is streaming music). * * @param device BluetoothDevice device * @return true if audio is playing (A2dp is streaming music), false otherwise * * @hide */ public boolean isA2dpPlaying(BluetoothDevice device) { @SystemApi @RequiresPermission(Manifest.permission.BLUETOOTH) public boolean isAudioPlaying(@Nullable BluetoothDevice device) { final IBluetoothA2dpSink service = getService(); if (service != null && isEnabled() && isValidDevice(device)) { try { Loading Loading @@ -448,9 +401,9 @@ public final class BluetoothA2dpSink implements BluetoothProfile { return "connected"; case STATE_DISCONNECTING: return "disconnecting"; case STATE_PLAYING: case BluetoothA2dp.STATE_PLAYING: return "playing"; case STATE_NOT_PLAYING: case BluetoothA2dp.STATE_NOT_PLAYING: return "not playing"; default: return "<unknown state " + state + ">"; Loading