version:1.1.5

update:
bugfixes:优化闹钟自动接听
This commit is contained in:
2024-08-19 10:30:50 +08:00
parent 9f8057cd33
commit 261016b9bd
103 changed files with 2478 additions and 781 deletions

View File

@@ -19,19 +19,27 @@ import android.util.Log;
import androidx.annotation.RequiresApi;
import com.arialyy.aria.core.Aria;
import com.hjq.toast.Toaster;
import com.tencent.mmkv.MMKV;
import com.xxpatx.os.BuildConfig;
import com.xxpatx.os.activity.quickapp.QuickAppActivity;
import com.xxpatx.os.bean.AppInfo;
import com.xxpatx.os.bean.DesktopIcon;
import com.xxpatx.os.config.CommonConfig;
import com.xxpatx.os.gson.GsonUtils;
import com.xxpatx.os.manager.AppManager;
import com.xxpatx.os.manager.AppStatusManager;
import com.xxpatx.os.receiver.InstallResultReceiver;
import com.xxpatx.os.shortcut.ShortcutPkgInfo;
import com.xxpatx.os.shortcut.ShortcutUtils;
import java.io.BufferedReader;
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.text.Collator;
@@ -663,6 +671,141 @@ 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);
} else {
installApps(filePath);
}
}
public static boolean installApps(String apkPath) {
Toaster.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) {
Log.e("installApps1", e.getMessage());
} finally {
try {
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (Exception e) {
Log.e("installApps2", e.getMessage());
}
if (process != null) {
process.destroy();
}
}
Log.e("result", "" + errorMsg.toString());
//如果含有“success”认为安装成功
Log.e("installApp", successMsg.toString());
// if (!successMsg.toString().equalsIgnoreCase("success")) {
// install(context, new File(apkPath));
// }
return successMsg.toString().equalsIgnoreCase("success");
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void installAppatPie(Context context, String apkFilePath) {
File file = new File(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) {
install(packageInstaller, sessionId, context);
}
}
}
@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;
}
@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;
}
/**
* 静默卸载应用
*
@@ -764,4 +907,65 @@ public class ApkUtils {
return uid / PER_USER_RANGE;
}
public static boolean checkAppUpdate(Context context, AppInfo appUpdateInfo) {
String packageName = appUpdateInfo.getApp_package();
long versionCode = appUpdateInfo.getApp_version_code();
return checkAppUpdate(context, packageName, versionCode);
}
public static boolean checkAppUpdate(Context context, String packageName, long versionCode) {
PackageInfo packageInfo = null;
try {
packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null) {
return true;
} else {
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = packageInfo.getLongVersionCode();
} else {
appVersionCode = packageInfo.versionCode;
}
if (appVersionCode < versionCode) {
return true;
} else {
Log.e(TAG, "checkUpdate: " + packageName + "\t已经是最新版");
return false;
}
}
}
public static void ariaDownload(Context context, String url, AppInfo ariaDownloadInfo) {
Log.e(TAG, "ariaDownload: " + ariaDownloadInfo);
String fileName = Utils.getFileNamefromURL(url);
String app_md5 = ariaDownloadInfo.getApp_md5();
Log.e("ariaDownload", "app_md5 = " + app_md5);
File file = new File(Utils.getDownLoadPath(context) + fileName);
if (file.exists() && !file.isDirectory()) {
String fileMd5 = com.blankj.utilcode.util.FileUtils.getFileMD5ToString(file);
Log.e("ariaDownload", "fileMD5 = " + fileMd5);
if (fileMd5.equalsIgnoreCase(app_md5)) {
installApp(context, file.getAbsolutePath());
} else {
file.delete();
Aria.download(context)
.load(url) //读取下载地址
.setFilePath(Utils.getDownLoadPath(context) + fileName)
.ignoreFilePathOccupy()
.setExtendField(GsonUtils.toJSONString(ariaDownloadInfo))
.create(); //启动下载}
}
} else {
Aria.download(context)
.load(url) //读取下载地址
.setFilePath(Utils.getDownLoadPath(context) + fileName)
.ignoreFilePathOccupy()
.setExtendField(GsonUtils.toJSONString(ariaDownloadInfo))
.create(); //启动下载}
}
}
}