Merge "Deprecate BluetoothHealth APIs"

This commit is contained in:
Treehugger Robot
2019-01-10 04:46:21 +00:00
committed by Gerrit Code Review
6 changed files with 239 additions and 486 deletions

View File

@@ -8339,42 +8339,44 @@ package android.bluetooth {
field public static final java.lang.String VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY = "android.bluetooth.headset.intent.category.companyid"; field public static final java.lang.String VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY = "android.bluetooth.headset.intent.category.companyid";
} }
public final class BluetoothHealth implements android.bluetooth.BluetoothProfile { public final deprecated class BluetoothHealth implements android.bluetooth.BluetoothProfile {
method public boolean connectChannelToSource(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration); ctor public BluetoothHealth();
method public boolean disconnectChannel(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration, int); method public deprecated boolean connectChannelToSource(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration);
method public deprecated boolean disconnectChannel(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration, int);
method public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices(); method public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
method public int getConnectionState(android.bluetooth.BluetoothDevice); method public int getConnectionState(android.bluetooth.BluetoothDevice);
method public java.util.List<android.bluetooth.BluetoothDevice> getDevicesMatchingConnectionStates(int[]); method public java.util.List<android.bluetooth.BluetoothDevice> getDevicesMatchingConnectionStates(int[]);
method public android.os.ParcelFileDescriptor getMainChannelFd(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration); method public deprecated android.os.ParcelFileDescriptor getMainChannelFd(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration);
method public boolean registerSinkAppConfiguration(java.lang.String, int, android.bluetooth.BluetoothHealthCallback); method public deprecated boolean registerSinkAppConfiguration(java.lang.String, int, android.bluetooth.BluetoothHealthCallback);
method public boolean unregisterAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration); method public deprecated boolean unregisterAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration);
field public static final int APP_CONFIG_REGISTRATION_FAILURE = 1; // 0x1 field public static final deprecated int APP_CONFIG_REGISTRATION_FAILURE = 1; // 0x1
field public static final int APP_CONFIG_REGISTRATION_SUCCESS = 0; // 0x0 field public static final deprecated int APP_CONFIG_REGISTRATION_SUCCESS = 0; // 0x0
field public static final int APP_CONFIG_UNREGISTRATION_FAILURE = 3; // 0x3 field public static final deprecated int APP_CONFIG_UNREGISTRATION_FAILURE = 3; // 0x3
field public static final int APP_CONFIG_UNREGISTRATION_SUCCESS = 2; // 0x2 field public static final deprecated int APP_CONFIG_UNREGISTRATION_SUCCESS = 2; // 0x2
field public static final int CHANNEL_TYPE_RELIABLE = 10; // 0xa field public static final deprecated int CHANNEL_TYPE_RELIABLE = 10; // 0xa
field public static final int CHANNEL_TYPE_STREAMING = 11; // 0xb field public static final deprecated int CHANNEL_TYPE_STREAMING = 11; // 0xb
field public static final int SINK_ROLE = 2; // 0x2 field public static final deprecated int SINK_ROLE = 2; // 0x2
field public static final int SOURCE_ROLE = 1; // 0x1 field public static final deprecated int SOURCE_ROLE = 1; // 0x1
field public static final int STATE_CHANNEL_CONNECTED = 2; // 0x2 field public static final deprecated int STATE_CHANNEL_CONNECTED = 2; // 0x2
field public static final int STATE_CHANNEL_CONNECTING = 1; // 0x1 field public static final deprecated int STATE_CHANNEL_CONNECTING = 1; // 0x1
field public static final int STATE_CHANNEL_DISCONNECTED = 0; // 0x0 field public static final deprecated int STATE_CHANNEL_DISCONNECTED = 0; // 0x0
field public static final int STATE_CHANNEL_DISCONNECTING = 3; // 0x3 field public static final deprecated int STATE_CHANNEL_DISCONNECTING = 3; // 0x3
} }
public final class BluetoothHealthAppConfiguration implements android.os.Parcelable { public final deprecated class BluetoothHealthAppConfiguration implements android.os.Parcelable {
ctor public BluetoothHealthAppConfiguration();
method public int describeContents(); method public int describeContents();
method public int getDataType(); method public deprecated int getDataType();
method public java.lang.String getName(); method public deprecated java.lang.String getName();
method public int getRole(); method public deprecated int getRole();
method public void writeToParcel(android.os.Parcel, int); method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothHealthAppConfiguration> CREATOR; field public static final deprecated android.os.Parcelable.Creator<android.bluetooth.BluetoothHealthAppConfiguration> CREATOR;
} }
public abstract class BluetoothHealthCallback { public abstract deprecated class BluetoothHealthCallback {
ctor public BluetoothHealthCallback(); ctor public BluetoothHealthCallback();
method public void onHealthAppConfigurationStatusChange(android.bluetooth.BluetoothHealthAppConfiguration, int); method public deprecated void onHealthAppConfigurationStatusChange(android.bluetooth.BluetoothHealthAppConfiguration, int);
method public void onHealthChannelStateChange(android.bluetooth.BluetoothHealthAppConfiguration, android.bluetooth.BluetoothDevice, int, int, android.os.ParcelFileDescriptor, int); method public deprecated void onHealthChannelStateChange(android.bluetooth.BluetoothHealthAppConfiguration, android.bluetooth.BluetoothDevice, int, int, android.os.ParcelFileDescriptor, int);
} }
public final class BluetoothHidDevice implements android.bluetooth.BluetoothProfile { public final class BluetoothHidDevice implements android.bluetooth.BluetoothProfile {
@@ -8471,7 +8473,7 @@ package android.bluetooth {
field public static final int GATT = 7; // 0x7 field public static final int GATT = 7; // 0x7
field public static final int GATT_SERVER = 8; // 0x8 field public static final int GATT_SERVER = 8; // 0x8
field public static final int HEADSET = 1; // 0x1 field public static final int HEADSET = 1; // 0x1
field public static final int HEALTH = 3; // 0x3 field public static final deprecated int HEALTH = 3; // 0x3
field public static final int HID_DEVICE = 19; // 0x13 field public static final int HID_DEVICE = 19; // 0x13
field public static final int SAP = 10; // 0xa field public static final int SAP = 10; // 0xa
field public static final int STATE_CONNECTED = 2; // 0x2 field public static final int STATE_CONNECTED = 2; // 0x2

View File

@@ -2066,8 +2066,7 @@ public final class BluetoothAdapter {
* Get the current connection state of a profile. * Get the current connection state of a profile.
* This function can be used to check whether the local Bluetooth adapter * This function can be used to check whether the local Bluetooth adapter
* is connected to any remote device for a specific profile. * is connected to any remote device for a specific profile.
* Profile can be one of {@link BluetoothProfile#HEALTH}, {@link BluetoothProfile#HEADSET}, * Profile can be one of {@link BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP}.
* {@link BluetoothProfile#A2DP}.
* *
* <p> Return value can be one of * <p> Return value can be one of
* {@link BluetoothProfile#STATE_DISCONNECTED}, * {@link BluetoothProfile#STATE_DISCONNECTED},
@@ -2441,16 +2440,15 @@ public final class BluetoothAdapter {
/** /**
* Get the profile proxy object associated with the profile. * Get the profile proxy object associated with the profile.
* *
* <p>Profile can be one of {@link BluetoothProfile#HEALTH}, {@link BluetoothProfile#HEADSET}, * <p>Profile can be one of {@link BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP},
* {@link BluetoothProfile#A2DP}, {@link BluetoothProfile#GATT}, or * {@link BluetoothProfile#GATT}, or {@link BluetoothProfile#GATT_SERVER}. Clients must
* {@link BluetoothProfile#GATT_SERVER}. Clients must implement * implement {@link BluetoothProfile.ServiceListener} to get notified of the connection status
* {@link BluetoothProfile.ServiceListener} to get notified of * and to get the proxy object.
* the connection status and to get the proxy object.
* *
* @param context Context of the application * @param context Context of the application
* @param listener The service Listener for connection callbacks. * @param listener The service Listener for connection callbacks.
* @param profile The Bluetooth profile; either {@link BluetoothProfile#HEALTH}, {@link * @param profile The Bluetooth profile; either {@link BluetoothProfile#HEADSET},
* BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP}. {@link BluetoothProfile#GATT} or * {@link BluetoothProfile#A2DP}. {@link BluetoothProfile#GATT} or
* {@link BluetoothProfile#GATT_SERVER}. * {@link BluetoothProfile#GATT_SERVER}.
* @return true on success, false on error * @return true on success, false on error
*/ */
@@ -2479,8 +2477,8 @@ public final class BluetoothAdapter {
BluetoothPan pan = new BluetoothPan(context, listener); BluetoothPan pan = new BluetoothPan(context, listener);
return true; return true;
} else if (profile == BluetoothProfile.HEALTH) { } else if (profile == BluetoothProfile.HEALTH) {
BluetoothHealth health = new BluetoothHealth(context, listener); Log.e(TAG, "getProfileProxy(): BluetoothHealth is deprecated");
return true; return false;
} else if (profile == BluetoothProfile.MAP) { } else if (profile == BluetoothProfile.MAP) {
BluetoothMap map = new BluetoothMap(context, listener); BluetoothMap map = new BluetoothMap(context, listener);
return true; return true;
@@ -2512,8 +2510,7 @@ public final class BluetoothAdapter {
* *
* <p> Clients should call this when they are no longer using * <p> Clients should call this when they are no longer using
* the proxy obtained from {@link #getProfileProxy}. * the proxy obtained from {@link #getProfileProxy}.
* Profile can be one of {@link BluetoothProfile#HEALTH}, {@link BluetoothProfile#HEADSET} or * Profile can be one of {@link BluetoothProfile#HEADSET} or {@link BluetoothProfile#A2DP}
* {@link BluetoothProfile#A2DP}
* *
* @param profile * @param profile
* @param proxy Profile proxy object * @param proxy Profile proxy object
@@ -2548,10 +2545,6 @@ public final class BluetoothAdapter {
BluetoothPan pan = (BluetoothPan) proxy; BluetoothPan pan = (BluetoothPan) proxy;
pan.close(); pan.close();
break; break;
case BluetoothProfile.HEALTH:
BluetoothHealth health = (BluetoothHealth) proxy;
health.close();
break;
case BluetoothProfile.GATT: case BluetoothProfile.GATT:
BluetoothGatt gatt = (BluetoothGatt) proxy; BluetoothGatt gatt = (BluetoothGatt) proxy;
gatt.close(); gatt.close();

View File

@@ -16,14 +16,7 @@
package android.bluetooth; package android.bluetooth;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.IBinder;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.util.Log; import android.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
@@ -53,79 +46,59 @@ import java.util.List;
* <li> When done, close the health channel by calling {@link #disconnectChannel} * <li> When done, close the health channel by calling {@link #disconnectChannel}
* and unregister the application configuration calling * and unregister the application configuration calling
* {@link #unregisterAppConfiguration} * {@link #unregisterAppConfiguration}
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps
* should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public final class BluetoothHealth implements BluetoothProfile { public final class BluetoothHealth implements BluetoothProfile {
private static final String TAG = "BluetoothHealth"; private static final String TAG = "BluetoothHealth";
private static final boolean DBG = true;
private static final boolean VDBG = false;
/** /**
* Health Profile Source Role - the health device. * Health Profile Source Role - the health device.
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public static final int SOURCE_ROLE = 1 << 0; public static final int SOURCE_ROLE = 1 << 0;
/** /**
* Health Profile Sink Role the device talking to the health device. * Health Profile Sink Role the device talking to the health device.
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public static final int SINK_ROLE = 1 << 1; public static final int SINK_ROLE = 1 << 1;
/** /**
* Health Profile - Channel Type used - Reliable * Health Profile - Channel Type used - Reliable
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public static final int CHANNEL_TYPE_RELIABLE = 10; public static final int CHANNEL_TYPE_RELIABLE = 10;
/** /**
* Health Profile - Channel Type used - Streaming * Health Profile - Channel Type used - Streaming
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public static final int CHANNEL_TYPE_STREAMING = 11; public static final int CHANNEL_TYPE_STREAMING = 11;
/**
* @hide
*/
public static final int CHANNEL_TYPE_ANY = 12;
/** @hide */
public static final int HEALTH_OPERATION_SUCCESS = 6000;
/** @hide */
public static final int HEALTH_OPERATION_ERROR = 6001;
/** @hide */
public static final int HEALTH_OPERATION_INVALID_ARGS = 6002;
/** @hide */
public static final int HEALTH_OPERATION_GENERIC_FAILURE = 6003;
/** @hide */
public static final int HEALTH_OPERATION_NOT_FOUND = 6004;
/** @hide */
public static final int HEALTH_OPERATION_NOT_ALLOWED = 6005;
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);
}
}
}
}
};
/** /**
* Register an application configuration that acts as a Health SINK. * Register an application configuration that acts as a Health SINK.
@@ -141,53 +114,17 @@ public final class BluetoothHealth implements BluetoothProfile {
* @param callback A callback to indicate success or failure of the registration and all * @param callback A callback to indicate success or failure of the registration and all
* operations done on this application configuration. * operations done on this application configuration.
* @return If true, callback will be called. * @return If true, callback will be called.
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public boolean registerSinkAppConfiguration(String name, int dataType, public boolean registerSinkAppConfiguration(String name, int dataType,
BluetoothHealthCallback callback) { BluetoothHealthCallback callback) {
if (!isEnabled() || name == null) return false; Log.e(TAG, "registerSinkAppConfiguration(): BluetoothHealth is deprecated");
return false;
if (VDBG) log("registerSinkApplication(" + name + ":" + dataType + ")");
return registerAppConfiguration(name, dataType, SINK_ROLE,
CHANNEL_TYPE_ANY, callback);
}
/**
* Register an application configuration that acts as a Health SINK or in a Health
* SOURCE role.This is an asynchronous call and so
* the callback is used to notify success or failure if the function returns true.
*
* <p>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.
* @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
*/
public boolean registerAppConfiguration(String name, int dataType, int role,
int channelType, BluetoothHealthCallback callback) {
boolean result = false;
if (!isEnabled() || !checkAppParam(name, role, channelType, callback)) return result;
if (VDBG) log("registerApplication(" + name + ":" + dataType + ")");
BluetoothHealthCallbackWrapper wrapper = new BluetoothHealthCallbackWrapper(callback);
BluetoothHealthAppConfiguration config =
new BluetoothHealthAppConfiguration(name, dataType, role, channelType);
final IBluetoothHealth service = mService;
if (service != null) {
try {
result = service.registerAppConfiguration(config, wrapper);
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
}
return result;
} }
/** /**
@@ -198,22 +135,16 @@ public final class BluetoothHealth implements BluetoothProfile {
* *
* @param config The health app configuration * @param config The health app configuration
* @return Success or failure. * @return Success or failure.
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public boolean unregisterAppConfiguration(BluetoothHealthAppConfiguration config) { public boolean unregisterAppConfiguration(BluetoothHealthAppConfiguration config) {
boolean result = false; Log.e(TAG, "unregisterAppConfiguration(): BluetoothHealth is deprecated");
final IBluetoothHealth service = mService; return false;
if (service != null && isEnabled() && config != null) {
try {
result = service.unregisterAppConfiguration(config);
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
}
return result;
} }
/** /**
@@ -227,49 +158,16 @@ public final class BluetoothHealth implements BluetoothProfile {
* @param config The application configuration which has been registered using {@link * @param config The application configuration which has been registered using {@link
* #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) } * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
* @return If true, the callback associated with the application config will be called. * @return If true, the callback associated with the application config will be called.
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public boolean connectChannelToSource(BluetoothDevice device, public boolean connectChannelToSource(BluetoothDevice device,
BluetoothHealthAppConfiguration config) { BluetoothHealthAppConfiguration config) {
final IBluetoothHealth service = mService; Log.e(TAG, "connectChannelToSource(): BluetoothHealth is deprecated");
if (service != null && isEnabled() && isValidDevice(device) && config != null) {
try {
return service.connectChannelToSource(device, config);
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
}
return false;
}
/**
* Connect to a health device which has the {@link #SINK_ROLE}.
* This is an asynchronous call. If this function returns true, the callback
* associated with the application configuration will be called.
*
* <p>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) }
* @return If true, the callback associated with the application config will be called.
* @hide
*/
public boolean connectChannelToSink(BluetoothDevice device,
BluetoothHealthAppConfiguration config, int channelType) {
final IBluetoothHealth service = mService;
if (service != null && isEnabled() && isValidDevice(device) && config != null) {
try {
return service.connectChannelToSink(device, config, channelType);
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
}
return false; return false;
} }
@@ -285,20 +183,16 @@ public final class BluetoothHealth implements BluetoothProfile {
* #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) } * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
* @param channelId The channel id associated with the channel * @param channelId The channel id associated with the channel
* @return If true, the callback associated with the application config will be called. * @return If true, the callback associated with the application config will be called.
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public boolean disconnectChannel(BluetoothDevice device, public boolean disconnectChannel(BluetoothDevice device,
BluetoothHealthAppConfiguration config, int channelId) { BluetoothHealthAppConfiguration config, int channelId) {
final IBluetoothHealth service = mService; Log.e(TAG, "disconnectChannel(): BluetoothHealth is deprecated");
if (service != null && isEnabled() && isValidDevice(device) && config != null) {
try {
return service.disconnectChannel(device, config, channelId);
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
}
return false; return false;
} }
@@ -314,20 +208,16 @@ public final class BluetoothHealth implements BluetoothProfile {
* @param device The remote Bluetooth health device * @param device The remote Bluetooth health device
* @param config The application configuration * @param config The application configuration
* @return null on failure, ParcelFileDescriptor on success. * @return null on failure, ParcelFileDescriptor on success.
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public ParcelFileDescriptor getMainChannelFd(BluetoothDevice device, public ParcelFileDescriptor getMainChannelFd(BluetoothDevice device,
BluetoothHealthAppConfiguration config) { BluetoothHealthAppConfiguration config) {
final IBluetoothHealth service = mService; Log.e(TAG, "getMainChannelFd(): BluetoothHealth is deprecated");
if (service != null && isEnabled() && isValidDevice(device) && config != null) {
try {
return service.getMainChannelFd(device, config);
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
}
return null; return null;
} }
@@ -347,17 +237,7 @@ public final class BluetoothHealth implements BluetoothProfile {
*/ */
@Override @Override
public int getConnectionState(BluetoothDevice device) { public int getConnectionState(BluetoothDevice device) {
final IBluetoothHealth service = mService; Log.e(TAG, "getConnectionState(): BluetoothHealth is deprecated");
if (service != null && isEnabled() && isValidDevice(device)) {
try {
return service.getHealthDeviceConnectionState(device);
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
}
return STATE_DISCONNECTED; return STATE_DISCONNECTED;
} }
@@ -377,17 +257,8 @@ public final class BluetoothHealth implements BluetoothProfile {
*/ */
@Override @Override
public List<BluetoothDevice> getConnectedDevices() { public List<BluetoothDevice> getConnectedDevices() {
final IBluetoothHealth service = mService; Log.e(TAG, "getConnectedDevices(): BluetoothHealth is deprecated");
if (service != null && isEnabled()) { return new ArrayList<>();
try {
return service.getConnectedHealthDevices();
} catch (RemoteException e) {
Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
return new ArrayList<BluetoothDevice>();
}
}
if (service == null) Log.w(TAG, "Proxy not attached to service");
return new ArrayList<BluetoothDevice>();
} }
/** /**
@@ -409,163 +280,81 @@ public final class BluetoothHealth implements BluetoothProfile {
*/ */
@Override @Override
public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
final IBluetoothHealth service = mService; Log.e(TAG, "getDevicesMatchingConnectionStates(): BluetoothHealth is deprecated");
if (service != null && isEnabled()) { return new ArrayList<>();
try {
return service.getHealthDevicesMatchingConnectionStates(states);
} catch (RemoteException e) {
Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
return new ArrayList<BluetoothDevice>();
}
}
if (service == null) Log.w(TAG, "Proxy not attached to service");
return new ArrayList<BluetoothDevice>();
} }
private static class BluetoothHealthCallbackWrapper extends IBluetoothHealthCallback.Stub { /** Health Channel Connection State - Disconnected
private BluetoothHealthCallback mCallback; *
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
public BluetoothHealthCallbackWrapper(BluetoothHealthCallback callback) { * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
mCallback = callback; * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
} * {@link BluetoothDevice#createL2capChannel(int)}
*/
@Override @Deprecated
public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config,
int status) {
mCallback.onHealthAppConfigurationStatusChange(config, status);
}
@Override
public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config,
BluetoothDevice device, int prevState, int newState,
ParcelFileDescriptor fd, int channelId) {
mCallback.onHealthChannelStateChange(config, device, prevState, newState, fd,
channelId);
}
}
/** Health Channel Connection State - Disconnected */
public static final int STATE_CHANNEL_DISCONNECTED = 0; public static final int STATE_CHANNEL_DISCONNECTED = 0;
/** Health Channel Connection State - Connecting */ /** Health Channel Connection State - Connecting
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/
@Deprecated
public static final int STATE_CHANNEL_CONNECTING = 1; public static final int STATE_CHANNEL_CONNECTING = 1;
/** Health Channel Connection State - Connected */ /** Health Channel Connection State - Connected
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/
@Deprecated
public static final int STATE_CHANNEL_CONNECTED = 2; public static final int STATE_CHANNEL_CONNECTED = 2;
/** Health Channel Connection State - Disconnecting */ /** Health Channel Connection State - Disconnecting
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/
@Deprecated
public static final int STATE_CHANNEL_DISCONNECTING = 3; public static final int STATE_CHANNEL_DISCONNECTING = 3;
/** Health App Configuration registration success */ /** Health App Configuration registration success
public static final int APP_CONFIG_REGISTRATION_SUCCESS = 0; *
/** Health App Configuration registration failure */ * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
public static final int APP_CONFIG_REGISTRATION_FAILURE = 1; * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
/** Health App Configuration un-registration success */ * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
public static final int APP_CONFIG_UNREGISTRATION_SUCCESS = 2; * {@link BluetoothDevice#createL2capChannel(int)}
/** Health App Configuration un-registration failure */
public static final int APP_CONFIG_UNREGISTRATION_FAILURE = 3;
private Context mContext;
private ServiceListener mServiceListener;
private volatile IBluetoothHealth mService;
BluetoothAdapter mAdapter;
/**
* Create a BluetoothHealth proxy object.
*/ */
/*package*/ BluetoothHealth(Context context, ServiceListener l) { @Deprecated
mContext = context; public static final int APP_CONFIG_REGISTRATION_SUCCESS = 0;
mServiceListener = l; /** Health App Configuration registration failure
mAdapter = BluetoothAdapter.getDefaultAdapter(); *
IBluetoothManager mgr = mAdapter.getBluetoothManager(); * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
if (mgr != null) { * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
try { * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
mgr.registerStateChangeCallback(mBluetoothStateChangeCallback); * {@link BluetoothDevice#createL2capChannel(int)}
} catch (RemoteException e) { */
Log.e(TAG, "", e); @Deprecated
} public static final int APP_CONFIG_REGISTRATION_FAILURE = 1;
} /** Health App Configuration un-registration success
*
doBind(); * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
} * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
boolean doBind() { * {@link BluetoothDevice#createL2capChannel(int)}
Intent intent = new Intent(IBluetoothHealth.class.getName()); */
ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0); @Deprecated
intent.setComponent(comp); public static final int APP_CONFIG_UNREGISTRATION_SUCCESS = 2;
if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0, /** Health App Configuration un-registration failure
mContext.getUser())) { *
Log.e(TAG, "Could not bind to Bluetooth Health Service with " + intent); * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
return false; * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
} * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
return true; * {@link BluetoothDevice#createL2capChannel(int)}
} */
@Deprecated
/*package*/ void close() { public static final int APP_CONFIG_UNREGISTRATION_FAILURE = 3;
if (VDBG) log("close()");
IBluetoothManager mgr = mAdapter.getBluetoothManager();
if (mgr != null) {
try {
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
} catch (Exception e) {
Log.e(TAG, "", e);
}
}
synchronized (mConnection) {
if (mService != null) {
try {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
Log.e(TAG, "", re);
}
}
}
mServiceListener = null;
}
private final ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
if (DBG) Log.d(TAG, "Proxy object connected");
mService = IBluetoothHealth.Stub.asInterface(Binder.allowBlocking(service));
if (mServiceListener != null) {
mServiceListener.onServiceConnected(BluetoothProfile.HEALTH, BluetoothHealth.this);
}
}
public void onServiceDisconnected(ComponentName className) {
if (DBG) Log.d(TAG, "Proxy object disconnected");
mService = null;
if (mServiceListener != null) {
mServiceListener.onServiceDisconnected(BluetoothProfile.HEALTH);
}
}
};
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 static boolean isValidDevice(BluetoothDevice device) {
return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress());
}
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) {
return false;
}
if (role == SOURCE_ROLE && channelType == CHANNEL_TYPE_ANY) return false;
return true;
}
private static void log(String msg) {
Log.d(TAG, msg);
}
} }

View File

@@ -25,72 +25,14 @@ import android.os.Parcelable;
* the {@link BluetoothHealth} class. This class represents an application configuration * the {@link BluetoothHealth} class. This class represents an application configuration
* that the Bluetooth Health third party application will register to communicate with the * that the Bluetooth Health third party application will register to communicate with the
* remote Bluetooth health device. * remote Bluetooth health device.
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public final class BluetoothHealthAppConfiguration implements Parcelable { public final class BluetoothHealthAppConfiguration implements Parcelable {
private final String mName;
private final int mDataType;
private final int mRole;
private final int mChannelType;
/**
* Constructor to register the SINK role
*
* @param name Friendly name associated with the application configuration
* @param dataType Data Type of the remote Bluetooth Health device
* @hide
*/
BluetoothHealthAppConfiguration(String name, int dataType) {
mName = name;
mDataType = dataType;
mRole = BluetoothHealth.SINK_ROLE;
mChannelType = BluetoothHealth.CHANNEL_TYPE_ANY;
}
/**
* Constructor to register the application configuration.
*
* @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}
* @hide
*/
BluetoothHealthAppConfiguration(String name, int dataType, int role, int
channelType) {
mName = name;
mDataType = dataType;
mRole = role;
mChannelType = channelType;
}
@Override
public boolean equals(Object o) {
if (o instanceof BluetoothHealthAppConfiguration) {
BluetoothHealthAppConfiguration config = (BluetoothHealthAppConfiguration) o;
if (mName == null) return false;
return mName.equals(config.getName()) && mDataType == config.getDataType()
&& mRole == config.getRole() && mChannelType == config.getChannelType();
}
return false;
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + (mName != null ? mName.hashCode() : 0);
result = 31 * result + mDataType;
result = 31 * result + mRole;
result = 31 * result + mChannelType;
return result;
}
@Override
public String toString() {
return "BluetoothHealthAppConfiguration [mName = " + mName + ",mDataType = " + mDataType
+ ", mRole = " + mRole + ",mChannelType = " + mChannelType + "]";
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
@@ -100,50 +42,59 @@ public final class BluetoothHealthAppConfiguration implements Parcelable {
* Return the data type associated with this application configuration. * Return the data type associated with this application configuration.
* *
* @return dataType * @return dataType
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public int getDataType() { public int getDataType() {
return mDataType; return 0;
} }
/** /**
* Return the name of the application configuration. * Return the name of the application configuration.
* *
* @return String name * @return String name
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public String getName() { public String getName() {
return mName; return null;
} }
/** /**
* Return the role associated with this application configuration. * 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}
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public int getRole() { public int getRole() {
return mRole; return 0;
} }
/** /**
* Return the channel type associated with this application configuration. * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* @return One of {@link BluetoothHealth#CHANNEL_TYPE_RELIABLE} or {@link * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* BluetoothHealth#CHANNEL_TYPE_STREAMING} or {@link BluetoothHealth#CHANNEL_TYPE_ANY}. * {@link BluetoothDevice#createL2capChannel(int)}
* @hide
*/ */
public int getChannelType() { @Deprecated
return mChannelType;
}
public static final Parcelable.Creator<BluetoothHealthAppConfiguration> CREATOR = public static final Parcelable.Creator<BluetoothHealthAppConfiguration> CREATOR =
new Parcelable.Creator<BluetoothHealthAppConfiguration>() { new Parcelable.Creator<BluetoothHealthAppConfiguration>() {
@Override @Override
public BluetoothHealthAppConfiguration createFromParcel(Parcel in) { public BluetoothHealthAppConfiguration createFromParcel(Parcel in) {
String name = in.readString(); return new BluetoothHealthAppConfiguration();
int type = in.readInt();
int role = in.readInt();
int channelType = in.readInt();
return new BluetoothHealthAppConfiguration(name, type, role,
channelType);
} }
@Override @Override
@@ -153,10 +104,5 @@ public final class BluetoothHealthAppConfiguration implements Parcelable {
}; };
@Override @Override
public void writeToParcel(Parcel out, int flags) { public void writeToParcel(Parcel out, int flags) {}
out.writeString(mName);
out.writeInt(mDataType);
out.writeInt(mRole);
out.writeInt(mChannelType);
}
} }

View File

@@ -23,7 +23,13 @@ import android.util.Log;
/** /**
* This abstract class is used to implement {@link BluetoothHealth} callbacks. * This abstract class is used to implement {@link BluetoothHealth} callbacks.
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
public abstract class BluetoothHealthCallback { public abstract class BluetoothHealthCallback {
private static final String TAG = "BluetoothHealthCallback"; private static final String TAG = "BluetoothHealthCallback";
@@ -38,8 +44,14 @@ public abstract class BluetoothHealthCallback {
* BluetoothHealth#APP_CONFIG_REGISTRATION_FAILURE} or * BluetoothHealth#APP_CONFIG_REGISTRATION_FAILURE} or
* {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_SUCCESS} * {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_SUCCESS}
* or {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_FAILURE} * or {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_FAILURE}
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@BinderThread @BinderThread
@Deprecated
public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config, public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config,
int status) { int status) {
Log.d(TAG, "onHealthAppConfigurationStatusChange: " + config + "Status: " + status); Log.d(TAG, "onHealthAppConfigurationStatusChange: " + config + "Status: " + status);
@@ -58,8 +70,14 @@ public abstract class BluetoothHealthCallback {
* @param fd The Parcel File Descriptor when the channel state is connected. * @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 * @param channelId The id associated with the channel. This id will be used in future calls
* like when disconnecting the channel. * like when disconnecting the channel.
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@BinderThread @BinderThread
@Deprecated
public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config, public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config,
BluetoothDevice device, int prevState, int newState, ParcelFileDescriptor fd, BluetoothDevice device, int prevState, int newState, ParcelFileDescriptor fd,
int channelId) { int channelId) {

View File

@@ -72,7 +72,13 @@ public interface BluetoothProfile {
/** /**
* Health Profile * Health Profile
*
* @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
* apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
* {@link BluetoothAdapter#listenUsingL2capChannel()}, or
* {@link BluetoothDevice#createL2capChannel(int)}
*/ */
@Deprecated
int HEALTH = 3; int HEALTH = 3;
/** /**
@@ -269,9 +275,8 @@ public interface BluetoothProfile {
* Called to notify the client when the proxy object has been * Called to notify the client when the proxy object has been
* connected to the service. * connected to the service.
* *
* @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP} * @param profile - One of {@link #HEADSET} or {@link #A2DP}
* @param proxy - One of {@link BluetoothHealth}, {@link BluetoothHeadset} or {@link * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp}
* BluetoothA2dp}
*/ */
public void onServiceConnected(int profile, BluetoothProfile proxy); public void onServiceConnected(int profile, BluetoothProfile proxy);
@@ -279,7 +284,7 @@ public interface BluetoothProfile {
* Called to notify the client that this proxy object has been * Called to notify the client that this proxy object has been
* disconnected from the service. * disconnected from the service.
* *
* @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP} * @param profile - One of {@link #HEADSET} or {@link #A2DP}
*/ */
public void onServiceDisconnected(int profile); public void onServiceDisconnected(int profile);
} }