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

Commit aab4e9e0 authored by William Escande's avatar William Escande
Browse files

AutoOn: Clear stored timer when bluetooth is on

Timer is obsolete when bluetooth reach state on. Deleting the storage
prevent miss-activation of the feature

Bug: 323060869
Bug: 333353069
Fix: 333353069
Flag: com.android.bluetooth.flags.auto_on_feature
Test: atest ServiceBluetoothRoboTest
Change-Id: I4bffa7527f81cbc82031eb41eb05720206a7bd67
parent 65718a9e
Loading
Loading
Loading
Loading
+5 −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)
    }
}

@@ -204,7 +208,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)
        }

+10 −0
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()