diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java index c58eaa14ed821..7841b83cf92cf 100644 --- a/core/java/android/bluetooth/BluetoothA2dp.java +++ b/core/java/android/bluetooth/BluetoothA2dp.java @@ -42,7 +42,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; * This class provides the public APIs to control the Bluetooth A2DP * profile. * - *
BluetoothA2dp is a proxy object for controlling the Bluetooth A2DP + *
BluetoothA2dp is a proxy object for controlling the Bluetooth A2DP * Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get * the BluetoothA2dp proxy object. * @@ -60,9 +60,9 @@ public final class BluetoothA2dp implements BluetoothProfile { * *
This intent will have 3 extras: *
{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of @@ -74,7 +74,7 @@ public final class BluetoothA2dp implements BluetoothProfile { */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_CONNECTION_STATE_CHANGED = - "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED"; + "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED"; /** * Intent used to broadcast the change in the Playing state of the A2DP @@ -82,9 +82,9 @@ public final class BluetoothA2dp implements BluetoothProfile { * *
This intent will have 3 extras: *
{@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of @@ -95,12 +95,12 @@ public final class BluetoothA2dp implements BluetoothProfile { */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_PLAYING_STATE_CHANGED = - "android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED"; + "android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED"; /** @hide */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_AVRCP_CONNECTION_STATE_CHANGED = - "android.bluetooth.a2dp.profile.action.AVRCP_CONNECTION_STATE_CHANGED"; + "android.bluetooth.a2dp.profile.action.AVRCP_CONNECTION_STATE_CHANGED"; /** * Intent used to broadcast the change in the Audio Codec state of the @@ -108,9 +108,9 @@ public final class BluetoothA2dp implements BluetoothProfile { * *
This intent will have 2 extras: *
Requires {@link android.Manifest.permission#BLUETOOTH} permission to
@@ -120,61 +120,74 @@ public final class BluetoothA2dp implements BluetoothProfile {
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_CODEC_CONFIG_CHANGED =
- "android.bluetooth.a2dp.profile.action.CODEC_CONFIG_CHANGED";
+ "android.bluetooth.a2dp.profile.action.CODEC_CONFIG_CHANGED";
/**
* A2DP sink device is streaming music. This state can be one of
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of
* {@link #ACTION_PLAYING_STATE_CHANGED} intent.
*/
- public static final int STATE_PLAYING = 10;
+ public static final int STATE_PLAYING = 10;
/**
* A2DP sink device is NOT streaming music. This state can be one of
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of
* {@link #ACTION_PLAYING_STATE_CHANGED} intent.
*/
- public static final int STATE_NOT_PLAYING = 11;
+ public static final int STATE_NOT_PLAYING = 11;
/**
* We don't have a stored preference for whether or not the given A2DP sink device supports
* optional codecs.
- * @hide */
+ *
+ * @hide
+ */
public static final int OPTIONAL_CODECS_SUPPORT_UNKNOWN = -1;
/**
* The given A2DP sink device does not support optional codecs.
- * @hide */
+ *
+ * @hide
+ */
public static final int OPTIONAL_CODECS_NOT_SUPPORTED = 0;
/**
* The given A2DP sink device does support optional codecs.
- * @hide */
+ *
+ * @hide
+ */
public static final int OPTIONAL_CODECS_SUPPORTED = 1;
/**
* We don't have a stored preference for whether optional codecs should be enabled or disabled
* for the given A2DP device.
- * @hide */
+ *
+ * @hide
+ */
public static final int OPTIONAL_CODECS_PREF_UNKNOWN = -1;
/**
* Optional codecs should be disabled for the given A2DP device.
- * @hide */
+ *
+ * @hide
+ */
public static final int OPTIONAL_CODECS_PREF_DISABLED = 0;
/**
- * Optional codecs should be enabled for the given A2DP device.
- * @hide */
+ * Optional codecs should be enabled for the given A2DP device.
+ *
+ * @hide
+ */
public static final int OPTIONAL_CODECS_PREF_ENABLED = 1;
private Context mContext;
private ServiceListener mServiceListener;
private final ReentrantReadWriteLock mServiceLock = new ReentrantReadWriteLock();
- @GuardedBy("mServiceLock") private IBluetoothA2dp mService;
+ @GuardedBy("mServiceLock")
+ private IBluetoothA2dp mService;
private BluetoothAdapter mAdapter;
- final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
+ private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
new IBluetoothStateChangeCallback.Stub() {
public void onBluetoothStateChange(boolean up) {
if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
@@ -193,21 +206,21 @@ public final class BluetoothA2dp implements BluetoothProfile {
try {
mServiceLock.readLock().lock();
if (mService == null) {
- if (VDBG) Log.d(TAG,"Binding service...");
+ if (VDBG) Log.d(TAG, "Binding service...");
doBind();
}
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
} finally {
mServiceLock.readLock().unlock();
}
}
}
- };
+ };
+
/**
* Create a BluetoothA2dp proxy object for interacting with the local
* Bluetooth A2DP service.
- *
*/
/*package*/ BluetoothA2dp(Context context, ServiceListener l) {
mContext = context;
@@ -218,7 +231,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
try {
mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -244,7 +257,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
try {
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
} catch (Exception e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -261,10 +274,12 @@ public final class BluetoothA2dp implements BluetoothProfile {
}
}
+ @Override
public void finalize() {
// The empty finalize needs to be kept or the
// cts signature tests would fail.
}
+
/**
* Initiate connection to a profile of the remote bluetooth device.
*
@@ -283,16 +298,14 @@ public final class BluetoothA2dp implements BluetoothProfile {
* permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean connect(BluetoothDevice device) {
if (DBG) log("connect(" + device + ")");
try {
mServiceLock.readLock().lock();
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
return mService.connect(device);
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -327,16 +340,14 @@ public final class BluetoothA2dp implements BluetoothProfile {
* permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean disconnect(BluetoothDevice device) {
if (DBG) log("disconnect(" + device + ")");
try {
mServiceLock.readLock().lock();
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
return mService.disconnect(device);
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -352,6 +363,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
/**
* {@inheritDoc}
*/
+ @Override
public List The device should already be paired.
- * Priority can be one of {@link #PRIORITY_ON} orgetBluetoothManager
+ * Priority can be one of {@link #PRIORITY_ON} orgetBluetoothManager
* {@link #PRIORITY_OFF},
*
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
@@ -430,9 +444,9 @@ public final class BluetoothA2dp implements BluetoothProfile {
try {
mServiceLock.readLock().lock();
if (mService != null && isEnabled()
- && isValidDevice(device)) {
- if (priority != BluetoothProfile.PRIORITY_OFF &&
- priority != BluetoothProfile.PRIORITY_ON) {
+ && isValidDevice(device)) {
+ if (priority != BluetoothProfile.PRIORITY_OFF
+ && priority != BluetoothProfile.PRIORITY_ON) {
return false;
}
return mService.setPriority(device, priority);
@@ -464,7 +478,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
try {
mServiceLock.readLock().lock();
if (mService != null && isEnabled()
- && isValidDevice(device)) {
+ && isValidDevice(device)) {
return mService.getPriority(device);
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -560,7 +574,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
try {
mServiceLock.readLock().lock();
if (mService != null && isEnabled()
- && isValidDevice(device)) {
+ && isValidDevice(device)) {
return mService.isA2dpPlaying(device);
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -577,6 +591,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
* This function checks if the remote device is an AVCRP
* target and thus whether we should send volume keys
* changes or not.
+ *
* @hide
*/
public boolean shouldSendVolumeKeys(BluetoothDevice device) {
@@ -584,7 +599,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
ParcelUuid[] uuids = device.getUuids();
if (uuids == null) return false;
- for (ParcelUuid uuid: uuids) {
+ for (ParcelUuid uuid : uuids) {
if (BluetoothUuid.isAvrcpTarget(uuid)) {
return true;
}
@@ -691,8 +706,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
*
* @param device The device to check
* @return one of OPTIONAL_CODECS_SUPPORT_UNKNOWN, OPTIONAL_CODECS_NOT_SUPPORTED, or
- * OPTIONAL_CODECS_SUPPORTED.
- *
+ * OPTIONAL_CODECS_SUPPORTED.
* @hide
*/
public int supportsOptionalCodecs(BluetoothDevice device) {
@@ -716,8 +730,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
*
* @param device The device in question.
* @return one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or
- * OPTIONAL_CODECS_PREF_DISABLED.
- *
+ * OPTIONAL_CODECS_PREF_DISABLED.
* @hide
*/
public int getOptionalCodecsEnabled(BluetoothDevice device) {
@@ -741,15 +754,15 @@ public final class BluetoothA2dp implements BluetoothProfile {
*
* @param device The device to set this preference for.
* @param value Whether the optional codecs should be enabled for this device. This should be
- * one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or
- * OPTIONAL_CODECS_PREF_DISABLED.
+ * one of OPTIONAL_CODECS_PREF_UNKNOWN, OPTIONAL_CODECS_PREF_ENABLED, or
+ * OPTIONAL_CODECS_PREF_DISABLED.
* @hide
*/
public void setOptionalCodecsEnabled(BluetoothDevice device, int value) {
try {
- if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN &&
- value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED &&
- value != BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) {
+ if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN
+ && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED
+ && value != BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED) {
Log.e(TAG, "Invalid value passed to setOptionalCodecsEnabled: " + value);
return;
}
@@ -772,24 +785,25 @@ public final class BluetoothA2dp implements BluetoothProfile {
* Helper for converting a state to a string.
*
* For debug use only - strings are not internationalized.
+ *
* @hide
*/
public static String stateToString(int state) {
switch (state) {
- case STATE_DISCONNECTED:
- return "disconnected";
- case STATE_CONNECTING:
- return "connecting";
- case STATE_CONNECTED:
- return "connected";
- case STATE_DISCONNECTING:
- return "disconnecting";
- case STATE_PLAYING:
- return "playing";
- case STATE_NOT_PLAYING:
- return "not playing";
- default:
- return " BluetoothA2dpSink is a proxy object for controlling the Bluetooth A2DP Sink
+ * BluetoothA2dpSink is a proxy object for controlling the Bluetooth A2DP Sink
* Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get
* the BluetoothA2dpSink proxy object.
*
@@ -49,9 +49,9 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
*
* This intent will have 3 extras:
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
@@ -62,7 +62,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
* receive.
*/
public static final String ACTION_CONNECTION_STATE_CHANGED =
- "android.bluetooth.a2dp-sink.profile.action.CONNECTION_STATE_CHANGED";
+ "android.bluetooth.a2dp-sink.profile.action.CONNECTION_STATE_CHANGED";
/**
* Intent used to broadcast the change in the Playing state of the A2DP Sink
@@ -70,9 +70,9 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
*
* This intent will have 3 extras:
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
@@ -82,21 +82,21 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
* receive.
*/
public static final String ACTION_PLAYING_STATE_CHANGED =
- "android.bluetooth.a2dp-sink.profile.action.PLAYING_STATE_CHANGED";
+ "android.bluetooth.a2dp-sink.profile.action.PLAYING_STATE_CHANGED";
/**
* A2DP sink device is streaming music. This state can be one of
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of
* {@link #ACTION_PLAYING_STATE_CHANGED} intent.
*/
- public static final int STATE_PLAYING = 10;
+ public static final int STATE_PLAYING = 10;
/**
* A2DP sink device is NOT streaming music. This state can be one of
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} of
* {@link #ACTION_PLAYING_STATE_CHANGED} intent.
*/
- public static final int STATE_NOT_PLAYING = 11;
+ public static final int STATE_NOT_PLAYING = 11;
/**
* Intent used to broadcast the change in the Playing state of the A2DP Sink
@@ -104,15 +104,15 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
*
* This intent will have 3 extras:
* Requires {@link android.Manifest.permission#BLUETOOTH} permission to
* receive.
*/
public static final String ACTION_AUDIO_CONFIG_CHANGED =
- "android.bluetooth.a2dp-sink.profile.action.AUDIO_CONFIG_CHANGED";
+ "android.bluetooth.a2dp-sink.profile.action.AUDIO_CONFIG_CHANGED";
/**
* Extra for the {@link #ACTION_AUDIO_CONFIG_CHANGED} intent.
@@ -120,46 +120,46 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
* This extra represents the current audio configuration of the A2DP source device.
* {@see BluetoothAudioConfig}
*/
- public static final String EXTRA_AUDIO_CONFIG
- = "android.bluetooth.a2dp-sink.profile.extra.AUDIO_CONFIG";
+ public static final String EXTRA_AUDIO_CONFIG =
+ "android.bluetooth.a2dp-sink.profile.extra.AUDIO_CONFIG";
private Context mContext;
private ServiceListener mServiceListener;
private IBluetoothA2dpSink mService;
private BluetoothAdapter mAdapter;
- final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
+ private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
new IBluetoothStateChangeCallback.Stub() {
public void onBluetoothStateChange(boolean up) {
if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
if (!up) {
- if (VDBG) Log.d(TAG,"Unbinding service...");
+ if (VDBG) Log.d(TAG, "Unbinding service...");
synchronized (mConnection) {
try {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
} else {
synchronized (mConnection) {
try {
if (mService == null) {
- if (VDBG) Log.d(TAG,"Binding service...");
+ if (VDBG) Log.d(TAG, "Binding service...");
doBind();
}
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
}
- };
+ };
+
/**
* Create a BluetoothA2dp proxy object for interacting with the local
* Bluetooth A2DP service.
- *
*/
/*package*/ BluetoothA2dpSink(Context context, ServiceListener l) {
mContext = context;
@@ -170,7 +170,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
try {
mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -196,7 +196,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
try {
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
} catch (Exception e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -206,15 +206,17 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
}
+ @Override
public void finalize() {
close();
}
+
/**
* Initiate connection to a profile of the remote bluetooth device.
*
@@ -233,14 +235,12 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
* permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean connect(BluetoothDevice device) {
if (DBG) log("connect(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.connect(device);
} catch (RemoteException e) {
@@ -274,14 +274,12 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
* permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean disconnect(BluetoothDevice device) {
if (DBG) log("disconnect(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.disconnect(device);
} catch (RemoteException e) {
@@ -296,6 +294,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
/**
* {@inheritDoc}
*/
+ @Override
public List The device should already be paired.
- * Priority can be one of {@link #PRIORITY_ON} orgetBluetoothManager
+ * Priority can be one of {@link #PRIORITY_ON} orgetBluetoothManager
* {@link #PRIORITY_OFF},
*
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
@@ -389,20 +390,20 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
public boolean setPriority(BluetoothDevice device, int priority) {
if (DBG) log("setPriority(" + device + ", " + priority + ")");
if (mService != null && isEnabled()
- && isValidDevice(device)) {
- if (priority != BluetoothProfile.PRIORITY_OFF &&
- priority != BluetoothProfile.PRIORITY_ON){
+ && isValidDevice(device)) {
+ if (priority != BluetoothProfile.PRIORITY_OFF
+ && priority != BluetoothProfile.PRIORITY_ON) {
return false;
}
try {
return mService.setPriority(device, priority);
} catch (RemoteException e) {
- Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
- return false;
+ Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
+ return false;
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
- return false;
+ return false;
}
/**
@@ -421,7 +422,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
public int getPriority(BluetoothDevice device) {
if (VDBG) log("getPriority(" + device + ")");
if (mService != null && isEnabled()
- && isValidDevice(device)) {
+ && isValidDevice(device)) {
try {
return mService.getPriority(device);
} catch (RemoteException e) {
@@ -442,7 +443,7 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
*/
public boolean isA2dpPlaying(BluetoothDevice device) {
if (mService != null && isEnabled()
- && isValidDevice(device)) {
+ && isValidDevice(device)) {
try {
return mService.isA2dpPlaying(device);
} catch (RemoteException e) {
@@ -458,24 +459,25 @@ public final class BluetoothA2dpSink implements BluetoothProfile {
* Helper for converting a state to a string.
*
* For debug use only - strings are not internationalized.
+ *
* @hide
*/
public static String stateToString(int state) {
switch (state) {
- case STATE_DISCONNECTED:
- return "disconnected";
- case STATE_CONNECTING:
- return "connecting";
- case STATE_CONNECTED:
- return "connected";
- case STATE_DISCONNECTING:
- return "disconnecting";
- case STATE_PLAYING:
- return "playing";
- case STATE_NOT_PLAYING:
- return "not playing";
- default:
- return " This class is thread safe.
- * For more information about using Bluetooth, read the Bluetooth developer
* guide.
*
* Use {@link #isLePeriodicAdvertisingSupported()} to check whether LE Periodic Advertising is
* supported on this device before calling this method.
+ *
* @hide
*/
public PeriodicAdvertisingManager getPeriodicAdvertisingManager() {
- if (!getLeAccess())
- return null;
-
- if (!isLePeriodicAdvertisingSupported())
- return null;
-
- synchronized (mLock) {
- if (sPeriodicAdvertisingManager == null) {
- sPeriodicAdvertisingManager =
- new PeriodicAdvertisingManager(mManagerService);
+ if (!getLeAccess()) {
+ return null;
}
- }
- return sPeriodicAdvertisingManager;
+
+ if (!isLePeriodicAdvertisingSupported()) {
+ return null;
+ }
+
+ synchronized (mLock) {
+ if (sPeriodicAdvertisingManager == null) {
+ sPeriodicAdvertisingManager =
+ new PeriodicAdvertisingManager(mManagerService);
+ }
+ }
+ return sPeriodicAdvertisingManager;
}
/**
@@ -686,7 +710,7 @@ public final class BluetoothAdapter {
*/
public BluetoothLeScanner getBluetoothLeScanner() {
if (!getLeAccess()) return null;
- synchronized(mLock) {
+ synchronized (mLock) {
if (sBluetoothLeScanner == null) {
sBluetoothLeScanner = new BluetoothLeScanner(mManagerService);
}
@@ -725,9 +749,9 @@ public final class BluetoothAdapter {
*/
@SystemApi
public boolean isLeEnabled() {
- final int state = getLeState();
- if (DBG) Log.d(TAG, "isLeEnabled(): " + BluetoothAdapter.nameForState(state));
- return (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_BLE_ON);
+ final int state = getLeState();
+ if (DBG) Log.d(TAG, "isLeEnabled(): " + BluetoothAdapter.nameForState(state));
+ return (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_BLE_ON);
}
/**
@@ -752,8 +776,7 @@ public final class BluetoothAdapter {
* immediate problem that will prevent the QAdapter from being turned off -
* such as the QAadapter already being turned off.
*
- * @return true to indicate success, or false on
- * immediate error
+ * @return true to indicate success, or false on immediate error
* @hide
*/
@SystemApi
@@ -763,7 +786,7 @@ public final class BluetoothAdapter {
int state = getLeState();
if (state == BluetoothAdapter.STATE_ON || state == BluetoothAdapter.STATE_BLE_ON) {
String packageName = ActivityThread.currentPackageName();
- if (DBG) Log.d (TAG, "disableBLE(): de-registering " + packageName);
+ if (DBG) Log.d(TAG, "disableBLE(): de-registering " + packageName);
try {
mManagerService.updateBleAppCount(mToken, false, packageName);
} catch (RemoteException e) {
@@ -772,7 +795,7 @@ public final class BluetoothAdapter {
return true;
}
- if (DBG) Log.d (TAG, "disableBLE(): Already disabled");
+ if (DBG) Log.d(TAG, "disableBLE(): Already disabled");
return false;
}
@@ -804,8 +827,7 @@ public final class BluetoothAdapter {
* states, It includes all the classic Bluetooth Adapter states along with
* internal BLE only states
*
- * @return true to indicate Bluetooth LE will be available, or false on
- * immediate error
+ * @return true to indicate Bluetooth LE will be available, or false on immediate error
* @hide
*/
@SystemApi
@@ -856,12 +878,19 @@ public final class BluetoothAdapter {
// Consider all internal states as OFF
if (state == BluetoothAdapter.STATE_BLE_ON
- || state == BluetoothAdapter.STATE_BLE_TURNING_ON
- || state == BluetoothAdapter.STATE_BLE_TURNING_OFF) {
- if (VDBG) Log.d(TAG, "Consider " + BluetoothAdapter.nameForState(state) + " state as OFF");
+ || state == BluetoothAdapter.STATE_BLE_TURNING_ON
+ || state == BluetoothAdapter.STATE_BLE_TURNING_OFF) {
+ if (VDBG) {
+ Log.d(TAG,
+ "Consider " + BluetoothAdapter.nameForState(state) + " state as OFF");
+ }
state = BluetoothAdapter.STATE_OFF;
}
- if (VDBG) Log.d(TAG, "" + hashCode() + ": getState(). Returning " + BluetoothAdapter.nameForState(state));
+ if (VDBG) {
+ Log.d(TAG,
+ "" + hashCode() + ": getState(). Returning " + BluetoothAdapter.nameForState(
+ state));
+ }
return state;
}
@@ -897,16 +926,16 @@ public final class BluetoothAdapter {
mServiceLock.readLock().unlock();
}
- if (VDBG) Log.d(TAG,"getLeState() returning " + BluetoothAdapter.nameForState(state));
+ if (VDBG) Log.d(TAG, "getLeState() returning " + BluetoothAdapter.nameForState(state));
return state;
}
boolean getLeAccess() {
- if (getLeState() == STATE_ON)
+ if (getLeState() == STATE_ON) {
return true;
-
- else if (getLeState() == STATE_BLE_ON)
+ } else if (getLeState() == STATE_BLE_ON) {
return true; // TODO: FILTER SYSTEM APPS HERE <--
+ }
return false;
}
@@ -933,8 +962,7 @@ public final class BluetoothAdapter {
* immediate problem that will prevent the adapter from being turned on -
* such as Airplane mode, or the adapter is already turned on.
*
- * @return true to indicate adapter startup has begun, or false on
- * immediate error
+ * @return true to indicate adapter startup has begun, or false on immediate error
*/
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public boolean enable() {
@@ -944,7 +972,9 @@ public final class BluetoothAdapter {
}
try {
return mManagerService.enable(ActivityThread.currentPackageName());
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -967,14 +997,15 @@ public final class BluetoothAdapter {
* immediate problem that will prevent the adapter from being turned off -
* such as the adapter already being turned off.
*
- * @return true to indicate adapter shutdown has begun, or false on
- * immediate error
+ * @return true to indicate adapter shutdown has begun, or false on immediate error
*/
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public boolean disable() {
try {
return mManagerService.disable(ActivityThread.currentPackageName(), true);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -984,15 +1015,16 @@ public final class BluetoothAdapter {
* Requires the {@link android.Manifest.permission#BLUETOOTH_ADMIN}
* permission
*
- * @return true to indicate adapter shutdown has begun, or false on
- * immediate error
+ * @return true to indicate adapter shutdown has begun, or false on immediate error
* @hide
*/
public boolean disable(boolean persist) {
try {
return mManagerService.disable(ActivityThread.currentPackageName(), persist);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -1006,7 +1038,9 @@ public final class BluetoothAdapter {
public String getAddress() {
try {
return mManagerService.getAddress();
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return null;
}
@@ -1020,7 +1054,9 @@ public final class BluetoothAdapter {
public String getName() {
try {
return mManagerService.getName();
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return null;
}
@@ -1031,7 +1067,6 @@ public final class BluetoothAdapter {
* permission
*
* @return true to indicate that the config file was successfully cleared
- *
* @hide
*/
public boolean factoryReset() {
@@ -1082,7 +1117,7 @@ public final class BluetoothAdapter {
* to get the updated value.
*
* @param name a valid Bluetooth name
- * @return true if the name was set, false otherwise
+ * @return true if the name was set, false otherwise
*/
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public boolean setName(String name) {
@@ -1151,9 +1186,9 @@ public final class BluetoothAdapter {
* instead.
*
* @param mode valid scan mode
- * @param duration time in seconds to apply scan mode, only used for
- * {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}
- * @return true if the scan mode was set, false otherwise
+ * @param duration time in seconds to apply scan mode, only used for {@link
+ * #SCAN_MODE_CONNECTABLE_DISCOVERABLE}
+ * @return true if the scan mode was set, false otherwise
* @hide
*/
public boolean setScanMode(@ScanMode int mode, int duration) {
@@ -1205,9 +1240,10 @@ public final class BluetoothAdapter {
/**
* Get the end time of the latest remote device discovery process.
- * @return the latest time that the bluetooth adapter was/will be in discovery mode,
- * in milliseconds since the epoch.
- * This time can be in the future if {@link #startDiscovery()} has been called recently.
+ *
+ * @return the latest time that the bluetooth adapter was/will be in discovery mode, in
+ * milliseconds since the epoch. This time can be in the future if {@link #startDiscovery()} has
+ * been called recently.
* @hide
*/
public long getDiscoveryEndMillis() {
@@ -1517,13 +1553,13 @@ public final class BluetoothAdapter {
* Return the record of {@link BluetoothActivityEnergyInfo} object that
* has the activity and energy info. This can be used to ascertain what
* the controller has been up to, since the last sample.
- * @param updateType Type of info, cached vs refreshed.
*
- * @return a record with {@link BluetoothActivityEnergyInfo} or null if
- * report is unavailable or unsupported
- * @deprecated use the asynchronous
- * {@link #requestControllerActivityEnergyInfo(ResultReceiver)} instead.
+ * @param updateType Type of info, cached vs refreshed.
+ * @return a record with {@link BluetoothActivityEnergyInfo} or null if report is unavailable or
+ * unsupported
* @hide
+ * @deprecated use the asynchronous {@link #requestControllerActivityEnergyInfo(ResultReceiver)}
+ * instead.
*/
@Deprecated
public BluetoothActivityEnergyInfo getControllerActivityEnergyInfo(int updateType) {
@@ -1599,11 +1635,11 @@ public final class BluetoothAdapter {
/**
* Gets the currently supported profiles by the adapter.
*
- * This can be used to check whether a profile is supported before attempting
+ * This can be used to check whether a profile is supported before attempting
* to connect to its respective proxy.
*
- * @return a list of integers indicating the ids of supported profiles as defined in
- * {@link BluetoothProfile}.
+ * @return a list of integers indicating the ids of supported profiles as defined in {@link
+ * BluetoothProfile}.
* @hide
*/
public List Use this function along with {@link #ACTION_CONNECTION_STATE_CHANGED}
* intent to get the connection state of the adapter.
*
- * @return One of {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTED},
- * {@link #STATE_CONNECTING} or {@link #STATE_DISCONNECTED}
- *
+ * @return One of {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTED}, {@link
+ * #STATE_CONNECTING} or {@link #STATE_DISCONNECTED}
* @hide
*/
public int getConnectionState() {
@@ -1688,10 +1723,11 @@ public final class BluetoothAdapter {
* connections from a listening {@link BluetoothServerSocket}.
* Valid RFCOMM channels are in range 1 to 30.
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
+ *
* @param channel RFCOMM channel to listen on
* @return a listening RFCOMM BluetoothServerSocket
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions, or channel in use.
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions, or channel in use.
* @hide
*/
public BluetoothServerSocket listenUsingRfcommOn(int channel) throws IOException {
@@ -1708,12 +1744,14 @@ public final class BluetoothAdapter {
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
* To auto assign a channel without creating a SDP record use
* {@link SOCKET_CHANNEL_AUTO_STATIC_NO_SDP} as channel number.
+ *
* @param channel RFCOMM channel to listen on
- * @param mitm enforce man-in-the-middle protection for authentication.
- * @param min16DigitPin enforce a pin key length og minimum 16 digit for sec mode 2 connections.
+ * @param mitm enforce man-in-the-middle protection for authentication.
+ * @param min16DigitPin enforce a pin key length og minimum 16 digit for sec mode 2
+ * connections.
* @return a listening RFCOMM BluetoothServerSocket
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions, or channel in use.
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions, or channel in use.
* @hide
*/
public BluetoothServerSocket listenUsingRfcommOn(int channel, boolean mitm,
@@ -1749,11 +1787,12 @@ public final class BluetoothAdapter {
* closed, or if this application closes unexpectedly.
* Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to
* connect to this socket from another device using the same {@link UUID}.
+ *
* @param name service name for SDP record
* @param uuid uuid for SDP record
* @return a listening RFCOMM BluetoothServerSocket
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions, or channel in use.
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions, or channel in use.
*/
@RequiresPermission(Manifest.permission.BLUETOOTH)
public BluetoothServerSocket listenUsingRfcommWithServiceRecord(String name, UUID uuid)
@@ -1780,11 +1819,12 @@ public final class BluetoothAdapter {
* closed, or if this application closes unexpectedly.
* Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to
* connect to this socket from another device using the same {@link UUID}.
+ *
* @param name service name for SDP record
* @param uuid uuid for SDP record
* @return a listening RFCOMM BluetoothServerSocket
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions, or channel in use.
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions, or channel in use.
*/
@RequiresPermission(Manifest.permission.BLUETOOTH)
public BluetoothServerSocket listenUsingInsecureRfcommWithServiceRecord(String name, UUID uuid)
@@ -1792,7 +1832,7 @@ public final class BluetoothAdapter {
return createNewRfcommSocketAndRecord(name, uuid, false, false);
}
- /**
+ /**
* Create a listening, encrypted,
* RFCOMM Bluetooth socket with Service Record.
* The link will be encrypted, but the link key is not required to be authenticated
@@ -1818,11 +1858,12 @@ public final class BluetoothAdapter {
* Use {@link BluetoothDevice#createRfcommSocketToServiceRecord} to
* connect to this socket from another device using the same {@link UUID}.
* Requires {@link android.Manifest.permission#BLUETOOTH}
+ *
* @param name service name for SDP record
* @param uuid uuid for SDP record
* @return a listening RFCOMM BluetoothServerSocket
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions, or channel in use.
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions, or channel in use.
* @hide
*/
public BluetoothServerSocket listenUsingEncryptedRfcommWithServiceRecord(
@@ -1835,7 +1876,7 @@ public final class BluetoothAdapter {
boolean auth, boolean encrypt) throws IOException {
BluetoothServerSocket socket;
socket = new BluetoothServerSocket(BluetoothSocket.TYPE_RFCOMM, auth,
- encrypt, new ParcelUuid(uuid));
+ encrypt, new ParcelUuid(uuid));
socket.setServiceName(name);
int errno = socket.mSocket.bindListen();
if (errno != 0) {
@@ -1850,16 +1891,17 @@ public final class BluetoothAdapter {
/**
* Construct an unencrypted, unauthenticated, RFCOMM server socket.
* Call #accept to retrieve connections to this socket.
+ *
* @return An RFCOMM BluetoothServerSocket
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient permissions.
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * permissions.
* @hide
*/
public BluetoothServerSocket listenUsingInsecureRfcommOn(int port) throws IOException {
BluetoothServerSocket socket = new BluetoothServerSocket(
BluetoothSocket.TYPE_RFCOMM, false, false, port);
int errno = socket.mSocket.bindListen();
- if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
+ if (port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
socket.setChannel(socket.mSocket.getPort());
}
if (errno != 0) {
@@ -1871,12 +1913,13 @@ public final class BluetoothAdapter {
return socket;
}
- /**
+ /**
* Construct an encrypted, RFCOMM server socket.
* Call #accept to retrieve connections to this socket.
+ *
* @return An RFCOMM BluetoothServerSocket
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient permissions.
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * permissions.
* @hide
*/
public BluetoothServerSocket listenUsingEncryptedRfcommOn(int port)
@@ -1884,7 +1927,7 @@ public final class BluetoothAdapter {
BluetoothServerSocket socket = new BluetoothServerSocket(
BluetoothSocket.TYPE_RFCOMM, false, true, port);
int errno = socket.mSocket.bindListen();
- if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
+ if (port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
socket.setChannel(socket.mSocket.getPort());
}
if (errno < 0) {
@@ -1899,9 +1942,10 @@ public final class BluetoothAdapter {
/**
* Construct a SCO server socket.
* Call #accept to retrieve connections to this socket.
+ *
* @return A SCO BluetoothServerSocket
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient permissions.
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * permissions.
* @hide
*/
public static BluetoothServerSocket listenUsingScoOn() throws IOException {
@@ -1921,12 +1965,14 @@ public final class BluetoothAdapter {
* Call #accept to retrieve connections to this socket.
* To auto assign a port without creating a SDP record use
* {@link SOCKET_CHANNEL_AUTO_STATIC_NO_SDP} as port number.
- * @param port the PSM to listen on
- * @param mitm enforce man-in-the-middle protection for authentication.
- * @param min16DigitPin enforce a pin key length og minimum 16 digit for sec mode 2 connections.
+ *
+ * @param port the PSM to listen on
+ * @param mitm enforce man-in-the-middle protection for authentication.
+ * @param min16DigitPin enforce a pin key length og minimum 16 digit for sec mode 2
+ * connections.
* @return An L2CAP BluetoothServerSocket
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient permissions.
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * permissions.
* @hide
*/
public BluetoothServerSocket listenUsingL2capOn(int port, boolean mitm, boolean min16DigitPin)
@@ -1934,7 +1980,7 @@ public final class BluetoothAdapter {
BluetoothServerSocket socket = new BluetoothServerSocket(
BluetoothSocket.TYPE_L2CAP, true, true, port, mitm, min16DigitPin);
int errno = socket.mSocket.bindListen();
- if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
+ if (port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
socket.setChannel(socket.mSocket.getPort());
}
if (errno != 0) {
@@ -1951,10 +1997,11 @@ public final class BluetoothAdapter {
* Call #accept to retrieve connections to this socket.
* To auto assign a port without creating a SDP record use
* {@link SOCKET_CHANNEL_AUTO_STATIC_NO_SDP} as port number.
- * @param port the PSM to listen on
+ *
+ * @param port the PSM to listen on
* @return An L2CAP BluetoothServerSocket
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient permissions.
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * permissions.
* @hide
*/
public BluetoothServerSocket listenUsingL2capOn(int port) throws IOException {
@@ -1967,17 +2014,18 @@ public final class BluetoothAdapter {
* Call #accept to retrieve connections to this socket.
* To auto assign a port without creating a SDP record use
* {@link SOCKET_CHANNEL_AUTO_STATIC_NO_SDP} as port number.
- * @param port the PSM to listen on
+ *
+ * @param port the PSM to listen on
* @return An L2CAP BluetoothServerSocket
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient permissions.
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * permissions.
* @hide
*/
public BluetoothServerSocket listenUsingInsecureL2capOn(int port) throws IOException {
BluetoothServerSocket socket = new BluetoothServerSocket(
BluetoothSocket.TYPE_L2CAP, false, false, port, false, false);
int errno = socket.mSocket.bindListen();
- if(port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
+ if (port == SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
socket.setChannel(socket.mSocket.getPort());
}
if (errno != 0) {
@@ -1995,7 +2043,6 @@ public final class BluetoothAdapter {
* Requires {@link android.Manifest.permission#BLUETOOTH}
*
* @return Pair
* For now we only include Company ID values.
- * @see
- * The Official Bluetooth SIG Member Website | Company Identifiers
*
+ * @see The Official
+ * Bluetooth SIG Member Website | Company Identifiers
*/
public class BluetoothAssignedNumbers {
diff --git a/core/java/android/bluetooth/BluetoothAudioConfig.java b/core/java/android/bluetooth/BluetoothAudioConfig.java
index 03176b9e07390..a4410563c9915 100644
--- a/core/java/android/bluetooth/BluetoothAudioConfig.java
+++ b/core/java/android/bluetooth/BluetoothAudioConfig.java
@@ -41,10 +41,9 @@ public final class BluetoothAudioConfig implements Parcelable {
@Override
public boolean equals(Object o) {
if (o instanceof BluetoothAudioConfig) {
- BluetoothAudioConfig bac = (BluetoothAudioConfig)o;
- return (bac.mSampleRate == mSampleRate &&
- bac.mChannelConfig == mChannelConfig &&
- bac.mAudioFormat == mAudioFormat);
+ BluetoothAudioConfig bac = (BluetoothAudioConfig) o;
+ return (bac.mSampleRate == mSampleRate && bac.mChannelConfig == mChannelConfig
+ && bac.mAudioFormat == mAudioFormat);
}
return false;
}
@@ -60,23 +59,26 @@ public final class BluetoothAudioConfig implements Parcelable {
+ ",mAudioFormat:" + mAudioFormat + "}";
}
+ @Override
public int describeContents() {
return 0;
}
public static final Parcelable.Creator BluetoothAvrcpController is a proxy object for controlling the Bluetooth AVRCP
+ * BluetoothAvrcpController is a proxy object for controlling the Bluetooth AVRCP
* Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get
* the BluetoothAvrcpController proxy object.
*
@@ -51,9 +49,9 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
*
* This intent will have 3 extras:
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
@@ -64,19 +62,19 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
* receive.
*/
public static final String ACTION_CONNECTION_STATE_CHANGED =
- "android.bluetooth.avrcp-controller.profile.action.CONNECTION_STATE_CHANGED";
+ "android.bluetooth.avrcp-controller.profile.action.CONNECTION_STATE_CHANGED";
/**
* Intent used to broadcast the change in player application setting state on AVRCP AG.
*
* This intent will have the following extras:
* Each {@link BluetoothClass} encodes zero or more service classes.
*/
public static final class Service {
- private static final int BITMASK = 0xFFE000;
+ private static final int BITMASK = 0xFFE000;
public static final int LIMITED_DISCOVERABILITY = 0x002000;
- public static final int POSITIONING = 0x010000;
- public static final int NETWORKING = 0x020000;
- public static final int RENDER = 0x040000;
- public static final int CAPTURE = 0x080000;
- public static final int OBJECT_TRANSFER = 0x100000;
- public static final int AUDIO = 0x200000;
- public static final int TELEPHONY = 0x400000;
- public static final int INFORMATION = 0x800000;
+ public static final int POSITIONING = 0x010000;
+ public static final int NETWORKING = 0x020000;
+ public static final int RENDER = 0x040000;
+ public static final int CAPTURE = 0x080000;
+ public static final int OBJECT_TRANSFER = 0x100000;
+ public static final int AUDIO = 0x200000;
+ public static final int TELEPHONY = 0x400000;
+ public static final int INFORMATION = 0x800000;
}
/**
@@ -141,91 +145,91 @@ public final class BluetoothClass implements Parcelable {
* See {@link BluetoothClass.Service} for service class constants.
*/
public static class Device {
- private static final int BITMASK = 0x1FFC;
+ private static final int BITMASK = 0x1FFC;
/**
* Defines all major device class constants.
* See {@link BluetoothClass.Device} for minor classes.
*/
public static class Major {
- private static final int BITMASK = 0x1F00;
+ private static final int BITMASK = 0x1F00;
- public static final int MISC = 0x0000;
- public static final int COMPUTER = 0x0100;
- public static final int PHONE = 0x0200;
- public static final int NETWORKING = 0x0300;
- public static final int AUDIO_VIDEO = 0x0400;
- public static final int PERIPHERAL = 0x0500;
- public static final int IMAGING = 0x0600;
- public static final int WEARABLE = 0x0700;
- public static final int TOY = 0x0800;
- public static final int HEALTH = 0x0900;
- public static final int UNCATEGORIZED = 0x1F00;
+ public static final int MISC = 0x0000;
+ public static final int COMPUTER = 0x0100;
+ public static final int PHONE = 0x0200;
+ public static final int NETWORKING = 0x0300;
+ public static final int AUDIO_VIDEO = 0x0400;
+ public static final int PERIPHERAL = 0x0500;
+ public static final int IMAGING = 0x0600;
+ public static final int WEARABLE = 0x0700;
+ public static final int TOY = 0x0800;
+ public static final int HEALTH = 0x0900;
+ public static final int UNCATEGORIZED = 0x1F00;
}
// Devices in the COMPUTER major class
- public static final int COMPUTER_UNCATEGORIZED = 0x0100;
- public static final int COMPUTER_DESKTOP = 0x0104;
- public static final int COMPUTER_SERVER = 0x0108;
- public static final int COMPUTER_LAPTOP = 0x010C;
- public static final int COMPUTER_HANDHELD_PC_PDA = 0x0110;
- public static final int COMPUTER_PALM_SIZE_PC_PDA = 0x0114;
- public static final int COMPUTER_WEARABLE = 0x0118;
+ public static final int COMPUTER_UNCATEGORIZED = 0x0100;
+ public static final int COMPUTER_DESKTOP = 0x0104;
+ public static final int COMPUTER_SERVER = 0x0108;
+ public static final int COMPUTER_LAPTOP = 0x010C;
+ public static final int COMPUTER_HANDHELD_PC_PDA = 0x0110;
+ public static final int COMPUTER_PALM_SIZE_PC_PDA = 0x0114;
+ public static final int COMPUTER_WEARABLE = 0x0118;
// Devices in the PHONE major class
- public static final int PHONE_UNCATEGORIZED = 0x0200;
- public static final int PHONE_CELLULAR = 0x0204;
- public static final int PHONE_CORDLESS = 0x0208;
- public static final int PHONE_SMART = 0x020C;
- public static final int PHONE_MODEM_OR_GATEWAY = 0x0210;
- public static final int PHONE_ISDN = 0x0214;
+ public static final int PHONE_UNCATEGORIZED = 0x0200;
+ public static final int PHONE_CELLULAR = 0x0204;
+ public static final int PHONE_CORDLESS = 0x0208;
+ public static final int PHONE_SMART = 0x020C;
+ public static final int PHONE_MODEM_OR_GATEWAY = 0x0210;
+ public static final int PHONE_ISDN = 0x0214;
// Minor classes for the AUDIO_VIDEO major class
- public static final int AUDIO_VIDEO_UNCATEGORIZED = 0x0400;
- public static final int AUDIO_VIDEO_WEARABLE_HEADSET = 0x0404;
- public static final int AUDIO_VIDEO_HANDSFREE = 0x0408;
+ public static final int AUDIO_VIDEO_UNCATEGORIZED = 0x0400;
+ public static final int AUDIO_VIDEO_WEARABLE_HEADSET = 0x0404;
+ public static final int AUDIO_VIDEO_HANDSFREE = 0x0408;
//public static final int AUDIO_VIDEO_RESERVED = 0x040C;
- public static final int AUDIO_VIDEO_MICROPHONE = 0x0410;
- public static final int AUDIO_VIDEO_LOUDSPEAKER = 0x0414;
- public static final int AUDIO_VIDEO_HEADPHONES = 0x0418;
- public static final int AUDIO_VIDEO_PORTABLE_AUDIO = 0x041C;
- public static final int AUDIO_VIDEO_CAR_AUDIO = 0x0420;
- public static final int AUDIO_VIDEO_SET_TOP_BOX = 0x0424;
- public static final int AUDIO_VIDEO_HIFI_AUDIO = 0x0428;
- public static final int AUDIO_VIDEO_VCR = 0x042C;
- public static final int AUDIO_VIDEO_VIDEO_CAMERA = 0x0430;
- public static final int AUDIO_VIDEO_CAMCORDER = 0x0434;
- public static final int AUDIO_VIDEO_VIDEO_MONITOR = 0x0438;
+ public static final int AUDIO_VIDEO_MICROPHONE = 0x0410;
+ public static final int AUDIO_VIDEO_LOUDSPEAKER = 0x0414;
+ public static final int AUDIO_VIDEO_HEADPHONES = 0x0418;
+ public static final int AUDIO_VIDEO_PORTABLE_AUDIO = 0x041C;
+ public static final int AUDIO_VIDEO_CAR_AUDIO = 0x0420;
+ public static final int AUDIO_VIDEO_SET_TOP_BOX = 0x0424;
+ public static final int AUDIO_VIDEO_HIFI_AUDIO = 0x0428;
+ public static final int AUDIO_VIDEO_VCR = 0x042C;
+ public static final int AUDIO_VIDEO_VIDEO_CAMERA = 0x0430;
+ public static final int AUDIO_VIDEO_CAMCORDER = 0x0434;
+ public static final int AUDIO_VIDEO_VIDEO_MONITOR = 0x0438;
public static final int AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER = 0x043C;
- public static final int AUDIO_VIDEO_VIDEO_CONFERENCING = 0x0440;
+ public static final int AUDIO_VIDEO_VIDEO_CONFERENCING = 0x0440;
//public static final int AUDIO_VIDEO_RESERVED = 0x0444;
- public static final int AUDIO_VIDEO_VIDEO_GAMING_TOY = 0x0448;
+ public static final int AUDIO_VIDEO_VIDEO_GAMING_TOY = 0x0448;
// Devices in the WEARABLE major class
- public static final int WEARABLE_UNCATEGORIZED = 0x0700;
- public static final int WEARABLE_WRIST_WATCH = 0x0704;
- public static final int WEARABLE_PAGER = 0x0708;
- public static final int WEARABLE_JACKET = 0x070C;
- public static final int WEARABLE_HELMET = 0x0710;
- public static final int WEARABLE_GLASSES = 0x0714;
+ public static final int WEARABLE_UNCATEGORIZED = 0x0700;
+ public static final int WEARABLE_WRIST_WATCH = 0x0704;
+ public static final int WEARABLE_PAGER = 0x0708;
+ public static final int WEARABLE_JACKET = 0x070C;
+ public static final int WEARABLE_HELMET = 0x0710;
+ public static final int WEARABLE_GLASSES = 0x0714;
// Devices in the TOY major class
- public static final int TOY_UNCATEGORIZED = 0x0800;
- public static final int TOY_ROBOT = 0x0804;
- public static final int TOY_VEHICLE = 0x0808;
- public static final int TOY_DOLL_ACTION_FIGURE = 0x080C;
- public static final int TOY_CONTROLLER = 0x0810;
- public static final int TOY_GAME = 0x0814;
+ public static final int TOY_UNCATEGORIZED = 0x0800;
+ public static final int TOY_ROBOT = 0x0804;
+ public static final int TOY_VEHICLE = 0x0808;
+ public static final int TOY_DOLL_ACTION_FIGURE = 0x080C;
+ public static final int TOY_CONTROLLER = 0x0810;
+ public static final int TOY_GAME = 0x0814;
// Devices in the HEALTH major class
- public static final int HEALTH_UNCATEGORIZED = 0x0900;
- public static final int HEALTH_BLOOD_PRESSURE = 0x0904;
- public static final int HEALTH_THERMOMETER = 0x0908;
- public static final int HEALTH_WEIGHING = 0x090C;
- public static final int HEALTH_GLUCOSE = 0x0910;
- public static final int HEALTH_PULSE_OXIMETER = 0x0914;
- public static final int HEALTH_PULSE_RATE = 0x0918;
- public static final int HEALTH_DATA_DISPLAY = 0x091C;
+ public static final int HEALTH_UNCATEGORIZED = 0x0900;
+ public static final int HEALTH_BLOOD_PRESSURE = 0x0904;
+ public static final int HEALTH_THERMOMETER = 0x0908;
+ public static final int HEALTH_WEIGHING = 0x090C;
+ public static final int HEALTH_GLUCOSE = 0x0910;
+ public static final int HEALTH_PULSE_OXIMETER = 0x0914;
+ public static final int HEALTH_PULSE_RATE = 0x0918;
+ public static final int HEALTH_DATA_DISPLAY = 0x091C;
// Devices in PERIPHERAL major class
/**
@@ -235,15 +239,15 @@ public final class BluetoothClass implements Parcelable {
/**
* @hide
*/
- public static final int PERIPHERAL_KEYBOARD = 0x0540;
+ public static final int PERIPHERAL_KEYBOARD = 0x0540;
/**
* @hide
*/
- public static final int PERIPHERAL_POINTING = 0x0580;
+ public static final int PERIPHERAL_POINTING = 0x0580;
/**
* @hide
*/
- public static final int PERIPHERAL_KEYBOARD_POINTING = 0x05C0;
+ public static final int PERIPHERAL_KEYBOARD_POINTING = 0x05C0;
}
/**
@@ -291,6 +295,7 @@ public final class BluetoothClass implements Parcelable {
* This is a simple heuristic that tries to guess if a device with the
* given class bits might support specified profile. It is not accurate for all
* devices. It tries to err on the side of false positives.
+ *
* @param profile The profile to be checked
* @return True if this device might support specified profile.
* @hide
@@ -322,7 +327,7 @@ public final class BluetoothClass implements Parcelable {
switch (getDeviceClass()) {
case Device.AUDIO_VIDEO_HIFI_AUDIO:
case Device.AUDIO_VIDEO_SET_TOP_BOX:
- case Device.AUDIO_VIDEO_VCR :
+ case Device.AUDIO_VIDEO_VCR:
return true;
default:
return false;
@@ -367,7 +372,7 @@ public final class BluetoothClass implements Parcelable {
}
} else if (profile == PROFILE_HID) {
return (getDeviceClass() & Device.Major.PERIPHERAL) == Device.Major.PERIPHERAL;
- } else if (profile == PROFILE_PANU || profile == PROFILE_NAP){
+ } else if (profile == PROFILE_PANU || profile == PROFILE_NAP) {
// No good way to distinguish between the two, based on class bits.
if (hasService(Service.NETWORKING)) {
return true;
diff --git a/core/java/android/bluetooth/BluetoothCodecConfig.java b/core/java/android/bluetooth/BluetoothCodecConfig.java
index d5e1429810135..e3a6e064725e2 100644
--- a/core/java/android/bluetooth/BluetoothCodecConfig.java
+++ b/core/java/android/bluetooth/BluetoothCodecConfig.java
@@ -32,12 +32,12 @@ public final class BluetoothCodecConfig implements Parcelable {
// Add an entry for each source codec here.
// NOTE: The values should be same as those listed in the following file:
// hardware/libhardware/include/hardware/bt_av.h
- public static final int SOURCE_CODEC_TYPE_SBC = 0;
- public static final int SOURCE_CODEC_TYPE_AAC = 1;
- public static final int SOURCE_CODEC_TYPE_APTX = 2;
+ public static final int SOURCE_CODEC_TYPE_SBC = 0;
+ public static final int SOURCE_CODEC_TYPE_AAC = 1;
+ public static final int SOURCE_CODEC_TYPE_APTX = 2;
public static final int SOURCE_CODEC_TYPE_APTX_HD = 3;
- public static final int SOURCE_CODEC_TYPE_LDAC = 4;
- public static final int SOURCE_CODEC_TYPE_MAX = 5;
+ public static final int SOURCE_CODEC_TYPE_LDAC = 4;
+ public static final int SOURCE_CODEC_TYPE_MAX = 5;
public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000;
@@ -45,21 +45,21 @@ public final class BluetoothCodecConfig implements Parcelable {
public static final int CODEC_PRIORITY_DEFAULT = 0;
public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000;
- public static final int SAMPLE_RATE_NONE = 0;
- public static final int SAMPLE_RATE_44100 = 0x1 << 0;
- public static final int SAMPLE_RATE_48000 = 0x1 << 1;
- public static final int SAMPLE_RATE_88200 = 0x1 << 2;
- public static final int SAMPLE_RATE_96000 = 0x1 << 3;
+ public static final int SAMPLE_RATE_NONE = 0;
+ public static final int SAMPLE_RATE_44100 = 0x1 << 0;
+ public static final int SAMPLE_RATE_48000 = 0x1 << 1;
+ public static final int SAMPLE_RATE_88200 = 0x1 << 2;
+ public static final int SAMPLE_RATE_96000 = 0x1 << 3;
public static final int SAMPLE_RATE_176400 = 0x1 << 4;
public static final int SAMPLE_RATE_192000 = 0x1 << 5;
public static final int BITS_PER_SAMPLE_NONE = 0;
- public static final int BITS_PER_SAMPLE_16 = 0x1 << 0;
- public static final int BITS_PER_SAMPLE_24 = 0x1 << 1;
- public static final int BITS_PER_SAMPLE_32 = 0x1 << 2;
+ public static final int BITS_PER_SAMPLE_16 = 0x1 << 0;
+ public static final int BITS_PER_SAMPLE_24 = 0x1 << 1;
+ public static final int BITS_PER_SAMPLE_32 = 0x1 << 2;
- public static final int CHANNEL_MODE_NONE = 0;
- public static final int CHANNEL_MODE_MONO = 0x1 << 0;
+ public static final int CHANNEL_MODE_NONE = 0;
+ public static final int CHANNEL_MODE_MONO = 0x1 << 0;
public static final int CHANNEL_MODE_STEREO = 0x1 << 1;
private final int mCodecType;
@@ -73,10 +73,10 @@ public final class BluetoothCodecConfig implements Parcelable {
private final long mCodecSpecific4;
public BluetoothCodecConfig(int codecType, int codecPriority,
- int sampleRate, int bitsPerSample,
- int channelMode, long codecSpecific1,
- long codecSpecific2, long codecSpecific3,
- long codecSpecific4) {
+ int sampleRate, int bitsPerSample,
+ int channelMode, long codecSpecific1,
+ long codecSpecific2, long codecSpecific3,
+ long codecSpecific4) {
mCodecType = codecType;
mCodecPriority = codecPriority;
mSampleRate = sampleRate;
@@ -91,16 +91,16 @@ public final class BluetoothCodecConfig implements Parcelable {
@Override
public boolean equals(Object o) {
if (o instanceof BluetoothCodecConfig) {
- BluetoothCodecConfig other = (BluetoothCodecConfig)o;
- return (other.mCodecType == mCodecType &&
- other.mCodecPriority == mCodecPriority &&
- other.mSampleRate == mSampleRate &&
- other.mBitsPerSample == mBitsPerSample &&
- other.mChannelMode == mChannelMode &&
- other.mCodecSpecific1 == mCodecSpecific1 &&
- other.mCodecSpecific2 == mCodecSpecific2 &&
- other.mCodecSpecific3 == mCodecSpecific3 &&
- other.mCodecSpecific4 == mCodecSpecific4);
+ BluetoothCodecConfig other = (BluetoothCodecConfig) o;
+ return (other.mCodecType == mCodecType
+ && other.mCodecPriority == mCodecPriority
+ && other.mSampleRate == mSampleRate
+ && other.mBitsPerSample == mBitsPerSample
+ && other.mChannelMode == mChannelMode
+ && other.mCodecSpecific1 == mCodecSpecific1
+ && other.mCodecSpecific2 == mCodecSpecific2
+ && other.mCodecSpecific3 == mCodecSpecific3
+ && other.mCodecSpecific4 == mCodecSpecific4);
}
return false;
}
@@ -108,32 +108,30 @@ public final class BluetoothCodecConfig implements Parcelable {
@Override
public int hashCode() {
return Objects.hash(mCodecType, mCodecPriority, mSampleRate,
- mBitsPerSample, mChannelMode, mCodecSpecific1,
- mCodecSpecific2, mCodecSpecific3, mCodecSpecific4);
+ mBitsPerSample, mChannelMode, mCodecSpecific1,
+ mCodecSpecific2, mCodecSpecific3, mCodecSpecific4);
}
/**
* Checks whether the object contains valid codec configuration.
*
- * @return true if the object contains valid codec configuration,
- * otherwise false.
+ * @return true if the object contains valid codec configuration, otherwise false.
*/
public boolean isValid() {
- return (mSampleRate != SAMPLE_RATE_NONE) &&
- (mBitsPerSample != BITS_PER_SAMPLE_NONE) &&
- (mChannelMode != CHANNEL_MODE_NONE);
+ return (mSampleRate != SAMPLE_RATE_NONE)
+ && (mBitsPerSample != BITS_PER_SAMPLE_NONE)
+ && (mChannelMode != CHANNEL_MODE_NONE);
}
/**
* Adds capability string to an existing string.
*
- * @param prevStr the previous string with the capabilities. Can be
- * a null pointer.
+ * @param prevStr the previous string with the capabilities. Can be a null pointer.
* @param capStr the capability string to append to prevStr argument.
* @return the result string in the form "prevStr|capStr".
*/
private static String appendCapabilityToString(String prevStr,
- String capStr) {
+ String capStr) {
if (prevStr == null) {
return capStr;
}
@@ -190,48 +188,51 @@ public final class BluetoothCodecConfig implements Parcelable {
channelModeStr = appendCapabilityToString(channelModeStr, "STEREO");
}
- return "{codecName:" + getCodecName() +
- ",mCodecType:" + mCodecType +
- ",mCodecPriority:" + mCodecPriority +
- ",mSampleRate:" + String.format("0x%x", mSampleRate) +
- "(" + sampleRateStr + ")" +
- ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample) +
- "(" + bitsPerSampleStr + ")" +
- ",mChannelMode:" + String.format("0x%x", mChannelMode) +
- "(" + channelModeStr + ")" +
- ",mCodecSpecific1:" + mCodecSpecific1 +
- ",mCodecSpecific2:" + mCodecSpecific2 +
- ",mCodecSpecific3:" + mCodecSpecific3 +
- ",mCodecSpecific4:" + mCodecSpecific4 + "}";
+ return "{codecName:" + getCodecName()
+ + ",mCodecType:" + mCodecType
+ + ",mCodecPriority:" + mCodecPriority
+ + ",mSampleRate:" + String.format("0x%x", mSampleRate)
+ + "(" + sampleRateStr + ")"
+ + ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample)
+ + "(" + bitsPerSampleStr + ")"
+ + ",mChannelMode:" + String.format("0x%x", mChannelMode)
+ + "(" + channelModeStr + ")"
+ + ",mCodecSpecific1:" + mCodecSpecific1
+ + ",mCodecSpecific2:" + mCodecSpecific2
+ + ",mCodecSpecific3:" + mCodecSpecific3
+ + ",mCodecSpecific4:" + mCodecSpecific4 + "}";
}
+ @Override
public int describeContents() {
return 0;
}
public static final Parcelable.Creator Requires {@link android.Manifest.permission#BLUETOOTH} and
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} to receive.
*/
- // TODO: Change API to not broadcast RSSI if not available (incoming connection)
+ // TODO: Change API to not broadcast RSSI if not available (incoming connection)
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_FOUND =
"android.bluetooth.device.action.FOUND";
@@ -112,6 +111,7 @@ public final class BluetoothDevice implements Parcelable {
* found in the current discovery.
* Always contains the extra field {@link #EXTRA_DEVICE}.
* Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
+ *
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
@@ -208,6 +208,7 @@ public final class BluetoothDevice implements Parcelable {
* Always contains the extra fields {@link #EXTRA_DEVICE} and {@link
* #EXTRA_BATTERY_LEVEL}.
* Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
+ *
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
@@ -219,6 +220,7 @@ public final class BluetoothDevice implements Parcelable {
* intent. It contains the most recently retrieved battery level information
* ranging from 0% to 100% for a remote device, {@link #BATTERY_LEVEL_UNKNOWN}
* when the valid is unknown or there is an error
+ *
* @hide
*/
public static final String EXTRA_BATTERY_LEVEL =
@@ -226,6 +228,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* Used as the unknown value for {@link #EXTRA_BATTERY_LEVEL} and {@link #getBatteryLevel()}
+ *
* @hide
*/
public static final int BATTERY_LEVEL_UNKNOWN = -1;
@@ -300,6 +303,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* Used as an int extra field in {@link #ACTION_PAIRING_REQUEST}
* intents for unbond reason.
+ *
* @hide
*/
public static final String EXTRA_REASON = "android.bluetooth.device.extra.REASON";
@@ -368,6 +372,7 @@ public final class BluetoothDevice implements Parcelable {
* device.
* Always contains the extra field {@link #EXTRA_DEVICE}.
* Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
+ *
* @hide
*/
//TODO: is this actually useful?
@@ -405,26 +410,28 @@ public final class BluetoothDevice implements Parcelable {
/**
* Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intent.
+ *
* @hide
*/
public static final String EXTRA_ACCESS_REQUEST_TYPE =
- "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE";
+ "android.bluetooth.device.extra.ACCESS_REQUEST_TYPE";
- /**@hide*/
+ /** @hide */
public static final int REQUEST_TYPE_PROFILE_CONNECTION = 1;
- /**@hide*/
+ /** @hide */
public static final int REQUEST_TYPE_PHONEBOOK_ACCESS = 2;
- /**@hide*/
+ /** @hide */
public static final int REQUEST_TYPE_MESSAGE_ACCESS = 3;
- /**@hide*/
+ /** @hide */
public static final int REQUEST_TYPE_SIM_ACCESS = 4;
/**
* Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
* Contains package name to return reply intent to.
+ *
* @hide
*/
public static final String EXTRA_PACKAGE_NAME = "android.bluetooth.device.extra.PACKAGE_NAME";
@@ -432,34 +439,38 @@ public final class BluetoothDevice implements Parcelable {
/**
* Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REQUEST} intents,
* Contains class name to return reply intent to.
+ *
* @hide
*/
public static final String EXTRA_CLASS_NAME = "android.bluetooth.device.extra.CLASS_NAME";
/**
* Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intent.
+ *
* @hide
*/
public static final String EXTRA_CONNECTION_ACCESS_RESULT =
- "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT";
+ "android.bluetooth.device.extra.CONNECTION_ACCESS_RESULT";
- /**@hide*/
+ /** @hide */
public static final int CONNECTION_ACCESS_YES = 1;
- /**@hide*/
+ /** @hide */
public static final int CONNECTION_ACCESS_NO = 2;
/**
* Used as an extra field in {@link #ACTION_CONNECTION_ACCESS_REPLY} intents,
* Contains boolean to indicate if the allowed response is once-for-all so that
* next request will be granted without asking user again.
+ *
* @hide
*/
public static final String EXTRA_ALWAYS_ALLOWED =
- "android.bluetooth.device.extra.ALWAYS_ALLOWED";
+ "android.bluetooth.device.extra.ALWAYS_ALLOWED";
/**
* A bond attempt succeeded
+ *
* @hide
*/
public static final int BOND_SUCCESS = 0;
@@ -467,6 +478,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* A bond attempt failed because pins did not match, or remote device did
* not respond to pin request in time
+ *
* @hide
*/
public static final int UNBOND_REASON_AUTH_FAILED = 1;
@@ -474,36 +486,42 @@ public final class BluetoothDevice implements Parcelable {
/**
* A bond attempt failed because the other side explicitly rejected
* bonding
+ *
* @hide
*/
public static final int UNBOND_REASON_AUTH_REJECTED = 2;
/**
* A bond attempt failed because we canceled the bonding process
+ *
* @hide
*/
public static final int UNBOND_REASON_AUTH_CANCELED = 3;
/**
* A bond attempt failed because we could not contact the remote device
+ *
* @hide
*/
public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN = 4;
/**
* A bond attempt failed because a discovery is in progress
+ *
* @hide
*/
public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS = 5;
/**
* A bond attempt failed because of authentication timeout
+ *
* @hide
*/
public static final int UNBOND_REASON_AUTH_TIMEOUT = 6;
/**
* A bond attempt failed because of repeated attempts
+ *
* @hide
*/
public static final int UNBOND_REASON_REPEATED_ATTEMPTS = 7;
@@ -511,12 +529,14 @@ public final class BluetoothDevice implements Parcelable {
/**
* A bond attempt failed because we received an Authentication Cancel
* by remote end
+ *
* @hide
*/
public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED = 8;
/**
* An existing bond was explicitly revoked
+ *
* @hide
*/
public static final int UNBOND_REASON_REMOVED = 9;
@@ -529,6 +549,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* The user will be prompted to enter a passkey
+ *
* @hide
*/
public static final int PAIRING_VARIANT_PASSKEY = 1;
@@ -541,6 +562,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* The user will be prompted to accept or deny the incoming pairing request
+ *
* @hide
*/
public static final int PAIRING_VARIANT_CONSENT = 3;
@@ -548,6 +570,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* The user will be prompted to enter the passkey displayed on remote device
* This is used for Bluetooth 2.1 pairing.
+ *
* @hide
*/
public static final int PAIRING_VARIANT_DISPLAY_PASSKEY = 4;
@@ -555,12 +578,14 @@ public final class BluetoothDevice implements Parcelable {
/**
* The user will be prompted to enter the PIN displayed on remote device.
* This is used for Bluetooth 2.0 pairing.
+ *
* @hide
*/
public static final int PAIRING_VARIANT_DISPLAY_PIN = 5;
/**
* The user will be prompted to accept or deny the OOB pairing request
+ *
* @hide
*/
public static final int PAIRING_VARIANT_OOB_CONSENT = 6;
@@ -568,6 +593,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* The user will be prompted to enter a 16 digit pin or
* an app will enter a 16 digit pin for user.
+ *
* @hide
*/
public static final int PAIRING_VARIANT_PIN_16_DIGITS = 7;
@@ -581,7 +607,7 @@ public final class BluetoothDevice implements Parcelable {
/** @hide */
public static final String EXTRA_SDP_RECORD =
- "android.bluetooth.device.extra.SDP_RECORD";
+ "android.bluetooth.device.extra.SDP_RECORD";
/** @hide */
public static final String EXTRA_SDP_SEARCH_STATUS =
@@ -589,6 +615,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission},
* {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}.
+ *
* @hide
*/
public static final int ACCESS_UNKNOWN = 0;
@@ -596,6 +623,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission},
* {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}.
+ *
* @hide
*/
public static final int ACCESS_ALLOWED = 1;
@@ -603,13 +631,14 @@ public final class BluetoothDevice implements Parcelable {
/**
* For {@link #getPhonebookAccessPermission}, {@link #setPhonebookAccessPermission},
* {@link #getMessageAccessPermission} and {@link #setMessageAccessPermission}.
+ *
* @hide
*/
public static final int ACCESS_REJECTED = 2;
- /**
- * No preferrence of physical transport for GATT connections to remote dual-mode devices
- */
+ /**
+ * No preferrence of physical transport for GATT connections to remote dual-mode devices
+ */
public static final int TRANSPORT_AUTO = 0;
/**
@@ -676,7 +705,7 @@ public final class BluetoothDevice implements Parcelable {
/** @hide */
public static final String EXTRA_MAS_INSTANCE =
- "android.bluetooth.device.extra.MAS_INSTANCE";
+ "android.bluetooth.device.extra.MAS_INSTANCE";
/**
* Lazy initialization. Guaranteed final after first object constructed, or
@@ -687,17 +716,18 @@ public final class BluetoothDevice implements Parcelable {
private final String mAddress;
- /*package*/ static IBluetooth getService() {
+ /*package*/
+ static IBluetooth getService() {
synchronized (BluetoothDevice.class) {
if (sService == null) {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
- sService = adapter.getBluetoothService(mStateChangeCallback);
+ sService = adapter.getBluetoothService(sStateChangeCallback);
}
}
return sService;
}
- static IBluetoothManagerCallback mStateChangeCallback = new IBluetoothManagerCallback.Stub() {
+ static IBluetoothManagerCallback sStateChangeCallback = new IBluetoothManagerCallback.Stub() {
public void onBluetoothServiceUp(IBluetooth bluetoothService)
throws RemoteException {
@@ -709,21 +739,22 @@ public final class BluetoothDevice implements Parcelable {
}
public void onBluetoothServiceDown()
- throws RemoteException {
+ throws RemoteException {
synchronized (BluetoothDevice.class) {
sService = null;
}
}
- public void onBrEdrDown()
- {
+ public void onBrEdrDown() {
if (DBG) Log.d(TAG, "onBrEdrDown: reached BLE ON state");
}
};
+
/**
* Create a new BluetoothDevice
* Bluetooth MAC address must be upper case, such as "00:11:22:33:AA:BB",
* and is validated in this constructor.
+ *
* @param address valid Bluetooth MAC address
* @throws RuntimeException Bluetooth is not available on this platform
* @throws IllegalArgumentException address is invalid
@@ -741,7 +772,7 @@ public final class BluetoothDevice implements Parcelable {
@Override
public boolean equals(Object o) {
if (o instanceof BluetoothDevice) {
- return mAddress.equals(((BluetoothDevice)o).getAddress());
+ return mAddress.equals(((BluetoothDevice) o).getAddress());
}
return false;
}
@@ -757,6 +788,7 @@ public final class BluetoothDevice implements Parcelable {
* "00:11:22:AA:BB:CC". However, you should always use {@link #getAddress}
* if you explicitly require the Bluetooth hardware address in case the
* {@link #toString} representation changes in the future.
+ *
* @return string representation of this BluetoothDevice
*/
@Override
@@ -764,20 +796,23 @@ public final class BluetoothDevice implements Parcelable {
return mAddress;
}
+ @Override
public int describeContents() {
return 0;
}
public static final Parcelable.Creator For example, "00:11:22:AA:BB:CC".
+ *
* @return Bluetooth hardware address as string
*/
public String getAddress() {
@@ -809,16 +845,17 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return sService.getRemoteName(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return null;
}
/**
* Get the Bluetooth device type of the remote device.
*
- * @return the device type {@link #DEVICE_TYPE_CLASSIC}, {@link #DEVICE_TYPE_LE}
- * {@link #DEVICE_TYPE_DUAL}.
- * {@link #DEVICE_TYPE_UNKNOWN} if it's not available
+ * @return the device type {@link #DEVICE_TYPE_CLASSIC}, {@link #DEVICE_TYPE_LE} {@link
+ * #DEVICE_TYPE_DUAL}. {@link #DEVICE_TYPE_UNKNOWN} if it's not available
*/
@RequiresPermission(Manifest.permission.BLUETOOTH)
public int getType() {
@@ -828,7 +865,9 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return sService.getRemoteType(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return DEVICE_TYPE_UNKNOWN;
}
@@ -846,7 +885,9 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return sService.getRemoteAlias(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return null;
}
@@ -867,18 +908,20 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return sService.setRemoteAlias(this, alias);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
/**
* Get the Bluetooth alias of the remote device.
* If Alias is null, get the Bluetooth name instead.
- * @see #getAlias()
- * @see #getName()
*
* @return the Bluetooth alias, or null if no alias or there was a problem
* @hide
+ * @see #getAlias()
+ * @see #getName()
*/
public String getAliasName() {
String name = getAlias();
@@ -893,8 +936,8 @@ public final class BluetoothDevice implements Parcelable {
* Requires {@link android.Manifest.permission#BLUETOOTH}
*
* @return Battery level in percents from 0 to 100, or {@link #BATTERY_LEVEL_UNKNOWN} if
- * Bluetooth is disabled, or device is disconnected, or does not have any battery
- * reporting service, or return value is invalid
+ * Bluetooth is disabled, or device is disconnected, or does not have any battery reporting
+ * service, or return value is invalid
* @hide
*/
@RequiresPermission(Manifest.permission.BLUETOOTH)
@@ -905,7 +948,9 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return sService.getBatteryLevel(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return BATTERY_LEVEL_UNKNOWN;
}
@@ -926,11 +971,13 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- Log.i(TAG, "createBond() for device " + getAddress() +
- " called by pid: " + Process.myPid() +
- " tid: " + Process.myTid());
+ Log.i(TAG, "createBond() for device " + getAddress()
+ + " called by pid: " + Process.myPid()
+ + " tid: " + Process.myTid());
return sService.createBond(this, TRANSPORT_AUTO);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -955,16 +1002,17 @@ public final class BluetoothDevice implements Parcelable {
Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
return false;
}
- if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE)
- {
+ if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE) {
throw new IllegalArgumentException(transport + " is not a valid Bluetooth transport");
}
try {
- Log.i(TAG, "createBond() for device " + getAddress() +
- " called by pid: " + Process.myPid() +
- " tid: " + Process.myTid());
+ Log.i(TAG, "createBond() for device " + getAddress()
+ + " called by pid: " + Process.myPid()
+ + " tid: " + Process.myTid());
return sService.createBond(this, transport);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -984,13 +1032,14 @@ public final class BluetoothDevice implements Parcelable {
* @param transport - Transport to use
* @param oobData - Out Of Band data
* @return false on immediate error, true if bonding will begin
- *
* @hide
*/
public boolean createBondOutOfBand(int transport, OobData oobData) {
try {
return sService.createBondOutOfBand(this, transport, oobData);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -998,7 +1047,9 @@ public final class BluetoothDevice implements Parcelable {
public boolean isBondingInitiatedLocally() {
try {
return sService.isBondingInitiatedLocally(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -1012,16 +1063,15 @@ public final class BluetoothDevice implements Parcelable {
* @param hash Simple Secure pairing hash
* @param randomizer The random key obtained using OOB
* @return false on error; true otherwise
- *
* @hide
*/
public boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer) {
- //TODO(BT)
+ //TODO(BT)
/*
try {
return sService.setDeviceOutOfBandData(this, hash, randomizer);
} catch (RemoteException e) {Log.e(TAG, "", e);} */
- return false;
+ return false;
}
/**
@@ -1037,11 +1087,13 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- Log.i(TAG, "cancelBondProcess() for device " + getAddress() +
- " called by pid: " + Process.myPid() +
- " tid: " + Process.myTid());
+ Log.i(TAG, "cancelBondProcess() for device " + getAddress()
+ + " called by pid: " + Process.myPid()
+ + " tid: " + Process.myTid());
return sService.cancelBondProcess(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -1061,11 +1113,13 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
try {
- Log.i(TAG, "removeBond() for device " + getAddress() +
- " called by pid: " + Process.myPid() +
- " tid: " + Process.myTid());
+ Log.i(TAG, "removeBond() for device " + getAddress()
+ + " called by pid: " + Process.myPid()
+ + " tid: " + Process.myTid());
return sService.removeBond(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -1086,12 +1140,13 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return sService.getBondState(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- catch (NullPointerException npe) {
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ } catch (NullPointerException npe) {
// Handle case where bluetooth service proxy
// is already null.
- Log.e(TAG, "NullPointerException for getBondState() of device ("+
- getAddress()+")", npe);
+ Log.e(TAG, "NullPointerException for getBondState() of device ("
+ + getAddress() + ")", npe);
}
return BOND_NONE;
}
@@ -1154,7 +1209,9 @@ public final class BluetoothDevice implements Parcelable {
int classInt = sService.getRemoteClass(this);
if (classInt == BluetoothClass.ERROR) return null;
return new BluetoothClass(classInt);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return null;
}
@@ -1166,86 +1223,89 @@ public final class BluetoothDevice implements Parcelable {
* UUIDs are returned.
* Use {@link #fetchUuidsWithSdp} if fresh UUIDs are desired.
*
- * @return the supported features (UUIDs) of the remote device,
- * or null on error
+ * @return the supported features (UUIDs) of the remote device, or null on error
*/
@RequiresPermission(Manifest.permission.BLUETOOTH)
- public ParcelUuid[] getUuids() {
- if (sService == null || isBluetoothEnabled() == false) {
+ public ParcelUuid[] getUuids() {
+ if (sService == null || !isBluetoothEnabled()) {
Log.e(TAG, "BT not enabled. Cannot get remote device Uuids");
- return null;
- }
+ return null;
+ }
try {
return sService.getRemoteUuids(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return null;
}
- /**
- * Perform a service discovery on the remote device to get the UUIDs supported.
- *
- * This API is asynchronous and {@link #ACTION_UUID} intent is sent,
- * with the UUIDs supported by the remote end. If there is an error
- * in getting the SDP records or if the process takes a long time,
- * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently
- * present in the cache. Clients should use the {@link #getUuids} to get UUIDs
- * if service discovery is not to be performed.
- *
- * @return False if the sanity check fails, True if the process
- * of initiating an ACL connection to the remote device
- * was started.
- */
- @RequiresPermission(Manifest.permission.BLUETOOTH)
- public boolean fetchUuidsWithSdp() {
+ /**
+ * Perform a service discovery on the remote device to get the UUIDs supported.
+ *
+ * This API is asynchronous and {@link #ACTION_UUID} intent is sent,
+ * with the UUIDs supported by the remote end. If there is an error
+ * in getting the SDP records or if the process takes a long time,
+ * {@link #ACTION_UUID} intent is sent with the UUIDs that is currently
+ * present in the cache. Clients should use the {@link #getUuids} to get UUIDs
+ * if service discovery is not to be performed.
+ *
+ * @return False if the sanity check fails, True if the process of initiating an ACL connection
+ * to the remote device was started.
+ */
+ @RequiresPermission(Manifest.permission.BLUETOOTH)
+ public boolean fetchUuidsWithSdp() {
IBluetooth service = sService;
- if (service == null || isBluetoothEnabled() == false) {
+ if (service == null || !isBluetoothEnabled()) {
Log.e(TAG, "BT not enabled. Cannot fetchUuidsWithSdp");
return false;
}
try {
return service.fetchRemoteUuids(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- return false;
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
+ return false;
}
- /**
- * Perform a service discovery on the remote device to get the SDP records associated
- * with the specified UUID.
- *
- * This API is asynchronous and {@link #ACTION_SDP_RECORD} intent is sent,
- * with the SDP records found on the remote end. If there is an error
- * in getting the SDP records or if the process takes a long time,
- * {@link #ACTION_SDP_RECORD} intent is sent with an status value in
- * {@link #EXTRA_SDP_SEARCH_STATUS} different from 0.
- * Detailed status error codes can be found by members of the Bluetooth package in
- * the AbstractionLayer class.
- * Requires {@link android.Manifest.permission#BLUETOOTH}.
- * The SDP record data will be stored in the intent as {@link #EXTRA_SDP_RECORD}.
- * The object type will match one of the SdpXxxRecord types, depending on the UUID searched
- * for.
- *
- * @return False if the sanity check fails, True if the process
- * of initiating an ACL connection to the remote device
- * was started.
- */
- /** @hide */
- public boolean sdpSearch(ParcelUuid uuid) {
- if (sService == null) {
- Log.e(TAG, "BT not enabled. Cannot query remote device sdp records");
- return false;
- }
- try {
- return sService.sdpSearch(this,uuid);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
- return false;
- }
+ /**
+ * Perform a service discovery on the remote device to get the SDP records associated
+ * with the specified UUID.
+ *
+ * This API is asynchronous and {@link #ACTION_SDP_RECORD} intent is sent,
+ * with the SDP records found on the remote end. If there is an error
+ * in getting the SDP records or if the process takes a long time,
+ * {@link #ACTION_SDP_RECORD} intent is sent with an status value in
+ * {@link #EXTRA_SDP_SEARCH_STATUS} different from 0.
+ * Detailed status error codes can be found by members of the Bluetooth package in
+ * the AbstractionLayer class.
+ * Requires {@link android.Manifest.permission#BLUETOOTH}.
+ * The SDP record data will be stored in the intent as {@link #EXTRA_SDP_RECORD}.
+ * The object type will match one of the SdpXxxRecord types, depending on the UUID searched
+ * for.
+ *
+ * @return False if the sanity check fails, True if the process
+ * of initiating an ACL connection to the remote device
+ * was started.
+ */
+ /** @hide */
+ public boolean sdpSearch(ParcelUuid uuid) {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot query remote device sdp records");
+ return false;
+ }
+ try {
+ return sService.sdpSearch(this, uuid);
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
+ return false;
+ }
/**
* Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN}
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
*
- * @return true pin has been set
- * false for error
+ * @return true pin has been set false for error
*/
public boolean setPin(byte[] pin) {
if (sService == null) {
@@ -1254,7 +1314,9 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return sService.setPin(this, true, pin.length, pin);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -1271,8 +1333,7 @@ public final class BluetoothDevice implements Parcelable {
/**
* Confirm passkey for {@link #PAIRING_VARIANT_PASSKEY_CONFIRMATION} pairing.
*
- * @return true confirmation has been sent out
- * false for error
+ * @return true confirmation has been sent out false for error
*/
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public boolean setPairingConfirmation(boolean confirm) {
@@ -1282,7 +1343,9 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return sService.setPairingConfirmation(this, confirm);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -1293,7 +1356,7 @@ public final class BluetoothDevice implements Parcelable {
try {
return sService.setRemoteOutOfBandData(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}*/
- return false;
+ return false;
}
/** @hide */
@@ -1304,7 +1367,9 @@ public final class BluetoothDevice implements Parcelable {
}
try {
return sService.cancelBondProcess(this);
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return false;
}
@@ -1318,19 +1383,20 @@ public final class BluetoothDevice implements Parcelable {
return false;
}
- boolean isBluetoothEnabled() {
- boolean ret = false;
- BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
- if (adapter != null && adapter.isEnabled() == true) {
- ret = true;
- }
- return ret;
- }
+ boolean isBluetoothEnabled() {
+ boolean ret = false;
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+ if (adapter != null && adapter.isEnabled()) {
+ ret = true;
+ }
+ return ret;
+ }
/**
* Requires {@link android.Manifest.permission#BLUETOOTH}.
- * @return Whether the phonebook access is allowed to this device. Can be
- * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
+ *
+ * @return Whether the phonebook access is allowed to this device. Can be {@link
+ * #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
* @hide
*/
public int getPhonebookAccessPermission() {
@@ -1348,8 +1414,9 @@ public final class BluetoothDevice implements Parcelable {
/**
* Sets whether the phonebook access is allowed to this device.
* Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}.
- * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or
- * {@link #ACCESS_REJECTED}.
+ *
+ * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link
+ * #ACCESS_REJECTED}.
* @return Whether the value has been successfully set.
* @hide
*/
@@ -1367,8 +1434,9 @@ public final class BluetoothDevice implements Parcelable {
/**
* Requires {@link android.Manifest.permission#BLUETOOTH}.
- * @return Whether the message access is allowed to this device. Can be
- * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
+ *
+ * @return Whether the message access is allowed to this device. Can be {@link #ACCESS_UNKNOWN},
+ * {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
* @hide
*/
public int getMessageAccessPermission() {
@@ -1386,8 +1454,9 @@ public final class BluetoothDevice implements Parcelable {
/**
* Sets whether the message access is allowed to this device.
* Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}.
- * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or
- * {@link #ACCESS_REJECTED}.
+ *
+ * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link
+ * #ACCESS_REJECTED}.
* @return Whether the value has been successfully set.
* @hide
*/
@@ -1405,8 +1474,9 @@ public final class BluetoothDevice implements Parcelable {
/**
* Requires {@link android.Manifest.permission#BLUETOOTH}.
- * @return Whether the Sim access is allowed to this device. Can be
- * {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
+ *
+ * @return Whether the Sim access is allowed to this device. Can be {@link #ACCESS_UNKNOWN},
+ * {@link #ACCESS_ALLOWED} or {@link #ACCESS_REJECTED}.
* @hide
*/
public int getSimAccessPermission() {
@@ -1424,8 +1494,9 @@ public final class BluetoothDevice implements Parcelable {
/**
* Sets whether the Sim access is allowed to this device.
* Requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}.
- * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or
- * {@link #ACCESS_REJECTED}.
+ *
+ * @param value Can be {@link #ACCESS_UNKNOWN}, {@link #ACCESS_ALLOWED} or {@link
+ * #ACCESS_REJECTED}.
* @return Whether the value has been successfully set.
* @hide
*/
@@ -1462,12 +1533,12 @@ public final class BluetoothDevice implements Parcelable {
*
* @param channel RFCOMM channel to connect to
* @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions
* @hide
*/
public BluetoothSocket createRfcommSocket(int channel) throws IOException {
- if (isBluetoothEnabled() == false) {
+ if (!isBluetoothEnabled()) {
Log.e(TAG, "Bluetooth is not enabled");
throw new IOException();
}
@@ -1496,8 +1567,8 @@ public final class BluetoothDevice implements Parcelable {
*
* @param channel L2cap PSM/channel to connect to
* @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions
* @hide
*/
public BluetoothSocket createL2capSocket(int channel) throws IOException {
@@ -1517,8 +1588,8 @@ public final class BluetoothDevice implements Parcelable {
*
* @param channel L2cap PSM/channel to connect to
* @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions
* @hide
*/
public BluetoothSocket createInsecureL2capSocket(int channel) throws IOException {
@@ -1553,12 +1624,12 @@ public final class BluetoothDevice implements Parcelable {
*
* @param uuid service record uuid to lookup RFCOMM channel
* @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions
*/
@RequiresPermission(Manifest.permission.BLUETOOTH)
public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException {
- if (isBluetoothEnabled() == false) {
+ if (!isBluetoothEnabled()) {
Log.e(TAG, "Bluetooth is not enabled");
throw new IOException();
}
@@ -1591,12 +1662,12 @@ public final class BluetoothDevice implements Parcelable {
*
* @param uuid service record uuid to lookup RFCOMM channel
* @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions
*/
@RequiresPermission(Manifest.permission.BLUETOOTH)
public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException {
- if (isBluetoothEnabled() == false) {
+ if (!isBluetoothEnabled()) {
Log.e(TAG, "Bluetooth is not enabled");
throw new IOException();
}
@@ -1612,15 +1683,14 @@ public final class BluetoothDevice implements Parcelable {
* socket will not be encrypted.
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
*
- * @param port remote port
+ * @param port remote port
* @return An RFCOMM BluetoothSocket
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient permissions.
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * permissions.
* @hide
*/
public BluetoothSocket createInsecureRfcommSocket(int port) throws IOException {
-
- if (isBluetoothEnabled() == false) {
+ if (!isBluetoothEnabled()) {
Log.e(TAG, "Bluetooth is not enabled");
throw new IOException();
}
@@ -1634,13 +1704,12 @@ public final class BluetoothDevice implements Parcelable {
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
*
* @return a SCO BluetoothSocket
- * @throws IOException on error, for example Bluetooth not available, or
- * insufficient permissions.
+ * @throws IOException on error, for example Bluetooth not available, or insufficient
+ * permissions.
* @hide
*/
public BluetoothSocket createScoSocket() throws IOException {
-
- if (isBluetoothEnabled() == false) {
+ if (!isBluetoothEnabled()) {
Log.e(TAG, "Bluetooth is not enabled");
throw new IOException();
}
@@ -1651,9 +1720,9 @@ public final class BluetoothDevice implements Parcelable {
* Check that a pin is valid and convert to byte array.
*
* Bluetooth pin's are 1 to 16 bytes of UTF-8 characters.
+ *
* @param pin pin as java String
- * @return the pin code as a UTF-8 byte array, or null if it is an invalid
- * Bluetooth pin.
+ * @return the pin code as a UTF-8 byte array, or null if it is an invalid Bluetooth pin.
* @hide
*/
public static byte[] convertPinToBytes(String pin) {
@@ -1679,15 +1748,15 @@ public final class BluetoothDevice implements Parcelable {
* as any further GATT client operations.
* The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
* GATT client operations.
+ *
* @param callback GATT callback handler that will receive asynchronous callbacks.
- * @param autoConnect Whether to directly connect to the remote device (false)
- * or to automatically connect as soon as the remote
- * device becomes available (true).
+ * @param autoConnect Whether to directly connect to the remote device (false) or to
+ * automatically connect as soon as the remote device becomes available (true).
* @throws IllegalArgumentException if callback is null
*/
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
- BluetoothGattCallback callback) {
- return (connectGatt(context, autoConnect,callback, TRANSPORT_AUTO));
+ BluetoothGattCallback callback) {
+ return (connectGatt(context, autoConnect, callback, TRANSPORT_AUTO));
}
/**
@@ -1696,18 +1765,18 @@ public final class BluetoothDevice implements Parcelable {
* as any further GATT client operations.
* The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
* GATT client operations.
+ *
* @param callback GATT callback handler that will receive asynchronous callbacks.
- * @param autoConnect Whether to directly connect to the remote device (false)
- * or to automatically connect as soon as the remote
- * device becomes available (true).
- * @param transport preferred transport for GATT connections to remote dual-mode devices
- * {@link BluetoothDevice#TRANSPORT_AUTO} or
- * {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
+ * @param autoConnect Whether to directly connect to the remote device (false) or to
+ * automatically connect as soon as the remote device becomes available (true).
+ * @param transport preferred transport for GATT connections to remote dual-mode devices {@link
+ * BluetoothDevice#TRANSPORT_AUTO} or {@link BluetoothDevice#TRANSPORT_BREDR} or {@link
+ * BluetoothDevice#TRANSPORT_LE}
* @throws IllegalArgumentException if callback is null
*/
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
- BluetoothGattCallback callback, int transport) {
- return (connectGatt(context, autoConnect,callback, transport, PHY_LE_1M_MASK));
+ BluetoothGattCallback callback, int transport) {
+ return (connectGatt(context, autoConnect, callback, transport, PHY_LE_1M_MASK));
}
/**
@@ -1716,22 +1785,22 @@ public final class BluetoothDevice implements Parcelable {
* as any further GATT client operations.
* The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
* GATT client operations.
+ *
* @param callback GATT callback handler that will receive asynchronous callbacks.
- * @param autoConnect Whether to directly connect to the remote device (false)
- * or to automatically connect as soon as the remote
- * device becomes available (true).
- * @param transport preferred transport for GATT connections to remote dual-mode devices
- * {@link BluetoothDevice#TRANSPORT_AUTO} or
- * {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
- * @param phy preferred PHY for connections to remote LE device. Bitwise OR of any of
- * {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
- * and {@link BluetoothDevice#PHY_LE_CODED_MASK}. This option does not take effect
- * if {@code autoConnect} is set to true.
+ * @param autoConnect Whether to directly connect to the remote device (false) or to
+ * automatically connect as soon as the remote device becomes available (true).
+ * @param transport preferred transport for GATT connections to remote dual-mode devices {@link
+ * BluetoothDevice#TRANSPORT_AUTO} or {@link BluetoothDevice#TRANSPORT_BREDR} or {@link
+ * BluetoothDevice#TRANSPORT_LE}
+ * @param phy preferred PHY for connections to remote LE device. Bitwise OR of any of {@link
+ * BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK}, and {@link
+ * BluetoothDevice#PHY_LE_CODED_MASK}. This option does not take effect if {@code autoConnect}
+ * is set to true.
* @throws NullPointerException if callback is null
*/
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
- BluetoothGattCallback callback, int transport, int phy) {
- return connectGatt(context, autoConnect,callback, transport, phy, null);
+ BluetoothGattCallback callback, int transport, int phy) {
+ return connectGatt(context, autoConnect, callback, transport, phy, null);
}
/**
@@ -1740,24 +1809,24 @@ public final class BluetoothDevice implements Parcelable {
* as any further GATT client operations.
* The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
* GATT client operations.
+ *
* @param callback GATT callback handler that will receive asynchronous callbacks.
- * @param autoConnect Whether to directly connect to the remote device (false)
- * or to automatically connect as soon as the remote
- * device becomes available (true).
- * @param transport preferred transport for GATT connections to remote dual-mode devices
- * {@link BluetoothDevice#TRANSPORT_AUTO} or
- * {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
- * @param phy preferred PHY for connections to remote LE device. Bitwise OR of any of
- * {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
- * an d{@link BluetoothDevice#PHY_LE_CODED_MASK}. This option does not take effect
- * if {@code autoConnect} is set to true.
- * @param handler The handler to use for the callback. If {@code null}, callbacks will happen
- * on an un-specified background thread.
+ * @param autoConnect Whether to directly connect to the remote device (false) or to
+ * automatically connect as soon as the remote device becomes available (true).
+ * @param transport preferred transport for GATT connections to remote dual-mode devices {@link
+ * BluetoothDevice#TRANSPORT_AUTO} or {@link BluetoothDevice#TRANSPORT_BREDR} or {@link
+ * BluetoothDevice#TRANSPORT_LE}
+ * @param phy preferred PHY for connections to remote LE device. Bitwise OR of any of {@link
+ * BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK}, an d{@link
+ * BluetoothDevice#PHY_LE_CODED_MASK}. This option does not take effect if {@code autoConnect}
+ * is set to true.
+ * @param handler The handler to use for the callback. If {@code null}, callbacks will happen on
+ * an un-specified background thread.
* @throws NullPointerException if callback is null
*/
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
- BluetoothGattCallback callback, int transport, int phy,
- Handler handler) {
+ BluetoothGattCallback callback, int transport, int phy,
+ Handler handler) {
return connectGatt(context, autoConnect, callback, transport, false, phy, handler);
}
@@ -1767,31 +1836,32 @@ public final class BluetoothDevice implements Parcelable {
* as any further GATT client operations.
* The method returns a BluetoothGatt instance. You can use BluetoothGatt to conduct
* GATT client operations.
+ *
* @param callback GATT callback handler that will receive asynchronous callbacks.
- * @param autoConnect Whether to directly connect to the remote device (false)
- * or to automatically connect as soon as the remote
- * device becomes available (true).
- * @param transport preferred transport for GATT connections to remote dual-mode devices
- * {@link BluetoothDevice#TRANSPORT_AUTO} or
- * {@link BluetoothDevice#TRANSPORT_BREDR} or {@link BluetoothDevice#TRANSPORT_LE}
+ * @param autoConnect Whether to directly connect to the remote device (false) or to
+ * automatically connect as soon as the remote device becomes available (true).
+ * @param transport preferred transport for GATT connections to remote dual-mode devices {@link
+ * BluetoothDevice#TRANSPORT_AUTO} or {@link BluetoothDevice#TRANSPORT_BREDR} or {@link
+ * BluetoothDevice#TRANSPORT_LE}
* @param opportunistic Whether this GATT client is opportunistic. An opportunistic GATT client
- * does not hold a GATT connection. It automatically disconnects when no
- * other GATT connections are active for the remote device.
- * @param phy preferred PHY for connections to remote LE device. Bitwise OR of any of
- * {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
- * an d{@link BluetoothDevice#PHY_LE_CODED_MASK}. This option does not take effect
- * if {@code autoConnect} is set to true.
- * @param handler The handler to use for the callback. If {@code null}, callbacks will happen
- * on an un-specified background thread.
+ * does not hold a GATT connection. It automatically disconnects when no other GATT connections
+ * are active for the remote device.
+ * @param phy preferred PHY for connections to remote LE device. Bitwise OR of any of {@link
+ * BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK}, an d{@link
+ * BluetoothDevice#PHY_LE_CODED_MASK}. This option does not take effect if {@code autoConnect}
+ * is set to true.
+ * @param handler The handler to use for the callback. If {@code null}, callbacks will happen on
+ * an un-specified background thread.
* @return A BluetoothGatt instance. You can use BluetoothGatt to conduct GATT client
- * operations.
+ * operations.
* @hide
*/
public BluetoothGatt connectGatt(Context context, boolean autoConnect,
- BluetoothGattCallback callback, int transport,
- boolean opportunistic, int phy, Handler handler) {
- if (callback == null)
+ BluetoothGattCallback callback, int transport,
+ boolean opportunistic, int phy, Handler handler) {
+ if (callback == null) {
throw new NullPointerException("callback is null");
+ }
// TODO(Bluetooth) check whether platform support BLE
// Do the check here or in GattServer?
@@ -1806,7 +1876,9 @@ public final class BluetoothDevice implements Parcelable {
BluetoothGatt gatt = new BluetoothGatt(iGatt, this, transport, opportunistic, phy);
gatt.connect(autoConnect, callback, handler);
return gatt;
- } catch (RemoteException e) {Log.e(TAG, "", e);}
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
return null;
}
}
diff --git a/core/java/android/bluetooth/BluetoothDevicePicker.java b/core/java/android/bluetooth/BluetoothDevicePicker.java
index c794be2e2c9ef..09b0a80313f68 100644
--- a/core/java/android/bluetooth/BluetoothDevicePicker.java
+++ b/core/java/android/bluetooth/BluetoothDevicePicker.java
@@ -48,11 +48,11 @@ public interface BluetoothDevicePicker {
* This intent contains below extra data:
* - {@link #EXTRA_NEED_AUTH} (boolean): if need authentication
* - {@link #EXTRA_FILTER_TYPE} (int): what kinds of device should be
- * listed
+ * listed
* - {@link #EXTRA_LAUNCH_PACKAGE} (string): where(which package) this
- * intent come from
+ * intent come from
* - {@link #EXTRA_LAUNCH_CLASS} (string): where(which class) this intent
- * come from
+ * come from
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_LAUNCH =
@@ -64,8 +64,10 @@ public interface BluetoothDevicePicker {
public static final int FILTER_TYPE_AUDIO = 1;
/** Ask device picker to show BT devices that support Object Transfer */
public static final int FILTER_TYPE_TRANSFER = 2;
- /** Ask device picker to show BT devices that support
- * Personal Area Networking User (PANU) profile*/
+ /**
+ * Ask device picker to show BT devices that support
+ * Personal Area Networking User (PANU) profile
+ */
public static final int FILTER_TYPE_PANU = 3;
/** Ask device picker to show BT devices that support Network Access Point (NAP) profile */
public static final int FILTER_TYPE_NAP = 4;
diff --git a/core/java/android/bluetooth/BluetoothGatt.java b/core/java/android/bluetooth/BluetoothGatt.java
index 678159b71296b..759d772920baa 100644
--- a/core/java/android/bluetooth/BluetoothGatt.java
+++ b/core/java/android/bluetooth/BluetoothGatt.java
@@ -118,18 +118,21 @@ public final class BluetoothGatt implements BluetoothProfile {
/**
* No authentication required.
+ *
* @hide
*/
/*package*/ static final int AUTHENTICATION_NONE = 0;
/**
* Authentication requested; no man-in-the-middle protection required.
+ *
* @hide
*/
/*package*/ static final int AUTHENTICATION_NO_MITM = 1;
/**
* Authentication with man-in-the-middle protection requested.
+ *
* @hide
*/
/*package*/ static final int AUTHENTICATION_MITM = 2;
@@ -138,498 +141,536 @@ public final class BluetoothGatt implements BluetoothProfile {
* Bluetooth GATT callbacks. Overrides the default BluetoothGattCallback implementation.
*/
private final IBluetoothGattCallback mBluetoothGattCallback =
- new IBluetoothGattCallback.Stub() {
- /**
- * Application interface registered - app is ready to go
- * @hide
- */
- @Override
- public void onClientRegistered(int status, int clientIf) {
- if (DBG) Log.d(TAG, "onClientRegistered() - status=" + status
- + " clientIf=" + clientIf);
- if (VDBG) {
- synchronized(mStateLock) {
- if (mConnState != CONN_STATE_CONNECTING) {
- Log.e(TAG, "Bad connection state: " + mConnState);
+ new IBluetoothGattCallback.Stub() {
+ /**
+ * Application interface registered - app is ready to go
+ * @hide
+ */
+ @Override
+ public void onClientRegistered(int status, int clientIf) {
+ if (DBG) {
+ Log.d(TAG, "onClientRegistered() - status=" + status
+ + " clientIf=" + clientIf);
+ }
+ if (VDBG) {
+ synchronized (mStateLock) {
+ if (mConnState != CONN_STATE_CONNECTING) {
+ Log.e(TAG, "Bad connection state: " + mConnState);
+ }
}
}
+ mClientIf = clientIf;
+ if (status != GATT_SUCCESS) {
+ runOrQueueCallback(new Runnable() {
+ @Override
+ public void run() {
+ if (mCallback != null) {
+ mCallback.onConnectionStateChange(BluetoothGatt.this,
+ GATT_FAILURE,
+ BluetoothProfile.STATE_DISCONNECTED);
+ }
+ }
+ });
+
+ synchronized (mStateLock) {
+ mConnState = CONN_STATE_IDLE;
+ }
+ return;
+ }
+ try {
+ mService.clientConnect(mClientIf, mDevice.getAddress(),
+ !mAutoConnect, mTransport, mOpportunistic,
+ mPhy); // autoConnect is inverse of "isDirect"
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ }
}
- mClientIf = clientIf;
- if (status != GATT_SUCCESS) {
+
+ /**
+ * Phy update callback
+ * @hide
+ */
+ @Override
+ public void onPhyUpdate(String address, int txPhy, int rxPhy, int status) {
+ if (DBG) {
+ Log.d(TAG, "onPhyUpdate() - status=" + status
+ + " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
+ }
+ if (!address.equals(mDevice.getAddress())) {
+ return;
+ }
+
runOrQueueCallback(new Runnable() {
@Override
public void run() {
if (mCallback != null) {
- mCallback.onConnectionStateChange(BluetoothGatt.this, GATT_FAILURE,
- BluetoothProfile.STATE_DISCONNECTED);
+ mCallback.onPhyUpdate(BluetoothGatt.this, txPhy, rxPhy, status);
+ }
+ }
+ });
+ }
+
+ /**
+ * Phy read callback
+ * @hide
+ */
+ @Override
+ public void onPhyRead(String address, int txPhy, int rxPhy, int status) {
+ if (DBG) {
+ Log.d(TAG, "onPhyRead() - status=" + status
+ + " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
+ }
+ if (!address.equals(mDevice.getAddress())) {
+ return;
+ }
+
+ runOrQueueCallback(new Runnable() {
+ @Override
+ public void run() {
+ if (mCallback != null) {
+ mCallback.onPhyRead(BluetoothGatt.this, txPhy, rxPhy, status);
+ }
+ }
+ });
+ }
+
+ /**
+ * Client connection state changed
+ * @hide
+ */
+ @Override
+ public void onClientConnectionState(int status, int clientIf,
+ boolean connected, String address) {
+ if (DBG) {
+ Log.d(TAG, "onClientConnectionState() - status=" + status
+ + " clientIf=" + clientIf + " device=" + address);
+ }
+ if (!address.equals(mDevice.getAddress())) {
+ return;
+ }
+ int profileState = connected ? BluetoothProfile.STATE_CONNECTED :
+ BluetoothProfile.STATE_DISCONNECTED;
+
+ runOrQueueCallback(new Runnable() {
+ @Override
+ public void run() {
+ if (mCallback != null) {
+ mCallback.onConnectionStateChange(BluetoothGatt.this, status,
+ profileState);
}
}
});
- synchronized(mStateLock) {
- mConnState = CONN_STATE_IDLE;
- }
- return;
- }
- try {
- mService.clientConnect(mClientIf, mDevice.getAddress(),
- !mAutoConnect, mTransport, mOpportunistic, mPhy); // autoConnect is inverse of "isDirect"
- } catch (RemoteException e) {
- Log.e(TAG,"",e);
- }
- }
-
- /**
- * Phy update callback
- * @hide
- */
- @Override
- public void onPhyUpdate(String address, int txPhy, int rxPhy, int status) {
- if (DBG) Log.d(TAG, "onPhyUpdate() - status=" + status
- + " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
- if (!address.equals(mDevice.getAddress())) {
- return;
- }
-
- runOrQueueCallback(new Runnable() {
- @Override
- public void run() {
- if (mCallback != null) {
- mCallback.onPhyUpdate(BluetoothGatt.this, txPhy, rxPhy, status);
- }
- }
- });
- }
-
- /**
- * Phy read callback
- * @hide
- */
- @Override
- public void onPhyRead(String address, int txPhy, int rxPhy, int status) {
- if (DBG) Log.d(TAG, "onPhyRead() - status=" + status
- + " address=" + address + " txPhy=" + txPhy + " rxPhy=" + rxPhy);
- if (!address.equals(mDevice.getAddress())) {
- return;
- }
-
- runOrQueueCallback(new Runnable() {
- @Override
- public void run() {
- if (mCallback != null) {
- mCallback.onPhyRead(BluetoothGatt.this, txPhy, rxPhy, status);
- }
- }
- });
- }
-
- /**
- * Client connection state changed
- * @hide
- */
- @Override
- public void onClientConnectionState(int status, int clientIf,
- boolean connected, String address) {
- if (DBG) Log.d(TAG, "onClientConnectionState() - status=" + status
- + " clientIf=" + clientIf + " device=" + address);
- if (!address.equals(mDevice.getAddress())) {
- return;
- }
- int profileState = connected ? BluetoothProfile.STATE_CONNECTED :
- BluetoothProfile.STATE_DISCONNECTED;
-
- runOrQueueCallback(new Runnable() {
- @Override
- public void run() {
- if (mCallback != null) {
- mCallback.onConnectionStateChange(BluetoothGatt.this, status,
- profileState);
- }
- }
- });
-
- synchronized(mStateLock) {
- if (connected) {
- mConnState = CONN_STATE_CONNECTED;
- } else {
- mConnState = CONN_STATE_IDLE;
- }
- }
-
- synchronized(mDeviceBusy) {
- mDeviceBusy = false;
- }
- }
-
- /**
- * Remote search has been completed.
- * The internal object structure should now reflect the state
- * of the remote device database. Let the application know that
- * we are done at this point.
- * @hide
- */
- @Override
- public void onSearchComplete(String address, List Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param callback GATT callback handler that will receive asynchronous callbacks.
- * @return If true, the callback will be called to notify success or failure,
- * false on immediate error
+ * @return If true, the callback will be called to notify success or failure, false on immediate
+ * error
*/
private boolean registerApp(BluetoothGattCallback callback, Handler handler) {
if (DBG) Log.d(TAG, "registerApp()");
@@ -743,7 +790,7 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.registerClient(new ParcelUuid(uuid), mBluetoothGattCallback);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -762,7 +809,7 @@ public final class BluetoothGatt implements BluetoothProfile {
mService.unregisterClient(mClientIf);
mClientIf = 0;
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -784,15 +831,17 @@ public final class BluetoothGatt implements BluetoothProfile {
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param device Remote device to connect to
- * @param autoConnect Whether to directly connect to the remote device (false)
- * or to automatically connect as soon as the remote
- * device becomes available (true).
+ * @param autoConnect Whether to directly connect to the remote device (false) or to
+ * automatically connect as soon as the remote device becomes available (true).
* @return true, if the connection attempt was initiated successfully
*/
/*package*/ boolean connect(Boolean autoConnect, BluetoothGattCallback callback,
- Handler handler) {
- if (DBG) Log.d(TAG, "connect() - device: " + mDevice.getAddress() + ", auto: " + autoConnect);
- synchronized(mStateLock) {
+ Handler handler) {
+ if (DBG) {
+ Log.d(TAG,
+ "connect() - device: " + mDevice.getAddress() + ", auto: " + autoConnect);
+ }
+ synchronized (mStateLock) {
if (mConnState != CONN_STATE_IDLE) {
throw new IllegalStateException("Not idle");
}
@@ -802,7 +851,7 @@ public final class BluetoothGatt implements BluetoothProfile {
mAutoConnect = autoConnect;
if (!registerApp(callback, handler)) {
- synchronized(mStateLock) {
+ synchronized (mStateLock) {
mConnState = CONN_STATE_IDLE;
}
Log.e(TAG, "Failed to register callback");
@@ -826,7 +875,7 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.clientDisconnect(mClientIf, mDevice.getAddress());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -845,7 +894,7 @@ public final class BluetoothGatt implements BluetoothProfile {
mOpportunistic, mPhy); // autoConnect is inverse of "isDirect"
return true;
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
}
@@ -858,22 +907,22 @@ public final class BluetoothGatt implements BluetoothProfile {
* {@link BluetoothGattCallback#onPhyUpdate} will be triggered as a result of this call, even
* if no PHY change happens. It is also triggered when remote device updates the PHY.
*
- * @param txPhy preferred transmitter PHY. Bitwise OR of any of
- * {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
- * and {@link BluetoothDevice#PHY_LE_CODED_MASK}.
- * @param rxPhy preferred receiver PHY. Bitwise OR of any of
- * {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
- * and {@link BluetoothDevice#PHY_LE_CODED_MASK}.
+ * @param txPhy preferred transmitter PHY. Bitwise OR of any of {@link
+ * BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK}, and {@link
+ * BluetoothDevice#PHY_LE_CODED_MASK}.
+ * @param rxPhy preferred receiver PHY. Bitwise OR of any of {@link
+ * BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK}, and {@link
+ * BluetoothDevice#PHY_LE_CODED_MASK}.
* @param phyOptions preferred coding to use when transmitting on the LE Coded PHY. Can be one
- * of {@link BluetoothDevice#PHY_OPTION_NO_PREFERRED},
- * {@link BluetoothDevice#PHY_OPTION_S2} or {@link BluetoothDevice#PHY_OPTION_S8}
+ * of {@link BluetoothDevice#PHY_OPTION_NO_PREFERRED}, {@link BluetoothDevice#PHY_OPTION_S2} or
+ * {@link BluetoothDevice#PHY_OPTION_S8}
*/
public void setPreferredPhy(int txPhy, int rxPhy, int phyOptions) {
try {
mService.clientSetPreferredPhy(mClientIf, mDevice.getAddress(), txPhy, rxPhy,
- phyOptions);
+ phyOptions);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -885,7 +934,7 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.clientReadPhy(mClientIf, mDevice.getAddress());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -920,7 +969,7 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.discoverServices(mClientIf, mDevice.getAddress());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -960,8 +1009,8 @@ public final class BluetoothGatt implements BluetoothProfile {
*
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
- * @return List of services on the remote device. Returns an empty list
- * if service discovery has not yet been performed.
+ * @return List of services on the remote device. Returns an empty list if service discovery has
+ * not yet been performed.
*/
public List Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param uuid UUID of the requested service
- * @return BluetoothGattService if supported, or null if the requested
- * service is not offered by the remote device.
+ * @return BluetoothGattService if supported, or null if the requested service is not offered by
+ * the remote device.
*/
public BluetoothGattService getService(UUID uuid) {
for (BluetoothGattService service : mServices) {
- if (service.getDevice().equals(mDevice) &&
- service.getUuid().equals(uuid)) {
+ if (service.getDevice().equals(mDevice) && service.getUuid().equals(uuid)) {
return service;
}
}
@@ -1016,8 +1064,9 @@ public final class BluetoothGatt implements BluetoothProfile {
* @return true, if the read operation was initiated successfully
*/
public boolean readCharacteristic(BluetoothGattCharacteristic characteristic) {
- if ((characteristic.getProperties() &
- BluetoothGattCharacteristic.PROPERTY_READ) == 0) return false;
+ if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) {
+ return false;
+ }
if (VDBG) Log.d(TAG, "readCharacteristic() - uuid: " + characteristic.getUuid());
if (mService == null || mClientIf == 0) return false;
@@ -1028,16 +1077,16 @@ public final class BluetoothGatt implements BluetoothProfile {
BluetoothDevice device = service.getDevice();
if (device == null) return false;
- synchronized(mDeviceBusy) {
+ synchronized (mDeviceBusy) {
if (mDeviceBusy) return false;
mDeviceBusy = true;
}
try {
mService.readCharacteristic(mClientIf, device.getAddress(),
- characteristic.getInstanceId(), AUTHENTICATION_NONE);
+ characteristic.getInstanceId(), AUTHENTICATION_NONE);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
mDeviceBusy = false;
return false;
}
@@ -1062,16 +1111,16 @@ public final class BluetoothGatt implements BluetoothProfile {
if (VDBG) Log.d(TAG, "readUsingCharacteristicUuid() - uuid: " + uuid);
if (mService == null || mClientIf == 0) return false;
- synchronized(mDeviceBusy) {
+ synchronized (mDeviceBusy) {
if (mDeviceBusy) return false;
mDeviceBusy = true;
}
try {
mService.readUsingCharacteristicUuid(mClientIf, mDevice.getAddress(),
- new ParcelUuid(uuid), startHandle, endHandle, AUTHENTICATION_NONE);
+ new ParcelUuid(uuid), startHandle, endHandle, AUTHENTICATION_NONE);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
mDeviceBusy = false;
return false;
}
@@ -1094,8 +1143,10 @@ public final class BluetoothGatt implements BluetoothProfile {
*/
public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic) {
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0
- && (characteristic.getProperties() &
- BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) return false;
+ && (characteristic.getProperties()
+ & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0) {
+ return false;
+ }
if (VDBG) Log.d(TAG, "writeCharacteristic() - uuid: " + characteristic.getUuid());
if (mService == null || mClientIf == 0 || characteristic.getValue() == null) return false;
@@ -1106,17 +1157,17 @@ public final class BluetoothGatt implements BluetoothProfile {
BluetoothDevice device = service.getDevice();
if (device == null) return false;
- synchronized(mDeviceBusy) {
+ synchronized (mDeviceBusy) {
if (mDeviceBusy) return false;
mDeviceBusy = true;
}
try {
mService.writeCharacteristic(mClientIf, device.getAddress(),
- characteristic.getInstanceId(), characteristic.getWriteType(),
- AUTHENTICATION_NONE, characteristic.getValue());
+ characteristic.getInstanceId(), characteristic.getWriteType(),
+ AUTHENTICATION_NONE, characteristic.getValue());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
mDeviceBusy = false;
return false;
}
@@ -1149,16 +1200,16 @@ public final class BluetoothGatt implements BluetoothProfile {
BluetoothDevice device = service.getDevice();
if (device == null) return false;
- synchronized(mDeviceBusy) {
+ synchronized (mDeviceBusy) {
if (mDeviceBusy) return false;
mDeviceBusy = true;
}
try {
mService.readDescriptor(mClientIf, device.getAddress(),
- descriptor.getInstanceId(), AUTHENTICATION_NONE);
+ descriptor.getInstanceId(), AUTHENTICATION_NONE);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
mDeviceBusy = false;
return false;
}
@@ -1190,16 +1241,16 @@ public final class BluetoothGatt implements BluetoothProfile {
BluetoothDevice device = service.getDevice();
if (device == null) return false;
- synchronized(mDeviceBusy) {
+ synchronized (mDeviceBusy) {
if (mDeviceBusy) return false;
mDeviceBusy = true;
}
try {
mService.writeDescriptor(mClientIf, device.getAddress(), descriptor.getInstanceId(),
- AUTHENTICATION_NONE, descriptor.getValue());
+ AUTHENTICATION_NONE, descriptor.getValue());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
mDeviceBusy = false;
return false;
}
@@ -1234,7 +1285,7 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.beginReliableWrite(mClientIf, mDevice.getAddress());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -1258,7 +1309,7 @@ public final class BluetoothGatt implements BluetoothProfile {
if (VDBG) Log.d(TAG, "executeReliableWrite() - device: " + mDevice.getAddress());
if (mService == null || mClientIf == 0) return false;
- synchronized(mDeviceBusy) {
+ synchronized (mDeviceBusy) {
if (mDeviceBusy) return false;
mDeviceBusy = true;
}
@@ -1266,7 +1317,7 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.endReliableWrite(mClientIf, mDevice.getAddress(), true);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
mDeviceBusy = false;
return false;
}
@@ -1289,7 +1340,7 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.endReliableWrite(mClientIf, mDevice.getAddress(), false);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -1316,9 +1367,11 @@ public final class BluetoothGatt implements BluetoothProfile {
* @return true, if the requested notification status was set successfully
*/
public boolean setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
- boolean enable) {
- if (DBG) Log.d(TAG, "setCharacteristicNotification() - uuid: " + characteristic.getUuid()
- + " enable: " + enable);
+ boolean enable) {
+ if (DBG) {
+ Log.d(TAG, "setCharacteristicNotification() - uuid: " + characteristic.getUuid()
+ + " enable: " + enable);
+ }
if (mService == null || mClientIf == 0) return false;
BluetoothGattService service = characteristic.getService();
@@ -1329,9 +1382,9 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.registerForNotification(mClientIf, device.getAddress(),
- characteristic.getInstanceId(), enable);
+ characteristic.getInstanceId(), enable);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -1341,6 +1394,7 @@ public final class BluetoothGatt implements BluetoothProfile {
/**
* Clears the internal cache and forces a refresh of the services from the
* remote device.
+ *
* @hide
*/
public boolean refresh() {
@@ -1350,7 +1404,7 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.refreshDevice(mClientIf, mDevice.getAddress());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -1374,7 +1428,7 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.readRemoteRssi(mClientIf, mDevice.getAddress());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -1396,14 +1450,16 @@ public final class BluetoothGatt implements BluetoothProfile {
* @return true, if the new MTU value has been requested successfully
*/
public boolean requestMtu(int mtu) {
- if (DBG) Log.d(TAG, "configureMTU() - device: " + mDevice.getAddress()
- + " mtu: " + mtu);
+ if (DBG) {
+ Log.d(TAG, "configureMTU() - device: " + mDevice.getAddress()
+ + " mtu: " + mtu);
+ }
if (mService == null || mClientIf == 0) return false;
try {
mService.configureMTU(mClientIf, mDevice.getAddress(), mtu);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -1416,16 +1472,14 @@ public final class BluetoothGatt implements BluetoothProfile {
* This function will send a connection parameter update request to the
* remote device.
*
- * @param connectionPriority Request a specific connection priority. Must be one of
- * {@link BluetoothGatt#CONNECTION_PRIORITY_BALANCED},
- * {@link BluetoothGatt#CONNECTION_PRIORITY_HIGH}
- * or {@link BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER}.
- * @throws IllegalArgumentException If the parameters are outside of their
- * specified range.
+ * @param connectionPriority Request a specific connection priority. Must be one of {@link
+ * BluetoothGatt#CONNECTION_PRIORITY_BALANCED}, {@link BluetoothGatt#CONNECTION_PRIORITY_HIGH}
+ * or {@link BluetoothGatt#CONNECTION_PRIORITY_LOW_POWER}.
+ * @throws IllegalArgumentException If the parameters are outside of their specified range.
*/
public boolean requestConnectionPriority(int connectionPriority) {
- if (connectionPriority < CONNECTION_PRIORITY_BALANCED ||
- connectionPriority > CONNECTION_PRIORITY_LOW_POWER) {
+ if (connectionPriority < CONNECTION_PRIORITY_BALANCED
+ || connectionPriority > CONNECTION_PRIORITY_LOW_POWER) {
throw new IllegalArgumentException("connectionPriority not within valid range");
}
@@ -1435,7 +1489,7 @@ public final class BluetoothGatt implements BluetoothProfile {
try {
mService.connectionParameterUpdate(mClientIf, mDevice.getAddress(), connectionPriority);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -1461,8 +1515,8 @@ public final class BluetoothGatt implements BluetoothProfile {
*/
@Override
public List See {@link #getValue} for details.
*
- * @param formatType The format type used to interpret the characteristic
- * value.
+ * @param formatType The format type used to interpret the characteristic value.
* @param offset Offset at which the float value can be found.
- * @return Cached value of the characteristic at a given offset or null
- * if the requested offset exceeds the value size.
+ * @return Cached value of the characteristic at a given offset or null if the requested offset
+ * exceeds the value size.
*/
public Float getFloatValue(int formatType, int offset) {
if ((offset + getTypeLen(formatType)) > mValue.length) return null;
switch (formatType) {
case FORMAT_SFLOAT:
- return bytesToFloat(mValue[offset], mValue[offset+1]);
+ return bytesToFloat(mValue[offset], mValue[offset + 1]);
case FORMAT_FLOAT:
- return bytesToFloat(mValue[offset], mValue[offset+1],
- mValue[offset+2], mValue[offset+3]);
+ return bytesToFloat(mValue[offset], mValue[offset + 1],
+ mValue[offset + 2], mValue[offset + 3]);
}
return null;
@@ -572,7 +581,7 @@ public class BluetoothGattCharacteristic implements Parcelable {
public String getStringValue(int offset) {
if (mValue == null || offset > mValue.length) return null;
byte[] strBytes = new byte[mValue.length - offset];
- for (int i=0; i != (mValue.length-offset); ++i) strBytes[i] = mValue[offset+i];
+ for (int i = 0; i != (mValue.length - offset); ++i) strBytes[i] = mValue[offset + i];
return new String(strBytes);
}
@@ -585,8 +594,8 @@ public class BluetoothGattCharacteristic implements Parcelable {
* remote device.
*
* @param value New value for this characteristic
- * @return true if the locally stored value has been set, false if the
- * requested value could not be stored locally.
+ * @return true if the locally stored value has been set, false if the requested value could not
+ * be stored locally.
*/
public boolean setValue(byte[] value) {
mValue = value;
@@ -612,25 +621,25 @@ public class BluetoothGattCharacteristic implements Parcelable {
value = intToSignedBits(value, 8);
// Fall-through intended
case FORMAT_UINT8:
- mValue[offset] = (byte)(value & 0xFF);
+ mValue[offset] = (byte) (value & 0xFF);
break;
case FORMAT_SINT16:
value = intToSignedBits(value, 16);
// Fall-through intended
case FORMAT_UINT16:
- mValue[offset++] = (byte)(value & 0xFF);
- mValue[offset] = (byte)((value >> 8) & 0xFF);
+ mValue[offset++] = (byte) (value & 0xFF);
+ mValue[offset] = (byte) ((value >> 8) & 0xFF);
break;
case FORMAT_SINT32:
value = intToSignedBits(value, 32);
// Fall-through intended
case FORMAT_UINT32:
- mValue[offset++] = (byte)(value & 0xFF);
- mValue[offset++] = (byte)((value >> 8) & 0xFF);
- mValue[offset++] = (byte)((value >> 16) & 0xFF);
- mValue[offset] = (byte)((value >> 24) & 0xFF);
+ mValue[offset++] = (byte) (value & 0xFF);
+ mValue[offset++] = (byte) ((value >> 8) & 0xFF);
+ mValue[offset++] = (byte) ((value >> 16) & 0xFF);
+ mValue[offset] = (byte) ((value >> 24) & 0xFF);
break;
default:
@@ -644,7 +653,7 @@ public class BluetoothGattCharacteristic implements Parcelable {
* See {@link #setValue(byte[])} for details.
*
* @param mantissa Mantissa for this characteristic
- * @param exponent exponent value for this characteristic
+ * @param exponent exponent value for this characteristic
* @param formatType Float format type used to transform the value parameter
* @param offset Offset at which the value should be placed
* @return true if the locally stored value has been set
@@ -658,18 +667,18 @@ public class BluetoothGattCharacteristic implements Parcelable {
case FORMAT_SFLOAT:
mantissa = intToSignedBits(mantissa, 12);
exponent = intToSignedBits(exponent, 4);
- mValue[offset++] = (byte)(mantissa & 0xFF);
- mValue[offset] = (byte)((mantissa >> 8) & 0x0F);
- mValue[offset] += (byte)((exponent & 0x0F) << 4);
+ mValue[offset++] = (byte) (mantissa & 0xFF);
+ mValue[offset] = (byte) ((mantissa >> 8) & 0x0F);
+ mValue[offset] += (byte) ((exponent & 0x0F) << 4);
break;
case FORMAT_FLOAT:
mantissa = intToSignedBits(mantissa, 24);
exponent = intToSignedBits(exponent, 8);
- mValue[offset++] = (byte)(mantissa & 0xFF);
- mValue[offset++] = (byte)((mantissa >> 8) & 0xFF);
- mValue[offset++] = (byte)((mantissa >> 16) & 0xFF);
- mValue[offset] += (byte)(exponent & 0xFF);
+ mValue[offset++] = (byte) (mantissa & 0xFF);
+ mValue[offset++] = (byte) ((mantissa >> 8) & 0xFF);
+ mValue[offset++] = (byte) ((mantissa >> 16) & 0xFF);
+ mValue[offset] += (byte) (exponent & 0xFF);
break;
default:
@@ -717,7 +726,7 @@ public class BluetoothGattCharacteristic implements Parcelable {
*/
private int unsignedBytesToInt(byte b0, byte b1, byte b2, byte b3) {
return (unsignedByteToInt(b0) + (unsignedByteToInt(b1) << 8))
- + (unsignedByteToInt(b2) << 16) + (unsignedByteToInt(b3) << 24);
+ + (unsignedByteToInt(b2) << 16) + (unsignedByteToInt(b3) << 24);
}
/**
@@ -725,9 +734,9 @@ public class BluetoothGattCharacteristic implements Parcelable {
*/
private float bytesToFloat(byte b0, byte b1) {
int mantissa = unsignedToSigned(unsignedByteToInt(b0)
- + ((unsignedByteToInt(b1) & 0x0F) << 8), 12);
+ + ((unsignedByteToInt(b1) & 0x0F) << 8), 12);
int exponent = unsignedToSigned(unsignedByteToInt(b1) >> 4, 4);
- return (float)(mantissa * Math.pow(10, exponent));
+ return (float) (mantissa * Math.pow(10, exponent));
}
/**
@@ -735,9 +744,9 @@ public class BluetoothGattCharacteristic implements Parcelable {
*/
private float bytesToFloat(byte b0, byte b1, byte b2, byte b3) {
int mantissa = unsignedToSigned(unsignedByteToInt(b0)
- + (unsignedByteToInt(b1) << 8)
- + (unsignedByteToInt(b2) << 16), 24);
- return (float)(mantissa * Math.pow(10, b3));
+ + (unsignedByteToInt(b1) << 8)
+ + (unsignedByteToInt(b2) << 16), 24);
+ return (float) (mantissa * Math.pow(10, b3));
}
/**
@@ -745,8 +754,8 @@ public class BluetoothGattCharacteristic implements Parcelable {
* signed value.
*/
private int unsignedToSigned(int unsigned, int size) {
- if ((unsigned & (1 << size-1)) != 0) {
- unsigned = -1 * ((1 << size-1) - (unsigned & ((1 << size-1) - 1)));
+ if ((unsigned & (1 << size - 1)) != 0) {
+ unsigned = -1 * ((1 << size - 1) - (unsigned & ((1 << size - 1) - 1)));
}
return unsigned;
}
@@ -756,7 +765,7 @@ public class BluetoothGattCharacteristic implements Parcelable {
*/
private int intToSignedBits(int i, int size) {
if (i < 0) {
- i = (1 << size-1) + (i & ((1 << size-1) - 1));
+ i = (1 << size - 1) + (i & ((1 << size - 1) - 1));
}
return i;
}
diff --git a/core/java/android/bluetooth/BluetoothGattDescriptor.java b/core/java/android/bluetooth/BluetoothGattDescriptor.java
index 1a4fa487a4d78..217a5abf1fe56 100644
--- a/core/java/android/bluetooth/BluetoothGattDescriptor.java
+++ b/core/java/android/bluetooth/BluetoothGattDescriptor.java
@@ -17,8 +17,9 @@
package android.bluetooth;
import android.os.Parcel;
-import android.os.Parcelable;
import android.os.ParcelUuid;
+import android.os.Parcelable;
+
import java.util.UUID;
/**
@@ -89,30 +90,35 @@ public class BluetoothGattDescriptor implements Parcelable {
/**
* The UUID of this descriptor.
+ *
* @hide
*/
protected UUID mUuid;
/**
* Instance ID for this descriptor.
+ *
* @hide
*/
protected int mInstance;
/**
* Permissions for this descriptor
+ *
* @hide
*/
protected int mPermissions;
/**
* Back-reference to the characteristic this descriptor belongs to.
+ *
* @hide
*/
protected BluetoothGattCharacteristic mCharacteristic;
/**
* The value for this descriptor.
+ *
* @hide
*/
protected byte[] mValue;
@@ -137,7 +143,7 @@ public class BluetoothGattDescriptor implements Parcelable {
* @param permissions Permissions for this descriptor
*/
/*package*/ BluetoothGattDescriptor(BluetoothGattCharacteristic characteristic, UUID uuid,
- int instance, int permissions) {
+ int instance, int permissions) {
initDescriptor(characteristic, uuid, instance, permissions);
}
@@ -149,28 +155,27 @@ public class BluetoothGattDescriptor implements Parcelable {
}
private void initDescriptor(BluetoothGattCharacteristic characteristic, UUID uuid,
- int instance, int permissions) {
+ int instance, int permissions) {
mCharacteristic = characteristic;
mUuid = uuid;
mInstance = instance;
mPermissions = permissions;
}
- /**
- * @hide
- */
+ @Override
public int describeContents() {
return 0;
}
+ @Override
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(new ParcelUuid(mUuid), 0);
out.writeInt(mInstance);
out.writeInt(mPermissions);
}
- public static final Parcelable.Creator Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
- * @param callback GATT callback handler that will receive asynchronous
- * callbacks.
- * @return true, the callback will be called to notify success or failure,
- * false on immediate error
+ * @param callback GATT callback handler that will receive asynchronous callbacks.
+ * @return true, the callback will be called to notify success or failure, false on immediate
+ * error
*/
/*package*/ boolean registerCallback(BluetoothGattServerCallback callback) {
if (DBG) Log.d(TAG, "registerCallback()");
@@ -430,7 +451,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
UUID uuid = UUID.randomUUID();
if (DBG) Log.d(TAG, "registerCallback() - UUID=" + uuid);
- synchronized(mServerIfLock) {
+ synchronized (mServerIfLock) {
if (mCallback != null) {
Log.e(TAG, "App can register callback only once");
return false;
@@ -440,7 +461,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
try {
mService.registerServer(new ParcelUuid(uuid), mBluetoothGattServerCallback);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
mCallback = null;
return false;
}
@@ -473,19 +494,20 @@ public final class BluetoothGattServer implements BluetoothProfile {
mService.unregisterServer(mServerIf);
mServerIf = 0;
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
/**
* Returns a service by UUID, instance and type.
+ *
* @hide
*/
/*package*/ BluetoothGattService getService(UUID uuid, int instanceId, int type) {
- for(BluetoothGattService svc : mServices) {
- if (svc.getType() == type &&
- svc.getInstanceId() == instanceId &&
- svc.getUuid().equals(uuid)) {
+ for (BluetoothGattService svc : mServices) {
+ if (svc.getType() == type
+ && svc.getInstanceId() == instanceId
+ && svc.getUuid().equals(uuid)) {
return svc;
}
}
@@ -509,20 +531,22 @@ public final class BluetoothGattServer implements BluetoothProfile {
*
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
- * @param autoConnect Whether to directly connect to the remote device (false)
- * or to automatically connect as soon as the remote
- * device becomes available (true).
+ * @param autoConnect Whether to directly connect to the remote device (false) or to
+ * automatically connect as soon as the remote device becomes available (true).
* @return true, if the connection attempt was initiated successfully
*/
public boolean connect(BluetoothDevice device, boolean autoConnect) {
- if (DBG) Log.d(TAG, "connect() - device: " + device.getAddress() + ", auto: " + autoConnect);
+ if (DBG) {
+ Log.d(TAG,
+ "connect() - device: " + device.getAddress() + ", auto: " + autoConnect);
+ }
if (mService == null || mServerIf == 0) return false;
try {
- mService.serverConnect(mServerIf, device.getAddress(),
- autoConnect ? false : true,mTransport); // autoConnect is inverse of "isDirect"
+ // autoConnect is inverse of "isDirect"
+ mService.serverConnect(mServerIf, device.getAddress(), !autoConnect, mTransport);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -544,35 +568,34 @@ public final class BluetoothGattServer implements BluetoothProfile {
try {
mService.serverDisconnect(mServerIf, device.getAddress());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
/**
* Set the preferred connection PHY for this app. Please note that this is just a
* recommendation, whether the PHY change will happen depends on other applications peferences,
- * local and remote controller capabilities. Controller can override these settings.
- *
- * {@link BluetoothGattServerCallback#onPhyUpdate} will be triggered as a result of this call, even
- * if no PHY change happens. It is also triggered when remote device updates the PHY.
+ * local and remote controller capabilities. Controller can override these settings. {@link
+ * BluetoothGattServerCallback#onPhyUpdate} will be triggered as a result of this call, even if
+ * no PHY change happens. It is also triggered when remote device updates the PHY.
*
* @param device The remote device to send this response to
- * @param txPhy preferred transmitter PHY. Bitwise OR of any of
- * {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
- * and {@link BluetoothDevice#PHY_LE_CODED_MASK}.
- * @param rxPhy preferred receiver PHY. Bitwise OR of any of
- * {@link BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK},
- * and {@link BluetoothDevice#PHY_LE_CODED_MASK}.
+ * @param txPhy preferred transmitter PHY. Bitwise OR of any of {@link
+ * BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK}, and {@link
+ * BluetoothDevice#PHY_LE_CODED_MASK}.
+ * @param rxPhy preferred receiver PHY. Bitwise OR of any of {@link
+ * BluetoothDevice#PHY_LE_1M_MASK}, {@link BluetoothDevice#PHY_LE_2M_MASK}, and {@link
+ * BluetoothDevice#PHY_LE_CODED_MASK}.
* @param phyOptions preferred coding to use when transmitting on the LE Coded PHY. Can be one
- * of {@link BluetoothDevice#PHY_OPTION_NO_PREFERRED},
- * {@link BluetoothDevice#PHY_OPTION_S2} or {@link BluetoothDevice#PHY_OPTION_S8}
+ * of {@link BluetoothDevice#PHY_OPTION_NO_PREFERRED}, {@link BluetoothDevice#PHY_OPTION_S2} or
+ * {@link BluetoothDevice#PHY_OPTION_S8}
*/
public void setPreferredPhy(BluetoothDevice device, int txPhy, int rxPhy, int phyOptions) {
try {
mService.serverSetPreferredPhy(mServerIf, device.getAddress(), txPhy, rxPhy,
- phyOptions);
+ phyOptions);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -586,7 +609,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
try {
mService.serverReadPhy(mServerIf, device.getAddress());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -597,10 +620,10 @@ public final class BluetoothGattServer implements BluetoothProfile {
* is received by one of these callback methods:
*
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -612,15 +635,15 @@ public final class BluetoothGattServer implements BluetoothProfile {
* @param value The value of the attribute that was read/written (optional)
*/
public boolean sendResponse(BluetoothDevice device, int requestId,
- int status, int offset, byte[] value) {
+ int status, int offset, byte[] value) {
if (VDBG) Log.d(TAG, "sendResponse() - device: " + device.getAddress());
if (mService == null || mServerIf == 0) return false;
try {
mService.sendResponse(mServerIf, device.getAddress(), requestId,
- status, offset, value);
+ status, offset, value);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
return true;
@@ -639,13 +662,13 @@ public final class BluetoothGattServer implements BluetoothProfile {
*
* @param device The remote device to receive the notification/indication
* @param characteristic The local characteristic that has been updated
- * @param confirm true to request confirmation from the client (indication),
- * false to send a notification
- * @throws IllegalArgumentException
+ * @param confirm true to request confirmation from the client (indication), false to send a
+ * notification
* @return true, if the notification has been triggered successfully
+ * @throws IllegalArgumentException
*/
public boolean notifyCharacteristicChanged(BluetoothDevice device,
- BluetoothGattCharacteristic characteristic, boolean confirm) {
+ BluetoothGattCharacteristic characteristic, boolean confirm) {
if (VDBG) Log.d(TAG, "notifyCharacteristicChanged() - device: " + device.getAddress());
if (mService == null || mServerIf == 0) return false;
@@ -662,7 +685,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
characteristic.getInstanceId(), confirm,
characteristic.getValue());
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -680,8 +703,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
*
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
- * @param service Service to be added to the list of services provided
- * by this device.
+ * @param service Service to be added to the list of services provided by this device.
* @return true, if the service has been added successfully
*/
public boolean addService(BluetoothGattService service) {
@@ -693,7 +715,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
try {
mService.addService(mServerIf, service);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -713,14 +735,14 @@ public final class BluetoothGattServer implements BluetoothProfile {
if (mService == null || mServerIf == 0) return false;
BluetoothGattService intService = getService(service.getUuid(),
- service.getInstanceId(), service.getType());
+ service.getInstanceId(), service.getType());
if (intService == null) return false;
try {
mService.removeService(mServerIf, service.getInstanceId());
mServices.remove(intService);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
return false;
}
@@ -739,7 +761,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
mService.clearServices(mServerIf);
mServices.clear();
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -751,8 +773,7 @@ public final class BluetoothGattServer implements BluetoothProfile {
*
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
- * @return List of services. Returns an empty list
- * if no services have been added yet.
+ * @return List of services. Returns an empty list if no services have been added yet.
*/
public List Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param uuid UUID of the requested service
- * @return BluetoothGattService if supported, or null if the requested
- * service is not offered by this device.
+ * @return BluetoothGattService if supported, or null if the requested service is not offered by
+ * this device.
*/
public BluetoothGattService getService(UUID uuid) {
for (BluetoothGattService service : mServices) {
@@ -801,8 +822,8 @@ public final class BluetoothGattServer implements BluetoothProfile {
*/
@Override
public List This intent will have 3 extras:
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
* {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING},
@@ -69,7 +69,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_CONNECTION_STATE_CHANGED =
- "android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED";
+ "android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED";
/**
* Intent used to broadcast the change in the Audio Connection state of the
@@ -77,9 +77,9 @@ public final class BluetoothHeadset implements BluetoothProfile {
*
* This intent will have 3 extras:
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
* {@link #STATE_AUDIO_CONNECTED}, {@link #STATE_AUDIO_DISCONNECTED},
@@ -89,7 +89,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_AUDIO_STATE_CHANGED =
- "android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED";
+ "android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED";
/**
@@ -98,19 +98,19 @@ public final class BluetoothHeadset implements BluetoothProfile {
*
* This intent will have 4 extras and 1 category.
* The category is the Company ID of the vendor defining the
+ * The category is the Company ID of the vendor defining the
* vendor-specific command. {@link BluetoothAssignedNumbers}
*
* For example, for Plantronics specific events
@@ -118,9 +118,9 @@ public final class BluetoothHeadset implements BluetoothProfile {
*
* For example, an AT+XEVENT=foo,3 will get translated into
* Requires {@link android.Manifest.permission#BLUETOOTH} permission
* to receive.
@@ -191,7 +191,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
* The intent category to be used with {@link #ACTION_VENDOR_SPECIFIC_HEADSET_EVENT}
* for the companyId
*/
- public static final String VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY =
+ public static final String VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY =
"android.bluetooth.headset.intent.category.companyid";
/**
@@ -201,12 +201,14 @@ public final class BluetoothHeadset implements BluetoothProfile {
/**
* A vendor-specific AT command
+ *
* @hide
*/
public static final String VENDOR_SPECIFIC_HEADSET_EVENT_XAPL = "+XAPL";
/**
* A vendor-specific AT command
+ *
* @hide
*/
public static final String VENDOR_SPECIFIC_HEADSET_EVENT_IPHONEACCEV = "+IPHONEACCEV";
@@ -214,18 +216,21 @@ public final class BluetoothHeadset implements BluetoothProfile {
/**
* Battery level indicator associated with
* {@link #VENDOR_SPECIFIC_HEADSET_EVENT_IPHONEACCEV}
+ *
* @hide
*/
public static final int VENDOR_SPECIFIC_HEADSET_EVENT_IPHONEACCEV_BATTERY_LEVEL = 1;
/**
* A vendor-specific AT command
+ *
* @hide
*/
public static final String VENDOR_SPECIFIC_HEADSET_EVENT_XEVENT = "+XEVENT";
/**
* Battery level indicator associated with {@link #VENDOR_SPECIFIC_HEADSET_EVENT_XEVENT}
+ *
* @hide
*/
public static final String VENDOR_SPECIFIC_HEADSET_EVENT_XEVENT_BATTERY_LEVEL = "BATTERY";
@@ -258,17 +263,18 @@ public final class BluetoothHeadset implements BluetoothProfile {
*
* This intent will have 3 extras:
* {@link #EXTRA_HF_INDICATORS_IND_ID} is defined by Bluetooth SIG and each of the indicators
- * are given an assigned number. Below shows the assigned number of Indicator added so far
+ * are given an assigned number. Below shows the assigned number of Indicator added so far
* - Enhanced Safety - 1, Valid Values: 0 - Disabled, 1 - Enabled
* - Battery Level - 2, Valid Values: 0~100 - Remaining level of Battery
* Requires {@link android.Manifest.permission#BLUETOOTH} permission to receive.
+ *
* @hide
*/
public static final String ACTION_HF_INDICATORS_VALUE_CHANGED =
@@ -278,6 +284,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
* A int extra field in {@link #ACTION_HF_INDICATORS_VALUE_CHANGED}
* intents that contains the assigned number of the headset indicator as defined by
* Bluetooth SIG that is being sent. Value range is 0-65535 as defined in HFP 1.7
+ *
* @hide
*/
public static final String EXTRA_HF_INDICATORS_IND_ID =
@@ -286,6 +293,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
/**
* A int extra field in {@link #ACTION_HF_INDICATORS_VALUE_CHANGED}
* intents that contains the value of the Headset indicator that is being sent.
+ *
* @hide
*/
public static final String EXTRA_HF_INDICATORS_IND_VALUE =
@@ -301,27 +309,27 @@ public final class BluetoothHeadset implements BluetoothProfile {
private IBluetoothHeadset mService;
private BluetoothAdapter mAdapter;
- final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
+ private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
new IBluetoothStateChangeCallback.Stub() {
public void onBluetoothStateChange(boolean up) {
if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
if (!up) {
- if (VDBG) Log.d(TAG,"Unbinding service...");
+ if (VDBG) Log.d(TAG, "Unbinding service...");
doUnbind();
} else {
synchronized (mConnection) {
try {
if (mService == null) {
- if (VDBG) Log.d(TAG,"Binding service...");
+ if (VDBG) Log.d(TAG, "Binding service...");
doBind();
}
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
}
- };
+ };
/**
* Create a BluetoothHeadset proxy object.
@@ -336,7 +344,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
try {
mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -360,7 +368,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
mAdapter.getBluetoothManager().unbindBluetoothProfileService(
BluetoothProfile.HEADSET, mConnection);
} catch (RemoteException e) {
- Log.e(TAG,"Unable to unbind HeadsetService", e);
+ Log.e(TAG, "Unable to unbind HeadsetService", e);
}
}
}
@@ -380,7 +388,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
try {
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
} catch (Exception e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
mServiceListener = null;
@@ -405,14 +413,12 @@ public final class BluetoothHeadset implements BluetoothProfile {
* permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean connect(BluetoothDevice device) {
if (DBG) log("connect(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.connect(device);
} catch (RemoteException e) {
@@ -446,19 +452,17 @@ public final class BluetoothHeadset implements BluetoothProfile {
* permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean disconnect(BluetoothDevice device) {
if (DBG) log("disconnect(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.disconnect(device);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
- return false;
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ return false;
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -468,6 +472,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
/**
* {@inheritDoc}
*/
+ @Override
public List The device should already be paired.
- * Priority can be one of {@link #PRIORITY_ON} or
+ * Priority can be one of {@link #PRIORITY_ON} or
* {@link #PRIORITY_OFF},
*
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
@@ -534,11 +540,10 @@ public final class BluetoothHeadset implements BluetoothProfile {
*/
public boolean setPriority(BluetoothDevice device, int priority) {
if (DBG) log("setPriority(" + device + ", " + priority + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
- if (priority != BluetoothProfile.PRIORITY_OFF &&
- priority != BluetoothProfile.PRIORITY_ON) {
- return false;
+ if (mService != null && isEnabled() && isValidDevice(device)) {
+ if (priority != BluetoothProfile.PRIORITY_OFF
+ && priority != BluetoothProfile.PRIORITY_ON) {
+ return false;
}
try {
return mService.setPriority(device, priority);
@@ -566,8 +571,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
*/
public int getPriority(BluetoothDevice device) {
if (VDBG) log("getPriority(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getPriority(device);
} catch (RemoteException e) {
@@ -596,18 +600,16 @@ public final class BluetoothHeadset implements BluetoothProfile {
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param device Bluetooth headset
- * @return false if there is no headset connected of if the
- * connected headset doesn't support voice recognition
- * or on error, true otherwise
+ * @return false if there is no headset connected of if the connected headset doesn't support
+ * voice recognition or on error, true otherwise
*/
public boolean startVoiceRecognition(BluetoothDevice device) {
if (DBG) log("startVoiceRecognition()");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.startVoiceRecognition(device);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -621,17 +623,15 @@ public final class BluetoothHeadset implements BluetoothProfile {
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param device Bluetooth headset
- * @return false if there is no headset connected
- * or on error, true otherwise
+ * @return false if there is no headset connected or on error, true otherwise
*/
public boolean stopVoiceRecognition(BluetoothDevice device) {
if (DBG) log("stopVoiceRecognition()");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.stopVoiceRecognition(device);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -644,17 +644,15 @@ public final class BluetoothHeadset implements BluetoothProfile {
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param device Bluetooth headset
- * @return true if SCO is connected,
- * false otherwise or on error
+ * @return true if SCO is connected, false otherwise or on error
*/
public boolean isAudioConnected(BluetoothDevice device) {
if (VDBG) log("isAudioConnected()");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
- return mService.isAudioConnected(device);
+ return mService.isAudioConnected(device);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -671,18 +669,16 @@ public final class BluetoothHeadset implements BluetoothProfile {
* rule of thumb, each AT command prevents the CPU from sleeping for 500 ms
*
* @param device the bluetooth headset.
- * @return monotonically increasing battery usage hint, or a negative error
- * code on error
+ * @return monotonically increasing battery usage hint, or a negative error code on error
* @hide
*/
public int getBatteryUsageHint(BluetoothDevice device) {
if (VDBG) log("getBatteryUsageHint()");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getBatteryUsageHint(device);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -711,7 +707,9 @@ public final class BluetoothHeadset implements BluetoothProfile {
if (mService != null && isEnabled()) {
try {
return mService.acceptIncomingConnect(device);
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } 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()));
@@ -721,6 +719,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
/**
* Reject the incoming connection.
+ *
* @hide
*/
public boolean rejectIncomingConnect(BluetoothDevice device) {
@@ -728,7 +727,9 @@ public final class BluetoothHeadset implements BluetoothProfile {
if (mService != null) {
try {
return mService.rejectIncomingConnect(device);
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } 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()));
@@ -747,7 +748,9 @@ public final class BluetoothHeadset implements BluetoothProfile {
if (mService != null && !isDisabled()) {
try {
return mService.getAudioState(device);
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } 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()));
@@ -763,7 +766,6 @@ public final class BluetoothHeadset implements BluetoothProfile {
* Note: This is an internal function and shouldn't be exposed
*
* @param allowed {@code true} if the profile can reroute audio, {@code false} otherwise.
- *
* @hide
*/
public void setAudioRouteAllowed(boolean allowed) {
@@ -771,7 +773,9 @@ public final class BluetoothHeadset implements BluetoothProfile {
if (mService != null && isEnabled()) {
try {
mService.setAudioRouteAllowed(allowed);
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } 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()));
@@ -789,7 +793,9 @@ public final class BluetoothHeadset implements BluetoothProfile {
if (mService != null && isEnabled()) {
try {
return mService.getAudioRouteAllowed();
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } 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()));
@@ -800,9 +806,8 @@ public final class BluetoothHeadset implements BluetoothProfile {
/**
* Force SCO audio to be opened regardless any other restrictions
*
- * @param forced Whether or not SCO audio connection should be forced:
- * True to force SCO audio
- * False to use SCO audio in normal manner
+ * @param forced Whether or not SCO audio connection should be forced: True to force SCO audio
+ * False to use SCO audio in normal manner
* @hide
*/
public void setForceScoAudio(boolean forced) {
@@ -811,7 +816,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
try {
mService.setForceScoAudio(forced);
} catch (RemoteException e) {
- Log.e(TAG, e.toString());
+ Log.e(TAG, e.toString());
}
} else {
Log.w(TAG, "Proxy not attached to service");
@@ -824,17 +829,16 @@ public final class BluetoothHeadset implements BluetoothProfile {
*
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
- * @return true if SCO is connected,
- * false otherwise or on error
+ * @return true if SCO is connected, false otherwise or on error
* @hide
*/
public boolean isAudioOn() {
if (VDBG) log("isAudioOn()");
if (mService != null && isEnabled()) {
try {
- return mService.isAudioOn();
+ return mService.isAudioOn();
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -846,9 +850,8 @@ public final class BluetoothHeadset implements BluetoothProfile {
* Initiates a connection of headset audio.
* It setup SCO channel with remote connected headset device.
*
- * @return true if successful
- * false if there was some error such as
- * there is no connected headset
+ * @return true if successful false if there was some error such as there is no connected
+ * headset
* @hide
*/
public boolean connectAudio() {
@@ -869,9 +872,8 @@ public final class BluetoothHeadset implements BluetoothProfile {
* Initiates a disconnection of headset audio.
* It tears down the SCO channel from remote headset device.
*
- * @return true if successful
- * false if there was some error such as
- * there is no connected SCO channel
+ * @return true if successful false if there was some error such as there is no connected SCO
+ * channel
* @hide
*/
public boolean disconnectAudio() {
@@ -946,7 +948,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
* @hide
*/
public void phoneStateChanged(int numActive, int numHeld, int callState, String number,
- int type) {
+ int type) {
if (mService != null && isEnabled()) {
try {
mService.phoneStateChanged(numActive, numHeld, callState, number, type);
@@ -965,7 +967,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
* @hide
*/
public void clccResponse(int index, int direction, int status, int mode, boolean mpty,
- String number, int type) {
+ String number, int type) {
if (mService != null && isEnabled()) {
try {
mService.clccResponse(index, direction, status, mode, mpty, number, type);
@@ -981,9 +983,9 @@ public final class BluetoothHeadset implements BluetoothProfile {
/**
* Sends a vendor-specific unsolicited result code to the headset.
*
- * The actual string to be sent is The actual string to be sent is Currently only {@link #VENDOR_RESULT_CODE_COMMAND_ANDROID} is allowed as {@code command}.
*
@@ -993,7 +995,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
* @param command A vendor-specific command.
* @param arg The argument that will be attached to the command.
* @return {@code false} if there is no headset connected, or if the command is not an allowed
- * vendor-specific unsolicited result code, or on error. {@code true} otherwise.
+ * vendor-specific unsolicited result code, or on error. {@code true} otherwise.
* @throws IllegalArgumentException if {@code command} is {@code null}.
*/
public boolean sendVendorSpecificResultCode(BluetoothDevice device, String command,
@@ -1004,8 +1006,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
if (command == null) {
throw new IllegalArgumentException("command is null");
}
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.sendVendorSpecificResultCode(device, command, arg);
} catch (RemoteException e) {
@@ -1021,9 +1022,8 @@ public final class BluetoothHeadset implements BluetoothProfile {
/**
* enable WBS codec setting.
*
- * @return true if successful
- * false if there was some error such as
- * there is no connected headset
+ * @return true if successful false if there was some error such as there is no connected
+ * headset
* @hide
*/
public boolean enableWBS() {
@@ -1043,9 +1043,8 @@ public final class BluetoothHeadset implements BluetoothProfile {
/**
* disable WBS codec settting. It set NBS codec.
*
- * @return true if successful
- * false if there was some error such as
- * there is no connected headset
+ * @return true if successful false if there was some error such as there is no connected
+ * headset
* @hide
*/
public boolean disableWBS() {
@@ -1065,8 +1064,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
/**
* check if in-band ringing is supported for this platform.
*
- * @return true if in-band ringing is supported
- * false if in-band ringing is not supported
+ * @return true if in-band ringing is supported false if in-band ringing is not supported
* @hide
*/
public static boolean isInbandRingingSupported(Context context) {
@@ -1078,16 +1076,16 @@ public final class BluetoothHeadset implements BluetoothProfile {
* Send Headset the BIND response from AG to report change in the status of the
* HF indicators to the headset
*
- * @param ind_id Assigned Number of the indicator (defined by SIG)
- * @param ind_status
- * possible values- false-Indicator is disabled, no value changes shall be sent for this indicator
- * true-Indicator is enabled, value changes may be sent for this indicator
+ * @param indId Assigned Number of the indicator (defined by SIG)
+ * @param indStatus possible values- false-Indicator is disabled, no value changes shall be
+ * sent for this indicator true-Indicator is enabled, value changes may be sent for this
+ * indicator
* @hide
*/
- public void bindResponse(int ind_id, boolean ind_status) {
+ public void bindResponse(int indId, boolean indStatus) {
if (mService != null && isEnabled()) {
try {
- mService.bindResponse(ind_id, ind_status);
+ mService.bindResponse(indId, indStatus);
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
@@ -1097,8 +1095,8 @@ public final class BluetoothHeadset implements BluetoothProfile {
}
}
- private final IBluetoothProfileServiceConnection mConnection
- = new IBluetoothProfileServiceConnection.Stub() {
+ private final IBluetoothProfileServiceConnection mConnection =
+ new IBluetoothProfileServiceConnection.Stub() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) Log.d(TAG, "Proxy object connected");
@@ -1106,6 +1104,7 @@ public final class BluetoothHeadset implements BluetoothProfile {
mHandler.sendMessage(mHandler.obtainMessage(
MESSAGE_HEADSET_SERVICE_CONNECTED));
}
+
@Override
public void onServiceDisconnected(ComponentName className) {
if (DBG) Log.d(TAG, "Proxy object disconnected");
@@ -1116,20 +1115,20 @@ public final class BluetoothHeadset implements BluetoothProfile {
};
private boolean isEnabled() {
- if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
- return false;
+ if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
+ return false;
}
private boolean isDisabled() {
- if (mAdapter.getState() == BluetoothAdapter.STATE_OFF) return true;
- return false;
+ if (mAdapter.getState() == BluetoothAdapter.STATE_OFF) return true;
+ return false;
}
private boolean isValidDevice(BluetoothDevice device) {
- if (device == null) return false;
+ if (device == null) return false;
- if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
- return false;
+ if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
+ return false;
}
private static void log(String msg) {
diff --git a/core/java/android/bluetooth/BluetoothHeadsetClient.java b/core/java/android/bluetooth/BluetoothHeadsetClient.java
index 544b3b95db0a4..7ed2d2e98f7f2 100644
--- a/core/java/android/bluetooth/BluetoothHeadsetClient.java
+++ b/core/java/android/bluetooth/BluetoothHeadsetClient.java
@@ -28,7 +28,6 @@ import android.util.Log;
import java.util.ArrayList;
import java.util.List;
-import java.util.UUID;
/**
* Public API to control Hands Free Profile (HFP role only).
@@ -38,7 +37,7 @@ import java.util.UUID;
*
*
* @hide
- * */
+ */
public final class BluetoothHeadsetClient implements BluetoothProfile {
private static final String TAG = "BluetoothHeadsetClient";
private static final boolean DBG = true;
@@ -71,7 +70,7 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
* and not supported ones are not being sent at all. Possible values: Value: 0 - network unavailable,
- * 1 - network available Value: 0 - no roaming
- * 1 - active roaming Value:
- * 0 - voice recognition stopped,
- * 1 - voice recognition started. Value:
- * 0 - in band ring tone not supported, or
- * 1 - in band ring tone supported. Feature required for successful execution is being reported by:
- * {@link #EXTRA_AG_FEATURE_VOICE_RECOGNITION}.
- * This method invocation will fail silently when feature is not supported. Feature required for successful execution is being reported by: {@link
+ * #EXTRA_AG_FEATURE_VOICE_RECOGNITION}. This method invocation will fail silently when feature
+ * is not supported. Feature required for successful execution is being reported by:
- * {@link #EXTRA_AG_FEATURE_VOICE_RECOGNITION}.
- * This method invocation will fail silently when feature is not supported. Feature required for successful execution is being reported by: {@link
+ * #EXTRA_AG_FEATURE_VOICE_RECOGNITION}. This method invocation will fail silently when feature
+ * is not supported. Feature required for successful execution is being reported by:
- * {@link #EXTRA_AG_FEATURE_REJECT_CALL}.
- * This method invocation will fail silently when feature is not supported. Feature required for successful execution is being reported by: {@link
+ * #EXTRA_AG_FEATURE_REJECT_CALL}. This method invocation will fail silently when feature is not
+ * supported. Feature required for successful execution is being reported by:
- * {@link #EXTRA_AG_FEATURE_ECC}.
- * This method invocation will fail silently when feature is not supported. Feature required for successful execution is being reported by: {@link
+ * #EXTRA_AG_FEATURE_ECC}. This method invocation will fail silently when feature is not
+ * supported. Feature required for successful execution is being reported by:
- * {@link #EXTRA_AG_FEATURE_ECC}.
- * This method invocation will fail silently when feature is not supported. Feature required for successful execution is being reported by: {@link
+ * #EXTRA_AG_FEATURE_ECC}. This method invocation will fail silently when feature is not
+ * supported. Feature required for successful execution is being reported by:
- * {@link #EXTRA_AG_FEATURE_MERGE_AND_DETACH}.
- * This method invocation will fail silently when feature is not supported. Feature required for successful execution is being reported by: {@link
+ * #EXTRA_AG_FEATURE_MERGE_AND_DETACH}. This method invocation will fail silently when feature
+ * is not supported. Feature required for successful execution is being reported by:
- * {@link #EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT}.
- * This method invocation will fail silently when feature is not supported. Feature required for successful execution is being reported by: {@link
+ * #EXTRA_AG_FEATURE_ATTACH_NUMBER_TO_VT}. This method invocation will fail silently when
+ * feature is not supported. Note: This is an internal function and shouldn't be exposed Note: This is an internal function and shouldn't be exposed Note: This is an internal function and shouldn't be exposed How to connect to a health device which is acting in the source role.
- * Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param name The friendly name associated with the application or configuration.
- * @param dataType The dataType of the Source role of Health Profile to which
- * the sink wants to connect to.
- * @param callback A callback to indicate success or failure of the registration and
- * all operations done on this application configuration.
+ * @param dataType The dataType of the Source role of Health Profile to which the sink wants to
+ * connect to.
+ * @param callback A callback to indicate success or failure of the registration and all
+ * operations done on this application configuration.
* @return If true, callback will be called.
*/
public boolean registerSinkAppConfiguration(String name, int dataType,
@@ -161,9 +160,8 @@ public final class BluetoothHealth implements BluetoothProfile {
*
* @param name The friendly name associated with the application or configuration.
* @param dataType The dataType of the Source role of Health Profile.
- * @param channelType The channel type. Will be one of
- * {@link #CHANNEL_TYPE_RELIABLE} or
- * {@link #CHANNEL_TYPE_STREAMING}
+ * @param channelType The channel type. Will be one of {@link #CHANNEL_TYPE_RELIABLE} or {@link
+ * #CHANNEL_TYPE_STREAMING}
* @param callback - A callback to indicate success or failure.
* @return If true, callback will be called.
* @hide
@@ -197,7 +195,7 @@ public final class BluetoothHealth implements BluetoothProfile {
*
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
- * @param config The health app configuration
+ * @param config The health app configuration
* @return Success or failure.
*/
public boolean unregisterAppConfiguration(BluetoothHealthAppConfiguration config) {
@@ -224,14 +222,13 @@ public final class BluetoothHealth implements BluetoothProfile {
* Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param device The remote Bluetooth device.
- * @param config The application configuration which has been registered using
- * {@link #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
+ * @param config The application configuration which has been registered using {@link
+ * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
* @return If true, the callback associated with the application config will be called.
*/
public boolean connectChannelToSource(BluetoothDevice device,
BluetoothHealthAppConfiguration config) {
- if (mService != null && isEnabled() && isValidDevice(device) &&
- config != null) {
+ if (mService != null && isEnabled() && isValidDevice(device) && config != null) {
try {
return mService.connectChannelToSource(device, config);
} catch (RemoteException e) {
@@ -249,18 +246,17 @@ public final class BluetoothHealth implements BluetoothProfile {
* This is an asynchronous call. If this function returns true, the callback
* associated with the application configuration will be called.
*
- * Requires {@link android.Manifest.permission#BLUETOOTH} permission.
+ * Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param device The remote Bluetooth device.
- * @param config The application configuration which has been registered using
- * {@link #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
+ * @param config The application configuration which has been registered using {@link
+ * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
* @return If true, the callback associated with the application config will be called.
* @hide
*/
public boolean connectChannelToSink(BluetoothDevice device,
BluetoothHealthAppConfiguration config, int channelType) {
- if (mService != null && isEnabled() && isValidDevice(device) &&
- config != null) {
+ if (mService != null && isEnabled() && isValidDevice(device) && config != null) {
try {
return mService.connectChannelToSink(device, config, channelType);
} catch (RemoteException e) {
@@ -278,18 +274,17 @@ public final class BluetoothHealth implements BluetoothProfile {
* This is an asynchronous call. If this function returns true, the callback
* associated with the application configuration will be called.
*
- * Requires {@link android.Manifest.permission#BLUETOOTH} permission.
+ * Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param device The remote Bluetooth device.
- * @param config The application configuration which has been registered using
- * {@link #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
+ * @param config The application configuration which has been registered using {@link
+ * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
* @param channelId The channel id associated with the channel
* @return If true, the callback associated with the application config will be called.
*/
public boolean disconnectChannel(BluetoothDevice device,
BluetoothHealthAppConfiguration config, int channelId) {
- if (mService != null && isEnabled() && isValidDevice(device) &&
- config != null) {
+ if (mService != null && isEnabled() && isValidDevice(device) && config != null) {
try {
return mService.disconnectChannel(device, config, channelId);
} catch (RemoteException e) {
@@ -317,8 +312,7 @@ public final class BluetoothHealth implements BluetoothProfile {
*/
public ParcelFileDescriptor getMainChannelFd(BluetoothDevice device,
BluetoothHealthAppConfiguration config) {
- if (mService != null && isEnabled() && isValidDevice(device) &&
- config != null) {
+ if (mService != null && isEnabled() && isValidDevice(device) && config != null) {
try {
return mService.getMainChannelFd(device, config);
} catch (RemoteException e) {
@@ -342,9 +336,8 @@ public final class BluetoothHealth implements BluetoothProfile {
* local adapter.
*
* @param device Remote bluetooth device.
- * @return State of the profile connection. One of
- * {@link #STATE_CONNECTED}, {@link #STATE_CONNECTING},
- * {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
+ * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
+ * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
*/
@Override
public int getConnectionState(BluetoothDevice device) {
@@ -372,6 +365,7 @@ public final class BluetoothHealth implements BluetoothProfile {
* state of the local Bluetooth adapter for this profile. This can be used
* by applications like status bar which would just like to know the state of the
* local adapter.
+ *
* @return List of devices. The list will be empty on error.
*/
@Override
@@ -401,9 +395,8 @@ public final class BluetoothHealth implements BluetoothProfile {
* by applications like status bar which would just like to know the state of the
* local adapter.
*
- * @param states Array of states. States can be one of
- * {@link #STATE_CONNECTED}, {@link #STATE_CONNECTING},
- * {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
+ * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
+ * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
* @return List of devices. The list will be empty on error.
*/
@Override
@@ -429,25 +422,25 @@ public final class BluetoothHealth implements BluetoothProfile {
@Override
public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config,
- int status) {
- mCallback.onHealthAppConfigurationStatusChange(config, status);
+ int status) {
+ mCallback.onHealthAppConfigurationStatusChange(config, status);
}
@Override
public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config,
- BluetoothDevice device, int prevState, int newState,
- ParcelFileDescriptor fd, int channelId) {
+ BluetoothDevice device, int prevState, int newState,
+ ParcelFileDescriptor fd, int channelId) {
mCallback.onHealthChannelStateChange(config, device, prevState, newState, fd,
- channelId);
+ channelId);
}
}
- /** Health Channel Connection State - Disconnected */
- public static final int STATE_CHANNEL_DISCONNECTED = 0;
+ /** Health Channel Connection State - Disconnected */
+ public static final int STATE_CHANNEL_DISCONNECTED = 0;
/** Health Channel Connection State - Connecting */
- public static final int STATE_CHANNEL_CONNECTING = 1;
+ public static final int STATE_CHANNEL_CONNECTING = 1;
/** Health Channel Connection State - Connected */
- public static final int STATE_CHANNEL_CONNECTED = 2;
+ public static final int STATE_CHANNEL_CONNECTED = 2;
/** Health Channel Connection State - Disconnecting */
public static final int STATE_CHANNEL_DISCONNECTING = 3;
@@ -477,7 +470,7 @@ public final class BluetoothHealth implements BluetoothProfile {
try {
mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -503,7 +496,7 @@ public final class BluetoothHealth implements BluetoothProfile {
try {
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
} catch (Exception e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -513,7 +506,7 @@ public final class BluetoothHealth implements BluetoothProfile {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
@@ -529,6 +522,7 @@ public final class BluetoothHealth implements BluetoothProfile {
mServiceListener.onServiceConnected(BluetoothProfile.HEALTH, BluetoothHealth.this);
}
}
+
public void onServiceDisconnected(ComponentName className) {
if (DBG) Log.d(TAG, "Proxy object disconnected");
mService = null;
@@ -555,10 +549,10 @@ public final class BluetoothHealth implements BluetoothProfile {
private boolean checkAppParam(String name, int role, int channelType,
BluetoothHealthCallback callback) {
- if (name == null || (role != SOURCE_ROLE && role != SINK_ROLE) ||
- (channelType != CHANNEL_TYPE_RELIABLE &&
- channelType != CHANNEL_TYPE_STREAMING &&
- channelType != CHANNEL_TYPE_ANY) || callback == null) {
+ if (name == null || (role != SOURCE_ROLE && role != SINK_ROLE)
+ || (channelType != CHANNEL_TYPE_RELIABLE && channelType != CHANNEL_TYPE_STREAMING
+ && channelType != CHANNEL_TYPE_ANY)
+ || callback == null) {
return false;
}
if (role == SOURCE_ROLE && channelType == CHANNEL_TYPE_ANY) return false;
diff --git a/core/java/android/bluetooth/BluetoothHealthAppConfiguration.java b/core/java/android/bluetooth/BluetoothHealthAppConfiguration.java
index 1717a1e36e1f6..7c9db6f7213c6 100644
--- a/core/java/android/bluetooth/BluetoothHealthAppConfiguration.java
+++ b/core/java/android/bluetooth/BluetoothHealthAppConfiguration.java
@@ -25,7 +25,6 @@ import android.os.Parcelable;
* the {@link BluetoothHealth} class. This class represents an application configuration
* that the Bluetooth Health third party application will register to communicate with the
* remote Bluetooth health device.
- *
*/
public final class BluetoothHealthAppConfiguration implements Parcelable {
private final String mName;
@@ -52,12 +51,11 @@ public final class BluetoothHealthAppConfiguration implements Parcelable {
*
* @param name Friendly name associated with the application configuration
* @param dataType Data Type of the remote Bluetooth Health device
- * @param role {@link BluetoothHealth#SOURCE_ROLE} or
- * {@link BluetoothHealth#SINK_ROLE}
+ * @param role {@link BluetoothHealth#SOURCE_ROLE} or {@link BluetoothHealth#SINK_ROLE}
* @hide
*/
BluetoothHealthAppConfiguration(String name, int dataType, int role, int
- channelType) {
+ channelType) {
mName = name;
mDataType = dataType;
mRole = role;
@@ -71,10 +69,8 @@ public final class BluetoothHealthAppConfiguration implements Parcelable {
if (mName == null) return false;
- return mName.equals(config.getName()) &&
- mDataType == config.getDataType() &&
- mRole == config.getRole() &&
- mChannelType == config.getChannelType();
+ return mName.equals(config.getName()) && mDataType == config.getDataType()
+ && mRole == config.getRole() && mChannelType == config.getChannelType();
}
return false;
}
@@ -91,11 +87,11 @@ public final class BluetoothHealthAppConfiguration implements Parcelable {
@Override
public String toString() {
- return "BluetoothHealthAppConfiguration [mName = " + mName +
- ",mDataType = " + mDataType + ", mRole = " + mRole + ",mChannelType = " +
- mChannelType + "]";
+ return "BluetoothHealthAppConfiguration [mName = " + mName + ",mDataType = " + mDataType
+ + ", mRole = " + mRole + ",mChannelType = " + mChannelType + "]";
}
+ @Override
public int describeContents() {
return 0;
}
@@ -121,8 +117,7 @@ public final class BluetoothHealthAppConfiguration implements Parcelable {
/**
* Return the role associated with this application configuration.
*
- * @return One of {@link BluetoothHealth#SOURCE_ROLE} or
- * {@link BluetoothHealth#SINK_ROLE}
+ * @return One of {@link BluetoothHealth#SOURCE_ROLE} or {@link BluetoothHealth#SINK_ROLE}
*/
public int getRole() {
return mRole;
@@ -131,9 +126,8 @@ public final class BluetoothHealthAppConfiguration implements Parcelable {
/**
* Return the channel type associated with this application configuration.
*
- * @return One of {@link BluetoothHealth#CHANNEL_TYPE_RELIABLE} or
- * {@link BluetoothHealth#CHANNEL_TYPE_STREAMING} or
- * {@link BluetoothHealth#CHANNEL_TYPE_ANY}.
+ * @return One of {@link BluetoothHealth#CHANNEL_TYPE_RELIABLE} or {@link
+ * BluetoothHealth#CHANNEL_TYPE_STREAMING} or {@link BluetoothHealth#CHANNEL_TYPE_ANY}.
* @hide
*/
public int getChannelType() {
@@ -141,23 +135,24 @@ public final class BluetoothHealthAppConfiguration implements Parcelable {
}
public static final Parcelable.Creator This callback is called on the binder thread (not on the UI thread)
*
* @param config Bluetooth Health app configuration
- * @param status Success or failure of the registration or unregistration
- * calls. Can be one of
- * {@link BluetoothHealth#APP_CONFIG_REGISTRATION_SUCCESS} or
- * {@link BluetoothHealth#APP_CONFIG_REGISTRATION_FAILURE} or
- * {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_SUCCESS} or
- * {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_FAILURE}
+ * @param status Success or failure of the registration or unregistration calls. Can be one of
+ * {@link BluetoothHealth#APP_CONFIG_REGISTRATION_SUCCESS} or {@link
+ * BluetoothHealth#APP_CONFIG_REGISTRATION_FAILURE} or
+ * {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_SUCCESS}
+ * or {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_FAILURE}
*/
@BinderThread
public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config,
@@ -57,15 +56,15 @@ public abstract class BluetoothHealthCallback {
* @param prevState The previous state of the channel
* @param newState The new state of the channel.
* @param fd The Parcel File Descriptor when the channel state is connected.
- * @param channelId The id associated with the channel. This id will be used
- * in future calls like when disconnecting the channel.
+ * @param channelId The id associated with the channel. This id will be used in future calls
+ * like when disconnecting the channel.
*/
@BinderThread
public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config,
BluetoothDevice device, int prevState, int newState, ParcelFileDescriptor fd,
int channelId) {
- Log.d(TAG, "onHealthChannelStateChange: " + config + "Device: " + device +
- "prevState:" + prevState + "newState:" + newState + "ParcelFd:" + fd +
- "ChannelId:" + channelId);
+ Log.d(TAG, "onHealthChannelStateChange: " + config + "Device: " + device
+ + "prevState:" + prevState + "newState:" + newState + "ParcelFd:" + fd
+ + "ChannelId:" + channelId);
}
}
diff --git a/core/java/android/bluetooth/BluetoothHidDeviceAppConfiguration.java b/core/java/android/bluetooth/BluetoothHidDeviceAppConfiguration.java
index 05ba64e981f13..2731935a4ea7c 100644
--- a/core/java/android/bluetooth/BluetoothHidDeviceAppConfiguration.java
+++ b/core/java/android/bluetooth/BluetoothHidDeviceAppConfiguration.java
@@ -49,19 +49,19 @@ public final class BluetoothHidDeviceAppConfiguration implements Parcelable {
}
public static final Parcelable.Creator BluetoothInputDevice is a proxy object for controlling the Bluetooth
+ * BluetoothInputDevice is a proxy object for controlling the Bluetooth
* Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get
* the BluetoothInputDevice proxy object.
*
- * Each method is protected with its appropriate permission.
- *@hide
+ * Each method is protected with its appropriate permission.
+ *
+ * @hide
*/
public final class BluetoothInputDevice implements BluetoothProfile {
private static final String TAG = "BluetoothInputDevice";
@@ -53,9 +54,9 @@ public final class BluetoothInputDevice implements BluetoothProfile {
*
* This intent will have 3 extras:
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
@@ -67,45 +68,46 @@ public final class BluetoothInputDevice implements BluetoothProfile {
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_CONNECTION_STATE_CHANGED =
- "android.bluetooth.input.profile.action.CONNECTION_STATE_CHANGED";
+ "android.bluetooth.input.profile.action.CONNECTION_STATE_CHANGED";
/**
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_PROTOCOL_MODE_CHANGED =
- "android.bluetooth.input.profile.action.PROTOCOL_MODE_CHANGED";
+ "android.bluetooth.input.profile.action.PROTOCOL_MODE_CHANGED";
/**
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_HANDSHAKE =
- "android.bluetooth.input.profile.action.HANDSHAKE";
+ "android.bluetooth.input.profile.action.HANDSHAKE";
/**
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_REPORT =
- "android.bluetooth.input.profile.action.REPORT";
+ "android.bluetooth.input.profile.action.REPORT";
/**
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_VIRTUAL_UNPLUG_STATUS =
- "android.bluetooth.input.profile.action.VIRTUAL_UNPLUG_STATUS";
+ "android.bluetooth.input.profile.action.VIRTUAL_UNPLUG_STATUS";
/**
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_IDLE_TIME_CHANGED =
- "android.bluetooth.input.profile.action.IDLE_TIME_CHANGED";
+ "android.bluetooth.input.profile.action.IDLE_TIME_CHANGED";
/**
* Return codes for the connect and disconnect Bluez / Dbus calls.
+ *
* @hide
*/
public static final int INPUT_DISCONNECT_FAILED_NOT_CONNECTED = 5000;
@@ -174,22 +176,26 @@ public final class BluetoothInputDevice implements BluetoothProfile {
/**
* @hide
*/
- public static final String EXTRA_PROTOCOL_MODE = "android.bluetooth.BluetoothInputDevice.extra.PROTOCOL_MODE";
+ public static final String EXTRA_PROTOCOL_MODE =
+ "android.bluetooth.BluetoothInputDevice.extra.PROTOCOL_MODE";
/**
* @hide
*/
- public static final String EXTRA_REPORT_TYPE = "android.bluetooth.BluetoothInputDevice.extra.REPORT_TYPE";
+ public static final String EXTRA_REPORT_TYPE =
+ "android.bluetooth.BluetoothInputDevice.extra.REPORT_TYPE";
/**
* @hide
*/
- public static final String EXTRA_REPORT_ID = "android.bluetooth.BluetoothInputDevice.extra.REPORT_ID";
+ public static final String EXTRA_REPORT_ID =
+ "android.bluetooth.BluetoothInputDevice.extra.REPORT_ID";
/**
* @hide
*/
- public static final String EXTRA_REPORT_BUFFER_SIZE = "android.bluetooth.BluetoothInputDevice.extra.REPORT_BUFFER_SIZE";
+ public static final String EXTRA_REPORT_BUFFER_SIZE =
+ "android.bluetooth.BluetoothInputDevice.extra.REPORT_BUFFER_SIZE";
/**
* @hide
@@ -204,51 +210,52 @@ public final class BluetoothInputDevice implements BluetoothProfile {
/**
* @hide
*/
- public static final String EXTRA_VIRTUAL_UNPLUG_STATUS = "android.bluetooth.BluetoothInputDevice.extra.VIRTUAL_UNPLUG_STATUS";
+ public static final String EXTRA_VIRTUAL_UNPLUG_STATUS =
+ "android.bluetooth.BluetoothInputDevice.extra.VIRTUAL_UNPLUG_STATUS";
/**
* @hide
*/
- public static final String EXTRA_IDLE_TIME = "android.bluetooth.BluetoothInputDevice.extra.IDLE_TIME";
+ public static final String EXTRA_IDLE_TIME =
+ "android.bluetooth.BluetoothInputDevice.extra.IDLE_TIME";
private Context mContext;
private ServiceListener mServiceListener;
private BluetoothAdapter mAdapter;
private IBluetoothInputDevice mService;
- final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
+ private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
new IBluetoothStateChangeCallback.Stub() {
public void onBluetoothStateChange(boolean up) {
if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
if (!up) {
- if (VDBG) Log.d(TAG,"Unbinding service...");
+ if (VDBG) Log.d(TAG, "Unbinding service...");
synchronized (mConnection) {
try {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
} else {
synchronized (mConnection) {
try {
if (mService == null) {
- if (VDBG) Log.d(TAG,"Binding service...");
+ if (VDBG) Log.d(TAG, "Binding service...");
doBind();
}
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
}
- };
+ };
/**
* Create a BluetoothInputDevice proxy object for interacting with the local
* Bluetooth Service which handles the InputDevice profile
- *
*/
/*package*/ BluetoothInputDevice(Context context, ServiceListener l) {
mContext = context;
@@ -260,7 +267,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
try {
mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -286,7 +293,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
try {
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
} catch (Exception e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -296,9 +303,9 @@ public final class BluetoothInputDevice implements BluetoothProfile {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
- }
+ }
}
mServiceListener = null;
}
@@ -319,8 +326,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
* permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean connect(BluetoothDevice device) {
@@ -359,8 +365,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
* permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean disconnect(BluetoothDevice device) {
@@ -380,6 +385,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
/**
* {@inheritDoc}
*/
+ @Override
public List The device should already be paired.
- * Priority can be one of {@link #PRIORITY_ON} or
+ * Priority can be one of {@link #PRIORITY_ON} or
* {@link #PRIORITY_OFF},
*
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
@@ -446,9 +454,9 @@ public final class BluetoothInputDevice implements BluetoothProfile {
public boolean setPriority(BluetoothDevice device, int priority) {
if (DBG) log("setPriority(" + device + ", " + priority + ")");
if (mService != null && isEnabled() && isValidDevice(device)) {
- if (priority != BluetoothProfile.PRIORITY_OFF &&
- priority != BluetoothProfile.PRIORITY_ON) {
- return false;
+ if (priority != BluetoothProfile.PRIORITY_OFF
+ && priority != BluetoothProfile.PRIORITY_ON) {
+ return false;
}
try {
return mService.setPriority(device, priority);
@@ -494,9 +502,11 @@ public final class BluetoothInputDevice implements BluetoothProfile {
mService = IBluetoothInputDevice.Stub.asInterface(Binder.allowBlocking(service));
if (mServiceListener != null) {
- mServiceListener.onServiceConnected(BluetoothProfile.INPUT_DEVICE, BluetoothInputDevice.this);
+ mServiceListener.onServiceConnected(BluetoothProfile.INPUT_DEVICE,
+ BluetoothInputDevice.this);
}
}
+
public void onServiceDisconnected(ComponentName className) {
if (DBG) Log.d(TAG, "Proxy object disconnected");
mService = null;
@@ -507,15 +517,15 @@ public final class BluetoothInputDevice implements BluetoothProfile {
};
private boolean isEnabled() {
- if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
- return false;
+ if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
+ return false;
}
private boolean isValidDevice(BluetoothDevice device) {
- if (device == null) return false;
+ if (device == null) return false;
- if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
- return false;
+ if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
+ return false;
}
@@ -525,8 +535,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean virtualUnplug(BluetoothDevice device) {
@@ -546,15 +555,14 @@ public final class BluetoothInputDevice implements BluetoothProfile {
}
/**
- * Send Get_Protocol_Mode command to the connected HID input device.
- *
- * Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
- *
- * @param device Remote Bluetooth Device
- * @return false on immediate error,
- *true otherwise
- * @hide
- */
+ * Send Get_Protocol_Mode command to the connected HID input device.
+ *
+ * Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
+ *
+ * @param device Remote Bluetooth Device
+ * @return false on immediate error, true otherwise
+ * @hide
+ */
public boolean getProtocolMode(BluetoothDevice device) {
if (VDBG) log("getProtocolMode(" + device + ")");
if (mService != null && isEnabled() && isValidDevice(device)) {
@@ -566,7 +574,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
- return false;
+ return false;
}
/**
@@ -575,8 +583,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean setProtocolMode(BluetoothDevice device, int protocolMode) {
@@ -602,12 +609,16 @@ public final class BluetoothInputDevice implements BluetoothProfile {
* @param reportType Report type
* @param reportId Report ID
* @param bufferSize Report receiving buffer size
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
- public boolean getReport(BluetoothDevice device, byte reportType, byte reportId, int bufferSize) {
- if (VDBG) log("getReport(" + device + "), reportType=" + reportType + " reportId=" + reportId + "bufferSize=" + bufferSize);
+ public boolean getReport(BluetoothDevice device, byte reportType, byte reportId,
+ int bufferSize) {
+ if (VDBG) {
+ log(
+ "getReport(" + device + "), reportType=" + reportType + " reportId=" + reportId
+ + "bufferSize=" + bufferSize);
+ }
if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getReport(device, reportType, reportId, bufferSize);
@@ -628,8 +639,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
* @param device Remote Bluetooth Device
* @param reportType Report type
* @param report Report receiving buffer size
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean setReport(BluetoothDevice device, byte reportType, String report) {
@@ -653,8 +663,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
*
* @param device Remote Bluetooth Device
* @param report Report to send
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean sendData(BluetoothDevice device, String report) {
@@ -677,8 +686,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean getIdleTime(BluetoothDevice device) {
@@ -702,8 +710,7 @@ public final class BluetoothInputDevice implements BluetoothProfile {
*
* @param device Remote Bluetooth Device
* @param idleTime Idle time to be set on HID Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean setIdleTime(BluetoothDevice device, byte idleTime) {
@@ -721,6 +728,6 @@ public final class BluetoothInputDevice implements BluetoothProfile {
}
private static void log(String msg) {
- Log.d(TAG, msg);
+ Log.d(TAG, msg);
}
}
diff --git a/core/java/android/bluetooth/BluetoothInputHost.java b/core/java/android/bluetooth/BluetoothInputHost.java
index 68d105f1155d8..15303dc79448a 100644
--- a/core/java/android/bluetooth/BluetoothInputHost.java
+++ b/core/java/android/bluetooth/BluetoothInputHost.java
@@ -26,8 +26,8 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
-import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -43,9 +43,9 @@ public final class BluetoothInputHost implements BluetoothProfile {
*
* This intent will have 3 extras:
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
@@ -57,13 +57,12 @@ public final class BluetoothInputHost implements BluetoothProfile {
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_CONNECTION_STATE_CHANGED =
- "android.bluetooth.inputhost.profile.action.CONNECTION_STATE_CHANGED";
+ "android.bluetooth.inputhost.profile.action.CONNECTION_STATE_CHANGED";
/**
* Constants representing device subclass.
*
- * @see #registerApp(String, String, String, byte, byte[],
- * BluetoothHidDeviceCallback)
+ * @see #registerApp(String, String, String, byte, byte[], BluetoothHidDeviceCallback)
*/
public static final byte SUBCLASS1_NONE = (byte) 0x00;
public static final byte SUBCLASS1_KEYBOARD = (byte) 0x40;
@@ -118,7 +117,8 @@ public final class BluetoothInputHost implements BluetoothProfile {
private BluetoothAdapter mAdapter;
- private static class BluetoothHidDeviceCallbackWrapper extends IBluetoothHidDeviceCallback.Stub {
+ private static class BluetoothHidDeviceCallbackWrapper extends
+ IBluetoothHidDeviceCallback.Stub {
private BluetoothHidDeviceCallback mCallback;
@@ -163,37 +163,44 @@ public final class BluetoothInputHost implements BluetoothProfile {
}
}
- final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
- new IBluetoothStateChangeCallback.Stub() {
+ private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
+ new IBluetoothStateChangeCallback.Stub() {
- public void onBluetoothStateChange(boolean up) {
- Log.d(TAG, "onBluetoothStateChange: up=" + up);
- synchronized (mConnection) {
- if (!up) {
- Log.d(TAG,"Unbinding service...");
- if (mService != null) {
- mService = null;
- try {
- mContext.unbindService(mConnection);
- } catch (IllegalArgumentException e) {
- Log.e(TAG,"onBluetoothStateChange: could not unbind service:", e);
+ public void onBluetoothStateChange(boolean up) {
+ Log.d(TAG, "onBluetoothStateChange: up=" + up);
+ synchronized (mConnection) {
+ if (!up) {
+ Log.d(TAG, "Unbinding service...");
+ if (mService != null) {
+ mService = null;
+ try {
+ mContext.unbindService(mConnection);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "onBluetoothStateChange: could not unbind service:",
+ e);
+ }
+ }
+ } else {
+ try {
+ if (mService == null) {
+ Log.d(TAG, "Binding HID Device service...");
+ doBind();
+ }
+ } catch (IllegalStateException e) {
+ Log.e(TAG,
+ "onBluetoothStateChange: could not bind to HID Dev "
+ + "service: ",
+ e);
+ } catch (SecurityException e) {
+ Log.e(TAG,
+ "onBluetoothStateChange: could not bind to HID Dev "
+ + "service: ",
+ e);
+ }
}
}
- } else {
- try {
- if (mService == null) {
- Log.d(TAG,"Binding HID Device service...");
- doBind();
- }
- } catch (IllegalStateException e) {
- Log.e(TAG,"onBluetoothStateChange: could not bind to HID Dev service: ", e);
- } catch (SecurityException e) {
- Log.e(TAG,"onBluetoothStateChange: could not bind to HID Dev service: ", e);
- }
}
- }
- }
- };
+ };
private ServiceConnection mConnection = new ServiceConnection() {
@@ -204,7 +211,7 @@ public final class BluetoothInputHost implements BluetoothProfile {
if (mServiceListener != null) {
mServiceListener.onServiceConnected(BluetoothProfile.INPUT_HOST,
- BluetoothInputHost.this);
+ BluetoothInputHost.this);
}
}
@@ -269,9 +276,9 @@ public final class BluetoothInputHost implements BluetoothProfile {
try {
mContext.unbindService(mConnection);
} catch (IllegalArgumentException e) {
- Log.e(TAG,"close: could not unbind HID Dev service: ", e);
+ Log.e(TAG, "close: could not unbind HID Dev service: ", e);
}
- }
+ }
}
mServiceListener = null;
@@ -280,6 +287,7 @@ public final class BluetoothInputHost implements BluetoothProfile {
/**
* {@inheritDoc}
*/
+ @Override
public List The device should already be paired.
- * Priority can be one of {@link #PRIORITY_ON} or
+ * Priority can be one of {@link #PRIORITY_ON} or
* {@link #PRIORITY_OFF},
*
* @param device Paired bluetooth device
@@ -326,11 +335,10 @@ public final class BluetoothMap implements BluetoothProfile {
*/
public boolean setPriority(BluetoothDevice device, int priority) {
if (DBG) log("setPriority(" + device + ", " + priority + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
- if (priority != BluetoothProfile.PRIORITY_OFF &&
- priority != BluetoothProfile.PRIORITY_ON) {
- return false;
+ if (mService != null && isEnabled() && isValidDevice(device)) {
+ if (priority != BluetoothProfile.PRIORITY_OFF
+ && priority != BluetoothProfile.PRIORITY_ON) {
+ return false;
}
try {
return mService.setPriority(device, priority);
@@ -355,8 +363,7 @@ public final class BluetoothMap implements BluetoothProfile {
*/
public int getPriority(BluetoothDevice device) {
if (VDBG) log("getPriority(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getPriority(device);
} catch (RemoteException e) {
@@ -376,6 +383,7 @@ public final class BluetoothMap implements BluetoothProfile {
mServiceListener.onServiceConnected(BluetoothProfile.MAP, BluetoothMap.this);
}
}
+
public void onServiceDisconnected(ComponentName className) {
if (DBG) log("Proxy object disconnected");
mService = null;
@@ -389,17 +397,18 @@ public final class BluetoothMap implements BluetoothProfile {
Log.d(TAG, msg);
}
- private boolean isEnabled() {
+ private boolean isEnabled() {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON) return true;
log("Bluetooth is Not enabled");
return false;
}
- private boolean isValidDevice(BluetoothDevice device) {
- if (device == null) return false;
- if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
- return false;
+ private boolean isValidDevice(BluetoothDevice device) {
+ if (device == null) return false;
+
+ if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
+ return false;
}
diff --git a/core/java/android/bluetooth/BluetoothMapClient.java b/core/java/android/bluetooth/BluetoothMapClient.java
index ccab3cdf0b6f8..3e0c36548c41e 100644
--- a/core/java/android/bluetooth/BluetoothMapClient.java
+++ b/core/java/android/bluetooth/BluetoothMapClient.java
@@ -72,7 +72,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
/** Connection canceled before completion. */
public static final int RESULT_CANCELED = 2;
- final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
+ private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
new IBluetoothStateChangeCallback.Stub() {
public void onBluetoothStateChange(boolean up) {
if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
@@ -216,8 +216,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
*/
public boolean disconnect(BluetoothDevice device) {
if (DBG) Log.d(TAG, "disconnect(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.disconnect(device);
} catch (RemoteException e) {
@@ -276,8 +275,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
@Override
public int getConnectionState(BluetoothDevice device) {
if (DBG) Log.d(TAG, "getConnectionState(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getConnectionState(device);
} catch (RemoteException e) {
@@ -300,10 +298,9 @@ public final class BluetoothMapClient implements BluetoothProfile {
*/
public boolean setPriority(BluetoothDevice device, int priority) {
if (DBG) Log.d(TAG, "setPriority(" + device + ", " + priority + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
- if (priority != BluetoothProfile.PRIORITY_OFF &&
- priority != BluetoothProfile.PRIORITY_ON) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
+ if (priority != BluetoothProfile.PRIORITY_OFF
+ && priority != BluetoothProfile.PRIORITY_ON) {
return false;
}
try {
@@ -329,8 +326,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
*/
public int getPriority(BluetoothDevice device) {
if (VDBG) Log.d(TAG, "getPriority(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getPriority(device);
} catch (RemoteException e) {
@@ -347,10 +343,10 @@ public final class BluetoothMapClient implements BluetoothProfile {
*
* Send an SMS message to either the contacts primary number or the telephone number specified.
*
- * @param device Bluetooth device
- * @param contacts Uri[] of the contacts
- * @param message Message to be sent
- * @param sentIntent intent issued when message is sent
+ * @param device Bluetooth device
+ * @param contacts Uri[] of the contacts
+ * @param message Message to be sent
+ * @param sentIntent intent issued when message is sent
* @param deliveredIntent intent issued when message is delivered
* @return true if the message is enqueued, false on error
*/
@@ -393,7 +389,7 @@ public final class BluetoothMapClient implements BluetoothProfile {
mService = IBluetoothMapClient.Stub.asInterface(service);
if (mServiceListener != null) {
mServiceListener.onServiceConnected(BluetoothProfile.MAP_CLIENT,
- BluetoothMapClient.this);
+ BluetoothMapClient.this);
}
}
diff --git a/core/java/android/bluetooth/BluetoothMasInstance.java b/core/java/android/bluetooth/BluetoothMasInstance.java
index 4459e2c44bdcf..7a31328eaf02c 100644
--- a/core/java/android/bluetooth/BluetoothMasInstance.java
+++ b/core/java/android/bluetooth/BluetoothMasInstance.java
@@ -36,7 +36,7 @@ public final class BluetoothMasInstance implements Parcelable {
@Override
public boolean equals(Object o) {
if (o instanceof BluetoothMasInstance) {
- return mId == ((BluetoothMasInstance)o).mId;
+ return mId == ((BluetoothMasInstance) o).mId;
}
return false;
}
@@ -48,25 +48,28 @@ public final class BluetoothMasInstance implements Parcelable {
@Override
public String toString() {
- return Integer.toString(mId) + ":" + mName + ":" + mChannel + ":" +
- Integer.toHexString(mMsgTypes);
+ return Integer.toString(mId) + ":" + mName + ":" + mChannel + ":"
+ + Integer.toHexString(mMsgTypes);
}
+ @Override
public int describeContents() {
return 0;
}
public static final Parcelable.Creator BluetoothPan is a proxy object for controlling the Bluetooth
+ * BluetoothPan is a proxy object for controlling the Bluetooth
* Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get
* the BluetoothPan proxy object.
*
- * Each method is protected with its appropriate permission.
- *@hide
+ * Each method is protected with its appropriate permission.
+ *
+ * @hide
*/
public final class BluetoothPan implements BluetoothProfile {
private static final String TAG = "BluetoothPan";
@@ -52,11 +53,11 @@ public final class BluetoothPan implements BluetoothProfile {
*
* This intent will have 4 extras:
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
@@ -70,7 +71,7 @@ public final class BluetoothPan implements BluetoothProfile {
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_CONNECTION_STATE_CHANGED =
- "android.bluetooth.pan.profile.action.CONNECTION_STATE_CHANGED";
+ "android.bluetooth.pan.profile.action.CONNECTION_STATE_CHANGED";
/**
* Extra for {@link #ACTION_CONNECTION_STATE_CHANGED} intent
@@ -94,6 +95,7 @@ public final class BluetoothPan implements BluetoothProfile {
/**
* Return codes for the connect and disconnect Bluez / Dbus calls.
+ *
* @hide
*/
public static final int PAN_DISCONNECT_FAILED_NOT_CONNECTED = 1000;
@@ -126,7 +128,6 @@ public final class BluetoothPan implements BluetoothProfile {
/**
* Create a BluetoothPan proxy object for interacting with the local
* Bluetooth Service which handles the Pan profile
- *
*/
/*package*/ BluetoothPan(Context context, ServiceListener l) {
mContext = context;
@@ -135,7 +136,7 @@ public final class BluetoothPan implements BluetoothProfile {
try {
mAdapter.getBluetoothManager().registerStateChangeCallback(mStateChangeCallback);
} catch (RemoteException re) {
- Log.w(TAG,"Unable to register BluetoothStateChangeCallback",re);
+ Log.w(TAG, "Unable to register BluetoothStateChangeCallback", re);
}
if (VDBG) Log.d(TAG, "BluetoothPan() call bindService");
doBind();
@@ -161,7 +162,7 @@ public final class BluetoothPan implements BluetoothProfile {
try {
mgr.unregisterStateChangeCallback(mStateChangeCallback);
} catch (RemoteException re) {
- Log.w(TAG,"Unable to unregister BluetoothStateChangeCallback",re);
+ Log.w(TAG, "Unable to unregister BluetoothStateChangeCallback", re);
}
}
@@ -171,7 +172,7 @@ public final class BluetoothPan implements BluetoothProfile {
mPanService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
@@ -182,38 +183,41 @@ public final class BluetoothPan implements BluetoothProfile {
close();
}
- final private IBluetoothStateChangeCallback mStateChangeCallback = new IBluetoothStateChangeCallback.Stub() {
+ private final IBluetoothStateChangeCallback mStateChangeCallback =
+ new IBluetoothStateChangeCallback.Stub() {
- @Override
- public void onBluetoothStateChange(boolean on) {
- // Handle enable request to bind again.
- Log.d(TAG, "onBluetoothStateChange on: " + on);
- if (on) {
- try {
- if (mPanService == null) {
- if (VDBG) Log.d(TAG, "onBluetoothStateChange calling doBind()");
- doBind();
- }
+ @Override
+ public void onBluetoothStateChange(boolean on) {
+ // Handle enable request to bind again.
+ Log.d(TAG, "onBluetoothStateChange on: " + on);
+ if (on) {
+ try {
+ if (mPanService == null) {
+ if (VDBG) Log.d(TAG, "onBluetoothStateChange calling doBind()");
+ doBind();
+ }
- } catch (IllegalStateException e) {
- Log.e(TAG,"onBluetoothStateChange: could not bind to PAN service: ", e);
+ } catch (IllegalStateException e) {
+ Log.e(TAG, "onBluetoothStateChange: could not bind to PAN service: ",
+ e);
- } catch (SecurityException e) {
- Log.e(TAG,"onBluetoothStateChange: could not bind to PAN service: ", e);
- }
- } else {
- if (VDBG) Log.d(TAG,"Unbinding service...");
- synchronized (mConnection) {
- try {
- mPanService = null;
- mContext.unbindService(mConnection);
- } catch (Exception re) {
- Log.e(TAG,"",re);
+ } catch (SecurityException e) {
+ Log.e(TAG, "onBluetoothStateChange: could not bind to PAN service: ",
+ e);
+ }
+ } else {
+ if (VDBG) Log.d(TAG, "Unbinding service...");
+ synchronized (mConnection) {
+ try {
+ mPanService = null;
+ mContext.unbindService(mConnection);
+ } catch (Exception re) {
+ Log.e(TAG, "", re);
+ }
+ }
}
}
- }
- }
- };
+ };
/**
* Initiate connection to a profile of the remote bluetooth device.
@@ -229,14 +233,12 @@ public final class BluetoothPan implements BluetoothProfile {
* permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean connect(BluetoothDevice device) {
if (DBG) log("connect(" + device + ")");
- if (mPanService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mPanService != null && isEnabled() && isValidDevice(device)) {
try {
return mPanService.connect(device);
} catch (RemoteException e) {
@@ -270,14 +272,12 @@ public final class BluetoothPan implements BluetoothProfile {
* permission.
*
* @param device Remote Bluetooth Device
- * @return false on immediate error,
- * true otherwise
+ * @return false on immediate error, true otherwise
* @hide
*/
public boolean disconnect(BluetoothDevice device) {
if (DBG) log("disconnect(" + device + ")");
- if (mPanService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mPanService != null && isEnabled() && isValidDevice(device)) {
try {
return mPanService.disconnect(device);
} catch (RemoteException e) {
@@ -292,6 +292,7 @@ public final class BluetoothPan implements BluetoothProfile {
/**
* {@inheritDoc}
*/
+ @Override
public List The device should already be paired.
- * Priority can be one of {@link #PRIORITY_ON} or
+ * Priority can be one of {@link #PRIORITY_ON} or
* {@link #PRIORITY_OFF},
*
* @param device Paired bluetooth device
@@ -343,11 +346,10 @@ public final class BluetoothPbapClient implements BluetoothProfile {
if (DBG) {
log("setPriority(" + device + ", " + priority + ")");
}
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
- if (priority != BluetoothProfile.PRIORITY_OFF &&
- priority != BluetoothProfile.PRIORITY_ON) {
- return false;
+ if (mService != null && isEnabled() && isValidDevice(device)) {
+ if (priority != BluetoothProfile.PRIORITY_OFF
+ && priority != BluetoothProfile.PRIORITY_ON) {
+ return false;
}
try {
return mService.setPriority(device, priority);
diff --git a/core/java/android/bluetooth/BluetoothProfile.java b/core/java/android/bluetooth/BluetoothProfile.java
index c5b58e97e5287..bc8fa846087d8 100644
--- a/core/java/android/bluetooth/BluetoothProfile.java
+++ b/core/java/android/bluetooth/BluetoothProfile.java
@@ -46,14 +46,14 @@ public interface BluetoothProfile {
* Bluetooth device.
*/
public static final String EXTRA_PREVIOUS_STATE =
- "android.bluetooth.profile.extra.PREVIOUS_STATE";
+ "android.bluetooth.profile.extra.PREVIOUS_STATE";
/** The profile is in disconnected state */
- public static final int STATE_DISCONNECTED = 0;
+ public static final int STATE_DISCONNECTED = 0;
/** The profile is in connecting state */
- public static final int STATE_CONNECTING = 1;
+ public static final int STATE_CONNECTING = 1;
/** The profile is in connected state */
- public static final int STATE_CONNECTED = 2;
+ public static final int STATE_CONNECTED = 2;
/** The profile is in disconnecting state */
public static final int STATE_DISCONNECTING = 3;
@@ -74,18 +74,21 @@ public interface BluetoothProfile {
/**
* Input Device Profile
+ *
* @hide
*/
public static final int INPUT_DEVICE = 4;
/**
* PAN Profile
+ *
* @hide
*/
public static final int PAN = 5;
/**
* PBAP
+ *
* @hide
*/
public static final int PBAP = 6;
@@ -93,15 +96,16 @@ public interface BluetoothProfile {
/**
* GATT
*/
- static public final int GATT = 7;
+ public static final int GATT = 7;
/**
* GATT_SERVER
*/
- static public final int GATT_SERVER = 8;
+ public static final int GATT_SERVER = 8;
/**
* MAP Profile
+ *
* @hide
*/
public static final int MAP = 9;
@@ -114,43 +118,50 @@ public interface BluetoothProfile {
/**
* A2DP Sink Profile
+ *
* @hide
*/
public static final int A2DP_SINK = 11;
/**
* AVRCP Controller Profile
+ *
* @hide
*/
public static final int AVRCP_CONTROLLER = 12;
/**
* Headset Client - HFP HF Role
+ *
* @hide
*/
public static final int HEADSET_CLIENT = 16;
/**
* PBAP Client
+ *
* @hide
*/
public static final int PBAP_CLIENT = 17;
/**
* MAP Messaging Client Equipment (MCE)
+ *
* @hide
*/
public static final int MAP_CLIENT = 18;
/**
* Input Host
+ *
* @hide
*/
- static public final int INPUT_HOST = 19;
+ public static final int INPUT_HOST = 19;
/**
* Max profile ID. This value should be updated whenever a new profile is added to match
* the largest value assigned to a profile.
+ *
* @hide
*/
public static final int MAX_PROFILE_ID = 19;
@@ -158,13 +169,15 @@ public interface BluetoothProfile {
/**
* Default priority for devices that we try to auto-connect to and
* and allow incoming connections for the profile
+ *
* @hide
**/
public static final int PRIORITY_AUTO_CONNECT = 1000;
/**
- * Default priority for devices that allow incoming
+ * Default priority for devices that allow incoming
* and outgoing connections for the profile
+ *
* @hide
**/
public static final int PRIORITY_ON = 100;
@@ -172,14 +185,16 @@ public interface BluetoothProfile {
/**
* Default priority for devices that does not allow incoming
* connections and outgoing connections for the profile.
+ *
* @hide
**/
public static final int PRIORITY_OFF = 0;
/**
* Default priority when not set or when the device is unpaired
+ *
* @hide
- * */
+ */
public static final int PRIORITY_UNDEFINED = -1;
/**
@@ -199,9 +214,8 @@ public interface BluetoothProfile {
* If none of the devices match any of the given states,
* an empty list will be returned.
*
- * @param states Array of states. States can be one of
- * {@link #STATE_CONNECTED}, {@link #STATE_CONNECTING},
- * {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
+ * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
+ * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
* @return List of devices. The list will be empty on error.
*/
@RequiresPermission(Manifest.permission.BLUETOOTH)
@@ -211,9 +225,8 @@ public interface BluetoothProfile {
* Get the current connection state of the profile
*
* @param device Remote bluetooth device.
- * @return State of the profile connection. One of
- * {@link #STATE_CONNECTED}, {@link #STATE_CONNECTING},
- * {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
+ * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
+ * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
*/
@RequiresPermission(Manifest.permission.BLUETOOTH)
public int getConnectionState(BluetoothDevice device);
@@ -226,18 +239,18 @@ public interface BluetoothProfile {
/**
* Called to notify the client when the proxy object has been
* connected to the service.
- * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or
- * {@link #A2DP}
- * @param proxy - One of {@link BluetoothHealth}, {@link BluetoothHeadset} or
- * {@link BluetoothA2dp}
+ *
+ * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP}
+ * @param proxy - One of {@link BluetoothHealth}, {@link BluetoothHeadset} or {@link
+ * BluetoothA2dp}
*/
public void onServiceConnected(int profile, BluetoothProfile proxy);
/**
* Called to notify the client that this proxy object has been
* disconnected from the service.
- * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or
- * {@link #A2DP}
+ *
+ * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP}
*/
public void onServiceDisconnected(int profile);
}
diff --git a/core/java/android/bluetooth/BluetoothSap.java b/core/java/android/bluetooth/BluetoothSap.java
index 89c1bf8f9aa25..bcdf4938fe2f2 100644
--- a/core/java/android/bluetooth/BluetoothSap.java
+++ b/core/java/android/bluetooth/BluetoothSap.java
@@ -16,19 +16,18 @@
package android.bluetooth;
-import java.util.ArrayList;
-import java.util.List;
-
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
-import android.os.RemoteException;
import android.os.Binder;
import android.os.IBinder;
-import android.os.ServiceManager;
+import android.os.RemoteException;
import android.util.Log;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* This class provides the APIs to control the Bluetooth SIM
* Access Profile (SAP).
@@ -38,6 +37,7 @@ import android.util.Log;
* the BluetoothSap proxy object.
*
* Each method is protected with its appropriate permission.
+ *
* @hide
*/
public final class BluetoothSap implements BluetoothProfile {
@@ -51,9 +51,9 @@ public final class BluetoothSap implements BluetoothProfile {
*
* This intent will have 4 extras:
* {@link #EXTRA_STATE} or {@link #EXTRA_PREVIOUS_STATE} can be any of
@@ -62,10 +62,11 @@ public final class BluetoothSap implements BluetoothProfile {
*
* Requires {@link android.Manifest.permission#BLUETOOTH} permission to
* receive.
+ *
* @hide
*/
public static final String ACTION_CONNECTION_STATE_CHANGED =
- "android.bluetooth.sap.profile.action.CONNECTION_STATE_CHANGED";
+ "android.bluetooth.sap.profile.action.CONNECTION_STATE_CHANGED";
private IBluetoothSap mService;
private final Context mContext;
@@ -74,50 +75,53 @@ public final class BluetoothSap implements BluetoothProfile {
/**
* There was an error trying to obtain the state.
+ *
* @hide
*/
public static final int STATE_ERROR = -1;
/**
* Connection state change succceeded.
+ *
* @hide
*/
public static final int RESULT_SUCCESS = 1;
/**
* Connection canceled before completion.
+ *
* @hide
*/
public static final int RESULT_CANCELED = 2;
- final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
+ private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
new IBluetoothStateChangeCallback.Stub() {
public void onBluetoothStateChange(boolean up) {
if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
if (!up) {
- if (VDBG) Log.d(TAG,"Unbinding service...");
+ if (VDBG) Log.d(TAG, "Unbinding service...");
synchronized (mConnection) {
try {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
} else {
synchronized (mConnection) {
try {
if (mService == null) {
- if (VDBG) Log.d(TAG,"Binding service...");
+ if (VDBG) Log.d(TAG, "Binding service...");
doBind();
}
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
}
- };
+ };
/**
* Create a BluetoothSap proxy object.
@@ -132,7 +136,7 @@ public final class BluetoothSap implements BluetoothProfile {
try {
mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
doBind();
@@ -163,6 +167,7 @@ public final class BluetoothSap implements BluetoothProfile {
* Other public functions of BluetoothSap will return default error
* results once close() has been called. Multiple invocations of close()
* are ok.
+ *
* @hide
*/
public synchronized void close() {
@@ -171,7 +176,7 @@ public final class BluetoothSap implements BluetoothProfile {
try {
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
} catch (Exception e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -181,7 +186,7 @@ public final class BluetoothSap implements BluetoothProfile {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
@@ -190,8 +195,9 @@ public final class BluetoothSap implements BluetoothProfile {
/**
* Get the current state of the BluetoothSap service.
- * @return One of the STATE_ return codes, or STATE_ERROR if this proxy
- * object is currently not connected to the Sap service.
+ *
+ * @return One of the STATE_ return codes, or STATE_ERROR if this proxy object is currently not
+ * connected to the Sap service.
* @hide
*/
public int getState() {
@@ -199,7 +205,9 @@ public final class BluetoothSap implements BluetoothProfile {
if (mService != null) {
try {
return mService.getState();
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) log(Log.getStackTraceString(new Throwable()));
@@ -209,9 +217,9 @@ public final class BluetoothSap implements BluetoothProfile {
/**
* Get the currently connected remote Bluetooth device (PCE).
- * @return The remote Bluetooth device, or null if not in connected or
- * connecting state, or if this proxy object is not connected to
- * the Sap service.
+ *
+ * @return The remote Bluetooth device, or null if not in connected or connecting state, or if
+ * this proxy object is not connected to the Sap service.
* @hide
*/
public BluetoothDevice getClient() {
@@ -219,7 +227,9 @@ public final class BluetoothSap implements BluetoothProfile {
if (mService != null) {
try {
return mService.getClient();
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) log(Log.getStackTraceString(new Throwable()));
@@ -231,6 +241,7 @@ public final class BluetoothSap implements BluetoothProfile {
* Returns true if the specified Bluetooth device is connected.
* Returns false if not connected, or if this proxy object is not
* currently connected to the Sap service.
+ *
* @hide
*/
public boolean isConnected(BluetoothDevice device) {
@@ -238,7 +249,9 @@ public final class BluetoothSap implements BluetoothProfile {
if (mService != null) {
try {
return mService.isConnected(device);
- } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) log(Log.getStackTraceString(new Throwable()));
@@ -249,6 +262,7 @@ public final class BluetoothSap implements BluetoothProfile {
/**
* Initiate connection. Initiation of outgoing connections is not
* supported for SAP server.
+ *
* @hide
*/
public boolean connect(BluetoothDevice device) {
@@ -260,19 +274,17 @@ public final class BluetoothSap implements BluetoothProfile {
* Initiate disconnect.
*
* @param device Remote Bluetooth Device
- * @return false on error,
- * true otherwise
+ * @return false on error, true otherwise
* @hide
*/
public boolean disconnect(BluetoothDevice device) {
if (DBG) log("disconnect(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.disconnect(device);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
- return false;
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ return false;
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -327,8 +339,7 @@ public final class BluetoothSap implements BluetoothProfile {
*/
public int getConnectionState(BluetoothDevice device) {
if (DBG) log("getConnectionState(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getConnectionState(device);
} catch (RemoteException e) {
@@ -352,11 +363,10 @@ public final class BluetoothSap implements BluetoothProfile {
*/
public boolean setPriority(BluetoothDevice device, int priority) {
if (DBG) log("setPriority(" + device + ", " + priority + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
- if (priority != BluetoothProfile.PRIORITY_OFF &&
- priority != BluetoothProfile.PRIORITY_ON) {
- return false;
+ if (mService != null && isEnabled() && isValidDevice(device)) {
+ if (priority != BluetoothProfile.PRIORITY_OFF
+ && priority != BluetoothProfile.PRIORITY_ON) {
+ return false;
}
try {
return mService.setPriority(device, priority);
@@ -378,8 +388,7 @@ public final class BluetoothSap implements BluetoothProfile {
*/
public int getPriority(BluetoothDevice device) {
if (VDBG) log("getPriority(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getPriority(device);
} catch (RemoteException e) {
@@ -399,6 +408,7 @@ public final class BluetoothSap implements BluetoothProfile {
mServiceListener.onServiceConnected(BluetoothProfile.SAP, BluetoothSap.this);
}
}
+
public void onServiceDisconnected(ComponentName className) {
if (DBG) log("Proxy object disconnected");
mService = null;
@@ -415,19 +425,22 @@ public final class BluetoothSap implements BluetoothProfile {
private boolean isEnabled() {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
- if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON)
+ if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON) {
return true;
+ }
log("Bluetooth is Not enabled");
return false;
}
private boolean isValidDevice(BluetoothDevice device) {
- if (device == null)
- return false;
+ if (device == null) {
+ return false;
+ }
- if (BluetoothAdapter.checkBluetoothAddress(device.getAddress()))
- return true;
- return false;
+ if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) {
+ return true;
+ }
+ return false;
}
}
diff --git a/core/java/android/bluetooth/BluetoothServerSocket.java b/core/java/android/bluetooth/BluetoothServerSocket.java
index 4860c93840512..58d090dc287b4 100644
--- a/core/java/android/bluetooth/BluetoothServerSocket.java
+++ b/core/java/android/bluetooth/BluetoothServerSocket.java
@@ -75,12 +75,13 @@ public final class BluetoothServerSocket implements Closeable {
/**
* Construct a socket for incoming connections.
- * @param type type of socket
- * @param auth require the remote device to be authenticated
+ *
+ * @param type type of socket
+ * @param auth require the remote device to be authenticated
* @param encrypt require the connection to be encrypted
- * @param port remote port
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient privileges
+ * @param port remote port
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * privileges
*/
/*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port)
throws IOException {
@@ -93,14 +94,15 @@ public final class BluetoothServerSocket implements Closeable {
/**
* Construct a socket for incoming connections.
- * @param type type of socket
- * @param auth require the remote device to be authenticated
+ *
+ * @param type type of socket
+ * @param auth require the remote device to be authenticated
* @param encrypt require the connection to be encrypted
- * @param port remote port
- * @param mitm enforce man-in-the-middle protection for authentication.
+ * @param port remote port
+ * @param mitm enforce man-in-the-middle protection for authentication.
* @param min16DigitPin enforce a minimum length of 16 digits for a sec mode 2 connection
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient privileges
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * privileges
*/
/*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, int port,
boolean mitm, boolean min16DigitPin)
@@ -108,19 +110,20 @@ public final class BluetoothServerSocket implements Closeable {
mChannel = port;
mSocket = new BluetoothSocket(type, -1, auth, encrypt, null, port, null, mitm,
min16DigitPin);
- if(port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
+ if (port == BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
mSocket.setExcludeSdp(true);
}
}
/**
* Construct a socket for incoming connections.
- * @param type type of socket
- * @param auth require the remote device to be authenticated
+ *
+ * @param type type of socket
+ * @param auth require the remote device to be authenticated
* @param encrypt require the connection to be encrypted
- * @param uuid uuid
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient privileges
+ * @param uuid uuid
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * privileges
*/
/*package*/ BluetoothServerSocket(int type, boolean auth, boolean encrypt, ParcelUuid uuid)
throws IOException {
@@ -136,9 +139,9 @@ public final class BluetoothServerSocket implements Closeable {
* Once this call returns, it can be called again to accept subsequent
* incoming connections.
* {@link #close} can be used to abort this call from another thread.
+ *
* @return a connected {@link BluetoothSocket}
- * @throws IOException on error, for example this call was aborted, or
- * timeout
+ * @throws IOException on error, for example this call was aborted, or timeout
*/
public BluetoothSocket accept() throws IOException {
return accept(-1);
@@ -150,9 +153,9 @@ public final class BluetoothServerSocket implements Closeable {
* Once this call returns, it can be called again to accept subsequent
* incoming connections.
* {@link #close} can be used to abort this call from another thread.
+ *
* @return a connected {@link BluetoothSocket}
- * @throws IOException on error, for example this call was aborted, or
- * timeout
+ * @throws IOException on error, for example this call was aborted, or timeout
*/
public BluetoothSocket accept(int timeout) throws IOException {
return mSocket.accept(timeout);
@@ -174,16 +177,19 @@ public final class BluetoothServerSocket implements Closeable {
mSocket.close();
}
- /*package*/ synchronized void setCloseHandler(Handler handler, int message) {
+ /*package*/
+ synchronized void setCloseHandler(Handler handler, int message) {
mHandler = handler;
mMessage = message;
}
- /*package*/ void setServiceName(String ServiceName) {
- mSocket.setServiceName(ServiceName);
+
+ /*package*/ void setServiceName(String serviceName) {
+ mSocket.setServiceName(serviceName);
}
/**
* Returns the channel on which this socket is bound.
+ *
* @hide
*/
public int getChannel() {
@@ -199,10 +205,10 @@ public final class BluetoothServerSocket implements Closeable {
* The bind operation should be conducted through this class
* and the resulting port should be kept in mChannel, and
* not set from BluetoothAdapter. */
- if(mSocket != null) {
- if(mSocket.getPort() != newChannel) {
- Log.w(TAG,"The port set is different that the underlying port. mSocket.getPort(): "
- + mSocket.getPort() + " requested newChannel: " + newChannel);
+ if (mSocket != null) {
+ if (mSocket.getPort() != newChannel) {
+ Log.w(TAG, "The port set is different that the underlying port. mSocket.getPort(): "
+ + mSocket.getPort() + " requested newChannel: " + newChannel);
}
}
mChannel = newChannel;
@@ -212,19 +218,16 @@ public final class BluetoothServerSocket implements Closeable {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("ServerSocket: Type: ");
- switch(mSocket.getConnectionType()) {
- case BluetoothSocket.TYPE_RFCOMM:
- {
+ switch (mSocket.getConnectionType()) {
+ case BluetoothSocket.TYPE_RFCOMM: {
sb.append("TYPE_RFCOMM");
break;
}
- case BluetoothSocket.TYPE_L2CAP:
- {
+ case BluetoothSocket.TYPE_L2CAP: {
sb.append("TYPE_L2CAP");
break;
}
- case BluetoothSocket.TYPE_SCO:
- {
+ case BluetoothSocket.TYPE_SCO: {
sb.append("TYPE_SCO");
break;
}
diff --git a/core/java/android/bluetooth/BluetoothSocket.java b/core/java/android/bluetooth/BluetoothSocket.java
index 6bf6aa0a9efa3..4035ee1beb8f1 100644
--- a/core/java/android/bluetooth/BluetoothSocket.java
+++ b/core/java/android/bluetooth/BluetoothSocket.java
@@ -16,25 +16,23 @@
package android.bluetooth;
-import android.os.ParcelUuid;
+import android.net.LocalSocket;
import android.os.ParcelFileDescriptor;
+import android.os.ParcelUuid;
import android.os.RemoteException;
import android.util.Log;
-import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Locale;
import java.util.UUID;
-import android.net.LocalSocket;
-import java.nio.Buffer;
-import java.nio.ByteOrder;
-import java.nio.ByteBuffer;
/**
* A connected or connecting Bluetooth socket.
*
@@ -106,9 +104,9 @@ public final class BluetoothSocket implements Closeable {
/*package*/ static final int SEC_FLAG_ENCRYPT = 1;
/*package*/ static final int SEC_FLAG_AUTH = 1 << 1;
- /*package*/ static final int BTSOCK_FLAG_NO_SDP = 1 << 2;
- /*package*/ static final int SEC_FLAG_AUTH_MITM = 1 << 3;
- /*package*/ static final int SEC_FLAG_AUTH_16_DIGIT = 1 << 4;
+ /*package*/ static final int BTSOCK_FLAG_NO_SDP = 1 << 2;
+ /*package*/ static final int SEC_FLAG_AUTH_MITM = 1 << 3;
+ /*package*/ static final int SEC_FLAG_AUTH_16_DIGIT = 1 << 4;
private final int mType; /* one of TYPE_RFCOMM etc */
private BluetoothDevice mDevice; /* remote device */
@@ -128,9 +126,9 @@ public final class BluetoothSocket implements Closeable {
private int mPort; /* RFCOMM channel or L2CAP psm */
private int mFd;
private String mServiceName;
- private static int PROXY_CONNECTION_TIMEOUT = 5000;
+ private static final int PROXY_CONNECTION_TIMEOUT = 5000;
- private static int SOCK_SIGNAL_SIZE = 20;
+ private static final int SOCK_SIGNAL_SIZE = 20;
private ByteBuffer mL2capBuffer = null;
private int mMaxTxPacketSize = 0; // The l2cap maximum packet size supported by the peer.
@@ -151,15 +149,16 @@ public final class BluetoothSocket implements Closeable {
/**
* Construct a BluetoothSocket.
- * @param type type of socket
- * @param fd fd to use for connected socket, or -1 for a new socket
- * @param auth require the remote device to be authenticated
+ *
+ * @param type type of socket
+ * @param fd fd to use for connected socket, or -1 for a new socket
+ * @param auth require the remote device to be authenticated
* @param encrypt require the connection to be encrypted
- * @param device remote device that this socket can connect to
- * @param port remote port
- * @param uuid SDP uuid
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient privileges
+ * @param device remote device that this socket can connect to
+ * @param port remote port
+ * @param uuid SDP uuid
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * privileges
*/
/*package*/ BluetoothSocket(int type, int fd, boolean auth, boolean encrypt,
BluetoothDevice device, int port, ParcelUuid uuid) throws IOException {
@@ -168,21 +167,22 @@ public final class BluetoothSocket implements Closeable {
/**
* Construct a BluetoothSocket.
- * @param type type of socket
- * @param fd fd to use for connected socket, or -1 for a new socket
- * @param auth require the remote device to be authenticated
+ *
+ * @param type type of socket
+ * @param fd fd to use for connected socket, or -1 for a new socket
+ * @param auth require the remote device to be authenticated
* @param encrypt require the connection to be encrypted
- * @param device remote device that this socket can connect to
- * @param port remote port
- * @param uuid SDP uuid
- * @param mitm enforce man-in-the-middle protection.
+ * @param device remote device that this socket can connect to
+ * @param port remote port
+ * @param uuid SDP uuid
+ * @param mitm enforce man-in-the-middle protection.
* @param min16DigitPin enforce a minimum length of 16 digits for a sec mode 2 connection
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient privileges
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * privileges
*/
/*package*/ BluetoothSocket(int type, int fd, boolean auth, boolean encrypt,
BluetoothDevice device, int port, ParcelUuid uuid, boolean mitm, boolean min16DigitPin)
- throws IOException {
+ throws IOException {
if (VDBG) Log.d(TAG, "Creating new BluetoothSocket of type: " + type);
if (type == BluetoothSocket.TYPE_RFCOMM && uuid == null && fd == -1
&& port != BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP) {
@@ -190,9 +190,11 @@ public final class BluetoothSocket implements Closeable {
throw new IOException("Invalid RFCOMM channel: " + port);
}
}
- if (uuid != null)
+ if (uuid != null) {
mUuid = uuid;
- else mUuid = new ParcelUuid(new UUID(0, 0));
+ } else {
+ mUuid = new ParcelUuid(new UUID(0, 0));
+ }
mType = type;
mAuth = auth;
mAuthMitm = mitm;
@@ -214,6 +216,7 @@ public final class BluetoothSocket implements Closeable {
mInputStream = new BluetoothInputStream(this);
mOutputStream = new BluetoothOutputStream(this);
}
+
private BluetoothSocket(BluetoothSocket s) {
if (VDBG) Log.d(TAG, "Creating new Private BluetoothSocket of type: " + s.mType);
mUuid = s.mUuid;
@@ -231,12 +234,13 @@ public final class BluetoothSocket implements Closeable {
mAuthMitm = s.mAuthMitm;
mMin16DigitPin = s.mMin16DigitPin;
}
- private BluetoothSocket acceptSocket(String RemoteAddr) throws IOException {
+
+ private BluetoothSocket acceptSocket(String remoteAddr) throws IOException {
BluetoothSocket as = new BluetoothSocket(this);
as.mSocketState = SocketState.CONNECTED;
FileDescriptor[] fds = mSocket.getAncillaryFileDescriptors();
if (DBG) Log.d(TAG, "socket fd passed by stack fds: " + Arrays.toString(fds));
- if(fds == null || fds.length != 1) {
+ if (fds == null || fds.length != 1) {
Log.e(TAG, "socket fd passed from stack failed, fds: " + Arrays.toString(fds));
as.close();
throw new IOException("bt socket acept failed");
@@ -246,20 +250,22 @@ public final class BluetoothSocket implements Closeable {
as.mSocket = LocalSocket.createConnectedLocalSocket(fds[0]);
as.mSocketIS = as.mSocket.getInputStream();
as.mSocketOS = as.mSocket.getOutputStream();
- as.mAddress = RemoteAddr;
- as.mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(RemoteAddr);
+ as.mAddress = remoteAddr;
+ as.mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(remoteAddr);
return as;
}
+
/**
* Construct a BluetoothSocket from address. Used by native code.
- * @param type type of socket
- * @param fd fd to use for connected socket, or -1 for a new socket
- * @param auth require the remote device to be authenticated
+ *
+ * @param type type of socket
+ * @param fd fd to use for connected socket, or -1 for a new socket
+ * @param auth require the remote device to be authenticated
* @param encrypt require the connection to be encrypted
* @param address remote device that this socket can connect to
- * @param port remote port
- * @throws IOException On error, for example Bluetooth not available, or
- * insufficient privileges
+ * @param port remote port
+ * @throws IOException On error, for example Bluetooth not available, or insufficient
+ * privileges
*/
private BluetoothSocket(int type, int fd, boolean auth, boolean encrypt, String address,
int port) throws IOException {
@@ -275,23 +281,30 @@ public final class BluetoothSocket implements Closeable {
super.finalize();
}
}
+
private int getSecurityFlags() {
int flags = 0;
- if(mAuth)
+ if (mAuth) {
flags |= SEC_FLAG_AUTH;
- if(mEncrypt)
+ }
+ if (mEncrypt) {
flags |= SEC_FLAG_ENCRYPT;
- if(mExcludeSdp)
+ }
+ if (mExcludeSdp) {
flags |= BTSOCK_FLAG_NO_SDP;
- if(mAuthMitm)
+ }
+ if (mAuthMitm) {
flags |= SEC_FLAG_AUTH_MITM;
- if(mMin16DigitPin)
+ }
+ if (mMin16DigitPin) {
flags |= SEC_FLAG_AUTH_16_DIGIT;
+ }
return flags;
}
/**
* Get the remote device this socket is connecting, or connected, to.
+ *
* @return remote device
*/
public BluetoothDevice getRemoteDevice() {
@@ -303,6 +316,7 @@ public final class BluetoothSocket implements Closeable {
* The input stream will be returned even if the socket is not yet
* connected, but operations on that stream will throw IOException until
* the associated socket is connected.
+ *
* @return InputStream
*/
public InputStream getInputStream() throws IOException {
@@ -314,6 +328,7 @@ public final class BluetoothSocket implements Closeable {
* The output stream will be returned even if the socket is not yet
* connected, but operations on that stream will throw IOException until
* the associated socket is connected.
+ *
* @return OutputStream
*/
public OutputStream getOutputStream() throws IOException {
@@ -323,8 +338,8 @@ public final class BluetoothSocket implements Closeable {
/**
* Get the connection status of this socket, ie, whether there is an active connection with
* remote device.
- * @return true if connected
- * false if not connected
+ *
+ * @return true if connected false if not connected
*/
public boolean isConnected() {
return mSocketState == SocketState.CONNECTED;
@@ -349,6 +364,7 @@ public final class BluetoothSocket implements Closeable {
* {@link BluetoothAdapter#cancelDiscovery()} even if it
* did not directly request a discovery, just to be sure.
* {@link #close} can be used to abort this call from another thread.
+ *
* @throws IOException on error, for example connection failure
*/
public void connect() throws IOException {
@@ -361,8 +377,7 @@ public final class BluetoothSocket implements Closeable {
if (bluetoothProxy == null) throw new IOException("Bluetooth is off");
mPfd = bluetoothProxy.connectSocket(mDevice, mType,
mUuid, mPort, getSecurityFlags());
- synchronized(this)
- {
+ synchronized (this) {
if (DBG) Log.d(TAG, "connect(), SocketState: " + mSocketState + ", mPfd: " + mPfd);
if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
if (mPfd == null) throw new IOException("bt socket connect failed");
@@ -372,14 +387,15 @@ public final class BluetoothSocket implements Closeable {
mSocketOS = mSocket.getOutputStream();
}
int channel = readInt(mSocketIS);
- if (channel <= 0)
+ if (channel <= 0) {
throw new IOException("bt socket connect failed");
+ }
mPort = channel;
waitSocketSignal(mSocketIS);
- synchronized(this)
- {
- if (mSocketState == SocketState.CLOSED)
+ synchronized (this) {
+ if (mSocketState == SocketState.CLOSED) {
throw new IOException("bt socket closed");
+ }
mSocketState = SocketState.CONNECTED;
}
} catch (RemoteException e) {
@@ -410,11 +426,12 @@ public final class BluetoothSocket implements Closeable {
// read out port number
try {
- synchronized(this) {
- if (DBG) Log.d(TAG, "bindListen(), SocketState: " + mSocketState + ", mPfd: " +
- mPfd);
- if(mSocketState != SocketState.INIT) return EBADFD;
- if(mPfd == null) return -1;
+ synchronized (this) {
+ if (DBG) {
+ Log.d(TAG, "bindListen(), SocketState: " + mSocketState + ", mPfd: " + mPfd);
+ }
+ if (mSocketState != SocketState.INIT) return EBADFD;
+ if (mPfd == null) return -1;
FileDescriptor fd = mPfd.getFileDescriptor();
if (fd == null) {
Log.e(TAG, "bindListen(), null file descriptor");
@@ -429,9 +446,10 @@ public final class BluetoothSocket implements Closeable {
}
if (DBG) Log.d(TAG, "bindListen(), readInt mSocketIS: " + mSocketIS);
int channel = readInt(mSocketIS);
- synchronized(this) {
- if(mSocketState == SocketState.INIT)
+ synchronized (this) {
+ if (mSocketState == SocketState.INIT) {
mSocketState = SocketState.LISTENING;
+ }
}
if (DBG) Log.d(TAG, "channel: " + channel);
if (mPort <= -1) {
@@ -455,19 +473,21 @@ public final class BluetoothSocket implements Closeable {
/*package*/ BluetoothSocket accept(int timeout) throws IOException {
BluetoothSocket acceptedSocket;
- if (mSocketState != SocketState.LISTENING)
+ if (mSocketState != SocketState.LISTENING) {
throw new IOException("bt socket is not in listen state");
- if(timeout > 0) {
+ }
+ if (timeout > 0) {
Log.d(TAG, "accept() set timeout (ms):" + timeout);
- mSocket.setSoTimeout(timeout);
+ mSocket.setSoTimeout(timeout);
}
String RemoteAddr = waitSocketSignal(mSocketIS);
- if(timeout > 0)
+ if (timeout > 0) {
mSocket.setSoTimeout(0);
- synchronized(this)
- {
- if (mSocketState != SocketState.LISTENING)
+ }
+ synchronized (this) {
+ if (mSocketState != SocketState.LISTENING) {
throw new IOException("bt socket is not in listen state");
+ }
acceptedSocket = acceptSocket(RemoteAddr);
//quick drop the reference of the file handle
}
@@ -478,12 +498,13 @@ public final class BluetoothSocket implements Closeable {
if (VDBG) Log.d(TAG, "available: " + mSocketIS);
return mSocketIS.available();
}
+
/**
* Wait until the data in sending queue is emptied. A polling version
* for flush implementation. Used to ensure the writing data afterwards will
* be packed in new RFCOMM frame.
- * @throws IOException
- * if an i/o error occurs.
+ *
+ * @throws IOException if an i/o error occurs.
*/
/*package*/ void flush() throws IOException {
if (mSocketOS == null) throw new IOException("flush is called on null OutputStream");
@@ -494,11 +515,12 @@ public final class BluetoothSocket implements Closeable {
/*package*/ int read(byte[] b, int offset, int length) throws IOException {
int ret = 0;
if (VDBG) Log.d(TAG, "read in: " + mSocketIS + " len: " + length);
- if(mType == TYPE_L2CAP)
- {
+ if (mType == TYPE_L2CAP) {
int bytesToRead = length;
- if (VDBG) Log.v(TAG, "l2cap: read(): offset: " + offset + " length:" + length
- + "mL2capBuffer= " + mL2capBuffer);
+ if (VDBG) {
+ Log.v(TAG, "l2cap: read(): offset: " + offset + " length:" + length
+ + "mL2capBuffer= " + mL2capBuffer);
+ }
if (mL2capBuffer == null) {
createL2capRxBuffer();
}
@@ -511,16 +533,19 @@ public final class BluetoothSocket implements Closeable {
if (bytesToRead > mL2capBuffer.remaining()) {
bytesToRead = mL2capBuffer.remaining();
}
- if(VDBG) Log.v(TAG, "get(): offset: " + offset
- + " bytesToRead: " + bytesToRead);
+ if (VDBG) {
+ Log.v(TAG, "get(): offset: " + offset
+ + " bytesToRead: " + bytesToRead);
+ }
mL2capBuffer.get(b, offset, bytesToRead);
ret = bytesToRead;
- }else {
+ } else {
if (VDBG) Log.v(TAG, "default: read(): offset: " + offset + " length:" + length);
ret = mSocketIS.read(b, offset, length);
}
- if (ret < 0)
+ if (ret < 0) {
throw new IOException("bt socket closed, read return: " + ret);
+ }
if (VDBG) Log.d(TAG, "read out: " + mSocketIS + " ret: " + ret);
return ret;
}
@@ -532,48 +557,49 @@ public final class BluetoothSocket implements Closeable {
// splitting the write into multiple smaller writes.
// Rfcomm uses dynamic allocation, and should not have any bindings
// to the actual message length.
- if (VDBG) Log.d(TAG, "write: " + mSocketOS + " length: " + length);
- if (mType == TYPE_L2CAP) {
- if(length <= mMaxTxPacketSize) {
- mSocketOS.write(b, offset, length);
- } else {
- if(DBG) Log.w(TAG, "WARNING: Write buffer larger than L2CAP packet size!\n"
+ if (VDBG) Log.d(TAG, "write: " + mSocketOS + " length: " + length);
+ if (mType == TYPE_L2CAP) {
+ if (length <= mMaxTxPacketSize) {
+ mSocketOS.write(b, offset, length);
+ } else {
+ if (DBG) {
+ Log.w(TAG, "WARNING: Write buffer larger than L2CAP packet size!\n"
+ "Packet will be divided into SDU packets of size "
+ mMaxTxPacketSize);
- int tmpOffset = offset;
- int bytesToWrite = length;
- while (bytesToWrite > 0) {
- int tmpLength = (bytesToWrite > mMaxTxPacketSize)
- ? mMaxTxPacketSize
- : bytesToWrite;
- mSocketOS.write(b, tmpOffset, tmpLength);
- tmpOffset += tmpLength;
- bytesToWrite -= tmpLength;
- }
}
- } else {
- mSocketOS.write(b, offset, length);
+ int tmpOffset = offset;
+ int bytesToWrite = length;
+ while (bytesToWrite > 0) {
+ int tmpLength = (bytesToWrite > mMaxTxPacketSize)
+ ? mMaxTxPacketSize
+ : bytesToWrite;
+ mSocketOS.write(b, tmpOffset, tmpLength);
+ tmpOffset += tmpLength;
+ bytesToWrite -= tmpLength;
+ }
}
- // There is no good way to confirm since the entire process is asynchronous anyway
- if (VDBG) Log.d(TAG, "write out: " + mSocketOS + " length: " + length);
- return length;
+ } else {
+ mSocketOS.write(b, offset, length);
+ }
+ // There is no good way to confirm since the entire process is asynchronous anyway
+ if (VDBG) Log.d(TAG, "write out: " + mSocketOS + " length: " + length);
+ return length;
}
@Override
public void close() throws IOException {
- Log.d(TAG, "close() this: " + this + ", channel: " + mPort +
- ", mSocketIS: " + mSocketIS + ", mSocketOS: " + mSocketOS +
- "mSocket: " + mSocket + ", mSocketState: " + mSocketState);
- if(mSocketState == SocketState.CLOSED)
+ Log.d(TAG, "close() this: " + this + ", channel: " + mPort + ", mSocketIS: " + mSocketIS
+ + ", mSocketOS: " + mSocketOS + "mSocket: " + mSocket + ", mSocketState: "
+ + mSocketState);
+ if (mSocketState == SocketState.CLOSED) {
return;
- else
- {
- synchronized(this)
- {
- if(mSocketState == SocketState.CLOSED)
+ } else {
+ synchronized (this) {
+ if (mSocketState == SocketState.CLOSED) {
return;
- mSocketState = SocketState.CLOSED;
- if(mSocket != null) {
+ }
+ mSocketState = SocketState.CLOSED;
+ if (mSocket != null) {
if (DBG) Log.d(TAG, "Closing mSocket: " + mSocket);
mSocket.shutdownInput();
mSocket.shutdownOutput();
@@ -584,7 +610,7 @@ public final class BluetoothSocket implements Closeable {
mPfd.close();
mPfd = null;
}
- }
+ }
}
}
@@ -599,9 +625,10 @@ public final class BluetoothSocket implements Closeable {
* Get the maximum supported Transmit packet size for the underlying transport.
* Use this to optimize the writes done to the output socket, to avoid sending
* half full packets.
+ *
* @return the maximum supported Transmit packet size for the underlying transport.
*/
- public int getMaxTransmitPacketSize(){
+ public int getMaxTransmitPacketSize() {
return mMaxTxPacketSize;
}
@@ -610,14 +637,16 @@ public final class BluetoothSocket implements Closeable {
* Use this to optimize the reads done on the input stream, as any call to read
* will return a maximum of this amount of bytes - or for some transports a
* multiple of this value.
+ *
* @return the maximum supported Receive packet size for the underlying transport.
*/
- public int getMaxReceivePacketSize(){
+ public int getMaxReceivePacketSize() {
return mMaxRxPacketSize;
}
/**
* Get the type of the underlying connection.
+ *
* @return one of {@link #TYPE_RFCOMM}, {@link #TYPE_SCO} or {@link #TYPE_L2CAP}
*/
public int getConnectionType() {
@@ -627,67 +656,77 @@ public final class BluetoothSocket implements Closeable {
/**
* Change if a SDP entry should be automatically created.
* Must be called before calling .bind, for the call to have any effect.
- * @param mExcludeSdp
* Advertising data must be empty if non-legacy scannable advertising is used.
*
- * @param advertiseData Advertisement data to be broadcasted. Size must not exceed
- * {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
- * advertisement is connectable, three bytes will be added for flags. If the
- * update takes place when the advertising set is enabled, the data can be
- * maximum 251 bytes long.
+ * @param advertiseData Advertisement data to be broadcasted. Size must not exceed {@link
+ * BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the advertisement is connectable,
+ * three bytes will be added for flags. If the update takes place when the advertising set is
+ * enabled, the data can be maximum 251 bytes long.
*/
public void setAdvertisingData(AdvertiseData advertiseData) {
try {
- gatt.setAdvertisingData(this.advertiserId, advertiseData);
+ mGatt.setAdvertisingData(mAdvertiserId, advertiseData);
} catch (RemoteException e) {
Log.e(TAG, "remote exception - ", e);
}
@@ -107,13 +104,12 @@ public final class AdvertisingSet {
* is delivered through {@code callback.onScanResponseDataSet()}.
*
* @param scanResponse Scan response associated with the advertisement data. Size must not
- * exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
- * update takes place when the advertising set is enabled, the data can be
- * maximum 251 bytes long.
+ * exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the update takes place
+ * when the advertising set is enabled, the data can be maximum 251 bytes long.
*/
public void setScanResponseData(AdvertiseData scanResponse) {
try {
- gatt.setScanResponseData(this.advertiserId, scanResponse);
+ mGatt.setScanResponseData(mAdvertiserId, scanResponse);
} catch (RemoteException e) {
Log.e(TAG, "remote exception - ", e);
}
@@ -128,7 +124,7 @@ public final class AdvertisingSet {
*/
public void setAdvertisingParameters(AdvertisingSetParameters parameters) {
try {
- gatt.setAdvertisingParameters(this.advertiserId, parameters);
+ mGatt.setAdvertisingParameters(mAdvertiserId, parameters);
} catch (RemoteException e) {
Log.e(TAG, "remote exception - ", e);
}
@@ -141,7 +137,7 @@ public final class AdvertisingSet {
*/
public void setPeriodicAdvertisingParameters(PeriodicAdvertisingParameters parameters) {
try {
- gatt.setPeriodicAdvertisingParameters(this.advertiserId, parameters);
+ mGatt.setPeriodicAdvertisingParameters(mAdvertiserId, parameters);
} catch (RemoteException e) {
Log.e(TAG, "remote exception - ", e);
}
@@ -153,14 +149,13 @@ public final class AdvertisingSet {
* immediately, the operation status is delivered through
* {@code callback.onPeriodicAdvertisingDataSet()}.
*
- * @param periodicData Periodic advertising data. Size must not exceed
- * {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
- * update takes place when the periodic advertising is enabled for this set,
- * the data can be maximum 251 bytes long.
+ * @param periodicData Periodic advertising data. Size must not exceed {@link
+ * BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the update takes place when the
+ * periodic advertising is enabled for this set, the data can be maximum 251 bytes long.
*/
public void setPeriodicAdvertisingData(AdvertiseData periodicData) {
try {
- gatt.setPeriodicAdvertisingData(this.advertiserId, periodicData);
+ mGatt.setPeriodicAdvertisingData(mAdvertiserId, periodicData);
} catch (RemoteException e) {
Log.e(TAG, "remote exception - ", e);
}
@@ -170,11 +165,12 @@ public final class AdvertisingSet {
* Used to enable/disable periodic advertising. This method returns immediately, the operation
* status is delivered through {@code callback.onPeriodicAdvertisingEnable()}.
*
- * @param enable whether the periodic advertising should be enabled (true), or disabled (false).
+ * @param enable whether the periodic advertising should be enabled (true), or disabled
+ * (false).
*/
public void setPeriodicAdvertisingEnabled(boolean enable) {
try {
- gatt.setPeriodicAdvertisingEnable(this.advertiserId, enable);
+ mGatt.setPeriodicAdvertisingEnable(mAdvertiserId, enable);
} catch (RemoteException e) {
Log.e(TAG, "remote exception - ", e);
}
@@ -186,11 +182,12 @@ public final class AdvertisingSet {
* should ever use it.
*
* This method requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED} permission.
+ *
* @hide
*/
- public void getOwnAddress(){
+ public void getOwnAddress() {
try {
- gatt.getOwnAddress(this.advertiserId);
+ mGatt.getOwnAddress(mAdvertiserId);
} catch (RemoteException e) {
Log.e(TAG, "remote exception - ", e);
}
@@ -201,7 +198,7 @@ public final class AdvertisingSet {
*
* @hide
*/
- public int getAdvertiserId(){
- return advertiserId;
+ public int getAdvertiserId() {
+ return mAdvertiserId;
}
-}
\ No newline at end of file
+}
diff --git a/core/java/android/bluetooth/le/AdvertisingSetCallback.java b/core/java/android/bluetooth/le/AdvertisingSetCallback.java
index c3c16a479e718..58a3696fc0926 100644
--- a/core/java/android/bluetooth/le/AdvertisingSetCallback.java
+++ b/core/java/android/bluetooth/le/AdvertisingSetCallback.java
@@ -16,8 +16,6 @@
package android.bluetooth.le;
-import android.bluetooth.BluetoothDevice;
-
/**
* Bluetooth LE advertising set callbacks, used to deliver advertising operation
* status.
@@ -65,7 +63,8 @@ public abstract class AdvertisingSetCallback {
* @param txPower tx power that will be used for this set.
* @param status Status of the operation.
*/
- public void onAdvertisingSetStarted(AdvertisingSet advertisingSet, int txPower, int status) {}
+ public void onAdvertisingSetStarted(AdvertisingSet advertisingSet, int txPower, int status) {
+ }
/**
* Callback triggered in response to {@link BluetoothLeAdvertiser#stopAdvertisingSet}
@@ -73,16 +72,19 @@ public abstract class AdvertisingSetCallback {
*
* @param advertisingSet The advertising set.
*/
- public void onAdvertisingSetStopped(AdvertisingSet advertisingSet) {}
+ public void onAdvertisingSetStopped(AdvertisingSet advertisingSet) {
+ }
/**
- * Callback triggered in response to {@link BluetoothLeAdvertiser#startAdvertisingSet} indicating
- * result of the operation. If status is ADVERTISE_SUCCESS, then advertising set is advertising.
+ * Callback triggered in response to {@link BluetoothLeAdvertiser#startAdvertisingSet}
+ * indicating result of the operation. If status is ADVERTISE_SUCCESS, then advertising set is
+ * advertising.
*
* @param advertisingSet The advertising set.
* @param status Status of the operation.
*/
- public void onAdvertisingEnabled(AdvertisingSet advertisingSet, boolean enable, int status) {}
+ public void onAdvertisingEnabled(AdvertisingSet advertisingSet, boolean enable, int status) {
+ }
/**
* Callback triggered in response to {@link AdvertisingSet#setAdvertisingData} indicating
@@ -91,7 +93,8 @@ public abstract class AdvertisingSetCallback {
* @param advertisingSet The advertising set.
* @param status Status of the operation.
*/
- public void onAdvertisingDataSet(AdvertisingSet advertisingSet, int status) {}
+ public void onAdvertisingDataSet(AdvertisingSet advertisingSet, int status) {
+ }
/**
* Callback triggered in response to {@link AdvertisingSet#setAdvertisingData} indicating
@@ -100,7 +103,8 @@ public abstract class AdvertisingSetCallback {
* @param advertisingSet The advertising set.
* @param status Status of the operation.
*/
- public void onScanResponseDataSet(AdvertisingSet advertisingSet, int status) {}
+ public void onScanResponseDataSet(AdvertisingSet advertisingSet, int status) {
+ }
/**
* Callback triggered in response to {@link AdvertisingSet#setAdvertisingParameters}
@@ -111,7 +115,8 @@ public abstract class AdvertisingSetCallback {
* @param status Status of the operation.
*/
public void onAdvertisingParametersUpdated(AdvertisingSet advertisingSet,
- int txPower, int status) {}
+ int txPower, int status) {
+ }
/**
* Callback triggered in response to {@link AdvertisingSet#setPeriodicAdvertisingParameters}
@@ -120,9 +125,8 @@ public abstract class AdvertisingSetCallback {
* @param advertisingSet The advertising set.
* @param status Status of the operation.
*/
- public void
- onPeriodicAdvertisingParametersUpdated(AdvertisingSet advertisingSet,
- int status) {}
+ public void onPeriodicAdvertisingParametersUpdated(AdvertisingSet advertisingSet, int status) {
+ }
/**
* Callback triggered in response to {@link AdvertisingSet#setPeriodicAdvertisingData}
@@ -132,7 +136,8 @@ public abstract class AdvertisingSetCallback {
* @param status Status of the operation.
*/
public void onPeriodicAdvertisingDataSet(AdvertisingSet advertisingSet,
- int status) {}
+ int status) {
+ }
/**
* Callback triggered in response to {@link AdvertisingSet#setPeriodicAdvertisingEnabled}
@@ -142,7 +147,8 @@ public abstract class AdvertisingSetCallback {
* @param status Status of the operation.
*/
public void onPeriodicAdvertisingEnabled(AdvertisingSet advertisingSet, boolean enable,
- int status) {}
+ int status) {
+ }
/**
* Callback triggered in response to {@link AdvertisingSet#getOwnAddress()}
@@ -153,5 +159,6 @@ public abstract class AdvertisingSetCallback {
* @param address advertising set bluetooth address.
* @hide
*/
- public void onOwnAddressRead(AdvertisingSet advertisingSet, int addressType, String address) {}
-}
\ No newline at end of file
+ public void onOwnAddressRead(AdvertisingSet advertisingSet, int addressType, String address) {
+ }
+}
diff --git a/core/java/android/bluetooth/le/AdvertisingSetParameters.java b/core/java/android/bluetooth/le/AdvertisingSetParameters.java
index e9747d8205bf8..0c0291eb0ed34 100644
--- a/core/java/android/bluetooth/le/AdvertisingSetParameters.java
+++ b/core/java/android/bluetooth/le/AdvertisingSetParameters.java
@@ -31,9 +31,9 @@ import android.os.Parcelable;
public final class AdvertisingSetParameters implements Parcelable {
/**
- * Advertise on low frequency, around every 1000ms. This is the default and
- * preferred advertising mode as it consumes the least power.
- */
+ * Advertise on low frequency, around every 1000ms. This is the default and
+ * preferred advertising mode as it consumes the least power.
+ */
public static final int INTERVAL_HIGH = 1600;
/**
@@ -97,156 +97,174 @@ public final class AdvertisingSetParameters implements Parcelable {
*/
private static final int LIMITED_ADVERTISING_MAX_MILLIS = 180 * 1000;
- private final boolean isLegacy;
- private final boolean isAnonymous;
- private final boolean includeTxPower;
- private final int primaryPhy;
- private final int secondaryPhy;
- private final boolean connectable;
- private final boolean scannable;
- private final int interval;
- private final int txPowerLevel;
+ private final boolean mIsLegacy;
+ private final boolean mIsAnonymous;
+ private final boolean mIncludeTxPower;
+ private final int mPrimaryPhy;
+ private final int mSecondaryPhy;
+ private final boolean mConnectable;
+ private final boolean mScannable;
+ private final int mInterval;
+ private final int mTxPowerLevel;
private AdvertisingSetParameters(boolean connectable, boolean scannable, boolean isLegacy,
- boolean isAnonymous, boolean includeTxPower,
- int primaryPhy, int secondaryPhy,
- int interval, int txPowerLevel) {
- this.connectable = connectable;
- this.scannable = scannable;
- this.isLegacy = isLegacy;
- this.isAnonymous = isAnonymous;
- this.includeTxPower = includeTxPower;
- this.primaryPhy = primaryPhy;
- this.secondaryPhy = secondaryPhy;
- this.interval = interval;
- this.txPowerLevel = txPowerLevel;
+ boolean isAnonymous, boolean includeTxPower,
+ int primaryPhy, int secondaryPhy,
+ int interval, int txPowerLevel) {
+ mConnectable = connectable;
+ mScannable = scannable;
+ mIsLegacy = isLegacy;
+ mIsAnonymous = isAnonymous;
+ mIncludeTxPower = includeTxPower;
+ mPrimaryPhy = primaryPhy;
+ mSecondaryPhy = secondaryPhy;
+ mInterval = interval;
+ mTxPowerLevel = txPowerLevel;
}
private AdvertisingSetParameters(Parcel in) {
- connectable = in.readInt() != 0 ? true : false;
- scannable = in.readInt() != 0 ? true : false;
- isLegacy = in.readInt() != 0 ? true : false;
- isAnonymous = in.readInt() != 0 ? true : false;
- includeTxPower = in.readInt() != 0 ? true : false;
- primaryPhy = in.readInt();
- secondaryPhy = in.readInt();
- interval = in.readInt();
- txPowerLevel = in.readInt();
+ mConnectable = in.readInt() != 0;
+ mScannable = in.readInt() != 0;
+ mIsLegacy = in.readInt() != 0;
+ mIsAnonymous = in.readInt() != 0;
+ mIncludeTxPower = in.readInt() != 0;
+ mPrimaryPhy = in.readInt();
+ mSecondaryPhy = in.readInt();
+ mInterval = in.readInt();
+ mTxPowerLevel = in.readInt();
}
/**
* Returns whether the advertisement will be connectable.
*/
- public boolean isConnectable() { return connectable; }
+ public boolean isConnectable() {
+ return mConnectable;
+ }
/**
* Returns whether the advertisement will be scannable.
*/
- public boolean isScannable() { return scannable; }
+ public boolean isScannable() {
+ return mScannable;
+ }
/**
* Returns whether the legacy advertisement will be used.
*/
- public boolean isLegacy() { return isLegacy; }
+ public boolean isLegacy() {
+ return mIsLegacy;
+ }
/**
* Returns whether the advertisement will be anonymous.
*/
- public boolean isAnonymous() { return isAnonymous; }
+ public boolean isAnonymous() {
+ return mIsAnonymous;
+ }
/**
* Returns whether the TX Power will be included.
*/
- public boolean includeTxPower() { return includeTxPower; }
+ public boolean includeTxPower() {
+ return mIncludeTxPower;
+ }
/**
* Returns the primary advertising phy.
*/
- public int getPrimaryPhy() { return primaryPhy; }
+ public int getPrimaryPhy() {
+ return mPrimaryPhy;
+ }
/**
* Returns the secondary advertising phy.
*/
- public int getSecondaryPhy() { return secondaryPhy; }
+ public int getSecondaryPhy() {
+ return mSecondaryPhy;
+ }
/**
* Returns the advertising interval.
*/
- public int getInterval() { return interval; }
+ public int getInterval() {
+ return mInterval;
+ }
/**
* Returns the TX power level for advertising.
*/
- public int getTxPowerLevel() { return txPowerLevel; }
+ public int getTxPowerLevel() {
+ return mTxPowerLevel;
+ }
@Override
public String toString() {
- return "AdvertisingSetParameters [connectable=" + connectable
- + ", isLegacy=" + isLegacy
- + ", isAnonymous=" + isAnonymous
- + ", includeTxPower=" + includeTxPower
- + ", primaryPhy=" + primaryPhy
- + ", secondaryPhy=" + secondaryPhy
- + ", interval=" + interval
- + ", txPowerLevel=" + txPowerLevel + "]";
+ return "AdvertisingSetParameters [connectable=" + mConnectable
+ + ", isLegacy=" + mIsLegacy
+ + ", isAnonymous=" + mIsAnonymous
+ + ", includeTxPower=" + mIncludeTxPower
+ + ", primaryPhy=" + mPrimaryPhy
+ + ", secondaryPhy=" + mSecondaryPhy
+ + ", interval=" + mInterval
+ + ", txPowerLevel=" + mTxPowerLevel + "]";
}
@Override
public int describeContents() {
- return 0;
+ return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
- dest.writeInt(connectable ? 1 : 0);
- dest.writeInt(scannable ? 1 : 0);
- dest.writeInt(isLegacy ? 1 : 0);
- dest.writeInt(isAnonymous ? 1 : 0);
- dest.writeInt(includeTxPower ? 1 : 0);
- dest.writeInt(primaryPhy);
- dest.writeInt(secondaryPhy);
- dest.writeInt(interval);
- dest.writeInt(txPowerLevel);
+ dest.writeInt(mConnectable ? 1 : 0);
+ dest.writeInt(mScannable ? 1 : 0);
+ dest.writeInt(mIsLegacy ? 1 : 0);
+ dest.writeInt(mIsAnonymous ? 1 : 0);
+ dest.writeInt(mIncludeTxPower ? 1 : 0);
+ dest.writeInt(mPrimaryPhy);
+ dest.writeInt(mSecondaryPhy);
+ dest.writeInt(mInterval);
+ dest.writeInt(mTxPowerLevel);
}
public static final Parcelable.Creator
+ *
* @param parameters advertising set parameters.
- * @param advertiseData Advertisement data to be broadcasted. Size must not exceed
- * {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
- * advertisement is connectable, three bytes will be added for flags.
+ * @param advertiseData Advertisement data to be broadcasted. Size must not exceed {@link
+ * BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the advertisement is connectable,
+ * three bytes will be added for flags.
* @param scanResponse Scan response associated with the advertisement data. Size must not
- * exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
+ * exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
* @param periodicParameters periodic advertisng parameters. If null, periodic advertising will
- * not be started.
- * @param periodicData Periodic advertising data. Size must not exceed
- * {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
+ * not be started.
+ * @param periodicData Periodic advertising data. Size must not exceed {@link
+ * BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
* @param callback Callback for advertising set.
* @throws IllegalArgumentException when any of the data parameter exceed the maximum allowable
- * size, or unsupported advertising PHY is selected, or when attempt to use
- * Periodic Advertising feature is made when it's not supported by the
- * controller.
+ * size, or unsupported advertising PHY is selected, or when attempt to use Periodic Advertising
+ * feature is made when it's not supported by the controller.
*/
public void startAdvertisingSet(AdvertisingSetParameters parameters,
- AdvertiseData advertiseData, AdvertiseData scanResponse,
- PeriodicAdvertisingParameters periodicParameters,
- AdvertiseData periodicData, AdvertisingSetCallback callback) {
- startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
- periodicData, 0, 0, callback, new Handler(Looper.getMainLooper()));
+ AdvertiseData advertiseData, AdvertiseData scanResponse,
+ PeriodicAdvertisingParameters periodicParameters,
+ AdvertiseData periodicData, AdvertisingSetCallback callback) {
+ startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
+ periodicData, 0, 0, callback, new Handler(Looper.getMainLooper()));
}
/**
@@ -247,30 +245,30 @@ public final class BluetoothLeAdvertiser {
* method returns immediately, the operation status is delivered through
* {@code callback.onAdvertisingSetStarted()}.
*
+ *
* @param parameters advertising set parameters.
- * @param advertiseData Advertisement data to be broadcasted. Size must not exceed
- * {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
- * advertisement is connectable, three bytes will be added for flags.
+ * @param advertiseData Advertisement data to be broadcasted. Size must not exceed {@link
+ * BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the advertisement is connectable,
+ * three bytes will be added for flags.
* @param scanResponse Scan response associated with the advertisement data. Size must not
- * exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
+ * exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
* @param periodicParameters periodic advertisng parameters. If null, periodic advertising will
- * not be started.
- * @param periodicData Periodic advertising data. Size must not exceed
- * {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
+ * not be started.
+ * @param periodicData Periodic advertising data. Size must not exceed {@link
+ * BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
* @param callback Callback for advertising set.
* @param handler thread upon which the callbacks will be invoked.
* @throws IllegalArgumentException when any of the data parameter exceed the maximum allowable
- * size, or unsupported advertising PHY is selected, or when attempt to use
- * Periodic Advertising feature is made when it's not supported by the
- * controller.
+ * size, or unsupported advertising PHY is selected, or when attempt to use Periodic Advertising
+ * feature is made when it's not supported by the controller.
*/
public void startAdvertisingSet(AdvertisingSetParameters parameters,
- AdvertiseData advertiseData, AdvertiseData scanResponse,
- PeriodicAdvertisingParameters periodicParameters,
- AdvertiseData periodicData, AdvertisingSetCallback callback,
- Handler handler) {
+ AdvertiseData advertiseData, AdvertiseData scanResponse,
+ PeriodicAdvertisingParameters periodicParameters,
+ AdvertiseData periodicData, AdvertisingSetCallback callback,
+ Handler handler) {
startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
- periodicData, 0, 0, callback, handler);
+ periodicData, 0, 0, callback, handler);
}
/**
@@ -278,37 +276,36 @@ public final class BluetoothLeAdvertiser {
* method returns immediately, the operation status is delivered through
* {@code callback.onAdvertisingSetStarted()}.
*
+ *
* @param parameters advertising set parameters.
- * @param advertiseData Advertisement data to be broadcasted. Size must not exceed
- * {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
- * advertisement is connectable, three bytes will be added for flags.
+ * @param advertiseData Advertisement data to be broadcasted. Size must not exceed {@link
+ * BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the advertisement is connectable,
+ * three bytes will be added for flags.
* @param scanResponse Scan response associated with the advertisement data. Size must not
- * exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
+ * exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
* @param periodicParameters periodic advertisng parameters. If null, periodic advertising will
- * not be started.
- * @param periodicData Periodic advertising data. Size must not exceed
- * {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
- * @param duration advertising duration, in 10ms unit. Valid range is from 1 (10ms) to
- * 65535 (655,350 ms). 0 means advertising should continue until stopped.
+ * not be started.
+ * @param periodicData Periodic advertising data. Size must not exceed {@link
+ * BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
+ * @param duration advertising duration, in 10ms unit. Valid range is from 1 (10ms) to 65535
+ * (655,350 ms). 0 means advertising should continue until stopped.
* @param maxExtendedAdvertisingEvents maximum number of extended advertising events the
- * controller shall attempt to send prior to terminating the extended
- * advertising, even if the duration has not expired. Valid range is
- * from 1 to 255. 0 means no maximum.
+ * controller shall attempt to send prior to terminating the extended advertising, even if the
+ * duration has not expired. Valid range is from 1 to 255. 0 means no maximum.
* @param callback Callback for advertising set.
* @throws IllegalArgumentException when any of the data parameter exceed the maximum allowable
- * size, or unsupported advertising PHY is selected, or when attempt to use
- * Periodic Advertising feature is made when it's not supported by the
- * controller.
+ * size, or unsupported advertising PHY is selected, or when attempt to use Periodic Advertising
+ * feature is made when it's not supported by the controller.
*/
public void startAdvertisingSet(AdvertisingSetParameters parameters,
- AdvertiseData advertiseData, AdvertiseData scanResponse,
- PeriodicAdvertisingParameters periodicParameters,
- AdvertiseData periodicData, int duration,
- int maxExtendedAdvertisingEvents,
- AdvertisingSetCallback callback) {
+ AdvertiseData advertiseData, AdvertiseData scanResponse,
+ PeriodicAdvertisingParameters periodicParameters,
+ AdvertiseData periodicData, int duration,
+ int maxExtendedAdvertisingEvents,
+ AdvertisingSetCallback callback) {
startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
- periodicData, duration, maxExtendedAdvertisingEvents, callback,
- new Handler(Looper.getMainLooper()));
+ periodicData, duration, maxExtendedAdvertisingEvents, callback,
+ new Handler(Looper.getMainLooper()));
}
/**
@@ -316,39 +313,39 @@ public final class BluetoothLeAdvertiser {
* method returns immediately, the operation status is delivered through
* {@code callback.onAdvertisingSetStarted()}.
*
+ *
* @param parameters Advertising set parameters.
- * @param advertiseData Advertisement data to be broadcasted. Size must not exceed
- * {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
- * advertisement is connectable, three bytes will be added for flags.
+ * @param advertiseData Advertisement data to be broadcasted. Size must not exceed {@link
+ * BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the advertisement is connectable,
+ * three bytes will be added for flags.
* @param scanResponse Scan response associated with the advertisement data. Size must not
- * exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}
+ * exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}
* @param periodicParameters Periodic advertisng parameters. If null, periodic advertising will
- * not be started.
- * @param periodicData Periodic advertising data. Size must not exceed
- * {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}
- * @param duration advertising duration, in 10ms unit. Valid range is from 1 (10ms) to
- * 65535 (655,350 ms). 0 means advertising should continue until stopped.
+ * not be started.
+ * @param periodicData Periodic advertising data. Size must not exceed {@link
+ * BluetoothAdapter#getLeMaximumAdvertisingDataLength}
+ * @param duration advertising duration, in 10ms unit. Valid range is from 1 (10ms) to 65535
+ * (655,350 ms). 0 means advertising should continue until stopped.
* @param maxExtendedAdvertisingEvents maximum number of extended advertising events the
- * controller shall attempt to send prior to terminating the extended
- * advertising, even if the duration has not expired. Valid range is
- * from 1 to 255. 0 means no maximum.
+ * controller shall attempt to send prior to terminating the extended advertising, even if the
+ * duration has not expired. Valid range is from 1 to 255. 0 means no maximum.
* @param callback Callback for advertising set.
* @param handler Thread upon which the callbacks will be invoked.
* @throws IllegalArgumentException When any of the data parameter exceed the maximum allowable
- * size, or unsupported advertising PHY is selected, or when attempt to use
- * Periodic Advertising feature is made when it's not supported by the
- * controller, or when maxExtendedAdvertisingEvents is used on a controller
- * that doesn't support the LE Extended Advertising
+ * size, or unsupported advertising PHY is selected, or when attempt to use Periodic Advertising
+ * feature is made when it's not supported by the controller, or when
+ * maxExtendedAdvertisingEvents is used on a controller that doesn't support the LE Extended
+ * Advertising
*/
public void startAdvertisingSet(AdvertisingSetParameters parameters,
- AdvertiseData advertiseData, AdvertiseData scanResponse,
- PeriodicAdvertisingParameters periodicParameters,
- AdvertiseData periodicData, int duration,
- int maxExtendedAdvertisingEvents, AdvertisingSetCallback callback,
- Handler handler) {
+ AdvertiseData advertiseData, AdvertiseData scanResponse,
+ PeriodicAdvertisingParameters periodicParameters,
+ AdvertiseData periodicData, int duration,
+ int maxExtendedAdvertisingEvents, AdvertisingSetCallback callback,
+ Handler handler) {
BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
if (callback == null) {
- throw new IllegalArgumentException("callback cannot be null");
+ throw new IllegalArgumentException("callback cannot be null");
}
boolean isConnectable = parameters.isConnectable();
@@ -370,7 +367,7 @@ public final class BluetoothLeAdvertiser {
}
if ((sphy == BluetoothDevice.PHY_LE_CODED && !supportCodedPhy)
- || (sphy == BluetoothDevice.PHY_LE_2M && !support2MPhy)) {
+ || (sphy == BluetoothDevice.PHY_LE_2M && !support2MPhy)) {
throw new IllegalArgumentException("Unsupported secondary PHY selected");
}
@@ -390,20 +387,20 @@ public final class BluetoothLeAdvertiser {
boolean supportPeriodic = mBluetoothAdapter.isLePeriodicAdvertisingSupported();
if (periodicParameters != null && !supportPeriodic) {
throw new IllegalArgumentException(
- "Controller does not support LE Periodic Advertising");
+ "Controller does not support LE Periodic Advertising");
}
}
if (maxExtendedAdvertisingEvents < 0 || maxExtendedAdvertisingEvents > 255) {
throw new IllegalArgumentException(
- "maxExtendedAdvertisingEvents out of range: " + maxExtendedAdvertisingEvents);
+ "maxExtendedAdvertisingEvents out of range: " + maxExtendedAdvertisingEvents);
}
- if (maxExtendedAdvertisingEvents != 0 &&
- !mBluetoothAdapter.isLePeriodicAdvertisingSupported()) {
+ if (maxExtendedAdvertisingEvents != 0
+ && !mBluetoothAdapter.isLePeriodicAdvertisingSupported()) {
throw new IllegalArgumentException(
- "Can't use maxExtendedAdvertisingEvents with controller that don't support " +
- "LE Extended Advertising");
+ "Can't use maxExtendedAdvertisingEvents with controller that don't support "
+ + "LE Extended Advertising");
}
if (duration < 0 || duration > 65535) {
@@ -412,26 +409,28 @@ public final class BluetoothLeAdvertiser {
IBluetoothGatt gatt;
try {
- gatt = mBluetoothManager.getBluetoothGatt();
+ gatt = mBluetoothManager.getBluetoothGatt();
} catch (RemoteException e) {
- Log.e(TAG, "Failed to get Bluetooth gatt - ", e);
- postStartSetFailure(handler, callback, AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
- return;
+ Log.e(TAG, "Failed to get Bluetooth gatt - ", e);
+ postStartSetFailure(handler, callback,
+ AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
+ return;
}
IAdvertisingSetCallback wrapped = wrap(callback, handler);
if (mCallbackWrappers.putIfAbsent(callback, wrapped) != null) {
throw new IllegalArgumentException(
- "callback instance already associated with advertising");
+ "callback instance already associated with advertising");
}
try {
gatt.startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
- periodicData, duration, maxExtendedAdvertisingEvents, wrapped);
+ periodicData, duration, maxExtendedAdvertisingEvents, wrapped);
} catch (RemoteException e) {
- Log.e(TAG, "Failed to start advertising set - ", e);
- postStartSetFailure(handler, callback, AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
- return;
+ Log.e(TAG, "Failed to start advertising set - ", e);
+ postStartSetFailure(handler, callback,
+ AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
+ return;
}
}
@@ -441,7 +440,7 @@ public final class BluetoothLeAdvertiser {
*/
public void stopAdvertisingSet(AdvertisingSetCallback callback) {
if (callback == null) {
- throw new IllegalArgumentException("callback cannot be null");
+ throw new IllegalArgumentException("callback cannot be null");
}
IAdvertisingSetCallback wrapped = mCallbackWrappers.remove(callback);
@@ -453,9 +452,9 @@ public final class BluetoothLeAdvertiser {
try {
gatt = mBluetoothManager.getBluetoothGatt();
gatt.stopAdvertisingSet(wrapped);
- } catch (RemoteException e) {
+ } catch (RemoteException e) {
Log.e(TAG, "Failed to stop advertising - ", e);
- }
+ }
}
/**
@@ -489,18 +488,16 @@ public final class BluetoothLeAdvertiser {
}
// 16 bit service uuids are grouped into one field when doing advertising.
if (num16BitUuids != 0) {
- size += OVERHEAD_BYTES_PER_FIELD +
- num16BitUuids * BluetoothUuid.UUID_BYTES_16_BIT;
+ size += OVERHEAD_BYTES_PER_FIELD + num16BitUuids * BluetoothUuid.UUID_BYTES_16_BIT;
}
// 32 bit service uuids are grouped into one field when doing advertising.
if (num32BitUuids != 0) {
- size += OVERHEAD_BYTES_PER_FIELD +
- num32BitUuids * BluetoothUuid.UUID_BYTES_32_BIT;
+ size += OVERHEAD_BYTES_PER_FIELD + num32BitUuids * BluetoothUuid.UUID_BYTES_32_BIT;
}
// 128 bit service uuids are grouped into one field when doing advertising.
if (num128BitUuids != 0) {
- size += OVERHEAD_BYTES_PER_FIELD +
- num128BitUuids * BluetoothUuid.UUID_BYTES_128_BIT;
+ size += OVERHEAD_BYTES_PER_FIELD
+ + num128BitUuids * BluetoothUuid.UUID_BYTES_128_BIT;
}
}
for (ParcelUuid uuid : data.getServiceData().keySet()) {
@@ -509,8 +506,8 @@ public final class BluetoothLeAdvertiser {
+ byteLength(data.getServiceData().get(uuid));
}
for (int i = 0; i < data.getManufacturerSpecificData().size(); ++i) {
- size += OVERHEAD_BYTES_PER_FIELD + MANUFACTURER_SPECIFIC_DATA_LENGTH +
- byteLength(data.getManufacturerSpecificData().valueAt(i));
+ size += OVERHEAD_BYTES_PER_FIELD + MANUFACTURER_SPECIFIC_DATA_LENGTH
+ + byteLength(data.getManufacturerSpecificData().valueAt(i));
}
if (data.getIncludeTxPowerLevel()) {
size += OVERHEAD_BYTES_PER_FIELD + 1; // tx power level value is one byte.
@@ -539,7 +536,7 @@ public final class BluetoothLeAdvertiser {
}
AdvertisingSet advertisingSet =
- new AdvertisingSet(advertiserId, mBluetoothManager);
+ new AdvertisingSet(advertiserId, mBluetoothManager);
mAdvertisingSets.put(advertiserId, advertisingSet);
callback.onAdvertisingSetStarted(advertisingSet, txPower, status);
}
@@ -650,13 +647,13 @@ public final class BluetoothLeAdvertiser {
}
private void postStartSetFailure(Handler handler, final AdvertisingSetCallback callback,
- final int error) {
+ final int error) {
handler.post(new Runnable() {
- @Override
- public void run() {
- callback.onAdvertisingSetStarted(null, 0, error);
- }
- });
+ @Override
+ public void run() {
+ callback.onAdvertisingSetStarted(null, 0, error);
+ }
+ });
}
private void postStartFailure(final AdvertiseCallback callback, final int error) {
diff --git a/core/java/android/bluetooth/le/BluetoothLeScanner.java b/core/java/android/bluetooth/le/BluetoothLeScanner.java
index e3bc78e5a2bb4..9a0f70fe9f72f 100644
--- a/core/java/android/bluetooth/le/BluetoothLeScanner.java
+++ b/core/java/android/bluetooth/le/BluetoothLeScanner.java
@@ -62,8 +62,8 @@ public final class BluetoothLeScanner {
* error. In case of error, {@link #EXTRA_ERROR_CODE} will contain the error code and this
* extra will not be available.
*/
- public static final String EXTRA_LIST_SCAN_RESULT
- = "android.bluetooth.le.extra.LIST_SCAN_RESULT";
+ public static final String EXTRA_LIST_SCAN_RESULT =
+ "android.bluetooth.le.extra.LIST_SCAN_RESULT";
/**
* Optional extra indicating the error code, if any. The error code will be one of the
@@ -74,6 +74,7 @@ public final class BluetoothLeScanner {
/**
* Optional extra indicating the callback type, which will be one of
* CALLBACK_TYPE_* constants in {@link ScanSettings}.
+ *
* @see ScanCallback#onScanResult(int, ScanResult)
*/
public static final String EXTRA_CALLBACK_TYPE = "android.bluetooth.le.extra.CALLBACK_TYPE";
@@ -162,13 +163,13 @@ public final class BluetoothLeScanner {
* specify on behalf of which application(s) the work is being done.
*
* @param workSource {@link WorkSource} identifying the application(s) for which to blame for
- * the scan.
+ * the scan.
* @param callback Callback used to deliver scan results.
* @hide
*/
@SystemApi
@RequiresPermission(allOf = {
- Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.UPDATE_DEVICE_STATS })
+ Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.UPDATE_DEVICE_STATS})
public void startScanFromSource(final WorkSource workSource, final ScanCallback callback) {
startScanFromSource(null, new ScanSettings.Builder().build(), workSource, callback);
}
@@ -180,22 +181,22 @@ public final class BluetoothLeScanner {
* @param filters {@link ScanFilter}s for finding exact BLE devices.
* @param settings Settings for the scan.
* @param workSource {@link WorkSource} identifying the application(s) for which to blame for
- * the scan.
+ * the scan.
* @param callback Callback used to deliver scan results.
* @hide
*/
@SystemApi
@RequiresPermission(allOf = {
- Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.UPDATE_DEVICE_STATS })
+ Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.UPDATE_DEVICE_STATS})
public void startScanFromSource(List
* Note: Most of the methods here require
* {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
+ *
* @hide
*/
public final class PeriodicAdvertisingManager {
- private static final String TAG = "PeriodicAdvertisingManager";
+ private static final String TAG = "PeriodicAdvertisingManager";
- private static final int SKIP_MIN = 0;
- private static final int SKIP_MAX = 499;
- private static final int TIMEOUT_MIN = 10;
- private static final int TIMEOUT_MAX = 16384;
+ private static final int SKIP_MIN = 0;
+ private static final int SKIP_MAX = 499;
+ private static final int TIMEOUT_MIN = 10;
+ private static final int TIMEOUT_MAX = 16384;
- private static final int SYNC_STARTING = -1;
+ private static final int SYNC_STARTING = -1;
- private final IBluetoothManager mBluetoothManager;
- private BluetoothAdapter mBluetoothAdapter;
+ private final IBluetoothManager mBluetoothManager;
+ private BluetoothAdapter mBluetoothAdapter;
- /* maps callback, to callback wrapper and sync handle */
- Map
* The {@code serviceDataMask} must have the same length of the {@code serviceData}.
*
- * @throws IllegalArgumentException If {@code serviceDataUuid} is null or
- * {@code serviceDataMask} is {@code null} while {@code serviceData} is not or
- * {@code serviceDataMask} and {@code serviceData} has different length.
+ * @throws IllegalArgumentException If {@code serviceDataUuid} is null or {@code
+ * serviceDataMask} is {@code null} while {@code serviceData} is not or {@code
+ * serviceDataMask} and {@code serviceData} has different length.
*/
public Builder setServiceData(ParcelUuid serviceDataUuid,
byte[] serviceData, byte[] serviceDataMask) {
@@ -563,10 +564,9 @@ public final class ScanFilter implements Parcelable {
*
* The {@code manufacturerDataMask} must have the same length of {@code manufacturerData}.
*
- * @throws IllegalArgumentException If the {@code manufacturerId} is invalid, or
- * {@code manufacturerData} is null while {@code manufacturerDataMask} is not,
- * or {@code manufacturerData} and {@code manufacturerDataMask} have different
- * length.
+ * @throws IllegalArgumentException If the {@code manufacturerId} is invalid, or {@code
+ * manufacturerData} is null while {@code manufacturerDataMask} is not, or {@code
+ * manufacturerData} and {@code manufacturerDataMask} have different length.
*/
public Builder setManufacturerData(int manufacturerId, byte[] manufacturerData,
byte[] manufacturerDataMask) {
diff --git a/core/java/android/bluetooth/le/ScanRecord.java b/core/java/android/bluetooth/le/ScanRecord.java
index 914e8fd9e07f8..f8aaba910b7bd 100644
--- a/core/java/android/bluetooth/le/ScanRecord.java
+++ b/core/java/android/bluetooth/le/ScanRecord.java
@@ -231,9 +231,9 @@ public final class ScanRecord {
case DATA_TYPE_SERVICE_DATA_128_BIT:
int serviceUuidLength = BluetoothUuid.UUID_BYTES_16_BIT;
if (fieldType == DATA_TYPE_SERVICE_DATA_32_BIT) {
- serviceUuidLength = BluetoothUuid.UUID_BYTES_32_BIT;
+ serviceUuidLength = BluetoothUuid.UUID_BYTES_32_BIT;
} else if (fieldType == DATA_TYPE_SERVICE_DATA_128_BIT) {
- serviceUuidLength = BluetoothUuid.UUID_BYTES_128_BIT;
+ serviceUuidLength = BluetoothUuid.UUID_BYTES_128_BIT;
}
byte[] serviceDataUuidBytes = extractBytes(scanRecord, currentPos,
@@ -247,8 +247,8 @@ public final class ScanRecord {
case DATA_TYPE_MANUFACTURER_SPECIFIC_DATA:
// The first two bytes of the manufacturer specific data are
// manufacturer ids in little endian.
- int manufacturerId = ((scanRecord[currentPos + 1] & 0xFF) << 8) +
- (scanRecord[currentPos] & 0xFF);
+ int manufacturerId = ((scanRecord[currentPos + 1] & 0xFF) << 8)
+ + (scanRecord[currentPos] & 0xFF);
byte[] manufacturerDataBytes = extractBytes(scanRecord, currentPos + 2,
dataLength - 2);
manufacturerData.put(manufacturerId, manufacturerDataBytes);
@@ -276,7 +276,8 @@ public final class ScanRecord {
@Override
public String toString() {
return "ScanRecord [mAdvertiseFlags=" + mAdvertiseFlags + ", mServiceUuids=" + mServiceUuids
- + ", mManufacturerSpecificData=" + BluetoothLeUtils.toString(mManufacturerSpecificData)
+ + ", mManufacturerSpecificData=" + BluetoothLeUtils.toString(
+ mManufacturerSpecificData)
+ ", mServiceData=" + BluetoothLeUtils.toString(mServiceData)
+ ", mTxPowerLevel=" + mTxPowerLevel + ", mDeviceName=" + mDeviceName + "]";
}
diff --git a/core/java/android/bluetooth/le/ScanResult.java b/core/java/android/bluetooth/le/ScanResult.java
index e552398e9e267..f87a47fb936bd 100644
--- a/core/java/android/bluetooth/le/ScanResult.java
+++ b/core/java/android/bluetooth/le/ScanResult.java
@@ -98,8 +98,10 @@ public final class ScanResult implements Parcelable {
* @param scanRecord Scan record including both advertising data and scan response data.
* @param rssi Received signal strength.
* @param timestampNanos Timestamp at which the scan result was observed.
- * @deprecated use {@link #ScanResult(BluetoothDevice, int, int, int, int, int, int, int, ScanRecord, long)}
+ * @deprecated use {@link #ScanResult(BluetoothDevice, int, int, int, int, int, int, int,
+ * ScanRecord, long)}
*/
+ @Deprecated
public ScanResult(BluetoothDevice device, ScanRecord scanRecord, int rssi,
long timestampNanos) {
mDevice = device;
@@ -129,8 +131,8 @@ public final class ScanResult implements Parcelable {
* @param timestampNanos Timestamp at which the scan result was observed.
*/
public ScanResult(BluetoothDevice device, int eventType, int primaryPhy, int secondaryPhy,
- int advertisingSid, int txPower, int rssi, int periodicAdvertisingInterval,
- ScanRecord scanRecord, long timestampNanos) {
+ int advertisingSid, int txPower, int rssi, int periodicAdvertisingInterval,
+ ScanRecord scanRecord, long timestampNanos) {
mDevice = device;
mEventType = eventType;
mPrimaryPhy = primaryPhy;
@@ -254,7 +256,9 @@ public final class ScanResult implements Parcelable {
* Can be one of {@link BluetoothDevice#PHY_LE_1M} or
* {@link BluetoothDevice#PHY_LE_CODED}.
*/
- public int getPrimaryPhy() { return mPrimaryPhy; }
+ public int getPrimaryPhy() {
+ return mPrimaryPhy;
+ }
/**
* Returns the secondary Physical Layer
@@ -264,21 +268,27 @@ public final class ScanResult implements Parcelable {
* or {@link ScanResult#PHY_UNUSED} - if the advertisement
* was not received on a secondary physical channel.
*/
- public int getSecondaryPhy() { return mSecondaryPhy; }
+ public int getSecondaryPhy() {
+ return mSecondaryPhy;
+ }
/**
* Returns the advertising set id.
* May return {@link ScanResult#SID_NOT_PRESENT} if
* no set id was is present.
*/
- public int getAdvertisingSid() { return mAdvertisingSid; }
+ public int getAdvertisingSid() {
+ return mAdvertisingSid;
+ }
/**
* Returns the transmit power in dBm.
* Valid range is [-127, 126]. A value of {@link ScanResult#TX_POWER_NOT_PRESENT}
* indicates that the TX power is not present.
*/
- public int getTxPower() { return mTxPower; }
+ public int getTxPower() {
+ return mTxPower;
+ }
/**
* Returns the periodic advertising interval in units of 1.25ms.
@@ -293,9 +303,9 @@ public final class ScanResult implements Parcelable {
@Override
public int hashCode() {
return Objects.hash(mDevice, mRssi, mScanRecord, mTimestampNanos,
- mEventType, mPrimaryPhy, mSecondaryPhy,
- mAdvertisingSid, mTxPower,
- mPeriodicAdvertisingInterval);
+ mEventType, mPrimaryPhy, mSecondaryPhy,
+ mAdvertisingSid, mTxPower,
+ mPeriodicAdvertisingInterval);
}
@Override
@@ -307,34 +317,34 @@ public final class ScanResult implements Parcelable {
return false;
}
ScanResult other = (ScanResult) obj;
- return Objects.equals(mDevice, other.mDevice) && (mRssi == other.mRssi) &&
- Objects.equals(mScanRecord, other.mScanRecord) &&
- (mTimestampNanos == other.mTimestampNanos) &&
- mEventType == other.mEventType &&
- mPrimaryPhy == other.mPrimaryPhy &&
- mSecondaryPhy == other.mSecondaryPhy &&
- mAdvertisingSid == other.mAdvertisingSid &&
- mTxPower == other.mTxPower &&
- mPeriodicAdvertisingInterval == other.mPeriodicAdvertisingInterval;
+ return Objects.equals(mDevice, other.mDevice) && (mRssi == other.mRssi)
+ && Objects.equals(mScanRecord, other.mScanRecord)
+ && (mTimestampNanos == other.mTimestampNanos)
+ && mEventType == other.mEventType
+ && mPrimaryPhy == other.mPrimaryPhy
+ && mSecondaryPhy == other.mSecondaryPhy
+ && mAdvertisingSid == other.mAdvertisingSid
+ && mTxPower == other.mTxPower
+ && mPeriodicAdvertisingInterval == other.mPeriodicAdvertisingInterval;
}
@Override
public String toString() {
- return "ScanResult{" + "device=" + mDevice + ", scanRecord=" +
- Objects.toString(mScanRecord) + ", rssi=" + mRssi +
- ", timestampNanos=" + mTimestampNanos + ", eventType=" + mEventType +
- ", primaryPhy=" + mPrimaryPhy + ", secondaryPhy=" + mSecondaryPhy +
- ", advertisingSid=" + mAdvertisingSid + ", txPower=" + mTxPower +
- ", periodicAdvertisingInterval=" + mPeriodicAdvertisingInterval + '}';
+ return "ScanResult{" + "device=" + mDevice + ", scanRecord="
+ + Objects.toString(mScanRecord) + ", rssi=" + mRssi
+ + ", timestampNanos=" + mTimestampNanos + ", eventType=" + mEventType
+ + ", primaryPhy=" + mPrimaryPhy + ", secondaryPhy=" + mSecondaryPhy
+ + ", advertisingSid=" + mAdvertisingSid + ", txPower=" + mTxPower
+ + ", periodicAdvertisingInterval=" + mPeriodicAdvertisingInterval + '}';
}
public static final Parcelable.Creator
- *
*
*
- *
*
*
- *
*
* Developer Guides
*
- *
*
*
- *
*/
public static final String ACTION_PLAYER_SETTING =
- "android.bluetooth.avrcp-controller.profile.action.PLAYER_SETTING";
+ "android.bluetooth.avrcp-controller.profile.action.PLAYER_SETTING";
public static final String EXTRA_PLAYER_SETTING =
"android.bluetooth.avrcp-controller.profile.extra.PLAYER_SETTING";
@@ -86,39 +84,38 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
private IBluetoothAvrcpController mService;
private BluetoothAdapter mAdapter;
- final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
- new IBluetoothStateChangeCallback.Stub() {
- public void onBluetoothStateChange(boolean up) {
- if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
- if (!up) {
- if (VDBG) Log.d(TAG,"Unbinding service...");
- synchronized (mConnection) {
- try {
- mService = null;
- mContext.unbindService(mConnection);
- } catch (Exception re) {
- Log.e(TAG,"",re);
- }
- }
- } else {
- synchronized (mConnection) {
- try {
- if (mService == null) {
- if (VDBG) Log.d(TAG,"Binding service...");
- doBind();
+ private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
+ new IBluetoothStateChangeCallback.Stub() {
+ public void onBluetoothStateChange(boolean up) {
+ if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
+ if (!up) {
+ if (VDBG) Log.d(TAG, "Unbinding service...");
+ synchronized (mConnection) {
+ try {
+ mService = null;
+ mContext.unbindService(mConnection);
+ } catch (Exception re) {
+ Log.e(TAG, "", re);
+ }
+ }
+ } else {
+ synchronized (mConnection) {
+ try {
+ if (mService == null) {
+ if (VDBG) Log.d(TAG, "Binding service...");
+ doBind();
+ }
+ } catch (Exception re) {
+ Log.e(TAG, "", re);
}
- } catch (Exception re) {
- Log.e(TAG,"",re);
}
}
}
- }
- };
+ };
/**
* Create a BluetoothAvrcpController proxy object for interacting with the local
* Bluetooth AVRCP service.
- *
*/
/*package*/ BluetoothAvrcpController(Context context, ServiceListener l) {
mContext = context;
@@ -129,7 +126,7 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
try {
mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
} catch (RemoteException e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -155,7 +152,7 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
try {
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
} catch (Exception e) {
- Log.e(TAG,"",e);
+ Log.e(TAG, "", e);
}
}
@@ -165,12 +162,13 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
- Log.e(TAG,"",re);
+ Log.e(TAG, "", re);
}
}
}
}
+ @Override
public void finalize() {
close();
}
@@ -178,6 +176,7 @@ public final class BluetoothAvrcpController implements BluetoothProfile {
/**
* {@inheritDoc}
*/
+ @Override
public List
- *
*
*
- *
*
- *
*
- *
*
- *
- *
*
- *
* command + ": " + arg.
- * For example, if {@code command} is {@link #VENDOR_RESULT_CODE_COMMAND_ANDROID} and {@code arg}
- * is {@code "0"}, the string "+ANDROID: 0" will be sent.
+ * command + ": " + arg. For example, if {@code
+ * command} is {@link #VENDOR_RESULT_CODE_COMMAND_ANDROID} and {@code arg} is {@code "0"}, the
+ * string "+ANDROID: 0" will be sent.
*
* true,
- * false.false.true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_CONNECTION_STATE_CHANGED}
- * intent.
+ * @param device a remote device we want connect to
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_CONNECTION_STATE_CHANGED} intent.
*/
public boolean connect(BluetoothDevice device) {
if (DBG) log("connect(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.connect(device);
} catch (RemoteException e) {
@@ -496,21 +493,18 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
/**
* Disconnects remote device
*
- * @param device a remote device we want disconnect
- * @return true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_CONNECTION_STATE_CHANGED}
- * intent.
+ * @param device a remote device we want disconnect
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_CONNECTION_STATE_CHANGED} intent.
*/
public boolean disconnect(BluetoothDevice device) {
if (DBG) log("disconnect(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.disconnect(device);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
- return false;
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ return false;
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -540,10 +534,9 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
/**
* Returns list of remote devices in a particular state
*
- * @param states collection of states
- * @return list of devices that state matches the states listed in
- * states; empty list if nothing matches the
- * states
+ * @param states collection of states
+ * @return list of devices that state matches the states listed in states; empty
+ * list if nothing matches the states
*/
@Override
public Listdevice
*
- * @param device a remote device
- * @return the state of connection of the device
+ * @param device a remote device
+ * @return the state of connection of the device
*/
@Override
public int getConnectionState(BluetoothDevice device) {
if (VDBG) log("getConnectionState(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getConnectionState(device);
} catch (RemoteException e) {
@@ -589,11 +581,10 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
*/
public boolean setPriority(BluetoothDevice device, int priority) {
if (DBG) log("setPriority(" + device + ", " + priority + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
- if (priority != BluetoothProfile.PRIORITY_OFF &&
- priority != BluetoothProfile.PRIORITY_ON) {
- return false;
+ if (mService != null && isEnabled() && isValidDevice(device)) {
+ if (priority != BluetoothProfile.PRIORITY_OFF
+ && priority != BluetoothProfile.PRIORITY_ON) {
+ return false;
}
try {
return mService.setPriority(device, priority);
@@ -611,8 +602,7 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
*/
public int getPriority(BluetoothDevice device) {
if (VDBG) log("getPriority(" + device + ")");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.getPriority(device);
} catch (RemoteException e) {
@@ -627,24 +617,21 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
/**
* Starts voice recognition.
*
- * @param device remote device
- * @return true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_AG_EVENT}
- * intent.
+ * @param device remote device
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_AG_EVENT} intent.
*
- * true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_AG_EVENT}
- * intent.
+ * @param device remote device
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_AG_EVENT} intent.
*
- * true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_CALL_CHANGED}
- * intent.
+ * @param device remote device
+ * @param flag action policy while accepting a call. Possible values {@link #CALL_ACCEPT_NONE},
+ * {@link #CALL_ACCEPT_HOLD}, {@link #CALL_ACCEPT_TERMINATE}
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.
*/
public boolean acceptCall(BluetoothDevice device, int flag) {
if (DBG) log("acceptCall()");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.acceptCall(device, flag);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -748,20 +725,17 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
/**
* Holds a call.
*
- * @param device remote device
- * @return true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_CALL_CHANGED}
- * intent.
+ * @param device remote device
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.
*/
public boolean holdCall(BluetoothDevice device) {
if (DBG) log("holdCall()");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.holdCall(device);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -771,24 +745,21 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
/**
* Rejects a call.
*
- * @param device remote device
- * @return true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_CALL_CHANGED}
- * intent.
+ * @param device remote device
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.
*
- * true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_CALL_CHANGED}
- * intent.
+ * @param device remote device
+ * @param call Handle of call obtained in {@link #dial(BluetoothDevice, String)} or obtained via
+ * {@link #ACTION_CALL_CHANGED}. {@code call} may be null in which case we will hangup all active
+ * calls.
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.
*
- * true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_CALL_CHANGED}
- * intent.
+ * @param device remote device
+ * @param index index of the call to connect in private mode
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.
*
- * true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_CALL_CHANGED}
- * intent.
+ * @param device remote device
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_CALL_CHANGED} intent.
*
- * {@link BluetoothHeadsetClientCall} call if command has been
- * issued successfully;
- * {@link null} otherwise;
- * upon completion HFP sends {@link #ACTION_CALL_CHANGED}
- * intent in case of success; {@link #ACTION_RESULT} is sent
- * otherwise;
+ * @param device remote device
+ * @param number valid phone number
+ * @return {@link BluetoothHeadsetClientCall} call if command has been issued
+ * successfully; {@link null} otherwise; upon completion HFP sends {@link
+ * #ACTION_CALL_CHANGED} intent in case of success; {@link #ACTION_RESULT} is sent otherwise;
*/
public BluetoothHeadsetClientCall dial(BluetoothDevice device, String number) {
if (DBG) log("dial()");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.dial(device, number);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -917,20 +875,18 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
*
* Possible code values : 0,1,2,3,4,5,6,7,8,9,A,B,C,D,*,#
*
- * @param device remote device
- * @param code ASCII code
- * @return true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_RESULT} intent;
+ * @param device remote device
+ * @param code ASCII code
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_RESULT} intent;
*/
public boolean sendDTMF(BluetoothDevice device, byte code) {
if (DBG) log("sendDTMF()");
- if (mService != null && isEnabled() &&
- isValidDevice(device)) {
+ if (mService != null && isEnabled() && isValidDevice(device)) {
try {
return mService.sendDTMF(device, code);
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
@@ -940,24 +896,22 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
/**
* Get a number corresponding to last voice tag recorded on AG.
*
- * @param device remote device
- * @return true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_LAST_VTAG}
- * or {@link #ACTION_RESULT} intent;
+ * @param device remote device
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_LAST_VTAG} or {@link #ACTION_RESULT}
+ * intent;
*
- * true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_AUDIO_STATE_CHANGED}
- * intent;
+ * @param device remote device
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_AUDIO_STATE_CHANGED} intent;
*/
public boolean connectAudio(BluetoothDevice device) {
if (mService != null && isEnabled()) {
@@ -1050,11 +1009,9 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
*
* It tears down the SCO channel from remote AG device.
*
- * @param device remote device
- * @return true if command has been issued successfully;
- * false otherwise;
- * upon completion HFP sends {@link #ACTION_AUDIO_STATE_CHANGED}
- * intent;
+ * @param device remote device
+ * @return true if command has been issued successfully; false
+ * otherwise; upon completion HFP sends {@link #ACTION_AUDIO_STATE_CHANGED} intent;
*/
public boolean disconnectAudio(BluetoothDevice device) {
if (mService != null && isEnabled()) {
@@ -1073,9 +1030,8 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
/**
* Get Audio Gateway features
*
- * @param device remote device
- * @return bundle of AG features; null if no service or
- * AG not connected
+ * @param device remote device
+ * @return bundle of AG features; null if no service or AG not connected
*/
public Bundle getCurrentAgFeatures(BluetoothDevice device) {
if (mService != null && isEnabled()) {
@@ -1103,6 +1059,7 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
BluetoothHeadsetClient.this);
}
}
+
@Override
public void onServiceDisconnected(ComponentName className) {
if (DBG) Log.d(TAG, "Proxy object disconnected");
@@ -1114,15 +1071,15 @@ public final class BluetoothHeadsetClient implements BluetoothProfile {
};
private boolean isEnabled() {
- if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
- return false;
+ if (mAdapter.getState() == BluetoothAdapter.STATE_ON) return true;
+ return false;
}
private boolean isValidDevice(BluetoothDevice device) {
- if (device == null) return false;
+ if (device == null) return false;
- if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
- return false;
+ if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
+ return false;
}
private static void log(String msg) {
diff --git a/core/java/android/bluetooth/BluetoothHeadsetClientCall.java b/core/java/android/bluetooth/BluetoothHeadsetClientCall.java
index 420c079f5fea8..dc00d63043fc9 100644
--- a/core/java/android/bluetooth/BluetoothHeadsetClientCall.java
+++ b/core/java/android/bluetooth/BluetoothHeadsetClientCall.java
@@ -25,6 +25,7 @@ import java.util.UUID;
/**
* This class represents a single call, its state and properties.
* It implements {@link Parcelable} for inter-process message passing.
+ *
* @hide
*/
public final class BluetoothHeadsetClientCall implements Parcelable {
@@ -98,7 +99,7 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
*
* true sets this call as a part
- * of multi party conference.
+ * @param multiParty if true sets this call as a part of multi party conference.
*/
public void setMultiParty(boolean multiParty) {
mMultiParty = multiParty;
@@ -185,8 +185,7 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
/**
* Checks if call is an active call in a conference mode (aka multi party).
*
- * @return true if call is a multi party call,
- * false otherwise.
+ * @return true if call is a multi party call, false otherwise.
*/
public boolean isMultiParty() {
return mMultiParty;
@@ -195,17 +194,22 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
/**
* Checks if this call is an outgoing call.
*
- * @return true if its outgoing call,
- * false otherwise.
+ * @return true if its outgoing call, false otherwise.
*/
public boolean isOutgoing() {
return mOutgoing;
}
+ @Override
public String toString() {
return toString(false);
}
+ /**
+ * Generate a log string for this call
+ * @param loggable whether device address should be logged
+ * @return log string
+ */
public String toString(boolean loggable) {
StringBuilder builder = new StringBuilder("BluetoothHeadsetClientCall{mDevice: ");
builder.append(loggable ? mDevice : mDevice.hashCode());
@@ -215,15 +219,33 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
builder.append(mUUID);
builder.append(", mState: ");
switch (mState) {
- case CALL_STATE_ACTIVE: builder.append("ACTIVE"); break;
- case CALL_STATE_HELD: builder.append("HELD"); break;
- case CALL_STATE_DIALING: builder.append("DIALING"); break;
- case CALL_STATE_ALERTING: builder.append("ALERTING"); break;
- case CALL_STATE_INCOMING: builder.append("INCOMING"); break;
- case CALL_STATE_WAITING: builder.append("WAITING"); break;
- case CALL_STATE_HELD_BY_RESPONSE_AND_HOLD: builder.append("HELD_BY_RESPONSE_AND_HOLD"); break;
- case CALL_STATE_TERMINATED: builder.append("TERMINATED"); break;
- default: builder.append(mState); break;
+ case CALL_STATE_ACTIVE:
+ builder.append("ACTIVE");
+ break;
+ case CALL_STATE_HELD:
+ builder.append("HELD");
+ break;
+ case CALL_STATE_DIALING:
+ builder.append("DIALING");
+ break;
+ case CALL_STATE_ALERTING:
+ builder.append("ALERTING");
+ break;
+ case CALL_STATE_INCOMING:
+ builder.append("INCOMING");
+ break;
+ case CALL_STATE_WAITING:
+ builder.append("WAITING");
+ break;
+ case CALL_STATE_HELD_BY_RESPONSE_AND_HOLD:
+ builder.append("HELD_BY_RESPONSE_AND_HOLD");
+ break;
+ case CALL_STATE_TERMINATED:
+ builder.append("TERMINATED");
+ break;
+ default:
+ builder.append(mState);
+ break;
}
builder.append(", mNumber: ");
builder.append(loggable ? mNumber : mNumber.hashCode());
@@ -242,7 +264,7 @@ public final class BluetoothHeadsetClientCall implements Parcelable {
new Parcelable.Creatornull
- * .
- * @param config {@link BluetoothHidDeviceAppConfiguration} object which
- * represents token required to unregister application using
- * {@link BluetoothHidDevice#unregisterApp(BluetoothHidDeviceAppConfiguration)}
- * .
- * @param registered true if application is registered,
- * false otherwise.
+ * @param pluggedDevice {@link BluetoothDevice} object which represents host that currently has
+ * Virtual Cable established with device. Only valid when application is registered, can be
+ * null.
+ * @param config {@link BluetoothHidDeviceAppConfiguration} object which represents token
+ * required to unregister application using
+ * {@link BluetoothHidDevice#unregisterApp(BluetoothHidDeviceAppConfiguration)}.
+ * @param registered true if application is registered, false
+ * otherwise.
*/
public void onAppStatusChanged(BluetoothDevice pluggedDevice,
BluetoothHidDeviceAppConfiguration config, boolean registered) {
@@ -55,8 +53,8 @@ public abstract class BluetoothHidDeviceCallback {
* Application can assume than Virtual Cable is established when called with
* {@link BluetoothProfile#STATE_CONNECTED} state.
*
- * @param device {@link BluetoothDevice} object representing host device
- * which connection state was changed.
+ * @param device {@link BluetoothDevice} object representing host device which connection state
+ * was changed.
* @param state Connection state as defined in {@link BluetoothProfile}.
*/
public void onConnectionStateChanged(BluetoothDevice device, int state) {
@@ -69,10 +67,9 @@ public abstract class BluetoothHidDeviceCallback {
* {@link BluetoothHidDevice#replyReport(BluetoothDevice, byte, byte, byte[])}.
*
* @param type Requested Report Type.
- * @param id Requested Report Id, can be 0 if no Report Id are defined in
- * descriptor.
- * @param bufferSize Requested buffer size, application shall respond with
- * at least given number of bytes.
+ * @param id Requested Report Id, can be 0 if no Report Id are defined in descriptor.
+ * @param bufferSize Requested buffer size, application shall respond with at least given number
+ * of bytes.
*/
public void onGetReport(BluetoothDevice device, byte type, byte id, int bufferSize) {
Log.d(TAG, "onGetReport: device=" + device + " type=" + type + " id=" + id + " bufferSize="
diff --git a/core/java/android/bluetooth/BluetoothInputDevice.java b/core/java/android/bluetooth/BluetoothInputDevice.java
index a5a02435e37ab..a9a9010c7edbf 100644
--- a/core/java/android/bluetooth/BluetoothInputDevice.java
+++ b/core/java/android/bluetooth/BluetoothInputDevice.java
@@ -35,12 +35,13 @@ import java.util.List;
* This class provides the public APIs to control the Bluetooth Input
* Device Profile.
*
- *
- *
*
*
- *
*
*
- *
*
* true if command has been issued successfully;
- * false otherwise;
+ * @param device a remote device we want connect to
+ * @return true if command has been issued successfully; false
+ * otherwise;
*/
public boolean connect(BluetoothDevice device) {
if (DBG) {
@@ -189,20 +191,19 @@ public final class BluetoothPbapClient implements BluetoothProfile {
* Initiate disconnect.
*
* @param device Remote Bluetooth Device
- * @return false on error,
- * true otherwise
+ * @return false on error, true otherwise
*/
public boolean disconnect(BluetoothDevice device) {
if (DBG) {
- log("disconnect(" + device + ")" + new Exception() );
+ log("disconnect(" + device + ")" + new Exception());
}
if (mService != null && isEnabled() && isValidDevice(device)) {
try {
mService.disconnect(device);
return true;
} catch (RemoteException e) {
- Log.e(TAG, Log.getStackTraceString(new Throwable()));
- return false;
+ Log.e(TAG, Log.getStackTraceString(new Throwable()));
+ return false;
}
}
if (mService == null) {
@@ -291,9 +292,11 @@ public final class BluetoothPbapClient implements BluetoothProfile {
}
mService = IBluetoothPbapClient.Stub.asInterface(Binder.allowBlocking(service));
if (mServiceListener != null) {
- mServiceListener.onServiceConnected(BluetoothProfile.PBAP_CLIENT, BluetoothPbapClient.this);
+ mServiceListener.onServiceConnected(BluetoothProfile.PBAP_CLIENT,
+ BluetoothPbapClient.this);
}
}
+
public void onServiceDisconnected(ComponentName className) {
if (DBG) {
log("Proxy object disconnected");
@@ -319,20 +322,20 @@ public final class BluetoothPbapClient implements BluetoothProfile {
}
private boolean isValidDevice(BluetoothDevice device) {
- if (device == null) {
- return false;
- }
- if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) {
- return true;
- }
- return false;
+ if (device == null) {
+ return false;
+ }
+ if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) {
+ return true;
+ }
+ return false;
}
/**
* Set priority of the profile
*
*
- *
*
* > resultStorages) {
+ final WorkSource workSource, final ScanCallback callback,
+ final PendingIntent callbackIntent,
+ List
> resultStorages) {
BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
if (callback == null && callbackIntent == null) {
throw new IllegalArgumentException("callback is null");
@@ -219,11 +220,11 @@ public final class BluetoothLeScanner {
}
if (!isSettingsConfigAllowedForScan(settings)) {
return postCallbackErrorOrReturn(callback,
- ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED);
+ ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED);
}
if (!isHardwareResourcesAvailableForScan(settings)) {
return postCallbackErrorOrReturn(callback,
- ScanCallback.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES);
+ ScanCallback.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES);
}
if (!isSettingsAndFilterComboAllowed(settings, filters)) {
return postCallbackErrorOrReturn(callback,
@@ -286,7 +287,7 @@ public final class BluetoothLeScanner {
* will be delivered through the {@code callback}.
*
* @param callback Callback of the Bluetooth LE Scan, it has to be the same instance as the one
- * used to start scan.
+ * used to start scan.
*/
public void flushPendingScanResults(ScanCallback callback) {
BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
@@ -419,8 +420,8 @@ public final class BluetoothLeScanner {
*/
@Override
public void onScannerRegistered(int status, int scannerId) {
- Log.d(TAG, "onScannerRegistered() - status=" + status +
- " scannerId=" + scannerId + " mScannerId=" + mScannerId);
+ Log.d(TAG, "onScannerRegistered() - status=" + status
+ + " scannerId=" + scannerId + " mScannerId=" + mScannerId);
synchronized (this) {
if (status == BluetoothGatt.GATT_SUCCESS) {
try {
@@ -481,18 +482,18 @@ public final class BluetoothLeScanner {
@Override
public void onFoundOrLost(final boolean onFound, final ScanResult scanResult) {
if (VDBG) {
- Log.d(TAG, "onFoundOrLost() - onFound = " + onFound +
- " " + scanResult.toString());
+ Log.d(TAG, "onFoundOrLost() - onFound = " + onFound + " " + scanResult.toString());
}
// Check null in case the scan has been stopped
synchronized (this) {
- if (mScannerId <= 0)
+ if (mScannerId <= 0) {
return;
+ }
}
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
- @Override
+ @Override
public void run() {
if (onFound) {
mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_FIRST_MATCH,
@@ -511,8 +512,9 @@ public final class BluetoothLeScanner {
Log.d(TAG, "onScanManagerErrorCallback() - errorCode = " + errorCode);
}
synchronized (this) {
- if (mScannerId <= 0)
+ if (mScannerId <= 0) {
return;
+ }
}
postCallbackError(mScanCallback, errorCode);
}
@@ -550,11 +552,11 @@ public final class BluetoothLeScanner {
}
private boolean isSettingsAndFilterComboAllowed(ScanSettings settings,
- List