Merge branch 'fix/gapps_install_issue' into 'release'
fix: 修复畅玩安装谷歌框架时应用切换到后台返回时安装卡住的问题 See merge request halo/android/assistant-android!1081
This commit is contained in:
@ -121,7 +121,7 @@ object VHelper {
|
||||
private var mBatchInstallMap = hashMapOf<String, File>()
|
||||
|
||||
// 批量安装的监听
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment<DialogGappsDownload
|
||||
|
||||
private var mIsInstalling = false // 是否正在安装,避免重复触发
|
||||
private var mRequiredAutoInstall = false // 是否需要自动安装(下载完成后自动安装)
|
||||
private var mRequiredReTriggerInstall = false // 是否需要重新触发安装(因为切换到后台被中断)
|
||||
private var mInstallSuccess = false // 安装是否已经成功
|
||||
private var mInstallProgressAnimator: ValueAnimator? = null
|
||||
|
||||
@ -52,22 +53,28 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment<DialogGappsDownload
|
||||
File(mGAppsUnZipDestPath).also { if (!it.exists()) it.mkdir() }
|
||||
}
|
||||
|
||||
private val mBatchInstallListener: (isSuccess: Boolean) -> 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<DialogGappsDownload
|
||||
NewFlatLogUtils.logGAppsDialogShowed(mGameId, mGameName)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// 执行安装重试
|
||||
if (mRequiredReTriggerInstall) {
|
||||
batchInstall(mGAppsUnZipDestFile)
|
||||
mRequiredReTriggerInstall = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateViewByDownload(downloadEntity: SimpleDownloadEntity?) {
|
||||
if (downloadEntity != null) {
|
||||
updateViewByDownloadStatus(downloadEntity.status)
|
||||
@ -291,7 +308,7 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment<DialogGappsDownload
|
||||
|
||||
runOnUiThread {
|
||||
mInstallProgressAnimator = ValueAnimator.ofInt(500, 1000)
|
||||
mInstallProgressAnimator?.duration = 10 * 1000L
|
||||
mInstallProgressAnimator?.duration = INSTALL_ANIMATION_DURATION
|
||||
mInstallProgressAnimator?.interpolator = DecelerateInterpolator()
|
||||
mInstallProgressAnimator?.addUpdateListener {
|
||||
mBinding.downloadButton.progress = it.animatedValue as Int
|
||||
@ -333,6 +350,7 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment<DialogGappsDownload
|
||||
private const val TRIGGER_PACKAGE_NAME = "trigger_package_name" // 触发弹窗的原始游戏包名
|
||||
private const val GAME_ID = "game_id"
|
||||
private const val GAME_NAME = "game_name"
|
||||
private const val INSTALL_ANIMATION_DURATION = 30 * 1000L // 安装动画时长
|
||||
|
||||
fun getInstance(packageName: String, gameId: String, gameName: String): GAppsDownloadDialogFragment {
|
||||
return GAppsDownloadDialogFragment().also {
|
||||
|
||||
Reference in New Issue
Block a user