Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d172e60 authored by Jaikumar Ganesh's avatar Jaikumar Ganesh Committed by Android (Google) Code Review
Browse files

Merge "Add error codes for channel disconnection / connection."

parents 4eb37f8a b5d2d452
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -81,6 +81,20 @@ public final class BluetoothHealth implements BluetoothProfile {
     */
    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;


    /**
     * Register an application configuration that acts as a Health SINK.
     * This is the configuration that will be used to communicate with health devices
+17 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHealth;
import android.bluetooth.BluetoothInputDevice;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
@@ -973,6 +974,22 @@ class BluetoothEventLoop {
        }
    }

    /**
     * Called by native code for the async response to a Connect
     * method call to org.bluez.Health
     *
     * @param chanCode The internal id of the channel
     * @param result Result code of the operation.
     */
    private void onHealthDeviceConnectionResult(int chanCode, int result) {
        log ("onHealthDeviceConnectionResult " + chanCode + " " + result);
        // Success case gets handled by Property Change signal
        if (result != BluetoothHealth.HEALTH_OPERATION_SUCCESS) {
            mBluetoothService.onHealthDeviceChannelConnectionError(chanCode,
                                                 BluetoothHealth.STATE_CHANNEL_DISCONNECTED);
        }
    }

    /**
     * Called by native code on a DeviceDisconnected signal from
     * org.bluez.NetworkServer.
+28 −18
Original line number Diff line number Diff line
@@ -84,7 +84,6 @@ final class BluetoothHealthProfileHandler {
            result = 31 * result + (mChannelPath == null ? 0 : mChannelPath.hashCode());
            result = 31 * result + mDevice.hashCode();
            result = 31 * result + mConfig.hashCode();
            result = 31 * result + mState;
            result = 31 * result + mChannelType;
            return result;
        }
@@ -152,7 +151,7 @@ final class BluetoothHealthProfileHandler {
                String channelType = getStringChannelType(chan.mChannelType);

                if (!mBluetoothService.createChannelNative(deviceObjectPath, configPath,
                          channelType)) {
                          channelType, chan.hashCode())) {
                    int prevState = chan.mState;
                    int state = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
                    callHealthChannelCallback(chan.mConfig, chan.mDevice, prevState, state, null,
@@ -258,7 +257,7 @@ final class BluetoothHealthProfileHandler {

    boolean disconnectChannel(BluetoothDevice device,
            BluetoothHealthAppConfiguration config, int id) {
        HealthChannel chan = findChannelById(device, config, id);
        HealthChannel chan = findChannelById(id);
        if (chan == null) {
          return false;
        }
@@ -273,7 +272,8 @@ final class BluetoothHealthProfileHandler {
        callHealthChannelCallback(config, device, prevState, chan.mState,
                null, chan.hashCode());

        if (!mBluetoothService.destroyChannelNative(deviceObjectPath, chan.mChannelPath)) {
        if (!mBluetoothService.destroyChannelNative(deviceObjectPath, chan.mChannelPath,
                                                    chan.hashCode())) {
            prevState = chan.mState;
            chan.mState = BluetoothHealth.STATE_CHANNEL_CONNECTED;
            callHealthChannelCallback(config, device, prevState, chan.mState,
@@ -284,8 +284,7 @@ final class BluetoothHealthProfileHandler {
        }
    }

    private HealthChannel findChannelById(BluetoothDevice device,
            BluetoothHealthAppConfiguration config, int id) {
    private HealthChannel findChannelById(int id) {
        for (HealthChannel chan : mHealthChannels) {
            if (chan.hashCode() == id) return chan;
        }
@@ -384,6 +383,15 @@ final class BluetoothHealthProfileHandler {
        }
    }

    /*package*/ void onHealthDeviceChannelConnectionError(int chanCode,
                                                          int state) {
        HealthChannel channel = findChannelById(chanCode);
        if (channel == null) errorLog("No record of this channel:" + chanCode);

        callHealthChannelCallback(channel.mConfig, channel.mDevice, channel.mState, state, null,
                chanCode);
    }

    private BluetoothHealthAppConfiguration findHealthApplication(
            BluetoothDevice device, String channelPath) {
        BluetoothHealthAppConfiguration config = null;
@@ -424,9 +432,19 @@ final class BluetoothHealthProfileHandler {
        config = findHealthApplication(device, channelPath);

        if (exists) {
            channel = findConnectingChannel(device, config);
            if (channel == null) {
               channel = new HealthChannel(device, config, null, false,
                       channelPath);
               channel.mState = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
               mHealthChannels.add(channel);
            }
            channel.mChannelPath = channelPath;

            fd = mBluetoothService.getChannelFdNative(channelPath);
            if (fd == null) {
                errorLog("Error obtaining fd for channel:" + channelPath);
                disconnectChannel(device, config, channel.hashCode());
                return;
            }
            boolean mainChannel =
@@ -440,18 +458,10 @@ final class BluetoothHealthProfileHandler {
                }
                if (mainChannelPath.equals(channelPath)) mainChannel = true;
            }
            channel = findConnectingChannel(device, config);
            if (channel != null) {

            channel.mChannelFd = fd;
            channel.mMainChannel = mainChannel;
               channel.mChannelPath = channelPath;
            prevState = channel.mState;
            } else {
               channel = new HealthChannel(device, config, fd, mainChannel,
                       channelPath);
               mHealthChannels.add(channel);
               prevState = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
            }
            state = BluetoothHealth.STATE_CHANNEL_CONNECTED;
        } else {
            channel = findChannelByPath(device, channelPath);
+11 −2
Original line number Diff line number Diff line
@@ -2255,6 +2255,14 @@ public class BluetoothService extends IBluetooth.Stub {
        }
    }

    /*package*/ void onHealthDeviceChannelConnectionError(int channelCode,
            int newState) {
        synchronized(mBluetoothHealthProfileHandler) {
            mBluetoothHealthProfileHandler.onHealthDeviceChannelConnectionError(channelCode,
                                                                                newState);
        }
    }

    public int getHealthDeviceConnectionState(BluetoothDevice device) {
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
                "Need BLUETOOTH permission");
@@ -2785,8 +2793,9 @@ public class BluetoothService extends IBluetooth.Stub {
            String channelType);
    native String registerHealthApplicationNative(int dataType, String role, String name);
    native boolean unregisterHealthApplicationNative(String path);
    native boolean createChannelNative(String devicePath, String appPath, String channelType);
    native boolean destroyChannelNative(String devicePath, String channelpath);
    native boolean createChannelNative(String devicePath, String appPath, String channelType,
                                       int code);
    native boolean destroyChannelNative(String devicePath, String channelpath, int code);
    native String getMainChannelNative(String path);
    native String getChannelApplicationNative(String channelPath);
    native ParcelFileDescriptor getChannelFdNative(String channelPath);
+7 −0
Original line number Diff line number Diff line
@@ -202,6 +202,13 @@ bool debug_no_encrypt();
#define INPUT_OPERATION_GENERIC_FAILURE        5003
#define INPUT_OPERATION_SUCCESS                5004

#define HEALTH_OPERATION_SUCCESS               6000
#define HEALTH_OPERATION_ERROR                 6001
#define HEALTH_OPERATION_INVALID_ARGS          6002
#define HEALTH_OPERATION_GENERIC_FAILURE       6003
#define HEALTH_OPERATION_NOT_FOUND             6004
#define HEALTH_OPERATION_NOT_ALLOWED           6005

#endif
} /* namespace android */

Loading