Search in sources :

Example 1 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by ParanoidAndroid.

the class BluetoothGatt method writeDescriptor.

/**
     * Write the value of a given descriptor to the associated remote device.
     *
     * <p>A {@link BluetoothGattCallback#onDescriptorWrite} callback is
     * triggered to report the result of the write operation.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param descriptor Descriptor to write to the associated remote device
     * @return true, if the write operation was initiated successfully
     */
public boolean writeDescriptor(BluetoothGattDescriptor descriptor) {
    if (DBG)
        Log.d(TAG, "writeDescriptor() - uuid: " + descriptor.getUuid());
    if (mService == null || mClientIf == 0)
        return false;
    BluetoothGattCharacteristic characteristic = descriptor.getCharacteristic();
    if (characteristic == null)
        return false;
    BluetoothGattService service = characteristic.getService();
    if (service == null)
        return false;
    BluetoothDevice device = service.getDevice();
    if (device == null)
        return false;
    try {
        mService.writeDescriptor(mClientIf, device.getAddress(), service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()), characteristic.getInstanceId(), new ParcelUuid(characteristic.getUuid()), new ParcelUuid(descriptor.getUuid()), characteristic.getWriteType(), AUTHENTICATION_NONE, descriptor.getValue());
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
        return false;
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothDevice(android.bluetooth.BluetoothDevice) RemoteException(android.os.RemoteException)

Example 2 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by ParanoidAndroid.

the class BluetoothGatt method readCharacteristic.

/**
     * Reads the requested characteristic from the associated remote device.
     *
     * <p>This is an asynchronous operation. The result of the read operation
     * is reported by the {@link BluetoothGattCallback#onCharacteristicRead}
     * callback.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param characteristic Characteristic to read from the remote device
     * @return true, if the read operation was initiated successfully
     */
public boolean readCharacteristic(BluetoothGattCharacteristic characteristic) {
    if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0)
        return false;
    if (DBG)
        Log.d(TAG, "readCharacteristic() - uuid: " + characteristic.getUuid());
    if (mService == null || mClientIf == 0)
        return false;
    BluetoothGattService service = characteristic.getService();
    if (service == null)
        return false;
    BluetoothDevice device = service.getDevice();
    if (device == null)
        return false;
    try {
        mService.readCharacteristic(mClientIf, device.getAddress(), service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()), characteristic.getInstanceId(), new ParcelUuid(characteristic.getUuid()), AUTHENTICATION_NONE);
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
        return false;
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothDevice(android.bluetooth.BluetoothDevice) RemoteException(android.os.RemoteException)

Example 3 with BluetoothDevice

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

the class BluetoothA2dpService method onBluetoothDisable.

private synchronized void onBluetoothDisable() {
    if (!mAudioDevices.isEmpty()) {
        BluetoothDevice[] devices = new BluetoothDevice[mAudioDevices.size()];
        devices = mAudioDevices.keySet().toArray(devices);
        for (BluetoothDevice device : devices) {
            int state = getConnectionState(device);
            switch(state) {
                case BluetoothA2dp.STATE_CONNECTING:
                case BluetoothA2dp.STATE_CONNECTED:
                case BluetoothA2dp.STATE_PLAYING:
                    disconnectSinkNative(mBluetoothService.getObjectPathFromAddress(device.getAddress()));
                    handleSinkStateChange(device, state, BluetoothA2dp.STATE_DISCONNECTED);
                    break;
                case BluetoothA2dp.STATE_DISCONNECTING:
                    handleSinkStateChange(device, BluetoothA2dp.STATE_DISCONNECTING, BluetoothA2dp.STATE_DISCONNECTED);
                    break;
            }
        }
        mAudioDevices.clear();
    }
    mAudioManager.setParameters(BLUETOOTH_ENABLED + "=false");
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 4 with BluetoothDevice

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

the class BluetoothA2dpService method onConnectSinkResult.

/**
     * Called by native code for the async response to a Connect
     * method call to org.bluez.AudioSink.
     *
     * @param deviceObjectPath the object path for the connecting device
     * @param result true on success; false on error
     */
private void onConnectSinkResult(String deviceObjectPath, boolean result) {
    // when we a Sink Property Change
    if (!result) {
        if (deviceObjectPath != null) {
            String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath);
            if (address == null)
                return;
            BluetoothDevice device = mAdapter.getRemoteDevice(address);
            int state = getConnectionState(device);
            handleSinkStateChange(device, state, BluetoothA2dp.STATE_DISCONNECTED);
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 5 with BluetoothDevice

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

the class BluetoothA2dpService method onBluetoothEnable.

private synchronized void onBluetoothEnable() {
    String devices = mBluetoothService.getProperty("Devices", true);
    if (devices != null) {
        String[] paths = devices.split(",");
        for (String path : paths) {
            String address = mBluetoothService.getAddressFromObjectPath(path);
            BluetoothDevice device = mAdapter.getRemoteDevice(address);
            ParcelUuid[] remoteUuids = mBluetoothService.getRemoteUuids(address);
            if (remoteUuids != null)
                if (BluetoothUuid.containsAnyUuid(remoteUuids, new ParcelUuid[] { BluetoothUuid.AudioSink, BluetoothUuid.AdvAudioDist })) {
                    addAudioSink(device);
                }
        }
    }
    mAudioManager.setParameters(BLUETOOTH_ENABLED + "=true");
    mAudioManager.setParameters("A2dpSuspended=false");
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothDevice(android.bluetooth.BluetoothDevice)

Aggregations

BluetoothDevice (android.bluetooth.BluetoothDevice)402 CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)95 Intent (android.content.Intent)47 NonNull (androidx.annotation.NonNull)36 Test (org.junit.Test)35 MapProfile (com.android.settingslib.bluetooth.MapProfile)30 PbapServerProfile (com.android.settingslib.bluetooth.PbapServerProfile)30 A2dpProfile (com.android.settingslib.bluetooth.A2dpProfile)28 ActiveBluetoothDevice (com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice)26 BluetoothAdapter (android.bluetooth.BluetoothAdapter)25 View (android.view.View)21 TextView (android.widget.TextView)21 PanProfile (com.android.settingslib.bluetooth.PanProfile)21 SwitchPreference (android.support.v14.preference.SwitchPreference)18 IntentFilter (android.content.IntentFilter)17 PendingIntent (android.app.PendingIntent)16 Transmitter (com.eveningoutpost.dexdrip.G5Model.Transmitter)16 Method (java.lang.reflect.Method)16 LocalBluetoothManager (com.android.settingslib.bluetooth.LocalBluetoothManager)14 LocalBluetoothProfile (com.android.settingslib.bluetooth.LocalBluetoothProfile)13