blob: 246e3bd229a0f470c55c45b56a2c3331aeec3de7 [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
26namespace android {
27
28static struct {
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070029 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;
Dianne Hackborn69cb8752011-05-19 18:13:32 -070041 jfieldID screenWidthDp;
42 jfieldID screenHeightDp;
43 jfieldID smallestScreenWidthDp;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070044} gConfigurationClassInfo;
45
46void android_Configuration_getFromJava(
47 JNIEnv* env, jobject clazz, struct AConfiguration* out) {
48 out->mcc = env->GetIntField(clazz, gConfigurationClassInfo.mcc);
49 out->mnc = env->GetIntField(clazz, gConfigurationClassInfo.mnc);
50 out->screenLayout = env->GetIntField(clazz, gConfigurationClassInfo.screenLayout);
51 out->touchscreen = env->GetIntField(clazz, gConfigurationClassInfo.touchscreen);
52 out->keyboard = env->GetIntField(clazz, gConfigurationClassInfo.keyboard);
53 out->navigation = env->GetIntField(clazz, gConfigurationClassInfo.navigation);
54
55 out->inputFlags = env->GetIntField(clazz, gConfigurationClassInfo.keyboardHidden);
56 int hardKeyboardHidden = env->GetIntField(clazz, gConfigurationClassInfo.hardKeyboardHidden);
57 if (out->inputFlags == ACONFIGURATION_KEYSHIDDEN_NO
58 && hardKeyboardHidden == 2) {
59 out->inputFlags = ACONFIGURATION_KEYSHIDDEN_SOFT;
60 }
61 out->inputFlags |= env->GetIntField(clazz, gConfigurationClassInfo.navigationHidden)
62 << ResTable_config::SHIFT_NAVHIDDEN;
63
64 out->orientation = env->GetIntField(clazz, gConfigurationClassInfo.orientation);
65 out->uiMode = env->GetIntField(clazz, gConfigurationClassInfo.uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -070066
67 out->screenWidthDp = env->GetIntField(clazz, gConfigurationClassInfo.screenWidthDp);
68 out->screenHeightDp = env->GetIntField(clazz, gConfigurationClassInfo.screenHeightDp);
69 out->smallestScreenWidthDp = env->GetIntField(clazz,
70 gConfigurationClassInfo.smallestScreenWidthDp);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070071}
72
73/*
74 * JNI registration.
75 */
76static JNINativeMethod gMethods[] = {
77 /* name, signature, funcPtr */
78 //{ "getObbInfo_native", "(Ljava/lang/String;Landroid/content/res/ObbInfo;)Z",
79 // (void*) android_content_res_ObbScanner_getObbInfo },
80};
81
82#define FIND_CLASS(var, className) \
83 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -080084 LOG_FATAL_IF(! var, "Unable to find class " className);
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070085
86#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
87 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
88 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
89
90int register_android_content_res_Configuration(JNIEnv* env)
91{
Carl Shapiro17cc33a2011-03-05 20:53:16 -080092 jclass clazz;
93 FIND_CLASS(clazz, "android/content/res/Configuration");
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070094
Carl Shapiro17cc33a2011-03-05 20:53:16 -080095 GET_FIELD_ID(gConfigurationClassInfo.mcc, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070096 "mcc", "I");
Carl Shapiro17cc33a2011-03-05 20:53:16 -080097 GET_FIELD_ID(gConfigurationClassInfo.mnc, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070098 "mnc", "I");
Carl Shapiro17cc33a2011-03-05 20:53:16 -080099 GET_FIELD_ID(gConfigurationClassInfo.locale, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700100 "locale", "Ljava/util/Locale;");
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800101 GET_FIELD_ID(gConfigurationClassInfo.screenLayout, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700102 "screenLayout", "I");
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800103 GET_FIELD_ID(gConfigurationClassInfo.touchscreen, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700104 "touchscreen", "I");
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800105 GET_FIELD_ID(gConfigurationClassInfo.keyboard, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700106 "keyboard", "I");
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800107 GET_FIELD_ID(gConfigurationClassInfo.keyboardHidden, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700108 "keyboardHidden", "I");
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800109 GET_FIELD_ID(gConfigurationClassInfo.hardKeyboardHidden, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700110 "hardKeyboardHidden", "I");
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800111 GET_FIELD_ID(gConfigurationClassInfo.navigation, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700112 "navigation", "I");
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800113 GET_FIELD_ID(gConfigurationClassInfo.navigationHidden, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700114 "navigationHidden", "I");
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800115 GET_FIELD_ID(gConfigurationClassInfo.orientation, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700116 "orientation", "I");
Carl Shapiro17cc33a2011-03-05 20:53:16 -0800117 GET_FIELD_ID(gConfigurationClassInfo.uiMode, clazz,
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700118 "uiMode", "I");
Dianne Hackbornfef966a2011-05-19 22:02:22 -0700119 GET_FIELD_ID(gConfigurationClassInfo.screenWidthDp, clazz,
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700120 "screenWidthDp", "I");
Dianne Hackbornfef966a2011-05-19 22:02:22 -0700121 GET_FIELD_ID(gConfigurationClassInfo.screenHeightDp, clazz,
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700122 "screenHeightDp", "I");
Dianne Hackbornfef966a2011-05-19 22:02:22 -0700123 GET_FIELD_ID(gConfigurationClassInfo.smallestScreenWidthDp, clazz,
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700124 "smallestScreenWidthDp", "I");
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700125
126 return AndroidRuntime::registerNativeMethods(env, "android/content/res/Configuration", gMethods,
127 NELEM(gMethods));
128}
129
130}; // namespace android