fix: 优化部分启动逻辑&修复个别游戏因为安装架构选择导致黑屏无法启动

This commit is contained in:
yangfei
2024-03-05 14:35:32 +08:00
parent dc6eb0b850
commit 58ba6cecf5

View File

@ -69,6 +69,8 @@ import com.lightgame.download.DownloadEntity
import com.lightgame.utils.AppManager
import com.lightgame.utils.Utils
import com.va.host.HostUtils
import io.reactivex.Completable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject
import org.greenrobot.eventbus.EventBus
@ -115,6 +117,7 @@ object VHelper {
private var m32UpdateEntity: AppEntity? = null
private var mIsInitialized = false // 是否已初始化
private var mMustInitialized = false // 是否已必须初始化
private var mIsServiceConnected = false // AIDL 服务是否成功连接,不可作为 AIDL 仍然可用的依据
private var mShouldLaunchGameAfterInstallation = true // 是否需要在安装完成后启动游戏的开关
@ -217,12 +220,29 @@ object VHelper {
@SuppressLint("CheckResult")
@JvmStatic
fun init(context: Context) {
Completable.fromAction {
refreshVGameSnapshot()
}.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
onInit(context)
}
}
private fun onInit(context: Context) {
if (!mMustInitialized) {
mMustInitialized = true
VArchiveHelper.init()
val allGames = mVGameSnapshotList.map { it.packageName }.toArrayList()
if (allGames.isNotEmpty()) {
PackageRepository.addInstalledGames(allGames, true)
}
}
if (isVGameOn()) {
if (!mIsInitialized) {
mIsInitialized = true
VArchiveHelper.init()
if (isVIsUsed()) {
connectService(shouldCheckUpdate = true)
}
@ -248,35 +268,29 @@ object VHelper {
mIsAppVisible = false
}
})
runOnIoThread {
val allGames = vGameDao.getAll().map { it.packageName }.toArrayList()
if (allGames.isNotEmpty()) {
PackageRepository.addInstalledGames(allGames, true)
}
}
}
checkVspaceUpdate(context)
}
}
val config = Config.getVSettingEntity()?.va
if (config?.arch64 != null
&& m64UpdateEntity == null
&& PackageUtils.isInstalledFromAllPackage(context, config.arch64.packageName)
) {
// 检查畅玩助手 64 位组件更新
getVSpaceUpdate(config.arch64, true)
}
private fun checkVspaceUpdate(context: Context) {
val config = Config.getVSettingEntity()?.va
if (config?.arch32 != null
&& m32UpdateEntity == null
&& PackageUtils.isInstalledFromAllPackage(context, config.arch32.packageName)
) {
// 检查畅玩助手 32 位组件更新
getVSpaceUpdate(config.arch32, false)
}
if (config?.arch64 != null
&& m64UpdateEntity == null
&& PackageUtils.isInstalledFromAllPackage(context, config.arch64.packageName)
) {
// 检查畅玩助手 64 位组件更新
getVSpaceUpdate(config.arch64, true)
}
runOnIoThread {
refreshVGameSnapshot()
}
if (config?.arch32 != null
&& m32UpdateEntity == null
&& PackageUtils.isInstalledFromAllPackage(context, config.arch32.packageName)
) {
// 检查畅玩助手 32 位组件更新
getVSpaceUpdate(config.arch32, false)
}
}
@ -284,6 +298,7 @@ object VHelper {
* 手动刷新畅玩游戏快照列表
*/
@WorkerThread
@Synchronized
fun refreshVGameSnapshot() {
try {
mVGameSnapshotList = ArrayList(vGameDao.getAll())
@ -316,7 +331,7 @@ object VHelper {
BuildConfig.AIDL_SERVER_PACKAGE_NAME
)
if (!isOldCwInstalled) {
Utils.log(LOG_TAG, "包名[${BuildConfig.AIDL_SERVER_PACKAGE_NAME}]应用没有安装")
Utils.log(LOG_TAG, "分体式畅玩没有安装")
return
}
if (!shouldConnectSilently) {
@ -806,23 +821,6 @@ object VHelper {
return ArrayList(list)
}
private fun gotoVspaceLoading(
context: Context,
downloadEntity: DownloadEntity,
shouldLaunchGameAfterInstallation: Boolean
) {
if (shouldLaunchGameAfterInstallation) {
runOnUiThread {
val gameEntity = toGameEntity(downloadEntity)
try {
context.startActivity(VSpaceLoadingActivity.getIntent(context, gameEntity, true))
} catch (e: Exception) {
ToastUtils.toast(e.localizedMessage ?: "启动游戏异常,请稍候再试")
}
}
}
}
/**
* 安装新游戏
* 正常的游戏使用这个方法来安装,内部有重试处理
@ -835,6 +833,7 @@ object VHelper {
Utils.log(LOG_TAG, "尝试安装新游戏 ${downloadEntity.path}")
// 如果一个游戏存在旧版畅玩助手内,此次安装就是游戏更新
val isLegacyGame = isLegacyInstalled(downloadEntity.packageName)
Utils.log(LOG_TAG, "${downloadEntity.packageName} ${if (isLegacyGame) "是旧畅玩助手的游戏" else "是新畅玩组件的游戏"}")
// 更新此包名对应的 gameId Map
mTempPackageNameAndGameIdMap[downloadEntity.packageName] = downloadEntity.gameId
@ -859,7 +858,16 @@ object VHelper {
mShouldLaunchGameAfterInstallation = true
val installClosure: () -> Unit = {
gotoVspaceLoading(context, downloadEntity, shouldLaunchGameAfterInstallation)
if (shouldLaunchGameAfterInstallation) {
runOnUiThread {
val gameEntity = toGameEntity(downloadEntity)
try {
context.startActivity(VSpaceLoadingActivity.getIntent(context, gameEntity, true))
} catch (e: Exception) {
ToastUtils.toast(e.localizedMessage ?: "启动游戏异常,请稍候再试")
}
}
}
val path = downloadEntity.path
// 正在安装中,忽略重复调用 (手动安装时强行再安装,避免安装结果没有回调时永远卡住,无法安装)
@ -876,16 +884,13 @@ object VHelper {
}
} else {
runOnIoThread {
val bit = downloadEntity.getMetaExtra(KEY_BIT)
val installParams =
VGameInstallerParams(VGameInstallerParams.FLAG_INSTALL_OVERRIDE_NO_CHECK)
if (bit == "32") {
installParams.cpuAbiOverride = "armeabi-v7a"
} else {
installParams.cpuAbiOverride = "arm64-v8a"
}
val installGameResult = VaApp.get().appManager.installGame(path, installParams)
onInstallFinished(downloadEntity.packageName, installGameResult)
onInstallFinished(
downloadEntity.packageName,
VaApp.get().appManager.installGame(
path,
VGameInstallerParams(VGameInstallerParams.FLAG_INSTALL_OVERRIDE_NO_CHECK)
)
)
}
}