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

Commit 76dd2ce9 authored by Danica Chang's avatar Danica Chang Committed by Android (Google) Code Review
Browse files

Merge "Wait for bluetooth to turn on before Bluetooth Tethering is enabled"

parents f7b472fa 8aac82a5
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");