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
android_cts_CpuFeatures_isArmCpu(JNIEnv * env,jobject thiz)22 jboolean android_cts_CpuFeatures_isArmCpu(JNIEnv* env, jobject thiz)
23 {
24 AndroidCpuFamily cpuFamily = android_getCpuFamily();
25 return cpuFamily == ANDROID_CPU_FAMILY_ARM;
26 }
27
android_cts_CpuFeatures_isX86Cpu(JNIEnv * env,jobject thiz)28 jboolean android_cts_CpuFeatures_isX86Cpu(JNIEnv* env, jobject thiz)
29 {
30 AndroidCpuFamily cpuFamily = android_getCpuFamily();
31 return cpuFamily == ANDROID_CPU_FAMILY_X86;
32 }
33
android_cts_CpuFeatures_isArm64Cpu(JNIEnv * env,jobject thiz)34 jboolean android_cts_CpuFeatures_isArm64Cpu(JNIEnv* env, jobject thiz)
35 {
36 AndroidCpuFamily cpuFamily = android_getCpuFamily();
37 return cpuFamily == ANDROID_CPU_FAMILY_ARM64;
38 }
39
android_cts_CpuFeatures_isX86_64Cpu(JNIEnv * env,jobject thiz)40 jboolean android_cts_CpuFeatures_isX86_64Cpu(JNIEnv* env, jobject thiz)
41 {
42 AndroidCpuFamily cpuFamily = android_getCpuFamily();
43 return cpuFamily == ANDROID_CPU_FAMILY_X86_64;
44 }
45
android_cts_CpuFeatures_getHwCaps(JNIEnv *,jobject)46 jint android_cts_CpuFeatures_getHwCaps(JNIEnv*, jobject)
47 {
48 return (jint)getauxval(AT_HWCAP);
49 }
50
51 static JNINativeMethod gMethods[] = {
52 { "isArmCpu", "()Z",
53 (void *) android_cts_CpuFeatures_isArmCpu },
54 { "isX86Cpu", "()Z",
55 (void *) android_cts_CpuFeatures_isX86Cpu },
56 { "isArm64Cpu", "()Z",
57 (void *) android_cts_CpuFeatures_isArm64Cpu },
58 { "isX86_64Cpu", "()Z",
59 (void *) android_cts_CpuFeatures_isX86_64Cpu },
60 { "getHwCaps", "()I",
61 (void *) android_cts_CpuFeatures_getHwCaps },
62 };
63
register_android_cts_CpuFeatures(JNIEnv * env)64 int register_android_cts_CpuFeatures(JNIEnv* env)
65 {
66 jclass clazz = env->FindClass("com/android/compatibility/common/util/CpuFeatures");
67
68 return env->RegisterNatives(clazz, gMethods,
69 sizeof(gMethods) / sizeof(JNINativeMethod));
70 }
71