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 java.io.IOException; /* loaded from: classes2.dex */ class c1 implements Runnable { /* renamed from: f, reason: collision with root package name */ private static final Object f5553f = new Object(); /* renamed from: g, reason: collision with root package name */ private static Boolean f5554g; /* renamed from: h, reason: collision with root package name */ private static Boolean f5555h; /* renamed from: a, reason: collision with root package name */ private final Context f5556a; /* renamed from: b, reason: collision with root package name */ private final g0 f5557b; /* renamed from: c, reason: collision with root package name */ private final PowerManager.WakeLock f5558c; /* renamed from: d, reason: collision with root package name */ private final b1 f5559d; /* renamed from: e, reason: collision with root package name */ private final long f5560e; class a extends BroadcastReceiver { /* renamed from: a, reason: collision with root package name */ private c1 f5561a; public a(c1 c1Var) { this.f5561a = c1Var; } public void a() { if (c1.j()) { Log.d("FirebaseMessaging", "Connectivity change received registered"); } c1.this.f5556a.registerReceiver(this, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE")); } @Override // android.content.BroadcastReceiver public synchronized void onReceive(Context context, Intent intent) { c1 c1Var = this.f5561a; if (c1Var == null) { return; } if (c1Var.i()) { if (c1.j()) { Log.d("FirebaseMessaging", "Connectivity changed. Starting background sync."); } this.f5561a.f5559d.l(this.f5561a, 0L); context.unregisterReceiver(this); this.f5561a = null; } } } c1(b1 b1Var, Context context, g0 g0Var, long j10) { this.f5559d = b1Var; this.f5556a = context; this.f5560e = j10; this.f5557b = g0Var; this.f5558c = ((PowerManager) context.getSystemService("power")).newWakeLock(1, "wake:com.google.firebase.messaging"); } private static String e(String str) { return "Missing Permission: " + str + ". This permission should normally be included by the manifest merger, but may needed to be manually added to your manifest"; } private static boolean f(Context context) { boolean booleanValue; synchronized (f5553f) { Boolean bool = f5555h; Boolean valueOf = Boolean.valueOf(bool == null ? g(context, "android.permission.ACCESS_NETWORK_STATE", bool) : bool.booleanValue()); f5555h = valueOf; booleanValue = valueOf.booleanValue(); } return booleanValue; } private static boolean g(Context context, String str, Boolean bool) { if (bool != null) { return bool.booleanValue(); } boolean z10 = context.checkCallingOrSelfPermission(str) == 0; if (!z10 && Log.isLoggable("FirebaseMessaging", 3)) { Log.d("FirebaseMessaging", e(str)); } return z10; } private static boolean h(Context context) { boolean booleanValue; synchronized (f5553f) { Boolean bool = f5554g; Boolean valueOf = Boolean.valueOf(bool == null ? g(context, "android.permission.WAKE_LOCK", bool) : bool.booleanValue()); f5554g = valueOf; booleanValue = valueOf.booleanValue(); } return booleanValue; } /* JADX INFO: Access modifiers changed from: private */ public synchronized boolean i() { boolean z10; ConnectivityManager connectivityManager = (ConnectivityManager) this.f5556a.getSystemService("connectivity"); NetworkInfo activeNetworkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null; if (activeNetworkInfo != null) { z10 = activeNetworkInfo.isConnected(); } return z10; } /* JADX INFO: Access modifiers changed from: private */ public static boolean j() { return Log.isLoggable("FirebaseMessaging", 3) || (Build.VERSION.SDK_INT == 23 && Log.isLoggable("FirebaseMessaging", 3)); } @Override // java.lang.Runnable public void run() { PowerManager.WakeLock wakeLock; if (h(this.f5556a)) { this.f5558c.acquire(e.f5571a); } try { try { try { this.f5559d.m(true); } catch (IOException e10) { Log.e("FirebaseMessaging", "Failed to sync topics. Won't retry sync. " + e10.getMessage()); this.f5559d.m(false); if (!h(this.f5556a)) { return; } else { wakeLock = this.f5558c; } } if (!this.f5557b.g()) { this.f5559d.m(false); if (h(this.f5556a)) { try { this.f5558c.release(); return; } catch (RuntimeException unused) { Log.i("FirebaseMessaging", "TopicsSyncTask's wakelock was already released due to timeout."); return; } } return; } if (f(this.f5556a) && !i()) { new a(this).a(); if (h(this.f5556a)) { try { this.f5558c.release(); return; } catch (RuntimeException unused2) { Log.i("FirebaseMessaging", "TopicsSyncTask's wakelock was already released due to timeout."); return; } } return; } if (this.f5559d.p()) { this.f5559d.m(false); } else { this.f5559d.q(this.f5560e); } if (h(this.f5556a)) { wakeLock = this.f5558c; wakeLock.release(); } } catch (Throwable th) { if (h(this.f5556a)) { try { this.f5558c.release(); } catch (RuntimeException unused3) { Log.i("FirebaseMessaging", "TopicsSyncTask's wakelock was already released due to timeout."); } } throw th; } } catch (RuntimeException unused4) { Log.i("FirebaseMessaging", "TopicsSyncTask's wakelock was already released due to timeout."); } } }