summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-11-14 10:02:54 +0100
committerAlbin <albin@mullvad.net>2023-03-16 15:55:37 +0100
commit87d4d90919cb677b3ae8d5effbdf4980aae7961b (patch)
treefc7a79c9070e3423b7dabcbea32661350510c736
parent4274c386ac4248136b0ae99fbd98f9a1deeea103 (diff)
downloadmullvadvpn-87d4d90919cb677b3ae8d5effbdf4980aae7961b.tar.xz
mullvadvpn-87d4d90919cb677b3ae8d5effbdf4980aae7961b.zip
Prevent unbind attempt if already unbound
Cherry-pick from: 5d8ee191100a195c675ff6a7dd1f09f04648778a
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionManager.kt33
1 files changed, 22 insertions, 11 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionManager.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionManager.kt
index f912f765a8..a2a6a63f03 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionManager.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionManager.kt
@@ -26,6 +26,7 @@ class ServiceConnectionManager(
@Deprecated(message = "Use connectionState")
val serviceNotifier = EventNotifier<ServiceConnectionContainer?>(null)
+ var isBound = false
private var vpnPermissionRequestHandler: (() -> Unit)? = null
private val serviceConnection = object : android.content.ServiceConnection {
@@ -54,22 +55,32 @@ class ServiceConnectionManager(
vpnPermissionRequestHandler: () -> Unit,
apiEndpointConfiguration: ApiEndpointConfiguration?
) {
- this.vpnPermissionRequestHandler = vpnPermissionRequestHandler
- val intent = Intent(context, MullvadVpnService::class.java)
+ synchronized(this) {
+ if (isBound.not()) {
+ this.vpnPermissionRequestHandler = vpnPermissionRequestHandler
+ val intent = Intent(context, MullvadVpnService::class.java)
- if (BuildConfig.DEBUG && apiEndpointConfiguration != null) {
- intent.putApiEndpointConfigurationExtra(apiEndpointConfiguration)
- }
+ if (BuildConfig.DEBUG && apiEndpointConfiguration != null) {
+ intent.putApiEndpointConfigurationExtra(apiEndpointConfiguration)
+ }
- context.startService(intent)
- context.bindService(intent, serviceConnection, 0)
+ context.startService(intent)
+ context.bindService(intent, serviceConnection, 0)
+ isBound = true
+ }
+ }
}
fun unbind() {
- _connectionState.value.readyContainer()?.onDestroy()
- context.unbindService(serviceConnection)
- notify(ServiceConnectionState.Disconnected)
- vpnPermissionRequestHandler = null
+ synchronized(this) {
+ if (isBound) {
+ _connectionState.value.readyContainer()?.onDestroy()
+ context.unbindService(serviceConnection)
+ notify(ServiceConnectionState.Disconnected)
+ vpnPermissionRequestHandler = null
+ isBound = false
+ }
+ }
}
fun onDestroy() {