Skip to content

Commit 907220e

Browse files
devinmoore-googGerrit Code Review
authored andcommitted
Merge "Fixes for NDK API Review feedback" into main
2 parents ad4b07e + db85295 commit 907220e

2 files changed

Lines changed: 57 additions & 24 deletions

File tree

libs/binder/ndk/binder_rpc.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct OnDeleteProviderHolder {
9494
}
9595
void* mData;
9696
ABinderRpc_AccessorProviderUserData_deleteCallback mOnDelete;
97-
// needs to be copyable for std::function, but we will never copy it
97+
// needs to be copy-able for std::function, but we will never copy it
9898
OnDeleteProviderHolder(const OnDeleteProviderHolder&) {
9999
LOG_ALWAYS_FATAL("This object can't be copied!");
100100
}
@@ -113,7 +113,7 @@ ABinderRpc_AccessorProvider* ABinderRpc_registerAccessorProvider(
113113
}
114114
if (data && onDelete == nullptr) {
115115
ALOGE("If a non-null data ptr is passed to ABinderRpc_registerAccessorProvider, then a "
116-
"ABinderRpc_AccessorProviderUserData_deleteCallback must alse be passed to delete "
116+
"ABinderRpc_AccessorProviderUserData_deleteCallback must also be passed to delete "
117117
"the data object once the ABinderRpc_AccessorProvider is removed.");
118118
return nullptr;
119119
}
@@ -179,7 +179,7 @@ struct OnDeleteConnectionInfoHolder {
179179
}
180180
void* mData;
181181
ABinderRpc_ConnectionInfoProviderUserData_delete mOnDelete;
182-
// needs to be copyable for std::function, but we will never copy it
182+
// needs to be copy-able for std::function, but we will never copy it
183183
OnDeleteConnectionInfoHolder(const OnDeleteConnectionInfoHolder&) {
184184
LOG_ALWAYS_FATAL("This object can't be copied!");
185185
}
@@ -197,7 +197,7 @@ ABinderRpc_Accessor* ABinderRpc_Accessor_new(
197197
}
198198
if (data && onDelete == nullptr) {
199199
ALOGE("If a non-null data ptr is passed to ABinderRpc_Accessor_new, then a "
200-
"ABinderRpc_ConnectionInfoProviderUserData_delete callback must alse be passed to "
200+
"ABinderRpc_ConnectionInfoProviderUserData_delete callback must also be passed to "
201201
"delete "
202202
"the data object once the ABinderRpc_Accessor is deleted.");
203203
return nullptr;
@@ -304,7 +304,7 @@ ABinderRpc_Accessor* ABinderRpc_Accessor_fromBinder(const char* instance, AIBind
304304

305305
ABinderRpc_ConnectionInfo* ABinderRpc_ConnectionInfo_new(const sockaddr* addr, socklen_t len) {
306306
if (addr == nullptr || len < 0 || static_cast<size_t>(len) < sizeof(sa_family_t)) {
307-
ALOGE("Invalid arguments in Arpc_Connection_new");
307+
ALOGE("Invalid arguments in ABinderRpc_Connection_new");
308308
return nullptr;
309309
}
310310
// socklen_t was int32_t on 32-bit and uint32_t on 64 bit.
@@ -317,8 +317,9 @@ ABinderRpc_ConnectionInfo* ABinderRpc_ConnectionInfo_new(const sockaddr* addr, s
317317
return nullptr;
318318
}
319319
sockaddr_vm vm = *reinterpret_cast<const sockaddr_vm*>(addr);
320-
LOG_ACCESSOR_DEBUG("Arpc_ConnectionInfo_new found AF_VSOCK. family %d, port %d, cid %d",
321-
vm.svm_family, vm.svm_port, vm.svm_cid);
320+
LOG_ACCESSOR_DEBUG(
321+
"ABinderRpc_ConnectionInfo_new found AF_VSOCK. family %d, port %d, cid %d",
322+
vm.svm_family, vm.svm_port, vm.svm_cid);
322323
return new ABinderRpc_ConnectionInfo(vm);
323324
} else if (addr->sa_family == AF_UNIX) {
324325
if (len != sizeof(sockaddr_un)) {
@@ -327,7 +328,7 @@ ABinderRpc_ConnectionInfo* ABinderRpc_ConnectionInfo_new(const sockaddr* addr, s
327328
return nullptr;
328329
}
329330
sockaddr_un un = *reinterpret_cast<const sockaddr_un*>(addr);
330-
LOG_ACCESSOR_DEBUG("Arpc_ConnectionInfo_new found AF_UNIX. family %d, path %s",
331+
LOG_ACCESSOR_DEBUG("ABinderRpc_ConnectionInfo_new found AF_UNIX. family %d, path %s",
331332
un.sun_family, un.sun_path);
332333
return new ABinderRpc_ConnectionInfo(un);
333334
} else if (addr->sa_family == AF_INET) {
@@ -337,12 +338,14 @@ ABinderRpc_ConnectionInfo* ABinderRpc_ConnectionInfo_new(const sockaddr* addr, s
337338
return nullptr;
338339
}
339340
sockaddr_in in = *reinterpret_cast<const sockaddr_in*>(addr);
340-
LOG_ACCESSOR_DEBUG("Arpc_ConnectionInfo_new found AF_INET. family %d, address %s, port %d",
341-
in.sin_family, inet_ntoa(in.sin_addr), ntohs(in.sin_port));
341+
LOG_ACCESSOR_DEBUG(
342+
"ABinderRpc_ConnectionInfo_new found AF_INET. family %d, address %s, port %d",
343+
in.sin_family, inet_ntoa(in.sin_addr), ntohs(in.sin_port));
342344
return new ABinderRpc_ConnectionInfo(in);
343345
}
344346

345-
ALOGE("ARpc APIs only support AF_VSOCK right now but the supplied sockadder::sa_family is: %hu",
347+
ALOGE("ABinderRpc APIs only support AF_VSOCK right now but the supplied sockaddr::sa_family "
348+
"is: %hu",
346349
addr->sa_family);
347350
return nullptr;
348351
}

libs/binder/ndk/include_platform/android/binder_rpc.h

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121

2222
__BEGIN_DECLS
2323

24+
/**
25+
* @defgroup ABinderRpc Binder RPC
26+
*
27+
* This set of APIs makes it possible for a process to use the AServiceManager
28+
* APIs to get binder objects for services that are available over sockets
29+
* instead of the traditional kernel binder with the extra ServiceManager
30+
* process.
31+
*
32+
* These APIs are used to supply libbinder with enough information to create
33+
* and manage the socket connections underneath the ServiceManager APIs so the
34+
* clients do not need to know the service implementation details or what
35+
* transport they use for communication.
36+
*
37+
* @{
38+
*/
39+
2440
/**
2541
* This represents an IAccessor implementation from libbinder that is
2642
* responsible for providing a pre-connected socket file descriptor for a
@@ -66,7 +82,8 @@ typedef struct ABinderRpc_ConnectionInfo ABinderRpc_ConnectionInfo;
6682
* libbinder.
6783
*
6884
* \param instance name of the service like
69-
* `android.hardware.vibrator.IVibrator/default`
85+
* `android.hardware.vibrator.IVibrator/default`. This string must remain
86+
* valid and unchanged for the duration of this function call.
7087
* \param data the data that was associated with this instance when the callback
7188
* was registered.
7289
* \return The ABinderRpc_Accessor associated with the service `instance`. This
@@ -103,13 +120,15 @@ typedef void (*ABinderRpc_AccessorProviderUserData_deleteCallback)(void* _Nullab
103120
* instance is being registered that was previously registered, this call
104121
* will fail and the ABinderRpc_AccessorProviderUserData_deleteCallback
105122
* will be called to clean up the data.
123+
* This array of strings must remain valid and unchanged for the duration
124+
* of this function call.
106125
* \param number of instances in the instances array.
107126
* \param data pointer that is passed to the ABinderRpc_AccessorProvider callback.
108127
* IMPORTANT: The ABinderRpc_AccessorProvider now OWNS that object that data
109128
* points to. It can be used as necessary in the callback. The data MUST
110129
* remain valid for the lifetime of the provider callback.
111130
* Do not attempt to give ownership of the same object to different
112-
* providers throguh multiple calls to this function because the first
131+
* providers through multiple calls to this function because the first
113132
* one to be deleted will call the onDelete callback.
114133
* \param onDelete callback used to delete the objects that `data` points to.
115134
* This is called after ABinderRpc_AccessorProvider is guaranteed to never be
@@ -151,8 +170,9 @@ void ABinderRpc_unregisterAccessorProvider(ABinderRpc_AccessorProvider* _Nonnull
151170
* connect to a socket that a given service is listening on. This is needed to
152171
* create an ABinderRpc_Accessor so it can connect to these services.
153172
*
154-
* \param instance name of the service to connect to
155-
* \param data userdata for this callback. The pointer is provided in
173+
* \param instance name of the service to connect to. This string must remain
174+
* valid and unchanged for the duration of this function call.
175+
* \param data user data for this callback. The pointer is provided in
156176
* ABinderRpc_Accessor_new.
157177
* \return ABinderRpc_ConnectionInfo with socket connection information for `instance`
158178
*/
@@ -177,7 +197,9 @@ typedef void (*ABinderRpc_ConnectionInfoProviderUserData_delete)(void* _Nullable
177197
* that can use the info from the ABinderRpc_ConnectionInfoProvider to connect to a
178198
* socket that the service with `instance` name is listening to.
179199
*
180-
* \param instance name of the service that is listening on the socket
200+
* \param instance name of the service that is listening on the socket. This
201+
* string must remain valid and unchanged for the duration of this
202+
* function call.
181203
* \param provider callback that can get the socket connection information for the
182204
* instance. This connection information may be dynamic, so the
183205
* provider will be called any time a new connection is required.
@@ -219,18 +241,24 @@ AIBinder* _Nullable ABinderRpc_Accessor_asBinder(ABinderRpc_Accessor* _Nonnull a
219241

220242
/**
221243
* Return the ABinderRpc_Accessor associated with an AIBinder. The instance must match
222-
* the ABinderRpc_Accessor implementation, and the AIBinder must a proxy binder for a
223-
* remote service (ABpBinder).
224-
* This can be used when receivng an AIBinder from another process that the
244+
* the ABinderRpc_Accessor implementation.
245+
* This can be used when receiving an AIBinder from another process that the
225246
* other process obtained from ABinderRpc_Accessor_asBinder.
226247
*
227248
* \param instance name of the service that the Accessor is responsible for.
228-
* \param accessorBinder proxy binder from another processes ABinderRpc_Accessor.
249+
* This string must remain valid and unchanged for the duration of this
250+
* function call.
251+
* \param accessorBinder proxy binder from another process's ABinderRpc_Accessor.
252+
* This function preserves the refcount of this binder object and the
253+
* caller still owns it.
229254
* \return ABinderRpc_Accessor representing the other processes ABinderRpc_Accessor
230-
* implementation. This function does not take ownership of the
231-
* ABinderRpc_Accessor (so the caller needs to delete with
232-
* ABinderRpc_Accessor_delete), and it preserves the recount of the bidner
233-
* object.
255+
* implementation. The caller owns this ABinderRpc_Accessor instance and
256+
* is responsible for deleting it with ABinderRpc_Accessor_delete or
257+
* passing ownership of it elsewhere, like returning it through
258+
* ABinderRpc_AccessorProvider_getAccessorCallback.
259+
* nullptr on error when the accessorBinder is not a valid binder from
260+
* an IAccessor implementation or the IAccessor implementation is not
261+
* associated with the provided instance.
234262
*/
235263
ABinderRpc_Accessor* _Nullable ABinderRpc_Accessor_fromBinder(const char* _Nonnull instance,
236264
AIBinder* _Nonnull accessorBinder)
@@ -258,4 +286,6 @@ ABinderRpc_ConnectionInfo* _Nullable ABinderRpc_ConnectionInfo_new(const sockadd
258286
*/
259287
void ABinderRpc_ConnectionInfo_delete(ABinderRpc_ConnectionInfo* _Nonnull info) __INTRODUCED_IN(36);
260288

289+
/** @} */
290+
261291
__END_DECLS

0 commit comments

Comments
 (0)