version:1.4
update:2021-10-21 10:14:40 fix: add:增加浏览器桌面检测升级,修复重复请求
This commit is contained in:
@@ -35,7 +35,6 @@ import com.aoleyun.sn.network.api.newapi.GetLockStateApi;
|
||||
import com.aoleyun.sn.receiver.BootReceiver;
|
||||
import com.aoleyun.sn.receiver.NewAppReceiver;
|
||||
import com.aoleyun.sn.utils.JGYUtils;
|
||||
import com.aoleyun.sn.utils.Logutils;
|
||||
import com.aoleyun.sn.utils.SPUtils;
|
||||
import com.aoleyun.sn.utils.XAPKUtils;
|
||||
import com.aoleyun.sn.KeepAliveConnection;
|
||||
@@ -75,7 +74,7 @@ public class GuardService extends Service {
|
||||
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||
Logutils.w(TAG, "GuardService:建立链接");
|
||||
Log.w(TAG, "GuardService:建立链接");
|
||||
boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(GuardService.this, StepService.class.getName());
|
||||
if (!isServiceRunning) {
|
||||
startService(new Intent(GuardService.this, StepService.class));
|
||||
@@ -119,7 +118,7 @@ public class GuardService extends Service {
|
||||
|
||||
@Override
|
||||
public void onNext(Long aLong) {
|
||||
Logutils.e(TAG, "timeObserver: onNext: " + aLong);
|
||||
Log.e(TAG, "timeObserver: onNext: " + aLong);
|
||||
startService(new Intent(GuardService.this, MainService.class));
|
||||
}
|
||||
|
||||
@@ -151,7 +150,7 @@ public class GuardService extends Service {
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Logutils.e(TAG, "onStartCommand: ");
|
||||
Log.e(TAG, "onStartCommand: ");
|
||||
Aria.init(this);
|
||||
Aria.download(this).register();
|
||||
// 绑定建立链接
|
||||
@@ -197,8 +196,12 @@ public class GuardService extends Service {
|
||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
filter.addAction(Intent.ACTION_USER_UNLOCKED);
|
||||
filter.addAction("android.intent.action.FACTORY_RESET");
|
||||
filter.addAction("android.intent.action.MASTER_CLEAR");
|
||||
filter.addAction(Intent.ACTION_FACTORY_RESET);
|
||||
filter.addAction(Intent.ACTION_MASTER_CLEAR);
|
||||
filter.addAction(Intent.ACTION_MASTER_CLEAR_NOTIFICATION);
|
||||
filter.addAction("android.intent.action.FORCE_FACTORY_RESET");
|
||||
filter.addAction(Intent.ACTION_SHUTDOWN);
|
||||
filter.addAction(Intent.ACTION_REBOOT);
|
||||
registerReceiver(presentReceiver, filter);
|
||||
}
|
||||
|
||||
@@ -206,7 +209,7 @@ public class GuardService extends Service {
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Logutils.e(TAG, "action:" + action);
|
||||
Log.e(TAG, "action:" + action);
|
||||
switch (action) {
|
||||
default:
|
||||
break;
|
||||
@@ -267,18 +270,50 @@ public class GuardService extends Service {
|
||||
sendScreenStatus(2);
|
||||
}
|
||||
break;
|
||||
case "android.intent.action.FACTORY_RESET":
|
||||
case "android.intent.action.MASTER_CLEAR":
|
||||
case "android.intent.action.MASTER_CLEAR_NOTIFICATION":
|
||||
case Intent.ACTION_SHUTDOWN:
|
||||
case Intent.ACTION_REBOOT:
|
||||
int restart_count = (int) SPUtils.get(context, "restart_count", 0);
|
||||
SPUtils.put(context, "restart_count", restart_count + 1);
|
||||
// android.os.Process.killProcess(android.os.Process.myPid());
|
||||
break;
|
||||
case Intent.ACTION_FACTORY_RESET:
|
||||
case Intent.ACTION_MASTER_CLEAR:
|
||||
case Intent.ACTION_MASTER_CLEAR_NOTIFICATION:
|
||||
case "android.intent.action.FORCE_FACTORY_RESET":
|
||||
Logutils.e("PresentReceiver", "MASTER_CLEAR");
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(0);
|
||||
sendRestoreTimes();
|
||||
Log.e("PresentReceiver", "MASTER_CLEAR");
|
||||
// android.os.Process.killProcess(android.os.Process.myPid());
|
||||
// System.exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendRestoreTimes() {
|
||||
NetInterfaceManager.getInstance().getRestoreTimesApi()
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("sendRestoreTimes", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("sendRestoreTimes", "onNext: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("sendRestoreTimes", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("sendRestoreTimes", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendScreenStatus(int status) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.client(NetInterfaceManager.getInstance().getOkHttpClient())
|
||||
@@ -378,7 +413,7 @@ public class GuardService extends Service {
|
||||
// 最大电量
|
||||
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
|
||||
int elec = (level * 100) / scale;
|
||||
// Logutils.e(TAG, "electricity:=" + elec + "%");
|
||||
// Log.e(TAG, "electricity:=" + elec + "%");
|
||||
if (elec == 50) {
|
||||
start.onstar(SystemClock.elapsedRealtime());
|
||||
}
|
||||
@@ -388,7 +423,7 @@ public class GuardService extends Service {
|
||||
|| Intent.ACTION_BATTERY_OKAY.equals(action)
|
||||
) {
|
||||
setDefaultUSBStatus();
|
||||
Logutils.e(TAG, action);
|
||||
Log.e(TAG, action);
|
||||
start.onstar(SystemClock.elapsedRealtime());
|
||||
}
|
||||
}
|
||||
@@ -396,7 +431,7 @@ public class GuardService extends Service {
|
||||
|
||||
private void setDefaultUSBStatus() {
|
||||
String setting_usb = Settings.System.getString(getContentResolver(), "qch_usb_choose");
|
||||
Logutils.e("setDefaultUSBStatus", "setting_usb---------" + setting_usb);
|
||||
Log.e("setDefaultUSBStatus", "setting_usb---------" + setting_usb);
|
||||
String usbStatus = "";
|
||||
if (TextUtils.isEmpty(setting_usb)) {
|
||||
usbStatus = "qch_action_usb_usb_charge";
|
||||
@@ -425,7 +460,7 @@ public class GuardService extends Service {
|
||||
JSONObject jsonObject = JSON.parseObject(task.getExtendField());
|
||||
String app_name = jsonObject.getString("app_name");
|
||||
String app_package = jsonObject.getString("app_package");
|
||||
Logutils.e("aria", "正在下载:" + task.getPercent() + ":" + task.getExtendField());
|
||||
Log.e("aria", "正在下载:" + task.getPercent() + ":" + task.getExtendField());
|
||||
ToastUtil.show("正在下载:" + app_name + "-" + task.getPercent() + "%" + "\t" + Formatter.formatFileSize(GuardService.this, task.getSpeed()) + "/s");
|
||||
}
|
||||
|
||||
@@ -434,8 +469,8 @@ public class GuardService extends Service {
|
||||
//在这里处理任务完成的状态
|
||||
String filepath = task.getFilePath();
|
||||
String extendField = task.getExtendField();
|
||||
Logutils.e("taskComplete", "downloadPath::" + filepath);
|
||||
Logutils.e("taskComplete", "extendField::" + extendField);
|
||||
Log.e("taskComplete", "downloadPath::" + filepath);
|
||||
Log.e("taskComplete", "extendField::" + extendField);
|
||||
|
||||
if (filepath.endsWith("apk")) {
|
||||
JSONObject jsonObject = JSON.parseObject(extendField);
|
||||
@@ -445,13 +480,13 @@ public class GuardService extends Service {
|
||||
ToastUtil.show(app_name + "\t:下载完成");
|
||||
if (filepath.endsWith(".xapk")) {
|
||||
XAPKUtils.getInstance().installXAPK(filepath);
|
||||
Logutils.e(TAG, "taskComplete: " + filepath);
|
||||
Log.e(TAG, "taskComplete: " + filepath);
|
||||
} else if (filepath.endsWith(".apk")) {
|
||||
new Thread(() -> ApkUtils.installApp(GuardService.this, filepath)).start();
|
||||
List<DownloadEntity> list = Aria.download(this).getDRunningTask();
|
||||
if (list == null || list.size() == 0) {
|
||||
BaseApplication.getInstance().setDownloadState(false);
|
||||
Logutils.e("taskComplete", "isDownloading=" + BaseApplication.getInstance().isDownloading());
|
||||
Log.e("taskComplete", "isDownloading=" + BaseApplication.getInstance().isDownloading());
|
||||
}
|
||||
}
|
||||
NetInterfaceManager.getInstance()
|
||||
@@ -495,12 +530,12 @@ public class GuardService extends Service {
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("SEND_DOWNLOAD_FILE_INFO", "onNext: "+baseResponse.msg);
|
||||
Log.e("SEND_DOWNLOAD_FILE_INFO", "onNext: " + baseResponse.msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("SEND_DOWNLOAD_FILE_INFO", "onError: "+e.getMessage());
|
||||
Log.e("SEND_DOWNLOAD_FILE_INFO", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -509,7 +544,7 @@ public class GuardService extends Service {
|
||||
}
|
||||
});
|
||||
} else if (filepath.endsWith(".zip")) {
|
||||
Logutils.e("taskComplete", "下载完成:" + task.getPercent() + ":" + task.getExtendField());
|
||||
Log.e("taskComplete", "下载完成:" + task.getPercent() + ":" + task.getExtendField());
|
||||
JGYUtils.getInstance().setBootanimation(task.getFilePath());
|
||||
}
|
||||
}
|
||||
@@ -522,10 +557,10 @@ public class GuardService extends Service {
|
||||
JSONObject jsonObject = JSON.parseObject(task.getExtendField());
|
||||
String app_name = jsonObject.getString("app_name");
|
||||
String app_package = jsonObject.getString("app_package");
|
||||
Logutils.e("aria", "下载失败: " + packageName + "filepath: " + filepath + "Exception: " + e.getMessage());
|
||||
Log.e("aria", "taskFail: " + packageName + "filepath: " + filepath + "Exception: " + e.getMessage());
|
||||
// ToastUtil.show(app_name + "\t:下载失败");
|
||||
} catch (Exception e1) {
|
||||
Logutils.e("aria", "taskFail: " + e1.getMessage());
|
||||
Log.e("aria", "taskFail: " + e1.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.aoleyun.sn.service;
|
||||
|
||||
import com.aoleyun.sn.utils.Logutils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.drafts.Draft_6455;
|
||||
@@ -15,22 +15,22 @@ public class JWebSocketClient extends WebSocketClient {
|
||||
|
||||
@Override
|
||||
public void onOpen(ServerHandshake handshakedata) {
|
||||
Logutils.e("JWebSocketClient", "onOpen()");
|
||||
Log.e("JWebSocketClient", "onOpen()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
Logutils.e("JWebSocketClient", "onMessage()");
|
||||
Log.e("JWebSocketClient", "onMessage()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int code, String reason, boolean remote) {
|
||||
Logutils.e("JWebSocketClient", "onClose():" + reason);
|
||||
Log.e("JWebSocketClient", "onClose():" + reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception ex) {
|
||||
Logutils.e("JWebSocketClient", "onError():" + ex.getMessage());
|
||||
Log.e("JWebSocketClient", "onError():" + ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,11 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.IBinder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.aoleyun.sn.utils.Logutils;
|
||||
import com.aoleyun.sn.bean.BaseResponse;
|
||||
import com.aoleyun.sn.bean.SnRunLog;
|
||||
import com.aoleyun.sn.network.NetInterfaceManager;
|
||||
import com.aoleyun.sn.utils.Utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -19,6 +22,16 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class LogcatService extends Service {
|
||||
public final static String LOGCAT_START_ACTION = "START";
|
||||
@@ -58,11 +71,33 @@ public class LogcatService extends Service {
|
||||
//// exec.destroy();
|
||||
// } catch (IOException e) {
|
||||
//// e.printStackTrace();
|
||||
// Logutils.e("第一个是Logcat", e.getMessage());
|
||||
// Log.e("第一个是Logcat", e.getMessage());
|
||||
// }
|
||||
registerLogcatReceiver();
|
||||
}
|
||||
|
||||
private static long start_Time;
|
||||
private static long condition_duration;
|
||||
private static long condition_file_max_size;
|
||||
private static boolean clear_file;
|
||||
|
||||
public static void setStart_Time(long start_Time) {
|
||||
LogcatService.start_Time = start_Time;
|
||||
}
|
||||
|
||||
public static void setDuration(long duration) {
|
||||
condition_duration = duration;
|
||||
}
|
||||
|
||||
public static void setFileMaxSize(long fileMaxSize) {
|
||||
condition_file_max_size = fileMaxSize * 1024 * 1024;
|
||||
}
|
||||
|
||||
public static void setClearFile(int clearfile) {
|
||||
clear_file = clearfile == 1;
|
||||
}
|
||||
|
||||
|
||||
LogcatReceiver receiver;
|
||||
|
||||
private void registerLogcatReceiver() {
|
||||
@@ -103,6 +138,7 @@ public class LogcatService extends Service {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
uploadFile();
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +154,7 @@ public class LogcatService extends Service {
|
||||
String logFilePath;
|
||||
//= getExternalCacheDir() + File.separator + "LOG" + File.separator;
|
||||
String logFileName;
|
||||
String tempFilePath;
|
||||
|
||||
class LogThread extends Thread {
|
||||
InputStream is;
|
||||
@@ -133,7 +170,7 @@ public class LogcatService extends Service {
|
||||
try {
|
||||
//新建一个路径信息
|
||||
File file = new File(logFilePath + logFileName);
|
||||
Logutils.e(TAG, "run: " + logFilePath);
|
||||
Log.e(TAG, "run: " + logFilePath);
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
@@ -146,7 +183,7 @@ public class LogcatService extends Service {
|
||||
os.flush();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logutils.e("writelog", "read logcat process failed. message: "
|
||||
Log.e("writelog", "read logcat process failed. message: "
|
||||
+ e.getMessage());
|
||||
} finally {
|
||||
if (null != os) {
|
||||
@@ -161,12 +198,7 @@ public class LogcatService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable LogcatRunnale = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getLog();
|
||||
}
|
||||
};
|
||||
private Runnable LogcatRunnale = this::getLog;
|
||||
|
||||
public static boolean shouldGetLog = true;
|
||||
|
||||
@@ -181,27 +213,41 @@ public class LogcatService extends Service {
|
||||
BufferedReader bufferedReader;
|
||||
FileOutputStream fileOutputStream;
|
||||
File file = new File(logFilePath);
|
||||
Logutils.e(TAG, "getLog: " + logFilePath);
|
||||
Log.e(TAG, "getLog: " + logFilePath);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
logFileName = Utils.getSerial() + "-" + getTime() + ".log";
|
||||
|
||||
if (clear_file) {
|
||||
logFileName = Utils.getSerial() + ".log";
|
||||
} else {
|
||||
logFileName = Utils.getSerial() + "-" + getTime() + ".log";
|
||||
}
|
||||
|
||||
try {
|
||||
inputStreamReader = new InputStreamReader(process.getInputStream());
|
||||
bufferedReader = new BufferedReader(inputStreamReader);
|
||||
fileOutputStream = new FileOutputStream(logFilePath + logFileName);
|
||||
Logutils.e(TAG, "getLog: " + logFilePath + logFileName);
|
||||
|
||||
tempFilePath = logFilePath + logFileName;
|
||||
fileOutputStream = new FileOutputStream(tempFilePath);
|
||||
Log.e(TAG, "getLog: " + tempFilePath);
|
||||
long fileSize = file.length();
|
||||
String logEntry;
|
||||
while (shouldGetLog) {
|
||||
logEntry = bufferedReader.readLine() + "\n";
|
||||
fileOutputStream.write(logEntry.getBytes());
|
||||
fileOutputStream.flush();
|
||||
fileSize += logEntry.length();
|
||||
// Log.e(TAG, "getLog: " + fileSize);
|
||||
if (fileSize >= condition_file_max_size ||
|
||||
(start_Time + condition_duration) * 1000 < System.currentTimeMillis()) {
|
||||
shouldGetLog = false;
|
||||
stopLogThread();
|
||||
}
|
||||
}
|
||||
inputStreamReader.close();
|
||||
bufferedReader.close();
|
||||
fileOutputStream.close();
|
||||
Logutils.e(TAG, "getLog: " + "closed");
|
||||
Log.e(TAG, "getLog: " + "closed");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NullPointerException e) {
|
||||
@@ -209,20 +255,66 @@ public class LogcatService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void uploadFile() {
|
||||
File file = new File(tempFilePath);
|
||||
if (!file.exists() || file.isDirectory()) {
|
||||
Log.e("uploadFile", "File does not exists");
|
||||
return;
|
||||
}
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("sn", Utils.getSerial());
|
||||
MediaType mediaType = MediaType.Companion.parse("text/plain");
|
||||
RequestBody fileBody = RequestBody.Companion.create(file, mediaType);
|
||||
//设置一个file文件
|
||||
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), fileBody);
|
||||
|
||||
NetInterfaceManager.getInstance().getUploadLogApi()
|
||||
.GetSnRunLog(params, body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseResponse<SnRunLog>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("uploadFile", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse<SnRunLog> snRunLogBaseResponse) {
|
||||
Log.e("uploadFile", "onNext: " + snRunLogBaseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("uploadFile", "onError: " + e.getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("uploadFile", "onComplete: ");
|
||||
if (clear_file) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class LogcatReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Logutils.e(TAG, "onReceive: " + action);
|
||||
Log.e(TAG, "onReceive: " + action);
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
return;
|
||||
}
|
||||
switch (action) {
|
||||
case LOGCAT_START_ACTION:
|
||||
Log.e(TAG, "onReceive: "+"开始录制log");
|
||||
startLogThread();
|
||||
break;
|
||||
case LOGCAT_STOP_ACTION:
|
||||
Log.e(TAG, "onReceive: "+"停止录制log");
|
||||
stopLogThread();
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.aoleyun.sn.service;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
@@ -12,10 +10,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
@@ -29,37 +25,43 @@ import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aoleyun.sn.comm.PackageNames;
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.aoleyun.sn.R;
|
||||
import com.aoleyun.sn.action.JGYActions;
|
||||
import com.aoleyun.sn.activity.MainActivity;
|
||||
import com.aoleyun.sn.activity.MainContact;
|
||||
import com.aoleyun.sn.activity.MainPresenter;
|
||||
import com.aoleyun.sn.bean.PoweroffBean;
|
||||
import com.aoleyun.sn.comm.PackageNames;
|
||||
import com.aoleyun.sn.receiver.BootReceiver;
|
||||
import com.aoleyun.sn.utils.ApkUtils;
|
||||
import com.aoleyun.sn.utils.ForegroundAppUtil;
|
||||
import com.aoleyun.sn.utils.Logutils;
|
||||
import com.aoleyun.sn.utils.JGYUtils;
|
||||
import com.aoleyun.sn.utils.SPUtils;
|
||||
import com.aoleyun.sn.utils.SaveListUtils;
|
||||
import com.aoleyun.sn.utils.SysSettingUtils;
|
||||
import com.aoleyun.sn.utils.TimeUtils;
|
||||
import com.aoleyun.sn.utils.ToastUtil;
|
||||
import com.aoleyun.sn.utils.Utils;
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.trello.rxlifecycle2.LifecycleProvider;
|
||||
import com.trello.rxlifecycle2.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle2.RxLifecycle;
|
||||
import com.trello.rxlifecycle2.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle2.android.RxLifecycleAndroid;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import cn.jpush.android.api.JPushInterface;
|
||||
@@ -88,6 +90,7 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
runningTime = SystemClock.elapsedRealtime();
|
||||
//直接获取数据
|
||||
ToastUtil.betaShow("网络已连接");
|
||||
Utils.getPublicIP(this);
|
||||
mPresenter.getLockedState();
|
||||
start.onstar(SystemClock.elapsedRealtime());
|
||||
}
|
||||
@@ -130,7 +133,7 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
|
||||
@Override
|
||||
public void onNext(Long aLong) {
|
||||
Logutils.e("TimeObserver", "onNext: " + aLong);
|
||||
Log.e("TimeObserver", "onNext: " + aLong);
|
||||
startCommandTime = runningTime = SystemClock.elapsedRealtime();
|
||||
mPresenter.getFirstConnect();
|
||||
mPresenter.getLockedState();
|
||||
@@ -165,7 +168,7 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
mPresenter.setProvider(this);
|
||||
if ((int) SPUtils.get(this, "first_connect", 0) == 0) {
|
||||
// TODO: 2021/5/26 待底层修改,临时解决办法
|
||||
Logutils.e(TAG, "onCreate: " + "Disable All Settings");
|
||||
Log.e(TAG, "onCreate: " + "Disable All Settings");
|
||||
mPresenter.setDisableSetting();
|
||||
}
|
||||
registerReceivers();
|
||||
@@ -209,20 +212,20 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
sendBroadcast(bootIntent);
|
||||
JPushInterface.init(this);
|
||||
if (MainActivity.isForeground) {
|
||||
Logutils.e(TAG, "onStartCommand: MainService: isForeground: " + MainActivity.isForeground);
|
||||
Log.e(TAG, "onStartCommand: MainService: isForeground: " + MainActivity.isForeground);
|
||||
} else {
|
||||
// if (((SystemClock.elapsedRealtime() - startCommandTime) < 60000) && startCommandTime != 0) {
|
||||
// Logutils.e(TAG, "onStartCommand: " + "启动时间过短");
|
||||
// Log.e(TAG, "onStartCommand: " + "启动时间过短");
|
||||
// //一分钟内防止多次调用
|
||||
// } else {
|
||||
// mPresenter.getFirstConnect();
|
||||
// mPresenter.getLockedState();
|
||||
// startCommandTime = runningTime = SystemClock.elapsedRealtime();
|
||||
// Logutils.e(TAG, "onStartCommand: isForeground: " + MainActivity.isForeground);
|
||||
// Logutils.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime));
|
||||
// Log.e(TAG, "onStartCommand: isForeground: " + MainActivity.isForeground);
|
||||
// Log.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime));
|
||||
// }
|
||||
start.onstar(SystemClock.elapsedRealtime());
|
||||
Logutils.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime) + "ms");
|
||||
Log.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime) + "ms");
|
||||
}
|
||||
return START_STICKY;
|
||||
}
|
||||
@@ -268,9 +271,9 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
|
||||
private void setStatusbar() {
|
||||
String status = (String) SPUtils.get(this, JGYActions.ACTION_STATUS_BAR_STATUS, "");
|
||||
Logutils.e(TAG, "setStatusbar: String: " + status);
|
||||
Log.e(TAG, "setStatusbar: String: " + status);
|
||||
if (TextUtils.isEmpty(status)) {
|
||||
Logutils.e(TAG, "setStatusbar: " + "status is NULL");
|
||||
Log.e(TAG, "setStatusbar: " + "status is NULL");
|
||||
return;
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(status);
|
||||
@@ -393,7 +396,7 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Logutils.e("LockScreenReceiver", "onReceive: " + action);
|
||||
Log.e("LockScreenReceiver", "onReceive: " + action);
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
return;
|
||||
}
|
||||
@@ -473,44 +476,73 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.e(TAG, "onReceive: " + intent.getAction());
|
||||
if (Intent.ACTION_DATE_CHANGED.equals(intent.getAction())) {
|
||||
Logutils.e("TimeChangedReceiver", "onReceive:" + "data changed");
|
||||
Log.e("TimeChangedReceiver", "onReceive:" + "data changed");
|
||||
} else if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) {
|
||||
Logutils.e("TimeChangedReceiver", "onReceive:" + "time changed");
|
||||
Log.e("TimeChangedReceiver", "onReceive:" + "time changed");
|
||||
} else if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
|
||||
Logutils.e("TimeChangedReceiver", "onReceive:" + "timezone changed");
|
||||
Log.e("TimeChangedReceiver", "onReceive:" + "timezone changed");
|
||||
} else if (Intent.ACTION_TIME_TICK.equals(intent.getAction())) {
|
||||
Logutils.e("TimeChangedReceiver", "onReceive:" + "time tick");
|
||||
Log.e("TimeChangedReceiver", "onReceive:" + "time tick");
|
||||
checkShutdownTime();
|
||||
setFloatingWindow(MainService.this);
|
||||
} else if (ACTION_UPDATE.equals(intent.getAction())) {
|
||||
setFloatingWindow(MainService.this);
|
||||
mPresenter.getScreenLockState();
|
||||
Logutils.e("TimeChangedReceiver", "onReceive:" + "date update");
|
||||
Log.e("TimeChangedReceiver", "onReceive:" + "date update");
|
||||
}
|
||||
timeChangedStart.onstar(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkShutdownTime() {
|
||||
MMKV mmkv = MMKV.defaultMMKV();
|
||||
String poweroffTime = mmkv.decodeString("poweroffTime", "");
|
||||
Log.e("checkShutdownTime", "poweroffTime: " + poweroffTime);
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<List<PoweroffBean>>() {
|
||||
}.getType();
|
||||
List<PoweroffBean> poweroffBeanList = gson.fromJson(poweroffTime, listType);
|
||||
if (poweroffBeanList != null && poweroffBeanList.size() != 0) {
|
||||
boolean inTime = false;
|
||||
for (PoweroffBean poweroffBean : poweroffBeanList) {
|
||||
if (TimeUtils.isShutdownTime(poweroffBean)) {
|
||||
inTime = true;
|
||||
}
|
||||
}
|
||||
if (inTime) {
|
||||
JGYUtils.getInstance().shutdown();
|
||||
Log.e(TAG, "checkShutdownTime: " + "设备关机");
|
||||
} else {
|
||||
Log.e(TAG, "checkShutdownTime: " + "没有关机事件");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
synchronized private void setFloatingWindow(Context context) {
|
||||
ForegroundAppUtil.openTopApp(context);
|
||||
long nowTime = System.currentTimeMillis();
|
||||
TimeUtils.ContralTime contralTime = TimeUtils.getDefaltContralTime(MainService.this);
|
||||
Log.e(TAG, "setFloatingWindow: " + contralTime);
|
||||
Log.e(TAG, "setFloatingWindow: screenlocked: " + screenlocked);
|
||||
if (null != contralTime) {
|
||||
if (contralTime.inControlTime(nowTime)) {
|
||||
Log.e(TAG, "setFloatingWindow: " + "inControlTime is true");
|
||||
if (!screenlocked) {
|
||||
showFloatingWindow("管控时间:" + contralTime.toString());
|
||||
showFloatingWindow("设备可用时间:" + contralTime.toString());
|
||||
} else {
|
||||
TextView textView = topView.findViewById(R.id.textView);
|
||||
textView.setText("管控时间:" + contralTime.toString());
|
||||
textView.setText("设备可用时间:" + contralTime.toString());
|
||||
}
|
||||
timelocked = true;
|
||||
} else {
|
||||
Log.e(TAG, "setFloatingWindow: " + "inControlTime is false");
|
||||
if (!screenlocked) {
|
||||
hideFloatingWindow();
|
||||
}
|
||||
timelocked = false;
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "setFloatingWindow: " + "inControlTime is null");
|
||||
if (!screenlocked) {
|
||||
hideFloatingWindow();
|
||||
}
|
||||
@@ -540,25 +572,25 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
Logutils.e(TAG, "onReceive: " + "Action is NULL!");
|
||||
Log.e(TAG, "onReceive: " + "Action is NULL!");
|
||||
return;
|
||||
}
|
||||
Logutils.e(TAG, "onReceive: " + "Sender is " + intent.getPackage());
|
||||
Log.e(TAG, "onReceive: " + "Sender is " + intent.getPackage());
|
||||
String packageName = intent.getStringExtra("packageName");
|
||||
String filePath = intent.getStringExtra("filePath");
|
||||
if (!TextUtils.isEmpty(packageName) && !TextUtils.isEmpty(filePath)) {
|
||||
Logutils.e(TAG, "onReceive: " + "packageName: " + packageName + "filePath: " + filePath);
|
||||
Log.e(TAG, "onReceive: " + "packageName: " + packageName + "filePath: " + filePath);
|
||||
installApkByPackage(filePath, packageName);
|
||||
} else if (!TextUtils.isEmpty(filePath)) {
|
||||
String pkg = ApkUtils.getPackageName(MainService.this, filePath);
|
||||
if (TextUtils.isEmpty(pkg)) {
|
||||
Logutils.e(TAG, "onReceive: " + "unknow packageName");
|
||||
Log.e(TAG, "onReceive: " + "unknow packageName");
|
||||
} else {
|
||||
Logutils.e(TAG, "onReceive: " + "pkg: " + pkg + "\tfilePath: " + filePath);
|
||||
Log.e(TAG, "onReceive: " + "pkg: " + pkg + "\tfilePath: " + filePath);
|
||||
installApkByPackage(filePath, pkg);
|
||||
}
|
||||
} else {
|
||||
Logutils.e(TAG, "onReceive: " + "no filePath and packageName");
|
||||
Log.e(TAG, "onReceive: " + "no filePath and packageName");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -572,9 +604,9 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
String oldListString = Settings.System.getString(getContentResolver(), "qch_app_forbid");
|
||||
HashSet<String> packageList = new HashSet<>(Arrays.asList(oldListString.split(",")));
|
||||
if (!packageList.contains(pkg)) {
|
||||
Logutils.e(TAG, "installApkByPackage: " + "packageName: " + pkg + " not in whitelist");
|
||||
Log.e(TAG, "installApkByPackage: " + "packageName: " + pkg + " not in whitelist");
|
||||
} else {
|
||||
Logutils.e(TAG, "installApkByPackage: " + "packageName: " + pkg);
|
||||
Log.e(TAG, "installApkByPackage: " + "packageName: " + pkg);
|
||||
ApkUtils.installApp(MainService.this, filePath);
|
||||
}
|
||||
}
|
||||
@@ -604,25 +636,29 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHead(String url) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLockedState(boolean loocked) {
|
||||
//发送设备mac地址和信息
|
||||
mPresenter.sendMACAddress();
|
||||
//设置极光推送别名
|
||||
mPresenter.setJpushAlias();
|
||||
//设置极光推送标签
|
||||
mPresenter.setJpushTags();
|
||||
if (loocked) {
|
||||
ToastUtil.betaShow("设备已上锁");
|
||||
Logutils.e(TAG, "setLockedState: " + netWorkIsRunning);
|
||||
Log.e(TAG, "setLockedState: " + netWorkIsRunning);
|
||||
//上传APP信息
|
||||
ApkUtils.getAppInfo(this);
|
||||
//发送设备mac地址和信息
|
||||
mPresenter.sendMACAddress();
|
||||
//设置极光推送别名
|
||||
mPresenter.setJpushAlias();
|
||||
//设置极光推送标签
|
||||
SaveListUtils.getList();
|
||||
if (netWorkIsRunning) {
|
||||
//如果正在执行,不执行
|
||||
// return;
|
||||
}
|
||||
//获取系统管控
|
||||
mPresenter.setJpushTags();
|
||||
netWorkIsRunning = true;
|
||||
} else {
|
||||
ToastUtil.betaShow("设备已解锁");
|
||||
@@ -638,7 +674,7 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
*/
|
||||
@Override
|
||||
public void setFirstConnect(boolean state) {
|
||||
Logutils.e(TAG, "isFirstConnect: " + "end request: " + state);
|
||||
Log.e(TAG, "isFirstConnect: " + "end request: " + state);
|
||||
if (state) {
|
||||
mPresenter.setDisableSetting();
|
||||
} else {
|
||||
@@ -647,57 +683,72 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMACFinished() {
|
||||
public void sendMACFinish() {
|
||||
mPresenter.updateDeviceInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceInfoFinished() {
|
||||
public void updateDeviceInfoFinish() {
|
||||
mPresenter.getSnTimeControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSnTimeControlFinished() {
|
||||
public void getSnTimeControlFinish() {
|
||||
mPresenter.getEBagCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getEBagCodeFinished() {
|
||||
public void getEBagCodeFinish() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAliasFinished() {
|
||||
public void setAliasFinish() {
|
||||
mPresenter.checkStoreUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJpushPlatformTagsFinished() {
|
||||
public void setJpushPlatformTagsFinish() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkStoreUpdateFinished() {
|
||||
public void checkStoreUpdateFinish() {
|
||||
mPresenter.checkInfoUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkInfoUpdateFinished() {
|
||||
public void checkInfoUpdateFinish() {
|
||||
mPresenter.checkDesktopUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkDesktopUpdateFinish() {
|
||||
mPresenter.checkNotifyUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkNotifyUpdateFinish() {
|
||||
mPresenter.checkBrowserUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkBrowserUpdateFinish() {
|
||||
mPresenter.checkTestUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkTestUpdateFinished() {
|
||||
public void buttonCheckUpdateFinish(boolean update, JsonObject jsonObject) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonCheckUpdateFinished(boolean update, JsonObject jsonObject) {
|
||||
public void checkTestUpdateFinish() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTagsFinished(boolean noTag) {
|
||||
public void setTagsFinish(boolean noTag) {
|
||||
if (noTag) {
|
||||
Log.e(TAG, "setTagsFinished: " + "not set tag");
|
||||
netWorkIsRunning = false;
|
||||
@@ -705,6 +756,12 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
} else {
|
||||
mPresenter.getSystemSettingbegin();
|
||||
}
|
||||
mPresenter.getDeveloper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDeveloperFinish() {
|
||||
Log.e(TAG, "getDeveloperFinished: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -713,89 +770,95 @@ public class MainService extends Service implements MainContact.MainView, Networ
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAppLimitFinished(String packageList) {
|
||||
public void getAppLimitFinish(String packageList) {
|
||||
mPresenter.getDeviceBatch(packageList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDeviceBatchFinished() {
|
||||
public void getDeviceBatchFinish() {
|
||||
mPresenter.getForceDownload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getForceDownloadFinished() {
|
||||
public void getForceDownloadFinish() {
|
||||
mPresenter.getBrowserList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBrowserListFinished(String whitelist) {
|
||||
public void getBrowserListFinish(String whitelist) {
|
||||
mPresenter.getBrowserBookmarks(whitelist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBrowserBookmarksFinished() {
|
||||
public void getBrowserBookmarksFinish() {
|
||||
mPresenter.getBrowserWhiteList();
|
||||
mPresenter.getDesktopIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDesktopIconFinished() {
|
||||
public void getDesktopIconFinish() {
|
||||
mPresenter.getAppAutoStartUpdateAndNet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAppAutoStartUpdateAndNetFinished() {
|
||||
public void getAppAutoStartUpdateAndNetFinish() {
|
||||
mPresenter.getAppIDControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAppIDControlFinished() {
|
||||
public void getAppIDControlFinish() {
|
||||
mPresenter.setAppinsideWeb();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAppinsideWebFinished() {
|
||||
public void setAppinsideWebFinish() {
|
||||
mPresenter.setSystemSetting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemSettingFinished() {
|
||||
public void setSystemSettingFinish() {
|
||||
mPresenter.getDefaultApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultAppFinished() {
|
||||
public void setDefaultAppFinish() {
|
||||
mPresenter.getROMApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getROMAppFinished() {
|
||||
mPresenter.getDeveloper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDeveloperFinished() {
|
||||
public void getROMAppFinish() {
|
||||
mPresenter.setLogoImg();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogoImgFinished() {
|
||||
public void setLogoImgFinish() {
|
||||
mPresenter.setTopApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTopAppFinished() {
|
||||
public void setTopAppFinish() {
|
||||
mPresenter.getDefaultDesktop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDefaultDesktopFinished() {
|
||||
public void getDefaultDesktopFinish() {
|
||||
netWorkIsRunning = false;
|
||||
Log.e(TAG, "SettingFinished: " + (SystemClock.elapsedRealtime() - runningTime) + " ms");
|
||||
mPresenter.getPoweroffTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScreenLockStateFinished(boolean locked, String tips) {
|
||||
public void setPoweroffTime() {
|
||||
mPresenter.getWiFiPasswd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWiFiPasswd() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScreenLockStateFinish(boolean locked, String tips) {
|
||||
if (locked) {
|
||||
if (!timelocked) {
|
||||
showFloatingWindow(tips);
|
||||
|
||||
@@ -4,9 +4,9 @@ import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.aoleyun.sn.IGetLicenseInterface;
|
||||
import com.aoleyun.sn.utils.Logutils;
|
||||
import com.aoleyun.sn.utils.SPUtils;
|
||||
|
||||
public class RemoteService extends Service {
|
||||
@@ -17,7 +17,7 @@ public class RemoteService extends Service {
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
Logutils.e(TAG, "onBind: ");
|
||||
Log.e(TAG, "onBind: ");
|
||||
return mBinde;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class RemoteService extends Service {
|
||||
@Override
|
||||
public String getLicense() throws RemoteException {
|
||||
String ebagCode = (String) SPUtils.get(RemoteService.this, "ebagCode", "");
|
||||
Logutils.e(TAG, "getLicense: " + ebagCode);
|
||||
Log.e(TAG, "getLicense: " + ebagCode);
|
||||
return ebagCode;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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