The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.bluetooth; |
| 18 | |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 21 | import android.annotation.RequiresPermission; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.annotation.SdkConstant; |
| 23 | import android.annotation.SdkConstant.SdkConstantType; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 24 | import android.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.Context; |
Jeff Sharkey | 0a17db1 | 2016-11-04 11:23:46 -0600 | [diff] [blame] | 26 | import android.os.Binder; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 27 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.os.IBinder; |
Jaikumar Ganesh | 41d5c80 | 2010-10-13 19:11:28 -0700 | [diff] [blame] | 29 | import android.os.ParcelUuid; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 30 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.util.Log; |
| 32 | |
Jaikumar Ganesh | 03cd78c | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 33 | import java.util.ArrayList; |
| 34 | import java.util.List; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 35 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 38 | * This class provides the public APIs to control the Bluetooth A2DP |
| 39 | * profile. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 41 | * <p>BluetoothA2dp is a proxy object for controlling the Bluetooth A2DP |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 42 | * Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get |
| 43 | * the BluetoothA2dp proxy object. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | * |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 45 | * <p> Android only supports one connected Bluetooth A2dp device at a time. |
| 46 | * Each method is protected with its appropriate permission. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | */ |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 48 | public final class BluetoothA2dp implements BluetoothProfile { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | private static final String TAG = "BluetoothA2dp"; |
Matthew Xie | 3e8c82e | 2012-02-16 16:57:18 -0800 | [diff] [blame] | 50 | private static final boolean DBG = true; |
Matthew Xie | 563e414 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 51 | private static final boolean VDBG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 53 | /** |
| 54 | * Intent used to broadcast the change in connection state of the A2DP |
| 55 | * profile. |
| 56 | * |
| 57 | * <p>This intent will have 3 extras: |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 58 | * <ul> |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 59 | * <li> {@link #EXTRA_STATE} - The current state of the profile. </li> |
| 60 | * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile.</li> |
| 61 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 62 | * </ul> |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 63 | * |
Jaikumar Ganesh | 0706fed | 2011-01-26 11:46:56 -0800 | [diff] [blame] | 64 | * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 65 | * {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, |
| 66 | * {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTING}. |
| 67 | * |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 68 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to |
| 69 | * receive. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | */ |
| 71 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 72 | public static final String ACTION_CONNECTION_STATE_CHANGED = |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 73 | "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Intent used to broadcast the change in the Playing state of the A2DP |
| 77 | * profile. |
| 78 | * |
| 79 | * <p>This intent will have 3 extras: |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 80 | * <ul> |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 81 | * <li> {@link #EXTRA_STATE} - The current state of the profile. </li> |
| 82 | * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile. </li> |
| 83 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li> |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 84 | * </ul> |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 85 | * |
Jaikumar Ganesh | 0706fed | 2011-01-26 11:46:56 -0800 | [diff] [blame] | 86 | * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 87 | * {@link #STATE_PLAYING}, {@link #STATE_NOT_PLAYING}, |
| 88 | * |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 89 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to |
| 90 | * receive. |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 91 | */ |
| 92 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 93 | public static final String ACTION_PLAYING_STATE_CHANGED = |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 94 | "android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | |
Hemant Gupta | 3b76a4b | 2014-02-14 19:53:31 +0530 | [diff] [blame] | 96 | /** @hide */ |
| 97 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 98 | public static final String ACTION_AVRCP_CONNECTION_STATE_CHANGED = |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 99 | "android.bluetooth.a2dp.profile.action.AVRCP_CONNECTION_STATE_CHANGED"; |
Hemant Gupta | 3b76a4b | 2014-02-14 19:53:31 +0530 | [diff] [blame] | 100 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 101 | /** |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 102 | * Intent used to broadcast the selection of a connected device as active. |
| 103 | * |
| 104 | * <p>This intent will have one extra: |
| 105 | * <ul> |
| 106 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. It can |
| 107 | * be null if no device is active. </li> |
| 108 | * </ul> |
| 109 | * |
| 110 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to |
| 111 | * receive. |
| 112 | * |
| 113 | * @hide |
| 114 | */ |
| 115 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 116 | @UnsupportedAppUsage |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 117 | public static final String ACTION_ACTIVE_DEVICE_CHANGED = |
| 118 | "android.bluetooth.a2dp.profile.action.ACTIVE_DEVICE_CHANGED"; |
| 119 | |
| 120 | /** |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 121 | * Intent used to broadcast the change in the Audio Codec state of the |
| 122 | * A2DP Source profile. |
| 123 | * |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 124 | * <p>This intent will have 2 extras: |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 125 | * <ul> |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 126 | * <li> {@link BluetoothCodecStatus#EXTRA_CODEC_STATUS} - The codec status. </li> |
| 127 | * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device if the device is currently |
| 128 | * connected, otherwise it is not included.</li> |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 129 | * </ul> |
| 130 | * |
| 131 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to |
| 132 | * receive. |
| 133 | * |
| 134 | * @hide |
| 135 | */ |
| 136 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 137 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 138 | public static final String ACTION_CODEC_CONFIG_CHANGED = |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 139 | "android.bluetooth.a2dp.profile.action.CODEC_CONFIG_CHANGED"; |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 140 | |
| 141 | /** |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 142 | * A2DP sink device is streaming music. This state can be one of |
| 143 | * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of |
| 144 | * {@link #ACTION_PLAYING_STATE_CHANGED} intent. |
| 145 | */ |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 146 | public static final int STATE_PLAYING = 10; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 147 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 148 | /** |
| 149 | * A2DP sink device is NOT streaming music. This state can be one of |
| 150 | * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of |
| 151 | * {@link #ACTION_PLAYING_STATE_CHANGED} intent. |
| 152 | */ |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 153 | public static final int STATE_NOT_PLAYING = 11; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 154 | |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 155 | /** |
| 156 | * We don't have a stored preference for whether or not the given A2DP sink device supports |
| 157 | * optional codecs. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 158 | * |
| 159 | * @hide |
| 160 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 161 | @UnsupportedAppUsage |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 162 | public static final int OPTIONAL_CODECS_SUPPORT_UNKNOWN = -1; |
| 163 | |
| 164 | /** |
| 165 | * The given A2DP sink device does not support optional codecs. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 166 | * |
| 167 | * @hide |
| 168 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 169 | @UnsupportedAppUsage |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 170 | public static final int OPTIONAL_CODECS_NOT_SUPPORTED = 0; |
| 171 | |
| 172 | /** |
| 173 | * The given A2DP sink device does support optional codecs. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 174 | * |
| 175 | * @hide |
| 176 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 177 | @UnsupportedAppUsage |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 178 | public static final int OPTIONAL_CODECS_SUPPORTED = 1; |
| 179 | |
| 180 | /** |
| 181 | * We don't have a stored preference for whether optional codecs should be enabled or disabled |
| 182 | * for the given A2DP device. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 183 | * |
| 184 | * @hide |
| 185 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 186 | @UnsupportedAppUsage |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 187 | public static final int OPTIONAL_CODECS_PREF_UNKNOWN = -1; |
| 188 | |
| 189 | /** |
| 190 | * Optional codecs should be disabled for the given A2DP device. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 191 | * |
| 192 | * @hide |
| 193 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 194 | @UnsupportedAppUsage |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 195 | public static final int OPTIONAL_CODECS_PREF_DISABLED = 0; |
| 196 | |
| 197 | /** |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 198 | * Optional codecs should be enabled for the given A2DP device. |
| 199 | * |
| 200 | * @hide |
| 201 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 202 | @UnsupportedAppUsage |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 203 | public static final int OPTIONAL_CODECS_PREF_ENABLED = 1; |
| 204 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 205 | private BluetoothAdapter mAdapter; |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 206 | private final BluetoothProfileConnector<IBluetoothA2dp> mProfileConnector = |
| 207 | new BluetoothProfileConnector(this, BluetoothProfile.A2DP, "BluetoothA2dp", |
| 208 | IBluetoothA2dp.class.getName()) { |
| 209 | @Override |
| 210 | public IBluetoothA2dp getServiceInterface(IBinder service) { |
| 211 | return IBluetoothA2dp.Stub.asInterface(Binder.allowBlocking(service)); |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 212 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 213 | }; |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | /** |
| 216 | * Create a BluetoothA2dp proxy object for interacting with the local |
| 217 | * Bluetooth A2DP service. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | */ |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 219 | /*package*/ BluetoothA2dp(Context context, ServiceListener listener) { |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 220 | mAdapter = BluetoothAdapter.getDefaultAdapter(); |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 221 | mProfileConnector.connect(context, listener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 224 | @UnsupportedAppUsage |
Jaikumar Ganesh | 9bb2751 | 2011-11-28 09:59:08 -0800 | [diff] [blame] | 225 | /*package*/ void close() { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 226 | mProfileConnector.disconnect(); |
| 227 | } |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 228 | |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 229 | private IBluetoothA2dp getService() { |
| 230 | return mProfileConnector.getService(); |
Jaikumar Ganesh | 9bb2751 | 2011-11-28 09:59:08 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 233 | @Override |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 234 | public void finalize() { |
Mathias Jeppsson | 2d2d8c2 | 2013-08-06 11:41:55 +0200 | [diff] [blame] | 235 | // The empty finalize needs to be kept or the |
| 236 | // cts signature tests would fail. |
fredc | 0f42037 | 2012-04-12 00:02:00 -0700 | [diff] [blame] | 237 | } |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 238 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 239 | /** |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 240 | * Initiate connection to a profile of the remote Bluetooth device. |
Jaikumar Ganesh | f878916 | 2011-05-26 13:56:40 -0700 | [diff] [blame] | 241 | * |
| 242 | * <p> This API returns false in scenarios like the profile on the |
| 243 | * device is already connected or Bluetooth is not turned on. |
| 244 | * When this API returns true, it is guaranteed that |
| 245 | * connection state intent for the profile will be broadcasted with |
| 246 | * the state. Users can get the connection state of the profile |
| 247 | * from this intent. |
| 248 | * |
| 249 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 250 | * permission. |
| 251 | * |
| 252 | * @param device Remote Bluetooth Device |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 253 | * @return false on immediate error, true otherwise |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 254 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 256 | @UnsupportedAppUsage |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 257 | public boolean connect(BluetoothDevice device) { |
| 258 | if (DBG) log("connect(" + device + ")"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 259 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 260 | final IBluetoothA2dp service = getService(); |
| 261 | if (service != null && isEnabled() && isValidDevice(device)) { |
| 262 | return service.connect(device); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 263 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 264 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 265 | return false; |
| 266 | } catch (RemoteException e) { |
| 267 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 268 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 272 | /** |
Jaikumar Ganesh | f878916 | 2011-05-26 13:56:40 -0700 | [diff] [blame] | 273 | * Initiate disconnection from a profile |
| 274 | * |
| 275 | * <p> This API will return false in scenarios like the profile on the |
| 276 | * Bluetooth device is not in connected state etc. When this API returns, |
| 277 | * true, it is guaranteed that the connection state change |
| 278 | * intent will be broadcasted with the state. Users can get the |
| 279 | * disconnection state of the profile from this intent. |
| 280 | * |
| 281 | * <p> If the disconnection is initiated by a remote device, the state |
| 282 | * will transition from {@link #STATE_CONNECTED} to |
| 283 | * {@link #STATE_DISCONNECTED}. If the disconnect is initiated by the |
| 284 | * host (local) device the state will transition from |
| 285 | * {@link #STATE_CONNECTED} to state {@link #STATE_DISCONNECTING} to |
| 286 | * state {@link #STATE_DISCONNECTED}. The transition to |
| 287 | * {@link #STATE_DISCONNECTING} can be used to distinguish between the |
| 288 | * two scenarios. |
| 289 | * |
| 290 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 291 | * permission. |
| 292 | * |
| 293 | * @param device Remote Bluetooth Device |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 294 | * @return false on immediate error, true otherwise |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 295 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 297 | @UnsupportedAppUsage |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 298 | public boolean disconnect(BluetoothDevice device) { |
| 299 | if (DBG) log("disconnect(" + device + ")"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 300 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 301 | final IBluetoothA2dp service = getService(); |
| 302 | if (service != null && isEnabled() && isValidDevice(device)) { |
| 303 | return service.disconnect(device); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 304 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 305 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 306 | return false; |
| 307 | } catch (RemoteException e) { |
| 308 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 309 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 313 | /** |
| 314 | * {@inheritDoc} |
| 315 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 316 | @Override |
Jaikumar Ganesh | 03cd78c | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 317 | public List<BluetoothDevice> getConnectedDevices() { |
Matthew Xie | 563e414 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 318 | if (VDBG) log("getConnectedDevices()"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 319 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 320 | final IBluetoothA2dp service = getService(); |
| 321 | if (service != null && isEnabled()) { |
| 322 | return service.getConnectedDevices(); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 323 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 324 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 325 | return new ArrayList<BluetoothDevice>(); |
| 326 | } catch (RemoteException e) { |
| 327 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 328 | return new ArrayList<BluetoothDevice>(); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 329 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
| 333 | * {@inheritDoc} |
| 334 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 335 | @Override |
Jaikumar Ganesh | 03cd78c | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 336 | public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { |
Matthew Xie | 563e414 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 337 | if (VDBG) log("getDevicesMatchingStates()"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 338 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 339 | final IBluetoothA2dp service = getService(); |
| 340 | if (service != null && isEnabled()) { |
| 341 | return service.getDevicesMatchingConnectionStates(states); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 342 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 343 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 344 | return new ArrayList<BluetoothDevice>(); |
| 345 | } catch (RemoteException e) { |
| 346 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 347 | return new ArrayList<BluetoothDevice>(); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 348 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /** |
| 352 | * {@inheritDoc} |
| 353 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 354 | @Override |
Jean-Michel Trivi | 5885037 | 2018-09-14 16:01:28 -0700 | [diff] [blame] | 355 | public @BtProfileState int getConnectionState(BluetoothDevice device) { |
Matthew Xie | 563e414 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 356 | if (VDBG) log("getState(" + device + ")"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 357 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 358 | final IBluetoothA2dp service = getService(); |
| 359 | if (service != null && isEnabled() |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 360 | && isValidDevice(device)) { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 361 | return service.getConnectionState(device); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 362 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 363 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 364 | return BluetoothProfile.STATE_DISCONNECTED; |
| 365 | } catch (RemoteException e) { |
| 366 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 367 | return BluetoothProfile.STATE_DISCONNECTED; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 368 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /** |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 372 | * Select a connected device as active. |
| 373 | * |
| 374 | * The active device selection is per profile. An active device's |
| 375 | * purpose is profile-specific. For example, A2DP audio streaming |
| 376 | * is to the active A2DP Sink device. If a remote device is not |
| 377 | * connected, it cannot be selected as active. |
| 378 | * |
| 379 | * <p> This API returns false in scenarios like the profile on the |
| 380 | * device is not connected or Bluetooth is not turned on. |
| 381 | * When this API returns true, it is guaranteed that the |
| 382 | * {@link #ACTION_ACTIVE_DEVICE_CHANGED} intent will be broadcasted |
| 383 | * with the active device. |
| 384 | * |
| 385 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 386 | * permission. |
| 387 | * |
| 388 | * @param device the remote Bluetooth device. Could be null to clear |
| 389 | * the active device and stop streaming audio to a Bluetooth device. |
| 390 | * @return false on immediate error, true otherwise |
| 391 | * @hide |
| 392 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 393 | @UnsupportedAppUsage |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 394 | public boolean setActiveDevice(@Nullable BluetoothDevice device) { |
| 395 | if (DBG) log("setActiveDevice(" + device + ")"); |
| 396 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 397 | final IBluetoothA2dp service = getService(); |
| 398 | if (service != null && isEnabled() |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 399 | && ((device == null) || isValidDevice(device))) { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 400 | return service.setActiveDevice(device); |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 401 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 402 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 403 | return false; |
| 404 | } catch (RemoteException e) { |
| 405 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 406 | return false; |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Get the connected device that is active. |
| 412 | * |
| 413 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} |
| 414 | * permission. |
| 415 | * |
| 416 | * @return the connected device that is active or null if no device |
| 417 | * is active |
| 418 | * @hide |
| 419 | */ |
| 420 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| 421 | @Nullable |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 422 | @UnsupportedAppUsage |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 423 | public BluetoothDevice getActiveDevice() { |
| 424 | if (VDBG) log("getActiveDevice()"); |
| 425 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 426 | final IBluetoothA2dp service = getService(); |
| 427 | if (service != null && isEnabled()) { |
| 428 | return service.getActiveDevice(); |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 429 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 430 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 431 | return null; |
| 432 | } catch (RemoteException e) { |
| 433 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 434 | return null; |
Pavlin Radoslavov | 64a9435 | 2017-12-19 13:20:06 -0800 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | |
| 438 | /** |
Jaikumar Ganesh | f878916 | 2011-05-26 13:56:40 -0700 | [diff] [blame] | 439 | * Set priority of the profile |
| 440 | * |
| 441 | * <p> The device should already be paired. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 442 | * Priority can be one of {@link #PRIORITY_ON} orgetBluetoothManager |
Jaikumar Ganesh | f878916 | 2011-05-26 13:56:40 -0700 | [diff] [blame] | 443 | * {@link #PRIORITY_OFF}, |
| 444 | * |
| 445 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 446 | * permission. |
| 447 | * |
| 448 | * @param device Paired bluetooth device |
| 449 | * @param priority |
| 450 | * @return true if priority is set, false on error |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 451 | * @hide |
| 452 | */ |
| 453 | public boolean setPriority(BluetoothDevice device, int priority) { |
| 454 | if (DBG) log("setPriority(" + device + ", " + priority + ")"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 455 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 456 | final IBluetoothA2dp service = getService(); |
| 457 | if (service != null && isEnabled() |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 458 | && isValidDevice(device)) { |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 459 | if (priority != BluetoothProfile.PRIORITY_OFF |
| 460 | && priority != BluetoothProfile.PRIORITY_ON) { |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 461 | return false; |
| 462 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 463 | return service.setPriority(device, priority); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 464 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 465 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 466 | return false; |
| 467 | } catch (RemoteException e) { |
| 468 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 469 | return false; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 470 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | /** |
Jaikumar Ganesh | f878916 | 2011-05-26 13:56:40 -0700 | [diff] [blame] | 474 | * Get the priority of the profile. |
| 475 | * |
| 476 | * <p> The priority can be any of: |
| 477 | * {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF}, |
| 478 | * {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED} |
| 479 | * |
Jaikumar Ganesh | f878916 | 2011-05-26 13:56:40 -0700 | [diff] [blame] | 480 | * @param device Bluetooth device |
| 481 | * @return priority of the device |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 482 | * @hide |
| 483 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 484 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 485 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 486 | public int getPriority(BluetoothDevice device) { |
Matthew Xie | 563e414 | 2012-10-09 22:10:37 -0700 | [diff] [blame] | 487 | if (VDBG) log("getPriority(" + device + ")"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 488 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 489 | final IBluetoothA2dp service = getService(); |
| 490 | if (service != null && isEnabled() |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 491 | && isValidDevice(device)) { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 492 | return service.getPriority(device); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 493 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 494 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 495 | return BluetoothProfile.PRIORITY_OFF; |
| 496 | } catch (RemoteException e) { |
| 497 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 498 | return BluetoothProfile.PRIORITY_OFF; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 499 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** |
John Du | 5a0cf7a | 2013-07-19 11:30:34 -0700 | [diff] [blame] | 503 | * Checks if Avrcp device supports the absolute volume feature. |
| 504 | * |
| 505 | * @return true if device supports absolute volume |
| 506 | * @hide |
| 507 | */ |
| 508 | public boolean isAvrcpAbsoluteVolumeSupported() { |
| 509 | if (DBG) Log.d(TAG, "isAvrcpAbsoluteVolumeSupported"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 510 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 511 | final IBluetoothA2dp service = getService(); |
| 512 | if (service != null && isEnabled()) { |
| 513 | return service.isAvrcpAbsoluteVolumeSupported(); |
John Du | 5a0cf7a | 2013-07-19 11:30:34 -0700 | [diff] [blame] | 514 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 515 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 516 | return false; |
| 517 | } catch (RemoteException e) { |
| 518 | Log.e(TAG, "Error talking to BT service in isAvrcpAbsoluteVolumeSupported()", e); |
| 519 | return false; |
John Du | 5a0cf7a | 2013-07-19 11:30:34 -0700 | [diff] [blame] | 520 | } |
John Du | 5a0cf7a | 2013-07-19 11:30:34 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /** |
John Du | 5a0cf7a | 2013-07-19 11:30:34 -0700 | [diff] [blame] | 524 | * Tells remote device to set an absolute volume. Only if absolute volume is supported |
| 525 | * |
| 526 | * @param volume Absolute volume to be set on AVRCP side |
| 527 | * @hide |
| 528 | */ |
| 529 | public void setAvrcpAbsoluteVolume(int volume) { |
| 530 | if (DBG) Log.d(TAG, "setAvrcpAbsoluteVolume"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 531 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 532 | final IBluetoothA2dp service = getService(); |
| 533 | if (service != null && isEnabled()) { |
| 534 | service.setAvrcpAbsoluteVolume(volume); |
John Du | 5a0cf7a | 2013-07-19 11:30:34 -0700 | [diff] [blame] | 535 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 536 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 537 | } catch (RemoteException e) { |
| 538 | Log.e(TAG, "Error talking to BT service in setAvrcpAbsoluteVolume()", e); |
John Du | 5a0cf7a | 2013-07-19 11:30:34 -0700 | [diff] [blame] | 539 | } |
John Du | 5a0cf7a | 2013-07-19 11:30:34 -0700 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /** |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 543 | * Check if A2DP profile is streaming music. |
| 544 | * |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 545 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 546 | * |
| 547 | * @param device BluetoothDevice device |
| 548 | */ |
| 549 | public boolean isA2dpPlaying(BluetoothDevice device) { |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 550 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 551 | final IBluetoothA2dp service = getService(); |
| 552 | if (service != null && isEnabled() |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 553 | && isValidDevice(device)) { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 554 | return service.isA2dpPlaying(device); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 555 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 556 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Calvin On | d7d16b9 | 2016-06-20 15:59:48 -0700 | [diff] [blame] | 557 | return false; |
| 558 | } catch (RemoteException e) { |
| 559 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 560 | return false; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 561 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /** |
Jaikumar Ganesh | 41d5c80 | 2010-10-13 19:11:28 -0700 | [diff] [blame] | 565 | * This function checks if the remote device is an AVCRP |
| 566 | * target and thus whether we should send volume keys |
| 567 | * changes or not. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 568 | * |
Jaikumar Ganesh | 41d5c80 | 2010-10-13 19:11:28 -0700 | [diff] [blame] | 569 | * @hide |
| 570 | */ |
| 571 | public boolean shouldSendVolumeKeys(BluetoothDevice device) { |
| 572 | if (isEnabled() && isValidDevice(device)) { |
| 573 | ParcelUuid[] uuids = device.getUuids(); |
| 574 | if (uuids == null) return false; |
| 575 | |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 576 | for (ParcelUuid uuid : uuids) { |
Jaikumar Ganesh | 41d5c80 | 2010-10-13 19:11:28 -0700 | [diff] [blame] | 577 | if (BluetoothUuid.isAvrcpTarget(uuid)) { |
| 578 | return true; |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | return false; |
| 583 | } |
| 584 | |
Matthew Xie | a0c6803 | 2011-06-25 21:47:07 -0700 | [diff] [blame] | 585 | /** |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 586 | * Gets the current codec status (configuration and capability). |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 587 | * |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 588 | * @param device the remote Bluetooth device. If null, use the current |
| 589 | * active A2DP Bluetooth device. |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 590 | * @return the current codec status |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 591 | * @hide |
| 592 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 593 | @UnsupportedAppUsage |
Jean-Michel Trivi | 5885037 | 2018-09-14 16:01:28 -0700 | [diff] [blame] | 594 | public @Nullable BluetoothCodecStatus getCodecStatus(BluetoothDevice device) { |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 595 | if (DBG) Log.d(TAG, "getCodecStatus(" + device + ")"); |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 596 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 597 | final IBluetoothA2dp service = getService(); |
| 598 | if (service != null && isEnabled()) { |
| 599 | return service.getCodecStatus(device); |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 600 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 601 | if (service == null) { |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 602 | Log.w(TAG, "Proxy not attached to service"); |
| 603 | } |
| 604 | return null; |
| 605 | } catch (RemoteException e) { |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 606 | Log.e(TAG, "Error talking to BT service in getCodecStatus()", e); |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 607 | return null; |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * Sets the codec configuration preference. |
| 613 | * |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 614 | * @param device the remote Bluetooth device. If null, use the current |
| 615 | * active A2DP Bluetooth device. |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 616 | * @param codecConfig the codec configuration preference |
| 617 | * @hide |
| 618 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 619 | @UnsupportedAppUsage |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 620 | public void setCodecConfigPreference(BluetoothDevice device, |
| 621 | BluetoothCodecConfig codecConfig) { |
| 622 | if (DBG) Log.d(TAG, "setCodecConfigPreference(" + device + ")"); |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 623 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 624 | final IBluetoothA2dp service = getService(); |
| 625 | if (service != null && isEnabled()) { |
| 626 | service.setCodecConfigPreference(device, codecConfig); |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 627 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 628 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 629 | return; |
| 630 | } catch (RemoteException e) { |
| 631 | Log.e(TAG, "Error talking to BT service in setCodecConfigPreference()", e); |
| 632 | return; |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
| 636 | /** |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 637 | * Enables the optional codecs. |
| 638 | * |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 639 | * @param device the remote Bluetooth device. If null, use the currect |
| 640 | * active A2DP Bluetooth device. |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 641 | * @hide |
| 642 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 643 | @UnsupportedAppUsage |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 644 | public void enableOptionalCodecs(BluetoothDevice device) { |
| 645 | if (DBG) Log.d(TAG, "enableOptionalCodecs(" + device + ")"); |
| 646 | enableDisableOptionalCodecs(device, true); |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /** |
| 650 | * Disables the optional codecs. |
| 651 | * |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 652 | * @param device the remote Bluetooth device. If null, use the currect |
| 653 | * active A2DP Bluetooth device. |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 654 | * @hide |
| 655 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 656 | @UnsupportedAppUsage |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 657 | public void disableOptionalCodecs(BluetoothDevice device) { |
| 658 | if (DBG) Log.d(TAG, "disableOptionalCodecs(" + device + ")"); |
| 659 | enableDisableOptionalCodecs(device, false); |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /** |
| 663 | * Enables or disables the optional codecs. |
| 664 | * |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 665 | * @param device the remote Bluetooth device. If null, use the currect |
| 666 | * active A2DP Bluetooth device. |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 667 | * @param enable if true, enable the optional codecs, other disable them |
| 668 | */ |
Pavlin Radoslavov | 502af21 | 2018-01-03 19:38:39 -0800 | [diff] [blame] | 669 | private void enableDisableOptionalCodecs(BluetoothDevice device, boolean enable) { |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 670 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 671 | final IBluetoothA2dp service = getService(); |
| 672 | if (service != null && isEnabled()) { |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 673 | if (enable) { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 674 | service.enableOptionalCodecs(device); |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 675 | } else { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 676 | service.disableOptionalCodecs(device); |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 677 | } |
| 678 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 679 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 680 | return; |
| 681 | } catch (RemoteException e) { |
| 682 | Log.e(TAG, "Error talking to BT service in enableDisableOptionalCodecs()", e); |
| 683 | return; |
Pavlin Radoslavov | 011597b | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | |
| 687 | /** |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 688 | * Returns whether this device supports optional codecs. |
| 689 | * |
| 690 | * @param device The device to check |
| 691 | * @return one of OPTIONAL_CODECS_SUPPORT_UNKNOWN, OPTIONAL_CODECS_NOT_SUPPORTED, or |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 692 | * OPTIONAL_CODECS_SUPPORTED. |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 693 | * @hide |
| 694 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 695 | @UnsupportedAppUsage |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 696 | public int supportsOptionalCodecs(BluetoothDevice device) { |
| 697 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 698 | final IBluetoothA2dp service = getService(); |
| 699 | if (service != null && isEnabled() && isValidDevice(device)) { |
| 700 | return service.supportsOptionalCodecs(device); |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 701 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 702 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 703 | return OPTIONAL_CODECS_SUPPORT_UNKNOWN; |
| 704 | } catch (RemoteException e) { |
| 705 | Log.e(TAG, "Error talking to BT service in getSupportsOptionalCodecs()", e); |
| 706 | return OPTIONAL_CODECS_SUPPORT_UNKNOWN; |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
| 710 | /** |
| 711 | * Returns whether this device should have optional codecs enabled. |
| 712 | * |
| 713 | * @param device The device in question. |
| 714 | * @return one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 715 | * OPTIONAL_CODECS_PREF_DISABLED. |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 716 | * @hide |
| 717 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 718 | @UnsupportedAppUsage |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 719 | public int getOptionalCodecsEnabled(BluetoothDevice device) { |
| 720 | try { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 721 | final IBluetoothA2dp service = getService(); |
| 722 | if (service != null && isEnabled() && isValidDevice(device)) { |
| 723 | return service.getOptionalCodecsEnabled(device); |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 724 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 725 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 726 | return OPTIONAL_CODECS_PREF_UNKNOWN; |
| 727 | } catch (RemoteException e) { |
| 728 | Log.e(TAG, "Error talking to BT service in getSupportsOptionalCodecs()", e); |
| 729 | return OPTIONAL_CODECS_PREF_UNKNOWN; |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | |
| 733 | /** |
| 734 | * Sets a persistent preference for whether a given device should have optional codecs enabled. |
| 735 | * |
| 736 | * @param device The device to set this preference for. |
| 737 | * @param value Whether the optional codecs should be enabled for this device. This should be |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 738 | * one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or |
| 739 | * OPTIONAL_CODECS_PREF_DISABLED. |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 740 | * @hide |
| 741 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 742 | @UnsupportedAppUsage |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 743 | public void setOptionalCodecsEnabled(BluetoothDevice device, int value) { |
| 744 | try { |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 745 | if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN |
| 746 | && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED |
| 747 | && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) { |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 748 | Log.e(TAG, "Invalid value passed to setOptionalCodecsEnabled: " + value); |
| 749 | return; |
| 750 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 751 | final IBluetoothA2dp service = getService(); |
| 752 | if (service != null && isEnabled() |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 753 | && isValidDevice(device)) { |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 754 | service.setOptionalCodecsEnabled(device, value); |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 755 | } |
Ugo Yu | 6d9cfce | 2019-03-26 21:38:08 +0800 | [diff] [blame] | 756 | if (service == null) Log.w(TAG, "Proxy not attached to service"); |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 757 | return; |
| 758 | } catch (RemoteException e) { |
| 759 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 760 | return; |
Antony Sargent | f5772c6 | 2017-04-26 16:37:53 -0700 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | |
| 764 | /** |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 765 | * Helper for converting a state to a string. |
| 766 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | * For debug use only - strings are not internationalized. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 768 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | * @hide |
| 770 | */ |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 771 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | public static String stateToString(int state) { |
| 773 | switch (state) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 774 | case STATE_DISCONNECTED: |
| 775 | return "disconnected"; |
| 776 | case STATE_CONNECTING: |
| 777 | return "connecting"; |
| 778 | case STATE_CONNECTED: |
| 779 | return "connected"; |
| 780 | case STATE_DISCONNECTING: |
| 781 | return "disconnecting"; |
| 782 | case STATE_PLAYING: |
| 783 | return "playing"; |
| 784 | case STATE_NOT_PLAYING: |
| 785 | return "not playing"; |
| 786 | default: |
| 787 | return "<unknown state " + state + ">"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | } |
| 789 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 790 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 791 | private boolean isEnabled() { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 792 | if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true; |
| 793 | return false; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | private boolean isValidDevice(BluetoothDevice device) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 797 | if (device == null) return false; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 798 | |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 799 | if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true; |
| 800 | return false; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 801 | } |
| 802 | |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 803 | private static void log(String msg) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 804 | Log.d(TAG, msg); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 805 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | } |