diff --git a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/ReconnectManager.java b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/ReconnectManager.java index 18c937617c..cfd95b97c6 100644 --- a/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/ReconnectManager.java +++ b/libraries/mogo-adas/src/main/java/com/zhidao/support/adas/high/common/ReconnectManager.java @@ -66,13 +66,13 @@ public class ReconnectManager { } else if (reconnectCount == 0) { return true; } else { - return currentCount < reconnectCount; + return currentCount <= reconnectCount; } } private void callOnReconnection(AdasConstants.IpcConnectionStatus status) { + currentCount++; if (isNeedReconnect()) { - currentCount++; listener.onReconnection(status); } else { stop(true); @@ -84,7 +84,7 @@ public class ReconnectManager { */ public synchronized void start() { if (isNeedReconnect()) { - if (!isReconnection.get()) { + if (!isReconnection()) { CupidLogUtils.log(TAG, "开始重连"); isReconnection.set(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && connectivityManager == null) { @@ -97,10 +97,8 @@ public class ReconnectManager { timer.schedule(new TimerTask() { @Override public void run() { - if (isNeedReconnect()) { + if (isReconnection()) { callOnReconnection(AdasConstants.IpcConnectionStatus.RECONNECTING_TIMER); - } else { - stop(true); } } }, RECONNECT_INTERVAL, RECONNECT_INTERVAL);//延时 @@ -117,6 +115,7 @@ public class ReconnectManager { } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && connectivityManager != null) { connectivityManager.unregisterNetworkCallback(networkCallback); + connectivityManager = null; } if (timer != null) { timer.cancel(); @@ -130,7 +129,7 @@ public class ReconnectManager { public void onAvailable(@NonNull Network network) { super.onAvailable(network); CupidLogUtils.log(TAG, "网络连接成功"); - if (isReconnection.get() && !isNetworkConnected()) { + if (isReconnection() && isNetworkConnected()) { callOnReconnection(AdasConstants.IpcConnectionStatus.RECONNECTING_NETWORK); } }