package net.wequick.small.util;

import android.os.Build;

import java.util.HashMap;
import java.util.Map;

/**
 * This class
 */
public final class JNIUtils {

    private static int[] sSupportedABIFlags;
    private static String[] sSupportedABINames;

    /**
     * Get the ABI (Application Binary Interface) name from a specify flag
     *
     * @param flag the flag refer to an ABI, this is automatically set by `gradle-small'
     */
    public static String getExtractABI(int flag) {
        if (flag == 0) return null;

        if (sSupportedABIFlags == null) {
            // ABIs on http://developer.android.com/intl/zh-cn/ndk/guides/abis.html
            // FIXME: the flags here should keep updating while any new ABIs born.
            Map<String, Integer> flags = new HashMap<String, Integer>();
            flags.put("armeabi",     1);
            flags.put("armeabi-v7a", 1 << 1);
            flags.put("arm64-v8a",   1 << 2);
            flags.put("x86",         1 << 3);
            flags.put("x86_64",      1 << 4);
            flags.put("mips",        1 << 5);
            flags.put("mips64",      1 << 6);

            String[] abis;
            if (Build.VERSION.SDK_INT >= 21) {
                abis = Build.SUPPORTED_ABIS;
                // FIXME: seems the emulator no support 64bit JNI?
                if (abis[0].equals("x86_64")) {
                    abis = Build.SUPPORTED_32_BIT_ABIS;
                }
            } else if (Build.CPU_ABI2.equals(Build.UNKNOWN)) {
                abis = new String[] { Build.CPU_ABI };
            } else {
                abis = new String[] { Build.CPU_ABI, Build.CPU_ABI2 };
            }

            final int N = abis.length;
            sSupportedABINames = abis;
            sSupportedABIFlags = new int[N];
            for (int i = 0; i < N; i++) {
                String abi = abis[i];
                sSupportedABIFlags[i] = flags.get(abi);
            }
        }

        final int N = sSupportedABIFlags.length;
        for (int i = 0; i < N; i++) {
            int f = sSupportedABIFlags[i];
            if ((flag & f) != 0) {
                return sSupportedABINames[i];
            }
        }
        return null;
    }
}

@@ -1,8 +1,611 @@
+/*%0A * Copyright 2015-present wequick.net%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22); you may%0A * not use this file except in compliance with the License. You may obtain%0A * a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and limitations%0A * under the License.%0A */%0A
 package 
@@ -721,16 +721,76 @@
 is class
+ consists exclusively of static methods that operate on JNI.
 %0A */%0Apub

Add license and comment