package com.applovin.impl.sdk; import android.content.Intent; import android.content.IntentFilter; import com.applovin.impl.go; import com.applovin.impl.sdk.AppLovinBroadcastManager; import com.applovin.impl.ve; import java.lang.ref.WeakReference; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; /* loaded from: classes2.dex */ public class d implements AppLovinBroadcastManager.Receiver { private go a; private final Object b = new Object(); private final AtomicBoolean c = new AtomicBoolean(); private boolean d; private final j f; private final WeakReference g; private long h; public interface a { void onAdRefresh(); } public d(j jVar, a aVar) { this.g = new WeakReference(aVar); this.f = jVar; } private void e() { if (((Boolean) this.f.a(ve.f7)).booleanValue()) { k(); } } private void f() { if (((Boolean) this.f.a(ve.f7)).booleanValue()) { synchronized (this.b) { try { if (this.d) { this.f.J(); if (n.a()) { this.f.J().a("AdRefreshManager", "Fullscreen ad dismissed but banner ad refresh paused by publisher. Waiting for publisher to resume banner ad refresh."); } } else if (this.f.f0().isApplicationPaused()) { this.f.J(); if (n.a()) { this.f.J().a("AdRefreshManager", "Waiting for the application to enter foreground to resume the timer."); } } else { go goVar = this.a; if (goVar != null) { goVar.e(); } } } finally { } } } } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void i() { l(); a aVar = (a) this.g.get(); if (aVar != null) { aVar.onAdRefresh(); } } private void k() { synchronized (this.b) { try { go goVar = this.a; if (goVar != null) { goVar.d(); } else { this.f.J(); if (n.a()) { this.f.J().a("AdRefreshManager", "An ad load is in progress. Will pause refresh once the ad finishes loading."); } this.c.set(true); } } catch (Throwable th) { throw th; } } } private void l() { synchronized (this.b) { try { this.a = null; if (!((Boolean) this.f.a(ve.g7)).booleanValue()) { AppLovinBroadcastManager.unregisterReceiver(this); } } catch (Throwable th) { throw th; } } } private void n() { synchronized (this.b) { try { go goVar = this.a; if (goVar != null) { goVar.e(); } else { this.c.set(false); } } catch (Throwable th) { throw th; } } } public void a(long j) { synchronized (this.b) { try { a(); this.h = j; this.a = go.a(j, this.f, new Runnable() { // from class: com.applovin.impl.sdk.d$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { d.this.i(); } }); if (!((Boolean) this.f.a(ve.g7)).booleanValue()) { AppLovinBroadcastManager.registerReceiver(this, new IntentFilter(SessionTracker.ACTION_APPLICATION_PAUSED)); AppLovinBroadcastManager.registerReceiver(this, new IntentFilter(SessionTracker.ACTION_APPLICATION_RESUMED)); AppLovinBroadcastManager.registerReceiver(this, new IntentFilter("com.applovin.fullscreen_ad_displayed")); AppLovinBroadcastManager.registerReceiver(this, new IntentFilter("com.applovin.fullscreen_ad_hidden")); } if (((Boolean) this.f.a(ve.f7)).booleanValue() && (this.f.C().c() || this.f.f0().isApplicationPaused())) { this.a.d(); } if (this.c.compareAndSet(true, false) && ((Boolean) this.f.a(ve.h7)).booleanValue()) { this.f.J(); if (n.a()) { this.f.J().a("AdRefreshManager", "Pausing refresh for a previous request."); } this.a.d(); } } catch (Throwable th) { throw th; } } } public long b() { long c; synchronized (this.b) { try { go goVar = this.a; c = goVar != null ? goVar.c() : -1L; } catch (Throwable th) { throw th; } } return c; } public void c() { if (((Boolean) this.f.a(ve.e7)).booleanValue()) { k(); } } public void d() { boolean z; a aVar; if (((Boolean) this.f.a(ve.e7)).booleanValue()) { synchronized (this.b) { try { if (this.d) { this.f.J(); if (n.a()) { this.f.J().a("AdRefreshManager", "Application resumed but banner ad refresh paused by publisher. Waiting for publisher to resume banner ad refresh."); } return; } if (this.f.C().c()) { this.f.J(); if (n.a()) { this.f.J().a("AdRefreshManager", "Waiting for the full screen ad to be dismissed to resume the timer."); } return; } if (this.a != null) { long b = this.h - b(); long longValue = ((Long) this.f.a(ve.d7)).longValue(); if (longValue >= 0 && b > longValue) { a(); z = true; if (z || (aVar = (a) this.g.get()) == null) { } aVar.onAdRefresh(); return; } this.a.e(); } z = false; if (z) { } } catch (Throwable th) { throw th; } } } } public boolean g() { return this.d; } public boolean h() { boolean z; synchronized (this.b) { z = this.a != null; } return z; } public void j() { synchronized (this.b) { k(); this.d = true; } } public void m() { synchronized (this.b) { n(); this.d = false; } } @Override // com.applovin.impl.sdk.AppLovinBroadcastManager.Receiver public void onReceive(Intent intent, Map map) { String action = intent.getAction(); if (SessionTracker.ACTION_APPLICATION_PAUSED.equals(action)) { c(); return; } if (SessionTracker.ACTION_APPLICATION_RESUMED.equals(action)) { d(); } else if ("com.applovin.fullscreen_ad_displayed".equals(action)) { e(); } else if ("com.applovin.fullscreen_ad_hidden".equals(action)) { f(); } } public void a() { synchronized (this.b) { try { go goVar = this.a; if (goVar != null) { goVar.a(); l(); } } catch (Throwable th) { throw th; } } } }