Skip to content

Commit

Permalink
chore: show full host version number in about fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
cinit committed Sep 17, 2023
1 parent 14a0992 commit 11f923a
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion app/src/main/java/io/github/qauxv/fragment/AboutFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -40,6 +41,7 @@ import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import cc.ioctl.util.LayoutHelper.MATCH_PARENT
import cc.ioctl.util.ui.dsl.RecyclerListViewController
import io.github.qauxv.util.Log
import io.github.qauxv.BuildConfig
import io.github.qauxv.R
import io.github.qauxv.activity.ConfigV2Activity
Expand Down Expand Up @@ -90,7 +92,7 @@ class AboutFragment : BaseRootLayoutFragment() {
}
textItem("构建时间", value = getBuildTimeString())
if (isInHostProcess) {
val hostVersionName = hostInfo.versionName + "(" + hostInfo.versionCode32 + ")"
val hostVersionName = getHostFullVersionNameAndVersionCode()
textItem(hostInfo.hostName, value = hostVersionName) {
copyText(hostVersionName)
}
Expand Down Expand Up @@ -138,6 +140,34 @@ class AboutFragment : BaseRootLayoutFragment() {
)
}

private fun getBuildNumberForCurrentTencentHostApplication(): Int {
val ctx = hostInfo.application
val pm = ctx.packageManager
val metaData: Bundle
try {
metaData = pm.getApplicationInfo(ctx.packageName, PackageManager.GET_META_DATA).metaData ?: return 0
} catch (e: PackageManager.NameNotFoundException) {
// WTF? in container?
Log.e("getBuildNumberForCurrentTencentHostApplication WTF", e)
return 0
}
val rdmUuid = metaData.getString("com.tencent.rdm.uuid") ?: return 0
// [0-9]{3,5}_[0-9]{3,5}
if (!rdmUuid.matches("[0-9]{3,5}_[0-9]{3,5}".toRegex())) return 0
// buildNumber is first part
return rdmUuid.split("_")[0].toInt()
}

private fun getHostFullVersionNameAndVersionCode(): String {
val buildNumber = getBuildNumberForCurrentTencentHostApplication()
val fullVersionName = if (buildNumber == 0) {
hostInfo.versionName
} else {
hostInfo.versionName + "." + buildNumber
}
return fullVersionName + "(" + hostInfo.versionCode32 + ")"
}

private fun getBuildTimeString(): String {
// yyyy-MM-dd HH:mm:ss
val timestamp: Long = BuildConfig.BUILD_TIMESTAMP
Expand Down

0 comments on commit 11f923a

Please sign in to comment.