1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 #include <cpu-features.h> 18 #include <jni.h> 19 #include <string.h> 20 #include <sys/auxv.h> 21 22 jboolean android_os_cts_CpuFeatures_isArmCpu(JNIEnv* env, jobject thiz) 23 { 24 AndroidCpuFamily cpuFamily = android_getCpuFamily(); 25 return cpuFamily == ANDROID_CPU_FAMILY_ARM; 26 } 27 28 jboolean android_os_cts_CpuFeatures_isArm7Compatible(JNIEnv* env, jobject thiz) 29 { 30 uint64_t cpuFeatures = android_getCpuFeatures(); 31 return (cpuFeatures & ANDROID_CPU_ARM_FEATURE_ARMv7) == ANDROID_CPU_ARM_FEATURE_ARMv7; 32 } 33 34 jboolean android_os_cts_CpuFeatures_isMipsCpu(JNIEnv* env, jobject thiz) 35 { 36 AndroidCpuFamily cpuFamily = android_getCpuFamily(); 37 return cpuFamily == ANDROID_CPU_FAMILY_MIPS; 38 } 39 40 jboolean android_os_cts_CpuFeatures_isX86Cpu(JNIEnv* env, jobject thiz) 41 { 42 AndroidCpuFamily cpuFamily = android_getCpuFamily(); 43 return cpuFamily == ANDROID_CPU_FAMILY_X86; 44 } 45 46 jboolean android_os_cts_CpuFeatures_isArm64Cpu(JNIEnv* env, jobject thiz) 47 { 48 AndroidCpuFamily cpuFamily = android_getCpuFamily(); 49 return cpuFamily == ANDROID_CPU_FAMILY_ARM64; 50 } 51 52 jboolean android_os_cts_CpuFeatures_isMips64Cpu(JNIEnv* env, jobject thiz) 53 { 54 AndroidCpuFamily cpuFamily = android_getCpuFamily(); 55 return cpuFamily == ANDROID_CPU_FAMILY_MIPS64; 56 } 57 58 jboolean android_os_cts_CpuFeatures_isX86_64Cpu(JNIEnv* env, jobject thiz) 59 { 60 AndroidCpuFamily cpuFamily = android_getCpuFamily(); 61 return cpuFamily == ANDROID_CPU_FAMILY_X86_64; 62 } 63 64 jint android_os_cts_CpuFeatures_getHwCaps(JNIEnv*, jobject) 65 { 66 return (jint)getauxval(AT_HWCAP); 67 } 68 69 static JNINativeMethod gMethods[] = { 70 { "isArmCpu", "()Z", 71 (void *) android_os_cts_CpuFeatures_isArmCpu }, 72 { "isArm7Compatible", "()Z", 73 (void *) android_os_cts_CpuFeatures_isArm7Compatible }, 74 { "isMipsCpu", "()Z", 75 (void *) android_os_cts_CpuFeatures_isMipsCpu }, 76 { "isX86Cpu", "()Z", 77 (void *) android_os_cts_CpuFeatures_isX86Cpu }, 78 { "isArm64Cpu", "()Z", 79 (void *) android_os_cts_CpuFeatures_isArm64Cpu }, 80 { "isMips64Cpu", "()Z", 81 (void *) android_os_cts_CpuFeatures_isMips64Cpu }, 82 { "isX86_64Cpu", "()Z", 83 (void *) android_os_cts_CpuFeatures_isX86_64Cpu }, 84 { "getHwCaps", "()I", 85 (void *) android_os_cts_CpuFeatures_getHwCaps }, 86 }; 87 88 int register_android_os_cts_CpuFeatures(JNIEnv* env) 89 { 90 jclass clazz = env->FindClass("android/os/cts/CpuFeatures"); 91 92 return env->RegisterNatives(clazz, gMethods, 93 sizeof(gMethods) / sizeof(JNINativeMethod)); 94 } 95