version:1.4
update:2021-10-21 10:14:40 fix: add:增加浏览器桌面检测升级,修复重复请求
This commit is contained in:
@@ -20,8 +20,6 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.aoleyun.sn.BuildConfig;
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.aoleyun.sn.KeepAliveConnection;
|
||||
import com.aoleyun.sn.network.NetInterfaceManager;
|
||||
import com.aoleyun.sn.utils.Logutils;
|
||||
import com.aoleyun.sn.utils.ServiceAliveUtils;
|
||||
import com.aoleyun.sn.utils.Utils;
|
||||
|
||||
@@ -61,7 +59,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||
Logutils.w(TAG, "StepService:建立链接");
|
||||
Log.w(TAG, "StepService:建立链接");
|
||||
boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(StepService.this, GuardService.class.getName());
|
||||
if (!isServiceRunning) {
|
||||
Intent i = new Intent(StepService.this, GuardService.class);
|
||||
@@ -99,7 +97,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
// startForeground(1, new Notification());
|
||||
// 绑定建立链接
|
||||
Logutils.e("JWebSocketClientService", "onStartCommand: ");
|
||||
Log.e("JWebSocketClientService", "onStartCommand: ");
|
||||
bindService(new Intent(this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
return START_STICKY;
|
||||
}
|
||||
@@ -117,6 +115,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
|
||||
filter.addAction(Intent.ACTION_USER_PRESENT);
|
||||
filter.addAction(Intent.ACTION_SHUTDOWN);
|
||||
filter.addAction(Intent.ACTION_REBOOT);
|
||||
filter.addAction(Intent.ACTION_FACTORY_RESET);
|
||||
filter.addAction(Intent.ACTION_MASTER_CLEAR);
|
||||
registerReceiver(screenLockReceiver, filter);
|
||||
@@ -139,6 +138,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
break;
|
||||
case Intent.ACTION_SCREEN_OFF:
|
||||
case Intent.ACTION_SHUTDOWN:
|
||||
case Intent.ACTION_REBOOT:
|
||||
case Intent.ACTION_FACTORY_RESET:
|
||||
case Intent.ACTION_MASTER_CLEAR:
|
||||
sendMsg(2);
|
||||
@@ -169,20 +169,20 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
client = new JWebSocketClient(uri) {
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
Logutils.i("JWebSocketClientService", "收到服务器发来的消息:" + message);
|
||||
Log.i("JWebSocketClientService", "收到服务器发来的消息:" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(ServerHandshake handshakedata) {
|
||||
super.onOpen(handshakedata);
|
||||
Logutils.i("JWebSocketClientService", "websocket连接成功");
|
||||
Log.i("JWebSocketClientService", "websocket连接成功");
|
||||
sendMsg(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int code, String reason, boolean remote) {
|
||||
super.onClose(code, reason, remote);
|
||||
Logutils.i("JWebSocketClientService", "websocket连接关闭");
|
||||
Log.i("JWebSocketClientService", "websocket连接关闭");
|
||||
// client.close();
|
||||
// initSocketClient();
|
||||
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
|
||||
@@ -192,7 +192,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
@Override
|
||||
public void onError(Exception ex) {
|
||||
super.onError(ex);
|
||||
Logutils.i("JWebSocketClientService", "websocket连接错误:" + ex.getMessage());
|
||||
Log.i("JWebSocketClientService", "websocket连接错误:" + ex.getMessage());
|
||||
// client.close();
|
||||
// initSocketClient();
|
||||
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
|
||||
@@ -211,10 +211,10 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
public void run() {
|
||||
try {
|
||||
//connectBlocking多出一个等待操作,会先连接再发送,否则未连接发送会报错
|
||||
Logutils.i("JWebSocketClientService", "websocket链接中");
|
||||
Log.i("JWebSocketClientService", "websocket链接中");
|
||||
client.connectBlocking();
|
||||
} catch (Exception e) {
|
||||
Logutils.i("JWebSocketClientService", e.getMessage());
|
||||
Log.i("JWebSocketClientService", e.getMessage());
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -236,7 +236,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
jsonObject.put("online", 1);
|
||||
}
|
||||
if (null != client) {
|
||||
Logutils.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString());
|
||||
Log.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString());
|
||||
client.send(jsonObject.toJSONString());
|
||||
}
|
||||
}
|
||||
@@ -247,10 +247,10 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
jsonObject.put("online", state);
|
||||
try {
|
||||
if (null != client) {
|
||||
Logutils.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString());
|
||||
Log.i("JWebSocketClientService", "发送的消息:" + jsonObject.toJSONString());
|
||||
client.send(jsonObject.toJSONString());
|
||||
} else {
|
||||
Logutils.i("JWebSocketClientService", "未连接");
|
||||
Log.i("JWebSocketClientService", "未连接");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "sendMsg: " + e.getMessage());
|
||||
@@ -278,13 +278,13 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
private Runnable heartBeatRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Logutils.i("JWebSocketClientService", "心跳包检测websocket连接状态");
|
||||
Log.i("JWebSocketClientService", "心跳包检测websocket连接状态");
|
||||
if (client != null) {
|
||||
if (client.isOpen()) {
|
||||
Logutils.i("JWebSocketClientService", "websocket已连接");
|
||||
Log.i("JWebSocketClientService", "websocket已连接");
|
||||
sendMsg();
|
||||
} else if (client.isClosed()) {
|
||||
Logutils.i("JWebSocketClientService", "websocket重连中");
|
||||
Log.i("JWebSocketClientService", "websocket重连中");
|
||||
reconnectWs();
|
||||
}
|
||||
} else {
|
||||
@@ -306,7 +306,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Logutils.i("JWebSocketClientService", "开启重连");
|
||||
Log.i("JWebSocketClientService", "开启重连");
|
||||
client.reconnectBlocking();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user