com.hina.analytics.android.plugin.manager.SAPluginManager.kt Maven / Gradle / Ivy
package com.hina.analytics.android.plugin.manager
import com.hina.analytics.android.gradle.AGPVersion
import com.hina.analytics.android.plugin.configs.SAConfigHookHelper
import com.hina.analytics.android.plugin.extension.SAExtension
import com.hina.analytics.android.plugin.utils.Logger
import com.hina.analytics.android.plugin.version.SensorsDataSDKVersionHelper
import org.gradle.api.Project
import org.objectweb.asm.Opcodes
class SAPluginManager(private val project: Project) {
lateinit var extension: SAExtension
var isHookOnMethodEnter = false
var isAndroidTV = false
private var asmVersion = "ASM7"
val packageManager: SAPackageManager by lazy {
SAPackageManager().apply {
exclude.addAll(extension.exclude)
include.addAll(extension.include)
}
}
private val supportedModules: Set by lazy {
val set = mutableSetOf()
extension.disableModules.forEach {
set.add(SAModule.valueOf(it.uppercase()))
}
set
}
init {
createExtension()
parseProperty()
checkDependency()
otherInit()
}
val sdkVersionHelper: SensorsDataSDKVersionHelper by lazy {
SensorsDataSDKVersionHelper()
}
private fun checkDependency() {
project.afterEvaluate {
if (!project.plugins.hasPlugin("com.android.application")) {
check(false) {
"Hina Data Android Plugin must used at Android App Project"
}
}
/*//需要充分考虑到模块中依赖 sdk 和 aar 依赖
val dependencies = project.configurations.flatMap { it.dependencies }
dependencies.forEach {
val name = it.name
val group = it.group
val version = it.version
if ("HinaCloudSDK" == name) {
isAutoTrackInstall = true
isPushModuleInstall = true
if (version != null && version != "unspecified" && group == "com.hinadt.hicloud.android") {
check(
SensorsAnalyticsUtil.compareVersion(
VersionConstant.MIN_SDK_VERSION,
version
) <= 0
) {
"你目前集成的海纳嗨数插件版本号为 v$version,请升级到 v${VersionConstant.MIN_SDK_VERSION} 及以上的版本。"
}
}
}
}*/
}
}
private fun createExtension() {
extension = project.extensions.create("hinaAnalytics", SAExtension::class.java)
}
private fun parseProperty() {
project.properties.apply {
isHookOnMethodEnter =
(getOrDefault("hinaAnalytics.isHookOnMethodEnter", "") as String).toBoolean()
isAndroidTV =
(getOrDefault("hinaAnalytics.isAndroidTv", "false") as String).toBoolean()
asmVersion = getOrDefault("hinaAnalytics.asmVersion", "ASM7") as String
if (AGPVersion.CURRENT_AGP_VERSION >= AGPVersion(8, 0, 0)) {
asmVersion = "ASM9"
}
}
}
private fun otherInit() {
project.afterEvaluate {
SAConfigHookHelper.initSDKConfigCells(extension)
Logger.debug = extension.debug
//module check
}
}
fun getASMVersion(): Int {
return when (asmVersion) {
"ASM6" -> Opcodes.ASM6
"ASM7" -> Opcodes.ASM7
"ASM8" -> Opcodes.ASM8
"ASM9" -> Opcodes.ASM9
else -> Opcodes.ASM7
}
}
internal fun getASMVersionStr(): String = asmVersion
fun isModuleEnable(module: SAModule) = !supportedModules.contains(module)
}
enum class SAModule {
AUTOTRACK, PUSH, WEB_VIEW, REACT_NATIVE
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy