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

Commit 5e82dc9f authored by William Escande's avatar William Escande
Browse files

SystemServer: AutoOn: Set default feature value

Feature is enabled by default on device that support it.

Bug: 323060869
Bug: 316946334
Test: atest ServiceBluetoothRoboTests
Change-Id: Ib1808e46cff46bbf2d6a10f0c0dbe6d0ae784742
parent 723af485
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -56,9 +56,14 @@ public fun resetAutoOnTimerForUser(
    timer = Timer.start(looper, callback_on)
}

public fun notifyBluetoothOn() {
public fun notifyBluetoothOn(resolver: ContentResolver) {
    timer?.cancel()
    timer = null

    if (!isFeatureSupportedForUser(resolver)) {
        Log.i(TAG, "Feature was set to its default value")
        setFeatureEnabledForUserUnchecked(resolver)
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -128,3 +133,21 @@ private constructor(
private fun isFeatureEnabledForUser(resolver: ContentResolver): Boolean {
    return Settings.Secure.getInt(resolver, USER_SETTINGS_KEY, 0) == 1
}

/**
 * *Do not use outside of this file to avoid async issues*
 *
 * @return whether the auto on feature is supported for the user
 */
private fun isFeatureSupportedForUser(resolver: ContentResolver): Boolean {
    return Settings.Secure.getInt(resolver, USER_SETTINGS_KEY, -1) != -1
}

/**
 * *Do not use outside of this file to avoid async issues*
 *
 * @return whether the auto on feature is enabled for this user
 */
private fun setFeatureEnabledForUserUnchecked(resolver: ContentResolver) {
    Settings.Secure.putInt(resolver, USER_SETTINGS_KEY, 1)
}
+11 −2
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ class AutoOnFeatureTest {

    @Test
    fun notifyBluetoothOn_whenNoTimer_noCrash() {
        notifyBluetoothOn()
        notifyBluetoothOn(resolver)

        assertThat(timer).isNull()
    }
@@ -145,10 +145,19 @@ class AutoOnFeatureTest {
    @Test
    fun notifyBluetoothOn_whenTimer_isNotScheduled() {
        setupTimer()
        notifyBluetoothOn()
        notifyBluetoothOn(resolver)

        shadowOf(looper).runToEndOfTasks()
        expect.that(callback_count).isEqualTo(0)
        expect.that(timer).isNull()
    }

    @Test
    fun notifyBluetoothOn_whenItWasNeverUsed_enableSettings() {
        restoreSettings()

        notifyBluetoothOn(resolver)

        assertThat(Settings.Secure.getInt(resolver, USER_SETTINGS_KEY, 42)).isEqualTo(1)
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -2156,7 +2156,7 @@ class BluetoothManagerService {
        // Notify all proxy objects first of adapter state change
        if (newState == STATE_ON) {
            if (mDeviceConfigAllowAutoOn) {
                AutoOnFeature.notifyBluetoothOn();
                AutoOnFeature.notifyBluetoothOn(mCurrentUserContext.getContentResolver());
            }
            sendBluetoothOnCallback();
        } else if (newState == STATE_OFF) {