diff --git a/app/build.gradle b/app/build.gradle index 6f12943..561d8bb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -73,8 +73,8 @@ android { official { flavorDimensions "default" - versionCode 49 - versionName "3.0.9" + versionCode 50 + versionName "3.1.0" } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fc42867..a76fd03 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -93,7 +93,7 @@ @@ -115,28 +115,33 @@ - - + + + + @@ -150,7 +155,7 @@ - + @@ -163,7 +168,7 @@ @@ -182,7 +187,7 @@ @@ -195,7 +200,7 @@ @@ -222,7 +227,7 @@ - + diff --git a/app/src/main/java/com/fuying/sn/bean/SnRunLog.java b/app/src/main/java/com/fuying/sn/bean/SnRunLog.java new file mode 100644 index 0000000..5b049b4 --- /dev/null +++ b/app/src/main/java/com/fuying/sn/bean/SnRunLog.java @@ -0,0 +1,69 @@ +package com.fuying.sn.bean; + +import androidx.annotation.NonNull; + +import com.google.gson.Gson; +import com.google.gson.JsonParser; + +import java.io.Serializable; + +public class SnRunLog implements Serializable { + private static final long serialVersionUID = 7780957878619252035L; + + int id; + //开始时间 + long start_time; + //持续时间 + long duration; + //文件大小 + int file_max_size; + //上传成功之后是否删除文件 + int is_clear; + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public long getStart_time() { + return start_time; + } + + public void setStart_time(long start_time) { + this.start_time = start_time; + } + + public long getDuration() { + return duration; + } + + public void setDuration(long duration) { + this.duration = duration; + } + + public int getFile_max_size() { + return file_max_size; + } + + public void setFile_max_size(int file_max_size) { + this.file_max_size = file_max_size; + } + + public int getIs_clear() { + return is_clear; + } + + public void setIs_clear(int is_clear) { + this.is_clear = is_clear; + } + + @NonNull + @Override + public String toString() { + return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString(); + } +} diff --git a/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java b/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java index 8255fd5..b49d4b6 100644 --- a/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java +++ b/app/src/main/java/com/fuying/sn/desktop/RunningAppManager.java @@ -583,17 +583,6 @@ public class RunningAppManager { boolean havaConfigure = TimeControlManager.getInstance().havaConfigure(pkg); MachineControl machineControl = TimeControlManager.getInstance().getGlobalMachineControl(); - Log.e(TAG, "inControlTime: globalRemainingTime = " + globalRemainingTime); - if (globalRemainingTime <= 0) { - if (machineControl != null) { - if (machineControl.getIs_part() == 0 && machineControl.getIs_quota() == 0) { - return; - } - } else { - ToastUtil.show("今日可使用时间已用完"); - return; - } - } if (havaConfigure) { AppTimeControl appTimeControl = TimeControlManager.getInstance().getAppTimeControl(pkg); //全局配置的 @@ -615,6 +604,19 @@ public class RunningAppManager { } else { mGlobalUsageTime.remove(pkg); } + + Log.e(TAG, "inControlTime: globalRemainingTime = " + globalRemainingTime); + if (globalRemainingTime <= 0) { + if (machineControl != null) { + if (machineControl.getIs_part() == 0 && machineControl.getIs_quota() == 0) { + return; + } + } else { + ToastUtil.show("今日可使用时间已用完"); + return; + } + } + //单个app的 AppUsageTime singleAppUsageTime; if (mAllAppUsageTime.get(pkg) == null) { @@ -646,6 +648,17 @@ public class RunningAppManager { if (machineControl == null) { return; } + Log.e(TAG, "inControlTime: globalRemainingTime = " + globalRemainingTime); + if (globalRemainingTime <= 0) { + if (machineControl != null) { + if (machineControl.getIs_part() == 0 && machineControl.getIs_quota() == 0) { + return; + } + } else { + ToastUtil.show("今日可使用时间已用完"); + return; + } + } Log.i(TAG, "reduceAppRemainingTime: " + machineControl.getToday_time()); long remainingTime = machineControl.getToday_time() - time; if (remainingTime < 0) { diff --git a/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java b/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java index 9463bbf..9c1607d 100644 --- a/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java +++ b/app/src/main/java/com/fuying/sn/network/NetInterfaceManager.java @@ -1,6 +1,8 @@ package com.fuying.sn.network; import android.annotation.SuppressLint; +import android.app.AlarmManager; +import android.app.PendingIntent; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; @@ -31,6 +33,7 @@ import com.fuying.sn.bean.OverallAppBean; import com.fuying.sn.bean.ScreenPassword; import com.fuying.sn.bean.SnBindState; import com.fuying.sn.bean.SnInfo; +import com.fuying.sn.bean.SnRunLog; import com.fuying.sn.bean.SystemSettingsSet; import com.fuying.sn.bean.UserAvatarInfo; import com.fuying.sn.bean.browser.BrowserApiData; @@ -61,6 +64,8 @@ import com.fuying.sn.network.api.GetControlScreenshotApi; import com.fuying.sn.network.api.GetGuideApi; import com.fuying.sn.network.api.GetLockScreenPwdApi; import com.fuying.sn.network.api.GetPublicIPApi; +import com.fuying.sn.network.api.GetSnRunLogApi; +import com.fuying.sn.network.api.GetUploadLogApi; import com.fuying.sn.network.api.MachineTimeControlApi; import com.fuying.sn.network.api.MyAppListApi; import com.fuying.sn.network.api.NewestAppUpdate; @@ -81,6 +86,7 @@ import com.fuying.sn.network.api.UpdateLockScreen; import com.fuying.sn.network.api.UploadScreenshot; import com.fuying.sn.network.api.UserInfoControl; import com.fuying.sn.network.interceptor.RepeatRequestInterceptor; +import com.fuying.sn.service.LogcatService; import com.fuying.sn.utils.ApkUtils; import com.fuying.sn.utils.AppUsedTimeUtils; import com.fuying.sn.utils.CmdUtil; @@ -222,6 +228,10 @@ public class NetInterfaceManager { return okHttpClient; } + public GetUploadLogApi getUploadLogApi() { + return mRetrofit.create(GetUploadLogApi.class); + } + /* * * Observable @@ -464,6 +474,13 @@ public class NetInterfaceManager { .observeOn(AndroidSchedulers.mainThread()); } + public Observable> getSnRunLogControl() { + return mRetrofit.create(GetSnRunLogApi.class) + .getSnRunLog(Utils.getSerial()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); + } + /* * * execution @@ -3015,4 +3032,61 @@ public class NetInterfaceManager { } }; } + + + + private static final int REQUEST_CODE = 12345; + + public void getRunLog() { + getSnRunLogControl() + .subscribe(new Observer>() { + @Override + public void onSubscribe(Disposable d) { + Log.e("getRunLog", "onSubscribe: "); + } + + @Override + public void onNext(BaseResponse snRunLogBaseResponse) { + Log.e("getRunLog", "onNext: " + snRunLogBaseResponse); + if (snRunLogBaseResponse.code == 200) { + SnRunLog snRunLog = snRunLogBaseResponse.data; + LogcatService.setStart_Time(snRunLog.getStart_time()); + LogcatService.setDuration(snRunLog.getDuration()); + LogcatService.setFileMaxSize(snRunLog.getFile_max_size()); + LogcatService.setClearFile(snRunLog.getIs_clear()); + long timestamp = snRunLog.getStart_time() * 1000; + long nowTime = System.currentTimeMillis(); + AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); + if (nowTime > timestamp) { + Intent intent = new Intent(LogcatService.LOGCAT_START_ACTION); + mContext.sendBroadcast(intent); + } else { + Intent intent = new Intent(LogcatService.LOGCAT_START_ACTION); + PendingIntent startPendingIntent = PendingIntent.getBroadcast(mContext, + REQUEST_CODE, intent, + PendingIntent.FLAG_CANCEL_CURRENT); + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, + timestamp, startPendingIntent); + } + Intent intent = new Intent(LogcatService.LOGCAT_STOP_ACTION); + PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, + REQUEST_CODE, intent, + PendingIntent.FLAG_CANCEL_CURRENT); + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, + timestamp + snRunLog.getDuration() * 1000, pendingIntent); + } + } + + @Override + public void onError(Throwable e) { + Log.e("getRunLog", "onError: " + e.getMessage()); + onComplete(); + } + + @Override + public void onComplete() { + Log.e("getRunLog", "onComplete: "); + } + }); + } } diff --git a/app/src/main/java/com/fuying/sn/network/UrlAddress.java b/app/src/main/java/com/fuying/sn/network/UrlAddress.java index e2d0ae4..a68c8a8 100644 --- a/app/src/main/java/com/fuying/sn/network/UrlAddress.java +++ b/app/src/main/java/com/fuying/sn/network/UrlAddress.java @@ -81,6 +81,16 @@ public class UrlAddress { /*解除锁屏*/ public static final String UPDATE_LOCK_SCREEN = "sn/updateLockScreen"; + /** + * log相关 + */ + + /*获取log任务*/ + public static final String GET_LOG_ORDER = "sn/getSnRunLog"; + /*上传log文件*/ + public static final String UPLOAD_LOG_FILE = "sn/uploadLogFile"; + /*上传运行日志设置文件*/ + public static final String UPLOAD_IS_LOG_FILE = "sn/uploadIsLogFile"; /*获取公网IP*/ diff --git a/app/src/main/java/com/fuying/sn/network/api/GetSnRunLogApi.java b/app/src/main/java/com/fuying/sn/network/api/GetSnRunLogApi.java new file mode 100644 index 0000000..6539318 --- /dev/null +++ b/app/src/main/java/com/fuying/sn/network/api/GetSnRunLogApi.java @@ -0,0 +1,16 @@ +package com.fuying.sn.network.api; + +import com.fuying.sn.bean.BaseResponse; +import com.fuying.sn.bean.SnRunLog; +import com.fuying.sn.network.UrlAddress; + +import io.reactivex.rxjava3.core.Observable; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface GetSnRunLogApi { + @GET(UrlAddress.GET_LOG_ORDER) + Observable> getSnRunLog( + @Query("sn") String sn + ); +} diff --git a/app/src/main/java/com/fuying/sn/network/api/GetUploadLogApi.java b/app/src/main/java/com/fuying/sn/network/api/GetUploadLogApi.java new file mode 100644 index 0000000..46fb730 --- /dev/null +++ b/app/src/main/java/com/fuying/sn/network/api/GetUploadLogApi.java @@ -0,0 +1,22 @@ +package com.fuying.sn.network.api; + +import com.fuying.sn.bean.BaseResponse; +import com.fuying.sn.network.UrlAddress; + +import java.util.Map; + +import io.reactivex.rxjava3.core.Observable; +import okhttp3.MultipartBody; +import retrofit2.http.Multipart; +import retrofit2.http.POST; +import retrofit2.http.Part; +import retrofit2.http.QueryMap; + +public interface GetUploadLogApi { + @Multipart + @POST(UrlAddress.UPLOAD_LOG_FILE) + Observable UploadLog( + @QueryMap Map params, + @Part MultipartBody.Part body + ); +} diff --git a/app/src/main/java/com/fuying/sn/service/GuardService.java b/app/src/main/java/com/fuying/sn/service/GuardService.java index 26479b2..5d80f2b 100644 --- a/app/src/main/java/com/fuying/sn/service/GuardService.java +++ b/app/src/main/java/com/fuying/sn/service/GuardService.java @@ -33,7 +33,7 @@ public class GuardService extends Service { @Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { Log.e(TAG, "GuardService:建立链接"); - boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(GuardService.this, getClass().getName()); + boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(GuardService.this, getClass().getName()); if (!isServiceRunning) { Intent i = new Intent(GuardService.this, DownloadService.class); startService(i); diff --git a/app/src/main/java/com/fuying/sn/service/LogcatService.java b/app/src/main/java/com/fuying/sn/service/LogcatService.java new file mode 100644 index 0000000..7949467 --- /dev/null +++ b/app/src/main/java/com/fuying/sn/service/LogcatService.java @@ -0,0 +1,339 @@ +package com.fuying.sn.service; + +import android.app.Service; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.IBinder; +import android.text.TextUtils; +import android.util.Log; + +import com.fuying.sn.bean.BaseResponse; +import com.fuying.sn.network.NetInterfaceManager; +import com.fuying.sn.utils.Utils; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +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.rxjava3.android.schedulers.AndroidSchedulers; +import io.reactivex.rxjava3.core.Observer; +import io.reactivex.rxjava3.disposables.Disposable; +import io.reactivex.rxjava3.schedulers.Schedulers; +import okhttp3.MediaType; +import okhttp3.MultipartBody; +import okhttp3.RequestBody; + +public class LogcatService extends Service { + public final static String LOGCAT_START_ACTION = "START"; + public final static String LOGCAT_STOP_ACTION = "STOP"; + private String TAG = LogcatService.class.getSimpleName(); + + + public LogcatService() { + } + + @Override + public IBinder onBind(Intent intent) { + // TODO: Return the communication channel to the service. +// throw new UnsupportedOperationException("Not yet implemented"); + return null; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + return START_STICKY; + } + + @Override + public void onCreate() { + super.onCreate(); + logFilePath = getExternalCacheDir() + File.separator + "LOG" + File.separator; + File file = new File(logFilePath); + if (!file.exists()) { + file.mkdirs(); + } + // try { +// exec = Runtime.getRuntime().exec(running); +// final InputStream is = exec.getInputStream(); +// logThread = new LogThread(is); +// logThread.start(); +// // is.close(); +//// exec.destroy(); +// } catch (IOException e) { +//// e.printStackTrace(); +// 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() { + receiver = new LogcatReceiver(); + IntentFilter filter = new IntentFilter(); + filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); + filter.addAction(LOGCAT_START_ACTION); + filter.addAction(LOGCAT_STOP_ACTION); + registerReceiver(receiver, filter); + } + + Thread thread = null; + + private void creatLogThread() { + if (thread == null) { + thread = new Thread(LogcatRunnale); + } + } + + private void startLogThread() { + if (thread == null) { + creatLogThread(); + shouldGetLog = true; + thread.start(); + } else { + //已经有线程正在运行了 + } + } + + private void stopLogThread() { + if (thread != null) { + shouldGetLog = false; + thread = null; + //清除adb 缓存 + try { + Runtime.getRuntime().exec(clearLogcat); + } catch (IOException e) { + e.printStackTrace(); + } + } + uploadFile(); + } + + + private Process exec; + private LogThread logThread; + + //第一个是Logcat ,也就是我们想要获取的log日志 + //第二个是 -s 也就是表示过滤的意思 + //第三个就是 我们要过滤的类型 W表示warm ,我们也可以换成 D :debug, I:info,E:error等等 + // String[] running = new String[]{"logcat", "-s", "adb logcat *: W"}; + String[] running = new String[]{"logcat"}; + String clearLogcat = "logcat -c"; + String logFilePath; + //= getExternalCacheDir() + File.separator + "LOG" + File.separator; + String logFileName; + String tempFilePath; + + class LogThread extends Thread { + InputStream is; + + LogThread(InputStream inputStream) { + super(); + this.is = inputStream; + } + + @Override + public void run() { + FileOutputStream os = null; + try { + //新建一个路径信息 + File file = new File(logFilePath + logFileName); + Log.e(TAG, "run: " + logFilePath); + if (!file.exists()) { + file.getParentFile().mkdirs(); + file.createNewFile(); + } + os = new FileOutputStream(logFilePath); + int len = 0; + byte[] buf = new byte[1024]; + while (-1 != (len = is.read(buf))) { + os.write(buf, 0, len); + os.flush(); + } + } catch (Exception e) { + Log.e("writelog", "read logcat process failed. message: " + + e.getMessage()); + } finally { + if (null != os) { + try { + os.close(); + os = null; + } catch (IOException e) { + // Do nothing + } + } + } + } + } + + private Runnable LogcatRunnale = this::getLog; + + public static boolean shouldGetLog = true; + + private void getLog() { + Process process = null; + try { + process = Runtime.getRuntime().exec(running); + } catch (IOException e) { + e.printStackTrace(); + } + InputStreamReader inputStreamReader; + BufferedReader bufferedReader; + FileOutputStream fileOutputStream; + File file = new File(logFilePath); + Log.e(TAG, "getLog: " + logFilePath); + if (!file.exists()) { + file.mkdirs(); + } + + if (clear_file) { + logFileName = Utils.getSerial() + ".log"; + } else { + logFileName = Utils.getSerial() + "-" + getTime() + ".log"; + } + + try { + inputStreamReader = new InputStreamReader(process.getInputStream()); + bufferedReader = new BufferedReader(inputStreamReader); + 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(); + Log.e(TAG, "getLog: " + "closed"); + } catch (IOException e) { + e.printStackTrace(); + } catch (NullPointerException e) { + e.printStackTrace(); + } + } + + private void uploadFile() { + File file = new File(tempFilePath); + if (!file.exists() || file.isDirectory()) { + Log.e("uploadFile", "File does not exists"); + return; + } + Map params = new HashMap<>(); + params.put("sn", Utils.getSerial()); + MediaType mediaType = MediaType.Companion.parse("text/html"); + RequestBody fileBody = RequestBody.Companion.create(file, mediaType); + //设置一个file文件 + MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), fileBody); + + NetInterfaceManager.getInstance().getUploadLogApi() + .UploadLog(params, body) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + Log.e("uploadFile", "onSubscribe: "); + } + + @Override + public void onNext(BaseResponse 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(); + 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: + break; + } + } + } + + public static String getTime() { + long time = System.currentTimeMillis();//long now = android.os.SystemClock.uptimeMillis(); + SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); + Date d1 = new Date(time); + String t1 = format.format(d1); + return t1; + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (receiver != null) { + unregisterReceiver(receiver); + } + } +} diff --git a/app/src/main/java/com/fuying/sn/service/StepService.java b/app/src/main/java/com/fuying/sn/service/StepService.java index b01cca0..7d4991a 100644 --- a/app/src/main/java/com/fuying/sn/service/StepService.java +++ b/app/src/main/java/com/fuying/sn/service/StepService.java @@ -70,7 +70,7 @@ public class StepService extends Service implements NetworkUtils.OnNetworkStatus @Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { Log.w(TAG, "StepService:建立链接"); - boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(StepService.this, GuardService.class.getName()); + boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(StepService.this, GuardService.class.getName()); if (!isServiceRunning) { Intent i = new Intent(StepService.this, GuardService.class); startService(i); diff --git a/app/src/main/java/com/fuying/sn/service/main/MainSPresenter.java b/app/src/main/java/com/fuying/sn/service/main/MainSPresenter.java index 591b71d..ae4f5cc 100644 --- a/app/src/main/java/com/fuying/sn/service/main/MainSPresenter.java +++ b/app/src/main/java/com/fuying/sn/service/main/MainSPresenter.java @@ -370,7 +370,7 @@ public class MainSPresenter implements MainSContact.Presenter { if (code == 200) { JsonObject jsonObject = GsonUtils.getJsonObject(GsonUtils.toJSONString(baseResponse.data)); int is_screen_lock = jsonObject.get("is_screen_lock").getAsInt(); - if (!ServiceAliveUtils.isServiceAlice(mContext, ManagerService.class.getName())) { + if (!ServiceAliveUtils.isServiceAlive(mContext, ManagerService.class.getName())) { mContext.startService(new Intent(mContext, ManagerService.class)); } SPUtils.put(mContext, ManagerService.LOCK_STATE, is_screen_lock); diff --git a/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java b/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java index cd9d9f4..5af9de8 100644 --- a/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java +++ b/app/src/main/java/com/fuying/sn/tpush/MessageReceiver.java @@ -32,6 +32,7 @@ import com.fuying.sn.manager.ControlManager; import com.fuying.sn.manager.DeviceManager; import com.fuying.sn.network.NetInterfaceManager; import com.fuying.sn.receiver.BootReceiver; +import com.fuying.sn.service.LogcatService; import com.fuying.sn.service.ManagerService; import com.fuying.sn.tpush.common.NotificationService; import com.fuying.sn.tpush.po.XGNotification; @@ -481,6 +482,8 @@ public class MessageReceiver extends XGPushBaseReceiver { private static final String ACTION_APP_CONTROL = "81"; /*更新白名单*/ private static final String UPDATE_WHITE_LIST = "83"; + /*远程log*/ + private static final String SN_RUN_LOG = "84"; /*一键断网*/ private static final String ACTION_DISABLE_NETWORK = "85"; @@ -794,6 +797,9 @@ public class MessageReceiver extends XGPushBaseReceiver { case UPDATE_WHITE_LIST: NetInterfaceManager.getInstance().getAllappPackage(); break; + case SN_RUN_LOG: + recordLog(extras); + break; case ACTION_DISABLE_NETWORK: ToastUtil.debugShow("收到推送消息: 一键断网"); oneKeyNetwork(context, extras); @@ -1246,7 +1252,7 @@ public class MessageReceiver extends XGPushBaseReceiver { JsonObject jSONObject = GsonUtils.getJsonObject(jsonString); type = jSONObject.get("type").getAsInt(); - if (!ServiceAliveUtils.isServiceAlice(context, ManagerService.class.getName())) { + if (!ServiceAliveUtils.isServiceAlive(context, ManagerService.class.getName())) { context.startService(new Intent(context, ManagerService.class)); } Intent intent = new Intent(); @@ -1572,5 +1578,10 @@ public class MessageReceiver extends XGPushBaseReceiver { } } - + private void recordLog(String jsonString) { + if (!ServiceAliveUtils.isServiceAlive(mContext, LogcatService.class.getName())) { + mContext.startService(new Intent(mContext, LogcatService.class)); + } + NetInterfaceManager.getInstance().getRunLog(); + } } diff --git a/app/src/main/java/com/fuying/sn/utils/ServiceAliveUtils.java b/app/src/main/java/com/fuying/sn/utils/ServiceAliveUtils.java index f2ab2a8..821c645 100644 --- a/app/src/main/java/com/fuying/sn/utils/ServiceAliveUtils.java +++ b/app/src/main/java/com/fuying/sn/utils/ServiceAliveUtils.java @@ -6,19 +6,19 @@ import android.util.Log; public class ServiceAliveUtils { - public static boolean isServiceAlice(Context context,String className) { + public static boolean isServiceAlive(Context mContext, String serviceName) { boolean isServiceRunning = false; ActivityManager manager = - (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); if (manager == null) { return false; } for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { - if (className.equals(service.service.getClassName())) { + if (serviceName.equals(service.service.getClassName())) { isServiceRunning = true; } } - Log.e("ServiceAliveUtils", "className isServiceAlice: " + isServiceRunning); + Log.i("ServiceAliveUtils", serviceName + " :isServiceAlive: " + isServiceRunning); return isServiceRunning; } }