Android Intent - OpenVPN autoconnect not working

Hi there,

I’m attempting to configure an adroid notifiction from Home Asssitant that includes firing an intent to autoconnect my VPN…

However I get no response on my phone, no toast displayed no nothing.
I got no clue on how to debug it…

I’ve also attemptd to use the command_activity with no luck.

This is the yaml I’m currently testing, but failing:

service: notify.titi
data:
  message: command_broadcast_intent
  title: "android.intent.action.VIEW"
  data:
    channel: "net.openvpn.openvpn"
    group: "net.openvpn.openvpn.AUTOSTART_PROFILE_NAME:Home, net.openvpn.openvpn.AUTOCONNECT:true, net.openvpn.openvpn.APP_SECTION:PC"

Any help is appreciated to fix this.

go to app configuration and check the logs section after you reproduce the issue…should see some level of logs there

Thanks for the suggestion, unfortunately the logs don’t help much. I see the intent being sent by HA but android tells me to “verify command format”.
So the logs don’t provide additional information on why it fails…

Since it says verify command format did you go back to the docs to make sure you followed it precisely? It seems you have spaces after the commas under the group tag but do you see that exact format in the examples? Probably need to remove those extra spaces

I idd check the docs many times… I’ve attempted to use command_activity as well as command_broadcast_intent
But both I have issues with…

Looking more deeply at the logs, I see an exception being returned:

10-03 16:15:35.639 29954 12406 D MessagingService: From: 331041709873
10-03 16:15:35.639 29954 12406 D MessagingService: Message data payload: {tag=android.intent.action.VIEW, channel=net.openvpn.openvpn, message=command_activity}
10-03 16:15:35.640 29954 12406 D MessagingService: Processing device command
10-03 16:15:35.641 29954 12338 E sqlite3_android: ONEPLUS_NAME_PARTS_MATCH SQLITE_OK
10-03 16:15:35.642 29954 12406 E MessagingService: Unable to send activity intent please check command format
10-03 16:15:35.642 29954 12406 E MessagingService: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW flg=0x10000000 pkg=net.openvpn.openvpn }
10-03 16:15:35.642 29954 12406 E MessagingService: 	at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2258)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at android.app.Instrumentation.execStartActivity(Instrumentation.java:1914)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at android.app.ContextImpl.startActivity(ContextImpl.java:1034)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at android.app.ContextImpl.startActivity(ContextImpl.java:1005)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at android.content.ContextWrapper.startActivity(ContextWrapper.java:403)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at io.homeassistant.companion.android.notifications.MessagingService.processActivityCommand(MessagingService.kt:1283)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at io.homeassistant.companion.android.notifications.MessagingService.handleDeviceCommands(MessagingService.kt:536)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at io.homeassistant.companion.android.notifications.MessagingService.onMessageReceived(MessagingService.kt:287)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:[email protected]@22.0.0:13)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:[email protected]@22.0.0:8)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:[email protected]@22.0.0:3)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:[email protected]@22.0.0:3)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:[email protected]@22.0.0:1)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(Unknown Source:6)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:[email protected]@17.5.0:6)
10-03 16:15:35.642 29954 12406 E MessagingService: 	at java.lang.Thread.run(Thread.java:923)

Currently I’m not able to provide any class name through home assistant to provide additional guidance to android to locate the right endpoint…
Any idea Ho I can fix this?

Okay, doing some further digging, it seems I’m on the right track…
Looking at the implementation of the Intent in the Android app, it seems that the class cannot be provided.
Although Android "does it’s best to find the right one, in case of OpenVPN Connect it does not…

Original code in app:

try {
            val packageName = data["channel"]
            val action = data["tag"]
            val intentUri = if (!data[TITLE].isNullOrEmpty()) Uri.parse(data[TITLE]) else null
            val intent = if (intentUri != null) Intent(action, intentUri) else Intent(action)
            val type = data["subject"]
            if (!type.isNullOrEmpty())
                intent.type = type
            val extras = data["group"]
            if (!extras.isNullOrEmpty()) {
                val items = extras.split(',')
                for (item in items) {
                    val pair = item.split(":")
                    intent.putExtra(
                        pair[0],
                        if (pair[1].isDigitsOnly())
                            pair[1].toInt()
                        else if ((pair[1].toLowerCase() == "true") ||
                            (pair[1].toLowerCase() == "false")
                        )
                            pair[1].toBoolean()
                        else pair[1]
                    )
                }
            }

Using Automate (similar to Tasker), I experience same error when I remove the Class parameter.
Hence it seems somehow required…

Can this be enhance that we can at least provide the class through the YAML config in HA?

some applications require the component/class name to be provided, not all though.

PR to allow the class name: https://github.com/home-assistant/android/pull/1749