mirror of
https://github.com/moparisthebest/SSLDroid
synced 2024-11-27 03:12:18 -05:00
Implemented network state change listener that stops the service on
connectivity loss and starts it once connectivity is regained Signed-off-by: Balint Kovacs <blint@blint.hu>
This commit is contained in:
parent
5d92ede437
commit
6c07dca8e0
@ -23,6 +23,11 @@
|
||||
<category android:name="android.intent.category.HOME" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name="NetworkChangeReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
31
src/hu/blint/ssldroid/NetworkChangeReceiver.java
Normal file
31
src/hu/blint/ssldroid/NetworkChangeReceiver.java
Normal file
@ -0,0 +1,31 @@
|
||||
package hu.blint.ssldroid;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.util.Log;
|
||||
|
||||
public class NetworkChangeReceiver extends BroadcastReceiver{
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE );
|
||||
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
|
||||
if ( activeNetInfo == null ) {
|
||||
Intent i = new Intent();
|
||||
i.setAction("hu.blint.ssldroid.SSLDroid");
|
||||
context.stopService(i);
|
||||
return;
|
||||
}
|
||||
Log.d("SSLDroid", activeNetInfo.toString());
|
||||
if (activeNetInfo.isAvailable()) {
|
||||
Intent i = new Intent();
|
||||
i.setAction("hu.blint.ssldroid.SSLDroid");
|
||||
context.stopService(i);
|
||||
context.startService(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,10 +18,12 @@ import java.util.ListIterator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.database.Cursor;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
@ -66,7 +68,6 @@ public class SSLDroidTunnelDetails extends Activity {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
rowId = null;
|
||||
Bundle extras = getIntent().getExtras();
|
||||
rowId = (bundle == null) ? null : (Long) bundle
|
||||
@ -119,13 +120,17 @@ public class SSLDroidTunnelDetails extends Activity {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
//remote host should exist
|
||||
//if we have interwebs access, the remote host should exist
|
||||
ConnectivityManager conMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
if ( conMgr.getActiveNetworkInfo() != null || conMgr.getActiveNetworkInfo().isAvailable()) {
|
||||
try {
|
||||
InetAddress.getByName(remotehost.getText().toString());
|
||||
} catch (UnknownHostException e){
|
||||
Toast.makeText(getBaseContext(), "Remote host not found, please recheck...", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
//remote port validation
|
||||
if (remoteport.getText().length() == 0){
|
||||
Toast.makeText(getBaseContext(), "Required remote port parameter not setup, skipping save", Toast.LENGTH_LONG).show();
|
||||
|
@ -155,7 +155,6 @@ public class TcpProxyServerThread extends Thread {
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
//TODO: close client sockets if no data network is available
|
||||
Thread fromBrowserToServer = null;
|
||||
Thread fromServerToBrowser = null;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user