package com.mbridge.msdk.a; import android.content.Context; import android.text.TextUtils; import android.webkit.WebView; import com.iab.omid.library.mmadbridge.Omid; import com.iab.omid.library.mmadbridge.adsession.AdSession; import com.iab.omid.library.mmadbridge.adsession.AdSessionConfiguration; import com.iab.omid.library.mmadbridge.adsession.AdSessionContext; import com.iab.omid.library.mmadbridge.adsession.CreativeType; import com.iab.omid.library.mmadbridge.adsession.ImpressionType; import com.iab.omid.library.mmadbridge.adsession.Owner; import com.iab.omid.library.mmadbridge.adsession.Partner; import com.iab.omid.library.mmadbridge.adsession.VerificationScriptResource; import com.mbridge.msdk.MBridgeConstans; import com.mbridge.msdk.foundation.entity.CampaignEx; import com.mbridge.msdk.foundation.same.DomainNameUtils; import com.mbridge.msdk.foundation.same.b.c; import com.mbridge.msdk.foundation.same.b.e; import com.mbridge.msdk.foundation.same.report.h; import com.mbridge.msdk.foundation.tools.ad; import com.mbridge.msdk.foundation.tools.af; import com.mbridge.msdk.out.MBConfiguration; import com.mbridge.msdk.playercommon.exoplayer2.source.chunk.ChunkedTrackBlacklistUtil; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes4.dex */ public final class b { public static final String a = DomainNameUtils.VERIFICATION_URL; public static AdSession a(Context context, boolean z, String str, String str2, String str3, String str4, String str5, String str6) { Partner createPartner; CreativeType creativeType; ImpressionType impressionType; Owner owner; if (TextUtils.isEmpty(MBridgeConstans.OMID_JS_SERVICE_CONTENT)) { MBridgeConstans.OMID_JS_SERVICE_CONTENT = a(); } AdSession adSession = null; if (TextUtils.isEmpty(MBridgeConstans.OMID_JS_SERVICE_CONTENT) || TextUtils.isEmpty(str)) { af.a("OMSDK", "createNativeAdSession: TextUtils.isEmpty(omid) = " + TextUtils.isEmpty(str) + " TextUtils.isEmpty(MIntegralConstans.OMID_JS_SERVICE_CONTENT) = " + TextUtils.isEmpty(MBridgeConstans.OMID_JS_SERVICE_CONTENT)); new h(context).a(str2, str6, str3, str4, "failed, OMID_JS_SERVICE_CONTENT null or omid null"); return null; } try { c(context); createPartner = Partner.createPartner("Mintegral", MBConfiguration.SDK_VERSION); creativeType = z ? CreativeType.NATIVE_DISPLAY : CreativeType.VIDEO; impressionType = ImpressionType.BEGIN_TO_RENDER; owner = Owner.NATIVE; } catch (IllegalArgumentException e) { e = e; } catch (Exception e2) { e = e2; } try { adSession = AdSession.createAdSession(AdSessionConfiguration.createAdSessionConfiguration(creativeType, impressionType, owner, z ? Owner.NONE : owner, false), AdSessionContext.createNativeAdSessionContext(createPartner, MBridgeConstans.OMID_JS_SERVICE_CONTENT, a(str, context, str2, str3, str4, str6), str5, str2)); af.a("OMSDK", "adSession create success"); return adSession; } catch (IllegalArgumentException e3) { e = e3; af.b("OMSDK", e.getMessage()); new h(context).a(str2, str6, str3, str4, "failed, exception " + e.getMessage()); return adSession; } catch (Exception e4) { e = e4; af.b("OMSDK", e.getMessage()); new h(context).a(str2, str6, str3, str4, "failed, exception " + e.getMessage()); return adSession; } } private static String a() { try { return ad.b(new File(e.a(c.MBRIDGE_OTHER), "/omsdk/om_js_content.txt")); } catch (Exception e) { af.a("OMSDK", e.getMessage()); return ""; } } private static void c(Context context) { if (Omid.isActive()) { return; } Omid.activate(context); } private static List a(String str, Context context, String str2, String str3, String str4, String str5) { VerificationScriptResource createVerificationScriptResourceWithParameters; ArrayList arrayList = new ArrayList(); try { JSONArray jSONArray = new JSONArray(str); if (str != null) { for (int i = 0; i < jSONArray.length(); i++) { JSONObject optJSONObject = jSONArray.optJSONObject(i); String optString = optJSONObject.optString("vkey", ""); URL url = new URL(optJSONObject.optString("et_url", "")); String optString2 = optJSONObject.optString("verification_p", ""); if (TextUtils.isEmpty(optString2)) { if (TextUtils.isEmpty(optString)) { createVerificationScriptResourceWithParameters = VerificationScriptResource.createVerificationScriptResourceWithoutParameters(url); } else { createVerificationScriptResourceWithParameters = VerificationScriptResource.createVerificationScriptResourceWithoutParameters(url); } } else { createVerificationScriptResourceWithParameters = VerificationScriptResource.createVerificationScriptResourceWithParameters(optString, url, optString2); } arrayList.add(createVerificationScriptResourceWithParameters); } } } catch (IllegalArgumentException e) { af.b("OMSDK", e.getMessage()); new h(context).a(str2, str5, str3, str4, "failed, exception " + e.getMessage()); } catch (MalformedURLException e2) { af.b("OMSDK", e2.getMessage()); new h(context).a(str2, str5, str3, str4, "failed, exception " + e2.getMessage()); } catch (JSONException e3) { af.b("OMSDK", e3.getMessage()); new h(context).a(str2, str5, str3, str4, "failed, exception " + e3.getMessage()); } return arrayList; } public static AdSession a(Context context, WebView webView, String str, CampaignEx campaignEx) { if (TextUtils.isEmpty(MBridgeConstans.OMID_JS_SERVICE_CONTENT)) { MBridgeConstans.OMID_JS_SERVICE_CONTENT = a(); } if (TextUtils.isEmpty(MBridgeConstans.OMID_JS_H5_CONTENT)) { MBridgeConstans.OMID_JS_H5_CONTENT = b(); } if (TextUtils.isEmpty(MBridgeConstans.OMID_JS_SERVICE_CONTENT) || TextUtils.isEmpty(campaignEx.getOmid())) { af.a("OMSDK", "createNativeAdSession: TextUtils.isEmpty(omid) = " + TextUtils.isEmpty(campaignEx.getOmid()) + " TextUtils.isEmpty(MIntegralConstans.OMID_JS_SERVICE_CONTENT) = " + TextUtils.isEmpty(MBridgeConstans.OMID_JS_SERVICE_CONTENT)); new h(context).a(campaignEx.getRequestId(), campaignEx.getRequestIdNotice(), campaignEx.getId(), campaignEx.getCampaignUnitId(), "failed, OMID_JS_SERVICE_CONTENT null or omid null"); return null; } CreativeType creativeType = CreativeType.DEFINED_BY_JAVASCRIPT; c(context); AdSession createAdSession = AdSession.createAdSession(AdSessionConfiguration.createAdSessionConfiguration(CreativeType.HTML_DISPLAY, ImpressionType.BEGIN_TO_RENDER, Owner.NATIVE, Owner.NONE, false), AdSessionContext.createHtmlAdSessionContext(Partner.createPartner("Mintegral", MBConfiguration.SDK_VERSION), webView, null, null)); createAdSession.registerAdView(webView); return createAdSession; } private static String b() { try { File file = new File(e.a(c.MBRIDGE_OTHER), "/omsdk/om_js_h5_content.txt"); return file.exists() ? ad.b(file) : ""; } catch (Exception e) { af.a("OMSDK", e.getMessage()); return ""; } } public static void a(final Context context) { if (TextUtils.isEmpty(MBridgeConstans.OMID_JS_SERVICE_URL)) { MBridgeConstans.OMID_JS_SERVICE_CONTENT = ""; new h(context).a("", "", "", "", "fetch OM failed, OMID_JS_SERVICE_URL null"); } else { if (context == null) { return; } try { new a(context.getApplicationContext()).get(0, MBridgeConstans.OMID_JS_SERVICE_URL, (com.mbridge.msdk.foundation.same.net.f.e) null, new com.mbridge.msdk.foundation.same.net.b.a() { // from class: com.mbridge.msdk.a.b.1 @Override // com.mbridge.msdk.foundation.same.net.b.a public final void b(String str) { MBridgeConstans.OMID_JS_SERVICE_CONTENT = str; b.a(str); } @Override // com.mbridge.msdk.foundation.same.net.b.a public final void a(String str) { af.a("OMSDK", "fetch OMJSContent failed, errorCode = " + str); new h(context).a("", "", "", "", "fetch OM failed, request failed"); } }, "om_sdk", ChunkedTrackBlacklistUtil.DEFAULT_TRACK_BLACKLIST_MS); } catch (Exception e) { af.b("OMSDK", e.getMessage()); } } } public static void a(final String str) { new Thread(new Runnable() { // from class: com.mbridge.msdk.a.b.2 @Override // java.lang.Runnable public final void run() { try { File file = new File(e.a(c.MBRIDGE_OTHER), "/omsdk/om_js_content.txt"); if (file.exists()) { file.delete(); } ad.a(str.getBytes(), file); } catch (Exception e) { af.a("OMSDK", e.getMessage()); } } }).start(); } public static void b(final Context context) { if (TextUtils.isEmpty(MBridgeConstans.OMID_JS_H5_URL)) { MBridgeConstans.OMID_JS_H5_CONTENT = ""; new h(context).a("", "", "", "", "fetch OM failed, OMID_JS_H5_URL null"); } else { if (context == null) { return; } try { new a(context.getApplicationContext()).get(0, MBridgeConstans.OMID_JS_H5_URL, (com.mbridge.msdk.foundation.same.net.f.e) null, new com.mbridge.msdk.foundation.same.net.b.a() { // from class: com.mbridge.msdk.a.b.3 @Override // com.mbridge.msdk.foundation.same.net.b.a public final void b(String str) { MBridgeConstans.OMID_JS_H5_CONTENT = str; b.b(str); } @Override // com.mbridge.msdk.foundation.same.net.b.a public final void a(String str) { af.a("OMSDK", "fetch OMJSH5Content failed, errorCode = " + str); new h(context).a("", "", "", "", "fetch OM H5 failed, request failed"); } }, "om_sdk", ChunkedTrackBlacklistUtil.DEFAULT_TRACK_BLACKLIST_MS); } catch (Exception e) { af.b("OMSDK", e.getMessage()); } } } public static void b(final String str) { new Thread(new Runnable() { // from class: com.mbridge.msdk.a.b.4 @Override // java.lang.Runnable public final void run() { try { File file = new File(e.a(c.MBRIDGE_OTHER), "/omsdk/om_js_h5_content.txt"); if (file.exists()) { file.delete(); } ad.a(str.getBytes(), file); } catch (Exception e) { af.a("OMSDK", e.getMessage()); } } }).start(); } public static String c(String str) { if (TextUtils.isEmpty(MBridgeConstans.OMID_JS_H5_CONTENT)) { MBridgeConstans.OMID_JS_H5_CONTENT = b(); } return TextUtils.isEmpty(str) ? str : str.replace("/*OMSDK_INSERT_HERE*/", MBridgeConstans.OMID_JS_H5_CONTENT).replace("[INSERT RESOURCE URL]", a); } }