// Path: CoreLibrary/src/main/java/com/didi/virtualapk/internal/Constants.java
// public class Constants {
//     public static final String KEY_IS_PLUGIN = "isPlugin";
//     public static final String KEY_TARGET_PACKAGE = "target.package";
//     public static final String KEY_TARGET_ACTIVITY = "target.activity";
// 
//     public static final String OPTIMIZE_DIR = "dex";
//     public static final String NATIVE_DIR = "valibs";
// 
//     public static final boolean COMBINE_RESOURCES = true;
//     public static final boolean COMBINE_CLASSLOADER = true;
//     public static final boolean DEBUG = true;
//     
//     public static final String TAG = "VA";
//     public static final String TAG_PREFIX = TAG + ".";
// 
// }


import java.util.concurrent.Executor;
import android.app.ActivityManager;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.util.Log;
import android.util.Pair;
import com.didi.virtualapk.internal.Constants;
import java.util.List;
import java.util.concurrent.CountDownLatch;
/*
 * Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.didi.virtualapk.utils;




/**
 * Created by renyugang on 16/11/10.
 */
public class RunUtil {

    private static final int MESSAGE_RUN_ON_UITHREAD = 0x1;

    private static Handler sHandler;

    /**
     * execute a runnable on ui thread, then return immediately. see also {@link #runOnUiThread(Runnable, boolean)}
     * @param runnable the runnable prepared to run
     */
    public static void runOnUiThread(Runnable runnable) {
        runOnUiThread(runnable, false);
    }

    /**
     * execute a runnable on ui thread
     * @param runnable the runnable prepared to run
     * @param waitUtilDone if set true, the caller thread will wait until the specific runnable finished.
     */
    public static void runOnUiThread(Runnable runnable, boolean waitUtilDone) {
        if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
            runnable.run();
            return;
        }

        CountDownLatch countDownLatch = null;
        if (waitUtilDone) {
            countDownLatch = new CountDownLatch(1);
        }
        Pair<Runnable, CountDownLatch> pair = new Pair<>(runnable, countDownLatch);
        getHandler().obtainMessage(MESSAGE_RUN_ON_UITHREAD, pair).sendToTarget();
        if (waitUtilDone) {
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
// Path: CoreLibrary/src/main/java/com/didi/virtualapk/internal/Constants.java
// public class Constants {
//     public static final String KEY_IS_PLUGIN = "isPlugin";
//     public static final String KEY_TARGET_PACKAGE = "target.package";
//     public static final String KEY_TARGET_ACTIVITY = "target.activity";
// 
//     public static final String OPTIMIZE_DIR = "dex";
//     public static final String NATIVE_DIR = "valibs";
// 
//     public static final boolean COMBINE_RESOURCES = true;
//     public static final boolean COMBINE_CLASSLOADER = true;
//     public static final boolean DEBUG = true;
//     
//     public static final String TAG = "VA";
//     public static final String TAG_PREFIX = TAG + ".";
// 
// }


// Path: CoreLibrary/src/main/java/com/didi/virtualapk/utils/RunUtil.java
import java.util.concurrent.Executor;
import android.app.ActivityManager;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.util.Log;
import android.util.Pair;
import com.didi.virtualapk.internal.Constants;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/*
 * Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.didi.virtualapk.utils;




/**
 * Created by renyugang on 16/11/10.
 */
public class RunUtil {

    private static final int MESSAGE_RUN_ON_UITHREAD = 0x1;

    private static Handler sHandler;

    /**
     * execute a runnable on ui thread, then return immediately. see also {@link #runOnUiThread(Runnable, boolean)}
     * @param runnable the runnable prepared to run
     */
    public static void runOnUiThread(Runnable runnable) {
        runOnUiThread(runnable, false);
    }

    /**
     * execute a runnable on ui thread
     * @param runnable the runnable prepared to run
     * @param waitUtilDone if set true, the caller thread will wait until the specific runnable finished.
     */
    public static void runOnUiThread(Runnable runnable, boolean waitUtilDone) {
        if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
            runnable.run();
            return;
        }

        CountDownLatch countDownLatch = null;
        if (waitUtilDone) {
            countDownLatch = new CountDownLatch(1);
        }
        Pair<Runnable, CountDownLatch> pair = new Pair<>(runnable, countDownLatch);
        getHandler().obtainMessage(MESSAGE_RUN_ON_UITHREAD, pair).sendToTarget();
        if (waitUtilDone) {
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                Log.w(Constants.TAG, e);