diff options
author | Andrei Onea <andreionea@google.com> | 2019-01-25 15:56:53 +0000 |
---|---|---|
committer | Andrei-Valentin Onea <andreionea@google.com> | 2019-01-30 16:17:10 +0000 |
commit | be10c8582784ab64786fc71973fdbd37c480d3e2 (patch) | |
tree | bbc253cc2e48f905d2bdfbfc7d4c4a6adb257409 /libart | |
parent | 522a3fdf84285e7dd8d8b527e462209bca1da9dc (diff) |
Allow hidden api usage logging with VMRuntime
Added HiddenApiUsage interface, a static setter, and two static methods
which forward the hidden api usage events to the logger (for access via
JNI and via reflection)
Topic: hidden-api-reporting-upcall
Test: m
Bug: 119217680
Change-Id: I0185ebda779f9df3d4186806a6696b063847ad1c
Merged-In: Ia2f154f4649c5f0c22c55e6a12c0399a5912deb8
Diffstat (limited to 'libart')
-rw-r--r-- | libart/src/main/java/dalvik/system/VMRuntime.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libart/src/main/java/dalvik/system/VMRuntime.java b/libart/src/main/java/dalvik/system/VMRuntime.java index d2f0317b18..c5cabe31c4 100644 --- a/libart/src/main/java/dalvik/system/VMRuntime.java +++ b/libart/src/main/java/dalvik/system/VMRuntime.java @@ -56,6 +56,77 @@ public final class VMRuntime { } /** + * Interface for logging hidden API usage events. + */ + @libcore.api.CorePlatformApi + public interface HiddenApiUsageLogger { + + // The following ACCESS_METHOD_ constants must match the values in + // art/runtime/hidden_api.h + /** + * Internal test value that does not correspond to an actual access by the + * application. Never logged, added for completeness. + */ + public static final int ACCESS_METHOD_NONE = 0; + + /** + * Used when a method has been accessed via reflection. + */ + public static final int ACCESS_METHOD_REFLECTION = 1; + + /** + * Used when a method has been accessed via JNI. + */ + public static final int ACCESS_METHOD_JNI = 2; + + /** + * Used when a method is accessed at link time. Never logged, added only + * for completeness. + */ + public static final int ACCESS_METHOD_LINKING = 3; + + /** + * Logs hidden API access + * + * @param appPackageName package name of the app attempting the access + * @param signature signature of the method being called, i.e + * class_name->member_name:type_signature (e.g. + * {@code com.android.app.Activity->mDoReportFullyDrawn:Z}) for fields and + * class_name->method_name_and_signature for methods (e.g + * {@code com.android.app.Activity->finish(I)V}) + * @param accessType how the accessed was done + * @param accessDenied whether the access was allowed or not + */ + public void hiddenApiUsed(String appPackageName, String signature, + int accessType, boolean accessDenied); + } + + static HiddenApiUsageLogger hiddenApiUsageLogger; + + /** + * Sets the hidden API usage logger {@link #hiddenApiUsageLogger}. + * It should only be called if {@link #setHiddenApiAccessLogSamplingRate(int)} + * is called with a value > 0 + */ + @libcore.api.CorePlatformApi + public static void setHiddenApiUsageLogger(HiddenApiUsageLogger hiddenApiUsageLogger) { + VMRuntime.hiddenApiUsageLogger = hiddenApiUsageLogger; + } + + /** + * Records an attempted hidden API access to + * {@link HiddenApiUsageLogger#hiddenApiUsed(String, String, int, boolean} + * if a logger is registered via {@link #setHiddenApiUsageLogger}. + */ + private static void hiddenApiUsed(String appPackageName, String signature, + int accessType, boolean accessDenied) { + if (VMRuntime.hiddenApiUsageLogger != null) { + VMRuntime.hiddenApiUsageLogger.hiddenApiUsed(appPackageName, signature, + accessType, accessDenied); + } + } + + /** * Magic version number for a current development build, which has not * yet turned into an official release. This number must be larger than * any released version in {@code android.os.Build.VERSION_CODES}. |