Merge "fix FileNotFound exception when attempting to read bubble xml" into rvc-dev am: 750b4c93ec

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11758287

Change-Id: Ibc8d9c298090c9c8df132208078a7d9a3637bc56
This commit is contained in:
TreeHugger Robot
2020-06-05 23:14:50 +00:00
committed by Automerger Merge Worker
2 changed files with 8 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ class BubblePersistentRepository @Inject constructor(
fun readFromDisk(): List<BubbleEntity> {
synchronized(bubbleFile) {
if (!bubbleFile.exists()) return emptyList()
try { return bubbleFile.openRead().use(::readXml) } catch (e: Throwable) {
Log.e(TAG, "Failed to open bubble file", e)
}

View File

@@ -20,6 +20,8 @@ import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertNotNull
import junit.framework.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -42,6 +44,11 @@ class BubblePersistentRepositoryTest : SysuiTestCase() {
@Test
fun testReadWriteOperation() {
// Verify read before write doesn't cause FileNotFoundException
val actual = repository.readFromDisk()
assertNotNull(actual)
assertTrue(actual.isEmpty())
repository.persistsToDisk(bubbles)
assertEquals(bubbles, repository.readFromDisk())
}