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

@ -18,11 +18,16 @@
</intent-filter>
</service>
<receiver android:name="BootStartupReceiver">
<intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<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" />

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.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,12 +120,16 @@ public class SSLDroidTunnelDetails extends Activity {
return;
}
else {
//remote host should exist
try {
InetAddress.getByName(remotehost.getText().toString());
} catch (UnknownHostException e){
Toast.makeText(getBaseContext(), "Remote host not found, please recheck...", Toast.LENGTH_LONG).show();
}
//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){

View File

@ -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;