Merge "Don't create a file with empty favorites" into rvc-qpr-dev am: e7af3e1adb
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12435066 Change-Id: I37dea759f6b173b634d5cfb19c368361c1c37008
This commit is contained in:
@@ -87,6 +87,10 @@ class ControlsFavoritePersistenceWrapper(
|
|||||||
* @param list a list of favorite controls. The list will be stored in the same order.
|
* @param list a list of favorite controls. The list will be stored in the same order.
|
||||||
*/
|
*/
|
||||||
fun storeFavorites(structures: List<StructureInfo>) {
|
fun storeFavorites(structures: List<StructureInfo>) {
|
||||||
|
if (structures.isEmpty() && !file.exists()) {
|
||||||
|
// Do not create a new file to store nothing
|
||||||
|
return
|
||||||
|
}
|
||||||
executor.execute {
|
executor.execute {
|
||||||
Log.d(TAG, "Saving data to file: $file")
|
Log.d(TAG, "Saving data to file: $file")
|
||||||
val atomicFile = AtomicFile(file)
|
val atomicFile = AtomicFile(file)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import com.android.systemui.util.concurrency.FakeExecutor
|
|||||||
import com.android.systemui.util.time.FakeSystemClock
|
import com.android.systemui.util.time.FakeSystemClock
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
@@ -78,4 +79,15 @@ class ControlsFavoritePersistenceWrapperTest : SysuiTestCase() {
|
|||||||
|
|
||||||
assertEquals(list, wrapper.readFavorites())
|
assertEquals(list, wrapper.readFavorites())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSaveEmptyOnNonExistingFile() {
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
wrapper.storeFavorites(emptyList())
|
||||||
|
|
||||||
|
assertFalse(file.exists())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user