feat:补充畅玩相关的安装、启动埋点

This commit is contained in:
yangfei
2024-05-09 14:25:20 +08:00
parent c3b32bae03
commit 8dc9921be8
5 changed files with 108 additions and 35 deletions

View File

@ -63,6 +63,7 @@ import com.lg.vspace.VaApp
import com.lg.vspace.VirtualAppManager
import com.lg.vspace.archive.ArchiveExtHelper
import com.lg.vspace.bridge.BuildConfig
import com.lg.vspace.meta.ProcessUtils
import com.lg.vspace.plugin.host.PluginFileUtils
import com.lg.vspace.plugin.host.PluginHelper
import com.lg.vspace.remote.BinderPool
@ -70,10 +71,13 @@ import com.lg.vspace.remote.listener.RemoteConnectListener
import com.lg.vspace.remote.model.AppInstallerInfo
import com.lg.vspace.remote.model.VGameInstallerParams
import com.lg.vspace.remote.model.VGameInstallerResult
import com.lg.vspace.remote.model.VGameInstallerResult.STATUS_SUCCESS
import com.lightgame.download.DownloadEntity
import com.lightgame.utils.AppManager
import com.lightgame.utils.Utils
import com.lody.virtual.client.core.VirtualCore
import com.va.host.HostUtils
import com.walkud.rom.checker.RomIdentifier
import io.reactivex.Completable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
@ -84,6 +88,9 @@ import java.util.*
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.TimeUnit
import com.lg.vspace.log.NewFlatLogUtils as CwLogUtils
object VHelper {
// 畅玩游戏是否已被使用过
@ -93,6 +100,9 @@ object VHelper {
private const val KEY_LAST_ALERT_32_UPDATE_URL = "last_alert_32_update_url"
private const val KEY_TOTAL_PLAYED_TIME = "total_played_time"
// 新增畅玩启动次数
private const val KEY_LAUNCH_COUNT = "launch_count"
private const val G_GMS_PACKAGE_NAME = "com.google.android.gms"
private const val G_VENDING_PACKAGE_NAME = "com.android.vending"
private const val G_GSF_PACKAGE_NAME = "com.google.android.gsf"
@ -907,12 +917,47 @@ object VHelper {
}
} else {
runOnIoThread {
val cwBaseLogParams = getCwBaseLogParams()
val start = System.currentTimeMillis()
// 开始安装游戏
CwLogUtils.logBeforeGameLaunch(mutableMapOf<String, String>().apply {
put(CwLogUtils.KEY_EVENT, "game_install_began")
put(CwLogUtils.KEY_GAME_ID, downloadEntity.gameId)
put(CwLogUtils.KEY_PACKAGE_NAME, downloadEntity.packageName)
putAll(cwBaseLogParams)
})
val installResult = VaApp.get().appManager.installGame(
path,
VGameInstallerParams(VGameInstallerParams.FLAG_INSTALL_OVERRIDE_NO_CHECK)
)
val timeCost = (System.currentTimeMillis() - start) / 1000L
if (installResult.status == STATUS_SUCCESS) {
// 安装游戏完成
CwLogUtils.logBeforeGameLaunch(mutableMapOf<String, String>().apply {
put(CwLogUtils.KEY_EVENT, "game_install_complete")
put(CwLogUtils.KEY_GAME_ID, downloadEntity.gameId)
put(CwLogUtils.KEY_PACKAGE_NAME, downloadEntity.packageName)
put("install_time", "$timeCost")
putAll(cwBaseLogParams)
})
} else {
// 安装游戏失败
CwLogUtils.logBeforeGameLaunch(mutableMapOf<String, String>().apply {
put(CwLogUtils.KEY_EVENT, "game_install_fail")
put(CwLogUtils.KEY_GAME_ID, downloadEntity.gameId)
put(CwLogUtils.KEY_PACKAGE_NAME, downloadEntity.packageName)
put(
"crash_message", when (installResult.status) {
VGameInstallerResult.STATUS_RETURN_NULL_OBJECT -> "server进程远程调用崩溃"
else -> "错误码:${installResult.status}"
}
)
putAll(cwBaseLogParams)
})
}
onInstallFinished(
downloadEntity.packageName,
VaApp.get().appManager.installGame(
path,
VGameInstallerParams(VGameInstallerParams.FLAG_INSTALL_OVERRIDE_NO_CHECK)
)
installResult
)
}
}
@ -1033,6 +1078,7 @@ object VHelper {
mInstallingVaPathSet.remove(downloadEntity.path)
try {
downloadEntity.addMetaExtra(KEY_LAUNCH_COUNT, "0")
vGameDao.insert(VGameEntity.from(downloadEntity))
refreshVGameSnapshot()
} catch (e: SQLiteFullException) {
@ -1298,6 +1344,10 @@ object VHelper {
intent.putExtra("pluginId", it.id)
intent.putExtra("pluginVersionName", it.versionName)
}
downloadEntity?.getMetaExtra(KEY_LAUNCH_COUNT)?.toIntOrNull()?.let { count ->
intent.putExtra(KEY_LAUNCH_COUNT, count)
}
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
@ -1525,6 +1575,9 @@ object VHelper {
getVGameSnapshot(null, packageName)?.let {
it.downloadEntity.addMetaExtra(KEY_LAST_PLAYED_TIME, lastPlayedTime.toString())
it.downloadEntity.addMetaExtra(KEY_TOTAL_PLAYED_TIME, totalPlayedTime.toString())
it.downloadEntity.getMetaExtra(KEY_LAUNCH_COUNT)?.toIntOrNull()?.let { count ->
it.downloadEntity.addMetaExtra(KEY_LAUNCH_COUNT, "${count + 1}")
}
try {
vGameDao.insert(it)
refreshVGameSnapshot()
@ -2091,4 +2144,24 @@ object VHelper {
}
}
}
fun getCwBaseLogParams() = mapOf(
CwLogUtils.KEY_ANDROID_VERSION to Build.VERSION.RELEASE,
CwLogUtils.KEY_APP_64_VERSION to com.lg.core.BuildConfig.VERSION_NAME,
CwLogUtils.KEY_APP_32_VERSION to "",
CwLogUtils.KEY_VA_VERSION to HostUtils.getPluginVersion(),
CwLogUtils.KEY_ARCHITECTURE to if (ProcessUtils.is64Bit()) "64" else "32",
CwLogUtils.KEY_DIA to MetaUtil.getBase64EncodedAndroidId(),
CwLogUtils.KEY_GID to HaloApp.getInstance().gid,
CwLogUtils.KEY_JNFJ to "",
CwLogUtils.KEY_MAC to "",
CwLogUtils.KEY_MANUFACTURER to Build.MANUFACTURER,
CwLogUtils.KEY_MODEL to Build.MODEL,
CwLogUtils.KEY_ROM to RomIdentifier.getRom().name + " " + RomIdentifier.getRom().versionName,
CwLogUtils.KEY_HOST_VERSION to com.gh.gamecenter.BuildConfig.VERSION_NAME,
CwLogUtils.KEY_HOST_CHANNEL to HaloApp.getInstance().channel,
CwLogUtils.KEY_OAID to HaloApp.getInstance().oaid,
)
}