171 lines
8.2 KiB
Java
171 lines
8.2 KiB
Java
package com.google.firebase.firestore.remote;
|
|
|
|
import android.content.Context;
|
|
import com.google.firebase.firestore.FirebaseFirestoreException;
|
|
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.remote.WatchStream;
|
|
import com.google.firebase.firestore.remote.WriteStream;
|
|
import com.google.firebase.firestore.util.AsyncQueue;
|
|
import io.grpc.Status;
|
|
import java.util.Arrays;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
import javax.net.ssl.SSLHandshakeException;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class Datastore {
|
|
static final Set<String> WHITE_LISTED_HEADERS = new HashSet(Arrays.asList("date", "x-google-backends", "x-google-netmon-label", "x-google-service", "x-google-gfe-request-trace"));
|
|
private final FirestoreChannel channel;
|
|
private final DatabaseInfo databaseInfo;
|
|
private final RemoteSerializer serializer;
|
|
private final AsyncQueue workerQueue;
|
|
|
|
public Datastore(DatabaseInfo databaseInfo, AsyncQueue asyncQueue, CredentialsProvider<User> credentialsProvider, CredentialsProvider<String> credentialsProvider2, Context context, GrpcMetadataProvider grpcMetadataProvider) {
|
|
this.databaseInfo = databaseInfo;
|
|
this.workerQueue = asyncQueue;
|
|
this.serializer = new RemoteSerializer(databaseInfo.getDatabaseId());
|
|
this.channel = initializeChannel(databaseInfo, asyncQueue, credentialsProvider, credentialsProvider2, context, grpcMetadataProvider);
|
|
}
|
|
|
|
FirestoreChannel initializeChannel(DatabaseInfo databaseInfo, AsyncQueue asyncQueue, CredentialsProvider<User> credentialsProvider, CredentialsProvider<String> credentialsProvider2, Context context, GrpcMetadataProvider grpcMetadataProvider) {
|
|
return new FirestoreChannel(asyncQueue, context, credentialsProvider, credentialsProvider2, databaseInfo, grpcMetadataProvider);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public WatchStream createWatchStream(WatchStream.Callback callback) {
|
|
return new WatchStream(this.channel, this.workerQueue, this.serializer, callback);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public WriteStream createWriteStream(WriteStream.Callback callback) {
|
|
return new WriteStream(this.channel, this.workerQueue, this.serializer, callback);
|
|
}
|
|
|
|
public static boolean isPermanentError(Status status) {
|
|
return isPermanentError(FirebaseFirestoreException.Code.fromValue(status.getCode().value()));
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: com.google.firebase.firestore.remote.Datastore$2, reason: invalid class name */
|
|
/* loaded from: classes2.dex */
|
|
public static /* synthetic */ class AnonymousClass2 {
|
|
static final int[] $SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code;
|
|
|
|
static {
|
|
int[] iArr = new int[FirebaseFirestoreException.Code.values().length];
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code = iArr;
|
|
try {
|
|
iArr[FirebaseFirestoreException.Code.OK.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.CANCELLED.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused2) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.UNKNOWN.ordinal()] = 3;
|
|
} catch (NoSuchFieldError unused3) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.DEADLINE_EXCEEDED.ordinal()] = 4;
|
|
} catch (NoSuchFieldError unused4) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.RESOURCE_EXHAUSTED.ordinal()] = 5;
|
|
} catch (NoSuchFieldError unused5) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.INTERNAL.ordinal()] = 6;
|
|
} catch (NoSuchFieldError unused6) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.UNAVAILABLE.ordinal()] = 7;
|
|
} catch (NoSuchFieldError unused7) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.UNAUTHENTICATED.ordinal()] = 8;
|
|
} catch (NoSuchFieldError unused8) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.INVALID_ARGUMENT.ordinal()] = 9;
|
|
} catch (NoSuchFieldError unused9) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.NOT_FOUND.ordinal()] = 10;
|
|
} catch (NoSuchFieldError unused10) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.ALREADY_EXISTS.ordinal()] = 11;
|
|
} catch (NoSuchFieldError unused11) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.PERMISSION_DENIED.ordinal()] = 12;
|
|
} catch (NoSuchFieldError unused12) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.FAILED_PRECONDITION.ordinal()] = 13;
|
|
} catch (NoSuchFieldError unused13) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.ABORTED.ordinal()] = 14;
|
|
} catch (NoSuchFieldError unused14) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.OUT_OF_RANGE.ordinal()] = 15;
|
|
} catch (NoSuchFieldError unused15) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.UNIMPLEMENTED.ordinal()] = 16;
|
|
} catch (NoSuchFieldError unused16) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[FirebaseFirestoreException.Code.DATA_LOSS.ordinal()] = 17;
|
|
} catch (NoSuchFieldError unused17) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public static boolean isPermanentError(FirebaseFirestoreException.Code code) {
|
|
switch (AnonymousClass2.$SwitchMap$com$google$firebase$firestore$FirebaseFirestoreException$Code[code.ordinal()]) {
|
|
case 1:
|
|
throw new IllegalArgumentException("Treated status OK as error");
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
case 7:
|
|
case 8:
|
|
return false;
|
|
case 9:
|
|
case 10:
|
|
case 11:
|
|
case 12:
|
|
case 13:
|
|
case 14:
|
|
case 15:
|
|
case 16:
|
|
case 17:
|
|
return true;
|
|
default:
|
|
throw new IllegalArgumentException("Unknown gRPC status code: ".concat(String.valueOf(code)));
|
|
}
|
|
}
|
|
|
|
public static boolean isMissingSslCiphers(Status status) {
|
|
status.getCode();
|
|
Throwable cause = status.getCause();
|
|
if (!(cause instanceof SSLHandshakeException)) {
|
|
return false;
|
|
}
|
|
cause.getMessage().contains("no ciphers available");
|
|
return false;
|
|
}
|
|
|
|
public static boolean isPermanentWriteError(Status status) {
|
|
return isPermanentError(status) && !status.getCode().equals(Status.Code.ABORTED);
|
|
}
|
|
}
|