From 82aa1c4c07f1547961421c6c590d6a0e679ac7d5 Mon Sep 17 00:00:00 2001 From: snickersun Date: Fri, 28 Aug 2020 19:19:38 +0800 Subject: [PATCH] =?utf8?q?=E5=8F=91=E7=8E=B0=E7=BD=91=E7=BB=9C=E5=8D=B3?= =?utf8?q?=E4=BD=BF=E9=80=9A=E8=BF=87=E5=BF=83=E8=B7=B3=E9=87=8D=E5=8F=91?= =?utf8?q?=E6=9C=BA=E5=88=B6=EF=BC=8C=E4=B9=9F=E6=97=A0=E6=B3=95=E8=A7=A3?= =?utf8?q?=E5=86=B3=E9=95=BF=E6=97=B6=E9=97=B4=20socket=E5=81=87=E9=93=BE?= =?utf8?q?=E6=8E=A5=E7=9A=84=E6=83=85=E5=86=B5=E3=80=82=E5=9B=A0=E6=AD=A4?= =?utf8?q?=E6=B7=BB=E5=8A=A015=E5=88=86=E9=92=9F=EF=BC=883=E6=AC=A1?= =?utf8?q?=E5=BF=83=E8=B7=B3=EF=BC=89=E9=93=BE=E6=8E=A5=E6=9C=8D=E5=8A=A1?= =?utf8?q?=E5=99=A8=E6=97=A0=E5=8F=8D=E9=A6=88=E5=90=8E=20=E8=87=AA?= =?utf8?q?=E4=B8=BB=E6=96=AD=E5=BC=80=E7=BD=91=E7=BB=9C=E7=9A=84=E6=9C=BA?= =?utf8?q?=E5=88=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../enqualcomm/support/service/KeepAlive.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java b/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java index c123011d..445603d8 100644 --- a/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java +++ b/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java @@ -110,18 +110,26 @@ public class KeepAlive extends AbstractConnectionService { //更新系统的IMEI boolean ret=DeviceInfoUtil.updateImei(mRuntime); ICLogger.i("Update IMEI "+ret); - if (is_login_send_success) { + + //只有曾经login成功过,且上一次成功时间超过15分钟,才会自主断开网络。 + long currenttime=System.currentTimeMillis(); + ICLogger.i("只有曾经login或者心跳发送成功过,且上一次成功时间超过15分钟,才会自主断开网络! last longin time "+ + mRuntime.lastLoginSuccessTime+" ms from last login time "+(currenttime-mRuntime.lastLoginSuccessTime)); + if ((mRuntime.lastLoginSuccessTime>0) && ((currenttime- mRuntime.lastLoginSuccessTime) > 15 * 60 * 1000)) { + ICLogger.i("超时自主断开网络!"); + CoreService.getInstance().disconnect_server(); + }else { + if (is_login_send_success) { connection.send(protocolAPIHelper.getHeartbeatMSG(mRuntime)); Observable.timer(1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { - connection.send(protocolAPIHelper.getBindingMSG(mRuntime)); - - } + public void call(Long param1Long) { + connection.send(protocolAPIHelper.getBindingMSG(mRuntime)); + } }); + } else { + connection.send(protocolAPIHelper.getLoginMSG(mRuntime)); + } } - else - connection.send(protocolAPIHelper.getLoginMSG(mRuntime)); - } } @@ -313,7 +321,7 @@ public class KeepAlive extends AbstractConnectionService { paramRuntime.setServerProtocolConnected(true); // isConnected = true; is_heartBeat_send_success=true; - + paramRuntime.lastLoginSuccessTime=System.currentTimeMillis(); // LauncherCtrl.getInstance(this.mContext).setStatusBarIcon("server_connected", STATUS_BAR_STATE_SERVER_CONNECTED_ON); // Deliver.triggerSendThread(); //链接上就尝试清除 buffer中的数据 @@ -325,7 +333,7 @@ public class KeepAlive extends AbstractConnectionService { } }else if (paramStringMessage.cmd().equals("login")) { //广播服务器连接成功的消息 - // paramRuntime.getContextProxy().sendBroadcastServerConnectionChanged(true); + paramRuntime.getContextProxy().sendBroadcastServerConnectionChanged(true); //登录包收到就停止重链接服务器 CoreService.getInstance().stopConnectionRetryTimer(); is_login_send_success=true; @@ -333,6 +341,8 @@ public class KeepAlive extends AbstractConnectionService { //心跳开始发送的时候,先重置response检测标志 is_heartBeat_send_success=false; + + paramRuntime.lastLoginSuccessTime=System.currentTimeMillis(); //发送心跳包 Observable.timer(3500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { public void call(Long param1Long) { -- 2.17.1