package com.google.android.gms.measurement.internal; import android.content.SharedPreferences; import android.util.Pair; import com.google.android.gms.common.internal.Preconditions; /* loaded from: classes.dex */ public final class zzbh { private final String a; private final String b; private final String c; private final long d; private final /* synthetic */ zzbd e; private zzbh(zzbd zzbdVar, String str, long j) { this.e = zzbdVar; Preconditions.b(str); Preconditions.a(j > 0); this.a = String.valueOf(str).concat(":start"); this.b = String.valueOf(str).concat(":count"); this.c = String.valueOf(str).concat(":value"); this.d = j; } private final void b() { SharedPreferences B; this.e.f(); long a = this.e.d().a(); B = this.e.B(); SharedPreferences.Editor edit = B.edit(); edit.remove(this.b); edit.remove(this.c); edit.putLong(this.a, a); edit.apply(); } private final long c() { SharedPreferences B; B = this.e.B(); return B.getLong(this.a, 0L); } public final void a(String str, long j) { SharedPreferences B; SharedPreferences B2; SharedPreferences B3; this.e.f(); if (c() == 0) { b(); } if (str == null) { str = ""; } B = this.e.B(); long j2 = B.getLong(this.b, 0L); if (j2 <= 0) { B3 = this.e.B(); SharedPreferences.Editor edit = B3.edit(); edit.putString(this.c, str); edit.putLong(this.b, 1L); edit.apply(); return; } long j3 = j2 + 1; boolean z = (this.e.k().u().nextLong() & Long.MAX_VALUE) < Long.MAX_VALUE / j3; B2 = this.e.B(); SharedPreferences.Editor edit2 = B2.edit(); if (z) { edit2.putString(this.c, str); } edit2.putLong(this.b, j3); edit2.apply(); } public final Pair a() { long abs; SharedPreferences B; SharedPreferences B2; this.e.f(); this.e.f(); long c = c(); if (c == 0) { b(); abs = 0; } else { abs = Math.abs(c - this.e.d().a()); } long j = this.d; if (abs < j) { return null; } if (abs > (j << 1)) { b(); return null; } B = this.e.B(); String string = B.getString(this.c, null); B2 = this.e.B(); long j2 = B2.getLong(this.b, 0L); b(); if (string != null && j2 > 0) { return new Pair<>(string, Long.valueOf(j2)); } return zzbd.v; } }