version:1.6.1
fix:休息日管控完善 add:
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
package com.info.sn.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.usage.UsageStats;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -36,13 +40,17 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
|
||||
public class ApkUtils {
|
||||
|
||||
private static String TAG = ApkUtils.class.getSimpleName();
|
||||
|
||||
public static synchronized boolean getRootAhth() {
|
||||
Process process = null;
|
||||
@@ -534,7 +542,7 @@ public class ApkUtils {
|
||||
update = versionCode > code;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
// LogUtils.e("NameNotFoundException", e.getMessage());
|
||||
// Log.e("NameNotFoundException", e.getMessage());
|
||||
update = false;
|
||||
}
|
||||
return update;
|
||||
@@ -602,29 +610,29 @@ public class ApkUtils {
|
||||
int hide = 0;
|
||||
//后台0显示,1隐藏
|
||||
try {
|
||||
if (pkage.equalsIgnoreCase("com.mediatek.camera")) {
|
||||
if (Settings.System.getInt(context.getContentResolver(), "qch_app_camera") == 1) {
|
||||
if ("com.mediatek.camera".equalsIgnoreCase(pkage)) {
|
||||
if (JGYUtils.getInt(context.getContentResolver(), "qch_app_camera") == 1) {
|
||||
hide = 1;
|
||||
}
|
||||
} else if (pkage.equalsIgnoreCase("com.android.deskclock")) {
|
||||
if (Settings.System.getInt(context.getContentResolver(), "qch_app_deskclock") == 1) {
|
||||
} else if ("com.android.deskclock".equalsIgnoreCase(pkage)) {
|
||||
if (JGYUtils.getInt(context.getContentResolver(), "qch_app_deskclock") == 1) {
|
||||
hide = 1;
|
||||
}
|
||||
} else if (pkage.equalsIgnoreCase("com.android.soundrecorder")) {
|
||||
if (Settings.System.getInt(context.getContentResolver(), "qch_app_soundrecorder") == 1) {
|
||||
} else if ("com.android.soundrecorder".equalsIgnoreCase(pkage)) {
|
||||
if (JGYUtils.getInt(context.getContentResolver(), "qch_app_soundrecorder") == 1) {
|
||||
hide = 1;
|
||||
}
|
||||
} else if (pkage.equalsIgnoreCase("com.android.music")) {
|
||||
if (Settings.System.getInt(context.getContentResolver(), "qch_app_music") == 1) {
|
||||
} else if ("com.android.music".equalsIgnoreCase(pkage)) {
|
||||
if (JGYUtils.getInt(context.getContentResolver(), "qch_app_music") == 1) {
|
||||
hide = 1;
|
||||
}
|
||||
} else if (pkage.equalsIgnoreCase("com.android.gallery3d")) {
|
||||
if (Settings.System.getInt(context.getContentResolver(), "qch_app_gallery") == 1) {
|
||||
} else if ("com.android.gallery3d".equalsIgnoreCase(pkage)) {
|
||||
if (JGYUtils.getInt(context.getContentResolver(), "qch_app_gallery") == 1) {
|
||||
hide = 1;
|
||||
}
|
||||
} else if (pkage.equalsIgnoreCase("com.android.documentsui")
|
||||
|| pkage.equalsIgnoreCase("com.mediatek.filemanager")) {
|
||||
if (Settings.System.getInt(context.getContentResolver(), "qch_app_filemanager") == 1) {
|
||||
} else if ("com.android.documentsui".equalsIgnoreCase(pkage)
|
||||
|| "com.mediatek.filemanager".equalsIgnoreCase(pkage)) {
|
||||
if (JGYUtils.getInt(context.getContentResolver(), "qch_app_filemanager") == 1) {
|
||||
hide = 1;
|
||||
}
|
||||
}
|
||||
@@ -661,75 +669,148 @@ public class ApkUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void addShortcut(Context context, String packageList) {
|
||||
public static void addShortcut(Context context) {
|
||||
String packageList = (String) SPUtils.get(context, "only_jgy_shortcut_list", "Invalid");
|
||||
if (TextUtils.isEmpty(packageList)) {
|
||||
JGYUtils.putString(context.getContentResolver(), "qch_launcher_icon_app", "");
|
||||
return;
|
||||
}
|
||||
Log.e("addShortcut", "addShortcut: " + packageList);
|
||||
String[] stringList = packageList.split(",");
|
||||
List<String> packages = new ArrayList<>(Arrays.asList(stringList));
|
||||
String installedList = "";
|
||||
HashSet<String> packages = new HashSet<>(Arrays.asList(stringList));
|
||||
String romapps = JGYUtils.getString(context.getContentResolver(), "jgy_customromapp");
|
||||
Log.e(TAG, "addShortcut: romapps: " + romapps);
|
||||
HashSet<String> appSet = new HashSet<>();
|
||||
if (!TextUtils.isEmpty(romapps)) {
|
||||
appSet = new HashSet<>(Arrays.asList(romapps.split(",")));
|
||||
packages.addAll(appSet);
|
||||
}
|
||||
packages.removeIf(new Predicate<String>() {
|
||||
@Override
|
||||
public boolean test(String s) {
|
||||
return TextUtils.isEmpty(s);
|
||||
}
|
||||
});
|
||||
StringBuilder installedListBuilder = new StringBuilder();
|
||||
for (String s : packages) {
|
||||
if (s.equals("com.jiaoguanyi.store") || s.equals("com.jiaoguanyi.appstore")) {
|
||||
if ("com.jiaoguanyi.store".equals(s) || "com.jiaoguanyi.appstore".equals(s)) {
|
||||
continue;
|
||||
}
|
||||
if (isSystemApp(context, s)) {
|
||||
if (!appSet.contains(s)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!ApkUtils.isAvailable(context, s)) {
|
||||
continue;
|
||||
}
|
||||
// ApkUtils.getStartActivityName(context, s);
|
||||
if (!installedList.contains(s)) {
|
||||
installedList += s + ",";
|
||||
Log.e("addShortcut", s);
|
||||
if (installedListBuilder.length() > 0) {
|
||||
installedListBuilder.append(",");
|
||||
}
|
||||
installedListBuilder.append(s);
|
||||
Log.e("addShortcut", "packages: " + s);
|
||||
}
|
||||
if (installedList.length() != 0) {
|
||||
installedList = installedList.substring(0, installedList.length() - 1);
|
||||
} else {
|
||||
Log.e("addShortcut", installedList);
|
||||
}
|
||||
boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", installedList);
|
||||
// String old = Settings.System.getString(context.getContentResolver(), "qch_launcher_icon_app");
|
||||
String installedList = installedListBuilder.toString();
|
||||
boolean qch_force_app = JGYUtils.putString(context.getContentResolver(), "qch_launcher_icon_app", installedList);
|
||||
// String old = JGYUtils.getString(context.getContentResolver(), "qch_launcher_icon_app");
|
||||
// Log.e("addShortcut", old);
|
||||
Log.e("addShortcut", "installedList:" + installedList);
|
||||
Log.e("addShortcut", "putstring:" + qch_force_app);
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public static void writeAppPackageList(Context context, String result) {
|
||||
ApkUtils.addShortcut(context, result);//开机之后添加图标到桌面
|
||||
String appstore = "com.jiaoguanyi.appstore";
|
||||
String store = "com.jiaoguanyi.store";
|
||||
String infosn = "com.info.sn";
|
||||
String appstoreuiui = "com.appstore.uiui";
|
||||
String desktop = "com.android.uiuios";
|
||||
String jgy1 = "com.uiuios.jgy1";
|
||||
String jgy2 = "com.uiuios.jgy2";
|
||||
ApkUtils.addShortcut(context);//开机之后添加图标到桌面
|
||||
|
||||
List<String> factoryAppList = new ArrayList<String>() {{
|
||||
this.add("com.jiaoguanyi.appstore");
|
||||
this.add("com.jiaoguanyi.store");
|
||||
this.add("com.info.sn");
|
||||
this.add("com.appstore.uiui");
|
||||
this.add("com.android.uiuios");
|
||||
this.add("com.uiuios.jgy1");
|
||||
this.add("com.uiuios.jgy2");
|
||||
this.add("com.tt.ttutils");
|
||||
this.add("com.info.chat");
|
||||
this.add("com.info.learning");
|
||||
}};
|
||||
HashSet<String> factoryAppSet = new HashSet<>(factoryAppList);
|
||||
if (!TextUtils.isEmpty(result)) {
|
||||
if (!result.contains(appstore)) {
|
||||
result = result + "," + appstore;
|
||||
}
|
||||
if (!result.contains(store)) {
|
||||
result = result + "," + store;
|
||||
}
|
||||
if (!result.contains(jgy1)) {
|
||||
result = result + "," + jgy1;
|
||||
}
|
||||
if (!result.contains(jgy2)) {
|
||||
result = result + "," + jgy2;
|
||||
}
|
||||
if (!result.contains(infosn)) {
|
||||
result = result + "," + infosn;
|
||||
}
|
||||
if (!result.contains(appstoreuiui)) {
|
||||
result = result + "," + appstoreuiui;
|
||||
}
|
||||
if (!result.contains(desktop)) {
|
||||
result = result + "," + desktop;
|
||||
}
|
||||
boolean qch_app_forbid = Settings.System.putString(context.getContentResolver(), "qch_app_forbid", result);
|
||||
Log.e("fht", "qch_app_forbid :" + result + ":" + qch_app_forbid);
|
||||
HashSet<String> writeAppSet = new HashSet<>(Arrays.asList(result.split(",")));
|
||||
writeAppSet.addAll(factoryAppSet);
|
||||
String pkgString = String.join(",", writeAppSet);
|
||||
Log.e("fht", "qch_app_forbid :" + result);
|
||||
boolean qch_app_forbid = JGYUtils.putString(context.getContentResolver(), "qch_app_forbid", pkgString);
|
||||
} else {
|
||||
JGYUtils.putString(context.getContentResolver(), "qch_app_forbid", String.join(",", factoryAppSet));
|
||||
Log.e("fht", "writeAppPackageList is null:");
|
||||
}
|
||||
Utils.writeDisableUpdateList(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为系统应用
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param pkgName 包名
|
||||
* @return
|
||||
*/
|
||||
public static boolean isSystemApp(Context context, String pkgName) {
|
||||
boolean isSystemApp = false;
|
||||
PackageInfo pi = null;
|
||||
try {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
pi = pm.getPackageInfo(pkgName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e("isSystemApp: NameNotFoundException:", e.getMessage());
|
||||
}
|
||||
// 是系统中已安装的应用
|
||||
if (pi != null) {
|
||||
boolean isSysApp = (pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1;
|
||||
boolean isSysUpd = (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1;
|
||||
isSystemApp = isSysApp || isSysUpd;
|
||||
}
|
||||
return isSystemApp;
|
||||
}
|
||||
|
||||
//通过包名获取版本号
|
||||
public static String getAPPVersionName(Context context, String packageName) {
|
||||
String versionName = "0";
|
||||
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return versionName;
|
||||
}
|
||||
PackageManager pm = context.getPackageManager();
|
||||
try {
|
||||
PackageInfo packageInfo = pm.getPackageInfo(packageName, 0);
|
||||
versionName = packageInfo.versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return versionName;
|
||||
}
|
||||
public static String getTaskPackname(Context context) {
|
||||
String currentApp = "CurrentNULL";
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
@SuppressLint("WrongConstant") UsageStatsManager usm = (UsageStatsManager) context.getSystemService("usagestats");
|
||||
long time = System.currentTimeMillis();
|
||||
List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000 * 1000, time);
|
||||
if (appList != null && appList.size() > 0) {
|
||||
SortedMap<Long, UsageStats> mySortedMap = new TreeMap<Long, UsageStats>();
|
||||
for (UsageStats usageStats : appList) {
|
||||
mySortedMap.put(usageStats.getLastTimeUsed(), usageStats);
|
||||
}
|
||||
if (mySortedMap != null && !mySortedMap.isEmpty()) {
|
||||
currentApp = mySortedMap.get(mySortedMap.lastKey()).getPackageName();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
List<ActivityManager.RunningAppProcessInfo> tasks = am.getRunningAppProcesses();
|
||||
currentApp = tasks.get(0).processName;
|
||||
}
|
||||
// Log.e("TAG", "Current App in foreground is: " + currentApp);
|
||||
return currentApp;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user