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


package aegon.chrome.net.impl;

import aegon.chrome.base.ContextUtils;
import aegon.chrome.base.Log;
import aegon.chrome.base.annotations.JNINamespace;
import aegon.chrome.net.NetworkChangeNotifier;
import android.content.Context;
import android.os.ConditionVariable;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Process;

@JNINamespace("cronet")
public class CronetLibraryLoader {
    static final /* synthetic */ boolean $assertionsDisabled = false;
    private static final String LIBRARY_NAME = ("cronet." + ImplVersion.getCronetVersion());
    private static final String TAG = "CronetLibraryLoader";
    private static InitThreadHandler sInitThreadHandler = new DefaultInitThreadHandler();
    private static volatile boolean sInitThreadInitDone;
    private static volatile boolean sLibraryLoaded = false;
    private static final Object sLoadLock = new Object();
    private static final ConditionVariable sWaitForLibLoad = new ConditionVariable();

    static class DefaultInitThreadHandler implements InitThreadHandler {
        private final Object sInitLock;
        private HandlerThread sInitThread;

        private DefaultInitThreadHandler() {
            this.sInitLock = new Object();
        }

        private void ensureThread() {
            synchronized (this.sInitLock) {
                if (this.sInitThread == null) {
                    this.sInitThread = new HandlerThread("CronetInit");
                }
                if (!this.sInitThread.isAlive()) {
                    this.sInitThread.start();
                }
            }
        }

        @Override // aegon.chrome.net.impl.CronetLibraryLoader.InitThreadHandler
        public boolean onInitThread() {
            ensureThread();
            return this.sInitThread.getLooper() == Looper.myLooper();
        }

        @Override // aegon.chrome.net.impl.CronetLibraryLoader.InitThreadHandler
        public void postTask(Runnable runnable) {
            ensureThread();
            if (onInitThread()) {
                runnable.run();
            } else {
                new Handler(this.sInitThread.getLooper()).post(runnable);
            }
        }
    }

    public interface InitThreadHandler {
        boolean onInitThread();

        void postTask(Runnable runnable);
    }

    public static void ensureInitialized(Context context, CronetEngineBuilderImpl cronetEngineBuilderImpl) {
        synchronized (sLoadLock) {
            if (!sInitThreadInitDone) {
                ContextUtils.initApplicationContext(context);
                postToInitThread(new Runnable() {
                    /* class aegon.chrome.net.impl.CronetLibraryLoader.AnonymousClass1 */

                    public void run() {
                        CronetLibraryLoader.ensureInitializedOnInitThread();
                    }
                });
            }
            if (!sLibraryLoaded) {
                if (cronetEngineBuilderImpl.libraryLoader() != null) {
                    cronetEngineBuilderImpl.libraryLoader().loadLibrary(LIBRARY_NAME);
                } else {
                    System.loadLibrary(LIBRARY_NAME);
                }
                String cronetVersion = ImplVersion.getCronetVersion();
                if (cronetVersion.equals(SafeNativeFunctionCaller.EnsureResult(CronetLibraryLoader$$Lambda$1.lambdaFactory$()))) {
                    Log.i(TAG, "Cronet version: %s, arch: %s", cronetVersion, System.getProperty("os.arch"));
                    sLibraryLoaded = true;
                    sWaitForLibLoad.open();
                } else {
                    throw new RuntimeException(String.format("Expected Cronet version number %s, actual version number %s.", cronetVersion, nativeGetCronetVersion()));
                }
            }
        }
    }

    private static void ensureInitializedFromNative() {
        synchronized (sLoadLock) {
            sLibraryLoaded = true;
            sWaitForLibLoad.open();
        }
        ensureInitialized(ContextUtils.getApplicationContext(), null);
    }

    static void ensureInitializedOnInitThread() {
        if (!sInitThreadInitDone) {
            NetworkChangeNotifier.init();
            NetworkChangeNotifier.registerToReceiveNotificationsAlways();
            sWaitForLibLoad.block();
            SafeNativeFunctionCaller.Ensure(CronetLibraryLoader$$Lambda$2.lambdaFactory$());
            sInitThreadInitDone = true;
        }
    }

    private static String getDefaultUserAgent() {
        return UserAgent.from(ContextUtils.getApplicationContext());
    }

    /* access modifiers changed from: private */
    public static native void nativeCronetInitOnInitThread();

    /* access modifiers changed from: private */
    public static native String nativeGetCronetVersion();

    private static boolean onInitThread() {
        return sInitThreadHandler.onInitThread();
    }

    public static void postToInitThread(Runnable runnable) {
        sInitThreadHandler.postTask(runnable);
    }

    public static void setInitThreadHandler(InitThreadHandler initThreadHandler) {
        if (initThreadHandler != null) {
            sInitThreadHandler = initThreadHandler;
        }
    }

    private static void setNetworkThreadPriorityOnNetworkThread(int i) {
        Process.setThreadPriority(i);
    }
}