Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binder: Promote out of experimental status #9669

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import io.grpc.ExperimentalApi;
import java.net.SocketAddress;

/**
Expand All @@ -41,8 +40,7 @@
* fields, namely, an action of {@link ApiConstants#ACTION_BIND}, an empty category set and null
* type and data URI.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public class AndroidComponentAddress extends SocketAddress { // NOTE: Only temporarily non-final.
public final class AndroidComponentAddress extends SocketAddress {
private static final long serialVersionUID = 0L;

cbianchi-7 marked this conversation as resolved.
Show resolved Hide resolved
private final Intent bindIntent; // An "explicit" Intent. In other words, getComponent() != null.
Expand Down Expand Up @@ -103,6 +101,10 @@ public static AndroidComponentAddress forComponent(ComponentName component) {
new Intent(ApiConstants.ACTION_BIND).setComponent(component));
}

/**
* Returns the Authority which is the package name of the target app.
* See {@link android.content.ComponentName}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

between paragraphs (https://google.github.io/styleguide/javaguide.html#s7.1.2-javadoc-paragraphs)

*/
public String getAuthority() {
return getComponent().getPackageName();
}
Expand Down
16 changes: 16 additions & 0 deletions binder/src/main/java/io/grpc/binder/BinderInternal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.grpc.binder;
ejona86 marked this conversation as resolved.
Show resolved Hide resolved

import android.os.IBinder;

/**
* Helper class to expose IBinderReceiver methods for legacy internal builders.
*/
public class BinderInternal {

/**
* Set the receiver's {@link IBinder} using {@link IBinderReceiver#set(IBinder)}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
static void setIBinder(IBinderReceiver receiver, IBinder binder) {
receiver.set(binder);
}
}
16 changes: 7 additions & 9 deletions binder/src/main/java/io/grpc/binder/BinderServerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import android.os.IBinder;
import com.google.common.base.Supplier;
import com.google.errorprone.annotations.DoNotCall;
import io.grpc.CompressorRegistry;
import io.grpc.DecompressorRegistry;
import io.grpc.ExperimentalApi;
import io.grpc.Server;
import io.grpc.ServerBuilder;
Expand All @@ -48,7 +46,6 @@
/**
* Builder for a server that services requests from an Android Service.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public final class BinderServerBuilder
cbianchi-7 marked this conversation as resolved.
Show resolved Hide resolved
cbianchi-7 marked this conversation as resolved.
Show resolved Hide resolved
extends ForwardingServerBuilder<BinderServerBuilder> {

cbianchi-7 marked this conversation as resolved.
Show resolved Hide resolved
cbianchi-7 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -95,15 +92,10 @@ private BinderServerBuilder(
streamTracerFactories,
securityPolicy,
inboundParcelablePolicy);
binderReceiver.set(server.getHostBinder());
BinderInternal.setIBinder(binderReceiver, server.getHostBinder());
return server;
});

// Disable compression by default, since there's little benefit when all communication is
// on-device, and it means sending supported-encoding headers with every call.
decompressorRegistry(DecompressorRegistry.emptyInstance());
compressorRegistry(CompressorRegistry.newEmptyInstance());

// Disable stats and tracing by default.
serverImplBuilder.setStatsEnabled(false);
cbianchi-7 marked this conversation as resolved.
Show resolved Hide resolved
serverImplBuilder.setTracingEnabled(false);
Expand All @@ -117,12 +109,14 @@ protected ServerBuilder<?> delegate() {
}

/** Enable stats collection using census. */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public BinderServerBuilder enableStats() {
serverImplBuilder.setStatsEnabled(true);
return this;
}

/** Enable tracing using census. */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public BinderServerBuilder enableTracing() {
serverImplBuilder.setTracingEnabled(true);
return this;
Expand Down Expand Up @@ -157,12 +151,16 @@ public BinderServerBuilder securityPolicy(ServerSecurityPolicy securityPolicy) {
}

/** Sets the policy for inbound parcelable objects. */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public BinderServerBuilder inboundParcelablePolicy(
InboundParcelablePolicy inboundParcelablePolicy) {
this.inboundParcelablePolicy = checkNotNull(inboundParcelablePolicy, "inboundParcelablePolicy");
return this;
}

/**
* Always fails. TLS is not supported in BinderServer.
*/
@Override
public BinderServerBuilder useTransportSecurity(File certChain, File privateKey) {
throw new UnsupportedOperationException("TLS not supported in BinderServer");
Expand Down
8 changes: 3 additions & 5 deletions binder/src/main/java/io/grpc/binder/IBinderReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,22 @@
package io.grpc.binder;

import android.os.IBinder;
import io.grpc.ExperimentalApi;
import javax.annotation.Nullable;

/** A container for at most one instance of {@link IBinder}, useful as an "out parameter". */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public final class IBinderReceiver {
cbianchi-7 marked this conversation as resolved.
Show resolved Hide resolved
cbianchi-7 marked this conversation as resolved.
Show resolved Hide resolved
@Nullable private IBinder value;
@Nullable private volatile IBinder value;

/** Constructs a new, initially empty, container. */
public IBinderReceiver() {}

/** Returns the contents of this container or null if it is empty. */
@Nullable
public synchronized IBinder get() {
public IBinder get() {
return value;
}

public synchronized void set(IBinder value) {
protected void set(IBinder value) {
this.value = value;
}
}
2 changes: 0 additions & 2 deletions binder/src/main/java/io/grpc/binder/ParcelableUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.grpc.binder;

import android.os.Parcelable;
import io.grpc.ExperimentalApi;
import io.grpc.Metadata;
import io.grpc.binder.internal.MetadataHelper;

Expand All @@ -26,7 +25,6 @@
*
* <p>This class models the same pattern as the {@code ProtoLiteUtils} class.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public final class ParcelableUtils {

private ParcelableUtils() {}
Expand Down
9 changes: 8 additions & 1 deletion binder/src/main/java/io/grpc/binder/SecurityPolicies.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@

/** Static factory methods for creating standard security policies. */
@CheckReturnValue
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public final class SecurityPolicies {

private static final int MY_UID = Process.myUid();
private static final int SHA_256_BYTES_LENGTH = 32;

private SecurityPolicies() {}

@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public static ServerSecurityPolicy serverInternalOnly() {
return new ServerSecurityPolicy();
}
cbianchi-7 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates a default {@link SecurityPolicy} that checks authorization based on UID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"... that allows access only to callers with the same UID as the current process."

*/
public static SecurityPolicy internalOnly() {
return new SecurityPolicy() {
@Override
Expand All @@ -66,6 +69,7 @@ public Status checkAuthorization(int uid) {
};
}

@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public static SecurityPolicy permissionDenied(String description) {
Status denied = Status.PERMISSION_DENIED.withDescription(description);
return new SecurityPolicy() {
Expand All @@ -84,6 +88,7 @@ public Status checkAuthorization(int uid) {
* @param requiredSignature the allowed signature of the allowed package.
* @throws NullPointerException if any of the inputs are {@code null}.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public static SecurityPolicy hasSignature(
PackageManager packageManager, String packageName, Signature requiredSignature) {
return oneOfSignatures(
Expand All @@ -99,6 +104,7 @@ public static SecurityPolicy hasSignature(
* @throws NullPointerException if any of the inputs are {@code null}.
* @throws IllegalArgumentException if {@code requiredSignatureSha256Hash} is not of length 32.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public static SecurityPolicy hasSignatureSha256Hash(
PackageManager packageManager, String packageName, byte[] requiredSignatureSha256Hash) {
return oneOfSignatureSha256Hash(
Expand All @@ -114,6 +120,7 @@ public static SecurityPolicy hasSignatureSha256Hash(
* @throws NullPointerException if any of the inputs are {@code null}.
* @throws IllegalArgumentException if {@code requiredSignatures} is empty.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public static SecurityPolicy oneOfSignatures(
PackageManager packageManager,
String packageName,
Expand Down
2 changes: 0 additions & 2 deletions binder/src/main/java/io/grpc/binder/SecurityPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.grpc.binder;

import io.grpc.ExperimentalApi;
import io.grpc.Status;
import javax.annotation.CheckReturnValue;

Expand All @@ -37,7 +36,6 @@
* re-installation of the applications involved.
*/
@CheckReturnValue
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public abstract class SecurityPolicy {

protected SecurityPolicy() {}
Expand Down
2 changes: 0 additions & 2 deletions binder/src/main/java/io/grpc/binder/ServerSecurityPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.grpc.binder;

import com.google.common.collect.ImmutableMap;
import io.grpc.ExperimentalApi;
import io.grpc.Status;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -28,7 +27,6 @@
*
* Contains a default policy, and optional policies for each server.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public final class ServerSecurityPolicy {

private final SecurityPolicy defaultPolicy;
Expand Down