Skip to content

Commit

Permalink
Fixes based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Dec 12, 2024
1 parent 9b64645 commit ae191c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import net.mullvad.mullvadvpn.lib.common.util.prepareVpnSafe
import net.mullvad.mullvadvpn.lib.daemon.grpc.GrpcConnectivityState
import net.mullvad.mullvadvpn.lib.daemon.grpc.ManagementService
import net.mullvad.mullvadvpn.lib.endpoint.ApiEndpointFromIntentHolder
import net.mullvad.mullvadvpn.lib.endpoint.getApiEndpointConfigurationExtras
import net.mullvad.mullvadvpn.lib.model.PrepareError
import net.mullvad.mullvadvpn.lib.model.Prepared
import net.mullvad.mullvadvpn.lib.theme.AppTheme
Expand Down Expand Up @@ -84,7 +85,7 @@ class MainActivity : ComponentActivity(), AndroidScopeComponent {
window.decorView.filterTouchesWhenObscured = true

// Needs to be before we start the service, since we need to access the intent there
setUpIntentListener()
lifecycleScope.launch { intents().collect(::handleIntent) }

// We use lifecycleScope here to get less start service in background exceptions
// Se this article for more information:
Expand Down Expand Up @@ -129,15 +130,13 @@ class MainActivity : ComponentActivity(), AndroidScopeComponent {
super.onDestroy()
}

private fun setUpIntentListener() {
lifecycleScope.launch {
intents().collect {
if (it.action == KEY_REQUEST_VPN_PROFILE) {
handleRequestVpnProfileIntent()
} else {
apiEndpointFromIntentHolder.handleIntent(it)
}
}
private fun handleIntent(intent: Intent) {
if (intent.action == KEY_REQUEST_VPN_PROFILE) {
handleRequestVpnProfileIntent()
} else {
apiEndpointFromIntentHolder.setApiEndpointOverride(
intent.getApiEndpointConfigurationExtras()
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package net.mullvad.mullvadvpn.lib.endpoint

import android.content.Intent

class ApiEndpointFromIntentHolder {
var apiEndpointOverride: ApiEndpointOverride? = null
private set

fun handleIntent(intent: Intent) {
apiEndpointOverride = intent.getApiEndpointConfigurationExtras()
fun setApiEndpointOverride(apiEndpointOverride: ApiEndpointOverride?) {
this.apiEndpointOverride = apiEndpointOverride
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package net.mullvad.mullvadvpn.lib.endpoint

import android.content.Intent

// Overridding the API endpoint is not supported in release builds
class ApiEndpointFromIntentHolder {
val apiEndpointOverride: ApiEndpointOverride? = null

fun handleIntent(intent: Intent) {
@Suppress("UnusedParameter")
fun setApiEndpointOverride(apiEndpointOverride: ApiEndpointOverride?) {
// No-op
}
}

0 comments on commit ae191c8

Please sign in to comment.