修复升级bug
diff --git a/app/src/main/java/com/supwisdom/activities/upgrade/UpgradeActivity.kt b/app/src/main/java/com/supwisdom/activities/upgrade/UpgradeActivity.kt
index 38cbf5a..91f304d 100644
--- a/app/src/main/java/com/supwisdom/activities/upgrade/UpgradeActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/upgrade/UpgradeActivity.kt
@@ -32,6 +32,7 @@
     private lateinit var vServerUrl: TextView
     private lateinit var vPosOldVersion: TextView
     private lateinit var vPosVersion: TextView
+    @Volatile
     private var isUpgrading = false
     @Volatile
     private var keyActive = true
@@ -72,8 +73,6 @@
                     finish()
                 KeyEvent.KEYCODE_ENTER -> {
                     //ok
-                    isUpgrading = true
-                    AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("正在升级", "请稍等..."))
                     asyncUpgrade()
                 }
             }
@@ -133,12 +132,16 @@
      * 开始下载apk
      */
     fun asyncUpgrade() {
-        ThreadPool.getDownloadPool().execute(Runnable {
-            EpayUpgradeApi(upgradeApiCallback).upgrade(
-                pos.getConfigPara()!!.devphyid!!,
-                CommonUtil.getVersionName(this)
-            )
-        })
+        if (!isUpgrading) {
+            isUpgrading = true
+            AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("正在升级", "请稍等..."))
+            ThreadPool.getDownloadPool().execute(Runnable {
+                EpayUpgradeApi(upgradeApiCallback).upgrade(
+                    pos.getConfigPara()!!.devphyid!!,
+                    CommonUtil.getVersionName(this)
+                )
+            })
+        }
     }
 
     /**
@@ -162,10 +165,10 @@
     private var counter: ContinuePressTimer? = null
 
     private fun resetCounter(timems: Long) {
+        counter?.cancel()
         if (counter == null) {
             counter = ContinuePressTimer(timems, 100)
         }
-        counter!!.cancel()
         keyActive = false
         counter!!.start()
     }
diff --git a/app/src/main/java/com/supwisdom/activities/upgrade/mode/EpayUpgradeApi.kt b/app/src/main/java/com/supwisdom/activities/upgrade/mode/EpayUpgradeApi.kt
index 2225779..304a6a7 100644
--- a/app/src/main/java/com/supwisdom/activities/upgrade/mode/EpayUpgradeApi.kt
+++ b/app/src/main/java/com/supwisdom/activities/upgrade/mode/EpayUpgradeApi.kt
@@ -20,18 +20,18 @@
  */
 class EpayUpgradeApi constructor(callbackInterface: CallbackInterface) {
     private val TIMEOUT = 5 * 1000// 超时
-    private val callbackInterface = callbackInterface
+    private val callback = callbackInterface
     private val POSID = "posa711dali"
 
     fun upgrade(devphyid: String, version: String) {
         val resp = getAppVersion(devphyid, version)
         if (resp.retcode != PublicDef.SUCCESS) {
-            callbackInterface.failed(resp.retmsg!!)
+            callback.failed(resp.retmsg!!)
             return
         }
         val updateFile = FileUtil.getUpdateFile("$POSID.zip")
         if (updateFile == null) {
-            callbackInterface.failed("创建本地文件失败")
+            callback.failed("创建本地文件失败")
             return
         }
         if (!downloadUpdateFile(resp.upgrade_url!!, updateFile, resp.upgrade_version!!)) {
@@ -70,7 +70,7 @@
             totalSize = urlConnection.contentLength
             if (urlConnection.responseCode != HttpStatus.SC_OK) {
                 urlConnection.disconnect()
-                callbackInterface.failed("下载文件失败:错误码=${urlConnection.responseCode}")
+                callback.failed("下载文件失败:错误码=${urlConnection.responseCode}")
                 return false
             }
             val inputStream = urlConnection.inputStream
@@ -89,7 +89,7 @@
                 if (pro - downStep >= 1) {
                     downStep++
                     CommonUtil.doSleep(100)
-                    callbackInterface.progresss(pro)
+                    callback.progresss(pro)
                 }
             }
             urlConnection.disconnect()
@@ -98,7 +98,7 @@
             return true
         } catch (e: Exception) {
             e.printStackTrace()
-            callbackInterface.failed("下载文件异常:${e.message}")
+            callback.failed("下载文件异常:${e.message}")
             return false
         }
     }
@@ -110,33 +110,33 @@
             ZipUtil.unzip(zipFilePath, unZipFilePath, false)
             val apkFile = File("$unZipFilePath/$POSID.apk")
             if (!apkFile.exists()) {
-                callbackInterface.failed("未找到文件$POSID.apk")
+                callback.failed("未找到文件$POSID.apk")
                 return false
             }
 
             val fileHash256 = CryptUtil.HASH256(FileInputStream(apkFile), "nzoqPYMIu91VViA/mEIG5FtJXi8=")
             if (fileHash256 == null) {
-                callbackInterface.failed("计算文件校验数据错误")
+                callback.failed("计算文件校验数据错误")
                 return false
             }
             val signFile = FileInputStream("$unZipFilePath/hash256.sign")
             val buffer = ByteArray(1024)
             val length = signFile.read(buffer, 0, buffer.size)
             if (length < 0) {
-                callbackInterface.failed("读取校验文件失败")
+                callback.failed("读取校验文件失败")
                 return false
             }
             signFile.close()
             val signHash256 = String(Arrays.copyOfRange(buffer, 0, length))
             if (!fileHash256.equals(signHash256, ignoreCase = true)) {
-                callbackInterface.failed("文件校验错误")
+                callback.failed("文件校验错误")
                 return false
             }
-            callbackInterface.success("$unZipFilePath/$POSID.apk")
+            callback.success("$unZipFilePath/$POSID.apk")
             return true
         } catch (e: Exception) {
             e.printStackTrace()
-            callbackInterface.failed("文件校验异常:${e.message}")
+            callback.failed("文件校验异常:${e.message}")
             return false
         }
     }
@@ -149,20 +149,23 @@
             .setParameter("sourcetype", "pos")
 
         val resp = YktSession.getInstance().sendYktRequestPost("/api/pos/globalparam", "", params)
-            ?: return UpgradeInfoRetBean(PublicDef.ERROR, "获取版本号网络超时")
+            ?: return UpgradeInfoRetBean(PublicDef.ERROR, "获取版本超时")
         if (resp.retcode != HttpStatus.SC_OK) {
-            return UpgradeInfoRetBean(resp.retcode, resp.retmsg)
+            return UpgradeInfoRetBean(resp.retcode, "获取版本错误码=${resp.retcode}")
         }
         return try {
             val bean = GsonUtil.GsonToBean(resp.retjson!!, UpgradeInfoRetBean::class.java)
+            if (bean.retcode != PublicDef.SUCCESS) {
+                return UpgradeInfoRetBean(resp.retcode, "获取版本错误=" + bean.retmsg)
+            }
             when {
-                TextUtils.isEmpty(bean.upgrade_version) -> UpgradeInfoRetBean(PublicDef.ERROR, "获取版本号为空")
-                TextUtils.isEmpty(bean.upgrade_url) -> UpgradeInfoRetBean(PublicDef.ERROR, "获取升级链接为空")
+                TextUtils.isEmpty(bean.upgrade_version) -> UpgradeInfoRetBean(PublicDef.ERROR, "获取版本为空")
+                TextUtils.isEmpty(bean.upgrade_url) -> UpgradeInfoRetBean(PublicDef.ERROR, "获取升级地址为空")
                 else -> bean
             }
         } catch (e: Exception) {
             e.printStackTrace()
-            UpgradeInfoRetBean(PublicDef.ERROR, "获取版本号JSON异常:${e.message}")
+            UpgradeInfoRetBean(PublicDef.ERROR, "获取版本JSON异常:${e.message}")
         }
     }