package com.google.firebase.components; import com.google.firebase.events.Publisher; import com.google.firebase.inject.Deferred; import com.google.firebase.inject.Provider; import java.util.Collections; import java.util.HashSet; import java.util.Set; /* loaded from: classes.dex */ final class RestrictedComponentContainer extends AbstractComponentContainer { private final Set> allowedDeferredInterfaces; private final Set> allowedDirectInterfaces; private final Set> allowedProviderInterfaces; private final Set> allowedPublishedEvents; private final Set> allowedSetDirectInterfaces; private final Set> allowedSetProviderInterfaces; private final ComponentContainer delegateContainer; /* JADX INFO: Access modifiers changed from: package-private */ public RestrictedComponentContainer(Component component, ComponentContainer componentContainer) { HashSet hashSet = new HashSet(); HashSet hashSet2 = new HashSet(); HashSet hashSet3 = new HashSet(); HashSet hashSet4 = new HashSet(); HashSet hashSet5 = new HashSet(); for (Dependency dependency : component.getDependencies()) { if (dependency.isDirectInjection()) { if (dependency.isSet()) { hashSet4.add(dependency.getInterface()); } else { hashSet.add(dependency.getInterface()); } } else if (dependency.isDeferred()) { hashSet3.add(dependency.getInterface()); } else if (dependency.isSet()) { hashSet5.add(dependency.getInterface()); } else { hashSet2.add(dependency.getInterface()); } } if (!component.getPublishedEvents().isEmpty()) { hashSet.add(Publisher.class); } this.allowedDirectInterfaces = Collections.unmodifiableSet(hashSet); this.allowedProviderInterfaces = Collections.unmodifiableSet(hashSet2); this.allowedDeferredInterfaces = Collections.unmodifiableSet(hashSet3); this.allowedSetDirectInterfaces = Collections.unmodifiableSet(hashSet4); this.allowedSetProviderInterfaces = Collections.unmodifiableSet(hashSet5); this.allowedPublishedEvents = component.getPublishedEvents(); this.delegateContainer = componentContainer; } @Override // com.google.firebase.components.AbstractComponentContainer, com.google.firebase.components.ComponentContainer public final T get(Class cls) { if (!this.allowedDirectInterfaces.contains(cls)) { throw new DependencyException(String.format("Attempting to request an undeclared dependency %s.", cls)); } T t = (T) this.delegateContainer.get(cls); return !cls.equals(Publisher.class) ? t : (T) new RestrictedPublisher(this.allowedPublishedEvents, (Publisher) t); } @Override // com.google.firebase.components.ComponentContainer public final Provider getProvider(Class cls) { if (!this.allowedProviderInterfaces.contains(cls)) { throw new DependencyException(String.format("Attempting to request an undeclared dependency Provider<%s>.", cls)); } return this.delegateContainer.getProvider(cls); } @Override // com.google.firebase.components.ComponentContainer public final Deferred getDeferred(Class cls) { if (!this.allowedDeferredInterfaces.contains(cls)) { throw new DependencyException(String.format("Attempting to request an undeclared dependency Deferred<%s>.", cls)); } return this.delegateContainer.getDeferred(cls); } @Override // com.google.firebase.components.ComponentContainer public final Provider> setOfProvider(Class cls) { if (!this.allowedSetProviderInterfaces.contains(cls)) { throw new DependencyException(String.format("Attempting to request an undeclared dependency Provider>.", cls)); } return this.delegateContainer.setOfProvider(cls); } @Override // com.google.firebase.components.AbstractComponentContainer, com.google.firebase.components.ComponentContainer public final Set setOf(Class cls) { if (!this.allowedSetDirectInterfaces.contains(cls)) { throw new DependencyException(String.format("Attempting to request an undeclared dependency Set<%s>.", cls)); } return this.delegateContainer.setOf(cls); } /* loaded from: classes.dex */ static class RestrictedPublisher implements Publisher { private final Set> allowedPublishedEvents; private final Publisher delegate; public RestrictedPublisher(Set> set, Publisher publisher) { this.allowedPublishedEvents = set; this.delegate = publisher; } } }