Jelajahi Sumber

1.tcp断开连接后重连多次还是失败则重启app
2.优化左侧呼叫记录显示
3.发生crash重启app

weizhengliang 3 tahun lalu
induk
melakukan
96e8a514cd

+ 2 - 0
middleware/src/main/code/com/wdkl/ncs/android/middleware/common/Constants.kt

@@ -130,6 +130,8 @@ class Constants {
 
         val EVENT_JOIN_HOME_READY = 0x09
 
+        val EVENT_RESTART_APP = 0x10
+
         //手柄拿起
         val HOOK_OFF = "com.android.PhoneWinowManager.HOOK_OFF"
         //手柄放下

+ 13 - 22
middleware/src/main/code/com/wdkl/ncs/android/middleware/tcp/TcpClient.java

@@ -3,6 +3,9 @@ package com.wdkl.ncs.android.middleware.tcp;
 import android.util.Log;
 
 import com.wdkl.ncs.android.component.nursehome.common.Constants;
+import com.wdkl.ncs.android.middleware.utils.MessageEvent;
+
+import org.greenrobot.eventbus.EventBus;
 
 import java.util.Scanner;
 import java.util.concurrent.TimeUnit;
@@ -39,6 +42,7 @@ public class TcpClient {
     private Integer retrySeconds = 5;
     //重试计数
     private Integer retryTimes = 1;
+    private Integer reconnetTimes = 0;
     //tcp是否完成初始化
     private boolean inited = false;
 
@@ -111,20 +115,25 @@ public class TcpClient {
                         @Override
                         public void run() {
                             retryTimes++;
-                            if (retryTimes > 20) { //重试30次还没连成功,等10分钟后再试
+                            if (retryTimes > 30) { //重试30次还没连成功,等5分钟后再试
 //                                System.out.println("TcpClient 重试" + (retryTimes - 1) + "次,结束");
 //                                channel.close();
 //                                workGroup.shutdownGracefully();
 //                                //todo: 从API获取新的serverIP和serverPort,全新连接
 //                                TcpClient.getInstance().init(Constant.TCP_SERVER_URL, Constant.TCP_PORT, Constant.TCP_HEART_BEAT);
                                 retryTimes=1;
+                                reconnetTimes++;
                                 channelFuture.channel().eventLoop().schedule(new Runnable() {
                                     @Override
                                     public void run() {
-                                        System.out.println("TcpClientHandler 重新连接,第" + retryTimes + "次");
-                                        doConnect();
+                                        System.out.println("TcpClientHandler 重新连接,第" + retryTimes + "次" + ", 重试" + reconnetTimes + "次");
+                                        if (reconnetTimes > 2) {
+                                            EventBus.getDefault().post(new MessageEvent(0, Constants.Companion.getEVENT_RESTART_APP()));
+                                        } else {
+                                            doConnect();
+                                        }
                                     }
-                                }, 60*10, TimeUnit.SECONDS);
+                                }, 60*5, TimeUnit.SECONDS);
 
                             }else{
                                 doConnect();
@@ -162,22 +171,4 @@ public class TcpClient {
     public Channel getChannel() {
         return channel;
     }
-
-    //测试
-    public static void main(String[] args) {
-
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                TcpClient.getInstance().init("192.168.1.188", 5080, 9);
-            }
-        }).start();
-
-        Scanner scanner = new Scanner(System.in);
-        while (true) {
-            System.out.println("please type : ");
-            String line = scanner.nextLine();
-            TcpClient.getInstance().sendMsg(line);
-        }
-    }
 }

+ 7 - 3
nursehome/src/main/java/com/wdkl/ncs/android/component/nursehome/activity/NurseHomeActivity.kt

@@ -1200,7 +1200,7 @@ class NurseHomeActivity  : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
                         }
                     } else if (tcpModel.action == TcpAction.DeviceAction.DEVICE_REFRESH || tcpModel.action == TcpAction.DeviceAction.RESTART) {
                         if (!DeviceChannel.calling) {
-                            AppUpdateHelper.restartApp(this@NurseHomeActivity)
+                            AppUpdateHelper.restartApp(activity)
                         } else {
                             Constants.laterRestart = true
                         }
@@ -1250,7 +1250,7 @@ class NurseHomeActivity  : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
             Constants.EVENT_TCP_STATE -> {
                 updateTcpState()
                 //网络连接上,如果tcp是断开状态则重新连接
-                if (!TcpClientHandler.connected && NetHelper.getInstance().networkAvailable()) {
+                /*if (!TcpClientHandler.connected && NetHelper.getInstance().networkAvailable()) {
                     if (TcpClient.getInstance().getChannel() == null || !TcpClient.getInstance().getChannel().isOpen()) {
                         Thread ( Runnable {
                             run {
@@ -1258,7 +1258,11 @@ class NurseHomeActivity  : BaseActivity<NurseHomeActivityPresenter, ActivityNurs
                             }
                         }).start()
                     }
-                }
+                }*/
+            }
+
+            Constants.EVENT_RESTART_APP -> {
+                AppUpdateHelper.restartApp(activity)
             }
 
             //对方发起sip通话请求,我方接受

+ 2 - 2
nursehome/src/main/java/com/wdkl/ncs/android/component/nursehome/adapter/CallRecordsItemAdapter.kt

@@ -168,7 +168,7 @@ class CallRecordsItemAdapter(val data:ArrayList<InteractionVO>) : BaseDelegateAd
             }
 
             binding.callListReply.setOnClickListener {
-                if (Constants.ids != null) {
+                if (Constants.ids != 0) {
                     if (itemData.actionDirectionType == 1 && itemData.fromDeviceId != null && itemData.fromDeviceId != Constants.ids!!.toInt()) {
                         VoiceUtil.startAudioCall(Constants.ids, itemData.fromDeviceId)
                         Constants.call_type = 0
@@ -182,7 +182,7 @@ class CallRecordsItemAdapter(val data:ArrayList<InteractionVO>) : BaseDelegateAd
             }
 
             binding.callSosReply.setOnClickListener {
-                if (Constants.ids != null) {
+                if (Constants.ids != 0) {
                     OtherUtil.cancelSosCall(Constants.ids, itemData.fromDeviceId, itemData.id)
                     LedHelper.updateLedInfo(itemData, false, true)
                     EventBus.getDefault().post(MessageEvent(0, Constants.EVENT_REFRESH_CALL_LIST))

+ 24 - 14
nursehome/src/main/java/com/wdkl/ncs/android/component/nursehome/fragment/CallRecordsFragment.kt

@@ -92,18 +92,22 @@ class CallRecordsFragment: BaseFragment<CallRecordsFragmentPresenter, FragmentCa
     override fun onClick(p0: View) {
         when(p0.id){
             R.id.no_answer_calls_linlyout -> {
-                call_records_imagev.visibility = View.GONE
-                no_answer_calls_imagev.visibility = View.VISIBLE
-                page = 1
-                listType = 1
-                presenter.loadFloor(page, pageSize, Constants.part_id, listType, eventName)
+                if (listType != 1) {
+                    call_records_imagev.visibility = View.GONE
+                    no_answer_calls_imagev.visibility = View.VISIBLE
+                    page = 1
+                    listType = 1
+                    presenter.loadFloor(page, pageSize, Constants.part_id, listType, eventName)
+                }
             }
             R.id.call_records_linlyout -> {
-                no_answer_calls_imagev.visibility = View.GONE
-                call_records_imagev.visibility = View.VISIBLE
-                page = 1
-                listType = 0
-                presenter.loadFloor(page, pageSize, Constants.part_id, listType, eventName)
+                if (listType != 0) {
+                    no_answer_calls_imagev.visibility = View.GONE
+                    call_records_imagev.visibility = View.VISIBLE
+                    page = 1
+                    listType = 0
+                    presenter.loadFloor(page, pageSize, Constants.part_id, listType, eventName)
+                }
             }
             R.id.other_linlyout -> {
 
@@ -142,8 +146,11 @@ class CallRecordsFragment: BaseFragment<CallRecordsFragmentPresenter, FragmentCa
             adapter.data.clear()
             if (data.size > 0) {
                 for (item in data) {
-                    if (item.actionDirectionType == 1 || item.actionDirectionType == 2 || item.actionDirectionType == 3) {
-                        adapter.data.add(item)
+                    if (TcpType.VIDEO.name == item.actionType || TcpType.VOICE.name == item.actionType
+                        || TcpType.ENTRACEGUARD.name == item.actionType || TcpType.SOS.name == item.actionType) {
+                        if (item.actionDirectionType == 1 || item.actionDirectionType == 2 || item.actionDirectionType == 3) {
+                            adapter.data.add(item)
+                        }
                     }
                 }
                 Log.i("abc1"," " + adapter.data.size);
@@ -153,8 +160,11 @@ class CallRecordsFragment: BaseFragment<CallRecordsFragmentPresenter, FragmentCa
         } else {
             if (data.size > 0) {
                 for (item in data) {
-                    if (item.actionDirectionType == 1 || item.actionDirectionType == 2 || item.actionDirectionType == 3) {
-                        adapter.data.add(item)
+                    if (TcpType.VIDEO.name == item.actionType || TcpType.VOICE.name == item.actionType
+                        || TcpType.ENTRACEGUARD.name == item.actionType || TcpType.SOS.name == item.actionType) {
+                        if (item.actionDirectionType == 1 || item.actionDirectionType == 2 || item.actionDirectionType == 3) {
+                            adapter.data.add(item)
+                        }
                     }
                 }
                 adapter.notifyDataSetChanged()

+ 8 - 0
nursehome/src/main/java/com/wdkl/ncs/android/component/nursehome/util/AppUpdateHelper.java

@@ -14,6 +14,9 @@ import android.support.v4.content.FileProvider;
 import android.util.Log;
 
 import com.wdkl.ncs.android.component.nursehome.activity.RegisterActivity;
+import com.wdkl.skywebrtc.CallSession;
+import com.wdkl.skywebrtc.EnumType;
+import com.wdkl.skywebrtc.SkyEngineKit;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -220,6 +223,11 @@ public class AppUpdateHelper {
     }
 
     public static void restartApp(Context context) {
+        CallSession session= SkyEngineKit.Instance().getCurrentSession();
+        if(session!=null&&session.getState()!= EnumType.CallState.Idle){
+            SkyEngineKit.Instance().endCall();
+        }
+
         //重新启动app
         Intent mStartActivity = new Intent(context.getApplicationContext(), RegisterActivity.class);
         mStartActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

+ 7 - 29
nursehome/src/main/java/com/wdkl/ncs/android/component/nursehome/util/XCrashUtils.java

@@ -71,10 +71,8 @@ public class XCrashUtils {
             if (!BuildConfig.DEBUG) {
                 uploadCrashLog(logPath);
             } else {
-                AppUtils.relaunchApp(true);
+                AppUpdateHelper.restartApp(app);
             }
-
-            //restartApp();
         }
     };
 
@@ -84,7 +82,7 @@ public class XCrashUtils {
         public void onCrash(String logPath, String emergency) {
             Log.d(TAG, "log path: " + (logPath != null ? logPath : "(null)") + ", emergency: " + (emergency != null ? emergency : "(null)"));
 
-            if (emergency != null) {
+            /*if (emergency != null) {
                 debug(logPath, emergency);
 
                 // Disk is exhausted, send crash report immediately.
@@ -100,12 +98,12 @@ public class XCrashUtils {
                 // TombstoneManager.appendSection(logPath, "expanded_key_3", "expanded_content_row_1\n\nexpanded_content_row_2");
 
                 debug(logPath, null);
-            }
+            }*/
 
             // Disk is exhausted, send crash report immediately.
             //sendThenDeleteCrashLog(logPath, emergency);
 
-            AppUtils.relaunchApp(true);
+            AppUpdateHelper.restartApp(app);
         }
     };
 
@@ -144,7 +142,7 @@ public class XCrashUtils {
                 @Override
                 public void onFail() {
                     Log.e(TAG,"错误日志文件上传失败!");
-                    AppUtils.relaunchApp(true);
+                    AppUpdateHelper.restartApp(app);
                 }
 
                 @Override
@@ -185,7 +183,7 @@ public class XCrashUtils {
                 @Override
                 public void onFailure(Call call, IOException e) {
                     Log.e(TAG,"错误日志名称上传失败"+e.getMessage());
-                    AppUtils.relaunchApp(true);
+                    AppUpdateHelper.restartApp(app);
                 }
 
                 @Override
@@ -194,7 +192,7 @@ public class XCrashUtils {
                     TombstoneManager.deleteTombstone(logPath);
                     //String data = response.body().string();
                     //Log.d(TAG,"错误日志数据 data "+data);
-                    AppUtils.relaunchApp(true);
+                    AppUpdateHelper.restartApp(app);
                 }
             });
         } catch (Exception e) {
@@ -232,24 +230,4 @@ public class XCrashUtils {
         }
     }
 
-    private void restartApp() {
-        Constants.Companion.setCALL_STATE(Constants.Companion.getCALL_STANDBY());
-        DeviceChannel.calling = false;
-        CallSession session= SkyEngineKit.Instance().getCurrentSession();
-        if(session!=null&&session.getState()!= EnumType.CallState.Idle){
-            SkyEngineKit.Instance().endCall();
-        }
-
-        //重新启动app
-        Intent mStartActivity = new Intent(app.getApplicationContext(), RegisterActivity.class);
-        mStartActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
-        int mPendingIntentId = 123456;
-        PendingIntent mPendingIntent = PendingIntent.getActivity(app.getApplicationContext(), mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
-        AlarmManager mgr = (AlarmManager) app.getApplicationContext().getSystemService(Context.ALARM_SERVICE);
-        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, mPendingIntent);
-
-        android.os.Process.killProcess(android.os.Process.myPid());
-        System.exit(0);
-    }
-
 }