update:2019.04.11
fix:修复状态栏管控 add:增加OTG管控
This commit is contained in:
@@ -16,8 +16,8 @@ android {
|
||||
targetSdkVersion 26
|
||||
// versionCode 85
|
||||
// versionName "2.0.4.6"//正式jiaoguanyi.com
|
||||
versionCode 113
|
||||
versionName "2.7.5"//测试jiaoguanyi.cn
|
||||
versionCode 117
|
||||
versionName "2.7.9"//测试jiaoguanyi.cn
|
||||
multiDexEnabled true
|
||||
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
@@ -155,7 +155,8 @@ dependencies {
|
||||
|
||||
implementation 'com.github.tianma8023:NetDetector:v0.2.0'
|
||||
implementation 'com.android.support:cardview-v7:26.1.0'
|
||||
implementation "org.java-websocket:Java-WebSocket:1.4.0"
|
||||
|
||||
implementation "org.java-websocket:Java-WebSocket:1.4.1"
|
||||
|
||||
implementation 'com.google.zxing:core:3.2.1'
|
||||
implementation 'com.hjq:xxpermissions:6.0'
|
||||
|
||||
@@ -472,7 +472,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
Log.e("onSuccess", s);
|
||||
Log.e("getSerial", Utils.getSerial());
|
||||
com.alibaba.fastjson.JSONObject msgObject = JSON.parseObject(s);
|
||||
Log.e("getForceDownload", s);
|
||||
Log.e("getLockedState", s);
|
||||
Integer code = (msgObject.getInteger("code"));
|
||||
if (code == 200) {
|
||||
com.alibaba.fastjson.JSONObject dataArray = msgObject.getJSONObject("data");
|
||||
@@ -515,7 +515,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
getAppInfo();//上传APP信息
|
||||
getSystemSetting();//设置系统管控
|
||||
getNetAndLaunchSetting();//联网管控
|
||||
Aria.download(this).resumeAllTask();
|
||||
Aria.download(this).removeAllTask(true);
|
||||
// getForceDownload();//强制下载apk
|
||||
resetDevice();//恢复出厂设置
|
||||
// fromNetToUpdate();
|
||||
@@ -1079,7 +1079,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
.subscribe(new Observer<ForceDownloadBean>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("mjhseng", "forceDownloadApi---onSubscribe");
|
||||
Log.e("getForceDownload", "forceDownloadApi---onSubscribe");
|
||||
|
||||
}
|
||||
|
||||
@@ -1096,12 +1096,12 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("mjsheng", "forceDownloadApi=onError:");
|
||||
Log.e("getForceDownload", "forceDownloadApi=onError:");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("mjhseng", "forceDownloadApi---onComplete");
|
||||
Log.e("getForceDownload", "forceDownloadApi---onComplete");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1362,6 +1362,23 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
sendBroadcast(usbIntent);
|
||||
}
|
||||
|
||||
|
||||
//otg开关
|
||||
int setting_otg = changeNum(data.optInt("setting_otg"));
|
||||
Log.e("SystemSetting", "setting_otg---------" + setting_otg);
|
||||
String otgStatus = "";
|
||||
switch (setting_otg) {
|
||||
case 0:
|
||||
otgStatus = "qch_otg_open";
|
||||
break;
|
||||
case 1:
|
||||
otgStatus = "qch_otg_forbid";
|
||||
break;
|
||||
}
|
||||
Intent otgIntent = new Intent(otgStatus);
|
||||
sendBroadcast(otgIntent);
|
||||
|
||||
//蓝牙开关
|
||||
int setting_bluetooth = changeNum(data.optInt("setting_bluetooth"));
|
||||
boolean qch_bt_forbid_on = Settings.System.putInt(getContentResolver(), "qch_bt_forbid_on", setting_bluetooth);
|
||||
Log.e("SystemSetting", "qch_bt_forbid_on---------" + qch_bt_forbid_on);
|
||||
@@ -1392,7 +1409,19 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
if (oldNum != setting_statusbar) {
|
||||
boolean qch_hide_statusBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_statusBar", setting_statusbar);
|
||||
Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar);
|
||||
String statusbarStatus = "";
|
||||
switch (setting_statusbar) {
|
||||
case 0:
|
||||
statusbarStatus = "qch_show_statusBar";
|
||||
break;
|
||||
case 1:
|
||||
statusbarStatus = "qch_hide_statusBar";
|
||||
break;
|
||||
}
|
||||
Intent statusIntent = new Intent(statusbarStatus);
|
||||
mContext.sendBroadcast(statusIntent);
|
||||
}
|
||||
|
||||
//摄像头开关
|
||||
int setting_camera = changeNum(data.optInt("setting_camera"));
|
||||
Log.e("SystemSetting", "setting_camera---------" + setting_camera);
|
||||
|
||||
@@ -130,6 +130,22 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
mContext.sendBroadcast(usbIntent);
|
||||
}
|
||||
|
||||
//otg开关
|
||||
int setting_otg = changeNum(data.optInt("setting_otg"));
|
||||
Log.e("SystemSetting", "setting_otg---------" + setting_otg);
|
||||
String otgStatus = "";
|
||||
switch (setting_otg) {
|
||||
case 0:
|
||||
otgStatus = "qch_otg_open";
|
||||
break;
|
||||
case 1:
|
||||
otgStatus = "qch_otg_forbid";
|
||||
break;
|
||||
}
|
||||
Intent otgIntent = new Intent(otgStatus);
|
||||
mContext.sendBroadcast(otgIntent);
|
||||
|
||||
//蓝牙开关
|
||||
int setting_bluetooth = changeNum(data.optInt("setting_bluetooth"));
|
||||
boolean qch_bt_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_bt_forbid_on", setting_bluetooth);
|
||||
Log.e("SystemSetting", "qch_bt_forbid_on---------" + setting_bluetooth);
|
||||
@@ -162,7 +178,19 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
if (oldNum != setting_statusbar) {
|
||||
boolean qch_hide_statusBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_statusBar", setting_statusbar);
|
||||
Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar);
|
||||
String statusbarStatus = "";
|
||||
switch (setting_statusbar) {
|
||||
case 0:
|
||||
statusbarStatus = "qch_show_statusBar";
|
||||
break;
|
||||
case 1:
|
||||
statusbarStatus = "qch_hide_statusBar";
|
||||
break;
|
||||
}
|
||||
Intent statusIntent = new Intent(statusbarStatus);
|
||||
mContext.sendBroadcast(statusIntent);
|
||||
}
|
||||
|
||||
//摄像头开关
|
||||
int setting_camera = changeNum(data.optInt("setting_camera"));
|
||||
Log.e("SystemSetting", "setting_camera---------" + setting_camera);
|
||||
@@ -367,39 +395,45 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
|
||||
|
||||
private void getDeselectID() {
|
||||
Network.getDeselectIDApi().getDeselectIDApi("YTM3YTAxNTJmMmZmNzkyM2E2YzIwZjlhZTc0NzNmMGI=", Utils.getSerial()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ResponseBody>() {
|
||||
public void onComplete() {
|
||||
}
|
||||
|
||||
public void onError(Throwable param1Throwable) {
|
||||
Log.e("mjsheng", "DeselectIDApi=onError:");
|
||||
}
|
||||
|
||||
public void onNext(ResponseBody param1ResponseBody) {
|
||||
try {
|
||||
String str1;
|
||||
String str2 = param1ResponseBody.string();
|
||||
Log.e("mjsheng", str2);
|
||||
JSONObject jSONObject = new JSONObject(str2);
|
||||
switch (Integer.valueOf(jSONObject.optInt("code")).intValue()) {
|
||||
case 200:
|
||||
str1 = jSONObject.getJSONObject("data").optString("ids");
|
||||
str2 = jSONObject.getJSONObject("data").optString("package");
|
||||
writeDeselectIDtoSystem(str1, str2);
|
||||
return;
|
||||
Network.getDeselectIDApi()
|
||||
.getDeselectIDApi("YTM3YTAxNTJmMmZmNzkyM2E2YzIwZjlhZTc0NzNmMGI=",
|
||||
Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<ResponseBody>() {
|
||||
public void onComplete() {
|
||||
}
|
||||
Log.e("mjsheng", "getDeselectID---code is -200");
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
Log.e("mjsheng", "getDeselectID---woring----" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void onSubscribe(Disposable param1Disposable) {
|
||||
}
|
||||
});
|
||||
public void onError(Throwable param1Throwable) {
|
||||
Log.e("mjsheng", "DeselectIDApi=onError:");
|
||||
}
|
||||
|
||||
public void onNext(ResponseBody param1ResponseBody) {
|
||||
try {
|
||||
String str1;
|
||||
String str2 = param1ResponseBody.string();
|
||||
Log.e("mjsheng", str2);
|
||||
JSONObject jSONObject = new JSONObject(str2);
|
||||
switch (Integer.valueOf(jSONObject.optInt("code")).intValue()) {
|
||||
case 200:
|
||||
str1 = jSONObject.getJSONObject("data").optString("ids");
|
||||
str2 = jSONObject.getJSONObject("data").optString("package");
|
||||
writeDeselectIDtoSystem(str1, str2);
|
||||
return;
|
||||
}
|
||||
Log.e("mjsheng", "getDeselectID---code is -200");
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
Log.e("mjsheng", "getDeselectID---woring----" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void onSubscribe(Disposable param1Disposable) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,11 +19,13 @@ import android.util.Log;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.mjsheng.myappstore.KeepAliveConnection;
|
||||
import com.mjsheng.myappstore.utils.ApkUtils;
|
||||
import com.mjsheng.myappstore.utils.ServiceAliveUtils;
|
||||
import com.mjsheng.myappstore.utils.ToastUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -82,18 +84,18 @@ public class GuardService extends Service {
|
||||
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@Download.onTaskRunning
|
||||
protected void running(com.arialyy.aria.core.download.DownloadTask task) {
|
||||
Log.e("info", "正在下载=--------------::" + task.getState() + "-------" + task.getPercent() + "-------" + task.getExtendField());
|
||||
protected void running(DownloadTask task) {
|
||||
Log.e("aria", "正在下载=--------------::" + task.getState() + "-------" + task.getPercent() + "-------" + task.getExtendField());
|
||||
ToastUtils.showShort("正在下载=--------------::" + task.getExtendField() + "-------" + task.getPercent());
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(com.arialyy.aria.core.download.DownloadTask task) {
|
||||
void taskComplete(DownloadTask task) {
|
||||
//在这里处理任务完成的状态
|
||||
final String filepath = task.getDownloadPath();
|
||||
final String packageName = task.getExtendField();
|
||||
Log.e("mjsheng", "downloadPath::" + filepath);
|
||||
Log.e("mjsheng", "extendField::" + packageName);
|
||||
Log.e("aria", "downloadPath::" + filepath);
|
||||
Log.e("aria", "extendField::" + packageName);
|
||||
String s = Settings.System.getString(getContentResolver(), "qch_app_forbid");
|
||||
String s1 = s;
|
||||
if (s != null && !s.contains(packageName)) {
|
||||
@@ -106,7 +108,14 @@ public class GuardService extends Service {
|
||||
ApkUtils.installApp(GuardService.this, filepath);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
void taskFail(DownloadTask task) {
|
||||
final String filepath = task.getDownloadPath();
|
||||
final String packageName = task.getExtendField();
|
||||
Log.e("aria", "下载失败:" + filepath);
|
||||
ToastUtil.show("下载失败:" + packageName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,10 @@ import com.blankj.utilcode.util.EncryptUtils;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.PathUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.mjsheng.myappstore.BuildConfig;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.StringCallback;
|
||||
import com.mjsheng.myappstore.BuildConfig;
|
||||
import com.mjsheng.myappstore.MyApplication;
|
||||
import com.mjsheng.myappstore.activity.MainActivity;
|
||||
import com.mjsheng.myappstore.bean.ForceDownloadBean;
|
||||
import com.mjsheng.myappstore.bean.ForceDownloadData;
|
||||
import com.mjsheng.myappstore.bean.NetAndLaunchBean;
|
||||
@@ -46,13 +45,10 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import cn.jpush.android.api.JPushInterface;
|
||||
import cn.jpush.android.api.TagAliasCallback;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.Nullable;
|
||||
@@ -95,7 +91,8 @@ public class InitJpushServer extends Service {
|
||||
// getNetworkState();
|
||||
Log.e("InitJpushServer", "onStartCommand");
|
||||
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
// return super.onStartCommand(intent, flags, startId);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
|
||||
@@ -367,7 +364,7 @@ public class InitJpushServer extends Service {
|
||||
.subscribe(new Observer<ForceDownloadBean>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("initmjsheng", "forceDownloadApi---onSubscribe");
|
||||
Log.e("getForceDownload", "forceDownloadApi---onSubscribe");
|
||||
|
||||
}
|
||||
|
||||
@@ -384,12 +381,12 @@ public class InitJpushServer extends Service {
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("mjsheng", "forceDownloadApi=onError:");
|
||||
Log.e("getForceDownload", "forceDownloadApi=onError:");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("initmjsheng", "forceDownloadApi---onComplete");
|
||||
Log.e("getForceDownload", "forceDownloadApi---onComplete");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -668,7 +665,7 @@ public class InitJpushServer extends Service {
|
||||
Log.e("onSuccess", s);
|
||||
Log.e("getSerial", Utils.getSerial());
|
||||
com.alibaba.fastjson.JSONObject msgObject = JSON.parseObject(s);
|
||||
Log.e("getForceDownload", s);
|
||||
Log.e("getLockedState", s);
|
||||
Integer code = (msgObject.getInteger("code"));
|
||||
if (code == 200) {
|
||||
com.alibaba.fastjson.JSONObject dataArray = msgObject.getJSONObject("data");
|
||||
@@ -690,7 +687,7 @@ public class InitJpushServer extends Service {
|
||||
getDeselectID();
|
||||
getDeselectBrowerID();
|
||||
getNetAndLaunchSetting();
|
||||
Aria.download(this).resumeAllTask();
|
||||
Aria.download(this).removeAllTask(true);
|
||||
// getForceDownload();
|
||||
getSystemSetting();//从后台获取功能状态
|
||||
resetDevice();
|
||||
@@ -763,6 +760,22 @@ public class InitJpushServer extends Service {
|
||||
sendBroadcast(usbIntent);
|
||||
}
|
||||
|
||||
//otg开关
|
||||
int setting_otg = changeNum(data.optInt("setting_otg"));
|
||||
Log.e("SystemSetting", "setting_otg---------" + setting_otg);
|
||||
String otgStatus = "";
|
||||
switch (setting_otg) {
|
||||
case 0:
|
||||
otgStatus = "qch_otg_open";
|
||||
break;
|
||||
case 1:
|
||||
otgStatus = "qch_otg_forbid";
|
||||
break;
|
||||
}
|
||||
Intent otgIntent = new Intent(otgStatus);
|
||||
sendBroadcast(otgIntent);
|
||||
|
||||
//蓝牙开关
|
||||
int setting_bluetooth = changeNum(data.optInt("setting_bluetooth"));
|
||||
boolean qch_bt_forbid_on = Settings.System.putInt(getApplicationContext().getContentResolver(), "qch_bt_forbid_on", setting_bluetooth);
|
||||
Log.e("SystemSetting", "qch_bt_forbid_on---------" + qch_bt_forbid_on);
|
||||
@@ -792,7 +805,20 @@ public class InitJpushServer extends Service {
|
||||
if (oldNum != setting_statusbar) {
|
||||
boolean qch_hide_statusBar = Settings.System.putInt(getContentResolver(), "qch_hide_statusBar", setting_statusbar);
|
||||
Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar);
|
||||
String statusbarStatus = "";
|
||||
switch (setting_statusbar) {
|
||||
case 0:
|
||||
statusbarStatus = "qch_show_statusBar";
|
||||
break;
|
||||
case 1:
|
||||
statusbarStatus = "qch_hide_statusBar";
|
||||
break;
|
||||
}
|
||||
Intent statusIntent = new Intent(statusbarStatus);
|
||||
sendBroadcast(statusIntent);
|
||||
}
|
||||
|
||||
|
||||
//摄像头开关
|
||||
int setting_camera = changeNum(data.optInt("setting_camera"));
|
||||
Log.e("SystemSetting", "setting_camera---------" + setting_camera);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mjsheng.myappstore.server;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.drafts.Draft_6455;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class JWebSocketClient extends WebSocketClient {
|
||||
public JWebSocketClient(URI serverUri) {
|
||||
super(serverUri, new Draft_6455());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(ServerHandshake handshakedata) {
|
||||
Log.e("JWebSocketClient", "onOpen()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
Log.e("JWebSocketClient", "onMessage()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int code, String reason, boolean remote) {
|
||||
Log.e("JWebSocketClient", "onClose():" + reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception ex) {
|
||||
Log.e("JWebSocketClient", "onError():" + ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
@@ -24,7 +26,11 @@ import com.mjsheng.myappstore.bean.AppDateInfo;
|
||||
import com.mjsheng.myappstore.bean.FileData;
|
||||
import com.mjsheng.myappstore.utils.ApkUtils;
|
||||
import com.mjsheng.myappstore.utils.ServiceAliveUtils;
|
||||
import com.mjsheng.myappstore.utils.Utils;
|
||||
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
@@ -34,6 +40,15 @@ import java.nio.file.Path;
|
||||
* @time Created by 2018/8/17 11:26
|
||||
*/
|
||||
public class StepService extends Service {
|
||||
public JWebSocketClient client;
|
||||
private JWebSocketClientBinder mBinder = new JWebSocketClientBinder();
|
||||
|
||||
//用于Activity和service通讯
|
||||
public class JWebSocketClientBinder extends Binder {
|
||||
public StepService getService() {
|
||||
return StepService.this;
|
||||
}
|
||||
}
|
||||
|
||||
private final static String TAG = StepService.class.getSimpleName();
|
||||
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||
@@ -78,9 +93,128 @@ public class StepService extends Service {
|
||||
// } catch (Exception e) {
|
||||
// Log.e("fht", e.getMessage());
|
||||
// }
|
||||
|
||||
//初始化websocket
|
||||
initSocketClient();
|
||||
mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测
|
||||
bindService(new Intent(this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
closeConnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化websocket连接
|
||||
*/
|
||||
private void initSocketClient() {
|
||||
URI uri = URI.create("ws://47.107.133.19:2345");
|
||||
// URI uri = URI.create("ws://echo.websocket.org");
|
||||
// URI uri = URI.create("ws://123.207.136.134:9010/ajaxchattest");
|
||||
client = new JWebSocketClient(uri) {
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
Log.i("JWebSocketClientService", "收到服务器发来的消息:" + message + "?");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(ServerHandshake handshakedata) {
|
||||
super.onOpen(handshakedata);
|
||||
Log.i("JWebSocketClientService", "websocket连接成功");
|
||||
}
|
||||
};
|
||||
connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接websocket
|
||||
*/
|
||||
private void connect() {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//connectBlocking多出一个等待操作,会先连接再发送,否则未连接发送会报错
|
||||
Log.i("JWebSocketClientService", "websocket链接中");
|
||||
client.connectBlocking();
|
||||
} catch (InterruptedException e) {
|
||||
Log.i("JWebSocketClientService", e.getMessage());
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
public void sendMsg(String msg) {
|
||||
if (null != client) {
|
||||
Log.i("JWebSocketClientService", "发送的消息:" + msg);
|
||||
client.send(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断开连接
|
||||
*/
|
||||
private void closeConnect() {
|
||||
try {
|
||||
if (null != client) {
|
||||
client.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
client = null;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------websocket心跳检测------------------------------------------------
|
||||
private static final long HEART_BEAT_RATE = 50 * 1000;//每隔50秒进行一次对长连接的心跳检测
|
||||
private Handler mHandler = new Handler();
|
||||
private Runnable heartBeatRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i("JWebSocketClientService", "心跳包检测websocket连接状态");
|
||||
if (client != null) {
|
||||
if (client.isOpen()) {
|
||||
Log.i("JWebSocketClientService", "websocket已连接");
|
||||
sendMsg(Utils.getSerial());
|
||||
} else if (client.isClosed()) {
|
||||
Log.i("JWebSocketClientService", "websocket重连中");
|
||||
reconnectWs();
|
||||
}
|
||||
} else {
|
||||
//如果client已为空,重新初始化连接
|
||||
client = null;
|
||||
initSocketClient();
|
||||
}
|
||||
//每隔一定的时间,对长连接进行一次心跳检测
|
||||
mHandler.postDelayed(this, HEART_BEAT_RATE);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 开启重连
|
||||
*/
|
||||
private void reconnectWs() {
|
||||
mHandler.removeCallbacks(heartBeatRunnable);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Log.i("JWebSocketClientService", "开启重连");
|
||||
client.reconnectBlocking();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,8 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
import com.lzy.okserver.download.DownloadInfo;
|
||||
import com.lzy.okserver.download.DownloadManager;
|
||||
import com.lzy.okserver.download.DownloadService;
|
||||
import com.mjsheng.myappstore.BuildConfig;
|
||||
import com.mjsheng.myappstore.R;
|
||||
import com.mjsheng.myappstore.bean.AppDateInfo;
|
||||
import com.mjsheng.myappstore.bean.AppDownloadInfo;
|
||||
import com.mjsheng.myappstore.bean.FileData;
|
||||
import com.mjsheng.myappstore.download.StorageUtils;
|
||||
import com.mjsheng.myappstore.utils.update.ToastTool;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
||||
Reference in New Issue
Block a user