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#include "core_jni_helpers.h"
27
28namespace android {
29
30static struct {
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;
43    jfieldID screenWidthDp;
44    jfieldID screenHeightDp;
45    jfieldID smallestScreenWidthDp;
46} 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);
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);
73}
74
75int register_android_content_res_Configuration(JNIEnv* env)
76{
77    jclass clazz = FindClassOrDie(env, "android/content/res/Configuration");
78
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");
96
97    return 0;
98}
99
100}; // namespace android
101