From 2504be45cf610d384fc9ea0aefd212e3a2f686b5 Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 25 Oct 2019 05:01:11 +0800 Subject: [PATCH] Fix ConcurrentModificationException in ServiceNotification --- .../java/be/mygod/vpnhotspot/ServiceNotification.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt b/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt index bb972100..67612156 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/ServiceNotification.kt @@ -51,11 +51,13 @@ object ServiceNotification { } fun startForeground(service: Service, deviceCounts: Map, inactive: List = emptyList()) { - deviceCountsMap[service] = deviceCounts - if (inactive.isEmpty()) inactiveMap.remove(service) else inactiveMap[service] = inactive - service.startForeground(CHANNEL_ID, buildNotification(service)) + synchronized(this) { + deviceCountsMap[service] = deviceCounts + if (inactive.isEmpty()) inactiveMap.remove(service) else inactiveMap[service] = inactive + service.startForeground(CHANNEL_ID, buildNotification(service)) + } } - fun stopForeground(service: Service) { + fun stopForeground(service: Service) = synchronized(this) { deviceCountsMap.remove(service) if (deviceCountsMap.isEmpty()) service.stopForeground(true) else { service.stopForeground(false)