Search in sources :

Example 86 with BluetoothDevice

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

the class BluetoothEventManager method readPairedDevices.

boolean readPairedDevices() {
    Set<BluetoothDevice> bondedDevices = mLocalAdapter.getBondedDevices();
    if (bondedDevices == null) {
        return false;
    }
    boolean deviceAdded = false;
    for (BluetoothDevice device : bondedDevices) {
        CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
        if (cachedDevice == null) {
            cachedDevice = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, device);
            dispatchDeviceAdded(cachedDevice);
            deviceAdded = true;
        }
    }
    return deviceAdded;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 87 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project BleLiteLib4android by afunx.

the class BleConnectOperation method run.

@Override
public void run() {
    BluetoothDevice bluetoothDevice = BleUtils.getRemoteDevice(mBleAddr);
    //        bluetoothDevice.fetchUuidsWithSdp();
    BleConnector connector = getConnector();
    if (connector == null) {
        connector = new BleConnector.Builder().build(mAppContext, bluetoothDevice).setGattCallback(mBluetoothGattCallback).create();
        setConnector(connector);
    }
    connector.connect();
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) BleConnector(com.afunx.ble.blelitelib.connector.BleConnector)

Example 88 with BluetoothDevice

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

the class ScanFilterTest method setUp.

@Override
protected void setUp() throws Exception {
    byte[] scanRecord = new byte[] { // advertising flags
    0x02, // advertising flags
    0x01, // advertising flags
    0x1a, // 16 bit service uuids
    0x05, // 16 bit service uuids
    0x02, // 16 bit service uuids
    0x0b, // 16 bit service uuids
    0x11, // 16 bit service uuids
    0x0a, // 16 bit service uuids
    0x11, // setName
    0x04, // setName
    0x09, // setName
    0x50, // setName
    0x65, // setName
    0x64, // tx power level
    0x02, // tx power level
    0x0A, // tx power level
    (byte) 0xec, // service data
    0x05, // service data
    0x16, // service data
    0x0b, // service data
    0x11, // service data
    0x50, // service data
    0x64, // manufacturer specific data
    0x05, // manufacturer specific data
    (byte) 0xff, // manufacturer specific data
    (byte) 0xe0, // manufacturer specific data
    0x00, // manufacturer specific data
    0x02, // manufacturer specific data
    0x15, // an unknown data type won't cause trouble
    0x03, // an unknown data type won't cause trouble
    0x50, // an unknown data type won't cause trouble
    0x01, // an unknown data type won't cause trouble
    0x02 };
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice device = adapter.getRemoteDevice(DEVICE_MAC);
    mScanResult = new ScanResult(device, ScanRecord.parseFromBytes(scanRecord), -10, 1397545200000000L);
    mFilterBuilder = new ScanFilter.Builder();
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ScanFilter(android.bluetooth.le.ScanFilter) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 89 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DockEventReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (intent == null)
        return;
    int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, EXTRA_INVALID));
    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    if (DEBUG) {
        Log.d(TAG, "Action: " + intent.getAction() + " State:" + state + " Device: " + (device == null ? "null" : device.getAliasName()));
    }
    if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction()) || ACTION_DOCK_SHOW_UI.endsWith(intent.getAction())) {
        if ((device == null) && (ACTION_DOCK_SHOW_UI.endsWith(intent.getAction()) || ((state != Intent.EXTRA_DOCK_STATE_UNDOCKED) && (state != Intent.EXTRA_DOCK_STATE_LE_DESK)))) {
            if (DEBUG)
                Log.d(TAG, "Wrong state: " + state + " or intent: " + intent.toString() + " with null device");
            return;
        }
        switch(state) {
            case Intent.EXTRA_DOCK_STATE_UNDOCKED:
            case Intent.EXTRA_DOCK_STATE_CAR:
            case Intent.EXTRA_DOCK_STATE_DESK:
            case Intent.EXTRA_DOCK_STATE_LE_DESK:
            case Intent.EXTRA_DOCK_STATE_HE_DESK:
                Intent i = new Intent(intent);
                i.setClass(context, DockService.class);
                beginStartingService(context, i);
                break;
            default:
                Log.e(TAG, "Unknown state: " + state);
                break;
        }
    } else if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction()) || BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
        int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_CONNECTED);
        int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0);
        /*
             *  Reconnect to the dock if:
             *  1) it is a dock
             *  2) it is disconnected
             *  3) the disconnect is initiated remotely
             *  4) the dock is still docked (check can only be done in the Service)
             */
        if (device == null) {
            if (DEBUG)
                Log.d(TAG, "Device is missing");
            return;
        }
        if (newState == BluetoothProfile.STATE_DISCONNECTED && oldState != BluetoothProfile.STATE_DISCONNECTING) {
            // Too bad, the dock state can't be checked from a BroadcastReceiver.
            Intent i = new Intent(intent);
            i.setClass(context, DockService.class);
            beginStartingService(context, i);
        }
    } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
        int btState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
        if (btState != BluetoothAdapter.STATE_TURNING_ON) {
            Intent i = new Intent(intent);
            i.setClass(context, DockService.class);
            beginStartingService(context, i);
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) Intent(android.content.Intent)

Example 90 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceProfilesSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mManager = Utils.getLocalBtManager(getActivity());
    CachedBluetoothDeviceManager deviceManager = mManager.getCachedDeviceManager();
    String address = getArguments().getString(ARG_DEVICE_ADDRESS);
    BluetoothDevice remoteDevice = mManager.getBluetoothAdapter().getRemoteDevice(address);
    mCachedDevice = deviceManager.findDevice(remoteDevice);
    if (mCachedDevice == null) {
        mCachedDevice = deviceManager.addDevice(mManager.getBluetoothAdapter(), mManager.getProfileManager(), remoteDevice);
    }
    mProfileManager = mManager.getProfileManager();
}
Also used : CachedBluetoothDeviceManager(com.android.settingslib.bluetooth.CachedBluetoothDeviceManager) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

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