summaryrefslogtreecommitdiffstats
path: root/core/java/android/bluetooth
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-01-20 14:03:58 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-01-20 14:03:58 -0800
commit22f7dfd23490a3de2f21ff96949ba47003aac8f8 (patch)
tree41bc290bb2f1f08a0e37cfda4955742a85d42ecf /core/java/android/bluetooth
parent9266c558bf1d21ff647525ff99f7dadbca417309 (diff)
downloadframeworks_base-22f7dfd23490a3de2f21ff96949ba47003aac8f8.zip
frameworks_base-22f7dfd23490a3de2f21ff96949ba47003aac8f8.tar.gz
frameworks_base-22f7dfd23490a3de2f21ff96949ba47003aac8f8.tar.bz2
auto import from //branches/cupcake/...@127101
Diffstat (limited to 'core/java/android/bluetooth')
-rw-r--r--core/java/android/bluetooth/BluetoothA2dp.java66
-rw-r--r--core/java/android/bluetooth/BluetoothHeadset.java109
-rw-r--r--core/java/android/bluetooth/IBluetoothA2dp.aidl2
-rw-r--r--core/java/android/bluetooth/IBluetoothHeadset.aidl18
-rw-r--r--core/java/android/bluetooth/IBluetoothHeadsetCallback.aidl25
5 files changed, 149 insertions, 71 deletions
diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java
index 022a87c..b0b0154 100644
--- a/core/java/android/bluetooth/BluetoothA2dp.java
+++ b/core/java/android/bluetooth/BluetoothA2dp.java
@@ -72,6 +72,12 @@ public class BluetoothA2dp {
/** Playing implies connected */
public static final int STATE_PLAYING = 4;
+ /** Default priority for a2dp devices that should allow incoming
+ * connections */
+ public static final int PRIORITY_AUTO = 100;
+ /** Default priority for a2dp devices that should not allow incoming
+ * connections */
+ public static final int PRIORITY_OFF = 0;
private final IBluetoothA2dp mService;
private final Context mContext;
@@ -158,6 +164,66 @@ public class BluetoothA2dp {
}
}
+ /**
+ * Set priority of a2dp sink.
+ * Priority is a non-negative integer. By default paired sinks will have
+ * a priority of PRIORITY_AUTO, and unpaired headset PRIORITY_NONE (0).
+ * Sinks with priority greater than zero will accept incoming connections
+ * (if no sink is currently connected).
+ * Priority for unpaired sink must be PRIORITY_NONE.
+ * @param address Paired sink
+ * @param priority Integer priority, for example PRIORITY_AUTO or
+ * PRIORITY_NONE
+ * @return Result code, negative indicates an error
+ */
+ public int setSinkPriority(String address, int priority) {
+ try {
+ return mService.setSinkPriority(address, priority);
+ } catch (RemoteException e) {
+ Log.w(TAG, "", e);
+ return BluetoothError.ERROR_IPC;
+ }
+ }
+
+ /**
+ * Get priority of a2dp sink.
+ * @param address Sink
+ * @return non-negative priority, or negative error code on error.
+ */
+ public int getSinkPriority(String address) {
+ try {
+ return mService.getSinkPriority(address);
+ } catch (RemoteException e) {
+ Log.w(TAG, "", e);
+ return BluetoothError.ERROR_IPC;
+ }
+ }
+
+ /**
+ * Check class bits for possible A2DP Sink support.
+ * This is a simple heuristic that tries to guess if a device with the
+ * given class bits might be a A2DP Sink. It is not accurate for all
+ * devices. It tries to err on the side of false positives.
+ * @return True if this device might be a A2DP sink
+ */
+ public static boolean doesClassMatchSink(int btClass) {
+ if (BluetoothClass.Service.hasService(btClass, BluetoothClass.Service.RENDER)) {
+ return true;
+ }
+ // By the A2DP spec, sinks must indicate the RENDER service.
+ // However we found some that do not (Chordette). So lets also
+ // match on some other class bits.
+ switch (BluetoothClass.Device.getDevice(btClass)) {
+ case BluetoothClass.Device.AUDIO_VIDEO_HIFI_AUDIO:
+ case BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES:
+ case BluetoothClass.Device.AUDIO_VIDEO_LOUDSPEAKER:
+ case BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO:
+ return true;
+ default:
+ return false;
+ }
+ }
+
/** Helper for converting a state to a string.
* For debug use only - strings are not internationalized.
* @hide
diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java
index 905173e..c315271 100644
--- a/core/java/android/bluetooth/BluetoothHeadset.java
+++ b/core/java/android/bluetooth/BluetoothHeadset.java
@@ -57,7 +57,6 @@ public class BluetoothHeadset {
private IBluetoothHeadset mService;
private final Context mContext;
private final ServiceListener mServiceListener;
- private ConnectHeadsetCallback mConnectHeadsetCallback;
/** There was an error trying to obtain the state */
public static final int STATE_ERROR = -1;
@@ -73,6 +72,11 @@ public class BluetoothHeadset {
/** Connection cancelled before completetion. */
public static final int RESULT_CANCELLED = 2;
+ /** Default priority for headsets that should be auto-connected */
+ public static final int PRIORITY_AUTO = 100;
+ /** Default priority for headsets that should not be auto-connected */
+ public static final int PRIORITY_OFF = 0;
+
/**
* An interface for notifying BluetoothHeadset IPC clients when they have
* been connected to the BluetoothHeadset service.
@@ -97,14 +101,6 @@ public class BluetoothHeadset {
}
/**
- * Interface for connectHeadset() callback.
- * This callback can occur in the Binder thread.
- */
- public interface ConnectHeadsetCallback {
- public void onConnectHeadsetResult(String address, int resultCode);
- }
-
- /**
* Create a BluetoothHeadset proxy object.
*/
public BluetoothHeadset(Context context, ServiceListener l) {
@@ -175,24 +171,18 @@ public class BluetoothHeadset {
* Request to initiate a connection to a headset.
* This call does not block. Fails if a headset is already connecting
* or connected.
- * Will connect to the last connected headset if address is null.
- * onConnectHeadsetResult() of your ConnectHeadsetCallback will be called
- * on completition.
- * @param address The Bluetooth Address to connect to, or null to connect
- * to the last connected headset.
- * @param callback Callback on result. Not called if false is returned. Can
- * be null.
- * to the last connected headset.
+ * Initiates auto-connection if address is null. Tries to connect to all
+ * devices with priority greater than PRIORITY_AUTO in descending order.
+ * @param address The Bluetooth Address to connect to, or null to
+ * auto-connect to the last connected headset.
* @return False if there was a problem initiating the connection
- * procedure, and your callback will not be used. True if
- * the connection procedure was initiated, in which case
- * your callback is guarenteed to be called.
+ * procedure, and no further HEADSET_STATE_CHANGED intents
+ * will be expected.
*/
- public boolean connectHeadset(String address, ConnectHeadsetCallback callback) {
+ public boolean connectHeadset(String address) {
if (mService != null) {
try {
- if (mService.connectHeadset(address, mHeadsetCallback)) {
- mConnectHeadsetCallback = callback;
+ if (mService.connectHeadset(address)) {
return true;
}
} catch (RemoteException e) {Log.e(TAG, e.toString());}
@@ -273,6 +263,71 @@ public class BluetoothHeadset {
return false;
}
+ /**
+ * Set priority of headset.
+ * Priority is a non-negative integer. By default paired headsets will have
+ * a priority of PRIORITY_AUTO, and unpaired headset PRIORITY_NONE (0).
+ * Headsets with priority greater than zero will be auto-connected, and
+ * incoming connections will be accepted (if no other headset is
+ * connected).
+ * Auto-connection occurs at the following events: boot, incoming phone
+ * call, outgoing phone call.
+ * Headsets with priority equal to zero, or that are unpaired, are not
+ * auto-connected.
+ * Incoming connections are ignored regardless of priority if there is
+ * already a headset connected.
+ * @param address Paired headset
+ * @param priority Integer priority, for example PRIORITY_AUTO or
+ * PRIORITY_NONE
+ * @return True if successful, false if there was some error.
+ */
+ public boolean setPriority(String address, int priority) {
+ if (mService != null) {
+ try {
+ return mService.setPriority(address, priority);
+ } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
+ }
+ return false;
+ }
+
+ /**
+ * Get priority of headset.
+ * @param address Headset
+ * @return non-negative priority, or negative error code on error.
+ */
+ public int getPriority(String address) {
+ if (mService != null) {
+ try {
+ return mService.getPriority(address);
+ } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
+ }
+ return -1;
+ }
+
+ /**
+ * Check class bits for possible HSP or HFP support.
+ * This is a simple heuristic that tries to guess if a device with the
+ * given class bits might support HSP or HFP. It is not accurate for all
+ * devices. It tries to err on the side of false positives.
+ * @return True if this device might support HSP or HFP.
+ */
+ public static boolean doesClassMatch(int btClass) {
+ switch (BluetoothClass.Device.getDevice(btClass)) {
+ case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
+ case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
+ case BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO:
+ return true;
+ default:
+ return false;
+ }
+ }
+
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) Log.d(TAG, "Proxy object connected");
@@ -289,12 +344,4 @@ public class BluetoothHeadset {
}
}
};
-
- private IBluetoothHeadsetCallback mHeadsetCallback = new IBluetoothHeadsetCallback.Stub() {
- public void onConnectHeadsetResult(String address, int resultCode) {
- if (mConnectHeadsetCallback != null) {
- mConnectHeadsetCallback.onConnectHeadsetResult(address, resultCode);
- }
- }
- };
}
diff --git a/core/java/android/bluetooth/IBluetoothA2dp.aidl b/core/java/android/bluetooth/IBluetoothA2dp.aidl
index 7e0226d..55ff27f 100644
--- a/core/java/android/bluetooth/IBluetoothA2dp.aidl
+++ b/core/java/android/bluetooth/IBluetoothA2dp.aidl
@@ -26,4 +26,6 @@ interface IBluetoothA2dp {
int disconnectSink(in String address);
List<String> listConnectedSinks();
int getSinkState(in String address);
+ int setSinkPriority(in String address, int priority);
+ int getSinkPriority(in String address);
}
diff --git a/core/java/android/bluetooth/IBluetoothHeadset.aidl b/core/java/android/bluetooth/IBluetoothHeadset.aidl
index 564861f..582d4e3 100644
--- a/core/java/android/bluetooth/IBluetoothHeadset.aidl
+++ b/core/java/android/bluetooth/IBluetoothHeadset.aidl
@@ -16,8 +16,6 @@
package android.bluetooth;
-import android.bluetooth.IBluetoothHeadsetCallback;
-
/**
* System private API for Bluetooth Headset service
*
@@ -25,22 +23,12 @@ import android.bluetooth.IBluetoothHeadsetCallback;
*/
interface IBluetoothHeadset {
int getState();
-
String getHeadsetAddress();
-
- // Request that the given headset be connected
- // Assumes the given headset is already bonded
- // Will disconnect any currently connected headset
- // returns false if cannot start a connection (for example, there is
- // already a pending connect). callback will always be called iff this
- // returns true
- boolean connectHeadset(in String address, in IBluetoothHeadsetCallback callback);
-
+ boolean connectHeadset(in String address);
void disconnectHeadset();
-
boolean isConnected(in String address);
-
boolean startVoiceRecognition();
-
boolean stopVoiceRecognition();
+ boolean setPriority(in String address, int priority);
+ int getPriority(in String address);
}
diff --git a/core/java/android/bluetooth/IBluetoothHeadsetCallback.aidl b/core/java/android/bluetooth/IBluetoothHeadsetCallback.aidl
deleted file mode 100644
index 03e884b..0000000
--- a/core/java/android/bluetooth/IBluetoothHeadsetCallback.aidl
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2008, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.bluetooth;
-
-/**
- * {@hide}
- */
-oneway interface IBluetoothHeadsetCallback
-{
- void onConnectHeadsetResult(in String address, int resultCode);
-}