Skip to content

Commit 74aee11

Browse files
authored
Clarify requirements for creating a cross-user Channel. (#12181)
The @Systemapi runtime visibility requirement isn't really new. It has always been implicit in the required INTERACT_ACROSS_USERS permission, which (in production) can only be held by system apps. The SDK_INT >= 30 requirement was also always present, via @RequiresApi() on BinderChannelBuilder#bindAsUser. This change just updates its replacement APIs (AndroidComponentAddress and TARGET_ANDROID_USER) to require it too.
1 parent 64322c3 commit 74aee11

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,22 @@ public Builder setBindIntentFromComponent(ComponentName component) {
250250
return this;
251251
}
252252

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

0 commit comments

Comments
 (0)