diff --git a/app/build.gradle b/app/build.gradle index 540fbfc772..9635565a32 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -331,6 +331,7 @@ dependencies { } // implementation(project(':feature:vpn')) implementation(project(':feature:pkg')) + implementation(project(':feature:oaid')) implementation(project(':feature:floating-window')) implementation(project(':feature:beizi_startup_ad')) } diff --git a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.kt b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.kt index 8c9f3ab11d..bb041fc139 100644 --- a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.kt +++ b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.kt @@ -306,7 +306,7 @@ class SplashScreenActivity : BaseActivity() { private fun doFlavorInit() { HaloApp.getInstance().flavorProvider.init(HaloApp.getInstance(), this, PkgHelper.getActivateRatio()) - val whiteListChannel = arrayListOf( + val whiteListChannel = arrayListOf( "GH_206", "KS-GHZS-KY1", "KS-GHZS-MC1", @@ -326,12 +326,6 @@ class SplashScreenActivity : BaseActivity() { private fun initStartUpAdSDK() { mStartUpAdProvider?.run { if (shouldEnableSDK(HaloApp.getInstance().channel)) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - initOAID(applicationContext) { - HaloApp.getInstance().oaid = it - MetaUtil.refreshMeta() - } - } initSDK(applicationContext) } } diff --git a/app/src/main/java/com/gh/gamecenter/oaid/OAIDHelper.kt b/app/src/main/java/com/gh/gamecenter/oaid/OAIDHelper.kt new file mode 100644 index 0000000000..721e7f0a84 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/oaid/OAIDHelper.kt @@ -0,0 +1,22 @@ +package com.gh.gamecenter.oaid + +import android.content.Context +import com.alibaba.android.arouter.launcher.ARouter +import com.gh.gamecenter.common.constant.RouteConsts +import com.gh.gamecenter.core.provider.IOAIDProvider + +object OAIDHelper { + + fun doSystemLoad() { + val oaidProvider = ARouter.getInstance().build(RouteConsts.provider.oaid).navigation() as? IOAIDProvider + + oaidProvider?.doSystemLoad() + } + + fun getOAID(context: Context, callback: (String) -> Unit) { + val oaidProvider = ARouter.getInstance().build(RouteConsts.provider.oaid).navigation() as? IOAIDProvider + + oaidProvider?.getOAID(context, callback) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/halo/assistant/HaloApp.java b/app/src/main/java/com/halo/assistant/HaloApp.java index e931f2532b..6de9dd9f7e 100644 --- a/app/src/main/java/com/halo/assistant/HaloApp.java +++ b/app/src/main/java/com/halo/assistant/HaloApp.java @@ -43,6 +43,7 @@ import com.gh.gamecenter.BuildConfig; import com.gh.gamecenter.Injection; import com.gh.gamecenter.common.constant.Config; import com.gh.gamecenter.common.constant.Constants; +import com.gh.gamecenter.common.exposure.meta.MetaUtil; import com.gh.gamecenter.common.image.EmptyDecoder; import com.gh.gamecenter.common.tracker.Tracker; import com.gh.gamecenter.common.utils.DarkModeUtils; @@ -58,6 +59,7 @@ import com.gh.gamecenter.core.utils.SPUtils; import com.gh.gamecenter.entity.SubjectRecommendEntity; import com.gh.gamecenter.fragment.MainWrapperRepository; import com.gh.gamecenter.login.user.UserRepository; +import com.gh.gamecenter.oaid.OAIDHelper; import com.gh.gamecenter.packagehelper.PackageRepository; import com.gh.gamecenter.core.provider.IFlavorProvider; import com.gh.gamecenter.provider.FlavorProviderImp; @@ -204,6 +206,9 @@ public class HaloApp extends MultiDexApplication { application.onCreate(mInstance); } + // 似乎只是 load SO 不涉及方法调用,所以可以在隐私政策前调用吧? + OAIDHelper.INSTANCE.doSystemLoad(); + // 70ms PlayerFactory.setPlayManager(Exo2PlayerManager.class); CacheFactory.setCacheManager(ExoPlayerCacheManager.class); @@ -273,6 +278,12 @@ public class HaloApp extends MultiDexApplication { // 获取/更新 GID 和 读 SP 的操作不需要 delay DataUtils.getGid(); + OAIDHelper.INSTANCE.getOAID(this, s -> { + setOAID(s); + MetaUtil.INSTANCE.refreshMeta(); + return null; + }); + // 获取 settings 配置 ExtensionsKt.doOnMainProcessOnly(this, com.gh.common.constant.Config::getGhzsSettings); diff --git a/feature/beizi_startup_ad/build.gradle b/feature/beizi_startup_ad/build.gradle index a2f2db3d43..ae78cb2279 100644 --- a/feature/beizi_startup_ad/build.gradle +++ b/feature/beizi_startup_ad/build.gradle @@ -86,7 +86,6 @@ dependencies { implementation(project(path: ":module_common")) { exclude group: 'androidx.swiperefreshlayout' } - api project(':feature:oaid_lib') implementation 'com.beizi:beizi_ad_sdk:3.4.20.23' implementation 'com.beizi:beizi_fusion_sdk:4.90.2.27' } \ No newline at end of file diff --git a/feature/beizi_startup_ad/proguard-rules.pro b/feature/beizi_startup_ad/proguard-rules.pro index f1d4e54046..d225f396c5 100644 --- a/feature/beizi_startup_ad/proguard-rules.pro +++ b/feature/beizi_startup_ad/proguard-rules.pro @@ -24,21 +24,4 @@ -dontwarn com.beizi.fusion.** -dontwarn com.beizi.ad.** -keep class com.beizi.fusion.** {*; } --keep class com.beizi.ad.** {*; } - -# 移动安全联盟oaid混淆 --keep class XI.CA.XI.**{*;} --keep class XI.K0.XI.**{*;} --keep class XI.XI.K0.**{*;} --keep class XI.XI.XI.**{*;} --keep class XI.xo.XI.XI.**{*;} --keep class XI.kM.XI.XI.XI.**{*;} --keep class com.asus.msa.SupplementaryDID.**{*;} --keep class com.asus.msa.sdid.**{*;} --keep class com.bun.lib.**{*;} --keep class com.bun.miitmdid.**{*;} --keep class com.huawei.hms.ads.identifier.**{*;} --keep class com.samsung.android.deviceidservice.**{*;} --keep class com.zui.opendeviceidlibrary.**{*;} --keep class org.json.**{*;} --keep public class com.netease.nis.sdkwrapper.Utils {public ;} \ No newline at end of file +-keep class com.beizi.ad.** {*; } \ No newline at end of file diff --git a/feature/beizi_startup_ad/src/main/java/com/gh/gamecenter/beiziad/BeiziAdHelper.kt b/feature/beizi_startup_ad/src/main/java/com/gh/gamecenter/beiziad/BeiziAdHelper.kt index 4354ef0434..ed4a679044 100644 --- a/feature/beizi_startup_ad/src/main/java/com/gh/gamecenter/beiziad/BeiziAdHelper.kt +++ b/feature/beizi_startup_ad/src/main/java/com/gh/gamecenter/beiziad/BeiziAdHelper.kt @@ -8,11 +8,9 @@ import com.beizi.fusion.AdListener import com.beizi.fusion.BeiZiCustomController import com.beizi.fusion.BeiZis import com.beizi.fusion.SplashAd -import com.bun.miitmdid.core.MdidSdkHelper import com.gh.gamecenter.common.constant.Constants import com.gh.gamecenter.core.utils.DisplayUtils import com.gh.gamecenter.core.utils.SPUtils -import com.lightgame.utils.Utils object BeiziAdHelper { @@ -33,13 +31,6 @@ object BeiziAdHelper { }) } - fun initOAID(context: Context, callback: (String) -> Unit) { - MdidSdkHelper.InitSdk(context, true) { _, idSupplier -> - Utils.log("OAID: ${idSupplier.oaid}") - callback(idSupplier.oaid) - } - } - fun initBeiziStartUpAd(startAdContainer: View, adsFl: FrameLayout, showAd: Boolean, hideCallback: () -> Unit) { startAdContainer.visibility = View.VISIBLE mSplashAd = SplashAd(startAdContainer.context, null, BEIZI_START_UP_AD_ID, object : AdListener { diff --git a/feature/beizi_startup_ad/src/main/java/com/gh/gamecenter/beiziad/StartUpAdProviderImpl.kt b/feature/beizi_startup_ad/src/main/java/com/gh/gamecenter/beiziad/StartUpAdProviderImpl.kt index f9332f5418..23c544cf48 100644 --- a/feature/beizi_startup_ad/src/main/java/com/gh/gamecenter/beiziad/StartUpAdProviderImpl.kt +++ b/feature/beizi_startup_ad/src/main/java/com/gh/gamecenter/beiziad/StartUpAdProviderImpl.kt @@ -13,10 +13,6 @@ class StartUpAdProviderImpl : IStartUpAdProvider { BeiziAdHelper.initBeiziSDK(context) } - override fun initOAID(context: Context, callback: (String) -> Unit) { - BeiziAdHelper.initOAID(context, callback) - } - override fun initStartUpAd(startAdContainer: View, adsFl: FrameLayout, showAd: Boolean, hideCallback: () -> Unit) { BeiziAdHelper.initBeiziStartUpAd(startAdContainer, adsFl, showAd, hideCallback) } diff --git a/feature/oaid/.gitignore b/feature/oaid/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/feature/oaid/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature/oaid/build.gradle b/feature/oaid/build.gradle new file mode 100644 index 0000000000..d84cbf62ef --- /dev/null +++ b/feature/oaid/build.gradle @@ -0,0 +1,48 @@ +apply plugin: 'com.android.library' + +apply plugin: 'org.jetbrains.kotlin.android' +apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-parcelize' + +android { + compileSdkVersion rootProject.ext.compileSdkVersion + + defaultConfig { + minSdk rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName + } + + kapt { + arguments { + arg("AROUTER_MODULE_NAME", project.name) + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + buildTypes { + release { + minifyEnabled false + consumerProguardFiles 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') + kapt "com.alibaba:arouter-compiler:$arouterVersion" + + implementation(project(path: ":module_common")) { + exclude group: 'androidx.swiperefreshlayout' + } + implementation(project(':feature:oaid_lib')) +} \ No newline at end of file diff --git a/feature/oaid/proguard-rules.pro b/feature/oaid/proguard-rules.pro new file mode 100644 index 0000000000..d91f64f8df --- /dev/null +++ b/feature/oaid/proguard-rules.pro @@ -0,0 +1,41 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile + +# oaid混淆 +-keep class com.bun.miitmdid.** { *; } +-keep interface com.bun.supplier.** { *; } +-keep class com.asus.msa.SupplementaryDID.** { *; } +-keep class com.asus.msa.sdid.** { *; } +-keep class com.android.creator.** { *; } +-keep class com.android.msasdk.** { *; } +-keep class com.huawei.hms.ads.identifier.** { *; } +-keep class com.uodis.opendevice.aidl.** { *; } +-keep class com.zui.deviceidservice.** { *; } +-keep class com.zui.opendeviceidlibrary.** { *; } +-keep class com.meizu.flyme.openidsdk.** { *; } +-keep class com.bun.miitmdid.provider.nubia.NubiaIdentityImpl +-keep class com.heytap.openid.** { *; } +-keep class com.samsung.android.deviceidservice.** { *; } +-keep class com.vivo.identifier.** { *; } +-keep class com.bun.miitmdid.provider.xiaomi.IdentifierManager +-keep class com.bun.lib.** { *; } +-keep class com.coolpad.deviceidsupport.** { *; } \ No newline at end of file diff --git a/feature/oaid/src/main/AndroidManifest.xml b/feature/oaid/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..4a2835675e --- /dev/null +++ b/feature/oaid/src/main/AndroidManifest.xml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/feature/beizi_startup_ad/src/main/assets/supplierconfig.json b/feature/oaid/src/main/assets/supplierconfig.json similarity index 100% rename from feature/beizi_startup_ad/src/main/assets/supplierconfig.json rename to feature/oaid/src/main/assets/supplierconfig.json diff --git a/feature/oaid/src/main/java/com/gh/gamecenter/oaid/HaloApp.kt b/feature/oaid/src/main/java/com/gh/gamecenter/oaid/HaloApp.kt new file mode 100644 index 0000000000..69badc0c5a --- /dev/null +++ b/feature/oaid/src/main/java/com/gh/gamecenter/oaid/HaloApp.kt @@ -0,0 +1,44 @@ +package com.gh.gamecenter.oaid + +import android.app.Application +import android.content.res.Configuration +import com.gh.gamecenter.core.iinterface.IApplication +import com.google.auto.service.AutoService + +@AutoService(IApplication::class) +class HaloApp : IApplication { + + override fun attachBaseContext() { + + } + + override fun onCreate(application: Application) { + mApp = application + } + + + override fun onLowMemory() { + + } + + override fun onTerminate() { + + } + + override fun onTrimMemory(level: Int) { + + } + + override fun onConfigurationChanged(newConfig: Configuration) { + + } + + companion object { + private lateinit var mApp: Application + + @JvmStatic + fun getInstance(): Application { + return mApp + } + } +} \ No newline at end of file diff --git a/feature/oaid/src/main/java/com/gh/gamecenter/oaid/OAIDProviderImpl.kt b/feature/oaid/src/main/java/com/gh/gamecenter/oaid/OAIDProviderImpl.kt new file mode 100644 index 0000000000..3462df0f9c --- /dev/null +++ b/feature/oaid/src/main/java/com/gh/gamecenter/oaid/OAIDProviderImpl.kt @@ -0,0 +1,93 @@ +package com.gh.gamecenter.oaid + +import android.annotation.SuppressLint +import android.content.Context +import com.alibaba.android.arouter.facade.annotation.Route +import com.bun.miitmdid.core.MdidSdkHelper +import com.gh.gamecenter.common.constant.RouteConsts +import com.gh.gamecenter.common.retrofit.BiResponse +import com.gh.gamecenter.core.provider.IOAIDProvider +import com.gh.gamecenter.core.utils.SPUtils +import com.gh.gamecenter.oaid.network.CertEntity +import com.gh.gamecenter.oaid.network.RetrofitManager +import com.lightgame.utils.Utils +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.schedulers.Schedulers + +@Route(path = RouteConsts.provider.oaid, name = "OAID 暴露服务") +class OAIDProviderImpl : IOAIDProvider { + + override fun doSystemLoad() { + // android 6.0 以下不支持获取 OAID + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) return + + System.loadLibrary("msaoaidsec") + } + + override fun getOAID(context: Context, callback: (String) -> Unit) { + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) return + + val cachedCert = SPUtils.getString(SP_OAID_CERT) + + // 若存在缓存的证书,优先使用缓存的证书来初始化 + if (cachedCert.isNotEmpty()) { + Utils.log(TAG, "使用缓存的证书来初始化 $cachedCert") + + val result = MdidSdkHelper.InitCert(context, cachedCert) + + Utils.log(TAG, "初始化证书结果 $result") + + getOAIDForReal(context, true, callback) + } else { + getCertFromServerThenGetOAID(context, callback) + } + } + + @SuppressLint("CheckResult") + private fun getCertFromServerThenGetOAID(context: Context, callback: (String) -> Unit) { + RetrofitManager.getInstance().api.getOAIDCert() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : BiResponse() { + override fun onSuccess(data: CertEntity) { + Utils.log(TAG, "获取到的证书为 ${data.cert}") + + val result = MdidSdkHelper.InitCert(context, data.cert) + SPUtils.setString(SP_OAID_CERT, data.cert) + + Utils.log(TAG, "初始化证书结果 $result") + + getOAIDForReal(context, false, callback) + } + + override fun onFailure(exception: Exception) { + super.onFailure(exception) + Utils.log(TAG, "获取证书异常") + } + }) + } + + private fun getOAIDForReal(context: Context, fromCached: Boolean, callback: (String) -> Unit) { + val code = MdidSdkHelper.InitSdk(context, false, true, false, false) { p0 -> + p0?.oaid?.let { + callback.invoke(it) + } + } + + Utils.log(TAG, "获取 OAID 的返回值为 $code") + + // 缓存的证书失效了,访问接口重新获取 + if (fromCached && code == 1008616) { + getCertFromServerThenGetOAID(context, callback) + } + } + + override fun init(context: Context?) { + // do nothing + } + + companion object { + const val TAG = "oaid" + const val SP_OAID_CERT = "oaid_cert" + } +} \ No newline at end of file diff --git a/feature/oaid/src/main/java/com/gh/gamecenter/oaid/network/ApiService.kt b/feature/oaid/src/main/java/com/gh/gamecenter/oaid/network/ApiService.kt new file mode 100644 index 0000000000..baf4513e80 --- /dev/null +++ b/feature/oaid/src/main/java/com/gh/gamecenter/oaid/network/ApiService.kt @@ -0,0 +1,14 @@ +package com.gh.gamecenter.oaid.network + +import io.reactivex.Single +import retrofit2.http.* + +interface ApiService { + + /** + * 获取推广包配置 + */ + @GET("oaid/cert") + fun getOAIDCert(): Single + +} \ No newline at end of file diff --git a/feature/oaid/src/main/java/com/gh/gamecenter/oaid/network/CertEntity.kt b/feature/oaid/src/main/java/com/gh/gamecenter/oaid/network/CertEntity.kt new file mode 100644 index 0000000000..6192075d6f --- /dev/null +++ b/feature/oaid/src/main/java/com/gh/gamecenter/oaid/network/CertEntity.kt @@ -0,0 +1,6 @@ +package com.gh.gamecenter.oaid.network + +import androidx.annotation.Keep + +@Keep +class CertEntity(val cert: String) \ No newline at end of file diff --git a/feature/oaid/src/main/java/com/gh/gamecenter/oaid/network/RetrofitManager.kt b/feature/oaid/src/main/java/com/gh/gamecenter/oaid/network/RetrofitManager.kt new file mode 100644 index 0000000000..1129969aa3 --- /dev/null +++ b/feature/oaid/src/main/java/com/gh/gamecenter/oaid/network/RetrofitManager.kt @@ -0,0 +1,20 @@ +package com.gh.gamecenter.oaid.network + +import com.gh.gamecenter.common.retrofit.BaseRetrofitManager +import com.gh.gamecenter.common.utils.EnvHelper.getNewHost +import com.gh.gamecenter.core.utils.SingletonHolder +import com.gh.gamecenter.oaid.HaloApp + +class RetrofitManager private constructor() : BaseRetrofitManager() { + + val api: ApiService + + init { + val context = HaloApp.getInstance().applicationContext + val okHttpNormalConfig = getOkHttpConfig(context, 0, 2) + api = provideService(okHttpNormalConfig, getNewHost(), ApiService::class.java) + } + + companion object : SingletonHolder(::RetrofitManager) + +} \ No newline at end of file diff --git a/feature/oaid_lib/build.gradle b/feature/oaid_lib/build.gradle index 1766c2bd36..518ba54c74 100644 --- a/feature/oaid_lib/build.gradle +++ b/feature/oaid_lib/build.gradle @@ -1,2 +1,2 @@ configurations.maybeCreate("default") -artifacts.add("default", file('oaid_sdk_1.0.25.aar')) \ No newline at end of file +artifacts.add("default", file('oaid_sdk_2.1.0.aar')) \ No newline at end of file diff --git a/feature/oaid_lib/oaid_sdk_1.0.25.aar b/feature/oaid_lib/oaid_sdk_1.0.25.aar deleted file mode 100644 index 47ca06de7d..0000000000 Binary files a/feature/oaid_lib/oaid_sdk_1.0.25.aar and /dev/null differ diff --git a/feature/oaid_lib/oaid_sdk_2.1.0.aar b/feature/oaid_lib/oaid_sdk_2.1.0.aar new file mode 100644 index 0000000000..6280ad5d69 Binary files /dev/null and b/feature/oaid_lib/oaid_sdk_2.1.0.aar differ diff --git a/module_common/src/main/java/com/gh/gamecenter/common/constant/RouteConsts.kt b/module_common/src/main/java/com/gh/gamecenter/common/constant/RouteConsts.kt index aca3d5f283..db528d96c4 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/constant/RouteConsts.kt +++ b/module_common/src/main/java/com/gh/gamecenter/common/constant/RouteConsts.kt @@ -81,6 +81,8 @@ object RouteConsts { const val sensors = "/sensors/sensors" const val adSdk = "/adSdk/adSdk" + + const val oaid = "/oaid/oaid" } } \ No newline at end of file diff --git a/module_core/src/main/java/com/gh/gamecenter/core/provider/IOAIDProvider.kt b/module_core/src/main/java/com/gh/gamecenter/core/provider/IOAIDProvider.kt new file mode 100644 index 0000000000..c4ae1dd5a8 --- /dev/null +++ b/module_core/src/main/java/com/gh/gamecenter/core/provider/IOAIDProvider.kt @@ -0,0 +1,12 @@ +package com.gh.gamecenter.core.provider + +import android.content.Context +import com.alibaba.android.arouter.facade.template.IProvider + +interface IOAIDProvider : IProvider { + + fun doSystemLoad() + + fun getOAID(context: Context, callback: (String) -> Unit) + +} \ No newline at end of file diff --git a/module_core/src/main/java/com/gh/gamecenter/core/provider/IStartUpAdProvider.kt b/module_core/src/main/java/com/gh/gamecenter/core/provider/IStartUpAdProvider.kt index 157fa76ea2..6c4894e383 100644 --- a/module_core/src/main/java/com/gh/gamecenter/core/provider/IStartUpAdProvider.kt +++ b/module_core/src/main/java/com/gh/gamecenter/core/provider/IStartUpAdProvider.kt @@ -9,8 +9,6 @@ interface IStartUpAdProvider : IProvider { fun initSDK(context: Context) - fun initOAID(context: Context, callback: (String) -> Unit) - fun initStartUpAd(startAdContainer: View, adsFl: FrameLayout, showAd: Boolean, hideCallback: () -> Unit) fun cancelStartUpAd(context: Context) diff --git a/settings.gradle b/settings.gradle index 389a833022..2e2491b58e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -18,3 +18,4 @@ include ':feature:pkg' include ':feature:floating-window' include ':feature:beizi_startup_ad' include ':feature:oaid_lib' +include ':feature:oaid'