check-flagged-apis: add support for method with parameters

Teach check-flagged-apis to parse methods containing parameters.

Bug: 334870672
Test: atest --host check-flagged-apis-test
Change-Id: I171660b914b73fd85e03ed9300c2c81f33d80d61
This commit is contained in:
Mårten Kongstad 2024-04-28 00:21:11 +02:00
parent ece054c856
commit b4a14bfaa9
2 changed files with 28 additions and 6 deletions

View file

@ -34,6 +34,9 @@ private val API_SIGNATURE =
ctor @FlaggedApi("android.flag.foo") public Clazz();
field @FlaggedApi("android.flag.foo") public static final int FOO = 1; // 0x1
method @FlaggedApi("android.flag.foo") public int getErrorCode();
method @FlaggedApi("android.flag.foo") public boolean setData(int, int[][], @NonNull android.util.Utility<T, U>);
method @FlaggedApi("android.flag.foo") public boolean setVariableData(int, android.util.Atom...);
method @FlaggedApi("android.flag.foo") public boolean innerClassArg(android.Clazz.Builder);
}
@FlaggedApi("android.flag.bar") public static class Clazz.Builder {
}
@ -49,6 +52,9 @@ private val API_VERSIONS =
<method name="&lt;init>()V"/>
<field name="FOO"/>
<method name="getErrorCode()I"/>
<method name="setData(I[[ILandroid/util/Utility;)Z"/>
<method name="setVariableData(I[Landroid/util/Atom;)Z"/>
<method name="innerClassArg(Landroid/Clazz${"$"}Builder;)"/>
</class>
<class name="android/Clazz${"$"}Builder" since="2">
</class>
@ -93,6 +99,15 @@ class CheckFlaggedApisTest {
Pair(Symbol("android/Clazz/Clazz()"), Flag("android.flag.foo")),
Pair(Symbol("android/Clazz/FOO"), Flag("android.flag.foo")),
Pair(Symbol("android/Clazz/getErrorCode()"), Flag("android.flag.foo")),
Pair(
Symbol("android/Clazz/setData(I[[ILandroid/util/Utility;)"),
Flag("android.flag.foo")),
Pair(
Symbol("android/Clazz/setVariableData(I[Landroid/util/Atom;)"),
Flag("android.flag.foo")),
Pair(
Symbol("android/Clazz/innerClassArg(Landroid/Clazz/Builder;)"),
Flag("android.flag.foo")),
Pair(Symbol("android/Clazz/Builder"), Flag("android.flag.bar")),
)
val actual = parseApiSignature("in-memory", API_SIGNATURE.byteInputStream())
@ -115,6 +130,9 @@ class CheckFlaggedApisTest {
Symbol("android/Clazz/Clazz()"),
Symbol("android/Clazz/FOO"),
Symbol("android/Clazz/getErrorCode()"),
Symbol("android/Clazz/setData(I[[ILandroid/util/Utility;)"),
Symbol("android/Clazz/setVariableData(I[Landroid/util/Atom;)"),
Symbol("android/Clazz/innerClassArg(Landroid/Clazz/Builder;)"),
Symbol("android/Clazz/Builder"),
)
val actual = parseApiVersions(API_VERSIONS.byteInputStream())
@ -142,6 +160,15 @@ class CheckFlaggedApisTest {
DisabledFlaggedApiIsPresentError(Symbol("android/Clazz/FOO"), Flag("android.flag.foo")),
DisabledFlaggedApiIsPresentError(
Symbol("android/Clazz/getErrorCode()"), Flag("android.flag.foo")),
DisabledFlaggedApiIsPresentError(
Symbol("android/Clazz/setData(I[[ILandroid/util/Utility;)"),
Flag("android.flag.foo")),
DisabledFlaggedApiIsPresentError(
Symbol("android/Clazz/setVariableData(I[Landroid/util/Atom;)"),
Flag("android.flag.foo")),
DisabledFlaggedApiIsPresentError(
Symbol("android/Clazz/innerClassArg(Landroid/Clazz/Builder;)"),
Flag("android.flag.foo")),
DisabledFlaggedApiIsPresentError(
Symbol("android/Clazz/Builder"), Flag("android.flag.bar")),
)

View file

@ -178,7 +178,6 @@ The tool will exit with a non-zero exit code if any flagged APIs are found to be
}
internal fun parseApiSignature(path: String, input: InputStream): Set<Pair<Symbol, Flag>> {
// TODO(334870672): add support for metods
val output = mutableSetOf<Pair<Symbol, Flag>>()
val visitor =
object : BaseItemVisitor() {
@ -203,11 +202,7 @@ internal fun parseApiSignature(path: String, input: InputStream): Set<Pair<Symbo
append(".")
append(method.name())
append("(")
// TODO(334870672): replace this early return with proper parsing of the command line
// arguments, followed by translation to Lname/of/class; + III format
if (!method.parameters().isEmpty()) {
return
}
method.parameters().joinTo(this, separator = "") { it.type().internalName() }
append(")")
}
val symbol = Symbol.create(name)