Files
CubeAoleyunSN/app/src/main/java/com/aoleyun/sn/utils/ApkUtils.java

1449 lines
60 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.aoleyun.sn.utils;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.RequiresApi;
import androidx.core.content.FileProvider;
import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.bean.UploadAppInfo;
import com.aoleyun.sn.comm.JGYActions;
import com.aoleyun.sn.comm.PackageNames;
import com.aoleyun.sn.gson.GsonUtils;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
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.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
public class ApkUtils {
private static String TAG = ApkUtils.class.getSimpleName();
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();
if (exitValue == 0) {
return true;
} else {
return false;
}
} 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, 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 boolean openPackage(Context context, String packageName, String className) {
if (TextUtils.isEmpty(className)) {
return openPackage(context, packageName);
}
ComponentName cn = new ComponentName(packageName, className);
Intent intent = new Intent();
intent.setComponent(cn);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (context != null) {
try {
context.startActivity(intent);
return true;
} catch (Exception e) {
Log.e(TAG, "openPackage: " + e.getMessage());
ToastUtil.show("打开失败");
return false;
}
}
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.aoleyun.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);
}
/**
* 卸载一个app
*/
public static void unInstall(Context context, String packageName) {
//通过程序的包名创建URI
Uri packageURI = Uri.parse("package:" + packageName);
//创建Intent意图
Intent intent = new Intent(Intent.ACTION_DELETE, packageURI);
//执行卸载程序
context.startActivity(intent);
}
/**
* 检查手机上是否安装了指定的软件
*/
public static boolean isAvailable(Context context, String packageName) {
PackageManager packageManager = context.getPackageManager();
PackageInfo info = null;
try {
info = packageManager.getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return info != null;
}
/**
* 检查手机上是否安装了指定的软件
*/
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; //得到安装包名称
} else {
return "";
}
}
/**
* 从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) {
Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
File file = new File(filePath);
if (TextUtils.isEmpty(filePath) || !file.exists()) {
Log.e("installRx", "filePath is empty");
emitter.onNext(0);
return;
}
// String[] args = { "pm", "install", "-r", filePath };
String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath};
// String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath;
Log.e("installRx", "argss====" + args);
ProcessBuilder processBuilder = new ProcessBuilder(args);
Process process = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = new StringBuilder();
StringBuilder errorMsg = new StringBuilder();
try {
process = processBuilder.start();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) {
Log.e("mjhseng", "successResult----------" + s);
successMsg.append(s);
}
while ((s = errorResult.readLine()) != null) {
Log.e("mjhseng", "errorResult----------" + s);
errorMsg.append(s);
}
} catch (IOException e1) {
Log.e("installRx", "IOException e1)----------" + e1.toString());
e1.printStackTrace();
} finally {
try {
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (IOException e1) {
Log.e("installRx", "IOException e11)---------" + e1.toString());
e1.printStackTrace();
}
if (process != null) {
process.destroy();
}
}
if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) {
emitter.onNext(2);
} else {
Log.e("installRx", "errormesg :" + errorMsg.toString());
emitter.onNext(1);
}
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("installRx", "onSubscribe: ");
}
@Override
public void onNext(Integer value) {
if (value == 2) {
//安装成功
ToastUtil.show("安装成功");
Log.e("installRx", "-----------安装成功-----------");
} else {
//安装错误
Log.e("installRx", "------------安装错误-----------");
ToastUtil.show("安装失败");
}
}
@Override
public void onError(Throwable e) {
Log.e("installRx", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
Log.e("installRx", "onComplete: ");
}
});
}
public interface InstallCallback {
void installInfoCallback(String path, String packageName);
}
public static void installApp(Context context, String filePath) {
Log.e(TAG, "installApp: " + filePath);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
installAppatPie(context, filePath);
} else {
installApps(filePath);
}
}
public static boolean installApps(String apkPath) {
Log.e(TAG, "installApps: 正在安装应用 " + apkPath);
ToastUtil.show("正在安装应用");
Process process = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = new StringBuilder();
StringBuilder errorMsg = new StringBuilder();
try {
process = new ProcessBuilder("pm", "install", "-i", BuildConfig.APPLICATION_ID, "--user", "0", apkPath).start();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) {
successMsg.append(s);
}
while ((s = errorResult.readLine()) != null) {
errorMsg.append(s);
}
} catch (Exception e) {
} finally {
try {
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (Exception e) {
}
if (process != null) {
process.destroy();
}
}
Log.e("result", "" + errorMsg.toString());
//如果含有“success”认为安装成功
Log.e("installApp", successMsg.toString());
// if (!successMsg.toString().equalsIgnoreCase("success")) {
// ApkUtils.install(context, new File(apkPath));
// }
return "success".equalsIgnoreCase(successMsg.toString());
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void installAppatPie(Context context, String apkFilePath) {
File file = new File(apkFilePath);
Log.e(TAG, "installAppatPie: 正在安装应用 " + apkFilePath);
PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstaller
.SessionParams.MODE_FULL_INSTALL);
sessionParams.setSize(file.length());
int sessionId = createSession(packageInstaller, sessionParams);
if (sessionId != -1) {
boolean copySuccess = copyApkFile(packageInstaller, sessionId, apkFilePath);
if (copySuccess) {
ToastUtil.show("正在安装应用");
install(packageInstaller, sessionId, context);
}
}
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static void install(PackageInstaller packageInstaller, int sessionId, Context context) {
try {
PackageInstaller.Session session = packageInstaller.openSession(sessionId);
Intent intent = new Intent(context, InstallResultReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context,
1, intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
session.commit(pendingIntent.getIntentSender());
} catch (IOException e) {
e.printStackTrace();
}
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static int createSession(PackageInstaller packageInstaller, PackageInstaller.SessionParams sessionParams) {
int sessionId = -1;
try {
sessionId = packageInstaller.createSession(sessionParams);
} catch (IOException e) {
e.printStackTrace();
}
return sessionId;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static boolean copyApkFile(PackageInstaller pi, int sessionId, String apkFilePath) {
boolean success = false;
File apkFile = new File(apkFilePath);
PackageInstaller.Session session = null;
try {
session = pi.openSession(sessionId);
OutputStream out = session.openWrite("app.apk", 0, apkFile.length());
FileInputStream input = new FileInputStream(apkFile);
int read = 0;
byte[] buffer = new byte[65536];
// while (read != -1) {
// read = input.read(buffer);
// out.write(buffer, 0, read);
// }
while (true) {
read = input.read(buffer);
if (read == -1) {
session.fsync(out);
success = true;
out.close();
input.close();
break;
}
out.write(buffer, 0, read);
}
} catch (IOException e) {
e.printStackTrace();
Log.e("fht", "copyApkFile" + e.getMessage());
}
return success;
}
public static void installApkInSilence(String installPath, String packageName) {
Log.e(TAG, "installApps: 正在安装应用 " + installPath);
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();
Log.e("installApkInSilence", "ClassNotFoundException:" + e.getMessage());
} catch (NoSuchMethodException e) {
e.printStackTrace();
Log.e("installApkInSilence", "NoSuchMethodException:" + e.getMessage());
} catch (IllegalAccessException e) {
e.printStackTrace();
Log.e("installApkInSilence", "IllegalAccessException:" + e.getMessage());
} catch (InvocationTargetException e) {
e.printStackTrace();
Log.e("installApkInSilence", "InvocationTargetException:" + e.getMessage());
}
}
public static void deleteApkInSilence(String packageName) {
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, "deletePackageAsUser");
method = pmService.getMethod("deletePackageAsUser", paramTypes1);
method.invoke(PackageManagerService, packageName, null, getUserId(Binder.getCallingUid()), 0x00000040);//getUserId
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
/**
* 静默卸载应用
*
* @param context
* @param pkg
*/
public static void UninstallAPP(Context context, String pkg) {
Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
// Log.e("UninstallAPP", "call " + Thread.currentThread().getName());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ApkUtils.uninstall(context, pkg);
} else {
ApkUtils.deleteApkInSilence(pkg);
}
emitter.onNext(pkg);
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<String>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("UninstallAPP", "onSubscribe: ");
}
@Override
public void onNext(String s) {
Log.e("UninstallAPP", "onNext " + Thread.currentThread().getName());
Log.e("UninstallAPP", "onNext: " + s);
}
@Override
public void onError(Throwable e) {
Log.e("UninstallAPP", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
Log.e("UninstallAPP", "onComplete: ");
}
});
}
/**
* 根据包名卸载应用
*
* @param packageName
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void uninstall(Context context, String packageName) {
Intent broadcastIntent = new Intent(context, InstallResultReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1,
broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
packageInstaller.uninstall(packageName, pendingIntent.getIntentSender());
}
public static boolean pmUninstall(String packageName) {
Process process = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = new StringBuilder();
StringBuilder errorMsg = new StringBuilder();
try {
process = new ProcessBuilder("pm", "uninstall", packageName).start();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) {
successMsg.append(s);
}
while ((s = errorResult.readLine()) != null) {
errorMsg.append(s);
}
} catch (Exception e) {
} finally {
try {
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (Exception e) {
}
if (process != null) {
process.destroy();
}
}
//如果含有“success”单词则认为卸载成功
return "success".equalsIgnoreCase(successMsg.toString());
}
private static Class<?>[] getParamTypes(Class<?> cls, String mName) {
Class<?>[] cs = null;
Method[] mtd = cls.getMethods();
for (int i = 0; i < mtd.length; i++) {
if (!mtd[i].getName().equals(mName)) {
continue;
}
cs = mtd[i].getParameterTypes();
}
return cs;
}
public static final int PER_USER_RANGE = 100000;
public static int getUserId(int uid) {
return uid / PER_USER_RANGE;
}
private static String[] excludePackageName = {"com.easyold.uiuios"};
/**
* 获取第三方应用
*
* @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) {
// Log.e("queryFilterAppInfo", String.valueOf(app.flags));
// Log.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 List<String> canremove_systemapp = new ArrayList<String>() {{
this.add("com.android.quicksearchbox");
this.add("com.android.calendar");
this.add("com.android.dreams.basic");
this.add("com.android.musicfx");
this.add("com.android.email");
this.add("com.jiaoguanyi.sysc");
}};
//需要管控的系统可以卸载的应用
public static List<String> show_canremove_systemapp = new ArrayList<String>() {{
this.add("com.android.calendar");
// this.add("com.android.email");
}};
//需要管控的系统应用
public static List<String> systemapp = new ArrayList<String>() {{
this.add("com.android.gallery3d");//图库
this.add("com.android.settings");//图库
this.add("com.android.deskclock");//时钟
this.add("com.android.music");//音乐
this.add("com.mediatek.camera");//相机
this.add("com.android.camera");
this.add("com.android.camera2");//展讯相机
this.add("com.android.documentsui");//文件
this.add("com.mediatek.filemanager");//文件
this.add("com.android.soundrecorder");//录音机
this.add("com.android.browser");//浏览器
this.add("com.android.mms");//信息
this.add("com.android.messaging");//展讯信息
this.add("com.android.fmradio");//FM电台
this.add("com.android.dialer");//电话
this.add("com.android.contacts");//通讯录
//根据需求内置
this.add("com.easyclient.activity");//移动课堂
this.add("com.jiandan.mobilelesson");//简单课堂
this.add(PackageNames.APPSTORE);//教官壹
//展讯
this.add("com.android.calculator2");//计算器
this.add("com.android.email");//电子邮件
this.add("com.android.calendar");//日历
this.add("com.tencent.wework");
this.add("com.tencent.mm");
this.add("cn.wps.moffice_eng");
this.add("com.baidu.BaiduMap");
}};
//桌面app
public static List<String> desktopAPP = new ArrayList<String>() {{
this.add("com.aoleyunos.dop1");
this.add("com.aoleyunos.dop2");
this.add("com.aoleyunos.dop3");
this.add("com.aoleyunos.dop4");
this.add("com.aoleyunos.dop5");
this.add("com.aoleyunos.dop6");
this.add("com.aoleyunos.dop7");
this.add("com.aoleyunos.dop8");
this.add("com.aoleyunos.dop9");
this.add("com.aoleyunos.dop10");
// this.add("com.uiuios.jgy1");
// this.add("com.uiuios.jgy2");
// this.add("com.android.uiuios");
// this.add("com.shoufei.aole");
}};
public static Set<String> aoleyunAPP = new HashSet<String>() {{
this.add(BuildConfig.APPLICATION_ID);
this.add("com.aoleyun.appstore");
this.add("com.aoleyun.sn");
this.add("com.aoleyun.info");
this.add("com.aoleyun.os");
this.add("com.aoleyun.browser");
this.add("com.uiui.filecloud");
this.add("com.gl.dwlauncher");
this.add("com.qunyu.dividedroad");
this.add("com.ygyb.yischool");
this.add("com.uiui.floatwindow");
this.add("com.uiuipad.find");
this.add("com.uiuipad.appstore");
this.add("com.uiuipad.os");
this.add("com.uiuipad.zyinfo");
this.add("com.yixuepai.os");
this.add("com.tongyi.aistudent");
}};
//出厂自带的app
public static List<String> factoryapp = new ArrayList<String>() {{
this.add("com.android.fmradio");
this.add("com.mediatek.gba");
this.add("com.mediatek.ims");
this.add("com.mediatek.ppl");
this.add("com.android.cts.priv.ctsshim");
this.add("com.android.internal.display.cutout.emulation.corner");
this.add("com.android.internal.display.cutout.emulation.double");
this.add("com.mediatek.autobootcontroller");
this.add("com.android.providers.telephony");
this.add("com.android.dynsystem");
this.add("com.mediatek.camera");
this.add("com.android.providers.calendar");
this.add("com.mediatek.telephony");
this.add("com.android.providers.media");
this.add("com.android.theme.icon.square");
this.add("com.android.internal.systemui.navbar.gestural_wide_back");
this.add("com.mediatek.location.lppe.main");
this.add("com.android.wallpapercropper");
this.add("com.android.theme.color.cinnamon");
this.add("com.mediatek.gnss.nonframeworklbs");
this.add("com.verizon.remoteSimlock");
this.add("com.android.protips");
this.add("com.android.theme.icon_pack.rounded.systemui");
this.add("com.android.documentsui");
this.add("com.android.externalstorage");
this.add("com.mediatek.ygps");
this.add("com.mediatek.simprocessor");
this.add("com.android.htmlviewer");
this.add("com.mediatek.autodialer");
this.add("com.mediatek.mms.appservice");
this.add("com.android.companiondevicemanager");
this.add("com.android.quicksearchbox");
this.add("com.android.mms.service");
this.add("com.android.providers.downloads");
this.add("com.adups.fota");
this.add("com.mediatek.engineermode");
this.add("com.android.theme.icon_pack.rounded.android");
this.add("com.example.hragingtest");
this.add("com.mediatek.omacp");
this.add("com.bsm_wqy.validationtools");
this.add("com.android.browser");
this.add("com.android.theme.icon_pack.circular.themepicker");
this.add("com.android.soundrecorder");
this.add("com.android.providers.downloads.ui");
this.add("com.android.pacprocessor");
this.add("com.android.simappdialog");
this.add("com.android.networkstack");
this.add("com.android.internal.display.cutout.emulation.tall");
this.add("com.android.modulemetadata");
this.add("com.android.certinstaller");
this.add("com.android.theme.color.black");
this.add("com.android.carrierconfig");
this.add("com.android.theme.color.green");
this.add("com.android.theme.color.ocean");
this.add("com.android.theme.color.space");
this.add("com.android.internal.systemui.navbar.threebutton");
this.add("android");
this.add("com.android.contacts");
this.add("com.mediatek.emcamera");
this.add("com.android.theme.icon_pack.rounded.launcher");
this.add("com.st.nfc.dta.mobile");
this.add("com.android.egg");
this.add("com.android.mms");
this.add("com.android.mtp");
this.add("com.android.nfc");
this.add("com.android.ons");
this.add("com.android.stk");
this.add("com.android.launcher3");
this.add("com.android.backupconfirm");
this.add("com.mediatek.security");
this.add("com.android.internal.systemui.navbar.twobutton");
this.add("com.android.provision");
this.add("com.android.statementservice");
this.add("com.android.hotspot2");
this.add("com.mediatek.mdmlsample");
this.add("com.android.settings.intelligence");
this.add("com.android.calendar");
this.add("com.mediatek.frameworkresoverlay");
this.add("com.debug.loggerui");
this.add("com.android.internal.systemui.navbar.gestural_extra_wide_back");
this.add("com.android.providers.settings");
this.add("com.android.sharedstoragebackup");
this.add("com.mediatek.batterywarning");
this.add("com.android.printspooler");
this.add("com.android.theme.icon_pack.filled.settings");
this.add("com.android.dreams.basic");
this.add("com.android.webview");
this.add("com.android.se");
this.add("com.android.inputdevices");
this.add("com.chartcross.gpstest");
this.add("com.android.bips");
this.add("com.mediatek");
this.add("com.android.theme.icon_pack.circular.settings");
this.add("com.android.musicfx");
this.add("com.android.cellbroadcastreceiver");
this.add("com.android.theme.icon.teardrop");
this.add("android.ext.shared");
this.add("com.android.onetimeinitializer");
this.add("com.android.server.telecom");
this.add("com.android.keychain");
this.add("com.mediatek.security.service");
this.add("com.android.printservice.recommendation");
this.add("com.android.dialer");
this.add("com.android.gallery3d");
this.add("com.android.theme.icon_pack.filled.systemui");
this.add("android.ext.services");
this.add("com.android.calllogbackup");
this.add("com.hr.factorytesting");
this.add("com.android.localtransport");
this.add("com.android.packageinstaller");
this.add("com.android.carrierdefaultapp");
this.add("com.mediatek.atmwifimeta");
this.add("com.android.theme.font.notoserifsource");
this.add("com.android.theme.icon_pack.filled.android");
this.add("com.android.proxyhandler");
this.add("com.android.theme.icon_pack.circular.systemui");
this.add("com.android.inputmethod.latin");
this.add("com.android.managedprovisioning");
this.add("com.mediatek.capctrl.service");
this.add("com.mediatek.callrecorder");
this.add("com.android.wallpaper.livepicker");
this.add("com.android.apps.tag");
this.add("com.mediatek.gnssdebugreport");
this.add("com.android.theme.icon.squircle");
this.add("com.android.storagemanager");
this.add("com.android.bookmarkprovider");
this.add("com.android.settings");
this.add("com.google.android.inputmethod.pinyin");
this.add("com.android.theme.icon_pack.filled.launcher");
this.add("com.android.networkstack.permissionconfig");
this.add("com.mediatek.mdmconfig");
this.add("com.mediatek.lbs.em2.ui");
this.add("com.android.cts.ctsshim");
this.add("com.android.theme.icon_pack.circular.launcher");
this.add("com.android.vpndialogs");
this.add("com.android.email");
this.add("com.android.music");
this.add("com.android.phone");
this.add("com.android.shell");
this.add("com.android.theme.icon_pack.filled.themepicker");
this.add("com.android.wallpaperbackup");
this.add("com.android.providers.blockednumber");
this.add("com.android.providers.userdictionary");
this.add("com.android.emergency");
this.add("com.android.internal.systemui.navbar.gestural");
this.add("com.android.location.fused");
this.add("com.android.theme.color.orchid");
this.add("com.android.deskclock");
this.add("com.android.systemui");
this.add("com.android.theme.color.purple");
this.add("com.android.bluetoothmidiservice");
this.add("com.android.permissioncontroller");
this.add("com.android.traceur");
this.add("com.mediatek.sensorhub.ui");
this.add("android.auto_generated_rro_product__");
this.add("com.android.bluetooth");
this.add("com.android.wallpaperpicker");
this.add("com.android.providers.contacts");
this.add("com.android.captiveportallogin");
this.add("com.android.theme.icon.roundedrect");
this.add("com.android.internal.systemui.navbar.gestural_narrow_back");
this.add("com.android.theme.icon_pack.rounded.settings");
this.add("com.mediatek.dataprotection");
this.add("com.wapi.wapicertmanager");
this.add("android.auto_generated_rro_vendor__");
this.add("com.android.theme.icon_pack.circular.android");
this.add(PackageNames.OLD_DEVICE_INFO);
this.add(PackageNames.OLD_APPSTORE);
this.add("com.example.eyeshielyplus");
this.add("cn.com.bifa.eyeshiely");
}};
public static Set<String> aihuaApp = new HashSet<String>() {{
this.add("com.liuyang.jcstudentside");
this.add("com.alibaba.android.rimet");
this.add("com.tencent.wemeet.app");
this.add("com.qi.studycomputer.launcher");
this.add("com.qi.xiaoshi");
this.add("com.hardware.cn");
this.add("com.qi.gamemodel");
this.add("com.wyt.tongbuyouxue");
this.add("com.qi.wyt.setting");
this.add("air.wyt.modloader");
// this.add("com.google.android.inputmethod.pinyin");
this.add("com.android.calculator2");
this.add("com.qi.TFSystem");
this.add("com.qi.appstore");
this.add("com.wyt.evaluating");
this.add("com.wyt.picturebook");
this.add("com.hhdd.kadahd");
this.add("com.wyt.onlinedic");
this.add("com.ximalaya.ting.kid");
this.add("com.baidu.duershow.child");
this.add("com.gl.souti");
this.add("com.ihuman.pinyin");
this.add("com.hongen.app.word");
this.add("com.wyt.parents_assistant");
this.add("com.wyt.forbitpoint");
this.add("com.wyt.lessonhelper");
this.add("com.wyt.wangkexueximvvm");
this.add("com.wyt.clicktoread");
this.add("com.robot.app_ai");
this.add("com.wyt.appstore");
this.add("air.com.wyt.GLLearnMain");
this.add("com.wyt.examcenter");
this.add("com.gl.compositioncorrection");
this.add("com.gl.compositioncorrectionen");
this.add("cn.wps.moffice_eng");
this.add("com.ckl.launcher");
this.add("net.forclass.fcstudent");
this.add("com.creative.strokeprovider");
this.add("com.ckl.oraltraining");
this.add("com.ckl.fcfilemanager");
this.add("com.iflytek.inputmethod");
this.add("com.wyt.wangkexueximvvm1");
this.add("com.android.stk");
this.add("com.shoufei.aole");
this.add("com.ygyb.yischool");
this.add("com.tencent.wework");
this.add("com.tencent.mm");
this.add("com.baidu.BaiduMap");
this.add("com.jxw.singsound");
this.add("com.qunyu.dividedroad");
this.add("com.gl.dwlauncher");
this.add("com.gl.dongwa");
}};
public static Set<String> jxwApp = new HashSet<String>() {{
this.add("air.com.zhihuiyoujiao.flashplayer");
this.add("com.example.arithmeticformula");
this.add("com.example.elementcycleapp");
this.add("com.example.pianpangbushou");
this.add("com.iflytek.cyber.iot.show.core");
this.add("com.iflytek.speechcloud");
this.add("com.jxw.bihuamingcheng");
this.add("com.jxw.bishunguize");
this.add("com.jxw.characterlearning");
this.add("com.jxw.dmxcy");
this.add("com.jxw.englishsoundmark");
this.add("com.jxw.examsystem");
this.add("com.jxw.game");
this.add("com.jxw.gb.zwpg");
this.add("com.jxw.handwrite");
this.add("com.jxw.jinfangyici");
this.add("com.jxw.jxwbook");
this.add("com.jxw.jxwcalculator");
this.add("com.jxw.laboratory");
this.add("com.jxw.learnchinesepinyin");
this.add("com.jxw.letterstudynew");
this.add("com.jxw.liancichengju");
this.add("com.jxw.mskt.video");
this.add("com.jxw.newyouer.video");
this.add("com.jxw.online_study");
this.add("com.jxw.question");
this.add("com.jxw.schultegrid");
this.add("com.jxw.singsound");
this.add("com.jxw.studydigital");
this.add("com.jxw.teacher.video");
this.add("com.jxw.wuweijidanci");
this.add("com.jxw.youer.video");
this.add("com.jxw.yuwenxiezuo");
this.add("com.jxw.yyhb");
this.add("com.jxw.zncd");
this.add("com.oirsdfg89.flg");
this.add("com.study.flashplayer");
this.add("com.tech.translate");
this.add("com.uiui.zybrowser");
this.add("com.uiui.zysn");
this.add("com.jxw.launcher");
this.add("com.uiui.zyappstore");
this.add("com.uiui.zy");
this.add("com.uiui.zyos");
this.add("com.teclast.zyos");
this.add("com.teclast.zybrowser");
this.add("com.teclast.zyappstore");
this.add("com.teclast.zy");
}};
public static final Set<String> systemApps = new HashSet<String>() {{
this.add("com.android.deskclock");
this.add("com.android.music");
this.add("com.android.documentsui");
this.add("com.mediatek.camera");
this.add("com.android.calendar");
this.add("com.android.calculator2");
this.add("com.android.gallery3d");
this.add("com.android.soundrecorder");
this.add("com.android.settings");
this.add("org.chromium.chrome");
this.add("com.softwinner.music");
this.add("com.softwinner.miracastReceiver");
this.add("com.softwinner.camera");
this.add("org.chromium.webview_shell");
// this.add("com.uiuipad.find");
// this.add("com.uiuipad.os");
this.add("com.softwinner.videoplayer");
this.add("com.sohu.inputmethod.sogou");
this.add("com.tencent.mtt");
}};
public static void showAllAPP(Context context) {
PackageManager pm = context.getPackageManager();
// 查询所有已经安装的应用程序
List<PackageInfo> packages = pm.getInstalledPackages(PackageManager.COMPONENT_ENABLED_STATE_ENABLED | PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
for (PackageInfo packageInfo : packages) {
Log.i(TAG, "showAllAPP: " + packageInfo.packageName);
//如果是自带可以卸载的,除开不需要管控的
if (canremove_systemapp.contains(packageInfo.packageName)
&& !show_canremove_systemapp.contains(packageInfo.packageName)) {
continue;
}
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1 && !systemapp.contains(packageInfo.packageName)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
//10.0上日历和电子邮件是可卸载的
//7.0是系统应用
if (show_canremove_systemapp.contains(packageInfo.packageName)) {
Logger.e("showAllAPP2", "packageName:" + packageInfo.packageName);
try {
pm.setApplicationEnabledSetting(packageInfo.packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
} catch (Exception e) {
Log.e(TAG, "showAllAPP: " + e.getMessage());
}
}
}
} else {
Logger.e("showAllAPP", "packageName:" + packageInfo.packageName);
try {
pm.setApplicationEnabledSetting(packageInfo.packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
} catch (Exception e) {
Log.e(TAG, "showAllAPP: " + e.getMessage());
}
hideSystemSettingAPP(context, packageInfo.packageName);
}
}
}
public static void hideSystemSettingAPP(Context context, String pkage) {
int hide = 0;
//后台0显示1隐藏
try {
if ("com.mediatek.camera".equalsIgnoreCase(pkage)) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_camera") == 1) {
hide = 0;//管控摄像头隐藏图标有问题,先暂时不隐藏
}
} else if ("com.android.deskclock".equalsIgnoreCase(pkage)) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_deskclock") == 1) {
hide = 0;
}
} else if ("com.android.soundrecorder".equalsIgnoreCase(pkage)) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_soundrecorder") == 1) {
hide = 0;
}
} else if ("com.android.music".equalsIgnoreCase(pkage)) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_music") == 1) {
hide = 0;
}
} else if ("com.android.gallery3d".equalsIgnoreCase(pkage)) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_gallery") == 1) {
hide = 0;
}
} else if ("com.android.documentsui".equalsIgnoreCase(pkage)
|| "com.mediatek.filemanager".equalsIgnoreCase(pkage)) {
if (Settings.System.getInt(context.getContentResolver(), "qch_app_filemanager") == 1) {
hide = 0;
}
}
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
// PackageManager pm = context.getPackageManager();
// if (hide == 0) {
// pm.setApplicationEnabledSetting(pkage, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
// } else {
// pm.setApplicationEnabledSetting(pkage, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
// }
}
/**
* 判断是否为系统应用
*
* @param context 上下文
* @param pkgName 包名
* @return
*/
public static boolean isSystemApp(Context context, String pkgName) {
boolean isSystemApp = false;
PackageInfo pi = null;
try {
PackageManager pm = context.getPackageManager();
pi = pm.getPackageInfo(pkgName, 0);
} catch (PackageManager.NameNotFoundException e) {
Log.e("isSystemApp: ", "NameNotFoundException:" + e.getMessage());
}
// 是系统中已安装的应用
if (pi != null) {
boolean isSysApp = (pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1;
boolean isSysUpd = (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1;
isSystemApp = isSysApp || isSysUpd;
}
return isSystemApp;
}
public static void getStartActivityName(Context mContext, String packagename) {
// 通过包名获取此APP详细信息包括Activities、services、versioncode、name等等
PackageInfo packageinfo = null;
PackageManager pm = mContext.getPackageManager();
try {
packageinfo = pm.getPackageInfo(packagename, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageinfo == null) {
return;
}
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
resolveIntent.setPackage(packageinfo.packageName);
// 通过getPackageManager()的queryIntentActivities方法遍历
List<ResolveInfo> resolveinfoList = pm.queryIntentActivities(resolveIntent, 0);
for (ResolveInfo resolveInfo : resolveinfoList) {
Log.d("", "resolveInfo:" + resolveInfo);
}
ResolveInfo resolveinfo = resolveinfoList.iterator().next();
if (resolveinfo != null) {
// packagename = 参数packname
String packageName = resolveinfo.activityInfo.packageName;
// 这个就是我们要找的该APP的LAUNCHER的Activity[组织形式packagename.mainActivityname]
String className = resolveinfo.activityInfo.name;
Drawable icon = resolveinfo.loadIcon(pm);
Bitmap APKicon;
if (icon instanceof BitmapDrawable) {
APKicon = ((BitmapDrawable) icon).getBitmap();
} else {
Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
icon.draw(canvas);
APKicon = bitmap;
}
Intent apkIntent = new Intent();
apkIntent.setClassName(packageName, className);
Intent shortcutIntent = new Intent("android.content.hr.action.shortcutsh");
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, APKicon);
shortcutIntent.putExtra("duplicate", false);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, resolveinfo.loadLabel(pm));
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, apkIntent);
shortcutIntent.setPackage("com.android.launcher3");
mContext.sendBroadcast(shortcutIntent);
}
}
public static void addShortcut(Context context) {
String result = Settings.System.getString(context.getContentResolver(), JGYActions.ACTION_JGY_SHORTCUTLIST);
if (TextUtils.isEmpty(result)) {
Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", "");
return;
}
Log.e("addShortcut", "addShortcut: " + result);
String[] stringList = result.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 (PackageNames.DEVICE_INFO.equals(s) || PackageNames.APPSTORE.equals(s)) {
continue;
}
if (ApkUtils.isSystemApp(context, s)) {
if (!appSet.contains(s)) {
continue;
}
}
if (!ApkUtils.isAvailable(context, s)) {
continue;
}
// ApkUtils.getStartActivityName(context, s);
if (installedListBuilder.length() > 0) {
installedListBuilder.append(",");
}
installedListBuilder.append(s);
Log.i("addShortcut", "packages: " + s);
}
String installedList = installedListBuilder.toString();
boolean aole_force_app = Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", installedList);
// String old = Settings.System.getString(context.getContentResolver(), "qch_launcher_icon_app");
// Log.e("addShortcut", old);
Log.e("addShortcut", "installedList:" + installedList);
Log.e("addShortcut", "putstring:" + aole_force_app);
}
private static Set<String> AoleyunOSApp = new HashSet<String>() {{
this.add("com.aoleyun.info");
this.add("com.aoleyun.os");
this.add("com.aoleyun.sn");
this.add("com.aoleyun.browser");
this.add("com.aoleyun.appstore");
this.add("com.aoleyunos.dop1");
this.add("com.aoleyunos.dop2");
this.add("com.aoleyunos.dop3");
this.add("com.aoleyunos.dop4");
this.add("com.aoleyunos.dop5");
this.add("com.aoleyunos.dop6");
this.add("com.aoleyunos.dop7");
this.add("com.aoleyunos.dop8");
this.add("com.aoleyunos.dop9");
this.add("com.aoleyunos.dop10");
this.add("com.jiepier.filemanager");
this.add("com.calendar.uiui");
this.add("com.notepad.uiui");
this.add("com.calculator.uiui");
this.add("com.alarmclock.uiui");
this.add("com.uiui.speed");
}};
public static String getRunningAppInfo(Context context) {
// ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// List<ActivityManager.RunningServiceInfo> infoList = activityManager.getRunningServices(Integer.MAX_VALUE);
//用来存储获取的应用信息数据
ArrayList<UploadAppInfo> appList = new ArrayList<>();
List<PackageInfo> packages = context.getPackageManager().getInstalledPackages(0);
String topPkg = ForegroundAppUtil.getForegroundPackageName(context);
Log.e(TAG, "getRunningAppInfo: " + topPkg);
for (PackageInfo packageInfo : packages) {
String packageName = packageInfo.packageName;
//排除出厂自带app
if (factoryapp.contains(packageName)) {
continue;
}
//排除所有系统应用,不显示
if (isSystemApp(context, packageName)) {
if (!AoleyunOSApp.contains(packageName) && !aihuaApp.contains(packageName)) {
continue;
}
} else {
//排除预装可以卸载的应用
if (canremove_systemapp.contains(packageName)) {
continue;
}
}
UploadAppInfo uploadAppInfo = new UploadAppInfo();
uploadAppInfo.setApp_name(packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString());
uploadAppInfo.setPackage_name(packageName);
Log.e("getRunningAppInfo", "getRunningAppInfo:" + packageName);
String firstInstallTime = TimeUtils.transferLongToDate(packageInfo.lastUpdateTime);
uploadAppInfo.setInstall_time(firstInstallTime);
uploadAppInfo.setVersionCode(String.valueOf(packageInfo.versionCode));
uploadAppInfo.setState(0);
uploadAppInfo.setApp_size(getPackageSize(context, packageInfo.applicationInfo.publicSourceDir));
uploadAppInfo.setVersionName(packageInfo.versionName);
// for (ActivityManager.RunningServiceInfo info : infoList) {
// if (info.process.contains(packageName)) {
// uploadAppInfo.setState(1);
// Log.e("getRunningAppInfo", "getRunningAppInfo running: " + packageName);
// }
// }
if (topPkg.equals(packageName)) {
uploadAppInfo.setState(1);
}
appList.add(uploadAppInfo);
}
Gson gson = new Gson();
String jsonString = gson.toJson(appList);
Log.e(TAG, "getRunningAppInfo: " + jsonString);
return jsonString;
}
public static void RemoveTask(final Context context, final String packageName) {
if (TextUtils.isEmpty(packageName)) {
return;
}
Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> e) throws Exception {
List<DownloadEntity> list = Aria.download(context).getTaskList();
for (DownloadEntity entity : list) {
long id = entity.getId();
String extendField = Aria.download(this).load(id).getExtendField();
JsonObject jsonObject = GsonUtils.getJsonObject(extendField);
if (packageName.equals(jsonObject.get("app_package").getAsString())) {
Log.e("RemoveTask", "subscribe: " + "删除文件:" + entity.getFilePath());
Aria.download(this).load(id).cancel(true);
}
}
e.onComplete();
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<String>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("RemoveTask", "onSubscribe: ");
}
@Override
public void onNext(String s) {
Log.e("RemoveTask", "onNext: ");
}
@Override
public void onError(Throwable e) {
Log.e("RemoveTask", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
Log.e("RemoveTask", "onComplete: ");
}
});
}
public static long getPackageSize(Context context, String filePath) {
long size = new File(filePath).length();
return size;
}
}