package com.google.firebase.firestore.remote; import android.content.Context; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.gms.tasks.Task; import com.google.firebase.firestore.auth.CredentialsProvider; import com.google.firebase.firestore.auth.User; import com.google.firebase.firestore.core.DatabaseInfo; import com.google.firebase.firestore.model.DatabaseId; import com.google.firebase.firestore.util.Assert; import com.google.firebase.firestore.util.AsyncQueue; import io.grpc.ClientCall; import io.grpc.ForwardingClientCall; import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.Status; /* loaded from: classes2.dex */ public class FirestoreChannel { private final CredentialsProvider appCheckProvider; private final AsyncQueue asyncQueue; private final CredentialsProvider authProvider; private final GrpcCallProvider callProvider; private final GrpcMetadataProvider metadataProvider; private final String resourcePrefixValue; private static final Metadata.Key X_GOOG_API_CLIENT_HEADER = Metadata.Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER); private static final Metadata.Key RESOURCE_PREFIX_HEADER = Metadata.Key.of("google-cloud-resource-prefix", Metadata.ASCII_STRING_MARSHALLER); private static final Metadata.Key X_GOOG_REQUEST_PARAMS_HEADER = Metadata.Key.of("x-goog-request-params", Metadata.ASCII_STRING_MARSHALLER); private static volatile String clientLanguage = "gl-java/"; /* JADX INFO: Access modifiers changed from: package-private */ public FirestoreChannel(AsyncQueue asyncQueue, Context context, CredentialsProvider credentialsProvider, CredentialsProvider credentialsProvider2, DatabaseInfo databaseInfo, GrpcMetadataProvider grpcMetadataProvider) { this.asyncQueue = asyncQueue; this.metadataProvider = grpcMetadataProvider; this.authProvider = credentialsProvider; this.appCheckProvider = credentialsProvider2; this.callProvider = new GrpcCallProvider(asyncQueue, context, databaseInfo, new FirestoreCallCredentials(credentialsProvider, credentialsProvider2)); DatabaseId databaseId = databaseInfo.getDatabaseId(); this.resourcePrefixValue = String.format("projects/%s/databases/%s", databaseId.getProjectId(), databaseId.getDatabaseId()); } /* JADX INFO: Access modifiers changed from: package-private */ public ClientCall runBidiStreamingRpc(MethodDescriptor methodDescriptor, final IncomingStreamObserver incomingStreamObserver) { final ClientCall[] clientCallArr = {null}; Task> createClientCall = this.callProvider.createClientCall(methodDescriptor); createClientCall.addOnCompleteListener(this.asyncQueue.getExecutor(), new OnCompleteListener(this, clientCallArr, incomingStreamObserver) { // from class: com.google.firebase.firestore.remote.FirestoreChannel$$ExternalSyntheticLambda2 public final FirestoreChannel f$0; public final ClientCall[] f$1; public final IncomingStreamObserver f$2; @Override // com.google.android.gms.tasks.OnCompleteListener public final void onComplete(Task task) { this.f$0.m243xae2b8084(this.f$1, this.f$2, task); } { this.f$0 = this; this.f$1 = clientCallArr; this.f$2 = incomingStreamObserver; } }); return new AnonymousClass2(this, clientCallArr, createClientCall); } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: lambda$runBidiStreamingRpc$0$com-google-firebase-firestore-remote-FirestoreChannel, reason: not valid java name */ public /* synthetic */ void m243xae2b8084(ClientCall[] clientCallArr, IncomingStreamObserver incomingStreamObserver, Task task) { ClientCall clientCall = (ClientCall) task.getResult(); clientCallArr[0] = clientCall; clientCall.start(new ClientCall.Listener(this, incomingStreamObserver, clientCallArr) { // from class: com.google.firebase.firestore.remote.FirestoreChannel.1 final FirestoreChannel this$0; final ClientCall[] val$call; final IncomingStreamObserver val$observer; @Override // io.grpc.ClientCall.Listener public void onReady() { } { this.this$0 = this; this.val$observer = incomingStreamObserver; this.val$call = clientCallArr; } @Override // io.grpc.ClientCall.Listener public void onHeaders(Metadata metadata) { try { this.val$observer.onHeaders(metadata); } catch (Throwable th) { this.this$0.asyncQueue.panic(th); } } @Override // io.grpc.ClientCall.Listener public void onMessage(RespT respt) { try { this.val$observer.onNext(respt); this.val$call[0].request(1); } catch (Throwable th) { this.this$0.asyncQueue.panic(th); } } @Override // io.grpc.ClientCall.Listener public void onClose(Status status, Metadata metadata) { try { this.val$observer.onClose(status); } catch (Throwable th) { this.this$0.asyncQueue.panic(th); } } }, requestHeaders()); incomingStreamObserver.onOpen(); clientCallArr[0].request(1); } /* JADX INFO: Add missing generic type declarations: [ReqT, RespT] */ /* renamed from: com.google.firebase.firestore.remote.FirestoreChannel$2, reason: invalid class name */ /* loaded from: classes2.dex */ class AnonymousClass2 extends ForwardingClientCall { final FirestoreChannel this$0; final ClientCall[] val$call; final Task val$clientCall; AnonymousClass2(FirestoreChannel firestoreChannel, ClientCall[] clientCallArr, Task task) { this.this$0 = firestoreChannel; this.val$call = clientCallArr; this.val$clientCall = task; } @Override // io.grpc.ForwardingClientCall, io.grpc.PartialForwardingClientCall public ClientCall delegate() { Assert.hardAssert(this.val$call[0] != null, "ClientCall used before onOpen() callback", new Object[0]); return this.val$call[0]; } @Override // io.grpc.ForwardingClientCall, io.grpc.PartialForwardingClientCall, io.grpc.ClientCall public void halfClose() { if (this.val$call[0] == null) { this.val$clientCall.addOnSuccessListener(this.this$0.asyncQueue.getExecutor(), new OnSuccessListener() { // from class: com.google.firebase.firestore.remote.FirestoreChannel$2$$ExternalSyntheticLambda0 @Override // com.google.android.gms.tasks.OnSuccessListener public final void onSuccess(Object obj) { ((ClientCall) obj).halfClose(); } }); } else { super.halfClose(); } } } public void invalidateToken() { this.authProvider.invalidateToken(); this.appCheckProvider.invalidateToken(); } private String getGoogApiClientValue() { return String.format("%s fire/%s grpc/", clientLanguage, "24.3.0"); } private Metadata requestHeaders() { Metadata metadata = new Metadata(); metadata.put(X_GOOG_API_CLIENT_HEADER, getGoogApiClientValue()); metadata.put(RESOURCE_PREFIX_HEADER, this.resourcePrefixValue); metadata.put(X_GOOG_REQUEST_PARAMS_HEADER, this.resourcePrefixValue); GrpcMetadataProvider grpcMetadataProvider = this.metadataProvider; if (grpcMetadataProvider != null) { grpcMetadataProvider.updateMetadata(metadata); } return metadata; } }