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

302 lines
12 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.android.gms.internal.firebase_ml;
import android.os.SystemClock;
import android.util.SparseArray;
import com.google.android.gms.common.internal.GmsLogger;
import com.google.android.gms.internal.firebase_ml.zzmd;
import com.google.firebase.FirebaseApp;
import com.google.firebase.ml.common.FirebaseMLException;
import com.google.firebase.ml.common.modeldownload.FirebaseLocalModel;
import com.google.firebase.ml.common.modeldownload.FirebaseRemoteModel;
import com.google.firebase.ml.custom.FirebaseModelOutputs;
import java.nio.MappedByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import o.C15516gsl;
import org.tensorflow.lite.TensorFlowLite;
/* loaded from: classes2.dex */
public final class zzpe implements zznm<FirebaseModelOutputs, zzpa>, zznw {
private final FirebaseLocalModel zzaqk;
private final zzov zzaql;
private final zzog zzaqm;
private final zznu zzaqs;
private final FirebaseRemoteModel zzaqt;
private final boolean zzast;
private AtomicLong zzatb = new AtomicLong(0);
private zzpj zzatc = null;
public static final String zzasz = TensorFlowLite.version();
private static final GmsLogger zzaoz = new GmsLogger("ModelInterpreterTask", "");
private static boolean zzata = true;
public zzpe(FirebaseApp firebaseApp, FirebaseLocalModel firebaseLocalModel, FirebaseRemoteModel firebaseRemoteModel, boolean z) {
this.zzaqk = firebaseLocalModel;
this.zzaqt = firebaseRemoteModel;
this.zzast = z;
this.zzaqs = zznu.zza(firebaseApp, 2);
if (firebaseRemoteModel != null) {
this.zzaql = zzov.zza(firebaseApp, firebaseRemoteModel, new zzoz(), new zzpb(firebaseApp.getApplicationContext()), zzok.CUSTOM);
GmsLogger gmsLogger = zzaoz;
String valueOf = String.valueOf(firebaseRemoteModel);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 27);
sb.append("Cloud model source is set: ");
sb.append(valueOf);
gmsLogger.d("ModelInterpreterTask", sb.toString());
} else {
this.zzaql = null;
}
if (firebaseLocalModel == null) {
this.zzaqm = null;
return;
}
this.zzaqm = new zzog(firebaseApp.getApplicationContext(), firebaseLocalModel);
GmsLogger gmsLogger2 = zzaoz;
String valueOf2 = String.valueOf(firebaseLocalModel);
StringBuilder sb2 = new StringBuilder(String.valueOf(valueOf2).length() + 27);
sb2.append("Local model source is set: ");
sb2.append(valueOf2);
gmsLogger2.d("ModelInterpreterTask", sb2.toString());
}
@Override // com.google.android.gms.internal.firebase_ml.zznm
public final zznw zzlm() {
return this;
}
/* JADX INFO: Access modifiers changed from: private */
/* JADX WARN: Removed duplicated region for block: B:96:0x022a */
/* JADX WARN: Removed duplicated region for block: B:99:0x022c */
@Override // com.google.android.gms.internal.firebase_ml.zznm
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final com.google.firebase.ml.custom.FirebaseModelOutputs zza(com.google.android.gms.internal.firebase_ml.zzpa r19) throws com.google.firebase.ml.common.FirebaseMLException {
/*
Method dump skipped, instructions count: 596
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.android.gms.internal.firebase_ml.zzpe.zza(com.google.android.gms.internal.firebase_ml.zzpa):com.google.firebase.ml.custom.FirebaseModelOutputs");
}
@Override // com.google.android.gms.internal.firebase_ml.zznw
public final void zzlp() throws FirebaseMLException {
synchronized (this) {
zza(zzpf.zzatd);
}
}
private final void zza(zzpi zzpiVar) throws FirebaseMLException {
Exception exc;
boolean z;
synchronized (this) {
long elapsedRealtime = SystemClock.elapsedRealtime();
ArrayList arrayList = new ArrayList();
Exception e = null;
boolean z2 = false;
try {
z = zza(elapsedRealtime, zzpiVar, arrayList);
exc = null;
} catch (Exception e2) {
exc = e2;
z = false;
}
if (z) {
zze(arrayList);
return;
}
try {
z2 = zzb(elapsedRealtime, zzpiVar, arrayList);
} catch (Exception e3) {
e = e3;
}
if (z2) {
zze(arrayList);
return;
}
arrayList.add(zzmk.NO_VALID_MODEL);
zze(arrayList);
if (exc != null) {
throw new FirebaseMLException("Cloud 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 boolean zza(long j, zzpi zzpiVar, List<zzmk> list) throws FirebaseMLException {
synchronized (this) {
zzov zzovVar = this.zzaql;
if (zzovVar != null) {
try {
MappedByteBuffer load = zzovVar.load();
if (load != null) {
zzpj zzd = zzpiVar.zzd(load);
this.zzatc = zzd;
zzd.setUseNNAPI(this.zzast);
this.zzatb.set(SystemClock.elapsedRealtime() - j);
zzaoz.d("ModelInterpreterTask", "Cloud model source is loaded successfully");
return true;
}
zzaoz.d("ModelInterpreterTask", "Cloud model source can NOT be loaded, try local model.");
list.add(zzmk.CLOUD_MODEL_LOADER_LOADS_NO_MODEL);
} catch (FirebaseMLException e) {
zzaoz.d("ModelInterpreterTask", "Cloud model source can NOT be loaded, try local model.");
list.add(zzmk.CLOUD_MODEL_LOADER_ERROR);
throw e;
}
}
return false;
}
}
private final boolean zzb(long j, zzpi zzpiVar, List<zzmk> list) throws FirebaseMLException {
MappedByteBuffer load;
synchronized (this) {
zzog zzogVar = this.zzaqm;
if (zzogVar == null || (load = zzogVar.load()) == null) {
return false;
}
try {
zzpj zzd = zzpiVar.zzd(load);
this.zzatc = zzd;
zzd.setUseNNAPI(this.zzast);
this.zzatb.set(SystemClock.elapsedRealtime() - j);
zzaoz.d("ModelInterpreterTask", "Local model source is loaded successfully");
return true;
} catch (RuntimeException e) {
list.add(zzmk.LOCAL_MODEL_INVALID);
throw e;
}
}
}
@Override // com.google.android.gms.internal.firebase_ml.zznw
public final void release() {
synchronized (this) {
zzpj zzpjVar = this.zzatc;
if (zzpjVar != null) {
zzpjVar.close();
this.zzatc = null;
}
zzata = true;
}
}
public final int getInputIndex(String str) throws FirebaseMLException {
int inputIndex;
synchronized (this) {
zzpj zzpjVar = this.zzatc;
if (zzpjVar == null) {
throw new FirebaseMLException("Trying to get input index while model has not been initialized yet, or has been released.", 14);
}
inputIndex = zzpjVar.getInputIndex(str);
}
return inputIndex;
}
public final int getOutputIndex(String str) throws FirebaseMLException {
int outputIndex;
synchronized (this) {
zzpj zzpjVar = this.zzatc;
if (zzpjVar == null) {
throw new FirebaseMLException("Trying to get output index while model has not been initialized yet, or has been released.", 14);
}
outputIndex = zzpjVar.getOutputIndex(str);
}
return outputIndex;
}
private final void zza(final zzmk zzmkVar, final long j, final zzpa zzpaVar, final boolean z) {
this.zzaqs.zza(new zznv(this, j, zzpaVar, zzmkVar, z) { // from class: com.google.android.gms.internal.firebase_ml.zzpg
private final zzpe zzate;
private final long zzatf;
private final zzpa zzatg;
private final zzmk zzath;
private final boolean zzati;
@Override // com.google.android.gms.internal.firebase_ml.zznv
public final zzmd.zzq.zza zzm() {
return this.zzate.zza(this.zzatf, this.zzatg, this.zzath, this.zzati);
}
/* JADX INFO: Access modifiers changed from: package-private */
{
this.zzate = this;
this.zzatf = j;
this.zzatg = zzpaVar;
this.zzath = zzmkVar;
this.zzati = z;
}
}, zzmn.CUSTOM_MODEL_RUN);
}
private final void zze(final List<zzmk> list) {
this.zzaqs.zza(new zznv(this, list) { // from class: com.google.android.gms.internal.firebase_ml.zzph
private final zzpe zzate;
private final List zzatj;
@Override // com.google.android.gms.internal.firebase_ml.zznv
public final zzmd.zzq.zza zzm() {
return this.zzate.zzf(this.zzatj);
}
/* JADX INFO: Access modifiers changed from: package-private */
{
this.zzate = this;
this.zzatj = list;
}
}, zzmn.CUSTOM_MODEL_LOAD);
}
/* JADX INFO: Access modifiers changed from: package-private */
public final /* synthetic */ zzmd.zzq.zza zzf(List list) {
if (list.isEmpty()) {
list.add(zzmk.NO_ERROR);
}
zzmd.zzn.zza zzl = zzmd.zzn.zzjo().zzl(this.zzatb.get()).zzh(list).zzl(this.zzast);
FirebaseRemoteModel firebaseRemoteModel = this.zzaqt;
if (firebaseRemoteModel != null) {
zzl.zzf(firebaseRemoteModel.zzmh());
}
FirebaseLocalModel firebaseLocalModel = this.zzaqk;
if (firebaseLocalModel != null) {
zzl.zzg(firebaseLocalModel.zzmh());
}
return zzmd.zzq.zzjx().zzb(zzmd.zzac.zzli().zzbu(zzasz)).zzb(zzl);
}
/* JADX INFO: Access modifiers changed from: package-private */
public final /* synthetic */ zzmd.zzq.zza zza(long j, zzpa zzpaVar, zzmk zzmkVar, boolean z) {
zzmd.zzo zzmh;
long elapsedRealtime = SystemClock.elapsedRealtime();
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
if (zzpaVar != null) {
SparseArray<zzpc> zzml = zzpaVar.zzasw.zzml();
for (int i = 0; i < zzml.size(); i++) {
arrayList.add(zzml.valueAt(i).zzmu());
}
SparseArray<zzpc> zzmm = zzpaVar.zzasw.zzmm();
for (int i2 = 0; i2 < zzmm.size(); i2++) {
arrayList2.add(zzmm.valueAt(i2).zzmu());
}
}
zzmd.zzm.zza zzb = zzmd.zzm.zzjk().zzb(zzmd.zzs.zzkb().zzn(elapsedRealtime - j).zzc(zzmkVar).zzz(zzata).zzaa(true).zzab(true).zzac(this.zzast));
if (z) {
zzmh = this.zzaqt.zzmh();
} else {
zzmh = this.zzaqk.zzmh();
}
return zzmd.zzq.zzjx().zzb(zzmd.zzac.zzli().zzbu(zzasz)).zzb(zzb.zzc(zzmh).zzc(arrayList).zzd(arrayList2).zzk(this.zzatb.get()));
}
/* JADX INFO: Access modifiers changed from: package-private */
public static final /* synthetic */ zzpj zzc(MappedByteBuffer mappedByteBuffer) {
return new zzpj(new C15516gsl(mappedByteBuffer));
}
}