Commit d84e8318 by pye52

优化installDaemonFromAssets方法,不再向参数传入字符串

parent 7eb29a76
...@@ -46,9 +46,7 @@ public class InstallManager { ...@@ -46,9 +46,7 @@ public class InstallManager {
// 检查守护进程的安装情况,及其安装版本 // 检查守护进程的安装情况,及其安装版本
if (!AppUtils.isAppInstalled(DAEMON_PACKAGE_NAME)) { if (!AppUtils.isAppInstalled(DAEMON_PACKAGE_NAME)) {
LogUtils.d(TAG, "守护app未安装,从assets复制并进行安装"); LogUtils.d(TAG, "守护app未安装,从assets复制并进行安装");
// 安装守护进程 if (installDaemonFromAssets(false)) {
if (installDaemonFromAssets("守护app安装失败,启动静默安装",
"assets文件夹中未找到守护apk,或守护app复制失败,启动静默安装")) {
return DangerousUtils.installAppSilent(updateApk); return DangerousUtils.installAppSilent(updateApk);
} }
} else { } else {
...@@ -56,8 +54,7 @@ public class InstallManager { ...@@ -56,8 +54,7 @@ public class InstallManager {
AppUtils.AppInfo daemonAppInfo = AppUtils.getAppInfo(DAEMON_PACKAGE_NAME); AppUtils.AppInfo daemonAppInfo = AppUtils.getAppInfo(DAEMON_PACKAGE_NAME);
if (daemonAppInfo.getVersionCode() < BuildConfig.DaemonVersion) { if (daemonAppInfo.getVersionCode() < BuildConfig.DaemonVersion) {
LogUtils.d(TAG, "当前守护app版本: " + daemonAppInfo.getVersionCode() + ", 最新版本: " + BuildConfig.DaemonVersion); LogUtils.d(TAG, "当前守护app版本: " + daemonAppInfo.getVersionCode() + ", 最新版本: " + BuildConfig.DaemonVersion);
if (installDaemonFromAssets("守护app更新失败,启动静默安装", if (installDaemonFromAssets(true)) {
"新版app复制失败,启动静默安装")) {
return DangerousUtils.installAppSilent(updateApk); return DangerousUtils.installAppSilent(updateApk);
} }
} }
...@@ -85,18 +82,18 @@ public class InstallManager { ...@@ -85,18 +82,18 @@ public class InstallManager {
fos.close(); fos.close();
} }
private static boolean installDaemonFromAssets(String installFailedLog, String copyErrorLog) { private static boolean installDaemonFromAssets(boolean update) {
File daemonApk = new File(PathUtils.getExternalStoragePath(), DAEMON_APK_NAME); File daemonApk = new File(PathUtils.getExternalStoragePath(), DAEMON_APK_NAME);
try { try {
copyDaemonApkToTarget(daemonApk); copyDaemonApkToTarget(daemonApk);
boolean result = DangerousUtils.installAppSilent(daemonApk); boolean result = DangerousUtils.installAppSilent(daemonApk);
LogUtils.d(TAG, "守护app安装结果: " + result); LogUtils.d(TAG, "守护app安装结果: " + result);
if (!result) { if (!result) {
LogUtils.d(TAG, installFailedLog); LogUtils.d(TAG, "守护app" + (update ? "更新" : "安装") + "失败,启动静默安装");
return true; return true;
} }
} catch (IOException e) { } catch (IOException e) {
LogUtils.d(TAG, "复制安装过程出错: " + copyErrorLog, e); LogUtils.d(TAG, update ? "assets文件夹中未找到守护apk,或守护app复制失败,启动静默安装" : "新版app复制失败,启动静默安装", e);
return true; return true;
} finally { } finally {
FileUtils.delete(daemonApk); FileUtils.delete(daemonApk);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment