Skip to content

Commit 63d3134

Browse files
author
dengshiwei
committed
Release 3.2.7
1 parent cf1b739 commit 63d3134

File tree

7 files changed

+115
-14
lines changed

7 files changed

+115
-14
lines changed

plugin/ext.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project.ext {
2-
pluginVersion = '3.2.6'
2+
pluginVersion = '3.2.7'
33
Properties properties = new Properties()
44
if (project.file('local.properties').exists()) {
55
properties.load(project.file('local.properties').newDataInputStream())

plugin/src/main/groovy/com/sensorsdata/analytics/android/plugin/SensorsAnalyticsClassVisitor.groovy

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ class SensorsAnalyticsClassVisitor extends ClassVisitor {
134134
if (classNameAnalytics.isSensorsDataAPI) {
135135
if ('VERSION' == name) {
136136
String version = (String) value
137-
if (SensorsAnalyticsTransform.MIN_SDK_VERSION > version) {
137+
if (SensorsAnalyticsUtil.compareVersion(SensorsAnalyticsTransform.MIN_SDK_VERSION, version) > 0) {
138138
String errMessage = "你目前集成的神策埋点 SDK 版本号为 v${version},请升级到 v${SensorsAnalyticsTransform.MIN_SDK_VERSION} 及以上的版本。详情请参考:https://github.com/sensorsdata/sa-sdk-android"
139139
Logger.error(errMessage)
140140
throw new Error(errMessage)
141141
}
142142
} else if ('MIN_PLUGIN_VERSION' == name) {
143143
String minPluginVersion = (String) value
144144
if (minPluginVersion != "" && minPluginVersion != null) {
145-
if (SensorsAnalyticsTransform.VERSION < minPluginVersion) {
145+
if (SensorsAnalyticsUtil.compareVersion(SensorsAnalyticsTransform.VERSION, minPluginVersion) < 0) {
146146
String errMessage = "你目前集成的神策插件版本号为 v${SensorsAnalyticsTransform.VERSION},请升级到 v${minPluginVersion} 及以上的版本。详情请参考:https://github.com/sensorsdata/sa-sdk-android-plugin2"
147147
Logger.error(errMessage)
148148
throw new Error(errMessage)
@@ -173,7 +173,7 @@ class SensorsAnalyticsClassVisitor extends ClassVisitor {
173173

174174
MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, signature, exceptions)
175175
if (transformHelper.extension != null && transformHelper.extension.autoHandleWebView && transformHelper.urlClassLoader != null) {
176-
methodVisitor = new SensorsAnalyticsWebViewMethodVisitor(methodVisitor, transformHelper, mClassName)
176+
methodVisitor = new SensorsAnalyticsWebViewMethodVisitor(methodVisitor, transformHelper, mClassName, mSuperName)
177177
}
178178
SensorsAnalyticsDefaultMethodVisitor sensorsAnalyticsDefaultMethodVisitor = new SensorsAnalyticsDefaultMethodVisitor(methodVisitor, access, name, desc) {
179179
boolean isSensorsDataTrackViewOnClickAnnotation = false
@@ -498,13 +498,21 @@ class SensorsAnalyticsClassVisitor extends ClassVisitor {
498498
}
499499
}
500500
}
501-
502-
if (isOnClickMethod) {
501+
handleClassMethod(mClassName, nameDesc)
502+
if (!isHasTracked && isOnClickMethod) {
503503
trackViewOnClick(methodVisitor, variableID)
504504
isHasTracked = true
505505
}
506506
}
507507

508+
void handleClassMethod(String className, String nameDesc) {
509+
SensorsAnalyticsMethodCell sensorsAnalyticsMethodCell = SensorsAnalyticsHookConfig.CLASS_METHODS.get(className + nameDesc)
510+
if (sensorsAnalyticsMethodCell != null) {
511+
visitMethodWithLoadedParams(methodVisitor, INVOKESTATIC, SensorsAnalyticsHookConfig.SENSORS_ANALYTICS_API, sensorsAnalyticsMethodCell.agentName, sensorsAnalyticsMethodCell.agentDesc, sensorsAnalyticsMethodCell.paramsStart, sensorsAnalyticsMethodCell.paramsCount, sensorsAnalyticsMethodCell.opcodes)
512+
isHasTracked = true
513+
}
514+
}
515+
508516
boolean handleRN() {
509517
boolean result = false
510518
switch (transformHelper.rnState) {

plugin/src/main/groovy/com/sensorsdata/analytics/android/plugin/SensorsAnalyticsHookConfig.groovy

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.objectweb.asm.Opcodes
2121
class SensorsAnalyticsHookConfig {
2222
public static final String SENSORS_ANALYTICS_API = "com/sensorsdata/analytics/android/sdk/SensorsDataAutoTrackHelper"
2323
public final static HashMap<String, SensorsAnalyticsMethodCell> INTERFACE_METHODS = new HashMap<>()
24+
public final static HashMap<String, SensorsAnalyticsMethodCell> CLASS_METHODS = new HashMap<>()
2425

2526
static {
2627
addInterfaceMethod(new SensorsAnalyticsMethodCell(
@@ -201,12 +202,47 @@ class SensorsAnalyticsHookConfig {
201202
[Opcodes.ALOAD]))
202203
}
203204

205+
static {
206+
addClassMethod(new SensorsAnalyticsMethodCell(
207+
'performClick',
208+
'()Z',
209+
'androidx/appcompat/widget/ActionMenuPresenter$OverflowMenuButton',
210+
'trackViewOnClick',
211+
'(Landroid/view/View;)V',
212+
0, 1,
213+
[Opcodes.ALOAD]))
214+
215+
addClassMethod(new SensorsAnalyticsMethodCell(
216+
'performClick',
217+
'()Z',
218+
'android/support/v7/widget/ActionMenuPresenter$OverflowMenuButton',
219+
'trackViewOnClick',
220+
'(Landroid/view/View;)V',
221+
0, 1,
222+
[Opcodes.ALOAD]))
223+
224+
addClassMethod(new SensorsAnalyticsMethodCell(
225+
'performClick',
226+
'()Z',
227+
'android/widget/ActionMenuPresenter$OverflowMenuButton',
228+
'trackViewOnClick',
229+
'(Landroid/view/View;)V',
230+
0, 1,
231+
[Opcodes.ALOAD]))
232+
}
233+
204234
static void addInterfaceMethod(SensorsAnalyticsMethodCell sensorsAnalyticsMethodCell) {
205235
if (sensorsAnalyticsMethodCell != null) {
206236
INTERFACE_METHODS.put(sensorsAnalyticsMethodCell.parent + sensorsAnalyticsMethodCell.name + sensorsAnalyticsMethodCell.desc, sensorsAnalyticsMethodCell)
207237
}
208238
}
209239

240+
static void addClassMethod(SensorsAnalyticsMethodCell sensorsAnalyticsMethodCell) {
241+
if (sensorsAnalyticsMethodCell != null) {
242+
CLASS_METHODS.put(sensorsAnalyticsMethodCell.parent + sensorsAnalyticsMethodCell.name + sensorsAnalyticsMethodCell.desc, sensorsAnalyticsMethodCell)
243+
}
244+
}
245+
210246
/**
211247
* Fragment中的方法
212248
*/

plugin/src/main/groovy/com/sensorsdata/analytics/android/plugin/SensorsAnalyticsTransform.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import java.util.jar.JarOutputStream
4646

4747
class SensorsAnalyticsTransform extends Transform {
4848
private SensorsAnalyticsTransformHelper transformHelper
49-
public static final String VERSION = "3.2.6"
49+
public static final String VERSION = "3.2.7"
5050
public static final String MIN_SDK_VERSION = "4.0.7"
5151
private WaitableExecutor waitableExecutor
5252
private URLClassLoader urlClassLoader

plugin/src/main/groovy/com/sensorsdata/analytics/android/plugin/SensorsAnalyticsTransformHelper.groovy

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ class SensorsAnalyticsTransformHelper {
3333
'com.jakewharton.rxbinding.view.ViewClickOnSubscribe',
3434
'com.facebook.react.uimanager.NativeViewHierarchyManager'])
3535
/** 将一些特例需要排除在外 */
36-
public static final HashSet<String> special = new HashSet<>(['android.support.design.widget.TabLayout$ViewPagerOnTabSelectedListener',
37-
'com.google.android.material.tabs.TabLayout$ViewPagerOnTabSelectedListener',
38-
'android.support.v7.app.ActionBarDrawerToggle',
39-
'androidx.appcompat.app.ActionBarDrawerToggle'])
36+
public static final HashSet<String> special = ['android.support.design.widget.TabLayout$ViewPagerOnTabSelectedListener',
37+
'com.google.android.material.tabs.TabLayout$ViewPagerOnTabSelectedListener',
38+
'android.support.v7.app.ActionBarDrawerToggle',
39+
'androidx.appcompat.app.ActionBarDrawerToggle',
40+
'androidx.appcompat.widget.ActionMenuPresenter$OverflowMenuButton',
41+
'android.widget.ActionMenuPresenter$OverflowMenuButton',
42+
'android.support.v7.widget.ActionMenuPresenter$OverflowMenuButton']
4043
URLClassLoader urlClassLoader
4144

4245
SensorsAnalyticsTransformHelper(SensorsAnalyticsExtension extension, AppExtension android) {

plugin/src/main/groovy/com/sensorsdata/analytics/android/plugin/SensorsAnalyticsUtil.groovy

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,45 @@ class SensorsAnalyticsUtil {
8282
return specialClass.contains(className)
8383
}
8484

85+
/**
86+
* 比较两个字符串版本信息大小,例如 2.01.10 > 2.1.9.1.2
87+
*
88+
* @param version1 版本信息字符串
89+
* @param version2 版本信息字符串
90+
* @return 如果返回值为 0,表示版本相等;如果返回值为 1 表示 version1 大于 version2;如果返回值为 -1,表示 version1 小于 version2。
91+
*/
92+
static int compareVersion(String version1, String version2) {
93+
def v1Array = version1.replace("-pre", "").split("\\.")
94+
def v2Array = version2.replace("-pre", "").split("\\.")
95+
def maxLength = Math.max(v1Array.length, v2Array.length)
96+
String str1, str2
97+
for (int index = 0; index < maxLength; index++) {
98+
if (v1Array.length > index) {
99+
str1 = v1Array[index]
100+
} else {
101+
return -1
102+
}
103+
if (v2Array.length > index) {
104+
str2 = v2Array[index]
105+
} else {
106+
return 1
107+
}
108+
if (str1 != null && str2 != null) {
109+
try {
110+
int num1 = Integer.valueOf(str1)
111+
int num2 = Integer.valueOf(str2)
112+
if (num1 != num2) {
113+
return num1 - num2 > 0 ? 1 : -1
114+
}
115+
} catch (Exception ignored) {
116+
return str1 <=> str2
117+
}
118+
}
119+
}
120+
return 0
121+
}
122+
123+
85124
static byte[] toByteArrayAndAutoCloseStream(InputStream input) throws Exception {
86125
ByteArrayOutputStream output = null
87126
try {

plugin/src/main/groovy/com/sensorsdata/analytics/android/plugin/SensorsAnalyticsWebViewMethodVisitor.groovy

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,20 @@ class SensorsAnalyticsWebViewMethodVisitor extends MethodVisitor implements Opco
3434
private static final def VIEW_DESC = "Landroid/view/View;"
3535
private static final def OWNER_WHITE_SET = new HashSet(["android/webkit/WebView", "com/tencent/smtt/sdk/WebView"])
3636
private String className
37+
private String superName
3738

3839

39-
SensorsAnalyticsWebViewMethodVisitor(MethodVisitor mv, SensorsAnalyticsTransformHelper transformHelper, String className) {
40+
SensorsAnalyticsWebViewMethodVisitor(MethodVisitor mv, SensorsAnalyticsTransformHelper transformHelper, String className, String superName) {
4041
super(SensorsAnalyticsUtil.ASM_VERSION, mv)
4142
this.transformHelper = transformHelper
4243
this.className = className
44+
this.superName = superName
4345
}
4446

4547
@Override
4648
void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
4749
if (TARGET_NAME_DESC.contains(name + desc)) {
48-
//忽略 WebView 的子类
49-
if (!isAssignableWebView(className)) {
50+
if (!checkWebViewChild(className)) {
5051
if (isAssignableWebView(owner)) {
5152
opcode = INVOKESTATIC
5253
owner = SensorsAnalyticsHookConfig.SENSORS_ANALYTICS_API
@@ -57,6 +58,19 @@ class SensorsAnalyticsWebViewMethodVisitor extends MethodVisitor implements Opco
5758
super.visitMethodInsn(opcode, owner, name, desc, itf)
5859
}
5960

61+
/**
62+
* 判断是否是 WebView 的子类,避免 WebView 子类中调用 load* 方法,导致的递归调用
63+
*
64+
* @param className 当前被处理的类
65+
* @return true 是 WebView 的子类,false 非 WebView 子类
66+
*/
67+
private boolean checkWebViewChild(String className) {
68+
if (superName == "com/tencent/smtt/sdk/WebViewClient") {
69+
return false
70+
}
71+
isAssignableWebView(className)
72+
}
73+
6074
private boolean isAssignableWebView(String owner) {
6175
try {
6276
if (OWNER_WHITE_SET.contains(owner)) {
@@ -105,6 +119,7 @@ class SensorsAnalyticsWebViewMethodVisitor extends MethodVisitor implements Opco
105119
}
106120
}
107121

122+
108123
private static String reStructureDesc(String desc) {
109124
return desc.replaceFirst("\\(", "(" + VIEW_DESC)
110125
}

0 commit comments

Comments
 (0)