diff --git a/cronet/src/main/java/io/grpc/cronet/InternalCronetCallOptions.java b/cronet/src/main/java/io/grpc/cronet/InternalCronetCallOptions.java index 321354f1a92..e7c4144e63a 100644 --- a/cronet/src/main/java/io/grpc/cronet/InternalCronetCallOptions.java +++ b/cronet/src/main/java/io/grpc/cronet/InternalCronetCallOptions.java @@ -18,6 +18,8 @@ import io.grpc.CallOptions; import io.grpc.Internal; +import java.util.Collection; +import java.util.Collections; /** * Internal accessor class for call options using with the Cronet transport. This is intended for @@ -33,4 +35,17 @@ private InternalCronetCallOptions() {} public static CallOptions withAnnotation(CallOptions callOptions, Object annotation) { return CronetClientStream.withAnnotation(callOptions, annotation); } + + /** + * Returns Cronet annotations for gRPC included in the given {@code callOptions}. Annotations + * are attached via {@link #withAnnotation(CallOptions, Object)}. + */ + public static Collection getAnnotations(CallOptions callOptions) { + Collection annotations = + callOptions.getOption(CronetClientStream.CRONET_ANNOTATIONS_KEY); + if (annotations == null) { + annotations = Collections.emptyList(); + } + return annotations; + } }