package com.google.firebase.messaging; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Build; import android.os.PowerManager; import android.util.Log; import com.google.android.gms.common.util.concurrent.NamedThreadFactory; import java.io.IOException; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; /* loaded from: classes2.dex */ class x0 implements Runnable { /* renamed from: a, reason: collision with root package name */ private final long f5684a; /* renamed from: b, reason: collision with root package name */ private final PowerManager.WakeLock f5685b; /* renamed from: c, reason: collision with root package name */ private final FirebaseMessaging f5686c; /* renamed from: d, reason: collision with root package name */ ExecutorService f5687d = new ThreadPoolExecutor(0, 1, 30, TimeUnit.SECONDS, new LinkedBlockingQueue(), new NamedThreadFactory("firebase-iid-executor")); static class a extends BroadcastReceiver { /* renamed from: a, reason: collision with root package name */ private x0 f5688a; public a(x0 x0Var) { this.f5688a = x0Var; } public void a() { if (x0.c()) { Log.d("FirebaseMessaging", "Connectivity change received registered"); } this.f5688a.b().registerReceiver(this, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE")); } @Override // android.content.BroadcastReceiver public void onReceive(Context context, Intent intent) { x0 x0Var = this.f5688a; if (x0Var != null && x0Var.d()) { if (x0.c()) { Log.d("FirebaseMessaging", "Connectivity changed. Starting background sync."); } this.f5688a.f5686c.i(this.f5688a, 0L); this.f5688a.b().unregisterReceiver(this); this.f5688a = null; } } } public x0(FirebaseMessaging firebaseMessaging, long j10) { this.f5686c = firebaseMessaging; this.f5684a = j10; PowerManager.WakeLock newWakeLock = ((PowerManager) b().getSystemService("power")).newWakeLock(1, "fiid-sync"); this.f5685b = newWakeLock; newWakeLock.setReferenceCounted(false); } static boolean c() { return Log.isLoggable("FirebaseMessaging", 3) || (Build.VERSION.SDK_INT == 23 && Log.isLoggable("FirebaseMessaging", 3)); } Context b() { return this.f5686c.j(); } boolean d() { ConnectivityManager connectivityManager = (ConnectivityManager) b().getSystemService("connectivity"); NetworkInfo activeNetworkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null; return activeNetworkInfo != null && activeNetworkInfo.isConnected(); } boolean e() { try { if (this.f5686c.h() == null) { Log.e("FirebaseMessaging", "Token retrieval failed: null"); return false; } if (!Log.isLoggable("FirebaseMessaging", 3)) { return true; } Log.d("FirebaseMessaging", "Token successfully retrieved"); return true; } catch (IOException e10) { if (!b0.g(e10.getMessage())) { if (e10.getMessage() != null) { throw e10; } Log.w("FirebaseMessaging", "Token retrieval failed without exception message. Will retry token retrieval"); return false; } Log.w("FirebaseMessaging", "Token retrieval failed: " + e10.getMessage() + ". Will retry token retrieval"); return false; } catch (SecurityException unused) { Log.w("FirebaseMessaging", "Token retrieval failed with SecurityException. Will retry token retrieval"); return false; } } @Override // java.lang.Runnable public void run() { if (t0.b().e(b())) { this.f5685b.acquire(); } try { try { this.f5686c.w(true); } catch (IOException e10) { Log.e("FirebaseMessaging", "Topic sync or token retrieval failed on hard failure exceptions: " + e10.getMessage() + ". Won't retry the operation."); this.f5686c.w(false); if (!t0.b().e(b())) { return; } } if (!this.f5686c.q()) { this.f5686c.w(false); if (t0.b().e(b())) { this.f5685b.release(); return; } return; } if (t0.b().d(b()) && !d()) { new a(this).a(); if (t0.b().e(b())) { this.f5685b.release(); return; } return; } if (e()) { this.f5686c.w(false); } else { this.f5686c.z(this.f5684a); } if (!t0.b().e(b())) { return; } this.f5685b.release(); } catch (Throwable th) { if (t0.b().e(b())) { this.f5685b.release(); } throw th; } } }