blob: 3b45e72c110bf71b47506525af7cdcb3e16ab72e [file] [log] [blame]
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001/*
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 Gampe987f79f2014-11-18 17:29:46 -080026#include "core_jni_helpers.h"
27
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070028namespace android {
29
30static struct {
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070031 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 Hackborn69cb8752011-05-19 18:13:32 -070043 jfieldID screenWidthDp;
44 jfieldID screenHeightDp;
45 jfieldID smallestScreenWidthDp;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070046} gConfigurationClassInfo;
47
48void 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 Hackborn69cb8752011-05-19 18:13:32 -070068
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 Hackborn08d5b8f2010-08-04 11:12:40 -070073}
74
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070075int register_android_content_res_Configuration(JNIEnv* env)
76{
Andreas Gampe987f79f2014-11-18 17:29:46 -080077 jclass clazz = FindClassOrDie(env, "android/content/res/Configuration");
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070078
Andreas Gampe987f79f2014-11-18 17:29:46 -080079 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 Hackborn08d5b8f2010-08-04 11:12:40 -070096
Narayan Kamathf83c73e2014-03-19 14:13:27 +000097 return 0;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070098}
99
100}; // namespace android