Search in sources :

Example 26 with BluetoothDevice

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

the class DockService method handleBluetoothStateOn.

private void handleBluetoothStateOn(int startId) {
    if (mPendingDevice != null) {
        if (mPendingDevice.equals(mDevice)) {
            if (DEBUG) {
                Log.d(TAG, "applying settings");
            }
            applyBtSettings(mPendingDevice, mPendingStartId);
        } else if (DEBUG) {
            Log.d(TAG, "mPendingDevice  (" + mPendingDevice + ") != mDevice (" + mDevice + ')');
        }
        mPendingDevice = null;
        DockEventReceiver.finishStartingService(this, mPendingStartId);
    } else {
        final SharedPreferences prefs = getPrefs();
        if (DEBUG) {
            Log.d(TAG, "A DISABLE_BT_WHEN_UNDOCKED = " + prefs.getBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, false));
        }
        // Reconnect if docked and bluetooth was enabled by user.
        Intent i = registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT));
        if (i != null) {
            int state = i.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
            if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
                BluetoothDevice device = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                if (device != null) {
                    connectIfEnabled(device);
                }
            } else if (prefs.getBoolean(KEY_DISABLE_BT, false) && mLocalAdapter.disable()) {
                mPendingTurnOffStartId = startId;
                prefs.edit().remove(KEY_DISABLE_BT).apply();
                return;
            }
        }
    }
    if (mPendingTurnOnStartId != INVALID_STARTID) {
        DockEventReceiver.finishStartingService(this, mPendingTurnOnStartId);
        mPendingTurnOnStartId = INVALID_STARTID;
    }
    DockEventReceiver.finishStartingService(this, startId);
}
Also used : IntentFilter(android.content.IntentFilter) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent)

Example 27 with BluetoothDevice

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

the class DockService method handleUnexpectedDisconnect.

private synchronized void handleUnexpectedDisconnect(BluetoothDevice disconnectedDevice, LocalBluetoothProfile profile, int startId) {
    if (DEBUG) {
        Log.d(TAG, "handling failed connect for " + disconnectedDevice);
    }
    // Reconnect if docked.
    if (disconnectedDevice != null) {
        // registerReceiver can't be called from a BroadcastReceiver
        Intent intent = registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT));
        if (intent != null) {
            int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
            if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
                BluetoothDevice dockedDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                if (dockedDevice != null && dockedDevice.equals(disconnectedDevice)) {
                    CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(dockedDevice);
                    cachedDevice.connectProfile(profile);
                }
            }
        }
    }
    DockEventReceiver.finishStartingService(this, startId);
}
Also used : IntentFilter(android.content.IntentFilter) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) Intent(android.content.Intent)

Example 28 with BluetoothDevice

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

the class DockService method msgTypeDocked.

private boolean msgTypeDocked(BluetoothDevice device, final int state, final int startId) {
    if (DEBUG) {
        // TODO figure out why hasMsg always returns false if device
        // is supplied
        Log.d(TAG, "1 Has undock perm msg = " + mServiceHandler.hasMessages(MSG_TYPE_UNDOCKED_PERMANENT, mDevice));
        Log.d(TAG, "2 Has undock perm msg = " + mServiceHandler.hasMessages(MSG_TYPE_UNDOCKED_PERMANENT, device));
    }
    mServiceHandler.removeMessages(MSG_TYPE_UNDOCKED_PERMANENT);
    mServiceHandler.removeMessages(MSG_TYPE_DISABLE_BT);
    getPrefs().edit().remove(KEY_DISABLE_BT).apply();
    if (device != null) {
        if (!device.equals(mDevice)) {
            if (mDevice != null) {
                // Not expected. Cleanup/undock existing
                handleUndocked(mDevice);
            }
            mDevice = device;
            // Register first in case LocalBluetoothProfileManager
            // becomes ready after isManagerReady is called and it
            // would be too late to register a service listener.
            mProfileManager.addServiceListener(this);
            if (mProfileManager.isManagerReady()) {
                handleDocked(device, state, startId);
                // Not needed after all
                mProfileManager.removeServiceListener(this);
            } else {
                final BluetoothDevice d = device;
                mRunnable = new Runnable() {

                    public void run() {
                        // FIXME: WTF runnable here?
                        handleDocked(d, state, startId);
                    }
                };
                return true;
            }
        }
    } else {
        // display dialog to enable dock for media audio only in the case of low end docks and
        // if not already selected by user
        int dockAudioMediaEnabled = Settings.Global.getInt(getContentResolver(), Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, -1);
        if (dockAudioMediaEnabled == -1 && state == Intent.EXTRA_DOCK_STATE_LE_DESK) {
            handleDocked(null, state, startId);
            return true;
        }
    }
    return false;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 29 with BluetoothDevice

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

the class MidiService method openBluetoothDevice.

@Override
public void openBluetoothDevice(IBinder token, BluetoothDevice bluetoothDevice, IMidiDeviceOpenCallback callback) {
    Client client = getClient(token);
    if (client == null)
        return;
    // Bluetooth devices are created on demand
    Device device;
    synchronized (mDevicesByInfo) {
        device = mBluetoothDevices.get(bluetoothDevice);
        if (device == null) {
            device = new Device(bluetoothDevice);
            mBluetoothDevices.put(bluetoothDevice, device);
        }
    }
    // clear calling identity so bindService does not fail
    long identity = Binder.clearCallingIdentity();
    try {
        client.addDeviceConnection(device, callback);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 30 with BluetoothDevice

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

the class MidiService method addDeviceLocked.

// synchronize on mDevicesByInfo
private MidiDeviceInfo addDeviceLocked(int type, int numInputPorts, int numOutputPorts, String[] inputPortNames, String[] outputPortNames, Bundle properties, IMidiDeviceServer server, ServiceInfo serviceInfo, boolean isPrivate, int uid) {
    int id = mNextDeviceId++;
    MidiDeviceInfo deviceInfo = new MidiDeviceInfo(type, id, numInputPorts, numOutputPorts, inputPortNames, outputPortNames, properties, isPrivate);
    if (server != null) {
        try {
            server.setDeviceInfo(deviceInfo);
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in setDeviceInfo()");
            return null;
        }
    }
    Device device = null;
    BluetoothDevice bluetoothDevice = null;
    if (type == MidiDeviceInfo.TYPE_BLUETOOTH) {
        bluetoothDevice = (BluetoothDevice) properties.getParcelable(MidiDeviceInfo.PROPERTY_BLUETOOTH_DEVICE);
        device = mBluetoothDevices.get(bluetoothDevice);
        if (device != null) {
            device.setDeviceInfo(deviceInfo);
        }
    }
    if (device == null) {
        device = new Device(server, deviceInfo, serviceInfo, uid);
    }
    mDevicesByInfo.put(deviceInfo, device);
    if (bluetoothDevice != null) {
        mBluetoothDevices.put(bluetoothDevice, device);
    }
    synchronized (mClients) {
        for (Client c : mClients.values()) {
            c.deviceAdded(device);
        }
    }
    return deviceInfo;
}
Also used : MidiDeviceInfo(android.media.midi.MidiDeviceInfo) BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) RemoteException(android.os.RemoteException)

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