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 | |
| 19 | import android.annotation.SdkConstant; |
| 20 | import android.annotation.SdkConstant.SdkConstantType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.os.IBinder; |
Jaikumar Ganesh | 41d5c80 | 2010-10-13 19:11:28 -0700 | [diff] [blame^] | 23 | import android.os.ParcelUuid; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 24 | import android.os.RemoteException; |
| 25 | import android.os.ServiceManager; |
| 26 | import android.server.BluetoothA2dpService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 29 | import java.util.Collections; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 30 | import java.util.Arrays; |
| 31 | import java.util.HashMap; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 32 | import java.util.HashSet; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 33 | import java.util.Set; |
| 34 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 37 | * This class provides the public APIs to control the Bluetooth A2DP |
| 38 | * profile. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | * |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 40 | *<p>BluetoothA2dp is a proxy object for controlling the Bluetooth A2DP |
| 41 | * Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get |
| 42 | * the BluetoothA2dp proxy object. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | * |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 44 | * <p> Android only supports one connected Bluetooth A2dp device at a time. |
| 45 | * Each method is protected with its appropriate permission. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | */ |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 47 | public final class BluetoothA2dp implements BluetoothProfile { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | private static final String TAG = "BluetoothA2dp"; |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 49 | private static final boolean DBG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Intent used to broadcast the change in connection state of the A2DP |
| 53 | * profile. |
| 54 | * |
| 55 | * <p>This intent will have 3 extras: |
| 56 | * {@link #EXTRA_STATE} - The current state of the profile. |
| 57 | * {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile |
| 58 | * {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. |
| 59 | * |
| 60 | * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of |
| 61 | * {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, |
| 62 | * {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTING}. |
| 63 | * |
| 64 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | */ |
| 66 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 67 | public static final String ACTION_CONNECTION_STATE_CHANGED = |
| 68 | "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 70 | /** |
| 71 | * Intent used to broadcast the change in the Playing state of the A2DP |
| 72 | * profile. |
| 73 | * |
| 74 | * <p>This intent will have 3 extras: |
| 75 | * {@link #EXTRA_STATE} - The current state of the profile. |
| 76 | * {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile |
| 77 | * {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. |
| 78 | * |
| 79 | * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of |
| 80 | * {@link #STATE_PLAYING}, {@link #STATE_NOT_PLAYING}, |
| 81 | * |
| 82 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive. |
| 83 | */ |
| 84 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 85 | public static final String ACTION_PLAYING_STATE_CHANGED = |
| 86 | "android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 88 | /** |
| 89 | * A2DP sink device is streaming music. This state can be one of |
| 90 | * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of |
| 91 | * {@link #ACTION_PLAYING_STATE_CHANGED} intent. |
| 92 | */ |
| 93 | public static final int STATE_PLAYING = 10; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 94 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 95 | /** |
| 96 | * A2DP sink device is NOT streaming music. This state can be one of |
| 97 | * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of |
| 98 | * {@link #ACTION_PLAYING_STATE_CHANGED} intent. |
| 99 | */ |
| 100 | public static final int STATE_NOT_PLAYING = 11; |
| 101 | |
| 102 | private ServiceListener mServiceListener; |
| 103 | private IBluetoothA2dp mService; |
| 104 | private BluetoothAdapter mAdapter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * Create a BluetoothA2dp proxy object for interacting with the local |
| 108 | * Bluetooth A2DP service. |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 109 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | */ |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 111 | /*package*/ BluetoothA2dp(Context mContext, ServiceListener l) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | IBinder b = ServiceManager.getService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 113 | mServiceListener = l; |
| 114 | mAdapter = BluetoothAdapter.getDefaultAdapter(); |
Michael Chan | 081f58a | 2009-09-30 17:59:40 -0700 | [diff] [blame] | 115 | if (b != null) { |
| 116 | mService = IBluetoothA2dp.Stub.asInterface(b); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 117 | if (mServiceListener != null) { |
| 118 | mServiceListener.onServiceConnected(BluetoothProfile.A2DP, this); |
| 119 | } |
Michael Chan | 081f58a | 2009-09-30 17:59:40 -0700 | [diff] [blame] | 120 | } else { |
| 121 | Log.w(TAG, "Bluetooth A2DP service not available!"); |
| 122 | |
| 123 | // Instead of throwing an exception which prevents people from going |
| 124 | // into Wireless settings in the emulator. Let it crash later when it is actually used. |
| 125 | mService = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 129 | /** |
| 130 | * {@inheritDoc} |
| 131 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | */ |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 133 | public boolean connect(BluetoothDevice device) { |
| 134 | if (DBG) log("connect(" + device + ")"); |
| 135 | if (mService != null && isEnabled() && |
| 136 | isValidDevice(device)) { |
| 137 | try { |
| 138 | return mService.connect(device); |
| 139 | } catch (RemoteException e) { |
| 140 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 141 | return false; |
| 142 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 144 | if (mService == null) Log.w(TAG, "Proxy not attached to service"); |
| 145 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 148 | /** |
| 149 | * {@inheritDoc} |
| 150 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | */ |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 152 | public boolean disconnect(BluetoothDevice device) { |
| 153 | if (DBG) log("disconnect(" + device + ")"); |
| 154 | if (mService != null && isEnabled() && |
| 155 | isValidDevice(device)) { |
| 156 | try { |
| 157 | return mService.disconnect(device); |
| 158 | } catch (RemoteException e) { |
| 159 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 160 | return false; |
| 161 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 163 | if (mService == null) Log.w(TAG, "Proxy not attached to service"); |
| 164 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 167 | /** |
| 168 | * {@inheritDoc} |
| 169 | */ |
| 170 | public Set<BluetoothDevice> getConnectedDevices() { |
| 171 | if (DBG) log("getConnectedDevices()"); |
| 172 | if (mService != null && isEnabled()) { |
| 173 | try { |
| 174 | return toDeviceSet(mService.getConnectedDevices()); |
| 175 | } catch (RemoteException e) { |
| 176 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 177 | return toDeviceSet(new BluetoothDevice[0]); |
| 178 | } |
| 179 | } |
| 180 | if (mService == null) Log.w(TAG, "Proxy not attached to service"); |
| 181 | return toDeviceSet(new BluetoothDevice[0]); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * {@inheritDoc} |
| 186 | */ |
| 187 | public Set<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { |
| 188 | if (DBG) log("getDevicesMatchingStates()"); |
| 189 | if (mService != null && isEnabled()) { |
| 190 | try { |
| 191 | return toDeviceSet(mService.getDevicesMatchingConnectionStates(states)); |
| 192 | } catch (RemoteException e) { |
| 193 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 194 | return toDeviceSet(new BluetoothDevice[0]); |
| 195 | } |
| 196 | } |
| 197 | if (mService == null) Log.w(TAG, "Proxy not attached to service"); |
| 198 | return toDeviceSet(new BluetoothDevice[0]); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * {@inheritDoc} |
| 203 | */ |
| 204 | public int getConnectionState(BluetoothDevice device) { |
| 205 | if (DBG) log("getState(" + device + ")"); |
| 206 | if (mService != null && isEnabled() |
| 207 | && isValidDevice(device)) { |
| 208 | try { |
| 209 | return mService.getConnectionState(device); |
| 210 | } catch (RemoteException e) { |
| 211 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 212 | return BluetoothProfile.STATE_DISCONNECTED; |
| 213 | } |
| 214 | } |
| 215 | if (mService == null) Log.w(TAG, "Proxy not attached to service"); |
| 216 | return BluetoothProfile.STATE_DISCONNECTED; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * {@inheritDoc} |
| 221 | * @hide |
| 222 | */ |
| 223 | public boolean setPriority(BluetoothDevice device, int priority) { |
| 224 | if (DBG) log("setPriority(" + device + ", " + priority + ")"); |
| 225 | if (mService != null && isEnabled() |
| 226 | && isValidDevice(device)) { |
| 227 | if (priority != BluetoothProfile.PRIORITY_OFF && |
| 228 | priority != BluetoothProfile.PRIORITY_ON) { |
| 229 | return false; |
| 230 | } |
| 231 | try { |
| 232 | return mService.setPriority(device, priority); |
| 233 | } catch (RemoteException e) { |
| 234 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 235 | return false; |
| 236 | } |
| 237 | } |
| 238 | if (mService == null) Log.w(TAG, "Proxy not attached to service"); |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * {@inheritDoc} |
| 244 | * @hide |
| 245 | */ |
| 246 | public int getPriority(BluetoothDevice device) { |
| 247 | if (DBG) log("getPriority(" + device + ")"); |
| 248 | if (mService != null && isEnabled() |
| 249 | && isValidDevice(device)) { |
| 250 | try { |
| 251 | return mService.getPriority(device); |
| 252 | } catch (RemoteException e) { |
| 253 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 254 | return BluetoothProfile.PRIORITY_OFF; |
| 255 | } |
| 256 | } |
| 257 | if (mService == null) Log.w(TAG, "Proxy not attached to service"); |
| 258 | return BluetoothProfile.PRIORITY_OFF; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Check if A2DP profile is streaming music. |
| 263 | * |
| 264 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH} |
| 265 | * |
| 266 | * @param device BluetoothDevice device |
| 267 | */ |
| 268 | public boolean isA2dpPlaying(BluetoothDevice device) { |
| 269 | if (mService != null && isEnabled() |
| 270 | && isValidDevice(device)) { |
| 271 | try { |
| 272 | return mService.isA2dpPlaying(device); |
| 273 | } catch (RemoteException e) { |
| 274 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 275 | return false; |
| 276 | } |
| 277 | } |
| 278 | if (mService == null) Log.w(TAG, "Proxy not attached to service"); |
| 279 | return false; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Initiate suspend from an A2DP sink. |
| 284 | * |
| 285 | * <p> This API will return false in scenarios like the A2DP |
| 286 | * device is not in connected state etc. When this API returns, |
| 287 | * true, it is guaranteed that {@link #ACTION_SINK_STATE_CHANGED} |
| 288 | * intent will be broadcasted with the state. Users can get the |
| 289 | * state of the A2DP device from this intent. |
| 290 | * |
| 291 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 292 | * |
| 293 | * @param device Remote A2DP sink |
| 294 | * @return false on immediate error, |
| 295 | * true otherwise |
| 296 | * @hide |
Zhu Lan | f9bbe1e | 2009-06-24 10:51:57 +0800 | [diff] [blame] | 297 | */ |
Nick Pelly | e766eae | 2009-09-30 12:06:28 -0700 | [diff] [blame] | 298 | public boolean suspendSink(BluetoothDevice device) { |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 299 | if (mService != null && isEnabled() |
| 300 | && isValidDevice(device)) { |
| 301 | try { |
| 302 | return mService.suspendSink(device); |
| 303 | } catch (RemoteException e) { |
| 304 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 305 | return false; |
| 306 | } |
Zhu Lan | f9bbe1e | 2009-06-24 10:51:57 +0800 | [diff] [blame] | 307 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 308 | if (mService == null) Log.w(TAG, "Proxy not attached to service"); |
| 309 | return false; |
Zhu Lan | f9bbe1e | 2009-06-24 10:51:57 +0800 | [diff] [blame] | 310 | } |
| 311 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 312 | /** |
| 313 | * Initiate resume from a suspended A2DP sink. |
| 314 | * |
| 315 | * <p> This API will return false in scenarios like the A2DP |
| 316 | * device is not in suspended state etc. When this API returns, |
| 317 | * true, it is guaranteed that {@link #ACTION_SINK_STATE_CHANGED} |
| 318 | * intent will be broadcasted with the state. Users can get the |
| 319 | * state of the A2DP device from this intent. |
| 320 | * |
| 321 | * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} |
| 322 | * |
| 323 | * @param device Remote A2DP sink |
| 324 | * @return false on immediate error, |
| 325 | * true otherwise |
| 326 | * @hide |
Zhu Lan | f9bbe1e | 2009-06-24 10:51:57 +0800 | [diff] [blame] | 327 | */ |
Nick Pelly | e766eae | 2009-09-30 12:06:28 -0700 | [diff] [blame] | 328 | public boolean resumeSink(BluetoothDevice device) { |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 329 | if (mService != null && isEnabled() |
| 330 | && isValidDevice(device)) { |
| 331 | try { |
| 332 | return mService.resumeSink(device); |
| 333 | } catch (RemoteException e) { |
| 334 | Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); |
| 335 | return false; |
| 336 | } |
Zhu Lan | f9bbe1e | 2009-06-24 10:51:57 +0800 | [diff] [blame] | 337 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 338 | if (mService == null) Log.w(TAG, "Proxy not attached to service"); |
| 339 | return false; |
Zhu Lan | f9bbe1e | 2009-06-24 10:51:57 +0800 | [diff] [blame] | 340 | } |
| 341 | |
Jaikumar Ganesh | 41d5c80 | 2010-10-13 19:11:28 -0700 | [diff] [blame^] | 342 | /** |
| 343 | * This function checks if the remote device is an AVCRP |
| 344 | * target and thus whether we should send volume keys |
| 345 | * changes or not. |
| 346 | * @hide |
| 347 | */ |
| 348 | public boolean shouldSendVolumeKeys(BluetoothDevice device) { |
| 349 | if (isEnabled() && isValidDevice(device)) { |
| 350 | ParcelUuid[] uuids = device.getUuids(); |
| 351 | if (uuids == null) return false; |
| 352 | |
| 353 | for (ParcelUuid uuid: uuids) { |
| 354 | if (BluetoothUuid.isAvrcpTarget(uuid)) { |
| 355 | return true; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | return false; |
| 360 | } |
| 361 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 362 | /** |
| 363 | * Helper for converting a state to a string. |
| 364 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | * For debug use only - strings are not internationalized. |
| 366 | * @hide |
| 367 | */ |
| 368 | public static String stateToString(int state) { |
| 369 | switch (state) { |
| 370 | case STATE_DISCONNECTED: |
| 371 | return "disconnected"; |
| 372 | case STATE_CONNECTING: |
| 373 | return "connecting"; |
| 374 | case STATE_CONNECTED: |
| 375 | return "connected"; |
| 376 | case STATE_DISCONNECTING: |
| 377 | return "disconnecting"; |
| 378 | case STATE_PLAYING: |
| 379 | return "playing"; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 380 | case STATE_NOT_PLAYING: |
| 381 | return "not playing"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | default: |
| 383 | return "<unknown state " + state + ">"; |
| 384 | } |
| 385 | } |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 386 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 387 | private boolean isEnabled() { |
| 388 | if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true; |
| 389 | return false; |
| 390 | } |
| 391 | |
| 392 | private boolean isValidDevice(BluetoothDevice device) { |
| 393 | if (device == null) return false; |
| 394 | |
| 395 | if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true; |
| 396 | return false; |
| 397 | } |
| 398 | |
| 399 | private Set<BluetoothDevice> toDeviceSet(BluetoothDevice[] devices) { |
| 400 | return Collections.unmodifiableSet( |
| 401 | new HashSet<BluetoothDevice>(Arrays.asList(devices))); |
| 402 | } |
| 403 | |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 404 | private static void log(String msg) { |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 405 | Log.d(TAG, msg); |
The Android Open Source Project | f5b4b98 | 2009-03-05 20:00:43 -0800 | [diff] [blame] | 406 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | } |