libbinder: fix ToString() for smart pointers

android::internal::ToString() is a helper to provide implementation of
AIDL-generated type's toString/gen_log features.

For now, AIDL IBinder type is mapped to sp<IBinder> in the C++ backend,
and ToString() handles it as a pointer-like type. But when there's a
HIDL-generated toString(sp<IFoo>) function in the same scope, ToString()
tries to use it for sp<IBinder> because sp<T> can is constuctible from
sp<U>.

To avoid such ambiguities,
- IsPointerLike is checked before HasToStringFunction, so that
sp<IBinder> is treated as a pointer even when there's an overloaded
toString(sp<T>) function.
- IsPointerLike now explicitly checks if the target type is an
instatiation of of one of android::sp/std::optional/std::shared_ptr.

Bug: 179885793
Test: m
Change-Id: I884d8be92ed744237d7bf44d381437426f37045a
1 file changed