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

Commit b4a3fae9 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Fixes NPE in list from PrivacyItemController"

parents 94aeae08 7209010c
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