what-the-bank/sources/com/google/android/gms/internal/firebase_ml/zzov.java

129 lines
5.0 KiB
Java

package com.google.android.gms.internal.firebase_ml;
import android.os.ParcelFileDescriptor;
import com.google.android.gms.common.internal.GmsLogger;
import com.google.firebase.FirebaseApp;
import com.google.firebase.ml.common.FirebaseMLException;
import com.google.firebase.ml.common.modeldownload.FirebaseRemoteModel;
import java.io.File;
import java.nio.MappedByteBuffer;
import java.util.HashMap;
import java.util.Map;
/* loaded from: classes2.dex */
public final class zzov {
private static final GmsLogger zzaoz = new GmsLogger("RemoteModelLoader", "");
private static Map<String, zzov> zzarj = new HashMap();
private final zzon zzaqw;
private final zzok zzara;
private final zzoo zzark;
private final zzoq zzarl;
private final zzow zzarm;
private boolean zzarn;
private zzov(FirebaseApp firebaseApp, FirebaseRemoteModel firebaseRemoteModel, zzol zzolVar, zzow zzowVar, zzok zzokVar) {
zzoq zzoqVar = new zzoq(firebaseApp, firebaseRemoteModel.zzmj(), zzolVar, zzokVar);
this.zzarl = zzoqVar;
this.zzarn = true;
zzon zzonVar = new zzon(firebaseApp, firebaseRemoteModel);
this.zzaqw = zzonVar;
this.zzark = new zzoo(firebaseApp, zzoqVar, firebaseRemoteModel, zzonVar);
this.zzarm = zzowVar;
this.zzara = zzokVar;
}
public static zzov zza(FirebaseApp firebaseApp, FirebaseRemoteModel firebaseRemoteModel, zzol zzolVar, zzow zzowVar, zzok zzokVar) {
zzov zzovVar;
synchronized (zzov.class) {
String zzmj = firebaseRemoteModel.zzmj();
if (!zzarj.containsKey(zzmj)) {
zzarj.put(zzmj, new zzov(firebaseApp, firebaseRemoteModel, zzolVar, zzowVar, zzokVar));
}
zzovVar = zzarj.get(zzmj);
}
return zzovVar;
}
public final MappedByteBuffer load() throws FirebaseMLException {
MappedByteBuffer zzad;
synchronized (this) {
GmsLogger gmsLogger = zzaoz;
gmsLogger.d("RemoteModelLoader", "Try to load newly downloaded model file.");
zzad = zzad(this.zzarn);
if (zzad == null) {
gmsLogger.d("RemoteModelLoader", "Loading existing model file.");
String zzmf = this.zzarl.zzmf();
if (zzmf == null) {
gmsLogger.d("RemoteModelLoader", "No existing model file");
zzad = null;
} else {
zzad = zzbz(zzmf);
}
}
if (this.zzarn) {
this.zzarn = false;
gmsLogger.d("RemoteModelLoader", "Initial loading, check for model updates.");
this.zzark.zzlv();
}
}
return zzad;
}
private final MappedByteBuffer zzad(boolean z) throws FirebaseMLException {
zzoo zzooVar;
Long zzlw = this.zzark.zzlw();
String zzlx = this.zzark.zzlx();
if (zzlw == null || zzlx == null) {
zzaoz.d("RemoteModelLoader", "No new model is downloading.");
return null;
}
Integer zzlz = this.zzark.zzlz();
if (zzlz == null) {
return null;
}
GmsLogger gmsLogger = zzaoz;
String valueOf = String.valueOf(zzlz);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 22);
sb.append("Download Status code: ");
sb.append(valueOf);
gmsLogger.d("RemoteModelLoader", sb.toString());
if (zzlz.intValue() == 8) {
gmsLogger.d("RemoteModelLoader", "Model downloaded successfully");
this.zzaqw.zza(zzmk.NO_ERROR, true);
ParcelFileDescriptor zzma = this.zzark.zzma();
if (zzma == null) {
return null;
}
gmsLogger.d("RemoteModelLoader", "moving downloaded model from external storage to private folder.");
try {
File zza = this.zzarl.zza(zzma, zzlx, this.zzaqw);
if (zza == null) {
return null;
}
String valueOf2 = String.valueOf(zza.getParent());
gmsLogger.d("RemoteModelLoader", valueOf2.length() != 0 ? "Moved the downloaded model to private folder successfully: ".concat(valueOf2) : new String("Moved the downloaded model to private folder successfully: "));
this.zzark.zzby(zzlx);
if (z && this.zzarl.zzb(zza)) {
gmsLogger.d("RemoteModelLoader", "All old models are deleted.");
zza = this.zzarl.zzc(zza);
}
return zzbz(zza.getAbsolutePath());
} finally {
this.zzark.zzly();
}
}
if (zzlz.intValue() == 16) {
this.zzaqw.zza(zzmk.DOWNLOAD_FAILED, true);
}
return null;
}
public final void zzlu() throws FirebaseMLException {
this.zzarm.zzlu();
}
private final MappedByteBuffer zzbz(String str) throws FirebaseMLException {
return this.zzarm.zzca(str);
}
}