From: snickersun Date: Tue, 20 Apr 2021 03:19:35 +0000 (+0800) Subject: 优化日志上传功能,日志服务器可配。 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=6c577980f2f62ba6d9375e9d6f26c72bc0c692a0;p=protocol_srv.git 优化日志上传功能,日志服务器可配。 --- diff --git a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java index 2f9da84f..5f3202e6 100644 --- a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java +++ b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java @@ -844,19 +844,10 @@ public class ICSmsManager extends BroadcastReceiver { if (strtmp.contains("/")) { /* #setLogSrv#=http://icfota.snicker.com.cn:8089/UploadFile.jsp*/ - Config.setLogServerIP(mContext, strtmp, 8089); + Config.setHttpLogServerUrl(mContext, strtmp); sendSMS(phonenumber, "set setLogSrv to " + strtmp + "!"); - } else { - /* #setLogSrv#=icfota.snicker.com.cn:8089 */ - String[] ipstr = strtmp.split(":"); - if (ipstr.length == 2) { - String ip = ipstr[0]; - int port = Integer.valueOf(ipstr[1].replace("#", "")); - Config.setLogServerIP(mContext, ip, port); - sendSMS(phonenumber, "set setLogSrv to " + strtmp + "!"); - } else { - sendSMS(phonenumber, " setLogSrv cmd Format error!"); - } + }else { + sendSMS(phonenumber, " setLogSrv cmd Format error!"); } } else { @@ -873,7 +864,6 @@ public class ICSmsManager extends BroadcastReceiver { sendSMS(phonenumber, " setFotaSrv cmd Format error!"); } } else if (sms.equals(ENCRYPED_HEADER + "#FotaUpdate#")) { - cell_number_to_reply = phonenumber; broadCastStartFotaUpdate(mContext); sendSMS(phonenumber, "start fota update !"); 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 0e0e0ab3..222c6d4d 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java @@ -1,204 +1,188 @@ -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; -import com.sina.util.dnscache.net.ApacheHttpClientNetworkRequests; -import com.enqualcomm.support.bean.Runtime; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.zip.CRC32; -import java.util.zip.CheckedOutputStream; -import java.util.zip.ZipOutputStream; - -import static android.content.ContentValues.TAG; - -public class ICHttpUtil { - public static boolean uploadData(String filebuf, Runtime runtime, String logtime, Handler mhandler) { - String sdcard= Environment.getExternalStorageDirectory().getAbsolutePath(); - String filename=sdcard+File.separator+"tmp.txt"; - String zipfile=sdcard+File.separator+"tmp.zip"; - boolean compressSuccess=false; - try { - - CheckedOutputStream out=new CheckedOutputStream(new FileOutputStream(filename),new CRC32()); - out.write(filebuf.getBytes()); - out.close(); - - File srcfile=new File(filename); - if (Util.zipFile(srcfile, "", - new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile),new CRC32())) - , filename)) { - compressSuccess=true; - } - srcfile.delete(); - }catch (Exception e){ - e.printStackTrace(); - compressSuccess=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(); - String pkgver=DeviceInfoUtil.getSWVersionDisplayName(); - String imei=runtime.IMEI(); - if (server.startsWith("http://")){ - server=server.replace("http://",""); - } - //为了兼容之前的只设置ip和端口的设置方式 - String actionUrl = "http://"+server+":"+port + "/UploadFile.jsp?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime; - if (server.contains("/")){ //此时说明不是ip地址,而是个url - actionUrl= "http://"+server+"?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime; - } - - ICLogger.i("url="+actionUrl+"\nfile="+zipfile); - return upLoadFile(actionUrl, new File(zipfile),mhandler); - - } - public static boolean uploadFile(String filename, Runtime runtime, String logtime, Handler mhandler) { - - String zipfile=filename; - boolean compressSuccess=false; - try { - String sdcard= Environment.getExternalStorageDirectory().getAbsolutePath(); - File srcfile=new File(filename); - zipfile=sdcard+File.separator+srcfile.getName()+".zip"; - if (Util.zipFile(srcfile, "", - new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile),new CRC32())) - , filename)) { - compressSuccess=true; - } - }catch (Exception e){ - e.printStackTrace(); - compressSuccess=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(); - String pkgver=DeviceInfoUtil.getSWVersionDisplayName(); - String imei=runtime.IMEI(); - if (server.startsWith("http://")){ - server=server.replace("http://",""); - } - //为了兼容之前的只设置ip和端口的设置方式 - String actionUrl = "http://"+server+":"+port + "/UploadFile.jsp?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime; - if (server.contains("/")){ //此时说明不是ip地址,而是个url - actionUrl= "http://"+server+"?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime; - } - - ICLogger.i("url="+actionUrl+"\nfile="+zipfile); - return upLoadFile(actionUrl, new File(zipfile),mhandler); - - } - public static boolean upLoadFile(String url, File file, Handler mhandler) { - boolean result = false; - - if (null == url || null == file || !file.exists() || file.length() < 1) { - if(mhandler!=null) - mhandler.sendEmptyMessage(0); - return false; - } - - - 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; - } -} +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; +import com.sina.util.dnscache.net.ApacheHttpClientNetworkRequests; +import com.enqualcomm.support.bean.Runtime; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.zip.CRC32; +import java.util.zip.CheckedOutputStream; +import java.util.zip.ZipOutputStream; + +import static android.content.ContentValues.TAG; + +public class ICHttpUtil { + public static boolean uploadData(String filebuf, Runtime runtime, String logtime, Handler mhandler) { + String sdcard= Environment.getExternalStorageDirectory().getAbsolutePath(); + String filename=sdcard+File.separator+"tmp.txt"; + String zipfile=sdcard+File.separator+"tmp.zip"; + boolean compressSuccess=false; + try { + + CheckedOutputStream out=new CheckedOutputStream(new FileOutputStream(filename),new CRC32()); + out.write(filebuf.getBytes()); + out.close(); + + File srcfile=new File(filename); + if (Util.zipFile(srcfile, "", + new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile),new CRC32())) + , filename)) { + compressSuccess=true; + } + srcfile.delete(); + }catch (Exception e){ + e.printStackTrace(); + compressSuccess=false; + } + if (compressSuccess==false) { + + if(mhandler!=null) + mhandler.sendEmptyMessage(0); + return false; + } + String serverurl= Config.getHttpLogServerUrl(runtime.getContextProxy().context); + String product=DeviceInfoUtil.getModule(); + String pkgver=DeviceInfoUtil.getSWVersionDisplayName(); + String imei=runtime.IMEI(); + //为了兼容之前的只设置ip和端口的设置方式 + String actionUrl = serverurl+"?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime; + ICLogger.i("url="+actionUrl+"\nfile="+zipfile); + return upLoadFile(actionUrl, new File(zipfile),mhandler); + + } + public static boolean uploadFile(String filename, Runtime runtime, String logtime, Handler mhandler) { + + String zipfile=filename; + boolean compressSuccess=false; + try { + String sdcard= Environment.getExternalStorageDirectory().getAbsolutePath(); + File srcfile=new File(filename); + zipfile=sdcard+File.separator+srcfile.getName()+".zip"; + if (Util.zipFile(srcfile, "", + new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile),new CRC32())) + , filename)) { + compressSuccess=true; + } + }catch (Exception e){ + e.printStackTrace(); + compressSuccess=false; + } + if (compressSuccess==false) { + + if(mhandler!=null) + mhandler.sendEmptyMessage(0); + return false; + } + String serverurl= Config.getHttpLogServerUrl(runtime.getContextProxy().context); + String product=DeviceInfoUtil.getModule(); + String pkgver=DeviceInfoUtil.getSWVersionDisplayName(); + String imei=runtime.IMEI(); + //为了兼容之前的只设置ip和端口的设置方式 + String actionUrl = serverurl+"?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime; + ICLogger.i("url="+actionUrl+"\nfile="+zipfile); + return upLoadFile(actionUrl, new File(zipfile),mhandler); + + } + public static boolean upLoadFile(String url, File file, Handler mhandler) { + boolean result = false; + + if (null == url || null == file || !file.exists() || file.length() < 1) { + if(mhandler!=null) + mhandler.sendEmptyMessage(0); + return false; + } + + + 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; + } +}