清理死代码并修复日志、广播、上报等细节问题
This commit is contained in:
1 parent
a75dada468
commit
51cf8340e8
17 files changed
+57
-2230
No files matched your search
@@ -47,14 +47,6 @@ public interface DeviceSyncGateway {
|
||||
*/
|
||||
void reportAppUsage(String packageName, long openTime, long closeTime, Runnable onComplete);
|
||||
|
||||
/**
|
||||
* 上报应用关闭事件。
|
||||
*
|
||||
* @param packageName 应用包名
|
||||
* @param onComplete 上报流程结束后的回调
|
||||
*/
|
||||
void reportAppClose(String packageName, Runnable onComplete);
|
||||
|
||||
/**
|
||||
* 重新拉取应用管控策略。
|
||||
*/
|
||||
|
||||
@@ -2,20 +2,9 @@ package com.fuying.sn.core.data.local.db.log;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -159,39 +148,6 @@ public class LogDBManager {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public String saveToFile() {
|
||||
List<LogBean> logBeanList = getLogList();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss");
|
||||
Date date = new Date(System.currentTimeMillis());
|
||||
String fileName = sdf.format(date) + " log.txt";
|
||||
String filePath = ContextCompat.getExternalFilesDirs(mContext, Environment.DIRECTORY_DOCUMENTS)[0].getAbsolutePath()
|
||||
+ File.separator + fileName;
|
||||
File logFile = new File(filePath);
|
||||
if (logFile.exists()) {
|
||||
logFile.delete();
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (LogBean logBean : logBeanList) {
|
||||
stringBuilder.append(logBean.toLogString()).append("\n");
|
||||
}
|
||||
byte[] bs = stringBuilder.toString().getBytes();
|
||||
try {
|
||||
OutputStream out = new FileOutputStream(logFile);
|
||||
InputStream is = new ByteArrayInputStream(bs);
|
||||
byte[] buff = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = is.read(buff)) != -1) {
|
||||
out.write(buff, 0, len);
|
||||
}
|
||||
is.close();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "saveToFile: " + e.getMessage(), e);
|
||||
}
|
||||
Log.e(TAG, "saveToFile: " + logFile.getAbsolutePath());
|
||||
return logFile.getAbsolutePath();
|
||||
}
|
||||
|
||||
private void execute(String method, Runnable task) {
|
||||
mExecutor.execute(() -> {
|
||||
try {
|
||||
|
||||
@@ -186,7 +186,7 @@ public class HomeActivity extends BaseMvvmActivity<HomeViewModel, ActivityHomeBi
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == KeyEvent.ACTION_DOWN) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
|
||||
lazyExit();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package com.fuying.sn.feature.home;
|
||||
|
||||
import android.app.Application;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.fuying.sn.core.base.mvvm.BaseAndroidViewModel;
|
||||
import com.fuying.sn.core.common.crypto.CXAESUtil;
|
||||
import com.fuying.sn.core.common.device.DeviceIdUtils;
|
||||
import com.fuying.sn.core.common.image.BitmapUtils;
|
||||
import com.fuying.sn.core.common.sync.DeviceSyncGateway;
|
||||
import com.fuying.sn.core.common.sync.DeviceSyncGateways;
|
||||
import com.fuying.sn.core.data.dto.common.BaseResponse;
|
||||
@@ -53,15 +49,6 @@ public class HomeViewModel extends BaseAndroidViewModel {
|
||||
mDisposables.add(disposable);
|
||||
}
|
||||
|
||||
public MutableLiveData<Bitmap> mQRCodeData = new MutableLiveData<>();
|
||||
|
||||
public void getQRCode() {
|
||||
String encryptString = CXAESUtil.encrypt(DeviceIdUtils.getIMEI(getApplication()));
|
||||
Log.e(TAG, "getQRCode: setImageAndText: " + encryptString);
|
||||
Bitmap bitmap = BitmapUtils.createQRImage(encryptString, 400, 400);
|
||||
mQRCodeData.setValue(bitmap);
|
||||
}
|
||||
|
||||
public void getAllApp() {
|
||||
Disposable disposable = DeviceSyncGateways.get().requestAppWhitelist(new DeviceSyncGateway.RequestCallback() {
|
||||
@Override
|
||||
|
||||
@@ -15,42 +15,20 @@ public class InstallResultReceiver extends BroadcastReceiver {
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// an Intent broadcast.
|
||||
//throw new UnsupportedOperationException("Not yet implemented");
|
||||
|
||||
|
||||
if (intent != null) {
|
||||
final int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS,
|
||||
PackageInstaller.STATUS_FAILURE);
|
||||
if (status == PackageInstaller.STATUS_SUCCESS) {
|
||||
// success
|
||||
String PACKAGE_NAME = intent.getStringExtra("android.content.pm.extra.PACKAGE_NAME");
|
||||
|
||||
Log.e(TAG, "APP Install Success!");
|
||||
} else {
|
||||
String msg = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
|
||||
}
|
||||
if (intent == null) {
|
||||
Log.e(TAG, "onReceive: intent is null");
|
||||
return;
|
||||
}
|
||||
// String s = intent.getAction();
|
||||
// Log.e(TAG, "fht: " + s);
|
||||
// Bundle extras = intent.getExtras();
|
||||
// Set<String> ks = extras.keySet();
|
||||
// Iterator<String> iterator = ks.iterator();
|
||||
// while (iterator.hasNext()) {
|
||||
// Log.e(TAG, "KEY: " + iterator.next());
|
||||
// }
|
||||
String STATUS = intent.getStringExtra(PackageInstaller.EXTRA_STATUS);
|
||||
String PACKAGE_NAME = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME);
|
||||
String SESSION_ID = intent.getStringExtra(PackageInstaller.EXTRA_SESSION_ID);
|
||||
String STATUS_MESSAGE = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
|
||||
String LEGACY_STATUS = intent.getStringExtra("android.content.pm.extra.LEGACY_STATUS");
|
||||
// Log.e(TAG, "fht: " + STATUS);
|
||||
// Log.e(TAG, "fht: " + PACKAGE_NAME);
|
||||
// Log.e(TAG, "fht: " + SESSION_ID);
|
||||
// Log.e(TAG, "fht: " + LEGACY_STATUS);
|
||||
// Log.e(TAG, "fht: " + STATUS_MESSAGE);
|
||||
if (STATUS_MESSAGE != null && "INSTALL_SUCCEEDED".equals(STATUS_MESSAGE)) {
|
||||
// ToastUtil.show(PACKAGE_NAME + "安装成功");
|
||||
// EXTRA_STATUS 是 int 类型,必须用 getIntExtra 读取
|
||||
final int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS,
|
||||
PackageInstaller.STATUS_FAILURE);
|
||||
String packageName = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME);
|
||||
if (status == PackageInstaller.STATUS_SUCCESS) {
|
||||
Log.e(TAG, "onReceive: 安装成功, packageName = " + packageName);
|
||||
} else {
|
||||
String msg = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
|
||||
Log.e(TAG, "onReceive: 安装失败, packageName = " + packageName
|
||||
+ ", status = " + status + ", msg = " + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,77 +0,0 @@
|
||||
package com.fuying.sn.platform.control;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.fuying.sn.core.common.config.CommonConfig;
|
||||
import com.fuying.sn.core.data.local.prefs.KVStore;
|
||||
|
||||
/**
|
||||
* 控制面板管理类
|
||||
*/
|
||||
public class ControlPanelManager {
|
||||
private static final String TAG = "ControlPanelManager";
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static ControlPanelManager sInstance;
|
||||
private Context mContext;
|
||||
private ContentResolver mResolver;
|
||||
|
||||
private UsbManager mUsbManager;
|
||||
|
||||
public static final String KEY_USB_STATUS = "KEY_USB_STATUS";
|
||||
public static final String USB_STATUS_CHARGE = "usb_charge";
|
||||
public static final String USB_STATUS_MTP = "usb_mtp";
|
||||
public static final String USB_STATUS_MIDI = "usb_midi";
|
||||
|
||||
private ControlPanelManager(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
this.mContext = context;
|
||||
this.mResolver = context.getContentResolver();
|
||||
mUsbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new ControlPanelManager(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static ControlPanelManager getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init ControlPanelManager first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
||||
public boolean setUsbStatus(String action) {
|
||||
String functions = UsbManager.USB_FUNCTION_NONE;
|
||||
switch (action) {
|
||||
case USB_STATUS_CHARGE:
|
||||
functions = UsbManager.USB_FUNCTION_NONE;
|
||||
break;
|
||||
case USB_STATUS_MTP:
|
||||
functions = UsbManager.USB_FUNCTION_MTP;
|
||||
break;
|
||||
case USB_STATUS_MIDI:
|
||||
functions = UsbManager.USB_FUNCTION_MIDI;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
KVStore.encode(KEY_USB_STATUS, action);
|
||||
try {
|
||||
mUsbManager.setCurrentFunction(functions, true);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "setUsbStatus: " + e.getLocalizedMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -108,10 +108,21 @@ public class AmapManager {
|
||||
//errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明
|
||||
if (aMapLocation.getErrorCode() == 0) {
|
||||
Log.e(TAG, "onLocationChanged: " + "定位成功");
|
||||
updateAddress(aMapLocation);
|
||||
|
||||
mMapBean = getMapBean(aMapLocation);
|
||||
MapBean newMapBean = getMapBean(aMapLocation);
|
||||
// 地址变化时才同步资料,避免页面每次 onResume 重新定位都触发一次上报
|
||||
boolean addressChanged;
|
||||
if (mMapBean == null) {
|
||||
addressChanged = true;
|
||||
} else {
|
||||
addressChanged = !TextUtils.equals(mMapBean.getAddress(), newMapBean.getAddress());
|
||||
}
|
||||
|
||||
mMapBean = newMapBean;
|
||||
saveMapResult(mMapBean);
|
||||
if (addressChanged) {
|
||||
DeviceSyncGateways.get().requestProfileSync();
|
||||
}
|
||||
LiveEventBus.get(CommonConfig.MAP_BEAN)
|
||||
.post(mMapBean);
|
||||
LiveEventBus.get(CommonConfig.MAP_ADDRESS_KEY)
|
||||
@@ -131,10 +142,6 @@ public class AmapManager {
|
||||
}
|
||||
};
|
||||
|
||||
private void updateAddress(AMapLocation aMapLocation) {
|
||||
DeviceSyncGateways.get().requestProfileSync();
|
||||
}
|
||||
|
||||
private MapBean getMapBean(AMapLocation location) {
|
||||
MapBean mapBean = new MapBean();
|
||||
mapBean.setLongitude(location.getLongitude());
|
||||
|
||||
@@ -100,6 +100,9 @@ public class SystemUtils {
|
||||
if (context != null) {
|
||||
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (mConnectivityManager == null) {
|
||||
return false;
|
||||
}
|
||||
NetworkInfo mNetworkInfo = mConnectivityManager
|
||||
.getActiveNetworkInfo();
|
||||
if (mNetworkInfo != null) {
|
||||
|
||||
@@ -409,8 +409,13 @@ public class TimeManager {
|
||||
/**
|
||||
* 核心检测循环:每秒执行一次管控校验
|
||||
*/
|
||||
/**
|
||||
* 每秒检测任务的订阅句柄,销毁时必须释放,否则循环会一直运行
|
||||
*/
|
||||
private Disposable mIntervalDisposable;
|
||||
|
||||
private void startInIntervalTask() {
|
||||
Observable.interval(1, TimeUnit.SECONDS)
|
||||
mIntervalDisposable = Observable.interval(1, TimeUnit.SECONDS)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(aLong -> {
|
||||
@@ -426,7 +431,7 @@ public class TimeManager {
|
||||
private void checkForegroundAppName() {
|
||||
String pkg = getTopActivityPackageName();
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.e(TAG, "checkForegroundAppName: " + pkg);
|
||||
// Log.e(TAG, "checkForegroundAppName: " + pkg);
|
||||
}
|
||||
if (TextUtils.isEmpty(pkg)) return;
|
||||
|
||||
@@ -1011,6 +1016,10 @@ public class TimeManager {
|
||||
mConfigRetryDisposable.dispose();
|
||||
}
|
||||
mConfigRetryDisposable = null;
|
||||
if (mIntervalDisposable != null && !mIntervalDisposable.isDisposed()) {
|
||||
mIntervalDisposable.dispose();
|
||||
}
|
||||
mIntervalDisposable = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,19 +12,25 @@ import com.fuying.sn.runtime.service.ManagerService;
|
||||
import com.fuying.sn.runtime.service.SocketService;
|
||||
import com.fuying.sn.runtime.service.main.MainService;
|
||||
|
||||
public class
|
||||
BootReceiver extends BroadcastReceiver {
|
||||
public class BootReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "BootReceiver";
|
||||
public static final String BOOT_COMPLETED = CommonConfig.ACTION_ZUOYEOS_BOOT_COMPLETED;
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
String action = null;
|
||||
if (intent != null) {
|
||||
action = intent.getAction();
|
||||
}
|
||||
Log.e(TAG, "SNBootReceiver: " + action);
|
||||
if (action == null) {
|
||||
return;
|
||||
}
|
||||
switch (action) {
|
||||
case Intent.ACTION_BOOT_COMPLETED:
|
||||
KVStore.encode(CommonConfig.DEVICES_REBOOT, true);
|
||||
// 开机广播需要继续走下面统一的启动流程
|
||||
case BOOT_COMPLETED:
|
||||
context.startService(new Intent(context, MainService.class));
|
||||
context.startService(new Intent(context, SocketService.class));
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
package com.fuying.sn.runtime.service;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@@ -17,15 +12,12 @@ import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.fuying.sn.KeepAliveConnection;
|
||||
import com.fuying.sn.R;
|
||||
import com.fuying.sn.core.base.BaseService;
|
||||
import com.fuying.sn.core.common.gson.GsonUtils;
|
||||
import com.fuying.sn.platform.app.ApkUtils;
|
||||
import com.fuying.sn.runtime.service.main.MainService;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DownloadService extends BaseService {
|
||||
private static final String TAG = "DownloadService";
|
||||
|
||||
@@ -62,35 +54,6 @@ public class DownloadService extends BaseService {
|
||||
};
|
||||
}
|
||||
|
||||
private void update(final Bundle bundle) {
|
||||
String url = bundle.getString("url");
|
||||
|
||||
final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/");
|
||||
path.mkdirs();
|
||||
final File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/" + url.substring(url.lastIndexOf("/") + 1));
|
||||
|
||||
if (file.exists() && file.isFile()) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||
.setTitle("软件更新")
|
||||
.setIcon(R.mipmap.ic_launcher)
|
||||
.setCancelable(false)
|
||||
.setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content"))
|
||||
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
ApkUtils.installApk(DownloadService.this, file);
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
});
|
||||
AlertDialog ad = builder.create();
|
||||
ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
|
||||
ad.show();
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@Download.onTaskRunning
|
||||
void running(DownloadTask task) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -74,17 +73,6 @@ public class LogcatService extends BaseService {
|
||||
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) {
|
||||
// Log.e(TAG, "onCreate: " + e.getMessage(), e);
|
||||
// Log.e(TAG, "第一个是Logcat: " + e.getMessage());
|
||||
// }
|
||||
registerLogcatReceiver();
|
||||
}
|
||||
|
||||
@@ -219,61 +207,10 @@ public class LogcatService extends BaseService {
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
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(TAG, "writelog: read logcat process failed. message: "
|
||||
+ e.getMessage());
|
||||
} finally {
|
||||
if (null != os) {
|
||||
try {
|
||||
os.close();
|
||||
os = null;
|
||||
} catch (IOException e) {
|
||||
// 日志输出流关闭失败时,当前实现忽略该异常。
|
||||
Log.e(TAG, "run: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getLog(LogSession session) {
|
||||
Process process = null;
|
||||
@@ -293,12 +230,9 @@ public class LogcatService extends BaseService {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
String logFileName;
|
||||
if (session.clearFile) {
|
||||
logFileName = DeviceIdUtils.getSerial() + ".log";
|
||||
} else {
|
||||
logFileName = DeviceIdUtils.getSerial() + "-" + getTime() + ".log";
|
||||
}
|
||||
// 每轮使用唯一文件名,避免上一轮上传未完成时被下一轮的同名文件覆盖
|
||||
String logFileName = DeviceIdUtils.getSerial() + "-" + getTime()
|
||||
+ "-" + System.currentTimeMillis() + ".log";
|
||||
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
tempFilePath = session.filePath + logFileName;
|
||||
|
||||
@@ -29,7 +29,6 @@ import com.fuying.sn.core.data.remote.UrlAddress;
|
||||
import com.fuying.sn.core.data.repository.DeviceRepository;
|
||||
import com.fuying.sn.runtime.push.PushManager;
|
||||
import com.fuying.sn.runtime.receiver.ApkInstallReceiver;
|
||||
import com.fuying.sn.runtime.receiver.BootReceiver;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.tuo.customview.VerificationCodeView;
|
||||
|
||||
@@ -121,7 +120,6 @@ public class ManagerService extends BaseService implements NetworkUtils.OnNetwor
|
||||
registLockReceiver();
|
||||
registerTimeReceiver();
|
||||
registAppReceive();
|
||||
registBootReceive();
|
||||
setFloatingWindow();
|
||||
// 订阅句柄纳入 mDisposables,Service 销毁时统一释放
|
||||
mDisposables.add(startEvent.throttleFirst(3, TimeUnit.HOURS)
|
||||
@@ -504,18 +502,6 @@ public class ManagerService extends BaseService implements NetworkUtils.OnNetwor
|
||||
ReceiverCompat.registerReceiver(this, apkInstallReceiver, filter, ReceiverCompat.RECEIVER_NOT_EXPORTED);
|
||||
}
|
||||
|
||||
private BootReceiver bootReceiver;
|
||||
|
||||
private void registBootReceive() {
|
||||
if (null == bootReceiver) {
|
||||
bootReceiver = new BootReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||
filter.addAction(Intent.ACTION_USER_PRESENT);
|
||||
ReceiverCompat.registerReceiver(this, bootReceiver, filter, ReceiverCompat.RECEIVER_NOT_EXPORTED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
mDisposables.dispose();
|
||||
@@ -530,9 +516,6 @@ public class ManagerService extends BaseService implements NetworkUtils.OnNetwor
|
||||
if (null != apkInstallReceiver) {
|
||||
ReceiverCompat.unregisterReceiver(this, apkInstallReceiver);
|
||||
}
|
||||
if (null != bootReceiver) {
|
||||
ReceiverCompat.unregisterReceiver(this, bootReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.fuying.sn.runtime.sync;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -161,51 +160,4 @@ public final class AppUsageReporter {
|
||||
});
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void sendCloseApp(String packageName, CompleteCallback completeCallback) {
|
||||
int isLogined = KVStore.decodeInt(CommonConfig.isLogined, 2);
|
||||
if (isLogined != 1) {
|
||||
Log.e(TAG, "sendCloseApp: 没有绑定");
|
||||
// TODO: 2025/6/13 延迟获取不了数据
|
||||
// return;
|
||||
}
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
PackageInfo appInfo = null;
|
||||
try {
|
||||
appInfo = pm.getPackageInfo(packageName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e(TAG, "sendCloseApp: " + e.getMessage(), e);
|
||||
}
|
||||
if (null != appInfo) {
|
||||
String label = appInfo.applicationInfo.loadLabel(pm).toString();
|
||||
long openTime = 0;
|
||||
long closeTime = System.currentTimeMillis() / 1000;
|
||||
repository.getAppUsageRecordObservable(packageName, label, openTime, closeTime)
|
||||
.to(BackgroundRequests.submit(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e(TAG, "SendcloseApp: onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse baseResponse) {
|
||||
Log.e(TAG, "SendcloseApp: onNext: " + baseResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e(TAG, "SendcloseApp: onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e(TAG, "SendcloseApp: onComplete: ");
|
||||
completeCallback.onComplete();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -234,8 +234,7 @@ public final class BrowserPolicySync {
|
||||
//主页
|
||||
Intent homepag = new Intent("qch_app_brower_homepage");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
homepag.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
homepag.setPackage("com.android.browser");
|
||||
}
|
||||
if (!TextUtils.isEmpty(home_page)) {
|
||||
homepag.putExtra("homepage", home_page);
|
||||
@@ -248,8 +247,7 @@ public final class BrowserPolicySync {
|
||||
String label_page = response.data.getLabel_page();
|
||||
Intent websiteBookMark = new Intent("qch_app_brower_website");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
websiteBookMark.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
websiteBookMark.setPackage("com.android.browser");
|
||||
}
|
||||
if (label_page != null && !"".equals(label_page)) {
|
||||
websiteBookMark.putExtra("websiteBookMark", label_page);
|
||||
@@ -260,15 +258,13 @@ public final class BrowserPolicySync {
|
||||
} else {
|
||||
Intent intent1 = new Intent("qch_app_brower_homepage");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
intent1.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
intent1.setPackage("com.android.browser");
|
||||
}
|
||||
intent1.putExtra("homepage", "");
|
||||
mContext.sendBroadcast(intent1);
|
||||
Intent intent2 = new Intent("qch_app_brower_website");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
intent2.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
intent2.setPackage("com.android.browser");
|
||||
}
|
||||
intent2.putExtra("websiteBookMark", "");
|
||||
mContext.sendBroadcast(intent2);
|
||||
|
||||
@@ -51,11 +51,6 @@ public final class DeviceSyncGatewayImpl implements DeviceSyncGateway {
|
||||
AppUsageReporter.getInstance().sendAppUsageRecord(packageName, openTime, closeTime, onComplete::run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportAppClose(String packageName, Runnable onComplete) {
|
||||
AppUsageReporter.getInstance().sendCloseApp(packageName, onComplete::run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshAppTimeControl() {
|
||||
TimePolicySync.getInstance().getAppTimeControl();
|
||||
|
||||
Reference in new issue
Block a user