b.java 源代码
package com.mbridge.msdk.mbnative.controller;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import com.anythink.core.common.c.e;
import com.anythink.expressad.foundation.f.a.f;
import com.mbridge.msdk.MBridgeConstans;
import com.mbridge.msdk.foundation.db.e;
import com.mbridge.msdk.foundation.db.g;
import com.mbridge.msdk.foundation.entity.CampaignEx;
import com.mbridge.msdk.foundation.entity.CampaignUnit;
import com.mbridge.msdk.foundation.entity.j;
import com.mbridge.msdk.foundation.tools.SameMD5;
import com.mbridge.msdk.foundation.tools.l;
import com.mbridge.msdk.foundation.tools.o;
import com.mbridge.msdk.foundation.tools.q;
import com.mbridge.msdk.foundation.tools.u;
import com.mbridge.msdk.nativex.view.MBMediaView;
import com.mbridge.msdk.out.Campaign;
import com.mbridge.msdk.out.Frame;
import com.mbridge.msdk.out.PreloadListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class b {
private static final String f17703d = "b";
private static Map<String, Map<Long, Object>> f17704e = new HashMap();
private static Map<String, Boolean> f17705f = new HashMap();
private static Map<String, j> f17706g = new HashMap();
private static Map<String, Integer> f17707h = new HashMap();
private static Map<String, Integer> f17708i = new HashMap();
private static b f17709j = null;
private static int f17710u = -1;
private static int f17711v = -2;
protected List<Integer> f17714c;
private com.mbridge.msdk.b.c f17715k;
private com.mbridge.msdk.click.a f17716l;
private com.mbridge.msdk.b.d f17717m;
private String f17718n;
private Handler f17719o;
private Map<String, Object> f17721q;
private List<Integer> f17722r;
private List<Integer> f17723s;
private boolean f17724t;
private boolean f17725w;
private int f17726x;
private int f17727y;
Queue<Integer> f17712a = null;
Queue<Long> f17713b = null;
private int f17720p = 0;
private com.mbridge.msdk.foundation.same.e.b f17728z = new com.mbridge.msdk.foundation.same.e.b(com.mbridge.msdk.foundation.controller.a.e().g());
public class a extends com.mbridge.msdk.mbnative.e.a.b implements com.mbridge.msdk.foundation.same.e.c {
private int f17731b;
private int f17732c;
private int f17733g;
private int f17734h;
private int f17735i;
private Runnable f17738l;
private com.mbridge.msdk.a.a.a f17740n;
private List<String> f17736j = null;
private boolean f17737k = false;
private boolean f17739m = true;
public a(int i6) {
this.f17731b = i6;
}
public final void b(boolean z6) {
this.f17739m = z6;
}
public final void c(int i6) {
this.f17735i = i6;
}
public final void d(int i6) {
this.f17733g = i6;
}
public final void e(int i6) {
this.f17734h = i6;
}
public final void f(int i6) {
this.f17732c = i6;
}
public final void a(List<String> list) {
this.f17736j = list;
}
@Override
public final void b(final List<Frame> list) {
b.this.a(new Thread(new Runnable() {
@Override
public final void run() {
boolean z6;
if (MBridgeConstans.PRELOAD_RESULT_IN_SUBTHREAD && Looper.myLooper() == null) {
Looper.prepare();
z6 = true;
} else {
z6 = false;
}
if (!a.this.f17737k && a.this.f17738l != null) {
b.this.f17719o.removeCallbacks(a.this.f17738l);
}
List list2 = list;
if (list2 != null && list2.size() > 0) {
Iterator it = list.iterator();
while (it.hasNext()) {
for (CampaignEx campaignEx : ((Frame) it.next()).getCampaigns()) {
b bVar = b.this;
bVar.a(bVar.f17724t, campaignEx);
}
}
HashMap hashMap = new HashMap();
hashMap.put(Long.valueOf(System.currentTimeMillis()), list);
if (b.f17704e.containsKey("1_" + a.this.f17005d)) {
b.f17704e.remove("1_" + a.this.f17005d);
}
b.f17704e.put("1_" + a.this.f17005d, hashMap);
}
if (Looper.myLooper() != null && z6) {
Looper.loop();
}
}
}));
}
public final void a(com.mbridge.msdk.a.a.a aVar) {
this.f17740n = aVar;
}
@Override
public final void a(boolean z6) {
this.f17737k = z6;
}
@Override
public final void a(List<com.mbridge.msdk.foundation.same.net.c.b> list, final CampaignUnit campaignUnit) {
b.this.f17725w = true;
b.this.a(true, this.f17740n, (String) null);
b.this.a(new Thread(new Runnable() {
@Override
public final void run() {
boolean z6;
int i6 = 1;
if (MBridgeConstans.PRELOAD_RESULT_IN_SUBTHREAD && Looper.myLooper() == null) {
Looper.prepare();
z6 = true;
} else {
z6 = false;
}
if (a.this.f17738l != null) {
b.this.f17719o.removeCallbacks(a.this.f17738l);
}
if (b.f17704e.containsKey("0_" + a.this.f17005d)) {
b.f17704e.remove("0_" + a.this.f17005d);
}
if (a.this.f17735i > 0) {
if (campaignUnit.ads.size() <= a.this.f17735i) {
a.this.f17732c = campaignUnit.ads.size();
} else {
a aVar = a.this;
aVar.f17732c = aVar.f17735i;
}
} else if (a.this.f17735i == -1) {
a.this.f17732c = 0;
} else if (a.this.f17735i == -3) {
a.this.f17732c = campaignUnit.ads.size();
} else if (a.this.f17735i == -2) {
if (campaignUnit.getTemplate() == 3) {
if (a.this.f17734h != 0) {
a aVar2 = a.this;
aVar2.f17732c = aVar2.f17734h;
}
} else if (a.this.f17733g != 0) {
a aVar3 = a.this;
aVar3.f17732c = aVar3.f17733g;
}
if (a.this.f17732c <= 0) {
a.this.f17732c = ((Integer) b.f17707h.get(a.this.f17005d)).intValue();
}
}
if (campaignUnit.ads.size() < a.this.f17732c) {
a.this.f17732c = campaignUnit.ads.size();
}
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
for (int i7 = 0; i7 < campaignUnit.ads.size(); i7++) {
CampaignEx campaignEx = campaignUnit.ads.get(i7);
campaignEx.setCampaignUnitId(a.this.f17005d);
if (arrayList.size() < a.this.f17732c && campaignEx.getOfferType() != 99) {
arrayList.add(campaignEx);
if (!TextUtils.isEmpty(campaignEx.getVideoUrlEncode())) {
arrayList2.add(campaignEx);
}
}
b bVar = b.this;
bVar.a(bVar.f17724t, campaignEx);
}
a aVar4 = a.this;
b.a(b.this, arrayList2, aVar4.f17005d);
if (campaignUnit.getAds().get(0) != null) {
i6 = campaignUnit.getAds().get(0).getType();
}
com.mbridge.msdk.mbnative.a.b<String, List<Campaign>> a7 = com.mbridge.msdk.mbnative.a.c.a(i6);
if (a7 != null) {
a7.a((com.mbridge.msdk.mbnative.a.b<String, List<Campaign>>) a.this.f17005d, (String) arrayList);
}
b.a(a.this.f17731b, a.this.f17005d);
if (Looper.myLooper() != null && z6) {
Looper.loop();
}
if (campaignUnit.getAds().get(0) != null) {
com.mbridge.msdk.click.b.a(com.mbridge.msdk.foundation.controller.a.e().g(), campaignUnit.getAds().get(0).getMaitve(), campaignUnit.getAds().get(0).getMaitve_src());
}
}
}));
}
@Override
public final void a(final int i6, final String str) {
b.this.a(new Thread(new Runnable() {
@Override
public final void run() {
boolean z6;
if (MBridgeConstans.PRELOAD_RESULT_IN_SUBTHREAD && Looper.myLooper() == null) {
Looper.prepare();
z6 = true;
} else {
z6 = false;
}
if (!a.this.f17737k) {
if (a.this.f17738l != null) {
b.this.f17719o.removeCallbacks(a.this.f17738l);
}
if (a.this.g() == 1 || a.this.f17739m) {
a aVar = a.this;
b bVar = b.this;
String str2 = str;
int g6 = aVar.g();
a aVar2 = a.this;
bVar.a(str2, g6, aVar2.f17005d, aVar2.f17006e, aVar2.f17740n);
}
} else if (a.this.f17739m) {
a aVar3 = a.this;
b bVar2 = b.this;
String str3 = str;
int g7 = aVar3.g();
a aVar4 = a.this;
bVar2.a(str3, g7, aVar4.f17005d, aVar4.f17006e, aVar4.f17740n);
}
if (i6 == -1) {
b.b(a.this.f17731b, a.this.f17005d);
}
if (Looper.myLooper() != null && z6) {
Looper.loop();
}
}
}));
}
public final void a(Runnable runnable) {
this.f17738l = runnable;
}
}
public class RunnableC0218b implements Runnable {
private int f17749b;
private com.mbridge.msdk.foundation.same.e.c f17750c;
private int f17751d;
private String f17752e;
private String f17753f;
private com.mbridge.msdk.a.a.a f17754g;
private boolean f17755h = false;
public RunnableC0218b(int i6, com.mbridge.msdk.foundation.same.e.c cVar, int i7, String str, String str2) {
this.f17749b = i6;
this.f17750c = cVar;
this.f17751d = i7;
this.f17752e = str;
this.f17753f = str2;
}
public final void a(boolean z6) {
this.f17755h = z6;
}
@Override
public final void run() {
this.f17750c.a(true);
int i6 = this.f17749b;
if (i6 != 1) {
if (i6 == 2) {
b.this.a("REQUEST_TIMEOUT", this.f17751d, this.f17752e, this.f17753f, this.f17754g);
}
} else {
b.this.f17725w = true;
if (this.f17755h || this.f17751d == 1) {
b.this.a("REQUEST_TIMEOUT", this.f17751d, this.f17752e, this.f17753f, this.f17754g);
}
}
}
public final void a(com.mbridge.msdk.a.a.a aVar) {
this.f17754g = aVar;
}
public final void a(String str) {
this.f17752e = str;
}
}
public b() {
if (Looper.myLooper() == null) {
Looper.prepare();
}
this.f17719o = new Handler() {
@Override
public final void handleMessage(Message message) {
}
};
}
public static Map<String, j> c() {
return f17706g;
}
public static Map<String, Integer> d() {
return f17707h;
}
public static Map<String, Integer> e() {
return f17708i;
}
static void a(b bVar, List list, String str) {
if (list != null) {
try {
if (list.size() > 0) {
try {
String str2 = MBMediaView.TAG;
Object invoke = com.mbridge.msdk.videocommon.download.c.class.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
if (invoke != null) {
com.mbridge.msdk.videocommon.download.c.class.getMethod("createUnitCache", Context.class, String.class, List.class, Integer.TYPE, com.mbridge.msdk.videocommon.listener.a.class).invoke(invoke, com.mbridge.msdk.foundation.controller.a.e().g(), str, list, 1, null);
com.mbridge.msdk.videocommon.download.c.class.getMethod("load", String.class).invoke(invoke, str);
}
} catch (Exception unused) {
q.d(f17703d, "please import the videocommon aar");
}
}
} catch (Exception e6) {
q.d(f17703d, com.mbridge.msdk.mbnative.b.a.a(e6));
}
}
}
public static void b(int i6, String str) {
if (f17706g.containsKey(str)) {
j jVar = f17706g.get(str);
if (i6 == 1) {
jVar.b(0);
} else if (i6 == 2) {
jVar.a(0);
}
f17706g.put(str, jVar);
}
}
public static Map<String, Boolean> b() {
return f17705f;
}
public final void a(Map<String, Object> map, int i6) {
String str;
String str2;
String str3;
List<Integer> list;
com.mbridge.msdk.a.a.a aVar;
com.mbridge.msdk.a.a.a aVar2;
String str4;
String str5;
com.mbridge.msdk.mbnative.a.b<String, List<Campaign>> a7;
com.mbridge.msdk.a.a.a aVar3;
com.mbridge.msdk.mbnative.a.b<String, List<Campaign>> a8;
List<Campaign> b6;
Object obj;
try {
this.f17721q = map;
this.f17725w = false;
if (!map.containsKey("unit_id")) {
return;
}
String str6 = (String) map.get("unit_id");
if (f17704e.containsKey(((i6 + 1) % 2) + "_" + str6)) {
if (!f17704e.containsKey(i6 + "_" + str6)) {
return;
}
}
if (TextUtils.isEmpty(str6)) {
return;
}
if (map.containsKey(MBridgeConstans.PREIMAGE)) {
this.f17724t = ((Boolean) map.get(MBridgeConstans.PREIMAGE)).booleanValue();
}
com.mbridge.msdk.click.a aVar4 = this.f17716l;
if (aVar4 == null) {
this.f17716l = new com.mbridge.msdk.click.a(com.mbridge.msdk.foundation.controller.a.e().g(), str6);
} else {
aVar4.a(str6);
}
if (map.containsKey(MBridgeConstans.PROPERTIES_AD_FRAME_NUM)) {
this.f17720p = ((Integer) map.get(MBridgeConstans.PROPERTIES_AD_FRAME_NUM)).intValue();
}
if (map.containsKey(MBridgeConstans.PROPERTIES_API_REUQEST_CATEGORY)) {
this.f17718n = (String) map.get(MBridgeConstans.PROPERTIES_API_REUQEST_CATEGORY);
}
if (f17705f.containsKey(str6) && f17705f.get(str6).booleanValue()) {
Map<String, Map<Long, Object>> map2 = f17704e;
Map<Long, Object> map3 = map2.get(i6 + "_" + str6);
com.mbridge.msdk.b.a b7 = com.mbridge.msdk.b.b.a().b(com.mbridge.msdk.foundation.controller.a.e().h());
if (map3 != null && map3.size() > 0) {
Long next = map3.keySet().iterator().next();
long currentTimeMillis = System.currentTimeMillis();
if (b7 == null) {
b7 = com.mbridge.msdk.b.b.a().b();
}
if (currentTimeMillis - next.longValue() >= b7.B() * 1000) {
map2.remove(str6);
} else if (i6 == 1) {
return;
}
}
}
f17705f.put(str6, Boolean.TRUE);
this.f17727y = 1;
try {
if (map.containsKey("ad_num")) {
int intValue = ((Integer) map.get("ad_num")).intValue();
this.f17727y = intValue;
if (intValue < 1) {
this.f17727y = 1;
}
if (this.f17727y > 10) {
this.f17727y = 10;
}
}
} catch (Exception unused) {
q.d(f17703d, "ADNUM MUST BE INTEGER");
}
f17707h.put(str6, Integer.valueOf(this.f17727y));
com.mbridge.msdk.a.a.a aVar5 = (!map.containsKey(MBridgeConstans.PRELOAD_RESULT_LISTENER) || (obj = map.get(MBridgeConstans.PRELOAD_RESULT_LISTENER)) == null) ? null : new com.mbridge.msdk.a.a.a((PreloadListener) obj);
if (map.containsKey("app_id") && map.containsKey("app_key") && map.containsKey(MBridgeConstans.KEY_WORD)) {
str2 = (String) map.get("app_id");
str = (String) map.get("app_key");
} else {
str = null;
str2 = null;
}
if (this.f17715k == null) {
this.f17715k = new com.mbridge.msdk.b.c();
}
this.f17715k.a(com.mbridge.msdk.foundation.controller.a.e().g(), str2, str, str6);
com.mbridge.msdk.b.d e6 = com.mbridge.msdk.b.b.a().e(str2, str6);
this.f17717m = e6;
if (e6 == null) {
this.f17717m = com.mbridge.msdk.b.d.d(str6);
}
if (map.containsKey(MBridgeConstans.PLACEMENT_ID) && map.get(MBridgeConstans.PLACEMENT_ID) != null) {
String str7 = (String) map.get(MBridgeConstans.PLACEMENT_ID);
if (!TextUtils.isEmpty(str7)) {
str3 = str7;
this.f17722r = this.f17717m.q();
this.f17714c = this.f17717m.r();
this.f17723s = this.f17717m.r();
list = this.f17722r;
if (list != null || list.size() <= 0) {
aVar = aVar5;
if (aVar == null) {
aVar.onPreloadFaild("don't have sorceList");
return;
}
return;
}
this.f17712a = new LinkedList();
Iterator<Integer> it = this.f17722r.iterator();
while (it.hasNext()) {
this.f17712a.add(it.next());
}
List<Integer> list2 = this.f17723s;
if (list2 != null && list2.size() > 0) {
this.f17713b = new LinkedList();
Iterator<Integer> it2 = this.f17723s.iterator();
while (it2.hasNext()) {
this.f17713b.add(Long.valueOf(it2.next().intValue() * 1000));
}
}
try {
if (this.f17722r.contains(1) && i6 == 0) {
try {
aVar3 = aVar5;
str4 = "";
str5 = str6;
try {
a(1, this.f17714c.get(this.f17722r.indexOf(1)).intValue() * 1000, i6, this.f17717m, str6, str3, aVar3, false);
a8 = com.mbridge.msdk.mbnative.a.c.a(1);
} catch (Exception unused2) {
}
} catch (Exception unused3) {
}
if (a8 != null && (b6 = a8.b(str5, 0)) != null) {
if (b6.size() > 0) {
aVar2 = aVar3;
try {
a(true, aVar2, (String) null);
} catch (Exception unused4) {
}
a(i6, this.f17717m, str5, str3, aVar2);
com.mbridge.msdk.b.d dVar = this.f17717m;
f17708i.put(str5, Integer.valueOf(dVar != null ? dVar.u() * this.f17727y : 1));
String str8 = MBMediaView.TAG;
c.a(com.mbridge.msdk.foundation.controller.a.e().g(), str5);
o.b();
if (TextUtils.isEmpty(str5)) {
return;
}
e.a(g.a(com.mbridge.msdk.foundation.controller.a.e().g())).a();
int a9 = a(map.containsKey(MBridgeConstans.NATIVE_INFO) ? (String) map.get(MBridgeConstans.NATIVE_INFO) : null);
if (a9 <= 0) {
a9 = this.f17727y;
}
com.mbridge.msdk.b.d e7 = com.mbridge.msdk.b.b.a().e(str4, str5);
this.f17717m = e7;
if (e7 == null) {
this.f17717m = com.mbridge.msdk.b.d.d(str5);
}
List<Integer> q6 = this.f17717m.q();
this.f17722r = q6;
List<Campaign> b8 = (q6 == null || q6.size() <= 0 || !this.f17722r.contains(1) || (a7 = com.mbridge.msdk.mbnative.a.c.a(1)) == null) ? null : a7.b(str5, a9);
if (b8 != null) {
ArrayList arrayList = new ArrayList();
for (int i7 = 0; i7 < b8.size(); i7++) {
CampaignEx campaignEx = (CampaignEx) b8.get(i7);
if (!TextUtils.isEmpty(campaignEx.getVideoUrlEncode())) {
arrayList.add(campaignEx);
}
}
if (arrayList.size() > 0) {
Object invoke = com.mbridge.msdk.videocommon.download.c.class.getMethod("getInstance", new Class[0]).invoke(null, new Object[0]);
com.mbridge.msdk.videocommon.download.c.class.getMethod("createUnitCache", Context.class, String.class, List.class, Integer.TYPE, com.mbridge.msdk.videocommon.listener.a.class).invoke(invoke, com.mbridge.msdk.foundation.controller.a.e().g(), str5, arrayList, 1, null);
com.mbridge.msdk.videocommon.download.c.class.getMethod("load", String.class).invoke(invoke, str5);
return;
}
return;
}
return;
}
}
aVar2 = aVar3;
a(i6, this.f17717m, str5, str3, aVar2);
com.mbridge.msdk.b.d dVar2 = this.f17717m;
f17708i.put(str5, Integer.valueOf(dVar2 != null ? dVar2.u() * this.f17727y : 1));
String str82 = MBMediaView.TAG;
c.a(com.mbridge.msdk.foundation.controller.a.e().g(), str5);
o.b();
if (TextUtils.isEmpty(str5)) {
}
}
String str822 = MBMediaView.TAG;
c.a(com.mbridge.msdk.foundation.controller.a.e().g(), str5);
o.b();
if (TextUtils.isEmpty(str5)) {
}
} catch (Throwable unused5) {
q.d(f17703d, "init cam cache failed");
return;
}
aVar2 = aVar5;
str4 = "";
str5 = str6;
a(i6, this.f17717m, str5, str3, aVar2);
com.mbridge.msdk.b.d dVar22 = this.f17717m;
f17708i.put(str5, Integer.valueOf(dVar22 != null ? dVar22.u() * this.f17727y : 1));
}
}
str3 = "";
this.f17722r = this.f17717m.q();
this.f17714c = this.f17717m.r();
this.f17723s = this.f17717m.r();
list = this.f17722r;
if (list != null) {
}
aVar = aVar5;
if (aVar == null) {
}
} catch (Exception e8) {
q.d(f17703d, com.mbridge.msdk.mbnative.b.a.a(e8));
}
}
private int a(String str) {
if (str == null) {
return 0;
}
try {
JSONArray jSONArray = new JSONArray(str);
if (jSONArray.length() > 0) {
for (int i6 = 0; i6 < jSONArray.length(); i6++) {
JSONObject jSONObject = (JSONObject) jSONArray.opt(i6);
if (2 == jSONObject.optInt("id", 0)) {
return jSONObject.optInt("ad_num");
}
}
}
} catch (Exception e6) {
q.d(f17703d, com.mbridge.msdk.mbnative.b.a.a(e6));
}
return 0;
}
private void a(int i6, com.mbridge.msdk.b.d dVar, String str, String str2, com.mbridge.msdk.a.a.a aVar) {
Queue<Integer> queue = this.f17712a;
if (queue == null || queue.size() <= 0) {
return;
}
try {
int intValue = this.f17712a.poll().intValue();
long j6 = MBridgeConstans.REQUEST_TIME_OUT;
Queue<Long> queue2 = this.f17713b;
if (queue2 != null && queue2.size() > 0) {
j6 = this.f17713b.poll().longValue();
}
q.b(f17703d, "preload start queue adsource = " + intValue);
a(intValue, j6, str, str2, this.f17721q, i6, dVar, aVar);
} catch (Throwable unused) {
q.d(f17703d, "queue poll exception");
}
}
private void a(int i6, long j6, String str, String str2, Map<String, Object> map, int i7, com.mbridge.msdk.b.d dVar, com.mbridge.msdk.a.a.a aVar) {
com.mbridge.msdk.mbnative.a.b<String, List<Campaign>> a7;
if (i6 != 1 && (a7 = com.mbridge.msdk.mbnative.a.c.a(i6)) != null) {
List<Campaign> b6 = a7.b(str, this.f17727y);
if (b6 != null && b6.size() > 0) {
a(true, aVar, (String) null);
return;
}
}
if (i6 == 1) {
a(i6, j6, i7, dVar, str, str2, aVar, true);
} else if (i6 != 2) {
a(i6, j6, i7, dVar, str, str2, aVar, false);
} else {
a(2, j6, i7, dVar, str, str2, aVar, false);
}
}
private void a(int i6, long j6, int i7, com.mbridge.msdk.b.d dVar, String str, String str2, com.mbridge.msdk.a.a.a aVar, boolean z6) {
int i8;
int i9;
int i10;
int i11;
int i12;
String a7;
a aVar2;
j jVar;
String str3;
int i13;
String str4;
List<Campaign> b6;
List<Campaign> b7;
try {
e.a(g.a(com.mbridge.msdk.foundation.controller.a.e().g())).a();
int o6 = this.f17717m.o();
int p6 = this.f17717m.p();
com.mbridge.msdk.mbnative.e.a.a aVar3 = new com.mbridge.msdk.mbnative.e.a.a(com.mbridge.msdk.foundation.controller.a.e().g());
com.mbridge.msdk.foundation.same.net.h.d dVar2 = new com.mbridge.msdk.foundation.same.net.h.d();
String h6 = com.mbridge.msdk.foundation.controller.a.e().h();
String i14 = com.mbridge.msdk.foundation.controller.a.e().i();
Map<String, Object> map = this.f17721q;
if (map != null && map.containsKey("app_id") && this.f17721q.containsKey("app_key") && this.f17721q.containsKey(MBridgeConstans.KEY_WORD) && this.f17721q.get(MBridgeConstans.KEY_WORD) != null) {
if (this.f17721q.get("app_id") instanceof String) {
h6 = (String) this.f17721q.get("app_id");
}
if (this.f17721q.get("app_key") instanceof String) {
i14 = (String) this.f17721q.get("app_key");
}
String str5 = this.f17721q.get(MBridgeConstans.KEY_WORD) instanceof String ? (String) this.f17721q.get(MBridgeConstans.KEY_WORD) : null;
if (!TextUtils.isEmpty(str5)) {
dVar2.a("smart", l.a(str5));
}
}
String str6 = h6;
String str7 = i14;
dVar2.a("app_id", str6);
dVar2.a("unit_id", str);
dVar2.a(e.a.f1876c, "1");
if (!TextUtils.isEmpty(this.f17718n)) {
dVar2.a("category", this.f17718n);
}
if (!TextUtils.isEmpty(str2)) {
dVar2.a(MBridgeConstans.PLACEMENT_ID, str2);
}
dVar2.a(com.anythink.core.common.g.c.T, SameMD5.getMD5(str6 + str7));
dVar2.a("only_impression", "1");
String e6 = u.e(str);
if (!TextUtils.isEmpty(e6)) {
dVar2.a("j", e6);
}
int intValue = f17707h.get(str).intValue();
if (o6 != f17710u && o6 != 0 && intValue != 0) {
if (i7 == 0) {
com.mbridge.msdk.mbnative.a.b<String, List<Campaign>> a8 = com.mbridge.msdk.mbnative.a.c.a(i6);
if (z6) {
if (a8 != null && (b7 = a8.b(str, intValue)) != null && b7.size() > 0) {
a(true, aVar, (String) null);
return;
} else {
if (this.f17725w) {
a("", i7, str, str2, aVar);
return;
}
return;
}
}
if (i6 != 1 && a8 != null && (b6 = a8.b(str, intValue)) != null && b6.size() > 0) {
a(true, aVar, (String) null);
return;
}
}
if (intValue != 0) {
dVar2.a("ad_num", intValue + "");
}
if (this.f17720p != 0) {
dVar2.a("frame_num", this.f17720p + "");
}
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_INFO)) {
String str8 = (String) this.f17721q.get(MBridgeConstans.NATIVE_INFO);
if (TextUtils.isEmpty(str8)) {
i8 = intValue;
i9 = 0;
i10 = 0;
} else {
q.d(f17703d, "nativeinfo" + str8);
try {
JSONArray jSONArray = new JSONArray(str8);
if (jSONArray.length() > 0) {
str3 = str8;
int i15 = 0;
i10 = 0;
i13 = 0;
while (i15 < jSONArray.length()) {
try {
JSONObject jSONObject = (JSONObject) jSONArray.opt(i15);
int i16 = i10;
i8 = intValue;
try {
int optInt = jSONObject.optInt("id", 0);
if (2 == optInt) {
i10 = jSONObject.optInt("ad_num");
if (o6 > 0) {
try {
jSONObject.put("ad_num", o6);
} catch (JSONException e7) {
e = e7;
q.d(f17703d, com.mbridge.msdk.mbnative.b.a.a(e));
i9 = i13;
str4 = str3;
dVar2.a(MBridgeConstans.NATIVE_INFO, str4);
o6 = i8;
dVar2.a("ad_num", o6 + "");
dVar2.a("ping_mode", "1");
if (com.mbridge.msdk.b.b.a().b(com.mbridge.msdk.foundation.controller.a.e().h()) == null) {
}
if (!NativeController.a(this.f17721q)) {
}
if (f17706g.containsKey(str)) {
}
i11 = 0;
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_INFO)) {
}
if (i6 == i12) {
}
dVar2.a("offset", i11 + "");
dVar2.a("ad_type", "42");
dVar2.a("ad_source_id", i6 + "");
a7 = com.mbridge.msdk.foundation.same.a.d.a(str, f.f3691a);
if (!TextUtils.isEmpty(a7)) {
}
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_VIDEO_WIDTH)) {
}
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_VIDEO_HEIGHT)) {
}
dVar2.a("video_version", MBridgeConstans.NATIVE_VIDEO_VERSION);
aVar2 = new a(i6);
aVar2.f17005d = str;
aVar2.f17006e = str2;
aVar2.f17007f = 42;
aVar2.f(i8);
aVar2.d(i10);
aVar2.e(i9);
aVar2.c(p6);
aVar2.a(aVar);
if (i6 == 1) {
}
aVar2.b(true);
aVar2.a(NativeController.b(this.f17721q));
RunnableC0218b runnableC0218b = new RunnableC0218b(1, aVar2, i7, str, str2);
aVar2.a(runnableC0218b);
aVar2.g(i7);
runnableC0218b.a(aVar);
runnableC0218b.a(z6);
runnableC0218b.a(str);
if (i7 != 0) {
}
this.f17719o.postDelayed(runnableC0218b, j6);
return;
}
} else {
continue;
}
} else {
if (3 == optInt) {
i13 = jSONObject.optInt("ad_num");
if (o6 > 0) {
jSONObject.put("ad_num", o6);
}
}
i10 = i16;
}
i15++;
intValue = i8;
} catch (JSONException e8) {
e = e8;
i10 = i16;
}
} catch (JSONException e9) {
e = e9;
i8 = intValue;
}
}
i8 = intValue;
i9 = i13;
} else {
i8 = intValue;
str3 = str8;
i9 = 0;
i10 = 0;
}
try {
this.f17726x = Math.max(i10, i9);
str4 = jSONArray.toString();
} catch (JSONException e10) {
e = e10;
i13 = i9;
q.d(f17703d, com.mbridge.msdk.mbnative.b.a.a(e));
i9 = i13;
str4 = str3;
dVar2.a(MBridgeConstans.NATIVE_INFO, str4);
o6 = i8;
dVar2.a("ad_num", o6 + "");
dVar2.a("ping_mode", "1");
if (com.mbridge.msdk.b.b.a().b(com.mbridge.msdk.foundation.controller.a.e().h()) == null) {
}
if (!NativeController.a(this.f17721q)) {
}
if (f17706g.containsKey(str)) {
}
i11 = 0;
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_INFO)) {
}
if (i6 == i12) {
}
dVar2.a("offset", i11 + "");
dVar2.a("ad_type", "42");
dVar2.a("ad_source_id", i6 + "");
a7 = com.mbridge.msdk.foundation.same.a.d.a(str, f.f3691a);
if (!TextUtils.isEmpty(a7)) {
}
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_VIDEO_WIDTH)) {
}
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_VIDEO_HEIGHT)) {
}
dVar2.a("video_version", MBridgeConstans.NATIVE_VIDEO_VERSION);
aVar2 = new a(i6);
aVar2.f17005d = str;
aVar2.f17006e = str2;
aVar2.f17007f = 42;
aVar2.f(i8);
aVar2.d(i10);
aVar2.e(i9);
aVar2.c(p6);
aVar2.a(aVar);
if (i6 == 1) {
}
aVar2.b(true);
aVar2.a(NativeController.b(this.f17721q));
RunnableC0218b runnableC0218b2 = new RunnableC0218b(1, aVar2, i7, str, str2);
aVar2.a(runnableC0218b2);
aVar2.g(i7);
runnableC0218b2.a(aVar);
runnableC0218b2.a(z6);
runnableC0218b2.a(str);
if (i7 != 0) {
}
this.f17719o.postDelayed(runnableC0218b2, j6);
return;
}
} catch (JSONException e11) {
e = e11;
i8 = intValue;
str3 = str8;
i10 = 0;
i13 = 0;
}
dVar2.a(MBridgeConstans.NATIVE_INFO, str4);
}
o6 = i8;
} else {
i8 = intValue;
if (o6 == f17711v || o6 == 0) {
o6 = i8;
}
i9 = 0;
i10 = 0;
}
dVar2.a("ad_num", o6 + "");
dVar2.a("ping_mode", "1");
if (com.mbridge.msdk.b.b.a().b(com.mbridge.msdk.foundation.controller.a.e().h()) == null) {
com.mbridge.msdk.b.b.a().b();
}
if (!NativeController.a(this.f17721q)) {
JSONArray a9 = u.a(com.mbridge.msdk.foundation.controller.a.e().g(), str);
if (a9.length() > 0) {
dVar2.a(com.mbridge.msdk.foundation.same.net.h.d.f17062c, u.a(a9));
}
}
if (f17706g.containsKey(str) || (jVar = f17706g.get(str)) == null) {
i11 = 0;
} else if (i6 == 1) {
i11 = jVar.b();
} else if (i6 != 2) {
i11 = jVar.b();
} else {
i11 = jVar.a();
}
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_INFO)) {
i12 = 1;
if (i6 == 1) {
dVar2.a("tnum", this.f17726x + "");
dVar2.a("offset", i11 + "");
dVar2.a("ad_type", "42");
dVar2.a("ad_source_id", i6 + "");
a7 = com.mbridge.msdk.foundation.same.a.d.a(str, f.f3691a);
if (!TextUtils.isEmpty(a7)) {
dVar2.a(com.mbridge.msdk.foundation.same.net.h.d.f17061b, a7);
}
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_VIDEO_WIDTH) && (this.f17721q.get(MBridgeConstans.NATIVE_VIDEO_WIDTH) instanceof Integer)) {
dVar2.a("video_width", ((Integer) this.f17721q.get(MBridgeConstans.NATIVE_VIDEO_WIDTH)).intValue() + "");
}
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_VIDEO_HEIGHT) && (this.f17721q.get(MBridgeConstans.NATIVE_VIDEO_HEIGHT) instanceof Integer)) {
dVar2.a("video_height", ((Integer) this.f17721q.get(MBridgeConstans.NATIVE_VIDEO_HEIGHT)).intValue() + "");
}
dVar2.a("video_version", MBridgeConstans.NATIVE_VIDEO_VERSION);
aVar2 = new a(i6);
aVar2.f17005d = str;
aVar2.f17006e = str2;
aVar2.f17007f = 42;
aVar2.f(i8);
aVar2.d(i10);
aVar2.e(i9);
aVar2.c(p6);
aVar2.a(aVar);
if (i6 == 1 || z6) {
aVar2.b(true);
}
aVar2.a(NativeController.b(this.f17721q));
RunnableC0218b runnableC0218b22 = new RunnableC0218b(1, aVar2, i7, str, str2);
aVar2.a(runnableC0218b22);
aVar2.g(i7);
runnableC0218b22.a(aVar);
runnableC0218b22.a(z6);
runnableC0218b22.a(str);
if (i7 != 0) {
if (com.mbridge.msdk.foundation.same.net.g.d.c().b()) {
aVar3.b(1, com.mbridge.msdk.foundation.same.net.g.d.c().f17034h, dVar2, aVar2);
} else {
aVar3.a(1, com.mbridge.msdk.foundation.same.net.g.d.c().f17032f, dVar2, aVar2);
}
} else if (i7 == 1) {
aVar3.a(1, com.mbridge.msdk.foundation.same.net.g.d.c().f17033g, dVar2, aVar2);
}
this.f17719o.postDelayed(runnableC0218b22, j6);
return;
}
} else {
i12 = 1;
}
if (i6 == i12) {
dVar2.a("tnum", this.f17727y + "");
}
dVar2.a("offset", i11 + "");
dVar2.a("ad_type", "42");
dVar2.a("ad_source_id", i6 + "");
a7 = com.mbridge.msdk.foundation.same.a.d.a(str, f.f3691a);
if (!TextUtils.isEmpty(a7)) {
}
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_VIDEO_WIDTH)) {
dVar2.a("video_width", ((Integer) this.f17721q.get(MBridgeConstans.NATIVE_VIDEO_WIDTH)).intValue() + "");
}
if (this.f17721q.containsKey(MBridgeConstans.NATIVE_VIDEO_HEIGHT)) {
dVar2.a("video_height", ((Integer) this.f17721q.get(MBridgeConstans.NATIVE_VIDEO_HEIGHT)).intValue() + "");
}
dVar2.a("video_version", MBridgeConstans.NATIVE_VIDEO_VERSION);
aVar2 = new a(i6);
aVar2.f17005d = str;
aVar2.f17006e = str2;
aVar2.f17007f = 42;
aVar2.f(i8);
aVar2.d(i10);
aVar2.e(i9);
aVar2.c(p6);
aVar2.a(aVar);
if (i6 == 1) {
}
aVar2.b(true);
aVar2.a(NativeController.b(this.f17721q));
RunnableC0218b runnableC0218b222 = new RunnableC0218b(1, aVar2, i7, str, str2);
aVar2.a(runnableC0218b222);
aVar2.g(i7);
runnableC0218b222.a(aVar);
runnableC0218b222.a(z6);
runnableC0218b222.a(str);
if (i7 != 0) {
}
this.f17719o.postDelayed(runnableC0218b222, j6);
return;
}
a("The request was refused", i7, str, str2, aVar);
} catch (Exception e12) {
String str9 = f17703d;
q.d(str9, com.mbridge.msdk.mbnative.b.a.a(e12));
q.d(str9, e12.getMessage());
}
}
public static void a(int i6, String str) {
j jVar;
if (f17706g.containsKey(str)) {
jVar = f17706g.get(str);
} else {
jVar = new j();
}
int intValue = f17707h.get(str).intValue();
int intValue2 = f17708i.containsKey(str) ? f17708i.get(str).intValue() : 1;
if (i6 == 1) {
int b6 = intValue + jVar.b();
jVar.b(b6 <= intValue2 ? b6 : 0);
} else if (i6 == 2) {
int a7 = intValue + jVar.a();
jVar.a(a7 <= intValue2 ? a7 : 0);
}
f17706g.put(str, jVar);
}
public final void a(String str, int i6, String str2, String str3, com.mbridge.msdk.a.a.a aVar) {
Log.e(f17703d, str);
try {
Queue<Integer> queue = this.f17712a;
if ((queue != null && queue.size() <= 0) || this.f17712a == null) {
a(false, aVar, str);
} else {
a(i6, this.f17717m, str2, str3, aVar);
}
} catch (Exception e6) {
if (MBridgeConstans.DEBUG) {
e6.printStackTrace();
}
}
}
public static Map<String, Map<Long, Object>> a() {
return f17704e;
}
public final void a(boolean z6, com.mbridge.msdk.a.a.a aVar, String str) {
if (z6) {
if (aVar == null || aVar.a()) {
return;
}
aVar.a(true);
aVar.onPreloadSucceed();
return;
}
if (aVar == null || aVar.a()) {
return;
}
aVar.a(true);
aVar.onPreloadFaild(str);
}
public final void a(boolean z6, Campaign campaign) {
if (campaign == null) {
return;
}
if (z6 && campaign.getIconDrawable() == null) {
campaign.loadIconUrlAsyncWithBlock(null);
}
if (z6 && campaign.getBigDrawable() == null) {
campaign.loadImageUrlAsyncWithBlock(null);
}
}
public final void a(Thread thread) {
if (!MBridgeConstans.PRELOAD_RESULT_IN_SUBTHREAD) {
thread.run();
} else {
thread.start();
}
}
}