android_content_res_Configuration.cpp revision 08d5b8fad8d46ccb64db2fdcb4d66972ec87bf48
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
26namespace android {
27
28static struct {
29    jclass clazz;
30
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} gConfigurationClassInfo;
44
45void android_Configuration_getFromJava(
46        JNIEnv* env, jobject clazz, struct AConfiguration* out) {
47    out->mcc = env->GetIntField(clazz, gConfigurationClassInfo.mcc);
48    out->mnc = env->GetIntField(clazz, gConfigurationClassInfo.mnc);
49    out->screenLayout = env->GetIntField(clazz, gConfigurationClassInfo.screenLayout);
50    out->touchscreen = env->GetIntField(clazz, gConfigurationClassInfo.touchscreen);
51    out->keyboard = env->GetIntField(clazz, gConfigurationClassInfo.keyboard);
52    out->navigation = env->GetIntField(clazz, gConfigurationClassInfo.navigation);
53
54    out->inputFlags = env->GetIntField(clazz, gConfigurationClassInfo.keyboardHidden);
55    int hardKeyboardHidden = env->GetIntField(clazz, gConfigurationClassInfo.hardKeyboardHidden);
56    if (out->inputFlags == ACONFIGURATION_KEYSHIDDEN_NO
57            && hardKeyboardHidden == 2) {
58        out->inputFlags = ACONFIGURATION_KEYSHIDDEN_SOFT;
59    }
60    out->inputFlags |= env->GetIntField(clazz, gConfigurationClassInfo.navigationHidden)
61            << ResTable_config::SHIFT_NAVHIDDEN;
62
63    out->orientation = env->GetIntField(clazz, gConfigurationClassInfo.orientation);
64    out->uiMode = env->GetIntField(clazz, gConfigurationClassInfo.uiMode);
65}
66
67/*
68 * JNI registration.
69 */
70static JNINativeMethod gMethods[] = {
71    /* name, signature, funcPtr */
72    //{ "getObbInfo_native", "(Ljava/lang/String;Landroid/content/res/ObbInfo;)Z",
73    //        (void*) android_content_res_ObbScanner_getObbInfo },
74};
75
76#define FIND_CLASS(var, className) \
77        var = env->FindClass(className); \
78        LOG_FATAL_IF(! var, "Unable to find class " className); \
79        var = jclass(env->NewGlobalRef(var));
80
81#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
82        var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
83        LOG_FATAL_IF(! var, "Unable to find field " fieldName);
84
85int register_android_content_res_Configuration(JNIEnv* env)
86{
87    FIND_CLASS(gConfigurationClassInfo.clazz, "android/content/res/Configuration");
88
89    GET_FIELD_ID(gConfigurationClassInfo.mcc, gConfigurationClassInfo.clazz,
90            "mcc", "I");
91    GET_FIELD_ID(gConfigurationClassInfo.mnc, gConfigurationClassInfo.clazz,
92            "mnc", "I");
93    GET_FIELD_ID(gConfigurationClassInfo.locale, gConfigurationClassInfo.clazz,
94            "locale", "Ljava/util/Locale;");
95    GET_FIELD_ID(gConfigurationClassInfo.screenLayout, gConfigurationClassInfo.clazz,
96            "screenLayout", "I");
97    GET_FIELD_ID(gConfigurationClassInfo.touchscreen, gConfigurationClassInfo.clazz,
98            "touchscreen", "I");
99    GET_FIELD_ID(gConfigurationClassInfo.keyboard, gConfigurationClassInfo.clazz,
100            "keyboard", "I");
101    GET_FIELD_ID(gConfigurationClassInfo.keyboardHidden, gConfigurationClassInfo.clazz,
102            "keyboardHidden", "I");
103    GET_FIELD_ID(gConfigurationClassInfo.hardKeyboardHidden, gConfigurationClassInfo.clazz,
104            "hardKeyboardHidden", "I");
105    GET_FIELD_ID(gConfigurationClassInfo.navigation, gConfigurationClassInfo.clazz,
106            "navigation", "I");
107    GET_FIELD_ID(gConfigurationClassInfo.navigationHidden, gConfigurationClassInfo.clazz,
108            "navigationHidden", "I");
109    GET_FIELD_ID(gConfigurationClassInfo.orientation, gConfigurationClassInfo.clazz,
110            "orientation", "I");
111    GET_FIELD_ID(gConfigurationClassInfo.uiMode, gConfigurationClassInfo.clazz,
112            "uiMode", "I");
113
114    return AndroidRuntime::registerNativeMethods(env, "android/content/res/Configuration", gMethods,
115            NELEM(gMethods));
116}
117
118}; // namespace android
119