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 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 26 | #include "core_jni_helpers.h" |
| 27 | |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | |
| 30 | static struct { |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 31 | jfieldID mcc; |
| 32 | jfieldID mnc; |
| 33 | jfieldID locale; |
| 34 | jfieldID screenLayout; |
| 35 | jfieldID touchscreen; |
| 36 | jfieldID keyboard; |
| 37 | jfieldID keyboardHidden; |
| 38 | jfieldID hardKeyboardHidden; |
| 39 | jfieldID navigation; |
| 40 | jfieldID navigationHidden; |
| 41 | jfieldID orientation; |
| 42 | jfieldID uiMode; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 43 | jfieldID screenWidthDp; |
| 44 | jfieldID screenHeightDp; |
| 45 | jfieldID smallestScreenWidthDp; |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 46 | } gConfigurationClassInfo; |
| 47 | |
| 48 | void android_Configuration_getFromJava( |
| 49 | JNIEnv* env, jobject clazz, struct AConfiguration* out) { |
| 50 | out->mcc = env->GetIntField(clazz, gConfigurationClassInfo.mcc); |
| 51 | out->mnc = env->GetIntField(clazz, gConfigurationClassInfo.mnc); |
| 52 | out->screenLayout = env->GetIntField(clazz, gConfigurationClassInfo.screenLayout); |
| 53 | out->touchscreen = env->GetIntField(clazz, gConfigurationClassInfo.touchscreen); |
| 54 | out->keyboard = env->GetIntField(clazz, gConfigurationClassInfo.keyboard); |
| 55 | out->navigation = env->GetIntField(clazz, gConfigurationClassInfo.navigation); |
| 56 | |
| 57 | out->inputFlags = env->GetIntField(clazz, gConfigurationClassInfo.keyboardHidden); |
| 58 | int hardKeyboardHidden = env->GetIntField(clazz, gConfigurationClassInfo.hardKeyboardHidden); |
| 59 | if (out->inputFlags == ACONFIGURATION_KEYSHIDDEN_NO |
| 60 | && hardKeyboardHidden == 2) { |
| 61 | out->inputFlags = ACONFIGURATION_KEYSHIDDEN_SOFT; |
| 62 | } |
| 63 | out->inputFlags |= env->GetIntField(clazz, gConfigurationClassInfo.navigationHidden) |
| 64 | << ResTable_config::SHIFT_NAVHIDDEN; |
| 65 | |
| 66 | out->orientation = env->GetIntField(clazz, gConfigurationClassInfo.orientation); |
| 67 | out->uiMode = env->GetIntField(clazz, gConfigurationClassInfo.uiMode); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 68 | |
| 69 | out->screenWidthDp = env->GetIntField(clazz, gConfigurationClassInfo.screenWidthDp); |
| 70 | out->screenHeightDp = env->GetIntField(clazz, gConfigurationClassInfo.screenHeightDp); |
| 71 | out->smallestScreenWidthDp = env->GetIntField(clazz, |
| 72 | gConfigurationClassInfo.smallestScreenWidthDp); |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 75 | int register_android_content_res_Configuration(JNIEnv* env) |
| 76 | { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 77 | jclass clazz = FindClassOrDie(env, "android/content/res/Configuration"); |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 78 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 79 | gConfigurationClassInfo.mcc = GetFieldIDOrDie(env, clazz, "mcc", "I"); |
| 80 | gConfigurationClassInfo.mnc = GetFieldIDOrDie(env, clazz, "mnc", "I"); |
| 81 | gConfigurationClassInfo.locale = GetFieldIDOrDie(env, clazz, "locale", "Ljava/util/Locale;"); |
| 82 | gConfigurationClassInfo.screenLayout = GetFieldIDOrDie(env, clazz, "screenLayout", "I"); |
| 83 | gConfigurationClassInfo.touchscreen = GetFieldIDOrDie(env, clazz, "touchscreen", "I"); |
| 84 | gConfigurationClassInfo.keyboard = GetFieldIDOrDie(env, clazz, "keyboard", "I"); |
| 85 | gConfigurationClassInfo.keyboardHidden = GetFieldIDOrDie(env, clazz, "keyboardHidden", "I"); |
| 86 | gConfigurationClassInfo.hardKeyboardHidden = GetFieldIDOrDie(env, clazz, "hardKeyboardHidden", |
| 87 | "I"); |
| 88 | gConfigurationClassInfo.navigation = GetFieldIDOrDie(env, clazz, "navigation", "I"); |
| 89 | gConfigurationClassInfo.navigationHidden = GetFieldIDOrDie(env, clazz, "navigationHidden", "I"); |
| 90 | gConfigurationClassInfo.orientation = GetFieldIDOrDie(env, clazz, "orientation", "I"); |
| 91 | gConfigurationClassInfo.uiMode = GetFieldIDOrDie(env, clazz, "uiMode", "I"); |
| 92 | gConfigurationClassInfo.screenWidthDp = GetFieldIDOrDie(env, clazz, "screenWidthDp", "I"); |
| 93 | gConfigurationClassInfo.screenHeightDp = GetFieldIDOrDie(env, clazz, "screenHeightDp", "I"); |
| 94 | gConfigurationClassInfo.smallestScreenWidthDp = GetFieldIDOrDie(env, clazz, |
| 95 | "smallestScreenWidthDp", "I"); |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 96 | |
Narayan Kamath | f83c73e | 2014-03-19 14:13:27 +0000 | [diff] [blame] | 97 | return 0; |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | }; // namespace android |