Context
While removing GetValueMarshaler*() support from the trimmable typemap value manager, we noticed that Android.Graphics.Color still has:
[JniValueMarshaler (typeof (ColorValueMarshaler))]
public struct Color
ColorValueMarshaler appears to be legacy support for the old expression-based jnimarshalmethod-gen.exe pipeline:
JniValueMarshalerAttribute is only inspected by ReflectionJniValueManager.GetValueMarshalerCore(Type).
ColorValueMarshaler's runtime object-value methods still throw NotImplementedException.
- The only implemented parts are
System.Linq.Expressions-based methods.
- Current marshal-method support has an explicit
MarshalMethodsClassifier special case mapping Android.Graphics.Color to System.Int32 because JNI sees Color as an int.
Potential trimmable typemap gap
The trimmable typemap scanner/generator has special handling for primitives, arrays, enums, some well-known interfaces/collections, and [ExportParameter] stream/XML kinds, but it does not appear to have an equivalent Android.Graphics.Color special case.
This may be a gap for generated direct-dispatch wrappers, for example:
[Export]
public Android.Graphics.Color Foo (Android.Graphics.Color c) => c;
The scanner may synthesize Ljava/lang/Object; for Color instead of I, and the emitter may not generate the needed conversions:
- JNI
int -> new Android.Graphics.Color(int) for parameters/returns into managed code
Android.Graphics.Color -> int (via ToArgb() or implicit conversion) for managed return values going back to JNI
Cleanup opportunity
If ColorValueMarshaler is truly dead for current production paths, consider removing the [JniValueMarshaler] attribute and possibly the ColorValueMarshaler type. This may help reduce trim roots and avoid pulling System.Linq.Expressions into apps unnecessarily.
There are likely other expression-marshaler remnants to audit later, but this issue is specifically about Android.Graphics.Color and the trimmable typemap path.
Suggested work
- Add trimmable typemap scanner/generator tests for
[Export] / direct-dispatch methods with Android.Graphics.Color parameters and return values.
- Decide whether
Android.Graphics.Color should be treated as a JNI I descriptor in ManagedTypeToJniDescriptor / constructor-signature fallback where appropriate.
- Add emitter support for
int <-> Android.Graphics.Color conversions if direct managed dispatch wrappers need it.
- Investigate whether removing
[JniValueMarshaler(typeof(ColorValueMarshaler))] and ColorValueMarshaler is source/binary compatible enough, or whether it needs to remain as obsolete/dead public API.
- Measure whether the cleanup reduces
System.Linq.Expressions retention in trimmed apps.
Context
While removing
GetValueMarshaler*()support from the trimmable typemap value manager, we noticed thatAndroid.Graphics.Colorstill has:ColorValueMarshalerappears to be legacy support for the old expression-basedjnimarshalmethod-gen.exepipeline:JniValueMarshalerAttributeis only inspected byReflectionJniValueManager.GetValueMarshalerCore(Type).ColorValueMarshaler's runtime object-value methods still throwNotImplementedException.System.Linq.Expressions-based methods.MarshalMethodsClassifierspecial case mappingAndroid.Graphics.ColortoSystem.Int32because JNI sees Color as anint.Potential trimmable typemap gap
The trimmable typemap scanner/generator has special handling for primitives, arrays, enums, some well-known interfaces/collections, and
[ExportParameter]stream/XML kinds, but it does not appear to have an equivalentAndroid.Graphics.Colorspecial case.This may be a gap for generated direct-dispatch wrappers, for example:
The scanner may synthesize
Ljava/lang/Object;forColorinstead ofI, and the emitter may not generate the needed conversions:int->new Android.Graphics.Color(int)for parameters/returns into managed codeAndroid.Graphics.Color->int(viaToArgb()or implicit conversion) for managed return values going back to JNICleanup opportunity
If
ColorValueMarshaleris truly dead for current production paths, consider removing the[JniValueMarshaler]attribute and possibly theColorValueMarshalertype. This may help reduce trim roots and avoid pullingSystem.Linq.Expressionsinto apps unnecessarily.There are likely other expression-marshaler remnants to audit later, but this issue is specifically about
Android.Graphics.Colorand the trimmable typemap path.Suggested work
[Export]/ direct-dispatch methods withAndroid.Graphics.Colorparameters and return values.Android.Graphics.Colorshould be treated as a JNIIdescriptor inManagedTypeToJniDescriptor/ constructor-signature fallback where appropriate.int<->Android.Graphics.Colorconversions if direct managed dispatch wrappers need it.[JniValueMarshaler(typeof(ColorValueMarshaler))]andColorValueMarshaleris source/binary compatible enough, or whether it needs to remain as obsolete/dead public API.System.Linq.Expressionsretention in trimmed apps.