diff options
| author | 2018-01-06 17:41:05 +0000 | |
|---|---|---|
| committer | 2018-01-06 17:41:05 +0000 | |
| commit | e3428dae0480163ca729d762d05faa016b1180f4 (patch) | |
| tree | 14ee1fdbf0f0c59cead9d5c936800d56c783a55d | |
| parent | a4ac12c3ac754a5a89ae50dc6f8ec3d01dd2fd79 (diff) | |
| parent | 6efee9c079eecf025384228763982eecd935c2f8 (diff) | |
Merge "Added internal API to get/set the A2DP Active Device"
am: 6efee9c079
Change-Id: I5e82a41c4bcf546bdc8fd08c56103c333745c60c
| -rw-r--r-- | core/java/android/bluetooth/BluetoothA2dp.java | 88 | ||||
| -rw-r--r-- | core/res/AndroidManifest.xml | 2 |
2 files changed, 90 insertions, 0 deletions
diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java index 7841b83cf92c..35a21a4eaf9f 100644 --- a/core/java/android/bluetooth/BluetoothA2dp.java +++ b/core/java/android/bluetooth/BluetoothA2dp.java @@ -17,6 +17,7 @@ package android.bluetooth; import android.Manifest; +import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; @@ -103,6 +104,24 @@ public final class BluetoothA2dp implements BluetoothProfile { "android.bluetooth.a2dp.profile.action.AVRCP_CONNECTION_STATE_CHANGED"; /** + * Intent used to broadcast the selection of a connected device as active. + * + * <p>This intent will have one extra: + * <ul> + * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. It can + * be null if no device is active. </li> + * </ul> + * + * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to + * receive. + * + * @hide + */ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_ACTIVE_DEVICE_CHANGED = + "android.bluetooth.a2dp.profile.action.ACTIVE_DEVICE_CHANGED"; + + /** * Intent used to broadcast the change in the Audio Codec state of the * A2DP Source profile. * @@ -425,6 +444,75 @@ public final class BluetoothA2dp implements BluetoothProfile { } /** + * Select a connected device as active. + * + * The active device selection is per profile. An active device's + * purpose is profile-specific. For example, A2DP audio streaming + * is to the active A2DP Sink device. If a remote device is not + * connected, it cannot be selected as active. + * + * <p> This API returns false in scenarios like the profile on the + * device is not connected or Bluetooth is not turned on. + * When this API returns true, it is guaranteed that the + * {@link #ACTION_ACTIVE_DEVICE_CHANGED} intent will be broadcasted + * with the active device. + * + * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} + * permission. + * + * @param device the remote Bluetooth device. Could be null to clear + * the active device and stop streaming audio to a Bluetooth device. + * @return false on immediate error, true otherwise + * @hide + */ + public boolean setActiveDevice(@Nullable BluetoothDevice device) { + if (DBG) log("setActiveDevice(" + device + ")"); + try { + mServiceLock.readLock().lock(); + if (mService != null && isEnabled() + && ((device == null) || isValidDevice(device))) { + return mService.setActiveDevice(device); + } + if (mService == null) Log.w(TAG, "Proxy not attached to service"); + return false; + } catch (RemoteException e) { + Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); + return false; + } finally { + mServiceLock.readLock().unlock(); + } + } + + /** + * Get the connected device that is active. + * + * <p>Requires {@link android.Manifest.permission#BLUETOOTH} + * permission. + * + * @return the connected device that is active or null if no device + * is active + * @hide + */ + @RequiresPermission(Manifest.permission.BLUETOOTH) + @Nullable + public BluetoothDevice getActiveDevice() { + if (VDBG) log("getActiveDevice()"); + try { + mServiceLock.readLock().lock(); + if (mService != null && isEnabled()) { + return mService.getActiveDevice(); + } + if (mService == null) Log.w(TAG, "Proxy not attached to service"); + return null; + } catch (RemoteException e) { + Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); + return null; + } finally { + mServiceLock.readLock().unlock(); + } + } + + /** * Set priority of the profile * * <p> The device should already be paired. diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 90729607006f..e33c822dfc7d 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -173,6 +173,8 @@ <protected-broadcast android:name="android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED" /> <protected-broadcast + android:name="android.bluetooth.a2dp.profile.action.ACTIVE_DEVICE_CHANGED" /> + <protected-broadcast android:name="android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED" /> <protected-broadcast android:name="android.bluetooth.a2dp.profile.action.CODEC_CONFIG_CHANGED" /> |