This commit is contained in:
chenjuntao
2024-07-23 18:18:21 +08:00
parent dca0fc7261
commit 6fc7eea011
48 changed files with 522 additions and 128 deletions

View File

@ -28,6 +28,7 @@ import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.exposure.ExposureSource
import com.gh.gamecenter.common.retrofit.BiResponse
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.core.AppExecutor
import com.gh.gamecenter.core.provider.ICsjAdProvider
import com.gh.gamecenter.core.utils.CurrentActivityHolder
import com.gh.gamecenter.core.utils.SPUtils
@ -78,6 +79,19 @@ object AdDelegateHelper {
var gameSearchKeyword = ""
fun initAdSdk(context: Context) {
if (AdPluginDownloadHelper.isCsjPluginDownloaded()) {
initAdSdkInternal(context)
} else {
// 首次启动,为了不影响首页加载,延迟 3 秒再下载广告插件并初始化
AppExecutor.uiExecutor.executeWithDelay({
AdPluginDownloadHelper.downloadPluginIfNeeded(isCsj = true) {
initAdSdkInternal(context)
}
}, 3000L)
}
}
private fun initAdSdkInternal(context: Context) {
// 初始化穿山甲
if (mCsjAdImpl == null) {
mCsjAdImpl =

View File

@ -0,0 +1,147 @@
package com.gh.ad
import com.gh.download.simple.DownloadMessageHandler
import com.gh.download.simple.SimpleDownloadDatabase
import com.gh.download.simple.SimpleDownloadManager
import com.gh.gamecenter.core.runOnIoThread
import com.gh.gamecenter.core.utils.PluginRedirectHelper
import com.gh.gamecenter.core.utils.SPUtils
import com.lg.download.DownloadError
import com.lg.download.DownloadStatus
import com.lg.download.httpclient.DefaultHttpClient
import com.lg.download.listener.InnerDownloadListener
import com.lg.ndownload.DownloadConfig
import com.lg.ndownload.DownloadConfigBuilder
import com.lg.ndownload.DownloadIoExecutor
import com.lightgame.utils.Utils
import java.lang.Exception
import java.net.URLConnection
object AdPluginDownloadHelper : InnerDownloadListener {
private const val CSJ_FILE_NAME = "2011394667"
private const val GDT_FILE_NAME = "gdt_plugin/gdtadv2.jar"
private var csjDownloadedCallback: (() -> Unit)? = null
/**
* 是否已经下载了广告插件
*/
fun isCsjPluginDownloaded(): Boolean {
return SPUtils.getBoolean(CSJ_FILE_NAME, false)
}
/**
* 下载广告插件并初始化
*
* return 是否已经下载完成
*/
fun downloadPluginIfNeeded(isCsj: Boolean = false, isGdt: Boolean = false, csjCallback: (() -> Unit)? = null) {
val isCsjPluginDownloaded = SPUtils.getBoolean(CSJ_FILE_NAME, false)
val isGdtPluginDownloaded = SPUtils.getBoolean(GDT_FILE_NAME, false)
if (isCsj && isCsjPluginDownloaded) {
csjCallback?.invoke()
return
}
if (isGdt && isGdtPluginDownloaded) {
return
}
runOnIoThread {
csjDownloadedCallback = csjCallback
DownloadMessageHandler.init(SimpleDownloadDatabase.instance.downloadDao())
if (!isCsjPluginDownloaded) {
val csjPluginConfig = DownloadConfigBuilder()
.setUniqueId(CSJ_FILE_NAME)
.setUrl("https://and-static.ghzs66.com/android/static/2011394667")
.setFileName(CSJ_FILE_NAME)
.setHttpClient(DefaultHttpClient())
.setDownloadThreadSize(2)
.setPathToStore(PluginRedirectHelper.getAssetDir())
.setDownloadExecutor(DownloadIoExecutor.getInstance())
.setDownloadListener(this).build()
SimpleDownloadManager.download(csjPluginConfig)
}
if (!isGdtPluginDownloaded) {
val gdtPluginConfig = DownloadConfigBuilder()
.setUniqueId(GDT_FILE_NAME)
.setUrl("https://and-static.ghzs66.com/android/static/gdtadv2.jar")
.setFileName(GDT_FILE_NAME)
.setHttpClient(DefaultHttpClient())
.setDownloadThreadSize(2)
.setPathToStore(PluginRedirectHelper.getAssetDir())
.setDownloadExecutor(DownloadIoExecutor.getInstance())
.setDownloadListener(this).build()
SimpleDownloadManager.download(gdtPluginConfig)
}
}
}
override fun onError(id: String?, error: DownloadError?, exception: Exception?) {
Utils.log("下载广告插件失败 $id")
id?.let {
if (it == CSJ_FILE_NAME) {
csjDownloadedCallback = null
}
SimpleDownloadManager.cancel(it)
}
}
override fun onProgress(id: String?, progress: Float) {
Utils.log("下载广告插件进度 $id $progress")
}
override fun onProgressWithoutThrottle(id: String?, progress: Float) {
// do nothing
}
override fun onSizeReceived(id: String?, fileSize: Long) {
// do nothing
}
override fun onReadyToDownload(id: String?, actualThreadSize: Int) {
// do nothing
}
override fun onStatusChanged(id: String?, status: DownloadStatus?) {
// do nothing
}
override fun onDownloadComplete(id: String?, elapsedTime: Long) {
id?.let {
SPUtils.setBoolean(it, true)
if (it == CSJ_FILE_NAME) {
csjDownloadedCallback?.invoke()
csjDownloadedCallback = null
}
}
}
override fun onSpeedChanged(id: String?, speed: Float) {
// do nothing
}
override fun onRedirectingUrl(
id: String?,
connection: URLConnection?,
config: DownloadConfig?
) {
// do nothing
}
override fun onRedirectedUrl(
id: String?,
connection: URLConnection?,
redirectedUrl: String?
) {
// do nothing
}
}

View File

@ -12,6 +12,7 @@ import android.text.TextUtils
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import com.alibaba.android.arouter.launcher.ARouter
import com.gh.ad.AdPluginDownloadHelper
import com.gh.common.constant.Config
import com.gh.common.exposure.ExposureManager.log
import com.gh.common.exposure.ExposureTraceUtils.appendTrace
@ -1965,19 +1966,23 @@ object DirectUtils {
return
}
CheckLoginUtils.checkLogin(
activity, null, true, "QQ小游戏-秒开"
) {
val qGameProvider = ARouter
.getInstance()
.build(RouteConsts.provider.qGame)
.navigation() as? IQGameProvider
if (qGameProvider == null) return
// 下载广点通广告插件,供 QQ 小游戏启动使用 (当次启动不保证能用,但是下一次就大概率就能了)
AdPluginDownloadHelper.downloadPluginIfNeeded(isGdt = true)
CheckLoginUtils.checkLogin(activity, null, true, "QQ小游戏-秒开") {
val userToken = UserManager.getInstance().token
val userId = UserManager.getInstance().userId
val userName = UserManager.getInstance().userInfoEntity?.name ?: "unknown"
val qGameProvider = ARouter
.getInstance()
.build(RouteConsts.provider.qGame)
.navigation() as? IQGameProvider
qGameProvider?.setLoginInfo(activity, userId, userName, userToken)
qGameProvider?.launchGame(activity, qqAppId) { _, _ ->
qGameProvider.setLoginInfo(activity, userId, userName, userToken)
qGameProvider.launchGame(activity, qqAppId) { _, _ ->
MiniGameRecentlyPlayUseCase.submitRecentPlayedQGame(qqAppId, userId)
}
}

View File

@ -37,6 +37,8 @@ object DownloadMessageHandler : InnerDownloadListener {
@SuppressLint("CheckResult")
fun init(downloadDao: DownloadDao) {
if (::mDownloadDao.isInitialized) return
mDownloadDao = downloadDao
updateDownloadList()

View File

@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.app.Application
import android.text.TextUtils
import androidx.lifecycle.AndroidViewModel
import com.gh.ad.AdPluginDownloadHelper
import com.gh.common.util.DeviceTokenUtils
import com.gh.common.util.LunchType
import com.gh.common.util.PackageUtils

View File

@ -195,9 +195,6 @@ class UploadVideoActivity : ToolBarActivity() {
mBinding.activityContainer.visibility = View.GONE
checkPostButtonStatus()
}
mBinding.watermarkSb.setOnCheckedChangeListener { _, isChecked ->
MtaHelper.onEvent("上传视频", "视频水印", if (isChecked) "打开" else "关闭")
}
mBinding.originalTv.setOnClickListener {
switchVideoSource(true)
@ -391,7 +388,6 @@ class UploadVideoActivity : ToolBarActivity() {
ImageUtils.display(mBinding.videoPoster, videoPatch.poster)
handleUploadSuccess(videoPatch.url)
mBinding.watermarkSb.animationDuration = 0
mBinding.watermarkSb.isChecked = videoPatch.watermark
mBinding.watermarkClick.visibility = View.VISIBLE
mBinding.watermarkClick.setOnClickListener {

View File

@ -18,14 +18,9 @@ import androidx.multidex.MultiDexApplication;
import androidx.webkit.WebViewCompat;
import com.alibaba.android.arouter.launcher.ARouter;
import com.facebook.animated.giflite.GifDecoder;
import com.facebook.imageformat.DefaultImageFormats;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.facebook.imagepipeline.core.ImagePipelineFactory;
import com.facebook.imagepipeline.core.ImageTranscoderType;
import com.facebook.imagepipeline.core.MemoryChunkType;
import com.facebook.imagepipeline.decoder.ImageDecoderConfig;
import com.gh.ad.AdDelegateHelper;
import com.gh.ad.AdPluginDownloadHelper;
import com.gh.base.GlobalActivityLifecycleObserver;
import com.gh.common.FixedRateJobHelper;
import com.gh.common.filter.RegionSettingHelper;
@ -571,35 +566,8 @@ public class HaloApp extends MultiDexApplication {
ImageUtils.disableAnimatedImage();
}
// 在 5.0 & 5.1 设备上 disable native code原因是应用附带了 arm64 的 SO 以后在部分 5.0/5.1 设备
// 会出现找不到 arm64 so 的情况,具体可见
// https://sentry.ghzs.com/organizations/lightgame/issues/53107/
// 所以这里尝试在 5.0 & 5.1 设备上关闭 fresco 的 native 解码
ImagePipelineConfig.Builder pipelineConfigBuilder = ImagePipelineConfig.newBuilder(this);
ImageDecoderConfig.Builder decodeConfigBuilder = ImageDecoderConfig.newBuilder();
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP
|| Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1) {
pipelineConfigBuilder.setMemoryChunkType(MemoryChunkType.BUFFER_MEMORY)
.setImageTranscoderType(ImageTranscoderType.JAVA_TRANSCODER);
decodeConfigBuilder.overrideDecoder(DefaultImageFormats.GIF, new GifDecoder()).build();
String manufacture = Build.MANUFACTURER.toLowerCase();
// OPPO 和 VIVO 的 5.1.1 设备还会去加载 WEBP_ANIMATED 的 SO
// 实测没有发现有地方使用 WEBP_ANIMATED 的图片,这里用空占位图来替换 WEBP 动图
if ("oppo".equals(manufacture) || "vivo".equals(manufacture)) {
decodeConfigBuilder.overrideDecoder(DefaultImageFormats.WEBP_ANIMATED, new EmptyDecoder()).build();
}
pipelineConfigBuilder
.setImageDecoderConfig(decodeConfigBuilder.build())
.experiment()
.setNativeCodeDisabled(true);
}
try {
BigImageViewer.initialize(FrescoImageLoader.with(this, pipelineConfigBuilder.build()));
BigImageViewer.initialize(FrescoImageLoader.with(this));
} catch (Throwable e) {
e.printStackTrace();
}