package com.ironsource.mediationsdk; import android.text.TextUtils; import android.util.Log; import com.ironsource.el; import com.ironsource.hj; import com.ironsource.i9; import com.ironsource.kb; import com.ironsource.mediationsdk.IronSource; import com.ironsource.mediationsdk.adunit.adapter.utility.AdData; import com.ironsource.mediationsdk.bidding.BiddingDataCallback; import com.ironsource.mediationsdk.config.ConfigFile; import com.ironsource.mediationsdk.logger.IronLog; import com.ironsource.mediationsdk.logger.IronSourceError; import com.ironsource.mediationsdk.logger.IronSourceLogger; import com.ironsource.mediationsdk.logger.IronSourceLoggerManager; import com.ironsource.mediationsdk.model.NetworkSettings; import com.ironsource.mediationsdk.model.Placement; import com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener; import com.ironsource.mediationsdk.utils.IronSourceConstants; import com.ironsource.mediationsdk.utils.IronSourceUtils; import com.ironsource.mg; import com.ironsource.rp; import com.ironsource.s7; import com.ironsource.uj; import com.ironsource.v2; import java.util.Date; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import org.json.JSONObject; /* loaded from: classes4.dex */ public class r extends y implements RewardedVideoSmashListener, s7 { private b h; private uj i; private Timer j; private int k; private String l; private String m; private Placement n; private long o; private String p; private JSONObject q; private int r; private String s; private final Object t; private final Object u; private long v; private final mg.a w; public class a extends TimerTask { public a() { } @Override // java.util.TimerTask, java.lang.Runnable public void run() { int i; boolean z; b bVar = r.this.h; b bVar2 = b.LOAD_IN_PROGRESS; String str = "Rewarded Video - load instance time out"; if (bVar == bVar2 || r.this.h == b.INIT_IN_PROGRESS) { if (r.this.h == bVar2) { i = 1025; } else { i = IronSourceError.ERROR_RV_INIT_FAILED_TIMEOUT; str = "Rewarded Video - init instance time out"; } r.this.a(b.NOT_LOADED); z = true; } else { i = 510; z = false; } r.this.a(str); if (!z) { r.this.a(IronSourceConstants.RV_INSTANCE_AVAILABILITY_FALSE, new Object[][]{new Object[]{"errorCode", 1025}, new Object[]{IronSourceConstants.EVENTS_DURATION, Long.valueOf(r.this.v())}, new Object[]{IronSourceConstants.EVENTS_EXT1, r.this.h.name()}}); return; } r.this.a(1200, new Object[][]{new Object[]{"errorCode", Integer.valueOf(i)}, new Object[]{IronSourceConstants.EVENTS_DURATION, Long.valueOf(r.this.v())}}); r.this.a(IronSourceConstants.RV_INSTANCE_LOAD_FAILED_REASON, new Object[][]{new Object[]{"errorCode", Integer.valueOf(i)}, new Object[]{"reason", str}, new Object[]{IronSourceConstants.EVENTS_DURATION, Long.valueOf(r.this.v())}}); r.this.i.c(r.this); } } public enum b { NO_INIT, INIT_IN_PROGRESS, NOT_LOADED, LOAD_IN_PROGRESS, LOADED, SHOW_IN_PROGRESS, ENDED } public r(r rVar, uj ujVar, AbstractAdapter abstractAdapter, int i, String str, JSONObject jSONObject, int i2, String str2) { this(rVar.l, rVar.m, rVar.b.h(), ujVar, rVar.k, abstractAdapter, i); this.p = str; this.q = jSONObject; this.r = i2; this.s = str2; } public r(String str, String str2, NetworkSettings networkSettings, uj ujVar, int i, AbstractAdapter abstractAdapter, int i2) { super(new v2(networkSettings, networkSettings.getRewardedVideoSettings(), IronSource.AD_UNIT.REWARDED_VIDEO), abstractAdapter); this.t = new Object(); this.u = new Object(); this.w = el.I().e(); this.l = str; this.m = str2; this.i = ujVar; this.j = null; this.k = i; this.f = i2; this.h = b.NO_INIT; this.v = 0L; if (r()) { t(); } } private void C() { try { String pluginType = ConfigFile.getConfigFile().getPluginType(); if (TextUtils.isEmpty(pluginType)) { return; } this.a.setPluginData(pluginType); } catch (Throwable th) { i9.d().a(th); a("setCustomParams() " + th.getMessage()); } } private void D() { synchronized (this.u) { Timer timer = new Timer(); this.j = timer; timer.schedule(new a(), this.k * 1000); } } private void E() { synchronized (this.u) { try { Timer timer = this.j; if (timer != null) { timer.cancel(); this.j = null; } } catch (Throwable th) { throw th; } } } private void a(int i, Object[][] objArr, boolean z) { Placement placement; Map m = m(); if (!TextUtils.isEmpty(this.p)) { m.put("auctionId", this.p); } JSONObject jSONObject = this.q; if (jSONObject != null && jSONObject.length() > 0) { m.put("genericParams", this.q); } if (z && (placement = this.n) != null && !TextUtils.isEmpty(placement.getPlacementName())) { m.put("placement", this.n.getPlacementName()); } if (c(i)) { rp.i().a(m, this.r, this.s); } m.put("sessionDepth", Integer.valueOf(this.f)); if (objArr != null) { try { for (Object[] objArr2 : objArr) { m.put(objArr2[0].toString(), objArr2[1]); } } catch (Exception e) { i9.d().a(e); IronSourceLoggerManager.getLogger().log(IronSourceLogger.IronSourceTag.INTERNAL, c() + " smash: RV sendProviderEvent " + Log.getStackTraceString(e), 3); } } rp.i().a(new kb(i, new JSONObject(m))); if (i == 1203) { this.w.b(IronSource.AD_UNIT.REWARDED_VIDEO); } } /* JADX INFO: Access modifiers changed from: private */ public void a(b bVar) { a("current state=" + this.h + ", new state=" + bVar); synchronized (this.t) { this.h = bVar; } } private void b(int i) { b(i, null); } private boolean c(int i) { return i == 1001 || i == 1002 || i == 1200 || i == 1212 || i == 1213 || i == 1005 || i == 1203 || i == 1201 || i == 1202 || i == 1006 || i == 1010; } private void t() { a("isBidder = " + p() + ", shouldEarlyInit = " + s()); a(b.INIT_IN_PROGRESS); C(); try { this.a.initRewardedVideoWithCallback(this.l, this.m, this.d, this); } catch (Throwable th) { i9.d().a(th); b("initForBidding exception: " + th.getLocalizedMessage()); onRewardedVideoInitFailed(new IronSourceError(IronSourceError.ERROR_RV_INSTANCE_INIT_EXCEPTION, th.getLocalizedMessage())); } } /* JADX INFO: Access modifiers changed from: private */ public long v() { return new Date().getTime() - this.o; } public boolean A() { if (this.h != b.LOADED) { return false; } try { return this.a.isRewardedVideoAvailable(this.d); } catch (Throwable th) { i9.d().a(th); b("isReadyToShow exception: " + th.getLocalizedMessage()); a(IronSourceConstants.TROUBLESHOOTING_RV_SMASH_UNEXPECTED_EXCEPTION, new Object[][]{new Object[]{"errorCode", Integer.valueOf(IronSourceConstants.errorCode_isReadyException)}, new Object[]{"reason", th.getLocalizedMessage()}}); return false; } } public void B() { a(IronSourceConstants.RV_CAP_SESSION); } @Override // com.ironsource.s7 public Map a(AdData adData) { JSONObject a2 = adData != null ? hj.a(adData.getAdUnitData()) : null; if (p()) { return this.a.getRewardedVideoBiddingData(this.d, a2); } return null; } public void a(int i) { a(i, null, false); } public void a(int i, Object[][] objArr) { a(i, objArr, false); } @Override // com.ironsource.s7 public void a(AdData adData, BiddingDataCallback biddingDataCallback) { a(1020); try { this.a.collectRewardedVideoBiddingData(this.d, adData != null ? hj.a(adData.getAdUnitData()) : null, biddingDataCallback); } catch (Throwable th) { i9.d().a(th); b("collectBiddingData exception: " + th.getLocalizedMessage()); IronLog.INTERNAL.error(th.toString()); } } public void a(Placement placement) { E(); a("showVideo()"); this.n = placement; a(b.SHOW_IN_PROGRESS); b(1201); try { this.a.showRewardedVideo(this.d, this); } catch (Throwable th) { i9.d().a(th); b("showVideo exception: " + th.getLocalizedMessage()); onRewardedVideoAdShowFailed(new IronSourceError(IronSourceError.ERROR_RV_SHOW_EXCEPTION, th.getLocalizedMessage())); } } public void a(String str, JSONObject jSONObject) { b bVar; b bVar2; a("loadVideo() auctionId: " + this.p + " state: " + this.h); this.g = null; a(false); synchronized (this.t) { try { bVar = this.h; bVar2 = b.LOAD_IN_PROGRESS; if (bVar != bVar2 && bVar != b.SHOW_IN_PROGRESS) { a(bVar2); } } finally { } } if (bVar == bVar2) { a(IronSourceConstants.RV_SMASH_UNEXPECTED_STATE, new Object[][]{new Object[]{"errorCode", Integer.valueOf(IronSourceConstants.errorCode_loadInProgress)}, new Object[]{"reason", "load during load"}}); return; } if (bVar == b.SHOW_IN_PROGRESS) { a(IronSourceConstants.RV_SMASH_UNEXPECTED_STATE, new Object[][]{new Object[]{"errorCode", Integer.valueOf(IronSourceConstants.errorCode_showInProgress)}, new Object[]{"reason", "load during show"}}); return; } D(); this.o = new Date().getTime(); a(1001); try { if (p()) { this.a.loadRewardedVideoForBidding(this.d, jSONObject, str, this); } else { C(); this.a.initAndLoadRewardedVideo(this.l, this.m, this.d, jSONObject, this); } } catch (Throwable th) { i9.d().a(th); b("loadVideo exception: " + th.getLocalizedMessage()); a(IronSourceConstants.TROUBLESHOOTING_RV_SMASH_UNEXPECTED_EXCEPTION, new Object[][]{new Object[]{"errorCode", Integer.valueOf(p() ? IronSourceConstants.errorCode_loadException : IronSourceConstants.errorCode_initFailed)}, new Object[]{"reason", th.getLocalizedMessage()}}); } } public void b(int i, Object[][] objArr) { a(i, objArr, true); } public void b(boolean z) { Object[][] objArr = new Object[1][]; Object[] objArr2 = new Object[2]; objArr2[0] = "status"; objArr2[1] = z ? "true" : "false"; objArr[0] = objArr2; b(IronSourceConstants.RV_INSTANCE_SHOW_CHANCE, objArr); } @Override // com.ironsource.mediationsdk.y public IronSource.AD_UNIT d() { return IronSource.AD_UNIT.REWARDED_VIDEO; } @Override // com.ironsource.mediationsdk.y public String k() { return "LWSProgRvSmash"; } @Override // com.ironsource.mediationsdk.y public int l() { return 2; } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoAdClicked() { a("onRewardedVideoAdClicked"); this.i.b(this, this.n); b(1006); } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoAdClosed() { a("onRewardedVideoAdClosed"); synchronized (this.t) { try { if (this.h == b.SHOW_IN_PROGRESS) { a(b.ENDED); this.v = new Date().getTime(); this.i.b(this); } else { b(1203); a(IronSourceConstants.RV_SMASH_UNEXPECTED_STATE, new Object[][]{new Object[]{"errorCode", Integer.valueOf(IronSourceConstants.errorCode_adClosed)}, new Object[]{"reason", "adClosed: " + this.h}}); } } catch (Throwable th) { throw th; } } } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoAdEnded() { a("onRewardedVideoAdEnded"); this.i.f(this); b(IronSourceConstants.RV_INSTANCE_ENDED); } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoAdOpened() { a("onRewardedVideoAdOpened"); this.i.d(this); b(1005); } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoAdRewarded() { a("onRewardedVideoAdRewarded"); long time = new Date().getTime(); this.i.a(this, this.n); Map m = m(); Placement placement = this.n; if (placement != null) { m.put("placement", placement.getPlacementName()); m.put(IronSourceConstants.EVENTS_REWARD_NAME, this.n.getRewardName()); m.put(IronSourceConstants.EVENTS_REWARD_AMOUNT, Integer.valueOf(this.n.getRewardAmount())); } if (!TextUtils.isEmpty(p.m().l())) { m.put(IronSourceConstants.EVENTS_DYNAMIC_USER_ID, p.m().l()); } if (p.m().s() != null) { for (String str : p.m().s().keySet()) { m.put("custom_" + str, p.m().s().get(str)); } } if (!TextUtils.isEmpty(this.p)) { m.put("auctionId", this.p); } JSONObject jSONObject = this.q; if (jSONObject != null && jSONObject.length() > 0) { m.put("genericParams", this.q); } if (c(1010)) { rp.i().a(m, this.r, this.s); } m.put("sessionDepth", Integer.valueOf(this.f)); kb kbVar = new kb(1010, new JSONObject(m)); kbVar.a(IronSourceConstants.EVENTS_TRANS_ID, IronSourceUtils.getTransId(kbVar.d(), c())); long j = this.v; if (j != 0) { long j2 = time - j; a("onRewardedVideoAdRewarded timeAfterClosed=" + j2); kbVar.a(IronSourceConstants.EVENTS_DURATION, Long.valueOf(j2)); } rp.i().a(kbVar); } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoAdShowFailed(IronSourceError ironSourceError) { a("onRewardedVideoAdShowFailed error=" + ironSourceError.getErrorMessage()); b(1202, new Object[][]{new Object[]{"errorCode", Integer.valueOf(ironSourceError.getErrorCode())}, new Object[]{"reason", ironSourceError.getErrorMessage()}}); synchronized (this.t) { try { if (this.h == b.SHOW_IN_PROGRESS) { a(b.ENDED); this.i.a(ironSourceError, this); return; } a(IronSourceConstants.RV_SMASH_UNEXPECTED_STATE, new Object[][]{new Object[]{"errorCode", Integer.valueOf(IronSourceConstants.errorCode_showFailed)}, new Object[]{"reason", "showFailed: " + this.h}}); } catch (Throwable th) { throw th; } } } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoAdStarted() { a("onRewardedVideoAdStarted"); this.i.a(this); b(IronSourceConstants.RV_INSTANCE_STARTED); } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoAdVisible() { a("onRewardedVideoAdVisible"); b(1206); } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoAvailabilityChanged(boolean z) { boolean z2; a("onRewardedVideoAvailabilityChanged available=" + z + " state=" + this.h.name()); synchronized (this.t) { try { if (this.h == b.LOAD_IN_PROGRESS) { a(z ? b.LOADED : b.NOT_LOADED); z2 = false; } else { z2 = true; } } catch (Throwable th) { throw th; } } if (z2) { if (z) { a(IronSourceConstants.RV_INSTANCE_AVAILABILITY_TRUE, new Object[][]{new Object[]{IronSourceConstants.EVENTS_EXT1, this.h.name()}}); return; } else { a(IronSourceConstants.RV_INSTANCE_AVAILABILITY_FALSE, new Object[][]{new Object[]{"errorCode", Integer.valueOf(IronSourceError.ERROR_RV_LOAD_UNEXPECTED_CALLBACK)}, new Object[]{IronSourceConstants.EVENTS_DURATION, Long.valueOf(v())}, new Object[]{IronSourceConstants.EVENTS_EXT1, this.h.name()}}); return; } } E(); a(z ? 1002 : 1200, new Object[][]{new Object[]{IronSourceConstants.EVENTS_DURATION, Long.valueOf(v())}}); if (z) { this.i.e(this); } else { this.i.c(this); } } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoInitFailed(IronSourceError ironSourceError) { a("onRewardedVideoInitFailed error=" + ironSourceError.getErrorMessage()); E(); a(1200, new Object[][]{new Object[]{"errorCode", Integer.valueOf(IronSourceError.ERROR_RV_LOAD_FAIL_DUE_TO_INIT)}, new Object[]{IronSourceConstants.EVENTS_DURATION, Long.valueOf(v())}}); a(IronSourceConstants.RV_INSTANCE_LOAD_FAILED_REASON, new Object[][]{new Object[]{"errorCode", Integer.valueOf(ironSourceError.getErrorCode())}, new Object[]{"reason", ironSourceError.getErrorMessage()}, new Object[]{IronSourceConstants.EVENTS_DURATION, Long.valueOf(v())}}); synchronized (this.t) { try { if (this.h == b.INIT_IN_PROGRESS) { a(b.NO_INIT); this.i.c(this); return; } a(IronSourceConstants.RV_SMASH_UNEXPECTED_STATE, new Object[][]{new Object[]{"errorCode", Integer.valueOf(IronSourceConstants.errorCode_initFailed)}, new Object[]{"reason", "initFailed: " + this.h}}); } catch (Throwable th) { throw th; } } } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoInitSuccess() { a("onRewardedVideoInitSuccess"); synchronized (this.t) { try { if (this.h == b.INIT_IN_PROGRESS) { a(b.NOT_LOADED); return; } a(IronSourceConstants.RV_SMASH_UNEXPECTED_STATE, new Object[][]{new Object[]{"errorCode", Integer.valueOf(IronSourceConstants.errorCode_initSuccess)}, new Object[]{"reason", "initSuccess: " + this.h}}); } catch (Throwable th) { throw th; } } } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoLoadFailed(IronSourceError ironSourceError) { if (ironSourceError.getErrorCode() == 1058) { a(1213, new Object[][]{new Object[]{"errorCode", Integer.valueOf(ironSourceError.getErrorCode())}, new Object[]{IronSourceConstants.EVENTS_DURATION, Long.valueOf(v())}}); return; } if (ironSourceError.getErrorCode() == 1057) { this.g = Long.valueOf(System.currentTimeMillis()); } a(IronSourceConstants.RV_INSTANCE_LOAD_FAILED_REASON, new Object[][]{new Object[]{"errorCode", Integer.valueOf(ironSourceError.getErrorCode())}, new Object[]{"reason", ironSourceError.getErrorMessage()}, new Object[]{IronSourceConstants.EVENTS_DURATION, Long.valueOf(v())}}); } @Override // com.ironsource.mediationsdk.sdk.RewardedVideoSmashListener public void onRewardedVideoLoadSuccess() { } public String u() { return this.p; } public LoadWhileShowSupportState w() { try { return this.a.getLoadWhileShowSupportState(this.d); } catch (Throwable th) { i9.d().a(th); b("Exception while calling adapter.getLoadWhileShowSupportState() - " + th.getLocalizedMessage()); return LoadWhileShowSupportState.NONE; } } public Placement x() { return this.n; } public boolean y() { return this.h == b.LOADED; } public boolean z() { b bVar = this.h; return bVar == b.INIT_IN_PROGRESS || bVar == b.LOAD_IN_PROGRESS; } }