Skip to content

Commit

Permalink
Release 3.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dengshiwei committed Jun 29, 2020
1 parent d06cde8 commit 6c54b04
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugin/ext.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project.ext {
pluginVersion = '3.2.4'
pluginVersion = '3.2.5'
Properties properties = new Properties()
if (project.file('local.properties').exists()) {
properties.load(project.file('local.properties').newDataInputStream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ class SensorsAnalyticsClassVisitor extends ClassVisitor {
case SensorsAnalyticsTransformHelper.RN_STATE.NOT_FOUND:
break
case SensorsAnalyticsTransformHelper.RN_STATE.HAS_VERSION:
if (transformHelper.rnVersion > '2.0.0' && mSuperName == "com/facebook/react/uimanager/ViewGroupManager"
&& nameDesc == "addView(Landroid/view/ViewGroup;Landroid/view/View;I)V") {
methodVisitor.visitVarInsn(ALOAD, 2)
methodVisitor.visitVarInsn(ILOAD, 3)
methodVisitor.visitMethodInsn(INVOKESTATIC, "com/sensorsdata/analytics/RNAgent", "addView", "(Landroid/view/View;I)V", false)
result = true
}

if (nameDesc == 'handleTouchEvent(Landroid/view/MotionEvent;Lcom/facebook/react/uimanager/events/EventDispatcher;)V' && mClassName == 'com/facebook/react/uimanager/JSTouchDispatcher') {
methodVisitor.visitVarInsn(ALOAD, 0)
methodVisitor.visitVarInsn(ALOAD, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ import groovy.io.FileType
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils
import org.apache.commons.io.output.ByteArrayOutputStream
import org.objectweb.asm.ClassReader
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.ClassWriter

import java.lang.reflect.Field
import java.util.concurrent.Callable
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry

class SensorsAnalyticsTransform extends Transform {
private SensorsAnalyticsTransformHelper transformHelper
public static final String VERSION = "3.2.4"
public static final String VERSION = "3.2.5"
public static final String MIN_SDK_VERSION = "4.0.7"
private WaitableExecutor waitableExecutor
private URLClassLoader urlClassLoader
Expand Down Expand Up @@ -126,7 +127,6 @@ class SensorsAnalyticsTransform extends Transform {
if (waitableExecutor) {
waitableExecutor.waitForTasksWithQuickFail(true)
}

println("[SensorsAnalytics]: 此次编译共耗时:${System.currentTimeMillis() - startTime}毫秒")
}

Expand Down Expand Up @@ -176,7 +176,9 @@ class SensorsAnalyticsTransform extends Transform {
try {
Class rnClazz = urlClassLoader.loadClass("com.sensorsdata.analytics.RNSensorsAnalyticsPackage")
try {
rnClazz.getDeclaredField("VERSION")
Field versionField = rnClazz.getDeclaredField("VERSION")
versionField.setAccessible(true)
transformHelper.rnVersion = versionField.get(null) as String
transformHelper.rnState = SensorsAnalyticsTransformHelper.RN_STATE.HAS_VERSION
} catch (Exception e) {
transformHelper.rnState = SensorsAnalyticsTransformHelper.RN_STATE.NO_VERSION
Expand Down Expand Up @@ -325,6 +327,7 @@ class SensorsAnalyticsTransform extends Transform {
try {
inputStream = file.getInputStream(jarEntry)
} catch (Exception e) {
IOUtils.closeQuietly(inputStream)
e.printStackTrace()
return null
}
Expand All @@ -338,9 +341,11 @@ class SensorsAnalyticsTransform extends Transform {
byte[] sourceClassBytes
try {
jarOutputStream.putNextEntry(entry)
sourceClassBytes = IOUtils.toByteArray(inputStream)
sourceClassBytes = SensorsAnalyticsUtil.toByteArrayAndAutoCloseStream(inputStream)
} catch (Exception e) {
Logger.error("Exception encountered while processing jar: " + jarFile.getAbsolutePath())
IOUtils.closeQuietly(file)
IOUtils.closeQuietly(jarOutputStream)
e.printStackTrace()
return null
}
Expand Down Expand Up @@ -394,7 +399,7 @@ class SensorsAnalyticsTransform extends Transform {
String className = path2ClassName(classFile.absolutePath.replace(dir.absolutePath + File.separator, ""))
ClassNameAnalytics classNameAnalytics = transformHelper.analytics(className)
if (classNameAnalytics.isShouldModify) {
byte[] sourceClassBytes = IOUtils.toByteArray(new FileInputStream(classFile))
byte[] sourceClassBytes = SensorsAnalyticsUtil.toByteArrayAndAutoCloseStream(new FileInputStream(classFile))
byte[] modifiedClassBytes = modifyClass(sourceClassBytes, classNameAnalytics)
if (modifiedClassBytes) {
modified = new File(tempDir, className.replace('.', '') + '.class')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SensorsAnalyticsTransformHelper {
SensorsAnalyticsExtension extension
AppExtension android
RN_STATE rnState = RN_STATE.NOT_FOUND
String rnVersion = ""
SensorsAnalyticsSDKHookConfig sensorsAnalyticsHookConfig
boolean disableSensorsAnalyticsMultiThread
boolean disableSensorsAnalyticsIncremental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.sensorsdata.analytics.android.plugin

import groovy.transform.CompileStatic
import org.apache.commons.io.IOUtils
import org.apache.commons.io.output.ByteArrayOutputStream
import org.objectweb.asm.Opcodes

@CompileStatic
Expand Down Expand Up @@ -79,4 +81,23 @@ class SensorsAnalyticsUtil {
static boolean isTargetClassInSpecial(String className) {
return specialClass.contains(className)
}

static byte[] toByteArrayAndAutoCloseStream(InputStream input) throws Exception {
ByteArrayOutputStream output = null
try {
output = new ByteArrayOutputStream();
byte[] buffer = new byte[1024 * 4]
int n = 0
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n)
}
output.flush()
return output.toByteArray()
} catch (Exception e) {
throw e
} finally {
IOUtils.closeQuietly(output)
IOUtils.closeQuietly(input)
}
}
}

0 comments on commit 6c54b04

Please sign in to comment.