mirror of https://github.com/grpc/grpc-java.git
parent
fd8734f341
commit
c2eccca3bc
|
@ -20,9 +20,12 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static io.grpc.internal.GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
|
import static io.grpc.internal.GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
|
||||||
|
|
||||||
|
import android.net.Network;
|
||||||
|
import android.os.Build;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
import com.google.errorprone.annotations.DoNotCall;
|
import com.google.errorprone.annotations.DoNotCall;
|
||||||
import io.grpc.ChannelCredentials;
|
import io.grpc.ChannelCredentials;
|
||||||
import io.grpc.ChannelLogger;
|
import io.grpc.ChannelLogger;
|
||||||
|
@ -105,6 +108,7 @@ public final class CronetChannelBuilder extends ForwardingChannelBuilder2<Cronet
|
||||||
private int trafficStatsTag;
|
private int trafficStatsTag;
|
||||||
private boolean trafficStatsUidSet;
|
private boolean trafficStatsUidSet;
|
||||||
private int trafficStatsUid;
|
private int trafficStatsUid;
|
||||||
|
private Network network;
|
||||||
|
|
||||||
private CronetChannelBuilder(String host, int port, CronetEngine cronetEngine) {
|
private CronetChannelBuilder(String host, int port, CronetEngine cronetEngine) {
|
||||||
final class CronetChannelTransportFactoryBuilder implements ClientTransportFactoryBuilder {
|
final class CronetChannelTransportFactoryBuilder implements ClientTransportFactoryBuilder {
|
||||||
|
@ -190,6 +194,13 @@ public final class CronetChannelBuilder extends ForwardingChannelBuilder2<Cronet
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sets the network ID to use for this channel traffic. */
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
CronetChannelBuilder bindToNetwork(@Nullable Network network) {
|
||||||
|
this.network = network;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a custom scheduled executor service.
|
* Provides a custom scheduled executor service.
|
||||||
*
|
*
|
||||||
|
@ -210,7 +221,12 @@ public final class CronetChannelBuilder extends ForwardingChannelBuilder2<Cronet
|
||||||
ClientTransportFactory buildTransportFactory() {
|
ClientTransportFactory buildTransportFactory() {
|
||||||
return new CronetTransportFactory(
|
return new CronetTransportFactory(
|
||||||
new TaggingStreamFactory(
|
new TaggingStreamFactory(
|
||||||
cronetEngine, trafficStatsTagSet, trafficStatsTag, trafficStatsUidSet, trafficStatsUid),
|
cronetEngine,
|
||||||
|
trafficStatsTagSet,
|
||||||
|
trafficStatsTag,
|
||||||
|
trafficStatsUidSet,
|
||||||
|
trafficStatsUid,
|
||||||
|
network),
|
||||||
MoreExecutors.directExecutor(),
|
MoreExecutors.directExecutor(),
|
||||||
scheduledExecutorService,
|
scheduledExecutorService,
|
||||||
maxMessageSize,
|
maxMessageSize,
|
||||||
|
@ -294,18 +310,21 @@ public final class CronetChannelBuilder extends ForwardingChannelBuilder2<Cronet
|
||||||
private final int trafficStatsTag;
|
private final int trafficStatsTag;
|
||||||
private final boolean trafficStatsUidSet;
|
private final boolean trafficStatsUidSet;
|
||||||
private final int trafficStatsUid;
|
private final int trafficStatsUid;
|
||||||
|
private final Network network;
|
||||||
|
|
||||||
TaggingStreamFactory(
|
TaggingStreamFactory(
|
||||||
CronetEngine cronetEngine,
|
CronetEngine cronetEngine,
|
||||||
boolean trafficStatsTagSet,
|
boolean trafficStatsTagSet,
|
||||||
int trafficStatsTag,
|
int trafficStatsTag,
|
||||||
boolean trafficStatsUidSet,
|
boolean trafficStatsUidSet,
|
||||||
int trafficStatsUid) {
|
int trafficStatsUid,
|
||||||
|
Network network) {
|
||||||
this.cronetEngine = cronetEngine;
|
this.cronetEngine = cronetEngine;
|
||||||
this.trafficStatsTagSet = trafficStatsTagSet;
|
this.trafficStatsTagSet = trafficStatsTagSet;
|
||||||
this.trafficStatsTag = trafficStatsTag;
|
this.trafficStatsTag = trafficStatsTag;
|
||||||
this.trafficStatsUidSet = trafficStatsUidSet;
|
this.trafficStatsUidSet = trafficStatsUidSet;
|
||||||
this.trafficStatsUid = trafficStatsUid;
|
this.trafficStatsUid = trafficStatsUid;
|
||||||
|
this.network = network;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -320,6 +339,11 @@ public final class CronetChannelBuilder extends ForwardingChannelBuilder2<Cronet
|
||||||
if (trafficStatsUidSet) {
|
if (trafficStatsUidSet) {
|
||||||
builder.setTrafficStatsUid(trafficStatsUid);
|
builder.setTrafficStatsUid(trafficStatsUid);
|
||||||
}
|
}
|
||||||
|
if (network != null) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 23) {
|
||||||
|
builder.bindToNetwork(network.getNetworkHandle());
|
||||||
|
}
|
||||||
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
|
|
||||||
package io.grpc.cronet;
|
package io.grpc.cronet;
|
||||||
|
|
||||||
|
import android.net.Network;
|
||||||
import io.grpc.Internal;
|
import io.grpc.Internal;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal {@link CronetChannelBuilder} accessor. This is intended for usage internal to the gRPC
|
* Internal {@link CronetChannelBuilder} accessor. This is intended for usage internal to the gRPC
|
||||||
|
@ -58,4 +60,9 @@ public final class InternalCronetChannelBuilder {
|
||||||
public static void setTrafficStatsUid(CronetChannelBuilder builder, int uid) {
|
public static void setTrafficStatsUid(CronetChannelBuilder builder, int uid) {
|
||||||
builder.setTrafficStatsUid(uid);
|
builder.setTrafficStatsUid(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sets the network {@link android.net.Network} to use when relying traffic by this channel. */
|
||||||
|
public static void bindToNetwork(CronetChannelBuilder builder, @Nullable Network network) {
|
||||||
|
builder.bindToNetwork(network);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue