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


package com.kwad.sdk.api.loader;

import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import com.kwad.components.offline.api.BuildConfig;
import com.kwad.sdk.api.KsAdSDK;
import com.kwad.sdk.api.SdkConfig;
import com.kwad.sdk.api.b;
import com.kwad.sdk.api.core.IKsAdSDK;
import com.kwad.sdk.api.core.KsAdSdkDynamicApi;
import com.kwad.sdk.api.proxy.IComponentProxy;
import java.util.concurrent.atomic.AtomicBoolean;

public class Loader {
    static final /* synthetic */ boolean $assertionsDisabled = false;
    private IKsAdSDK aQP;
    private l aQQ;
    private AtomicBoolean aQR;
    private AtomicBoolean aQS;
    private volatile Context mContext;

    /* access modifiers changed from: package-private */
    public static class a {
        private static final Loader aQT = new Loader((byte) 0);
    }

    private Loader() {
        this.aQP = null;
        this.aQQ = null;
        this.aQR = new AtomicBoolean(false);
        this.aQS = new AtomicBoolean(false);
    }

    /* synthetic */ Loader(byte b) {
        this();
    }

    private static void G(Context context, String str) {
        h.E(context, str);
    }

    static synchronized IKsAdSDK a(ClassLoader classLoader) {
        IKsAdSDK iKsAdSDK;
        synchronized (Loader.class) {
            try {
                Object invoke = Class.forName(((KsAdSdkDynamicApi) IKsAdSDK.class.getAnnotation(KsAdSdkDynamicApi.class)).value(), true, classLoader).getDeclaredMethod("get", new Class[0]).invoke(null, new Object[0]);
                if (invoke != null) {
                    iKsAdSDK = (IKsAdSDK) invoke;
                } else {
                    throw new RuntimeException("Can not get sdk form " + classLoader);
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return iKsAdSDK;
    }

    private boolean aS(Context context) {
        String aO = g.aO(context);
        String aP = g.aP(context);
        if (TextUtils.isEmpty(aO) && TextUtils.isEmpty(aP)) {
            return false;
        }
        if (!TextUtils.isEmpty(aP) && g.F(aP, aO)) {
            g.v(context, aP);
            G(context, aO);
            g.w(context, "");
            aO = aP;
        }
        return !TextUtils.isEmpty(aO);
    }

    private static void aT(Context context) {
        String aQ = g.aQ(context);
        boolean b = u.b(context, g.aQt, false);
        if (TextUtils.isEmpty(aQ) || !aQ.equals(BuildConfig.VERSION_NAME) || b) {
            String aO = g.aO(context);
            g.v(context, "");
            g.w(context, "");
            u.a(context, g.aQt, false);
            h.e(h.A(context, aO));
            g.x(context, BuildConfig.VERSION_NAME);
        }
    }

    public static Loader get() {
        return a.aQT;
    }

    public void checkAutoRevert() {
        if (this.mContext != null && this.aQQ != null && !this.aQS.get()) {
            this.aQS.set(true);
            try {
                int JP = b.JP();
                if (JP > 0) {
                    try {
                        d.aN(this.mContext).setDefaultUncaughtExceptionHandler(Thread.getDefaultUncaughtExceptionHandler());
                        Thread.setDefaultUncaughtExceptionHandler(d.aN(this.mContext));
                        d.aN(this.mContext).bS(JP);
                        d.aN(this.mContext).a(this.aQP);
                    } catch (Throwable th) {
                        th.printStackTrace();
                    }
                }
            } catch (Throwable th2) {
                th2.printStackTrace();
            }
        }
    }

    public void checkUpdate(IKsAdSDK iKsAdSDK) {
        v.a(this.mContext, iKsAdSDK);
    }

    public Context getContext() {
        return this.mContext;
    }

    public ClassLoader getExternalClassLoader() {
        l lVar = this.aQQ;
        if (lVar != null) {
            return lVar.getClassLoader();
        }
        return null;
    }

    public Resources getExternalResource() {
        l lVar = this.aQQ;
        if (lVar != null) {
            return lVar.JV();
        }
        return null;
    }

    public IKsAdSDK getKsAdSDKImpl() {
        l lVar = this.aQQ;
        if (lVar != null) {
            IKsAdSDK JW = lVar.JW();
            JW.setIsExternal(true);
            return JW;
        }
        if (this.aQP == null) {
            this.aQP = a(this.mContext != null ? this.mContext.getClassLoader() : getClass().getClassLoader());
        }
        this.aQP.setIsExternal(false);
        return this.aQP;
    }

    public ClassLoader getRealClassLoader() {
        l lVar = this.aQQ;
        return lVar != null ? lVar.getClassLoader() : getClass().getClassLoader();
    }

    public void init(Context context) {
        if (!this.aQR.get()) {
            this.aQR.set(true);
            this.mContext = context.getApplicationContext();
            aT(this.mContext);
            if (aS(context)) {
                this.aQQ = l.F(this.mContext, g.aO(context));
            }
            if (this.aQQ == null) {
                this.aQP = a(getClass().getClassLoader());
            }
        }
    }

    public boolean isExternalLoaded() {
        return this.aQQ != null;
    }

    public <T extends IComponentProxy> T newComponentProxy(Context context, Class<?> cls, Object obj) {
        if (!this.aQR.get()) {
            KsAdSDK.init(context, SdkConfig.create(u.getString(context, "sdkconfig")));
        }
        return (T) getKsAdSDKImpl().newComponentProxy(cls, obj);
    }

    public <T extends IComponentProxy> T newComponentProxyNewProcess(Context context, Class<?> cls, Object obj) {
        if (!this.aQR.get()) {
            KsAdSDK.init(context, SdkConfig.create(u.getString(context, "sdkconfig")));
        }
        return (T) getKsAdSDKImpl().newComponentProxy(cls, obj);
    }

    public <T> T newInstance(Class<T> cls) {
        return (T) getKsAdSDKImpl().newInstance(cls);
    }
}