[8.2.0][adas] 修复重连管理器取消网络注册监听引起的崩溃问题,优化重连功能
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user