diff options
author | 2024-11-26 12:36:26 -0800 | |
---|---|---|
committer | 2024-11-26 15:15:48 -0800 | |
commit | e11147f7ff3ab692421a16f0d90e34274ee4f362 (patch) | |
tree | 1cd50a7e3b8d1f6e0fffff90eabf0bc056cbfe96 /ravenwood/junit-src | |
parent | c4a715709ee9116e17a2c81772e87061680ae2b7 (diff) |
Add a way to configure log levels
Bug: 381112373
Bug: 380949304
Bug: 380938496
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh -s
Flag: EXEMPT host test change only
Change-Id: I3851ba55abf8cdbdf518dda83b4780f2128c013d
Diffstat (limited to 'ravenwood/junit-src')
-rw-r--r-- | ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java index e49d3d934e9f..d4b15c66c68b 100644 --- a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java +++ b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java @@ -193,6 +193,12 @@ public final class RavenwoodRule implements TestRule { return IS_ON_RAVENWOOD; } + private static void ensureOnRavenwood(String featureName) { + if (!IS_ON_RAVENWOOD) { + throw new RuntimeException(featureName + " is only supported on Ravenwood."); + } + } + /** * @deprecated Use * {@code androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().getContext()} @@ -242,6 +248,40 @@ public final class RavenwoodRule implements TestRule { return System.currentTimeMillis(); } + /** + * Equivalent to setting the ANDROID_LOG_TAGS environmental variable. + * + * See https://developer.android.com/tools/logcat#filteringOutput for the string format. + * + * NOTE: this works only on Ravenwood. + */ + public static void setAndroidLogTags(@Nullable String androidLogTags) { + ensureOnRavenwood("RavenwoodRule.setAndroidLogTags()"); + try { + Class<?> logRavenwoodClazz = Class.forName("android.util.Log_ravenwood"); + var setter = logRavenwoodClazz.getMethod("setLogLevels", String.class); + setter.invoke(null, androidLogTags); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + /** + * Set a log level for a given tag. Pass NULL to {@code tag} to change the default level. + * + * NOTE: this works only on Ravenwood. + */ + public static void setLogLevel(@Nullable String tag, int level) { + ensureOnRavenwood("RavenwoodRule.setLogLevel()"); + try { + Class<?> logRavenwoodClazz = Class.forName("android.util.Log_ravenwood"); + var setter = logRavenwoodClazz.getMethod("setLogLevel", String.class, int.class); + setter.invoke(null, tag, level); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + // Below are internal to ravenwood. Don't use them from normal tests... public static class RavenwoodPrivate { |