翰林优商.apk(点击下载) / a.java


package com.mbridge.msdk.mbbanner.common.bridge;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Base64;
import com.baidu.mobads.sdk.api.IAdInterListener;
import com.bytedance.sdk.openadsdk.api.plugin.PluginConstants;
import com.mbridge.msdk.MBridgeConstans;
import com.mbridge.msdk.foundation.db.i;
import com.mbridge.msdk.foundation.db.l;
import com.mbridge.msdk.foundation.db.s;
import com.mbridge.msdk.foundation.download.download.H5DownLoadManager;
import com.mbridge.msdk.foundation.entity.CampaignEx;
import com.mbridge.msdk.foundation.entity.o;
import com.mbridge.msdk.foundation.tools.d;
import com.mbridge.msdk.foundation.tools.w;
import com.mbridge.msdk.foundation.tools.z;
import com.mbridge.msdk.mbjscommon.bridge.b;
import com.mbridge.msdk.mbjscommon.windvane.h;
import com.sigmob.sdk.base.mta.PointCategory;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: BannerJSBridgeImpl */
public final class a extends com.mbridge.msdk.mbjscommon.bridge.a {
    private WeakReference<Context> b;
    private List<CampaignEx> c;
    private String d;
    private String e;
    private int f;
    private com.mbridge.msdk.mbbanner.common.b.a g;
    private BannerExpandDialog h;
    private boolean i = false;

    public a(Context context, String str, String str2) {
        this.d = str;
        this.e = str2;
        this.b = new WeakReference<>(context);
    }

    public final void a(com.mbridge.msdk.mbbanner.common.b.a aVar) {
        if (aVar != null) {
            this.g = aVar;
        }
    }

    public final void a(List<CampaignEx> list) {
        this.c = list;
    }

    public final void a(int i2) {
        this.f = i2;
    }

    public final void a() {
        if (this.g != null) {
            this.g = null;
        }
        if (this.h != null) {
            this.h = null;
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.bridge.a, com.mbridge.msdk.mbjscommon.bridge.c
    public final void c(Object obj, String str) {
        if (obj != null) {
            try {
                int optInt = new JSONObject(str).optInt("isReady", 1);
                h.a().a(obj, b.a(0));
                com.mbridge.msdk.mbbanner.common.b.a aVar = this.g;
                if (aVar != null) {
                    aVar.b(optInt);
                }
            } catch (Throwable th) {
                w.b("BannerJSBridgeImpl", "readyStatus", th);
            }
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.bridge.a, com.mbridge.msdk.mbjscommon.bridge.c
    public final void a(Object obj, String str) {
        w.d("BannerJSBridgeImpl", "BANNER INIT INVOKE");
        try {
            JSONObject jSONObject = new JSONObject();
            d dVar = new d(com.mbridge.msdk.foundation.controller.a.f().j());
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("dev_close_state", this.f);
            jSONObject.put("sdkSetting", jSONObject2);
            jSONObject.put("device", dVar.a());
            jSONObject.put("campaignList", CampaignEx.parseCamplistToJson(this.c));
            com.mbridge.msdk.c.d e2 = com.mbridge.msdk.c.b.a().e(com.mbridge.msdk.foundation.controller.a.f().k(), this.e);
            if (e2 == null) {
                e2 = com.mbridge.msdk.c.d.d(this.e);
            }
            if (!TextUtils.isEmpty(this.d)) {
                e2.g(this.d);
            }
            jSONObject.put("unitSetting", e2.t());
            String c2 = com.mbridge.msdk.c.b.a().c(com.mbridge.msdk.foundation.controller.a.f().k());
            if (!TextUtils.isEmpty(c2)) {
                jSONObject.put("appSetting", new JSONObject(c2));
            }
            h.a().a(obj, Base64.encodeToString(jSONObject.toString().getBytes(), 2));
        } catch (Throwable th) {
            w.b("BannerJSBridgeImpl", PointCategory.INIT, th);
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.bridge.a, com.mbridge.msdk.mbjscommon.bridge.c
    public final void b(Object obj, String str) {
        w.d("BannerJSBridgeImpl", "click");
        try {
            List<CampaignEx> list = this.c;
            if (list != null) {
                CampaignEx campaignEx = null;
                if (list != null && list.size() > 0) {
                    campaignEx = this.c.get(0);
                }
                if (!TextUtils.isEmpty(str)) {
                    try {
                        JSONObject campaignToJsonObject = CampaignEx.campaignToJsonObject(campaignEx);
                        JSONObject jSONObject = new JSONObject(str).getJSONObject("pt");
                        Iterator<String> keys = jSONObject.keys();
                        while (keys.hasNext()) {
                            String next = keys.next();
                            campaignToJsonObject.put(next, jSONObject.getString(next));
                        }
                        CampaignEx parseCampaignWithBackData = CampaignEx.parseCampaignWithBackData(campaignToJsonObject);
                        String optString = campaignToJsonObject.optString("unitId");
                        if (!TextUtils.isEmpty(optString)) {
                            parseCampaignWithBackData.setCampaignUnitId(optString);
                        }
                        campaignEx = parseCampaignWithBackData;
                    } catch (JSONException e2) {
                        e2.printStackTrace();
                    }
                    com.mbridge.msdk.mbbanner.common.b.a aVar = this.g;
                    if (aVar != null) {
                        aVar.a(campaignEx);
                    }
                }
            }
        } catch (Throwable th) {
            w.b("BannerJSBridgeImpl", "click", th);
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.bridge.a, com.mbridge.msdk.mbjscommon.bridge.c
    public final void d(Object obj, String str) {
        w.d("BannerJSBridgeImpl", "toggleCloseBtn");
        try {
            if (!TextUtils.isEmpty(str)) {
                int optInt = new JSONObject(str).optInt("state");
                com.mbridge.msdk.mbbanner.common.b.a aVar = this.g;
                if (aVar != null) {
                    aVar.a(optInt);
                }
            }
        } catch (Throwable th) {
            w.b("BannerJSBridgeImpl", "toggleCloseBtn", th);
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.bridge.a, com.mbridge.msdk.mbjscommon.bridge.c
    public final void e(Object obj, String str) {
        w.d("BannerJSBridgeImpl", "triggerCloseBtn");
        try {
            if (!TextUtils.isEmpty(str)) {
                String optString = new JSONObject(str).optString("state");
                com.mbridge.msdk.mbbanner.common.b.a aVar = this.g;
                if (aVar != null) {
                    aVar.a(optString);
                }
                h.a().a(obj, b.a(0));
            }
        } catch (Throwable th) {
            w.b("BannerJSBridgeImpl", "triggerCloseBtn", th);
            h.a().a(obj, b.a(-1));
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.bridge.a, com.mbridge.msdk.mbjscommon.bridge.c
    public final void i(Object obj, String str) {
        w.a("BannerJSBridgeImpl", "sendImpressions:" + str);
        try {
            if (!TextUtils.isEmpty(str)) {
                JSONArray jSONArray = new JSONArray(str);
                final ArrayList arrayList = new ArrayList();
                for (int i2 = 0; i2 < jSONArray.length(); i2++) {
                    String string = jSONArray.getString(i2);
                    for (CampaignEx campaignEx : this.c) {
                        if (campaignEx.getId().equals(string)) {
                            com.mbridge.msdk.foundation.same.a.d.a(this.e, campaignEx, IAdInterListener.AdProdType.PRODUCT_BANNER);
                            arrayList.add(string);
                        }
                    }
                }
                new Thread(new Runnable() {
                    /* class com.mbridge.msdk.mbbanner.common.bridge.a.AnonymousClass1 */

                    public final void run() {
                        try {
                            l a2 = l.a(i.a(com.mbridge.msdk.foundation.controller.a.f().j()));
                            Iterator it = arrayList.iterator();
                            while (it.hasNext()) {
                                a2.b((String) it.next());
                            }
                        } catch (Exception unused) {
                            w.d("BannerJSBridgeImpl", "campain can't insert db");
                        }
                    }
                }).start();
            }
        } catch (Throwable th) {
            w.b("BannerJSBridgeImpl", "sendImpressions", th);
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.mraid.b
    public final void open(String str) {
        w.d("BannerJSBridgeImpl", "open");
        try {
            w.d("BannerJSBridgeImpl", str);
            if (this.c.size() > 1) {
                com.mbridge.msdk.foundation.controller.a.f().j().startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str)));
                str = null;
            }
            com.mbridge.msdk.mbbanner.common.b.a aVar = this.g;
            if (aVar != null) {
                aVar.a(true, str);
            }
        } catch (Throwable th) {
            w.b("BannerJSBridgeImpl", "open", th);
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.mraid.b
    public final void close() {
        w.d("BannerJSBridgeImpl", "close");
        try {
            com.mbridge.msdk.mbbanner.common.b.a aVar = this.g;
            if (aVar != null) {
                aVar.a();
            }
        } catch (Throwable th) {
            w.b("BannerJSBridgeImpl", "close", th);
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.mraid.b
    public final void unload() {
        close();
    }

    @Override // com.mbridge.msdk.mbjscommon.mraid.b
    public final CampaignEx getMraidCampaign() {
        List<CampaignEx> list = this.c;
        if (list == null || list.size() <= 0) {
            return null;
        }
        return this.c.get(0);
    }

    @Override // com.mbridge.msdk.mbjscommon.mraid.b
    public final void useCustomClose(boolean z) {
        int i2 = z ? 2 : 1;
        try {
            com.mbridge.msdk.mbbanner.common.b.a aVar = this.g;
            if (aVar != null) {
                aVar.a(i2);
            }
        } catch (Throwable th) {
            w.b("BannerJSBridgeImpl", "useCustomClose", th);
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.mraid.b
    public final void expand(String str, boolean z) {
        Context context;
        String str2 = "";
        try {
            if (getMraidCampaign() != null) {
                if (TextUtils.isEmpty(getMraidCampaign().getBannerHtml())) {
                    str2 = getMraidCampaign().getBannerUrl();
                } else {
                    str2 = "file:////" + getMraidCampaign().getBannerHtml();
                }
            }
            Bundle bundle = new Bundle();
            if (!TextUtils.isEmpty(str)) {
                str2 = str;
            }
            bundle.putString("url", str2);
            bundle.putBoolean("shouldUseCustomClose", z);
            WeakReference<Context> weakReference = this.b;
            if (!(weakReference == null || (context = weakReference.get()) == null)) {
                BannerExpandDialog bannerExpandDialog = this.h;
                if (bannerExpandDialog == null || !bannerExpandDialog.isShowing()) {
                    BannerExpandDialog bannerExpandDialog2 = new BannerExpandDialog(context, bundle, this.g);
                    this.h = bannerExpandDialog2;
                    bannerExpandDialog2.setCampaignList(this.e, this.c);
                    this.h.show();
                } else {
                    return;
                }
            }
            com.mbridge.msdk.mbbanner.common.b.a aVar = this.g;
            if (aVar != null) {
                aVar.a(true);
            }
            com.mbridge.msdk.mbbanner.common.d.a.a(this.e, getMraidCampaign(), str);
        } catch (Throwable th) {
            w.b("BannerJSBridgeImpl", "expand", th);
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.bridge.a, com.mbridge.msdk.mbjscommon.bridge.c
    public final void j(Object obj, String str) {
        if (TextUtils.isEmpty(str)) {
            b.a(obj, "params is empty");
            return;
        }
        try {
            a(obj, new JSONObject(str));
        } catch (Throwable th) {
            w.a("BannerJSBridgeImpl", th.getMessage());
        }
    }

    private static void a(Object obj, JSONObject jSONObject) {
        String str;
        String str2;
        Throwable th;
        String str3;
        JSONException e2;
        String str4;
        int i2;
        String str5;
        String str6;
        String str7;
        JSONObject jSONObject2 = new JSONObject();
        String str8 = "message";
        String str9 = PluginConstants.KEY_ERROR_CODE;
        int i3 = 1;
        if (jSONObject == null) {
            try {
                jSONObject2.put(str9, 1);
                jSONObject2.put(str8, "params is null");
                h.a().a(obj, Base64.encodeToString(jSONObject2.toString().getBytes(), 2));
            } catch (JSONException e3) {
                w.a("BannerJSBridgeImpl", e3.getMessage());
            }
        } else {
            try {
                jSONObject2.put(str9, 0);
                jSONObject2.put(str8, "");
                JSONArray jSONArray = jSONObject.getJSONArray("resource");
                if (jSONArray == null || jSONArray.length() <= 0) {
                    str3 = str8;
                    str2 = str9;
                    try {
                        jSONObject2.put(str2, 1);
                        str = str3;
                        try {
                            jSONObject2.put(str, "resource is null");
                            h.a().a(obj, Base64.encodeToString(jSONObject2.toString().getBytes(), 2));
                        } catch (JSONException e4) {
                            e2 = e4;
                        }
                    } catch (JSONException e5) {
                        e2 = e5;
                        str = str3;
                        try {
                            w.a("BannerJSBridgeImpl", e2.getMessage());
                        } catch (Throwable th2) {
                            th = th2;
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        str = str3;
                        try {
                            jSONObject2.put(str2, 1);
                            jSONObject2.put(str, th.getLocalizedMessage());
                            h.a().a(obj, Base64.encodeToString(jSONObject2.toString().getBytes(), 2));
                        } catch (JSONException e6) {
                            w.a("BannerJSBridgeImpl", e6.getMessage());
                        }
                    }
                } else {
                    JSONArray jSONArray2 = new JSONArray();
                    int length = jSONArray.length();
                    int i4 = 0;
                    while (i4 < length) {
                        JSONObject jSONObject3 = jSONArray.getJSONObject(i4);
                        String optString = jSONObject3.optString("ref", "");
                        int i5 = jSONObject3.getInt("type");
                        JSONObject jSONObject4 = new JSONObject();
                        if (i5 != i3 || TextUtils.isEmpty(optString)) {
                            str3 = str8;
                            str4 = str9;
                            i2 = length;
                            if (i5 == 2 && !TextUtils.isEmpty(optString)) {
                                JSONObject jSONObject5 = new JSONObject();
                                jSONObject5.put("type", 2);
                                if (H5DownLoadManager.getInstance().getResAddress(optString) == null) {
                                    str7 = "";
                                } else {
                                    str7 = H5DownLoadManager.getInstance().getH5ResAddress(optString);
                                }
                                jSONObject5.put("path", str7);
                                jSONObject4.put(optString, jSONObject5);
                                jSONArray2.put(jSONObject4);
                            } else if (i5 == 3 && !TextUtils.isEmpty(optString)) {
                                try {
                                    File file = new File(optString);
                                    if (file.exists() && file.isFile() && file.canRead()) {
                                        w.a("BannerJSBridgeImpl", "getFileInfo Mraid file " + optString);
                                        str6 = "file:////" + optString;
                                        JSONObject jSONObject6 = new JSONObject();
                                        jSONObject6.put("type", 3);
                                        jSONObject6.put("path", str6);
                                        jSONObject4.put(optString, jSONObject6);
                                        jSONArray2.put(jSONObject4);
                                    }
                                } catch (Throwable th4) {
                                    if (MBridgeConstans.DEBUG) {
                                        th4.printStackTrace();
                                    }
                                }
                                str6 = "";
                                JSONObject jSONObject62 = new JSONObject();
                                jSONObject62.put("type", 3);
                                jSONObject62.put("path", str6);
                                jSONObject4.put(optString, jSONObject62);
                                jSONArray2.put(jSONObject4);
                            } else if (i5 == 4 && !TextUtils.isEmpty(optString)) {
                                JSONObject jSONObject7 = new JSONObject();
                                jSONObject7.put("type", 4);
                                if (z.a(optString) == null) {
                                    str5 = "";
                                } else {
                                    str5 = z.a(optString);
                                }
                                jSONObject7.put("path", str5);
                                jSONObject4.put(optString, jSONObject7);
                                jSONArray2.put(jSONObject4);
                            }
                        } else {
                            JSONObject jSONObject8 = new JSONObject();
                            o a = s.a(i.a(com.mbridge.msdk.foundation.controller.a.f().j())).a(optString);
                            if (a != null) {
                                i2 = length;
                                w.a("BannerJSBridgeImpl", "VideoBean not null");
                                jSONObject8.put("type", 1);
                                str3 = str8;
                                try {
                                    jSONObject8.put("videoDataLength", a.c());
                                    String e7 = a.e();
                                    str4 = str9;
                                    if (TextUtils.isEmpty(e7)) {
                                        try {
                                            w.a("BannerJSBridgeImpl", "VideoPath null");
                                            jSONObject8.put("path", "");
                                            jSONObject8.put("path4Web", "");
                                        } catch (Throwable th5) {
                                            th = th5;
                                            str = str3;
                                            str2 = str4;
                                            jSONObject2.put(str2, 1);
                                            jSONObject2.put(str, th.getLocalizedMessage());
                                            h.a().a(obj, Base64.encodeToString(jSONObject2.toString().getBytes(), 2));
                                        }
                                    } else {
                                        w.a("BannerJSBridgeImpl", "VideoPath not null");
                                        jSONObject8.put("path", e7);
                                        jSONObject8.put("path4Web", e7);
                                    }
                                    if (a.d() == 5) {
                                        jSONObject8.put("downloaded", 1);
                                    } else {
                                        jSONObject8.put("downloaded", 0);
                                    }
                                    jSONObject4.put(optString, jSONObject8);
                                    jSONArray2.put(jSONObject4);
                                } catch (Throwable th6) {
                                    th = th6;
                                    str2 = str9;
                                    str = str3;
                                    jSONObject2.put(str2, 1);
                                    jSONObject2.put(str, th.getLocalizedMessage());
                                    h.a().a(obj, Base64.encodeToString(jSONObject2.toString().getBytes(), 2));
                                }
                            } else {
                                str3 = str8;
                                str4 = str9;
                                i2 = length;
                                w.a("BannerJSBridgeImpl", "VideoBean null");
                            }
                        }
                        i4++;
                        jSONArray = jSONArray;
                        length = i2;
                        str8 = str3;
                        str9 = str4;
                        i3 = 1;
                    }
                    jSONObject2.put("resource", jSONArray2);
                    h.a().a(obj, Base64.encodeToString(jSONObject2.toString().getBytes(), 2));
                }
            } catch (Throwable th7) {
                th = th7;
                str = str8;
                str2 = str9;
                jSONObject2.put(str2, 1);
                jSONObject2.put(str, th.getLocalizedMessage());
                h.a().a(obj, Base64.encodeToString(jSONObject2.toString().getBytes(), 2));
            }
        }
    }
}