version:1.0.8
fix: update:优化管控
This commit is contained in:
47
src/com/uiuipad/os/manager/AppUsedTimeUtils.java
Normal file
47
src/com/uiuipad/os/manager/AppUsedTimeUtils.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.uiuipad.os.manager;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
||||
public class AppUsedTimeUtils {
|
||||
private static final String TAG = AppUsedTimeUtils.class.getSimpleName();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static AppUsedTimeUtils sInstance;
|
||||
private Context mContext;
|
||||
private String app_package;
|
||||
private long start_time;
|
||||
|
||||
private AppUsedTimeUtils(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new AppUsedTimeUtils(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static AppUsedTimeUtils getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init AppUsedTimeUtils first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public String getApp_package() {
|
||||
return app_package;
|
||||
}
|
||||
|
||||
public void setApp_package(String app_package) {
|
||||
this.app_package = app_package;
|
||||
}
|
||||
|
||||
public long getStart_time() {
|
||||
return start_time;
|
||||
}
|
||||
|
||||
public void setStart_time(long start_time) {
|
||||
this.start_time = start_time;
|
||||
}
|
||||
}
|
||||
73
src/com/uiuipad/os/manager/MyAppUsageBean.java
Normal file
73
src/com/uiuipad/os/manager/MyAppUsageBean.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package com.uiuipad.os.manager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class MyAppUsageBean implements Serializable {
|
||||
private static final long serialVersionUID = 5340688429095924160L;
|
||||
|
||||
int id;
|
||||
String app_name;
|
||||
String app_package;
|
||||
String app_img;
|
||||
String class_name;
|
||||
long use_time;//s
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getApp_name() {
|
||||
return app_name;
|
||||
}
|
||||
|
||||
public void setApp_name(String app_name) {
|
||||
this.app_name = app_name;
|
||||
}
|
||||
|
||||
public String getApp_package() {
|
||||
return app_package;
|
||||
}
|
||||
|
||||
public void setApp_package(String app_package) {
|
||||
this.app_package = app_package;
|
||||
}
|
||||
|
||||
public String getApp_img() {
|
||||
return app_img;
|
||||
}
|
||||
|
||||
public void setApp_img(String app_img) {
|
||||
this.app_img = app_img;
|
||||
}
|
||||
|
||||
public String getClass_name() {
|
||||
return class_name;
|
||||
}
|
||||
|
||||
public void setClass_name(String class_name) {
|
||||
this.class_name = class_name;
|
||||
}
|
||||
|
||||
public long getUse_time() {
|
||||
return use_time;
|
||||
}
|
||||
|
||||
public void setUse_time(long use_time) {
|
||||
this.use_time = use_time;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
1491
src/com/uiuipad/os/manager/RunningAppManager.java
Normal file
1491
src/com/uiuipad/os/manager/RunningAppManager.java
Normal file
File diff suppressed because it is too large
Load Diff
191
src/com/uiuipad/os/manager/TimeControlManager.java
Normal file
191
src/com/uiuipad/os/manager/TimeControlManager.java
Normal file
@@ -0,0 +1,191 @@
|
||||
package com.uiuipad.os.manager;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.uiuipad.os.comm.CommonConfig;
|
||||
import com.uiuipad.os.disklrucache.CacheHelper;
|
||||
import com.uiuipad.os.network.UrlAddress;
|
||||
import com.uiuipad.os.network.bean.TimeManageApp;
|
||||
import com.uiuipad.os.network.bean.TimeManageSn;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TimeControlManager {
|
||||
private static final String TAG = TimeControlManager.class.getSimpleName();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static TimeControlManager mTimeControlManager;
|
||||
private Context mContext;
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private HashMap<Integer, TimeManageApp> mClassifyTimeControlHashMap = new HashMap<>();
|
||||
/*分类的所有包名列表*/
|
||||
private HashMap<String, TimeManageApp> mAppTimeControlMap = new HashMap<>();
|
||||
/*整机分类*/
|
||||
private TimeManageSn mGlobalMachineControl;
|
||||
|
||||
private TimeControlManager(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
this.mContext = context;
|
||||
String appTimeControlJson = mMMKV.decodeString(UrlAddress.GET_TIME_MANAGE_APP, "");
|
||||
if (!TextUtils.isEmpty(appTimeControlJson)) {
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<TimeManageApp>>() {
|
||||
}.getType();
|
||||
try {
|
||||
List<TimeManageApp> appTimeControls = gson.fromJson(appTimeControlJson, type);
|
||||
setAppTimeControlMap(appTimeControls);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "TimeControlManager: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (mTimeControlManager == null) {
|
||||
mTimeControlManager = new TimeControlManager(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static TimeControlManager getInstance() {
|
||||
if (mTimeControlManager == null) {
|
||||
throw new IllegalStateException("You must be init TimeControlManager first");
|
||||
}
|
||||
return mTimeControlManager;
|
||||
}
|
||||
|
||||
public HashMap<String, TimeManageApp> getAppTimeControlMap() {
|
||||
return mAppTimeControlMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有配置存在
|
||||
*
|
||||
* @param pkg
|
||||
* @return
|
||||
*/
|
||||
public boolean havaConfigure(String pkg) {
|
||||
TimeManageApp appTimeControl = mAppTimeControlMap.get(pkg);
|
||||
if (appTimeControl == null) {
|
||||
Log.e(TAG, "havaConfigure: not");
|
||||
return false;
|
||||
} else {
|
||||
if (appTimeControl.getUse_type() == 1) {
|
||||
//根据分类
|
||||
Log.e(TAG, "havaConfigure: classify");
|
||||
return mClassifyTimeControlHashMap.get(appTimeControl.getClass_id()) != null;
|
||||
}
|
||||
Log.e(TAG, "havaConfigure: hava");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取整机配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TimeManageSn getGlobalMachineControl() {
|
||||
if (mGlobalMachineControl == null) {
|
||||
String jsonString = mMMKV.decodeString(UrlAddress.GET_TIME_MANAGE_SN, "");
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
return null;
|
||||
} else {
|
||||
Gson gson = new Gson();
|
||||
Type Type = new TypeToken<TimeManageSn>() {
|
||||
}.getType();
|
||||
TimeManageSn machineControl = gson.fromJson(jsonString, Type);
|
||||
return machineControl;
|
||||
}
|
||||
} else {
|
||||
return mGlobalMachineControl;
|
||||
}
|
||||
}
|
||||
|
||||
public void setGlobalMachineControl(TimeManageSn machineControl) {
|
||||
this.mGlobalMachineControl = machineControl;
|
||||
if (machineControl != null) {
|
||||
RunningAppManager.getInstance().setGlobalUsageTime(machineControl.getToday_time());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取app的配置
|
||||
*
|
||||
* @param pkg
|
||||
* @return
|
||||
*/
|
||||
public TimeManageApp getAppTimeControl(String pkg) {
|
||||
TimeManageApp temp = mAppTimeControlMap.get(pkg);
|
||||
if (temp == null) {
|
||||
String jsonString = mMMKV.decodeString(UrlAddress.GET_TIME_MANAGE_APP, "");
|
||||
//为 "" 是已经请求成功的
|
||||
if (jsonString == null) {
|
||||
return null;
|
||||
} else {
|
||||
Gson gson = new Gson();
|
||||
Type Type = new TypeToken<List<TimeManageApp>>() {
|
||||
}.getType();
|
||||
List<TimeManageApp> appTimeControlList = gson.fromJson(jsonString, Type);
|
||||
if (appTimeControlList == null) {
|
||||
return null;
|
||||
}
|
||||
HashMap<String, TimeManageApp> appTimeControlMap = new HashMap<>();
|
||||
for (TimeManageApp appTimeControl : appTimeControlList) {
|
||||
appTimeControlMap.put(appTimeControl.getApp_package(), appTimeControl);
|
||||
}
|
||||
setAppTimeControlMap(appTimeControlList);
|
||||
return appTimeControlMap.get(pkg);
|
||||
}
|
||||
} else {
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAppTimeControl(String pkg, TimeManageApp appTimeControl) {
|
||||
this.mAppTimeControlMap.put(pkg, appTimeControl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置app的配置
|
||||
*
|
||||
* @param appTimeControlList
|
||||
*/
|
||||
public void setAppTimeControlMap(List<TimeManageApp> appTimeControlList) {
|
||||
if (appTimeControlList == null || appTimeControlList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
HashMap<Integer, TimeManageApp> classifyTimeControlHashMap = new HashMap<>();
|
||||
List<TimeManageApp> filterAppTimeControlList = appTimeControlList.stream().filter(appTimeControl -> {
|
||||
//tc_use_type == 1 时用的是分类配置,配置都是一样的
|
||||
return appTimeControl.getUse_type() == 1;
|
||||
}).collect(Collectors.toList());
|
||||
for (TimeManageApp appTimeControl : filterAppTimeControlList) {
|
||||
classifyTimeControlHashMap.put(appTimeControl.getClass_id(), appTimeControl);
|
||||
}
|
||||
this.mClassifyTimeControlHashMap = classifyTimeControlHashMap;
|
||||
|
||||
HashMap<String, TimeManageApp> appTimeControlMap = new HashMap<>();
|
||||
List<TimeManageApp> appTimeControls = new ArrayList<>();
|
||||
for (TimeManageApp appTimeControl : appTimeControlList) {
|
||||
appTimeControlMap.put(appTimeControl.getApp_package(), appTimeControl);
|
||||
appTimeControls.add(appTimeControl);
|
||||
}
|
||||
RunningAppManager.getInstance().syncAppRemainingTime(appTimeControls);
|
||||
this.mAppTimeControlMap = appTimeControlMap;
|
||||
}
|
||||
}
|
||||
75
src/com/uiuipad/os/manager/bean/AppRunTimeBean.java
Normal file
75
src/com/uiuipad/os/manager/bean/AppRunTimeBean.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package com.uiuipad.os.manager.bean;
|
||||
|
||||
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;
|
||||
|
||||
public class AppRunTimeBean implements Serializable {
|
||||
private static final long serialVersionUID = 3699088127005434759L;
|
||||
|
||||
String packageName;
|
||||
Long appRunTime;
|
||||
|
||||
AppRunTimeBean() {
|
||||
this.appRunTime = 0L;
|
||||
}
|
||||
|
||||
public AppRunTimeBean(String pkg) {
|
||||
this.packageName = pkg;
|
||||
this.appRunTime = 0L;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
src/com/uiuipad/os/manager/bean/AppUsageTime.java
Normal file
50
src/com/uiuipad/os/manager/bean/AppUsageTime.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package com.uiuipad.os.manager.bean;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class AppUsageTime implements Serializable {
|
||||
private static final long serialVersionUID = -2981074385838909527L;
|
||||
|
||||
/*包名*/
|
||||
String pkg;
|
||||
/*应用名*/
|
||||
String appName;
|
||||
/*使用时间*/
|
||||
long usageTime;
|
||||
|
||||
|
||||
public String getPkg() {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
public void setPkg(String pkg) {
|
||||
this.pkg = pkg;
|
||||
}
|
||||
|
||||
public String getAppName() {
|
||||
return appName;
|
||||
}
|
||||
|
||||
public void setAppName(String appName) {
|
||||
this.appName = appName;
|
||||
}
|
||||
|
||||
public long getUsageTime() {
|
||||
return usageTime;
|
||||
}
|
||||
|
||||
public void setUsageTime(long usageTime) {
|
||||
this.usageTime = usageTime;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
88
src/com/uiuipad/os/manager/bean/RemainTime.java
Normal file
88
src/com/uiuipad/os/manager/bean/RemainTime.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package com.uiuipad.os.manager.bean;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class RemainTime implements Serializable {
|
||||
private static final long serialVersionUID = 5651493620850107410L;
|
||||
|
||||
/*包名*/
|
||||
String pkg;
|
||||
/**
|
||||
* 禁用类型
|
||||
* 1 应用已被禁用
|
||||
* 2 该应用今日可使用时间已用完
|
||||
* 3 APP设置了禁用时间段
|
||||
* 4 该应用跟随整机使用,整机剩余时间不足
|
||||
* 5 该应用跟随分类使用,分类剩余时间不足
|
||||
*/
|
||||
int disableType;
|
||||
/*禁用提示*/
|
||||
String content;
|
||||
/*总时间*/
|
||||
long totalTime;
|
||||
/*应用设置的可用时间*/
|
||||
long availableTime;
|
||||
/*app使用时间*/
|
||||
List<AppUsageTime> mAppUsageTimes;
|
||||
|
||||
|
||||
public String getPkg() {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
public void setPkg(String pkg) {
|
||||
this.pkg = pkg;
|
||||
}
|
||||
|
||||
public int getDisableType() {
|
||||
return disableType;
|
||||
}
|
||||
|
||||
public void setDisableType(int disableType) {
|
||||
this.disableType = disableType;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public long getTotalTime() {
|
||||
return totalTime;
|
||||
}
|
||||
|
||||
public void setTotalTime(long totalTime) {
|
||||
this.totalTime = totalTime;
|
||||
}
|
||||
|
||||
public long getAvailableTime() {
|
||||
return availableTime;
|
||||
}
|
||||
|
||||
public void setAvailableTime(long availableTime) {
|
||||
this.availableTime = availableTime;
|
||||
}
|
||||
|
||||
public List<AppUsageTime> getAppUsageTimes() {
|
||||
return mAppUsageTimes;
|
||||
}
|
||||
|
||||
public void setAppUsageTimes(List<AppUsageTime> appUsageTimes) {
|
||||
this.mAppUsageTimes = appUsageTimes;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user