Skip to content

Commit

Permalink
[tinker] Fix: getCurrentInstructionSet() failed on some Android 4.4 d…
Browse files Browse the repository at this point in the history
…evices.
  • Loading branch information
tangyinsheng committed Sep 21, 2022
1 parent 56b46dc commit 9d14908
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,41 @@ public static boolean isAfterAndroidO() {
return Build.VERSION.SDK_INT > 25;
}

public static String getCurrentInstructionSet() throws Exception {
public static String getCurrentInstructionSet() {
if (currentInstructionSet != null) {
return currentInstructionSet;
}
Class<?> clazz = Class.forName("dalvik.system.VMRuntime");
Method currentGet = clazz.getDeclaredMethod("getCurrentInstructionSet");

currentInstructionSet = (String) currentGet.invoke(null);
try {
Class<?> clazz = Class.forName("dalvik.system.VMRuntime");
Method currentGet = clazz.getDeclaredMethod("getCurrentInstructionSet");
currentGet.setAccessible(true);
currentInstructionSet = (String) currentGet.invoke(null);
} catch (Throwable ignored) {
switch (Build.CPU_ABI) {
case "armeabi":
case "armeabi-v7a":
currentInstructionSet = "arm";
break;
case "arm64-v8a":
currentInstructionSet = "arm64";
break;
case "x86":
currentInstructionSet = "x86";
break;
case "x86_64":
currentInstructionSet = "x86_64";
break;
case "mips":
currentInstructionSet = "mips";
break;
case "mips64":
currentInstructionSet = "mips64";
break;
default:
throw new IllegalStateException("Unsupported abi: " + Build.CPU_ABI);
}
}
ShareTinkerLog.d(TAG, "getCurrentInstructionSet:" + currentInstructionSet);
return currentInstructionSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public static String getCurrentInstructionSet() {
} catch (Throwable ignored) {
switch (Build.CPU_ABI) {
case "armeabi":
case "armeabi_v7a":
case "armeabi-v7a":
currentInstructionSet = "arm";
break;
case "arm64_v8a":
case "arm64-v8a":
currentInstructionSet = "arm64";
break;
case "x86":
Expand Down

0 comments on commit 9d14908

Please sign in to comment.