Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] When using out array parameter in AIDL, the code generator is not working properly #4717

Closed
MrAlbin opened this issue May 23, 2020 · 1 comment
Assignees
Labels
Area: Bindings Issues in Java Library Binding projects. bug Component does not function as intended.

Comments

@MrAlbin
Copy link

MrAlbin commented May 23, 2020

I*m using Android Studio to buld an Android service and VisualStudio 2019 to build an App that uses this Service (have to do it this way).
There seems to be an issue when using out arrays like int[] or byte[].

Steps to Reproduce

  1. AIDL file with a function like
    int GetByte(out byte[] myByte);
  2. Implement a Java-Service using Android-Studio that implements AIDL interface and write 1 byte to the out parameter myByte
  3. Implement a Xamarin App that uses the Service and call GetByte.

Expected Behavior

The App shoud receive the byte correctly.

Actual Behavior

It always results in an Exception:

java.lang.RuntimeException: bad array lengths
at android.os.Parcel.readByteArray(Parcel.java:2233)

To me it looks like the code generator has a bug. I compared the generated Java code (Android Studio) and the corresponding C# code (Visual Studio):

Java:

@Override public int GetByte(byte[] myByte) throws android.os.RemoteException
{
	android.os.Parcel _data = android.os.Parcel.obtain();
	android.os.Parcel _reply = android.os.Parcel.obtain();
	int _result;
	try {
		_data.writeInterfaceToken(DESCRIPTOR);
		if ((count==null)) {
			_data.writeInt(-1);
		}
		else {
			_data.writeInt(count.length);
		}
		boolean _status = mRemote.transact(Stub.TRANSACTION_GetByte, _data, _reply, 0);
		if (!_status && getDefaultImpl() != null) {
			return getDefaultImpl().GetByte(count);
		}
		_reply.readException();
		_result = _reply.readInt();
		_reply.readByteArray(count);
	}
  	finally {
  	        _reply.recycle();
 	         _data.recycle();
 	}
	return _result;
}

C#

public int SIS_GetByte (byte [] myByte)
{
	global::Android.OS.Parcel __data = global::Android.OS.Parcel.Obtain ();

	global::Android.OS.Parcel __reply = global::Android.OS.Parcel.Obtain ();
	int __result = default (int);

	try {
		__data.WriteInterfaceToken (descriptor);
		remote.Transact (IScaleInterfaceServiceStub.TransactionSIS_GetByte, __data, __reply, 0);
		__reply.ReadException ();
		__result = __reply.ReadInt ();
		__reply.ReadByteArray (count);

	} finally {
		__reply.Recycle ();
		__data.Recycle ();
	}
	return __result;
}

The corresponding _data.writeInt before remote.Transact seems to be missing for the C# code. Thus the error java.lang.RuntimeException: bad array lengths makes sense to me.

Version Information

Xamarin 16.5.000.533 (d16-5@9152e1b)
Visual Studio-Erweiterung, um Entwicklung für Xamarin.iOS und Xamarin.Android zu ermöglichen.

Xamarin.Android SDK 10.2.0.100 (d16-5/988c811)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: c0c5c78
Java.Interop: xamarin/java.interop/d16-5@fc18c54
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-5@9f4ed4b

Log File

java.lang.ArrayIndexOutOfBoundsException: byte[] offset=0 length=1 dst.length=0

@MrAlbin
Copy link
Author

MrAlbin commented May 23, 2020

manually adding _data.writeInt makes it working

@MrAlbin MrAlbin changed the title using out or inout array parameter in AIDL not working [Bug] When using out array parameter in AIDL, the code generator is not working properly May 27, 2020
@grendello grendello added the Area: Bindings Issues in Java Library Binding projects. label May 28, 2020
@grendello grendello added this to the Under Consideration milestone May 28, 2020
@jonpryor jonpryor added the bug Component does not function as intended. label Apr 13, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: Bindings Issues in Java Library Binding projects. bug Component does not function as intended.
Projects
None yet
Development

No branches or pull requests

4 participants