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


package com.mbridge.msdk.splash.js;

import android.text.TextUtils;
import android.util.Base64;
import android.webkit.WebView;
import com.bytedance.sdk.openadsdk.api.plugin.PluginConstants;
import com.mbridge.msdk.MBridgeConstans;
import com.mbridge.msdk.foundation.controller.a;
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.same.a.d;
import com.mbridge.msdk.foundation.tools.w;
import com.mbridge.msdk.foundation.tools.z;
import com.mbridge.msdk.mbjscommon.windvane.h;
import java.io.File;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: SplashJsUtils */
public final class c {
    private static String a = "SplashJsUtils";
    private static int b = 0;
    private static int c = 1;

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

    public static String a(int i) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(PluginConstants.KEY_ERROR_CODE, i);
            String jSONObject2 = jSONObject.toString();
            if (!TextUtils.isEmpty(jSONObject2)) {
                return Base64.encodeToString(jSONObject2.getBytes(), 2);
            }
            return "";
        } catch (Throwable unused) {
            w.d(a, "code to string is error");
            return "";
        }
    }

    public static void b(Object obj, JSONObject jSONObject) {
        try {
            JSONObject optJSONObject = jSONObject.optJSONObject("data");
            if (optJSONObject == null) {
                a(obj, "data is empty");
                return;
            }
            final CampaignEx parseCampaignWithBackData = CampaignEx.parseCampaignWithBackData(optJSONObject);
            if (parseCampaignWithBackData == null) {
                a(obj, "data camapign is empty");
                return;
            }
            new Thread(new Runnable() {
                /* class com.mbridge.msdk.splash.js.c.AnonymousClass1 */

                public final void run() {
                    try {
                        l a2 = l.a(i.a(a.f().j()));
                        if (a2 != null) {
                            if (!a2.a(CampaignEx.this.getId())) {
                                com.mbridge.msdk.foundation.entity.h hVar = new com.mbridge.msdk.foundation.entity.h();
                                hVar.a(CampaignEx.this.getId());
                                hVar.a(CampaignEx.this.getFca());
                                hVar.b(CampaignEx.this.getFcb());
                                hVar.d(0);
                                hVar.c(1);
                                hVar.a(System.currentTimeMillis());
                                a2.a(hVar);
                            } else {
                                a2.b(CampaignEx.this.getId());
                            }
                        }
                        c.a(CampaignEx.this.getCampaignUnitId(), CampaignEx.this);
                    } catch (Throwable th) {
                        w.b(c.a, th.getMessage(), th);
                    }
                }
            }).start();
            try {
                JSONObject jSONObject2 = new JSONObject();
                jSONObject2.put(PluginConstants.KEY_ERROR_CODE, b);
                JSONObject jSONObject3 = new JSONObject();
                jSONObject3.put("id", "");
                jSONObject2.put("data", jSONObject3);
                h.a().a(obj, Base64.encodeToString(jSONObject2.toString().getBytes(), 2));
            } catch (Exception e) {
                a(obj, e.getMessage());
                w.a(a, e.getMessage());
            }
        } catch (Throwable th) {
            a(obj, th.getMessage());
        }
    }

    private static void a(Object obj, String str) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(PluginConstants.KEY_ERROR_CODE, c);
            jSONObject.put("message", str);
            jSONObject.put("data", new JSONObject());
            h.a().a(obj, Base64.encodeToString(jSONObject.toString().getBytes(), 2));
        } catch (Exception e) {
            w.a(a, e.getMessage());
        }
    }

    public static void a(WebView webView, String str, String str2) {
        h.a().a(webView, str, str2);
    }

    public static void a(WebView webView) {
        w.d(a, "fireOnJSBridgeConnected");
        h.a().a(webView);
    }

    static /* synthetic */ void a(String str, CampaignEx campaignEx) {
        if (d.i != null && !TextUtils.isEmpty(campaignEx.getId())) {
            d.a(str, campaignEx, "splash");
        }
    }
}