0

Use proxy object implments AIDL interface

    Class studyManager = Class.forName("StudyManager");
    Class iStudyCallbackClient = Class.forName("IStudyCallbackClient");
    Method setTouchCallback = studyManager.getDeclaredMethod("setTouchCallback", iStudyCallbackClient);
    Proxy proxy = (Proxy) Proxy.newProxyInstance(iStudyCallbackClient.getClassLoader(),
        new Class[] { iStudyCallbackClient }, new IStudyCallbackClientImpl());
    setTouchCallback.invoke(studyManager.newInstance(), proxy);

class IStudyCallbackClientImpl implements InvocationHandler {
    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        Log.d(TAG, method.getName());//why here is asBinde() not sendPoint()? 
        return null;
    }

AIDL

interface IStudyCallbackClient {
    void sendPoint(int x,int y);
}

Problems:

Code runing is OK.
when invoke the callback function (IStudyCallbackClient.sendPoint(int x,int y)), why method.getName() is asBinder?,not sendPoint()?

the AIDL interface auto generated code is here.

https://pastebin.com/CNFxGGu7

kaiattrib
  • 101
  • 6

1 Answers1

0

The error was JDK's proxy depends interface. The ture args was abstract class that implements the interface ,not just the interface.

I first thought the interface args like this:

public void setTouchCallback(ICallback mICallback)

but the true args was like this

public static abstract class Stub extends android.os.Binder implements ICallback
kaiattrib
  • 101
  • 6