1
0
mirror of https://github.com/moparisthebest/SSLDroid synced 2024-11-23 09:22:16 -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:
Balint Kovacs 2011-05-04 14:07:25 +02:00
parent 5d92ede437
commit 6c07dca8e0
4 changed files with 49 additions and 9 deletions

View File

@ -23,6 +23,11 @@
<category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.HOME" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name="NetworkChangeReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
</application> </application>
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

View 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);
}
}
}

View File

@ -18,10 +18,12 @@ import java.util.ListIterator;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.database.Cursor; import android.database.Cursor;
import android.net.ConnectivityManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.util.Log; import android.util.Log;
@ -66,7 +68,6 @@ public class SSLDroidTunnelDetails extends Activity {
} }
}); });
rowId = null; rowId = null;
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
rowId = (bundle == null) ? null : (Long) bundle rowId = (bundle == null) ? null : (Long) bundle
@ -119,13 +120,17 @@ public class SSLDroidTunnelDetails extends Activity {
return; return;
} }
else { 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 { try {
InetAddress.getByName(remotehost.getText().toString()); InetAddress.getByName(remotehost.getText().toString());
} catch (UnknownHostException e){ } catch (UnknownHostException e){
Toast.makeText(getBaseContext(), "Remote host not found, please recheck...", Toast.LENGTH_LONG).show(); Toast.makeText(getBaseContext(), "Remote host not found, please recheck...", Toast.LENGTH_LONG).show();
} }
} }
}
//remote port validation //remote port validation
if (remoteport.getText().length() == 0){ if (remoteport.getText().length() == 0){
Toast.makeText(getBaseContext(), "Required remote port parameter not setup, skipping save", Toast.LENGTH_LONG).show(); Toast.makeText(getBaseContext(), "Required remote port parameter not setup, skipping save", Toast.LENGTH_LONG).show();

View File

@ -155,7 +155,6 @@ public class TcpProxyServerThread extends Thread {
public void run() { public void run() {
while (true) { while (true) {
try { try {
//TODO: close client sockets if no data network is available
Thread fromBrowserToServer = null; Thread fromBrowserToServer = null;
Thread fromServerToBrowser = null; Thread fromServerToBrowser = null;