version:1.6.9
fix: add:
This commit is contained in:
@@ -12,6 +12,7 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageInstaller;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
@@ -40,6 +41,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
@@ -790,6 +792,7 @@ public class ApkUtils {
|
||||
}
|
||||
return versionName;
|
||||
}
|
||||
|
||||
public static String getTaskPackname(Context context) {
|
||||
String currentApp = "CurrentNULL";
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
@@ -813,4 +816,22 @@ public class ApkUtils {
|
||||
// Log.e("TAG", "Current App in foreground is: " + currentApp);
|
||||
return currentApp;
|
||||
}
|
||||
|
||||
public static boolean getIsCanStart(Context context, String pkg) {
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN, null);
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
// 通过查询,获得所有ResolveInfo对象.
|
||||
List<ResolveInfo> infos = context.getPackageManager().queryIntentActivities(intent, 0);
|
||||
HashMap<String, ResolveInfo> hashMap = new HashMap<>();
|
||||
for (ResolveInfo info : infos) {
|
||||
hashMap.put(info.activityInfo.packageName, info);
|
||||
}
|
||||
if (hashMap.get(pkg) == null) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,8 +33,11 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
|
||||
|
||||
@@ -610,4 +613,129 @@ public class JGYUtils {
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
//应用管理-允许联网
|
||||
public final static String ACTION_HrReceiver_JGY = "qch_jgy_network_allow";
|
||||
//应用管理-禁止联网
|
||||
public final static String ACTION_HrReceiver_JGY_DIS = "qch_jgy_network_disallow";
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
synchronized public static void setAppNetwork(Context context, HashSet<String> blackList) {
|
||||
Log.e(TAG, "setAppNetwork: " + "设置应用联网管控" + blackList);
|
||||
String dis = Settings.System.getString(context.getContentResolver(), ACTION_HrReceiver_JGY_DIS);
|
||||
String not = Settings.System.getString(context.getContentResolver(), ACTION_HrReceiver_JGY);
|
||||
//清除旧数据
|
||||
if (!TextUtils.isEmpty(dis)) {
|
||||
Log.e(TAG, "setAppNetwork: dis = " + dis);
|
||||
Settings.System.putString(context.getContentResolver(), ACTION_HrReceiver_JGY_DIS, "Invalid");
|
||||
}
|
||||
if (!TextUtils.isEmpty(not)) {
|
||||
Log.e(TAG, "setAppNetwork: not = " + not);
|
||||
Settings.System.putString(context.getContentResolver(), ACTION_HrReceiver_JGY, "Invalid");
|
||||
}
|
||||
|
||||
String oldBlackList = (String) SPUtils.get(context, ACTION_HrReceiver_JGY_DIS, "");
|
||||
HashSet<String> oldBlackListSet = new HashSet<>(Arrays.asList(oldBlackList.split(",")));
|
||||
oldBlackListSet.removeIf(new Predicate<String>() {
|
||||
@Override
|
||||
public boolean test(String s) {
|
||||
//去空
|
||||
return TextUtils.isEmpty(s.trim());
|
||||
}
|
||||
});
|
||||
//之前禁止上网得列表
|
||||
Log.e(TAG, "setAppNetwork: oldBlackListSet: " + oldBlackListSet);
|
||||
if (oldBlackListSet.size() == 0) {
|
||||
Log.e(TAG, "setAppNetwork: blackList: " + blackList);
|
||||
for (String pkg : blackList) {
|
||||
if (TextUtils.isEmpty(pkg)) continue;
|
||||
//发送没有安装的
|
||||
if (!ApkUtils.isAvailable(context, pkg)) {
|
||||
Log.e(TAG, "setAppNetwork: skip: " + pkg);
|
||||
continue;
|
||||
} else {
|
||||
Log.e(TAG, "setAppNetwork: " + pkg + " 已安装");
|
||||
}
|
||||
Intent netControlNotIntent = new Intent(ACTION_HrReceiver_JGY_DIS);
|
||||
netControlNotIntent.putExtra("package_name", pkg);
|
||||
netControlNotIntent.setPackage("com.android.settings");
|
||||
context.sendBroadcast(netControlNotIntent);
|
||||
}
|
||||
} else {
|
||||
//减少的
|
||||
Set<String> removedNet = oldBlackListSet;
|
||||
//增加的
|
||||
Set<String> addedNet = new HashSet<>();
|
||||
for (String pkg : blackList) {
|
||||
if (TextUtils.isEmpty(pkg)) continue;
|
||||
if (removedNet.contains(pkg)) {
|
||||
removedNet.remove(pkg);
|
||||
} else {
|
||||
addedNet.add(pkg);
|
||||
}
|
||||
}
|
||||
|
||||
Log.e(TAG, "setAppNetwork: removedNet: " + removedNet);
|
||||
Log.e(TAG, "setAppNetwork: addedNet: " + addedNet);
|
||||
for (String pkg : removedNet) {
|
||||
if (TextUtils.isEmpty(pkg)) continue;
|
||||
Intent netControlNotIntent = new Intent(ACTION_HrReceiver_JGY);
|
||||
netControlNotIntent.putExtra("package_name", pkg);
|
||||
netControlNotIntent.setPackage("com.android.settings");
|
||||
context.sendBroadcast(netControlNotIntent);
|
||||
}
|
||||
for (String pkg : addedNet) {
|
||||
if (TextUtils.isEmpty(pkg)) continue;
|
||||
if (!ApkUtils.isAvailable(context, pkg)) {
|
||||
Log.e(TAG, "setAppNetwork: skip: " + pkg);
|
||||
continue;
|
||||
} else {
|
||||
Log.e(TAG, "setAppNetwork: " + pkg + " 已安装");
|
||||
}
|
||||
Intent netControlNotIntent = new Intent(ACTION_HrReceiver_JGY_DIS);
|
||||
netControlNotIntent.putExtra("package_name", pkg);
|
||||
netControlNotIntent.setPackage("com.android.settings");
|
||||
context.sendBroadcast(netControlNotIntent);
|
||||
}
|
||||
}
|
||||
|
||||
String net_not = String.join(",", blackList);
|
||||
SPUtils.put(context, ACTION_HrReceiver_JGY_DIS, net_not);
|
||||
//Settings.System.putString(mContext.getContentResolver(), JGYActions.ACTION_HrReceiver_JGY_DIS, net_not);
|
||||
Log.e("fht", "not::" + net_not);
|
||||
|
||||
//Intent netControlIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY_DIS);
|
||||
//netControlIntent.putExtra("package_name", net_not);
|
||||
//sendBroadcast(netControlIntent);
|
||||
|
||||
//Intent netControlNotIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY);
|
||||
//netControlNotIntent.putExtra("package_name", net_ok);
|
||||
//sendBroadcast(netControlNotIntent);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
synchronized public void onBootSendNetwork() {
|
||||
String oldBlackListString = (String) SPUtils.get(mContext, ACTION_HrReceiver_JGY_DIS, "");
|
||||
HashSet<String> oldBlackListSet = new HashSet<>(Arrays.asList(oldBlackListString.split(",")));
|
||||
Log.e(TAG, "setAppNetwork: oldBlackListSet: " + oldBlackListSet);
|
||||
oldBlackListSet.removeIf(new Predicate<String>() {
|
||||
@Override
|
||||
public boolean test(String s) {
|
||||
return TextUtils.isEmpty(s.trim());
|
||||
}
|
||||
});
|
||||
for (String pkg : oldBlackListSet) {
|
||||
if (TextUtils.isEmpty(pkg)) continue;
|
||||
if (!ApkUtils.isAvailable(mContext, pkg)) {
|
||||
Log.e(TAG, "setAppNetwork: skip: " + pkg);
|
||||
continue;
|
||||
}
|
||||
Intent netControlNotIntent = new Intent(ACTION_HrReceiver_JGY_DIS);
|
||||
netControlNotIntent.putExtra("package_name", pkg);
|
||||
netControlNotIntent.setPackage("com.android.settings");
|
||||
mContext.sendBroadcast(netControlNotIntent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ public class TimeUtils {
|
||||
public static final String WEEK_START_TIME_KEY = "WEEK_START_TIME";
|
||||
public static final String WEEK_END_TIME_KEY = "WEEK_END_TIME";
|
||||
public static long dayTime = 60 * 60 * 24 * 1000;
|
||||
public static long minuteTime = 60 * 1000;
|
||||
|
||||
|
||||
public static String getNowTime() {
|
||||
long nowTime = System.currentTimeMillis();
|
||||
@@ -173,7 +175,7 @@ public class TimeUtils {
|
||||
* @return 时间戳格式化文本
|
||||
*/
|
||||
public static String getDate(long time) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String finaWayDate = sdf.format(time);
|
||||
Log.e(TAG, "getDate: " + finaWayDate);
|
||||
return finaWayDate;
|
||||
@@ -332,7 +334,9 @@ public class TimeUtils {
|
||||
//开始时间大于结束时间 列 16:00-01:00
|
||||
endDate.setTime(endDate.getTime() + dayTime);
|
||||
}
|
||||
if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) {
|
||||
Log.e(TAG, "inControlTime: " + (startDate.getTime() - minuteTime));
|
||||
assert nowDate != null;
|
||||
if (nowDate.getTime() <= startDate.getTime() - minuteTime || nowDate.getTime() >= endDate.getTime()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -1169,6 +1169,7 @@ public class Utils {
|
||||
|
||||
/**
|
||||
* 获取系统配置信息
|
||||
*
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
@@ -1216,7 +1217,7 @@ public class Utils {
|
||||
Log.e(TAG, "getHardware: storage = " + storage);
|
||||
double use_space = getUse_space(context);
|
||||
Log.e(TAG, "getHardware: use_space = " + use_space);
|
||||
long wifi_time = (long) com.info.sn.utils.SPUtils.get(context, "wifi_last_connect_time", 0L)/1000;
|
||||
long wifi_time = (long) com.info.sn.utils.SPUtils.get(context, "wifi_last_connect_time", 0L) / 1000;
|
||||
Log.e(TAG, "getHardware: wifi_time" + wifi_time);
|
||||
int CPU = getNumCores();
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
@@ -1246,7 +1247,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static String getAppUsedStatistics(Context context) {
|
||||
StatisticsInfo statisticsInfo = new StatisticsInfo(context, 3);
|
||||
StatisticsInfo statisticsInfo = new StatisticsInfo(context, 0);
|
||||
long totalTime = statisticsInfo.getTotalTime();
|
||||
int totalTimes = statisticsInfo.getTotalTimes();
|
||||
List<AppInformation> datalist = statisticsInfo.getShowList();
|
||||
@@ -1265,6 +1266,7 @@ public class Utils {
|
||||
}
|
||||
});
|
||||
String jsonString = JSON.toJSONString(appUsedList);
|
||||
Log.e(TAG, "getAppUsedStatistics: " + jsonString);
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user