Skip to content

Commit

Permalink
fix(core.transform): 识别实现了onReceive方法的类时,排除静态内部类
Browse files Browse the repository at this point in the history
静态内部类getDeclaredMethod时能获取到父类定义的方法,
但它带有Volatile标志位。
  • Loading branch information
shifujun committed Apr 18, 2023
1 parent 66eb1d3 commit 18c718e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ package com.tencent.shadow.core.transform.specific

import com.tencent.shadow.core.transform_kit.SpecificTransform
import com.tencent.shadow.core.transform_kit.TransformStep
import javassist.*
import javassist.CodeConverter
import javassist.CtClass
import javassist.CtMethod
import javassist.Modifier
import javassist.NotFoundException
import javassist.compiler.Javac.CtFieldWithInit

/**
Expand Down Expand Up @@ -70,7 +74,7 @@ class ReceiverSupportTransform : SpecificTransform() {
} catch (e: NotFoundException) {
null
}
if (onReceiveMethod != null) {
if (onReceiveMethod != null && !Modifier.isVolatile(onReceiveMethod.modifiers)) {
targetReceivers.add(ctClass)
}
}
Expand Down
27 changes: 27 additions & 0 deletions projects/sdk/core/transform/src/test/java/test/EggReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package test;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import java.util.List;

abstract class EggReceiver extends BroadcastReceiver {
List<String> log;

EggReceiver(List<String> log) {
this.log = log;
}

@Override
public void onReceive(Context context, Intent intent) {
log.add("EggReceiver onReceive");
}

public static class FoxReceiver extends EggReceiver {
FoxReceiver(List<String> log) {
super(log);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class ReceiverSupportTransformTest : AbstractTransformTest() {
"test.BarReceiver",
"test.CatReceiver",
"test.DogReceiver",
"test.EggReceiver",
"test.EggReceiver\$FoxReceiver",
)
].toMutableSet()

Expand Down

0 comments on commit 18c718e

Please sign in to comment.