Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8aac82a5 authored by Danica Chang's avatar Danica Chang
Browse files

Wait for bluetooth to turn on before Bluetooth Tethering is enabled

Change-Id: I3fef94ea2cb102e1bb618f85e25d60c95cea1221
parent 2b342f0a
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -1256,13 +1256,33 @@ public class BluetoothService extends IBluetooth.Stub {
        return mTetheringOn;
    }

    public synchronized void setBluetoothTethering(boolean value, String uuid, String bridge) {
    private BroadcastReceiver mTetheringReceiver = null;

    public synchronized void setBluetoothTethering(boolean value, 
            final String uuid, final String bridge) {
        mTetheringOn = value;
        if (!value) {
            disconnectPan();
        }

        if (getBluetoothState() != BluetoothAdapter.STATE_ON && mTetheringOn) {
            IntentFilter filter = new IntentFilter();
            filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
            mTetheringReceiver = new BroadcastReceiver() {
                @Override
                public synchronized void onReceive(Context context, Intent intent) {
                    if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF)
                            == BluetoothAdapter.STATE_ON) {
                        setBluetoothTethering(true, uuid, bridge);
                        mContext.unregisterReceiver(mTetheringReceiver);
                    }
                }
            };
            mContext.registerReceiver(mTetheringReceiver, filter);
        } else {
            setBluetoothTetheringNative(value, uuid, bridge);
        }
    }

    public synchronized int getPanDeviceState(BluetoothDevice device) {
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");