@@ -74,7 +74,8 @@ public static BinderChannelBuilder forAddress(
74
74
return new BinderChannelBuilder (
75
75
checkNotNull (directAddress , "directAddress" ),
76
76
null ,
77
- BinderChannelCredentials .forDefault (sourceContext ));
77
+ sourceContext ,
78
+ BinderChannelCredentials .forDefault ());
78
79
}
79
80
80
81
/**
@@ -90,16 +91,17 @@ public static BinderChannelBuilder forAddress(
90
91
* resulting builder. They will not be shut down automatically.
91
92
*
92
93
* @param directAddress the {@link AndroidComponentAddress} referencing the service to bind to.
94
+ * @param sourceContext the context to bind from (e.g. The current Activity or Application).
93
95
* @param channelCredentials the arbitrary binder specific channel credentials to be used to
94
- * establish a binder connection including the context to bind from (e.g. The current
95
- * Activity or Application).
96
+ * establish a binder connection.
96
97
* @return a new builder
97
98
*/
98
99
public static BinderChannelBuilder forAddress (
99
100
AndroidComponentAddress directAddress ,
101
+ Context sourceContext ,
100
102
BinderChannelCredentials channelCredentials ) {
101
103
return new BinderChannelBuilder (
102
- checkNotNull (directAddress , "directAddress" ), null , channelCredentials );
104
+ checkNotNull (directAddress , "directAddress" ), null , sourceContext , channelCredentials );
103
105
}
104
106
105
107
/**
@@ -123,7 +125,8 @@ public static BinderChannelBuilder forTarget(String target, Context sourceContex
123
125
return new BinderChannelBuilder (
124
126
null ,
125
127
checkNotNull (target , "target" ),
126
- BinderChannelCredentials .forDefault (sourceContext ));
128
+ sourceContext ,
129
+ BinderChannelCredentials .forDefault ());
127
130
}
128
131
129
132
/**
@@ -140,15 +143,15 @@ public static BinderChannelBuilder forTarget(String target, Context sourceContex
140
143
*
141
144
* @param target A target uri which should resolve into an {@link AndroidComponentAddress}
142
145
* referencing the service to bind to.
146
+ * @param sourceContext the context to bind from (e.g. The current Activity or Application).
143
147
* @param channelCredentials the arbitrary binder specific channel credentials to be used to
144
- * establish a binder connection including the context to bind from (e.g. The current
145
- * Activity or Application).
148
+ * establish a binder connection.
146
149
* @return a new builder
147
150
*/
148
151
public static BinderChannelBuilder forTarget (
149
- String target , BinderChannelCredentials channelCredentials ) {
152
+ String target , Context sourceContext , BinderChannelCredentials channelCredentials ) {
150
153
return new BinderChannelBuilder (
151
- null , checkNotNull (target , "target" ), channelCredentials );
154
+ null , checkNotNull (target , "target" ), sourceContext , channelCredentials );
152
155
}
153
156
154
157
/**
@@ -183,10 +186,10 @@ public static BinderChannelBuilder forTarget(String target) {
183
186
private BinderChannelBuilder (
184
187
@ Nullable AndroidComponentAddress directAddress ,
185
188
@ Nullable String target ,
189
+ Context sourceContext ,
186
190
BinderChannelCredentials channelCredentials ) {
187
191
mainThreadExecutor =
188
- ContextCompat .getMainExecutor (
189
- checkNotNull (channelCredentials .getSourceContext (), "sourceContext" ));
192
+ ContextCompat .getMainExecutor (checkNotNull (sourceContext , "sourceContext" ));
190
193
securityPolicy = SecurityPolicies .internalOnly ();
191
194
inboundParcelablePolicy = InboundParcelablePolicy .DEFAULT ;
192
195
bindServiceFlags = BindServiceFlags .DEFAULTS ;
@@ -196,13 +199,14 @@ final class BinderChannelTransportFactoryBuilder
196
199
@ Override
197
200
public ClientTransportFactory buildClientTransportFactory () {
198
201
return new TransportFactory (
199
- channelCredentials ,
202
+ sourceContext ,
200
203
mainThreadExecutor ,
201
204
schedulerPool ,
202
205
managedChannelImplBuilder .getOffloadExecutorPool (),
203
206
securityPolicy ,
204
207
bindServiceFlags ,
205
208
inboundParcelablePolicy ,
209
+ channelCredentials ,
206
210
targetUserHandle );
207
211
}
208
212
}
@@ -319,35 +323,38 @@ public BinderChannelBuilder idleTimeout(long value, TimeUnit unit) {
319
323
320
324
/** Creates new binder transports. */
321
325
private static final class TransportFactory implements ClientTransportFactory {
322
- private final BinderChannelCredentials channelCredentials ;
326
+ private final Context sourceContext ;
323
327
private final Executor mainThreadExecutor ;
324
328
private final ObjectPool <ScheduledExecutorService > scheduledExecutorPool ;
325
329
private final ObjectPool <? extends Executor > offloadExecutorPool ;
326
330
private final SecurityPolicy securityPolicy ;
327
331
private final InboundParcelablePolicy inboundParcelablePolicy ;
328
332
private final BindServiceFlags bindServiceFlags ;
333
+ private final BinderChannelCredentials channelCredentials ;
329
334
@ Nullable private final UserHandle targetUserHandle ;
330
335
331
336
private ScheduledExecutorService executorService ;
332
337
private Executor offloadExecutor ;
333
338
private boolean closed ;
334
339
335
340
TransportFactory (
336
- BinderChannelCredentials channelCredentials ,
341
+ Context sourceContext ,
337
342
Executor mainThreadExecutor ,
338
343
ObjectPool <ScheduledExecutorService > scheduledExecutorPool ,
339
344
ObjectPool <? extends Executor > offloadExecutorPool ,
340
345
SecurityPolicy securityPolicy ,
341
346
BindServiceFlags bindServiceFlags ,
342
347
InboundParcelablePolicy inboundParcelablePolicy ,
348
+ BinderChannelCredentials channelCredentials ,
343
349
@ Nullable UserHandle targetUserHandle ) {
344
- this .channelCredentials = channelCredentials ;
350
+ this .sourceContext = sourceContext ;
345
351
this .mainThreadExecutor = mainThreadExecutor ;
346
352
this .scheduledExecutorPool = scheduledExecutorPool ;
347
353
this .offloadExecutorPool = offloadExecutorPool ;
348
354
this .securityPolicy = securityPolicy ;
349
355
this .bindServiceFlags = bindServiceFlags ;
350
356
this .inboundParcelablePolicy = inboundParcelablePolicy ;
357
+ this .channelCredentials = channelCredentials ;
351
358
this .targetUserHandle = targetUserHandle ;
352
359
353
360
executorService = scheduledExecutorPool .getObject ();
@@ -361,9 +368,10 @@ public ConnectionClientTransport newClientTransport(
361
368
throw new IllegalStateException ("The transport factory is closed." );
362
369
}
363
370
return new BinderTransport .BinderClientTransport (
364
- channelCredentials ,
371
+ sourceContext ,
365
372
(AndroidComponentAddress ) addr ,
366
373
bindServiceFlags ,
374
+ channelCredentials ,
367
375
targetUserHandle ,
368
376
mainThreadExecutor ,
369
377
scheduledExecutorPool ,
0 commit comments