Skip to content

Commit

Permalink
fix: Fixed concurrent modification exception in SessionRecordingPolic…
Browse files Browse the repository at this point in the history
…yManager
  • Loading branch information
timschneeb committed Mar 6, 2023
1 parent f251956 commit 7835771
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class SessionRecordingPolicyManager(private val context: Context) {

fun clearSessions(){
Timber.d("Cleared session policy list")
sessionPolicyList.clear()
synchronized(sessionPolicyList) {
sessionPolicyList.clear()
}
}

fun update(dump: ISessionPolicyInfoDump)
Expand All @@ -43,11 +45,13 @@ class SessionRecordingPolicyManager(private val context: Context) {
}

var isMinorUpdate = true
removedPolicies.forEach {
Timber.d("Removed session policy: ${it.value}")
sessionPolicyList.remove(it.key)
if(it.value.isRestricted) {
isMinorUpdate = false
synchronized(sessionPolicyList) {
removedPolicies.forEach {
Timber.d("Removed session policy: ${it.value}")
sessionPolicyList.remove(it.key)
if (it.value.isRestricted) {
isMinorUpdate = false
}
}
}

Expand Down Expand Up @@ -87,15 +91,19 @@ class SessionRecordingPolicyManager(private val context: Context) {
Timber.d("Updated session policy: $data")
else if(data.isRestricted) // Only log new restricted sessions
Timber.d("Added session policy: $data")
sessionPolicyList[data.packageName] = data
synchronized(sessionPolicyList) {
sessionPolicyList[data.packageName] = data
}
}

fun getRestrictedUids(): Array<Int> {
return sessionPolicyList.values.toMutableList() // create copy to prevent concurrent access
.filter { it.isRestricted }
.filter { it.uid > 0 }
.map { it.uid }
.toTypedArray()
return synchronized(sessionPolicyList) {
sessionPolicyList.values // create copy to prevent concurrent access
.filter { it.isRestricted }
.filter { it.uid > 0 }
.map { it.uid }
.toTypedArray()
}
}

fun registerOnRestrictedSessionChangeListener(changeListener: OnSessionRecordingPolicyChangeListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ abstract class BaseSessionDatabase(protected val context: Context) {
}
}

// TODO use synchronized() block
fun setExcludedUids(uids: Array<Int>) {
excludedUids = uids

Expand Down

0 comments on commit 7835771

Please sign in to comment.