优化日志上传功能,日志服务器可配。
authorsnickersun <scy@incartech.cn>
Tue, 20 Apr 2021 03:19:35 +0000 (11:19 +0800)
committersnickersun <scy@incartech.cn>
Tue, 20 Apr 2021 03:19:35 +0000 (11:19 +0800)
app/src/main/java/com/enqualcomm/support/ICSmsManager.java
app/src/main/java/com/enqualcomm/support/utils/ICHttpUtil.java

index 2f9da84..5f3202e 100644 (file)
@@ -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 !");
index 0e0e0ab..222c6d4 100644 (file)
-package com.enqualcomm.support.utils;\r
-\r
-import android.content.Context;\r
-import android.os.Environment;\r
-import android.os.Handler;\r
-import android.util.Log;\r
-\r
-import com.enqualcomm.support.Config;\r
-import com.sina.util.dnscache.net.ApacheHttpClientNetworkRequests;\r
-import com.enqualcomm.support.bean.Runtime;\r
-\r
-import java.io.DataInputStream;\r
-import java.io.DataOutputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.OutputStream;\r
-import java.net.HttpURLConnection;\r
-import java.net.URL;\r
-import java.util.zip.CRC32;\r
-import java.util.zip.CheckedOutputStream;\r
-import java.util.zip.ZipOutputStream;\r
-\r
-import static android.content.ContentValues.TAG;\r
-\r
-public class ICHttpUtil {\r
-    public static boolean uploadData(String filebuf, Runtime runtime, String logtime, Handler mhandler)  {\r
-        String sdcard= Environment.getExternalStorageDirectory().getAbsolutePath();\r
-        String filename=sdcard+File.separator+"tmp.txt";\r
-        String zipfile=sdcard+File.separator+"tmp.zip";\r
-        boolean compressSuccess=false;\r
-        try {\r
-\r
-            CheckedOutputStream out=new CheckedOutputStream(new FileOutputStream(filename),new CRC32());\r
-            out.write(filebuf.getBytes());\r
-            out.close();\r
-\r
-            File srcfile=new File(filename);\r
-            if (Util.zipFile(srcfile, "",\r
-                    new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile),new CRC32()))\r
-                    , filename)) {\r
-                compressSuccess=true;\r
-            }\r
-            srcfile.delete();\r
-        }catch (Exception e){\r
-            e.printStackTrace();\r
-            compressSuccess=false;\r
-        }\r
-        if (compressSuccess==false) {\r
-\r
-            if(mhandler!=null)\r
-                mhandler.sendEmptyMessage(0);\r
-            return false;\r
-        }\r
-        String server= Config.getLogServerIP(runtime.getContextProxy().context);\r
-        int port= Config.getLogServerPort(runtime.getContextProxy().context);\r
-        String product=DeviceInfoUtil.getModule();\r
-        String pkgver=DeviceInfoUtil.getSWVersionDisplayName();\r
-        String imei=runtime.IMEI();\r
-        if (server.startsWith("http://")){\r
-            server=server.replace("http://","");\r
-        }\r
-        //为了兼容之前的只设置ip和端口的设置方式\r
-        String actionUrl = "http://"+server+":"+port + "/UploadFile.jsp?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime;\r
-        if (server.contains("/")){ //此时说明不是ip地址,而是个url\r
-            actionUrl= "http://"+server+"?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime;\r
-        }\r
-\r
-        ICLogger.i("url="+actionUrl+"\nfile="+zipfile);\r
-        return upLoadFile(actionUrl, new File(zipfile),mhandler);\r
-\r
-    }\r
-    public static boolean uploadFile(String filename, Runtime runtime, String logtime, Handler mhandler)  {\r
-\r
-        String zipfile=filename;\r
-        boolean compressSuccess=false;\r
-        try {\r
-            String sdcard= Environment.getExternalStorageDirectory().getAbsolutePath();\r
-            File srcfile=new File(filename);\r
-            zipfile=sdcard+File.separator+srcfile.getName()+".zip";\r
-            if (Util.zipFile(srcfile, "",\r
-                    new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(zipfile),new CRC32()))\r
-            , filename)) {\r
-                compressSuccess=true;\r
-            }\r
-        }catch (Exception e){\r
-            e.printStackTrace();\r
-            compressSuccess=false;\r
-        }\r
-        if (compressSuccess==false) {\r
-\r
-            if(mhandler!=null)\r
-                mhandler.sendEmptyMessage(0);\r
-            return false;\r
-        }\r
-        String server= Config.getLogServerIP(runtime.getContextProxy().context);\r
-        int port= Config.getLogServerPort(runtime.getContextProxy().context);\r
-        String product=DeviceInfoUtil.getModule();\r
-        String pkgver=DeviceInfoUtil.getSWVersionDisplayName();\r
-        String imei=runtime.IMEI();\r
-        if (server.startsWith("http://")){\r
-            server=server.replace("http://","");\r
-        }\r
-        //为了兼容之前的只设置ip和端口的设置方式\r
-        String actionUrl = "http://"+server+":"+port + "/UploadFile.jsp?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime;\r
-        if (server.contains("/")){ //此时说明不是ip地址,而是个url\r
-                actionUrl= "http://"+server+"?product=" + product + "&pkgver="+ pkgver + "&imei="+ imei+"&logtime="+logtime;\r
-        }\r
-\r
-        ICLogger.i("url="+actionUrl+"\nfile="+zipfile);\r
-        return upLoadFile(actionUrl, new File(zipfile),mhandler);\r
-\r
-    }\r
-    public static boolean upLoadFile(String url, File file, Handler mhandler) {\r
-        boolean result = false;\r
-\r
-            if (null == url || null == file || !file.exists() || file.length() < 1) {\r
-                if(mhandler!=null)\r
-                    mhandler.sendEmptyMessage(0);\r
-                return false;\r
-            }\r
-\r
-\r
-            new Thread(new Runnable() {\r
-                @Override\r
-                public void run() {\r
-                    try {\r
-                        /**\r
-                         * 第一部分\r
-                         */\r
-                        URL urlObj = new URL(url);\r
-                        HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();\r
-\r
-                        /**\r
-                         * 设置关键值\r
-                         */\r
-                        con.setRequestMethod("POST"); // 以Post方式提交表单,默认get方式\r
-                        con.setDoInput(true);\r
-                        con.setDoOutput(true);\r
-                        con.setUseCaches(false); // post方式不能使用缓存\r
-\r
-                        // 设置请求头信息\r
-                        con.setRequestProperty("Connection", "Keep-Alive");\r
-                        con.setRequestProperty("Charset", "UTF-8");\r
-\r
-                        // 设置边界\r
-                        String BOUNDARY = "----------" + System.currentTimeMillis();\r
-                        con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);\r
-\r
-                        // 请求正文信息\r
-\r
-                        // 第一部分:\r
-                        StringBuilder sb = new StringBuilder();\r
-                        sb.append("--"); // ////////必须多两道线\r
-                        sb.append(BOUNDARY);\r
-                        sb.append("\r\n");\r
-                        sb.append("Content-Disposition: form-data;name=\"file\";filename=\"" + file.getName() + "\"\r\n");\r
-                        sb.append("Content-Type:application/octet-stream\r\n\r\n");\r
-\r
-                        byte[] head = sb.toString().getBytes("utf-8");\r
-\r
-                        // 获得输出流\r
-                        OutputStream out = new DataOutputStream(con.getOutputStream());\r
-                        out.write(head);\r
-\r
-                        // 文件正文部分\r
-                        DataInputStream in = new DataInputStream(new FileInputStream(file));\r
-                        int bytes = 0;\r
-                        byte[] bufferOut = new byte[1024];\r
-                        while ((bytes = in.read(bufferOut)) != -1) {\r
-                            out.write(bufferOut, 0, bytes);\r
-                        }\r
-                        in.close();\r
-\r
-                        // 结尾部分\r
-                        byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");// 定义最后数据分隔线\r
-                        out.write(foot);\r
-                        out.flush();\r
-                        out.close();\r
-\r
-                        int statusCode = con.getResponseCode();\r
-                        String msg = con.getResponseMessage();\r
-                        ICLogger.i(msg);\r
-                        if (statusCode == 200) {\r
-                            if(mhandler!=null)\r
-                                mhandler.sendEmptyMessage(1);\r
-                        }else\r
-                        {\r
-                            if(mhandler!=null)\r
-                                mhandler.sendEmptyMessage(0);\r
-                        }\r
-\r
-\r
-                    } catch (Exception e) {\r
-                        e.printStackTrace();\r
-                        if(mhandler!=null)\r
-                            mhandler.sendEmptyMessage(0);\r
-                    }\r
-                }\r
-            }).start();\r
-\r
-        return true;\r
-    }\r
-}\r
+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;
+    }
+}