Skip to content

Commit

Permalink
feat: 1.2.6 upgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan authored and Stefan committed Apr 22, 2024
1 parent 4d69bb5 commit 5cf54e2
Show file tree
Hide file tree
Showing 29 changed files with 189 additions and 53 deletions.
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Vest-SDK

最新版本:1.2.5
最新版本:1.2.6
这是一个可以用于控制游戏跳转的三方依赖库,工程提供开源代码,可自行修改。

SDK总共四个依赖库:
Expand Down Expand Up @@ -69,13 +69,13 @@ vest-firebase: 用于切换A/B面的远程开关
```
dependencies {
//核心库(必须引入)
implementation 'io.github.bumptechlab:vest-core:1.2.5'
implementation 'io.github.bumptechlab:vest-core:1.2.6'
//B面游戏运行平台
implementation 'io.github.bumptechlab:vest-sdk:1.2.5'
implementation 'io.github.bumptechlab:vest-sdk:1.2.6'
//A/B面切换开关
implementation 'io.github.bumptechlab:vest-shf:1.2.5'
implementation 'io.github.bumptechlab:vest-shf:1.2.6'
//vest-shf和vest-firebase 二选一
//implementation 'io.github.bumptechlab:vest-firebase:1.2.5'
//implementation 'io.github.bumptechlab:vest-firebase:1.2.6'
}
```
(2) 本地依赖方式
Expand Down Expand Up @@ -208,6 +208,14 @@ vest-firebase: 用于切换A/B面的远程开关
*/
setInspectDelayTime(0, TimeUnit.DAYS)
/**
* 「Optional」If there is no need, you can skip calling this method
*
* set up a device whitelist for Firebase, where devices in the whitelist can bypass the interception of Install Referrer in the Release environment
* only effective in Release package, Debug package will not be intercepted due to attribution being a natural quantity
*/
setFirebaseDeviceWhiteList(listOf("xxxx",...))
}.inspect(this, object : VestInspectCallback {
/**
Expand Down Expand Up @@ -300,11 +308,11 @@ allprojects {

```
dependencies {
implementation 'io.github.bumptechlab:vest-core:1.2.5-SNAPSHOT'
implementation 'io.github.bumptechlab:vest-sdk:1.2.5-SNAPSHOT'
implementation 'io.github.bumptechlab:vest-shf:1.2.5-SNAPSHOT'
implementation 'io.github.bumptechlab:vest-core:1.2.6-SNAPSHOT'
implementation 'io.github.bumptechlab:vest-sdk:1.2.6-SNAPSHOT'
implementation 'io.github.bumptechlab:vest-shf:1.2.6-SNAPSHOT'
//vest-shf和vest-firebase 二选一
//implementation 'io.github.bumptechlab:vest-firebase:1.2.5-SNAPSHOT'
//implementation 'io.github.bumptechlab:vest-firebase:1.2.6-SNAPSHOT'
}
```

Expand Down Expand Up @@ -505,9 +513,19 @@ allprojects {
- 实现B面外部跳转
- A/B开关请求区分马甲包和渠道包

### 1.2.5
### 1.2.4

- 增加firebase控制A/B开关
- 移除风险代码
- deviceId都为0的时候使用UUID
- 修复子品牌缓存问题
- 修复子品牌缓存问题

### 1.2.5

- firebase增加一包通投

### 1.2.6

- firebase增加本地归因判断拦截,并新增加接口`setFirebaseDeviceWhiteList`来跳过该限制
- 将静默截止时间改为中国时间来做判断
- 支持新市场PBR/PID
7 changes: 7 additions & 0 deletions app-core/src/main/java/book/sdk/core/Configuration.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package book.sdk.core

import android.text.TextUtils
import org.json.JSONException
import org.json.JSONObject

Expand All @@ -10,6 +11,7 @@ class Configuration {
var shfSpareHosts: Array<String>? = null
var shfBaseHost: String? = null
var shfDispatcher: String? = null
var firebaseIRWhiteDeviceList: List<String>? = null

/* adjust start */
var adjustAppId: String? = null
Expand All @@ -30,6 +32,11 @@ fun String.toConfiguration(): Configuration? {
brand = jsonObject.optString("brand")
country = jsonObject.optString("country")
shfBaseHost = jsonObject.optString("shf_base_domain")
val whiteDeviceStringForIR = jsonObject.optString("white_device_for_ir_limit")
if (!TextUtils.isEmpty(whiteDeviceStringForIR)) {
firebaseIRWhiteDeviceList = whiteDeviceStringForIR.split(",")
}

val shfSpareHostArray = jsonObject.optJSONArray("shf_spare_domains")
val shfSpareHostList = mutableListOf<String>()
if (shfSpareHostArray != null) {
Expand Down
5 changes: 3 additions & 2 deletions app-core/src/main/java/book/sdk/core/manager/CocosManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import book.util.parseInt

object CocosManager {
private val TAG = CocosManager::class.java.simpleName
private val FILTER_COUNTRY_CODES = arrayOf("IN", "ID", "BR", "GW", "VN")
private val FILTER_COUNTRY_CODES = arrayOf("IN", "ID", "BR", "GW", "VN", "PBR", "PID")

fun getUserId(): String? {
var userID = CocosPreferenceUtil.getString(CocosPreferenceUtil.KEY_USER_ID)
Expand All @@ -30,7 +30,8 @@ object CocosManager {
}

fun getCocosFrameVersion(): String {
var cocosFrameVersion = CocosPreferenceUtil.getString(CocosPreferenceUtil.KEY_COCOS_FRAME_VERSION)
var cocosFrameVersion =
CocosPreferenceUtil.getString(CocosPreferenceUtil.KEY_COCOS_FRAME_VERSION)
if (cocosFrameVersion.isNullOrEmpty()) {
val targetCountry = VestCore.getTargetCountry()
cocosFrameVersion = if (is1d0CountryCode(targetCountry)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ConfigurationManager private constructor() {
saveAdjustEventGreeting(configuration.adjustEventGreeting)
saveAdjustEventAccess(configuration.adjustEventAccess)
saveAdjustEventUpdated(configuration.adjustEventUpdated)
saveFirebaseWhiteDevice(configuration.firebaseIRWhiteDeviceList)
}
}

Expand Down
32 changes: 32 additions & 0 deletions app-core/src/main/java/book/sdk/core/util/ConfigPreference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ object ConfigPreference : AbstractPreference("pref_vest_config") {
private const val CONFIG_ADJUST_EVENT_ACCESS = "CONFIG_BEAN_ADJUST_EVENT_ACCESS"
private const val CONFIG_ADJUST_EVENT_UPDATED = "CONFIG_BEAN_ADJUST_EVENT_UPDATED"
private const val CONFIG_RELEASE_MODE = "CONFIG_BEAN_RELEASE_MODE"
private const val CONFIG_FIREBASE_WHITE_DEVICE = "CONFIG_FIREBASE_WHITE_DEVICE"

fun saveChannel(chn: String?): Boolean {
return putString(CONFIG_CHN, chn)
Expand Down Expand Up @@ -143,4 +144,35 @@ object ConfigPreference : AbstractPreference("pref_vest_config") {
return getInt(CONFIG_RELEASE_MODE, VestReleaseMode.MODE_VEST.mode)
}

fun saveFirebaseWhiteDevice(value: List<String>?): Boolean {
var v = value
if (v == null) {
v = emptyList()
}
val shfHostArray = JSONArray()
for (i in v.indices) {
shfHostArray.put(v[i])
}
val valueJson = shfHostArray.toString()
return putString(CONFIG_FIREBASE_WHITE_DEVICE, valueJson)
}

fun readFirebaseWhiteDevice(): List<String> {
val valueJson = getString(CONFIG_FIREBASE_WHITE_DEVICE)
var hosts = listOf<String>()
if (!TextUtils.isEmpty(valueJson)) {
try {
val shfHostArray = JSONArray(valueJson)
val shfHostList = ArrayList<String>()
for (i in 0 until shfHostArray.length()) {
shfHostList.add(shfHostArray.optString(i))
}
hosts = shfHostList
} catch (e: JSONException) {
e.printStackTrace()
}
}
return hosts
}

}
2 changes: 2 additions & 0 deletions app-core/src/main/java/book/sdk/core/util/PreferenceUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import book.sdk.core.VestCore
import book.util.AbstractPreference
import java.text.SimpleDateFormat
import java.util.Locale
import java.util.TimeZone
import java.util.concurrent.TimeUnit

object PreferenceUtil : AbstractPreference("pref_vest") {
Expand Down Expand Up @@ -241,6 +242,7 @@ object PreferenceUtil : AbstractPreference("pref_vest") {
fun saveReleaseTime(delayTime: String?): Boolean {
val formatter =
SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault(Locale.Category.FORMAT))
formatter.timeZone = TimeZone.getTimeZone("GMT+8")
try {
val date = formatter.parse(delayTime!!)
return putLong(KEY_BUILD_TIME, date!!.time)
Expand Down
108 changes: 75 additions & 33 deletions app-firebase/src/main/java/book/sdk/firebase/VestFirebase.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package book.sdk.firebase

import android.annotation.SuppressLint
import android.content.Context
import android.text.TextUtils
import android.util.Base64
import android.webkit.URLUtil
import book.sdk.core.VestCore
import book.sdk.core.VestInspectCallback
Expand All @@ -10,6 +12,8 @@ import book.sdk.core.event.SDKEvent
import book.sdk.core.manager.AdjustManager
import book.sdk.core.manager.InitInspector
import book.sdk.core.manager.InstallReferrerManager
import book.sdk.core.util.ConfigPreference
import book.sdk.core.util.DeviceUtil
import book.sdk.core.util.GoogleAdIdInitializer
import book.sdk.core.util.PackageUtil
import book.sdk.core.util.PreferenceUtil
Expand All @@ -28,6 +32,7 @@ import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.net.URLDecoder
import java.util.concurrent.TimeUnit

class VestFirebase private constructor() {
Expand Down Expand Up @@ -67,6 +72,17 @@ class VestFirebase private constructor() {
return this
}

/**
* set up a device whitelist for Firebase, where devices in the whitelist can bypass the interception of Install Referrer in the Release environment
*
* @param deviceList Obtain the device ID of your current device by filtering "getDeviceId: DeviceId:" in Logcat
*/
fun setFirebaseDeviceWhiteList(deviceList: List<String>) {
if (deviceList.isEmpty()) return
val whiteFirebaseDeviceListInCache = ConfigPreference.readFirebaseWhiteDevice() + deviceList
ConfigPreference.saveFirebaseWhiteDevice(whiteFirebaseDeviceListInCache)
}

/**
* setup the date of apk build
*
Expand Down Expand Up @@ -109,35 +125,29 @@ class VestFirebase private constructor() {
return@flow
}
fetchRemoteFirebase(this)
}.flowOn(Dispatchers.IO)
.catch {
LogUtil.e(TAG, it, "[Vest-Firebase] onInspect error")
if (mVestInspectCallback != null) {
mVestInspectCallback?.onShowASide(VestInspectResult.REASON_FIREBASE_ERROR)
}
}
.onStart {
LogUtil.d(TAG, "[Vest-Firebase] onInspect start")
}.flowOn(Dispatchers.IO).catch {
LogUtil.e(TAG, it, "[Vest-Firebase] onInspect error")
if (mVestInspectCallback != null) {
mVestInspectCallback?.onShowASide(VestInspectResult.REASON_FIREBASE_ERROR)
}
.onCompletion {
LogUtil.d(TAG, "[Vest-Firebase] onInspect finish")
}
.collect {
LogUtil.d(TAG, "[Vest-Firebase] onInspectTarget: $it")
val url = it
if (mVestInspectCallback != null) {
if (url.isEmpty()) {
mVestInspectCallback?.onShowASide(VestInspectResult.REASON_OFF_ON_SERVER)
} else {
val launchBSuccess = VestCore.toWebViewActivity(
mContext,
url,
VestCore.WEBVIEW_TYPE_INNER
)
mVestInspectCallback?.onShowBSide(url, launchBSuccess)
}
}.onStart {
LogUtil.d(TAG, "[Vest-Firebase] onInspect start")
}.onCompletion {
LogUtil.d(TAG, "[Vest-Firebase] onInspect finish")
}.collect {
LogUtil.d(TAG, "[Vest-Firebase] onInspectTarget: $it")
val url = it
if (mVestInspectCallback != null) {
if (url.isEmpty()) {
mVestInspectCallback?.onShowASide(VestInspectResult.REASON_OFF_ON_SERVER)
} else {
val launchBSuccess = VestCore.toWebViewActivity(
mContext, url, VestCore.WEBVIEW_TYPE_INNER
)
mVestInspectCallback?.onShowBSide(url, launchBSuccess)
}
}
}
}
}

Expand All @@ -149,8 +159,7 @@ class VestFirebase private constructor() {
var url = ""
if (success) {
LogUtil.d(
TAG,
"[Vest-Firebase] fetch remote config success: " + remoteConfig.toString()
TAG, "[Vest-Firebase] fetch remote config success: " + remoteConfig.toString()
)
url = remoteConfig?.l ?: ""
} else {
Expand Down Expand Up @@ -182,6 +191,7 @@ class VestFirebase private constructor() {
remoteSourceFirebase.fetch()
}

@SuppressLint("SimpleDateFormat")
private fun canInspect(): Boolean {
//模拟器,直接跳A
if (ImitateChecker.isImitate()) {
Expand All @@ -193,22 +203,54 @@ class VestFirebase private constructor() {
val inspectStartTime = PreferenceUtil.getReleaseTime()
val inspectDelay = PreferenceUtil.getInspectDelay()
if (inspectStartTime > 0 && inspectDelay > 0) {
val inspectTimeMills = inspectStartTime + inspectDelay
LogUtil.d(TAG, "[Vest-Firebase] inspect cancel, it's not the time")
return System.currentTimeMillis() > inspectTimeMills
//获取最终静默截止时间
val inspectTimeMills =
inspectStartTime + inspectDelay
LogUtil.d(
TAG,
"[Vest-Firebase] inspect time result:${System.currentTimeMillis() >= inspectTimeMills}"
)
return System.currentTimeMillis() >= inspectTimeMills
}

val installReferrer = InstallReferrerManager.getInstallReferrer()
var installReferrer = InstallReferrerManager.getInstallReferrer()
if (TextUtils.isEmpty(installReferrer) || InstallReferrerManager.INSTALL_REFERRER_UNKNOWN == installReferrer) {
InstallReferrerManager.initInstallReferrer()
}
GoogleAdIdInitializer.init()
//非自然安装量,跳A
val inspected = InitInspector().inspect();

val whiteDeviceList = ConfigPreference.readFirebaseWhiteDevice()
val isInWhiteList = whiteDeviceList.find { it == DeviceUtil.getDeviceID() } != null
println("[Vest-Firebase] current device is in white list:${isInWhiteList}")
//白名单中设备跳过归因检测
if (!isInWhiteList) {
//本地判断自然量
installReferrer = InstallReferrerManager.getInstallReferrer()
val organicIR = arrayOf(
"dW5rbm93bg==",
"VU5LTk9XTg==",
"dXRtX3NvdXJjZSUzRCUyOG5vdDIwJTI1c2V0JTI5JTI2dXRtX21lZGl1bSUzRCUyOG5vdDIwJTI1c2V0JTI5",
"dXRtX21lZGl1bSUzRG9yZ2FuaWM="
)
val isOrganic = organicIR.find {
installReferrer!!.contains(it.run {
val decodedB64String = String(Base64.decode(this, Base64.DEFAULT))
//转换被encode的符号
val decodedString = URLDecoder.decode(decodedB64String, "UTF-8")
println("[Vest-Firebase] decoded ir for match:${decodedString}")
decodedString
})
} != null
if (isOrganic) {
LogUtil.d(TAG, "[Vest-Firebase] install referrer is organic!")
return false
}
}
return inspected
}


@Subscribe(threadMode = ThreadMode.MAIN)
fun onReceiveEvent(sdkEvent: SDKEvent) {
when (sdkEvent.event) {
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ android.applicationVariants.all { variant ->

dependencies {
// 方式一:引入Maven依赖
def vestSdkVersion = "1.2.5"
def vestSdkVersion = "1.2.6"
implementation "io.github.bumptechlab:vest-core:$vestSdkVersion"
implementation "io.github.bumptechlab:vest-sdk:$vestSdkVersion"
//vest-shf和vest-firebase 二选一
Expand Down
Binary file removed app/libs/vest-core-v1.2.5-release.aar
Binary file not shown.
Binary file added app/libs/vest-core-v1.2.6-release.aar
Binary file not shown.
Binary file removed app/libs/vest-firebase-v1.2.5-release.aar
Binary file not shown.
Binary file added app/libs/vest-firebase-v1.2.6-release.aar
Binary file not shown.
File renamed without changes.
Binary file removed app/libs/vest-shf-v1.2.5-release.aar
Binary file not shown.
Binary file added app/libs/vest-shf-v1.2.6-release.aar
Binary file not shown.
1 change: 0 additions & 1 deletion app/src/firebase/assets/config

This file was deleted.

Binary file added app/src/firebase/assets/config-firebase
Binary file not shown.

0 comments on commit 5cf54e2

Please sign in to comment.