diff options
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothA2dp.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothA2dp.java | 167 |
1 files changed, 91 insertions, 76 deletions
diff --git a/framework/java/android/bluetooth/BluetoothA2dp.java b/framework/java/android/bluetooth/BluetoothA2dp.java index c58eaa14ed..7841b83cf9 100644 --- a/framework/java/android/bluetooth/BluetoothA2dp.java +++ b/framework/java/android/bluetooth/BluetoothA2dp.java @@ -42,7 +42,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; * This class provides the public APIs to control the Bluetooth A2DP * profile. * - *<p>BluetoothA2dp is a proxy object for controlling the Bluetooth A2DP + * <p>BluetoothA2dp is a proxy object for controlling the Bluetooth A2DP * Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get * the BluetoothA2dp proxy object. * @@ -60,9 +60,9 @@ public final class BluetoothA2dp implements BluetoothProfile { * * <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> + * <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 @@ -74,7 +74,7 @@ public final class BluetoothA2dp implements BluetoothProfile { */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_CONNECTION_STATE_CHANGED = - "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED"; + "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED"; /** * Intent used to broadcast the change in the Playing state of the A2DP @@ -82,9 +82,9 @@ public final class BluetoothA2dp implements BluetoothProfile { * * <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> + * <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 @@ -95,12 +95,12 @@ public final class BluetoothA2dp implements BluetoothProfile { */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_PLAYING_STATE_CHANGED = - "android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED"; + "android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED"; /** @hide */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_AVRCP_CONNECTION_STATE_CHANGED = - "android.bluetooth.a2dp.profile.action.AVRCP_CONNECTION_STATE_CHANGED"; + "android.bluetooth.a2dp.profile.action.AVRCP_CONNECTION_STATE_CHANGED"; /** * Intent used to broadcast the change in the Audio Codec state of the @@ -108,9 +108,9 @@ public final class BluetoothA2dp implements BluetoothProfile { * * <p>This intent will have 2 extras: * <ul> - * <li> {@link BluetoothCodecStatus#EXTRA_CODEC_STATUS} - The codec status. </li> - * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device if the device is currently - * connected, otherwise it is not included.</li> + * <li> {@link BluetoothCodecStatus#EXTRA_CODEC_STATUS} - The codec status. </li> + * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device if the device is currently + * connected, otherwise it is not included.</li> * </ul> * * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to @@ -120,61 +120,74 @@ public final class BluetoothA2dp implements BluetoothProfile { */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_CODEC_CONFIG_CHANGED = - "android.bluetooth.a2dp.profile.action.CODEC_CONFIG_CHANGED"; + "android.bluetooth.a2dp.profile.action.CODEC_CONFIG_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; + 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; + public static final int STATE_NOT_PLAYING = 11; /** * We don't have a stored preference for whether or not the given A2DP sink device supports * optional codecs. - * @hide */ + * + * @hide + */ public static final int OPTIONAL_CODECS_SUPPORT_UNKNOWN = -1; /** * The given A2DP sink device does not support optional codecs. - * @hide */ + * + * @hide + */ public static final int OPTIONAL_CODECS_NOT_SUPPORTED = 0; /** * The given A2DP sink device does support optional codecs. - * @hide */ + * + * @hide + */ public static final int OPTIONAL_CODECS_SUPPORTED = 1; /** * We don't have a stored preference for whether optional codecs should be enabled or disabled * for the given A2DP device. - * @hide */ + * + * @hide + */ public static final int OPTIONAL_CODECS_PREF_UNKNOWN = -1; /** * Optional codecs should be disabled for the given A2DP device. - * @hide */ + * + * @hide + */ public static final int OPTIONAL_CODECS_PREF_DISABLED = 0; /** - * Optional codecs should be enabled for the given A2DP device. - * @hide */ + * Optional codecs should be enabled for the given A2DP device. + * + * @hide + */ public static final int OPTIONAL_CODECS_PREF_ENABLED = 1; private Context mContext; private ServiceListener mServiceListener; private final ReentrantReadWriteLock mServiceLock = new ReentrantReadWriteLock(); - @GuardedBy("mServiceLock") private IBluetoothA2dp mService; + @GuardedBy("mServiceLock") + private IBluetoothA2dp mService; private BluetoothAdapter mAdapter; - final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback = + private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback = new IBluetoothStateChangeCallback.Stub() { public void onBluetoothStateChange(boolean up) { if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up); @@ -193,21 +206,21 @@ public final class BluetoothA2dp implements BluetoothProfile { try { mServiceLock.readLock().lock(); if (mService == null) { - if (VDBG) Log.d(TAG,"Binding service..."); + if (VDBG) Log.d(TAG, "Binding service..."); doBind(); } } catch (Exception re) { - Log.e(TAG,"",re); + Log.e(TAG, "", re); } finally { mServiceLock.readLock().unlock(); } } } - }; + }; + /** * Create a BluetoothA2dp proxy object for interacting with the local * Bluetooth A2DP service. - * */ /*package*/ BluetoothA2dp(Context context, ServiceListener l) { mContext = context; @@ -218,7 +231,7 @@ public final class BluetoothA2dp implements BluetoothProfile { try { mgr.registerStateChangeCallback(mBluetoothStateChangeCallback); } catch (RemoteException e) { - Log.e(TAG,"",e); + Log.e(TAG, "", e); } } @@ -244,7 +257,7 @@ public final class BluetoothA2dp implements BluetoothProfile { try { mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback); } catch (Exception e) { - Log.e(TAG,"",e); + Log.e(TAG, "", e); } } @@ -261,10 +274,12 @@ public final class BluetoothA2dp implements BluetoothProfile { } } + @Override public void finalize() { // The empty finalize needs to be kept or the // cts signature tests would fail. } + /** * Initiate connection to a profile of the remote bluetooth device. * @@ -283,16 +298,14 @@ public final class BluetoothA2dp implements BluetoothProfile { * permission. * * @param device Remote Bluetooth Device - * @return false on immediate error, - * true otherwise + * @return false on immediate error, true otherwise * @hide */ public boolean connect(BluetoothDevice device) { if (DBG) log("connect(" + device + ")"); try { mServiceLock.readLock().lock(); - if (mService != null && isEnabled() && - isValidDevice(device)) { + if (mService != null && isEnabled() && isValidDevice(device)) { return mService.connect(device); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); @@ -327,16 +340,14 @@ public final class BluetoothA2dp implements BluetoothProfile { * permission. * * @param device Remote Bluetooth Device - * @return false on immediate error, - * true otherwise + * @return false on immediate error, true otherwise * @hide */ public boolean disconnect(BluetoothDevice device) { if (DBG) log("disconnect(" + device + ")"); try { mServiceLock.readLock().lock(); - if (mService != null && isEnabled() && - isValidDevice(device)) { + if (mService != null && isEnabled() && isValidDevice(device)) { return mService.disconnect(device); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); @@ -352,6 +363,7 @@ public final class BluetoothA2dp implements BluetoothProfile { /** * {@inheritDoc} */ + @Override public List<BluetoothDevice> getConnectedDevices() { if (VDBG) log("getConnectedDevices()"); try { @@ -372,6 +384,7 @@ public final class BluetoothA2dp implements BluetoothProfile { /** * {@inheritDoc} */ + @Override public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { if (VDBG) log("getDevicesMatchingStates()"); try { @@ -392,12 +405,13 @@ public final class BluetoothA2dp implements BluetoothProfile { /** * {@inheritDoc} */ + @Override public int getConnectionState(BluetoothDevice device) { if (VDBG) log("getState(" + device + ")"); try { mServiceLock.readLock().lock(); if (mService != null && isEnabled() - && isValidDevice(device)) { + && isValidDevice(device)) { return mService.getConnectionState(device); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); @@ -414,7 +428,7 @@ public final class BluetoothA2dp implements BluetoothProfile { * Set priority of the profile * * <p> The device should already be paired. - * Priority can be one of {@link #PRIORITY_ON} orgetBluetoothManager + * Priority can be one of {@link #PRIORITY_ON} orgetBluetoothManager * {@link #PRIORITY_OFF}, * * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} @@ -430,9 +444,9 @@ public final class BluetoothA2dp implements BluetoothProfile { try { mServiceLock.readLock().lock(); if (mService != null && isEnabled() - && isValidDevice(device)) { - if (priority != BluetoothProfile.PRIORITY_OFF && - priority != BluetoothProfile.PRIORITY_ON) { + && isValidDevice(device)) { + if (priority != BluetoothProfile.PRIORITY_OFF + && priority != BluetoothProfile.PRIORITY_ON) { return false; } return mService.setPriority(device, priority); @@ -464,7 +478,7 @@ public final class BluetoothA2dp implements BluetoothProfile { try { mServiceLock.readLock().lock(); if (mService != null && isEnabled() - && isValidDevice(device)) { + && isValidDevice(device)) { return mService.getPriority(device); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); @@ -560,7 +574,7 @@ public final class BluetoothA2dp implements BluetoothProfile { try { mServiceLock.readLock().lock(); if (mService != null && isEnabled() - && isValidDevice(device)) { + && isValidDevice(device)) { return mService.isA2dpPlaying(device); } if (mService == null) Log.w(TAG, "Proxy not attached to service"); @@ -577,6 +591,7 @@ public final class BluetoothA2dp implements BluetoothProfile { * This function checks if the remote device is an AVCRP * target and thus whether we should send volume keys * changes or not. + * * @hide */ public boolean shouldSendVolumeKeys(BluetoothDevice device) { @@ -584,7 +599,7 @@ public final class BluetoothA2dp implements BluetoothProfile { ParcelUuid[] uuids = device.getUuids(); if (uuids == null) return false; - for (ParcelUuid uuid: uuids) { + for (ParcelUuid uuid : uuids) { if (BluetoothUuid.isAvrcpTarget(uuid)) { return true; } @@ -691,8 +706,7 @@ public final class BluetoothA2dp implements BluetoothProfile { * * @param device The device to check * @return one of OPTIONAL_CODECS_SUPPORT_UNKNOWN, OPTIONAL_CODECS_NOT_SUPPORTED, or - * OPTIONAL_CODECS_SUPPORTED. - * + * OPTIONAL_CODECS_SUPPORTED. * @hide */ public int supportsOptionalCodecs(BluetoothDevice device) { @@ -716,8 +730,7 @@ public final class BluetoothA2dp implements BluetoothProfile { * * @param device The device in question. * @return one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or - * OPTIONAL_CODECS_PREF_DISABLED. - * + * OPTIONAL_CODECS_PREF_DISABLED. * @hide */ public int getOptionalCodecsEnabled(BluetoothDevice device) { @@ -741,15 +754,15 @@ public final class BluetoothA2dp implements BluetoothProfile { * * @param device The device to set this preference for. * @param value Whether the optional codecs should be enabled for this device. This should be - * one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or - * OPTIONAL_CODECS_PREF_DISABLED. + * one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or + * OPTIONAL_CODECS_PREF_DISABLED. * @hide */ public void setOptionalCodecsEnabled(BluetoothDevice device, int value) { try { - if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN && - value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED && - value != BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) { + if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN + && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED + && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) { Log.e(TAG, "Invalid value passed to setOptionalCodecsEnabled: " + value); return; } @@ -772,24 +785,25 @@ public final class BluetoothA2dp implements BluetoothProfile { * Helper for converting a state to a string. * * For debug use only - strings are not internationalized. + * * @hide */ public static String stateToString(int state) { switch (state) { - case STATE_DISCONNECTED: - return "disconnected"; - case STATE_CONNECTING: - return "connecting"; - case STATE_CONNECTED: - return "connected"; - case STATE_DISCONNECTING: - return "disconnecting"; - case STATE_PLAYING: - return "playing"; - case STATE_NOT_PLAYING: - return "not playing"; - default: - return "<unknown state " + state + ">"; + case STATE_DISCONNECTED: + return "disconnected"; + case STATE_CONNECTING: + return "connecting"; + case STATE_CONNECTED: + return "connected"; + case STATE_DISCONNECTING: + return "disconnecting"; + case STATE_PLAYING: + return "playing"; + case STATE_NOT_PLAYING: + return "not playing"; + default: + return "<unknown state " + state + ">"; } } @@ -807,6 +821,7 @@ public final class BluetoothA2dp implements BluetoothProfile { mServiceListener.onServiceConnected(BluetoothProfile.A2DP, BluetoothA2dp.this); } } + public void onServiceDisconnected(ComponentName className) { if (DBG) Log.d(TAG, "Proxy object disconnected"); try { @@ -822,18 +837,18 @@ public final class BluetoothA2dp implements BluetoothProfile { }; private boolean isEnabled() { - if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true; - return false; + if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true; + return false; } private boolean isValidDevice(BluetoothDevice device) { - if (device == null) return false; + if (device == null) return false; - if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true; - return false; + if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true; + return false; } private static void log(String msg) { - Log.d(TAG, msg); + Log.d(TAG, msg); } } |