远程获取管控增加应用名,优化管控逻辑

This commit is contained in:
2022-09-09 18:02:39 +08:00
parent a0723355e1
commit a64b3b5e03
4 changed files with 47 additions and 13 deletions

View File

@@ -7,6 +7,8 @@ public class AppUsageTime implements Serializable {
/*包名*/
String pkg;
/*应用名*/
String appName;
/*使用时间*/
long usageTime;
@@ -19,6 +21,14 @@ public class AppUsageTime implements Serializable {
this.pkg = pkg;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public long getUsageTime() {
return usageTime;
}

View File

@@ -10,6 +10,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.Build;
import android.os.PowerManager;
@@ -496,6 +498,7 @@ public class RunningAppManager {
if (mGlobalUsageTime.get(pkg) == null) {
appUsageTime = new AppUsageTime();
appUsageTime.setPkg(pkg);
appUsageTime.setAppName(getAppName(pkg));
appUsageTime.setUsageTime(1);
} else {
appUsageTime = mGlobalUsageTime.get(pkg);
@@ -516,7 +519,7 @@ public class RunningAppManager {
appTimeControl.setToday_time(remainingTime);
TimeControlManager.getInstance().setAppTimeControl(pkg, appTimeControl);
} else {
if (machineControl==null){
if (machineControl == null) {
return;
}
Log.i(TAG, "reduceAppRemainingTime: " + machineControl.getToday_time());
@@ -529,6 +532,21 @@ public class RunningAppManager {
}
}
private String getAppName(String pkg) {
if (TextUtils.isEmpty(pkg)) return "未知";
PackageManager pm = mContext.getPackageManager();
PackageInfo info = null;
try {
info = pm.getPackageInfo(pkg, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (info != null) {
return info.applicationInfo.loadLabel(pm).toString();
}
return "未知";
}
public HashSet<String> allowPackage = new HashSet<String>() {{
this.add("com.android.launcher3");
this.add("com.android.packageinstaller");
@@ -597,8 +615,8 @@ public class RunningAppManager {
}
} else {
if (appTimeControl.getIs_quota() == 0) {
ToastUtil.show("没有使用额度");
return true;
// ToastUtil.show("没有使用额度");
return false;
}
if (getAppRemainingTime(pkg) <= 0) {
//没有剩余时间
@@ -716,10 +734,10 @@ public class RunningAppManager {
remainTime.setContent("该应用" + partTime2String(appTimeControl));
return remainTime.toString();
} else {
// if (appTimeControl.getIs_quota() == 0) {
// //要求设置了管控时间段没有设置使用额度也可以使用
// return "";
// }
if (appTimeControl.getIs_quota() == 0) {
//要求设置了管控时间段没有设置使用额度也可以使用
return "没有管控";
}
if (getAppRemainingTime(pkg) <= 0) {
//没有剩余时间
if (inWeekDay()) {
@@ -744,9 +762,9 @@ public class RunningAppManager {
}
}
} else {
// if (appTimeControl.getIs_quota() == 0) {
// return "没有使用额度";
// }
if (appTimeControl.getIs_quota() == 0) {
return "没有管控";
}
if (getAppRemainingTime(pkg) <= 0) {
//没有剩余时间
if (appTimeControl.getTc_use_type() == 1) {
@@ -798,6 +816,7 @@ public class RunningAppManager {
}
AppUsageTime appUsageTime = new AppUsageTime();
appUsageTime.setPkg(pkg);
appUsageTime.setAppName(getAppName(pkg));
AppRunTimeBean appRunTimeBean = mRemainingTimeMap.get(pkg);
long usageTime = appRunTimeBean.getAppRunTime();
long time;

View File

@@ -8,6 +8,7 @@ import android.provider.Settings;
import android.util.Log;
import com.google.gson.JsonObject;
import com.uiui.sn.BuildConfig;
import com.uiui.sn.IGetInfoInterface;
import com.uiui.sn.config.CommonConfig;
import com.uiui.sn.desktop.RunningAppManager;
@@ -63,7 +64,11 @@ public class RemoteService extends Service {
@Override
public String getDisableContent(String pkg) throws RemoteException {
return RunningAppManager.getInstance().getDisableContent(pkg);
String content = RunningAppManager.getInstance().getDisableContent(pkg);
if (BuildConfig.DEBUG) {
Log.e(TAG, "getDisableContent: " + content);
}
return content;
}
};
}