From b4a14bfaa9915d8da91a4ad4987c39b033aab5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Sun, 28 Apr 2024 00:21:11 +0200 Subject: [PATCH] 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 --- .../checkflaggedapis/CheckFlaggedApisTest.kt | 27 +++++++++++++++++++ .../src/com/android/checkflaggedapis/Main.kt | 7 +---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt b/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt index 04c2f80e79..2f76b2a5a7 100644 --- a/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt +++ b/tools/check-flagged-apis/src/com/android/checkflaggedapis/CheckFlaggedApisTest.kt @@ -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); + 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 = + + + @@ -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")), ) diff --git a/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt b/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt index 0f2fbef719..e15e7fa6eb 100644 --- a/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt +++ b/tools/check-flagged-apis/src/com/android/checkflaggedapis/Main.kt @@ -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> { - // TODO(334870672): add support for metods val output = mutableSetOf>() val visitor = object : BaseItemVisitor() { @@ -203,11 +202,7 @@ internal fun parseApiSignature(path: String, input: InputStream): Set