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


package com.mbridge.msdk.splash.js;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Base64;
import com.bytedance.sdk.openadsdk.api.plugin.PluginConstants;
import com.mbridge.msdk.c.d;
import com.mbridge.msdk.click.c;
import com.mbridge.msdk.foundation.db.i;
import com.mbridge.msdk.foundation.db.l;
import com.mbridge.msdk.foundation.entity.CampaignEx;
import com.mbridge.msdk.foundation.tools.aa;
import com.mbridge.msdk.foundation.tools.w;
import com.mbridge.msdk.mbjscommon.windvane.WindVaneWebView;
import com.mbridge.msdk.mbjscommon.windvane.h;
import com.mbridge.msdk.splash.d.a;
import com.sigmob.sdk.base.mta.PointCategory;
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: SplashJSBridgeImpl */
public final class b implements a {
    private String a = "SplashJSBridgeImpl";
    private WeakReference<Context> b;
    private List<CampaignEx> c;
    private String d;
    private String e;
    private int f;
    private int g;
    private int h = 5;
    private int i;
    private a j;
    private SplashExpandDialog k;

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

    public final void a(Context context) {
        this.b = new WeakReference<>(context);
    }

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

    public final void b(int i2) {
        this.h = i2;
    }

    public final void c(int i2) {
        this.i = i2;
    }

    public final void a(a aVar) {
        if (aVar != null) {
            this.j = aVar;
        }
    }

    public final a a() {
        return this.j;
    }

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

    public final List<CampaignEx> b() {
        return this.c;
    }

    public final void a(Object obj, String str) {
        try {
            JSONObject jSONObject = new JSONObject();
            com.mbridge.msdk.splash.a.a aVar = new com.mbridge.msdk.splash.a.a(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", aVar.a());
            jSONObject.put("campaignList", CampaignEx.parseCamplistToJson(this.c));
            d e2 = com.mbridge.msdk.c.b.a().e(com.mbridge.msdk.foundation.controller.a.f().k(), this.d);
            if (e2 == null) {
                e2 = d.d(this.d);
            }
            if (!TextUtils.isEmpty(this.e)) {
                e2.g(this.e);
            }
            e2.a(this.d);
            e2.b(this.h);
            e2.a(this.g);
            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));
            }
            jSONObject.put("sdk_info", com.mbridge.msdk.mbjscommon.base.d.a);
            String str2 = this.a;
            w.d(str2, PointCategory.INIT + jSONObject.toString());
            h.a().a(obj, Base64.encodeToString(jSONObject.toString().getBytes(), 2));
        } catch (Throwable th) {
            w.b(this.a, PointCategory.INIT, th);
        }
    }

    public final void b(Object obj, String str) {
        try {
            if (!TextUtils.isEmpty(str)) {
                int optInt = new JSONObject(str).optInt("state");
                a aVar = this.j;
                if (aVar != null) {
                    aVar.a(optInt);
                }
            }
        } catch (Throwable th) {
            w.b(this.a, "toggleCloseBtn", th);
        }
    }

    public final void c(Object obj, String str) {
        a aVar = this.j;
        if (aVar != null) {
            aVar.a(obj, str);
        }
    }

    public final void d(Object obj, String str) {
        w.d(this.a, "install");
        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);
                        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();
                    }
                    a aVar = this.j;
                    if (aVar != null) {
                        aVar.a(campaignEx);
                    }
                }
            }
        } catch (Throwable th) {
            w.b(this.a, "click", th);
        }
    }

    public final void e(Object obj, String str) {
        WindVaneWebView windVaneWebView;
        String str2 = this.a;
        w.d(str2, "openURL:" + str);
        if (TextUtils.isEmpty(str)) {
            com.mbridge.msdk.mbjscommon.bridge.b.a(obj, "params is null");
            return;
        }
        Context j2 = com.mbridge.msdk.foundation.controller.a.f().j();
        if (!TextUtils.isEmpty(str)) {
            if (j2 == null) {
                try {
                    if ((obj instanceof com.mbridge.msdk.mbjscommon.windvane.a) && (windVaneWebView = ((com.mbridge.msdk.mbjscommon.windvane.a) obj).a) != null) {
                        j2 = windVaneWebView.getContext();
                    }
                } catch (Exception e2) {
                    w.d(this.a, e2.getMessage());
                }
            }
            if (j2 != null) {
                try {
                    JSONObject jSONObject = new JSONObject(str);
                    String optString = jSONObject.optString("url");
                    int optInt = jSONObject.optInt("type");
                    if (optInt == 1) {
                        c.a(j2, optString);
                    } else if (optInt == 2) {
                        c.b(j2, optString);
                    }
                } catch (JSONException e3) {
                    w.d(this.a, e3.getMessage());
                } catch (Throwable th) {
                    w.d(this.a, th.getMessage());
                }
            }
        }
    }

    public final void f(Object obj, String str) {
        String str2 = this.a;
        w.a(str2, "cai:" + str);
        if (TextUtils.isEmpty(str)) {
            com.mbridge.msdk.mbjscommon.bridge.b.a(obj, "params is null");
        } else if (!TextUtils.isEmpty(str)) {
            try {
                String optString = new JSONObject(str).optString("packageName");
                if (TextUtils.isEmpty(optString)) {
                    com.mbridge.msdk.mbjscommon.bridge.b.a(obj, "packageName is empty");
                }
                int i2 = aa.c(com.mbridge.msdk.foundation.controller.a.f().j(), optString) ? 1 : 2;
                try {
                    JSONObject jSONObject = new JSONObject();
                    jSONObject.put(PluginConstants.KEY_ERROR_CODE, com.mbridge.msdk.mbjscommon.bridge.b.b);
                    JSONObject jSONObject2 = new JSONObject();
                    jSONObject2.put("result", i2);
                    jSONObject.put("data", jSONObject2);
                    h.a().a(obj, Base64.encodeToString(jSONObject.toString().getBytes(), 2));
                } catch (Exception e2) {
                    com.mbridge.msdk.mbjscommon.bridge.b.a(obj, e2.getMessage());
                    w.a(this.a, e2.getMessage());
                }
            } catch (JSONException e3) {
                com.mbridge.msdk.mbjscommon.bridge.b.a(obj, "exception: " + e3.getLocalizedMessage());
                w.b(this.a, "cai", e3);
            } catch (Throwable th) {
                com.mbridge.msdk.mbjscommon.bridge.b.a(obj, "exception: " + th.getLocalizedMessage());
                w.b(this.a, "cai", th);
            }
        }
    }

    public final void g(Object obj, String str) {
        String str2 = this.a;
        w.a(str2, "gial:" + str);
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(PluginConstants.KEY_ERROR_CODE, com.mbridge.msdk.mbjscommon.bridge.b.b);
            JSONObject jSONObject2 = new JSONObject();
            List<String> list = com.mbridge.msdk.foundation.controller.a.c;
            JSONArray jSONArray = new JSONArray();
            if (list != null && list.size() > 0) {
                int size = list.size();
                for (int i2 = 0; i2 < size; i2++) {
                    jSONArray.put(list.get(i2));
                }
            }
            jSONObject2.put("packageNameList", jSONArray);
            jSONObject.put("data", jSONObject2);
            h.a().a(obj, Base64.encodeToString(jSONObject.toString().getBytes(), 2));
        } catch (Exception e2) {
            com.mbridge.msdk.mbjscommon.bridge.b.a(obj, e2.getMessage());
            w.a(this.a, e2.getMessage());
        } catch (Throwable th) {
            com.mbridge.msdk.mbjscommon.bridge.b.a(obj, th.getMessage());
            w.a(this.a, th.getMessage());
        }
    }

    public final void h(Object obj, String str) {
        try {
            if (!TextUtils.isEmpty(str)) {
                int i2 = new JSONObject(str).getInt("countdown");
                a aVar = this.j;
                if (aVar != null) {
                    aVar.b(i2);
                }
            }
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.mraid.b
    public final void open(String str) {
        a aVar = this.j;
        if (aVar != null) {
            aVar.a(true, str);
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.mraid.b
    public final void close() {
        w.d(this.a, "close");
        try {
            a aVar = this.j;
            if (aVar != null) {
                aVar.a();
            }
        } catch (Throwable th) {
            w.b(this.a, "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 {
            a aVar = this.j;
            if (aVar != null) {
                aVar.a(i2);
            }
        } catch (Throwable th) {
            w.b(this.a, "useCustomClose", th);
        }
    }

    @Override // com.mbridge.msdk.mbjscommon.mraid.b
    public final void expand(String str, boolean z) {
        try {
            Bundle bundle = new Bundle();
            bundle.putString("url", str);
            bundle.putBoolean("shouldUseCustomClose", z);
            WeakReference<Context> weakReference = this.b;
            if (weakReference != null && weakReference.get() != null) {
                SplashExpandDialog splashExpandDialog = this.k;
                if (splashExpandDialog == null || !splashExpandDialog.isShowing()) {
                    SplashExpandDialog splashExpandDialog2 = new SplashExpandDialog(this.b.get(), bundle, this.j);
                    this.k = splashExpandDialog2;
                    splashExpandDialog2.setCampaignList(this.d, this.c);
                    this.k.show();
                    a aVar = this.j;
                    if (aVar != null) {
                        aVar.a(true);
                    }
                    com.mbridge.msdk.splash.e.a.a(this.d, getMraidCampaign(), str);
                }
            }
        } catch (Throwable th) {
            w.b(this.a, "expand", th);
        }
    }

    public final void i(Object obj, String str) {
        String str2 = this.a;
        w.a(str2, "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.d, campaignEx, "splash");
                            arrayList.add(string);
                        }
                    }
                }
                new Thread(new Runnable() {
                    /* class com.mbridge.msdk.splash.js.b.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(b.this.a, "campain can't insert db");
                        }
                    }
                }).start();
            }
        } catch (Throwable th) {
            w.b(this.a, "sendImpressions", th);
        }
    }

    public final void j(Object obj, String str) {
        String str2 = this.a;
        w.a(str2, "reportUrls:" + str);
        if (TextUtils.isEmpty(str)) {
            com.mbridge.msdk.mbjscommon.bridge.b.a(obj, "params is null");
        } else if (!TextUtils.isEmpty(str)) {
            try {
                JSONArray jSONArray = new JSONArray(str);
                for (int i2 = 0; i2 < jSONArray.length(); i2++) {
                    JSONObject jSONObject = jSONArray.getJSONObject(i2);
                    int optInt = jSONObject.optInt("type");
                    String optString = jSONObject.optString("url");
                    int optInt2 = jSONObject.optInt(PointCategory.REPORT);
                    if (optInt2 == 0) {
                        com.mbridge.msdk.click.b.a(com.mbridge.msdk.foundation.controller.a.f().j(), (CampaignEx) null, "", optString, false, optInt != 0);
                    } else {
                        com.mbridge.msdk.click.b.a(com.mbridge.msdk.foundation.controller.a.f().j(), (CampaignEx) null, "", optString, false, optInt != 0, optInt2);
                    }
                }
                h.a().a(obj, c.a(0));
            } catch (Throwable th) {
                w.b(this.a, "reportUrls", th);
            }
        }
    }

    public final void k(Object obj, String str) {
        try {
            if (obj instanceof com.mbridge.msdk.mbjscommon.windvane.a) {
                h.a().a(((com.mbridge.msdk.mbjscommon.windvane.a) obj).a);
            }
        } catch (Throwable th) {
            w.b(this.a, "onJSBridgeConnect", th);
        }
    }

    public final void l(Object obj, String str) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put(PluginConstants.KEY_ERROR_CODE, 0);
            jSONObject.put("message", "Call pause count down success.");
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("countdown", this.i);
            jSONObject.put("data", jSONObject2);
            h.a().a(obj, Base64.encodeToString(jSONObject.toString().getBytes(), 2));
        } catch (Exception e2) {
            w.d(this.a, e2.getMessage());
        }
        a aVar = this.j;
        if (aVar != null) {
            aVar.a(1, -1);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:13:0x0030  */
    /* JADX WARNING: Removed duplicated region for block: B:15:? A[RETURN, SYNTHETIC] */
    public final void m(Object obj, String str) {
        a aVar;
        Exception e2;
        int i2 = 0;
        if (!TextUtils.isEmpty(str)) {
            try {
                int optInt = new JSONObject(str).optInt("countdown");
                try {
                    h.a().a(obj, c.a(0));
                    i2 = optInt;
                } catch (Exception e3) {
                    e2 = e3;
                    i2 = optInt;
                    w.d(this.a, e2.getMessage());
                    aVar = this.j;
                    if (aVar != null) {
                    }
                }
            } catch (Exception e4) {
                e2 = e4;
                w.d(this.a, e2.getMessage());
                aVar = this.j;
                if (aVar != null) {
                }
            }
        }
        aVar = this.j;
        if (aVar != null) {
            aVar.a(2, i2);
        }
    }
}