public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config, BluetoothDevice device, int prevState, int newState, ParcelFileDescriptor fd, int channelId) { if (Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, String.format("prevState\t%d ----------> newState\t%d", prevState, newState)); if (prevState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED && newState == BluetoothHealth.STATE_CHANNEL_CONNECTED) { if (config.equals(mHealthAppConfig)) { mChannelId = channelId; sendMessage(STATUS_CREATE_CHANNEL, RESULT_OK); (new ReadThread(fd)).start(); } else { sendMessage(STATUS_CREATE_CHANNEL, RESULT_FAIL); } } else if (prevState == BluetoothHealth.STATE_CHANNEL_CONNECTING && newState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED) { sendMessage(STATUS_CREATE_CHANNEL, RESULT_FAIL); } else if (newState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED) { if (config.equals(mHealthAppConfig)) { sendMessage(STATUS_DESTROY_CHANNEL, RESULT_OK); } else { sendMessage(STATUS_DESTROY_CHANNEL, RESULT_FAIL); } } }
public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config, int status) { if (status == BluetoothHealth.APP_CONFIG_REGISTRATION_FAILURE) { mHealthAppConfig = null; sendMessage(STATUS_HEALTH_APP_REG, RESULT_FAIL); } else if (status == BluetoothHealth.APP_CONFIG_REGISTRATION_SUCCESS) { mHealthAppConfig = config; sendMessage(STATUS_HEALTH_APP_REG, RESULT_OK); } else if (status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_FAILURE || status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_SUCCESS) { sendMessage(STATUS_HEALTH_APP_UNREG, status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_SUCCESS ? RESULT_OK : RESULT_FAIL); } }
private BluetoothHealthAppConfiguration getDeviceConfiguration(BluetoothDevice dev) { if (! deviceconfigs.containsKey(dev)) { if (configs.size() > 0) { return configs.get(0); } else { return null; } } return deviceconfigs.get(dev); }
public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config, int status) { if (status == BluetoothHealth.APP_CONFIG_REGISTRATION_FAILURE) { sendMessage(STATUS_HEALTH_APP_REG, RESULT_FAIL, null); } else if (status == BluetoothHealth.APP_CONFIG_REGISTRATION_SUCCESS) { configs.add(config); sendMessage(STATUS_HEALTH_APP_REG, RESULT_OK, null); } else if (status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_FAILURE || status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_SUCCESS) { sendMessage(STATUS_HEALTH_APP_UNREG, status == BluetoothHealth.APP_CONFIG_UNREGISTRATION_SUCCESS ? RESULT_OK : RESULT_FAIL, null); } }
public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config, BluetoothDevice device, int prevState, int newState, ParcelFileDescriptor fd, int channelId) { Log.w(TAG, String.format("prevState\t%d ----------> newState\t%d", prevState, newState)); if (prevState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED && newState == BluetoothHealth.STATE_CHANNEL_CONNECTED) { if (acceptsConfiguration(config)) { insertDeviceConfiguration(device, config); insertChannelId(device, channelId); sendMessage(STATUS_CREATE_CHANNEL, RESULT_OK, device); FileOutputStream wr = new FileOutputStream(fd.getFileDescriptor()); insertWriter(device, wr); (new ReadThread(device, fd)).start(); } else { sendMessage(STATUS_CREATE_CHANNEL, RESULT_FAIL, device); } } else if (prevState == BluetoothHealth.STATE_CHANNEL_CONNECTING && newState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED) { sendMessage(STATUS_CREATE_CHANNEL, RESULT_FAIL, device); removeWriter(device); } else if (newState == BluetoothHealth.STATE_CHANNEL_DISCONNECTED) { if (acceptsConfiguration(config)) { sendMessage(STATUS_DESTROY_CHANNEL, RESULT_OK, device); removeWriter(device); } else { sendMessage(STATUS_DESTROY_CHANNEL, RESULT_FAIL, device); removeWriter(device); } } }
private boolean acceptsConfiguration(BluetoothHealthAppConfiguration config) { return configs.contains(config); }
private synchronized void insertDeviceConfiguration(BluetoothDevice dev, BluetoothHealthAppConfiguration config) { deviceconfigs.put(dev, config); }
private void unregisterApp() { for (BluetoothHealthAppConfiguration app: configs) { mBluetoothHealth.unregisterAppConfiguration(app); } }
private void connectChannel(BluetoothDevice dev) { Log.w(TAG, "connectChannel()"); BluetoothHealthAppConfiguration app = getDeviceConfiguration(dev); if (app != null) mBluetoothHealth.connectChannelToSource(dev, app); }
private void disconnectChannel(BluetoothDevice dev) { Log.w(TAG, "disconnectChannel()"); BluetoothHealthAppConfiguration app = getDeviceConfiguration(dev); if (app != null) mBluetoothHealth.disconnectChannel(dev, app, getChannelId(dev)); }