From: snickersun Date: Thu, 10 Sep 2020 03:16:57 +0000 (+0800) Subject: release V609 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=c0a569b248bbc9c60d979675080e10cd1687df77;p=protocol_srv.git release V609 修复 用Thread替代observer.timer后造成的日志上传问题。 修复 Email上传日志的问题。 --- diff --git a/app/release/ICSer_V608_2009081941_release.apk b/app/release/ICSer_V609_2009101110_release.apk similarity index 78% rename from app/release/ICSer_V608_2009081941_release.apk rename to app/release/ICSer_V609_2009101110_release.apk index 3caf1982..e6d19447 100644 Binary files a/app/release/ICSer_V608_2009081941_release.apk and b/app/release/ICSer_V609_2009101110_release.apk differ diff --git a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java index 554eb921..da61b474 100644 --- a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java +++ b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java @@ -558,6 +558,27 @@ public class ICSmsManager extends BroadcastReceiver { sendSMS(phonenumber, "WiFi Control format error!"); } }else if(sms.startsWith(ENCRYPED_HEADER+"#logctl#=")){ + + Handler mhandler=new Handler(){ + @Override + public void handleMessage(Message msg) { + + switch(msg.what){ + case 0: + sendSMS(phonenumber, "Upload Failed!"); + Util.ShowToast(runtime,"Upload cmd Failed!"); + + break; + + case 1: + sendSMS(phonenumber, "Upload success!"); + Util.ShowToast(runtime,"Upload cmd success!"); + break; + } + + super.handleMessage(msg); + } + }; String tmp[] = sms.split("="); if (tmp.length == 2) { if (tmp[1].equals("current")) { @@ -605,7 +626,7 @@ public class ICSmsManager extends BroadcastReceiver { } } else { - if (ICHttpUtil.uploadFile(filepath, runtime, logtime)) { + if (ICHttpUtil.uploadFile(filepath, runtime, logtime,mhandler)) { sb.append(" ").append(file); ICLogger.i("Upload file " + file + " success! "); } else { @@ -617,11 +638,11 @@ public class ICSmsManager extends BroadcastReceiver { } } - if (sb.length() > 0) { - sendSMS(phonenumber, "Upload [" + sb.toString() + "] success to " + Config.getFtpServer(mContext)); - } else { - sendSMS(phonenumber, "Upload all files failed to " + Config.getFtpServer(mContext)); - } +// if (sb.length() > 0) { +// sendSMS(phonenumber, "Upload [" + sb.toString() + "] success to " + Config.getFtpServer(mContext)); +// } else { +// sendSMS(phonenumber, "Upload all files failed to " + Config.getFtpServer(mContext)); +// } } }, 500); @@ -663,16 +684,16 @@ public class ICSmsManager extends BroadcastReceiver { } } } else { - if (ICHttpUtil.uploadFile(filepath, runtime, logtime)) { - sendSMS(phonenumber, "Upload " + filepath + " to " + Config.getFtpServer(mContext) + " success!"); - if (logfile.startsWith("SDLogInfo:")){ - Util.ShowToast(runtime,"Upload " + filepath + " to " + Config.getFtpServer(mContext) + " success!"); - } + if (ICHttpUtil.uploadFile(filepath, runtime, logtime,mhandler)) { +// sendSMS(phonenumber, "Upload " + filepath + " to " + Config.getFtpServer(mContext) + " success!"); +// if (logfile.startsWith("SDLogInfo:")){ +// Util.ShowToast(runtime,"Upload " + filepath + " to " + Config.getFtpServer(mContext) + " success!"); +// } } else { - sendSMS(phonenumber, "Upload " + filepath + " to " + Config.getFtpServer(mContext) + " failed!"); - if (logfile.startsWith("SDLogInfo:")){ - Util.ShowToast(runtime,"Upload " + filepath + " to " + Config.getFtpServer(mContext) + " failed!"); - } +// sendSMS(phonenumber, "Upload " + filepath + " to " + Config.getFtpServer(mContext) + " failed!"); +// if (logfile.startsWith("SDLogInfo:")){ +// Util.ShowToast(runtime,"Upload " + filepath + " to " + Config.getFtpServer(mContext) + " failed!"); +// } } } } else { @@ -711,10 +732,10 @@ public class ICSmsManager extends BroadcastReceiver { sendSMS(phonenumber, "Upload " + logfile + " to " + Config.getFtpServer(mContext) + " failed!"); } }else{ - if (ICHttpUtil.uploadFile(filepath,runtime,logtime)) { - sendSMS(phonenumber, "Upload " + logfile + " to " + Config.getFtpServer(mContext) + " success!"); + if (ICHttpUtil.uploadFile(filepath,runtime,logtime,mhandler)) { +// sendSMS(phonenumber, "Upload " + logfile + " to " + Config.getFtpServer(mContext) + " success!"); } else { - sendSMS(phonenumber, "Upload " + logfile + " to " + Config.getFtpServer(mContext) + " failed!"); +// sendSMS(phonenumber, "Upload " + logfile + " to " + Config.getFtpServer(mContext) + " failed!"); } } } else { @@ -1070,21 +1091,36 @@ public class ICSmsManager extends BroadcastReceiver { new Handler().postDelayed(new Runnable() { @Override public void run() { - String logfile = "/sdcard/Android/ic"; + String logfile = ""; + String fileOrDir = "Android/ic"; Util.getDBFile(); - sendSMS(phonenumber, "mail " + logfile + " to " + mailaddr + " ..."); - Util.ShowToast(runtime,"mail " + logfile + " to " + mailaddr + " ..."); - String logtime = TimeUtil.getSystemTime3(); - if (SendEmail.getInstance().sendLogViaMail(logfile,mailaddr, logtime)) { - sendSMS(phonenumber, "mail " + logfile + " to " + mailaddr + " success!"); - Util.ShowToast(runtime,"mail " + logfile + " to " + mailaddr + " success!"); + logfile = Util.zipfiles(fileOrDir); + if (new File(logfile).exists()) { + + sendSMS(phonenumber, "mail " + fileOrDir + " to " + mailaddr + " ..."); + Util.ShowToast(runtime,"mail " + fileOrDir + " to " + mailaddr + " ..."); + + String logtime = TimeUtil.getSystemTime3(); + if (SendEmail.getInstance().sendLogViaMail(logfile,mailaddr, logtime)) { + sendSMS(phonenumber, "mail " + fileOrDir + " to " + mailaddr + " success!"); +// Util.ShowToast(runtime,"mail " + fileOrDir + " to " + mailaddr + " success!"); + } else { + sendSMS(phonenumber, "mail " + fileOrDir + " to " + mailaddr + " failed!"); +// Util.ShowToast(runtime,"mail " + fileOrDir + " to " + mailaddr + " failed!"); + } + } else { - sendSMS(phonenumber, "mail " + logfile + " to " + mailaddr + " failed!"); - Util.ShowToast(runtime,"mail " + logfile + " to " + mailaddr + " failed!"); + sendSMS(phonenumber, fileOrDir + " not exist !"); +// if (logfile.startsWith("SDLogInfo:")) { +// Util.ShowToast(runtime, fileOrDir + " not exist !"); +// } } } + + + }, 500); } diff --git a/app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java b/app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java index 8d1114d8..3dcb7c2c 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java @@ -2,6 +2,7 @@ package com.enqualcomm.support.utils; import android.content.Context; import android.os.Environment; +import android.os.Handler; import android.util.Log; import com.enqualcomm.support.Config; @@ -24,7 +25,7 @@ import static android.content.ContentValues.TAG; public class ICHttpUtil { - public static boolean uploadFile(String filename, Runtime runtime,String logtime) { + public static boolean uploadFile(String filename, Runtime runtime, String logtime, Handler mhandler) { String zipfile=filename; boolean compressSuccess=false; @@ -41,7 +42,12 @@ public class ICHttpUtil { e.printStackTrace(); compressSuccess=false; } - if (compressSuccess==false) return false; + if (compressSuccess==false) { + + if(mhandler!=null) + mhandler.sendEmptyMessage(0); + return false; + } String server= Config.getLogServerIP(runtime.getContextProxy().context); int port= Config.getLogServerPort(runtime.getContextProxy().context); String product=DeviceInfoUtil.getModule(); @@ -57,77 +63,97 @@ public class ICHttpUtil { } ICLogger.i("url="+actionUrl+"\nfile="+zipfile); - return upLoadFile(actionUrl, new File(zipfile)); + return upLoadFile(actionUrl, new File(zipfile),mhandler); } - public static boolean upLoadFile(String url, File file) { + public static boolean upLoadFile(String url, File file, Handler mhandler) { boolean result = false; - try { + if (null == url || null == file || !file.exists() || file.length() < 1) { + if(mhandler!=null) + mhandler.sendEmptyMessage(0); return false; } - /** - * 第一部分 - */ - URL urlObj = new URL(url); - HttpURLConnection con = (HttpURLConnection) urlObj.openConnection(); - - /** - * 设置关键值 - */ - con.setRequestMethod("POST"); // 以Post方式提交表单,默认get方式 - con.setDoInput(true); - con.setDoOutput(true); - con.setUseCaches(false); // post方式不能使用缓存 - - // 设置请求头信息 - con.setRequestProperty("Connection", "Keep-Alive"); - con.setRequestProperty("Charset", "UTF-8"); - - // 设置边界 - String BOUNDARY = "----------" + System.currentTimeMillis(); - con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY); - - // 请求正文信息 - - // 第一部分: - StringBuilder sb = new StringBuilder(); - sb.append("--"); // ////////必须多两道线 - sb.append(BOUNDARY); - sb.append("\r\n"); - sb.append("Content-Disposition: form-data;name=\"file\";filename=\"" + file.getName() + "\"\r\n"); - sb.append("Content-Type:application/octet-stream\r\n\r\n"); - - byte[] head = sb.toString().getBytes("utf-8"); - - // 获得输出流 - OutputStream out = new DataOutputStream(con.getOutputStream()); - out.write(head); - - // 文件正文部分 - DataInputStream in = new DataInputStream(new FileInputStream(file)); - int bytes = 0; - byte[] bufferOut = new byte[1024]; - while ((bytes = in.read(bufferOut)) != -1) { - out.write(bufferOut, 0, bytes); - } - in.close(); - - // 结尾部分 - byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");// 定义最后数据分隔线 - out.write(foot); - out.flush(); - out.close(); - - int statusCode = con.getResponseCode(); - String msg=con.getResponseMessage(); - ICLogger.i(msg); - if (statusCode == 200) { - result = true; - } - } catch (Exception e) { - e.printStackTrace(); - } - return result; + + + new Thread(new Runnable() { + @Override + public void run() { + try { + /** + * 第一部分 + */ + URL urlObj = new URL(url); + HttpURLConnection con = (HttpURLConnection) urlObj.openConnection(); + + /** + * 设置关键值 + */ + con.setRequestMethod("POST"); // 以Post方式提交表单,默认get方式 + con.setDoInput(true); + con.setDoOutput(true); + con.setUseCaches(false); // post方式不能使用缓存 + + // 设置请求头信息 + con.setRequestProperty("Connection", "Keep-Alive"); + con.setRequestProperty("Charset", "UTF-8"); + + // 设置边界 + String BOUNDARY = "----------" + System.currentTimeMillis(); + con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY); + + // 请求正文信息 + + // 第一部分: + StringBuilder sb = new StringBuilder(); + sb.append("--"); // ////////必须多两道线 + sb.append(BOUNDARY); + sb.append("\r\n"); + sb.append("Content-Disposition: form-data;name=\"file\";filename=\"" + file.getName() + "\"\r\n"); + sb.append("Content-Type:application/octet-stream\r\n\r\n"); + + byte[] head = sb.toString().getBytes("utf-8"); + + // 获得输出流 + OutputStream out = new DataOutputStream(con.getOutputStream()); + out.write(head); + + // 文件正文部分 + DataInputStream in = new DataInputStream(new FileInputStream(file)); + int bytes = 0; + byte[] bufferOut = new byte[1024]; + while ((bytes = in.read(bufferOut)) != -1) { + out.write(bufferOut, 0, bytes); + } + in.close(); + + // 结尾部分 + byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");// 定义最后数据分隔线 + out.write(foot); + out.flush(); + out.close(); + + int statusCode = con.getResponseCode(); + String msg = con.getResponseMessage(); + ICLogger.i(msg); + if (statusCode == 200) { + if(mhandler!=null) + mhandler.sendEmptyMessage(1); + }else + { + if(mhandler!=null) + mhandler.sendEmptyMessage(0); + } + + + } catch (Exception e) { + e.printStackTrace(); + if(mhandler!=null) + mhandler.sendEmptyMessage(0); + } + } + }).start(); + + return true; } } 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 a7c8e741..5e00ff8f 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/Util.java +++ b/app/src/main/java/com/enqualcomm/support/utils/Util.java @@ -620,6 +620,30 @@ public class Util { 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(); + zipfile=""; + } + + 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()); diff --git a/app/version_code.properties b/app/version_code.properties index 8628d580..b668e72c 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Tue Sep 08 19:41:57 CST 2020 -VERSION_CODE=608 +#Thu Sep 10 11:10:16 CST 2020 +VERSION_CODE=609