package x2; import android.app.job.JobInfo; import android.app.job.JobScheduler; import android.content.ComponentName; import android.content.Context; import android.os.PersistableBundle; import android.util.Base64; import com.google.android.datatransport.runtime.scheduling.jobscheduling.JobInfoSchedulerService; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.zip.Adler32; /* loaded from: classes.dex */ public class d implements x { /* renamed from: a, reason: collision with root package name */ private final Context f15291a; /* renamed from: b, reason: collision with root package name */ private final y2.d f15292b; /* renamed from: c, reason: collision with root package name */ private final f f15293c; public d(Context context, y2.d dVar, f fVar) { this.f15291a = context; this.f15292b = dVar; this.f15293c = fVar; } private boolean d(JobScheduler jobScheduler, int i10, int i11) { for (JobInfo jobInfo : jobScheduler.getAllPendingJobs()) { int i12 = jobInfo.getExtras().getInt("attemptNumber"); if (jobInfo.getId() == i10) { return i12 >= i11; } } return false; } @Override // x2.x public void a(q2.o oVar, int i10) { b(oVar, i10, false); } @Override // x2.x public void b(q2.o oVar, int i10, boolean z10) { ComponentName componentName = new ComponentName(this.f15291a, (Class) JobInfoSchedulerService.class); JobScheduler jobScheduler = (JobScheduler) this.f15291a.getSystemService("jobscheduler"); int c10 = c(oVar); if (!z10 && d(jobScheduler, c10, i10)) { u2.a.b("JobInfoScheduler", "Upload for context %s is already scheduled. Returning...", oVar); return; } long x02 = this.f15292b.x0(oVar); JobInfo.Builder c11 = this.f15293c.c(new JobInfo.Builder(c10, componentName), oVar.d(), x02, i10); PersistableBundle persistableBundle = new PersistableBundle(); persistableBundle.putInt("attemptNumber", i10); persistableBundle.putString("backendName", oVar.b()); persistableBundle.putInt("priority", b3.a.a(oVar.d())); if (oVar.c() != null) { persistableBundle.putString("extras", Base64.encodeToString(oVar.c(), 0)); } c11.setExtras(persistableBundle); u2.a.c("JobInfoScheduler", "Scheduling upload for context %s with jobId=%d in %dms(Backend next call timestamp %d). Attempt %d", oVar, Integer.valueOf(c10), Long.valueOf(this.f15293c.g(oVar.d(), x02, i10)), Long.valueOf(x02), Integer.valueOf(i10)); jobScheduler.schedule(c11.build()); } int c(q2.o oVar) { Adler32 adler32 = new Adler32(); adler32.update(this.f15291a.getPackageName().getBytes(Charset.forName("UTF-8"))); adler32.update(oVar.b().getBytes(Charset.forName("UTF-8"))); adler32.update(ByteBuffer.allocate(4).putInt(b3.a.a(oVar.d())).array()); if (oVar.c() != null) { adler32.update(oVar.c()); } return (int) adler32.getValue(); } }