Merge pull request 'handle network swap' (#32) from SD-230 into develop
Reviewed-on: #32 Reviewed-by: Cristi Ene <cristi.ene@safemobile.com>
This commit is contained in:
commit
8b89319d09
@ -102,10 +102,8 @@ public class TCPService extends Service {
|
|||||||
|
|
||||||
|
|
||||||
/** Stop TCP Connection */
|
/** Stop TCP Connection */
|
||||||
public void stopTCPConnection()
|
public void stopTCPConnection() {
|
||||||
{
|
if(tcp != null) {
|
||||||
if(tcp != null)
|
|
||||||
{
|
|
||||||
tcp.Stop();
|
tcp.Stop();
|
||||||
tcp = null;
|
tcp = null;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -74,6 +74,9 @@ import android.content.res.AssetManager;
|
|||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.Network;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
|
import android.net.NetworkRequest;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -571,7 +574,58 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
|
|
||||||
/* Create Service and bind to it */
|
/* Create Service and bind to it */
|
||||||
getApplicationContext().bindService(new Intent(this, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
|
getApplicationContext().bindService(new Intent(this, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
|
|
||||||
|
ConnectivityManager connectivityManager =
|
||||||
|
(ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||||
|
connectivityManager.registerDefaultNetworkCallback(networkCallback);
|
||||||
|
else {
|
||||||
|
NetworkRequest request = new NetworkRequest.Builder()
|
||||||
|
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build();
|
||||||
|
connectivityManager.registerNetworkCallback(request, networkCallback);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
|
||||||
|
@Override
|
||||||
|
public void onAvailable(Network network) {
|
||||||
|
// network available
|
||||||
|
Log.v(TAG, "network available");
|
||||||
|
Log.v(TAG, "tcp: " + (tcp != null));
|
||||||
|
|
||||||
|
if (tcp != null) {
|
||||||
|
if (tcp.isConnectionUP)
|
||||||
|
tcp.isConnectionUP = false;
|
||||||
|
|
||||||
|
uiHandler.post(() -> {
|
||||||
|
Log.v(TAG, "myService: " + (myService != null));
|
||||||
|
if (myService != null) {
|
||||||
|
myService.stopTCPConnection();
|
||||||
|
myService.recreateTCPConnection();
|
||||||
|
|
||||||
|
getApplicationContext().bindService(new Intent(context, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
if (getRadioActivity() != null)
|
||||||
|
getRadioActivity().onCreate(getRadioActivity().getSavedInstanceState());
|
||||||
|
if (getMessageActivity() != null)
|
||||||
|
getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
|
||||||
|
if (getRecordingsActivity() != null)
|
||||||
|
getRecordingsActivity().onCreate(getRecordingsActivity().getSavedInstanceState());
|
||||||
|
if (getAlarmActivity() != null)
|
||||||
|
getAlarmActivity().onCreate(getAlarmActivity().getSavedInstanceState());
|
||||||
|
|
||||||
|
uiHandler.post(initTCPRUN);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLost(Network network) {
|
||||||
|
// network unavailable
|
||||||
|
Log.v(TAG, "network unavailable");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcast Received for notifications
|
* Broadcast Received for notifications
|
||||||
@ -755,7 +809,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
if (getHistoryActivity() != null)
|
if (getHistoryActivity() != null)
|
||||||
getHistoryActivity().setLanguage();
|
getHistoryActivity().setLanguage();
|
||||||
if (getRadioActivity() != null)
|
if (getRadioActivity() != null)
|
||||||
getRadioActivity().onCreate(getRadioActivity().savedInstanceState);
|
getRadioActivity().onCreate(getRadioActivity().getSavedInstanceState());
|
||||||
if (getMessageActivity() != null)
|
if (getMessageActivity() != null)
|
||||||
getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
|
getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
|
||||||
if (getRecordingsActivity() != null)
|
if (getRecordingsActivity() != null)
|
||||||
@ -2074,7 +2128,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
|
|
||||||
getApplicationContext().bindService(new Intent(context, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
|
getApplicationContext().bindService(new Intent(context, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
if (getRadioActivity() != null)
|
if (getRadioActivity() != null)
|
||||||
getRadioActivity().onCreate(getRadioActivity().savedInstanceState);
|
getRadioActivity().onCreate(getRadioActivity().getSavedInstanceState());
|
||||||
if (getMessageActivity() != null)
|
if (getMessageActivity() != null)
|
||||||
getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
|
getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
|
||||||
if (getRecordingsActivity() != null)
|
if (getRecordingsActivity() != null)
|
||||||
@ -2098,7 +2152,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
// whenBackPressed(AppParams.ActivityResult.tcpDown);
|
// whenBackPressed(AppParams.ActivityResult.tcpDown);
|
||||||
|
|
||||||
// send a broadcast
|
// send a broadcast
|
||||||
notifyBroadcast(OperationCodes.TCP_CONNECTION_DOWN + "");
|
// notifyBroadcast(OperationCodes.TCP_CONNECTION_DOWN + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user