Mygod / VPNHotspot

Share your VPN connection over hotspot or repeater! (root required)
Apache License 2.0
3.55k stars 361 forks source link

Tasker integration #26

Closed Mygod closed 2 weeks ago

Mygod commented 6 years ago

@sea3pea0: https://github.com/Mygod/VPNHotspot/issues/9#issuecomment-401563308

How about the ability to control this app via intents so that we could use tasker to initiate actions in this app? I have an android head unit in my car that is connected to an android phone acting as a hotspot and running this app.

The only way I've found to reliably avoid having my hotspot being throttled by t-mobile is to share the hotspot through a vpn connection.

Right now, when my car is turned on or the android phone boots up, tasker turns my hotspot on and when the car turns off the hotspot is turned off by tasker. With tasker I sense whether the car is on or off by the charging cable for the phone. If its charging, the car is on and if not its off.

It would be great if I could also have an action to turn vpn hotspot on for my wlan as one of the actions. This way the process would be automated.

As of now, if the hotspot is turned off and then back on, I have to go manually into the vpn hotspot app and re-toggle the wlan switch to route the hotspot traffic back through the vpn.

Thanks in adavnce for your help and/or consideration for this feature request. Obviously if it was possible for this app to remember the last setting and just ensure that either after boot or if the hotspot is turned off and back on that traffic would be routed through the vpn, this would work for me too. If its easier to make this possible through the use of tasker automations perhaps this would help others too.

And maybe MacroDroid as well?

Mygod commented 5 years ago

A more compelling reason to support this would be for instant tethering. This could be done by checking wifiApConfiguration.SSID and see if it matches ^Instant Tethering.

Unfortunately, listening for ACTION_TETHER_STATE_CHANGED in manifest is not quite possible since Android 8, therefore a persistent foreground service would be needed. MacroDroid only supports listening for hotspot changes, and none at all for Tasker.

EDIT: I created a thread on their forum. Go spam them until they add this.

sea3pea0 commented 5 years ago

I'm still in the same boat. When I turn my car on, my hotspot is started and to get vpn/hotspot working I have to open the app and hit the wlan switch to route the hotspot through my vpn. I was thinking about trying to automate this process with tasker by opening vpn hotspot after tasker turns the hotspot on and then have tasker use the cli to initiate a screen press over the wlan switch to turn it on. It seems like this might be worth a try since my scenario should be fairly predictable because the only thing I use the phone for is the hotspot connection. I haven't looked at macro droid yet, but I'll have to check it out

Mygod commented 5 years ago

Meanwhile, I think a good workaround would be a monitoring mode for system VPN tethering. I will implement it in 2.3.0.

Kerrnel commented 5 years ago

Bump on implementing intent interface. I can not find an app as reliable in turning on & off tethering - just by itself, w/o VPN involvement. I'd love to use it with Llama to automate getting into the car and having tethering for my car radio / off when out. (On a side note... gets me thinking AppleScript for Android should be a thing with object & class interface definition part of every app.)

the-mentor commented 5 years ago

Why not use the tasker plugin system? https://tasker.joaoapps.com/plugins-intro.html

Awesome app btw! -DM

GluTbl commented 5 years ago

it will be a very lentgthy addition to enable tasker integration.

if you want to add with short code, just add some a Broadcastreceiver to receive intent... and trigget hr e action in the source code... Now from the Tasker send the Intent directly.

if you make a tasker plugin... you need to read whole documentation of tasker plugin making.

If i have free time i might add this tasker facility

sollermun commented 3 years ago

Has anyone figured out a good way to automatically toggle the rndis0 tunnel? I'm using a phone to act as a usb modem for a router. I've managed to automate turning on the usb hotspot and VPN. The missing piece would be to automatically turn on rndis0 whenever usb tethering is reset.

cocoands commented 2 years ago

+1 for Tasker integration. I also think making the app compatible with the AutoInput accessibility service would be another good place to start. It should be simpler than writing a new plugin. AutoInput currently can not interact with the VPN Hotspot UI, but if it could, manually toggling the switches as @sea3pea0 and @sollermun describe wouldn't be an issue.

Swap-File commented 1 year ago

I recently noticed that VPN Hotspot was able to toggle Bluetooth Tethering off and on without being systemized on android 13.

This interested me greatly, since all the other tools I used to use to toggle BT Tethering off and on refused to work on Android 13, even when systemized.

I've never done Android development before, but I sat down with Android Studio and copy & pasted the Tile Handler into a Broadcast Handler which can receive intents from MacroDroid or Tasker.

Here is what the changes look like if anyone wants to build a copy for themselves (or add more intents to support more automation): https://github.com/Swap-File/VPNHotspot/commit/a4024d2a2306aa3d3842d29ec513b8d9358179dc

I'm not sure if there is a limit to how many intents you can add to the manifest, but two work fine for me.

Here's what the intent looks like inside of Macrodroid: image

xangma commented 1 year ago

I recently noticed that VPN Hotspot was able to toggle Bluetooth Tethering off and on without being systemized on android 13.

This interested me greatly, since all the other tools I used to use to toggle BT Tethering off and on refused to work on Android 13, even when systemized.

I've never done Android development before, but I sat down with Android Studio and copy & pasted the Tile Handler into a Broadcast Handler which can receive intents from MacroDroid or Tasker.

Here is what the changes look like if anyone wants to build a copy for themselves (or add more intents to support more automation): Swap-File@a4024d2

I'm not sure if there is a limit to how many intents you can add to the manifest, but two work fine for me.

Here's what the intent looks like inside of Macrodroid: ...

Hello! Thanks so much for this information. With your (and an LLM's help) I was able to build and test this in a couple of hours, and it works great. And obviously thanks to the original app developer/s too! :-D

hansonxyz commented 1 year ago

Hi there,

I was really interested in this thread, as my goal was to automate bringing up a wireguard vpn interface and programmatically starting the hotspot via tasker. To do this, I needed to both add the broadcastreceiver to receive the intent to start tethering, as described above, and also have the program automatically monitor all new interfaces that were added. I made these modifications and published them in a modified source code here:

https://github.com/hansonxyz/vpnhotspotmod

The key extra changes to the code Swap-File added was changing the TetheringService from START_NOT_STICKY to START_STICKY, and adding the following code around line 565 on TetheringManager.kt:


                            method.matches1<java.util.List<*>>("onTetheredInterfacesChanged") -> {
                                @Suppress("UNCHECKED_CAST")
                                val tetheredInterfaces = args!![0] as List<String?>
                                callback?.onTetheredInterfacesChanged(tetheredInterfaces)

                                // hansonxyz
                                tetheredInterfaces?.let {
                                    for (iface in it) {
                                        App.app.startForegroundService(
                                            Intent(App.app, TetheringService::class.java)
                                                .putExtra(
                                                    TetheringService.EXTRA_ADD_INTERFACES,
                                                    arrayOf(iface)
                                                )
                                        )
                                    }
                                }
                            }
ibnusaja commented 1 year ago

Hi there,

I was really interested in this thread, as my goal was to automate bringing up a wireguard vpn interface and programmatically starting the hotspot via tasker. To do this, I needed to both add the broadcastreceiver to receive the intent to start tethering, as described above, and also have the program automatically monitor all new interfaces that were added. I made these modifications and published them in a modified source code here:

https://github.com/hansonxyz/vpnhotspotmod

The key extra changes to the code Swap-File added was changing the TetheringService from START_NOT_STICKY to START_STICKY, and adding the following code around line 565 on TetheringManager.kt:


                            method.matches1<java.util.List<*>>("onTetheredInterfacesChanged") -> {
                                @Suppress("UNCHECKED_CAST")
                                val tetheredInterfaces = args!![0] as List<String?>
                                callback?.onTetheredInterfacesChanged(tetheredInterfaces)

                                // hansonxyz
                                tetheredInterfaces?.let {
                                    for (iface in it) {
                                        App.app.startForegroundService(
                                            Intent(App.app, TetheringService::class.java)
                                                .putExtra(
                                                    TetheringService.EXTRA_ADD_INTERFACES,
                                                    arrayOf(iface)
                                                )
                                        )
                                    }
                                }
                            }

for adb shell am ? can you hel me for the command line ? thanks before

hachazo commented 1 month ago

@Mygod Hello, I wanted to ask you a question, since I am trying to compile the application. I already managed to get the vpn and hotspot to start automatically, but I want it to be activated automatically when I start the wlan0 application. Can you help me, I don't know very well what files to modify.

Mygod commented 2 weeks ago

Fixed via #591.