what-the-bank/sources/com/google/android/gms/internal/gtm/zzbb.java

703 lines
26 KiB
Java

package com.google.android.gms.internal.gtm;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Pair;
import com.google.android.gms.analytics.CampaignTrackingReceiver;
import com.google.android.gms.analytics.zzg;
import com.google.android.gms.analytics.zzk;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.common.wrappers.Wrappers;
import com.huawei.hms.support.feature.result.CommonConstant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class zzbb extends zzan {
private boolean started;
private final zzay zzxp;
private final zzck zzxq;
private final zzcj zzxr;
private final zzat zzxs;
private long zzxt;
private final zzbs zzxu;
private final zzbs zzxv;
private final zzcv zzxw;
private long zzxx;
private boolean zzxy;
/* JADX INFO: Access modifiers changed from: protected */
public zzbb(zzap zzapVar, zzar zzarVar) {
super(zzapVar);
Preconditions.checkNotNull(zzarVar);
this.zzxt = Long.MIN_VALUE;
this.zzxr = new zzcj(zzapVar);
this.zzxp = new zzay(zzapVar);
this.zzxq = new zzck(zzapVar);
this.zzxs = new zzat(zzapVar);
this.zzxw = new zzcv(zzcn());
this.zzxu = new zzbc(this, zzapVar);
this.zzxv = new zzbd(this, zzapVar);
}
@Override // com.google.android.gms.internal.gtm.zzan
protected final void zzaw() {
this.zzxp.zzag();
this.zzxq.zzag();
this.zzxs.zzag();
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void start() {
zzdb();
Preconditions.checkState(!this.started, "Analytics backend already started");
this.started = true;
zzcq().zza(new zzbe(this));
}
private final boolean zzx(String str) {
return Wrappers.packageManager(getContext()).checkCallingOrSelfPermission(str) == 0;
}
/* JADX INFO: Access modifiers changed from: protected */
public final void zzdw() {
zzdb();
zzk.zzav();
Context context = zzcm().getContext();
if (!zzcp.zza(context)) {
zzt("AnalyticsReceiver is not registered or is disabled. Register the receiver for reliable dispatching on non-Google Play devices. See http://goo.gl/8Rd3yj for instructions.");
} else if (!zzcq.zze(context)) {
zzu("AnalyticsService is not registered or is disabled. Analytics service at risk of not starting. See http://goo.gl/8Rd3yj for instructions.");
}
if (!CampaignTrackingReceiver.zza(context)) {
zzt("CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See http://goo.gl/8Rd3yj for instructions.");
}
zzcv().zzfv();
if (!zzx("android.permission.ACCESS_NETWORK_STATE")) {
zzu("Missing required android.permission.ACCESS_NETWORK_STATE. Google Analytics disabled. See http://goo.gl/8Rd3yj for instructions");
zzeg();
}
if (!zzx("android.permission.INTERNET")) {
zzu("Missing required android.permission.INTERNET. Google Analytics disabled. See http://goo.gl/8Rd3yj for instructions");
zzeg();
}
if (zzcq.zze(getContext())) {
zzq("AnalyticsService registered in the app manifest and enabled");
} else {
zzt("AnalyticsService not registered in the app manifest. Hits might not be delivered reliably. See http://goo.gl/8Rd3yj for instructions.");
}
if (!this.zzxy && !this.zzxp.isEmpty()) {
zzdz();
}
zzec();
}
/* JADX INFO: Access modifiers changed from: private */
public final void zzdx() {
zzb((zzbw) new zzbf(this));
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void zzcl() {
zzk.zzav();
this.zzxx = zzcn().currentTimeMillis();
}
/* JADX INFO: Access modifiers changed from: protected */
public final void onServiceConnected() {
zzk.zzav();
zzk.zzav();
zzdb();
if (!zzbq.zzen()) {
zzt("Service client disabled. Can't dispatch local hits to device AnalyticsService");
}
if (!this.zzxs.isConnected()) {
zzq("Service not connected");
return;
}
if (this.zzxp.isEmpty()) {
return;
}
zzq("Dispatching local hits to device AnalyticsService");
while (true) {
try {
List<zzcd> zzd = this.zzxp.zzd(zzbq.zzer());
if (zzd.isEmpty()) {
zzec();
return;
}
while (!zzd.isEmpty()) {
zzcd zzcdVar = zzd.get(0);
if (!this.zzxs.zzb(zzcdVar)) {
zzec();
return;
}
zzd.remove(zzcdVar);
try {
this.zzxp.zze(zzcdVar.zzfg());
} catch (SQLiteException e) {
zze("Failed to remove hit that was send for delivery", e);
zzee();
return;
}
}
} catch (SQLiteException e2) {
zze("Failed to read hits from store", e2);
zzee();
return;
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public final void zzdy() {
try {
this.zzxp.zzdr();
zzec();
} catch (SQLiteException e) {
zzd("Failed to delete stale hits", e);
}
this.zzxv.zzh(86400000L);
}
/* JADX INFO: Access modifiers changed from: protected */
public final void zzb(zzas zzasVar) {
zzk.zzav();
zzb("Sending first hit to property", zzasVar.zzdj());
if (zzcv().zzfw().zzj(zzbq.zzex())) {
return;
}
String zzfz = zzcv().zzfz();
if (TextUtils.isEmpty(zzfz)) {
return;
}
zzr zza = zzcz.zza(zzco(), zzfz);
zzb("Found relevant installation campaign", zza);
zza(zzasVar, zza);
}
public final void zzg(long j) {
zzk.zzav();
zzdb();
if (j < 0) {
j = 0;
}
this.zzxt = j;
zzec();
}
private final void zzdz() {
if (this.zzxy || !zzbq.zzen() || this.zzxs.isConnected()) {
return;
}
if (this.zzxw.zzj(zzby.zzaan.get().longValue())) {
this.zzxw.start();
zzq("Connecting to service");
if (this.zzxs.connect()) {
zzq("Connected to service");
this.zzxw.clear();
onServiceConnected();
}
}
}
public final long zza(zzas zzasVar, boolean z) {
Preconditions.checkNotNull(zzasVar);
zzdb();
zzk.zzav();
try {
try {
this.zzxp.beginTransaction();
zzay zzayVar = this.zzxp;
long zzdi = zzasVar.zzdi();
String zzbt = zzasVar.zzbt();
Preconditions.checkNotEmpty(zzbt);
zzayVar.zzdb();
zzk.zzav();
int delete = zzayVar.getWritableDatabase().delete("properties", "app_uid=? AND cid<>?", new String[]{String.valueOf(zzdi), zzbt});
if (delete > 0) {
zzayVar.zza("Deleted property records", Integer.valueOf(delete));
}
long zza = this.zzxp.zza(zzasVar.zzdi(), zzasVar.zzbt(), zzasVar.zzdj());
zzasVar.zzb(1 + zza);
zzay zzayVar2 = this.zzxp;
Preconditions.checkNotNull(zzasVar);
zzayVar2.zzdb();
zzk.zzav();
SQLiteDatabase writableDatabase = zzayVar2.getWritableDatabase();
Map<String, String> zzdm = zzasVar.zzdm();
Preconditions.checkNotNull(zzdm);
Uri.Builder builder = new Uri.Builder();
for (Map.Entry<String, String> entry : zzdm.entrySet()) {
builder.appendQueryParameter(entry.getKey(), entry.getValue());
}
String encodedQuery = builder.build().getEncodedQuery();
if (encodedQuery == null) {
encodedQuery = "";
}
ContentValues contentValues = new ContentValues();
contentValues.put("app_uid", Long.valueOf(zzasVar.zzdi()));
contentValues.put("cid", zzasVar.zzbt());
contentValues.put("tid", zzasVar.zzdj());
contentValues.put("adid", Integer.valueOf(zzasVar.zzdk() ? 1 : 0));
contentValues.put("hits_count", Long.valueOf(zzasVar.zzdl()));
contentValues.put("params", encodedQuery);
try {
if (writableDatabase.insertWithOnConflict("properties", null, contentValues, 5) == -1) {
zzayVar2.zzu("Failed to insert/update a property (got -1)");
}
} catch (SQLiteException e) {
zzayVar2.zze("Error storing a property", e);
}
this.zzxp.setTransactionSuccessful();
try {
this.zzxp.endTransaction();
} catch (SQLiteException e2) {
zze("Failed to end transaction", e2);
}
return zza;
} catch (SQLiteException e3) {
zze("Failed to update Analytics property", e3);
try {
this.zzxp.endTransaction();
} catch (SQLiteException e4) {
zze("Failed to end transaction", e4);
}
return -1L;
}
} catch (Throwable th) {
try {
this.zzxp.endTransaction();
} catch (SQLiteException e5) {
zze("Failed to end transaction", e5);
}
throw th;
}
}
public final void zza(zzcd zzcdVar) {
Pair<String, Long> zzgc;
Preconditions.checkNotNull(zzcdVar);
zzk.zzav();
zzdb();
if (this.zzxy) {
zzr("Hit delivery not possible. Missing network permissions. See http://goo.gl/8Rd3yj for instructions");
} else {
zza("Delivering hit", zzcdVar);
}
if (TextUtils.isEmpty(zzcdVar.zzfl()) && (zzgc = zzcv().zzga().zzgc()) != null) {
Long l = (Long) zzgc.second;
String str = (String) zzgc.first;
String valueOf = String.valueOf(l);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 1 + String.valueOf(str).length());
sb.append(valueOf);
sb.append(":");
sb.append(str);
String sb2 = sb.toString();
HashMap hashMap = new HashMap(zzcdVar.zzdm());
hashMap.put("_m", sb2);
zzcdVar = new zzcd(this, hashMap, zzcdVar.zzfh(), zzcdVar.zzfj(), zzcdVar.zzfg(), zzcdVar.zzff(), zzcdVar.zzfi());
}
zzdz();
if (this.zzxs.zzb(zzcdVar)) {
zzr("Hit sent to the device AnalyticsService for delivery");
return;
}
try {
this.zzxp.zzc(zzcdVar);
zzec();
} catch (SQLiteException e) {
zze("Delivery failed to save hit to a database", e);
zzco().zza(zzcdVar, "deliver: failed to insert hit to database");
}
}
public final void zzch() {
zzk.zzav();
zzdb();
zzq("Delete all hits from local store");
try {
zzay zzayVar = this.zzxp;
zzk.zzav();
zzayVar.zzdb();
zzayVar.getWritableDatabase().delete("hits2", null, null);
zzay zzayVar2 = this.zzxp;
zzk.zzav();
zzayVar2.zzdb();
zzayVar2.getWritableDatabase().delete("properties", null, null);
zzec();
} catch (SQLiteException e) {
zzd("Failed to delete hits from store", e);
}
zzdz();
if (this.zzxs.zzdn()) {
zzq("Device service unavailable. Can't clear hits stored on the device service.");
}
}
private final boolean zzea() {
zzk.zzav();
zzdb();
zzq("Dispatching a batch of local hits");
boolean isConnected = this.zzxs.isConnected();
boolean zzfr = this.zzxq.zzfr();
if ((!isConnected) && (!zzfr)) {
zzq("No network or service available. Will retry later");
return false;
}
long max = Math.max(zzbq.zzer(), zzbq.zzes());
ArrayList arrayList = new ArrayList();
long j = 0;
while (true) {
try {
try {
this.zzxp.beginTransaction();
arrayList.clear();
try {
List<zzcd> zzd = this.zzxp.zzd(max);
if (zzd.isEmpty()) {
zzq("Store is empty, nothing to dispatch");
zzee();
try {
this.zzxp.setTransactionSuccessful();
this.zzxp.endTransaction();
return false;
} catch (SQLiteException e) {
zze("Failed to commit local dispatch transaction", e);
zzee();
return false;
}
}
zza("Hits loaded from store. count", Integer.valueOf(zzd.size()));
Iterator<zzcd> it = zzd.iterator();
while (it.hasNext()) {
if (it.next().zzfg() == j) {
zzd("Database contains successfully uploaded hit", Long.valueOf(j), Integer.valueOf(zzd.size()));
zzee();
try {
this.zzxp.setTransactionSuccessful();
this.zzxp.endTransaction();
return false;
} catch (SQLiteException e2) {
zze("Failed to commit local dispatch transaction", e2);
zzee();
return false;
}
}
}
if (this.zzxs.isConnected()) {
zzq("Service connected, sending hits to the service");
while (!zzd.isEmpty()) {
zzcd zzcdVar = zzd.get(0);
if (!this.zzxs.zzb(zzcdVar)) {
break;
}
j = Math.max(j, zzcdVar.zzfg());
zzd.remove(zzcdVar);
zzb("Hit sent do device AnalyticsService for delivery", zzcdVar);
try {
this.zzxp.zze(zzcdVar.zzfg());
arrayList.add(Long.valueOf(zzcdVar.zzfg()));
} catch (SQLiteException e3) {
zze("Failed to remove hit that was send for delivery", e3);
zzee();
try {
this.zzxp.setTransactionSuccessful();
this.zzxp.endTransaction();
return false;
} catch (SQLiteException e4) {
zze("Failed to commit local dispatch transaction", e4);
zzee();
return false;
}
}
}
}
if (this.zzxq.zzfr()) {
List<Long> zzb = this.zzxq.zzb(zzd);
Iterator<Long> it2 = zzb.iterator();
while (it2.hasNext()) {
j = Math.max(j, it2.next().longValue());
}
try {
this.zzxp.zza(zzb);
arrayList.addAll(zzb);
} catch (SQLiteException e5) {
zze("Failed to remove successfully uploaded hits", e5);
zzee();
try {
this.zzxp.setTransactionSuccessful();
this.zzxp.endTransaction();
return false;
} catch (SQLiteException e6) {
zze("Failed to commit local dispatch transaction", e6);
zzee();
return false;
}
}
}
if (arrayList.isEmpty()) {
try {
this.zzxp.setTransactionSuccessful();
this.zzxp.endTransaction();
return false;
} catch (SQLiteException e7) {
zze("Failed to commit local dispatch transaction", e7);
zzee();
return false;
}
}
try {
this.zzxp.setTransactionSuccessful();
this.zzxp.endTransaction();
} catch (SQLiteException e8) {
zze("Failed to commit local dispatch transaction", e8);
zzee();
return false;
}
} catch (SQLiteException e9) {
zzd("Failed to read hits from persisted store", e9);
zzee();
try {
this.zzxp.setTransactionSuccessful();
this.zzxp.endTransaction();
return false;
} catch (SQLiteException e10) {
zze("Failed to commit local dispatch transaction", e10);
zzee();
return false;
}
}
} catch (Throwable th) {
this.zzxp.setTransactionSuccessful();
this.zzxp.endTransaction();
throw th;
}
this.zzxp.setTransactionSuccessful();
this.zzxp.endTransaction();
throw th;
} catch (SQLiteException e11) {
zze("Failed to commit local dispatch transaction", e11);
zzee();
return false;
}
}
}
public final void zzb(zzbw zzbwVar) {
long j = this.zzxx;
zzk.zzav();
zzdb();
long zzfx = zzcv().zzfx();
zzb("Dispatching local hits. Elapsed time since last dispatch (ms)", Long.valueOf(zzfx != 0 ? Math.abs(zzcn().currentTimeMillis() - zzfx) : -1L));
zzdz();
try {
zzea();
zzcv().zzfy();
zzec();
if (zzbwVar != null) {
zzbwVar.zza(null);
}
if (this.zzxx != j) {
this.zzxr.zzfq();
}
} catch (Exception e) {
zze("Local dispatch failed", e);
zzcv().zzfy();
zzec();
if (zzbwVar != null) {
zzbwVar.zza(e);
}
}
}
public final void zzeb() {
zzk.zzav();
zzdb();
zzr("Sync dispatching local hits");
long j = this.zzxx;
zzdz();
try {
zzea();
zzcv().zzfy();
zzec();
if (this.zzxx != j) {
this.zzxr.zzfq();
}
} catch (Exception e) {
zze("Sync local dispatch failed", e);
zzec();
}
}
private final long zzds() {
zzk.zzav();
zzdb();
try {
return this.zzxp.zzds();
} catch (SQLiteException e) {
zze("Failed to get min/max hit times from local store", e);
return 0L;
}
}
public final void zzec() {
long min;
zzk.zzav();
zzdb();
if (this.zzxy || zzef() <= 0) {
this.zzxr.unregister();
zzee();
return;
}
if (this.zzxp.isEmpty()) {
this.zzxr.unregister();
zzee();
return;
}
if (!zzby.zzaai.get().booleanValue()) {
this.zzxr.zzfo();
if (!this.zzxr.isConnected()) {
zzee();
zzed();
return;
}
}
zzed();
long zzef = zzef();
long zzfx = zzcv().zzfx();
if (zzfx != 0) {
min = zzef - Math.abs(zzcn().currentTimeMillis() - zzfx);
if (min <= 0) {
min = Math.min(zzbq.zzep(), zzef);
}
} else {
min = Math.min(zzbq.zzep(), zzef);
}
zza("Dispatch scheduled (ms)", Long.valueOf(min));
if (this.zzxu.zzez()) {
this.zzxu.zzi(Math.max(1L, min + this.zzxu.zzey()));
} else {
this.zzxu.zzh(min);
}
}
private final void zzed() {
zzbv zzct = zzct();
if (zzct.zzfc() && !zzct.zzez()) {
long zzds = zzds();
if (zzds == 0 || Math.abs(zzcn().currentTimeMillis() - zzds) > zzby.zzzm.get().longValue()) {
return;
}
zza("Dispatch alarm scheduled (ms)", Long.valueOf(zzbq.zzeq()));
zzct.zzfd();
}
}
private final void zzee() {
if (this.zzxu.zzez()) {
zzq("All hits dispatched or no network/service. Going to power save mode");
}
this.zzxu.cancel();
zzbv zzct = zzct();
if (zzct.zzez()) {
zzct.cancel();
}
}
private final long zzef() {
long j = this.zzxt;
if (j != Long.MIN_VALUE) {
return j;
}
long longValue = zzby.zzzh.get().longValue();
zzda zzcu = zzcu();
zzcu.zzdb();
if (!zzcu.zzacv) {
return longValue;
}
zzcu().zzdb();
return r0.zzaax * 1000;
}
public final void zzy(String str) {
Preconditions.checkNotEmpty(str);
zzk.zzav();
zzr zza = zzcz.zza(zzco(), str);
if (zza == null) {
zzd("Parsing failed. Ignoring invalid campaign data", str);
return;
}
String zzfz = zzcv().zzfz();
if (str.equals(zzfz)) {
zzt("Ignoring duplicate install campaign");
return;
}
if (!TextUtils.isEmpty(zzfz)) {
zzd("Ignoring multiple install campaigns. original, new", zzfz, str);
return;
}
zzcv().zzad(str);
if (zzcv().zzfw().zzj(zzbq.zzex())) {
zzd("Campaign received too late, ignoring", zza);
return;
}
zzb("Received installation campaign", zza);
Iterator<zzas> it = this.zzxp.zzf(0L).iterator();
while (it.hasNext()) {
zza(it.next(), zza);
}
}
private final void zza(zzas zzasVar, zzr zzrVar) {
Preconditions.checkNotNull(zzasVar);
Preconditions.checkNotNull(zzrVar);
com.google.android.gms.analytics.zza zzaVar = new com.google.android.gms.analytics.zza(zzcm());
zzaVar.zza(zzasVar.zzdj());
zzaVar.enableAdvertisingIdCollection(zzasVar.zzdk());
zzg zzac = zzaVar.zzac();
zzz zzzVar = (zzz) zzac.zzb(zzz.class);
zzzVar.zzl("data");
zzzVar.zzb(true);
zzac.zza(zzrVar);
zzu zzuVar = (zzu) zzac.zzb(zzu.class);
zzq zzqVar = (zzq) zzac.zzb(zzq.class);
for (Map.Entry<String, String> entry : zzasVar.zzdm().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if ("an".equals(key)) {
zzqVar.setAppName(value);
} else if ("av".equals(key)) {
zzqVar.setAppVersion(value);
} else if ("aid".equals(key)) {
zzqVar.setAppId(value);
} else if ("aiid".equals(key)) {
zzqVar.setAppInstallerId(value);
} else if (CommonConstant.KEY_UID.equals(key)) {
zzzVar.setUserId(value);
} else {
zzuVar.set(key, value);
}
}
zzb("Sending installation campaign to", zzasVar.zzdj(), zzrVar);
zzac.zza(zzcv().zzfv());
zzac.zzam();
}
private final void zzeg() {
zzdb();
zzk.zzav();
this.zzxy = true;
this.zzxs.disconnect();
zzec();
}
}