1.4.0705 优化后台,增加全局黑名单

This commit is contained in:
2024-07-08 10:32:45 +08:00
parent 526914c64c
commit 343700837e
22 changed files with 524 additions and 106 deletions

View File

@@ -57,7 +57,6 @@ import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.network.UrlAddress;
import com.aoleyun.sn.receiver.BootReceiver;
import com.aoleyun.sn.service.GuardService;
import com.aoleyun.sn.service.LogcatService;
import com.aoleyun.sn.service.StepService;
import com.aoleyun.sn.service.main.MainService;
import com.blankj.utilcode.util.FileUtils;
@@ -77,7 +76,6 @@ import com.tencent.mmkv.MMKV;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@@ -87,9 +85,6 @@ import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
@@ -534,8 +529,7 @@ public class JGYUtils {
*
* @param netAndLaunchBean
*/
@SuppressLint("NewApi")
synchronized public void setNetAndlaunch(NetAndLaunchBean netAndLaunchBean, List<AppListInfo> appListInfos) {
public void setNetAndlaunch(NetAndLaunchBean netAndLaunchBean, List<AppListInfo> appListInfos) {
Log.e(TAG, "setNetAndlaunch: " + "应用联网管控: " + netAndLaunchBean.getData().toString());
Log.e(TAG, "setNetAndlaunch: ");
HashSet<String> autoLaunchApp = new HashSet<>();//开机自启app
@@ -663,8 +657,7 @@ public class JGYUtils {
}
}
@SuppressLint("NewApi")
synchronized public void setNetAndlaunch(NetAndLaunchBean netAndLaunchBean) {
public void setNetAndlaunch(NetAndLaunchBean netAndLaunchBean) {
Log.e(TAG, "setNetAndlaunch: " + "应用联网管控: " + netAndLaunchBean.getData().toString());
Log.e(TAG, "setNetAndlaunch: ");
HashSet<String> autoLaunchApp = new HashSet<>();//开机自启app
@@ -772,31 +765,33 @@ public class JGYUtils {
}
}
@SuppressLint("NewApi")
synchronized public static void setAppNetwork(Context context, HashSet<String> blackList, HashSet<String> whiteList) {
public void setAppNetwork(Context context, HashSet<String> blackList, HashSet<String> whiteList) {
ContentResolver contentResolver = context.getContentResolver();
Log.e(TAG, "setAppNetwork: " + "设置应用联网管控" + blackList);
Log.e(TAG, "setAppNetwork: " + "设置应用联网管控 blackList =" + blackList);
Log.e(TAG, "setAppNetwork: " + "设置应用联网管控 whiteList =" + whiteList);
if (!MTK11Tag.equals(JGYUtils.getInstance().getAppPlatform())) {
if (blackList == null || blackList.size() == 0) {
SPUtils.put(context, CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "");
// 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);
// 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);
}
}
mMMKV.encode(CommonConfig.AOLE_ACTION_NETWORK_ALLOW, whiteList);
if (whiteList == null || whiteList.size() == 0) {
SPUtils.put(context, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "");
// Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "");
Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "");
} else {
// TODO: 2024/6/28 暂时所有的都为白名单
Settings.System.putString(contentResolver, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "");
String net_not = String.join(",", whiteList);
SPUtils.put(context, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, net_not);
Log.e(TAG, "setAppNetwork: net_not = " + net_not);
List<String> filterList = whiteList.stream().filter(s -> !ApkUtils.isAvailable(context, s)).collect(Collectors.toList());
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 {
@@ -815,13 +810,13 @@ public class JGYUtils {
}
public void updateNetworkWhiteList() {
String whiteString = (String) SPUtils.get(mContext, CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "");
if (TextUtils.isEmpty(whiteString)) {
Set<String> pkgs = mMMKV.decodeStringSet(CommonConfig.AOLE_ACTION_NETWORK_ALLOW, new HashSet<>());
if (pkgs.isEmpty()) {
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());
List<String> whiteList = new ArrayList<>(pkgs);
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 {
@@ -830,8 +825,7 @@ public class JGYUtils {
Log.e(TAG, "updateNetworkWhiteList: " + filterList);
}
@SuppressLint("NewApi")
synchronized public void onBootSendNetwork() {
public void onBootSendNetwork() {
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(",")));
@@ -897,7 +891,7 @@ public class JGYUtils {
}
}
synchronized public void setAppinsideWeb(BaseResponse<List<Appground>> response) {
public void setAppinsideWeb(BaseResponse<List<Appground>> response) {
if (response.code == 200) {
List<Appground> appgrounds = response.data;
if (appgrounds != null && appgrounds.size() > 0) {
@@ -951,7 +945,7 @@ public class JGYUtils {
/**
* @param response 黑白名单都可以管控
*/
synchronized public void setNewAppinsideWeb(BaseResponse response) {
public void setNewAppinsideWeb(BaseResponse response) {
Log.e(TAG, "setNewAppinsideWeb: " + "应用内部联网管控: " + response);
if (response.code == 200) {
String jsonString = GsonUtils.toJSONString(response.data);
@@ -989,7 +983,7 @@ public class JGYUtils {
// public static final String JGY_APPINSIDE_FIRST_WRITE = "JGY_APPINSIDE_FIRST_WRITE";
@SuppressLint("NewApi")
synchronized private void setWhiteApp(List<TTAppground> appgrounds) {
private void setWhiteApp(List<TTAppground> appgrounds) {
//去重
List<TTAppground> ttAppgrounds = appgrounds.stream().distinct().collect(Collectors.toList());
List<TTAppground> old = getOldWhitelist();
@@ -997,7 +991,7 @@ public class JGYUtils {
setWhiteList(ttAppgrounds);
}
synchronized private void comparedAppground(List<TTAppground> oldAppgrounds, List<TTAppground> newAppgrounds) {
private void comparedAppground(List<TTAppground> oldAppgrounds, List<TTAppground> newAppgrounds) {
List<TTAppground> addAppgrounds = new ArrayList<>();
List<TTAppground> deleteAppgrounds = new ArrayList<>();
List<TTAppground> changedAppgrounds = new ArrayList<>();
@@ -1131,7 +1125,7 @@ public class JGYUtils {
/**
* @param pkg 开启app白名单
*/
synchronized private void addPackage(String pkg) {
private void addPackage(String pkg) {
Log.e(TAG, "addPackage: " + pkg);
Intent intent26 = new Intent();
intent26.setAction("qch_app_inside_website");
@@ -1144,7 +1138,7 @@ public class JGYUtils {
* @param pkg
* @param urls 添加app白名单
*/
synchronized private void addToWhitelist(String pkg, String urls) {
private void addToWhitelist(String pkg, String urls) {
if (TextUtils.isEmpty(urls)) {
Log.e(TAG, "addToWhitelist: " + "urls is NULL");
return;
@@ -1169,7 +1163,7 @@ public class JGYUtils {
* @param pkg
* @param urls 删除某个app 内某个白名单
*/
synchronized private void deleteWhitelistUrl(String pkg, String urls) {
private void deleteWhitelistUrl(String pkg, String urls) {
if (TextUtils.isEmpty(urls)) {
Log.e(TAG, "addToWhitelist: " + "urls is NULL");
return;
@@ -1192,7 +1186,7 @@ public class JGYUtils {
/**
* @param pkg 开启和关闭白名单管控都需要发送
*/
synchronized private void deleteOtherAppWhitelist(String pkg) {
private void deleteOtherAppWhitelist(String pkg) {
Log.e(TAG, "disableAppWhitelist: " + pkg);
Intent intent24 = new Intent();
intent24.setAction("qch_app_setDelAppWhitUid");
@@ -1204,7 +1198,7 @@ public class JGYUtils {
/**
* @param appgrounds 设置黑名单管控
*/
synchronized private void setBlackApp(List<TTAppground> appgrounds) {
private void setBlackApp(List<TTAppground> appgrounds) {
Log.e(TAG, "setBlackApp: " + appgrounds);
StringBuilder blackList = new StringBuilder();
StringBuilder packageList = new StringBuilder();//单条管控名单
@@ -1244,7 +1238,7 @@ public class JGYUtils {
}
}
synchronized private static void sendAllweb(Context context) {
private static void sendAllweb(Context context) {
Log.e(TAG, "sendAllweb: ");
Intent intent = new Intent("qch_app_website")
.setPackage("com.android.settings");
@@ -1252,7 +1246,7 @@ public class JGYUtils {
context.sendBroadcast(intent);
}
synchronized private static void sendwebUrl(Context context) {
private static void sendwebUrl(Context context) {
Log.e(TAG, "sendwebUrl: ");
Intent intent = new Intent("qch_app_inside_website")
.setPackage("com.android.settings");
@@ -1260,7 +1254,7 @@ public class JGYUtils {
context.sendBroadcast(intent);
}
synchronized public void SettingSysData(String data) {
public void SettingSysData(String data) {
SPUtils.put(mContext, "SystemSettingData", data);
if (TextUtils.isEmpty(data)) {
Log.e(TAG, "SettingSysData: " + "data is empty");
@@ -1292,11 +1286,16 @@ public class JGYUtils {
this.add("com.notepad.uiui");
this.add("com.calendar.uiui");
this.add("com.alarmclock.uiui");
this.add("com.uiui.videoplayer");
// this.add("com.uiui.videoplayer");
this.add("com.ygyb.yischool");
this.add("com.books.wisdom");
this.add("com.qi.airoom");
this.add("com.qi.AiStudyRoom");
this.add("com.eusoft.eudic");
this.add("com.fenbi.android.solar");
this.add("com.eduyun.app.factory.ykt");
this.add("com.yaerxing.fkst");
this.add("com.jxw.usagedate");
}};
private Set<String> getWhitePkgList() {
@@ -1315,6 +1314,9 @@ public class JGYUtils {
if ("G23".equals(Build.MODEL)) {
pkgSet.addAll(ApkUtils.zhengwu);
}
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.G11Platform) {
pkgSet.addAll(ApkUtils.G11Pkgs);
}
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.YXPD1Platform) {
pkgSet.add("com.tencent.wemeet.app");
}
@@ -1362,19 +1364,20 @@ public class JGYUtils {
}
public void checkForceDownload() {
String jsonString = cacheHelper.getAsString(UrlAddress.GET_FORCE_INSTALL_LIST);
//为 "" 是已经请求成功的
if (jsonString == null) {
NetInterfaceManager.getInstance().getForceDownload();
} else {
Gson gson = new Gson();
Type listType = new TypeToken<List<ForceDownloadData>>() {
}.getType();
List<ForceDownloadData> forceDownloadData = gson.fromJson(jsonString, listType);
if (forceDownloadData != null) {
JGYUtils.getInstance().forceDownload(forceDownloadData);
}
}
// String jsonString = cacheHelper.getAsString(UrlAddress.GET_FORCE_INSTALL_LIST);
// //为 "" 是已经请求成功的
// if (jsonString == null) {
// NetInterfaceManager.getInstance().getForceDownload();
// } else {
// Gson gson = new Gson();
// Type listType = new TypeToken<List<ForceDownloadData>>() {
// }.getType();
// List<ForceDownloadData> forceDownloadData = gson.fromJson(jsonString, listType);
// if (forceDownloadData != null) {
// JGYUtils.getInstance().forceDownload(forceDownloadData);
// }
// }
NetInterfaceManager.getInstance().getForceDownload();
}
@@ -2009,6 +2012,7 @@ public class JGYUtils {
public void killPackage(String pkg) {
Log.e(TAG, "killPackage: " + pkg);
ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
manager.killBackgroundProcesses(pkg);
CmdUtil.execute("am force-stop " + pkg);
@@ -2329,12 +2333,13 @@ public class JGYUtils {
context.startService(new Intent(context, MainService.class));
context.startService(new Intent(context, StepService.class));
context.startService(new Intent(context, GuardService.class));
context.startService(new Intent(context, LogcatService.class));
// context.startService(new Intent(context, LogcatService.class));
}
}
private String Launcher3 = "com.android.launcher3";
private String Launcher3Class = "com.android.launcher3.Launcher";
private String Launcher3QuickstepClass = "com.android.launcher3.uioverrides.QuickstepLauncher";
private String AoleyunOs = "com.aoleyun.os";
private String AoleyunOsClass = "com.aoleyun.os.Launcher";
@@ -2407,6 +2412,12 @@ public class JGYUtils {
if (TextUtils.isEmpty(pkg)) {
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.YXPD1Platform) {
JGYUtils.getInstance().setDop7DefaultDesktop();
} else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.G11Platform) {
JGYUtils.getInstance().setJXWDefaultDesktop();
// } else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
// JGYUtils.getInstance().setJXWDefaultDesktop();
} else if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.AUDG104Platform) {
JGYUtils.getInstance().setAiuduDefaultDesktop();
}
} else {
if (pkg.equalsIgnoreCase(desktopPkg)) {
@@ -2438,29 +2449,45 @@ public class JGYUtils {
* 设置奥乐云桌面为默认
*/
public void setDefaultDesktop() {
Log.e(TAG, "setDefaultDesktop: ");
setDefaultDesktop(PackageNames.DESKTOP);
}
public void setYxpDefaultDesktop() {
Log.e(TAG, "setYxpDefaultDesktop: ");
setDefaultDesktop(PackageNames.YIXUEPAI_DESKTOP);
}
public void setDop7DefaultDesktop() {
Log.e(TAG, "setDop7DefaultDesktop: ");
setDefaultDesktop("com.aoleyunos.dop7");
}
public void setJXWDefaultDesktop() {
Log.e(TAG, "setJXWDefaultDesktop: ");
setDefaultDesktop("com.jxw.launcher");
}
public void setAiuduDefaultDesktop() {
Log.e(TAG, "setAiuduDefaultDesktop: ");
// setDefaultDesktop("com.aoleyun.audos");
// setLauncher3();
setDefaultDesktop(Launcher3, Launcher3QuickstepClass);
}
/**
* 设置默认桌面
*
* @param pkg
*/
public void setDefaultDesktop(String pkg) {
Log.e(TAG, "setDefaultDesktop: " + pkg);
Log.e(TAG, "setDefaultDesktop: pkg = " + pkg);
if (TextUtils.isEmpty(pkg)) {
setLauncher3();
} else {
String className = getStartClassName(pkg);
Log.e(TAG, "setDefaultDesktop: " + className);
Log.e(TAG, "setDefaultDesktop: className = " + className);
if (TextUtils.isEmpty(className)) {
setLauncher3();
} else {
@@ -2479,14 +2506,18 @@ public class JGYUtils {
}
}
private void setLauncher3() {
public void setLauncher3() {
if (ApkUtils.isAvailable(mContext, AoleyunOs)
|| "C2".equals(Build.MODEL)) {
setDefaultDesktop(AoleyunOs, AoleyunOsClass);
} else if ("Aiud_A8_ag_1095".equals(Build.MODEL)) {
setDefaultDesktop(AiUDuOs, AiUDuOsClass);
} else {
setDefaultDesktop(Launcher3, Launcher3Class);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
setDefaultDesktop(Launcher3, Launcher3QuickstepClass);
} else {
setDefaultDesktop(Launcher3, Launcher3Class);
}
}
}
@@ -2544,7 +2575,7 @@ public class JGYUtils {
} else {
//爱华设置,暂时屏蔽
// setDefaultLauncher(mContext, pkg, className);
Log.e(TAG, "setDefaultDesktop: setDefaultLauncher: " + pkg);
Log.e(TAG, "setDefaultDesktop: setDefaultLauncher: pkg = " + pkg);
}
// String oldDesktop = (String) SPUtils.get(mContext, "default_launcher", "");
// if (Objects.equals(oldDesktop, pkg)) {
@@ -2569,10 +2600,42 @@ public class JGYUtils {
Log.e(TAG, "setDefaultDesktop: " + pkg + ":" + className);
Log.e(TAG, "setDefaultDesktop: " + "persist.sys.launcher.pkgname = " + SystemProperties.get("persist.sys.launcher.pkgname"));
Log.e(TAG, "setDefaultDesktop: " + "persist.sys.launcher.classname = " + SystemProperties.get("persist.sys.launcher.classname"));
Log.e(TAG, "setDefaultDesktop: getDefaultLaunchers = " + getDefaultLaunchers());
setDefaultLauncher(new ComponentName(pkg, className));
}
public Set<String> getDefaultLaunchers() {
Set<String> defaultLaunchers = new HashSet<String>();
PackageManager packageManager = mContext.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
// 查询所有已安装的桌面应用
List<ResolveInfo> launcherList = packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
// 获取默认的桌面应用,没有指定默认桌面时返回"android"
ResolveInfo defaultLauncher = packageManager.resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (launcherList != null && defaultLauncher != null) {
String pkgName = defaultLauncher.activityInfo.packageName;
Log.e("getDefaultLaunchers", "default launcher is : " + pkgName);
// 没有指定默认桌面时返回的是"android",故这里过滤下防止"android"被添加到默认桌面列表中
for (ResolveInfo info : launcherList) {
Log.e("getDefaultLaunchers", "launcher : " + info.activityInfo.packageName);
if (info.activityInfo.packageName.equals(pkgName)) {
defaultLaunchers.add(pkgName);
}
}
}
// 有多个桌面应用,且目前没有指定默认桌面时,返回所有的桌面应用
if (defaultLaunchers.isEmpty() && launcherList != null) {
for (ResolveInfo resolveInfo : launcherList) {
defaultLaunchers.add(resolveInfo.activityInfo.packageName);
}
}
Log.e("getDefaultLaunchers", "defaultLaunchers : " + defaultLaunchers);
return defaultLaunchers;
}
public String getMacJson(Context context) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("sn", Utils.getSerial(context));
@@ -2800,9 +2863,10 @@ public class JGYUtils {
mContext.sendBroadcast(bootIntent);
}
@Deprecated
public void wakeUpAoleyunAPP() {
wakeUpAppstore();
wakeUpNotify();
// wakeUpAppstore();
// wakeUpNotify();
}
public static String getModel() {