Merge branch 'feature/CWZS-80' into 'dev-5.29.0'

feat: 新增谷歌框架版本管理 https://jira.shanqu.cc/browse/CWZS-81

See merge request halo/android/assistant-android!1181
This commit is contained in:
陈君陶
2023-07-04 17:45:56 +08:00
6 changed files with 39 additions and 20 deletions

View File

@ -311,7 +311,7 @@ public class Config {
@SuppressLint("CheckResult")
public static void refreshVSettingEntity() {
RetrofitManager.getInstance()
.getVApi().getSettings(BuildConfig.VERSION_NAME)
.getVApi().getSettings(BuildConfig.VERSION_NAME, Build.VERSION.SDK_INT)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BiResponse<VSetting>() {

View File

@ -165,7 +165,7 @@ object DownloadMessageHandler : InnerDownloadListener {
* @param error 错误类型
* @param exception 包裹错误的 Exception
*/
override fun onError(id: String, error: DownloadError?, exception: Exception) {
override fun onError(id: String, error: DownloadError?, exception: Exception?) {
error ?: return
when (error) {

View File

@ -3,8 +3,8 @@ package com.gh.gamecenter.entity
import com.google.gson.annotations.SerializedName
class VSetting {
@SerializedName("va")
var va: Va? = null
var gsf: GApp? = null
class Va(
@SerializedName("32-bit")
@ -23,4 +23,9 @@ class VSetting {
val versionCode: Int,
val url: String
)
class GApp(
val url: String? = null,
var md5: String? = null
)
}

View File

@ -22,6 +22,6 @@ interface VApiService {
* 获取设置
*/
@GET("setting")
fun getSettings(@Query("version") version: String?): Single<VSetting>
fun getSettings(@Query("version") version: String?, @Query("android") androidSdkVersion: Int): Single<VSetting>
}

View File

@ -23,7 +23,6 @@ import com.gh.download.DownloadManager
import com.gh.download.PackageObserver
import com.gh.gamecenter.R
import com.gh.gamecenter.SplashScreenActivity
import com.gh.gamecenter.common.BuildConfig
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.eventbus.EBReuse
import com.gh.gamecenter.common.exposure.meta.MetaUtil
@ -73,9 +72,7 @@ object VHelper {
const val KEY_REQUIRED_G_APPS = "required_g_apps"
const val G_APPS_DOWNLOAD_ID = "d673761a1dc031d40afc90d0a6efd25a"
const val G_APPS_DOWNLOAD_DEV_URL =
"https://dev-and-static.ghzs.com/game/apk/smooth_google/google_play_services.zip"
const val G_APPS_DOWNLOAD_URL = "https://and-static.ghzs.com/game/apk/smooth_google/google_play_services.zip"
const val G_APPS_INSTALLED_MD5 = "g_apps_installed_md5"
// 畅玩游戏位数
const val KEY_BIT = "bit"

View File

@ -9,15 +9,16 @@ import android.view.View
import android.view.animation.DecelerateInterpolator
import androidx.core.text.bold
import androidx.core.text.color
import com.gh.common.constant.Config
import com.gh.common.util.NewFlatLogUtils
import com.gh.download.simple.*
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.fragment.BaseBottomDialogFragment
import com.gh.gamecenter.common.utils.EnvHelper
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.core.AppExecutor
import com.gh.gamecenter.core.runOnIoThread
import com.gh.gamecenter.core.runOnUiThread
import com.gh.gamecenter.core.utils.SPUtils
import com.gh.gamecenter.core.utils.ToastUtils
import com.gh.gamecenter.core.utils.UnZipUtils
import com.gh.gamecenter.databinding.DialogGappsDownloadBinding
@ -69,6 +70,8 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment<DialogGappsDownload
showSuccessStyle()
mInstallSuccess = true
NewFlatLogUtils.logGAppsInstallSuccess(mGameId, mGameName, elapsedTime.toInt())
SPUtils.setString(VHelper.G_APPS_INSTALLED_MD5, Config.getVSettingEntity()?.gsf?.md5 ?: "")
clearCaches()
} else {
mInstallSuccess = false
@ -149,6 +152,9 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment<DialogGappsDownload
return
}
mBinding.downloadButton.text = "安装中"
mBinding.downloadButton.buttonStyle = DownloadButton.ButtonStyle.DOWNLOADING_NORMAL
if (mGAppsUnZipDestFile.listFiles()?.size != 3) {
// 畅玩功能仅支持 7.1 以后的设备,所以这里的这个判断条件不需要 else
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
@ -158,7 +164,20 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment<DialogGappsDownload
File(downloadEntity.dirPath + downloadEntity.fileName),
mGAppsUnZipDestPath
)
batchInstall(mGAppsUnZipDestFile)
var isZipFileValid = mGAppsUnZipDestFile.listFiles()?.size == 3
mGAppsUnZipDestFile.listFiles()?.forEach {
if (!it.name.endsWith("apk")) {
isZipFileValid = false
}
}
if (isZipFileValid) {
batchInstall(mGAppsUnZipDestFile)
} else {
SimpleDownloadManager.cancel(VHelper.G_APPS_DOWNLOAD_ID)
resetDownloadStatus(IllegalArgumentException("谷歌框架文件异常,安装失败"))
}
} catch (e: Exception) {
resetDownloadStatus(e)
}
@ -168,10 +187,14 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment<DialogGappsDownload
batchInstall(mGAppsUnZipDestFile)
}
mBinding.downloadButton.text = "安装中"
mBinding.downloadButton.buttonStyle = DownloadButton.ButtonStyle.DOWNLOADING_NORMAL
mBinding.downloadButton.setOnClickListener {
// 处理接口没有返回谷歌框架相关数据的情况
if (Config.getVSettingEntity()?.gsf == null || Config.getVSettingEntity()?.gsf?.url == null) {
ToastUtils.toast("谷歌框架获取异常,请稍候再试")
mBinding.cancelTv.performClick()
return@setOnClickListener
}
if (mInstallSuccess) {
VHelper.launch(requireContext(), mTriggerPackageName)
NewFlatLogUtils.logGAppsInstalledAndLaunchGame(mGameId, mGameName)
@ -248,13 +271,7 @@ class GAppsDownloadDialogFragment : BaseBottomDialogFragment<DialogGappsDownload
DownloadConfigBuilder()
.setUniqueId(VHelper.G_APPS_DOWNLOAD_ID)
.setFileName(VHelper.G_APPS_DOWNLOAD_ID + ".zip")
.apply {
if (EnvHelper.isDevEnv) {
setUrl(VHelper.G_APPS_DOWNLOAD_DEV_URL)
} else {
setUrl(VHelper.G_APPS_DOWNLOAD_URL)
}
}
.setUrl(Config.getVSettingEntity()?.gsf?.url ?: "")
.setPathToStore(requireContext().filesDir.absolutePath + File.separator)
.setHttpClient(DefaultHttpClient())
.setDownloadThreadSize(2)