blob: 96f3290160f0c50631e0ef8636bb867263655bfc [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.bluetooth;
18
19import android.annotation.SdkConstant;
20import android.annotation.SdkConstant.SdkConstantType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.os.IBinder;
Jaikumar Ganesh41d5c802010-10-13 19:11:28 -070023import android.os.ParcelUuid;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070024import android.os.RemoteException;
25import android.os.ServiceManager;
26import android.server.BluetoothA2dpService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.util.Log;
28
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -070029import java.util.ArrayList;
30import java.util.List;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032
33/**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070034 * This class provides the public APIs to control the Bluetooth A2DP
35 * profile.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070037 *<p>BluetoothA2dp is a proxy object for controlling the Bluetooth A2DP
38 * Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get
39 * the BluetoothA2dp proxy object.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070041 * <p> Android only supports one connected Bluetooth A2dp device at a time.
42 * Each method is protected with its appropriate permission.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 */
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070044public final class BluetoothA2dp implements BluetoothProfile {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 private static final String TAG = "BluetoothA2dp";
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -080046 private static final boolean DBG = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070048 /**
49 * Intent used to broadcast the change in connection state of the A2DP
50 * profile.
51 *
52 * <p>This intent will have 3 extras:
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -080053 * <ul>
54 * <li> {@link #EXTRA_STATE} - The current state of the profile. </li>
55 * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile.</li>
56 * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li>
57 * </ul>
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070058 *
Jaikumar Ganesh0706fed2011-01-26 11:46:56 -080059 * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070060 * {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING},
61 * {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTING}.
62 *
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -080063 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to
64 * receive.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 */
66 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070067 public static final String ACTION_CONNECTION_STATE_CHANGED =
68 "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070070 /**
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:
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -080075 * <ul>
76 * <li> {@link #EXTRA_STATE} - The current state of the profile. </li>
77 * <li> {@link #EXTRA_PREVIOUS_STATE}- The previous state of the profile. </li>
Jaikumar Ganesh0706fed2011-01-26 11:46:56 -080078 * <li> {@link BluetoothDevice#EXTRA_DEVICE} - The remote device. </li>
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -080079 * </ul>
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070080 *
Jaikumar Ganesh0706fed2011-01-26 11:46:56 -080081 * <p>{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070082 * {@link #STATE_PLAYING}, {@link #STATE_NOT_PLAYING},
83 *
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -080084 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission to
85 * receive.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070086 */
87 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
88 public static final String ACTION_PLAYING_STATE_CHANGED =
89 "android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070091 /**
92 * A2DP sink device is streaming music. This state can be one of
93 * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of
94 * {@link #ACTION_PLAYING_STATE_CHANGED} intent.
95 */
96 public static final int STATE_PLAYING = 10;
Nick Pellybd022f42009-08-14 18:33:38 -070097
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070098 /**
99 * A2DP sink device is NOT streaming music. This state can be one of
100 * {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of
101 * {@link #ACTION_PLAYING_STATE_CHANGED} intent.
102 */
103 public static final int STATE_NOT_PLAYING = 11;
104
105 private ServiceListener mServiceListener;
106 private IBluetoothA2dp mService;
107 private BluetoothAdapter mAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108
109 /**
110 * Create a BluetoothA2dp proxy object for interacting with the local
111 * Bluetooth A2DP service.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700112 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 */
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700114 /*package*/ BluetoothA2dp(Context mContext, ServiceListener l) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 IBinder b = ServiceManager.getService(BluetoothA2dpService.BLUETOOTH_A2DP_SERVICE);
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700116 mServiceListener = l;
117 mAdapter = BluetoothAdapter.getDefaultAdapter();
Michael Chan081f58a2009-09-30 17:59:40 -0700118 if (b != null) {
119 mService = IBluetoothA2dp.Stub.asInterface(b);
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700120 if (mServiceListener != null) {
121 mServiceListener.onServiceConnected(BluetoothProfile.A2DP, this);
122 }
Michael Chan081f58a2009-09-30 17:59:40 -0700123 } else {
124 Log.w(TAG, "Bluetooth A2DP service not available!");
125
126 // Instead of throwing an exception which prevents people from going
127 // into Wireless settings in the emulator. Let it crash later when it is actually used.
128 mService = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 }
131
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700132 /**
Jaikumar Ganeshf8789162011-05-26 13:56:40 -0700133 * Initiate connection to a profile of the remote bluetooth device.
134 *
135 * <p> Currently, the system supports only 1 connection to the
136 * A2DP profile. The API will automatically disconnect connected
137 * devices before connecting.
138 *
139 * <p> This API returns false in scenarios like the profile on the
140 * device is already connected or Bluetooth is not turned on.
141 * When this API returns true, it is guaranteed that
142 * connection state intent for the profile will be broadcasted with
143 * the state. Users can get the connection state of the profile
144 * from this intent.
145 *
146 * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
147 * permission.
148 *
149 * @param device Remote Bluetooth Device
150 * @return false on immediate error,
151 * true otherwise
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700152 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 */
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700154 public boolean connect(BluetoothDevice device) {
155 if (DBG) log("connect(" + device + ")");
156 if (mService != null && isEnabled() &&
157 isValidDevice(device)) {
158 try {
159 return mService.connect(device);
160 } catch (RemoteException e) {
161 Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
162 return false;
163 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 }
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700165 if (mService == null) Log.w(TAG, "Proxy not attached to service");
166 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 }
168
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700169 /**
Jaikumar Ganeshf8789162011-05-26 13:56:40 -0700170 * Initiate disconnection from a profile
171 *
172 * <p> This API will return false in scenarios like the profile on the
173 * Bluetooth device is not in connected state etc. When this API returns,
174 * true, it is guaranteed that the connection state change
175 * intent will be broadcasted with the state. Users can get the
176 * disconnection state of the profile from this intent.
177 *
178 * <p> If the disconnection is initiated by a remote device, the state
179 * will transition from {@link #STATE_CONNECTED} to
180 * {@link #STATE_DISCONNECTED}. If the disconnect is initiated by the
181 * host (local) device the state will transition from
182 * {@link #STATE_CONNECTED} to state {@link #STATE_DISCONNECTING} to
183 * state {@link #STATE_DISCONNECTED}. The transition to
184 * {@link #STATE_DISCONNECTING} can be used to distinguish between the
185 * two scenarios.
186 *
187 * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
188 * permission.
189 *
190 * @param device Remote Bluetooth Device
191 * @return false on immediate error,
192 * true otherwise
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700193 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 */
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700195 public boolean disconnect(BluetoothDevice device) {
196 if (DBG) log("disconnect(" + device + ")");
197 if (mService != null && isEnabled() &&
198 isValidDevice(device)) {
199 try {
200 return mService.disconnect(device);
201 } catch (RemoteException e) {
202 Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
203 return false;
204 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 }
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700206 if (mService == null) Log.w(TAG, "Proxy not attached to service");
207 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 }
209
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700210 /**
211 * {@inheritDoc}
212 */
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700213 public List<BluetoothDevice> getConnectedDevices() {
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700214 if (DBG) log("getConnectedDevices()");
215 if (mService != null && isEnabled()) {
216 try {
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700217 return mService.getConnectedDevices();
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700218 } catch (RemoteException e) {
219 Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700220 return new ArrayList<BluetoothDevice>();
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700221 }
222 }
223 if (mService == null) Log.w(TAG, "Proxy not attached to service");
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700224 return new ArrayList<BluetoothDevice>();
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700225 }
226
227 /**
228 * {@inheritDoc}
229 */
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700230 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700231 if (DBG) log("getDevicesMatchingStates()");
232 if (mService != null && isEnabled()) {
233 try {
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700234 return mService.getDevicesMatchingConnectionStates(states);
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700235 } catch (RemoteException e) {
236 Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700237 return new ArrayList<BluetoothDevice>();
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700238 }
239 }
240 if (mService == null) Log.w(TAG, "Proxy not attached to service");
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700241 return new ArrayList<BluetoothDevice>();
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700242 }
243
244 /**
245 * {@inheritDoc}
246 */
247 public int getConnectionState(BluetoothDevice device) {
248 if (DBG) log("getState(" + device + ")");
249 if (mService != null && isEnabled()
250 && isValidDevice(device)) {
251 try {
252 return mService.getConnectionState(device);
253 } catch (RemoteException e) {
254 Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
255 return BluetoothProfile.STATE_DISCONNECTED;
256 }
257 }
258 if (mService == null) Log.w(TAG, "Proxy not attached to service");
259 return BluetoothProfile.STATE_DISCONNECTED;
260 }
261
262 /**
Jaikumar Ganeshf8789162011-05-26 13:56:40 -0700263 * Set priority of the profile
264 *
265 * <p> The device should already be paired.
266 * Priority can be one of {@link #PRIORITY_ON} or
267 * {@link #PRIORITY_OFF},
268 *
269 * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
270 * permission.
271 *
272 * @param device Paired bluetooth device
273 * @param priority
274 * @return true if priority is set, false on error
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700275 * @hide
276 */
277 public boolean setPriority(BluetoothDevice device, int priority) {
278 if (DBG) log("setPriority(" + device + ", " + priority + ")");
279 if (mService != null && isEnabled()
280 && isValidDevice(device)) {
281 if (priority != BluetoothProfile.PRIORITY_OFF &&
282 priority != BluetoothProfile.PRIORITY_ON) {
283 return false;
284 }
285 try {
286 return mService.setPriority(device, priority);
287 } catch (RemoteException e) {
288 Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
289 return false;
290 }
291 }
292 if (mService == null) Log.w(TAG, "Proxy not attached to service");
293 return false;
294 }
295
296 /**
Jaikumar Ganeshf8789162011-05-26 13:56:40 -0700297 * Get the priority of the profile.
298 *
299 * <p> The priority can be any of:
300 * {@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF},
301 * {@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
302 *
303 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
304 *
305 * @param device Bluetooth device
306 * @return priority of the device
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700307 * @hide
308 */
309 public int getPriority(BluetoothDevice device) {
310 if (DBG) log("getPriority(" + device + ")");
311 if (mService != null && isEnabled()
312 && isValidDevice(device)) {
313 try {
314 return mService.getPriority(device);
315 } catch (RemoteException e) {
316 Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
317 return BluetoothProfile.PRIORITY_OFF;
318 }
319 }
320 if (mService == null) Log.w(TAG, "Proxy not attached to service");
321 return BluetoothProfile.PRIORITY_OFF;
322 }
323
324 /**
325 * Check if A2DP profile is streaming music.
326 *
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800327 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700328 *
329 * @param device BluetoothDevice device
330 */
331 public boolean isA2dpPlaying(BluetoothDevice device) {
332 if (mService != null && isEnabled()
333 && isValidDevice(device)) {
334 try {
335 return mService.isA2dpPlaying(device);
336 } catch (RemoteException e) {
337 Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
338 return false;
339 }
340 }
341 if (mService == null) Log.w(TAG, "Proxy not attached to service");
342 return false;
343 }
344
345 /**
346 * Initiate suspend from an A2DP sink.
347 *
348 * <p> This API will return false in scenarios like the A2DP
349 * device is not in connected state etc. When this API returns,
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800350 * true, it is guaranteed that {@link #ACTION_CONNECTION_STATE_CHANGED}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700351 * intent will be broadcasted with the state. Users can get the
352 * state of the A2DP device from this intent.
353 *
354 * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800355 * permission.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700356 *
357 * @param device Remote A2DP sink
358 * @return false on immediate error,
359 * true otherwise
360 * @hide
Zhu Lanf9bbe1e2009-06-24 10:51:57 +0800361 */
Nick Pellye766eae2009-09-30 12:06:28 -0700362 public boolean suspendSink(BluetoothDevice device) {
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700363 if (mService != null && isEnabled()
364 && isValidDevice(device)) {
365 try {
366 return mService.suspendSink(device);
367 } catch (RemoteException e) {
368 Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
369 return false;
370 }
Zhu Lanf9bbe1e2009-06-24 10:51:57 +0800371 }
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700372 if (mService == null) Log.w(TAG, "Proxy not attached to service");
373 return false;
Zhu Lanf9bbe1e2009-06-24 10:51:57 +0800374 }
375
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700376 /**
377 * Initiate resume from a suspended A2DP sink.
378 *
379 * <p> This API will return false in scenarios like the A2DP
380 * device is not in suspended state etc. When this API returns,
381 * true, it is guaranteed that {@link #ACTION_SINK_STATE_CHANGED}
382 * intent will be broadcasted with the state. Users can get the
383 * state of the A2DP device from this intent.
384 *
385 * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
386 *
387 * @param device Remote A2DP sink
388 * @return false on immediate error,
389 * true otherwise
390 * @hide
Zhu Lanf9bbe1e2009-06-24 10:51:57 +0800391 */
Nick Pellye766eae2009-09-30 12:06:28 -0700392 public boolean resumeSink(BluetoothDevice device) {
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700393 if (mService != null && isEnabled()
394 && isValidDevice(device)) {
395 try {
396 return mService.resumeSink(device);
397 } catch (RemoteException e) {
398 Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
399 return false;
400 }
Zhu Lanf9bbe1e2009-06-24 10:51:57 +0800401 }
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700402 if (mService == null) Log.w(TAG, "Proxy not attached to service");
403 return false;
Zhu Lanf9bbe1e2009-06-24 10:51:57 +0800404 }
405
Jaikumar Ganesh41d5c802010-10-13 19:11:28 -0700406 /**
407 * This function checks if the remote device is an AVCRP
408 * target and thus whether we should send volume keys
409 * changes or not.
410 * @hide
411 */
412 public boolean shouldSendVolumeKeys(BluetoothDevice device) {
413 if (isEnabled() && isValidDevice(device)) {
414 ParcelUuid[] uuids = device.getUuids();
415 if (uuids == null) return false;
416
417 for (ParcelUuid uuid: uuids) {
418 if (BluetoothUuid.isAvrcpTarget(uuid)) {
419 return true;
420 }
421 }
422 }
423 return false;
424 }
425
Matthew Xiea0c68032011-06-25 21:47:07 -0700426 /**
427 * Allow or disallow incoming connection
428 * @param device Sink
429 * @param value True / False
430 * @return Success or Failure of the binder call.
431 * @hide
432 */
433 public boolean allowIncomingConnect(BluetoothDevice device, boolean value) {
434 if (DBG) log("allowIncomingConnect(" + device + ":" + value + ")");
435 try {
436 return mService.allowIncomingConnect(device, value);
437 } catch (RemoteException e) {
438 Log.e(TAG, "", e);
439 return false;
440 }
441 }
442
443 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700444 * Helper for converting a state to a string.
445 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 * For debug use only - strings are not internationalized.
447 * @hide
448 */
449 public static String stateToString(int state) {
450 switch (state) {
451 case STATE_DISCONNECTED:
452 return "disconnected";
453 case STATE_CONNECTING:
454 return "connecting";
455 case STATE_CONNECTED:
456 return "connected";
457 case STATE_DISCONNECTING:
458 return "disconnecting";
459 case STATE_PLAYING:
460 return "playing";
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700461 case STATE_NOT_PLAYING:
462 return "not playing";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 default:
464 return "<unknown state " + state + ">";
465 }
466 }
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -0800467
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700468 private boolean isEnabled() {
469 if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
470 return false;
471 }
472
473 private boolean isValidDevice(BluetoothDevice device) {
474 if (device == null) return false;
475
476 if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
477 return false;
478 }
479
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -0800480 private static void log(String msg) {
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700481 Log.d(TAG, msg);
The Android Open Source Projectf5b4b982009-03-05 20:00:43 -0800482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483}