Compare commits
17 Commits
e59b522ccb
...
SD-217
Author | SHA1 | Date | |
---|---|---|---|
0b890b74e0 | |||
73d2cedfba | |||
5c075ee168 | |||
1299ff2d2e | |||
8ab29576c5 | |||
d9a031a46d | |||
ba0dc850f7 | |||
b2fdb1c8d7 | |||
19f5fe01a3 | |||
7b45edb624 | |||
3a0fe96708 | |||
5cd598bec9 | |||
79234c9830 | |||
ca4255943a | |||
cbeb912820 | |||
f15688b9a1 | |||
3935b3ad0b |
@ -5,7 +5,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
|
||||||
import com.safemobile.lib.AppParams;
|
import com.safemobile.lib.AppParams;
|
||||||
@ -38,21 +37,19 @@ public class TCPhandler implements Runnable {
|
|||||||
private String leftOver = "";
|
private String leftOver = "";
|
||||||
|
|
||||||
public static LinkedList<TCPmsg> msgList;
|
public static LinkedList<TCPmsg> msgList;
|
||||||
private volatile int n = 0;
|
|
||||||
|
|
||||||
public Boolean isConnectionUP = false;
|
public Boolean isConnectionUP = false;
|
||||||
public Boolean previousConnectionWasUP = false;
|
public Boolean previousConnectionWasUP = false;
|
||||||
|
|
||||||
private Context context;
|
private final Context context;
|
||||||
private boolean isWiFiOn = true;
|
private boolean isWiFiOn;
|
||||||
|
|
||||||
public TCPhandler(Context context, String hostName, int p) {
|
public TCPhandler(Context context, String hostName, int p) {
|
||||||
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
serverHostname = hostName;
|
serverHostname = hostName;
|
||||||
port = p;
|
port = p;
|
||||||
|
|
||||||
msgList = new LinkedList<TCPmsg>();
|
msgList = new LinkedList<>();
|
||||||
SM.Debug("---TCPhandler constructor [" + hostName + "," + p + "] ---");
|
SM.Debug("---TCPhandler constructor [" + hostName + "," + p + "] ---");
|
||||||
listenThread = new Thread(this, "TCPlisten");
|
listenThread = new Thread(this, "TCPlisten");
|
||||||
listenThread.start(); // (2) Start the thread.
|
listenThread.start(); // (2) Start the thread.
|
||||||
@ -64,7 +61,6 @@ public class TCPhandler implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
previousConnectionWasUP = isConnectionUP;
|
previousConnectionWasUP = isConnectionUP;
|
||||||
|
|
||||||
// try to send something
|
// try to send something
|
||||||
TCPmsgParser._fireonTCPConnectionStatusEvent(isConnectionUP, previousConnectionWasUP);
|
TCPmsgParser._fireonTCPConnectionStatusEvent(isConnectionUP, previousConnectionWasUP);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -72,18 +68,20 @@ public class TCPhandler implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0, 3000);
|
}, 0, 3000);
|
||||||
|
|
||||||
// get WiFi state
|
// get WiFi state
|
||||||
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
isWiFiOn = isNetworkConnected();
|
||||||
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
|
||||||
if (mWifi.isConnectedOrConnecting())
|
|
||||||
isWiFiOn = true;
|
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||||
context.registerReceiver(mReceived, intentFilter);
|
context.registerReceiver(mReceived, intentFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isNetworkConnected() {
|
||||||
|
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@ -100,20 +98,19 @@ public class TCPhandler implements Runnable {
|
|||||||
isConnectionUP = true;
|
isConnectionUP = true;
|
||||||
triggerTCPConnectionStateEvent();
|
triggerTCPConnectionStateEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
SM.Debug("UnknownHostException", "TCPhandler break:" + e.toString());
|
SM.Debug("UnknownHostException", "TCPhandler break:"+ e);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
SM.Debug("IllegalArgumentException", "TCPhandler break:" + e.toString());
|
SM.Debug("IllegalArgumentException", "TCPhandler break:"+ e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
SM.Debug("IOException", "TCPhandler break:" + e.toString());
|
SM.Debug("IOException", "TCPhandler break:"+ e);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (alive) {
|
while (alive) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
SM.Debug("TCPhandler Crash1 on sleep:" + e.toString());
|
SM.Debug("TCPhandler Crash1 on sleep:"+ e);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (Boolean.TRUE.equals(isConnectionUP)) {
|
while (Boolean.TRUE.equals(isConnectionUP)) {
|
||||||
@ -166,7 +163,7 @@ public class TCPhandler implements Runnable {
|
|||||||
//end process leftover
|
//end process leftover
|
||||||
|
|
||||||
String data = "";
|
String data = "";
|
||||||
n = 0;
|
int n = 0;
|
||||||
|
|
||||||
byte[] buf = new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
// read data into buffer
|
// read data into buffer
|
||||||
@ -181,7 +178,6 @@ public class TCPhandler implements Runnable {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
byte[] temp = new byte[n];
|
byte[] temp = new byte[n];
|
||||||
if (n >= 0) System.arraycopy(buf, 0, temp, 0, n);
|
if (n >= 0) System.arraycopy(buf, 0, temp, 0, n);
|
||||||
|
|
||||||
@ -190,77 +186,72 @@ public class TCPhandler implements Runnable {
|
|||||||
|
|
||||||
data = new String(temp);
|
data = new String(temp);
|
||||||
|
|
||||||
//if we have any leftovers from previous message add them
|
//if we have any leftovers from previous message add them
|
||||||
if (leftOver.length() > 1) // avoid case with only one #
|
if(leftOver.length() > 1) { // avoid case with only one #
|
||||||
{
|
data = leftOver+data;
|
||||||
data = leftOver + data;
|
leftOver = "";
|
||||||
leftOver = "";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//search for overflow message
|
//search for overflow message
|
||||||
String[] tempArr = data.split("#");
|
String[] tempArr = data.split("#");
|
||||||
if ((tempArr.length == 0) || (tempArr.length == 1)) {
|
if ((tempArr.length == 0) || (tempArr.length == 1)) {
|
||||||
SM.Debug("TCP Client", "incorect messagebuss message=" + data);
|
SM.Debug("TCP Client", "incorect messagebuss message=" + data);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//get msg len
|
//get msg len
|
||||||
int messLen;
|
int messLen;
|
||||||
try {
|
try {
|
||||||
messLen = Integer.parseInt(tempArr[1]);
|
messLen = Integer.parseInt(tempArr[1]);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SM.Debug("TCP Client", "incorect msg len =" + tempArr[1]);
|
SM.Debug("TCP Client", "incorect msg len =" + tempArr[1]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//messLen not int
|
//messLen not int
|
||||||
if (messLen == -1) {
|
if (messLen == -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char[] temMSG = data.toCharArray();
|
char[] temMSG = data.toCharArray();
|
||||||
if (data.length() != messLen) {
|
if (data.length() != messLen) {
|
||||||
if (messLen > data.length()) {
|
//if expected string message is smaller then actual string then exit processing;
|
||||||
leftOver = data; // Add by bigu
|
if (messLen > data.length()) {
|
||||||
continue;
|
leftOver = data; // Add by bigu
|
||||||
}
|
continue;
|
||||||
//perform cut
|
}
|
||||||
temMSG = data.substring(0, messLen).toCharArray();
|
//perform cut
|
||||||
leftOver = data.substring(messLen, data.length());
|
temMSG = data.substring(0,messLen).toCharArray();
|
||||||
}
|
leftOver = data.substring(messLen);
|
||||||
|
}
|
||||||
//decode TCP msg
|
//decode TCP msg
|
||||||
TCPmsg msg = new TCPmsg(temMSG);
|
TCPmsg msg = new TCPmsg(temMSG);
|
||||||
|
|
||||||
SM.Debug("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RX <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", msg.allData);
|
SM.Debug("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RX <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", msg.allData);
|
||||||
|
|
||||||
if (msg.allData.contains("#92#"))
|
if (msg.allData.contains("#92#"))
|
||||||
prioritizePongReceived();
|
prioritizePongReceived();
|
||||||
|
|
||||||
msgList.add(msg);
|
msgList.add(msg);
|
||||||
|
} catch(Exception ex) {
|
||||||
} catch (Exception ex) {
|
SM.Debug("TCPHandler", "TCPhandler/run/break:"+ ex);
|
||||||
SM.Debug("TCPHandler", "TCPhandler/run/break:" + ex.toString());
|
|
||||||
isConnectionUP = false;
|
isConnectionUP = false;
|
||||||
triggerTCPConnectionStateEvent();
|
triggerTCPConnectionStateEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
SM.Debug("TCPhandler Crash2 on sleep:" + e.toString());
|
SM.Debug("TCPhandler Crash2 on sleep:"+ e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//try to restart connection
|
//try to restart connection
|
||||||
if (alive && isWiFiOn)
|
if (alive && isWiFiOn)
|
||||||
restartTCP();
|
restartTCP();
|
||||||
|
|
||||||
}
|
}
|
||||||
SM.Debug("==================================");
|
SM.Debug("==================================");
|
||||||
SM.Debug("TCP listenThread stoped!! alive = false");
|
SM.Debug("TCP listenThread stoped!! alive = false");
|
||||||
SM.Debug("==================================");
|
SM.Debug("==================================");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a bypass in order to trigger the ping received event
|
* Create a bypass in order to trigger the ping received event
|
||||||
*/
|
*/
|
||||||
@ -268,33 +259,26 @@ public class TCPhandler implements Runnable {
|
|||||||
TCPmsgParser._firePONGReceivedEvent();
|
TCPmsgParser._firePONGReceivedEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Broadcast Received for WiFi Connect/Disconnect */
|
/* Broadcast Received for WiFi Connect/Disconnect */
|
||||||
public BroadcastReceiver mReceived = new BroadcastReceiver() {
|
public BroadcastReceiver mReceived = new BroadcastReceiver() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
SM.Debug("WIFI STATE", action);
|
SM.Debug("WIFI STATE", action);
|
||||||
|
|
||||||
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){
|
||||||
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
// close socket if the wifi is disconnecting or disconnected
|
||||||
// close socket if the wifi is disconnecting or disconnected
|
isWiFiOn = isNetworkConnected();
|
||||||
if (!info.isConnectedOrConnecting()) {
|
if (!isWiFiOn)
|
||||||
closeSocket();
|
closeSocket();
|
||||||
isWiFiOn = false;
|
}
|
||||||
} else
|
|
||||||
isWiFiOn = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Send a message through the TCP Socket
|
||||||
/**
|
* @param seqID The messages's sequence ID (a number of order)
|
||||||
* Send a message through the TCP Socket
|
* @param msg The messages which will be sent
|
||||||
*
|
|
||||||
* @param seqID The messages's sequence id (a number of order)
|
|
||||||
* @param msg The messages which will be sent
|
|
||||||
* @return True if the message was sent
|
* @return True if the message was sent
|
||||||
*/
|
*/
|
||||||
public boolean Write(String seqID, String msg) {
|
public boolean Write(String seqID, String msg) {
|
||||||
@ -338,52 +322,29 @@ public class TCPhandler implements Runnable {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setConnectionIsDown() {
|
|
||||||
if (input != null) {
|
|
||||||
try {
|
|
||||||
input.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
} finally {
|
|
||||||
input = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isConnectionUP = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Encrypt a string using an encryption algorithm,
|
/* Encrypt a string using an encryption algorithm,
|
||||||
* in this case TEA */
|
* in this case TEA */
|
||||||
public static byte[] encryptTEA(String toEncryptData) {
|
public static byte[] encryptTEA(String toEncryptData) {
|
||||||
byte[] encryptedByteArray = new byte[]{};
|
|
||||||
|
|
||||||
// no encryption
|
// no encryption
|
||||||
encryptedByteArray = toEncryptData.getBytes();
|
return toEncryptData.getBytes();
|
||||||
|
|
||||||
return encryptedByteArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decrypt a string using an encryption algorithm,
|
/* Decrypt a string using an encryption algorithm,
|
||||||
* in this case TEA */
|
* in this case TEA */
|
||||||
public static byte[] decryptTEA(byte[] toDecryptData) {
|
public static byte[] decryptTEA(byte[] toDecryptData) {
|
||||||
byte[] decryptedByteArray = new byte[]{};
|
byte[] decryptedByteArray;
|
||||||
|
|
||||||
// no decryption
|
// no decryption
|
||||||
decryptedByteArray = toDecryptData;
|
decryptedByteArray = toDecryptData;
|
||||||
|
|
||||||
return decryptedByteArray;
|
return decryptedByteArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTCPparameters(String ip, String _port) {
|
public void updateTCPparameters(String ip, String _port) {
|
||||||
|
|
||||||
// stop socket
|
// stop socket
|
||||||
try {
|
try {
|
||||||
if (soc != null)
|
if (soc != null)
|
||||||
@ -395,9 +356,8 @@ public class TCPhandler implements Runnable {
|
|||||||
serverHostname = ip;
|
serverHostname = ip;
|
||||||
try {
|
try {
|
||||||
port = Integer.parseInt(_port);
|
port = Integer.parseInt(_port);
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) { }
|
||||||
|
finally {
|
||||||
} finally {
|
|
||||||
port = 13589;
|
port = 13589;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -438,23 +398,11 @@ public class TCPhandler implements Runnable {
|
|||||||
SM.Exception("restartTCP break:" + e.toString());
|
SM.Exception("restartTCP break:" + e.toString());
|
||||||
isConnectionUP = false;
|
isConnectionUP = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
triggerTCPConnectionStateEvent();
|
triggerTCPConnectionStateEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlive() {
|
/** close Socket when unReachable */
|
||||||
return alive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAlive(boolean alive) {
|
|
||||||
this.alive = alive;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* close Socket when unReachable
|
|
||||||
*/
|
|
||||||
public void closeSocket() {
|
public void closeSocket() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
input = null;
|
input = null;
|
||||||
output = null;
|
output = null;
|
||||||
@ -465,17 +413,15 @@ public class TCPhandler implements Runnable {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop() {
|
public void Stop() {
|
||||||
SM.Debug("Stopping TCP", "TCP Connection is stopping on " + AppParams.IP + ":" + port);
|
SM.Debug("Stopping TCP", "TCP Connection is stopping on " + AppParams.IP + ":" + port);
|
||||||
alive = false;
|
alive = false;
|
||||||
|
|
||||||
|
if (mReceived!= null)
|
||||||
if (mReceived != null)
|
|
||||||
try {
|
try {
|
||||||
context.unregisterReceiver(mReceived);
|
context.unregisterReceiver(mReceived);
|
||||||
} catch (Exception ex) {/* receiver not registered //*/}
|
} catch(Exception ex) {/* receiver not registered //*/}
|
||||||
;
|
|
||||||
|
|
||||||
// stop thread
|
// stop thread
|
||||||
if (listenThread != null) {
|
if (listenThread != null) {
|
||||||
@ -484,7 +430,6 @@ public class TCPhandler implements Runnable {
|
|||||||
moribund.interrupt();
|
moribund.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
try {
|
try {
|
||||||
input.close();
|
input.close();
|
||||||
@ -493,7 +438,7 @@ public class TCPhandler implements Runnable {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output != null) {
|
if (output != null) {
|
||||||
try {
|
try {
|
||||||
output.close();
|
output.close();
|
||||||
@ -502,15 +447,14 @@ public class TCPhandler implements Runnable {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (soc != null) {
|
if (soc !=null) {
|
||||||
try {
|
try {
|
||||||
soc.close();
|
soc.close();
|
||||||
soc = null;
|
soc = null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
SM.Exception("TCPClient[STOP]", "Stop break:" + e.toString());
|
SM.Exception("TCPClient[STOP]", "Stop break:"+ e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
package com.safemobile.services;
|
package com.safemobile.services;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
@ -12,16 +11,14 @@ import com.safemobile.lib.SM;
|
|||||||
import com.safemobile.lib.TCPmsg;
|
import com.safemobile.lib.TCPmsg;
|
||||||
|
|
||||||
|
|
||||||
public class TCPmsgParser implements Runnable{
|
public class TCPmsgParser implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
public boolean run = true;
|
public boolean run = true;
|
||||||
private TCPmsg _msg;
|
private TCPmsg _msg;
|
||||||
private static List<ITCPListener> _listeners = new ArrayList<ITCPListener>();
|
private static final List<ITCPListener> _listeners = new ArrayList<>();
|
||||||
private Thread TCPmsgParserThread;
|
private Thread TCPmsgParserThread;
|
||||||
|
|
||||||
public TCPmsgParser()
|
public TCPmsgParser() {
|
||||||
{
|
|
||||||
TCPmsgParserThread = new Thread(this, "TCPmsgParserThread");
|
TCPmsgParserThread = new Thread(this, "TCPmsgParserThread");
|
||||||
TCPmsgParserThread.start(); // (2) Start the thread.
|
TCPmsgParserThread.start(); // (2) Start the thread.
|
||||||
}
|
}
|
||||||
@ -37,404 +34,349 @@ public class TCPmsgParser implements Runnable{
|
|||||||
public synchronized void clearITCPListeners() {
|
public synchronized void clearITCPListeners() {
|
||||||
_listeners.clear();
|
_listeners.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getListenersSize()
|
|
||||||
{
|
|
||||||
return _listeners.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void _fireLoginEvent() {
|
private synchronized void _fireLoginEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onLoginReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onLoginReceived( event );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private synchronized void _fireGPSEvent() {
|
private synchronized void _fireGPSEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onGPSReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onGPSReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private synchronized void _fireSMSEvent() {
|
private synchronized void _fireSMSEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onSMSReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onSMSReceived( event );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireLastSMSEvent() {
|
private synchronized void _fireLastSMSEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onLastSMSsReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onLastSMSsReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireVehEvent() {
|
private synchronized void _fireVehEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onVehiclesReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onVehiclesReceived( event );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireNewSMS() {
|
private synchronized void _fireNewSMS() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onNewSMSReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onNewSMSReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireSMSconfirm() {
|
private synchronized void _fireSMSconfirm() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onSMSAckReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onSMSAckReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireLastPos() {
|
private synchronized void _fireLastPos() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onLastPositionsReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onLastPositionsReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireRadioEvent() {
|
private synchronized void _fireRadioEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onRadioMsgReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onRadioMsgReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireHistPos() {
|
private synchronized void _fireHistPos() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onHistoryPositionsReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onHistoryPositionsReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireHistCount() {
|
private synchronized void _fireHistCount() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onHistoryPositionsCountReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onHistoryPositionsCountReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireAlarmList() {
|
private synchronized void _fireAlarmList() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onAlarmsReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onAlarmsReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireAlarmACK() {
|
private synchronized void _fireAlarmACK() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onAlarmAckReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).onAlarmAckReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireAlarmLive() {
|
private synchronized void _fireAlarmLive() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.alarmLiveReceived(event);
|
||||||
( (ITCPListener) listeners.next() ).alarmLiveReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireRecordList() {
|
private synchronized void _fireRecordList() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onRecordingsListReceived(event);
|
||||||
( (ITCPListener) listeners.next()).onRecordingsListReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireRecordPlay() {
|
private synchronized void _fireRecordPlay() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onRecordingPlayReceived(event);
|
||||||
( (ITCPListener) listeners.next()).onRecordingPlayReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _firePOLLEvent() {
|
private synchronized void _firePOLLEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onPollReceived(event);
|
||||||
( (ITCPListener) listeners.next()).onPollReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireConnectionReplyEvent() {
|
private synchronized void _fireConnectionReplyEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onConnectionReplyReceived(event);
|
||||||
( (ITCPListener) listeners.next()).onConnectionReplyReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireContactsReceivedEvent() {
|
private synchronized void _fireContactsReceivedEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
|
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onContactsListReceived(event);
|
||||||
( (ITCPListener) listeners.next()).onContactsListReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireRecordingsReceivedEvent() {
|
private synchronized void _fireRecordingsReceivedEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
|
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onRecordingsListReceived(event);
|
||||||
( (ITCPListener) listeners.next()).onRecordingsListReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void _fireTextMessagesReceivedEvent() {
|
private synchronized void _fireTextMessagesReceivedEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
|
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onTextMessagesListReceived(event);
|
||||||
( (ITCPListener) listeners.next()).onTextMessagesListReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private synchronized void _fireRecordingPlayReceivedEvent() {
|
private synchronized void _fireRecordingPlayReceivedEvent() {
|
||||||
TCPEvent event = new TCPEvent( this, _msg );
|
TCPEvent event = new TCPEvent( this, _msg );
|
||||||
|
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onRecordingPlayReceived(event);
|
||||||
( (ITCPListener) listeners.next()).onRecordingPlayReceived(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static synchronized void _fireTCPConnectionDownEvent(boolean previuosWasConnectionUp) {
|
public static synchronized void _fireTCPConnectionDownEvent(boolean previuosWasConnectionUp) {
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onTCPConnectionDown(previuosWasConnectionUp);
|
||||||
( (ITCPListener) listeners.next()).onTCPConnectionDown(previuosWasConnectionUp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void _fireTCPConnectionUpEvent(boolean previuosWasConnectionUp) {
|
public static synchronized void _fireTCPConnectionUpEvent(boolean previuosWasConnectionUp) {
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onTCPConnectionUp(previuosWasConnectionUp);
|
||||||
( (ITCPListener) listeners.next()).onTCPConnectionUp(previuosWasConnectionUp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static synchronized void _fireonTCPConnectionStatusEvent(boolean isConnectionUp, boolean previuosWasConnectionUp) {
|
public static synchronized void _fireonTCPConnectionStatusEvent(boolean isConnectionUp, boolean previuosWasConnectionUp) {
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onTCPConnectionStatusReceived(isConnectionUp, previuosWasConnectionUp);
|
||||||
( (ITCPListener) listeners.next()).onTCPConnectionStatusReceived(isConnectionUp, previuosWasConnectionUp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void _firePONGReceivedEvent() {
|
public static synchronized void _firePONGReceivedEvent() {
|
||||||
Iterator<ITCPListener> listeners = _listeners.iterator();
|
for (ITCPListener listener : _listeners) {
|
||||||
while( listeners.hasNext() ) {
|
listener.onPONGReceived();
|
||||||
( (ITCPListener) listeners.next()).onPONGReceived();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
while(run) {
|
||||||
while(run)
|
|
||||||
{
|
|
||||||
//SM.Debug("TCPmsgParser waiting for data...");
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
if(TCPhandler.msgList==null)
|
if (TCPhandler.msgList == null)
|
||||||
continue;
|
continue;
|
||||||
if(!TCPhandler.msgList.isEmpty())
|
if(!TCPhandler.msgList.isEmpty()) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
_msg = TCPhandler.msgList.poll();
|
_msg = TCPhandler.msgList.poll();
|
||||||
if(_msg == null)
|
if(_msg == null)
|
||||||
continue;
|
continue;
|
||||||
if(_msg.OK == false)
|
if(!_msg.OK)
|
||||||
continue;
|
continue;
|
||||||
//parse the rest of the message;
|
//parse the rest of the message;
|
||||||
|
|
||||||
switch(_msg.opCode)
|
switch(_msg.opCode) {
|
||||||
{
|
case 40:{
|
||||||
case 40:{
|
_fireLoginEvent();
|
||||||
_fireLoginEvent();
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case 41:{
|
case 41:{
|
||||||
_fireVehEvent();
|
_fireVehEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 42:{
|
case 42:{
|
||||||
_fireSMSEvent();
|
_fireSMSEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 43:{
|
case 43:{
|
||||||
_fireLastSMSEvent();
|
_fireLastSMSEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OperationCodes.TM_ACK:{
|
case OperationCodes.TM_ACK:
|
||||||
_fireSMSconfirm();
|
case OperationCodes.TM_ACK_SD: {
|
||||||
break;
|
_fireSMSconfirm();
|
||||||
}
|
break;
|
||||||
case OperationCodes.TM_ACK_SD:{
|
}
|
||||||
_fireSMSconfirm();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case OperationCodes.RECEIVED_TM:{
|
case OperationCodes.RECEIVED_TM:{
|
||||||
_fireNewSMS();
|
_fireNewSMS();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 45:{
|
case 45:{
|
||||||
_fireLastPos();
|
_fireLastPos();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 131:{
|
case 131:{
|
||||||
_fireGPSEvent();
|
_fireGPSEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 231:{
|
case 231:{
|
||||||
_firePOLLEvent();
|
_firePOLLEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 50:{
|
case 50:{
|
||||||
_fireRadioEvent();
|
_fireRadioEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 46:{
|
case 46:{
|
||||||
_fireHistPos();
|
_fireHistPos();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 86:{
|
case 86:{
|
||||||
_fireHistCount();
|
_fireHistCount();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 47:{
|
case 47:{
|
||||||
_fireAlarmList();
|
_fireAlarmList();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 48:{
|
case 48:{
|
||||||
_fireAlarmACK();
|
_fireAlarmACK();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 49:{
|
case 49:{
|
||||||
_fireRecordList();
|
_fireRecordList();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 38:{
|
case 38:{
|
||||||
_fireRecordPlay();
|
_fireRecordPlay();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 135:
|
case 135:
|
||||||
case 136:
|
case 136:
|
||||||
case 137:
|
case 137:
|
||||||
case 138:
|
case 138:
|
||||||
case 140:{
|
case 140:{
|
||||||
_fireAlarmLive();
|
_fireAlarmLive();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OperationCodes.PONG: {
|
case OperationCodes.PONG: {
|
||||||
//_firePONGReceivedEvent();
|
//_firePONGReceivedEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OperationCodes.CONNECTION_REP: {
|
case OperationCodes.CONNECTION_REP: {
|
||||||
_fireConnectionReplyEvent();
|
_fireConnectionReplyEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OperationCodes.CONTACTS_REP: {
|
case OperationCodes.CONTACTS_REP: {
|
||||||
sleep(15);
|
sleep(15);
|
||||||
_fireContactsReceivedEvent();
|
_fireContactsReceivedEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OperationCodes.TM_LIST_REP: {
|
case OperationCodes.TM_LIST_REP: {
|
||||||
_fireTextMessagesReceivedEvent();
|
_fireTextMessagesReceivedEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OperationCodes.RECORDINGS_LIST_REP: {
|
case OperationCodes.RECORDINGS_LIST_REP: {
|
||||||
_fireRecordingsReceivedEvent();
|
_fireRecordingsReceivedEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OperationCodes.RECORDING_REP: {
|
case OperationCodes.RECORDING_REP: {
|
||||||
_fireRecordingPlayReceivedEvent();
|
_fireRecordingPlayReceivedEvent();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} catch(Exception ex) {
|
||||||
catch(Exception ex)
|
try {
|
||||||
{
|
if(TCPhandler.msgList.size() > 0)
|
||||||
try {
|
_msg = TCPhandler.msgList.remove(0);
|
||||||
if(TCPhandler.msgList.size() > 0)
|
} catch(NoSuchElementException exe) {
|
||||||
_msg = TCPhandler.msgList.remove(0);
|
SM.Exception("TCP msg Parser", "NoSuchElementException");
|
||||||
}
|
}
|
||||||
catch(NoSuchElementException exe)
|
}
|
||||||
{
|
}
|
||||||
SM.Exception("TCP msg Parser", "NoSuchElementException");
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
SM.Debug("Error on fire Event:"+e.toString());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}*/
|
|
||||||
SM.Debug("TCPmsgParser listen thread stoped.");
|
SM.Debug("TCPmsgParser listen thread stoped.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sleep(int miliseconds) {
|
private void sleep(int miliseconds) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(miliseconds);
|
Thread.sleep(miliseconds);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException ignored) { }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearMsgList()
|
public void clearMsgList()
|
||||||
@ -442,17 +384,14 @@ public class TCPmsgParser implements Runnable{
|
|||||||
TCPhandler.msgList.clear();
|
TCPhandler.msgList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop() {
|
||||||
{
|
|
||||||
run = false;
|
run = false;
|
||||||
// stop thread
|
// stop thread
|
||||||
if(TCPmsgParserThread != null)
|
if(TCPmsgParserThread != null) {
|
||||||
{
|
|
||||||
Thread moribund = TCPmsgParserThread;
|
Thread moribund = TCPmsgParserThread;
|
||||||
TCPmsgParserThread = null;
|
TCPmsgParserThread = null;
|
||||||
moribund.interrupt();
|
moribund.interrupt();
|
||||||
}
|
}
|
||||||
SM.Debug("Stoping TCPmsgParser");
|
SM.Debug("Stoping TCPmsgParser");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
@ -78,6 +78,4 @@ dependencies {
|
|||||||
|
|
||||||
// add Gson
|
// add Gson
|
||||||
implementation 'com.google.code.gson:gson:2.8.6'
|
implementation 'com.google.code.gson:gson:2.8.6'
|
||||||
|
|
||||||
//retrofit
|
|
||||||
}
|
}
|
||||||
|
BIN
safeDispatch/release/SafeDispatchMobile_v.8.0.49-release.aab
Normal file
BIN
safeDispatch/release/SafeDispatchMobile_v.8.0.49-release.aab
Normal file
Binary file not shown.
@ -3,6 +3,7 @@ package com.safemobile.safedispatch;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.app.DatePickerDialog;
|
import android.app.DatePickerDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@ -124,6 +125,18 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
|
|||||||
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14));
|
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
builder.setMessage(getString(R.string.exit))
|
||||||
|
.setCancelable(false)
|
||||||
|
.setNeutralButton(getString(R.string.logout), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.logout))
|
||||||
|
.setPositiveButton(getString(R.string.ext), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.exit))
|
||||||
|
.setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel());
|
||||||
|
AlertDialog alert = builder.create();
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
|
||||||
private void setDate() {
|
private void setDate() {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
endDate = calendar.getTime();
|
endDate = calendar.getTime();
|
||||||
|
@ -16,17 +16,22 @@ public class NotificationActivity extends Activity{
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// get notification type
|
// get notification type
|
||||||
int key = getIntent().getExtras().getInt("key");
|
int key = getIntent().getExtras().getInt("key");
|
||||||
|
|
||||||
// broadcast intent
|
// broadcast intent
|
||||||
Intent i = new Intent();
|
Intent i = new Intent();
|
||||||
switch(key)
|
switch(key) {
|
||||||
{
|
case AppParams.messageNotif:
|
||||||
case AppParams.messageNotif: i.setAction(NOTIFICATION_MESSAGE_INTENT); break;
|
i.setAction(NOTIFICATION_MESSAGE_INTENT);
|
||||||
case AppParams.alertNotif: i.setAction(NOTIFICATION_ALERT_INTENT); break;
|
break;
|
||||||
case AppParams.pollNotif: i.setAction(NOTIFICATION_POLL_INTENT); break;
|
case AppParams.alertNotif:
|
||||||
}
|
i.setAction(NOTIFICATION_ALERT_INTENT);
|
||||||
|
break;
|
||||||
|
case AppParams.pollNotif:
|
||||||
|
i.setAction(NOTIFICATION_POLL_INTENT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
getBaseContext().sendBroadcast(i);
|
getBaseContext().sendBroadcast(i);
|
||||||
|
|
||||||
@ -35,6 +40,4 @@ public class NotificationActivity extends Activity{
|
|||||||
/* Finish activity and return to parent activity */
|
/* Finish activity and return to parent activity */
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
@ -42,6 +42,7 @@ public class RecordingsActivity extends Activity {
|
|||||||
private GridView gridView;
|
private GridView gridView;
|
||||||
private RecordingsGridViewAdapter adapter;
|
private RecordingsGridViewAdapter adapter;
|
||||||
private View convertViewRecording;
|
private View convertViewRecording;
|
||||||
|
private boolean isRecordingPlaying = false;
|
||||||
|
|
||||||
private int playingPosition = -1;
|
private int playingPosition = -1;
|
||||||
|
|
||||||
@ -89,6 +90,7 @@ public class RecordingsActivity extends Activity {
|
|||||||
gridView.setAdapter(adapter);
|
gridView.setAdapter(adapter);
|
||||||
|
|
||||||
gridView.setOnItemClickListener(onItemClickListener);
|
gridView.setOnItemClickListener(onItemClickListener);
|
||||||
|
gridView.setOnTouchListener((v, event) -> isRecordingPlaying);
|
||||||
|
|
||||||
if (recHandle == null && !AppParams.DEMO)
|
if (recHandle == null && !AppParams.DEMO)
|
||||||
recHandle = new RecordingHandle(AppParams.IP);
|
recHandle = new RecordingHandle(AppParams.IP);
|
||||||
@ -171,12 +173,17 @@ public class RecordingsActivity extends Activity {
|
|||||||
SM.Debug("onResume");
|
SM.Debug("onResume");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private final OnItemClickListener onItemClickListener = new OnItemClickListener() {
|
private final OnItemClickListener onItemClickListener = new OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
|
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
|
||||||
|
|
||||||
// disable grid scrolling and item click
|
// disable grid scrolling and item click
|
||||||
gridView.setEnabled(false);
|
if (isRecordingPlaying)
|
||||||
|
return;
|
||||||
|
|
||||||
|
isRecordingPlaying = true;
|
||||||
setConvertViewRecording(view);
|
setConvertViewRecording(view);
|
||||||
|
|
||||||
// change background to playing
|
// change background to playing
|
||||||
@ -262,7 +269,7 @@ public class RecordingsActivity extends Activity {
|
|||||||
adapter.changePlaying(getPlayingPosition(), false);
|
adapter.changePlaying(getPlayingPosition(), false);
|
||||||
|
|
||||||
// enable grid
|
// enable grid
|
||||||
gridView.setEnabled(true);
|
isRecordingPlaying = false;
|
||||||
|
|
||||||
// set playing Recording position to -1
|
// set playing Recording position to -1
|
||||||
setPlayingPosition(-1);
|
setPlayingPosition(-1);
|
||||||
|
@ -10,13 +10,19 @@ import android.content.ServiceConnection;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.Network;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
|
import android.net.NetworkRequest;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@ -114,6 +120,17 @@ public class SDMobileActivity extends Activity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
SM.Debug("##### onCREATE ##### with LANGUAGE " + AppParams.LANGUAGETMP);
|
SM.Debug("##### onCREATE ##### with LANGUAGE " + AppParams.LANGUAGETMP);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
AppParams.theme = AppParams.Theme.SAFEDISPATCH;
|
AppParams.theme = AppParams.Theme.SAFEDISPATCH;
|
||||||
if (AppParams.theme == AppParams.Theme.SAFENET)
|
if (AppParams.theme == AppParams.Theme.SAFENET)
|
||||||
this.setTheme(R.style.Theme_Safenet);
|
this.setTheme(R.style.Theme_Safenet);
|
||||||
@ -524,6 +541,22 @@ public class SDMobileActivity extends Activity {
|
|||||||
SM.Debug("##### onRESUME #####");
|
SM.Debug("##### onRESUME #####");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
|
||||||
|
@Override
|
||||||
|
public void onAvailable(Network network) {
|
||||||
|
// network available
|
||||||
|
Log.v("NetworkAvailability", "available");
|
||||||
|
if (tcp != null && !tcp.isConnectionUP)
|
||||||
|
saveIPandRestartTCP(AppParams.IP, AppParams.PORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLost(Network network) {
|
||||||
|
// network unavailable
|
||||||
|
Log.v("NetworkAvailability", "unavailable");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
private void startTabActivity(long userID) {
|
private void startTabActivity(long userID) {
|
||||||
// good login - load activity
|
// good login - load activity
|
||||||
|
@ -57,8 +57,9 @@ import com.safemobile.services.TCPService.TCPBinder;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.Notification;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@ -73,6 +74,7 @@ import android.content.res.Configuration;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@ -93,6 +95,8 @@ import android.widget.Toast;
|
|||||||
import android.widget.TabHost.TabSpec;
|
import android.widget.TabHost.TabSpec;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.app.NotificationCompat;
|
||||||
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
|
|
||||||
public class TabLayoutActivity extends AbstractSDParentActivity {
|
public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||||
|
|
||||||
@ -1230,7 +1234,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
getMessageActivity().updateSMS(sms.smsList);
|
getMessageActivity().updateSMS(sms.smsList);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
SM.Debug("Error on smsReceived:" + ex.toString());
|
SM.Debug("Error on smsReceived:" + ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1395,7 +1399,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
|
|
||||||
HistCountmsg histCountMsg = new HistCountmsg(msg);
|
HistCountmsg histCountMsg = new HistCountmsg(msg);
|
||||||
SM.Debug("Message Count:" + histCountMsg.histcountValue.count);
|
SM.Debug("Message Count:" + histCountMsg.histcountValue.count);
|
||||||
if (histCountMsg.histcountValue.count >= 2000 && AppParams.crtTab == AppParams.Tabs.history) {
|
if (AppParams.crtTab != AppParams.Tabs.history) {
|
||||||
//list for live
|
//list for live
|
||||||
SM.Debug("currentActivity instanceof HistoryActivity");
|
SM.Debug("currentActivity instanceof HistoryActivity");
|
||||||
try {
|
try {
|
||||||
@ -1406,6 +1410,44 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
SM.Debug(HASH_ERROR_MESSAGE + ex);
|
SM.Debug(HASH_ERROR_MESSAGE + ex);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (histCountMsg.histcountValue.count >= 2000) {
|
||||||
|
try {
|
||||||
|
if (getHistoryActivity() != null) {
|
||||||
|
getHistoryActivity().UpdateCancel();
|
||||||
|
getHistoryActivity().UpdateUnableDisp();
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SM.Debug(HASH_ERROR_MESSAGE + ex);
|
||||||
|
}
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
DialogService dialogService = new DialogService();
|
||||||
|
dialogService.showError(getHistoryActivity(), getString(R.string.too_many_positions, String.valueOf(histCountMsg.histcountValue.count)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (histCountMsg.histcountValue.count == 0) {
|
||||||
|
try {
|
||||||
|
if (getHistoryActivity() != null) {
|
||||||
|
getHistoryActivity().UpdateCancel();
|
||||||
|
getHistoryActivity().UpdateUnableDisp();
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SM.Debug(HASH_ERROR_MESSAGE + ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
DialogService dialogService = new DialogService();
|
||||||
|
dialogService.showError(getHistoryActivity(), getString(R.string.no_data_for_interval));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1423,7 +1465,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
|
|
||||||
SM.Debug("tmpHist seqID:" + tmpHist.seqID);
|
SM.Debug("tmpHist seqID:" + tmpHist.seqID);
|
||||||
int pos = Integer.parseInt(tmpHist.seqID.substring(0, tmpHist.seqID.indexOf('.')));
|
int pos = Integer.parseInt(tmpHist.seqID.substring(0, tmpHist.seqID.indexOf('.')));
|
||||||
int all = Integer.parseInt(tmpHist.seqID.substring(tmpHist.seqID.indexOf('.') + 1, tmpHist.seqID.length()));
|
int all = Integer.parseInt(tmpHist.seqID.substring(tmpHist.seqID.indexOf('.') + 1));
|
||||||
if (all != 0) {
|
if (all != 0) {
|
||||||
if (Boolean.TRUE.equals(getFirstHistoryData())) {
|
if (Boolean.TRUE.equals(getFirstHistoryData())) {
|
||||||
try {
|
try {
|
||||||
@ -1646,66 +1688,63 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
SM.Debug("Unit imei:" + tempArr[0]);
|
SM.Debug("Unit imei:" + tempArr[0]);
|
||||||
String unitIMEI = tempArr[0];
|
String unitIMEI = tempArr[0];
|
||||||
|
|
||||||
|
|
||||||
|
// change Visual Elements
|
||||||
|
setImei(unitIMEI);
|
||||||
|
switch (msg.opCode) {
|
||||||
|
case 135:
|
||||||
|
setMess("speed " + tempArr[1]);
|
||||||
|
break;
|
||||||
|
case 136:
|
||||||
|
setMess("landmark " + tempArr[1]);
|
||||||
|
break;
|
||||||
|
case 137:
|
||||||
|
setMess("zone " + tempArr[1]);
|
||||||
|
break;
|
||||||
|
case 140:
|
||||||
|
setMess("telemetry " + tempArr[1]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// 138
|
||||||
|
setMess("emergency");
|
||||||
|
}
|
||||||
|
myHandler.post(updateResultsAlarm);
|
||||||
|
|
||||||
|
if ((msg.opCode == 138) && (AppParams.crtTab == AppParams.Tabs.live)) {
|
||||||
|
SuperVehicle superVehicle = getSuperVehHash().get(Long.parseLong(unitIMEI));
|
||||||
|
|
||||||
|
if (superVehicle != null) {
|
||||||
|
//if is not check i need to force check to put on the map
|
||||||
|
boolean forceChecked = false;
|
||||||
|
if (!superVehicle.needUpdate) {
|
||||||
|
superVehicle.needUpdate = true;
|
||||||
|
forceChecked = true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
int x = 0;
|
||||||
|
if (forceChecked) {
|
||||||
|
for (Vehicle veh : getAllVehicle()) {
|
||||||
|
if (veh.imei.compareTo(unitIMEI) == 0) break;
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
} else x = -1;
|
||||||
|
if (getLiveActivity() != null) {
|
||||||
|
if (x != getAllVehicle().size())
|
||||||
|
getLiveActivity().emergencyAlarmReceived(x, superVehicle.lat, superVehicle.lng);
|
||||||
|
else
|
||||||
|
getLiveActivity().emergencyAlarmReceived(-1, superVehicle.lat, superVehicle.lng);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
SM.Debug(HASH_ERROR_MESSAGE + ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//list for SMS
|
//list for SMS
|
||||||
if (AppParams.crtTab == AppParams.Tabs.alarms) {
|
if (AppParams.crtTab == AppParams.Tabs.alarms) {
|
||||||
SM.Debug("currentActivity instanceof AlarmActivity - newSMS | " + tempArr[0] + " | " + tempArr[1]);
|
SM.Debug("currentActivity instanceof AlarmActivity - newSMS | " + tempArr[0] + " | " + tempArr[1]);
|
||||||
getAlarms(AppParams.USERID);
|
getAlarms(AppParams.USERID);
|
||||||
}
|
}
|
||||||
// if tab is not TextTab
|
|
||||||
if (tabHost.getCurrentTab() != 5) {
|
|
||||||
// change Visual Elements
|
|
||||||
setImei(unitIMEI);
|
|
||||||
switch (msg.opCode) {
|
|
||||||
case 135:
|
|
||||||
setMess("speed " + tempArr[1]);
|
|
||||||
break;
|
|
||||||
case 136:
|
|
||||||
setMess("landmark " + tempArr[1]);
|
|
||||||
break;
|
|
||||||
case 137:
|
|
||||||
setMess("zone " + tempArr[1]);
|
|
||||||
break;
|
|
||||||
case 138:
|
|
||||||
setMess("emergency");
|
|
||||||
break;
|
|
||||||
case 140:
|
|
||||||
setMess("telemetry " + tempArr[1]);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
setMess("emergency");
|
|
||||||
}
|
|
||||||
myHandler.post(updateResultsAlarm);
|
|
||||||
|
|
||||||
if ((msg.opCode == 138) && (AppParams.crtTab == AppParams.Tabs.live)) {
|
|
||||||
SuperVehicle superVehicle = getSuperVehHash().get(Long.parseLong(unitIMEI));
|
|
||||||
|
|
||||||
if (superVehicle != null) {
|
|
||||||
//if is not check i need to force check to put on the map
|
|
||||||
boolean forceChecked = false;
|
|
||||||
if (!superVehicle.needUpdate) {
|
|
||||||
superVehicle.needUpdate = true;
|
|
||||||
forceChecked = true;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
int x = 0;
|
|
||||||
if (forceChecked) {
|
|
||||||
for (Vehicle veh : getAllVehicle()) {
|
|
||||||
if (veh.imei.compareTo(unitIMEI) == 0) break;
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
} else x = -1;
|
|
||||||
if (getLiveActivity() != null) {
|
|
||||||
if (x != getAllVehicle().size())
|
|
||||||
getLiveActivity().emergencyAlarmReceived(x, superVehicle.lat, superVehicle.lng);
|
|
||||||
else
|
|
||||||
getLiveActivity().emergencyAlarmReceived(-1, superVehicle.lat, superVehicle.lng);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
SM.Debug(HASH_ERROR_MESSAGE + ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1950,10 +1989,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
|
|
||||||
public void createNotification(int icon) {
|
public void createNotification(int icon) {
|
||||||
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
String tickerText = "SafeMobile Dispatch: New Message from " + getImei();
|
String contentTitle, contentText;
|
||||||
String contentTitle = "New Message from " + getImei();
|
|
||||||
String contentText = "\"" + getMess() + "\"";
|
|
||||||
|
|
||||||
Vehicle veh = getVehicle4Imei(getImei());
|
Vehicle veh = getVehicle4Imei(getImei());
|
||||||
|
|
||||||
int iconValue = icon;
|
int iconValue = icon;
|
||||||
@ -1966,7 +2002,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
case AppParams.pollNotif:
|
case AppParams.pollNotif:
|
||||||
contentText = "\"" + getMess() + "\"";
|
contentText = "\"" + getMess() + "\"";
|
||||||
contentTitle = "Poll Reply from " + (veh != null ? getVehicle4Imei(getImei()).name : getImei());
|
contentTitle = "Poll Reply from " + (veh != null ? getVehicle4Imei(getImei()).name : getImei());
|
||||||
tickerText = "SafeMobile Dispatch: Poll Reply from " + (veh != null ? getVehicle4Imei(getImei()).name : getImei());
|
|
||||||
icon = R.drawable.poll;
|
icon = R.drawable.poll;
|
||||||
break;
|
break;
|
||||||
case AppParams.alertNotif:
|
case AppParams.alertNotif:
|
||||||
@ -1975,34 +2010,52 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
vehName = getString(R.string.from) + ": " + getVehicle4Imei(getImei()).name;
|
vehName = getString(R.string.from) + ": " + getVehicle4Imei(getImei()).name;
|
||||||
contentText = "\"" + getMess() + "\"";
|
contentText = "\"" + getMess() + "\"";
|
||||||
contentTitle = getString(R.string.newAlarm) + vehName;
|
contentTitle = getString(R.string.newAlarm) + vehName;
|
||||||
tickerText = "SafeMobile Dispatch: " + getString(R.string.newAlarm) + vehName;
|
icon = R.drawable.arrow_down;
|
||||||
icon = R.drawable.alert;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + icon);
|
throw new IllegalStateException("Unexpected value: " + icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification notification = new Notification(icon, tickerText, System.currentTimeMillis());
|
|
||||||
|
|
||||||
// set intent to be opened on NotificationClick
|
// set intent to be opened on NotificationClick
|
||||||
/* Notification */
|
/* Notification */
|
||||||
Intent notificationIntent = new Intent(this, NotificationActivity.class);
|
Intent intent = new Intent(this, NotificationActivity.class);
|
||||||
notificationIntent.putExtra("key", iconValue);
|
intent.putExtra("key", iconValue);
|
||||||
|
|
||||||
// cancel old notification
|
// cancel old notification
|
||||||
mNotificationManager.cancel(icon);
|
mNotificationManager.cancel(icon);
|
||||||
|
|
||||||
PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ACTIVITY_RESULT, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, NOTIFICATION_ACTIVITY_RESULT, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
createNotificationChannel(icon, contentTitle, contentText, pendingIntent);
|
||||||
// flag that the notification will be closed when clicked
|
|
||||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
||||||
notification.number = 1; // the same notification will be shown;
|
|
||||||
notification.tickerText = tickerText; // notification text when arrives
|
|
||||||
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.new_sms);
|
|
||||||
// add notification to the manager
|
|
||||||
mNotificationManager.notify(icon, notification);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createNotificationChannel(int icon, String title, String text, PendingIntent pendingIntent) {
|
||||||
|
// Create the NotificationChannel, but only on API 26+ because
|
||||||
|
// the NotificationChannel class is new and not in the support library
|
||||||
|
String notificationChannelID = String.valueOf(icon);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
CharSequence name = "Notification Channel";
|
||||||
|
int importance = NotificationManager.IMPORTANCE_HIGH;
|
||||||
|
NotificationChannel channel = new NotificationChannel(notificationChannelID, name, importance);
|
||||||
|
// Register the channel with the system; you can't change the importance
|
||||||
|
// or other notification behaviors after this
|
||||||
|
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
||||||
|
notificationManager.createNotificationChannel(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, notificationChannelID)
|
||||||
|
.setSmallIcon(icon)
|
||||||
|
.setContentTitle(title)
|
||||||
|
.setContentText(text)
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.setContentIntent(pendingIntent);
|
||||||
|
|
||||||
|
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context);
|
||||||
|
managerCompat.notify(icon, builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// return vehicle according to imei
|
// return vehicle according to imei
|
||||||
private Vehicle getVehicle4Imei(String imei) {
|
private Vehicle getVehicle4Imei(String imei) {
|
||||||
Vehicle veh = null;
|
Vehicle veh = null;
|
||||||
@ -2146,7 +2199,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
|
|
||||||
setVehicleStatus(Integer.parseInt(params[1]), Integer.parseInt(params[2]), Integer.parseInt(params[3]), Integer.parseInt(params[4]));
|
setVehicleStatus(Integer.parseInt(params[1]), Integer.parseInt(params[2]), Integer.parseInt(params[3]), Integer.parseInt(params[4]));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
SM.Exception("Paramas -> setVehicleStatus", "EXCeption ex " + ex.toString());
|
SM.Exception("Paramas -> setVehicleStatus", "EXCeption ex " + ex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2177,21 +2230,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
new ConnectTask().execute(params);
|
new ConnectTask().execute(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConnectParserTask extends AsyncTask<String, Void, TCPhandler> {
|
|
||||||
@Override
|
|
||||||
protected TCPhandler doInBackground(String... params) {
|
|
||||||
if (myService != null)
|
|
||||||
tcpParser = myService.getTCPmsgParser();
|
|
||||||
|
|
||||||
// add TCPParserListener
|
|
||||||
if (tcpParser != null) {
|
|
||||||
SM.Debug("## tcpParser != null ", "#### call tcpParserListener(");
|
|
||||||
tcpParserListener();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Display Toast messages*/
|
/* Display Toast messages*/
|
||||||
@Override
|
@Override
|
||||||
public void displayToast(final String msg) {
|
public void displayToast(final String msg) {
|
||||||
@ -2301,10 +2339,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
|
||||||
SM.Debug("onRequestPermissionsResult", "[requestCode] " + requestCode);
|
SM.Debug("onRequestPermissionsResult", "[requestCode] " + requestCode);
|
||||||
String permission = "";
|
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case PermissionModule.RECORD_AUDIO_PERMISSION_REQUEST_CODE:
|
case PermissionModule.RECORD_AUDIO_PERMISSION_REQUEST_CODE:
|
||||||
permission = Manifest.permission.RECORD_AUDIO;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + requestCode);
|
throw new IllegalStateException("Unexpected value: " + requestCode);
|
||||||
@ -2355,10 +2391,9 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
|
|
||||||
private void waitForUserInput(Boolean result) {
|
private void waitForUserInput(Boolean result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
final int requestCode = 1202;
|
|
||||||
//navigate to application's settings
|
//navigate to application's settings
|
||||||
String action = ProviderSettingsHelper.getAction(ProviderSettingsStatus.APPLICATION_DETAILS);
|
String action = ProviderSettingsHelper.getAction(ProviderSettingsStatus.APPLICATION_DETAILS);
|
||||||
if (action == null || action == "")
|
if (action == null || action.equals(""))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
boolean isActionApplicationDetailsSettings = action.equals(ProviderSettingsHelper.ACTION_APPLICATION_DETAILS_SETTINGS);
|
boolean isActionApplicationDetailsSettings = action.equals(ProviderSettingsHelper.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||||
|
@ -88,7 +88,9 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/layoutNewMessage"
|
android:id="@+id/layoutNewMessage"
|
||||||
android:layout_width="350dp"
|
android:layout_width="350dp"
|
||||||
@ -113,7 +115,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_height="wrap_content"
|
android:padding="3dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/slideTabsText"
|
android:id="@+id/slideTabsText"
|
||||||
|
@ -166,7 +166,7 @@
|
|||||||
<GridView
|
<GridView
|
||||||
android:id="@+id/gridView1"
|
android:id="@+id/gridView1"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:background="#999999"
|
android:background="#999999"
|
||||||
android:drawSelectorOnTop="false"
|
android:drawSelectorOnTop="false"
|
||||||
android:horizontalSpacing="0dp"
|
android:horizontalSpacing="0dp"
|
||||||
|
@ -164,7 +164,7 @@
|
|||||||
<GridView
|
<GridView
|
||||||
android:id="@+id/gridView1"
|
android:id="@+id/gridView1"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:background="#999999"
|
android:background="#999999"
|
||||||
android:drawSelectorOnTop="false"
|
android:drawSelectorOnTop="false"
|
||||||
android:horizontalSpacing="0dp"
|
android:horizontalSpacing="0dp"
|
||||||
|
@ -263,5 +263,7 @@
|
|||||||
<string name="permissionBlocked">%1$s permission was not accepted. To be able to use the %2$s, please open application settings and grant the %3$s permission</string>
|
<string name="permissionBlocked">%1$s permission was not accepted. To be able to use the %2$s, please open application settings and grant the %3$s permission</string>
|
||||||
<string name="microphone">Microphone</string>
|
<string name="microphone">Microphone</string>
|
||||||
<string name="radio_tab">Radio Tab</string>
|
<string name="radio_tab">Radio Tab</string>
|
||||||
|
<string name="too_many_positions">You have selected %1$s positions.\nPlease select a smalled interval.</string>
|
||||||
|
<string name="no_data_for_interval">No data for this interval</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Reference in New Issue
Block a user