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

Commit 3724143e authored by William Escande's avatar William Escande
Browse files

Read persistedState in the serverProxy

This is a prerequisite to have configurable test and change the expected
behavior without having the test to relly on actually writing on
settings.Global

Bug: 262605980
Test: atest ServiceBluetoothTests
Change-Id: Ie3f98d2b5060c6b3f6a14038e5f823baddd8c889
parent 1b715a66
Loading
Loading
Loading
Loading
+16 −21
Original line number Diff line number Diff line
@@ -170,7 +170,8 @@ class BluetoothManagerService {
    private static final int BLUETOOTH_OFF = 0;
    // Bluetooth persisted setting is on
    // and Airplane mode won't affect Bluetooth state at start up
    private static final int BLUETOOTH_ON_BLUETOOTH = 1;
    // This is the default value
    @VisibleForTesting static final int BLUETOOTH_ON_BLUETOOTH = 1;
    // Bluetooth persisted setting is on
    // but Airplane mode will affect Bluetooth state at start up
    // and Airplane mode will have higher priority.
@@ -793,42 +794,36 @@ class BluetoothManagerService {
        return Settings.Global.getInt(mContext.getContentResolver(), APM_ENHANCEMENT, 0) == 1;
    }

    private boolean supportBluetoothPersistedState() {
        // Set default support to true to copy config default.
        return BluetoothProperties.isSupportPersistedStateEnabled().orElse(true);
    }

    /** Returns true if the Bluetooth saved state is "on" */
    private boolean isBluetoothPersistedStateOn() {
        if (!supportBluetoothPersistedState()) {
            return false;
        }
        int state = Settings.Global.getInt(mContentResolver, Settings.Global.BLUETOOTH_ON, -1);
        final int state =
                BluetoothServerProxy.getInstance()
                        .getBluetoothPersistedState(mContentResolver, BLUETOOTH_ON_BLUETOOTH);
        if (DBG) {
            Log.d(TAG, "Bluetooth persisted state: " + state);
            Log.d(TAG, "isBluetoothPersistedStateOn: " + state);
        }
        return state != BLUETOOTH_OFF;
    }

    private boolean isBluetoothPersistedStateOnAirplane() {
        if (!supportBluetoothPersistedState()) {
            return false;
        }
        int state = Settings.Global.getInt(mContentResolver, Settings.Global.BLUETOOTH_ON, -1);
        final int state =
                BluetoothServerProxy.getInstance()
                        .getBluetoothPersistedState(mContentResolver, BLUETOOTH_ON_BLUETOOTH);
        if (DBG) {
            Log.d(TAG, "Bluetooth persisted state: " + state);
            Log.d(TAG, "isBluetoothPersistedStateOnAirplane: " + state);
        }
        return state == BLUETOOTH_ON_AIRPLANE;
    }

    /** Returns true if the Bluetooth saved state is BLUETOOTH_ON_BLUETOOTH */
    private boolean isBluetoothPersistedStateOnBluetooth() {
        if (!supportBluetoothPersistedState()) {
            return false;
        final int state =
                BluetoothServerProxy.getInstance()
                        .getBluetoothPersistedState(mContentResolver, BLUETOOTH_ON_BLUETOOTH);
        if (DBG) {
            Log.d(TAG, "isBluetoothPersistedStateOnBluetooth: " + state);
        }
        return Settings.Global.getInt(
                        mContentResolver, Settings.Global.BLUETOOTH_ON, BLUETOOTH_ON_BLUETOOTH)
                == BLUETOOTH_ON_BLUETOOTH;
        return state == BLUETOOTH_ON_BLUETOOTH;
    }

    /** Save the Bluetooth on/off state */
+4 −0
Original line number Diff line number Diff line
@@ -91,6 +91,10 @@ public class BluetoothServerProxy {
        return Settings.Secure.getString(contentResolver, name);
    }

    int getBluetoothPersistedState(ContentResolver resolver, int defaultValue) {
        return Settings.Global.getInt(resolver, Settings.Global.BLUETOOTH_ON, defaultValue);
    }

    /**
     * Proxies
     * {@link com.android.server.bluetooth.BluetoothManagerService.BluetoothHandler.sendMessage}.