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

Commit 7209010c authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Fixes NPE in list from PrivacyItemController

NPE is probably caused by concurrent modification of the variable. Added
guards to prevent concurrent modification.

Test: current tests passing
Fixes: 127138070
Change-Id: I19220c2123bcc1b1a759e2a01592dde1bcd1316f
parent 63727e26
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -61,7 +61,8 @@ class PrivacyItemController @Inject constructor(

    @VisibleForTesting
    internal var privacyList = emptyList<PrivacyItem>()
        get() = field.toList() // Provides a shallow copy of the list
        @Synchronized get() = field.toList() // Returns a shallow copy of the list
        @Synchronized set

    private val userManager = context.getSystemService(UserManager::class.java)
    private var currentUserIds = emptyList<Int>()
@@ -71,7 +72,8 @@ class PrivacyItemController @Inject constructor(
    private val callbacks = mutableListOf<WeakReference<Callback>>()

    private val notifyChanges = Runnable {
        callbacks.forEach { it.get()?.privacyChanged(privacyList) }
        val list = privacyList
        callbacks.forEach { it.get()?.privacyChanged(list) }
    }

    private val updateListAndNotifyChanges = Runnable {
@@ -157,8 +159,10 @@ class PrivacyItemController @Inject constructor(
    }

    private fun updatePrivacyList() {
        privacyList = currentUserIds.flatMap { appOpsController.getActiveAppOpsForUser(it) }

        val list = currentUserIds.flatMap { appOpsController.getActiveAppOpsForUser(it) }
                .mapNotNull { toPrivacyItem(it) }.distinct()
        privacyList = list
    }

    private fun toPrivacyItem(appOpItem: AppOpItem): PrivacyItem? {
+3 −2
Original line number Diff line number Diff line
@@ -264,7 +264,8 @@ class PrivacyItemControllerTest : SysuiTestCase() {
        val list = listOf(PrivacyItem(PrivacyType.TYPE_CAMERA,
                PrivacyApplication("", TEST_UID, mContext)))
        privacyItemController.privacyList = list
        assertEquals(list, privacyItemController.privacyList)
        assertTrue(list !== privacyItemController.privacyList)
        val privacyList = privacyItemController.privacyList
        assertEquals(list, privacyList)
        assertTrue(list !== privacyList)
    }
}
 No newline at end of file