I'm trying to enable and disable Wireguard tunnels through the ADB shell.
I can see the followings actions and receivers are available :
adb:# dumpsys package com.wireguard.android
...
Receiver Resolver Table:
Non-Data Actions:
com.wireguard.android.action.SET_TUNNEL_UP:
4166aa1 com.wireguard.android/.model.TunnelManager$IntentReceiver filter 631a6bf
Action: "com.wireguard.android.action.REFRESH_TUNNEL_STATES"
Action: "com.wireguard.android.action.SET_TUNNEL_UP"
Action: "com.wireguard.android.action.SET_TUNNEL_DOWN"
com.wireguard.android.action.REFRESH_TUNNEL_STATES:
4166aa1 com.wireguard.android/.model.TunnelManager$IntentReceiver filter 631a6bf
Action: "com.wireguard.android.action.REFRESH_TUNNEL_STATES"
Action: "com.wireguard.android.action.SET_TUNNEL_UP"
Action: "com.wireguard.android.action.SET_TUNNEL_DOWN"
com.wireguard.android.action.SET_TUNNEL_DOWN:
4166aa1 com.wireguard.android/.model.TunnelManager$IntentReceiver filter 631a6bf
Action: "com.wireguard.android.action.REFRESH_TUNNEL_STATES"
Action: "com.wireguard.android.action.SET_TUNNEL_UP"
Action: "com.wireguard.android.action.SET_TUNNEL_DOWN"
android.intent.action.BOOT_COMPLETED:
4f4cb74 com.wireguard.android/.BootShutdownReceiver filter 426c4de
Action: "android.intent.action.ACTION_SHUTDOWN"
Action: "android.intent.action.BOOT_COMPLETED"
android.intent.action.ACTION_SHUTDOWN:
4f4cb74 com.wireguard.android/.BootShutdownReceiver filter 426c4de
Action: "android.intent.action.ACTION_SHUTDOWN"
Action: "android.intent.action.BOOT_COMPLETED"
...
Looking at the package's sourcecode, I see that com.wireguard.android/.model.TunnelManager$IntentReceiver
asks for the name of the tunnel to enable/disable to be passed as an extra string :
val tunnelName = intent.getStringExtra("tunnel") ?: return@launch
val tunnels = manager.getTunnels()
val tunnel = tunnels[tunnelName] ?: return@launch
So I tried two different versions of the same command to enable a tunnel named my-tunnel
:
adb:# am broadcast -a com.wireguard.android.action.SET_TUNNEL_UP -e tunnel my-tunnel
Broadcasting: Intent { act=com.wireguard.android.action.SET_TUNNEL_UP flg=0x400000 (has extras) }
Broadcast completed: result=0
# am broadcast -a com.wireguard.android.action.SET_TUNNEL_UP -e tunnel my-tunnel -n com.wireguard.android/.model.TunnelManager$IntentReceiver
Broadcasting: Intent { act=com.wireguard.android.action.SET_TUNNEL_UP flg=0x400000 cmp=com.wireguard.android/.model.TunnelManager (has extras) }
Broadcast completed: result=0
But after checking on my phone my-tunnel
is still disabled.
What am I missing ? Note that I'm pretty new to using ADB commands so it might be something obvious.
am
then actual code is executed asynchronously, therefore you never get an result. Effectively this means the result code you see is meaningless.