update:接口优化,耗电优化
This commit is contained in:
2023-04-10 15:20:46 +08:00
parent e5cdbc2ecc
commit c7046475da
13 changed files with 165 additions and 176 deletions

View File

@@ -19,6 +19,7 @@ public class BootManager {
public void start() {
sendLauncherIcon();
timeControlUpdate();
JGYUtils.getInstance().updateNetworkWhiteList();
JGYUtils.getInstance().onBootSendNetwork();
JGYUtils.getInstance().onBootSetAppInsideWeb();
}

View File

@@ -276,6 +276,11 @@ public class JGYUtils {
return locked == JGYActions.FRAME_CODE_LOCKED;
}
public boolean tagEmpty() {
String tag = mMMKV.decodeString(CommonConfig.DEVICES_TAG, "");
return TextUtils.isEmpty(tag);
}
public int getBatteryLevel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
BatteryManager batteryManager = (BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE);
@@ -579,88 +584,17 @@ public class JGYUtils {
synchronized public static void setAppNetwork(Context context, HashSet<String> blackList, HashSet<String> whiteList) {
ContentResolver contentResolver = context.getContentResolver();
Log.e(TAG, "setAppNetwork: " + "设置应用联网管控" + blackList);
// String dis = Settings.System.getString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW);
// String not = Settings.System.getString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_ALLOW);
// //清除旧数据
// if (!TextUtils.isEmpty(dis)) {
// Log.e(TAG, "setAppNetwork: dis = " + dis);
// Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "Invalid");
// }
// if (!TextUtils.isEmpty(not)) {
// Log.e(TAG, "setAppNetwork: not = " + not);
// Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "Invalid");
// }
// String oldBlackList = Settings.System.getString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW);
// HashSet<String> oldBlackListSet = new HashSet<>(Arrays.asList(oldBlackList.split(",")));
// oldBlackListSet.removeIf(s -> TextUtils.isEmpty(s.trim()));
// //之前禁止上网得列表
// Log.e(TAG, "setAppNetwork: oldBlackListSet: " + oldBlackListSet);
// if (oldBlackListSet.size() == 0) {
// Log.e(TAG, "setAppNetwork: blackList: " + blackList);
// for (String pkg : new HashSet<>(blackList)) {
// if (TextUtils.isEmpty(pkg)) continue;
// //发送没有安装的
// if (!ApkUtils.isAvailable(context, pkg)) {
// Log.e(TAG, "setAppNetwork: skip: " + pkg);
// blackList.remove(pkg);
// continue;
// } else {
// Log.e(TAG, "setAppNetwork: " + pkg + " 已安装");
// }
// Intent netControlNotIntent = new Intent(CommonConfig.AOLE_ACTION_NETWORK_DISALLOW);
// 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;
// Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, pkg);
// Intent netControlNotIntent = new Intent(CommonConfig.AOLE_ACTION_NETWORK_ALLOW);
// 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);
// blackList.remove(pkg);
// continue;
// } else {
// Log.e(TAG, "setAppNetwork: " + pkg + " 已安装");
// }
// Intent netControlNotIntent = new Intent(CommonConfig.AOLE_ACTION_NETWORK_DISALLOW);
// netControlNotIntent.putExtra("package_name", pkg);
// netControlNotIntent.setPackage("com.android.settings");
// context.sendBroadcast(netControlNotIntent);
// }
// }
if (blackList == null || blackList.size() == 0) {
SPUtils.put(context, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "");
Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "");
} else {
String net_not = String.join(",", blackList);
SPUtils.put(context, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, net_not);
Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, net_not);
Log.e(TAG, "setAppNetwork: " + net_not);
if (!MTK11Tag.equals(JGYUtils.getInstance().getAppPlatform())) {
if (blackList == null || blackList.size() == 0) {
SPUtils.put(context, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "");
Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "");
} else {
String net_not = String.join(",", blackList);
SPUtils.put(context, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, net_not);
Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, net_not);
Log.e(TAG, "setAppNetwork: " + net_not);
}
}
if (whiteList == null || whiteList.size() == 0) {
@@ -669,9 +603,16 @@ public class JGYUtils {
} else {
String net_not = String.join(",", whiteList);
SPUtils.put(context, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, net_not);
Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, net_not);
Log.e(TAG, "setAppNetwork: " + net_not);
Log.e(TAG, "setAppNetwork: net_not = " + net_not);
List<String> filterList = whiteList.stream().filter(s -> !ApkUtils.isAvailable(context, s)).collect(Collectors.toList());
if (filterList.size() == 0) {
Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "");
} else {
Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, String.join(",", filterList));
}
Log.e(TAG, "setAppNetwork: filterList = " + filterList);
}
//Intent netControlIntent = new Intent(CommonDatas.ACTION_HrReceiver_JGY_DIS);
//netControlIntent.putExtra("package_name", net_not);
//sendBroadcast(netControlIntent);
@@ -681,27 +622,45 @@ public class JGYUtils {
//sendBroadcast(netControlNotIntent);
}
public void updateNetworkWhiteList() {
String whiteString = (String) SPUtils.get(mContext, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "");
if (TextUtils.isEmpty(whiteString)) {
Log.e(TAG, "updateNetworkWhiteList: allow content is empty");
return;
}
List<String> whiteList = new ArrayList<>(Arrays.asList(whiteString.split(",")));
List<String> filterList = whiteList.stream().filter(s -> !ApkUtils.isAvailable(mContext, s)).collect(Collectors.toList());
if (filterList.size() == 0) {
Settings.System.putString(crv, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "");
} else {
Settings.System.putString(crv, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, String.join(",", filterList));
}
Log.e(TAG, "updateNetworkWhiteList: " + filterList);
}
@SuppressLint("NewApi")
synchronized public void onBootSendNetwork() {
String oldBlackListString = (String) SPUtils.get(mContext, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "");
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());
if (!MTK11Tag.equals(JGYUtils.getInstance().getAppPlatform())) {
String oldBlackListString = (String) SPUtils.get(mContext, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "");
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(CommonConfig.AOLE_ACTION_NETWORK_DISALLOW);
netControlNotIntent.putExtra("package_name", pkg);
netControlNotIntent.setPackage("com.android.settings");
mContext.sendBroadcast(netControlNotIntent);
}
});
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(CommonConfig.AOLE_ACTION_NETWORK_DISALLOW);
netControlNotIntent.putExtra("package_name", pkg);
netControlNotIntent.setPackage("com.android.settings");
mContext.sendBroadcast(netControlNotIntent);
}
}

View File

@@ -806,7 +806,7 @@ public class Utils {
Log.e("getSerial", "读取设备序列号异常:" + e.toString());
}
if (BuildConfig.DEBUG) {
return "LTPKD22110000051";
// return "LTPKD22110000051";
// serial = "012345679ABCDEF";
}
if (NOSN.equalsIgnoreCase(serial)) {