Esempio n. 1
0
 public void startUICenterLog(String action, String resid, String packageName) {
   String logText = action + "#" + resid + "#" + packageName;
   boolean isFind = false;
   if (mContext == null) {
     if (enable_Statistics_LOG)
       Log.v(
           "UICenter - StatisticsNew",
           LOG_TAG
               + "\n=packageOnEvent"
               + "\n--[(mContext == null)] --------------------- return");
     return;
   }
   if (enable_Statistics_LOG)
     Log.v("UICenter - StatisticsNew", LOG_TAG + "\n=packageOnEvent" + "\n--order:" + logText);
   LogDB logDB = new LogDB(mContext);
   logDB.open();
   Cursor cursor = logDB.getAllLogText();
   while (cursor.moveToNext()) {
     String text = cursor.getString(cursor.getColumnIndexOrThrow("logtext"));
     if (text.equals(logText)) {
       isFind = true;
       break;
     }
   }
   cursor.close();
   if (!isFind) {
     logDB.insertRecord(logText);
   }
   logDB.close();
   if (mHandler != null) {
     if (enable_Statistics_LOG)
       Log.v(
           "UICenter - StatisticsNew",
           LOG_TAG + "\n=packageOnEvent" + "\n--存在上传线程 ---------------------return");
     return;
   }
   checkThread();
   if (!exitErrTime()) {
     if (enable_Statistics_LOG)
       Log.v("UICenter - StatisticsNew", LOG_TAG + "\n=packageOnEvent" + "\n--不存在错误时间");
     if (SuccessTimeTransfinite()) {
       if (enable_Statistics_LOG)
         Log.v(
             "UICenter - StatisticsNew",
             LOG_TAG + "\n=packageOnEvent" + "\n--成功时间超过时间间隔 ==========================");
       // 上传数据
       mHandler.post(UploadRun);
     } else {
       exitThread();
       if (enable_Statistics_LOG)
         Log.v(
             "UICenter - StatisticsNew",
             LOG_TAG
                 + "\n=packageOnEvent"
                 + "\n--exitThread成功时间没有超过时间间隔 ---------------------exitThread--------------------");
     }
   } else {
     if (enable_Statistics_LOG)
       Log.v("UICenter - StatisticsNew", LOG_TAG + "\n=packageOnEvent" + "\n--存在错误时间");
     if (getErrTimes() > 3 && ErrTimeTransfinite(TYPE.ONEDAYINTERVAL)) {
       if (enable_Statistics_LOG)
         Log.v(
             "UICenter - StatisticsNew",
             LOG_TAG + "\n=packageOnEvent" + "\n--错误时间超过一小时 ==========================");
       // 更新失败次数&失败时间
       recordErrCount(1);
       recordErrTime();
       // 上传数据
       mHandler.post(UploadRun);
     } else if (getErrTimes() <= 3 && ErrTimeTransfinite(TYPE.RETRYINTERVAL)) {
       if (enable_Statistics_LOG)
         Log.v(
             "UICenter - StatisticsNew",
             LOG_TAG + "\n=packageOnEvent" + "\n--错误时间间隔超过1分钟 ========================== ");
       // 上传数据
       mHandler.post(UploadRun);
     } else {
       exitThread();
       if (enable_Statistics_LOG)
         Log.v(
             "UICenter - StatisticsNew",
             LOG_TAG
                 + "\n=packageOnEvent"
                 + "\n--exitThread错误时间没有超过时间间隔 ---------------------exitThread-------------------- ");
     }
   }
 }
Esempio n. 2
0
 @Override
 public void run() {
   // TODO Auto-generated method stub
   mHandler.removeCallbacks(UploadRun);
   if (enable_Statistics_LOG) {
     Log.v("UICenter - StatisticsNew", LOG_TAG + "\n=UploadRun" + "\n--上传线程");
   }
   // 判断是否联网
   if (!IsHaveInternet(mContext)) {
     if (enable_Statistics_LOG)
       Log.v("UICenter - StatisticsNew", LOG_TAG + "\n=UploadRun" + "\n--没有线程");
     exitThread();
     if (enable_Statistics_LOG)
       Log.v(
           "UICenter - StatisticsNew",
           LOG_TAG
               + "\n=UploadRun"
               + "\n--没有网退出线程"
               + "---------------------exitThread--------------------");
     return;
   } else {
     String params = getLogInformation();
     if (params != null) {
       CustomerHttpClient client = new CustomerHttpClient(mContext);
       String[] res = client.post(LOG_URL_TEST, params);
       if (res != null) {
         String content = res[0];
         JSONObject json = null;
         try {
           json = new JSONObject(content);
           int retCode = json.getInt("retcode");
           if (retCode == 0) {
             delAllData();
             clearErrTimeAndCount();
             recordSuccessTime();
             if (enable_Statistics_LOG)
               Log.v(
                   "UICenter - StatisticsNew",
                   LOG_TAG
                       + "\n=UploadRun"
                       + "\n--上传成功 =============ok===================="
                       + "\n--params    = "
                       + params);
           } else {
             isUseLog = false;
             int errcount = getErrTimes();
             recordErrCount(++errcount);
             recordErrTime();
             if (enable_Statistics_LOG)
               Log.v(
                   "UICenter - StatisticsNew",
                   LOG_TAG
                       + "\n=UploadRun"
                       + "\n--上传失败=============not ok===================="
                       + "\n--params    = "
                       + params
                       + "\n--retCode    ="
                       + retCode);
           }
         } catch (JSONException e) {
           isUseLog = false;
           int errcount = getErrTimes();
           recordErrCount(++errcount);
           recordErrTime();
           if (enable_Statistics_LOG)
             Log.v(
                 "UICenter - StatisticsNew",
                 LOG_TAG
                     + "\n=UploadRun"
                     + "\n--上传失败=============not ok===================="
                     + "\n--params    = "
                     + params);
           e.printStackTrace();
         }
       } else {
         isUseLog = false;
         int errcount = getErrTimes();
         recordErrCount(++errcount);
         recordErrTime();
         if (enable_Statistics_LOG)
           Log.v(
               "UICenter - StatisticsNew",
               LOG_TAG
                   + "\n=UploadRun"
                   + "\n--上传失败=============not ok===================="
                   + "\n--params    = "
                   + params
                   + "\n--res      ="
                   + res);
       }
     }
     if (enable_Statistics_LOG)
       Log.v("UICenter - StatisticsNew", LOG_TAG + "\n=UploadRun" + "\n--关闭上传线程");
     exitThread();
   }
 }