binder: Promote out of experimental status (#9669)

This commit is contained in:
cbianchi-7 2022-11-30 10:37:32 -08:00 committed by GitHub
parent a5f458a3a7
commit d6aa0ea370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 24 deletions

View File

@ -22,7 +22,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import io.grpc.ExperimentalApi;
import java.net.SocketAddress;
/**
@ -41,8 +40,7 @@ import java.net.SocketAddress;
* 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;
private final Intent bindIntent; // An "explicit" Intent. In other words, getComponent() != null.
@ -103,6 +101,10 @@ public class AndroidComponentAddress extends SocketAddress { // NOTE: Only tempo
new Intent(ApiConstants.ACTION_BIND).setComponent(component));
}
/**
* Returns the Authority which is the package name of the target app.
* See {@link android.content.ComponentName}.
*/
public String getAuthority() {
return getComponent().getPackageName();
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 2022 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc.binder;
import android.os.IBinder;
import io.grpc.Internal;
/**
* Helper class to expose IBinderReceiver methods for legacy internal builders.
*/
@Internal
public class BinderInternal {
/**
* Set the receiver's {@link IBinder} using {@link IBinderReceiver#set(IBinder)}.
*/
static void setIBinder(IBinderReceiver receiver, IBinder binder) {
receiver.set(binder);
}
}

View File

@ -23,8 +23,6 @@ import android.app.Service;
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;
@ -48,7 +46,6 @@ import javax.annotation.Nullable;
/**
* Builder for a server that services requests from an Android Service.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public final class BinderServerBuilder
extends ForwardingServerBuilder<BinderServerBuilder> {
@ -96,15 +93,10 @@ public final class 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);
serverImplBuilder.setTracingEnabled(false);
@ -116,12 +108,14 @@ public final class BinderServerBuilder
}
/** 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;
@ -156,12 +150,16 @@ public final class BinderServerBuilder
}
/** 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");

View File

@ -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 {
@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;
}
}

View File

@ -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;
@ -26,7 +25,6 @@ import io.grpc.binder.internal.MetadataHelper;
*
* <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() {}

View File

@ -42,7 +42,6 @@ import java.util.List;
/** 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();
@ -50,10 +49,14 @@ public final class SecurityPolicies {
private SecurityPolicies() {}
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public static ServerSecurityPolicy serverInternalOnly() {
return new ServerSecurityPolicy();
}
/**
* Creates a default {@link SecurityPolicy} that checks authorization based on UID.
*/
public static SecurityPolicy internalOnly() {
return new SecurityPolicy() {
@Override
@ -66,6 +69,7 @@ public final class SecurityPolicies {
};
}
@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() {
@ -84,6 +88,7 @@ public final class SecurityPolicies {
* @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(
@ -99,6 +104,7 @@ public final class SecurityPolicies {
* @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(
@ -114,6 +120,7 @@ public final class SecurityPolicies {
* @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,

View File

@ -16,7 +16,6 @@
package io.grpc.binder;
import io.grpc.ExperimentalApi;
import io.grpc.Status;
import javax.annotation.CheckReturnValue;
@ -37,7 +36,6 @@ import javax.annotation.CheckReturnValue;
* re-installation of the applications involved.
*/
@CheckReturnValue
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8022")
public abstract class SecurityPolicy {
protected SecurityPolicy() {}

View File

@ -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;
@ -28,7 +27,6 @@ import javax.annotation.CheckReturnValue;
*
* 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;