Browse Source

修复新中新身份证阅读器,防止频繁加载导致闪退

Shangyp 11 months ago
parent
commit
fc676b2678
1 changed files with 25 additions and 32 deletions
  1. 25 32
      app/src/main/java/com/telpo/facenormal/activity/MainActivity.java

+ 25 - 32
app/src/main/java/com/telpo/facenormal/activity/MainActivity.java

@@ -451,19 +451,19 @@ import static com.telpo.facenormal.utile.Config.CheckList;
                     break;
                 case DeviceConnectManager.MESSAGE_CONNECTFAILED:
                     AppLogUtils.e(true, "newIdCardHandler_新中新身份证阅读器",devName + "新版身份证阅读器连接失败");
-//                    if (idCardReaderThread!=null){
-//                        idCardReaderThread.close();
-//                    }
-                    IDCardReaderThread.close();
+                    newIdCard = "ERROR";
+                    try {
+                        IDCardReaderThread.stop();
+                        IDCardReaderThread.close();
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
                     newIdCardStrarHandler.removeCallbacks(newIdCardStrarRunnable);
                     newIdCardStrarHandler.removeCallbacksAndMessages(null);
                     newIdCardStrarHandler.postDelayed(newIdCardStrarRunnable,5*1000);
                     break;
                 case DeviceConnectManager.MESSAGE_DISCONNECTED:
                     AppLogUtils.i(true, "newIdCardHandler_新中新身份证阅读器",devName + "新版身份证阅读器连接断开");
-//                    if (idCardReaderThread!=null){
-//                        idCardReaderThread.close();
-//                    }
                     IDCardReaderThread.close();
                     break;
                 case DeviceConnectManager.MESSAGE_RECONNECT_DEVICE:
@@ -472,6 +472,7 @@ import static com.telpo.facenormal.utile.Config.CheckList;
                 case DeviceConnectManager.MESSAGE_STOP_READCARD:
                     break;
                 case IDCardReaderThread.MESSAGE_START_READ:
+                    newIdCard = "succeed";
                     new MyTimer().start();
                     AppLogUtils.i(true, "newIdCardHandler_新中新身份证阅读器","新版身份证阅读器开始读卡");
                     break;
@@ -972,17 +973,9 @@ import static com.telpo.facenormal.utile.Config.CheckList;
 //                idCardReaderThread = new IDCardReaderThread();
                 IDCardReaderThread.getInstance().setActivityAndHandler(this, newIdCardHandler);
                 IDCardReaderThread.getInstance().open(null);
-                new Handler().postDelayed(new Runnable() {
-                    @Override
-                    public void run() {
-//                        if (Config.getAuthenticationBean().getData().get(0).isUseIdcard()) {
-//                            idCardReaderThread.read();
-//                        } else {
-//                            idCardReaderThread.stop();
-//                        }
-                        IDCardReaderThread.getInstance().read();
-                    }
-                },2000);
+                newIdCardStrarHandler.removeCallbacks(newIdCardStrarRunnable);
+                newIdCardStrarHandler.removeCallbacksAndMessages(null);
+                newIdCardStrarHandler.postDelayed(newIdCardStrarRunnable,2*1000);
 
             }
         }
@@ -2932,6 +2925,12 @@ import static com.telpo.facenormal.utile.Config.CheckList;
             AppLogUtils.e(true, "USB广播信号","重新尝试与新版身份证阅读器建立连接");
             if (!(Build.MODEL.indexOf("F2")!=-1|(Build.MODEL.indexOf("TPS980")!=-1))&&
                     !Config.getAuthenticationBean().getData().get(0).getUserOutputMode().equals("AnalogSignal")){
+                try {
+                    IDCardReaderThread.stop();
+                    IDCardReaderThread.close();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
                 try {
                     newIdCardStrarHandler.removeCallbacks(newIdCardStrarRunnable);
                     newIdCardStrarHandler.removeCallbacksAndMessages(null);
@@ -2941,16 +2940,8 @@ import static com.telpo.facenormal.utile.Config.CheckList;
                 }
             }
         } else if (eve.getMsg().equals("ENUSBReceiveSignal")) {
-            AppLogUtils.e(true, "USB广播信号","接收到USB拔出广播信号");
-            if (!(Build.MODEL.indexOf("F2")!=-1|(Build.MODEL.indexOf("TPS980")!=-1))&&
-                    !Config.getAuthenticationBean().getData().get(0).getUserOutputMode().equals("AnalogSignal")){
-                try {
-                    IDCardReaderThread.stop();
-                    IDCardReaderThread.close();
-                } catch (Exception e) {
-                    throw new RuntimeException(e);
-                }
-            }
+           // AppLogUtils.e(true, "USB广播信号","接收到USB拔出广播信号");
+            newIdCard = "PullUSB";
         } else {
             if (LoadingLocally_NumberOfVisitors != null) {
                 LoadingLocally_NumberOfVisitors.setText(Config.openTimes + "/" + Config.PassableOpenTimes);
@@ -3928,16 +3919,18 @@ import static com.telpo.facenormal.utile.Config.CheckList;
     /**
      * 新中新身份证阅读器
      */
+    private String newIdCard="init";
     class MyTimer extends Thread {
         @Override
         public void run() {
-            if (IDCardReaderThread.getInstance()==null){
-                return;
-            }
             while (IDCardReaderThread.getInstance().isReading()) {
+                if (newIdCard.equals("PullUSB")||newIdCard.equals("ERROR")){
+                    newIdCard = "stop";
+                    break;
+                }
                 newIdCardHandler.obtainMessage(UPDATE_READER_STATUS).sendToTarget();
                 try {
-                    Thread.sleep(500);
+                    Thread.sleep(1000);
                 } catch (InterruptedException e) {
                     e.printStackTrace();
                 }