Skip to content

Commit f2d44c3

Browse files
committed
binder: Give tests the ability to decorate a server's client binder
1 parent e81dff5 commit f2d44c3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

binder/src/main/java/io/grpc/binder/internal/BinderServer.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public final class BinderServer implements InternalServer, LeakSafeOneWayBinder.
7070
private final LeakSafeOneWayBinder hostServiceBinder;
7171
private final BinderTransportSecurity.ServerPolicyChecker serverPolicyChecker;
7272
private final InboundParcelablePolicy inboundParcelablePolicy;
73+
private final OneWayBinderProxy.Decorator clientBinderDecorator;
7374

7475
@GuardedBy("this")
7576
private ServerListener listener;
@@ -92,6 +93,7 @@ private BinderServer(Builder builder) {
9293
ImmutableList.copyOf(checkNotNull(builder.streamTracerFactories, "streamTracerFactories"));
9394
this.serverPolicyChecker = BinderInternal.createPolicyChecker(builder.serverSecurityPolicy);
9495
this.inboundParcelablePolicy = builder.inboundParcelablePolicy;
96+
this.clientBinderDecorator = builder.clientBinderDecorator;
9597
hostServiceBinder = new LeakSafeOneWayBinder(this);
9698
}
9799

@@ -183,7 +185,7 @@ public synchronized boolean handleTransaction(int code, Parcel parcel) {
183185
executorServicePool,
184186
attrsBuilder.build(),
185187
streamTracerFactories,
186-
OneWayBinderProxy.IDENTITY_DECORATOR,
188+
clientBinderDecorator,
187189
callbackBinder);
188190
transport.start(listener.transportCreated(transport));
189191
return true;
@@ -225,6 +227,7 @@ public static class Builder {
225227
SharedResourcePool.forResource(GrpcUtil.TIMER_SERVICE);
226228
ServerSecurityPolicy serverSecurityPolicy = SecurityPolicies.serverInternalOnly();
227229
InboundParcelablePolicy inboundParcelablePolicy = InboundParcelablePolicy.DEFAULT;
230+
OneWayBinderProxy.Decorator clientBinderDecorator = OneWayBinderProxy.IDENTITY_DECORATOR;
228231

229232
public BinderServer build() {
230233
return new BinderServer(this);
@@ -295,5 +298,19 @@ public Builder setInboundParcelablePolicy(InboundParcelablePolicy inboundParcela
295298
checkNotNull(inboundParcelablePolicy, "inboundParcelablePolicy");
296299
return this;
297300
}
301+
302+
/**
303+
* Sets the {@link OneWayBinderProxy.Decorator} to be applied to this server's "client Binders".
304+
*
305+
* <p>Tests can use this to capture post-setup transactions from server to client. The specified
306+
* decorator will be applied every time a client connects. The decorated result will be used for
307+
* all subsequent transactions to this client from the new ServerTransport.
308+
*
309+
* <p>Optional, {@link OneWayBinderProxy#IDENTITY_DECORATOR} is the default.
310+
*/
311+
public Builder setClientBinderDecorator(OneWayBinderProxy.Decorator clientBinderDecorator) {
312+
this.clientBinderDecorator = checkNotNull(clientBinderDecorator);
313+
return this;
314+
}
298315
}
299316
}

0 commit comments

Comments
 (0)