version:1.7.9
date:2021-11-01 14:02:44 fix:修复唤醒 add:
This commit is contained in:
@@ -126,8 +126,7 @@ public class ApkUtils {
|
||||
|
||||
/**
|
||||
* 根据包名卸载应用
|
||||
*
|
||||
* @param packageName
|
||||
* @param packageName 包名
|
||||
*/
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public static void uninstall(Context context, String packageName) {
|
||||
@@ -351,6 +350,11 @@ public class ApkUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过路径安装APK,兼容Android 9以上
|
||||
* @param context 上下文
|
||||
* @param filePath apk文件路径
|
||||
*/
|
||||
public static void installApp(Context context, String filePath) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
installAppatPie(context, filePath);
|
||||
@@ -360,7 +364,7 @@ public class ApkUtils {
|
||||
}
|
||||
|
||||
public static boolean installApps(String apkPath) {
|
||||
ToastUtil.show("正在安装应用...");
|
||||
ToastUtil.show("正在安装应用");
|
||||
Process process = null;
|
||||
BufferedReader successResult = null;
|
||||
BufferedReader errorResult = null;
|
||||
@@ -398,7 +402,7 @@ public class ApkUtils {
|
||||
//如果含有“success”认为安装成功
|
||||
Log.e("installApp", successMsg.toString());
|
||||
// if (!successMsg.toString().equalsIgnoreCase("success")) {
|
||||
// ApkUtils.install(context, new File(apkPath));
|
||||
// install(context, new File(apkPath));
|
||||
// }
|
||||
return successMsg.toString().equalsIgnoreCase("success");
|
||||
}
|
||||
@@ -414,40 +418,11 @@ public class ApkUtils {
|
||||
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;
|
||||
@@ -481,11 +456,38 @@ public class ApkUtils {
|
||||
return success;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
public static void uninstallApp(Context context, String packageName) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
ApkUtils.uninstall(context, packageName);
|
||||
uninstall(context, packageName);
|
||||
} else {
|
||||
ApkUtils.deleteApkInSilence(packageName);
|
||||
deleteApkInSilence(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,7 +503,8 @@ public class ApkUtils {
|
||||
pmService = PackageManagerService.getClass();
|
||||
Class<?> paramTypes1[] = getParamTypes(pmService, "deletePackageAsUser");
|
||||
method = pmService.getMethod("deletePackageAsUser", paramTypes1);
|
||||
method.invoke(PackageManagerService, packageName, null, getUserId(Binder.getCallingUid()), 0x00000040);//getUserId
|
||||
//getUserId
|
||||
method.invoke(PackageManagerService, packageName, null, getUserId(Binder.getCallingUid()), 0x00000040);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
@@ -513,7 +516,6 @@ public class ApkUtils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static Class<?>[] getParamTypes(Class<?> cls, String mName) {
|
||||
Class<?> cs[] = null;
|
||||
Method[] mtd = cls.getMethods();
|
||||
@@ -521,7 +523,6 @@ public class ApkUtils {
|
||||
if (!mtd[i].getName().equals(mName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cs = mtd[i].getParameterTypes();
|
||||
}
|
||||
return cs;
|
||||
@@ -702,10 +703,10 @@ public class ApkUtils {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!ApkUtils.isAvailable(context, s)) {
|
||||
if (!isAvailable(context, s)) {
|
||||
continue;
|
||||
}
|
||||
// ApkUtils.getStartActivityName(context, s);
|
||||
// getStartActivityName(context, s);
|
||||
if (installedListBuilder.length() > 0) {
|
||||
installedListBuilder.append(",");
|
||||
}
|
||||
@@ -722,13 +723,14 @@ public class ApkUtils {
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public static void writeAppPackageList(Context context, String result) {
|
||||
ApkUtils.addShortcut(context);//开机之后添加图标到桌面
|
||||
addShortcut(context);//开机之后添加图标到桌面
|
||||
|
||||
List<String> factoryAppList = new ArrayList<String>() {{
|
||||
this.add("com.jiaoguanyi.appstore");
|
||||
this.add("com.jiaoguanyi.store");
|
||||
this.add("com.info.sn");
|
||||
this.add("com.appstore.uiui");
|
||||
this.add("com.jgyapp.market");
|
||||
this.add("com.android.uiuios");
|
||||
this.add("com.uiuios.jgy1");
|
||||
this.add("com.uiuios.jgy2");
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.blankj.utilcode.util.PathUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -70,19 +71,19 @@ public class FileUtils {
|
||||
} else {
|
||||
Aria.download(context)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/jgy/" + fileName, true)
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName)
|
||||
.ignoreFilePathOccupy()
|
||||
.setExtendField(jsonObject.toJSONString())
|
||||
.create(); //启动下载}
|
||||
// SaveListUtils.addDownLoadList(app_package);
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
Aria.download(context)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/jgy/" + fileName, true)
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName)
|
||||
.ignoreFilePathOccupy()
|
||||
.setExtendField(jsonObject.toJSONString())
|
||||
.create(); //启动下载}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,12 @@ public class JGYUtils {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public static String getAuthorization() {
|
||||
// TODO: 2021/10/19 ndk代码待实现
|
||||
return "Basic ZWRmOWNlYzIyNzMxYjhiMmZlZDU2ZWU2OmIzYWRlZDRmODk5N2E0ODM5ZTI5MjRjYg==";
|
||||
}
|
||||
|
||||
|
||||
public static boolean isOfficialVersion() {
|
||||
String channelValue = JGYUtils.getInstance().getStringMetaData();
|
||||
return "official".equals(channelValue);
|
||||
@@ -88,6 +94,22 @@ public class JGYUtils {
|
||||
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) {
|
||||
@@ -189,24 +211,6 @@ public class JGYUtils {
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统应用hook使用webview
|
||||
*/
|
||||
@@ -384,17 +388,38 @@ public class JGYUtils {
|
||||
|
||||
public static String getCustomVersion() {
|
||||
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
|
||||
return Utils.getProperty("ro.build.display.id", "获取失败");
|
||||
return getProperty("ro.build.display.id", "获取失败");
|
||||
} else {
|
||||
return Utils.getProperty("ro.custom.build.version", "获取失败");
|
||||
return getProperty("ro.custom.build.version", "获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
public static String getRomVersion() {
|
||||
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
|
||||
return Utils.getProperty("ro.build.id", "获取失败");
|
||||
return getProperty("ro.build.id", "获取失败");
|
||||
} else {
|
||||
return Utils.getProperty("ro.build.display.id", "获取失败");
|
||||
return getProperty("ro.build.display.id", "获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取系统配置信息
|
||||
*
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty(String key, String defaultValue) {
|
||||
String value = defaultValue;
|
||||
try {
|
||||
Class<?> c = Class.forName("android.os.SystemProperties");
|
||||
Method get = c.getMethod("get", String.class, String.class);
|
||||
value = (String) (get.invoke(c, key, "unknown"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,8 +626,9 @@ public class JGYUtils {
|
||||
Intent intent = new Intent(UPDATE_FORBID_APP);
|
||||
intent.putStringArrayListExtra("forbid_app_list", getForbidList(context));
|
||||
Log.e(TAG, "updateForbidList: " + getForbidList(context));
|
||||
// intent.setComponent(new ComponentName("com.jiaoguanyi.os","com.jiaoguanyi.os.view.MainActivity"));
|
||||
intent.setPackage("com.jiaoguanyi.os");
|
||||
intent.setPackage("com.tt.ttutils");
|
||||
// intent.setPackage("com.tt.ttutils");
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
@@ -621,8 +647,9 @@ public class JGYUtils {
|
||||
public static void updateHideList(Context context) {
|
||||
Intent intent = new Intent(UPDATE_HIDE_APP);
|
||||
intent.putStringArrayListExtra("hide_app_list", getHideList(context));
|
||||
// intent.setComponent(new ComponentName("com.jiaoguanyi.os","com.jiaoguanyi.os.view.MainActivity"));
|
||||
intent.setPackage("com.jiaoguanyi.os");
|
||||
intent.setPackage("com.tt.ttutils");
|
||||
// intent.setPackage("com.tt.ttutils");
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
|
||||
@@ -1155,26 +1155,6 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统配置信息
|
||||
*
|
||||
* @param key
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty(String key, String defaultValue) {
|
||||
String value = defaultValue;
|
||||
try {
|
||||
Class<?> c = Class.forName("android.os.SystemProperties");
|
||||
Method get = c.getMethod("get", String.class, String.class);
|
||||
value = (String) (get.invoke(c, key, "unknown"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getMachine(Context context) {
|
||||
String device = Build.MODEL;//机型
|
||||
String imei = getIMEI(context);
|
||||
|
||||
Reference in New Issue
Block a user