package com.google.firebase.iid; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.PowerManager; import android.util.Log; import java.io.IOException; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public final class zzbb implements Runnable { private final long zza; private final PowerManager.WakeLock zzb; private final FirebaseInstanceId zzc; /* JADX INFO: Access modifiers changed from: package-private */ public zzbb(FirebaseInstanceId firebaseInstanceId, long j) { this.zzc = firebaseInstanceId; this.zza = j; PowerManager.WakeLock newWakeLock = ((PowerManager) zza().getSystemService("power")).newWakeLock(1, "fiid-sync"); this.zzb = newWakeLock; newWakeLock.setReferenceCounted(false); } @Override // java.lang.Runnable public final void run() { if (zzaw.zza().zza(zza())) { this.zzb.acquire(); } try { try { this.zzc.zza(true); if (!this.zzc.zzf()) { this.zzc.zza(false); if (zzaw.zza().zza(zza())) { this.zzb.release(); return; } return; } if (zzaw.zza().zzb(zza()) && !zzb()) { new zzba(this).zza(); if (zzaw.zza().zza(zza())) { this.zzb.release(); return; } return; } if (zzc()) { this.zzc.zza(false); } else { this.zzc.zza(this.zza); } if (zzaw.zza().zza(zza())) { this.zzb.release(); } } catch (IOException e) { e.getMessage(); this.zzc.zza(false); if (zzaw.zza().zza(zza())) { this.zzb.release(); } } } catch (Throwable th) { if (zzaw.zza().zza(zza())) { this.zzb.release(); } throw th; } } private final boolean zzc() throws IOException { zzay zzb = this.zzc.zzb(); if (!this.zzc.zza(zzb)) { return true; } try { String zzc = this.zzc.zzc(); if (zzc == null) { return false; } if ((zzb == null || (zzb != null && !zzc.equals(zzb.zza))) && "[DEFAULT]".equals(this.zzc.zza().getName())) { if (Log.isLoggable("FirebaseInstanceId", 3)) { this.zzc.zza().getName(); } Intent intent = new Intent("com.google.firebase.messaging.NEW_TOKEN"); intent.putExtra("token", zzc); Context zza = zza(); Intent intent2 = new Intent(zza, (Class) FirebaseInstanceIdReceiver.class); intent2.setAction("com.google.firebase.MESSAGING_EVENT"); intent2.putExtra("wrapped_intent", intent); zza.sendBroadcast(intent2); } return true; } catch (IOException e) { String message = e.getMessage(); if ("SERVICE_NOT_AVAILABLE".equals(message) || "INTERNAL_SERVER_ERROR".equals(message) || "InternalServerError".equals(message)) { e.getMessage(); return false; } if (e.getMessage() == null) { return false; } throw e; } catch (SecurityException unused) { return false; } } /* JADX INFO: Access modifiers changed from: package-private */ public final Context zza() { return this.zzc.zza().getApplicationContext(); } /* JADX INFO: Access modifiers changed from: package-private */ public final boolean zzb() { ConnectivityManager connectivityManager = (ConnectivityManager) zza().getSystemService("connectivity"); NetworkInfo activeNetworkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null; return activeNetworkInfo != null && activeNetworkInfo.isConnected(); } }