Skip to content

Commit e5272b3

Browse files
Merge branch 'grpc:master' into Issue_fixed_12142
2 parents 53a4385 + ca99a8c commit e5272b3

File tree

8 files changed

+103
-34
lines changed

8 files changed

+103
-34
lines changed

binder/src/main/java/io/grpc/binder/AndroidComponentAddress.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public final class AndroidComponentAddress extends SocketAddress {
5959
@Nullable
6060
private final UserHandle targetUser; // null means the same user that hosts this process.
6161

62-
protected AndroidComponentAddress(Intent bindIntent, @Nullable UserHandle targetUser) {
62+
private AndroidComponentAddress(Intent bindIntent, @Nullable UserHandle targetUser) {
6363
checkArgument(
6464
bindIntent.getComponent() != null || bindIntent.getPackage() != null,
6565
"'bindIntent' must be explicit. Specify either a package or ComponentName.");
@@ -252,7 +252,22 @@ public Builder setBindIntentFromComponent(ComponentName component) {
252252
return this;
253253
}
254254

255-
/** See {@link AndroidComponentAddress#getTargetUser()}. */
255+
/**
256+
* Specifies the Android user in which the built Address' bind Intent will be evaluated.
257+
*
258+
* <p>Connecting to a server in a different Android user is uncommon and requires the client app
259+
* have runtime visibility of &#064;SystemApi's and hold certain &#064;SystemApi permissions.
260+
* The device must also be running Android SDK version 30 or higher.
261+
*
262+
* <p>See https://developer.android.com/guide/app-compatibility/restrictions-non-sdk-interfaces
263+
* for details on which apps can call the underlying &#064;SystemApi's needed to make this type
264+
* of connection.
265+
*
266+
* <p>One of the "android.permission.INTERACT_ACROSS_XXX" permissions is required. The exact one
267+
* depends on the calling user's relationship to the target user, whether client and server are
268+
* in the same or different apps, and the version of Android in use. See {@link
269+
* Context#bindServiceAsUser}, the essential underlying Android API, for details.
270+
*/
256271
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/10173")
257272
public Builder setTargetUser(@Nullable UserHandle targetUser) {
258273
this.targetUser = targetUser;

binder/src/main/java/io/grpc/binder/ApiConstants.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ private ApiConstants() {}
3535
/**
3636
* Specifies the Android user in which target URIs should be resolved.
3737
*
38-
* <p>{@link UserHandle} can't reasonably be encoded in a target URI string. Instead, all
39-
* {@link io.grpc.NameResolverProvider}s producing {@link AndroidComponentAddress}es should let
40-
* clients address servers in another Android user using this argument.
38+
* <p>{@link UserHandle} can't reasonably be encoded in a target URI string. Instead, all {@link
39+
* io.grpc.NameResolverProvider}s producing {@link AndroidComponentAddress}es should let clients
40+
* address servers in another Android user using this argument.
4141
*
42-
* <p>See also {@link AndroidComponentAddress#getTargetUser()}.
42+
* <p>Connecting to a server in a different Android user is uncommon and can only be done by a
43+
* "system app" client with special permissions. See {@link
44+
* AndroidComponentAddress.Builder#setTargetUser(UserHandle)} for details.
4345
*/
46+
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/10173")
4447
public static final NameResolver.Args.Key<UserHandle> TARGET_ANDROID_USER =
4548
NameResolver.Args.Key.create("target-android-user");
4649
}

binder/src/main/java/io/grpc/binder/BinderChannelBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ public BinderChannelBuilder securityPolicy(SecurityPolicy securityPolicy) {
242242
* specify a {@link UserHandle}. If neither the Channel nor the {@link AndroidComponentAddress}
243243
* specifies a target user, the {@link UserHandle} of the current process will be used.
244244
*
245-
* <p>Targeting a Service in a different Android user is uncommon and requires special permissions
246-
* normally reserved for system apps. See {@link android.content.Context#bindServiceAsUser} for
247-
* details.
245+
* <p>Connecting to a server in a different Android user is uncommon and can only be done by a
246+
* "system app" client with special permissions. See {@link
247+
* AndroidComponentAddress.Builder#setTargetUser(UserHandle)} for details.
248248
*
249249
* @deprecated This method's name is misleading because it implies an impersonated client identity
250250
* when it's actually specifying part of the server's location. It's also no longer necessary

rls/src/main/java/io/grpc/rls/CachingRlsLbClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ void init() {
255255
}
256256
}
257257

258+
Status acceptResolvedAddressFactory(ResolvedAddressFactory childLbResolvedAddressFactory) {
259+
synchronized (lock) {
260+
return refCountedChildPolicyWrapperFactory.acceptResolvedAddressFactory(
261+
childLbResolvedAddressFactory);
262+
}
263+
}
264+
258265
/**
259266
* Convert the status to UNAVAILABLE and enhance the error message.
260267
* @param status status as provided by server

rls/src/main/java/io/grpc/rls/LbPolicyConfiguration.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.grpc.LoadBalancerProvider;
3232
import io.grpc.LoadBalancerRegistry;
3333
import io.grpc.NameResolver.ConfigOrError;
34+
import io.grpc.Status;
3435
import io.grpc.internal.ObjectPool;
3536
import io.grpc.rls.ChildLoadBalancerHelper.ChildLoadBalancerHelperProvider;
3637
import io.grpc.rls.RlsProtoData.RouteLookupConfig;
@@ -211,7 +212,7 @@ static final class RefCountedChildPolicyWrapperFactory {
211212
private final ChildLoadBalancerHelperProvider childLbHelperProvider;
212213
private final ChildLbStatusListener childLbStatusListener;
213214
private final ChildLoadBalancingPolicy childPolicy;
214-
private final ResolvedAddressFactory childLbResolvedAddressFactory;
215+
private ResolvedAddressFactory childLbResolvedAddressFactory;
215216

216217
public RefCountedChildPolicyWrapperFactory(
217218
ChildLoadBalancingPolicy childPolicy,
@@ -229,6 +230,19 @@ void init() {
229230
childLbHelperProvider.init();
230231
}
231232

233+
Status acceptResolvedAddressFactory(ResolvedAddressFactory childLbResolvedAddressFactory) {
234+
this.childLbResolvedAddressFactory = childLbResolvedAddressFactory;
235+
Status status = Status.OK;
236+
for (RefCountedChildPolicyWrapper wrapper : childPolicyMap.values()) {
237+
Status newStatus =
238+
wrapper.childPolicyWrapper.acceptResolvedAddressFactory(childLbResolvedAddressFactory);
239+
if (!newStatus.isOk()) {
240+
status = newStatus;
241+
}
242+
}
243+
return status;
244+
}
245+
232246
ChildPolicyWrapper createOrGet(String target) {
233247
// TODO(creamsoup) check if the target is valid or not
234248
RefCountedChildPolicyWrapper pooledChildPolicyWrapper = childPolicyMap.get(target);
@@ -277,6 +291,7 @@ static final class ChildPolicyWrapper {
277291
private final String target;
278292
private final ChildPolicyReportingHelper helper;
279293
private final LoadBalancer lb;
294+
private final Object childLbConfig;
280295
private volatile SubchannelPicker picker;
281296
private ConnectivityState state;
282297

@@ -295,21 +310,26 @@ public ChildPolicyWrapper(
295310
.parseLoadBalancingPolicyConfig(
296311
childPolicy.getEffectiveChildPolicy(target));
297312
this.lb = lbProvider.newLoadBalancer(helper);
313+
this.childLbConfig = lbConfig.getConfig();
298314
helper.getChannelLogger().log(
299-
ChannelLogLevel.DEBUG, "RLS child lb created. config: {0}", lbConfig.getConfig());
315+
ChannelLogLevel.DEBUG, "RLS child lb created. config: {0}", childLbConfig);
300316
helper.getSynchronizationContext().execute(
301317
new Runnable() {
302318
@Override
303319
public void run() {
304-
if (!lb.acceptResolvedAddresses(
305-
childLbResolvedAddressFactory.create(lbConfig.getConfig())).isOk()) {
320+
if (!acceptResolvedAddressFactory(childLbResolvedAddressFactory).isOk()) {
306321
helper.refreshNameResolution();
307322
}
308323
lb.requestConnection();
309324
}
310325
});
311326
}
312327

328+
Status acceptResolvedAddressFactory(ResolvedAddressFactory childLbResolvedAddressFactory) {
329+
helper.getSynchronizationContext().throwIfNotInThisSynchronizationContext();
330+
return lb.acceptResolvedAddresses(childLbResolvedAddressFactory.create(childLbConfig));
331+
}
332+
313333
String getTarget() {
314334
return target;
315335
}

rls/src/main/java/io/grpc/rls/RlsLoadBalancer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
7979
// not required.
8080
this.lbPolicyConfiguration = lbPolicyConfiguration;
8181
}
82-
return Status.OK;
82+
return routeLookupClient.acceptResolvedAddressFactory(
83+
new ChildLbResolvedAddressFactory(
84+
resolvedAddresses.getAddresses(), resolvedAddresses.getAttributes()));
8385
}
8486

8587
@Override

xds/src/main/java/io/grpc/xds/XdsNameResolver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,9 @@ private void updateRoutes(
823823
if (shouldUpdateResult && routingConfig != null) {
824824
updateResolutionResult(xdsConfig);
825825
shouldUpdateResult = false;
826+
} else {
827+
// Need to update at least once
828+
shouldUpdateResult = true;
826829
}
827830
// Make newly added clusters selectable by config selector and deleted clusters no longer
828831
// selectable.
@@ -993,7 +996,8 @@ private ClusterRefState(
993996
.put("routeLookupConfig", rlsPluginConfig.config())
994997
.put(
995998
"childPolicy",
996-
ImmutableList.of(ImmutableMap.of(XdsLbPolicies.CDS_POLICY_NAME, ImmutableMap.of())))
999+
ImmutableList.of(ImmutableMap.of(XdsLbPolicies.CDS_POLICY_NAME, ImmutableMap.of(
1000+
"is_dynamic", true))))
9971001
.put("childPolicyConfigTargetFieldName", "cluster")
9981002
.buildOrThrow();
9991003
return ImmutableMap.of("rls_experimental", rlsConfig);

0 commit comments

Comments
 (0)