summaryrefslogtreecommitdiffstats
path: root/core/java/android/bluetooth
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/bluetooth')
-rw-r--r--core/java/android/bluetooth/BluetoothDevice.java97
-rw-r--r--core/java/android/bluetooth/BluetoothHeadset.java10
-rw-r--r--core/java/android/bluetooth/BluetoothIntent.java19
-rw-r--r--core/java/android/bluetooth/HeadsetBase.java33
-rw-r--r--core/java/android/bluetooth/IBluetoothDevice.aidl12
5 files changed, 59 insertions, 112 deletions
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index d613e1c..56b231f 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/java/android/bluetooth/BluetoothDevice.java
@@ -31,10 +31,15 @@ import java.io.UnsupportedEncodingException;
* @hide
*/
public class BluetoothDevice {
- public static final int MODE_UNKNOWN = -1;
- public static final int MODE_OFF = 0;
- public static final int MODE_CONNECTABLE = 1;
- public static final int MODE_DISCOVERABLE = 2;
+ /** Inquiry scan and page scan are both off.
+ * Device is neither discoverable nor connectable */
+ public static final int SCAN_MODE_NONE = 0;
+ /** Page scan is on, inquiry scan is off.
+ * Device is connectable, but not discoverable */
+ public static final int SCAN_MODE_CONNECTABLE = 1;
+ /** Page scan and inquiry scan are on.
+ * Device is connectable and discoverable */
+ public static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE = 3;
public static final int RESULT_FAILURE = -1;
public static final int RESULT_SUCCESS = 0;
@@ -54,10 +59,10 @@ public class BluetoothDevice {
/** A bond attempt failed because the other side explicilty rejected
* bonding */
public static final int UNBOND_REASON_AUTH_REJECTED = 2;
- /** A bond attempt failed because we cancelled the bonding process */
- public static final int UNBOND_REASON_CANCELLED = 3;
+ /** A bond attempt failed because we canceled the bonding process */
+ public static final int UNBOND_REASON_AUTH_CANCELED = 3;
/** A bond attempt failed because we could not contact the remote device */
- public static final int UNBOND_REASON_AUTH_REMOTE_DEVICE_DOWN = 4;
+ public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4;
/** An existing bond was explicitly revoked */
public static final int UNBOND_REASON_REMOVED = 5;
@@ -174,18 +179,6 @@ public class BluetoothDevice {
return false;
}
- public String getMajorClass() {
- try {
- return mService.getMajorClass();
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- return null;
- }
- public String getMinorClass() {
- try {
- return mService.getMinorClass();
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- return null;
- }
public String getVersion() {
try {
return mService.getVersion();
@@ -211,15 +204,26 @@ public class BluetoothDevice {
return null;
}
- public int getMode() {
+ /**
+ * Get the current scan mode.
+ * Used to determine if the local device is connectable and/or discoverable
+ * @return Scan mode, one of SCAN_MODE_* or an error code
+ */
+ public int getScanMode() {
try {
- return mService.getMode();
+ return mService.getScanMode();
} catch (RemoteException e) {Log.e(TAG, "", e);}
- return MODE_UNKNOWN;
+ return BluetoothError.ERROR_IPC;
}
- public void setMode(int mode) {
+
+ /**
+ * Set the current scan mode.
+ * Used to make the local device connectable and/or discoverable
+ * @param scanMode One of SCAN_MODE_*
+ */
+ public void setScanMode(int scanMode) {
try {
- mService.setMode(mode);
+ mService.setScanMode(scanMode);
} catch (RemoteException e) {Log.e(TAG, "", e);}
}
@@ -435,24 +439,6 @@ public class BluetoothDevice {
return null;
}
- public String getRemoteAlias(String address) {
- try {
- return mService.getRemoteAlias(address);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- return null;
- }
- public boolean setRemoteAlias(String address, String alias) {
- try {
- return mService.setRemoteAlias(address, alias);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- return false;
- }
- public boolean clearRemoteAlias(String address) {
- try {
- return mService.clearRemoteAlias(address);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- return false;
- }
public String getRemoteVersion(String address) {
try {
return mService.getRemoteVersion(address);
@@ -477,24 +463,6 @@ public class BluetoothDevice {
} catch (RemoteException e) {Log.e(TAG, "", e);}
return null;
}
- public String getRemoteMajorClass(String address) {
- try {
- return mService.getRemoteMajorClass(address);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- return null;
- }
- public String getRemoteMinorClass(String address) {
- try {
- return mService.getRemoteMinorClass(address);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- return null;
- }
- public String[] getRemoteServiceClasses(String address) {
- try {
- return mService.getRemoteServiceClasses(address);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- return null;
- }
/**
* Returns the RFCOMM channel associated with the 16-byte UUID on
@@ -512,12 +480,19 @@ public class BluetoothDevice {
return false;
}
+ /**
+ * Get the major, minor and servics classes of a remote device.
+ * These classes are encoded as a 32-bit integer. See BluetoothClass.
+ * @param address remote device
+ * @return 32-bit class suitable for use with BluetoothClass.
+ */
public int getRemoteClass(String address) {
try {
return mService.getRemoteClass(address);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return BluetoothClass.ERROR;
}
+
public byte[] getRemoteFeatures(String address) {
try {
return mService.getRemoteFeatures(address);
@@ -576,8 +551,8 @@ public class BluetoothDevice {
}
- /* Sanity check a bluetooth address, such as "00:43:A8:23:10:F0" */
private static final int ADDRESS_LENGTH = 17;
+ /** Sanity check a bluetooth address, such as "00:43:A8:23:10:F0" */
public static boolean checkBluetoothAddress(String address) {
if (address == null || address.length() != ADDRESS_LENGTH) {
return false;
diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java
index c315271..34196bf 100644
--- a/core/java/android/bluetooth/BluetoothHeadset.java
+++ b/core/java/android/bluetooth/BluetoothHeadset.java
@@ -69,8 +69,8 @@ public class BluetoothHeadset {
public static final int RESULT_FAILURE = 0;
public static final int RESULT_SUCCESS = 1;
- /** Connection cancelled before completetion. */
- public static final int RESULT_CANCELLED = 2;
+ /** Connection canceled before completetion. */
+ public static final int RESULT_CANCELED = 2;
/** Default priority for headsets that should be auto-connected */
public static final int PRIORITY_AUTO = 100;
@@ -318,6 +318,12 @@ public class BluetoothHeadset {
* @return True if this device might support HSP or HFP.
*/
public static boolean doesClassMatch(int btClass) {
+ // The render service class is required by the spec for HFP, so is a
+ // pretty good signal
+ if (BluetoothClass.Service.hasService(btClass, BluetoothClass.Service.RENDER)) {
+ return true;
+ }
+ // Just in case they forgot the render service class
switch (BluetoothClass.Device.getDevice(btClass)) {
case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE:
case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET:
diff --git a/core/java/android/bluetooth/BluetoothIntent.java b/core/java/android/bluetooth/BluetoothIntent.java
index 57c46f9..b66b06e 100644
--- a/core/java/android/bluetooth/BluetoothIntent.java
+++ b/core/java/android/bluetooth/BluetoothIntent.java
@@ -29,8 +29,8 @@ import android.annotation.SdkConstant.SdkConstantType;
* @hide
*/
public interface BluetoothIntent {
- public static final String MODE =
- "android.bluetooth.intent.MODE";
+ public static final String SCAN_MODE =
+ "android.bluetooth.intent.SCAN_MODE";
public static final String ADDRESS =
"android.bluetooth.intent.ADDRESS";
public static final String NAME =
@@ -62,9 +62,14 @@ public interface BluetoothIntent {
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String NAME_CHANGED_ACTION =
"android.bluetooth.intent.action.NAME_CHANGED";
+
+ /**
+ * Broadcast when the scan mode changes. Always contains an int extra
+ * named SCAN_MODE that contains the new scan mode.
+ */
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
- public static final String MODE_CHANGED_ACTION =
- "android.bluetooth.intent.action.MODE_CHANGED";
+ public static final String SCAN_MODE_CHANGED_ACTION =
+ "android.bluetooth.intent.action.SCAN_MODE_CHANGED";
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String DISCOVERY_STARTED_ACTION =
@@ -104,12 +109,6 @@ public interface BluetoothIntent {
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String REMOTE_NAME_FAILED_ACTION =
"android.bluetooth.intent.action.REMOTE_NAME_FAILED";
- @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
- public static final String REMOTE_ALIAS_CHANGED_ACTION =
- "android.bluetooth.intent.action.REMOTE_ALIAS_CHANGED";
- @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
- public static final String REMOTE_ALIAS_CLEARED_ACTION =
- "android.bluetooth.intent.action.REMOTE_ALIAS_CLEARED";
/**
* Broadcast when the bond state of a remote device changes.
diff --git a/core/java/android/bluetooth/HeadsetBase.java b/core/java/android/bluetooth/HeadsetBase.java
index bce3388..fd2d2ab 100644
--- a/core/java/android/bluetooth/HeadsetBase.java
+++ b/core/java/android/bluetooth/HeadsetBase.java
@@ -21,13 +21,10 @@ import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
-import java.io.IOException;
-import java.lang.Thread;
-
/**
* The Android Bluetooth API is not finalized, and *will* change. Use at your
* own risk.
- *
+ *
* The base RFCOMM (service) connection for a headset or handsfree device.
*
* In the future this class will be removed.
@@ -90,7 +87,7 @@ public class HeadsetBase {
/* Create from an already exisiting rfcomm connection */
public HeadsetBase(PowerManager pm, BluetoothDevice bluetooth, String address, int socketFd,
- int rfcommChannel, Handler handler) {
+ int rfcommChannel, Handler handler) {
mDirection = DIRECTION_INCOMING;
mConnectTimestamp = System.currentTimeMillis();
mBluetooth = bluetooth;
@@ -132,30 +129,8 @@ public class HeadsetBase {
*/
protected void initializeAtParser() {
mAtParser = new AtParser();
-
- // Microphone Gain
- mAtParser.register("+VGM", new AtCommandHandler() {
- @Override
- public AtCommandResult handleSetCommand(Object[] args) {
- // AT+VGM=<gain> in range [0,15]
- // Headset/Handsfree is reporting its current gain setting
- //TODO: sync to android UI
- //TODO: Send unsolicited +VGM when volume changed on AG
- return new AtCommandResult(AtCommandResult.OK);
- }
- });
-
- // Speaker Gain
- mAtParser.register("+VGS", new AtCommandHandler() {
- @Override
- public AtCommandResult handleSetCommand(Object[] args) {
- // AT+VGS=<gain> in range [0,15]
- // Headset/Handsfree is reporting its current gain to Android
- //TODO: sync to AG UI
- //TODO: Send unsolicited +VGS when volume changed on AG
- return new AtCommandResult(AtCommandResult.OK);
- }
- });
+ //TODO(): Get rid of this as there are no parsers registered. But because of dependencies,
+ //it needs to be done as part of refactoring HeadsetBase and BluetoothHandsfree
}
public AtParser getAtParser() {
diff --git a/core/java/android/bluetooth/IBluetoothDevice.aidl b/core/java/android/bluetooth/IBluetoothDevice.aidl
index 59f679f..4351d2e 100644
--- a/core/java/android/bluetooth/IBluetoothDevice.aidl
+++ b/core/java/android/bluetooth/IBluetoothDevice.aidl
@@ -32,15 +32,13 @@ interface IBluetoothDevice
String getAddress();
String getName();
boolean setName(in String name);
- String getMajorClass();
- String getMinorClass();
String getVersion();
String getRevision();
String getManufacturer();
String getCompany();
- int getMode();
- boolean setMode(int mode);
+ int getScanMode();
+ boolean setScanMode(int mode);
int getDiscoverableTimeout();
boolean setDiscoverableTimeout(int timeout);
@@ -64,17 +62,11 @@ interface IBluetoothDevice
int getBondState(in String address);
String getRemoteName(in String address);
- String getRemoteAlias(in String address);
- boolean setRemoteAlias(in String address, in String alias);
- boolean clearRemoteAlias(in String address);
String getRemoteVersion(in String address);
String getRemoteRevision(in String address);
int getRemoteClass(in String address);
String getRemoteManufacturer(in String address);
String getRemoteCompany(in String address);
- String getRemoteMajorClass(in String address);
- String getRemoteMinorClass(in String address);
- String[] getRemoteServiceClasses(in String address);
boolean getRemoteServiceChannel(in String address, int uuid16, in IBluetoothDeviceCallback callback);
byte[] getRemoteFeatures(in String adddress);
String lastSeen(in String address);