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

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

@@ -67,8 +67,8 @@ android {
productFlavors { productFlavors {
beta { beta {
flavorDimensions "default" flavorDimensions "default"
versionCode 29 versionCode 30
versionName "3.8" versionName "3.9"
} }
official { official {

View File

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

View File

@@ -10,6 +10,8 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.os.Build; import android.os.Build;
import android.os.PowerManager; import android.os.PowerManager;
@@ -496,6 +498,7 @@ public class RunningAppManager {
if (mGlobalUsageTime.get(pkg) == null) { if (mGlobalUsageTime.get(pkg) == null) {
appUsageTime = new AppUsageTime(); appUsageTime = new AppUsageTime();
appUsageTime.setPkg(pkg); appUsageTime.setPkg(pkg);
appUsageTime.setAppName(getAppName(pkg));
appUsageTime.setUsageTime(1); appUsageTime.setUsageTime(1);
} else { } else {
appUsageTime = mGlobalUsageTime.get(pkg); appUsageTime = mGlobalUsageTime.get(pkg);
@@ -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>() {{ public HashSet<String> allowPackage = new HashSet<String>() {{
this.add("com.android.launcher3"); this.add("com.android.launcher3");
this.add("com.android.packageinstaller"); this.add("com.android.packageinstaller");
@@ -597,8 +615,8 @@ public class RunningAppManager {
} }
} else { } else {
if (appTimeControl.getIs_quota() == 0) { if (appTimeControl.getIs_quota() == 0) {
ToastUtil.show("没有使用额度"); // ToastUtil.show("没有使用额度");
return true; return false;
} }
if (getAppRemainingTime(pkg) <= 0) { if (getAppRemainingTime(pkg) <= 0) {
//没有剩余时间 //没有剩余时间
@@ -716,10 +734,10 @@ public class RunningAppManager {
remainTime.setContent("该应用" + partTime2String(appTimeControl)); remainTime.setContent("该应用" + partTime2String(appTimeControl));
return remainTime.toString(); return remainTime.toString();
} else { } else {
// if (appTimeControl.getIs_quota() == 0) { if (appTimeControl.getIs_quota() == 0) {
// //要求设置了管控时间段没有设置使用额度也可以使用 //要求设置了管控时间段没有设置使用额度也可以使用
// return ""; return "没有管控";
// } }
if (getAppRemainingTime(pkg) <= 0) { if (getAppRemainingTime(pkg) <= 0) {
//没有剩余时间 //没有剩余时间
if (inWeekDay()) { if (inWeekDay()) {
@@ -744,9 +762,9 @@ public class RunningAppManager {
} }
} }
} else { } else {
// if (appTimeControl.getIs_quota() == 0) { if (appTimeControl.getIs_quota() == 0) {
// return "没有使用额度"; return "没有管控";
// } }
if (getAppRemainingTime(pkg) <= 0) { if (getAppRemainingTime(pkg) <= 0) {
//没有剩余时间 //没有剩余时间
if (appTimeControl.getTc_use_type() == 1) { if (appTimeControl.getTc_use_type() == 1) {
@@ -798,6 +816,7 @@ public class RunningAppManager {
} }
AppUsageTime appUsageTime = new AppUsageTime(); AppUsageTime appUsageTime = new AppUsageTime();
appUsageTime.setPkg(pkg); appUsageTime.setPkg(pkg);
appUsageTime.setAppName(getAppName(pkg));
AppRunTimeBean appRunTimeBean = mRemainingTimeMap.get(pkg); AppRunTimeBean appRunTimeBean = mRemainingTimeMap.get(pkg);
long usageTime = appRunTimeBean.getAppRunTime(); long usageTime = appRunTimeBean.getAppRunTime();
long time; long time;

View File

@@ -8,6 +8,7 @@ import android.provider.Settings;
import android.util.Log; import android.util.Log;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.uiui.sn.BuildConfig;
import com.uiui.sn.IGetInfoInterface; import com.uiui.sn.IGetInfoInterface;
import com.uiui.sn.config.CommonConfig; import com.uiui.sn.config.CommonConfig;
import com.uiui.sn.desktop.RunningAppManager; import com.uiui.sn.desktop.RunningAppManager;
@@ -63,7 +64,11 @@ public class RemoteService extends Service {
@Override @Override
public String getDisableContent(String pkg) throws RemoteException { 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;
} }
}; };
} }