package com.mbridge.msdk.interstitial.c; import android.content.Context; import android.content.Intent; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.text.TextUtils; import androidx.core.view.accessibility.AccessibilityEventCompat; import androidx.work.WorkRequest; import com.google.android.gms.drive.DriveFile; import com.mbridge.msdk.MBridgeConstans; import com.mbridge.msdk.c.h; import com.mbridge.msdk.c.j; import com.mbridge.msdk.c.k; import com.mbridge.msdk.foundation.entity.CampaignEx; import com.mbridge.msdk.foundation.tools.af; import com.mbridge.msdk.interstitial.view.MBInterstitialActivity; import com.mbridge.msdk.out.InterstitialListener; import com.mbridge.msdk.out.MBridgeIds; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /* loaded from: classes4.dex */ public final class a { public static String a; public static Map c = new HashMap(); public static Map d = new HashMap(); public static Map e = new HashMap(); private Context g; private String h; private String i; private String j; private MBridgeIds k; private Handler l; private k m; private InterstitialListener n; private String f = "InterstitialController"; public boolean b = false; private String o = ""; private String p = ""; private String q = ""; private boolean r = false; public final void a(InterstitialListener interstitialListener) { this.n = interstitialListener; } public final String b() { return this.b ? this.q : this.o; } public final String c() { return this.p; } public static void a(String str, int i) { try { if (c == null || TextUtils.isEmpty(str)) { return; } c.put(str, Integer.valueOf(i)); } catch (Exception e2) { e2.printStackTrace(); } } public static int a(String str) { Map map; Integer num; try { if (TextUtils.isEmpty(str) || (map = c) == null || !map.containsKey(str) || (num = c.get(str)) == null) { return 0; } return num.intValue(); } catch (Exception e2) { e2.printStackTrace(); return 0; } } public a() { try { this.l = new Handler(Looper.getMainLooper()) { // from class: com.mbridge.msdk.interstitial.c.a.1 @Override // android.os.Handler public final void handleMessage(Message message) { if (message == null) { return; } int i = message.what; if (i == 1) { if (a.this.n != null) { a.this.n.onInterstitialLoadSuccess(a.this.k); return; } return; } String str = ""; if (i == 2) { if (a.this.n != null) { Object obj = message.obj; if (obj != null && (obj instanceof String)) { str = (String) obj; } a.this.n.onInterstitialLoadFail(a.this.k, TextUtils.isEmpty(str) ? "can't show because unknow error" : str); return; } return; } if (i == 3) { a aVar = a.this; aVar.b = true; if (aVar.n != null) { a.this.n.onInterstitialShowSuccess(a.this.k); return; } return; } if (i == 4) { if (a.this.n != null) { Object obj2 = message.obj; if (obj2 != null && (obj2 instanceof String)) { str = (String) obj2; } a.this.n.onInterstitialShowFail(a.this.k, TextUtils.isEmpty(str) ? "can't show because unknow error" : str); return; } return; } if (i == 6) { if (a.this.n != null) { a.this.n.onInterstitialAdClick(a.this.k); } } else { if (i != 7) { return; } a aVar2 = a.this; aVar2.b = false; if (aVar2.n != null) { a.this.n.onInterstitialClosed(a.this.k); } } } }; } catch (Exception e2) { try { e2.printStackTrace(); } catch (Exception e3) { e3.printStackTrace(); } } } public final boolean a(Context context, Map map) { try { this.r = false; } catch (Exception e2) { e2.printStackTrace(); this.r = false; } if (map != null && context != null && map.containsKey(MBridgeConstans.PROPERTIES_UNIT_ID) && (map.get(MBridgeConstans.PROPERTIES_UNIT_ID) instanceof String)) { if (map.containsKey(MBridgeConstans.PROPERTIES_API_REUQEST_CATEGORY) && (map.get(MBridgeConstans.PROPERTIES_API_REUQEST_CATEGORY) instanceof String)) { this.j = (String) map.get(MBridgeConstans.PROPERTIES_API_REUQEST_CATEGORY); } this.h = (String) map.get(MBridgeConstans.PROPERTIES_UNIT_ID); this.g = context; if (map.containsKey(MBridgeConstans.PLACEMENT_ID) && map.get(MBridgeConstans.PLACEMENT_ID) != null) { this.i = (String) map.get(MBridgeConstans.PLACEMENT_ID); } this.k = new MBridgeIds(this.i, this.h); this.r = true; return this.r; } return false; } public final void a() { try { if (this.g == null) { b("context is null"); return; } if (TextUtils.isEmpty(this.h)) { b("unitid is null"); return; } if (!this.r) { b("init error"); return; } e(); try { k kVar = this.m; if (kVar != null) { int d2 = kVar.d(); int w = this.m.w(); if (d2 <= 0) { d2 = 1; } if (w <= 0) { w = 1; } int i = w * d2; if (d != null && !TextUtils.isEmpty(this.h)) { d.put(this.h, Integer.valueOf(i)); } } } catch (Exception e2) { e2.printStackTrace(); } a(false); } catch (Exception e3) { e3.printStackTrace(); b("can't show because unknow error"); } } public final void d() { try { if (this.g == null) { c("context is null"); return; } if (TextUtils.isEmpty(this.h)) { c("unitid is null"); } else if (!this.r) { c("init error"); } else { e(); b(true); } } catch (Exception e2) { e2.printStackTrace(); c("can't show because unknow error"); } } private void e() { try { f(); k d2 = h.a().d(com.mbridge.msdk.foundation.controller.c.m().k(), this.h); this.m = d2; if (d2 == null) { this.m = k.c(this.h); } } catch (Exception e2) { e2.printStackTrace(); } } private void a(boolean z) { try { com.mbridge.msdk.interstitial.a.a aVar = new com.mbridge.msdk.interstitial.a.a(this.g, this.h, this.i, this.j, z); b bVar = new b(aVar); aVar.a(new C0205a(aVar, bVar)); Handler handler = this.l; if (handler != null) { handler.postDelayed(bVar, WorkRequest.DEFAULT_BACKOFF_DELAY_MILLIS); } aVar.b(); } catch (Exception e2) { e2.printStackTrace(); if (z) { return; } b("can't show because unknow error"); } } /* JADX INFO: Access modifiers changed from: private */ public void b(boolean z) { try { CampaignEx a2 = new com.mbridge.msdk.interstitial.a.a(this.g, this.h, this.i, this.j, true).a(); if (a2 != null) { a(a2); } else if (z) { a(true); } else { c("no ads available can show"); } } catch (Exception e2) { e2.printStackTrace(); if (this.n != null) { c("can't show because unknow error"); } } } private void a(CampaignEx campaignEx) { c cVar = new c(); if (e != null && !TextUtils.isEmpty(this.h)) { e.put(this.h, cVar); } Intent intent = new Intent(this.g, (Class) MBInterstitialActivity.class); intent.addFlags(AccessibilityEventCompat.TYPE_VIEW_TARGETED_BY_SCROLL); intent.addFlags(DriveFile.MODE_READ_ONLY); if (!TextUtils.isEmpty(this.h)) { intent.putExtra("unitId", this.h); } if (campaignEx != null) { this.q = campaignEx.getRequestId(); intent.putExtra(MBInterstitialActivity.INTENT_CAMAPIGN, campaignEx); } Context context = this.g; if (context != null) { context.startActivity(intent); } } public class b implements Runnable { private com.mbridge.msdk.interstitial.a.a b; public b(com.mbridge.msdk.interstitial.a.a aVar) { this.b = aVar; } @Override // java.lang.Runnable public final void run() { try { com.mbridge.msdk.interstitial.a.a aVar = this.b; if (aVar != null) { if (aVar.c()) { a.this.c("load timeout"); } else if (a.this.n != null) { a.this.b("load timeout"); } this.b.a((C0205a) null); this.b = null; } } catch (Exception e) { e.printStackTrace(); } } } /* renamed from: com.mbridge.msdk.interstitial.c.a$a, reason: collision with other inner class name */ public class C0205a { private com.mbridge.msdk.interstitial.a.a b; private b c; public C0205a(com.mbridge.msdk.interstitial.a.a aVar, b bVar) { this.b = aVar; this.c = bVar; } public final void a(boolean z, String str) { try { a.this.o = str; try { ArrayList arrayList = new ArrayList(); com.mbridge.msdk.interstitial.a.a aVar = this.b; if (aVar != null && aVar.a() != null) { arrayList.add(this.b.a()); } a.this.p = com.mbridge.msdk.foundation.same.c.a(arrayList); } catch (Exception e) { af.b(a.this.f, e.getMessage()); } if (this.c != null) { if (a.this.l != null) { a.this.l.removeCallbacks(this.c); } if (z) { a.this.b(false); } else if (a.this.n != null) { a.e(a.this); } } } catch (Exception e2) { e2.printStackTrace(); } } public final void b(boolean z, String str) { try { com.mbridge.msdk.interstitial.a.a aVar = this.b; if (aVar != null) { aVar.a((C0205a) null); this.b = null; } if (this.c != null) { if (a.this.l != null) { a.this.l.removeCallbacks(this.c); } if (z) { if (a.this.n != null) { a.this.c(str); } } else if (a.this.n != null) { a.this.b(str); } } } catch (Exception e) { e.printStackTrace(); } } } public class c { public c() { } public final void a(String str) { try { a.this.c(str); } catch (Exception e) { e.printStackTrace(); } } public final void a() { try { a.f(a.this); } catch (Exception e) { e.printStackTrace(); } } public final void b() { try { if (a.this.l != null) { a.this.l.sendEmptyMessage(7); } } catch (Exception e) { e.printStackTrace(); } } public final void c() { try { if (a.this.l != null) { a.this.l.sendEmptyMessage(6); } } catch (Exception e) { e.printStackTrace(); } } } /* JADX INFO: Access modifiers changed from: private */ public void b(String str) { try { if (this.l != null) { Message obtain = Message.obtain(); obtain.obj = str; obtain.what = 2; this.l.sendMessage(obtain); } } catch (Exception e2) { e2.printStackTrace(); } } /* JADX INFO: Access modifiers changed from: private */ public void c(String str) { try { if (this.l != null) { Message obtain = Message.obtain(); obtain.obj = str; obtain.what = 4; this.l.sendMessage(obtain); } } catch (Exception e2) { e2.printStackTrace(); } } private void f() { try { new j().a(this.g, (String) null, (String) null, this.h); } catch (Exception e2) { e2.printStackTrace(); } } public static /* synthetic */ void e(a aVar) { Handler handler = aVar.l; if (handler != null) { handler.sendEmptyMessage(1); } } public static /* synthetic */ void f(a aVar) { Handler handler = aVar.l; if (handler != null) { handler.sendEmptyMessage(3); } } }