Package 

Class BinderChannelBuilder


  • @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.

    • Method Detail

      • 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.
      • 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.
      • 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.