version:2.6
fix:修复爱华会禁用Google输入法,修复设置默认桌面 update:
This commit is contained in:
@@ -679,7 +679,7 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
Log.e(TAG, "processCustomMessage: " + extras);
|
||||
break;
|
||||
case DEFAULTP_APP:
|
||||
ToastUtil.betaShow("收到管控:");
|
||||
ToastUtil.betaShow("收到管控:设置默认APP");
|
||||
setDefalutApp(extras);
|
||||
break;
|
||||
case PLAY_SOUND:
|
||||
@@ -1135,7 +1135,6 @@ public class MessageReceiver extends XGPushBaseReceiver {
|
||||
if (TextUtils.isEmpty(default_launcher)) {
|
||||
JGYUtils.getInstance().setDefaultDesktop("");
|
||||
SPUtils.put(mContext, "default_launcher", "");
|
||||
|
||||
} else {
|
||||
JGYUtils.getInstance().setDefaultDesktop(default_launcher);
|
||||
SPUtils.put(mContext, "default_launcher", default_launcher);
|
||||
|
||||
@@ -928,7 +928,7 @@ public class ApkUtils {
|
||||
this.add("cn.com.bifa.eyeshiely");
|
||||
}};
|
||||
|
||||
public static List aihuaApp = new ArrayList() {{
|
||||
public static Set<String> aihuaApp = new HashSet<String>() {{
|
||||
this.add("com.liuyang.jcstudentside");
|
||||
this.add("com.alibaba.android.rimet");
|
||||
this.add("com.tencent.wemeet.app");
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.ActivityTaskManager;
|
||||
import android.app.role.RoleManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
@@ -23,7 +24,9 @@ import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.PowerManager;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -92,6 +95,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -1384,11 +1389,9 @@ public class JGYUtils {
|
||||
this.add("com.aoleyunos.dop2");
|
||||
|
||||
//aihua
|
||||
this.add("com.liuyang.jcstudentside");
|
||||
this.add("com.alibaba.android.rimet");
|
||||
this.add("com.tencent.wemeet.app");
|
||||
this.add("com.qi.studycomputer.launcher");
|
||||
|
||||
this.add("com.android.mms");
|
||||
this.add("com.android.fmradio");
|
||||
this.add("com.mediatek.filemanager");
|
||||
}};
|
||||
|
||||
/**
|
||||
@@ -1407,7 +1410,7 @@ public class JGYUtils {
|
||||
if (ApkUtils.isSystemApp(mContext, pkg)) {
|
||||
pm.setApplicationEnabledSetting(pkg, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
|
||||
}
|
||||
if (!showAppList.contains(pkg)) {
|
||||
if (!showAppList.contains(pkg) && !ApkUtils.aihuaApp.contains(pkg)) {
|
||||
pm.setApplicationEnabledSetting(pkg, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
|
||||
Log.e(TAG, "hideSystemAPP: " + "disable: " + pkg);
|
||||
} else {
|
||||
@@ -1919,6 +1922,62 @@ public class JGYUtils {
|
||||
private String Launcher3 = "com.android.launcher3";
|
||||
private String Launcher3Class = "com.android.launcher3.Launcher";
|
||||
|
||||
public void setDefaultLauncher(Context context, String defPackageName, String defClassName) {
|
||||
try {
|
||||
if (!TextUtils.isEmpty(defPackageName) && !TextUtils.isEmpty(defClassName)) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("android.intent.action.MAIN");
|
||||
filter.addCategory("android.intent.category.HOME");
|
||||
filter.addCategory("android.intent.category.DEFAULT");
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_HOME);
|
||||
// 返回给定条件的所有ResolveInfo对象(本质上是Activity)
|
||||
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||
int bestMatch = 0;
|
||||
final int size = list.size();
|
||||
ComponentName[] set = new ComponentName[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
ResolveInfo ri = list.get(i);
|
||||
set[i] = new ComponentName(ri.activityInfo.packageName, ri.activityInfo.name);
|
||||
if (ri.match > bestMatch) {
|
||||
bestMatch = ri.match;
|
||||
}
|
||||
}
|
||||
ComponentName preActivity = new ComponentName(defPackageName, defClassName);
|
||||
context.getPackageManager().addPreferredActivity(filter, bestMatch, set, preActivity);
|
||||
}
|
||||
} catch (java.lang.SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setRoleHolderAsUser(Context context, String packageName) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
String roleName = "android.app.role.HOME";
|
||||
boolean add = true;
|
||||
int flags = 0;
|
||||
UserHandle user = Process.myUserHandle();
|
||||
Log.i("settingssssssstemf", (add ? "Adding" : "Removing") + " package as role holder, role: "
|
||||
+ roleName + ", package: " + packageName);
|
||||
if (JGYUtils.getInstance().checkAppPlatform() != JGYUtils.MTKPlatform) {
|
||||
RoleManager roleManager = context.getSystemService(RoleManager.class);
|
||||
Executor executor = context.getMainExecutor();
|
||||
Consumer<Boolean> callback = successful -> {
|
||||
if (successful) {
|
||||
Log.d("settingssssssstemf", "Package " + (add ? "added" : "removed")
|
||||
+ " as role holder, role: " + roleName + ", package: " + packageName);
|
||||
} else {
|
||||
Log.d("settingssssssstemf", "Failed to " + (add ? "add" : "remove")
|
||||
+ " package as role holder, role: " + roleName + ", package: "
|
||||
+ packageName);
|
||||
}
|
||||
};
|
||||
roleManager.addRoleHolderAsUser(roleName, packageName, flags, user, executor, callback);
|
||||
Log.i("settingssssssstemf", "addRoleHolderAsUser done");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkDefaultDesktop(String pkg) {
|
||||
String desktopPkg = (String) SPUtils.get(mContext, "default_launcher", "");
|
||||
Log.e(TAG, "checkDefaultDesktop: " + desktopPkg);
|
||||
@@ -1983,6 +2042,11 @@ public class JGYUtils {
|
||||
}
|
||||
|
||||
public void setDefaultDesktop(String pkg, String className) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
setRoleHolderAsUser(mContext, pkg);
|
||||
} else {
|
||||
setDefaultLauncher(mContext, pkg, className);
|
||||
}
|
||||
String oldDesktop = (String) SPUtils.get(mContext, "default_launcher", "");
|
||||
if (Objects.equals(oldDesktop, pkg)) {
|
||||
Log.e(TAG, "setDefaultDesktop: " + "数据一致");
|
||||
|
||||
Reference in New Issue
Block a user