diff options
author | 2024-04-11 22:21:25 -0700 | |
---|---|---|
committer | 2024-04-23 14:30:17 -0700 | |
commit | aab4e9e01ddc6134e6ba8e811fab95840df240a6 (patch) | |
tree | 78f522037382a75fdccc6a9cce2cf99df36e53ea | |
parent | 65718a9e4e0c23c0b48e034d19f958f394bd0f3d (diff) |
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
-rw-r--r-- | service/src/AutoOnFeature.kt | 6 | ||||
-rw-r--r-- | service/src/AutoOnFeatureTest.kt | 10 |
2 files changed, 15 insertions, 1 deletions
diff --git a/service/src/AutoOnFeature.kt b/service/src/AutoOnFeature.kt index 03fcabeeef..0f53bee7ad 100644 --- a/service/src/AutoOnFeature.kt +++ b/service/src/AutoOnFeature.kt @@ -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) } diff --git a/service/src/AutoOnFeatureTest.kt b/service/src/AutoOnFeatureTest.kt index 3b282e9faa..b511f70bb2 100644 --- a/service/src/AutoOnFeatureTest.kt +++ b/service/src/AutoOnFeatureTest.kt @@ -210,6 +210,16 @@ class AutoOnFeatureTest { } @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() |