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

101 lines
3.5 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.android.gms.internal.firebase_ml;
import com.google.android.gms.common.internal.GmsLogger;
import com.google.android.gms.common.internal.Preconditions;
import com.google.firebase.ml.common.FirebaseMLException;
import java.nio.MappedByteBuffer;
import java.util.ArrayList;
import java.util.List;
/* loaded from: classes2.dex */
public final class zzoi {
private static final GmsLogger zzaoz = new GmsLogger("ModelLoader", "");
private final zzov zzaql;
private final zzog zzaqm;
public zzoi(zzov zzovVar, zzog zzogVar) {
Preconditions.checkArgument((zzovVar == null && zzogVar == null) ? false : true, "At least one of RemoteModelLoader or LocalModelLoader must be non-null.");
this.zzaql = zzovVar;
this.zzaqm = zzogVar;
}
public final <T> void zza(zzoj<T> zzojVar) throws FirebaseMLException {
Exception exc;
boolean z;
synchronized (this) {
ArrayList arrayList = new ArrayList();
Exception e = null;
boolean z2 = false;
try {
z = zza(zzojVar, arrayList);
exc = null;
} catch (Exception e2) {
exc = e2;
z = false;
}
if (z) {
return;
}
try {
z2 = zzb(zzojVar, arrayList);
} catch (Exception e3) {
e = e3;
}
if (z2) {
return;
}
arrayList.add(zzmk.NO_VALID_MODEL);
if (exc != null) {
throw new FirebaseMLException("Remote model load failed: ", 14, exc);
}
if (e != null) {
throw new FirebaseMLException("Local model load failed: ", 14, e);
}
throw new FirebaseMLException("Cannot load custom model", 14);
}
}
private final <T> boolean zza(zzoj<T> zzojVar, List<zzmk> list) throws FirebaseMLException {
synchronized (this) {
zzov zzovVar = this.zzaql;
if (zzovVar != null) {
try {
MappedByteBuffer load = zzovVar.load();
if (load != null) {
zzojVar.zzb(load);
this.zzaql.zzlu();
zzaoz.d("ModelLoader", "Remote model source is loaded successfully");
return true;
}
zzaoz.d("ModelLoader", "Remote model source can NOT be loaded, try local model.");
list.add(zzmk.CLOUD_MODEL_LOADER_LOADS_NO_MODEL);
} catch (FirebaseMLException e) {
zzaoz.d("ModelLoader", "Remote model source can NOT be loaded, try local model.");
list.add(zzmk.CLOUD_MODEL_LOADER_ERROR);
throw e;
}
}
return false;
}
}
private final <T> boolean zzb(zzoj<T> zzojVar, List<zzmk> list) throws FirebaseMLException {
MappedByteBuffer load;
synchronized (this) {
zzog zzogVar = this.zzaqm;
if (zzogVar == null || (load = zzogVar.load()) == null) {
return false;
}
try {
zzojVar.zzb(load);
this.zzaqm.zzlu();
zzaoz.d("ModelLoader", "Local model source is loaded successfully");
return true;
} catch (RuntimeException e) {
list.add(zzmk.LOCAL_MODEL_INVALID);
throw e;
}
}
}
}