robinpaulson / SimpleRT

Simple Reverse Tethering utility for Android
GNU General Public License v3.0
912 stars 95 forks source link

Launch service over adb? #34

Open pmeenan opened 7 years ago

pmeenan commented 7 years ago

Is it possible to start the service directly without requiring physically detaching and re-attaching the USB cable?

In an automated lab environment we may be rebooting devices remotely and managing the state of the device over adb and it is pretty critical to be able to start/stop remotely. It feels like I'm pretty close but may be missing something:

$ adb shell am startservice com.viper.simplert/.TetherService
Starting service: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.viper.simplert/.TetherService }
Error: Requires permission android.permission.BIND_VPN_SERVICE
$ adb shell pm grant com.viper.simplert android.permission.BIND_VPN_SERVICE
Operation not allowed: java.lang.SecurityException: Package com.viper.simplert has not requested permission android.permission.BIND_VPN_SERVICE

Stopping it remotely (and cleanly) is pretty easy:

adb shell am force-stop com.viper.simplert
vvviperrr commented 7 years ago

Hi. i suppose, it's possible. Give me some time to research this issue

pmeenan commented 7 years ago

FWIW, gnirehtet uses a control service with .START and .STOP intents

In the meantime, it's a bit ugly but setting the usb config will toggle the interface and start the VPN:

adb shell su -c 'setprop sys.usb.config adb'

The VPN confirmation dialog can also be detected:

dumpsys window windows | grep vpndialogs

and dismissed:

adb shell input keyevent KEYCODE_DPAD_RIGHT
adb shell input keyevent KEYCODE_ENTER
adb shell input keyevent KEYCODE_DPAD_RIGHT
adb shell input keyevent KEYCODE_ENTER

I need to test a couple different releases to see if the permissions dialog is the same but it looks like it is at least possible. It's a shame that the dialog comes up after every reboot.

That said, it would be a lot cleaner if:

robinpaulson commented 3 years ago

@pmeenan How are you getting on with this? Have you found any further info, or a suitable workaround? Or anything else relevant?

pmeenan commented 3 years ago

I went a different path and updated a fork of vpn-reverse-tether