Skip to content

Commit

Permalink
Feat(Compat): add VMRuntime and Build compat
Browse files Browse the repository at this point in the history
  • Loading branch information
cmzy committed Feb 4, 2016
1 parent ef5d185 commit 4950792
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
** DroidPlugin Project
**
** Copyright(c) 2015 Andy Zhang <[email protected]>
**
** This file is part of DroidPlugin.
**
** DroidPlugin is free software: you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation, either
** version 3 of the License, or (at your option) any later version.
**
** DroidPlugin is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with DroidPlugin. If not, see <http://www.gnu.org/licenses/lgpl.txt>
**
**/

package com.morgoo.helper.compat;

import android.os.Build;

/**
* Created by Andy Zhang([email protected]) on 2016/2/4.
*/
public class BuildCompat {

public final static String[] SUPPORTED_ABIS;

public final static String[] SUPPORTED_32_BIT_ABIS;

public static final String[] SUPPORTED_64_BIT_ABIS;

static {
//init SUPPORTED_ABIS
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (Build.SUPPORTED_ABIS != null) {
SUPPORTED_ABIS = new String[Build.SUPPORTED_ABIS.length];
System.arraycopy(Build.SUPPORTED_ABIS, 0, SUPPORTED_ABIS, 0, SUPPORTED_ABIS.length);
} else {
SUPPORTED_ABIS = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
} else {
SUPPORTED_ABIS = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}

//init SUPPORTED_32_BIT_ABIS
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (Build.SUPPORTED_32_BIT_ABIS != null) {
SUPPORTED_32_BIT_ABIS = new String[Build.SUPPORTED_32_BIT_ABIS.length];
System.arraycopy(Build.SUPPORTED_32_BIT_ABIS, 0, SUPPORTED_32_BIT_ABIS, 0, SUPPORTED_32_BIT_ABIS.length);
} else {
SUPPORTED_32_BIT_ABIS = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
} else {
SUPPORTED_32_BIT_ABIS = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}

//init SUPPORTED_64_BIT_ABIS
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (Build.SUPPORTED_64_BIT_ABIS != null) {
SUPPORTED_64_BIT_ABIS = new String[Build.SUPPORTED_64_BIT_ABIS.length];
System.arraycopy(Build.SUPPORTED_64_BIT_ABIS, 0, SUPPORTED_64_BIT_ABIS, 0, SUPPORTED_64_BIT_ABIS.length);
} else {
SUPPORTED_64_BIT_ABIS = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
} else {
SUPPORTED_64_BIT_ABIS = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
** DroidPlugin Project
**
** Copyright(c) 2015 Andy Zhang <[email protected]>
**
** This file is part of DroidPlugin.
**
** DroidPlugin is free software: you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation, either
** version 3 of the License, or (at your option) any later version.
**
** DroidPlugin is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with DroidPlugin. If not, see <http://www.gnu.org/licenses/lgpl.txt>
**
**/

package com.morgoo.helper.compat;

import android.os.Build;

import com.morgoo.droidplugin.reflect.MethodUtils;
import com.morgoo.helper.Log;

/**
* Created by Andy Zhang([email protected]) on 2016/2/4.
*/
public class VMRuntimeCompat {

private static final String TAG = VMRuntimeCompat.class.getSimpleName();

public final static boolean is64Bit() {
// dalvik.system.VMRuntime.getRuntime().is64Bit();
try {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return false;
}
Class VMRuntime = Class.forName("dalvik.system.VMRuntime");
Object VMRuntimeObj = MethodUtils.invokeStaticMethod(VMRuntime, "getRuntime");
Object is64Bit = MethodUtils.invokeMethod(VMRuntimeObj, "is64Bit");
if (is64Bit instanceof Boolean) {
return ((Boolean) is64Bit);
}
} catch (Throwable e) {
Log.w(TAG, "is64Bit", e);
}
return false;
}
}

0 comments on commit 4950792

Please sign in to comment.