下面列出了android.os.Build#CPU_ABI 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView)findViewById(R.id.textView);
String cpuArch;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
cpuArch = Build.SUPPORTED_ABIS[0];
} else {
cpuArch = Build.CPU_ABI;
}
textView.setText(cpuArch);
Log.d("ryg", "onCreate cpu arch is "+ cpuArch);
Log.d("ryg", "onCreate classloader is "+ getClassLoader());
if (hasPermission()) {
Log.d(TAG,"loadPlugin");
this.loadPlugin(this);
} else {
requestPermission();
}
}
/**
* 获取崩溃异常日志
*/
public static String getDeviceInfo() {
StringBuilder builder = new StringBuilder();
PackageInfo pi = getPackageInfo();
String dateTime = DateFormat.getDateTimeInstance().format(Calendar.getInstance(Locale.CHINA).getTime());
String appName = pi.applicationInfo.loadLabel(application.getPackageManager()).toString();
int[] pixels = getPixels();
String cpu;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cpu = Arrays.deepToString(Build.SUPPORTED_ABIS);
} else {
//noinspection deprecation
cpu = Build.CPU_ABI;
}
builder.append("Date Time: ").append(dateTime).append("\n");
builder.append("App Version: ").append(appName).append(" v").append(pi.versionName).append("(").append(pi.versionCode).append(")\n");
builder.append("Android OS: ").append(Build.VERSION.RELEASE).append("(").append(cpu).append(")\n");
builder.append("Phone Model: ").append(getDeviceModelName()).append("\n");
builder.append("Screen Pixel: ").append(pixels[0]).append("x").append(pixels[1]).append(",").append(pixels[2]).append("\n\n");
return builder.toString();
}
private static String writeMiniVPN(Context context) {
String[] abis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) abis = getSupportedABIsLollipop();
else
//noinspection deprecation
abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
String nativeAPI = NativeUtils.getNativeAPI();
if (!nativeAPI.equals(abis[0])) {
VpnStatus.logWarning(R.string.abi_mismatch, Arrays.toString(abis), nativeAPI);
abis = new String[]{nativeAPI};
}
for (String abi : abis) {
File vpnExecutable = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
if ((vpnExecutable.exists() && vpnExecutable.canExecute()) || writeMiniVPNBinary(context, abi, vpnExecutable)) {
return vpnExecutable.getPath();
}
}
return null;
}
private static String writeMiniVPN(Context context) {
String[] abis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
abis = getSupportedABIsLollipop();
else
//noinspection deprecation
abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
String nativeAPI = NativeUtils.getNativeAPI();
if (!nativeAPI.equals(abis[0])) {
VpnStatus.logWarning(R.string.abi_mismatch, Arrays.toString(abis), nativeAPI);
abis = new String[] {nativeAPI};
}
for (String abi: abis) {
File vpnExecutable = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
if ((vpnExecutable.exists() && vpnExecutable.canExecute()) || writeMiniVPNBinary(context, abi, vpnExecutable)) {
return vpnExecutable.getPath();
}
}
return null;
}
private static String writeMiniVPN(Context context) {
String[] abis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
abis = getSupportedABIsLollipop();
else
//noinspection deprecation
abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
String nativeAPI = NativeUtils.getNativeAPI();
if (!nativeAPI.equals(abis[0])) {
VpnStatus.logWarning(R.string.abi_mismatch, Arrays.toString(abis), nativeAPI);
abis = new String[] {nativeAPI};
}
for (String abi: abis) {
File vpnExecutable = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
if ((vpnExecutable.exists() && vpnExecutable.canExecute()) || writeMiniVPNBinary(context, abi, vpnExecutable)) {
return vpnExecutable.getPath();
}
}
return null;
}
private static String writeMiniVPN(Context context) {
String[] abis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) abis = getSupportedABIsLollipop();
else
//noinspection deprecation
abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
String nativeAPI = NativeUtils.getNativeAPI();
if (!nativeAPI.equals(abis[0])) {
VpnStatus.logWarning(R.string.abi_mismatch, Arrays.toString(abis), nativeAPI);
abis = new String[]{nativeAPI};
}
for (String abi : abis) {
File vpnExecutable = new File(context.getCacheDir(), getMiniVPNExecutableName() + "." + abi);
if ((vpnExecutable.exists() && vpnExecutable.canExecute()) || writeMiniVPNBinary(context, abi, vpnExecutable)) {
return vpnExecutable.getPath();
}
}
return null;
}
protected Void doInBackground(Void... params) {
DeleteBusybox();
if(Build.VERSION.SDK_INT >= 21){
s = Build.SUPPORTED_ABIS[0];
}else{
s = Build.CPU_ABI;
}
if(s.equals("arm64-v8a")){
CreateFile("busybox", R.raw.busybox_arm64);
}else if (s.contains("arm")){
CreateFile("busybox", R.raw.busybox_arm);
}else if(s.equals("x86")){
CreateFile("busybox", R.raw.busybox_x86);
}else if(s.equals("x86_64")){
CreateFile("busybox", R.raw.busybox_amd64);
}else if(s.equals("mips")){
CreateFile("busybox", R.raw.busybox_mips);
}else if(s.equals("mips64")){
CreateFile("busybox", R.raw.busybox_mips64);
}else{
Toast.makeText(context, "Sorry, your device is not supported !", Toast.LENGTH_LONG).show();
}
return null;
}
/**
* Helper method to create a salt for the crash identifier.
*
* @param context the context to use. Usually your Activity object.
*/
@SuppressLint("InlinedApi")
@SuppressWarnings("deprecation")
private static String createSalt(Context context) {
String abiString;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
abiString = Build.SUPPORTED_ABIS[0];
} else {
abiString = Build.CPU_ABI;
}
String fingerprint = "HA" + (Build.BOARD.length() % 10) + (Build.BRAND.length() % 10) +
(abiString.length() % 10) + (Build.PRODUCT.length() % 10);
String serial = "";
try {
serial = android.os.Build.class.getField("SERIAL").get(null).toString();
} catch (Throwable t) {
}
return fingerprint + ":" + serial;
}
private static String putCpuAbi() {
String[] abis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
abis = Build.SUPPORTED_ABIS;
} else {
abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
StringBuilder stringBuilder = new StringBuilder();
for (String abi : abis) {
stringBuilder.append(abi);
stringBuilder.append(",");
}
try {
return stringBuilder.toString().substring(0, stringBuilder.toString().length() - 1);
} catch (Exception e) {
Log.i(TAG, e.toString());
}
return null;
}
private static String writeMiniVPN(Context context) {
String[] abis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
abis = getSupportedABIsLollipop();
else
//noinspection deprecation
abis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
String nativeAPI = NativeUtils.getNativeAPI();
if (!nativeAPI.equals(abis[0])) {
VpnStatus.logWarning(R.string.abi_mismatch, Arrays.toString(abis), nativeAPI);
abis = new String[]{nativeAPI};
}
for (String abi : abis) {
File vpnExecutable = new File(context.getCacheDir(), "c_" + getMiniVPNExecutableName() + "." + abi);
if ((vpnExecutable.exists() && vpnExecutable.canExecute()) || writeMiniVPNBinary(context, abi, vpnExecutable)) {
return vpnExecutable.getPath();
}
}
throw new RuntimeException("Cannot find any execulte for this device's ABIs " + abis.toString());
}
protected Void doInBackground(Void... params) {
DeleteBusybox();
if(Build.VERSION.SDK_INT >= 21){
s = Build.SUPPORTED_ABIS[0];
}else{
s = Build.CPU_ABI;
}
if(s.equals("arm64-v8a")){
CreateFile("busybox", R.raw.busybox_arm64);
}else if (s.contains("arm")){
CreateFile("busybox", R.raw.busybox_arm);
}else if(s.equals("x86")){
CreateFile("busybox", R.raw.busybox_x86);
}else if(s.equals("x86_64")){
CreateFile("busybox", R.raw.busybox_amd64);
}else if(s.equals("mips")){
CreateFile("busybox", R.raw.busybox_mips);
}else if(s.equals("mips64")){
CreateFile("busybox", R.raw.busybox_mips64);
}else{
Toast.makeText(context, "Sorry, your device is not supported !", Toast.LENGTH_LONG).show();
}
return null;
}
public static String getABI() {
String abiString;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
abiString = Build.SUPPORTED_ABIS[0];
} else {
abiString = Build.CPU_ABI;
}
return abiString.toLowerCase().trim();
}
public static String[] getABIs() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return Build.SUPPORTED_ABIS;
} else {
if (!TextUtils.isEmpty(Build.CPU_ABI2)) {
return new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
return new String[]{Build.CPU_ABI};
}
}
@Override
public String[] supportedAbis() {
if (Build.VERSION.SDK_INT >= 21 && Build.SUPPORTED_ABIS.length > 0) {
return Build.SUPPORTED_ABIS;
} else if (!TextUtils.isEmpty(Build.CPU_ABI2)) {
return new String[] {Build.CPU_ABI, Build.CPU_ABI2};
} else {
return new String[] {Build.CPU_ABI};
}
}
@Architecture
private static int getDeviceArchitecture() {
final String primaryAbi = Build.CPU_ABI;
if (TextUtils.isEmpty(primaryAbi)) {
return Architecture.UNKNOWN;
}
final Integer arch = ARCHITECTURES_BY_NAME.get(primaryAbi.toLowerCase(Locale.US));
if (arch == null) {
return Architecture.UNKNOWN;
}
return arch;
}
private UUID generateDeviceUuid(Context context) {
// Get some of the hardware information
String buildParams = Build.BOARD + Build.BRAND + Build.CPU_ABI
+ Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST
+ Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT
+ Build.TAGS + Build.TYPE + Build.USER;
// Requires READ_PHONE_STATE
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
// gets the imei (GSM) or MEID/ESN (CDMA)
String imei = tm.getDeviceId();
// gets the android-assigned id
String androidId = Secure.getString(context.getContentResolver(),
Secure.ANDROID_ID);
// requires ACCESS_WIFI_STATE
WifiManager wm = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
// gets the MAC address
String mac = wm.getConnectionInfo().getMacAddress();
// if we've got nothing, return a random UUID
if (isEmpty(imei) && isEmpty(androidId) && isEmpty(mac)) {
return UUID.randomUUID();
}
// concatenate the string
String fullHash = buildParams.toString() + imei + androidId + mac;
return UUID.nameUUIDFromBytes(fullHash.getBytes());
}
/**
* 获取设备支持的abi列表
*/
public static String[] getSupportAbis() {
String[] cpuAbis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cpuAbis = Build.SUPPORTED_ABIS;
} else {
cpuAbis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
// avoid NPE
if (cpuAbis == null) {
cpuAbis = new String[0];
}
return cpuAbis;
}
public static CpuArch getCpuArch() {
Log.d("Build.CPU_ABI : " + Build.CPU_ABI);
switch (Build.CPU_ABI) {
case X86_CPU:
case X86_64_CPU:
return CpuArch.x86;
case ARM_64_CPU:
case ARM_V7_CPU:
return CpuArch.ARMv7;
default:
return CpuArch.NONE;
}
}
@Override
public String getABIS() {
return Build.CPU_ABI;
}
public static void loadLibrary(String libName) {
try {
ZipFile zipFile = new ZipFile(ReverseXposedModule.MODULE_PATH);
String soEntryPath;
if (Build.VERSION.SDK_INT >= 21) {
soEntryPath = "lib" + "/" + getSuitAbi() + "/lib" + libName + ".so";
} else {
soEntryPath = "lib" + "/" + Build.CPU_ABI + "/lib" + libName + ".so";
}
ZipEntry soEntry = zipFile.getEntry(soEntryPath);
if (soEntry.isDirectory()) {
Logger.log(soEntryPath + " in " + ReverseXposedModule.MODULE_PATH + " is not a file");
return;
} else {
File outFileDir = new File(ReverseXposedModule.APPINFO_DATA_DIR + "/" + CACHE_NAME + "/" + SO_CACHE_SECONDARY_FOLDER_NAME);
if (!outFileDir.exists()) {
outFileDir.mkdirs();
}
File outFile = new File(outFileDir, "lib" + libName + ".so");
FileOutputStream fileOutputStream = new FileOutputStream(outFile);
InputStream inputStream = zipFile.getInputStream(soEntry);
byte[] temp = new byte[2048];
int len;
while ((len = inputStream.read(temp)) != -1) {
fileOutputStream.write(temp, 0, len);
}
inputStream.close();
fileOutputStream.close();
System.load(outFile.getAbsolutePath());
outFile.delete();
outFileDir.delete();
outFileDir.getParentFile().delete();
}
} catch (IOException e) {
Logger.log("Load So File Error!");
e.printStackTrace();
}
}