package com.google.firebase.messaging; import android.os.Build; import android.os.Bundle; import android.text.TextUtils; import android.util.Base64; import android.util.Log; import com.google.android.gms.cloudmessaging.Rpc; import com.google.android.gms.tasks.Continuation; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Tasks; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.concurrent.ExecutionException; import m4.j; /* loaded from: classes2.dex */ class b0 { /* renamed from: a, reason: collision with root package name */ private final w3.f f5536a; /* renamed from: b, reason: collision with root package name */ private final g0 f5537b; /* renamed from: c, reason: collision with root package name */ private final Rpc f5538c; /* renamed from: d, reason: collision with root package name */ private final o4.b f5539d; /* renamed from: e, reason: collision with root package name */ private final o4.b f5540e; /* renamed from: f, reason: collision with root package name */ private final p4.e f5541f; b0(w3.f fVar, g0 g0Var, o4.b bVar, o4.b bVar2, p4.e eVar) { this(fVar, g0Var, new Rpc(fVar.k()), bVar, bVar2, eVar); } private static String b(byte[] bArr) { return Base64.encodeToString(bArr, 11); } private Task c(Task task) { return task.continueWith(new g(), new Continuation() { // from class: com.google.firebase.messaging.a0 @Override // com.google.android.gms.tasks.Continuation public final Object then(Task task2) { String h10; h10 = b0.this.h(task2); return h10; } }); } private String d() { try { return b(MessageDigest.getInstance("SHA-1").digest(this.f5536a.n().getBytes())); } catch (NoSuchAlgorithmException unused) { return "[HASH-ERROR]"; } } private String f(Bundle bundle) { if (bundle == null) { throw new IOException("SERVICE_NOT_AVAILABLE"); } String string = bundle.getString("registration_id"); if (string != null) { return string; } String string2 = bundle.getString("unregistered"); if (string2 != null) { return string2; } String string3 = bundle.getString("error"); if ("RST".equals(string3)) { throw new IOException("INSTANCE_ID_RESET"); } if (string3 != null) { throw new IOException(string3); } Log.w("FirebaseMessaging", "Unexpected response: " + bundle, new Throwable()); throw new IOException("SERVICE_NOT_AVAILABLE"); } static boolean g(String str) { return "SERVICE_NOT_AVAILABLE".equals(str) || "INTERNAL_SERVER_ERROR".equals(str) || "InternalServerError".equals(str); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ String h(Task task) { return f((Bundle) task.getResult(IOException.class)); } private void i(String str, String str2, Bundle bundle) { j.a b10; bundle.putString("scope", str2); bundle.putString("sender", str); bundle.putString("subtype", str); bundle.putString("gmp_app_id", this.f5536a.o().c()); bundle.putString("gmsv", Integer.toString(this.f5537b.d())); bundle.putString("osv", Integer.toString(Build.VERSION.SDK_INT)); bundle.putString("app_ver", this.f5537b.a()); bundle.putString("app_ver_name", this.f5537b.b()); bundle.putString("firebase-app-name-hash", d()); try { String b11 = ((com.google.firebase.installations.g) Tasks.await(this.f5541f.a(false))).b(); if (TextUtils.isEmpty(b11)) { Log.w("FirebaseMessaging", "FIS auth token is empty"); } else { bundle.putString("Goog-Firebase-Installations-Auth", b11); } } catch (InterruptedException | ExecutionException e10) { Log.e("FirebaseMessaging", "Failed to get FIS auth token", e10); } bundle.putString("appid", (String) Tasks.await(this.f5541f.getId())); bundle.putString("cliv", "fcm-23.2.1"); m4.j jVar = (m4.j) this.f5540e.get(); x4.i iVar = (x4.i) this.f5539d.get(); if (jVar == null || iVar == null || (b10 = jVar.b("fire-iid")) == j.a.NONE) { return; } bundle.putString("Firebase-Client-Log-Type", Integer.toString(b10.a())); bundle.putString("Firebase-Client", iVar.a()); } private Task j(String str, String str2, Bundle bundle) { try { i(str, str2, bundle); return this.f5538c.send(bundle); } catch (InterruptedException | ExecutionException e10) { return Tasks.forException(e10); } } Task e() { return c(j(g0.c(this.f5536a), "*", new Bundle())); } Task k(String str, String str2) { Bundle bundle = new Bundle(); bundle.putString("gcm.topic", "/topics/" + str2); return c(j(str, "/topics/" + str2, bundle)); } Task l(String str, String str2) { Bundle bundle = new Bundle(); bundle.putString("gcm.topic", "/topics/" + str2); bundle.putString("delete", "1"); return c(j(str, "/topics/" + str2, bundle)); } b0(w3.f fVar, g0 g0Var, Rpc rpc, o4.b bVar, o4.b bVar2, p4.e eVar) { this.f5536a = fVar; this.f5537b = g0Var; this.f5538c = rpc; this.f5539d = bVar; this.f5540e = bVar2; this.f5541f = eVar; } }