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