From 41a1347368c6f2b3a6165c688d481b9c79cc934d Mon Sep 17 00:00:00 2001 From: Kristijan Date: Thu, 9 Jan 2025 12:56:22 +0100 Subject: [PATCH] Resolve permissions Android --- .../wireguard_dart/WireguardDartPlugin.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/android/src/main/kotlin/network/mysterium/wireguard_dart/WireguardDartPlugin.kt b/android/src/main/kotlin/network/mysterium/wireguard_dart/WireguardDartPlugin.kt index 0ebaef0..9491b78 100644 --- a/android/src/main/kotlin/network/mysterium/wireguard_dart/WireguardDartPlugin.kt +++ b/android/src/main/kotlin/network/mysterium/wireguard_dart/WireguardDartPlugin.kt @@ -45,6 +45,7 @@ class WireguardDartPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, private var config: com.wireguard.config.Config? = null private var tunnel: WireguardTunnel? = null private var tunnelName: String? = null + private var permissionsResultCallback: Result? = null private var status: ConnectionStatus = ConnectionStatus.disconnected set(value) { field = value @@ -60,6 +61,16 @@ class WireguardDartPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean { if (requestCode == PERMISSIONS_REQUEST_CODE) { havePermission = resultCode == Activity.RESULT_OK + if (havePermission) { + permissionsResultCallback?.success(null) + } else { + permissionsResultCallback?.error( + "err_setup_tunnel", + "Permissions are not given", + null + ) + + } } return havePermission } @@ -170,11 +181,9 @@ class WireguardDartPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, flutterError(result, "Tunnel name is invalid") return@launch } + permissionsResultCallback = result checkPermission() - if (havePermission) { - initTunnel(tunnelName) - } - result.success(null) + initTunnel(tunnelName) } }