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

Commit e21a4ac0 authored by Jaikumar Ganesh's avatar Jaikumar Ganesh Committed by Android (Google) Code Review
Browse files

Add a new version of the disable API.

This allows for the setting to be persisted or not.
Also turn on Bluetooth in System Server if needed.
It won't work currently because the service wouldn't have
started.

Change-Id: I15fa2bff93aa32134c1b565fcbe90ba68614b6a1
parent 75780aa4
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -518,7 +518,24 @@ public final class BluetoothAdapter {
     */
    public boolean disable() {
        try {
            return mService.disable();
            return mService.disable(true);
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
    }

    /**
     * Turn off the local Bluetooth adapter and don't persist the setting.
     *
     * <p>Requires the {@link android.Manifest.permission#BLUETOOTH_ADMIN}
     * permission
     *
     * @return true to indicate adapter shutdown has begun, or false on
     *         immediate error
     * @hide
     */
    public boolean disable(boolean persist) {
        try {
            return mService.disable(persist);
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
    }
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ interface IBluetooth
    boolean isEnabled();
    int getState();
    boolean enable();
    boolean disable();
    boolean disable(boolean persist);

    String getAddress();
    ParcelUuid[] getUuids();
+7 −1
Original line number Diff line number Diff line
@@ -241,11 +241,17 @@ class ServerThread extends Thread {
            } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
                Slog.i(TAG, "No Bluetooth Service (factory test)");
            } else {
                //TODO(BT): Start BT services and turn on if needed.
                int airplaneModeOn = Settings.System.getInt(mContentResolver,
                        Settings.System.AIRPLANE_MODE_ON, 0);
                int bluetoothOn = Settings.Secure.getInt(mContentResolver,
                    Settings.Secure.BLUETOOTH_ON, 0);
                BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
                // TODO(BT): This will not work as the Bluetooth process is not
                // up. Depending on the process architecture, BluetoothAdapter
                // will have to bind to the service.
                if (adapter != null && airplaneModeOn == 0 &&  bluetoothOn != 0) {
                    adapter.enable();
                }
            }

        } catch (RuntimeException e) {
+1 −2
Original line number Diff line number Diff line
@@ -340,8 +340,7 @@ public final class ShutdownThread extends Thread {
                           bluetooth.getState() == BluetoothAdapter.STATE_OFF;
            if (!bluetoothOff) {
                Log.w(TAG, "Disabling Bluetooth...");
                //TODO(BT)
                bluetooth.disable();  // disable but don't persist new state
                bluetooth.disable(false);  // disable but don't persist new state
            }
        } catch (RemoteException ex) {
            Log.e(TAG, "RemoteException during bluetooth shutdown", ex);