core: Allow avoiding Provider loading, for Android

This commit is contained in:
Eric Anderson 2016-07-11 10:02:23 -07:00
parent d7bf67e01f
commit bfcb04c196
1 changed files with 8 additions and 1 deletions

View File

@ -241,11 +241,18 @@ public abstract class AbstractManagedChannelImplBuilder
transportFactory = new AuthorityOverridingTransportFactory(
transportFactory, authorityOverride);
}
NameResolver.Factory nameResolverFactory = this.nameResolverFactory;
if (nameResolverFactory == null) {
// Avoid loading the provider unless necessary, as a way to workaround a possibly-costly
// and poorly optimized getResource() call on Android. If any other piece of code calls
// getResource(), then this shouldn't be a problem unless called on the UI thread.
nameResolverFactory = NameResolverProvider.asFactory();
}
return new ManagedChannelImpl(
target,
// TODO(carl-mastrangelo): Allow clients to pass this in
new ExponentialBackoffPolicy.Provider(),
firstNonNull(nameResolverFactory, NameResolverProvider.asFactory()),
nameResolverFactory,
getNameResolverParams(),
firstNonNull(loadBalancerFactory, DummyLoadBalancerFactory.getInstance()),
transportFactory,