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

Commit b77a45b6 authored by Roman Birg's avatar Roman Birg
Browse files

Settings: add Bluetooth tethering option to BT overflow menu



Same toggle as in Settings > More > Tethering > BT Tethering.

Change-Id: I9455cb369e72eb4102d7238977c51564fabaa3c0
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 7e2428f8
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
@@ -62,6 +64,7 @@ import com.android.settings.widget.SwitchBar;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;

/**
 * BluetoothSettings is the Settings screen for Bluetooth configuration and
@@ -74,6 +77,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
    private static final int MENU_ID_RENAME_DEVICE = Menu.FIRST + 1;
    private static final int MENU_ID_SHOW_RECEIVED = Menu.FIRST + 2;
    private static final int MENU_ID_ACCEPT_ALL_FILES = Menu.FIRST + 3;
    private static final int MENU_ID_ENABLE_BLUETOOTH_TETHERING = Menu.FIRST + 4;

    /* Private intent to show the list of received files */
    private static final String BTOPP_ACTION_OPEN_RECEIVED_FILES =
@@ -95,6 +99,17 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem

    private final IntentFilter mIntentFilter;

    private AtomicReference<BluetoothPan> mBluetoothPan = new AtomicReference<BluetoothPan>();
    private BluetoothProfile.ServiceListener mProfileServiceListener =
            new BluetoothProfile.ServiceListener() {
                public void onServiceConnected(int profile, BluetoothProfile proxy) {
                    mBluetoothPan.set((BluetoothPan) proxy);
                }
                public void onServiceDisconnected(int profile) {
                    mBluetoothPan.set(null);
                }
            };


    // accessed from inner class (not private to avoid thunks)
    Preference mMyDevicePreference;
@@ -142,6 +157,13 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem

        mBluetoothEnabler = new BluetoothEnabler(activity, mSwitchBar);
        mBluetoothEnabler.setupSwitchBar();

        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter != null) {
            adapter.getProfileProxy(activity.getApplicationContext(), mProfileServiceListener,
                    BluetoothProfile.PAN);
        }

    }

    @Override
@@ -215,6 +237,9 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
        boolean isAcceptAllFilesEnabled = Settings.System.getInt(getContentResolver(),
                Settings.System.BLUETOOTH_ACCEPT_ALL_FILES, 0) == 1;

        final BluetoothPan bluetoothPan = mBluetoothPan.get();
        boolean isBluetoothTetheringEnabled = bluetoothPan != null && bluetoothPan.isTetheringOn();

        menu.add(Menu.NONE, MENU_ID_SCAN, 0, textId)
                .setEnabled(bluetoothIsEnabled && !isDiscovering)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
@@ -227,6 +252,11 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
                .setCheckable(true)
                .setChecked(isAcceptAllFilesEnabled)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        menu.add(Menu.NONE, MENU_ID_ENABLE_BLUETOOTH_TETHERING, 0,
                R.string.bluetooth_tether_checkbox_text)
                .setCheckable(true)
                .setChecked(isBluetoothTetheringEnabled)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        super.onCreateOptionsMenu(menu, inflater);
    }

@@ -255,6 +285,15 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
                        Settings.System.BLUETOOTH_ACCEPT_ALL_FILES,
                        item.isChecked() ? 1 : 0);
                return true;

            case MENU_ID_ENABLE_BLUETOOTH_TETHERING:
                final BluetoothPan bluetoothPan = mBluetoothPan.get();
                if (bluetoothPan != null) {
                    item.setChecked(!item.isChecked());
                    bluetoothPan.setBluetoothTethering(item.isChecked());
                }
                return true;

        }
        return super.onOptionsItemSelected(item);
    }