fix: 修复推送接收/AIDL 兼容/管控开关并清理冗余接口
- 推送: AliyunMessageReceiver 广播 action 改回 com.alibaba.sdk.android.push.RECEIVE,恢复消息接收 - AIDL: 补回 com.fuying.sn.service.RemoteService / receiver.BootReceiver 旧路径壳,兼容外部桌面绑定与开机广播 - 设置写入: 反射调用 IContentProvider 时跳过 Android 13 的 default call(内部固定 authority 为 unknown) - 管控: 关闭管控时仍统计应用使用时长;control/getSetting 仅授权类错误才关闭管控,400 限流保留现有配置 - 缓存: sn/getSnInfo 7 天、device/info 30 天(绑定成功主动失效) - 清理: 删除无调用接口(sn/getTimeControl、device/check-update、file/getFiles)与旧时间管控协议;合并 control/getSetting 双入口 - 上报: Bugly 补充设备型号与渠道信息
This commit is contained in:
1 parent
5c037fb676
commit
72cfca40f6
26 files changed
+202
-827
No files matched your search
@@ -121,6 +121,12 @@
|
|||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
|
|
||||||
|
<!-- 旧路径兼容:外部应用按类名显式绑定 AIDL 服务,勿删 -->
|
||||||
|
<service
|
||||||
|
android:name="com.fuying.sn.service.RemoteService"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".runtime.service.main.MainService"
|
android:name=".runtime.service.main.MainService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
@@ -149,6 +155,11 @@
|
|||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
<!-- 旧路径兼容:外部应用按类名显式发送开机广播,不声明 intent-filter 避免重复处理 -->
|
||||||
|
<receiver
|
||||||
|
android:name="com.fuying.sn.receiver.BootReceiver"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true" />
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".runtime.receiver.ApkInstallReceiver"
|
android:name=".runtime.receiver.ApkInstallReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
@@ -191,7 +202,7 @@
|
|||||||
<action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" />
|
<action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.alibaba.sdk.android.runtime.push.RECEIVE" />
|
<action android:name="com.alibaba.sdk.android.push.RECEIVE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
@@ -205,7 +216,7 @@
|
|||||||
<!-- <action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" />-->
|
<!-- <action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" />-->
|
||||||
<!-- </intent-filter>-->
|
<!-- </intent-filter>-->
|
||||||
<!-- <intent-filter>-->
|
<!-- <intent-filter>-->
|
||||||
<!-- <action android:name="com.alibaba.sdk.android.runtime.push.RECEIVE" />-->
|
<!-- <action android:name="com.alibaba.sdk.android.push.RECEIVE" />-->
|
||||||
<!-- </intent-filter>-->
|
<!-- </intent-filter>-->
|
||||||
<!-- </service>-->
|
<!-- </service>-->
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.fuying.sn.core.base.init;
|
package com.fuying.sn.core.base.init;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.fuying.sn.BuildConfig;
|
||||||
import com.fuying.sn.core.common.device.DeviceIdUtils;
|
import com.fuying.sn.core.common.device.DeviceIdUtils;
|
||||||
import com.hjq.toast.Toaster;
|
import com.hjq.toast.Toaster;
|
||||||
import com.tencent.bugly.crashreport.CrashReport;
|
import com.tencent.bugly.crashreport.CrashReport;
|
||||||
@@ -85,6 +87,8 @@ public final class CoreInitializers {
|
|||||||
public void init(Application application) {
|
public void init(Application application) {
|
||||||
CrashReport.initCrashReport(application, "e5f026c8d5", false);
|
CrashReport.initCrashReport(application, "e5f026c8d5", false);
|
||||||
CrashReport.setDeviceId(application, DeviceIdUtils.getSerial());
|
CrashReport.setDeviceId(application, DeviceIdUtils.getSerial());
|
||||||
|
CrashReport.setDeviceModel(application, Build.MODEL);
|
||||||
|
CrashReport.setAppChannel(application, BuildConfig.platform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,16 +47,6 @@ public interface DeviceSyncGateway {
|
|||||||
*/
|
*/
|
||||||
void reportAppUsage(String packageName, long openTime, long closeTime, Runnable onComplete);
|
void reportAppUsage(String packageName, long openTime, long closeTime, Runnable onComplete);
|
||||||
|
|
||||||
/**
|
|
||||||
* 重新拉取应用管控策略。
|
|
||||||
*/
|
|
||||||
void refreshAppTimeControl();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 重新拉取整机管控策略。
|
|
||||||
*/
|
|
||||||
void refreshMachineTimeControl();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拉取我的应用列表。
|
* 拉取我的应用列表。
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
package com.fuying.sn.core.data.dto.statistics;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class AppRunTimeBean implements Serializable {
|
|
||||||
private static final long serialVersionUID = 3699088127005434759L;
|
|
||||||
|
|
||||||
String packageName;
|
|
||||||
Long appRunTime;
|
|
||||||
|
|
||||||
public AppRunTimeBean() {
|
|
||||||
this.appRunTime = 0L;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AppRunTimeBean(String pkg) {
|
|
||||||
this.packageName = pkg;
|
|
||||||
this.appRunTime = 0L;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AppRunTimeBean(String pkg, long time) {
|
|
||||||
this.packageName = pkg;
|
|
||||||
this.appRunTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPackageName() {
|
|
||||||
return packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPackageName(String packageName) {
|
|
||||||
this.packageName = packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reduceTime(Long time) {
|
|
||||||
this.appRunTime -= time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getAppRunTime() {
|
|
||||||
return appRunTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppRunTime(Long appRunTime) {
|
|
||||||
this.appRunTime = appRunTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
JsonObject jsonObject = JsonParser.parseString(gson.toJson(this)).getAsJsonObject();
|
|
||||||
return jsonObject.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return super.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(@Nullable Object obj) {
|
|
||||||
if (obj instanceof AppRunTimeBean) {
|
|
||||||
AppRunTimeBean appRunTimeBean = (AppRunTimeBean) obj;
|
|
||||||
return appRunTimeBean.packageName.equals(packageName)
|
|
||||||
&& appRunTimeBean.appRunTime.equals(appRunTime);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
package com.fuying.sn.core.data.dto.time;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import com.fuying.sn.core.data.dto.time.PartTime;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class AppTimeControl implements Serializable {
|
|
||||||
private static final long serialVersionUID = -240088037272271214L;
|
|
||||||
|
|
||||||
String app_package;
|
|
||||||
//使用控制方式 0始终可用 1分类 2整机 3自由
|
|
||||||
int tc_use_type;
|
|
||||||
//分类使用控制方式 0始终可用 1整机 2自由
|
|
||||||
int class_use_type;
|
|
||||||
//控制方式开关 0关1开
|
|
||||||
int is_control;
|
|
||||||
//使用额度开关 0关1开
|
|
||||||
int is_quota;
|
|
||||||
//使用时间段开关 0关1开
|
|
||||||
int is_part;
|
|
||||||
//上学日可使用时间 单位秒
|
|
||||||
long work_time;
|
|
||||||
//休息日可使用时间 单位秒
|
|
||||||
long rest_time;
|
|
||||||
//使用时间段类型 0禁用 1开放
|
|
||||||
int part_type;
|
|
||||||
//使用时间段
|
|
||||||
List<PartTime> time_part;
|
|
||||||
//今日可用时间
|
|
||||||
long today_time;
|
|
||||||
//分类ID
|
|
||||||
int tc_class_id;
|
|
||||||
|
|
||||||
public String getApp_package() {
|
|
||||||
return app_package;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApp_package(String app_package) {
|
|
||||||
this.app_package = app_package;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTc_use_type() {
|
|
||||||
return tc_use_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTc_use_type(int tc_use_type) {
|
|
||||||
this.tc_use_type = tc_use_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getClass_use_type() {
|
|
||||||
return class_use_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClass_use_type(int class_use_type) {
|
|
||||||
this.class_use_type = class_use_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIs_control() {
|
|
||||||
return is_control;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIs_control(int is_control) {
|
|
||||||
this.is_control = is_control;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIs_quota() {
|
|
||||||
return is_quota;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIs_quota(int is_quota) {
|
|
||||||
this.is_quota = is_quota;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIs_part() {
|
|
||||||
return is_part;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIs_part(int is_part) {
|
|
||||||
this.is_part = is_part;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getWork_time() {
|
|
||||||
return work_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWork_time(long work_time) {
|
|
||||||
this.work_time = work_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getRest_time() {
|
|
||||||
return rest_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRest_time(long rest_time) {
|
|
||||||
this.rest_time = rest_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPart_type() {
|
|
||||||
return part_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPart_type(int part_type) {
|
|
||||||
this.part_type = part_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<PartTime> getTime_part() {
|
|
||||||
return time_part;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTime_part(List<PartTime> time_part) {
|
|
||||||
this.time_part = time_part;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getToday_time() {
|
|
||||||
return today_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setToday_time(long today_time) {
|
|
||||||
this.today_time = today_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTc_class_id() {
|
|
||||||
return tc_class_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTc_class_id(int tc_class_id) {
|
|
||||||
this.tc_class_id = tc_class_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
package com.fuying.sn.core.data.dto.time;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import com.fuying.sn.core.data.dto.time.PartTime;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class MachineControl implements Serializable {
|
|
||||||
private static final long serialVersionUID = 8554412088242960068L;
|
|
||||||
|
|
||||||
int id;
|
|
||||||
/*是否开启整机额度*/
|
|
||||||
int is_quota;
|
|
||||||
/*上学日额度*/
|
|
||||||
long work_time;
|
|
||||||
/*休息日额度*/
|
|
||||||
long rest_time;
|
|
||||||
|
|
||||||
/*整机使用时间段控制*/
|
|
||||||
int is_part;
|
|
||||||
/*开放或者禁用类型*/
|
|
||||||
int part_type;
|
|
||||||
/*今日剩余时长*/
|
|
||||||
long today_time;
|
|
||||||
/*上学日时间段*/
|
|
||||||
List<PartTime> time_part;
|
|
||||||
|
|
||||||
/*是否设置了可用时间*/
|
|
||||||
int is_set;
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIs_quota() {
|
|
||||||
return is_quota;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIs_quota(int is_quota) {
|
|
||||||
this.is_quota = is_quota;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getWork_time() {
|
|
||||||
return work_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWork_time(long work_time) {
|
|
||||||
this.work_time = work_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getRest_time() {
|
|
||||||
return rest_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRest_time(long rest_time) {
|
|
||||||
this.rest_time = rest_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIs_part() {
|
|
||||||
return is_part;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIs_part(int is_part) {
|
|
||||||
this.is_part = is_part;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPart_type() {
|
|
||||||
return part_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPart_type(int part_type) {
|
|
||||||
this.part_type = part_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getToday_time() {
|
|
||||||
return today_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setToday_time(long today_time) {
|
|
||||||
this.today_time = today_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<PartTime> getTime_part() {
|
|
||||||
return time_part;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTime_part(List<PartTime> time_part) {
|
|
||||||
this.time_part = time_part;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIs_set() {
|
|
||||||
return is_set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIs_set(int is_set) {
|
|
||||||
this.is_set = is_set;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,8 +24,6 @@ public class UrlAddress {
|
|||||||
public final static String GET_APP_START = "sn/querySnAppStart";
|
public final static String GET_APP_START = "sn/querySnAppStart";
|
||||||
/*app跳转管控*/
|
/*app跳转管控*/
|
||||||
public final static String GET_APP_JUMP = "sn/querySnJump";
|
public final static String GET_APP_JUMP = "sn/querySnJump";
|
||||||
/*获取时间管控*/
|
|
||||||
public final static String GET_TIME_CONTROL = "sn/getTimeControl";
|
|
||||||
/*获取屏幕管控*/
|
/*获取屏幕管控*/
|
||||||
public final static String GET_SCREEN_LOCK = "sn/getScreenshot";
|
public final static String GET_SCREEN_LOCK = "sn/getScreenshot";
|
||||||
/*获取锁屏密码*/
|
/*获取锁屏密码*/
|
||||||
@@ -69,14 +67,6 @@ public class UrlAddress {
|
|||||||
/*获取是否为网课模式*/
|
/*获取是否为网课模式*/
|
||||||
public static final String GET_CLOUD_LESSON_SETTING = "Control/getCloudLessonSetting";
|
public static final String GET_CLOUD_LESSON_SETTING = "Control/getCloudLessonSetting";
|
||||||
|
|
||||||
/*获取app桌面管控配置*/
|
|
||||||
@Deprecated
|
|
||||||
public final static String GET_APP_TIME_CONTROL = "Control/getAppTimeControl";
|
|
||||||
/*获取整机管控配置*/
|
|
||||||
@Deprecated
|
|
||||||
public final static String GET_SN_TIME_CONTROL = "Control/getSnTimeControl";
|
|
||||||
|
|
||||||
|
|
||||||
/*2026新接口*/
|
/*2026新接口*/
|
||||||
/*获取整体管控状态和时长*/
|
/*获取整体管控状态和时长*/
|
||||||
public final static String SN_TIME_CONTROL = "control/sn-time-control";
|
public final static String SN_TIME_CONTROL = "control/sn-time-control";
|
||||||
@@ -85,8 +75,6 @@ public class UrlAddress {
|
|||||||
|
|
||||||
/*获取设备绑定信息*/
|
/*获取设备绑定信息*/
|
||||||
public final static String DEVICE_INFO = "device/info";
|
public final static String DEVICE_INFO = "device/info";
|
||||||
/*检查设备守护更新*/
|
|
||||||
public final static String CHECK_UPDATE = "device/check-update";
|
|
||||||
|
|
||||||
/*使用统计*/
|
/*使用统计*/
|
||||||
/*获取整机控制配置*/
|
/*获取整机控制配置*/
|
||||||
@@ -100,8 +88,6 @@ public class UrlAddress {
|
|||||||
|
|
||||||
/*获取小程序二维码*/
|
/*获取小程序二维码*/
|
||||||
public static final String GET_APPLET_QRCODE = "file/getAppletQrCode";
|
public static final String GET_APPLET_QRCODE = "file/getAppletQrCode";
|
||||||
/*获取操作指南*/
|
|
||||||
public static final String GET_OPERATION_GUIDE = "file/getFiles";
|
|
||||||
|
|
||||||
/*全局黑名单列表*/
|
/*全局黑名单列表*/
|
||||||
public final static String GLOBAL_BLACKLIST = "common/blacklist";
|
public final static String GLOBAL_BLACKLIST = "common/blacklist";
|
||||||
|
|||||||
@@ -13,11 +13,4 @@ public interface DeviceInfoApi {
|
|||||||
Observable<BaseResponse<DeviceInfo>> getDeviceInfo(
|
Observable<BaseResponse<DeviceInfo>> getDeviceInfo(
|
||||||
@Query("sn") String sn
|
@Query("sn") String sn
|
||||||
);
|
);
|
||||||
|
|
||||||
@GET(UrlAddress.CHECK_UPDATE)
|
|
||||||
Observable<BaseResponse> checkUpdate(
|
|
||||||
@Query("sn") String sn,
|
|
||||||
@Query("platform") String platform,
|
|
||||||
@Query("app_package") String app_package
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
@@ -6,16 +6,9 @@ import com.fuying.sn.core.data.remote.UrlAddress;
|
|||||||
|
|
||||||
import io.reactivex.rxjava3.core.Observable;
|
import io.reactivex.rxjava3.core.Observable;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Query;
|
|
||||||
|
|
||||||
public interface FileApi {
|
public interface FileApi {
|
||||||
@GET(UrlAddress.GET_APPLET_QRCODE)
|
@GET(UrlAddress.GET_APPLET_QRCODE)
|
||||||
Observable<BaseResponse<AppletQRCode>> getQRCodeApi();
|
Observable<BaseResponse<AppletQRCode>> getQRCodeApi();
|
||||||
|
|
||||||
@GET(UrlAddress.GET_OPERATION_GUIDE)
|
|
||||||
Observable<BaseResponse> getGuidePic(
|
|
||||||
@Query("type") int type
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,12 +5,8 @@ import com.fuying.sn.core.data.dto.device.CloudLessonSetting;
|
|||||||
import com.fuying.sn.core.data.dto.device.Label;
|
import com.fuying.sn.core.data.dto.device.Label;
|
||||||
import com.fuying.sn.core.data.dto.device.SystemSettingsSet;
|
import com.fuying.sn.core.data.dto.device.SystemSettingsSet;
|
||||||
import com.fuying.sn.core.data.dto.browser.BrowserApiData;
|
import com.fuying.sn.core.data.dto.browser.BrowserApiData;
|
||||||
import com.fuying.sn.core.data.dto.time.AppTimeControl;
|
|
||||||
import com.fuying.sn.core.data.dto.time.MachineControl;
|
|
||||||
import com.fuying.sn.core.data.remote.UrlAddress;
|
import com.fuying.sn.core.data.remote.UrlAddress;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import io.reactivex.rxjava3.core.Observable;
|
import io.reactivex.rxjava3.core.Observable;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
@@ -41,16 +37,4 @@ public interface SettingsApi {
|
|||||||
@Query("sn") String sn
|
@Query("sn") String sn
|
||||||
);
|
);
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@GET(UrlAddress.GET_APP_TIME_CONTROL)
|
|
||||||
Observable<BaseResponse<List<AppTimeControl>>> getAppTimeControl(
|
|
||||||
@Query("sn") String sn
|
|
||||||
);
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@GET(UrlAddress.GET_SN_TIME_CONTROL)
|
|
||||||
Observable<BaseResponse<MachineControl>> getSnTimeControl(
|
|
||||||
@Query("sn") String sn
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,18 @@
|
|||||||
package com.fuying.sn.core.data.remote.api;
|
package com.fuying.sn.core.data.remote.api;
|
||||||
|
|
||||||
import com.fuying.sn.core.data.dto.common.BaseResponse;
|
import com.fuying.sn.core.data.dto.common.BaseResponse;
|
||||||
import com.fuying.sn.core.data.dto.common.BatchID;
|
|
||||||
import com.fuying.sn.core.data.dto.device.SnBindState;
|
import com.fuying.sn.core.data.dto.device.SnBindState;
|
||||||
import com.fuying.sn.core.data.dto.device.SnInfo;
|
import com.fuying.sn.core.data.dto.device.SnInfo;
|
||||||
import com.fuying.sn.core.data.dto.device.SnTag;
|
import com.fuying.sn.core.data.dto.device.SnTag;
|
||||||
import com.fuying.sn.core.data.dto.device.UserAvatarInfo;
|
|
||||||
import com.fuying.sn.core.data.remote.UrlAddress;
|
import com.fuying.sn.core.data.remote.UrlAddress;
|
||||||
|
|
||||||
import io.reactivex.rxjava3.core.Observable;
|
import io.reactivex.rxjava3.core.Observable;
|
||||||
import retrofit2.http.Field;
|
|
||||||
import retrofit2.http.FormUrlEncoded;
|
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.POST;
|
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
|
|
||||||
public interface SnApi {
|
public interface SnApi {
|
||||||
@GET(UrlAddress.SN_INFO)
|
@GET(UrlAddress.SN_INFO)
|
||||||
Observable<BaseResponse<SnInfo>> getsninfo(
|
Observable<BaseResponse<SnInfo>> getSnInfo(
|
||||||
@Query("sn") String sn
|
@Query("sn") String sn
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -26,11 +26,6 @@ public interface SnControlApi {
|
|||||||
@Query("sn") String sn
|
@Query("sn") String sn
|
||||||
);
|
);
|
||||||
|
|
||||||
@GET(UrlAddress.GET_TIME_CONTROL)
|
|
||||||
Observable<BaseResponse> getTimeControl(
|
|
||||||
@Query("sn") String sn
|
|
||||||
);
|
|
||||||
|
|
||||||
@GET(UrlAddress.GET_SCREEN_LOCK)
|
@GET(UrlAddress.GET_SCREEN_LOCK)
|
||||||
Observable<BaseResponse> getScreenshot(
|
Observable<BaseResponse> getScreenshot(
|
||||||
@Query("sn") String sn
|
@Query("sn") String sn
|
||||||
|
|||||||
@@ -25,9 +25,8 @@ import com.fuying.sn.core.data.dto.device.SnTag;
|
|||||||
import com.fuying.sn.core.data.dto.time.SnTimeControlInfo;
|
import com.fuying.sn.core.data.dto.time.SnTimeControlInfo;
|
||||||
import com.fuying.sn.core.data.dto.device.SystemSettingsSet;
|
import com.fuying.sn.core.data.dto.device.SystemSettingsSet;
|
||||||
import com.fuying.sn.core.data.dto.browser.BrowserApiData;
|
import com.fuying.sn.core.data.dto.browser.BrowserApiData;
|
||||||
import com.fuying.sn.core.data.dto.time.AppTimeControl;
|
|
||||||
import com.fuying.sn.core.data.dto.time.MachineControl;
|
|
||||||
import com.fuying.sn.core.data.local.cache.CacheHelper;
|
import com.fuying.sn.core.data.local.cache.CacheHelper;
|
||||||
|
import com.fuying.sn.core.data.local.prefs.KVStore;
|
||||||
import com.fuying.sn.core.common.gson.GsonUtils;
|
import com.fuying.sn.core.common.gson.GsonUtils;
|
||||||
import com.fuying.sn.core.data.remote.OkHttpManager;
|
import com.fuying.sn.core.data.remote.OkHttpManager;
|
||||||
import com.fuying.sn.core.data.remote.UrlAddress;
|
import com.fuying.sn.core.data.remote.UrlAddress;
|
||||||
@@ -68,10 +67,15 @@ public final class DeviceRepository {
|
|||||||
private static final String TAG = "DeviceRepository";
|
private static final String TAG = "DeviceRepository";
|
||||||
// 管控配置的显式刷新会先失效内存缓存,这里的 TTL 只用于页面等非强制读取
|
// 管控配置的显式刷新会先失效内存缓存,这里的 TTL 只用于页面等非强制读取
|
||||||
private static final long DEFAULT_CACHE_EXPIRE = TimeUnit.SECONDS.toMillis(30);
|
private static final long DEFAULT_CACHE_EXPIRE = TimeUnit.SECONDS.toMillis(30);
|
||||||
private static final long SN_INFO_CACHE_TTL_MS = TimeUnit.HOURS.toMillis(24);
|
// 设备信息基本不会变化,缓存放宽到 7 天;push 等场景仍会主动 removeCache(SN_INFO) 强制回源
|
||||||
|
private static final long SN_INFO_CACHE_TTL_MS = TimeUnit.DAYS.toMillis(7);
|
||||||
|
// 设备详情(绑定时间等)基本不会变化,缓存 30 天,绑定成功时主动失效
|
||||||
|
private static final long DEVICE_INFO_CACHE_TTL_MS = TimeUnit.DAYS.toMillis(30);
|
||||||
|
private static final String DEVICE_INFO_CACHE_SAVED_AT = "device_info_cache_saved_at";
|
||||||
|
private static final Type DEVICE_INFO_RESPONSE_TYPE = new TypeToken<BaseResponse<DeviceInfo>>() {
|
||||||
|
}.getType();
|
||||||
private static final long SN_INFO_OTHER_STATUS_TTL_MS = TimeUnit.SECONDS.toMillis(30);
|
private static final long SN_INFO_OTHER_STATUS_TTL_MS = TimeUnit.SECONDS.toMillis(30);
|
||||||
private static final long CACHE_EXPIRE_ONE_MINUTE = TimeUnit.MINUTES.toMillis(1);
|
private static final long CACHE_EXPIRE_ONE_MINUTE = TimeUnit.MINUTES.toMillis(1);
|
||||||
private static final String SYSTEM_SETTINGS_REFRESH = UrlAddress.GET_SETTINGS + ":refresh";
|
|
||||||
private static final long INVALIDATED_RETRY_BASE_MS = 2345;
|
private static final long INVALIDATED_RETRY_BASE_MS = 2345;
|
||||||
private static final long INVALIDATED_RETRY_SPREAD_MS = TimeUnit.SECONDS.toMillis(30);
|
private static final long INVALIDATED_RETRY_SPREAD_MS = TimeUnit.SECONDS.toMillis(30);
|
||||||
|
|
||||||
@@ -109,9 +113,6 @@ public final class DeviceRepository {
|
|||||||
synchronized (CACHE_LOCK) {
|
synchronized (CACHE_LOCK) {
|
||||||
CACHE_GENERATIONS.put(key, new Object());
|
CACHE_GENERATIONS.put(key, new Object());
|
||||||
IN_FLIGHT_REQUESTS.remove(key);
|
IN_FLIGHT_REQUESTS.remove(key);
|
||||||
if (UrlAddress.GET_SETTINGS.equals(key)) {
|
|
||||||
IN_FLIGHT_REQUESTS.remove(SYSTEM_SETTINGS_REFRESH);
|
|
||||||
}
|
|
||||||
CACHE_MANAGER.removeCache(key);
|
CACHE_MANAGER.removeCache(key);
|
||||||
// 同时清理内存和磁盘,避免推送刷新再次发出已作废的配置。
|
// 同时清理内存和磁盘,避免推送刷新再次发出已作废的配置。
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
@@ -226,6 +227,9 @@ public final class DeviceRepository {
|
|||||||
if (value.code == 200 && value.data != null) {
|
if (value.code == 200 && value.data != null) {
|
||||||
CACHE_MANAGER.saveCache(key, value, ttlMillis);
|
CACHE_MANAGER.saveCache(key, value, ttlMillis);
|
||||||
putDiskAsync(key, value);
|
putDiskAsync(key, value);
|
||||||
|
} else if (value.code == 400) {
|
||||||
|
// 限流响应不代表配置失效,保留上一份成功数据,保证离线/降级时仍可管控
|
||||||
|
Log.e(TAG, "withMultiLevelCache: 服务端限流(code=400),保留本地缓存 " + key);
|
||||||
} else {
|
} else {
|
||||||
clearCachedValues(key);
|
clearCachedValues(key);
|
||||||
}
|
}
|
||||||
@@ -381,7 +385,7 @@ public final class DeviceRepository {
|
|||||||
* 设备信息优先使用内存缓存;成功网络响应写入磁盘,其他响应短时缓存并移除磁盘副本。
|
* 设备信息优先使用内存缓存;成功网络响应写入磁盘,其他响应短时缓存并移除磁盘副本。
|
||||||
*/
|
*/
|
||||||
public Observable<BaseResponse<SnInfo>> getSnInfoControl() {
|
public Observable<BaseResponse<SnInfo>> getSnInfoControl() {
|
||||||
return withCache(getSnApi().getsninfo(DeviceIdUtils.getSerial()),
|
return withCache(getSnApi().getSnInfo(DeviceIdUtils.getSerial()),
|
||||||
UrlAddress.SN_INFO,
|
UrlAddress.SN_INFO,
|
||||||
response -> {
|
response -> {
|
||||||
if (response.code == 200 && response.data != null) {
|
if (response.code == 200 && response.data != null) {
|
||||||
@@ -416,16 +420,16 @@ public final class DeviceRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备应用设置时直接请求网络,合并当前同代并发请求,作废后按统一调度逻辑重试。
|
* 获取系统设置。
|
||||||
|
*
|
||||||
|
* @param forceRefresh true 时先失效内存缓存,保证本次走网络刷新(磁盘数据仍作为兜底);
|
||||||
|
* false 时与页面读取共用同一份缓存,避免重复请求
|
||||||
*/
|
*/
|
||||||
public Observable<BaseResponse<SystemSettingsSet>> fetchSystemSettings() {
|
public Observable<BaseResponse<SystemSettingsSet>> getSettingControl(boolean forceRefresh) {
|
||||||
return scheduleForCache(UrlAddress.GET_SETTINGS, Observable.defer(() -> {
|
if (forceRefresh) {
|
||||||
synchronized (CACHE_LOCK) {
|
invalidateMemory(UrlAddress.GET_SETTINGS);
|
||||||
return joinInFlight(SYSTEM_SETTINGS_REFRESH, getSettingsApi().getSetting(DeviceIdUtils.getSerial()),
|
}
|
||||||
response -> {
|
return getSettingControl();
|
||||||
});
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<BaseResponse<List<AppInfo>>> getForceInstallControl() {
|
public Observable<BaseResponse<List<AppInfo>>> getForceInstallControl() {
|
||||||
@@ -473,16 +477,6 @@ public final class DeviceRepository {
|
|||||||
return scheduleIo(getAppApi().getOverallApp(platformCode));
|
return scheduleIo(getAppApi().getOverallApp(platformCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Observable<BaseResponse<List<AppTimeControl>>> getAppTimeControlObservable() {
|
|
||||||
return schedule(getSettingsApi().getAppTimeControl(DeviceIdUtils.getSerial()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Observable<BaseResponse<MachineControl>> getMachineTimeControlObservable() {
|
|
||||||
return schedule(getSettingsApi().getSnTimeControl(DeviceIdUtils.getSerial()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Observable<BaseResponse> getAppUsageRecordObservable(String pkg, String pkgName, Long open_time, Long close_time) {
|
public Observable<BaseResponse> getAppUsageRecordObservable(String pkg, String pkgName, Long open_time, Long close_time) {
|
||||||
return schedule(getCommonApi().sendAppUsageRecord(DeviceIdUtils.getSerial(), pkg, pkgName, open_time, close_time));
|
return schedule(getCommonApi().sendAppUsageRecord(DeviceIdUtils.getSerial(), pkg, pkgName, open_time, close_time));
|
||||||
}
|
}
|
||||||
@@ -547,8 +541,42 @@ public final class DeviceRepository {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备详情(绑定时间等)基本不会变化:30 天内直接复用本地缓存,过期后才回源;
|
||||||
|
* 绑定成功时会主动 {@link #removeCache(String)} 失效。
|
||||||
|
*/
|
||||||
public Observable<DeviceInfo> getDeviceInfoObservable() {
|
public Observable<DeviceInfo> getDeviceInfoObservable() {
|
||||||
return unwrap(schedule(getDeviceInfoApi().getDeviceInfo(DeviceIdUtils.getSerial())));
|
return unwrap(scheduleForCache(UrlAddress.DEVICE_INFO, Observable.defer(() -> {
|
||||||
|
BaseResponse<DeviceInfo> fresh = CACHE_MANAGER.getCache(UrlAddress.DEVICE_INFO);
|
||||||
|
if (fresh != null) {
|
||||||
|
return Observable.just(fresh);
|
||||||
|
}
|
||||||
|
if (isDeviceInfoCacheFresh()) {
|
||||||
|
BaseResponse<DeviceInfo> cached = readDisk(UrlAddress.DEVICE_INFO, DEVICE_INFO_RESPONSE_TYPE);
|
||||||
|
if (cached != null) {
|
||||||
|
return Observable.just(cached);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return joinInFlight(UrlAddress.DEVICE_INFO,
|
||||||
|
getDeviceInfoApi().getDeviceInfo(DeviceIdUtils.getSerial()),
|
||||||
|
response -> {
|
||||||
|
if (response.code == 200 && response.data != null) {
|
||||||
|
CACHE_MANAGER.saveCache(UrlAddress.DEVICE_INFO, response, DEVICE_INFO_CACHE_TTL_MS);
|
||||||
|
putDiskAsync(UrlAddress.DEVICE_INFO, response);
|
||||||
|
KVStore.encode(DEVICE_INFO_CACHE_SAVED_AT, System.currentTimeMillis());
|
||||||
|
} else {
|
||||||
|
clearCachedValues(UrlAddress.DEVICE_INFO);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备详情的磁盘缓存是否仍在有效期内(30 天)。
|
||||||
|
*/
|
||||||
|
private boolean isDeviceInfoCacheFresh() {
|
||||||
|
long savedAt = KVStore.decodeLong(DEVICE_INFO_CACHE_SAVED_AT, 0L);
|
||||||
|
return savedAt > 0 && System.currentTimeMillis() - savedAt < DEVICE_INFO_CACHE_TTL_MS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import com.fuying.sn.platform.control.ControlManager;
|
|||||||
import com.fuying.sn.platform.location.AmapManager;
|
import com.fuying.sn.platform.location.AmapManager;
|
||||||
import com.fuying.sn.platform.system.DeviceManager;
|
import com.fuying.sn.platform.system.DeviceManager;
|
||||||
import com.fuying.sn.platform.system.JgyUtils;
|
import com.fuying.sn.platform.system.JgyUtils;
|
||||||
import com.fuying.sn.platform.time.TimeControlManager;
|
|
||||||
import com.fuying.sn.platform.time.TimeManager;
|
import com.fuying.sn.platform.time.TimeManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -36,7 +35,6 @@ public final class PlatformInitializers {
|
|||||||
List<AppInitializer> initializers = new ArrayList<>();
|
List<AppInitializer> initializers = new ArrayList<>();
|
||||||
initializers.add(new System());
|
initializers.add(new System());
|
||||||
initializers.add(new AppMonitor());
|
initializers.add(new AppMonitor());
|
||||||
initializers.add(new TimeControl());
|
|
||||||
initializers.add(new Control());
|
initializers.add(new Control());
|
||||||
initializers.add(new Device());
|
initializers.add(new Device());
|
||||||
initializers.add(new Location());
|
initializers.add(new Location());
|
||||||
@@ -91,22 +89,6 @@ public final class PlatformInitializers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 应用时间管控:构造时从磁盘缓存恢复上次下发的管控策略。
|
|
||||||
*/
|
|
||||||
public static final class TimeControl implements AppInitializer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean required() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(Application application) {
|
|
||||||
TimeControlManager.init(application);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统设置管控:构造时持有 ContentResolver。
|
* 系统设置管控:构造时持有 ContentResolver。
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -198,6 +198,11 @@ public final class AndroidSettingsWriter {
|
|||||||
if (!"call".equals(m.getName())) {
|
if (!"call".equals(m.getName())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Android 13+ 的 IContentProvider 提供了 4 参 call 的 default 实现,
|
||||||
|
// 内部固定用 "unknown" 作为 authority 转发,必然被 SettingsProvider 拒绝
|
||||||
|
if (m.isDefault()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Class<?>[] p = m.getParameterTypes();
|
Class<?>[] p = m.getParameterTypes();
|
||||||
try {
|
try {
|
||||||
// 1. Android 12+ (5 params: AttributionSource, String, String, String, Bundle)
|
// 1. Android 12+ (5 params: AttributionSource, String, String, String, Bundle)
|
||||||
|
|||||||
@@ -1,189 +0,0 @@
|
|||||||
package com.fuying.sn.platform.time;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.fuying.sn.core.data.dto.time.AppTimeControl;
|
|
||||||
import com.fuying.sn.core.data.dto.time.MachineControl;
|
|
||||||
import com.fuying.sn.core.data.local.cache.CacheHelper;
|
|
||||||
import com.fuying.sn.core.data.remote.UrlAddress;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class TimeControlManager {
|
|
||||||
private static final String TAG = "TimeControlManager";
|
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
|
||||||
private static TimeControlManager sInstance;
|
|
||||||
private Context mContext;
|
|
||||||
private CacheHelper mCacheHelper;
|
|
||||||
|
|
||||||
private HashMap<Integer, AppTimeControl> mClassifyTimeControlHashMap = new HashMap<>();
|
|
||||||
/*分类的所有包名列表*/
|
|
||||||
private HashMap<String, AppTimeControl> mAppTimeControlMap = new HashMap<>();
|
|
||||||
/*整机分类*/
|
|
||||||
private MachineControl mGlobalMachineControl;
|
|
||||||
|
|
||||||
private TimeControlManager(Context context) {
|
|
||||||
if (context == null) {
|
|
||||||
throw new RuntimeException("Context is NULL");
|
|
||||||
}
|
|
||||||
this.mContext = context;
|
|
||||||
this.mCacheHelper = CacheHelper.getInstance(context);
|
|
||||||
String appTimeControlJson = mCacheHelper.getAsString(UrlAddress.GET_APP_TIME_CONTROL);
|
|
||||||
if (!TextUtils.isEmpty(appTimeControlJson)) {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
Type type = new TypeToken<List<AppTimeControl>>() {
|
|
||||||
}.getType();
|
|
||||||
List<AppTimeControl> appTimeControls = gson.fromJson(appTimeControlJson, type);
|
|
||||||
setAppTimeControlMap(appTimeControls);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void init(Context context) {
|
|
||||||
if (sInstance == null) {
|
|
||||||
sInstance = new TimeControlManager(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TimeControlManager getInstance() {
|
|
||||||
if (sInstance == null) {
|
|
||||||
throw new IllegalStateException("You must be init TimeControlManager first");
|
|
||||||
}
|
|
||||||
return sInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, AppTimeControl> getAppTimeControlMap() {
|
|
||||||
return mAppTimeControlMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是否有配置存在
|
|
||||||
*
|
|
||||||
* @param pkg
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean havaConfigure(String pkg) {
|
|
||||||
AppTimeControl appTimeControl = mAppTimeControlMap.get(pkg);
|
|
||||||
if (appTimeControl == null) {
|
|
||||||
Log.e(TAG, "havaConfigure: not");
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if (appTimeControl.getTc_use_type() == 1) {
|
|
||||||
//根据分类
|
|
||||||
Log.e(TAG, "havaConfigure: classify");
|
|
||||||
return mClassifyTimeControlHashMap.get(appTimeControl.getTc_class_id()) != null;
|
|
||||||
}
|
|
||||||
Log.e(TAG, "havaConfigure: hava");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取整机配置
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public MachineControl getGlobalMachineControl() {
|
|
||||||
if (mGlobalMachineControl == null) {
|
|
||||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_SN_TIME_CONTROL);
|
|
||||||
//为 "" 是已经请求成功的
|
|
||||||
if (jsonString == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
Type type = new TypeToken<MachineControl>() {
|
|
||||||
}.getType();
|
|
||||||
MachineControl machineControl = gson.fromJson(jsonString, type);
|
|
||||||
return machineControl;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return mGlobalMachineControl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGlobalMachineControl(MachineControl machineControl) {
|
|
||||||
this.mGlobalMachineControl = machineControl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取app的配置
|
|
||||||
*
|
|
||||||
* @param pkg
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public AppTimeControl getAppTimeControl(String pkg) {
|
|
||||||
AppTimeControl temp = mAppTimeControlMap.get(pkg);
|
|
||||||
if (temp == null) {
|
|
||||||
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_APP_TIME_CONTROL);
|
|
||||||
Log.e(TAG, "getAppTimeControl: jsonString = " + jsonString);
|
|
||||||
//为 "" 是已经请求成功的
|
|
||||||
if (jsonString == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
Type Type = new TypeToken<List<AppTimeControl>>() {
|
|
||||||
}.getType();
|
|
||||||
List<AppTimeControl> appTimeControlList = gson.fromJson(jsonString, Type);
|
|
||||||
if (appTimeControlList == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
HashMap<String, AppTimeControl> appTimeControlMap = new HashMap<>();
|
|
||||||
for (AppTimeControl appTimeControl : appTimeControlList) {
|
|
||||||
appTimeControlMap.put(appTimeControl.getApp_package(), appTimeControl);
|
|
||||||
}
|
|
||||||
setAppTimeControlMap(appTimeControlList);
|
|
||||||
return appTimeControlMap.get(pkg);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppTimeControl(String pkg, AppTimeControl appTimeControl) {
|
|
||||||
this.mAppTimeControlMap.put(pkg, appTimeControl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置app的配置
|
|
||||||
*
|
|
||||||
* @param appTimeControlList
|
|
||||||
*/
|
|
||||||
public void setAppTimeControlMap(List<AppTimeControl> appTimeControlList) {
|
|
||||||
if (appTimeControlList == null || appTimeControlList.size() == 0) {
|
|
||||||
Log.e(TAG, "setAppTimeControlMap: appTimeControlList is empty");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
HashMap<Integer, AppTimeControl> classifyTimeControlHashMap = new HashMap<>();
|
|
||||||
List<AppTimeControl> filterAppTimeControlList = appTimeControlList.stream().filter(appTimeControl -> {
|
|
||||||
//tc_use_type == 1 时用的是分类配置,配置都是一样的
|
|
||||||
return appTimeControl.getTc_use_type() == 1;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
for (AppTimeControl appTimeControl : filterAppTimeControlList) {
|
|
||||||
classifyTimeControlHashMap.put(appTimeControl.getTc_class_id(), appTimeControl);
|
|
||||||
}
|
|
||||||
this.mClassifyTimeControlHashMap = classifyTimeControlHashMap;
|
|
||||||
|
|
||||||
HashMap<String, AppTimeControl> appTimeControlMap = new HashMap<>();
|
|
||||||
List<AppTimeControl> appTimeControls = new ArrayList<>();
|
|
||||||
for (AppTimeControl appTimeControl : appTimeControlList) {
|
|
||||||
// TODO: 2022/6/30 修改为全部配置
|
|
||||||
// if (appTimeControl.getTc_use_type() != 1) {
|
|
||||||
appTimeControlMap.put(appTimeControl.getApp_package(), appTimeControl);
|
|
||||||
appTimeControls.add(appTimeControl);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
this.mAppTimeControlMap = appTimeControlMap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -155,6 +155,18 @@ public class TimeManager {
|
|||||||
private volatile long mLastToastTime = 0;
|
private volatile long mLastToastTime = 0;
|
||||||
private static final long TOAST_INTERVAL = 5000; // 同一拦截提示 5 秒内只弹一次
|
private static final long TOAST_INTERVAL = 5000; // 同一拦截提示 5 秒内只弹一次
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前台应用监听日志:切换应用立即打印,同一应用每 5 秒心跳一次,避免每秒刷屏。
|
||||||
|
*/
|
||||||
|
private String mLastLoggedPackage;
|
||||||
|
private long mLastForegroundLogAt = 0;
|
||||||
|
private static final long FOREGROUND_LOG_INTERVAL = 5000;
|
||||||
|
/**
|
||||||
|
* 管控配置未就绪提示:30 秒内只打印一次,避免每秒刷日志。
|
||||||
|
*/
|
||||||
|
private long mLastConfigMissingLogAt = 0;
|
||||||
|
private static final long CONFIG_MISSING_LOG_INTERVAL = 30000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 免管控白名单,包含系统核心组件及特定工具应用
|
* 免管控白名单,包含系统核心组件及特定工具应用
|
||||||
*/
|
*/
|
||||||
@@ -293,7 +305,7 @@ public class TimeManager {
|
|||||||
*/
|
*/
|
||||||
private void onUidImportanceChanged(int uid, int importance) {
|
private void onUidImportanceChanged(int uid, int importance) {
|
||||||
String packageName = getFirstPackageNameForUid(uid);
|
String packageName = getFirstPackageNameForUid(uid);
|
||||||
Log.e(TAG, "onUidImportanceChanged: uid = " + uid + ", importance = " + importance+", packageName = " + packageName);
|
Log.e(TAG, "onUidImportanceChanged: uid = " + uid + ", importance = " + importance + ", packageName = " + packageName);
|
||||||
if (TextUtils.isEmpty(packageName)) {
|
if (TextUtils.isEmpty(packageName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -314,12 +326,13 @@ public class TimeManager {
|
|||||||
DeviceSyncGateways.get().reportAppUsage(prevPackage, prevStartTime, nowTime, this::getTimeControl);
|
DeviceSyncGateways.get().reportAppUsage(prevPackage, prevStartTime, nowTime, this::getTimeControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 开启对新进入应用的记录(排除系统应用及白名单应用)
|
// 开启对新进入应用的记录:使用统计与管控总开关解耦,
|
||||||
if (!ApkUtils.isSystemApp(mContext, packageName) && !isPackageExempted(packageName)) {
|
// 关闭管控时也要继续记录;仅排除系统应用和管控开启时的白名单应用
|
||||||
|
if (shouldRecordUsage(packageName)) {
|
||||||
Log.e(TAG, "onUidImportanceChanged New foreground app: " + packageName + ". Start recording.");
|
Log.e(TAG, "onUidImportanceChanged New foreground app: " + packageName + ". Start recording.");
|
||||||
usedTime.startRecord(packageName, nowTime);
|
usedTime.startRecord(packageName, nowTime);
|
||||||
}
|
}
|
||||||
// 系统应用或豁免应用:不开启记录,settleAndClear 已清空状态
|
// 系统应用或记入统计白名单的应用:不开启记录,settleAndClear 已清空状态
|
||||||
} else {
|
} else {
|
||||||
// 情况 2: 某个应用离开前台
|
// 情况 2: 某个应用离开前台
|
||||||
// 注意:不能无条件调用 settleAndClear()。
|
// 注意:不能无条件调用 settleAndClear()。
|
||||||
@@ -430,9 +443,7 @@ public class TimeManager {
|
|||||||
*/
|
*/
|
||||||
private void checkForegroundAppName() {
|
private void checkForegroundAppName() {
|
||||||
String pkg = getTopActivityPackageName();
|
String pkg = getTopActivityPackageName();
|
||||||
if (BuildConfig.DEBUG) {
|
logForegroundApp(pkg);
|
||||||
// Log.e(TAG, "checkForegroundAppName: " + pkg);
|
|
||||||
}
|
|
||||||
if (TextUtils.isEmpty(pkg)) return;
|
if (TextUtils.isEmpty(pkg)) return;
|
||||||
|
|
||||||
//如果应用没有退出锁屏,获取到的还是应用的包名
|
//如果应用没有退出锁屏,获取到的还是应用的包名
|
||||||
@@ -452,6 +463,7 @@ public class TimeManager {
|
|||||||
// 2. 检查基本配置是否就绪
|
// 2. 检查基本配置是否就绪
|
||||||
if (mSnTimeControlInfo == null) {
|
if (mSnTimeControlInfo == null) {
|
||||||
// 每秒检查只处理本地限时,配置由启动、联网和推送等事件同步。
|
// 每秒检查只处理本地限时,配置由启动、联网和推送等事件同步。
|
||||||
|
logConfigMissing();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,6 +478,39 @@ public class TimeManager {
|
|||||||
decrementUsageTime(pkg);
|
decrementUsageTime(pkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前台应用监听日志:切换应用立即打印,同一应用每 5 秒心跳一次。
|
||||||
|
* 每秒轮询直接打日志会刷屏,节流后仍能定位当前前台应用。
|
||||||
|
*/
|
||||||
|
private void logForegroundApp(String pkg) {
|
||||||
|
long now = SystemClock.elapsedRealtime();
|
||||||
|
if (TextUtils.equals(pkg, mLastLoggedPackage)
|
||||||
|
&& now - mLastForegroundLogAt < FOREGROUND_LOG_INTERVAL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mLastLoggedPackage = pkg;
|
||||||
|
mLastForegroundLogAt = now;
|
||||||
|
int isControl = Settings.System.getInt(mContext.getContentResolver(), CommonConfig.KEY_IS_CONTROL, 1);
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
Log.e(TAG, "checkForegroundAppName: " + pkg + ", isControl=" + isControl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管控配置未就绪提示:配置拉取被限流或尚未完成时会持续跳过校验,
|
||||||
|
* 这里限频打印,避免“既没有日志也不拦截”的静默状态难以定位。
|
||||||
|
*/
|
||||||
|
private void logConfigMissing() {
|
||||||
|
long now = SystemClock.elapsedRealtime();
|
||||||
|
if (now - mLastConfigMissingLogAt < CONFIG_MISSING_LOG_INTERVAL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mLastConfigMissingLogAt = now;
|
||||||
|
Log.e(TAG, "checkForegroundAppName: 管控配置未就绪,跳过本次校验,等待配置同步 sn="
|
||||||
|
+ mConfigRepository.isSnControlFetched()
|
||||||
|
+ ", app=" + mConfigRepository.isAppControlFetched());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 后台扫描一次系统应用包名,供 {@link #isSystemPackage(String)} 纯内存判断。
|
* 后台扫描一次系统应用包名,供 {@link #isSystemPackage(String)} 纯内存判断。
|
||||||
*/
|
*/
|
||||||
@@ -505,8 +550,34 @@ public class TimeManager {
|
|||||||
*/
|
*/
|
||||||
private boolean isPackageExempted(String pkg) {
|
private boolean isPackageExempted(String pkg) {
|
||||||
if (allowPackage.contains(pkg)) return true;
|
if (allowPackage.contains(pkg)) return true;
|
||||||
int isControl = Settings.System.getInt(mContext.getContentResolver(), CommonConfig.KEY_IS_CONTROL, 1);
|
return !isControlEnabled();
|
||||||
return isControl == 0;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管控总开关是否开启。
|
||||||
|
*/
|
||||||
|
private boolean isControlEnabled() {
|
||||||
|
return Settings.System.getInt(mContext.getContentResolver(), CommonConfig.KEY_IS_CONTROL, 1) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否需要记录该应用的使用时长。
|
||||||
|
*
|
||||||
|
* <p>使用统计与管控总开关解耦:家长关闭管控(is_control_key=0)时不再拦截应用,
|
||||||
|
* 但使用时长仍要统计,否则报表会完全缺失;仅在管控开启时按白名单排除,
|
||||||
|
* 避免白名单应用被计入管控时长。</p>
|
||||||
|
*
|
||||||
|
* @param pkg 应用包名
|
||||||
|
* @return true 表示需要开启一条使用时长记录
|
||||||
|
*/
|
||||||
|
private boolean shouldRecordUsage(String pkg) {
|
||||||
|
if (ApkUtils.isSystemApp(mContext, pkg)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!isControlEnabled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return !allowPackage.contains(pkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -847,13 +918,13 @@ public class TimeManager {
|
|||||||
new TimeConfigRepository.OnConfigChangedListener() {
|
new TimeConfigRepository.OnConfigChangedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSnConfigUpdated(SnTimeControlInfo info) {
|
public void onSnConfigUpdated(SnTimeControlInfo info) {
|
||||||
Log.e(TAG, "onSnConfigUpdated: " );
|
Log.e(TAG, "onSnConfigUpdated: ");
|
||||||
mMainHandler.post(() -> applySnConfigUpdated(info));
|
mMainHandler.post(() -> applySnConfigUpdated(info));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAppConfigUpdated(List<AppTimeControlInfo> list) {
|
public void onAppConfigUpdated(List<AppTimeControlInfo> list) {
|
||||||
Log.e(TAG, "onAppConfigUpdated: " );
|
Log.e(TAG, "onAppConfigUpdated: ");
|
||||||
mMainHandler.post(() -> applyAppConfigUpdated(list));
|
mMainHandler.post(() -> applyAppConfigUpdated(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,7 +935,7 @@ public class TimeManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigFetchFinished() {
|
public void onConfigFetchFinished() {
|
||||||
Log.e(TAG, "onConfigFetchFinished: " );
|
Log.e(TAG, "onConfigFetchFinished: ");
|
||||||
Log.e(TAG, "Config fetch finished. sn=" + mConfigRepository.isSnControlFetched()
|
Log.e(TAG, "Config fetch finished. sn=" + mConfigRepository.isSnControlFetched()
|
||||||
+ ", app=" + mConfigRepository.isAppControlFetched());
|
+ ", app=" + mConfigRepository.isAppControlFetched());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.fuying.sn.receiver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 旧版开机广播入口,仅供外部应用兼容使用。
|
||||||
|
*
|
||||||
|
* <p>外部应用会显式发送广播到
|
||||||
|
* {@code ComponentName("com.fuying.sn", "com.fuying.sn.receiver.BootReceiver")},
|
||||||
|
* 包结构调整后类名变化会导致启动失败,这里保留旧路径的空壳,
|
||||||
|
* 处理逻辑全部继承自 {@link com.fuying.sn.runtime.receiver.BootReceiver}。</p>
|
||||||
|
*/
|
||||||
|
public class BootReceiver extends com.fuying.sn.runtime.receiver.BootReceiver {
|
||||||
|
}
|
||||||
@@ -153,7 +153,7 @@ public final class RuntimeInitializers {
|
|||||||
AppPolicySync.init(application, syncCache);
|
AppPolicySync.init(application, syncCache);
|
||||||
DeviceSettingsSync.init(application, syncCache);
|
DeviceSettingsSync.init(application, syncCache);
|
||||||
RemoteDiagnostics.init(application);
|
RemoteDiagnostics.init(application);
|
||||||
TimePolicySync.init(application, syncCache);
|
TimePolicySync.init(syncCache);
|
||||||
AppUpdateCoordinator.init(application, syncCache);
|
AppUpdateCoordinator.init(application, syncCache);
|
||||||
AppUsageReporter.init(application);
|
AppUsageReporter.init(application);
|
||||||
// 平台层通过网关触发同步动作,避免 platform 反向依赖 runtime;需在同步类初始化之后注册
|
// 平台层通过网关触发同步动作,避免 platform 反向依赖 runtime;需在同步类初始化之后注册
|
||||||
@@ -172,7 +172,6 @@ public final class RuntimeInitializers {
|
|||||||
DataSync.class,
|
DataSync.class,
|
||||||
PlatformInitializers.System.class,
|
PlatformInitializers.System.class,
|
||||||
PlatformInitializers.AppMonitor.class,
|
PlatformInitializers.AppMonitor.class,
|
||||||
PlatformInitializers.TimeControl.class,
|
|
||||||
PlatformInitializers.Control.class,
|
PlatformInitializers.Control.class,
|
||||||
PlatformInitializers.Device.class,
|
PlatformInitializers.Device.class,
|
||||||
PlatformInitializers.Location.class,
|
PlatformInitializers.Location.class,
|
||||||
|
|||||||
@@ -1187,9 +1187,6 @@ public class PushManager {
|
|||||||
}
|
}
|
||||||
DeviceProfileSync.getInstance().getSnInfo();
|
DeviceProfileSync.getInstance().getSnInfo();
|
||||||
DeviceSettingsSync.getInstance().getSystemSettings();
|
DeviceSettingsSync.getInstance().getSystemSettings();
|
||||||
// TimePolicySync.getInstance().getAppTimeControl();
|
|
||||||
// TimePolicySync.getInstance().getMachineTimeControl();
|
|
||||||
// TimePolicySync.getInstance().getSnTimeControl();
|
|
||||||
TimeManager.getInstance().refreshTimeControl();
|
TimeManager.getInstance().refreshTimeControl();
|
||||||
AppInventorySync.getInstance().getAllappPackage();
|
AppInventorySync.getInstance().getAllappPackage();
|
||||||
}
|
}
|
||||||
@@ -1294,6 +1291,7 @@ public class PushManager {
|
|||||||
if (code == 200) {
|
if (code == 200) {
|
||||||
// 绑定成功后立即作废之前的设备信息,完成回调会重新查询。
|
// 绑定成功后立即作废之前的设备信息,完成回调会重新查询。
|
||||||
DeviceRepository.removeCache(UrlAddress.SN_INFO);
|
DeviceRepository.removeCache(UrlAddress.SN_INFO);
|
||||||
|
DeviceRepository.removeCache(UrlAddress.DEVICE_INFO);
|
||||||
ToastUtil.show("绑定成功");
|
ToastUtil.show("绑定成功");
|
||||||
} else if (code == 301) {
|
} else if (code == 301) {
|
||||||
ToastUtil.show(msg);
|
ToastUtil.show(msg);
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import com.fuying.sn.core.data.dto.device.SnInfo;
|
|||||||
import com.fuying.sn.core.data.local.db.log.LogDBManager;
|
import com.fuying.sn.core.data.local.db.log.LogDBManager;
|
||||||
import com.fuying.sn.core.data.local.prefs.KVStore;
|
import com.fuying.sn.core.data.local.prefs.KVStore;
|
||||||
import com.fuying.sn.core.data.remote.RequestCompletion;
|
import com.fuying.sn.core.data.remote.RequestCompletion;
|
||||||
import com.fuying.sn.core.data.remote.UrlAddress;
|
|
||||||
import com.fuying.sn.platform.app.ApkUtils;
|
import com.fuying.sn.platform.app.ApkUtils;
|
||||||
import com.fuying.sn.platform.control.ControlManager;
|
import com.fuying.sn.platform.control.ControlManager;
|
||||||
import com.fuying.sn.platform.location.AmapManager;
|
import com.fuying.sn.platform.location.AmapManager;
|
||||||
@@ -502,7 +501,6 @@ public class MainService extends BaseService implements ViewModelStoreOwner, Net
|
|||||||
switch (action) {
|
switch (action) {
|
||||||
case Intent.ACTION_USER_PRESENT:
|
case Intent.ACTION_USER_PRESENT:
|
||||||
// TODO: 2022/11/3 暂时屏蔽获取
|
// TODO: 2022/11/3 暂时屏蔽获取
|
||||||
// mViewModel.getAppTimeControl();
|
|
||||||
break;
|
break;
|
||||||
case Intent.ACTION_SCREEN_ON:
|
case Intent.ACTION_SCREEN_ON:
|
||||||
getAppControl();
|
getAppControl();
|
||||||
@@ -521,7 +519,7 @@ public class MainService extends BaseService implements ViewModelStoreOwner, Net
|
|||||||
|
|
||||||
private void getAppControl() {
|
private void getAppControl() {
|
||||||
Log.e(TAG, "getAppControl: ");
|
Log.e(TAG, "getAppControl: ");
|
||||||
long lastTime = KVStore.decodeLong(UrlAddress.GET_APP_TIME_CONTROL + "_time", System.currentTimeMillis());
|
long lastTime = KVStore.decodeLong("app_time_control_sync_time", System.currentTimeMillis());
|
||||||
Log.e(TAG, "getAppControl: lastTime = " + lastTime);
|
Log.e(TAG, "getAppControl: lastTime = " + lastTime);
|
||||||
Log.e(TAG, "getAppControl: lastTime = " + TimeUtils.getDate(lastTime));
|
Log.e(TAG, "getAppControl: lastTime = " + TimeUtils.getDate(lastTime));
|
||||||
if (TimeUtils.isTodayWithJavaTime(lastTime)) {
|
if (TimeUtils.isTodayWithJavaTime(lastTime)) {
|
||||||
|
|||||||
@@ -223,37 +223,6 @@ public class MainServiceModel extends BaseAndroidViewModel {
|
|||||||
mDisposables.add(disposable);
|
mDisposables.add(disposable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getAppTimeControl() {
|
|
||||||
// TimePolicySync.getInstance().getAppTimeControl(new RequestCallbacks.CompleteCallback() {
|
|
||||||
// @Override
|
|
||||||
// public void onComplete() {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// TimePolicySync.getInstance().getAppTimeControlInfo(new RequestCallbacks.CompleteCallback() {
|
|
||||||
// @Override
|
|
||||||
// public void onComplete() {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getSnTimeControl() {
|
|
||||||
// TimePolicySync.getInstance().getMachineTimeControl(new RequestCallbacks.CompleteCallback() {
|
|
||||||
// @Override
|
|
||||||
// public void onComplete() {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// TimePolicySync.getInstance().getSnTimeControl(new RequestCallbacks.CompleteCallback() {
|
|
||||||
// @Override
|
|
||||||
// public void onComplete() {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getMyAppList() {
|
public void getMyAppList() {
|
||||||
Disposable disposable = TimePolicySync.getInstance().getMyAppListRequest(new TimePolicySync.MyAppListCallback() {
|
Disposable disposable = TimePolicySync.getInstance().getMyAppListRequest(new TimePolicySync.MyAppListCallback() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -135,11 +135,11 @@ public final class DeviceSettingsSync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Completable getSystemSettingsRequest(CompleteCallback callback) {
|
public Completable getSystemSettingsRequest(CompleteCallback callback) {
|
||||||
return asRequest(repository.fetchSystemSettings(), getSystemSettingsObserver(callback));
|
return asRequest(repository.getSettingControl(true), getSystemSettingsObserver(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getSystemSettings() {
|
public void getSystemSettings() {
|
||||||
repository.fetchSystemSettings()
|
repository.getSettingControl(true)
|
||||||
.to(BackgroundRequests.submit(getSystemSettingsObserver(null)));
|
.to(BackgroundRequests.submit(getSystemSettingsObserver(null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,9 +164,14 @@ public final class DeviceSettingsSync {
|
|||||||
}
|
}
|
||||||
String data = new Gson().toJson(systemSettingsBaseResponse.data.getUser());
|
String data = new Gson().toJson(systemSettingsBaseResponse.data.getUser());
|
||||||
ControlManager.getInstance().setSystemSetting(data);
|
ControlManager.getInstance().setSystemSetting(data);
|
||||||
} else {
|
} else if (code == 300 || code == 401 || code == 403) {
|
||||||
|
// 设备未绑定/未授权:关闭管控
|
||||||
AndroidSettingsWriter.putInt(mContext, AndroidSettingsWriter.NAMESPACE_SYSTEM, CommonConfig.KEY_IS_CONTROL, 0);
|
AndroidSettingsWriter.putInt(mContext, AndroidSettingsWriter.NAMESPACE_SYSTEM, CommonConfig.KEY_IS_CONTROL, 0);
|
||||||
ControlManager.getInstance().setDisableSetting();
|
ControlManager.getInstance().setDisableSetting();
|
||||||
|
} else {
|
||||||
|
// 限流(400)或服务端异常:保留当前已生效的管控配置,避免把管控总开关误关闭
|
||||||
|
Log.e(TAG, "getSystemSettings: 非授权类响应 code=" + code + ",保留现有配置");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//imei是否绑定
|
//imei是否绑定
|
||||||
|
|||||||
@@ -51,16 +51,6 @@ public final class DeviceSyncGatewayImpl implements DeviceSyncGateway {
|
|||||||
AppUsageReporter.getInstance().sendAppUsageRecord(packageName, openTime, closeTime, onComplete::run);
|
AppUsageReporter.getInstance().sendAppUsageRecord(packageName, openTime, closeTime, onComplete::run);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshAppTimeControl() {
|
|
||||||
TimePolicySync.getInstance().getAppTimeControl();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshMachineTimeControl() {
|
|
||||||
TimePolicySync.getInstance().getMachineTimeControl();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void requestMyAppList(MyAppListCallback callback) {
|
public void requestMyAppList(MyAppListCallback callback) {
|
||||||
TimePolicySync.getInstance().getMyAppList(new TimePolicySync.MyAppListCallback() {
|
TimePolicySync.getInstance().getMyAppList(new TimePolicySync.MyAppListCallback() {
|
||||||
|
|||||||
@@ -2,23 +2,18 @@ package com.fuying.sn.runtime.sync;
|
|||||||
|
|
||||||
import static com.fuying.sn.runtime.sync.RequestCallbacks.asRequest;
|
import static com.fuying.sn.runtime.sync.RequestCallbacks.asRequest;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.fuying.sn.core.common.gson.GsonUtils;
|
import com.fuying.sn.core.common.gson.GsonUtils;
|
||||||
import com.fuying.sn.core.data.dto.common.BaseResponse;
|
import com.fuying.sn.core.data.dto.common.BaseResponse;
|
||||||
import com.fuying.sn.core.data.dto.statistics.MyAppUsageBean;
|
import com.fuying.sn.core.data.dto.statistics.MyAppUsageBean;
|
||||||
import com.fuying.sn.core.data.dto.time.AppTimeControl;
|
|
||||||
import com.fuying.sn.core.data.dto.time.AppTimeControlInfo;
|
import com.fuying.sn.core.data.dto.time.AppTimeControlInfo;
|
||||||
import com.fuying.sn.core.data.dto.time.MachineControl;
|
|
||||||
import com.fuying.sn.core.data.dto.time.SnTimeControlInfo;
|
import com.fuying.sn.core.data.dto.time.SnTimeControlInfo;
|
||||||
import com.fuying.sn.core.data.local.cache.CacheHelper;
|
import com.fuying.sn.core.data.local.cache.CacheHelper;
|
||||||
import com.fuying.sn.core.data.remote.BackgroundRequests;
|
import com.fuying.sn.core.data.remote.BackgroundRequests;
|
||||||
import com.fuying.sn.core.data.remote.UrlAddress;
|
import com.fuying.sn.core.data.remote.UrlAddress;
|
||||||
import com.fuying.sn.core.data.repository.DeviceRepository;
|
import com.fuying.sn.core.data.repository.DeviceRepository;
|
||||||
import com.fuying.sn.core.data.repository.TimeConfigRepository;
|
import com.fuying.sn.core.data.repository.TimeConfigRepository;
|
||||||
import com.fuying.sn.platform.time.TimeControlManager;
|
|
||||||
import com.fuying.sn.runtime.sync.RequestCallbacks.CompleteCallback;
|
import com.fuying.sn.runtime.sync.RequestCallbacks.CompleteCallback;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -34,19 +29,17 @@ import io.reactivex.rxjava3.disposables.Disposable;
|
|||||||
public final class TimePolicySync {
|
public final class TimePolicySync {
|
||||||
private static final String TAG = "TimePolicySync";
|
private static final String TAG = "TimePolicySync";
|
||||||
private static volatile TimePolicySync instance;
|
private static volatile TimePolicySync instance;
|
||||||
private final Context mContext;
|
|
||||||
private final CacheHelper mCacheHelper;
|
private final CacheHelper mCacheHelper;
|
||||||
private final DeviceRepository repository;
|
private final DeviceRepository repository;
|
||||||
|
|
||||||
private TimePolicySync(Context context, CacheHelper cacheHelper) {
|
private TimePolicySync(CacheHelper cacheHelper) {
|
||||||
mContext = context;
|
|
||||||
mCacheHelper = cacheHelper;
|
mCacheHelper = cacheHelper;
|
||||||
repository = DeviceRepository.getInstance();
|
repository = DeviceRepository.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void init(Context context, CacheHelper cacheHelper) {
|
public static synchronized void init(CacheHelper cacheHelper) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new TimePolicySync(context.getApplicationContext(), cacheHelper);
|
instance = new TimePolicySync(cacheHelper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,126 +50,6 @@ public final class TimePolicySync {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String APP_TIME_CONTROL_UPDATE = "APP_TIME_CONTROL_UPDATE";
|
|
||||||
public static final String SN_TIME_CONTROL_UPDATE = "SN_TIME_CONTROL_UPDATE";
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public String getAppTimeControlJson() {
|
|
||||||
return mCacheHelper.getAsString(UrlAddress.GET_APP_TIME_CONTROL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void getAppTimeControl(CompleteCallback callback) {
|
|
||||||
repository.getAppTimeControlObservable()
|
|
||||||
.to(BackgroundRequests.submit(getAppTimeControlObserver(callback)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void getAppTimeControl() {
|
|
||||||
repository.getAppTimeControlObservable()
|
|
||||||
.to(BackgroundRequests.submit(getAppTimeControlObserver(null)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private Observer<BaseResponse<List<AppTimeControl>>> getAppTimeControlObserver(CompleteCallback callback) {
|
|
||||||
return new Observer<BaseResponse<List<AppTimeControl>>>() {
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(@NonNull Disposable d) {
|
|
||||||
Log.e(TAG, "getAppTimeControlObserver: onSubscribe: ");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(@NonNull BaseResponse<List<AppTimeControl>> listBaseResponse) {
|
|
||||||
Log.e(TAG, "getAppTimeControlObserver: onNext: " + listBaseResponse);
|
|
||||||
if (listBaseResponse.code == 200) {
|
|
||||||
List<AppTimeControl> appTimeControls = listBaseResponse.data;
|
|
||||||
// TODO: 2022/6/21 后台没数据时也返回200
|
|
||||||
if (appTimeControls == null || appTimeControls.size() == 0) {
|
|
||||||
mCacheHelper.put(UrlAddress.GET_APP_TIME_CONTROL, "");
|
|
||||||
} else {
|
|
||||||
TimeControlManager.getInstance().setAppTimeControlMap(appTimeControls);
|
|
||||||
mCacheHelper.put(UrlAddress.GET_APP_TIME_CONTROL, GsonUtils.toJSONString(appTimeControls));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mCacheHelper.put(UrlAddress.GET_APP_TIME_CONTROL, "");
|
|
||||||
}
|
|
||||||
Intent intent = new Intent(APP_TIME_CONTROL_UPDATE);
|
|
||||||
intent.putExtra("jsonString", GsonUtils.toJSONString(listBaseResponse.data));
|
|
||||||
mContext.sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(@NonNull Throwable e) {
|
|
||||||
Log.e(TAG, "getAppTimeControlObserver: onError: " + e.getMessage());
|
|
||||||
onComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
Log.e(TAG, "getAppTimeControlObserver: onComplete: ");
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onComplete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public String getSnTimeControllJson() {
|
|
||||||
return mCacheHelper.getAsString(UrlAddress.GET_SN_TIME_CONTROL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void getMachineTimeControl(CompleteCallback callback) {
|
|
||||||
repository.getMachineTimeControlObservable()
|
|
||||||
.to(BackgroundRequests.submit(getMachineTimeControlObserver(callback)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void getMachineTimeControl() {
|
|
||||||
repository.getMachineTimeControlObservable()
|
|
||||||
.to(BackgroundRequests.submit(getMachineTimeControlObserver(null)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public Observer<BaseResponse<MachineControl>> getMachineTimeControlObserver(CompleteCallback callback) {
|
|
||||||
return new Observer<BaseResponse<MachineControl>>() {
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(@NonNull Disposable d) {
|
|
||||||
Log.e(TAG, "getMachineTimeControlObserver: onSubscribe: ");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(@NonNull BaseResponse<MachineControl> machineControlBaseResponse) {
|
|
||||||
Log.e(TAG, "getMachineTimeControlObserver: onNext: " + machineControlBaseResponse);
|
|
||||||
if (machineControlBaseResponse.code == 200) {
|
|
||||||
MachineControl machineControl = machineControlBaseResponse.data;
|
|
||||||
TimeControlManager.getInstance().setGlobalMachineControl(machineControl);
|
|
||||||
mCacheHelper.put(UrlAddress.GET_SN_TIME_CONTROL, GsonUtils.toJSONString(machineControl));
|
|
||||||
} else {
|
|
||||||
mCacheHelper.put(UrlAddress.GET_SN_TIME_CONTROL, "");
|
|
||||||
}
|
|
||||||
Intent intent = new Intent(SN_TIME_CONTROL_UPDATE);
|
|
||||||
intent.putExtra("jsonString", GsonUtils.toJSONString(machineControlBaseResponse.data));
|
|
||||||
mContext.sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(@NonNull Throwable e) {
|
|
||||||
Log.e(TAG, "getMachineTimeControlObserver: onError: " + e.getMessage());
|
|
||||||
onComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
Log.e(TAG, "getMachineTimeControlObserver: onComplete: ");
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onComplete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface MyAppListCallback {
|
public interface MyAppListCallback {
|
||||||
void setMyAppList(List<MyAppUsageBean> myAppList);
|
void setMyAppList(List<MyAppUsageBean> myAppList);
|
||||||
}
|
}
|
||||||
@@ -291,7 +164,7 @@ public final class TimePolicySync {
|
|||||||
List<AppTimeControlInfo> list = response.data;
|
List<AppTimeControlInfo> list = response.data;
|
||||||
TimeConfigRepository.getInstance().applyAppConfig(list);
|
TimeConfigRepository.getInstance().applyAppConfig(list);
|
||||||
} else if (response.code == 400) {
|
} else if (response.code == 400) {
|
||||||
Log.e(TAG, "getSnTimeControl: onNext: Too frequent");
|
Log.e(TAG, "getAppTimeControlInfo: onNext: Too frequent");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.fuying.sn.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 旧版 AIDL 服务入口,仅供外部应用兼容使用。
|
||||||
|
*
|
||||||
|
* <p>桌面/家长端(如 com.fuying.fuxiaoying)通过
|
||||||
|
* {@code ComponentName("com.fuying.sn", "com.fuying.sn.service.RemoteService")} 显式绑定,
|
||||||
|
* 包结构收敛到 runtime 后类名发生变化,会导致外部应用 bindService 直接失败。
|
||||||
|
* 这里保留旧路径的空壳,实现全部继承自
|
||||||
|
* {@link com.fuying.sn.runtime.service.RemoteService}。</p>
|
||||||
|
*/
|
||||||
|
public class RemoteService extends com.fuying.sn.runtime.service.RemoteService {
|
||||||
|
}
|
||||||
Reference in new issue
Block a user