Merge branch 'develop' into SD_256_incorect_timestamp_in_buble_live_tab
This commit is contained in:
@ -25,6 +25,7 @@ public abstract class AbstractLiveActivity extends AppCompatActivity {
|
||||
public abstract void vehicleStatusReceived(long imei, int opCode, int status); // --> UpdateOptions
|
||||
public abstract void emergencyAlarmReceived(int position, double lat, double lng); // --> UpdateEmergencyAlarm
|
||||
public abstract GoogleMap getMap(); // --> UpdateEmergencyAlarm
|
||||
public abstract void setLanguage();
|
||||
|
||||
/** Misc */
|
||||
public AbstractSDParentActivity getParentTab() {
|
||||
|
@ -102,10 +102,8 @@ public class TCPService extends Service {
|
||||
|
||||
|
||||
/** Stop TCP Connection */
|
||||
public void stopTCPConnection()
|
||||
{
|
||||
if(tcp != null)
|
||||
{
|
||||
public void stopTCPConnection() {
|
||||
if(tcp != null) {
|
||||
tcp.Stop();
|
||||
tcp = null;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.SM;
|
||||
@ -24,6 +25,7 @@ import java.util.TimerTask;
|
||||
|
||||
|
||||
public class TCPhandler implements Runnable {
|
||||
private final String TAG = "TCPhandler";
|
||||
private boolean alive = true;
|
||||
|
||||
public String serverHostname;
|
||||
@ -56,18 +58,22 @@ public class TCPhandler implements Runnable {
|
||||
|
||||
// create timer to check socket status
|
||||
Timer timer = new Timer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
previousConnectionWasUP = isConnectionUP;
|
||||
// try to send something
|
||||
TCPmsgParser._fireonTCPConnectionStatusEvent(isConnectionUP, previousConnectionWasUP);
|
||||
} catch (Exception e) {
|
||||
SM.Exception("TIMERException", e.toString());
|
||||
try {
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
previousConnectionWasUP = isConnectionUP;
|
||||
// try to send something
|
||||
TCPmsgParser._fireonTCPConnectionStatusEvent(isConnectionUP, previousConnectionWasUP);
|
||||
} catch (Exception e) {
|
||||
SM.Exception("TIMERException", e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0, 3000);
|
||||
}, 0, 3000);
|
||||
} catch(Exception e) {
|
||||
Log.v("Exception", e.getMessage());
|
||||
}
|
||||
|
||||
// get WiFi state
|
||||
isWiFiOn = isNetworkConnected();
|
||||
@ -104,6 +110,8 @@ public class TCPhandler implements Runnable {
|
||||
SM.Debug("IllegalArgumentException", "TCPhandler break:"+ e);
|
||||
} catch (IOException e) {
|
||||
SM.Debug("IOException", "TCPhandler break:"+ e);
|
||||
} catch (Exception e) {
|
||||
Log.v("Exception", e.getMessage());
|
||||
}
|
||||
|
||||
while (alive) {
|
||||
@ -111,6 +119,8 @@ public class TCPhandler implements Runnable {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
SM.Debug("TCPhandler Crash1 on sleep:"+ e);
|
||||
} catch (Exception e) {
|
||||
Log.v("Exception", e.getMessage());
|
||||
}
|
||||
|
||||
while (Boolean.TRUE.equals(isConnectionUP)) {
|
||||
@ -242,6 +252,8 @@ public class TCPhandler implements Runnable {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
SM.Debug("TCPhandler Crash2 on sleep:"+ e);
|
||||
} catch (Exception e) {
|
||||
Log.v("Exception", e.getMessage());
|
||||
}
|
||||
//try to restart connection
|
||||
if (alive && isWiFiOn)
|
||||
@ -350,6 +362,7 @@ public class TCPhandler implements Runnable {
|
||||
if (soc != null)
|
||||
soc.close();
|
||||
} catch (IOException e1) {
|
||||
Log.v("IOException", e1.getMessage());
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
@ -371,14 +384,15 @@ public class TCPhandler implements Runnable {
|
||||
|
||||
private void restartTCP() {
|
||||
try {
|
||||
Log.v(TAG, "restartTCP");
|
||||
isConnectionUP = false;
|
||||
previousConnectionWasUP = false;
|
||||
|
||||
SM.Debug("Restarting TCP...ip:" + serverHostname + ":" + port);
|
||||
soc = new Socket();
|
||||
soc.connect(new InetSocketAddress(serverHostname, port), 5000);
|
||||
|
||||
soc.connect(new InetSocketAddress(serverHostname, port), 50000);
|
||||
input = new DataInputStream(soc.getInputStream());
|
||||
|
||||
//output stream
|
||||
output = new DataOutputStream(soc.getOutputStream());
|
||||
|
||||
@ -386,17 +400,11 @@ public class TCPhandler implements Runnable {
|
||||
isConnectionUP = true;
|
||||
}
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
SM.Exception("restartTCP break:" + e.toString());
|
||||
} catch (NullPointerException | IOException e) {
|
||||
SM.Exception("restartTCP break:" + e);
|
||||
isConnectionUP = false;
|
||||
} catch (IllegalArgumentException e) {
|
||||
SM.Debug("IllegalArgumentException", "restartTCP break:" + e.toString());
|
||||
} catch (IOException e) {
|
||||
SM.Exception("restartTCP break:" + e.toString());
|
||||
isConnectionUP = false;
|
||||
} catch (NullPointerException e) {
|
||||
SM.Exception("restartTCP break:" + e.toString());
|
||||
isConnectionUP = false;
|
||||
SM.Debug("IllegalArgumentException", "restartTCP break:" + e);
|
||||
}
|
||||
triggerTCPConnectionStateEvent();
|
||||
}
|
||||
@ -410,6 +418,7 @@ public class TCPhandler implements Runnable {
|
||||
soc.close();
|
||||
soc = null;
|
||||
} catch (IOException e) {
|
||||
Log.v("IOException", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user