refactor(utils): 清理未使用的工具类和方法
- 删除整个 AppsManagerUtils、AppUpdateInfo、ForegroundAppUtil 类 - 移除 ApkUtils 中未使用的方法,包括 getRootAhth、openApp、installApkInSilence、addShortcut、getTaskPackname、queryFilterAppInfo、getAppIcon 等 - 移除 CacheUtils 中未使用的 getApplicationCache 方法和 PackageStatsObserver 内部类 - 移除 CXAESUtil 中未使用的加解密及文件操作方法 - 将 StringUtils.join 替换为 String.join 以消除自定义依赖 - 清理各文件中未使用的 import 语句和冗余字段
This commit is contained in:
1 parent
cf1dfe64df
commit
df8a7bc153
22 files changed
+6
-2803
No files matched your search
@@ -29,7 +29,6 @@ import com.fuying.sn.utils.ApkUtils;
|
|||||||
import com.fuying.sn.utils.FileUtils;
|
import com.fuying.sn.utils.FileUtils;
|
||||||
import com.fuying.sn.utils.JgyUtils;
|
import com.fuying.sn.utils.JgyUtils;
|
||||||
import com.fuying.sn.utils.SPUtils;
|
import com.fuying.sn.utils.SPUtils;
|
||||||
import com.fuying.sn.utils.StringUtils;
|
|
||||||
import com.fuying.sn.utils.Utils;
|
import com.fuying.sn.utils.Utils;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.tencent.mmkv.MMKV;
|
import com.tencent.mmkv.MMKV;
|
||||||
@@ -580,7 +579,7 @@ public final class AppPolicySync {
|
|||||||
List<AppAndWhiteBean> appAndWhiteList = baseResponse.data;
|
List<AppAndWhiteBean> appAndWhiteList = baseResponse.data;
|
||||||
if (appAndWhiteList != null) {
|
if (appAndWhiteList != null) {
|
||||||
List<String> pkgList = appAndWhiteList.stream().map(AppAndWhiteBean::getApp_package).collect(Collectors.toList());
|
List<String> pkgList = appAndWhiteList.stream().map(AppAndWhiteBean::getApp_package).collect(Collectors.toList());
|
||||||
String pkgString = StringUtils.join(",", pkgList);
|
String pkgString = String.join(",", pkgList);
|
||||||
mMMKV.encode(CommonConfig.BUILT_IN_APPS, pkgString);
|
mMMKV.encode(CommonConfig.BUILT_IN_APPS, pkgString);
|
||||||
Log.e("getAppAndWhite", "onNext: " + pkgString);
|
Log.e("getAppAndWhite", "onNext: " + pkgString);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
package com.fuying.sn.utils;
|
package com.fuying.sn.utils;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.usage.UsageStats;
|
|
||||||
import android.app.usage.UsageStatsManager;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
@@ -14,27 +9,23 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageInstaller;
|
import android.content.pm.PackageInstaller;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.content.FileProvider;
|
import androidx.core.content.FileProvider;
|
||||||
|
|
||||||
import com.fuying.sn.BuildConfig;
|
import com.fuying.sn.BuildConfig;
|
||||||
import com.fuying.sn.R;
|
|
||||||
import com.fuying.sn.bean.AppInfo;
|
import com.fuying.sn.bean.AppInfo;
|
||||||
import com.fuying.sn.config.CommonConfig;
|
import com.fuying.sn.config.CommonConfig;
|
||||||
import com.fuying.sn.gson.GsonUtils;
|
import com.fuying.sn.gson.GsonUtils;
|
||||||
import com.fuying.sn.receiver.InstallResultReceiver;
|
import com.fuying.sn.receiver.InstallResultReceiver;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -44,15 +35,9 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
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;
|
|
||||||
|
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.rxjava3.core.Observable;
|
import io.reactivex.rxjava3.core.Observable;
|
||||||
@@ -90,124 +75,6 @@ public class ApkUtils {
|
|||||||
return applicationInfos;
|
return applicationInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized boolean getRootAhth() {
|
|
||||||
Process process = null;
|
|
||||||
DataOutputStream os = null;
|
|
||||||
try {
|
|
||||||
process = Runtime.getRuntime().exec("su");
|
|
||||||
os = new DataOutputStream(process.getOutputStream());
|
|
||||||
os.writeBytes("exit\n");
|
|
||||||
os.flush();
|
|
||||||
int exitValue = process.waitFor();
|
|
||||||
return exitValue == 0;
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("*** DEBUG ***", "Unexpected error - Here is what I know: "
|
|
||||||
+ e.getMessage());
|
|
||||||
return false;
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (os != null) {
|
|
||||||
os.close();
|
|
||||||
}
|
|
||||||
process.destroy();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openApp(Context context, View view) {
|
|
||||||
try {
|
|
||||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage((String) view.getTag(R.string.download_btn_had));
|
|
||||||
context.startActivity(intent);
|
|
||||||
} catch (Exception e) {
|
|
||||||
ToastUtil.show(String.valueOf(R.string.open_app_fail));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void openApp(Context context, String packageName) {
|
|
||||||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
|
|
||||||
if (intent != null) {
|
|
||||||
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean openPackage(Context context, String packageName) {
|
|
||||||
Context pkgContext = getPackageContext(context, packageName);
|
|
||||||
Intent intent = getAppOpenIntentByPackageName(context, packageName);
|
|
||||||
if (pkgContext != null && intent != null) {
|
|
||||||
pkgContext.startActivity(intent);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Context getPackageContext(Context context, String packageName) {
|
|
||||||
Context pkgContext = null;
|
|
||||||
if (context.getPackageName().equals(packageName)) {
|
|
||||||
pkgContext = context;
|
|
||||||
} else {
|
|
||||||
// 创建第三方应用的上下文环境
|
|
||||||
try {
|
|
||||||
pkgContext = context.createPackageContext(packageName,
|
|
||||||
Context.CONTEXT_IGNORE_SECURITY
|
|
||||||
| Context.CONTEXT_INCLUDE_CODE);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pkgContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Intent getAppOpenIntentByPackageName(Context context, String packageName) {
|
|
||||||
//Activity完整名
|
|
||||||
String mainAct = null;
|
|
||||||
//根据包名寻找
|
|
||||||
PackageManager pkgMag = context.getPackageManager();
|
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
|
|
||||||
List<ResolveInfo> list = pkgMag.queryIntentActivities(intent,
|
|
||||||
PackageManager.GET_ACTIVITIES);
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
ResolveInfo info = list.get(i);
|
|
||||||
if (info.activityInfo.packageName.equals(packageName)) {
|
|
||||||
mainAct = info.activityInfo.name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (TextUtils.isEmpty(mainAct)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
intent.setComponent(new ComponentName(packageName, mainAct));
|
|
||||||
return intent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 安装一个apk文件
|
|
||||||
*/
|
|
||||||
public static void install(Context context, File uriFile) {
|
|
||||||
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
||||||
// 由于没有在Activity环境下启动Activity,设置下面的标签
|
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
if (Build.VERSION.SDK_INT >= 24) { //判读版本是否在7.0以上
|
|
||||||
//参数1 上下文, 参数2 Provider主机地址 和配置文件中保持一致 参数3 共享的文件
|
|
||||||
Uri apkUri =
|
|
||||||
FileProvider.getUriForFile(context, "com.fuying.sn.fileprovider", uriFile);
|
|
||||||
//添加这一句表示对目标应用临时授权该Uri所代表的文件
|
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
||||||
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
|
|
||||||
} else {
|
|
||||||
intent.setDataAndType(Uri.fromFile(uriFile),
|
|
||||||
"application/vnd.android.package-archive");
|
|
||||||
}
|
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据包名卸载应用
|
* 根据包名卸载应用
|
||||||
*
|
*
|
||||||
@@ -243,68 +110,6 @@ public class ApkUtils {
|
|||||||
return packageNames.contains(packageName);
|
return packageNames.contains(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查手机上是否安装了指定的软件
|
|
||||||
*/
|
|
||||||
public static boolean isAvailable(Context context, File file) {
|
|
||||||
return isAvailable(context, getPackageName(context, file.getAbsolutePath()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据文件路径获取包名
|
|
||||||
*/
|
|
||||||
public static String getPackageName(Context context, String filePath) {
|
|
||||||
PackageManager packageManager = context.getPackageManager();
|
|
||||||
PackageInfo info = packageManager.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
|
|
||||||
if (info != null) {
|
|
||||||
ApplicationInfo appInfo = info.applicationInfo;
|
|
||||||
return appInfo.packageName; //得到安装包名称
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从apk中获取版本信息
|
|
||||||
*/
|
|
||||||
public static String getChannelFromApk(Context context, String channelPrefix) {
|
|
||||||
//从apk包中获取
|
|
||||||
ApplicationInfo appinfo = context.getApplicationInfo();
|
|
||||||
String sourceDir = appinfo.sourceDir;
|
|
||||||
//默认放在meta-inf/里, 所以需要再拼接一下
|
|
||||||
String key = "META-INF/" + channelPrefix;
|
|
||||||
String ret = "";
|
|
||||||
ZipFile zipfile = null;
|
|
||||||
try {
|
|
||||||
zipfile = new ZipFile(sourceDir);
|
|
||||||
Enumeration<?> entries = zipfile.entries();
|
|
||||||
while (entries.hasMoreElements()) {
|
|
||||||
ZipEntry entry = ((ZipEntry) entries.nextElement());
|
|
||||||
String entryName = entry.getName();
|
|
||||||
if (entryName.startsWith(key)) {
|
|
||||||
ret = entryName;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (zipfile != null) {
|
|
||||||
try {
|
|
||||||
zipfile.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String[] split = ret.split(channelPrefix);
|
|
||||||
String channel = "";
|
|
||||||
if (split.length >= 2) {
|
|
||||||
channel = ret.substring(key.length());
|
|
||||||
}
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// public static void installRx(final Context context, final String packageName, final String filePath) {
|
// public static void installRx(final Context context, final String packageName, final String filePath) {
|
||||||
//
|
//
|
||||||
// Observable.create(new Observable.OnSubscribe<Integer>() {
|
// Observable.create(new Observable.OnSubscribe<Integer>() {
|
||||||
@@ -410,31 +215,6 @@ public class ApkUtils {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
//使用系统签名
|
//使用系统签名
|
||||||
public static void installApkInSilence(String installPath, String packageName) {
|
|
||||||
ToastUtil.show("正在安装应用...");
|
|
||||||
Class<?> pmService;
|
|
||||||
Class<?> activityTherad;
|
|
||||||
Method method;
|
|
||||||
try {
|
|
||||||
activityTherad = Class.forName("android.app.ActivityThread");
|
|
||||||
Class<?>[] paramTypes = getParamTypes(activityTherad, "getPackageManager");
|
|
||||||
method = activityTherad.getMethod("getPackageManager", paramTypes);
|
|
||||||
Object PackageManagerService = method.invoke(activityTherad);
|
|
||||||
pmService = PackageManagerService.getClass();
|
|
||||||
Class<?>[] paramTypes1 = getParamTypes(pmService, "installPackageAsUser");
|
|
||||||
method = pmService.getMethod("installPackageAsUser", paramTypes1);
|
|
||||||
method.invoke(PackageManagerService, installPath, null, 0x00000040, packageName, getUserId(Binder.getCallingUid()));//getUserId
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过路径安装APK,兼容Android 9以上
|
* 通过路径安装APK,兼容Android 9以上
|
||||||
*
|
*
|
||||||
@@ -664,64 +444,6 @@ public class ApkUtils {
|
|||||||
return uid / PER_USER_RANGE;
|
return uid / PER_USER_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkIsUpdate(Context context, String packageName, int versionCode) {
|
|
||||||
PackageManager packageManager = context.getPackageManager();
|
|
||||||
boolean update = false;
|
|
||||||
PackageInfo packageInfo = null;
|
|
||||||
try {
|
|
||||||
packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
|
|
||||||
int code = packageInfo.versionCode;
|
|
||||||
update = versionCode > code;
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
// Log.e("NameNotFoundException", e.getMessage());
|
|
||||||
update = false;
|
|
||||||
}
|
|
||||||
return update;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized public static PackageInfo getPackageInfo(Context context, String packageName) {
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
PackageInfo packageInfo = null;
|
|
||||||
try {
|
|
||||||
packageInfo = pm.getPackageInfo(packageName, 0);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.e("getPackageInfo", packageName + ":" + e.getMessage());
|
|
||||||
}
|
|
||||||
return packageInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized public static String getApplicationName(Context context, String packageName) {
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
PackageInfo packageInfo = null;
|
|
||||||
String name = "";
|
|
||||||
try {
|
|
||||||
packageInfo = pm.getPackageInfo(packageName, 0);
|
|
||||||
name = pm.getApplicationLabel(packageInfo.applicationInfo).toString();
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.e("getPackageInfo", packageName + ":" + e.getMessage());
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void installApk(Activity activity, File newApkFile) {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
||||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
String type = "application/vnd.android.package-archive";
|
|
||||||
Uri uri;
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
uri = FileProvider.getUriForFile(activity, "com.fuying.sn.fileprovider", newApkFile);
|
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
||||||
} else {
|
|
||||||
uri = Uri.fromFile(newApkFile);
|
|
||||||
}
|
|
||||||
intent.setDataAndType(uri, type);
|
|
||||||
activity.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void installApk(Context context, File newApkFile) {
|
public static void installApk(Context context, File newApkFile) {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
@@ -780,77 +502,6 @@ public class ApkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static int getAppVersionCode(Context context, String packageName) {
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
PackageInfo info = null;
|
|
||||||
try {
|
|
||||||
info = pm.getPackageInfo(packageName, 0);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (null != info) {
|
|
||||||
long appVersionCode;
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
||||||
appVersionCode = info.getLongVersionCode();
|
|
||||||
} else {
|
|
||||||
appVersionCode = info.versionCode;
|
|
||||||
}
|
|
||||||
return (int) appVersionCode;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addShortcut(Context context) {
|
|
||||||
String packageList = Settings.System.getString(context.getContentResolver(), CommonConfig.ONLY_SHORTCUT_LIST);
|
|
||||||
if (TextUtils.isEmpty(packageList)) {
|
|
||||||
Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", "");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Log.e("addShortcut", "addShortcut: " + packageList);
|
|
||||||
String[] stringList = packageList.split(",");
|
|
||||||
HashSet<String> packages = new HashSet<>(Arrays.asList(stringList));
|
|
||||||
String romapps = Settings.System.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 ("com.jiaoguanyi.store".equals(s) || "com.jiaoguanyi.appstore".equals(s)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (isSystemApp(context, s)) {
|
|
||||||
if (!appSet.contains(s)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isAvailable(context, s)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// getStartActivityName(context, s);
|
|
||||||
if (installedListBuilder.length() > 0) {
|
|
||||||
installedListBuilder.append(",");
|
|
||||||
}
|
|
||||||
installedListBuilder.append(s);
|
|
||||||
Log.e("addShortcut", "packages: " + s);
|
|
||||||
}
|
|
||||||
String installedList = installedListBuilder.toString();
|
|
||||||
boolean aole_force_app = Settings.System.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:" + aole_force_app);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
public static void writeAppPackageList(Context context, String result) {
|
public static void writeAppPackageList(Context context, String result) {
|
||||||
Log.e(TAG, "writeAppPackageList: " + result);
|
Log.e(TAG, "writeAppPackageList: " + result);
|
||||||
@@ -915,30 +566,6 @@ public class ApkUtils {
|
|||||||
return versionName;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean getIsCanStart(Context context, String pkg) {
|
public static boolean getIsCanStart(Context context, String pkg) {
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN, null);
|
Intent intent = new Intent(Intent.ACTION_MAIN, null);
|
||||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||||
@@ -952,30 +579,6 @@ public class ApkUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取第三方应用
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static List<String> queryFilterAppInfo(Context context) {
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
// 查询所有已经安装的应用程序
|
|
||||||
List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的
|
|
||||||
List<String> applicationInfos = new ArrayList<>();
|
|
||||||
for (ApplicationInfo app : appInfos) {
|
|
||||||
// Logutils.e("queryFilterAppInfo", String.valueOf(app.flags));
|
|
||||||
// Logutils.e("queryFilterAppInfo", String.valueOf((app.flags & mask)));
|
|
||||||
if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
|
|
||||||
//通过flag排除系统应用,会将电话、短信也排除掉
|
|
||||||
} else {
|
|
||||||
applicationInfos.add(app.packageName);
|
|
||||||
Log.e("queryFilterAppInfo", app.packageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return applicationInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isUpdate(Context context, AppInfo appUpdateInfo) {
|
public static boolean isUpdate(Context context, AppInfo appUpdateInfo) {
|
||||||
String packageName = appUpdateInfo.getApp_package();
|
String packageName = appUpdateInfo.getApp_package();
|
||||||
long versionCode = appUpdateInfo.getApp_version_code();
|
long versionCode = appUpdateInfo.getApp_version_code();
|
||||||
@@ -1049,26 +652,4 @@ public class ApkUtils {
|
|||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过包名获取应用图标
|
|
||||||
*
|
|
||||||
* @param context 上下文
|
|
||||||
* @param packageName 包名
|
|
||||||
* @return 应用图标 Drawable,未找到时返回 null
|
|
||||||
*/
|
|
||||||
public static Drawable getAppIcon(Context context, String packageName) {
|
|
||||||
if (context == null || TextUtils.isEmpty(packageName)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
try {
|
|
||||||
ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, 0);
|
|
||||||
return applicationInfo.loadIcon(pm);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.e(TAG, "getAppIcon: " + packageName + " : " + e.getMessage());
|
|
||||||
}
|
|
||||||
return context.getDrawable(R.mipmap.ic_launcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.fuying.sn.utils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Administrator on 2017/1/10.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class AppUpdateInfo {
|
|
||||||
private String packageName;
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
public String getPackageName() {
|
|
||||||
return packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPackageName(String packageName) {
|
|
||||||
this.packageName = packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(String version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "AppUpdateInfo{" +
|
|
||||||
"packageName='" + packageName + '\'' +
|
|
||||||
", version='" + version + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,18 +5,15 @@ import android.content.Context;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
public class AppUsedTimeUtils {
|
public class AppUsedTimeUtils {
|
||||||
private static final String TAG = "AppUsedTimeUtils";
|
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
private static AppUsedTimeUtils sInstance;
|
private static AppUsedTimeUtils sInstance;
|
||||||
private Context mContext;
|
|
||||||
private String app_package;
|
private String app_package;
|
||||||
private long start_time;
|
private long start_time;
|
||||||
|
|
||||||
// private AppTimeinfo appTimeinfo;
|
// private AppTimeinfo appTimeinfo;
|
||||||
|
|
||||||
private AppUsedTimeUtils(Context context) {
|
private AppUsedTimeUtils(Context context) {
|
||||||
this.mContext = context;
|
|
||||||
// appTimeinfo = getAppTimeinfo();
|
// appTimeinfo = getAppTimeinfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,148 +0,0 @@
|
|||||||
package com.fuying.sn.utils;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
|
|
||||||
import com.fuying.sn.bean.LocalAppInfo;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AppsManagerUtils {
|
|
||||||
|
|
||||||
public static AppUpdateInfo getUpAppsByPackageName(Context context, String packageName) {
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
AppUpdateInfo appInfo = new AppUpdateInfo();
|
|
||||||
try {
|
|
||||||
PackageInfo packinfo = pm.getPackageInfo(packageName, 0);
|
|
||||||
appInfo.setPackageName(packageName);
|
|
||||||
appInfo.setVersion(packinfo.versionName);
|
|
||||||
if (packinfo.versionName == null || packinfo.versionName.equals("")) {
|
|
||||||
appInfo.setVersion(packinfo.versionCode + "");
|
|
||||||
}
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return appInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LocalAppInfo getAppsByPackageName(Context context, String packageName) {
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
List<LocalAppInfo> appInfos = new ArrayList<LocalAppInfo>();
|
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN, null);
|
|
||||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
||||||
// 通过查询,获得所有ResolveInfo对象.
|
|
||||||
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
|
|
||||||
for (ResolveInfo info : infos) {
|
|
||||||
// 不列出系统应用
|
|
||||||
String pkg = info.activityInfo.packageName;
|
|
||||||
if (pkg.equals(packageName)) {
|
|
||||||
extractedAppInfo(pm, appInfos, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return appInfos.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<AppUpdateInfo> getUpadteApps(Context context) {
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
List<AppUpdateInfo> appInfos = new ArrayList<AppUpdateInfo>();
|
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN, null);
|
|
||||||
|
|
||||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
||||||
// 通过查询,获得所有ResolveInfo对象.
|
|
||||||
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
|
|
||||||
for (ResolveInfo info : infos) {
|
|
||||||
// 不列出系统应用
|
|
||||||
String pkg = info.activityInfo.packageName;
|
|
||||||
if (!isSystemApp(context, pkg)) {
|
|
||||||
PackageInfo packageInfo = null;
|
|
||||||
AppUpdateInfo appInfo = new AppUpdateInfo();
|
|
||||||
appInfo.setPackageName(info.activityInfo.packageName);
|
|
||||||
try {
|
|
||||||
packageInfo = pm.getPackageInfo(info.activityInfo.packageName, 0);
|
|
||||||
appInfo.setVersion(packageInfo.versionName);
|
|
||||||
if (packageInfo.versionName == null || packageInfo.versionName.equals("")) {
|
|
||||||
appInfo.setVersion(packageInfo.versionCode + "");
|
|
||||||
}
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
appInfos.add(appInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return appInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<LocalAppInfo> getUserApps(Context context) {
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
List<LocalAppInfo> appInfos = new ArrayList<LocalAppInfo>();
|
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN, null);
|
|
||||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
||||||
// 通过查询,获得所有ResolveInfo对象.
|
|
||||||
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
|
|
||||||
for (ResolveInfo info : infos) {
|
|
||||||
// 不列出系统应用
|
|
||||||
String pkg = info.activityInfo.packageName;
|
|
||||||
if (!isSystemApp(context, pkg)) {
|
|
||||||
extractedAppInfo(pm, appInfos, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return appInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static void extractedAppInfo(PackageManager pm,
|
|
||||||
List<LocalAppInfo> appInfos, ResolveInfo info) {
|
|
||||||
PackageInfo packageInfo = null;
|
|
||||||
LocalAppInfo appInfo = new LocalAppInfo();
|
|
||||||
appInfo.setIcon(info.activityInfo.loadIcon(pm));
|
|
||||||
appInfo.setAppName(info.activityInfo.loadLabel(pm).toString());
|
|
||||||
appInfo.setPackageName(info.activityInfo.packageName);
|
|
||||||
|
|
||||||
try {
|
|
||||||
packageInfo = pm.getPackageInfo(info.activityInfo.packageName, 0);
|
|
||||||
appInfo.setVersion(packageInfo.versionName);
|
|
||||||
if (packageInfo.versionName == null || packageInfo.versionName.equals("")) {
|
|
||||||
appInfo.setVersion(packageInfo.versionCode + "");
|
|
||||||
}
|
|
||||||
String appInstallDir = info.activityInfo.applicationInfo.publicSourceDir;
|
|
||||||
int size = Integer.valueOf((int) new File(appInstallDir).length());
|
|
||||||
appInfo.setSize(size);
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
appInfos.add(appInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isSystemApp(Context context, String pkg) {
|
|
||||||
try {
|
|
||||||
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(pkg, 0);
|
|
||||||
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0) {
|
|
||||||
if (pkg.equals(context.getPackageName())) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
//第三方应用
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//系统应用
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,28 +1,11 @@
|
|||||||
package com.fuying.sn.utils;
|
package com.fuying.sn.utils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
|
||||||
import java.security.InvalidKeyException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import javax.crypto.CipherInputStream;
|
|
||||||
import javax.crypto.CipherOutputStream;
|
|
||||||
import javax.crypto.NoSuchPaddingException;
|
|
||||||
import javax.crypto.spec.IvParameterSpec;
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
public class CXAESUtil {
|
public class CXAESUtil {
|
||||||
/**
|
|
||||||
* 加解密算法/工作模式/填充方式
|
|
||||||
*/
|
|
||||||
private static final String CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
|
|
||||||
public final static String HEX = "0123456789ABCDEF";
|
public final static String HEX = "0123456789ABCDEF";
|
||||||
private static final int keyLenght = 16;
|
private static final int keyLenght = 16;
|
||||||
private static final String defaultV = "0";
|
private static final String defaultV = "0";
|
||||||
@@ -48,39 +31,6 @@ public class CXAESUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 加密
|
|
||||||
*
|
|
||||||
* @param key 密钥
|
|
||||||
* @param src 加密文本
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static String encrypt2Java(String key, String src) throws Exception {
|
|
||||||
// /src = Base64.encodeToString(src.getBytes(), Base64.DEFAULT);
|
|
||||||
byte[] rawKey = toMakekey(key, keyLenght, defaultV).getBytes();// key.getBytes();
|
|
||||||
byte[] result = encrypt2Java(rawKey, src.getBytes("utf-8"));
|
|
||||||
// result = Base64.encode(result, Base64.DEFAULT);
|
|
||||||
return toHex(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解密
|
|
||||||
*
|
|
||||||
* @param key 密钥
|
|
||||||
* @param encrypted 待揭秘文本
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static String decrypt(String key, String encrypted) throws Exception {
|
|
||||||
byte[] rawKey = toMakekey(key, keyLenght, defaultV).getBytes();// key.getBytes();
|
|
||||||
byte[] enc = toByte(encrypted);
|
|
||||||
// enc = Base64.decode(enc, Base64.DEFAULT);
|
|
||||||
byte[] result = decrypt(rawKey, enc);
|
|
||||||
// /result = Base64.decode(result, Base64.DEFAULT);
|
|
||||||
return new String(result, "utf-8");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 密钥key ,默认补的数字,补全16位数,以保证安全补全至少16位长度,android和ios对接通过
|
* 密钥key ,默认补的数字,补全16位数,以保证安全补全至少16位长度,android和ios对接通过
|
||||||
*
|
*
|
||||||
@@ -121,62 +71,6 @@ public class CXAESUtil {
|
|||||||
return encrypted;
|
return encrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 真正的加密过程
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* @param src
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private static byte[] encrypt2Java(byte[] key, byte[] src) throws Exception {
|
|
||||||
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
|
|
||||||
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(new byte[cipher.getBlockSize()]));
|
|
||||||
byte[] encrypted = cipher.doFinal(src);
|
|
||||||
return encrypted;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 真正的解密过程
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* @param encrypted
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private static byte[] decrypt(byte[] key, byte[] encrypted) throws Exception {
|
|
||||||
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
|
|
||||||
Cipher cipher = Cipher.getInstance("AES");
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(new byte[cipher.getBlockSize()]));
|
|
||||||
byte[] decrypted = cipher.doFinal(encrypted);
|
|
||||||
return decrypted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String toHex(String txt) {
|
|
||||||
return toHex(txt.getBytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String fromHex(String hex) {
|
|
||||||
return new String(toByte(hex));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 把16进制转化为字节数组
|
|
||||||
*
|
|
||||||
* @param hexString
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static byte[] toByte(String hexString) {
|
|
||||||
int len = hexString.length() / 2;
|
|
||||||
byte[] result = new byte[len];
|
|
||||||
for (int i = 0; i < len; i++)
|
|
||||||
result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2), 16).byteValue();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 二进制转字符,转成了16进制
|
* 二进制转字符,转成了16进制
|
||||||
* 0123456789abcdefg
|
* 0123456789abcdefg
|
||||||
@@ -198,134 +92,4 @@ public class CXAESUtil {
|
|||||||
sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
|
sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化 AES Cipher
|
|
||||||
*
|
|
||||||
* @param sKey
|
|
||||||
* @param cipherMode
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Cipher initAESCipher(String sKey, int cipherMode) {
|
|
||||||
// 创建Key gen
|
|
||||||
// KeyGenerator keyGenerator = null;
|
|
||||||
Cipher cipher = null;
|
|
||||||
try {
|
|
||||||
/*
|
|
||||||
* keyGenerator = KeyGenerator.getInstance("AES");
|
|
||||||
* keyGenerator.init(128, new SecureRandom(sKey.getBytes()));
|
|
||||||
* SecretKey secretKey = keyGenerator.generateKey(); byte[]
|
|
||||||
* codeFormat = secretKey.getEncoded(); SecretKeySpec key = new
|
|
||||||
* SecretKeySpec(codeFormat, "AES"); cipher =
|
|
||||||
* Cipher.getInstance("AES"); //初始化 cipher.init(cipherMode, key);
|
|
||||||
*/
|
|
||||||
byte[] rawKey = toMakekey(sKey, keyLenght, defaultV).getBytes();
|
|
||||||
SecretKeySpec skeySpec = new SecretKeySpec(rawKey, "AES");
|
|
||||||
cipher = Cipher.getInstance("AES");
|
|
||||||
cipher.init(cipherMode, skeySpec, new IvParameterSpec(new byte[cipher.getBlockSize()]));
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
e.printStackTrace(); // To change body of catch statement use File |
|
|
||||||
// Settings | File Templates.
|
|
||||||
} catch (NoSuchPaddingException e) {
|
|
||||||
e.printStackTrace(); // To change body of catch statement use File |
|
|
||||||
// Settings | File Templates.
|
|
||||||
} catch (InvalidKeyException e) {
|
|
||||||
e.printStackTrace(); // To change body of catch statement use File |
|
|
||||||
// Settings | File Templates.
|
|
||||||
} catch (InvalidAlgorithmParameterException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return cipher;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 对文件进行AES加密
|
|
||||||
*
|
|
||||||
* @param sourceFile
|
|
||||||
* @param sKey
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static File encryptFile(File sourceFile, String toFile, String dir, String sKey) {
|
|
||||||
// 新建临时加密文件
|
|
||||||
File encrypfile = null;
|
|
||||||
InputStream inputStream = null;
|
|
||||||
OutputStream outputStream = null;
|
|
||||||
try {
|
|
||||||
inputStream = new FileInputStream(sourceFile);
|
|
||||||
encrypfile = new File(dir + toFile);
|
|
||||||
outputStream = new FileOutputStream(encrypfile);
|
|
||||||
Cipher cipher = initAESCipher(sKey, Cipher.ENCRYPT_MODE);
|
|
||||||
// 以加密流写入文件
|
|
||||||
CipherInputStream cipherInputStream = new CipherInputStream(inputStream, cipher);
|
|
||||||
byte[] cache = new byte[1024];
|
|
||||||
int nRead = 0;
|
|
||||||
while ((nRead = cipherInputStream.read(cache)) != -1) {
|
|
||||||
outputStream.write(cache, 0, nRead);
|
|
||||||
outputStream.flush();
|
|
||||||
}
|
|
||||||
cipherInputStream.close();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace(); // To change body of catch statement use File |
|
|
||||||
// Settings | File Templates.
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace(); // To change body of catch statement use File |
|
|
||||||
// Settings | File Templates.
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace(); // To change body of catch statement use
|
|
||||||
// File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
outputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace(); // To change body of catch statement use
|
|
||||||
// File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return encrypfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AES方式解密文件
|
|
||||||
*
|
|
||||||
* @param sourceFile
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static File decryptFile(File sourceFile, String toFile, String dir, String sKey) {
|
|
||||||
File decryptFile = null;
|
|
||||||
InputStream inputStream = null;
|
|
||||||
OutputStream outputStream = null;
|
|
||||||
try {
|
|
||||||
decryptFile = new File(dir + toFile);
|
|
||||||
Cipher cipher = initAESCipher(sKey, Cipher.DECRYPT_MODE);
|
|
||||||
inputStream = new FileInputStream(sourceFile);
|
|
||||||
outputStream = new FileOutputStream(decryptFile);
|
|
||||||
CipherOutputStream cipherOutputStream = new CipherOutputStream(outputStream, cipher);
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int r;
|
|
||||||
while ((r = inputStream.read(buffer)) >= 0) {
|
|
||||||
cipherOutputStream.write(buffer, 0, r);
|
|
||||||
}
|
|
||||||
cipherOutputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace(); // To change body of catch statement use File |
|
|
||||||
// Settings | File Templates.
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace(); // To change body of catch statement use
|
|
||||||
// File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
outputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace(); // To change body of catch statement use
|
|
||||||
// File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return decryptFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,12 +3,8 @@ package com.fuying.sn.utils;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.IPackageDataObserver;
|
import android.content.pm.IPackageDataObserver;
|
||||||
import android.content.pm.IPackageManager;
|
|
||||||
import android.content.pm.IPackageStatsObserver;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageStats;
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -19,43 +15,6 @@ public class CacheUtils {
|
|||||||
private final long MAX_WAIT_TIME = 60 * 1000;
|
private final long MAX_WAIT_TIME = 60 * 1000;
|
||||||
private final long WAIT_TIME_INCR = 10 * 1000;
|
private final long WAIT_TIME_INCR = 10 * 1000;
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取应用数据大小 cache + data
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @param packageName
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
public long getApplicationCache(Context context, String packageName) throws Exception {
|
|
||||||
try {
|
|
||||||
PackageStatsObserver observer = new PackageStatsObserver();
|
|
||||||
// wait on observer
|
|
||||||
synchronized (observer) {
|
|
||||||
Method method = PackageManager.class.getMethod("getPackageSizeInfo", new Class[] { String.class, IPackageStatsObserver.class });
|
|
||||||
method.invoke(context.getPackageManager(), packageName, observer);
|
|
||||||
// getPm().getPackageSizeInfo(packageName, UserHandle.myUserId(), observer);
|
|
||||||
long waitTime = 0;
|
|
||||||
while ((!observer.isDone()) || (waitTime > MAX_WAIT_TIME)) {
|
|
||||||
observer.wait(WAIT_TIME_INCR);
|
|
||||||
waitTime += WAIT_TIME_INCR;
|
|
||||||
}
|
|
||||||
if (!observer.isDone()) {
|
|
||||||
throw new Exception("Timed out waiting for PackageStatsObserver.onGetStatsCompleted");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.d(TAG, "toString " + observer.stats.toString());
|
|
||||||
return observer.stats.dataSize + observer.stats.cacheSize;
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.w(TAG, "Failed to get handle for PackageManger Exception: " + e);
|
|
||||||
return -1;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Log.w(TAG, "InterruptedException :" + e);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除应用数据
|
* 清除应用数据
|
||||||
*
|
*
|
||||||
@@ -92,10 +51,6 @@ public class CacheUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IPackageManager getPm() {
|
|
||||||
return IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
|
|
||||||
}
|
|
||||||
|
|
||||||
class PackageDataObserver extends IPackageDataObserver.Stub {
|
class PackageDataObserver extends IPackageDataObserver.Stub {
|
||||||
public boolean retValue = false;
|
public boolean retValue = false;
|
||||||
private boolean doneFlag = false;
|
private boolean doneFlag = false;
|
||||||
@@ -114,25 +69,6 @@ public class CacheUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PackageStatsObserver extends IPackageStatsObserver.Stub {
|
|
||||||
public boolean retValue = false;
|
|
||||||
public PackageStats stats;
|
|
||||||
private boolean doneFlag = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) throws RemoteException {
|
|
||||||
synchronized (this) {
|
|
||||||
retValue = succeeded;
|
|
||||||
stats = pStats;
|
|
||||||
doneFlag = true;
|
|
||||||
notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDone() {
|
|
||||||
return doneFlag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
package com.fuying.sn.utils;
|
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.app.usage.UsageStats;
|
|
||||||
import android.app.usage.UsageStatsManager;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ForegroundAppUtil {
|
|
||||||
|
|
||||||
private static final long END_TIME = System.currentTimeMillis();
|
|
||||||
private static final long TIME_INTERVAL = 7 * 24 * 60 * 60 * 1000L;
|
|
||||||
private static final long START_TIME = END_TIME - TIME_INTERVAL;
|
|
||||||
|
|
||||||
|
|
||||||
public static String getForegroundPackageName(Context context) {
|
|
||||||
//系统应用可以直接获取
|
|
||||||
ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
List<ActivityManager.RunningTaskInfo> runningTaskInfos = mActivityManager.getRunningTasks(1);
|
|
||||||
return runningTaskInfos.get(0).topActivity.getPackageName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取栈顶的应用包名
|
|
||||||
*/
|
|
||||||
public static String getForegroundActivityName(Context context) {
|
|
||||||
String currentClassName = "";
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
ActivityManager manager = (ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
currentClassName = manager.getRunningTasks(1).get(0).topActivity.getPackageName();
|
|
||||||
} else {
|
|
||||||
UsageStats initStat = getForegroundUsageStats(context, START_TIME, END_TIME);
|
|
||||||
if (initStat != null) {
|
|
||||||
currentClassName = initStat.getPackageName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return currentClassName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断当前应用是否在前台
|
|
||||||
*/
|
|
||||||
public static boolean isForegroundApp(Context context) {
|
|
||||||
return TextUtils.equals(getForegroundActivityName(context), context.getPackageName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取时间段内,
|
|
||||||
*/
|
|
||||||
public static long getTotleForegroundTime(Context context) {
|
|
||||||
UsageStats usageStats = getCurrentUsageStats(context, START_TIME, END_TIME);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
return usageStats != null ? usageStats.getTotalTimeInForeground() : 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取记录前台应用的UsageStats对象
|
|
||||||
*/
|
|
||||||
private static UsageStats getForegroundUsageStats(Context context, long startTime, long endTime) {
|
|
||||||
UsageStats usageStatsResult = null;
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
List<UsageStats> usageStatses = getUsageStatsList(context, startTime, endTime);
|
|
||||||
if (usageStatses == null || usageStatses.isEmpty()) return null;
|
|
||||||
for (UsageStats usageStats : usageStatses) {
|
|
||||||
if (usageStatsResult == null || usageStatsResult.getLastTimeUsed() < usageStats.getLastTimeUsed()) {
|
|
||||||
usageStatsResult = usageStats;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return usageStatsResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取记录当前应用的UsageStats对象
|
|
||||||
*/
|
|
||||||
public static UsageStats getCurrentUsageStats(Context context, long startTime, long endTime) {
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
List<UsageStats> usageStatses = getUsageStatsList(context, startTime, endTime);
|
|
||||||
if (usageStatses == null || usageStatses.isEmpty()) return null;
|
|
||||||
for (UsageStats usageStats : usageStatses) {
|
|
||||||
if (TextUtils.equals(usageStats.getPackageName(), context.getPackageName())) {
|
|
||||||
return usageStats;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过UsageStatsManager获取List<UsageStats>集合
|
|
||||||
*/
|
|
||||||
public static List<UsageStats> getUsageStatsList(Context context, long startTime, long endTime) {
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
UsageStatsManager manager = (UsageStatsManager) context.getApplicationContext().getSystemService(Context.USAGE_STATS_SERVICE);
|
|
||||||
//UsageStatsManager.INTERVAL_WEEKLY,UsageStatsManager的参数定义了5个,具体查阅源码
|
|
||||||
List<UsageStats> usageStatses = manager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, startTime, endTime);
|
|
||||||
if (usageStatses == null || usageStatses.size() == 0) {// 没有权限,获取不到数据
|
|
||||||
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
context.getApplicationContext().startActivity(intent);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return usageStatses;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +1,12 @@
|
|||||||
package com.fuying.sn.utils;
|
package com.fuying.sn.utils;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
|
||||||
import com.bumptech.glide.request.RequestOptions;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Glide 加载 简单判空封装 防止异步加载数据时调用Glide 抛出异常
|
* Glide 加载 简单判空封装 防止异步加载数据时调用Glide 抛出异常
|
||||||
@@ -57,96 +48,4 @@ public class GlideLoadUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void glideLoadRound(Context context, String url, ImageView imageView, int defaultImage) {
|
|
||||||
if (context != null) {
|
|
||||||
Glide.with(context).load(url).centerCrop().error(defaultImage)
|
|
||||||
.placeholder(imageView.getDrawable()).dontAnimate()
|
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCorners(ScreenUtils.dp2px(context, 16f))))
|
|
||||||
.into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,context is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void glideLoad(Context context, int resId, ImageView imageView, int defaultImage) {
|
|
||||||
if (context != null) {
|
|
||||||
Glide.with(context).load(resId).centerCrop().placeholder(imageView.getDrawable()).error(defaultImage).into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,context is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void glideLoad(Context context, String url, ImageView imageView) {
|
|
||||||
if (context != null) {
|
|
||||||
Glide.with(context).load(url).centerCrop().dontAnimate().placeholder(imageView.getDrawable()).into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,context is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void glideLoad(Context context, Bitmap bitmap, ImageView imageView) {
|
|
||||||
if (context != null) {
|
|
||||||
Glide.with(context).load(bitmap).centerCrop().dontAnimate().placeholder(imageView.getDrawable()).into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,context is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void glideLoad(Context context, Drawable drawable, ImageView imageView) {
|
|
||||||
if (context != null) {
|
|
||||||
Glide.with(context).load(drawable).centerCrop().dontAnimate().placeholder(imageView.getDrawable()).into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,context is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void glideLoad(Context context, Drawable drawable, ImageView imageView,int resId) {
|
|
||||||
if (context != null) {
|
|
||||||
Glide.with(context).load(drawable).centerCrop().dontAnimate().placeholder(imageView.getDrawable()).error(resId).into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,context is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void glideLoad(Context context, File file, ImageView imageView) {
|
|
||||||
if (context != null) {
|
|
||||||
Glide.with(context).load(file).centerCrop().into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,context is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void glideLoad(Context context, File file, ImageView imageView, int defaultRes) {
|
|
||||||
if (context != null) {
|
|
||||||
Glide.with(context).load(file).centerCrop().error(defaultRes).into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,context is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
|
||||||
public void glideLoad(Activity activity, String url, ImageView imageView, int default_image) {
|
|
||||||
if (!activity.isDestroyed()) {
|
|
||||||
Glide.with(activity).load(url).centerCrop().error(default_image).placeholder(imageView.getDrawable()).into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,activity is Destroyed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void glideLoad(Fragment fragment, String url, ImageView imageView, int default_image) {
|
|
||||||
if (fragment != null && fragment.getActivity() != null) {
|
|
||||||
Glide.with(fragment).load(url).centerCrop().error(default_image).into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,fragment is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void glideLoad(android.app.Fragment fragment, String url, ImageView imageView, int default_image) {
|
|
||||||
if (fragment != null && fragment.getActivity() != null) {
|
|
||||||
Glide.with(fragment).load(url).centerCrop().error(default_image).into(imageView);
|
|
||||||
} else {
|
|
||||||
Log.i(TAG, "Picture loading failed,android.app.Fragment is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,35 +1,23 @@
|
|||||||
package com.fuying.sn.utils;
|
package com.fuying.sn.utils;
|
||||||
|
|
||||||
import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.ActivityManagerNative;
|
|
||||||
import android.app.ActivityTaskManager;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.role.RoleManager;
|
import android.app.role.RoleManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.UserInfo;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.media.AudioManager;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.BatteryManager;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
@@ -40,11 +28,9 @@ import android.view.inputmethod.InputMethodManager;
|
|||||||
|
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import com.android.internal.view.RotationPolicy;
|
|
||||||
import com.arialyy.aria.core.Aria;
|
import com.arialyy.aria.core.Aria;
|
||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.download.DownloadEntity;
|
||||||
import com.fuying.sn.BuildConfig;
|
import com.fuying.sn.BuildConfig;
|
||||||
import com.fuying.sn.R;
|
|
||||||
import com.fuying.sn.config.CommonConfig;
|
import com.fuying.sn.config.CommonConfig;
|
||||||
import com.fuying.sn.gson.GsonUtils;
|
import com.fuying.sn.gson.GsonUtils;
|
||||||
import com.fuying.sn.receiver.BootReceiver;
|
import com.fuying.sn.receiver.BootReceiver;
|
||||||
@@ -254,84 +240,6 @@ public class JgyUtils {
|
|||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAuthorization() {
|
|
||||||
return "Basic ZWRmOWNlYzIyNzMxYjhiMmZlZDU2ZWU2OmIzYWRlZDRmODk5N2E0ODM5ZTI5MjRjYg==";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isOfficialVersion() {
|
|
||||||
String channelValue = JgyUtils.getInstance().getStringMetaData();
|
|
||||||
return "official".equals(channelValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNewlyVersion() {
|
|
||||||
String channelValue = JgyUtils.getInstance().getStringMetaData();
|
|
||||||
return "beta".equals(channelValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isBetaVersion() {
|
|
||||||
String channelValue = JgyUtils.getInstance().getStringMetaData();
|
|
||||||
return "beta".equals(channelValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从Manifest中获取meta-data值
|
|
||||||
* https://blog.csdn.net/yue_233/article/details/91453451
|
|
||||||
*
|
|
||||||
* @return 清单中配置的元数据
|
|
||||||
*/
|
|
||||||
public String getStringMetaData() {
|
|
||||||
ApplicationInfo appInfo = null;
|
|
||||||
try {
|
|
||||||
appInfo = mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
String value = appInfo.metaData.getString("CHANNEL_VALUE");
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getBatteryLevel() {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
BatteryManager batteryManager = (BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE);
|
|
||||||
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
|
||||||
} else {
|
|
||||||
Intent intent = new ContextWrapper(mContext).registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
|
||||||
return (intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100) /
|
|
||||||
intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private PowerManager.WakeLock wakeLock = null;
|
|
||||||
private static final String mWakeLockName = "BackupService";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取电源锁,保持该服务在屏幕熄灭时仍然获取CPU时,保持运行
|
|
||||||
*/
|
|
||||||
@SuppressLint("InvalidWakeLockTag")
|
|
||||||
private synchronized void acquireWakeLock() {
|
|
||||||
if (null == wakeLock) {
|
|
||||||
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
|
||||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
|
|
||||||
| PowerManager.ON_AFTER_RELEASE, mWakeLockName);
|
|
||||||
if (null != wakeLock) {
|
|
||||||
Log.e("fht", "acquireWakeLock!");
|
|
||||||
wakeLock.acquire();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 释放设备电源锁
|
|
||||||
*/
|
|
||||||
private synchronized void releaseWakeLock() {
|
|
||||||
if (null != wakeLock) {
|
|
||||||
Log.e("fht", "releaseWakeLock!");
|
|
||||||
wakeLock.release();
|
|
||||||
wakeLock = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDownLoadPath() {
|
public String getDownLoadPath() {
|
||||||
String path = ContextCompat.getExternalFilesDirs(mContext, Environment.DIRECTORY_DOWNLOADS)[0].getAbsolutePath();
|
String path = ContextCompat.getExternalFilesDirs(mContext, Environment.DIRECTORY_DOWNLOADS)[0].getAbsolutePath();
|
||||||
@@ -381,20 +289,6 @@ public class JgyUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendAllweb() {
|
|
||||||
Intent intent = new Intent("qch_app_website")
|
|
||||||
.setPackage("com.android.settings");
|
|
||||||
intent.putExtra("package_name", "");
|
|
||||||
mContext.sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendwebUrl() {
|
|
||||||
Intent intent = new Intent("qch_app_inside_website")
|
|
||||||
.setPackage("com.android.settings");
|
|
||||||
intent.putExtra("websitelist", "");
|
|
||||||
mContext.sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统应用hook使用webview
|
* 系统应用hook使用webview
|
||||||
*/
|
*/
|
||||||
@@ -455,25 +349,6 @@ public class JgyUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 忽略电池优化
|
|
||||||
*/
|
|
||||||
private void ignoreBatteryOptimization() {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
|
||||||
|
|
||||||
boolean hasIgnored = powerManager.isIgnoringBatteryOptimizations(mContext.getPackageName());
|
|
||||||
// 判断当前APP是否有加入电池优化的白名单,如果没有,弹出加入电池优化的白名单的设置对话框。
|
|
||||||
if (!hasIgnored) {
|
|
||||||
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
||||||
intent.setData(Uri.parse("package:" + mContext.getPackageName()));
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
mContext.startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void killPackage(String pkg) {
|
public void killPackage(String pkg) {
|
||||||
Log.e(TAG, "killPackage: " + pkg);
|
Log.e(TAG, "killPackage: " + pkg);
|
||||||
ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
@@ -481,31 +356,6 @@ public class JgyUtils {
|
|||||||
CmdUtil.execute("am force-stop " + pkg);
|
CmdUtil.execute("am force-stop " + pkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void KillOTA() {
|
|
||||||
ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
manager.killBackgroundProcesses("com.adups.fota");
|
|
||||||
CmdUtil.execute("am force-stop " + "com.adups.fota");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openOTA() {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
/**知道要跳转应用的包命与目标Activity*/
|
|
||||||
ComponentName componentName = new ComponentName("com.adups.fota", "com.adups.fota.GoogleOtaClient");
|
|
||||||
intent.setComponent(componentName);
|
|
||||||
mContext.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openLauncher() {
|
|
||||||
Log.e(TAG, "openLauncher: ");
|
|
||||||
killPackage("com.android.launcher3");
|
|
||||||
Intent intent = new Intent();
|
|
||||||
// 为Intent设置Action、Category属性
|
|
||||||
intent.setAction(Intent.ACTION_MAIN);// "android.intent.action.MAIN"
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
intent.addCategory(Intent.CATEGORY_HOME); //"android.intent.category.HOME"
|
|
||||||
mContext.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cleanLauncherCache() {
|
public void cleanLauncherCache() {
|
||||||
Log.e(TAG, "cleanLauncherCache: Start");
|
Log.e(TAG, "cleanLauncherCache: Start");
|
||||||
int cleaned = (int) SPUtils.get(mContext, "fristcleanLauncherCache", 0);
|
int cleaned = (int) SPUtils.get(mContext, "fristcleanLauncherCache", 0);
|
||||||
@@ -521,18 +371,6 @@ public class JgyUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int checkSNPlatform(String sn) {
|
|
||||||
String secondChars = sn.substring(1, 2);
|
|
||||||
if ("N".equalsIgnoreCase(secondChars)) {//MTK平台
|
|
||||||
return MTKPlatform;
|
|
||||||
} else if ("R".equalsIgnoreCase(secondChars)) {//展锐平台
|
|
||||||
return ZhanruiPlatform;
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "checkSNPlatform: " + "sn: " + sn + "没有对应平台");
|
|
||||||
return UnknowPlatform;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int checkAppPlatform() {
|
public int checkAppPlatform() {
|
||||||
String platform = BuildConfig.platform;
|
String platform = BuildConfig.platform;
|
||||||
if ("MTK".equalsIgnoreCase(platform)) {
|
if ("MTK".equalsIgnoreCase(platform)) {
|
||||||
@@ -571,15 +409,6 @@ public class JgyUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSamePlatform(String platform) {
|
|
||||||
String AppPlatform = BuildConfig.platform;
|
|
||||||
if ("ZhanRui".equals(AppPlatform)) {
|
|
||||||
return ZhanruiTag.equals(platform);
|
|
||||||
} else {
|
|
||||||
return AppPlatform.equals(platform);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface GetAppPlatformCallback {
|
public interface GetAppPlatformCallback {
|
||||||
void AppPlatform(int platform);
|
void AppPlatform(int platform);
|
||||||
}
|
}
|
||||||
@@ -681,47 +510,6 @@ public class JgyUtils {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除所有最近记录
|
|
||||||
*/
|
|
||||||
public void removeAllTask() {
|
|
||||||
List<ActivityManager.RecentTaskInfo> list = getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), getCurrentUserId());
|
|
||||||
|
|
||||||
for (ActivityManager.RecentTaskInfo info : list) {
|
|
||||||
if (info.realActivity != null) {
|
|
||||||
Log.e(TAG, "removeAllTask: " + info.realActivity.getPackageName());
|
|
||||||
//排除自身
|
|
||||||
if (BuildConfig.APPLICATION_ID.equals(info.realActivity.getPackageName())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ActivityManagerNative.getDefault().removeTask(info.id);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.e(TAG, "removeAllTask: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeTask(String packageName) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
List<ActivityManager.RecentTaskInfo> list = getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), getCurrentUserId());
|
|
||||||
HashMap<String, Integer> taskMap = new HashMap<>();
|
|
||||||
for (ActivityManager.RecentTaskInfo info : list) {
|
|
||||||
taskMap.put(info.realActivity.getPackageName(), info.id);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ActivityManagerNative.getDefault().removeTask(taskMap.get(packageName));
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.e(TAG, "removeTask: " + e.getMessage());
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
Log.e(TAG, "removeTask: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 强行返回主桌面,优化跳转逻辑以确保回到系统默认桌面。
|
* 强行返回主桌面,优化跳转逻辑以确保回到系统默认桌面。
|
||||||
*/
|
*/
|
||||||
@@ -750,34 +538,6 @@ public class JgyUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return 最近任务列表
|
|
||||||
* 获取近期任务列表
|
|
||||||
*/
|
|
||||||
public List<ActivityManager.RecentTaskInfo> getRecentTasks(int numTasks, int userId) {
|
|
||||||
try {
|
|
||||||
return ActivityTaskManager.getService().getRecentTasks(numTasks,
|
|
||||||
RECENT_IGNORE_UNAVAILABLE, userId).getList();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Failed to get recent tasks", e);
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return 当前系统用户的编号
|
|
||||||
* 获取userId
|
|
||||||
*/
|
|
||||||
public int getCurrentUserId() {
|
|
||||||
UserInfo ui;
|
|
||||||
try {
|
|
||||||
ui = ActivityManager.getService().getCurrentUser();
|
|
||||||
return ui != null ? ui.id : 0;
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw e.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int isWifiConnect() {
|
public int isWifiConnect() {
|
||||||
// 网络管理对象
|
// 网络管理对象
|
||||||
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
@@ -815,22 +575,6 @@ public class JgyUtils {
|
|||||||
// return Settings.System.putString(cr, name, value);
|
// return Settings.System.putString(cr, name, value);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前进程名
|
|
||||||
*/
|
|
||||||
public String getCurrentProcessName() {
|
|
||||||
int pid = android.os.Process.myPid();
|
|
||||||
String processName = "";
|
|
||||||
ActivityManager manager = (ActivityManager) mContext.getSystemService
|
|
||||||
(Context.ACTIVITY_SERVICE);
|
|
||||||
for (ActivityManager.RunningAppProcessInfo process : manager.getRunningAppProcesses()) {
|
|
||||||
if (process.pid == pid) {
|
|
||||||
processName = process.processName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return processName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String Launcher3 = "com.android.launcher3";
|
private String Launcher3 = "com.android.launcher3";
|
||||||
private String Launcher3Class = "com.android.launcher3.Launcher";
|
private String Launcher3Class = "com.android.launcher3.Launcher";
|
||||||
|
|
||||||
@@ -910,14 +654,6 @@ public class JgyUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkDefaultDesktop(String pkg) {
|
|
||||||
String desktopPkg = (String) SPUtils.get(mContext, "default_launcher", "");
|
|
||||||
Log.e(TAG, "checkDefaultDesktop: " + desktopPkg);
|
|
||||||
if (desktopPkg.equalsIgnoreCase(pkg)) {
|
|
||||||
setDefaultDesktop(pkg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//设置默认桌面
|
//设置默认桌面
|
||||||
public void setDefaultDesktop(String pkg) {
|
public void setDefaultDesktop(String pkg) {
|
||||||
Log.e(TAG, "setDefaultDesktop: " + pkg);
|
Log.e(TAG, "setDefaultDesktop: " + pkg);
|
||||||
@@ -1068,142 +804,12 @@ public class JgyUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//删除用户除了在应用市场的其他应用
|
//删除用户除了在应用市场的其他应用
|
||||||
public void deleteOtherApp() {
|
|
||||||
int locked = Settings.System.getInt(resolver, "qch_unlock_ipad", 0);
|
|
||||||
if (locked == 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Log.e(TAG, "deleteOtherApp: " + "start");
|
|
||||||
//获取后台应用白名单
|
|
||||||
String only_jgy_shortcut_list = Settings.System.getString(resolver, CommonConfig.ONLY_SHORTCUT_LIST);
|
|
||||||
if (only_jgy_shortcut_list == null) {
|
|
||||||
only_jgy_shortcut_list = "";
|
|
||||||
}
|
|
||||||
//获取可以被安装的包名
|
|
||||||
String aole_app_forbid = Settings.System.getString(resolver, CommonConfig.AOLE_ACTION_APP_FORBID);
|
|
||||||
if (aole_app_forbid == null) {
|
|
||||||
aole_app_forbid = "";
|
|
||||||
}
|
|
||||||
Log.e("deleteOtherApp", "only_jgy_shortcut_list: " + only_jgy_shortcut_list);
|
|
||||||
Log.e("deleteOtherApp", "aole_app_forbid: " + aole_app_forbid);
|
|
||||||
String[] result_white = only_jgy_shortcut_list.split(",");
|
|
||||||
String[] result_forbid = aole_app_forbid.split(",");
|
|
||||||
List<String> resulWhitetList = new ArrayList<>(Arrays.asList(result_white));
|
|
||||||
List<String> resulForbidtList = new ArrayList<>(Arrays.asList(result_forbid));
|
|
||||||
resulWhitetList.addAll(resulForbidtList);
|
|
||||||
HashSet<String> allWhitePkg = new HashSet<>(resulWhitetList);
|
|
||||||
List<String> installedPackageList = ApkUtils.queryFilterAppInfo(mContext);
|
|
||||||
|
|
||||||
Log.e("deleteOtherApp", "installedPackageList:" + installedPackageList.toString());
|
|
||||||
if (allWhitePkg.size() > 0) {
|
|
||||||
for (final String packageName : installedPackageList) {
|
|
||||||
if (ApkUtils.isSystemApp(mContext, packageName)) {
|
|
||||||
Log.e("deleteOtherApp", "is systemApp:" + packageName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// if (ApkUtils.desktopAPP.contains(packageName)) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// if (ApkUtils.canremove_systemapp.contains(packageName)) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
if (ownApp.contains(packageName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (fuxiaoyingApp.contains(packageName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!allWhitePkg.contains(packageName)) {
|
|
||||||
ApkUtils.uninstallApp(mContext, packageName);
|
|
||||||
Log.e("deleteOtherApp", "uninstall apkName:" + packageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.e(TAG, "deleteOtherApp: " + "end");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isScreenOn() {
|
public boolean isScreenOn() {
|
||||||
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||||
//true为打开,false为关闭
|
//true为打开,false为关闭
|
||||||
return powerManager.isInteractive();
|
return powerManager.isInteractive();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int zenModOn = Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
|
|
||||||
private int zenModOff = Settings.Global.ZEN_MODE_OFF;
|
|
||||||
private String ZENNODETAG = "ZenModeSettingsBackend";
|
|
||||||
|
|
||||||
public void setZenMode(String extras) {
|
|
||||||
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
|
|
||||||
int setting_disturbance = jsonObject.get("setting_disturbance").getAsInt();
|
|
||||||
NotificationManager.from(mContext).setZenMode(setting_disturbance, null, ZENNODETAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRotationLock(String extras) {
|
|
||||||
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
|
|
||||||
int setting_rotation = jsonObject.get("setting_rotation").getAsInt();
|
|
||||||
RotationPolicy.setRotationLock(mContext, setting_rotation == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScreenBrightness(String extras) {
|
|
||||||
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
|
|
||||||
int setting_luminance = jsonObject.get("setting_luminance").getAsInt();
|
|
||||||
Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
|
||||||
int Scrern_brightness = (int) ((1.0 * 255 / 100) * setting_luminance);
|
|
||||||
Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, Scrern_brightness);
|
|
||||||
}
|
|
||||||
|
|
||||||
private float[] mValues;
|
|
||||||
/**
|
|
||||||
* 当前设置值在候选列表中的索引。
|
|
||||||
*/
|
|
||||||
protected int mCurrentIndex;
|
|
||||||
/**
|
|
||||||
* 设置项对应的候选文本列表。
|
|
||||||
*/
|
|
||||||
protected List<String> mEntries;
|
|
||||||
|
|
||||||
public void setFontSize(String extras) {
|
|
||||||
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
|
|
||||||
String setting_typeface = jsonObject.get("setting_typeface").getAsString();
|
|
||||||
final Resources res = mContext.getResources();
|
|
||||||
mEntries = Arrays.asList(res.getStringArray(R.array.entries_font_size));
|
|
||||||
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
|
|
||||||
mValues = new float[strEntryValues.length];
|
|
||||||
for (int i = 0; i < strEntryValues.length; ++i) {
|
|
||||||
mValues[i] = Float.parseFloat(strEntryValues[i]);
|
|
||||||
}
|
|
||||||
mCurrentIndex = mEntries.indexOf(setting_typeface);
|
|
||||||
if (mCurrentIndex == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Settings.System.putFloat(resolver, Settings.System.FONT_SCALE, mValues[mCurrentIndex]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVolume(String extras) {
|
|
||||||
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
|
|
||||||
int setting_volume = jsonObject.get("setting_volume").getAsInt();
|
|
||||||
//获取系统的Audio管理者
|
|
||||||
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
|
|
||||||
//最大音量
|
|
||||||
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
|
||||||
//当前音量
|
|
||||||
// int currentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
|
||||||
int currentVolume = (int) ((1.0f * maxVolume / 100) * setting_volume);
|
|
||||||
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setDefaultLauncher(String pkg) {
|
|
||||||
Intent intent = new Intent("setDefaultLauncher");
|
|
||||||
intent.putExtra("package", "com.uiui.os");
|
|
||||||
intent.putExtra("className", "com.uiui.os.Launcher");
|
|
||||||
intent.setPackage("com.android.settings");
|
|
||||||
mContext.sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getLauncherClassName(String pkg) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInputMethodId(String pkg) {
|
public String getInputMethodId(String pkg) {
|
||||||
InputMethodManager imeManager = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imeManager = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
@@ -1257,13 +863,6 @@ public class JgyUtils {
|
|||||||
public static final String CLASS_APPSTORE = "com.fuying.appstore.receiver.BootReceiver";
|
public static final String CLASS_APPSTORE = "com.fuying.appstore.receiver.BootReceiver";
|
||||||
public static final String CLASS_UPDATETOOLS = "com.uiui.updatetools.receiver.BootReceiver";
|
public static final String CLASS_UPDATETOOLS = "com.uiui.updatetools.receiver.BootReceiver";
|
||||||
|
|
||||||
public void wakeUpDeviceInfo() {
|
|
||||||
//启动设备信息
|
|
||||||
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
|
|
||||||
bootIntent.setComponent(new ComponentName(PACKAGE_DEVICEINFO, CLASS_DEVICEINFO));
|
|
||||||
mContext.sendBroadcast(bootIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void wakeUpAppstore() {
|
public void wakeUpAppstore() {
|
||||||
//启动应用市场
|
//启动应用市场
|
||||||
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
|
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
|
||||||
@@ -1278,25 +877,6 @@ public class JgyUtils {
|
|||||||
mContext.sendBroadcast(bootIntent);
|
mContext.sendBroadcast(bootIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断网络连接状态
|
|
||||||
*
|
|
||||||
* @return true:网络已链接, false:网络已断开连接
|
|
||||||
*/
|
|
||||||
public boolean isNetworkConnected() {
|
|
||||||
if (mContext != null) {
|
|
||||||
ConnectivityManager mConnectivityManager = (ConnectivityManager) mContext
|
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
NetworkInfo mNetworkInfo = mConnectivityManager
|
|
||||||
.getActiveNetworkInfo();
|
|
||||||
if (mNetworkInfo != null) {
|
|
||||||
return mNetworkInfo.isAvailable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getIMEI() {
|
public String getIMEI() {
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
// return "861918053899168";
|
// return "861918053899168";
|
||||||
|
|||||||
@@ -8,36 +8,6 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
|
|
||||||
public class MD5Util {
|
public class MD5Util {
|
||||||
|
|
||||||
public static String packetMD5(String str) {
|
|
||||||
MessageDigest messageDigest = null;
|
|
||||||
try {
|
|
||||||
messageDigest = MessageDigest.getInstance("MD5");
|
|
||||||
|
|
||||||
messageDigest.reset();
|
|
||||||
|
|
||||||
messageDigest.update(str.getBytes("UTF-8"));
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
System.out.println("NoSuchAlgorithmException caught!");
|
|
||||||
System.exit(-1);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] byteArray = messageDigest.digest();
|
|
||||||
|
|
||||||
StringBuffer md5StrBuff = new StringBuffer();
|
|
||||||
|
|
||||||
for (int i = 0; i < byteArray.length; i++) {
|
|
||||||
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
|
|
||||||
md5StrBuff.append("0").append(
|
|
||||||
Integer.toHexString(0xFF & byteArray[i]));
|
|
||||||
else
|
|
||||||
md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return md5StrBuff.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
public static String getUpperMD5Str(String str) {
|
public static String getUpperMD5Str(String str) {
|
||||||
MessageDigest messageDigest = null;
|
MessageDigest messageDigest = null;
|
||||||
@@ -71,42 +41,4 @@ public class MD5Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取16位的MD5 值得
|
|
||||||
*
|
|
||||||
* @param str
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SuppressLint("DefaultLocale")
|
|
||||||
public static String getUpperMD5Str16(String str) {
|
|
||||||
MessageDigest messageDigest = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
messageDigest = MessageDigest.getInstance("MD5");
|
|
||||||
|
|
||||||
messageDigest.reset();
|
|
||||||
|
|
||||||
messageDigest.update(str.getBytes("UTF-8"));
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
System.out.println("NoSuchAlgorithmException caught!");
|
|
||||||
System.exit(-1);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] byteArray = messageDigest.digest();
|
|
||||||
|
|
||||||
StringBuffer md5StrBuff = new StringBuffer();
|
|
||||||
|
|
||||||
for (int i = 0; i < byteArray.length; i++) {
|
|
||||||
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
|
|
||||||
md5StrBuff.append("0").append(
|
|
||||||
Integer.toHexString(0xFF & byteArray[i]));
|
|
||||||
else
|
|
||||||
md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return md5StrBuff.toString().toUpperCase().substring(8, 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -25,60 +25,4 @@ public class NetStateUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断wifi状态
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @return true:是wifi情况 ,false:非wifi情况
|
|
||||||
*/
|
|
||||||
public static boolean isWifiConnected(Context context) {
|
|
||||||
if (context != null) {
|
|
||||||
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
|
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
NetworkInfo mWiFiNetworkInfo = mConnectivityManager
|
|
||||||
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
|
||||||
if (mWiFiNetworkInfo != null) {
|
|
||||||
return mWiFiNetworkInfo.isAvailable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断移动网络
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @return true:是移动网络情况, false:非移动网络情况
|
|
||||||
*/
|
|
||||||
public static boolean isMobileConnected(Context context) {
|
|
||||||
if (context != null) {
|
|
||||||
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
|
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
NetworkInfo mMobileNetworkInfo = mConnectivityManager
|
|
||||||
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
|
||||||
if (mMobileNetworkInfo != null) {
|
|
||||||
return mMobileNetworkInfo.isAvailable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取连接类型
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static int getConnectedType(Context context) {
|
|
||||||
if (context != null) {
|
|
||||||
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
|
|
||||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
NetworkInfo mNetworkInfo = mConnectivityManager
|
|
||||||
.getActiveNetworkInfo();
|
|
||||||
if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
|
|
||||||
return mNetworkInfo.getType();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
package com.fuying.sn.utils;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 动态注册广播兼容工具。
|
|
||||||
*
|
|
||||||
* <p>Android 13(API 33)起,动态注册的接收器若包含非系统保护广播,必须显式声明导出标志;
|
|
||||||
* Android 14+ 的系统(含各厂商定制 ROM,例如本机 Android 16)会强制校验,缺失时直接抛出:
|
|
||||||
* <pre>
|
|
||||||
* java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED
|
|
||||||
* should be specified when a receiver isn't being registered exclusively for system broadcasts
|
|
||||||
* </pre>
|
|
||||||
* 该异常会导致 Activity / Service 创建失败(启动闪退),并进一步造成前台服务
|
|
||||||
* {@code startForegroundService()} 超时 ANR。
|
|
||||||
*
|
|
||||||
* <p>说明:本工程通过 {@code app/libs/framework.jar} 提供系统隐藏 API(该 jar 为
|
|
||||||
* Android 10 / API 29 的 framework),其中已包含
|
|
||||||
* {@code registerReceiver(BroadcastReceiver, IntentFilter, int)} 等带 flags 的重载,
|
|
||||||
* 因此这里直接调用即可,无需反射;在低版本系统中未知标志位会被忽略,
|
|
||||||
* 行为与改造前的两参注册保持一致。
|
|
||||||
*
|
|
||||||
* <p>标志选择建议:
|
|
||||||
* <ul>
|
|
||||||
* <li>{@link #RECEIVER_NOT_EXPORTED}:只接收系统广播,或本应用
|
|
||||||
* (含共享 {@code android.uid.system} 的兄弟应用)发送的广播;</li>
|
|
||||||
* <li>{@link #RECEIVER_EXPORTED}:需要接收其它(不同 UID 的)应用发送的广播,
|
|
||||||
* 与改造前两参 {@code registerReceiver} 的默认行为一致。</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @author LiGuangMin
|
|
||||||
*/
|
|
||||||
public final class ReceiverCompat {
|
|
||||||
|
|
||||||
private static final String TAG = "ReceiverCompat";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 对应 Context.RECEIVER_EXPORTED(API 33)。
|
|
||||||
*/
|
|
||||||
public static final int RECEIVER_EXPORTED = 0x00000002;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 对应 Context.RECEIVER_NOT_EXPORTED(API 33)。
|
|
||||||
*/
|
|
||||||
public static final int RECEIVER_NOT_EXPORTED = 0x00000004;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 带导出标志的注册重载从 API 33 开始对应用生效。
|
|
||||||
* 此处不使用 {@code Build.VERSION_CODES.TIRAMISU},因为 framework.jar 只到 API 29。
|
|
||||||
*/
|
|
||||||
private static final int FLAGS_API = 33;
|
|
||||||
|
|
||||||
private ReceiverCompat() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 兼容注册,等价于 {@code registerReceiver(receiver, filter)},
|
|
||||||
* 但在 API 33+ 上显式带上导出标志。
|
|
||||||
*/
|
|
||||||
public static Intent registerReceiver(Context context, BroadcastReceiver receiver,
|
|
||||||
IntentFilter filter, int flags) {
|
|
||||||
return registerReceiver(context, receiver, filter, flags, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 安全注销广播接收器。
|
|
||||||
*
|
|
||||||
* <p>系统自带的 {@code unregisterReceiver()} 在"接收器未注册过"或"重复注销"时会抛出
|
|
||||||
* {@code IllegalArgumentException: Receiver not registered},直接导致进程崩溃;
|
|
||||||
* 而业务代码通常只能用字段是否为 null 来判断,字段非 null 并不代表注册成功
|
|
||||||
* (例如注册过程中抛异常、Service 被销毁等场景)。这里统一做容错处理。
|
|
||||||
*
|
|
||||||
* @param receiver 允许为 null
|
|
||||||
*/
|
|
||||||
public static void unregisterReceiver(Context context, BroadcastReceiver receiver) {
|
|
||||||
if (context == null || receiver == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
context.unregisterReceiver(receiver);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "unregisterReceiver failed: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 兼容注册,等价于
|
|
||||||
* {@code registerReceiver(receiver, filter, broadcastPermission, scheduler)}。
|
|
||||||
*
|
|
||||||
* @param receiver 可以为 null,此时用于查询粘性广播
|
|
||||||
* @param flags {@link #RECEIVER_EXPORTED} 或 {@link #RECEIVER_NOT_EXPORTED}
|
|
||||||
* @param broadcastPermission 发送方必须持有的权限,可为 null
|
|
||||||
*/
|
|
||||||
public static Intent registerReceiver(Context context, BroadcastReceiver receiver,
|
|
||||||
IntentFilter filter, int flags,
|
|
||||||
String broadcastPermission) {
|
|
||||||
if (context == null || filter == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if (Build.VERSION.SDK_INT >= FLAGS_API) {
|
|
||||||
return context.registerReceiver(receiver, filter, broadcastPermission, null, flags);
|
|
||||||
}
|
|
||||||
//Android 13 以下不支持导出标志,保持原有注册方式
|
|
||||||
return context.registerReceiver(receiver, filter, broadcastPermission, null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
//兜底:极端情况下(例如厂商裁剪了重载)退回到传统注册,避免直接崩溃
|
|
||||||
Log.e(TAG, "registerReceiver failed, fallback to legacy: " + e);
|
|
||||||
try {
|
|
||||||
return context.registerReceiver(receiver, filter);
|
|
||||||
} catch (Exception inner) {
|
|
||||||
Log.e(TAG, "registerReceiver legacy failed: " + inner);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,15 +2,8 @@ package com.fuying.sn.utils;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.util.Base64;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -78,17 +71,6 @@ public class SPUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 移除某个key值已经对应的值
|
|
||||||
*/
|
|
||||||
public static void remove(Context context, String key) {
|
|
||||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
|
||||||
Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sp.edit();
|
|
||||||
editor.remove(key);
|
|
||||||
SharedPreferencesCompat.apply(editor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * 清除所有数据
|
// * 清除所有数据
|
||||||
// */
|
// */
|
||||||
@@ -107,15 +89,6 @@ public class SPUtils {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询某个key是否已经存在
|
|
||||||
*/
|
|
||||||
public static boolean contains(Context context, String key) {
|
|
||||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
|
||||||
Context.MODE_PRIVATE);
|
|
||||||
return sp.contains(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回所有的键值对
|
* 返回所有的键值对
|
||||||
*/
|
*/
|
||||||
@@ -126,43 +99,6 @@ public class SPUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存图片到SharedPreferences
|
|
||||||
*
|
|
||||||
* @param mContext
|
|
||||||
* @param imageView
|
|
||||||
*/
|
|
||||||
public static void putImage(Context mContext, String key, ImageView imageView) {
|
|
||||||
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
|
|
||||||
Bitmap bitmap = drawable.getBitmap();
|
|
||||||
// 将Bitmap压缩成字节数组输出流
|
|
||||||
ByteArrayOutputStream byStream = new ByteArrayOutputStream();
|
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 80, byStream);
|
|
||||||
// 利用Base64将我们的字节数组输出流转换成String
|
|
||||||
byte[] byteArray = byStream.toByteArray();
|
|
||||||
String imgString = new String(Base64.encodeToString(byteArray, Base64.DEFAULT));
|
|
||||||
// 将String保存shareUtils
|
|
||||||
SPUtils.put(mContext, key, imgString);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从SharedPreferences读取图片
|
|
||||||
*
|
|
||||||
* @param mContext
|
|
||||||
* @param imageView
|
|
||||||
*/
|
|
||||||
public static Bitmap getImage(Context mContext, String key, ImageView imageView) {
|
|
||||||
String imgString = (String) SPUtils.get(mContext, key, "");
|
|
||||||
if (!imgString.equals("")) {
|
|
||||||
// 利用Base64将我们string转换
|
|
||||||
byte[] byteArray = Base64.decode(imgString, Base64.DEFAULT);
|
|
||||||
ByteArrayInputStream byStream = new ByteArrayInputStream(byteArray);
|
|
||||||
// 生成bitmap
|
|
||||||
return BitmapFactory.decodeStream(byStream);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类
|
* 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,25 +9,9 @@ public class ScreenUtils {
|
|||||||
return (int) (dpValue * scale + 0.5f);
|
return (int) (dpValue * scale + 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int dp2px(Context context, final float dpValue) {
|
|
||||||
final float scale = context.getResources().getDisplayMetrics().density;
|
|
||||||
return (int) (dpValue * scale + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int px2dp(Context context, final float pxValue) {
|
|
||||||
final float scale = context.getResources().getDisplayMetrics().density;
|
|
||||||
return (int) (pxValue / scale + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static int sp2px(Context context, final float spValue) {
|
public static int sp2px(Context context, final float spValue) {
|
||||||
final float scale = context.getResources().getDisplayMetrics().scaledDensity;
|
final float scale = context.getResources().getDisplayMetrics().scaledDensity;
|
||||||
return (int) (spValue * scale + 0.5f);
|
return (int) (spValue * scale + 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int px2sp(Context context, final float pxValue) {
|
|
||||||
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
|
|
||||||
return (int) (pxValue / fontScale + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,10 @@ package com.fuying.sn.utils;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.DisplayMetrics;
|
|
||||||
import android.view.Display;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
@@ -22,12 +19,8 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class StatusBarUtil {
|
public class StatusBarUtil {
|
||||||
public static int screenWidth;
|
|
||||||
public static int screenHeight;
|
|
||||||
public static int navigationHeight = 0;
|
public static int navigationHeight = 0;
|
||||||
|
|
||||||
private static DisplayMetrics mMetrics;
|
|
||||||
public static final String HOME_CURRENT_TAB_POSITION = "HOME_CURRENT_TAB_POSITION";
|
|
||||||
|
|
||||||
public static final String SYS_EMUI = "sys_emui";
|
public static final String SYS_EMUI = "sys_emui";
|
||||||
public static final String SYS_MIUI = "sys_miui";
|
public static final String SYS_MIUI = "sys_miui";
|
||||||
@@ -67,43 +60,7 @@ public class StatusBarUtil {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取底部导航栏高度
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static int getNavigationBarHeight(Context context) {
|
|
||||||
Resources resources = context.getResources();
|
|
||||||
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
|
|
||||||
//获取NavigationBar的高度
|
|
||||||
navigationHeight = resources.getDimensionPixelSize(resourceId);
|
|
||||||
return navigationHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取是否存在NavigationBar
|
//获取是否存在NavigationBar
|
||||||
public static boolean checkDeviceHasNavigationBar(Context context) {
|
|
||||||
boolean hasNavigationBar = false;
|
|
||||||
Resources rs = context.getResources();
|
|
||||||
int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
|
|
||||||
if (id > 0) {
|
|
||||||
hasNavigationBar = rs.getBoolean(id);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
|
|
||||||
Method m = systemPropertiesClass.getMethod("get", String.class);
|
|
||||||
String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
|
|
||||||
if ("1".equals(navBarOverride)) {
|
|
||||||
hasNavigationBar = false;
|
|
||||||
} else if ("0".equals(navBarOverride)) {
|
|
||||||
hasNavigationBar = true;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
return hasNavigationBar;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param activity
|
* @param activity
|
||||||
* @param useThemestatusBarColor 是否要状态栏的颜色,不设置则为透明色
|
* @param useThemestatusBarColor 是否要状态栏的颜色,不设置则为透明色
|
||||||
@@ -129,20 +86,6 @@ public class StatusBarUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reMeasure(Activity activity) {
|
|
||||||
Display display = activity.getWindowManager().getDefaultDisplay();
|
|
||||||
mMetrics = new DisplayMetrics();
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 17) {
|
|
||||||
display.getRealMetrics(mMetrics);
|
|
||||||
} else {
|
|
||||||
display.getMetrics(mMetrics);
|
|
||||||
}
|
|
||||||
|
|
||||||
screenWidth = mMetrics.widthPixels;
|
|
||||||
screenHeight = mMetrics.heightPixels;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 改变魅族的状态栏字体为黑色,要求FlyMe4以上
|
* 改变魅族的状态栏字体为黑色,要求FlyMe4以上
|
||||||
*/
|
*/
|
||||||
@@ -259,24 +202,6 @@ public class StatusBarUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 作者:Loyea
|
|
||||||
* 链接:https://www.jianshu.com/p/abd021c22728
|
|
||||||
* 來源:简书
|
|
||||||
* 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
|
|
||||||
*/
|
|
||||||
public static void setAndroidNativeLightStatusBar(Activity activity, boolean dark) {
|
|
||||||
View decor = activity.getWindow().getDecorView();
|
|
||||||
if (dark) {
|
|
||||||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
|
||||||
} else {
|
|
||||||
// We want to change tint color to white again.
|
|
||||||
// You can also record the flags in advance so that you can turn UI back completely if
|
|
||||||
// you have set other flags before, such as translucent or full screen.
|
|
||||||
decor.setSystemUiVisibility(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getSystem() {
|
public static String getSystem() {
|
||||||
String SYS = "";
|
String SYS = "";
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
|
||||||
|
|||||||
@@ -3,82 +3,17 @@ package com.fuying.sn.utils;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.storage.StorageManager;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
|
|
||||||
public class StorageUtils {
|
public class StorageUtils {
|
||||||
|
|
||||||
|
|
||||||
// 获取存储空间 false 内置sd卡路径,true 外置sd卡路径
|
// 获取存储空间 false 内置sd卡路径,true 外置sd卡路径
|
||||||
public static File getStoragePath(Context mContext, boolean isSDcard) {
|
|
||||||
StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
|
|
||||||
Class<?> storageVolumeClazz = null;
|
|
||||||
try {
|
|
||||||
storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
|
|
||||||
Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
|
|
||||||
Method getPath = storageVolumeClazz.getMethod("getPath");
|
|
||||||
Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
|
|
||||||
Object result = getVolumeList.invoke(mStorageManager);
|
|
||||||
final int length = Array.getLength(result);
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
Object storageVolumeElement = Array.get(result, i);
|
|
||||||
String path = (String) getPath.invoke(storageVolumeElement);
|
|
||||||
boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);
|
|
||||||
if (isSDcard == removable) {
|
|
||||||
File file = new File(path);
|
|
||||||
if (file.exists()) {
|
|
||||||
return file;
|
|
||||||
}else {
|
|
||||||
if (!isSDcard) {
|
|
||||||
return Environment.getExternalStorageDirectory();
|
|
||||||
} else {
|
|
||||||
File file1 = new File("root/storage/sdcard1");
|
|
||||||
if (file1.exists()){
|
|
||||||
return file1;
|
|
||||||
}else {
|
|
||||||
File file2 = new File("storage/sdcard1");
|
|
||||||
if (file2.exists()){
|
|
||||||
return file2;
|
|
||||||
}else {
|
|
||||||
File file3 = new File("/storage/emulated/0");
|
|
||||||
if (file3.exists()){
|
|
||||||
return file3;
|
|
||||||
}else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String getFileCache(Context context, String s) {
|
public static String getFileCache(Context context, String s) {
|
||||||
return getExternalFilesDir(context, s).getAbsolutePath();
|
return getExternalFilesDir(context, s).getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFileRoot(Context context) {
|
|
||||||
return getExternalFilesDir(context, "Download").getAbsolutePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getExternalFilesDir(Context context, String s) {
|
public static File getExternalFilesDir(Context context, String s) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
|
||||||
File path = context.getExternalFilesDir(s);
|
File path = context.getExternalFilesDir(s);
|
||||||
@@ -91,34 +26,4 @@ public class StorageUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 检测文件是否存在
|
|
||||||
public static boolean isFileIsExists(String filePath){
|
|
||||||
try{
|
|
||||||
File f=new File(filePath);
|
|
||||||
if(!f.exists()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static String size(long size) {
|
|
||||||
if (size / (1024 * 1024) > 0) {
|
|
||||||
float tmpSize = (float) (size) / (float) (1024 * 1024 );
|
|
||||||
DecimalFormat df = new DecimalFormat("#.##");
|
|
||||||
return "" + df.format(tmpSize) + "GB";
|
|
||||||
} else if (size / 1024 > 0) {
|
|
||||||
float tmpSize = (float) (size) / (float) 1024 ;
|
|
||||||
DecimalFormat df = new DecimalFormat("#.##");
|
|
||||||
return "" + df.format(tmpSize) + "MB";
|
|
||||||
} else if (size > 0) {
|
|
||||||
return "" + (size ) + "KB";
|
|
||||||
} else {
|
|
||||||
return "" + (size) + "KB";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package com.fuying.sn.utils;
|
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import java.util.StringJoiner;
|
|
||||||
|
|
||||||
public class StringUtils {
|
|
||||||
public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
return String.join(delimiter, elements);
|
|
||||||
} else {
|
|
||||||
if (elements == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
StringJoiner joiner = new StringJoiner(delimiter);
|
|
||||||
for (CharSequence cs : elements) {
|
|
||||||
joiner.add(cs);
|
|
||||||
}
|
|
||||||
return joiner.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
package com.fuying.sn.utils;
|
package com.fuying.sn.utils;
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
|
||||||
|
|
||||||
import com.fuying.sn.bean.PartTime;
|
import com.fuying.sn.bean.PartTime;
|
||||||
import com.fuying.sn.data.model.AppControlDetail;
|
import com.fuying.sn.data.model.AppControlDetail;
|
||||||
|
|
||||||
@@ -14,15 +11,14 @@ import java.net.DatagramPacket;
|
|||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class TimeUtils {
|
public class TimeUtils {
|
||||||
private static final String TAG = "TimeUtils";
|
private static final String TAG = "TimeUtils";
|
||||||
@@ -33,16 +29,6 @@ public class TimeUtils {
|
|||||||
return sdf.format(date);
|
return sdf.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
||||||
public static boolean isTodayTime(long timeStamp) {
|
|
||||||
String time = transferLongToDate(timeStamp);
|
|
||||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
LocalDateTime localTime = LocalDateTime.parse(time, dtf);
|
|
||||||
LocalDateTime startTime = LocalDate.now().atTime(0, 0, 0);
|
|
||||||
LocalDateTime endTime = LocalDate.now().atTime(23, 59, 59);
|
|
||||||
return localTime.isAfter(startTime) && localTime.isBefore(endTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取格式化后的时间
|
* 获取格式化后的时间
|
||||||
*
|
*
|
||||||
@@ -183,10 +169,6 @@ public class TimeUtils {
|
|||||||
return weekDay > 5;
|
return weekDay > 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSystemTime(long time) {
|
|
||||||
SystemClock.setCurrentTimeMillis(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SntpClient mNtpClient;
|
private static SntpClient mNtpClient;
|
||||||
|
|
||||||
public static long getTimeFromNtpServer(String hostAddress) {
|
public static long getTimeFromNtpServer(String hostAddress) {
|
||||||
|
|||||||
@@ -35,12 +35,4 @@ public class ToastUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showCenter(final String msg) {
|
|
||||||
ToastUtils.make()
|
|
||||||
.setBgColor(ColorUtils.getColor(R.color.toast_color))
|
|
||||||
.setTextColor(Color.WHITE)
|
|
||||||
.setGravity(Gravity.CENTER, 0, 0)
|
|
||||||
.setNotUseSystemToast()
|
|
||||||
.show(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -162,44 +162,6 @@ public class URLUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashSet<String> blackList = new HashSet<>();
|
|
||||||
private HashSet<String> blackIPList = new HashSet<>();
|
|
||||||
|
|
||||||
public void setBrowserBlackList() {
|
|
||||||
String qch_webblack_url = Settings.System.getString(mContext.getContentResolver(), "qch_webblack_url");
|
|
||||||
Log.e(TAG, "setBrowserBlackList: qch_webblack_url = " + qch_webblack_url);
|
|
||||||
if (TextUtils.isEmpty(qch_webblack_url)) {
|
|
||||||
Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", "");
|
|
||||||
} else {
|
|
||||||
String black_ip = (String) SPUtils.get(mContext, "black_ip", "");
|
|
||||||
if (!TextUtils.isEmpty(black_ip)) {
|
|
||||||
blackIPList = new HashSet<>(Arrays.asList(black_ip.split(",")));
|
|
||||||
}
|
|
||||||
blackIPList.removeIf(TextUtils::isEmpty);
|
|
||||||
HashSet<String> URLList = new HashSet<>(Arrays.asList(qch_webblack_url.trim().split(",")));
|
|
||||||
for (String url : URLList) {
|
|
||||||
if (TextUtils.isEmpty(url)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Log.e(TAG, "setBrowserBlackList: url: " + url);
|
|
||||||
if (qch_webblack_url.startsWith("http://")) {
|
|
||||||
blackList.add(url);
|
|
||||||
blackList.add(url.replace("http://", "https://"));
|
|
||||||
} else if (qch_webblack_url.startsWith("https://")) {
|
|
||||||
blackList.add(url);
|
|
||||||
blackList.add(url.replace("https://", "http://"));
|
|
||||||
} else {
|
|
||||||
blackList.add("http://" + url);
|
|
||||||
blackList.add("https://" + url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
blackList.addAll(blackIPList);
|
|
||||||
blackList.removeIf(TextUtils::isEmpty);
|
|
||||||
Log.e(TAG, "setBrowserBlackList: blackList: " + blackList);
|
|
||||||
boolean write = Settings.System.putString(mContext.getContentResolver(), "qch_webblack_url", String.join(",", blackList));
|
|
||||||
Log.e(TAG, "setBrowserBlackList: write: " + write);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getOkHttpURL(String URL) {
|
private String getOkHttpURL(String URL) {
|
||||||
if (!URL.startsWith("http")) {
|
if (!URL.startsWith("http")) {
|
||||||
@@ -273,37 +235,6 @@ public class URLUtils {
|
|||||||
return m.find();
|
return m.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets ip.
|
|
||||||
* 通过url获取到域名
|
|
||||||
*
|
|
||||||
* @param url the url
|
|
||||||
* @return the ip
|
|
||||||
*/
|
|
||||||
public String getIP(String url) {
|
|
||||||
//使用正则表达式过滤,
|
|
||||||
String re = "((http|ftp|https)://)(([a-zA-Z0-9._-]+)|([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}))(([a-zA-Z]{2,6})|(:[0-9]{1,4})?)";
|
|
||||||
String str = "";
|
|
||||||
// 编译正则表达式
|
|
||||||
Pattern pattern = Pattern.compile(re);
|
|
||||||
// 忽略大小写的写法
|
|
||||||
// Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
|
|
||||||
Matcher matcher = pattern.matcher(url);
|
|
||||||
//若url==http://127.0.0.1:9040或www.baidu.com的,正则表达式表示匹配
|
|
||||||
if (matcher.matches()) {
|
|
||||||
str = url;
|
|
||||||
} else {
|
|
||||||
String[] split2 = url.split(re);
|
|
||||||
if (split2.length > 1) {
|
|
||||||
String substring = url.substring(0, url.length() - split2[1].length());
|
|
||||||
str = substring;
|
|
||||||
} else {
|
|
||||||
str = split2[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
private URI getIP(URI uri) {
|
private URI getIP(URI uri) {
|
||||||
URI effectiveURI = null;
|
URI effectiveURI = null;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,31 +1,17 @@
|
|||||||
package com.fuying.sn.utils;
|
package com.fuying.sn.utils;
|
||||||
|
|
||||||
|
import static android.content.Context.WIFI_SERVICE;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.admin.DevicePolicyManager;
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.PorterDuffXfermode;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
@@ -37,22 +23,10 @@ import android.text.TextUtils;
|
|||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.fuying.sn.BuildConfig;
|
import com.fuying.sn.BuildConfig;
|
||||||
import com.fuying.sn.R;
|
|
||||||
import com.fuying.sn.statistics.AppInformation;
|
|
||||||
import com.fuying.sn.statistics.StatisticsInfo;
|
|
||||||
import com.fuying.sn.bean.AppUsed;
|
|
||||||
import com.fuying.sn.config.CommonConfig;
|
import com.fuying.sn.config.CommonConfig;
|
||||||
import com.fuying.sn.gson.GsonUtils;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.EncodeHintType;
|
import com.google.zxing.EncodeHintType;
|
||||||
@@ -65,23 +39,15 @@ import com.tencent.mmkv.MMKV;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.LineNumberReader;
|
import java.io.LineNumberReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -90,8 +56,6 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static android.content.Context.WIFI_SERVICE;
|
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
private static final String TAG = "Utils";
|
private static final String TAG = "Utils";
|
||||||
|
|
||||||
@@ -200,108 +164,10 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MD5 设备地址标识
|
// MD5 设备地址标识
|
||||||
public static String getMD5(Context context) {
|
|
||||||
String WLANMAC = getMAC(context);
|
|
||||||
// compute md5
|
|
||||||
MessageDigest m = null;
|
|
||||||
try {
|
|
||||||
m = MessageDigest.getInstance("MD5");
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (WLANMAC != null && !"".equals(WLANMAC)) {
|
|
||||||
m.update(WLANMAC.getBytes(), 0, WLANMAC.length());
|
|
||||||
} else if (getSimSerialNumber(context) != null && !"".equals(getSimSerialNumber(context))) {
|
|
||||||
m.update(getSimSerialNumber(context).getBytes(), 0, getSimSerialNumber(context).length());
|
|
||||||
} else {
|
|
||||||
m.update(getPesudoUniqueID().getBytes(), 0, getPesudoUniqueID().length());
|
|
||||||
}
|
|
||||||
// get md5 bytes
|
|
||||||
byte[] p_md5Data = m.digest();
|
|
||||||
// create a hex string
|
|
||||||
String m_szUniqueID = "";
|
|
||||||
for (int i = 0; i < p_md5Data.length; i++) {
|
|
||||||
int b = (0xFF & p_md5Data[i]);
|
|
||||||
// if it is a single digit, make sure it have 0 in front (proper padding)
|
|
||||||
if (b <= 0xF)
|
|
||||||
m_szUniqueID += "0";
|
|
||||||
// add number to string
|
|
||||||
m_szUniqueID += Integer.toHexString(b);
|
|
||||||
} // hex string to uppercase
|
|
||||||
m_szUniqueID = m_szUniqueID.toUpperCase();
|
|
||||||
return m_szUniqueID;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getSimSerialNumber(Context context) {
|
|
||||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
||||||
|
|
||||||
@SuppressLint("MissingPermission") String simSerialNumber = tm.getSimSerialNumber();
|
|
||||||
return simSerialNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getPesudoUniqueID() {
|
|
||||||
String m_szDevIDShort = "35" + //we make this look like a valid IMEI
|
|
||||||
Build.BOARD.length() % 10 +
|
|
||||||
Build.BRAND.length() % 10 +
|
|
||||||
Build.CPU_ABI.length() % 10 +
|
|
||||||
Build.DEVICE.length() % 10 +
|
|
||||||
Build.DISPLAY.length() % 10 +
|
|
||||||
Build.HOST.length() % 10 +
|
|
||||||
Build.ID.length() % 10 +
|
|
||||||
Build.MANUFACTURER.length() % 10 +
|
|
||||||
Build.MODEL.length() % 10 +
|
|
||||||
Build.PRODUCT.length() % 10 +
|
|
||||||
Build.TAGS.length() % 10 +
|
|
||||||
Build.TYPE.length() % 10 +
|
|
||||||
Build.USER.length() % 10;
|
|
||||||
return m_szDevIDShort;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 防止连续点击
|
// 防止连续点击
|
||||||
private static long lastClickTime;
|
|
||||||
|
|
||||||
public static boolean isFastDoubleClick() {
|
|
||||||
long time = System.currentTimeMillis();
|
|
||||||
long timeD = time - lastClickTime;
|
|
||||||
if (0 < timeD && timeD < 500) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
lastClickTime = time;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5分钟 = 1 转换成时间
|
// 5分钟 = 1 转换成时间
|
||||||
public static String getRangeTime(int range) {
|
|
||||||
StringBuffer sBuffer = new StringBuffer();
|
|
||||||
String hour;
|
|
||||||
String minute;
|
|
||||||
if ((range / 12) >= 10) {
|
|
||||||
hour = range / 12 + "";
|
|
||||||
} else {
|
|
||||||
hour = "0" + range / 12 + "";
|
|
||||||
}
|
|
||||||
if ((range % 12) > 0) {
|
|
||||||
minute = ":" + range % 12 / 2 + "0";
|
|
||||||
} else {
|
|
||||||
minute = ":00";
|
|
||||||
}
|
|
||||||
sBuffer.append(hour.trim());
|
|
||||||
sBuffer.append(minute.trim());
|
|
||||||
return sBuffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据日期取得星期几
|
// 根据日期取得星期几
|
||||||
public static String getWeek(Date date) {
|
|
||||||
String[] weeks = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
cal.setTime(date);
|
|
||||||
int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
|
||||||
if (week_index < 0) {
|
|
||||||
week_index = 0;
|
|
||||||
}
|
|
||||||
return weeks[week_index];
|
|
||||||
}
|
|
||||||
|
|
||||||
// // 非空判断
|
// // 非空判断
|
||||||
// public static boolean isEmpty(String s) {
|
// public static boolean isEmpty(String s) {
|
||||||
// if (null == s)
|
// if (null == s)
|
||||||
@@ -312,263 +178,11 @@ public class Utils {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// 手动隐藏键盘
|
// 手动隐藏键盘
|
||||||
public static void CloseKeyBoard(Context context) {
|
|
||||||
InputMethodManager imm = (InputMethodManager) context
|
|
||||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
System.out.println("isActive:" + imm.isActive());
|
|
||||||
if (imm.isActive()) {
|
|
||||||
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
|
|
||||||
InputMethodManager.HIDE_NOT_ALWAYS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 接受软键盘输入
|
// 接受软键盘输入
|
||||||
public static void hideKeyboard(Context context, View view) {
|
|
||||||
if (context == null || view == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
InputMethodManager imm = (InputMethodManager) context
|
|
||||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 卸载app
|
// 卸载app
|
||||||
public static void unInstallAPP(Context context, String packageName) {
|
|
||||||
if (!TextUtils.isEmpty(packageName) && !AppsManagerUtils.isSystemApp(context, packageName)) {
|
|
||||||
if (AppsManagerUtils.isSystemApp(context, packageName)) {
|
|
||||||
ToastUtil.show("系统应用无法卸载!");
|
|
||||||
} else {
|
|
||||||
Uri packageURI = Uri.parse("package:" + packageName);
|
|
||||||
Intent intent = new Intent(Intent.ACTION_DELETE, packageURI);
|
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ToastUtil.show("系统应用无法卸载!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打开app
|
// 打开app
|
||||||
public static void startApp(Context context, String packageName, String activityName) {
|
|
||||||
if (TextUtils.isEmpty(packageName))
|
|
||||||
return;
|
|
||||||
try {
|
|
||||||
Intent intent = null;
|
|
||||||
if (TextUtils.isEmpty(activityName)) {
|
|
||||||
intent = context.getPackageManager().getLaunchIntentForPackage(
|
|
||||||
packageName);
|
|
||||||
} else {
|
|
||||||
intent = new Intent();
|
|
||||||
intent.setComponent(new ComponentName(packageName, activityName));
|
|
||||||
}
|
|
||||||
if (intent == null) {
|
|
||||||
intent = getLaunchIntentForNoCategory(context, packageName);
|
|
||||||
}
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
context.startActivity(intent);
|
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Intent getLaunchIntentForNoCategory(Context context, String packageName) {
|
|
||||||
Intent intent = null;
|
|
||||||
PackageManager packageManager = context.getPackageManager();
|
|
||||||
PackageInfo packageinfo = null;
|
|
||||||
try {
|
|
||||||
packageinfo = packageManager.getPackageInfo(packageName, 0);
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (packageinfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
|
|
||||||
resolveIntent.setPackage(packageinfo.packageName);
|
|
||||||
List<ResolveInfo> resolveinfoList = packageManager.queryIntentActivities(resolveIntent, 0);
|
|
||||||
ResolveInfo resolveinfo = resolveinfoList.iterator().next();
|
|
||||||
if (resolveinfo != null) {
|
|
||||||
String className = resolveinfo.activityInfo.name;
|
|
||||||
intent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
||||||
ComponentName cn = new ComponentName(packageName, className);
|
|
||||||
intent.setComponent(cn);
|
|
||||||
}
|
|
||||||
return intent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置系统亮度模式
|
// 设置系统亮度模式
|
||||||
public static void systemBrightness(Context context) {
|
|
||||||
try {
|
|
||||||
SharedPreferences mPrefs = context.getSharedPreferences("colorflykids", 0);
|
|
||||||
boolean initSetting = mPrefs.getBoolean("init_setting", true);
|
|
||||||
if (initSetting) {
|
|
||||||
mPrefs.edit().putBoolean("init_setting", false).commit();
|
|
||||||
}
|
|
||||||
Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, 0);
|
|
||||||
mPrefs.edit().putBoolean("first_init", false).commit();
|
|
||||||
} catch (Exception err) {
|
|
||||||
err.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新 版本比较
|
// 更新 版本比较
|
||||||
public static boolean isUpdate(String oldVersion, String newVersion) {
|
|
||||||
if (TextUtils.isEmpty(oldVersion) || TextUtils.isEmpty(newVersion) || oldVersion.equals(newVersion)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
String[] oldVersionSp = oldVersion.replaceAll("[^.\\d]", "").trim().split("\\.");
|
|
||||||
String[] newVsersionSp = newVersion.replaceAll("[^.\\d]", "").trim().split("\\.");
|
|
||||||
int index = 0;
|
|
||||||
int minLen = Math.min(oldVersionSp.length, newVsersionSp.length);
|
|
||||||
int diff = 0;
|
|
||||||
while (index < minLen && (diff = Integer.parseInt(newVsersionSp[index]) - Integer.parseInt(oldVersionSp[index])) == 0) {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
if (diff == 0) {
|
|
||||||
for (int i = index; i < oldVersionSp.length; i++) {
|
|
||||||
if (Integer.parseInt(oldVersionSp[i]) > 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = index; i < newVsersionSp.length; i++) {
|
|
||||||
if (Integer.parseInt(newVsersionSp[i]) > 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return diff > 0;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* 半角转换为全角
|
|
||||||
*
|
|
||||||
* @param input
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String ToDBC(String input) {
|
|
||||||
char[] c = input.toCharArray();
|
|
||||||
for (int i = 0; i < c.length; i++) {
|
|
||||||
if (c[i] == 12288) {
|
|
||||||
c[i] = (char) 32;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (c[i] > 65280 && c[i] < 65375)
|
|
||||||
c[i] = (char) (c[i] - 65248);
|
|
||||||
}
|
|
||||||
return new String(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected static Toast toast = null;
|
|
||||||
private static String oldMsg;
|
|
||||||
private static long oneTime = 0;
|
|
||||||
private static long twoTime = 0;
|
|
||||||
|
|
||||||
public static void showToast(Context context, String s) {
|
|
||||||
if (toast == null) {
|
|
||||||
toast = Toast.makeText(context, s, Toast.LENGTH_SHORT);
|
|
||||||
toast.show();
|
|
||||||
oneTime = System.currentTimeMillis();
|
|
||||||
} else {
|
|
||||||
twoTime = System.currentTimeMillis();
|
|
||||||
if (s.equals(oldMsg)) {
|
|
||||||
if (twoTime - oneTime > Toast.LENGTH_SHORT) {
|
|
||||||
toast.show();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
oldMsg = s;
|
|
||||||
toast.setText(s);
|
|
||||||
toast.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
oneTime = twoTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isShouldHideInput(View v, MotionEvent event) {
|
|
||||||
if (v != null && (v instanceof EditText)) {
|
|
||||||
int[] leftTop = {0, 0};
|
|
||||||
//获取输入框当前的location位置
|
|
||||||
v.getLocationInWindow(leftTop);
|
|
||||||
int left = leftTop[0];
|
|
||||||
int top = leftTop[1];
|
|
||||||
int bottom = top + v.getHeight();
|
|
||||||
int right = left + v.getWidth();
|
|
||||||
// 点击的是输入框区域,保留点击EditText的事件
|
|
||||||
return !(event.getX() > left) || !(event.getX() < right)
|
|
||||||
|| !(event.getY() > top) || !(event.getY() < bottom);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isIntent(Context context) {
|
|
||||||
|
|
||||||
ConnectivityManager manager = (ConnectivityManager) context
|
|
||||||
.getApplicationContext().getSystemService(
|
|
||||||
Context.CONNECTIVITY_SERVICE);
|
|
||||||
if (manager == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// 检查网络连接,如果无网络可用,就不需要进行连网操作等
|
|
||||||
NetworkInfo networkinfo = manager.getActiveNetworkInfo();
|
|
||||||
|
|
||||||
return networkinfo != null && networkinfo.isAvailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getTime(int time) {
|
|
||||||
int min = time / 60;
|
|
||||||
int sec = time % 60;
|
|
||||||
if (sec > 0) {
|
|
||||||
return String.valueOf(min + 1);
|
|
||||||
} else {
|
|
||||||
return String.valueOf(min);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getTimeClick(int time) {
|
|
||||||
StringBuffer timeClick = new StringBuffer();
|
|
||||||
int min = time / 60;
|
|
||||||
int sec = time % 60;
|
|
||||||
timeClick.append(min >= 10 ? (int) Math.ceil(min / 10) : 0)
|
|
||||||
.append(min % 10)
|
|
||||||
.append(":")
|
|
||||||
.append(sec >= 10 ? (int) Math.ceil(sec / 10) : 0)
|
|
||||||
.append(sec % 10);
|
|
||||||
return timeClick.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getVersionName(Context context) {
|
|
||||||
// 获取packagemanager的实例
|
|
||||||
PackageManager packageManager = context.getPackageManager();
|
|
||||||
// getPackageName()是你当前类的包名,0代表是获取版本信息
|
|
||||||
PackageInfo packInfo;
|
|
||||||
try {
|
|
||||||
packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
|
|
||||||
String version = packInfo.versionName.replaceAll("[a-zA-Z]", "").trim();
|
|
||||||
return version;
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getTime() {
|
|
||||||
long time = System.currentTimeMillis();//long now = android.os.SystemClock.uptimeMillis();
|
|
||||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
||||||
Date d1 = new Date(time);
|
|
||||||
String t1 = format.format(d1);
|
|
||||||
return t1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void getAdmin(Context context, ComponentName componentName) {
|
|
||||||
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
|
|
||||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
|
|
||||||
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "宏云萌书院OS");
|
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备序列号
|
* 获取设备序列号
|
||||||
@@ -604,107 +218,6 @@ public class Utils {
|
|||||||
return serial;
|
return serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param context 获取真实的MAC地址
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String getAndroid10MAC(Context context) {
|
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
|
|
||||||
return getMacAddress(context);
|
|
||||||
} else {
|
|
||||||
return getAndroid7MAC();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("HardwareIds")
|
|
||||||
@VisibleForTesting
|
|
||||||
public static String getMacAddress(Context mContext) {
|
|
||||||
WifiManager mWifiManager = (WifiManager) mContext.getSystemService(WIFI_SERVICE);
|
|
||||||
final String[] macAddresses = mWifiManager.getFactoryMacAddresses();
|
|
||||||
String macAddress = null;
|
|
||||||
if (macAddresses != null && macAddresses.length > 0) {
|
|
||||||
macAddress = macAddresses[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(macAddress)) {
|
|
||||||
String mac = getMacFromFile();
|
|
||||||
// Add for CTCC Feature:WIFI MAC should be gotten while wifi disabled.
|
|
||||||
// Get Wifi MAC from file since we can not get it with WifiManager.
|
|
||||||
if (!TextUtils.isEmpty(mac)) {
|
|
||||||
macAddress = mac;
|
|
||||||
} else {
|
|
||||||
macAddress = "未能获取到MAC地址";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return macAddress.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add for CTCC Feature:WIFI MAC should be gotten while wifi disabled.
|
|
||||||
* get Wifi MAC from /mnt/vendor/wifimac.txt
|
|
||||||
*
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
private static String MACID_FILE_PATH = "/mnt/vendor/wifimac.txt";
|
|
||||||
|
|
||||||
private static String getMacFromFile() {
|
|
||||||
File file = new File(MACID_FILE_PATH);
|
|
||||||
BufferedReader reader = null;
|
|
||||||
String macAddress = null;
|
|
||||||
try {
|
|
||||||
reader = new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
macAddress = line;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
Log.w(TAG, "Mac file not exist", e);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w(TAG, "get mac from file caught exception", e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (reader != null)
|
|
||||||
reader.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.w(TAG, "reader close exception");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return macAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final long A_GB = 1073741824;
|
|
||||||
public static final long A_MB = 1048576;
|
|
||||||
public static final int A_KB = 1024;
|
|
||||||
|
|
||||||
public static String fmtSpace(long space) {
|
|
||||||
if (space <= 0) {
|
|
||||||
return "0";
|
|
||||||
}
|
|
||||||
double gbValue = (double) space / A_GB;
|
|
||||||
if (gbValue >= 1) {
|
|
||||||
return String.format("%.2fGB", gbValue);
|
|
||||||
} else {
|
|
||||||
double mbValue = (double) space / A_MB;
|
|
||||||
// Log.e("GB", "gbvalue=" + mbValue);
|
|
||||||
if (mbValue >= 1) {
|
|
||||||
return String.format("%.2fMB", mbValue);
|
|
||||||
} else {
|
|
||||||
final double kbValue = space / A_KB;
|
|
||||||
return String.format("%.2fKB", kbValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String transferLongToDate(Long millSec) {
|
|
||||||
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
|
|
||||||
Date date = new Date(millSec);
|
|
||||||
|
|
||||||
return sdf.format(date);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Bitmap createQRImage(String content, int widthPix, int heightPix) {
|
public static Bitmap createQRImage(String content, int widthPix, int heightPix) {
|
||||||
try {
|
try {
|
||||||
@@ -760,74 +273,6 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//判断是否为系统应用
|
//判断是否为系统应用
|
||||||
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 (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.e("isSystemApp", e.getMessage(), e);
|
|
||||||
|
|
||||||
}
|
|
||||||
// 是系统中已安装的应用
|
|
||||||
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 Bitmap getRoundedBitmap(Bitmap mBitmap, Context context) {
|
|
||||||
Bitmap bgBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
|
||||||
|
|
||||||
Bitmap mask = BitmapFactory.decodeResource(context.getResources(), R.drawable.mask);
|
|
||||||
int width = mask.getWidth();
|
|
||||||
int height = mask.getHeight();
|
|
||||||
Bitmap bitmapScale = Bitmap.createScaledBitmap(mBitmap, width, height, true);
|
|
||||||
|
|
||||||
// Palette p = Palette.from(mBitmap).generate();
|
|
||||||
// Palette.Swatch vibrant = p.getVibrantSwatch();//有活力的
|
|
||||||
// int color = vibrant.getRgb(); //样本中的像素数量
|
|
||||||
|
|
||||||
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
||||||
Canvas canvas = new Canvas();
|
|
||||||
Paint paint = new Paint();
|
|
||||||
|
|
||||||
canvas.setBitmap(result);
|
|
||||||
// canvas.drawColor(color);
|
|
||||||
canvas.drawBitmap(mask, 0, 0, paint);
|
|
||||||
// paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
|
||||||
canvas.drawBitmap(bitmapScale, 0, 0, paint);
|
|
||||||
// return result;
|
|
||||||
|
|
||||||
Bitmap result2 = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
||||||
Canvas canvas2 = new Canvas();
|
|
||||||
Paint paint2 = new Paint();
|
|
||||||
canvas2.setBitmap(result2);
|
|
||||||
canvas2.drawBitmap(mask, 0, 0, paint2);
|
|
||||||
paint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
|
||||||
canvas2.drawBitmap(result, 0, 0, paint2);
|
|
||||||
return result2;
|
|
||||||
|
|
||||||
// Canvas mCanvas = new Canvas();
|
|
||||||
// mCanvas.setBitmap(bgBitmap);
|
|
||||||
// Paint mPaint = new Paint();
|
|
||||||
// RectF mRectM = new RectF(scaleM, scaleM, mBitmap.getWidth() - scaleM, mBitmap.getHeight() - scaleM); //设置剪裁圆角的区域
|
|
||||||
// Rect mRect = new Rect(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
|
|
||||||
// RectF mRectF = mRectM;
|
|
||||||
//
|
|
||||||
// float roundPx = 15; //圆角半径
|
|
||||||
// mPaint.setAntiAlias(true);
|
|
||||||
// //Log.d("wy"+TAG,"mBitmap.getWidth()="+mBitmap.getWidth()+", mBitmap.getHeight()="+mBitmap.getHeight());
|
|
||||||
// mCanvas.drawRoundRect(mRectF, roundPx, roundPx, mPaint);
|
|
||||||
// mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
|
||||||
// mCanvas.drawBitmap(mBitmap, mRect, mRect, mPaint);
|
|
||||||
// return bgBitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新应用白名单禁止升级
|
* 更新应用白名单禁止升级
|
||||||
*
|
*
|
||||||
@@ -951,33 +396,6 @@ public class Utils {
|
|||||||
return width + "×" + height;
|
return width + "×" + height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMacAddress() {
|
|
||||||
List<NetworkInterface> interfaces = null;
|
|
||||||
try {
|
|
||||||
interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
|
|
||||||
for (NetworkInterface networkInterface : interfaces) {
|
|
||||||
if (networkInterface != null && TextUtils.isEmpty(networkInterface.getName()) == false) {
|
|
||||||
if ("wlan0".equalsIgnoreCase(networkInterface.getName())) {
|
|
||||||
byte[] macBytes = networkInterface.getHardwareAddress();
|
|
||||||
if (macBytes != null && macBytes.length > 0) {
|
|
||||||
StringBuilder str = new StringBuilder();
|
|
||||||
for (byte b : macBytes) {
|
|
||||||
str.append(String.format("%02X:", b));
|
|
||||||
}
|
|
||||||
if (str.length() > 0) {
|
|
||||||
str.deleteCharAt(str.length() - 1);
|
|
||||||
}
|
|
||||||
return str.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SocketException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getBattery(Context context) {
|
public static int getBattery(Context context) {
|
||||||
try {
|
try {
|
||||||
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
||||||
@@ -1009,26 +427,6 @@ public class Utils {
|
|||||||
return batteryCapacity;
|
return batteryCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized private static int getBatteryLevel(Context mContext) {
|
|
||||||
if (Build.VERSION.SDK_INT >= 21)
|
|
||||||
return ((BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
|
|
||||||
Intent intent = (new ContextWrapper(mContext)).registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
|
|
||||||
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getBatteryPercentage(Context context) {
|
|
||||||
|
|
||||||
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
|
||||||
Intent batteryStatus = context.registerReceiver(null, iFilter);
|
|
||||||
|
|
||||||
int level = batteryStatus != null ? batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) : -1;
|
|
||||||
int scale = batteryStatus != null ? batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1) : -1;
|
|
||||||
|
|
||||||
float batteryPct = level / (float) scale;
|
|
||||||
|
|
||||||
return (int) (batteryPct * 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getIsCharging(Context context) {
|
public static int getIsCharging(Context context) {
|
||||||
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||||
Intent batteryStatus = context.registerReceiver(null, ifilter);
|
Intent batteryStatus = context.registerReceiver(null, ifilter);
|
||||||
@@ -1061,23 +459,6 @@ public class Utils {
|
|||||||
return freeMem;
|
return freeMem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 描述:获取可用内存.
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static long getAvailMemory(Context context) {
|
|
||||||
// 获取android当前可用内存大小
|
|
||||||
ActivityManager activityManager = (ActivityManager) context
|
|
||||||
.getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
|
|
||||||
activityManager.getMemoryInfo(memoryInfo);
|
|
||||||
// 当前系统可用内存 ,将获得的内存大小规格化
|
|
||||||
Log.e(TAG, "getAvailMemory: " + memoryInfo.availMem);
|
|
||||||
return memoryInfo.availMem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getTotalMem(Context context) {
|
public static long getTotalMem(Context context) {
|
||||||
// 获取android当前可用内存大小
|
// 获取android当前可用内存大小
|
||||||
ActivityManager activityManager = (ActivityManager) context
|
ActivityManager activityManager = (ActivityManager) context
|
||||||
@@ -1133,12 +514,6 @@ public class Utils {
|
|||||||
return (float) 100.0 * ((blockSize * totalBlocks) - availableSize) / (blockSize * totalBlocks);
|
return (float) 100.0 * ((blockSize * totalBlocks) - availableSize) / (blockSize * totalBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRemnantSize(Context context) {
|
|
||||||
StatFs sf = new StatFs(context.getCacheDir().getAbsolutePath());
|
|
||||||
long availableSize = sf.getAvailableBytes();
|
|
||||||
return Formatter.formatFileSize(context, availableSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getUsedSize(Context context) {
|
public static String getUsedSize(Context context) {
|
||||||
StatFs sf = new StatFs(context.getCacheDir().getAbsolutePath());
|
StatFs sf = new StatFs(context.getCacheDir().getAbsolutePath());
|
||||||
long availableSize = sf.getAvailableBytes();
|
long availableSize = sf.getAvailableBytes();
|
||||||
@@ -1270,25 +645,6 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAppUsedStatistics(Context context) {
|
|
||||||
StatisticsInfo statisticsInfo = new StatisticsInfo(context, 0);
|
|
||||||
long totalTime = statisticsInfo.getTotalTime();
|
|
||||||
int totalTimes = statisticsInfo.getTotalTimes();
|
|
||||||
List<AppInformation> datalist = statisticsInfo.getShowList();
|
|
||||||
List<AppUsed> appUsedList = new ArrayList<>();
|
|
||||||
for (AppInformation information : datalist) {
|
|
||||||
AppUsed used = new AppUsed();
|
|
||||||
used.setPackages(information.getPackageName());
|
|
||||||
used.setUseTime(information.getUsedTimebyDay() / 1000);
|
|
||||||
used.setApp_name(information.getLabel());
|
|
||||||
appUsedList.add(used);
|
|
||||||
}
|
|
||||||
appUsedList.removeIf(appUsed -> appUsed.getUseTime() == 0);
|
|
||||||
String jsonString = GsonUtils.toJSONString(appUsedList);
|
|
||||||
Log.e(TAG, "getAppUsedStatistics: " + jsonString);
|
|
||||||
return jsonString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void killBackgroundApp(Context context) {
|
public static void killBackgroundApp(Context context) {
|
||||||
List<String> pkgList = ApkUtils.queryFilterAppList(context);
|
List<String> pkgList = ApkUtils.queryFilterAppList(context);
|
||||||
for (String pkg : pkgList) {
|
for (String pkg : pkgList) {
|
||||||
|
|||||||
Reference in new issue
Block a user