Genymobile / gnirehtet

Gnirehtet provides reverse tethering for Android
Apache License 2.0
6.3k stars 579 forks source link

Auto stop gnirehtet app when disconnected #51

Open twoi opened 6 years ago

twoi commented 6 years ago

In https://github.com/Genymobile/gnirehtet/issues/49, we managed to come up with a script that automatically reestablishes the connection - which is great.

Now I also have a usb wired ethernet device, that I use alternatively with this reverse tethering solution. However, when the gnirehtet app is running on the device - and it stays running after pulling the plug - I cannot use the wired ethernet device until I stop gnirehtet. Then ethernet works, and when I switch back to reverse tethering, that works as well, as #49 restarts the app on the device.

So all I seem to need now to be 100% happy with this great tool, is the app to auto-stop when the usb cable is disconnected. Does it make sense to keep it running after unplugging in the first place? Because unplugging and replugging does not do the trick even when the app is running - hence the need for the script in #49 - and #49 does not require the app to stay running either. So unless there are scenarios I am not aware off, the gnirethet app should auto stop by default.

Biswa96 commented 6 years ago

Yeah, it stops by default when you disconnect USB from PC. The relay server shows client disconnected. Are you talking about this notification? Just tap it to stop. 😒

client_stop

twoi commented 6 years ago

@Biswa96 The app on the Android device continues running. The notification item (whatever the technical Android term for this would be) reads "Disconnected from the relay server" and displays a "STOP GNIREHTET" button.

rom1v commented 6 years ago

Does it make sense to keep it running after unplugging in the first place?

The rationale is that a user may use gnirehtet to connect to the trusted desktop network, and don't want to leak data if it switches back automatically to mobile network. That's why I wanted this action to be manual. (In practice, we detect the socket disconnection, not the cable unplug.)

However, we might consider adding an option to get the behavior you request, something like:

adb start -d   # disable on disconnect
twoi commented 6 years ago

OK, I see.

Having the -d parameter would work perfect for me! Except that -d is already taken - to override thedefault DNS server.

I haven't looked at the sources yet, and I'm sure you'd be able to implement this feature in 15 minutes, but if you'd prefer a pull request, do let me know.

I guess this would involve changes to all 3 projects: 1) the desktop side java code and 2) the rust code, to accept and forward the parameter to the android app and 3) the android java app to accept the parameter from the server and actually implement the feature

rom1v commented 6 years ago

Except that -d is already taken - to override the default DNS server.

Ahah, I managed to get a name conflict with only 2 parameters 😆.

but if you'd prefer a pull request, do let me know

If you're motivated, please do :) (start on the dev branch)

If you want to implement only the java or only the rust part, I'll take care of the other if necessary.

I guess this would involve changes to all 3 projects

Correct 👍

rom1v commented 6 years ago

@twoi Do you still consider implementing the option?

svladimirs commented 6 years ago

adb start -d # disable on disconnect Where and when I must do this? Before or after '@gnirehtet.exe autorun'?

rom1v commented 6 years ago

Where and when I must do this?

For now, never, it's not implemented.

midluk commented 6 years ago

I use gnirehtet when I have wired network on my notebook but only unreliable wifi and/or mobile data connection. I definitely want those connection methods used when I unplug my phone (better have unreliable connection than none at all, and the connection might be better at the place I move my phone to after unplugging). But currently I always have to unlock my phone to stop gnirehtet. There definitely should be an option to stop the app automatically. I can see the uses of preventing data from going through other untrusted channels, but are you sure that that use case is important for a majority of users?

rom1v commented 6 years ago

There definitely should be an option to stop the app automatically.

I'm ok with that.

I can see the uses of preventing data from going through other untrusted channels, but are you sure that that use case is important for a majority of users?

I don't know, but IMO it should have the "safe" behavior by default. As an explicit option, it's ok.

rom1v commented 6 years ago

I'll probably add an option when I have some time, but meanwhile you can just apply this change:

diff --git a/app/src/main/java/com/genymobile/gnirehtet/GnirehtetService.java b/app/src/main/java/com/genymobile/gnirehtet/GnirehtetService.java
index 7e8b716..70732cc 100644
--- a/app/src/main/java/com/genymobile/gnirehtet/GnirehtetService.java
+++ b/app/src/main/java/com/genymobile/gnirehtet/GnirehtetService.java
@@ -224,7 +224,7 @@ public class GnirehtetService extends VpnService {
                     break;
                 case RelayTunnelListener.MSG_RELAY_TUNNEL_DISCONNECTED:
                     Log.d(TAG, "Relay tunnel disconnected");
-                    vpnService.notifier.setFailure(true);
+                    vpnService.stop(vpnService);
                     break;
                 default:
             }
tango25001 commented 5 years ago

Can someone tell me, how i get this change into the app? Thank you very much

tango25001 commented 3 years ago

Hello I compiled the app with the above mentioned changes ans it worked fine so far - up to Android 9.

I bought a new Samsung Android 10 device and now the app does not exit automatically. Is there a solution for that?

Thank you!

simonferndriger commented 2 years ago

Hi

How can I use this if I can't compile this special feature but want to use it nevertheless? Can anyone release a version 2.6 with this addition please?