Search in sources :

Example 1 with BluetoothHealthAppConfiguration

use of android.bluetooth.BluetoothHealthAppConfiguration in project XobotOS by xamarin.

the class BluetoothHealthProfileHandler method onHealthDeviceChannelChanged.

/*package*/
void onHealthDeviceChannelChanged(String devicePath, String channelPath, boolean exists) {
    debugLog("onHealthDeviceChannelChanged: devicePath: " + devicePath + "ChannelPath: " + channelPath + "Exists: " + exists);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    String address = mBluetoothService.getAddressFromObjectPath(devicePath);
    if (address == null)
        return;
    BluetoothDevice device = adapter.getRemoteDevice(address);
    BluetoothHealthAppConfiguration config;
    int state, prevState = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
    ParcelFileDescriptor fd;
    HealthChannel channel;
    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.mId);
            return;
        }
        boolean mainChannel = getMainChannel(device, config) == null ? false : true;
        if (!mainChannel) {
            String mainChannelPath = mBluetoothService.getMainChannelNative(devicePath);
            if (mainChannelPath == null) {
                errorLog("Main Channel Path is null for devicePath:" + devicePath);
                return;
            }
            if (mainChannelPath.equals(channelPath))
                mainChannel = true;
        }
        channel.mChannelFd = fd;
        channel.mMainChannel = mainChannel;
        prevState = channel.mState;
        state = BluetoothHealth.STATE_CHANNEL_CONNECTED;
    } else {
        channel = findChannelByPath(device, channelPath);
        if (channel == null) {
            errorLog("Channel not found:" + config + ":" + channelPath);
            return;
        }
        mHealthChannels.remove(channel);
        channel.mChannelFd = null;
        prevState = channel.mState;
        state = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
    }
    channel.mState = state;
    callHealthChannelCallback(config, device, prevState, state, channel.mChannelFd, channel.mId);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ParcelFileDescriptor(android.os.ParcelFileDescriptor) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothHealthAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration)

Example 2 with BluetoothHealthAppConfiguration

use of android.bluetooth.BluetoothHealthAppConfiguration in project XobotOS by xamarin.

the class BluetoothHealthProfileHandler method findHealthApplication.

private BluetoothHealthAppConfiguration findHealthApplication(BluetoothDevice device, String channelPath) {
    BluetoothHealthAppConfiguration config = null;
    HealthChannel chan = findChannelByPath(device, channelPath);
    if (chan != null) {
        config = chan.mConfig;
    } else {
        String configPath = mBluetoothService.getChannelApplicationNative(channelPath);
        if (configPath == null) {
            errorLog("Config path is null for application");
        } else {
            for (Entry<BluetoothHealthAppConfiguration, String> e : mHealthAppConfigs.entrySet()) {
                if (e.getValue().equals(configPath)) {
                    config = e.getKey();
                }
            }
            if (config == null)
                errorLog("No associated application for path:" + configPath);
        }
    }
    return config;
}
Also used : BluetoothHealthAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration)

Example 3 with BluetoothHealthAppConfiguration

use of android.bluetooth.BluetoothHealthAppConfiguration in project XobotOS by xamarin.

the class BluetoothHealthProfileHandler method onHealthDevicePropertyChanged.

/*package*/
void onHealthDevicePropertyChanged(String devicePath, String channelPath) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    String address = mBluetoothService.getAddressFromObjectPath(devicePath);
    if (address == null)
        return;
    //TODO: Fix this in Bluez
    if (channelPath.equals("/")) {
        // This means that the main channel is being destroyed.
        return;
    }
    BluetoothDevice device = adapter.getRemoteDevice(address);
    BluetoothHealthAppConfiguration config = findHealthApplication(device, channelPath);
    if (config != null) {
        HealthChannel chan = findChannelByPath(device, channelPath);
        if (chan == null) {
            errorLog("Health Channel is not present:" + channelPath);
        } else {
            chan.mMainChannel = true;
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothHealthAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration)

Aggregations

BluetoothHealthAppConfiguration (android.bluetooth.BluetoothHealthAppConfiguration)3 BluetoothAdapter (android.bluetooth.BluetoothAdapter)2 BluetoothDevice (android.bluetooth.BluetoothDevice)2 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1