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


package com.mbridge.msdk.video.js.bridge;

import android.content.Context;
import android.text.TextUtils;
import android.util.Base64;
import com.bytedance.sdk.openadsdk.api.plugin.PluginConstants;
import com.mbridge.msdk.click.c;
import com.mbridge.msdk.foundation.tools.aa;
import com.mbridge.msdk.foundation.tools.w;
import com.mbridge.msdk.mbjscommon.bridge.b;
import com.mbridge.msdk.mbjscommon.windvane.WindVaneWebView;
import com.mbridge.msdk.mbjscommon.windvane.a;
import com.mbridge.msdk.mbjscommon.windvane.h;
import com.mbridge.msdk.video.js.a.j;
import com.mbridge.msdk.video.js.factory.IJSFactory;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class BaseRewardJsH5 implements IRewardBridge {
    protected IJSFactory a;

    public void initialize(Context context, WindVaneWebView windVaneWebView) {
        if (context instanceof IJSFactory) {
            this.a = (IJSFactory) context;
        }
    }

    public void initialize(Object obj, WindVaneWebView windVaneWebView) {
        if (obj instanceof IJSFactory) {
            this.a = (IJSFactory) obj;
        }
    }

    @Override // com.mbridge.msdk.video.js.bridge.IRewardBridge
    public void getEndScreenInfo(Object obj, String str) {
        String str2;
        try {
            IJSFactory iJSFactory = this.a;
            if (iJSFactory != null) {
                String a2 = iJSFactory.getIJSRewardVideoV1().a();
                if (!TextUtils.isEmpty(a2)) {
                    str2 = Base64.encodeToString(a2.getBytes(), 2);
                    w.a("JS-Reward-Brigde", "getEndScreenInfo success");
                } else {
                    str2 = "";
                    w.a("JS-Reward-Brigde", "getEndScreenInfo failed");
                }
                h.a().a(obj, str2);
            }
        } catch (Throwable th) {
            w.b("JS-Reward-Brigde", "getEndScreenInfo", th);
        }
    }

    @Override // com.mbridge.msdk.video.js.bridge.IRewardBridge
    public void install(Object obj, String str) {
        j jVar;
        Context context;
        try {
            if (this.a != null) {
                w.a("JS-Reward-Brigde", "install:" + str);
                if (obj != null) {
                    a aVar = (a) obj;
                    if (!(!(aVar.a.getObject() instanceof j) || (jVar = (j) aVar.a.getObject()) == null || (context = aVar.a.getContext()) == null || context == context.getApplicationContext())) {
                        jVar.a(context);
                    }
                }
                if (this.a.getJSContainerModule().endCardShowing()) {
                    this.a.getJSCommon().click(3, str);
                } else {
                    this.a.getJSCommon().click(1, str);
                }
            }
        } catch (Throwable th) {
            w.b("JS-Reward-Brigde", "install", th);
        }
    }

    @Override // com.mbridge.msdk.video.js.bridge.IRewardBridge
    public void openURL(Object obj, String str) {
        WindVaneWebView windVaneWebView;
        w.d("JS-Reward-Brigde", "openURL:" + str);
        Context j = com.mbridge.msdk.foundation.controller.a.f().j();
        if (!TextUtils.isEmpty(str)) {
            if (j == null) {
                try {
                    if ((obj instanceof a) && (windVaneWebView = ((a) obj).a) != null) {
                        j = windVaneWebView.getContext();
                    }
                } catch (Exception e) {
                    w.d("JS-Reward-Brigde", e.getMessage());
                }
            }
            if (j != null) {
                try {
                    JSONObject jSONObject = new JSONObject(str);
                    String optString = jSONObject.optString("url");
                    int optInt = jSONObject.optInt("type");
                    if (optInt == 1) {
                        c.a(j, optString);
                    } else if (optInt == 2) {
                        c.b(j, optString);
                    }
                } catch (JSONException e2) {
                    w.d("JS-Reward-Brigde", e2.getMessage());
                } catch (Throwable th) {
                    w.d("JS-Reward-Brigde", th.getMessage());
                }
            }
        }
    }

    @Override // com.mbridge.msdk.video.js.bridge.IRewardBridge
    public void cai(Object obj, String str) {
        w.a("JS-Reward-Brigde", "cai:" + str);
        if (!TextUtils.isEmpty(str)) {
            try {
                String optString = new JSONObject(str).optString("packageName");
                if (TextUtils.isEmpty(optString)) {
                    b.a(obj, "packageName is empty");
                }
                int i = aa.c(com.mbridge.msdk.foundation.controller.a.f().j(), optString) ? 1 : 2;
                try {
                    JSONObject jSONObject = new JSONObject();
                    jSONObject.put(PluginConstants.KEY_ERROR_CODE, b.b);
                    JSONObject jSONObject2 = new JSONObject();
                    jSONObject2.put("result", i);
                    jSONObject.put("data", jSONObject2);
                    h.a().a(obj, Base64.encodeToString(jSONObject.toString().getBytes(), 2));
                } catch (Exception e) {
                    b.a(obj, e.getMessage());
                    w.a("JS-Reward-Brigde", e.getMessage());
                }
            } catch (JSONException e2) {
                b.a(obj, "exception: " + e2.getLocalizedMessage());
                w.b("JS-Reward-Brigde", "cai", e2);
            } catch (Throwable th) {
                b.a(obj, "exception: " + th.getLocalizedMessage());
                w.b("JS-Reward-Brigde", "cai", th);
            }
        }
    }

    @Override // com.mbridge.msdk.video.js.bridge.IRewardBridge
    public void gial(Object obj, String str) {
        w.a("JS-Reward-Brigde", "gial:" + str);
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(PluginConstants.KEY_ERROR_CODE, 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 i = 0; i < size; i++) {
                    jSONArray.put(list.get(i));
                }
            }
            jSONObject2.put("packageNameList", jSONArray);
            jSONObject.put("data", jSONObject2);
            h.a().a(obj, Base64.encodeToString(jSONObject.toString().getBytes(), 2));
        } catch (Exception e) {
            b.a(obj, e.getMessage());
            w.a("JS-Reward-Brigde", e.getMessage());
        } catch (Throwable th) {
            b.a(obj, th.getMessage());
            w.a("JS-Reward-Brigde", th.getMessage());
        }
    }

    @Override // com.mbridge.msdk.video.js.bridge.IRewardBridge
    public void notifyCloseBtn(Object obj, String str) {
        try {
            if (this.a != null && !TextUtils.isEmpty(str)) {
                int optInt = new JSONObject(str).optInt("state");
                w.a("JS-Reward-Brigde", "notifyCloseBtn,state:" + str);
                this.a.getIJSRewardVideoV1().notifyCloseBtn(optInt);
            }
        } catch (Throwable th) {
            w.b("JS-Reward-Brigde", "notifyCloseBtn", th);
        }
    }

    @Override // com.mbridge.msdk.video.js.bridge.IRewardBridge
    public void toggleCloseBtn(Object obj, String str) {
        try {
            if (this.a != null && !TextUtils.isEmpty(str)) {
                int optInt = new JSONObject(str).optInt("state");
                w.a("JS-Reward-Brigde", "toggleCloseBtn,state:" + str);
                this.a.getIJSRewardVideoV1().toggleCloseBtn(optInt);
            }
        } catch (Throwable th) {
            w.b("JS-Reward-Brigde", "toggleCloseBtn", th);
        }
    }

    @Override // com.mbridge.msdk.video.js.bridge.IRewardBridge
    public void triggerCloseBtn(Object obj, String str) {
        try {
            if (this.a != null && !TextUtils.isEmpty(str)) {
                h.a().a(obj, a(0));
                this.a.getIJSRewardVideoV1().a(new JSONObject(str).optString("state"));
                w.a("JS-Reward-Brigde", "triggerCloseBtn,state:" + str);
            }
        } catch (Throwable th) {
            w.b("JS-Reward-Brigde", "triggerCloseBtn", th);
            h.a().a(obj, a(-1));
        }
    }

    @Override // com.mbridge.msdk.video.js.bridge.IRewardBridge
    public void setOrientation(Object obj, String str) {
        try {
            if (this.a != null && !TextUtils.isEmpty(str)) {
                String optString = new JSONObject(str).optString("state");
                w.a("JS-Reward-Brigde", "setOrientation,state:" + str);
                this.a.getIJSRewardVideoV1().b(optString);
            }
        } catch (Throwable th) {
            w.b("JS-Reward-Brigde", "setOrientation", th);
        }
    }

    @Override // com.mbridge.msdk.video.js.bridge.IRewardBridge
    public void handlerPlayableException(Object obj, String str) {
        try {
            if (this.a != null && !TextUtils.isEmpty(str)) {
                String optString = new JSONObject(str).optString("msg");
                w.a("JS-Reward-Brigde", "handlerPlayableException,msg:" + str);
                this.a.getIJSRewardVideoV1().c(optString);
            }
        } catch (Throwable th) {
            w.b("JS-Reward-Brigde", "setOrientation", th);
        }
    }

    private 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("JS-Reward-Brigde", "code to string is error");
            return "";
        }
    }
}