2

I am writing a test code to study binder APIs, referring to (the reference sample also has similar problem) https://github.com/qianjigui/android_system_service_example

I wrote a Java service and a native client. It seems everything is fine except for that I cannot get the full content of returned String.

The server side method getName:

@Override
public String getName() throws RemoteException {
    Log.i("------>", "Calling method getName()");
    return "123456";
}

The client side proxy method:

String16 BpTestServiceAPI::getName()
{
    Parcel data, reply;
    data.writeInterfaceToken(IRemoteControlServiceAPI::getInterfaceDescriptor());
    //By operation code to transact
    remote()->transact(GET_NAME, data, &reply);
    //Exception Code. In Java Level, aidl auto generate codes will process exceptioncode.
    reply.readExceptionCode();
    return reply.readString16();
}

The problem is that when I tried to print the string content of getName(), only the first byte can be print. E.g. I returned "123456" from server but

ALOGE("Service Name=%s", bts->getName().string());

only gave me

E/ ( 5344): Service Name=1

I also tried to print out the length of the String8 instance, it is 6 in this case. I tried to use getCString and directly use it as (char *), I got empty result.

So, does anyone know what is going wrong here?

Onik
  • 19,396
  • 14
  • 68
  • 91
Robin
  • 10,052
  • 6
  • 31
  • 52

0 Answers0