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: classes3.dex */ public final class RestrictedComponentContainer implements ComponentContainer { public final Set allowedDeferredInterfaces; public final Set allowedDirectInterfaces; public final Set allowedProviderInterfaces; public final Set allowedPublishedEvents; public final Set allowedSetDirectInterfaces; public final Set allowedSetProviderInterfaces; public final ComponentContainer delegateContainer; 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(Qualified.unqualified(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.ComponentContainer public Object get(Class cls) { if (!this.allowedDirectInterfaces.contains(Qualified.unqualified(cls))) { throw new DependencyException(String.format("Attempting to request an undeclared dependency %s.", cls)); } Object obj = this.delegateContainer.get(cls); return !cls.equals(Publisher.class) ? obj : new RestrictedPublisher(this.allowedPublishedEvents, (Publisher) obj); } @Override // com.google.firebase.components.ComponentContainer public Object get(Qualified qualified) { if (!this.allowedDirectInterfaces.contains(qualified)) { throw new DependencyException(String.format("Attempting to request an undeclared dependency %s.", qualified)); } return this.delegateContainer.get(qualified); } @Override // com.google.firebase.components.ComponentContainer public Provider getProvider(Class cls) { return getProvider(Qualified.unqualified(cls)); } @Override // com.google.firebase.components.ComponentContainer public Deferred getDeferred(Class cls) { return getDeferred(Qualified.unqualified(cls)); } @Override // com.google.firebase.components.ComponentContainer public Provider getProvider(Qualified qualified) { if (!this.allowedProviderInterfaces.contains(qualified)) { throw new DependencyException(String.format("Attempting to request an undeclared dependency Provider<%s>.", qualified)); } return this.delegateContainer.getProvider(qualified); } @Override // com.google.firebase.components.ComponentContainer public Deferred getDeferred(Qualified qualified) { if (!this.allowedDeferredInterfaces.contains(qualified)) { throw new DependencyException(String.format("Attempting to request an undeclared dependency Deferred<%s>.", qualified)); } return this.delegateContainer.getDeferred(qualified); } @Override // com.google.firebase.components.ComponentContainer public Provider setOfProvider(Qualified qualified) { if (!this.allowedSetProviderInterfaces.contains(qualified)) { throw new DependencyException(String.format("Attempting to request an undeclared dependency Provider>.", qualified)); } return this.delegateContainer.setOfProvider(qualified); } @Override // com.google.firebase.components.ComponentContainer public Set setOf(Qualified qualified) { if (!this.allowedSetDirectInterfaces.contains(qualified)) { throw new DependencyException(String.format("Attempting to request an undeclared dependency Set<%s>.", qualified)); } return this.delegateContainer.setOf(qualified); } public static class RestrictedPublisher implements Publisher { public final Set allowedPublishedEvents; public final Publisher delegate; public RestrictedPublisher(Set set, Publisher publisher) { this.allowedPublishedEvents = set; this.delegate = publisher; } } }