diff --git a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/session/rootless/SessionRecordingPolicyManager.kt b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/session/rootless/SessionRecordingPolicyManager.kt index 391617bb4..82ad4d200 100644 --- a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/session/rootless/SessionRecordingPolicyManager.kt +++ b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/session/rootless/SessionRecordingPolicyManager.kt @@ -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) @@ -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 + } } } @@ -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 { - 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) { diff --git a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/session/shared/BaseSessionDatabase.kt b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/session/shared/BaseSessionDatabase.kt index 1a1d5389d..7ca14b21f 100644 --- a/app/src/main/java/me/timschneeberger/rootlessjamesdsp/session/shared/BaseSessionDatabase.kt +++ b/app/src/main/java/me/timschneeberger/rootlessjamesdsp/session/shared/BaseSessionDatabase.kt @@ -103,7 +103,6 @@ abstract class BaseSessionDatabase(protected val context: Context) { } } - // TODO use synchronized() block fun setExcludedUids(uids: Array) { excludedUids = uids