version:1.6.0403
bugfixes: add:增加时间管控
This commit is contained in:
@@ -55,6 +55,8 @@ import com.aoleyun.sn.bean.LessonJson;
|
||||
import com.aoleyun.sn.bean.NetAndLaunchBean;
|
||||
import com.aoleyun.sn.bean.NetAndLaunchData;
|
||||
import com.aoleyun.sn.bean.TTAppground;
|
||||
import com.aoleyun.sn.bean.TimeControlApp;
|
||||
import com.aoleyun.sn.bean.TimeControlInfo;
|
||||
import com.aoleyun.sn.comm.CommonConfig;
|
||||
import com.aoleyun.sn.comm.JGYActions;
|
||||
import com.aoleyun.sn.comm.PackageNames;
|
||||
@@ -98,6 +100,9 @@ import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
@@ -143,6 +148,8 @@ public class JgyUtils {
|
||||
private LessonJson mLessonJson;
|
||||
private TimeUtils.ContralTime mContralTime;
|
||||
|
||||
private List<TimeControlInfo> mAppPeriods;
|
||||
|
||||
public static final int UnknowPlatform = 0;
|
||||
|
||||
public static final int MTKPlatform = 1;
|
||||
@@ -230,6 +237,7 @@ public class JgyUtils {
|
||||
bindEbaifenService();
|
||||
}
|
||||
refresh();
|
||||
syncTimePeriod();
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
@@ -1028,17 +1036,13 @@ public class JgyUtils {
|
||||
return;
|
||||
}
|
||||
if (appIDList == null || appIDList.isEmpty()) {
|
||||
if ("G10".equals(Build.MODEL) || "D1".equals(Build.MODEL)) {
|
||||
Settings.System.putString(mContext.getContentResolver(), CommonConfig.APP_VIEW_CLICK_DISABLED, "com.arivoc.wordhd:2131624676,2131624689;com.ttstd.utils:12345");
|
||||
} else {
|
||||
try {
|
||||
Settings.System.putString(crv, CommonConfig.APP_VIEW_CLICK_DISABLED, null);
|
||||
// TODO: 2024/9/11 修复1.4.0907版本数据为空系统报错
|
||||
CmdUtil.Result result = CmdUtil.execute(" settings delete system app_view_click_disabled");
|
||||
Log.e(TAG, "writeDeselectIDtoSystem: " + result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Settings.System.putString(crv, CommonConfig.APP_VIEW_CLICK_DISABLED, null);
|
||||
// TODO: 2024/9/11 修复1.4.0907版本数据为空系统报错
|
||||
CmdUtil.Result result = CmdUtil.execute(" settings delete system app_view_click_disabled");
|
||||
Log.e(TAG, "writeDeselectIDtoSystem: " + result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
String s = appIDList.stream().map(new Function<AppID, String>() {
|
||||
@@ -3916,4 +3920,133 @@ public class JgyUtils {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
|
||||
private String getTopActivityInfo() {
|
||||
ActivityManager manager = (ActivityManager) mContext.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
|
||||
List<ActivityManager.RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);
|
||||
if (runningTaskInfos != null && !runningTaskInfos.isEmpty()) {
|
||||
ComponentName componentName = runningTaskInfos.get(0).topActivity;
|
||||
if (componentName != null) {
|
||||
String currentClassName = componentName.getPackageName();
|
||||
return currentClassName;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean inOpenTimePeriod(TimeControlInfo timeControlInfo) {
|
||||
String startTimeStr = timeControlInfo.getStart_time();
|
||||
String endTimeStr = timeControlInfo.getEnd_time();
|
||||
|
||||
// 获取当前日期和时间
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
LocalTime currentTime = LocalTime.now();
|
||||
|
||||
// 解析时间并比较
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
LocalTime startTime = LocalTime.parse(startTimeStr, formatter);
|
||||
LocalTime endTime = LocalTime.parse(endTimeStr, formatter);
|
||||
|
||||
boolean inTime = !currentTime.isBefore(startTime) && !currentTime.isAfter(endTime);
|
||||
return inTime;
|
||||
}
|
||||
|
||||
public void syncTimePeriod() {
|
||||
String jsonString = mMMKV.decodeString(CommonConfig.TIME_CONTROL_DATA_KEY, "");
|
||||
if (TextUtils.isEmpty(jsonString)) {
|
||||
mAppPeriods = null;
|
||||
return;
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<TimeControlInfo>>() {
|
||||
}.getType();
|
||||
try {
|
||||
mAppPeriods = gson.fromJson(jsonString, type);
|
||||
Log.e(TAG, "checkTimePeriod: periods = " + mAppPeriods);
|
||||
checkTimePeriod();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "checkTimePeriod: Exception = " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void checkTimePeriod() {
|
||||
if (mAppPeriods == null || mAppPeriods.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String foregroundPackage = getTopActivityInfo();
|
||||
if (ApkUtils.isSystemApp(mContext, foregroundPackage)) {
|
||||
Log.d(TAG, "checkTimePeriod: " + foregroundPackage + " is system app, skip");
|
||||
return;
|
||||
}
|
||||
Set<String> packageNames = mAppPeriods.stream()
|
||||
.filter(new Predicate<TimeControlInfo>() {
|
||||
@Override
|
||||
public boolean test(TimeControlInfo timeControlInfo) {
|
||||
return inOpenTimePeriod(timeControlInfo);
|
||||
}
|
||||
})
|
||||
.map(new Function<TimeControlInfo, List<String>>() {
|
||||
@Override
|
||||
public List<String> apply(TimeControlInfo timeControlInfo) {
|
||||
return timeControlInfo.getApp().stream().map(new Function<TimeControlApp, String>() {
|
||||
@Override
|
||||
public String apply(TimeControlApp timeControlApp) {
|
||||
return timeControlApp.getApp_package();
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
})
|
||||
//使用 stream 和 flatMap 将所有元素合并
|
||||
.flatMap(List::stream)
|
||||
.collect(Collectors.toSet());
|
||||
Log.d(TAG, "checkTimePeriod: " + packageNames);
|
||||
if (packageNames.contains(foregroundPackage)) {
|
||||
Log.e(TAG, "checkTimePeriod: " + foregroundPackage + " skip");
|
||||
} else {
|
||||
gotoLauncher();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pkgName
|
||||
* @return true为可以打开
|
||||
*/
|
||||
public boolean checkTimePeriod(String pkgName) {
|
||||
if (mAppPeriods == null || mAppPeriods.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (ApkUtils.isSystemApp(mContext, pkgName)) {
|
||||
Log.d(TAG, "checkTimePeriod: " + pkgName + " is system app, skip");
|
||||
return true;
|
||||
}
|
||||
Set<String> packageNames = mAppPeriods.stream()
|
||||
.filter(new Predicate<TimeControlInfo>() {
|
||||
@Override
|
||||
public boolean test(TimeControlInfo timeControlInfo) {
|
||||
return inOpenTimePeriod(timeControlInfo);
|
||||
}
|
||||
})
|
||||
.map(new Function<TimeControlInfo, List<String>>() {
|
||||
@Override
|
||||
public List<String> apply(TimeControlInfo timeControlInfo) {
|
||||
return timeControlInfo.getApp().stream().map(new Function<TimeControlApp, String>() {
|
||||
@Override
|
||||
public String apply(TimeControlApp timeControlApp) {
|
||||
return timeControlApp.getApp_package();
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
})
|
||||
//使用 stream 和 flatMap 将所有元素合并
|
||||
.flatMap(List::stream)
|
||||
.collect(Collectors.toSet());
|
||||
Log.d(TAG, "checkTimePeriod: " + packageNames);
|
||||
if (packageNames.contains(pkgName)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user