|
|
|
|
@@ -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: " + "数据一致");
|
|
|
|
|
|