public static int HeartBeatAlarmCycle = 5;
//如果重试都失败,则丢弃命令不进行盲点续传
- public static boolean discard_cmd_after_retryfailed = true;
+ public static boolean discard_cmd_after_retry_failed = true;
public static boolean enableDataRoaming = false;
}, 5000);
}
} else if (cmd.startsWith("testCMDRecords")) {
-
if (CoreService.getInstance() != null) {
StringMessage msg = protocolAPIHelper.getLBSLocationMSG(runtime);
runtime.getDbHelper().insertCMDRecord(msg);
package com.enqualcomm.support.service;
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
-import android.net.ConnectivityManager;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
-import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.PowerManager;
import com.enqualcomm.support.service.base.AbstractConnectionService;
import com.enqualcomm.support.utils.AESCipher;
import com.enqualcomm.support.utils.Connection;
-import com.enqualcomm.support.utils.FileCache;
import com.enqualcomm.support.utils.ICLogger;
import com.enqualcomm.support.utils.NettyConnection;
import com.enqualcomm.support.utils.SharePreferenceUtil;
import com.ic.protocols.protocolAPIHelper;
import java.util.concurrent.LinkedBlockingDeque;
-import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
-import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
-import static com.enqualcomm.support.Constants.ACTION_WAKEUP_ALARM;
import static com.enqualcomm.support.Constants.DIALOG_ACTION;
import static com.enqualcomm.support.Constants.FROM_SERVER;
import static com.enqualcomm.support.bean.Contact.CATEGORY_GROUP;
private static int CheckCount = 0;
private static boolean checkNeedServerResponse(StringMessage cmd) {
- return false;
-// boolean NeedCheckServerResponse;
-// if (cmd != null &&
-// Config.protocol_no == Config.PROTOCOL_FZD &&
-// (protocolAPIHelper.isCmdStr(cmd).equals("UD")
-// || protocolAPIHelper.isCmdStr(cmd).equals("UD2"))
-// ) {
-// NeedCheckServerResponse = false;
-// } else if (cmd != null &&
-// Config.protocol_no == Config.PROTOCOL_FZD &&
-// (protocolAPIHelper.isCmdStr(cmd).equals("AP10"))) {
-// NeedCheckServerResponse = false;
-// } else {
-// NeedCheckServerResponse = true;
-// }
-// return NeedCheckServerResponse;
+// return false;
+ boolean NeedCheckServerResponse;
+ if (cmd != null &&
+ Config.protocol_no == Config.PROTOCOL_FZD &&
+ (protocolAPIHelper.isCmdStr(cmd).equals("UD")
+ || protocolAPIHelper.isCmdStr(cmd).equals("UD2"))
+ ) {
+ NeedCheckServerResponse = false;
+ } else if (cmd != null &&
+ Config.protocol_no == Config.PROTOCOL_FZD &&
+ (protocolAPIHelper.isCmdStr(cmd).equals("AP10"))) {
+ NeedCheckServerResponse = false;
+ } else {
+ NeedCheckServerResponse = true;
+ }
+ return NeedCheckServerResponse;
}
public static void dumpMessage(StringMessage msg) {
ICLogger.i("queue locked " + mLock.isLocked() +
" current Thread is == > "
+ Thread.currentThread().getName());
- if (mLock.isLocked()) return false;
+ if (mLock.isLocked()) {
+ return false;
+ }
mLock.lock();
try {
String str;
//如果没有数据从缓存中尝试读取
//检查刚刚发送出去的包是否需要检查server response
+ //FLAG为1的表示等待发送的指令
StringMessage msgWait = mRuntime.getDbHelper().queryWaitCMDRecord();
dumpMessage(msgWait);
if (msgWait != null) {
if (CheckCount > 5) {
ICLogger.i("checkSrvResponse CheckCount=" + CheckCount + " Timeout or cmd is null, skip ");
//C5要的临时版本,去掉盲点续传。
- if (Config.discard_cmd_after_retryfailed) {
+ if (Config.discard_cmd_after_retry_failed) {
if (msgWait.getIndex() >= 0) {
//有些协议需要对盲点数据进行修改(盲点数据可能是不同的topic),在此对数据修改后更新数据库
mRuntime.getDbHelper().updateCMDRecord(msgWait.getIndex(), 3);//设置为盲点不发送
}
dumpMessage(msgWait);
}
- if (Config.LOG_TOFILE)
+ if (Config.LOG_TOFILE) {
ICLogger.logToFile("APILog", "response timeout skip! ");
+ }
CheckCount = 0;
- if (mLock != null && mLock.isLocked())
+ if (mLock != null && mLock.isLocked()) {
mLock.unlock();
+ }
return false;
}
-
}
StringBuilder stringBuilder = new StringBuilder();
StringMessage msgSent;
- if (Config.discard_cmd_after_retryfailed) {
+ if (Config.discard_cmd_after_retry_failed) {
//如果可以丢弃数据,则直接查找没发送的数据即可
msgSent = mRuntime.getDbHelper().queryNotSentCMDRecord();
} else {
if (checkNetwork()) {
connection.send(msgSent);
//如果需要CheckResponse
- if (checkNeedServerResponse(msgSent) == true) {
+ if (checkNeedServerResponse(msgSent)) {
ICLogger.i("checkSrvResponse " + topic + " " + cmd);
mRuntime.getDbHelper().updateCMDRecord(msgSent.getIndex(), 1); //设置为等待响应
} else {
//但是有些协议要求此数据 需要转变为 盲点续传数据(已经是盲点的跳过)
mRuntime.getDbHelper().updateCMDRecordForUD2(0, msgSent); //重发时无网络 //把UD改为UD2 保存到数据库
}
-
//ICLogger.i("\n"+queue.size()+" left in Queue!");
} finally {
- if (mLock != null && mLock.isLocked())
+ if (mLock != null && mLock.isLocked()) {
mLock.unlock();
+ }
}
}
ICLogger.d("getAndSendMsgFromQueue == > ret == > " + ret);
StringMessage msgWait = mRuntime.getDbHelper().queryWaitCMDRecord();
dumpMessage(msgWait);
if (msgWait != null) {
- if (Config.discard_cmd_after_retryfailed) {
+ if (Config.discard_cmd_after_retry_failed) {
while (msgWait != null) {
//所有缓存数据都设置为放弃发送
mRuntime.getDbHelper().updateCMDRecord(msgWait.getIndex(), 3);
flagcontent.put("TOPIC", UD2.cmd());
flagcontent.put("CMD", UD2.isFromCache());
this.cr.update(ICContentProvider.PROTOCOL_CMD_RECORDS_URI, flagcontent, WhereClause, null);
-
ICLogger.d(" 更新 UD " + msg.isFromCache() + "\nto UD2 " + UD2.isFromCache());
} else {
ICLogger.e("genMissedUD2Msg failed, skip gen UD2 msg");
String WhereClause = null;
if (id >= 0) {
WhereClause = new StringBuilder("_id=").append(id).toString();
- ContentValues flagcontent = new ContentValues();
- flagcontent.put("FLAG", flag);
- this.cr.update(ICContentProvider.PROTOCOL_CMD_RECORDS_URI, flagcontent, WhereClause, null);
+ ContentValues values = new ContentValues();
+ values.put("FLAG", flag);
+ this.cr.update(ICContentProvider.PROTOCOL_CMD_RECORDS_URI, values, WhereClause, null);
}
}
msg.setSentFlag(flag);
msg.setIndex(index);
ICLogger.i("get cmd Record not sent _id " + index + " " + date + time + " topic " + topic + " cmd " + cmd);
-
}
cmdrecords.close();
} else { //没有警报,就查询 UD 消息发送 //当前数据优先于 UD2数据
public StringMessage queryWaitCMDRecord() {
ContentResolver pcr = this.cr;
Uri table = ICContentProvider.PROTOCOL_CMD_RECORDS_URI;
- StringBuilder where = new StringBuilder();
- where.append("FLAG=1");
- // ICLogger.i("Query cmdRecords "+where);
- Cursor cmdrecords = pcr.query(table, (String[]) null, where.toString(), (String[]) null, (String) null);
+ Cursor cmdRecords = pcr.query(table, null, "FLAG=1", null, null);
StringMessage msg = null;
- if (cmdrecords != null) {
- int score = 0;
- if (cmdrecords.getCount() > 0) {
- if (cmdrecords.moveToFirst()) {
- String topic = cmdrecords.getString(cmdrecords.getColumnIndex("TOPIC"));
- String cmd = cmdrecords.getString(cmdrecords.getColumnIndex("CMD"));
- String date = cmdrecords.getString(cmdrecords.getColumnIndex("DATE"));
- String time = cmdrecords.getString(cmdrecords.getColumnIndex("TIME"));
- int flag = cmdrecords.getInt(cmdrecords.getColumnIndex("FLAG"));
- int index = cmdrecords.getInt(cmdrecords.getColumnIndex("_id"));
+ if (cmdRecords != null) {
+ if (cmdRecords.getCount() > 0) {
+ if (cmdRecords.moveToFirst()) {
+ String topic = cmdRecords.getString(cmdRecords.getColumnIndex("TOPIC"));
+ String cmd = cmdRecords.getString(cmdRecords.getColumnIndex("CMD"));
+ String date = cmdRecords.getString(cmdRecords.getColumnIndex("DATE"));
+ String time = cmdRecords.getString(cmdRecords.getColumnIndex("TIME"));
+ int flag = cmdRecords.getInt(cmdRecords.getColumnIndex("FLAG"));
+ int index = cmdRecords.getInt(cmdRecords.getColumnIndex("_id"));
msg = new StringMessage(new String[]{topic});
msg.refresh(cmd);
msg.setSentFlag(flag);
msg.setIndex(index);
ICLogger.i("get cmd Record wait response _id " + index + " " + date + time + " topic " + topic + " cmd " + cmd);
-
}
}
- cmdrecords.close();
+ cmdRecords.close();
if (msg == null)
ICLogger.i("no cmd record in wait status !");
ret = protocol_jiai.AP02(runtime);
break;
case Config.PROTOCOL_BEEHOME:
- ret = protocol_beehome.AP02(runtime);
+ ret = protocol_beehome.AP01(runtime);
break;
case Config.PROTOCOL_IC:
ret = protocol_ic.AP02(runtime);
}
return ret;
}
- public static void sendVoice(int duration, String remoteNum, String content, String voiceId){
- if (is_protocol_not_Initialled()) return ;
+
+ public static void sendVoice(int duration, String remoteNum, String content, String voiceId) {
+ if (is_protocol_not_Initialled()) return;
switch (Config.protocol_no) {
case Config.PROTOCOL_JIAI:
case Config.PROTOCOL_IC:
break;
case Config.PROTOCOL_FZD:
- protocolfzd_handler.sendVoice(duration,remoteNum,content,voiceId);
+ protocolfzd_handler.sendVoice(duration, remoteNum, content, voiceId);
break;
case Config.PROTOCOL_MQTT:
break;
case Config.PROTOCOL_GATOR:
- protocolgator_handler.sendVoicePackage(duration,remoteNum,content,voiceId);
+ protocolgator_handler.sendVoicePackage(duration, remoteNum, content, voiceId);
break;
}
}
+
public static void sendPicture(String remoteNum, String imagePath, String imageId) {
- if (is_protocol_not_Initialled()) return ;
+ if (is_protocol_not_Initialled()) return;
switch (Config.protocol_no) {
case Config.PROTOCOL_JIAI:
case Config.PROTOCOL_IC:
break;
case Config.PROTOCOL_FZD:
- protocolfzd_handler.sendPicture(remoteNum,imagePath,imageId);
+ protocolfzd_handler.sendPicture(remoteNum, imagePath, imageId);
break;
case Config.PROTOCOL_MQTT:
}
}
- public static byte[] getVoicePacketItem(String sender,String durationHEX,String packetTime, int count, int index, int datalen, byte[] amrdata, int filetype, int datatype) {
+
+ public static byte[] getVoicePacketItem(String sender, String durationHEX, String packetTime, int count, int index, int datalen, byte[] amrdata, int filetype, int datatype) {
byte[] ret = null;
if (is_protocol_not_Initialled()) return null;
switch (Config.protocol_no) {
}
break;
case Config.PROTOCOL_GATOR:
- ret = protocol_gator.BP34_Raw(sender,packetTime,durationHEX,count,index,datalen,amrdata);
+ ret = protocol_gator.BP34_Raw(sender, packetTime, durationHEX, count, index, datalen, amrdata);
break;
}
return ret;
/**
* 获取VideoCall 联系人列表
+ *
* @param runtime
* @return
*/
/**
* 获取VideoCall ID
+ *
* @param runtime
* @return
*/
/**
* 拒接VideoCall
+ *
* @param runtime
* @param remoteId
* @param type
* @return
*/
- public static StringMessage rejectVideoCall(Runtime runtime,String remoteId, int type) {
+ public static StringMessage rejectVideoCall(Runtime runtime, String remoteId, int type) {
if (is_protocol_not_Initialled()) return null;
StringMessage ret = null;
switch (Config.protocol_no) {
}
return ret;
}
- public static StringMessage dialVideoCall(Runtime runtime,int type, int remoteUserId) {
+
+ public static StringMessage dialVideoCall(Runtime runtime, int type, int remoteUserId) {
if (is_protocol_not_Initialled()) return null;
StringMessage ret = null;
switch (Config.protocol_no) {
}
public static void updateEnvState(Runtime runtime, int state) {
- if (is_protocol_not_Initialled()) return ;
+ if (is_protocol_not_Initialled()) return;
switch (Config.protocol_no) {
case Config.PROTOCOL_JIAI:
break;
case Config.PROTOCOL_FZD:
- protocolfzd_handler.updateEnvState(state);
+ protocolfzd_handler.updateEnvState(state);
break;
case Config.PROTOCOL_MQTT:
ICLogger.i("服务器收到心跳包AP03");
mConnection.DeliverCMDMessageToSystem("heartbeat", cmd);//通知下面线程状态变化
break;
-
case BP07:
//收到发送的语音包
handleBP07(cmd, mConnection);