From 892d7dba038d31c812b619cf971fc97d9f79eb0b Mon Sep 17 00:00:00 2001 From: TrillGates Date: Tue, 30 Mar 2021 09:35:47 +0800 Subject: [PATCH] parse talk msg for fzd --- .../com/enqualcomm/support/CrashHandler.java | 27 +- .../com/enqualcomm/support/bean/Runtime.java | 2 +- .../enqualcomm/support/bean/voicePacket.java | 198 +- .../support/provider/FZDDatabaseHelper.java | 36 +- .../support/utils/CellInfoUtil.java | 4 +- .../support/utils/NettyConnection.java | 9 +- .../enqualcomm/support/utils/RxSocket.java | 3 +- .../com/enqualcomm/support/utils/Util.java | 2177 +++++++++-------- .../java/com/ic/protocols/protocol_fzd.java | 235 +- .../java/com/ic/protocols/protocol_jiai.java | 15 +- docs/README.md | 19 + local.properties | 4 +- 12 files changed, 1485 insertions(+), 1244 deletions(-) create mode 100644 docs/README.md diff --git a/app/src/main/java/com/enqualcomm/support/CrashHandler.java b/app/src/main/java/com/enqualcomm/support/CrashHandler.java index 7b76c212..277841a5 100644 --- a/app/src/main/java/com/enqualcomm/support/CrashHandler.java +++ b/app/src/main/java/com/enqualcomm/support/CrashHandler.java @@ -4,12 +4,10 @@ import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; -import android.os.Environment; import android.os.Looper; import android.util.Log; import android.widget.Toast; -import com.enqualcomm.support.R; import com.enqualcomm.support.utils.StorageUtils; import com.enqualcomm.support.utils.Util; @@ -26,7 +24,6 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; - /** * Created by Administrator on 2017/5/18. */ @@ -55,9 +52,9 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler { /** * 获取CrashHandler实例 ,单例模式 */ - public synchronized static CrashHandler getInstance() { - if (INSTANCE==null) - INSTANCE=new CrashHandler(); + public synchronized static CrashHandler getInstance() { + if (INSTANCE == null) + INSTANCE = new CrashHandler(); return INSTANCE; } @@ -119,7 +116,7 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler { // 保存日志文件 saveCrashInfo2File(ex); //设置断网状态 - Util.setSystemProperties("persist.sys.server_connected","false"); + Util.setSystemProperties("persist.sys.server_connected", "false"); return true; } @@ -198,14 +195,14 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler { // if (Environment.getExternalStorageState().equals( // Environment.MEDIA_MOUNTED)) { // File dir = new File(mContext.getExternalCacheDir(), "crash"); - File dir= new File(StorageUtils.getExternalStorageLogDir()); - String path = dir.getPath(); - if (!dir.exists()) { - dir.mkdirs(); - } - FileOutputStream fos = new FileOutputStream(new File(path, fileName), true); - fos.write(sb.toString().getBytes()); - fos.close(); + File dir = new File(StorageUtils.getExternalStorageLogDir()); + String path = dir.getPath(); + if (!dir.exists()) { + dir.mkdirs(); + } + FileOutputStream fos = new FileOutputStream(new File(path, fileName), true); + fos.write(sb.toString().getBytes()); + fos.close(); // } return fileName; } catch (Exception e) { diff --git a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java index b7b0f6dd..1db8b58b 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java +++ b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java @@ -118,7 +118,7 @@ public class Runtime { } public boolean isServerProtocolConnected() { - ICLogger.d("ServerHeartBeadReceived == > " + ServerHeartBeadReceived); + // ICLogger.d("ServerHeartBeadReceived == > " + ServerHeartBeadReceived); return ServerHeartBeadReceived; } diff --git a/app/src/main/java/com/enqualcomm/support/bean/voicePacket.java b/app/src/main/java/com/enqualcomm/support/bean/voicePacket.java index 92add632..cd51f3c4 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/voicePacket.java +++ b/app/src/main/java/com/enqualcomm/support/bean/voicePacket.java @@ -6,45 +6,49 @@ import java.util.Iterator; public class voicePacket { - private static voicePacket gvoicePacket=null; - public synchronized static voicePacket getInstance(){ - if (gvoicePacket==null) - gvoicePacket=new voicePacket(); + private static voicePacket gvoicePacket = null; + + public synchronized static voicePacket getInstance() { + if (gvoicePacket == null) + gvoicePacket = new voicePacket(); return gvoicePacket; } - private static voicePacket gvoicepacket_sent=null; - public synchronized static voicePacket getInstanceSent(){ - if (gvoicepacket_sent==null) - gvoicepacket_sent=new voicePacket(); + + private static voicePacket gvoicepacket_sent = null; + + public synchronized static voicePacket getInstanceSent() { + if (gvoicepacket_sent == null) + gvoicepacket_sent = new voicePacket(); return gvoicepacket_sent; } - int filetype=1; - int datatype=3; - String time=null; - String Name=null; - String appendIndex=null; - int packetCount =0; - int currentIndexToSent=0;// 如果 (currentIndexToSent == (packetCount -1)) 则发送完毕 + int filetype = 1; + int datatype = 3; + String time = null; + String Name = null; + String appendIndex = null; + int packetCount = 0; + int currentIndexToSent = 0;// 如果 (currentIndexToSent == (packetCount -1)) 则发送完毕 - public void setCurrentIndexToSent(int index){ - currentIndexToSent=index; + public void setCurrentIndexToSent(int index) { + currentIndexToSent = index; } - public int getCurrentIndexToSent(){ + public int getCurrentIndexToSent() { return currentIndexToSent; } - public int getPacketCount(){ + public int getPacketCount() { return packetCount; } - public void setPacketTime(String _time){ - time=_time; + public void setPacketTime(String _time) { + time = _time; } - public String getPacketTime(){ + + public String getPacketTime() { return time; } @@ -55,84 +59,90 @@ public class voicePacket { * @param type * @param dtype */ - public void setFileType(int type,int dtype){ - filetype=type; - datatype=dtype; + public void setFileType(int type, int dtype) { + filetype = type; + datatype = dtype; } - public int getFiletype(){ + public int getFiletype() { return filetype; } - public int getDateType(){ + + public int getDateType() { return datatype; } - ArrayList packetArray =new ArrayList(); - public class voicepacketItem{ + + ArrayList packetArray = new ArrayList(); + + public class voicepacketItem { int currentId; int packetLen; byte[] packetData; - voicepacketItem(int _currentId, int _packetLen, byte[] _packetData){ - packetLen=_packetLen; - packetData=new byte[packetLen]; - System.arraycopy(_packetData,0,packetData,0,packetLen); - currentId=_currentId; + + voicepacketItem(int _currentId, int _packetLen, byte[] _packetData) { + packetLen = _packetLen; + packetData = new byte[packetLen]; + System.arraycopy(_packetData, 0, packetData, 0, packetLen); + currentId = _currentId; } - public byte[] getPacketData() - { + + public byte[] getPacketData() { return packetData; } - public int getPacketLen(){ + + public int getPacketLen() { return packetLen; } } - public boolean appendVoice(String _Name, String _appendIndex,int _packetCount,int _currentId, int _packetLen, byte[] _packetData){ - boolean ret=false; - if (_Name==null|| _appendIndex==null || _Name.isEmpty() ){ - return false; + + public boolean appendVoice(String _Name, String _appendIndex, int _packetCount, int _currentId, int _packetLen, byte[] _packetData) { + boolean ret = false; + if (_Name == null || _appendIndex == null || _Name.isEmpty()) { + return false; } - if (packetArray.size()==0) - { - Name=_Name; - appendIndex=_appendIndex; - packetCount=_packetCount; + if (packetArray.size() == 0) { + Name = _Name; + appendIndex = _appendIndex; + packetCount = _packetCount; } - if (_packetCount==packetCount && Name.equals(_Name) ){ - boolean packetfound=false; - for ( voicepacketItem item: packetArray ) { - if (item.currentId == _currentId){ - packetfound=true; + if (_packetCount == packetCount && Name.equals(_Name)) { + boolean packetfound = false; + for (voicepacketItem item : packetArray) { + if (item.currentId == _currentId) { + packetfound = true; } } if (packetfound) return false; - packetArray.add(new voicepacketItem(_currentId,_packetLen,_packetData)); + packetArray.add(new voicepacketItem(_currentId, _packetLen, _packetData)); } return ret; } - public boolean isFinished(){ - return (packetCount!=0 && packetCount==packetArray.size()); + public boolean isFinished() { + return (packetCount != 0 && packetCount == packetArray.size()); } - public boolean isEmpty(){ - return packetArray.size()==0; + public boolean isEmpty() { + return packetArray.size() == 0; } + @Override - public String toString(){ - StringBuilder stringBuilder=new StringBuilder(); - if (Name==null|| appendIndex==null || Name.isEmpty() ){ + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + if (Name == null || appendIndex == null || Name.isEmpty()) { return stringBuilder.toString(); } stringBuilder.append("{ Name=").append(Name) .append(", packetCount=").append(packetCount) .append(", appendIndex=").append(appendIndex) - .append("["); - for (voicepacketItem item: packetArray ) { + .append("["); + for (voicepacketItem item : packetArray) { stringBuilder.append("(").append(item.currentId) .append(",").append(item.packetLen).append("},"); } @@ -140,57 +150,59 @@ public class voicePacket { return stringBuilder.toString(); } - public void clearPacket(){ + public void clearPacket() { packetArray.clear(); - packetCount=0; - Name=null; - appendIndex=null; - } - - public int getVoicePacketLen(){ - int len=0; - if (isFinished()){ - Iterator it= packetArray.iterator(); - while(it.hasNext()){ - len+=it.next().packetLen; - } + packetCount = 0; + Name = null; + appendIndex = null; + } + + public int getVoicePacketLen() { + int len = 0; + if (isFinished()) { + Iterator it = packetArray.iterator(); + while (it.hasNext()) { + len += it.next().packetLen; + } } return len; } - public voicepacketItem getVoicePacketWithIndex(int index){ - for (int i=0;i< packetArray.size();i++){ - voicepacketItem tmp=packetArray.get(i); - if (tmp.currentId==index) - return tmp; - } - return null; + + public voicepacketItem getVoicePacketWithIndex(int index) { + for (int i = 0; i < packetArray.size(); i++) { + voicepacketItem tmp = packetArray.get(i); + if (tmp.currentId == index) + return tmp; + } + return null; } - public byte[] getVoicePacketBytes(){ + + public byte[] getVoicePacketBytes() { byte[] amrbuf; - int buflen=getVoicePacketLen(); - if (buflen>0){ - amrbuf=new byte[buflen]; - int index=0; - for(int i =0;i 0) { + amrbuf = new byte[buflen]; + int index = 0; + for (int i = 0; i < packetCount; i++) { + voicepacketItem tmp = getVoicePacketWithIndex(i); + if (tmp != null) { //src - 源数组。 //srcPos - 源数组中的起始位置。 //dest - 目标数组。 //destPos - 目标数据中的起始位置。 //length - 要复制的数组元素的数量。 - System.arraycopy(tmp.packetData,0,amrbuf,index,tmp.packetLen); - index+=tmp.packetLen; + System.arraycopy(tmp.packetData, 0, amrbuf, index, tmp.packetLen); + index += tmp.packetLen; } } return amrbuf; - }else{ + } else { return null; } } - public String getName(){ + public String getName() { return Name; } } diff --git a/app/src/main/java/com/enqualcomm/support/provider/FZDDatabaseHelper.java b/app/src/main/java/com/enqualcomm/support/provider/FZDDatabaseHelper.java index 5b1a9043..493fc49d 100644 --- a/app/src/main/java/com/enqualcomm/support/provider/FZDDatabaseHelper.java +++ b/app/src/main/java/com/enqualcomm/support/provider/FZDDatabaseHelper.java @@ -17,8 +17,8 @@ public class FZDDatabaseHelper extends SQLiteOpenHelper { public FZDDatabaseHelper(@Nullable Context context) { super(context, DB_NAME, null, DEFAULT_VERSION); } - //数据库字段需要有:id,user_name,phone_num,create_time,update_time + //数据库字段需要有:id,user_name,phone_num,create_time,update_time public static final String tMembers = "members"; public static final String fID = "_id"; public static final String fUserName = "user_name"; @@ -26,6 +26,18 @@ public class FZDDatabaseHelper extends SQLiteOpenHelper { public static final String fCreateTime = "create_time"; public static final String fUpdateTime = "update_time"; + //语音相关的表,字段有:id:ID,content:内容,type:类型,1表示语音,2表示文本,3表示图片 + //state:状态,0表示未读,1表示已读,in_or_out:1表示来信,2表示发出去的内容,remote_num:对方的手机号码 + //create_time:创建时间,update_time:更新时间 + public static final String tMessage = "message"; + public static final String mId = "_id"; + public static final String mContent = "content"; + public static final String mType = "type"; + public static final String mState = "state"; + public static final String mInOrOut = "in_or_out"; + public static final String mRemoteNum = "remote_num"; + public static final String mCreateTime = "create_time"; + public static final String mUpdateTime = "update_time"; @Override public void onCreate(SQLiteDatabase db) { @@ -46,6 +58,28 @@ public class FZDDatabaseHelper extends SQLiteOpenHelper { + ")"; ICLogger.d(createMembers); db.execSQL(createMembers); + //创建消息数据库 + String createMsg = "create table " + + tMessage + + " (" + + mId + + " integer primary key, " + + mContent + + " text, " + + mType + + " integer, " + + mState + + " integer, " + + mInOrOut + + " integer "+ + mRemoteNum + + " text, "+ + mCreateTime + + " date, " + + mUpdateTime+ + " date)"; + ICLogger.d(createMsg); + db.execSQL(createMsg); } @Override diff --git a/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java b/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java index 450ac7e3..6bcb7cb8 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java @@ -121,12 +121,12 @@ public class CellInfoUtil { return cigsm.getDbm(); } else if (cinfo instanceof CellInfoLte) { CellSignalStrengthLte cigsm = ((CellInfoLte) cinfo).getCellSignalStrength(); - ICLogger.i("lte signal dbm =" + cigsm.getDbm() + ",level=" + cigsm.getLevel()); + //ICLogger.i("lte signal dbm =" + cigsm.getDbm() + ",level=" + cigsm.getLevel()); runtime.setSignalInfo("lte signal dbm =" + cigsm.getDbm() + ",level=" + cigsm.getLevel()); return cigsm.getDbm(); } else if (cinfo instanceof CellInfoWcdma) { CellSignalStrengthWcdma cicdma = ((CellInfoWcdma) cinfo).getCellSignalStrength(); - ICLogger.i("wcdma signal dbm =" + cicdma.getDbm() + ",level=" + cicdma.getLevel()); + // ICLogger.i("wcdma signal dbm =" + cicdma.getDbm() + ",level=" + cicdma.getLevel()); runtime.setSignalInfo("wcdma signal dbm =" + cicdma.getDbm() + ",level=" + cicdma.getLevel()); return cicdma.getDbm(); } diff --git a/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java b/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java index 22fb2bd9..c014a8d3 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java +++ b/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java @@ -41,14 +41,13 @@ public class NettyConnection implements Connection { mHandler = new Handler(handlerThread.getLooper(), new Handler.Callback() { @Override public boolean handleMessage(Message message) { - if (message.what == 100) { byte[] bytes = message.getData().getByteArray("RecvData"); + //ICLogger.d("bytes length == > " + bytes); String msg = new String(bytes); - - log("get Msg :" + msg + " (size) byteslen" + bytes.length + " strlen" + msg.length()); + // ICLogger.d("msg == > " + msg); + //log("get Msg :" + msg + " (size) byteslen" + bytes.length + " strlen" + msg.length()); API.parserCmd("", bytes); - } return false; } @@ -270,7 +269,7 @@ public class NettyConnection implements Connection { RxSocket.getInstance().setSocketReadCallback(new RxSocket.SocketReadCallback() { @Override public void onRecvMsg(byte[] bytes) { - + //ICLogger.d("onRecvMsg == > " + bytes.length); Message msg = new Message(); Bundle bdl = new Bundle(); bdl.putByteArray("RecvData", bytes); diff --git a/app/src/main/java/com/enqualcomm/support/utils/RxSocket.java b/app/src/main/java/com/enqualcomm/support/utils/RxSocket.java index 0a27dbe2..7da9b62f 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/RxSocket.java +++ b/app/src/main/java/com/enqualcomm/support/utils/RxSocket.java @@ -373,8 +373,9 @@ public class RxSocket { for (int i = 0; i < length; i++) { bytes[i] = buf.get(i); } - if (socketReadCallback != null) + if (socketReadCallback != null) { socketReadCallback.onRecvMsg(bytes); + } readSubject.onNext(bytes); } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/Util.java b/app/src/main/java/com/enqualcomm/support/utils/Util.java index 41a8c4ce..2e32584c 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/Util.java +++ b/app/src/main/java/com/enqualcomm/support/utils/Util.java @@ -1,12 +1,9 @@ package com.enqualcomm.support.utils; -import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.media.AudioManager; import android.media.MediaPlayer; import android.net.ConnectivityManager; @@ -21,14 +18,18 @@ import android.os.PowerManager; import android.provider.Settings; import android.widget.Toast; +import com.enqualcomm.support.Config; +import com.enqualcomm.support.CoreService; +import com.enqualcomm.support.bean.Runtime; +import com.enqualcomm.support.bean.VoiceContent; +import com.enqualcomm.support.bean.voicePacket; +import com.enqualcomm.support.service.Deliver; +import com.ic.protocols.protocolAPIHelper; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; -import java.io.ByteArrayOutputStream; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -52,15 +53,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; - -import com.enqualcomm.support.Config; -import com.enqualcomm.support.CoreService; -import com.enqualcomm.support.bean.Runtime; -import com.enqualcomm.support.bean.VoiceContent; -import com.enqualcomm.support.bean.voicePacket; -import com.enqualcomm.support.service.Deliver; -import com.ic.protocols.protocolAPIHelper; - import static android.content.Context.CONNECTIVITY_SERVICE; import static android.content.Context.WIFI_SERVICE; import static chestnut.utils.FileUtils.closeIO; @@ -69,774 +61,789 @@ import static chestnut.utils.FileUtils.createOrExistsFile; import static chestnut.utils.StringUtils.isSpace; public class Util { - public static Charset UTF_16 = Charset.forName("UTF-16LE"); - - public static Charset UTF_8 = Charset.forName("UTF-8"); - - private static String FT6236U_upgrade_dev="/sys/devices/platform/soc/soc:ap-apb/70800000.i2c/i2c-3/3-0038/ftsfwupdate"; - private static String FT6236U_getver_dev="/sys/devices/platform/soc/soc:ap-apb/70800000.i2c/i2c-3/3-0038/ftstpfwver"; - - public static void mSleep(int ms){ - try { - Thread.yield(); - Thread.sleep(ms); - }catch ( Exception e){ - ICLogger.e(e.getMessage(),e); + public static Charset UTF_16 = Charset.forName("UTF-16LE"); + + public static Charset UTF_8 = Charset.forName("UTF-8"); + + private static String FT6236U_upgrade_dev = "/sys/devices/platform/soc/soc:ap-apb/70800000.i2c/i2c-3/3-0038/ftsfwupdate"; + private static String FT6236U_getver_dev = "/sys/devices/platform/soc/soc:ap-apb/70800000.i2c/i2c-3/3-0038/ftstpfwver"; + + public static void mSleep(int ms) { + try { + Thread.yield(); + Thread.sleep(ms); + } catch (Exception e) { + ICLogger.e(e.getMessage(), e); + } } - } - public static void SetRingMode(Context context,int mod,boolean vibmod){ - AudioManager am= (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); - int currentRingmod=am.getRingerMode(); - am.setRingerMode(mod); - ICLogger.i("Current OldRingMod="+currentRingmod+", Set To RingMod="+mod+", check RingMod="+am.getRingerMode()); - - int curretnVibmod=am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER); - - if(vibmod){ - Settings.System.putInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING,1); - am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON); - am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON); - } else { - Settings.System.putInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING,0); - am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF); - am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF); + + public static void SetRingMode(Context context, int mod, boolean vibmod) { + AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + int currentRingmod = am.getRingerMode(); + am.setRingerMode(mod); + ICLogger.i("Current OldRingMod=" + currentRingmod + ", Set To RingMod=" + mod + ", check RingMod=" + am.getRingerMode()); + + int curretnVibmod = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER); + + if (vibmod) { + Settings.System.putInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 1); + am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON); + am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON); + } else { + Settings.System.putInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 0); + am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF); + am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF); + } + ICLogger.i("Current OldVibRingMod=" + curretnVibmod + ", check VibRingMod=" + am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER) + " , shoudl Vib " + am.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)); + } - ICLogger.i("Current OldVibRingMod="+curretnVibmod+", check VibRingMod="+am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER)+" , shoudl Vib "+am.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)); - - } - public static void checkMesageNeedNotifi(String msg,Runtime runtime){ - - if(msg!=null ) { - //msg 格式 index,20201111182000,003f99302994 - String list[]= msg.split(","); - if(list.length==3) { - String index=list[0]; - String datetime=list[1]; - String txtmsg=list[2]; - - long lasttime_inms=System.currentTimeMillis()-TimeUtil.parseDatetiime(datetime).getTime(); - ICLogger.i("有消息"+lasttime_inms/1000 +"秒未读!"); - if ((lasttime_inms>8*60*1000 && lasttime_inms<=13*60*1000) //在10分钟,20分钟时都提醒一次。 - ||(lasttime_inms>18*60*1000 && lasttime_inms<=23*60*1000)) - { - - if (!Config.custom_name.equals("VitracK") ){ - if(Config.protocol_no==Config.PROTOCOL_JIAI){ - txtmsg=Util.decodeUnicode2Utf8(txtmsg); - }else { - txtmsg = Util.UrlGB2312ToUTF8(txtmsg); - } - } - if(Config.custom_name.equals("YQ") || Config.custom_name.equals("YQ_EN")) - { - runtime.setAlarmType(Runtime.AlarmType.ALARM_UNREADMSG); - // Config.setLastUnReadMessage(CoreService.getInstance(),""); - Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); - } - runtime.getContextProxy().sendMsgBroadcast(txtmsg, 3); //msgType 3需要回复,0不需要回复 + public static void checkMesageNeedNotifi(String msg, Runtime runtime) { - //runtime.getContextProxy().sendMsgBroadcast(txtmsg, 0); //msgType 3需要回复,0不需要回复 + if (msg != null) { + //msg 格式 index,20201111182000,003f99302994 + String list[] = msg.split(","); + if (list.length == 3) { + String index = list[0]; + String datetime = list[1]; + String txtmsg = list[2]; + long lasttime_inms = System.currentTimeMillis() - TimeUtil.parseDatetiime(datetime).getTime(); + ICLogger.i("有消息" + lasttime_inms / 1000 + "秒未读!"); + if ((lasttime_inms > 8 * 60 * 1000 && lasttime_inms <= 13 * 60 * 1000) //在10分钟,20分钟时都提醒一次。 + || (lasttime_inms > 18 * 60 * 1000 && lasttime_inms <= 23 * 60 * 1000)) { - } + if (!Config.custom_name.equals("VitracK")) { + if (Config.protocol_no == Config.PROTOCOL_JIAI) { + txtmsg = Util.decodeUnicode2Utf8(txtmsg); + } else { + txtmsg = Util.UrlGB2312ToUTF8(txtmsg); + } + } + if (Config.custom_name.equals("YQ") || Config.custom_name.equals("YQ_EN")) { + runtime.setAlarmType(Runtime.AlarmType.ALARM_UNREADMSG); + // Config.setLastUnReadMessage(CoreService.getInstance(),""); + Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); + } + runtime.getContextProxy().sendMsgBroadcast(txtmsg, 3); //msgType 3需要回复,0不需要回复 - }else{ - ICLogger.i("UnreadMsg format error !"); - } + //runtime.getContextProxy().sendMsgBroadcast(txtmsg, 0); //msgType 3需要回复,0不需要回复 + + + } + + + } else { + ICLogger.i("UnreadMsg format error !"); + } + } } - } - - public static boolean installed(Context context,String appPackageName) { - PackageManager packageManager = context.getPackageManager();// 获取packagemanager - List pinfo = packageManager.getInstalledPackages(0);// 获取所有已安装程序的包信息 - for (PackageInfo pkif : pinfo) { - String pn = pkif.packageName; - if (appPackageName.equals(pn)) { - return true; - } + + public static boolean installed(Context context, String appPackageName) { + PackageManager packageManager = context.getPackageManager();// 获取packagemanager + List pinfo = packageManager.getInstalledPackages(0);// 获取所有已安装程序的包信息 + for (PackageInfo pkif : pinfo) { + String pn = pkif.packageName; + if (appPackageName.equals(pn)) { + return true; + } + } + return false; } - return false; - } - public static boolean is_FT6236U_upgrade_firmware_support(){ - boolean ret=getSystemProperties("product.tp.upgradeable").toLowerCase().equals("true"); - return ret; - } - - public static boolean FT6236U_upgrade_firmware(){ - boolean ret=true; - try { - File nod=new File(FT6236U_upgrade_dev); - ICLogger.i("can upgrade ? "+nod.exists()+" "+nod.canWrite()+"\n"); - FileOutputStream fos=new FileOutputStream(nod); - fos.write(new byte[]{'1'}); - fos.close(); - } catch (Exception e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - ret=false; + + public static boolean is_FT6236U_upgrade_firmware_support() { + boolean ret = getSystemProperties("product.tp.upgradeable").toLowerCase().equals("true"); + return ret; } - return ret; - } - - public static String FT6236U_getVer(){ - String ret="not found"; - try { - File nod=new File(FT6236U_getver_dev); - FileInputStream fis=new FileInputStream(nod); - byte buf[]=new byte[20]; - int bytes_readed=fis.read(buf,0,buf.length); - fis.close(); - char charArray[]=new char[20]; - for (int i=0;i 0) { - String[] ipAddressArr = new String[inetAddressArr.length]; - - for (int i = 0; i < inetAddressArr.length; i++) { - String ip=inetAddressArr[i].getHostAddress(); - serverip.append( ip); - ipAddressArr[i]=ip; + public static String FT6236U_getVer() { + String ret = "not found"; + try { + File nod = new File(FT6236U_getver_dev); + FileInputStream fis = new FileInputStream(nod); + byte buf[] = new byte[20]; + int bytes_readed = fis.read(buf, 0, buf.length); + fis.close(); + char charArray[] = new char[20]; + for (int i = 0; i < bytes_readed; i++) { + charArray[i] = (char) buf[i]; + } + ret = String.valueOf(charArray, 0, bytes_readed); + } catch (Exception e) { + ICLogger.e(e.getMessage(), e); + e.printStackTrace(); } - } - } catch (Exception e) { + + return ret; + } + + /** + * 解析域名获取IP数组 + * + * @param host + * @return + */ + public static String parseHostGetIPAddress(String host) { + StringBuilder serverip = new StringBuilder(""); + try { + + + InetAddress[] inetAddressArr = InetAddress.getAllByName(host); + if (inetAddressArr != null && inetAddressArr.length > 0) { + String[] ipAddressArr = new String[inetAddressArr.length]; + + for (int i = 0; i < inetAddressArr.length; i++) { + String ip = inetAddressArr[i].getHostAddress(); + serverip.append(ip); + ipAddressArr[i] = ip; + } + } + } catch (Exception e) { // e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - ICLogger.i("GetHostIpByName Failed " + host); - return null; + ICLogger.e(e.getMessage(), e); + ICLogger.i("GetHostIpByName Failed " + host); + return null; + } + return serverip.toString(); } - return serverip.toString(); - } - /** - * - * 此函数专门给L02 协议使用 ,解析名字用 - * @param unicodestr - * @return - */ - public static String decodeUnicode2Utf8(String unicodestr) { - int len = unicodestr.length(); - //由于协议中Unicode 都是不带\\u 字头的,和网络中常见的不同,直接4个字节代表一个unicode字。 - //如果不是4的整倍数,则证明字符串格式有误,取消转换 - if (len%4==0) { - //先给每个unicode字符都加上\\u字头,然后再进行转换。 - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < len; i += 4) { - sb.append("\\u").append(unicodestr.substring(i, i + 4)); - } - try { - return decodeUnicode2Utf8Common(sb.toString()); - }catch (Exception e){ - ICLogger.e(e.getMessage(),e); - return ""; - } - }else{ - return ""; + + /** + * 此函数专门给L02 协议使用 ,解析名字用 + * + * @param unicodestr + * @return + */ + public static String decodeUnicode2Utf8(String unicodestr) { + int len = unicodestr.length(); + //由于协议中Unicode 都是不带\\u 字头的,和网络中常见的不同,直接4个字节代表一个unicode字。 + //如果不是4的整倍数,则证明字符串格式有误,取消转换 + if (len % 4 == 0) { + //先给每个unicode字符都加上\\u字头,然后再进行转换。 + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < len; i += 4) { + sb.append("\\u").append(unicodestr.substring(i, i + 4)); + } + try { + return decodeUnicode2Utf8Common(sb.toString()); + } catch (Exception e) { + ICLogger.e(e.getMessage(), e); + return ""; + } + } else { + return ""; + } + } - } - - public static String decodeUnicode2Utf8Common(String unicodestr) { - char aChar; - int len = unicodestr.length(); - StringBuffer outBuffer = new StringBuffer(len); - for (int x = 0; x < len; ) { - aChar = unicodestr.charAt(x++); - if (aChar == '\\') { - aChar = unicodestr.charAt(x++); - if (aChar == 'u') { - // Read the xxxx - int value = 0; - for (int i = 0; i < 4; i++) { - aChar = unicodestr.charAt(x++); - switch (aChar) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - value = (value << 4) + aChar - '0'; - break; - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - value = (value << 4) + 10 + aChar - 'a'; - break; - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - value = (value << 4) + 10 + aChar - 'A'; - break; - default: - throw new IllegalArgumentException( - "Malformed \\uxxxx encoding."); - } + public static String decodeUnicode2Utf8Common(String unicodestr) { + char aChar; + int len = unicodestr.length(); + StringBuffer outBuffer = new StringBuffer(len); + for (int x = 0; x < len; ) { + aChar = unicodestr.charAt(x++); + if (aChar == '\\') { + aChar = unicodestr.charAt(x++); + if (aChar == 'u') { + // Read the xxxx + int value = 0; + for (int i = 0; i < 4; i++) { + aChar = unicodestr.charAt(x++); + switch (aChar) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + value = (value << 4) + aChar - '0'; + break; + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + value = (value << 4) + 10 + aChar - 'a'; + break; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + value = (value << 4) + 10 + aChar - 'A'; + break; + default: + throw new IllegalArgumentException( + "Malformed \\uxxxx encoding."); + } + + } + outBuffer.append((char) value); + } else { + if (aChar == 't') + aChar = '\t'; + else if (aChar == 'r') + aChar = '\r'; + else if (aChar == 'n') + aChar = '\n'; + else if (aChar == 'f') + aChar = '\f'; + outBuffer.append(aChar); + } + } else + outBuffer.append(aChar); + } + return outBuffer.toString(); + - } - outBuffer.append((char) value); - } else { - if (aChar == 't') - aChar = '\t'; - else if (aChar == 'r') - aChar = '\r'; - else if (aChar == 'n') - aChar = '\n'; - else if (aChar == 'f') - aChar = '\f'; - outBuffer.append(aChar); - } - } else - outBuffer.append(aChar); - } - return outBuffer.toString(); - - - } - public static String getSystemProperties(String prop){ - - String str =""; - Class clazz = null; - try { - clazz = Class.forName("android.os.SystemProperties"); - Method get=clazz.getMethod("get", new Class[] { String.class }); - str = (String)get.invoke(clazz, new Object[] { prop }); - } catch (Exception e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); } - return str; - } - public static String getSystemProperties(String prop,String defaultValue){ - - String str =defaultValue; - Class clazz = null; - try { - clazz = Class.forName("android.os.SystemProperties"); - Method get=clazz.getMethod("get", new Class[] { String.class }); - str = (String)get.invoke(clazz, new Object[] { prop }); - if(str==null || (str!=null && str.trim().isEmpty())){ - str=defaultValue; - } - } catch (Exception e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); + + public static String getSystemProperties(String prop) { + + String str = ""; + Class clazz = null; + try { + clazz = Class.forName("android.os.SystemProperties"); + Method get = clazz.getMethod("get", new Class[]{String.class}); + str = (String) get.invoke(clazz, new Object[]{prop}); + } catch (Exception e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + } + return str; } - return str; - } - public static int getSystemPropertiesInt(String prop,int defaultValue){ - - int ret=defaultValue; - String str =""; - Class clazz = null; - try { - clazz = Class.forName("android.os.SystemProperties"); - Method get=clazz.getMethod("get", new Class[] { String.class }); - str = (String)get.invoke(clazz, new Object[] { prop }); - if (str!=null && str.trim().length()>0 && isNumeric(str)){ - ret=Integer.parseInt(str); - } - } catch (Exception e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); + + public static String getSystemProperties(String prop, String defaultValue) { + + String str = defaultValue; + Class clazz = null; + try { + clazz = Class.forName("android.os.SystemProperties"); + Method get = clazz.getMethod("get", new Class[]{String.class}); + str = (String) get.invoke(clazz, new Object[]{prop}); + if (str == null || (str != null && str.trim().isEmpty())) { + str = defaultValue; + } + } catch (Exception e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + } + return str; } - return ret; - } - - public static boolean isNumeric(String str){ - Pattern pattern = Pattern.compile("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$"); - Matcher isNum = pattern.matcher(str); - if( !isNum.matches() ){ - return false; + + public static int getSystemPropertiesInt(String prop, int defaultValue) { + + int ret = defaultValue; + String str = ""; + Class clazz = null; + try { + clazz = Class.forName("android.os.SystemProperties"); + Method get = clazz.getMethod("get", new Class[]{String.class}); + str = (String) get.invoke(clazz, new Object[]{prop}); + if (str != null && str.trim().length() > 0 && isNumeric(str)) { + ret = Integer.parseInt(str); + } + } catch (Exception e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + } + return ret; } - return true; - } - static public void setSystemProperties(String key, int defaultValue) { - String value = String.valueOf(defaultValue); + public static boolean isNumeric(String str) { + Pattern pattern = Pattern.compile("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$"); + Matcher isNum = pattern.matcher(str); + if (!isNum.matches()) { + return false; + } + return true; + } + + static public void setSystemProperties(String key, int defaultValue) { - try { + String value = String.valueOf(defaultValue); + + try { - Class c = Class.forName("android.os.SystemProperties"); + Class c = Class.forName("android.os.SystemProperties"); - Method set = c.getMethod("set", String.class, String.class ); + Method set = c.getMethod("set", String.class, String.class); - set.invoke(c, key, value ); + set.invoke(c, key, value); - } catch (Exception e) { + } catch (Exception e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + } } - } - static public void setSystemProperties(String key, String defaultValue) { - String value = defaultValue; + static public void setSystemProperties(String key, String defaultValue) { - try { + String value = defaultValue; - Class c = Class.forName("android.os.SystemProperties"); + try { - Method set = c.getMethod("set", String.class, String.class ); + Class c = Class.forName("android.os.SystemProperties"); - set.invoke(c, key, value ); + Method set = c.getMethod("set", String.class, String.class); - } catch (Exception e) { + set.invoke(c, key, value); - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); + } catch (Exception e) { + + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + } } - } - public static WifiConfiguration GetconfigWifiInfo(Context context, String ssid, String pwd, String encryptType) { - WifiConfiguration wifiConfiguration=null; - StringBuilder stringBuilder; - WifiManager wifiManager = (WifiManager)context.getSystemService(WIFI_SERVICE); - if (wifiManager != null && wifiManager.getConfiguredNetworks()!=null) { - Iterator it = wifiManager.getConfiguredNetworks().iterator(); - - while(it.hasNext()) { - wifiConfiguration = (WifiConfiguration)it.next(); - if (wifiConfiguration != null) { - String ssid_tmp = wifiConfiguration.SSID; - stringBuilder= new StringBuilder(); - stringBuilder.append("\""); - stringBuilder.append(ssid); - stringBuilder.append("\""); - if (ssid_tmp.equals(stringBuilder.toString())) { - return wifiConfiguration; + + public static WifiConfiguration GetconfigWifiInfo(Context context, String ssid, String pwd, String encryptType) { + WifiConfiguration wifiConfiguration = null; + StringBuilder stringBuilder; + WifiManager wifiManager = (WifiManager) context.getSystemService(WIFI_SERVICE); + if (wifiManager != null && wifiManager.getConfiguredNetworks() != null) { + Iterator it = wifiManager.getConfiguredNetworks().iterator(); + + while (it.hasNext()) { + wifiConfiguration = (WifiConfiguration) it.next(); + if (wifiConfiguration != null) { + String ssid_tmp = wifiConfiguration.SSID; + stringBuilder = new StringBuilder(); + stringBuilder.append("\""); + stringBuilder.append(ssid); + stringBuilder.append("\""); + if (ssid_tmp.equals(stringBuilder.toString())) { + return wifiConfiguration; + } + } } - } } - } + WifiConfiguration retWiFiConfigration = wifiConfiguration; + if (retWiFiConfigration == null) { + retWiFiConfigration = new WifiConfiguration(); + } - WifiConfiguration retWiFiConfigration = wifiConfiguration; - if (retWiFiConfigration == null) { - retWiFiConfigration = new WifiConfiguration(); + retWiFiConfigration.allowedAuthAlgorithms.clear(); + retWiFiConfigration.allowedGroupCiphers.clear(); + retWiFiConfigration.allowedKeyManagement.clear(); + retWiFiConfigration.allowedPairwiseCiphers.clear(); + retWiFiConfigration.allowedProtocols.clear(); + stringBuilder = new StringBuilder(); + stringBuilder.append("\""); + stringBuilder.append(ssid); + stringBuilder.append("\""); + retWiFiConfigration.SSID = stringBuilder.toString(); + if ("none".equals(encryptType)) { + retWiFiConfigration.allowedKeyManagement.set(0); + } else if ("wep".equals(encryptType)) { + retWiFiConfigration.hiddenSSID = true; + stringBuilder = new StringBuilder(); + stringBuilder.append("\""); + stringBuilder.append(pwd); + stringBuilder.append("\""); + retWiFiConfigration.wepKeys[0] = stringBuilder.toString(); + retWiFiConfigration.allowedAuthAlgorithms.set(1); + retWiFiConfigration.allowedGroupCiphers.set(3); + retWiFiConfigration.allowedGroupCiphers.set(2); + retWiFiConfigration.allowedGroupCiphers.set(0); + retWiFiConfigration.allowedGroupCiphers.set(1); + retWiFiConfigration.allowedKeyManagement.set(0); + retWiFiConfigration.wepTxKeyIndex = 0; + } else if ("psk".equals(encryptType)) { + stringBuilder = new StringBuilder(); + stringBuilder.append("\""); + stringBuilder.append(pwd); + stringBuilder.append("\""); + retWiFiConfigration.preSharedKey = stringBuilder.toString(); + retWiFiConfigration.hiddenSSID = true; + retWiFiConfigration.allowedAuthAlgorithms.set(0); + retWiFiConfigration.allowedGroupCiphers.set(2); + retWiFiConfigration.allowedKeyManagement.set(1); + retWiFiConfigration.allowedPairwiseCiphers.set(1); + retWiFiConfigration.allowedGroupCiphers.set(3); + retWiFiConfigration.allowedPairwiseCiphers.set(2); + retWiFiConfigration.status = 2; + } + + return retWiFiConfigration; } - retWiFiConfigration.allowedAuthAlgorithms.clear(); - retWiFiConfigration.allowedGroupCiphers.clear(); - retWiFiConfigration.allowedKeyManagement.clear(); - retWiFiConfigration.allowedPairwiseCiphers.clear(); - retWiFiConfigration.allowedProtocols.clear(); - stringBuilder = new StringBuilder(); - stringBuilder.append("\""); - stringBuilder.append(ssid); - stringBuilder.append("\""); - retWiFiConfigration.SSID = stringBuilder.toString(); - if ("none".equals(encryptType)) { - retWiFiConfigration.allowedKeyManagement.set(0); - } else if ("wep".equals(encryptType)) { - retWiFiConfigration.hiddenSSID = true; - stringBuilder = new StringBuilder(); - stringBuilder.append("\""); - stringBuilder.append(pwd); - stringBuilder.append("\""); - retWiFiConfigration.wepKeys[0] = stringBuilder.toString(); - retWiFiConfigration.allowedAuthAlgorithms.set(1); - retWiFiConfigration.allowedGroupCiphers.set(3); - retWiFiConfigration.allowedGroupCiphers.set(2); - retWiFiConfigration.allowedGroupCiphers.set(0); - retWiFiConfigration.allowedGroupCiphers.set(1); - retWiFiConfigration.allowedKeyManagement.set(0); - retWiFiConfigration.wepTxKeyIndex = 0; - } else if ("psk".equals(encryptType)) { - stringBuilder = new StringBuilder(); - stringBuilder.append("\""); - stringBuilder.append(pwd); - stringBuilder.append("\""); - retWiFiConfigration.preSharedKey = stringBuilder.toString(); - retWiFiConfigration.hiddenSSID = true; - retWiFiConfigration.allowedAuthAlgorithms.set(0); - retWiFiConfigration.allowedGroupCiphers.set(2); - retWiFiConfigration.allowedKeyManagement.set(1); - retWiFiConfigration.allowedPairwiseCiphers.set(1); - retWiFiConfigration.allowedGroupCiphers.set(3); - retWiFiConfigration.allowedPairwiseCiphers.set(2); - retWiFiConfigration.status = 2; + public static String byte2hex(byte[] var0) { + if (var0 == null) { + throw new IllegalArgumentException("Argument b ( byte array ) is null! "); + } else { + String var1 = ""; + + for (int var2 = 0; var2 < var0.length; ++var2) { + String var3 = Integer.toHexString(var0[var2] & 255); + StringBuilder var4; + if (var3.length() == 1) { + var4 = new StringBuilder(); + var4.append(var1); + var4.append("0"); + var4.append(var3); + var1 = var4.toString(); + } else { + var4 = new StringBuilder(); + var4.append(var1); + var4.append(var3); + var1 = var4.toString(); + } + } + + return var1.toUpperCase(); + } } - return retWiFiConfigration; - } - - public static String byte2hex(byte[] var0) { - if (var0 == null) { - throw new IllegalArgumentException("Argument b ( byte array ) is null! "); - } else { - String var1 = ""; - - for(int var2 = 0; var2 < var0.length; ++var2) { - String var3 = Integer.toHexString(var0[var2] & 255); - StringBuilder var4; - if (var3.length() == 1) { - var4 = new StringBuilder(); - var4.append(var1); - var4.append("0"); - var4.append(var3); - var1 = var4.toString(); + public static boolean checkNetwork(Context var0) { + NetworkInfo var2 = ((ConnectivityManager) var0.getSystemService(CONNECTIVITY_SERVICE)).getActiveNetworkInfo(); + boolean var1; + if (var2 != null && var2.isConnected()) { + var1 = true; } else { - var4 = new StringBuilder(); - var4.append(var1); - var4.append(var3); - var1 = var4.toString(); + var1 = false; } - } - return var1.toUpperCase(); - } - } - - public static boolean checkNetwork(Context var0) { - NetworkInfo var2 = ((ConnectivityManager)var0.getSystemService(CONNECTIVITY_SERVICE)).getActiveNetworkInfo(); - boolean var1; - if (var2 != null && var2.isConnected()) { - var1 = true; - } else { - var1 = false; + return var1; } - return var1; - } - - public static Method connectWifiByReflectMethod(Context var0, int var1) { - WifiManager var2 = (WifiManager)var0.getSystemService(WIFI_SERVICE); - Method[] var3; - int var4; - int var5; - Method var6; - Method var7; - Class[] var8; - Method var11; - StringBuilder var12; - - ICLogger.i("connectWifiByReflectMethod road 1"); - var3 = var2.getClass().getDeclaredMethods(); - var4 = var3.length; - var11 = null; - - for(var5 = 0; var5 < var4; var11 = var7) { - var6 = var3[var5]; - var7 = var11; - if ("connect".equalsIgnoreCase(var6.getName())) { - var8 = var6.getParameterTypes(); - var7 = var11; - if (var8 != null) { + public static Method connectWifiByReflectMethod(Context var0, int var1) { + WifiManager var2 = (WifiManager) var0.getSystemService(WIFI_SERVICE); + Method[] var3; + int var4; + int var5; + Method var6; + Method var7; + Class[] var8; + Method var11; + StringBuilder var12; + + ICLogger.i("connectWifiByReflectMethod road 1"); + var3 = var2.getClass().getDeclaredMethods(); + var4 = var3.length; + var11 = null; + + for (var5 = 0; var5 < var4; var11 = var7) { + var6 = var3[var5]; var7 = var11; - if (var8.length > 0) { - var7 = var11; - if ("int".equalsIgnoreCase(var8[0].getName())) { - var7 = var6; - } + if ("connect".equalsIgnoreCase(var6.getName())) { + var8 = var6.getParameterTypes(); + var7 = var11; + if (var8 != null) { + var7 = var11; + if (var8.length > 0) { + var7 = var11; + if ("int".equalsIgnoreCase(var8[0].getName())) { + var7 = var6; + } + } + } } - } - } - - ++var5; - } - var7 = var11; - if (var11 != null) { - try { - var11.invoke(var2, var1, null); - } catch (Exception e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - var12 = new StringBuilder(); - var12.append("connectWifiByReflectMethod Android "); - var12.append(Build.VERSION.SDK_INT); - var12.append(" error!"); - ICLogger.i(var12.toString()); - return null; + ++var5; } var7 = var11; - } - - return var7; - } - - - - - public static int getDuration(String amrfilePath) { - if (amrfilePath != null) { - double d1; - MediaPlayer mediaPlayer = new MediaPlayer(); - try { - mediaPlayer.setDataSource(amrfilePath); - mediaPlayer.prepare(); - int i = mediaPlayer.getDuration(); - d1 = i; - mediaPlayer.release(); - } catch (Exception e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - mediaPlayer.release(); - d1 = 1000.0D; - } finally {} - return (int)Math.ceil(d1 / 1000.0D); - } - double d = 1000.0D; - return 0; - } - - public static boolean LogfileExist(Runtime runtime,String logfilename){ - return new File(getLogfilePath(runtime,logfilename)).exists(); - } - public static String getRecordfilePath(Runtime runtime,String recordfilename){ - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(recordfilename); - stringBuilder.append(".amr"); - File file = new File(runtime.getCacheDir(), stringBuilder.toString()); - return file.getAbsolutePath(); - } - - public static String getLogfilePath(Runtime runtime,String logfilename){ - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(logfilename); - stringBuilder.append(".txt"); - File file = new File(runtime.getCacheDir(), stringBuilder.toString()); - return file.getAbsolutePath(); - } - - public static void getDBFile() { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(StorageUtils.getExternalStorageLogDir()); - stringBuilder.append("/contacts.db"); - FileOutputUtil.copyFolder("/data/data/com.enqualcomm.support/databases", stringBuilder.toString()); - } - private static int BUFFER_LEN=1024; - /** - * 压缩文件 - * @param srcFile 待压缩的源文件 - * @param rootPath 源文件的根路径 - * @param zos Zip输出流 - * @param comment 备注 - * @return 压缩成功返回true - * @throws IOException - */ - public static boolean zipFile(final File srcFile, String rootPath ,final ZipOutputStream zos ,final String comment) throws IOException { - rootPath = rootPath + (isSpace(rootPath) ? "" : File.separator) + srcFile.getName(); - - if (srcFile.isDirectory()) { - File[] fileList = srcFile.listFiles(); - if (fileList == null || fileList.length <= 0) { - ZipEntry entry = new ZipEntry(rootPath + '/'); - entry.setComment(comment); - zos.putNextEntry(entry); - zos.closeEntry(); - } else { - for (File file : fileList) { - if (!zipFile(file, rootPath, zos, comment)) return false; - } - } - } else { - InputStream is = null; - try { - is = new BufferedInputStream(new FileInputStream(srcFile)); - ZipEntry entry = new ZipEntry(rootPath); - entry.setComment(comment); - zos.putNextEntry(entry); - byte buffer[] = new byte[BUFFER_LEN]; - int len; - while ((len = is.read(buffer, 0, BUFFER_LEN)) != -1) { - zos.write(buffer, 0, len); + if (var11 != null) { + try { + var11.invoke(var2, var1, null); + } catch (Exception e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + var12 = new StringBuilder(); + var12.append("connectWifiByReflectMethod Android "); + var12.append(Build.VERSION.SDK_INT); + var12.append(" error!"); + ICLogger.i(var12.toString()); + return null; + } + + var7 = var11; } - zos.closeEntry(); - } finally { - if(is!=null) - closeIO(is); - is=null; - } + + return var7; } - return true; - } - /** - * Unzip the file by keyword. - * - * @param zipFile The ZIP file. - * @param destDir The destination directory. - * @param keyword The keyboard. - * @return the unzipped files - * @throws IOException if unzip unsuccessfully - */ - public static List unzipFileByKeyword(final File zipFile,final File destDir,final String keyword) throws IOException { - if (zipFile == null || destDir == null) return null; - List files = new ArrayList<>(); - ZipFile zip = new ZipFile(zipFile); - Enumeration entries = zip.entries(); - try { - if (isSpace(keyword)) { - while (entries.hasMoreElements()) { - ZipEntry entry = ((ZipEntry) entries.nextElement()); - String entryName = entry.getName(); - if (entryName.contains("../")) { - ICLogger.log("ZipUtils", "it's dangerous!");//防止被利用漏洞恶意修改文件 - return files; - } - if (!unzipChildFile(destDir, files, zip, entry)) return files; + + + public static int getDuration(String amrfilePath) { + if (amrfilePath != null) { + double d1; + MediaPlayer mediaPlayer = new MediaPlayer(); + try { + mediaPlayer.setDataSource(amrfilePath); + mediaPlayer.prepare(); + int i = mediaPlayer.getDuration(); + d1 = i; + mediaPlayer.release(); + } catch (Exception e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + mediaPlayer.release(); + d1 = 1000.0D; + } finally { + } + return (int) Math.ceil(d1 / 1000.0D); } - } else { - while (entries.hasMoreElements()) { - ZipEntry entry = ((ZipEntry) entries.nextElement()); - String entryName = entry.getName(); - if (entryName.contains("../")) { - ICLogger.log("ZipUtils", "it's dangerous!"); - return files; - } - if (entryName.contains(keyword)) { - if (!unzipChildFile(destDir, files, zip, entry)) return files; - } + double d = 1000.0D; + return 0; + } + + public static boolean LogfileExist(Runtime runtime, String logfilename) { + return new File(getLogfilePath(runtime, logfilename)).exists(); + } + + public static String getRecordfilePath(Runtime runtime, String recordfilename) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(recordfilename); + stringBuilder.append(".amr"); + File file = new File(runtime.getCacheDir(), stringBuilder.toString()); + return file.getAbsolutePath(); + } + + public static String getLogfilePath(Runtime runtime, String logfilename) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(logfilename); + stringBuilder.append(".txt"); + File file = new File(runtime.getCacheDir(), stringBuilder.toString()); + return file.getAbsolutePath(); + } + + public static void getDBFile() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(StorageUtils.getExternalStorageLogDir()); + stringBuilder.append("/contacts.db"); + FileOutputUtil.copyFolder("/data/data/com.enqualcomm.support/databases", stringBuilder.toString()); + } + + private static int BUFFER_LEN = 1024; + + /** + * 压缩文件 + * + * @param srcFile 待压缩的源文件 + * @param rootPath 源文件的根路径 + * @param zos Zip输出流 + * @param comment 备注 + * @return 压缩成功返回true + * @throws IOException + */ + public static boolean zipFile(final File srcFile, String rootPath, final ZipOutputStream zos, final String comment) throws IOException { + rootPath = rootPath + (isSpace(rootPath) ? "" : File.separator) + srcFile.getName(); + + if (srcFile.isDirectory()) { + File[] fileList = srcFile.listFiles(); + if (fileList == null || fileList.length <= 0) { + ZipEntry entry = new ZipEntry(rootPath + '/'); + entry.setComment(comment); + zos.putNextEntry(entry); + zos.closeEntry(); + } else { + for (File file : fileList) { + if (!zipFile(file, rootPath, zos, comment)) return false; + } + } + } else { + InputStream is = null; + try { + is = new BufferedInputStream(new FileInputStream(srcFile)); + ZipEntry entry = new ZipEntry(rootPath); + entry.setComment(comment); + zos.putNextEntry(entry); + byte buffer[] = new byte[BUFFER_LEN]; + int len; + while ((len = is.read(buffer, 0, BUFFER_LEN)) != -1) { + zos.write(buffer, 0, len); + } + zos.closeEntry(); + } finally { + if (is != null) + closeIO(is); + is = null; + } } - } - } finally { - zip.close(); + return true; } - return files; - } - - /*** - * - * @param filename 输入SD卡中的文件或者目录的 相对路径 - * @return 压缩有的文件 - */ - public static String zipfiles(String filename){ - String zipfile=filename; - - try { - String sdcard= Environment.getExternalStorageDirectory().getAbsolutePath(); - File srcfile=new File(sdcard+"/"+filename); - zipfile=sdcard+File.separator+srcfile.getName()+".zip"; - if (Util.zipFile(srcfile, "", - new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile),new CRC32())) - , filename)) { - } - }catch (Exception e){ - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - zipfile=""; + + /** + * Unzip the file by keyword. + * + * @param zipFile The ZIP file. + * @param destDir The destination directory. + * @param keyword The keyboard. + * @return the unzipped files + * @throws IOException if unzip unsuccessfully + */ + public static List unzipFileByKeyword(final File zipFile, final File destDir, final String keyword) throws IOException { + if (zipFile == null || destDir == null) return null; + List files = new ArrayList<>(); + ZipFile zip = new ZipFile(zipFile); + Enumeration entries = zip.entries(); + try { + if (isSpace(keyword)) { + while (entries.hasMoreElements()) { + ZipEntry entry = ((ZipEntry) entries.nextElement()); + String entryName = entry.getName(); + if (entryName.contains("../")) { + ICLogger.log("ZipUtils", "it's dangerous!");//防止被利用漏洞恶意修改文件 + return files; + } + if (!unzipChildFile(destDir, files, zip, entry)) return files; + } + } else { + while (entries.hasMoreElements()) { + ZipEntry entry = ((ZipEntry) entries.nextElement()); + String entryName = entry.getName(); + if (entryName.contains("../")) { + ICLogger.log("ZipUtils", "it's dangerous!"); + return files; + } + if (entryName.contains(keyword)) { + if (!unzipChildFile(destDir, files, zip, entry)) return files; + } + } + } + } finally { + zip.close(); + } + return files; } - return zipfile; - } - - private static boolean unzipChildFile(final File destDir, final List files, final ZipFile zip, final ZipEntry entry) - throws IOException { - File file = new File(destDir, entry.getName()); - files.add(file); - if (entry.isDirectory()) { - return createOrExistsDir(file);//创建文件夹 - } else { - if (!createOrExistsFile(file)) return false; - InputStream in = null; - OutputStream out = null; - try { - in = new BufferedInputStream(zip.getInputStream(entry)); - out = new BufferedOutputStream(new FileOutputStream(file)); - byte buffer[] = new byte[BUFFER_LEN]; - int len; - while ((len = in.read(buffer)) != -1) { - out.write(buffer, 0, len); + /*** + * + * @param filename 输入SD卡中的文件或者目录的 相对路径 + * @return 压缩有的文件 + */ + public static String zipfiles(String filename) { + String zipfile = filename; + + try { + String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath(); + File srcfile = new File(sdcard + "/" + filename); + zipfile = sdcard + File.separator + srcfile.getName() + ".zip"; + if (Util.zipFile(srcfile, "", + new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile), new CRC32())) + , filename)) { + } + } catch (Exception e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + zipfile = ""; } - } finally { - if (in != null) { - in.close(); + + return zipfile; + } + + private static boolean unzipChildFile(final File destDir, final List files, final ZipFile zip, final ZipEntry entry) + throws IOException { + File file = new File(destDir, entry.getName()); + files.add(file); + if (entry.isDirectory()) { + return createOrExistsDir(file);//创建文件夹 + } else { + if (!createOrExistsFile(file)) return false; + InputStream in = null; + OutputStream out = null; + try { + in = new BufferedInputStream(zip.getInputStream(entry)); + out = new BufferedOutputStream(new FileOutputStream(file)); + byte buffer[] = new byte[BUFFER_LEN]; + int len; + while ((len = in.read(buffer)) != -1) { + out.write(buffer, 0, len); + } + } finally { + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } + } } - if (out != null) { - out.close(); + return true; + } + + public static String getServerLogfilePath(String serverhost, String timefolder, String logfilename, Runtime runtime) { + StringBuilder urlbuilder = new StringBuilder(); + String srvIP = serverhost; + if (SimSignalUtil.checkNet(runtime.getContextProxy().context)) { + srvIP = runtime.getDnsUtil().getServerIP_ByDNSCache("http://" + serverhost); + if (null == srvIP) { + srvIP = serverhost; + } } - } + urlbuilder.append("ftp://").append(srvIP).append("/") + .append("ftp/log/") + .append(DeviceInfoUtil.getModule()).append("/") + .append(DeviceInfoUtil.getSWVersionDisplayName()).append("/") + .append(CoreService.getInstance().getRuntime().IMEI()).append("/") + .append(timefolder); + + return urlbuilder.toString(); + } + + public static boolean isConnectWifi(Context paramContext) { + ConnectivityManager connectivityManager = (ConnectivityManager) paramContext.getSystemService(CONNECTIVITY_SERVICE); + NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); + NetworkInfo.State state = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); + return (networkInfo != null && networkInfo.isAvailable() && state == NetworkInfo.State.CONNECTED); + } + + public static boolean isWifiInIdle(Context paramContext) { + NetworkInfo.State state = ((ConnectivityManager) paramContext.getSystemService(CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("yls wifi="); + stringBuilder.append(state); + ICLogger.i(stringBuilder.toString()); + return (state == NetworkInfo.State.DISCONNECTED); + } + + public static boolean isWifiIsOpen(Context paramContext, Runtime paramRuntime) { + return paramRuntime.getContextProxy().getWifiManager().isWifiEnabled(); } - return true; - } - - public static String getServerLogfilePath(String serverhost,String timefolder,String logfilename ,Runtime runtime) { - StringBuilder urlbuilder=new StringBuilder(); - String srvIP=serverhost; - if (SimSignalUtil.checkNet(runtime.getContextProxy().context) ) { - srvIP=runtime.getDnsUtil().getServerIP_ByDNSCache("http://"+serverhost); - if (null == srvIP ) { - srvIP=serverhost; - } + + public static void ShowToast(Runtime runtime, String msg) { + new Thread(new Runnable() { + + @Override + public void run() { + Handler handler = new Handler(Looper.getMainLooper()); + handler.post(new Runnable() { + + @Override + public void run() { + Toast.makeText(runtime.getContextProxy().context, msg, Toast.LENGTH_LONG).show(); + } + }); + } + }).start(); } - urlbuilder.append("ftp://").append(srvIP).append("/") - .append("ftp/log/") - .append(DeviceInfoUtil.getModule()).append("/") - .append(DeviceInfoUtil.getSWVersionDisplayName()).append("/") - .append(CoreService.getInstance().getRuntime().IMEI()).append("/") - .append(timefolder); - - return urlbuilder.toString(); - } - public static boolean isConnectWifi(Context paramContext) { - ConnectivityManager connectivityManager = (ConnectivityManager)paramContext.getSystemService(CONNECTIVITY_SERVICE); - NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); - NetworkInfo.State state = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); - return (networkInfo != null && networkInfo.isAvailable() && state == NetworkInfo.State.CONNECTED); - } - - public static boolean isWifiInIdle(Context paramContext) { - NetworkInfo.State state = ((ConnectivityManager)paramContext.getSystemService(CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("yls wifi="); - stringBuilder.append(state); - ICLogger.i(stringBuilder.toString()); - return (state == NetworkInfo.State.DISCONNECTED); - } - - public static boolean isWifiIsOpen(Context paramContext, Runtime paramRuntime) { - return paramRuntime.getContextProxy().getWifiManager().isWifiEnabled(); - } - public static void ShowToast(Runtime runtime,String msg) { - new Thread(new Runnable() { - - @Override - public void run() { - Handler handler = new Handler(Looper.getMainLooper()); - handler.post(new Runnable() { - - @Override - public void run() { - Toast.makeText(runtime.getContextProxy().context, msg, Toast.LENGTH_LONG).show(); - } - }); - } - }).start(); - } - - public static byte[] loadFile(File paramFile) { + + public static byte[] loadFile(File paramFile) { // if (paramFile != null && paramFile.exists()) // try { // if (paramFile.getName().endsWith(".jpg")) { @@ -859,359 +866,453 @@ public class Util { // } catch (IOException paramFile) { // paramFile.printStackTrace(); // } - return null; - } - - public static File makeDir(File paramFile, String paramString) { - StringBuilder stringBuilder = new StringBuilder(Integer.toHexString(paramString.hashCode())); -// for (byte b = 2; b < stringBuilder.length(); b += 3) -// stringBuilder.insert(b, "/"); - paramFile = new File(paramFile, stringBuilder.toString()); - paramFile.mkdirs(); - return paramFile; - } - - public static String saveFile(byte[] buf, int start, int size, File dir, String filename) { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(UUID.randomUUID().toString()); - stringBuilder.append("_"); - stringBuilder.append(filename); - filename = stringBuilder.toString(); - File paramFile = makeDir(dir, filename); //建立以文件名Hash命名的路径 - try { - paramFile = new File(paramFile, filename);//在路径下再建立文件 - FileOutputStream fos=new FileOutputStream(paramFile); - fos.write(buf,start,size); - fos.close(); - return paramFile.getAbsolutePath(); - } catch (IOException e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); + return null; } - return null; - } - - public static ArrayList split(byte[] paramArrayOfByte, byte paramByte, int paramInt) { - ArrayList arrayList = new ArrayList(); - int m = paramArrayOfByte.length; - int k = paramInt; - int j = paramInt; - for (paramInt = k; j < m; paramInt = k) { - k = paramInt; - if (paramArrayOfByte[j] == paramByte) { - k = j - paramInt; - if (k != 0) { - byte[] arrayOfByte = new byte[k]; - System.arraycopy(paramArrayOfByte, paramInt, arrayOfByte, 0, k); - arrayList.add(arrayOfByte); - } - k = j + 1; - } - j++; - } - int i = m - paramInt; - if (i != 0) { - byte[] arrayOfByte = new byte[i]; - System.arraycopy(paramArrayOfByte, paramInt, arrayOfByte, 0, i); - arrayList.add(arrayOfByte); - } - return arrayList; - } - - public static ArrayList split(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2) { - ArrayList arrayList = new ArrayList(); - int k = paramArrayOfByte1.length; - int m = paramArrayOfByte2.length; - int i = 0; - int j; - int n; - for (j = 0; i < k; j = n) { - - int i1; - byte b = 0; - while (true) { - int bool = i + b; - i1 = i; - n = j; - if (bool < k) { - i1 = i; - n = j; - if (paramArrayOfByte1[bool] == paramArrayOfByte2[b]) { - b = (byte)(b + 1); - - if (n == m) { - n = i - j; - if (n != 0) { - byte[] arrayOfByte = new byte[n]; - System.arraycopy(paramArrayOfByte1, j, arrayOfByte, 0, n); - arrayList.add(arrayOfByte); - } - i += m; - n = i; - i1 = i - 1; - break; - } - continue; - } + + public static File makeDir(File paramFile, String paramString) { + StringBuilder stringBuilder = new StringBuilder(Integer.toHexString(paramString.hashCode())); + paramFile = new File(paramFile, stringBuilder.toString()); + paramFile.mkdirs(); + return paramFile; + } + + public static String saveFile(byte[] buf, int start, int size, File dir, String filename) { + + System.out.print("["); + for (byte b : buf) { + System.out.print(b + ","); } - break; - } - i = i1 + 1; + System.out.println("]"); + System.out.println("-----after------"); + + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(UUID.randomUUID().toString()); + stringBuilder.append("_"); + stringBuilder.append(filename); + filename = stringBuilder.toString(); + File paramFile = makeDir(dir, filename); //建立以文件名Hash命名的路径 + try { + paramFile = new File(paramFile, filename);//在路径下再建立文件 + FileOutputStream fos = new FileOutputStream(paramFile); + fos.write(buf, start, size); + fos.close(); + return paramFile.getAbsolutePath(); + } catch (IOException e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + } + return null; } - i = paramArrayOfByte1.length - j; - if (i != 0) { - paramArrayOfByte2 = new byte[i]; - System.arraycopy(paramArrayOfByte1, j, paramArrayOfByte2, 0, i); - arrayList.add(paramArrayOfByte2); + + public static ArrayList split(byte[] paramArrayOfByte, byte paramByte, int paramInt) { + ArrayList arrayList = new ArrayList(); + int m = paramArrayOfByte.length; + int k = paramInt; + int j = paramInt; + for (paramInt = k; j < m; paramInt = k) { + k = paramInt; + if (paramArrayOfByte[j] == paramByte) { + k = j - paramInt; + if (k != 0) { + byte[] arrayOfByte = new byte[k]; + System.arraycopy(paramArrayOfByte, paramInt, arrayOfByte, 0, k); + arrayList.add(arrayOfByte); + } + k = j + 1; + } + j++; + } + int i = m - paramInt; + if (i != 0) { + byte[] arrayOfByte = new byte[i]; + System.arraycopy(paramArrayOfByte, paramInt, arrayOfByte, 0, i); + arrayList.add(arrayOfByte); + } + return arrayList; } - return arrayList; - } - - public static byte[] subArray(byte[] paramArrayOfByte, int paramInt) { - return subArray(paramArrayOfByte, paramInt, paramArrayOfByte.length); - } - - public static byte[] subArray(byte[] paramArrayOfByte, int paramInt1, int paramInt2) { - paramInt2 -= paramInt1; - byte[] arrayOfByte = new byte[paramInt2]; - System.arraycopy(paramArrayOfByte, paramInt1, arrayOfByte, 0, paramInt2); - return arrayOfByte; - } - - public static void turnOffWifiForSleep(Context paramContext, Runtime paramRuntime) { - paramRuntime.getContextProxy().getWifiManager().setWifiEnabled(false); - } - - public static void turnOnWifiForConnect(Context paramContext, Runtime paramRuntime) { - paramRuntime.getContextProxy().getWifiManager().setWifiEnabled(true); - } - - - public static boolean parseToVoicePacketSent(VoiceContent voiceContent){ - - long filesize; - File voicefile=new File(voiceContent.content); - if (voicefile.exists()) { - filesize = voicefile.length(); - - int count= (int)(filesize/1024); - if ((filesize%1024)>0) - count++; - ICLogger.i("File "+voiceContent.content+", size "+filesize+", count "+count + " filetype "+voiceContent.filetype + ", datatype "+voiceContent.datatype); - voicePacket.getInstanceSent().clearPacket(); - voicePacket.getInstanceSent().setFileType(voiceContent.filetype,voiceContent.datatype); - try { - FileInputStream fis = new FileInputStream(voicefile); - byte[] audiobuf = new byte[1024]; - for (int i = 0; i < count; i++) { - int readbytes=fis.read(audiobuf,0,1024); - voicePacket.getInstanceSent().appendVoice(voiceContent.contactNumber, "", count, i, readbytes, audiobuf); + + public static ArrayList split(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2) { + ArrayList arrayList = new ArrayList(); + int k = paramArrayOfByte1.length; + int m = paramArrayOfByte2.length; + int i = 0; + int j; + int n; + for (j = 0; i < k; j = n) { + + int i1; + byte b = 0; + while (true) { + int bool = i + b; + i1 = i; + n = j; + if (bool < k) { + i1 = i; + n = j; + if (paramArrayOfByte1[bool] == paramArrayOfByte2[b]) { + b = (byte) (b + 1); + + if (n == m) { + n = i - j; + if (n != 0) { + byte[] arrayOfByte = new byte[n]; + System.arraycopy(paramArrayOfByte1, j, arrayOfByte, 0, n); + arrayList.add(arrayOfByte); + } + i += m; + n = i; + i1 = i - 1; + break; + } + continue; + } + } + break; + } + i = i1 + 1; } - fis.close(); - voicePacket.getInstanceSent().setCurrentIndexToSent(0); - voicePacket.getInstanceSent().setPacketTime(TimeUtil.getSystemTime3()); - return true; - }catch (Exception e){ - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - } + i = paramArrayOfByte1.length - j; + if (i != 0) { + paramArrayOfByte2 = new byte[i]; + System.arraycopy(paramArrayOfByte1, j, paramArrayOfByte2, 0, i); + arrayList.add(paramArrayOfByte2); + } + return arrayList; + } + public static byte[] subArray(byte[] paramArrayOfByte, int paramInt) { + return subArray(paramArrayOfByte, paramInt, paramArrayOfByte.length); } - return false; - } - - - public static void reboot(Context context) { - PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); - try { - ICLogger.i("do reboot!"); - powerManager.reboot("remote reboot"); - ICLogger.i("命令重启"); - return; - } catch (Exception e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - return; + + public static byte[] subArray(byte[] paramArrayOfByte, int paramInt1, int paramInt2) { + paramInt2 -= paramInt1; + byte[] arrayOfByte = new byte[paramInt2]; + System.arraycopy(paramArrayOfByte, paramInt1, arrayOfByte, 0, paramInt2); + return arrayOfByte; } - } - - - public static void shutdown() { - try { - ICLogger.i("do shutdown!"); - //获得ServiceManager类 - Class ServiceManager = Class - .forName("android.os.ServiceManager"); - - //获得ServiceManager的getService方法 - Method getService = ServiceManager.getMethod("getService", java.lang.String.class); - - //调用getService获取RemoteService - Object oRemoteService = getService.invoke(null, Context.POWER_SERVICE); - - //获得IPowerManager.Stub类 - Class cStub = Class - .forName("android.os.IPowerManager$Stub"); - //获得asInterface方法 - Method asInterface = cStub.getMethod("asInterface", android.os.IBinder.class); - //调用asInterface方法获取IPowerManager对象 - Object oIPowerManager = asInterface.invoke(null, oRemoteService); - //获得shutdown()方法 - Method shutdown = oIPowerManager.getClass().getMethod("shutdown",boolean.class,boolean.class); - //调用shutdown()方法 - shutdown.invoke(oIPowerManager,false,true); - - } catch (Exception e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); + + public static void turnOffWifiForSleep(Context paramContext, Runtime paramRuntime) { + paramRuntime.getContextProxy().getWifiManager().setWifiEnabled(false); } - } - - public static final String ACTION_MASTER_CLEAR = "android.intent.action.MASTER_CLEAR"; - public static final String EXTRA_REASON = "android.intent.extra.REASON"; - public static final String EXTRA_WIPE_EXTERNAL_STORAGE = "android.intent.extra.WIPE_EXTERNAL_STORAGE"; - - public static void doMasterClear(Context context) { - ICLogger.i("do doMasterClear!"); - Intent intent = new Intent(ACTION_MASTER_CLEAR); - intent.setPackage("android"); - intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); - intent.putExtra(EXTRA_REASON, "MasterClearConfirm"); - if (Environment.isExternalStorageRemovable()) { - intent.putExtra(EXTRA_WIPE_EXTERNAL_STORAGE, true); - }else - { - intent.putExtra(EXTRA_WIPE_EXTERNAL_STORAGE, false); + + public static void turnOnWifiForConnect(Context paramContext, Runtime paramRuntime) { + paramRuntime.getContextProxy().getWifiManager().setWifiEnabled(true); } - context.sendBroadcast(intent); - } + /** + * 传入数据,然后做转换 + * + * @param source 源数据 + * @param isSend 是否要发送 + * @return + */ + public static byte[] fzdTransfer(byte[] source, boolean isSend) { + System.out.print("["); + for (byte b : source) { + System.out.print(b + ","); + } + System.out.println("]"); + System.out.println("-----before------"); + List list = new ArrayList<>(); + byte a = 0X7D; + if (isSend) { + //往外发的数据 + // 0X7D --> 0X7D 0X01 + // 0X5B --> 0X7D 0X02 + // 0X5D --> 0X7D 0X03 + // 0X2C --> 0X7D 0X04 + // 0X2A --> 0X7D 0X05 + for (byte value : source) { + if (value == 0x7d) { + list.add(a); + byte b = 0X01; + list.add(b); + } else if (value == 0x5b) { + list.add(a); + byte b = 0X02; + list.add(b); + } else if (value == 0x5d) { + list.add(a); + byte b = 0X03; + list.add(b); + } else if (value == 0x2c) { + list.add(a); + byte b = 0X04; + list.add(b); + } else if (value == 0x2a) { + list.add(a); + byte b = 0X05; + list.add(b); + } else { + list.add(value); + } + } + } else { + // 0X7D 0X01 --> 0X7D + // 0X7D 0X02 --> 0X5B + // 0X7D 0X03 --> 0X5D + // 0X7D 0X04 --> 0X2C + // 0X7D 0X05 --> 0X2A + for (int i = 0; i < source.length - 1; i += 2) { + //如果i是最后一位,那么直接添加完事 + if (i == source.length - 1) { + list.add(source[i]); + } else if (source[i] == a && source[i + 1] == 0X01) { + byte b = 0X7D; + list.add(b); + } else if (source[i] == a && source[i + 1] == 0X02) { + byte b = 0X5B; + list.add(b); + } else if (source[i] == a && source[i + 1] == 0X03) { + byte b = 0X5D; + list.add(b); + } else if (source[i] == a && source[i + 1] == 0X04) { + byte b = 0X2C; + list.add(b); + } else if (source[i] == a && source[i + 1] == 0X05) { + byte b = 0X2A; + list.add(b); + } else { + list.add(source[i]); + list.add(source[i + 1]); + } + } + } + byte[] result = new byte[list.size()]; + for (int i = 0; i < list.size(); i++) { + result[i] = list.get(i); + } + return result; + } - public static String UrlGB2312ToUTF8(String url){ - String ret=""; - String src=url; + public static boolean parseToVoicePacketSent(VoiceContent voiceContent) { + + long filesize; + File voicefile = new File(voiceContent.content); + if (voicefile.exists()) { + filesize = voicefile.length(); + + int count = (int) (filesize / 1024); + if ((filesize % 1024) > 0) + count++; + ICLogger.i("File " + voiceContent.content + ", size " + filesize + ", count " + count + " filetype " + voiceContent.filetype + ", datatype " + voiceContent.datatype); + voicePacket.getInstanceSent().clearPacket(); + voicePacket.getInstanceSent().setFileType(voiceContent.filetype, voiceContent.datatype); + try { + FileInputStream fis = new FileInputStream(voicefile); + byte[] audiobuf = new byte[1024]; + for (int i = 0; i < count; i++) { + int readbytes = fis.read(audiobuf, 0, 1024); + voicePacket.getInstanceSent().appendVoice(voiceContent.contactNumber, "", count, i, readbytes, audiobuf); + } + fis.close(); + voicePacket.getInstanceSent().setCurrentIndexToSent(0); + voicePacket.getInstanceSent().setPacketTime(TimeUtil.getSystemTime3()); + return true; + } catch (Exception e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + } + } + return false; + } - if (!url.contains("%")){ - int len = url.length(); - //由于协议中GB2312 都是不带% 字头的,和网络中常见的不同,直接2个字节代表一个GB2312字。 - //如果不是2的整倍数,则证明字符串格式有误,取消转换 - if (len%2==0) { - //先给每个unicode字符都加上\\u字头,然后再进行转换。 - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < len; i += 2) { - sb.append("%").append(url.substring(i, i + 2)); + public static void reboot(Context context) { + PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + try { + ICLogger.i("do reboot!"); + powerManager.reboot("remote reboot"); + ICLogger.i("命令重启"); + return; + } catch (Exception e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + return; } - src=sb.toString(); - }else{ - return ret; - } } - try { - ret=java.net.URLDecoder.decode(src,"GB2312"); - } catch (Exception e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); + + + public static void shutdown() { + try { + ICLogger.i("do shutdown!"); + //获得ServiceManager类 + Class ServiceManager = Class + .forName("android.os.ServiceManager"); + + //获得ServiceManager的getService方法 + Method getService = ServiceManager.getMethod("getService", java.lang.String.class); + + //调用getService获取RemoteService + Object oRemoteService = getService.invoke(null, Context.POWER_SERVICE); + + //获得IPowerManager.Stub类 + Class cStub = Class + .forName("android.os.IPowerManager$Stub"); + //获得asInterface方法 + Method asInterface = cStub.getMethod("asInterface", android.os.IBinder.class); + //调用asInterface方法获取IPowerManager对象 + Object oIPowerManager = asInterface.invoke(null, oRemoteService); + //获得shutdown()方法 + Method shutdown = oIPowerManager.getClass().getMethod("shutdown", boolean.class, boolean.class); + //调用shutdown()方法 + shutdown.invoke(oIPowerManager, false, true); + + } catch (Exception e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + } } - return ret; - } - public static String UTF8ToUrlGB2312(String msg){ + public static final String ACTION_MASTER_CLEAR = "android.intent.action.MASTER_CLEAR"; + public static final String EXTRA_REASON = "android.intent.extra.REASON"; + public static final String EXTRA_WIPE_EXTERNAL_STORAGE = "android.intent.extra.WIPE_EXTERNAL_STORAGE"; + + public static void doMasterClear(Context context) { + ICLogger.i("do doMasterClear!"); + Intent intent = new Intent(ACTION_MASTER_CLEAR); + intent.setPackage("android"); + intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); + intent.putExtra(EXTRA_REASON, "MasterClearConfirm"); + if (Environment.isExternalStorageRemovable()) { + intent.putExtra(EXTRA_WIPE_EXTERNAL_STORAGE, true); + } else { + intent.putExtra(EXTRA_WIPE_EXTERNAL_STORAGE, false); + } + context.sendBroadcast(intent); + } - String ret=""; - try { - ret=java.net.URLEncoder.encode(msg,"GB2312"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + + public static String UrlGB2312ToUTF8(String url) { + String ret = ""; + String src = url; + + + if (!url.contains("%")) { + int len = url.length(); + //由于协议中GB2312 都是不带% 字头的,和网络中常见的不同,直接2个字节代表一个GB2312字。 + //如果不是2的整倍数,则证明字符串格式有误,取消转换 + if (len % 2 == 0) { + //先给每个unicode字符都加上\\u字头,然后再进行转换。 + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < len; i += 2) { + sb.append("%").append(url.substring(i, i + 2)); + } + src = sb.toString(); + } else { + return ret; + } + } + try { + ret = java.net.URLDecoder.decode(src, "GB2312"); + } catch (Exception e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + } + return ret; } - return ret; - } - public static String bytesToHexString(byte[] src) { - StringBuilder stringBuilder = new StringBuilder(""); - if (src == null || src.length <= 0) { - return null; + public static String UTF8ToUrlGB2312(String msg) { + + String ret = ""; + try { + ret = java.net.URLEncoder.encode(msg, "GB2312"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return ret; } - for (int i = 0; i < src.length; i++) { - int v = src[i] & 0xFF; - String hv = Integer.toHexString(v); - if (hv.length() < 2) { - stringBuilder.append(0); - } - stringBuilder.append(hv); + + public static String bytesToHexString(byte[] src) { + StringBuilder stringBuilder = new StringBuilder(""); + if (src == null || src.length <= 0) { + return null; + } + for (int i = 0; i < src.length; i++) { + int v = src[i] & 0xFF; + String hv = Integer.toHexString(v); + if (hv.length() < 2) { + stringBuilder.append(0); + } + stringBuilder.append(hv); + } + return stringBuilder.toString(); + } + + public static byte[] hexStringToBytes(String hexString) { + if (hexString == null || hexString.equals("")) { + return null; + } + hexString = hexString.toUpperCase(); + int length = hexString.length() / 2; + char[] hexChars = hexString.toCharArray(); + byte[] d = new byte[length]; + for (int i = 0; i < length; i++) { + int pos = i * 2; + d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); + } + return d; + } + + private static byte charToByte(char c) { + return (byte) "0123456789ABCDEF".indexOf(c); } - return stringBuilder.toString(); - } - public static byte[] hexStringToBytes(String hexString) { - if (hexString == null || hexString.equals("")) { - return null; + + public static int byteArray4ToInt(byte[] b) { + return b[3] & 0xFF | + (b[2] & 0xFF) << 8 | + (b[1] & 0xFF) << 16 | + (b[0] & 0xFF) << 24; } - hexString = hexString.toUpperCase(); - int length = hexString.length() / 2; - char[] hexChars = hexString.toCharArray(); - byte[] d = new byte[length]; - for (int i = 0; i < length; i++) { - int pos = i * 2; - d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); + + public static byte[] intToByteArray4(int a) { + return new byte[]{ + (byte) ((a >> 24) & 0xFF), + (byte) ((a >> 16) & 0xFF), + (byte) ((a >> 8) & 0xFF), + (byte) (a & 0xFF) + }; } - return d; - } - private static byte charToByte(char c) { - return (byte) "0123456789ABCDEF".indexOf(c); - } - - public static int byteArray4ToInt(byte[] b) { - return b[3] & 0xFF | - (b[2] & 0xFF) << 8 | - (b[1] & 0xFF) << 16 | - (b[0] & 0xFF) << 24; - } - public static byte[] intToByteArray4(int a) { - return new byte[] { - (byte) ((a >> 24) & 0xFF), - (byte) ((a >> 16) & 0xFF), - (byte) ((a >> 8) & 0xFF), - (byte) (a & 0xFF) - }; - } - - /** - * 将字节数组转为long
- * 如果input为null,或offset指定的剩余数组长度不足8字节则抛出异常 - * @param input - * @param offset 起始偏移量 - * @param littleEndian 输入数组是否小端模式 - * @return - */ - public static long longFrom8Bytes(byte[] input, int offset, boolean littleEndian){ - if(offset <0 || offset+8>input.length) - throw new IllegalArgumentException(String.format("less than 8 bytes from index %d is insufficient for long",offset)); - long value=0; - for(int count=0;count<8;++count){ - int shift=(littleEndian?count:(7-count))<<3; - value |=((long)0xff<< shift) & ((long)input[offset+count] << shift); + + /** + * 将字节数组转为long
+ * 如果input为null,或offset指定的剩余数组长度不足8字节则抛出异常 + * + * @param input + * @param offset 起始偏移量 + * @param littleEndian 输入数组是否小端模式 + * @return + */ + public static long longFrom8Bytes(byte[] input, int offset, boolean littleEndian) { + if (offset < 0 || offset + 8 > input.length) + throw new IllegalArgumentException(String.format("less than 8 bytes from index %d is insufficient for long", offset)); + long value = 0; + for (int count = 0; count < 8; ++count) { + int shift = (littleEndian ? count : (7 - count)) << 3; + value |= ((long) 0xff << shift) & ((long) input[offset + count] << shift); + } + return value; } - return value; - } - - /** - * 利用 {@link java.nio.ByteBuffer}实现byte[]转long - * @param input - * @param offset - * @param littleEndian 输入数组是否小端模式 - * @return - */ - public static long bytesToLong(byte[] input, int offset, boolean littleEndian) { - if(offset <0 || offset+8>input.length) - throw new IllegalArgumentException(String.format("less than 8 bytes from index %d is insufficient for long",offset)); - ByteBuffer buffer = ByteBuffer.wrap(input,offset,8); - if(littleEndian){ - // ByteBuffer.order(ByteOrder) 方法指定字节序,即大小端模式(BIG_ENDIAN/LITTLE_ENDIAN) - // ByteBuffer 默认为大端(BIG_ENDIAN)模式 - buffer.order(ByteOrder.LITTLE_ENDIAN); + + /** + * 利用 {@link java.nio.ByteBuffer}实现byte[]转long + * + * @param input + * @param offset + * @param littleEndian 输入数组是否小端模式 + * @return + */ + public static long bytesToLong(byte[] input, int offset, boolean littleEndian) { + if (offset < 0 || offset + 8 > input.length) + throw new IllegalArgumentException(String.format("less than 8 bytes from index %d is insufficient for long", offset)); + ByteBuffer buffer = ByteBuffer.wrap(input, offset, 8); + if (littleEndian) { + // ByteBuffer.order(ByteOrder) 方法指定字节序,即大小端模式(BIG_ENDIAN/LITTLE_ENDIAN) + // ByteBuffer 默认为大端(BIG_ENDIAN)模式 + buffer.order(ByteOrder.LITTLE_ENDIAN); + } + return buffer.getLong(); } - return buffer.getLong(); - } } diff --git a/app/src/main/java/com/ic/protocols/protocol_fzd.java b/app/src/main/java/com/ic/protocols/protocol_fzd.java index 7b53dace..09196584 100644 --- a/app/src/main/java/com/ic/protocols/protocol_fzd.java +++ b/app/src/main/java/com/ic/protocols/protocol_fzd.java @@ -7,7 +7,9 @@ import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.media.MediaPlayer; import android.net.Uri; +import android.os.Environment; import android.os.RemoteCallbackList; import android.text.TextUtils; @@ -28,6 +30,8 @@ import com.enqualcomm.support.utils.TimeUtil; import com.enqualcomm.support.utils.Util; import com.enqualcomm.support.utils.regexUtil; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -48,7 +52,7 @@ public class protocol_fzd { private static final String CMDHEADERSPLIT = "*"; private static final String CMDSPLIT = ","; private static final boolean doEncryption = Util.getSystemProperties("persist.sys.encrypt_fzd", "true").equals("true"); - public static final String defaultServerIP = "api.xcloudtech.com"; + public static final String defaultServerIP = "fzd.xcloudtech.com"; public static final int defaultServerPort = 9000; private final SharedPreferences sharedPreferences; @@ -173,8 +177,6 @@ public class protocol_fzd { sharedPreferences = runtime.getContextProxy().context.getSharedPreferences(FZD_SP, Context.MODE_PRIVATE); } - private StringBuffer cmdbuf = new StringBuffer(); - private void log(String msg) { ICLogger.log(TAG, msg); @@ -228,19 +230,24 @@ public class protocol_fzd { } //[6fb043e7f6bb5f107319e3f3822d7124IC*860316012050026*0126*UD,210318,163421,A,33.0227161,N,114.0202817,E,2.98,0.0,0.0,5,039,095,35,00,0100018,5,1,460,00,18899,190839372,44,18899,81,43,18899,56,39,18899,458,38,18899,497,33,5,AP1,fc:d7:33:c8:77:d2,-57,AP2,1c:60:de:28:03:b4,-65,AP3,a4:2b:8c:89:62:91,-68,AP4,cc:2d:21:e2:46:a8,-68,AP5,be:dd:c2:47:04:2b,-70] - public StringMessage genUD2FromUD(StringMessage ud){ - String cmd,data,tmp; - tmp=ud.isFromCache(); - if(isCmdStr(tmp).equals("UD")) { + public StringMessage genUD2FromUD(StringMessage ud) { + String cmd, data, tmp; + tmp = ud.isFromCache(); + if (isCmdStr(tmp).equals("UD")) { cmd = ud.cmd().equals("UD") ? "UD2" : ud.cmd(); - tmp=ud.isFromCache().replace("]",""); - int index=tmp.indexOf("UD,"); - data=tmp.substring(index+3); - return genFZDCMD("UD2",data); - }else{ + tmp = ud.isFromCache().replace("]", ""); + int index = tmp.indexOf("UD,"); + data = tmp.substring(index + 3); + return genFZDCMD("UD2", data); + } else { return null; } } + + private int dataPart = 1; + + private byte[] totalByte; + /* 返回true 表示 cmd 全部解析成功 返回false表示 cmd至少有一条解析失败,失败的数据归入buffer,下一次识别接着使用 @@ -248,39 +255,109 @@ public class protocol_fzd { 每个字符串如果发现 #,却又没有Header,“IW”则会被丢弃 */ public boolean parserCmd(byte[] bytes) { - String cmd_msgbuf = new String(bytes); - log("bytes.size " + bytes.length); - cmdbuf.append(cmd_msgbuf); - log("cmdbuf.size " + cmdbuf.length() + " " + cmdbuf.toString()); - int cmdindex = cmd_msgbuf.indexOf(CMDCOMPANY + CMDHEADERSPLIT); - if (cmdindex > 0) { //如果开头不是CMDHEADER但是包含CMDHEADER则删除前面的数据 - String cmd = cmd_msgbuf.substring(cmdindex); - cmd_msgbuf = cmd; + ICLogger.d("source byte size == > " + bytes.length); + String dataStr = new String(bytes); + //因为buffer有限,所以以[判断开头,以]判断结尾,这些数据要叠加起来 + //这样才是完整的数据 + //by TrillGates + ICLogger.d("添加第" + dataPart + "部分数据."); + dataPart++; + if (dataStr.startsWith(CMDHEADER + CMDCOMPANY + CMDHEADERSPLIT)) { + ICLogger.d("头部数据,开始接收数据了..."); + //命令开始,准备好容器,开始保存数据 + dataPart = 1; + totalByte = bytes; + } else { + //对数据进行合并 + totalByte = byteMerger(totalByte, bytes); } - cmdindex = cmd_msgbuf.indexOf(CMDEND); - if (cmdindex > 0) { - String cmd = cmd_msgbuf.substring(0, cmdindex); - cmd_msgbuf = cmd; + //命令结束,开始处理内容 + if (dataStr.endsWith(CMDEND)) { + ICLogger.d("数据接收结束..开始处理数据." + totalByte.length); + //处理数据了 + //获取指令 + String content = new String(totalByte); + ICLogger.d("total content == > " + content); + //切割出指令 + int cmdIndex = content.indexOf(CMDSPLIT); + ICLogger.d("cmdIndex == > " + cmdIndex); + //指令带数据的 + String cmd = null; + if (cmdIndex > 0) { //如果开头不是CMDHEADER但是包含CMDHEADER则删除前面的数据 + cmd = content.substring(1, cmdIndex); + } else if (content.startsWith(CMDHEADER) && content.endsWith(CMDEND)) { + //纯指令的:[IC*860314001009830*0002*LK],没有逗号的 + cmd = content.replace("[", "").replace("]", ""); + } + ICLogger.d("cmd ---> " + cmd); + //处理内容 + for (CMD_TYPE key : cmdMap.keySet()) { + //如果是FZD命令,则进行处理,否则保留数据动 + if (regexUtil.isFZDCMD(cmdMap.get(key), cmd)) { + ICLogger.d("key is == > " + key); + if (key == CMD_TYPE.TK) { + handlerVoiceContent(totalByte); + } else { + String data = content.replace(CMDHEADER, "").replace(cmd, "").replace(CMDEND, ""); + if (data.startsWith(CMDSPLIT)) { + data = data.substring(1); + } + handleCmd(key, cmd, data); + } + } + + } } - cmdindex = cmd_msgbuf.indexOf(CMDSPLIT); - if (cmdindex > 0) { - String cmd = cmd_msgbuf.substring(0, cmdindex); - cmd_msgbuf = cmd; + return true; + } + + private static byte[] byteMerger(byte[]... byteList) { + int lengthByte = 0; + //求出总的长度 + for (int i = 0; i < byteList.length; i++) { + lengthByte += byteList[i].length; } - if (cmdbuf.toString().split(CMDCOMPANY + CMDHEADERSPLIT).length > 1) { - ICLogger.i("More than 1 cmd in buffer ! just log it"); + //创建总的数组 + byte[] allByte = new byte[lengthByte]; + int countLength = 0; + for (int i = 0; i < byteList.length; i++) { + byte[] b = byteList[i]; + System.arraycopy(b, 0, allByte, countLength, b.length); + countLength += b.length; } - for (CMD_TYPE key : cmdMap.keySet()) { - // ICLogger.i("key "+cmdMap.get(key)+" cmdbuf "+cmd_msgbuf); - if (regexUtil.isFZDCMD(cmdMap.get(key), cmd_msgbuf)) { //如果是FZD命令,则进行处理,否则保留数据动 - String data = cmdbuf.toString().replace(CMDHEADER, "").replace(cmd_msgbuf, "").replace(CMDEND, ""); - if (data.startsWith(CMDSPLIT)) data = data.substring(1); - handleCmd(key, cmd_msgbuf, data); - cmdbuf.delete(0, cmdbuf.length());//处理后清空 -// } - } + return allByte; + } + + private void handlerVoiceContent(byte[] bytes) { + ICLogger.d("voice length == > " + bytes.length); + String cmdStr = new String(bytes); + String[] split = cmdStr.split(","); + ICLogger.d("split[0].length() == > " + split[0].length()); + //处理数据 + byte[] dataPackage = Util.subArray(bytes, split[0].length() + 1, bytes.length - 1); + //String packageStr = new String(dataPackage); + //ICLogger.d("packageStr == > " + packageStr); + String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) + "/Android/VoiceCache"; + byte[] result = Util.fzdTransfer(dataPackage, false); + ICLogger.d("dataPackage LENGTH == > " + result.length); + String amrFilepath = Util.saveFile(result, + 0, result.length, + new File(dir), + "receive_" + System.currentTimeMillis() + ".amr"); + ICLogger.d("amrFilepath == > " + amrFilepath + " dataPackage size == > " + dataPackage.length); + //播放一下吧 + MediaPlayer mediaPlayer = new MediaPlayer(); + try { + mediaPlayer.setDataSource(amrFilepath); + mediaPlayer.prepare(); + ICLogger.d("playVoice.. "); + mediaPlayer.start(); + } catch (IOException e) { + ICLogger.d("playVoice: ERROR "); } - return true; + //TODO: + //回复服务器状态 + mConnection.send(TK("1")); } private static String getHexLen(int len) { @@ -668,7 +745,6 @@ public class protocol_fzd { } public void handleFIND(Connection connection) { - connection.send(FIND()); } @@ -912,6 +988,10 @@ public class protocol_fzd { } + private StringMessage TK(String result) { + return genFZDCMD(cmdMap.get(CMD_TYPE.TK), result); + } + private static final String BRREG_ID = "brreg_id"; @@ -923,11 +1003,8 @@ public class protocol_fzd { */ private void handleBRREG(Runtime runtime, String data) { RemoteCallbackList fzdCallback = runtime.getFZDCallback(); - if (fzdCallback == null) { - return; - } + int i = fzdCallback.beginBroadcast(); try { - int i = fzdCallback.beginBroadcast(); while (i > 0) { i--; IFZDCallback broadcastItem = fzdCallback.getBroadcastItem(i); @@ -938,11 +1015,12 @@ public class protocol_fzd { broadcastItem.onBRIdLoaded(data); } } - fzdCallback.finishBroadcast(); //保存到sp里面 sharedPreferences.edit().putString(BRREG_ID, data).apply(); } catch (Exception e) { e.printStackTrace(); + } finally { + fzdCallback.finishBroadcast(); } } @@ -1011,22 +1089,24 @@ public class protocol_fzd { * @param data */ private void handleRTalk(Connection mConnection, Runtime mRuntime, String data) { + RemoteCallbackList fzdCallback = mRuntime.getFZDCallback(); + if (TextUtils.isEmpty(data)) { + return; + } + int i = fzdCallback.beginBroadcast(); try { - RemoteCallbackList fzdCallback = mRuntime.getFZDCallback(); - if (fzdCallback != null && !TextUtils.isEmpty(data)) { - int i = fzdCallback.beginBroadcast(); - ICLogger.d("data == > " + data); - String[] split = data.split(CMDSPLIT); - while (i > 0) { - i--; - if (split.length == 3) { - fzdCallback.getBroadcastItem(i).onRemoteReject(split[0], Integer.parseInt(split[1])); - } + ICLogger.d("data == > " + data); + String[] split = data.split(CMDSPLIT); + while (i > 0) { + i--; + if (split.length == 3) { + fzdCallback.getBroadcastItem(i).onRemoteReject(split[0], Integer.parseInt(split[1])); } - fzdCallback.finishBroadcast(); } } catch (Exception e) { e.printStackTrace(); + } finally { + fzdCallback.finishBroadcast(); } //终端回复: [XT*设备 ID*LEN*RTALK] mConnection.send(genFZDCMD(cmdMap.get(CMD_TYPE.RTALK))); @@ -1082,9 +1162,9 @@ public class protocol_fzd { ICLogger.d("handlerTalkRequestResult == > " + data); //可以正常通话,可以不处理 //如果不能正常通话,则要提示用户了 + RemoteCallbackList fzdCallback = mRuntime.getFZDCallback(); + int i = fzdCallback.beginBroadcast(); try { - RemoteCallbackList fzdCallback = mRuntime.getFZDCallback(); - int i = fzdCallback.beginBroadcast(); while (i > 0) { i--; if (fzdCallback != null) { @@ -1093,9 +1173,10 @@ public class protocol_fzd { fzdCallback.getBroadcastItem(i).onCallRequestResult(result); } } - fzdCallback.finishBroadcast(); } catch (Exception e) { e.printStackTrace(); + } finally { + fzdCallback.finishBroadcast(); } } @@ -1138,27 +1219,29 @@ public class protocol_fzd { contentValues.put("_id", Integer.parseInt(split[i])); contentValues.put("user_name", split[i + 1]); contentValues.put("phone_num", split[i + 2]); + contentValues.put("create_time", System.currentTimeMillis()); + contentValues.put("update_time", System.currentTimeMillis()); //结果有了,保存到内容提供者里头去. resolver.insert(Uri.parse(FZDMembersProvider.MEMBERS), contentValues); } - //解析完成了,通知UI。 - RemoteCallbackList fzdCallback = mRuntime.getFZDCallback(); - try { - ICLogger.d("onContractsLoaded..."); - int i = fzdCallback.beginBroadcast(); - while (i > 0) { - i--; - IFZDCallback broadcastItem = fzdCallback.getBroadcastItem(i); - //通知UI层数据已经准备好了,可以去获取了。 - broadcastItem.onContractsLoaded(); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - fzdCallback.finishBroadcast(); - } } } + //不管有没有数据,都要通知UI。 + RemoteCallbackList fzdCallback = mRuntime.getFZDCallback(); + ICLogger.d("onContractsLoaded..."); + int i = fzdCallback.beginBroadcast(); + try { + while (i > 0) { + i--; + IFZDCallback broadcastItem = fzdCallback.getBroadcastItem(i); + //通知UI层数据已经准备好了,可以去获取了。 + broadcastItem.onContractsLoaded(); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + fzdCallback.finishBroadcast(); + } } diff --git a/app/src/main/java/com/ic/protocols/protocol_jiai.java b/app/src/main/java/com/ic/protocols/protocol_jiai.java index 6936c542..a2f8ca51 100644 --- a/app/src/main/java/com/ic/protocols/protocol_jiai.java +++ b/app/src/main/java/com/ic/protocols/protocol_jiai.java @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; -import static com.enqualcomm.support.Constants.ACTION_HEATR_RATE_START; import static com.enqualcomm.support.Constants.FROM_SERVER; import static com.enqualcomm.support.LocationClient.LOCATION_MODE; import static com.enqualcomm.support.bean.Contact.GROUP_ALL; @@ -295,7 +294,6 @@ public class protocol_jiai { log("found cmd keyid=" + key + " ,keyname=" + cmdMap.get(key) + " , " + cmdlist[i]); if (key == CMD_TYPE.BP28) { //如果是BP28则 后面的数据是音频,需要保留 - byte[] amrBuf; int amrLen = getBP28Amrlen(cmdlist[i]); if (bytes.length > amrLen) { handleCmd(key, cmdlist[i], bytes); @@ -371,10 +369,10 @@ public class protocol_jiai { int timezone = Integer.parseInt(msg[2]); if (datetime != null) { ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); - TimeUtil.setTimeZone(runtime.getContextProxy().context,timezone); + TimeUtil.setTimeZone(runtime.getContextProxy().context, timezone); ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); - TimeUtil.setSysDateTime(runtime.getContextProxy().context, datetime, timezone,true); + TimeUtil.setSysDateTime(runtime.getContextProxy().context, datetime, timezone, true); ICLogger.i("===" + TimeUtil.getDefaultTimeZone()); } @@ -1221,7 +1219,7 @@ public class protocol_jiai { //85 : 血压低压 [舒张压] //95:血氧 //90:血糖 -// 本消息适用所有终端,其中需要每项指标不一定全部有值,如果无值,则留空 + //本消息适用所有终端,其中需要每项指标不一定全部有值,如果无值,则留空 return genStringMessage(cmdMap.get(protocol_ic.CMD_TYPE.APHP), new StringBuffer(CMDHEADER).append(cmdMap.get(protocol_ic.CMD_TYPE.APHP)) .append(CMDSPLIT).append(ds.getHRS().getPPG()) .append(CMDSPLIT).append(ds.getHRS().getBPH()) @@ -1275,8 +1273,8 @@ public class protocol_jiai { //立即定位反馈 public static StringMessage AP16(String cmdindex) { -//IWAP16,080835# -//080835:指令流水号 + //IWAP16,080835# + //080835:指令流水号 return genStringMessage("AP16", new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP16)) .append(CMDSPLIT).append(cmdindex) .append(CMDEND).toString()); @@ -1312,7 +1310,6 @@ public class protocol_jiai { //0: MNC //9750: LAC //3613: CID - return genStringMessage(cmdMap.get(CMD_TYPE.APTM), new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.APTM)) .append(CMDSPLIT).append(ds.getLocationInstance().getMCC()) .append(CMDSPLIT).append(ds.getLocationInstance().getMNC()) @@ -1327,9 +1324,7 @@ public class protocol_jiai { //返回时间,格式为:yyyyMMddHHmmss ,为UTC0 时间 //经纬度保留六位小数,若没取到则返回 0 String[] list = cmd.split(CMDSPLIT); - if (list.length == 4) { - String time = list[1]; String lat = list[2]; String lon = list[3]; diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..03854b0d --- /dev/null +++ b/docs/README.md @@ -0,0 +1,19 @@ +# 防走丢数据库字段说明 + +- 联系人表 + - _id:ID + - user_name:用户名 + - phone_num:手机号码 + - create_time:创建时间 + - update_time:更新时间 + + +- 消息表(微聊) + - _id:ID + - content:内容 + - type:消息类型,1表示语音消息 ,2表示文本消息,3表示图片,如果需要视频其他类型的话可以继续定义 + - state:状态,0表示未读,1表示已读 + - in_or_out:来源,1表示来信,2表示发送的消息 + - remote_num:对方号码,手机号码,可以从联系人中查询 + - create_time:创建时间 + - update_time:更新时间 \ No newline at end of file diff --git a/local.properties b/local.properties index 704f65c2..5021b8e4 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Sat Mar 06 19:12:47 CST 2021 -sdk.dir=C\:\\Users\\incar\\AppData\\Local\\Android\\Sdk +#Fri Mar 26 10:19:03 CST 2021 +sdk.dir=E\:\\Android\\Sdk -- 2.17.1