-
@ExperimentalApi(value = https://github.com/grpc/grpc-java/issues/8022) public final class BinderChannelBuilder extends ForwardingChannelBuilder<BinderChannelBuilder>
Builder for a gRPC channel which communicates with an Android bound service.
-
-
Field Summary
Fields Modifier and Type Field Description private BindServiceFlagsbindServiceFlags
-
Method Summary
Modifier and Type Method Description BinderChannelBuildersetBindServiceFlags(BindServiceFlags bindServiceFlags)Specifies certain optional aspects of the underlying Android Service binding. static BinderChannelBuilderforAddress(AndroidComponentAddress directAddress, Context sourceContext)Creates a channel builder that will bind to a remote Android service. static BinderChannelBuilderforAddress(AndroidComponentAddress directAddress, Context sourceContext, BinderChannelCredentials channelCredentials)Creates a channel builder that will bind to a remote Android service with providedBinderChannelCredentials. static BinderChannelBuilderforTarget(String target, Context sourceContext)Creates a channel builder that will bind to a remote Android service, via a stringtarget name which will be resolved. static BinderChannelBuilderforTarget(String target, Context sourceContext, BinderChannelCredentials channelCredentials)Creates a channel builder that will bind to a remote Android service, via a string target namewhich will be resolved. static BinderChannelBuilderforAddress(String name, int port)Always fails. static BinderChannelBuilderforTarget(String target)Always fails. BinderChannelBuilderscheduledExecutorService(ScheduledExecutorService scheduledExecutorService)Provides a custom scheduled executor service. BinderChannelBuildermainThreadExecutor(Executor mainThreadExecutor)Provides a custom Executor for accessing this application's main thread. BinderChannelBuildersecurityPolicy(SecurityPolicy securityPolicy)Provides a custom security policy. BinderChannelBuilderbindAsUser(UserHandle targetUserHandle)Provides the target {@UserHandle} of the remote Android service. BinderChannelBuilderinboundParcelablePolicy(InboundParcelablePolicy inboundParcelablePolicy)Sets the policy for inbound parcelable objects. BinderChannelBuilderstrictLifecycleManagement()Disables the channel idle timeout and prevents it from being enabled. BinderChannelBuilderidleTimeout(long value, TimeUnit unit)-
Methods inherited from class io.grpc.ForwardingChannelBuilder
compressorRegistry, decompressorRegistry, defaultLoadBalancingPolicy, defaultServiceConfig, directExecutor, disableRetry, disableServiceConfigLookUp, enableRetry, executor, idleTimeout, intercept, keepAliveTime, keepAliveTimeout, keepAliveWithoutCalls, maxHedgedAttempts, maxInboundMessageSize, maxInboundMetadataSize, maxRetryAttempts, maxTraceEvents, nameResolverFactory, offloadExecutor, overrideAuthority, perRpcBufferLimit, proxyDetector, retryBufferSize, setBinaryLog, usePlaintext, useTransportSecurity, userAgent -
Methods inherited from class io.grpc.ForwardingChannelBuilder2
build, forAddress, forTarget, toString -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
setBindServiceFlags
BinderChannelBuilder setBindServiceFlags(BindServiceFlags bindServiceFlags)
Specifies certain optional aspects of the underlying Android Service binding.
-
forAddress
static BinderChannelBuilder forAddress(AndroidComponentAddress directAddress, Context sourceContext)
Creates a channel builder that will bind to a remote Android service.
The underlying Android binding will be torn down when the channel becomes idle. This happensafter 30 minutes without use by default but can be configured via or triggered manually with .
You the caller are responsible for managing the lifecycle of any channels built by theresulting builder. They will not be shut down automatically.
- Parameters:
directAddress- the AndroidComponentAddress referencing the service to bind to.sourceContext- the context to bind from (e.g.
-
forAddress
@ExperimentalApi(value = https://github.com/grpc/grpc-java/issues/10173) static BinderChannelBuilder forAddress(AndroidComponentAddress directAddress, Context sourceContext, BinderChannelCredentials channelCredentials)
Creates a channel builder that will bind to a remote Android service with providedBinderChannelCredentials.
The underlying Android binding will be torn down when the channel becomes idle. This happensafter 30 minutes without use by default but can be configured via or triggered manually with .
You the caller are responsible for managing the lifecycle of any channels built by theresulting builder. They will not be shut down automatically.
- Parameters:
directAddress- the AndroidComponentAddress referencing the service to bind to.sourceContext- the context to bind from (e.g.channelCredentials- the arbitrary binder specific channel credentials to be used toestablish a binder connection.
-
forTarget
static BinderChannelBuilder forTarget(String target, Context sourceContext)
Creates a channel builder that will bind to a remote Android service, via a stringtarget name which will be resolved.
The underlying Android binding will be torn down when the channel becomes idle. This happensafter 30 minutes without use by default but can be configured via or triggered manually with .
You the caller are responsible for managing the lifecycle of any channels built by theresulting builder. They will not be shut down automatically.
- Parameters:
target- A target uri which should resolve into an AndroidComponentAddress referencing the service to bind to.sourceContext- the context to bind from (e.g.
-
forTarget
@ExperimentalApi(value = https://github.com/grpc/grpc-java/issues/10173) static BinderChannelBuilder forTarget(String target, Context sourceContext, BinderChannelCredentials channelCredentials)
Creates a channel builder that will bind to a remote Android service, via a string target namewhich will be resolved.
The underlying Android binding will be torn down when the channel becomes idle. This happensafter 30 minutes without use by default but can be configured via or triggered manually with .
You the caller are responsible for managing the lifecycle of any channels built by theresulting builder. They will not be shut down automatically.
- Parameters:
target- A target uri which should resolve into an AndroidComponentAddress referencing the service to bind to.sourceContext- the context to bind from (e.g.channelCredentials- the arbitrary binder specific channel credentials to be used toestablish a binder connection.
-
forAddress
static BinderChannelBuilder forAddress(String name, int port)
Always fails. Call forAddress instead.
-
forTarget
static BinderChannelBuilder forTarget(String target)
Always fails. Call forAddress instead.
-
scheduledExecutorService
BinderChannelBuilder scheduledExecutorService(ScheduledExecutorService scheduledExecutorService)
Provides a custom scheduled executor service.
This is an optional parameter. If the user has not provided a scheduled executor servicewhen the channel is built, the builder will use a static cached thread pool.
-
mainThreadExecutor
BinderChannelBuilder mainThreadExecutor(Executor mainThreadExecutor)
Provides a custom Executor for accessing this application's main thread.
Optional. A default implementation will be used if no custom Executor is provided.
-
securityPolicy
BinderChannelBuilder securityPolicy(SecurityPolicy securityPolicy)
Provides a custom security policy.
This is optional. If the user has not provided a security policy, this channel will onlycommunicate with the same application UID.
-
bindAsUser
@ExperimentalApi(value = https://github.com/grpc/grpc-java/issues/10173) BinderChannelBuilder bindAsUser(UserHandle targetUserHandle)
Provides the target {@UserHandle} of the remote Android service.
When targetUserHandle is set, Context.bindServiceAsUser will used and additional Androidpermissions will be required. If your usage does not require cross-user communications, pleasedo not set this field. It is the caller's responsibility to make sure that it holds thecorresponding permissions.
- Parameters:
targetUserHandle- the target user to bind into.
-
inboundParcelablePolicy
BinderChannelBuilder inboundParcelablePolicy(InboundParcelablePolicy inboundParcelablePolicy)
Sets the policy for inbound parcelable objects.
-
strictLifecycleManagement
BinderChannelBuilder strictLifecycleManagement()
Disables the channel idle timeout and prevents it from being enabled. Thisallows a centralized application method to configure the channel builderand return it, without worrying about another part of the applicationaccidentally enabling the idle timeout.
-
idleTimeout
BinderChannelBuilder idleTimeout(long value, TimeUnit unit)
-
-
-
-