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
This commit is contained in:
@@ -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? {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user