1

I am trying to modify AOSP by adding a new system service.

I have the aidl for the service as follows :

package android.app;

import java.util.ArrayList;

import android.app.TypeA;
import android.app.TypeB;

interface myService { 

     ArrayList<TypeA> getA();
     ArrayList<TypeB> getB();

}

TypeA and TypeB are implementing Parcelable interface, still when I try to build Android, it fails to import these 3:

couldn't find import for class java.util.ArrayList
couldn't find import for class android.app.TypeA
couldn't find import for class android.app.TypeB

I have looked at other related questions on SO and so far have not found an answer that works for me.

Does anyone know how to resolve this ?

Jake
  • 16,329
  • 50
  • 126
  • 202

1 Answers1

3

I can see one problem and I'll guess at a second:

  • ArrayList, TypeA and TypeB are not Parcelable. All of the objects you pass around, via Binder, must implement the Parcelable interface.
  • In order for AIDL to work, you must declare every object used in an AIDL definition, in an AIDL file. If, for instance, TypeA did implement Parcelable, you still need an AIDL file for it

Like this:

package my.app;

parcelable TypeA;
G. Blake Meike
  • 6,615
  • 3
  • 24
  • 40
  • 1
    Ok .. so I have TypeA.java (in which TypeA implements Parcelable) .. you suggest I add another file .. TypeA.aidl containing `parcelable TypeA` .. any other imports in the aidl (I mean how will the aidl know what is typeA is ?) – Jake Jul 20 '14 at 22:38
  • 1
    That's all. Just add the AIDL file that declares TypeA 'parcelable'. AIDL doesn't know or care much about Java definitions. You must declare all AIDL objects to the AIDL complier. Declaring an object as parcelable' is good enough... so long Java agrees ;-) – G. Blake Meike Jul 20 '14 at 22:46
  • What can I do about ArrayList ? I need a type that can return as a list of items .. Do you know any type that implements Parcelable ? I don't want to spend time creating a new List type if one already exists, Thanks ! – Jake Jul 20 '14 at 22:48
  • 1
    Check out Bundle.putParcelableArrayList – G. Blake Meike Jul 20 '14 at 22:52