Search in sources :

Example 76 with BluetoothDevice

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

the class BluetoothEventLoop method onInputDeviceConnectionResult.

/**
     * Called by native code for the async response to a Connect
     * method call to org.bluez.Input.
     *
     * @param path the path of the specified input device
     * @param result Result code of the operation.
     */
private void onInputDeviceConnectionResult(String path, int result) {
    // Success case gets handled by Property Change signal
    if (result != BluetoothInputDevice.INPUT_OPERATION_SUCCESS) {
        String address = mBluetoothService.getAddressFromObjectPath(path);
        if (address == null)
            return;
        boolean connected = false;
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        int state = mBluetoothService.getInputDeviceConnectionState(device);
        if (state == BluetoothInputDevice.STATE_CONNECTING) {
            if (result == BluetoothInputDevice.INPUT_CONNECT_FAILED_ALREADY_CONNECTED) {
                connected = true;
            } else {
                connected = false;
            }
        } else if (state == BluetoothInputDevice.STATE_DISCONNECTING) {
            if (result == BluetoothInputDevice.INPUT_DISCONNECT_FAILED_NOT_CONNECTED) {
                connected = false;
            } else {
                // There is no better way to handle this, this shouldn't happen
                connected = true;
            }
        } else {
            Log.e(TAG, "Error onInputDeviceConnectionResult. State is:" + state);
        }
        mBluetoothService.handleInputDevicePropertyChange(address, connected);
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 77 with BluetoothDevice

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

the class BluetoothEventLoop method onPanDeviceConnectionResult.

/**
     * Called by native code for the async response to a Connect
     * method call to org.bluez.Network.
     *
     * @param path the path of the specified PAN device
     * @param result Result code of the operation.
     */
private void onPanDeviceConnectionResult(String path, int result) {
    log("onPanDeviceConnectionResult " + path + " " + result);
    // Success case gets handled by Property Change signal
    if (result != BluetoothPan.PAN_OPERATION_SUCCESS) {
        String address = mBluetoothService.getAddressFromObjectPath(path);
        if (address == null)
            return;
        boolean connected = false;
        BluetoothDevice device = mAdapter.getRemoteDevice(address);
        int state = mBluetoothService.getPanDeviceConnectionState(device);
        if (state == BluetoothPan.STATE_CONNECTING) {
            if (result == BluetoothPan.PAN_CONNECT_FAILED_ALREADY_CONNECTED) {
                connected = true;
            } else {
                connected = false;
            }
        } else if (state == BluetoothPan.STATE_DISCONNECTING) {
            if (result == BluetoothPan.PAN_DISCONNECT_FAILED_NOT_CONNECTED) {
                connected = false;
            } else {
                // There is no better way to handle this, this shouldn't happen
                connected = true;
            }
        } else {
            Log.e(TAG, "Error onPanDeviceConnectionResult. State is: " + state + " result: " + result);
        }
        int newState = connected ? BluetoothPan.STATE_CONNECTED : BluetoothPan.STATE_DISCONNECTED;
        mBluetoothService.handlePanDeviceStateChange(device, newState, BluetoothPan.LOCAL_PANU_ROLE);
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 78 with BluetoothDevice

use of android.bluetooth.BluetoothDevice 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)

Example 79 with BluetoothDevice

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

the class BluetoothPanProfileHandler method disconnectPanServerDevices.

private boolean disconnectPanServerDevices() {
    debugLog("disconnect all PAN devices");
    for (BluetoothDevice device : mPanDevices.keySet()) {
        BluetoothPanDevice panDevice = mPanDevices.get(device);
        int state = panDevice.mState;
        if (state == BluetoothPan.STATE_CONNECTED && panDevice.mLocalRole == BluetoothPan.LOCAL_NAP_ROLE) {
            String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
            handlePanDeviceStateChange(device, panDevice.mIface, BluetoothPan.STATE_DISCONNECTING, panDevice.mLocalRole);
            if (!mBluetoothService.disconnectPanServerDeviceNative(objectPath, device.getAddress(), panDevice.mIface)) {
                errorLog("could not disconnect Pan Server Device " + device.getAddress());
                // Restore prev state
                handlePanDeviceStateChange(device, panDevice.mIface, state, panDevice.mLocalRole);
                return false;
            }
        }
    }
    return true;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 80 with BluetoothDevice

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

the class BluetoothPanProfileHandler method connectPanDevice.

boolean connectPanDevice(BluetoothDevice device) {
    String objectPath = mBluetoothService.getObjectPathFromAddress(device.getAddress());
    if (DBG)
        Log.d(TAG, "connect PAN(" + objectPath + ")");
    if (getPanDeviceConnectionState(device) != BluetoothPan.STATE_DISCONNECTED) {
        errorLog(device + " already connected to PAN");
    }
    int connectedCount = 0;
    for (BluetoothDevice panDevice : mPanDevices.keySet()) {
        if (getPanDeviceConnectionState(panDevice) == BluetoothPan.STATE_CONNECTED) {
            connectedCount++;
        }
    }
    if (connectedCount > 8) {
        debugLog(device + " could not connect to PAN because 8 other devices are" + "already connected");
        return false;
    }
    // Send interface as null as it is not known
    handlePanDeviceStateChange(device, null, BluetoothPan.STATE_CONNECTING, BluetoothPan.LOCAL_PANU_ROLE);
    if (mBluetoothService.connectPanDeviceNative(objectPath, "nap")) {
        debugLog("connecting to PAN");
        return true;
    } else {
        handlePanDeviceStateChange(device, null, BluetoothPan.STATE_DISCONNECTED, BluetoothPan.LOCAL_PANU_ROLE);
        errorLog("could not connect to PAN");
        return false;
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Aggregations

BluetoothDevice (android.bluetooth.BluetoothDevice)101 Intent (android.content.Intent)13 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)11 ParcelUuid (android.os.ParcelUuid)9 RemoteException (android.os.RemoteException)9 ScanFilter (android.bluetooth.le.ScanFilter)5 Parcel (android.os.Parcel)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 IOException (java.io.IOException)5 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)5 IntentFilter (android.content.IntentFilter)4 MidiDeviceInfo (android.media.midi.MidiDeviceInfo)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2