diff --git a/app/src/main/java/com/gh/vspace/VHelper.kt b/app/src/main/java/com/gh/vspace/VHelper.kt index dcdaae3b8d..b6b33b0141 100644 --- a/app/src/main/java/com/gh/vspace/VHelper.kt +++ b/app/src/main/java/com/gh/vspace/VHelper.kt @@ -121,7 +121,7 @@ object VHelper { private var mBatchInstallMap = hashMapOf() // 批量安装的监听 - private var mBatchInstallListener: ((isSuccess: Boolean) -> Unit)? = null + private var mBatchInstallListener: ((isSuccess: Boolean, interrupted: Boolean) -> Unit)? = null // 批量安装失败的统计 private var mBatchInstallFailedCount = 0 @@ -131,6 +131,7 @@ object VHelper { // 下次应用可见时是否需要尝试重连 private var mShouldReConnectOnVisible = false + // 是否已经尝试过重连 private var mHasAlreadyTriedReConnect = false @@ -741,7 +742,7 @@ object VHelper { /** * 注册批量安装结果回调,值为空时为取消注册 */ - fun registerBatchInstallListener(listener: ((isSuccess: Boolean) -> Unit)? = null) { + fun registerBatchInstallListener(listener: ((isSuccess: Boolean, isInterrupted: Boolean) -> Unit)? = null) { mBatchInstallListener = listener } @@ -759,9 +760,17 @@ object VHelper { val path = file.path if (!mInstallingVaPathSet.contains(path)) { try { - mInstallingVaPathSet.add(path) - runOnUiThread { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q + && !PackageUtils.isAppOnForeground(context) + ) { + mBatchInstallListener?.invoke(false, true) + Utils.log(LOG_TAG, "应用切换至后台,批量安装被打断") + return@runOnUiThread + } + + mInstallingVaPathSet.add(path) + val intent = VirtualAppManager.getInstallIntent(context, path, packageName) Utils.log(LOG_TAG, "正在安装 $packageName") @@ -832,7 +841,7 @@ object VHelper { if (result.status == 0) { updateInstalledList() } else { - Utils.log(LOG_TAG, "安装出现异常, ${result.status}") + ToastUtils.toast("安装出现异常, ${result.status}") } } @@ -864,7 +873,7 @@ object VHelper { if (mBatchInstallMap.size == 0) { runOnUiThread { // 批量安装完成后回调成功/失败事件 - mBatchInstallListener?.invoke(mBatchInstallFailedCount == 0) + mBatchInstallListener?.invoke(mBatchInstallFailedCount == 0, false) } } } diff --git a/app/src/main/java/com/gh/vspace/gapps/GAppsDownloadDialogFragment.kt b/app/src/main/java/com/gh/vspace/gapps/GAppsDownloadDialogFragment.kt index 9e12f87007..a6b626db9e 100644 --- a/app/src/main/java/com/gh/vspace/gapps/GAppsDownloadDialogFragment.kt +++ b/app/src/main/java/com/gh/vspace/gapps/GAppsDownloadDialogFragment.kt @@ -34,6 +34,7 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment Unit = { isSuccess -> - val elapsedTime = - (System.currentTimeMillis() - mGAppsDownloadAndInstallStartTimestampMills + mGAppsDownloadAndInstallElapsedTimeMills) / 1000 - - mGAppsDownloadAndInstallStartTimestampMills = 0L - mGAppsDownloadAndInstallElapsedTimeMills = 0L - - if (isSuccess) { - showSuccessStyle() - mInstallSuccess = true - NewFlatLogUtils.logGAppsInstallSuccess(mGameId, mGameName, elapsedTime.toInt()) - clearCaches() + private val mBatchInstallListener: (isSuccess: Boolean, isInterrupted: Boolean) -> Unit = { isSuccess, isInterrupted -> + if (isInterrupted) { + // 安装过程被打断 + mIsInstalling = false + mRequiredReTriggerInstall = true } else { - mInstallSuccess = false - NewFlatLogUtils.logGAppsInstallFailed(mGameId, mGameName, elapsedTime.toInt()) - resetDownloadStatus(null) + val elapsedTime = + (System.currentTimeMillis() - mGAppsDownloadAndInstallStartTimestampMills + mGAppsDownloadAndInstallElapsedTimeMills) / 1000 + + mGAppsDownloadAndInstallStartTimestampMills = 0L + mGAppsDownloadAndInstallElapsedTimeMills = 0L + + if (isSuccess) { + showSuccessStyle() + mInstallSuccess = true + NewFlatLogUtils.logGAppsInstallSuccess(mGameId, mGameName, elapsedTime.toInt()) + clearCaches() + } else { + mInstallSuccess = false + NewFlatLogUtils.logGAppsInstallFailed(mGameId, mGameName, elapsedTime.toInt()) + resetDownloadStatus(null) + } } } @@ -113,6 +120,16 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment