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

Commit 23c9b688 authored by Pinyao Ting's avatar Pinyao Ting
Browse files

fix FileNotFound exception when attempting to read bubble xml

BubbleDataRepository tried to read the xml file before a write,
and the xml file is only created on write if it didn't exist,
which caused the FileNotFound exception.

Bug: 158231089
Test: BubblePersistentRepositoryTest
Change-Id: I7cd75b1d74be277df49f433338ad814ce50c87c1
parent 16fd58a0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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)
            }
+7 −0
Original line number Diff line number Diff line
@@ -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())
    }