添加日志
diff --git a/app/src/main/java/com/supwisdom/activities/consume/BeepManager.kt b/app/src/main/java/com/supwisdom/activities/consume/BeepManager.kt
index 4973200..4a2cd3e 100644
--- a/app/src/main/java/com/supwisdom/activities/consume/BeepManager.kt
+++ b/app/src/main/java/com/supwisdom/activities/consume/BeepManager.kt
@@ -18,9 +18,8 @@
  * @desc  滴滴声
  */
 @Suppress("DEPRECATION")
-class BeepManager constructor(context: Context) : MediaPlayer.OnErrorListener, Closeable {
-    private val context = context
-
+class BeepManager constructor(private val context: Context) : MediaPlayer.OnErrorListener,
+    Closeable {
     private val BEEP_VOLUME = 0.10f
     private val VIBRATE_DURATION = 200L
 
diff --git a/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt b/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
index 2b2575c..665b729 100644
--- a/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
@@ -78,7 +78,7 @@
     private var payWay: String? = null

     private var counter: LastPayShowTimer? = null

     private var lastPayInfo: CardUserInfoBean? = null

-    private var dialogPurchase: DialogPurchase? = null

+    private lateinit var dialogPurchase: DialogPurchase

     private var periodFixPayList: List<PeriodFixPayRecord>? = null

     private var periodFixPayEnable = false

 

@@ -129,8 +129,8 @@
                     }

                     beepManager!!.playBeepSoundAndVibrate()

                     presenter.clickNoPay()

-                    dialogPurchase!!.codePaying = true

-                    dialogPurchase!!.codePayingNoCancelEnable = true

+                    dialogPurchase.codePaying = true

+                    dialogPurchase.codePayingNoCancelEnable = true

                     payStatusEnable = false

                     presenter.codeToPay(code, amount)

                 } finally {

@@ -142,7 +142,7 @@
     }

 

     private fun someWayPaying(): Boolean {

-        if (cardPaying || dialogPurchase!!.codePaying || isBackRunning) {

+        if (cardPaying || dialogPurchase.codePaying || isBackRunning) {

             return true

         }

         return false

@@ -180,7 +180,7 @@
     override fun onDestroy() {

         SoundUtil.releaseMusic()

         presenter.stop()

-        beepManager!!.close()

+        beepManager?.close()

         super.onDestroy()

     }

 

@@ -356,8 +356,8 @@
                 parsePeriodFixPay()

             }

         }

-        if (dialogPurchase!!.isShowing &&

-            !dialogPurchase!!.isFixPay &&

+        if (dialogPurchase.isShowing &&

+            !dialogPurchase.isFixPay &&

             payStatusEnable

         ) {

             beepManager!!.playBeepSoundAndVibrate()

@@ -379,7 +379,7 @@
         val operation = this.intent.getStringExtra("operation")

         if (operation == "reverse") {

             presenter.clickToReverse(amount)

-            dialogPurchase!!.show("等待冲正", CommonUtil.showFormatAmount("金额", amount))

+            dialogPurchase.show("等待冲正", CommonUtil.showFormatAmount("金额", amount))

         }

         this.intent.putExtra("amount", "0")

         this.intent.putExtra("payway", "")

@@ -498,7 +498,7 @@
     }

 

     override fun showConsumeSuc(info: CardUserInfoBean) {

-        dialogPurchase!!.showPaySuccess(info)

+        dialogPurchase.showPaySuccess(info)

         val auxList = ArrayList<String>()

         auxList.add(info.getErrorMsg())

         auxList.add(CommonUtil.showFormatAmount("金额", info.payamt))

@@ -520,24 +520,24 @@
 

     override fun showConsumeHint(hint: String) {

         val amountStr = CommonUtil.showFormatAmount("金额", amount)

-        dialogPurchase!!.showProcess(hint, amountStr)

+        dialogPurchase.showProcess(hint, amountStr)

         AuxScreenController.getInstance().refreshContent(Arrays.asList(hint, amountStr))

     }

 

     override fun showConsumeQuery(hint: String) {

-        dialogPurchase!!.showQueryProcess(hint, "请耐心等待")

+        dialogPurchase.showQueryProcess(hint, "请耐心等待")

         AuxScreenController.getInstance().refreshContent(Arrays.asList(hint, "请耐心等待"))

     }

 

     override fun showConsumeInterrupt(info: CardUserInfoBean) {

         showPayInterrupt(info.cardno)

-        dialogPurchase!!.showPayInterrupt()

+        dialogPurchase.showPayInterrupt()

         AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("交易取消", "以银行交易为准"))

         SoundUtil.playMusic(applicationContext, R.raw.pay_cancel)

     }

 

     override fun showConsumeFail(info: CardUserInfoBean) {

-        dialogPurchase!!.showPayFail(info)

+        dialogPurchase.showPayFail(info)

         AuxScreenController.getInstance()

             .refreshContent(Arrays.asList<String>("消费失败", "原因:", info.getErrorMsg()))

         SoundUtil.playMusic(applicationContext, R.raw.consume_fail)

@@ -545,7 +545,7 @@
     }

 

     override fun showReverseSuc(info: CardUserInfoBean) {

-        dialogPurchase!!.showReverseSuccess(info)

+        dialogPurchase.showReverseSuccess(info)

         AuxScreenController.getInstance()

             .refreshContent(

                 Arrays.asList<String>(

@@ -558,7 +558,7 @@
     }

 

     override fun showReverseFail(info: CardUserInfoBean) {

-        dialogPurchase!!.showReverseFail(info)

+        dialogPurchase.showReverseFail(info)

         AuxScreenController.getInstance()

             .refreshContent(Arrays.asList<String>("冲正失败", "原因:", info.getErrorMsg()))

         SoundUtil.playMusic(applicationContext, R.raw.reversal_fail)

@@ -586,9 +586,9 @@
             lastShowRecentTime = info.transtime

 

             if (info.status == PayStatus.SUC) {

-                when {

-                    info.reversalFlag == ReversalFlag.AUTO -> vLastResult.text = "自动冲正"

-                    info.reversalFlag == ReversalFlag.MANUAL -> vLastResult.text = "手动撤销"

+                when (info.reversalFlag) {

+                    ReversalFlag.AUTO -> vLastResult.text = "自动冲正"

+                    ReversalFlag.MANUAL -> vLastResult.text = "手动撤销"

                     else -> vLastResult.text = "消费成功"

                 }

                 vLastPayFailll.visibility = View.GONE

@@ -688,10 +688,10 @@
     }

 

     private fun showDialogPay(isFixPay: Boolean) {

-        dialogPurchase!!.codePaying = false

-        dialogPurchase!!.isFixPay = isFixPay

-        dialogPurchase!!.codePayingNoCancelEnable = false

-        dialogPurchase!!.show("请刷卡", CommonUtil.showFormatAmount("金额", amount))

+        dialogPurchase.codePaying = false

+        dialogPurchase.isFixPay = isFixPay

+        dialogPurchase.codePayingNoCancelEnable = false

+        dialogPurchase.show("请刷卡", CommonUtil.showFormatAmount("金额", amount))

     }

 

     private fun getCurAmount(): Int {

diff --git a/app/src/main/java/com/supwisdom/epaycard/DaliReader.kt b/app/src/main/java/com/supwisdom/epaycard/DaliReader.kt
index f146948..755a2d1 100644
--- a/app/src/main/java/com/supwisdom/epaycard/DaliReader.kt
+++ b/app/src/main/java/com/supwisdom/epaycard/DaliReader.kt
@@ -75,9 +75,9 @@
     fun cpuApdu(cmd: ByteArray): ApduResponse {
         val send = ApduSend()
         val resp = ApduResp()
-        when {
-            cmd.size == 4 -> System.arraycopy(cmd, 0, send.Command, 0, 4)
-            cmd.size == 5 -> {
+        when (cmd.size) {
+            4 -> System.arraycopy(cmd, 0, send.Command, 0, 4)
+            5 -> {
                 System.arraycopy(cmd, 0, send.Command, 0, 4)
                 send.Le = cmd[4].unsignedToInt().toShort()
                 if (0xB2 == cmd[1].unsignedToInt() &&
diff --git a/app/src/main/java/com/supwisdom/service/BackgroundTaskService.kt b/app/src/main/java/com/supwisdom/service/BackgroundTaskService.kt
index 3eb31d2..a6f8610 100644
--- a/app/src/main/java/com/supwisdom/service/BackgroundTaskService.kt
+++ b/app/src/main/java/com/supwisdom/service/BackgroundTaskService.kt
@@ -20,6 +20,7 @@
     private var apiInterface: APIInterface = EpayApiImpl()
     private var sysRecord: SysParaRecord? = null
     private var transdtlClearDate: String? = null
+
     @Volatile
     private var isExist = false
 
@@ -35,6 +36,7 @@
 
     override fun run() {
         var heartgap: Int
+        LogUtil.i(TAG, "BackgroundTaskService run !!")
         while (!isExist) {
             try {
                 heartAndTransdtl()
@@ -44,11 +46,12 @@
                 LogUtil.d(TAG, CommonUtil.getExceptionStack(ex))
             }
             sysRecord = pos.getSysPara()
-            heartgap = if (sysRecord == null || sysRecord!!.heatBeat < 10 || sysRecord!!.heatBeat > 600) {
-                60
-            } else {
-                sysRecord!!.heatBeat
-            }
+            heartgap =
+                if (sysRecord == null || sysRecord!!.heatBeat < 10 || sysRecord!!.heatBeat > 600) {
+                    60
+                } else {
+                    sysRecord!!.heatBeat
+                }
             CommonUtil.doSleep(heartgap * 1000)
         }
     }
@@ -64,10 +67,13 @@
             uploadTransdtl()
         } catch (ex: HeartBeatError) {
             SPApplication.getInstance().setEpayLinking(false)
+            throw ex
         } catch (ex: TransdtlUploadError) {
             ex.printStackTrace()
+            throw ex
         } catch (ex: AuthEpayError) {
             SPApplication.getInstance().setEpayLinking(false)
+            throw ex
         }
     }
 
diff --git a/app/src/main/java/com/supwisdom/service/NtpClient.kt b/app/src/main/java/com/supwisdom/service/NtpClient.kt
index 2e4f3f0..53c861f 100644
--- a/app/src/main/java/com/supwisdom/service/NtpClient.kt
+++ b/app/src/main/java/com/supwisdom/service/NtpClient.kt
@@ -10,6 +10,8 @@
  **/
 class NtpClient {
     private val NTP_TIME_OUT_MILLISECOND = 10000
+    private val DIFF_TIME_GAP = 30000
+
     /**
      * 国内ntp服务器地址集
      */
@@ -44,9 +46,9 @@
     fun startCalibrateTime(synctime: Long) {
         val localTime = System.currentTimeMillis()
         if (synctime > 0) {
-            if (synctime > localTime && synctime - localTime > 60000) {
+            if (synctime > localTime && synctime - localTime > DIFF_TIME_GAP) {
                 setCurrentTimeMillis(synctime)
-            } else if (localTime > synctime && localTime - synctime > 60000) {
+            } else if (localTime > synctime && localTime - synctime > DIFF_TIME_GAP) {
                 setCurrentTimeMillis(synctime)
             }
         }
diff --git a/app/src/main/java/com/supwisdom/utils/SoundUtil.kt b/app/src/main/java/com/supwisdom/utils/SoundUtil.kt
index 2c80655..6a3132f 100644
--- a/app/src/main/java/com/supwisdom/utils/SoundUtil.kt
+++ b/app/src/main/java/com/supwisdom/utils/SoundUtil.kt
@@ -21,7 +21,11 @@
             return
         }
         if (soundPool == null) {
-            soundPool = SoundPool(30, AudioManager.STREAM_MUSIC, 0) //分别对应声音池数量,AudioManager.STREAM_MUSIC 和 0
+            soundPool = SoundPool(
+                50,
+                AudioManager.STREAM_MUSIC,
+                0
+            ) //分别对应声音池数量,AudioManager.STREAM_MUSIC 和 0
         }
         if (soundMap.containsKey(mid)) {
             soundPool!!.play(soundMap[mid]!!, 1.0f, 1.0f, 1, 0, 1.0f)
@@ -36,10 +40,8 @@
     }
 
     fun releaseMusic() {
-        if (soundPool != null) {
-            soundPool!!.release()
-            soundPool = null
-        }
+        soundPool?.release()
+        soundPool = null
         soundMap.clear()
     }