Skip to content

Commit

Permalink
binder: Beef up hasPermissions security policy Javadoc (#10650)
Browse files Browse the repository at this point in the history
Try to manage the fact that runtime permissions could be granted externally by the user after a hasPermissions() SecurityPolicy check has already been made on a transport.
  • Loading branch information
jdcormie authored Nov 15, 2023
1 parent 32d85d8 commit bdb0c72
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions binder/src/main/java/io/grpc/binder/SecurityPolicies.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,25 @@ public Status checkAuthorization(int uid) {
/**
* Creates a {@link SecurityPolicy} which checks if the caller has all of the given permissions
* from {@code permissions}.
*
* <p>The gRPC framework assumes that a {@link SecurityPolicy}'s verdict for a given peer UID will
* not change over the lifetime of any process with that UID. But Android runtime permissions can
* be granted or revoked by the user at any time and so using the {@link #hasPermissions}
* {@link SecurityPolicy} comes with certain special responsibilities.
*
* <p>In particular, callers must ensure that the *subjects* of the returned
* {@link SecurityPolicy} hold all required {@code permissions} *before* making use of it. Android
* kills an app's processes when it loses any permission but the same isn't true when a permission
* is granted. And so without special care, a {@link #hasPermissions} denial could incorrectly
* persist even if the subject is later granted all required {@code permissions}.
*
* <p>A server using {@link #hasPermissions} must, as part of its RPC API contract, require
* clients to request and receive all {@code permissions} before making a call. This is in line
* with official Android guidance to request and confirm receipt of runtime permissions before
* using them.
*
* <p>A client, on the other hand, should only use {@link #hasPermissions} policies that require
* install-time permissions which cannot change.
*
* @param permissions all permissions that the calling package needs to have
* @throws NullPointerException if any of the inputs are {@code null}
Expand Down

0 comments on commit bdb0c72

Please sign in to comment.