summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2020-09-03 13:26:05 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-09-03 13:26:05 +0000
commite7af3e1adbdce106b5a42c9bd3128d7dc0dbf733 (patch)
treef2f2984d43b24cafdf069d85f18341a3eb72bd94
parent3223c578cb3a4f749662bef6e034d5f7f3a0c4d3 (diff)
parent4477d12e0db07bf1517949a63dfb38797a3ccabc (diff)
Merge "Don't create a file with empty favorites" into rvc-qpr-dev
-rw-r--r--packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt4
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapperTest.kt12
2 files changed, 16 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt
index 1bda841d4a63..d930c98cabe1 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt
@@ -87,6 +87,10 @@ class ControlsFavoritePersistenceWrapper(
* @param list a list of favorite controls. The list will be stored in the same order.
*/
fun storeFavorites(structures: List<StructureInfo>) {
+ if (structures.isEmpty() && !file.exists()) {
+ // Do not create a new file to store nothing
+ return
+ }
executor.execute {
Log.d(TAG, "Saving data to file: $file")
val atomicFile = AtomicFile(file)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapperTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapperTest.kt
index 861c6207f5b0..690b9a7248be 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapperTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapperTest.kt
@@ -25,6 +25,7 @@ import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.time.FakeSystemClock
import org.junit.After
import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -78,4 +79,15 @@ class ControlsFavoritePersistenceWrapperTest : SysuiTestCase() {
assertEquals(list, wrapper.readFavorites())
}
+
+ @Test
+ fun testSaveEmptyOnNonExistingFile() {
+ if (file.exists()) {
+ file.delete()
+ }
+
+ wrapper.storeFavorites(emptyList())
+
+ assertFalse(file.exists())
+ }
}