Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | #define LOG_TAG "Configuration" |
| 18 | |
| 19 | #include <utils/Log.h> |
| 20 | #include "utils/misc.h" |
| 21 | |
| 22 | #include "jni.h" |
| 23 | #include <android_runtime/android_content_res_Configuration.h> |
| 24 | #include "android_runtime/AndroidRuntime.h" |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | static struct { |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 29 | jfieldID mcc; |
| 30 | jfieldID mnc; |
| 31 | jfieldID locale; |
| 32 | jfieldID screenLayout; |
| 33 | jfieldID touchscreen; |
| 34 | jfieldID keyboard; |
| 35 | jfieldID keyboardHidden; |
| 36 | jfieldID hardKeyboardHidden; |
| 37 | jfieldID navigation; |
| 38 | jfieldID navigationHidden; |
| 39 | jfieldID orientation; |
| 40 | jfieldID uiMode; |
| 41 | } gConfigurationClassInfo; |
| 42 | |
| 43 | void android_Configuration_getFromJava( |
| 44 | JNIEnv* env, jobject clazz, struct AConfiguration* out) { |
| 45 | out->mcc = env->GetIntField(clazz, gConfigurationClassInfo.mcc); |
| 46 | out->mnc = env->GetIntField(clazz, gConfigurationClassInfo.mnc); |
| 47 | out->screenLayout = env->GetIntField(clazz, gConfigurationClassInfo.screenLayout); |
| 48 | out->touchscreen = env->GetIntField(clazz, gConfigurationClassInfo.touchscreen); |
| 49 | out->keyboard = env->GetIntField(clazz, gConfigurationClassInfo.keyboard); |
| 50 | out->navigation = env->GetIntField(clazz, gConfigurationClassInfo.navigation); |
| 51 | |
| 52 | out->inputFlags = env->GetIntField(clazz, gConfigurationClassInfo.keyboardHidden); |
| 53 | int hardKeyboardHidden = env->GetIntField(clazz, gConfigurationClassInfo.hardKeyboardHidden); |
| 54 | if (out->inputFlags == ACONFIGURATION_KEYSHIDDEN_NO |
| 55 | && hardKeyboardHidden == 2) { |
| 56 | out->inputFlags = ACONFIGURATION_KEYSHIDDEN_SOFT; |
| 57 | } |
| 58 | out->inputFlags |= env->GetIntField(clazz, gConfigurationClassInfo.navigationHidden) |
| 59 | << ResTable_config::SHIFT_NAVHIDDEN; |
| 60 | |
| 61 | out->orientation = env->GetIntField(clazz, gConfigurationClassInfo.orientation); |
| 62 | out->uiMode = env->GetIntField(clazz, gConfigurationClassInfo.uiMode); |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * JNI registration. |
| 67 | */ |
| 68 | static JNINativeMethod gMethods[] = { |
| 69 | /* name, signature, funcPtr */ |
| 70 | //{ "getObbInfo_native", "(Ljava/lang/String;Landroid/content/res/ObbInfo;)Z", |
| 71 | // (void*) android_content_res_ObbScanner_getObbInfo }, |
| 72 | }; |
| 73 | |
| 74 | #define FIND_CLASS(var, className) \ |
| 75 | var = env->FindClass(className); \ |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 76 | LOG_FATAL_IF(! var, "Unable to find class " className); |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 77 | |
| 78 | #define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \ |
| 79 | var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \ |
| 80 | LOG_FATAL_IF(! var, "Unable to find field " fieldName); |
| 81 | |
| 82 | int register_android_content_res_Configuration(JNIEnv* env) |
| 83 | { |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 84 | jclass clazz; |
| 85 | FIND_CLASS(clazz, "android/content/res/Configuration"); |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 86 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 87 | GET_FIELD_ID(gConfigurationClassInfo.mcc, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 88 | "mcc", "I"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 89 | GET_FIELD_ID(gConfigurationClassInfo.mnc, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 90 | "mnc", "I"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 91 | GET_FIELD_ID(gConfigurationClassInfo.locale, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 92 | "locale", "Ljava/util/Locale;"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 93 | GET_FIELD_ID(gConfigurationClassInfo.screenLayout, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 94 | "screenLayout", "I"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 95 | GET_FIELD_ID(gConfigurationClassInfo.touchscreen, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 96 | "touchscreen", "I"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 97 | GET_FIELD_ID(gConfigurationClassInfo.keyboard, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 98 | "keyboard", "I"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 99 | GET_FIELD_ID(gConfigurationClassInfo.keyboardHidden, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 100 | "keyboardHidden", "I"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 101 | GET_FIELD_ID(gConfigurationClassInfo.hardKeyboardHidden, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 102 | "hardKeyboardHidden", "I"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 103 | GET_FIELD_ID(gConfigurationClassInfo.navigation, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 104 | "navigation", "I"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 105 | GET_FIELD_ID(gConfigurationClassInfo.navigationHidden, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 106 | "navigationHidden", "I"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 107 | GET_FIELD_ID(gConfigurationClassInfo.orientation, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 108 | "orientation", "I"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 109 | GET_FIELD_ID(gConfigurationClassInfo.uiMode, clazz, |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 110 | "uiMode", "I"); |
| 111 | |
| 112 | return AndroidRuntime::registerNativeMethods(env, "android/content/res/Configuration", gMethods, |
| 113 | NELEM(gMethods)); |
| 114 | } |
| 115 | |
| 116 | }; // namespace android |