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

288 lines
12 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.android.gms.internal.firebase_ml;
import android.app.DownloadManager;
import android.content.Context;
import android.net.Uri;
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.FirebaseModelDownloadConditions;
import com.google.firebase.ml.common.modeldownload.FirebaseRemoteModel;
import java.io.FileNotFoundException;
/* loaded from: classes2.dex */
public final class zzoo {
private static final GmsLogger zzaoz = new GmsLogger("ModelDownloadManager", "");
private final Context zzad;
private final FirebaseApp zzapo;
private final DownloadManager zzaqu;
private final FirebaseRemoteModel zzaqv;
private final zzon zzaqw;
private final zzoq zzaqx;
/* JADX INFO: Access modifiers changed from: package-private */
public zzoo(FirebaseApp firebaseApp, zzoq zzoqVar, FirebaseRemoteModel firebaseRemoteModel, zzon zzonVar) {
this.zzapo = firebaseApp;
this.zzaqx = zzoqVar;
Context applicationContext = firebaseApp.getApplicationContext();
this.zzad = applicationContext;
this.zzaqv = firebaseRemoteModel;
DownloadManager downloadManager = (DownloadManager) applicationContext.getSystemService("download");
this.zzaqu = downloadManager;
if (downloadManager == null) {
zzaoz.d("ModelDownloadManager", "Download manager service is not available in the service.");
}
this.zzaqw = zzonVar;
}
/* JADX INFO: Access modifiers changed from: package-private */
public final Long zzlv() throws FirebaseMLException {
synchronized (this) {
zzop zzmc = zzmc();
if (zzmc == null) {
GmsLogger gmsLogger = zzaoz;
String valueOf = String.valueOf(this.zzaqv.zzmj());
gmsLogger.d("ModelDownloadManager", valueOf.length() != 0 ? "No model updates for model: ".concat(valueOf) : new String("No model updates for model: "));
return null;
}
return zza(zzmc);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public final Long zzlw() {
Long zza;
synchronized (this) {
zza = zzoa.zza(this.zzapo, this.zzaqv.zzmj());
}
return zza;
}
/* JADX INFO: Access modifiers changed from: package-private */
public final String zzlx() {
String zzc;
synchronized (this) {
zzc = zzoa.zzc(this.zzapo, this.zzaqv.zzmj());
}
return zzc;
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void zzly() throws FirebaseMLException {
synchronized (this) {
Long zzlw = zzlw();
if (this.zzaqu != null && zzlw != null) {
GmsLogger gmsLogger = zzaoz;
String valueOf = String.valueOf(zzlw);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 44);
sb.append("Cancel or remove existing downloading task: ");
sb.append(valueOf);
gmsLogger.d("ModelDownloadManager", sb.toString());
if (this.zzaqu.remove(zzlw.longValue()) > 0 || zzlz() == null) {
this.zzaqx.zzmg();
zzoa.zzh(this.zzapo, this.zzaqv.zzmj());
}
}
}
}
private final Long zza(DownloadManager.Request request, zzop zzopVar) {
synchronized (this) {
DownloadManager downloadManager = this.zzaqu;
if (downloadManager == null) {
return null;
}
long enqueue = downloadManager.enqueue(request);
GmsLogger gmsLogger = zzaoz;
StringBuilder sb = new StringBuilder(53);
sb.append("Schedule a new downloading task: ");
sb.append(enqueue);
gmsLogger.d("ModelDownloadManager", sb.toString());
zzoa.zza(this.zzapo, enqueue, zzopVar);
return Long.valueOf(enqueue);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: Code restructure failed: missing block: B:26:0x0062, code lost:
if (r0.intValue() != 16) goto L30;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final java.lang.Integer zzlz() {
/*
r8 = this;
monitor-enter(r8)
java.lang.Long r0 = r8.zzlw() // Catch: java.lang.Throwable -> L6a
android.app.DownloadManager r1 = r8.zzaqu // Catch: java.lang.Throwable -> L6a
r2 = 0
if (r1 == 0) goto L68
if (r0 != 0) goto Ld
goto L68
Ld:
android.app.DownloadManager$Query r3 = new android.app.DownloadManager$Query // Catch: java.lang.Throwable -> L6a
r3.<init>() // Catch: java.lang.Throwable -> L6a
r4 = 1
long[] r5 = new long[r4] // Catch: java.lang.Throwable -> L6a
long r6 = r0.longValue() // Catch: java.lang.Throwable -> L6a
r0 = 0
r5[r0] = r6 // Catch: java.lang.Throwable -> L6a
android.app.DownloadManager$Query r0 = r3.setFilterById(r5) // Catch: java.lang.Throwable -> L6a
android.database.Cursor r0 = r1.query(r0) // Catch: java.lang.Throwable -> L6a
if (r0 == 0) goto L3b
boolean r1 = r0.moveToFirst() // Catch: java.lang.Throwable -> L6a
if (r1 == 0) goto L3b
java.lang.String r1 = "status"
int r1 = r0.getColumnIndex(r1) // Catch: java.lang.Throwable -> L6a
int r0 = r0.getInt(r1) // Catch: java.lang.Throwable -> L6a
java.lang.Integer r0 = java.lang.Integer.valueOf(r0) // Catch: java.lang.Throwable -> L6a
goto L3c
L3b:
r0 = r2
L3c:
if (r0 != 0) goto L40
monitor-exit(r8)
return r2
L40:
int r1 = r0.intValue() // Catch: java.lang.Throwable -> L6a
r3 = 2
if (r1 == r3) goto L65
int r1 = r0.intValue() // Catch: java.lang.Throwable -> L6a
r3 = 4
if (r1 == r3) goto L65
int r1 = r0.intValue() // Catch: java.lang.Throwable -> L6a
if (r1 == r4) goto L65
int r1 = r0.intValue() // Catch: java.lang.Throwable -> L6a
r3 = 8
if (r1 == r3) goto L65
int r1 = r0.intValue() // Catch: java.lang.Throwable -> L6a
r3 = 16
if (r1 == r3) goto L65
goto L66
L65:
r2 = r0
L66:
monitor-exit(r8)
return r2
L68:
monitor-exit(r8)
return r2
L6a:
r0 = move-exception
monitor-exit(r8)
throw r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.android.gms.internal.firebase_ml.zzoo.zzlz():java.lang.Integer");
}
/* JADX INFO: Access modifiers changed from: package-private */
public final ParcelFileDescriptor zzma() {
synchronized (this) {
Long zzlw = zzlw();
DownloadManager downloadManager = this.zzaqu;
ParcelFileDescriptor parcelFileDescriptor = null;
if (downloadManager == null || zzlw == null) {
return null;
}
try {
parcelFileDescriptor = downloadManager.openDownloadedFile(zzlw.longValue());
} catch (FileNotFoundException unused) {
zzaoz.e("ModelDownloadManager", "Downloaded file is not found");
}
return parcelFileDescriptor;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void zzby(String str) throws FirebaseMLException {
synchronized (this) {
zzoa.zza(this.zzapo, this.zzaqv.zzmj(), str);
zzly();
}
}
private final boolean zzmb() throws FirebaseMLException {
String zzmf;
synchronized (this) {
zzmf = this.zzaqx.zzmf();
}
return zzmf != null;
}
private final zzop zzmc() throws FirebaseMLException {
String str;
boolean z;
String str2;
synchronized (this) {
String zzmj = this.zzaqv.zzmj();
zzop zzb = zzou.zzb(this.zzapo, this.zzaqv, this.zzaqw);
if (zzb == null) {
return null;
}
FirebaseApp firebaseApp = this.zzapo;
str = zzb.zzaqz;
if (str.equals(zzoa.zze(firebaseApp, zzmj)) && zznk.zza(firebaseApp.getApplicationContext()).equals(zzoa.zze(firebaseApp))) {
zzaoz.d("ModelDownloadManager", "The new model is incompatible and the app is not upgraded, do not download");
z = false;
} else {
z = true;
}
boolean z2 = !zzmb();
if (z2) {
zzoa.zzi(this.zzapo, zzmj);
}
FirebaseApp firebaseApp2 = this.zzapo;
str2 = zzb.zzaqz;
boolean equals = str2.equals(zzoa.zzd(firebaseApp2, zzmj));
if (z && (z2 || (!equals))) {
return zzb;
}
return null;
}
}
private final Long zza(zzop zzopVar) throws FirebaseMLException {
String str;
Uri uri;
String str2;
synchronized (this) {
FirebaseApp firebaseApp = this.zzapo;
str = zzopVar.zzaqg;
String zzc = zzoa.zzc(firebaseApp, str);
if (zzc != null) {
str2 = zzopVar.zzaqz;
if (zzc.equals(str2)) {
zzaoz.d("ModelDownloadManager", "New model is already in downloading, do nothing.");
return null;
}
}
GmsLogger gmsLogger = zzaoz;
gmsLogger.d("ModelDownloadManager", "Need to download a new model.");
zzly();
uri = zzopVar.zzaqy;
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDestinationUri(null);
FirebaseModelDownloadConditions initialDownloadConditions = this.zzaqv.getInitialDownloadConditions();
if (!this.zzaqv.isModelUpdatesEnabled() && this.zzaqx.zzmf() != null) {
gmsLogger.d("ModelDownloadManager", "Model update is disabled and have a previous downloaded model, skip downloading");
return null;
}
if (this.zzaqv.isModelUpdatesEnabled() && this.zzaqx.zzmf() != null) {
gmsLogger.d("ModelDownloadManager", "Model update is enabled and have a previous downloaded model, use download condition");
initialDownloadConditions = this.zzaqv.getUpdatesDownloadConditions();
}
gmsLogger.d("ModelDownloadManager", "Use initial download conditions.");
request.setRequiresCharging(initialDownloadConditions.isChargingRequired());
request.setRequiresDeviceIdle(initialDownloadConditions.isDeviceIdleRequired());
if (initialDownloadConditions.isWifiRequired()) {
request.setAllowedNetworkTypes(2);
}
return zza(request, zzopVar);
}
}
}