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

Commit 389812b4 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes Ibd740f0b,I4bffa752 into main

* changes:
  AutoOn: Clear stored timer when setting is toggled
  AutoOn: Clear stored timer when bluetooth is on
parents 20bb5ff6 300eb71a
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -109,6 +109,10 @@ public fun notifyBluetoothOn(context: Context) {
        } else {
            Log.i(TAG, "Feature was set to its default value ${defaultFeatureValue}")
        }
    } else {
        // When Bluetooth turned on state, any saved time will be obsolete.
        // This happen only when the phone reboot while Bluetooth is ON
        Timer.resetStorage(context.contentResolver)
    }
}

@@ -138,6 +142,7 @@ public fun setUserEnabled(
    Counter.logIncrement(
        if (status) "bluetooth.value_auto_on_enabled" else "bluetooth.value_auto_on_disabled"
    )
    Timer.resetStorage(context.contentResolver)
    resetAutoOnTimerForUser(looper, context, state, callback_on)
}

@@ -204,7 +209,7 @@ private constructor(
            return date?.let { LocalDateTime.parse(it) }
        }

        private fun resetStorage(resolver: ContentResolver) {
        fun resetStorage(resolver: ContentResolver) {
            Settings.Secure.putString(resolver, STORAGE_KEY, null)
        }

+25 −1
Original line number Diff line number Diff line
@@ -209,6 +209,16 @@ class AutoOnFeatureTest {
        assertThat(isUserSupported(resolver)).isTrue()
    }

    @Test
    fun notifyBluetoothOn_whenStorage_resetStorage() {
        Settings.Secure.putString(resolver, Timer.STORAGE_KEY, timerTarget.toString())
        shadowOf(looper).idle()

        notifyBluetoothOn(context)

        expectNoStorageTime()
    }

    @Test
    fun apiIsUserEnable_whenItWasNeverUsed_throwException() {
        restoreSettings()
@@ -259,7 +269,21 @@ class AutoOnFeatureTest {
        disableUserSettings()

        setUserEnabled(true)
        setupTimer()

        assertThat(timer).isNotNull()
    }

    @Test
    fun apiSetUserEnableToggle_whenScheduled_isRescheduled() {
        val pastTime = timerTarget.minusDays(3)
        Settings.Secure.putString(resolver, Timer.STORAGE_KEY, pastTime.toString())
        shadowOf(looper).idle()

        setUserEnabled(false)
        expectNoStorageTime()

        setUserEnabled(true)
        expectStorageTime()

        assertThat(timer).isNotNull()
    }