blob: 87fe9edb49c514e5f09cb4716a49e0cc9676d19c [file] [log] [blame]
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -07001/*
2 * Copyright (C) 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#include <utils/Log.h>
19
Adam Lesinskibebfcc42018-02-12 14:27:46 -080020#include <androidfw/AssetManager2.h>
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070021
22#include <android_runtime/android_content_res_Configuration.h>
Adam Lesinskibebfcc42018-02-12 14:27:46 -080023#include <android_runtime/android_util_AssetManager.h>
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070024
25using namespace android;
26
27AConfiguration* AConfiguration_new() {
28 AConfiguration* config = new AConfiguration;
29 memset(config, 0, sizeof(AConfiguration));
30 return config;
31}
32
33void AConfiguration_delete(AConfiguration* config) {
34 delete config;
35}
36
37void AConfiguration_fromAssetManager(AConfiguration* out, AAssetManager* am) {
Adam Lesinskibebfcc42018-02-12 14:27:46 -080038 ScopedLock<AssetManager2> locked_mgr(*AssetManagerForNdkAssetManager(am));
39 ResTable_config config = locked_mgr->GetConfiguration();
40
41 // AConfiguration is not a virtual subclass, so we can memcpy.
42 memcpy(out, &config, sizeof(config));
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070043}
44
45void AConfiguration_copy(AConfiguration* dest, AConfiguration* src) {
46 *dest = *src;
47}
48
49int32_t AConfiguration_getMcc(AConfiguration* config) {
50 return config->mcc;
51}
52
53int32_t AConfiguration_getMnc(AConfiguration* config) {
54 return config->mnc;
55}
56
57void AConfiguration_getLanguage(AConfiguration* config, char* outLanguage) {
58 outLanguage[0] = config->language[0];
59 outLanguage[1] = config->language[1];
60}
61
62void AConfiguration_getCountry(AConfiguration* config, char* outCountry) {
63 outCountry[0] = config->country[0];
64 outCountry[1] = config->country[1];
65}
66
67int32_t AConfiguration_getOrientation(AConfiguration* config) {
68 return config->orientation;
69}
70
71int32_t AConfiguration_getTouchscreen(AConfiguration* config) {
72 return config->touchscreen;
73}
74
75int32_t AConfiguration_getDensity(AConfiguration* config) {
76 return config->density;
77}
78
79int32_t AConfiguration_getKeyboard(AConfiguration* config) {
80 return config->keyboard;
81}
82
83int32_t AConfiguration_getNavigation(AConfiguration* config) {
84 return config->navigation;
85}
86
87int32_t AConfiguration_getKeysHidden(AConfiguration* config) {
88 return config->inputFlags&ResTable_config::MASK_KEYSHIDDEN;
89}
90
91int32_t AConfiguration_getNavHidden(AConfiguration* config) {
92 return (config->inputFlags&ResTable_config::MASK_NAVHIDDEN)
93 >> ResTable_config::SHIFT_NAVHIDDEN;
94}
95
96int32_t AConfiguration_getSdkVersion(AConfiguration* config) {
97 return config->sdkVersion;
98}
99
100int32_t AConfiguration_getScreenSize(AConfiguration* config) {
101 return config->screenLayout&ResTable_config::MASK_SCREENSIZE;
102}
103
104int32_t AConfiguration_getScreenLong(AConfiguration* config) {
105 return (config->screenLayout&ResTable_config::MASK_SCREENLONG)
106 >> ResTable_config::SHIFT_SCREENLONG;
107}
108
Adam Lesinski2738c962015-05-14 14:25:36 -0700109int32_t AConfiguration_getScreenRound(AConfiguration* config) {
110 return (config->screenLayout2&ResTable_config::MASK_SCREENROUND);
111}
112
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700113int32_t AConfiguration_getUiModeType(AConfiguration* config) {
114 return config->uiMode&ResTable_config::MASK_UI_MODE_TYPE;
115}
116
117int32_t AConfiguration_getUiModeNight(AConfiguration* config) {
118 return (config->uiMode&ResTable_config::MASK_UI_MODE_NIGHT)
119 >> ResTable_config::SHIFT_UI_MODE_NIGHT;
120
121}
122
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700123int32_t AConfiguration_getScreenWidthDp(AConfiguration* config) {
124 return config->screenWidthDp;
125}
126
127int32_t AConfiguration_getScreenHeightDp(AConfiguration* config) {
128 return config->screenHeightDp;
129}
130
131int32_t AConfiguration_getSmallestScreenWidthDp(AConfiguration* config) {
132 return config->smallestScreenWidthDp;
133}
134
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700135int32_t AConfiguration_getLayoutDirection(AConfiguration* config) {
136 return (config->screenLayout&ResTable_config::MASK_LAYOUTDIR)
137 >> ResTable_config::SHIFT_LAYOUTDIR;
138}
139
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700140// ----------------------------------------------------------------------
141
142void AConfiguration_setMcc(AConfiguration* config, int32_t mcc) {
143 config->mcc = mcc;
144}
145
146void AConfiguration_setMnc(AConfiguration* config, int32_t mnc) {
147 config->mnc = mnc;
148}
149
150void AConfiguration_setLanguage(AConfiguration* config, const char* language) {
151 config->language[0] = language[0];
152 config->language[1] = language[1];
153}
154
155void AConfiguration_setCountry(AConfiguration* config, const char* country) {
156 config->country[0] = country[0];
157 config->country[1] = country[1];
158}
159
160void AConfiguration_setOrientation(AConfiguration* config, int32_t orientation) {
161 config->orientation = orientation;
162}
163
164void AConfiguration_setTouchscreen(AConfiguration* config, int32_t touchscreen) {
165 config->touchscreen = touchscreen;
166}
167
168void AConfiguration_setDensity(AConfiguration* config, int32_t density) {
169 config->density = density;
170}
171
172void AConfiguration_setKeyboard(AConfiguration* config, int32_t keyboard) {
173 config->keyboard = keyboard;
174}
175
176void AConfiguration_setNavigation(AConfiguration* config, int32_t navigation) {
177 config->navigation = navigation;
178}
179
180void AConfiguration_setKeysHidden(AConfiguration* config, int32_t keysHidden) {
181 config->inputFlags = (config->inputFlags&~ResTable_config::MASK_KEYSHIDDEN)
182 | (keysHidden&ResTable_config::MASK_KEYSHIDDEN);
183}
184
185void AConfiguration_setNavHidden(AConfiguration* config, int32_t navHidden) {
186 config->inputFlags = (config->inputFlags&~ResTable_config::MASK_NAVHIDDEN)
187 | ((navHidden<<ResTable_config::SHIFT_NAVHIDDEN)&ResTable_config::MASK_NAVHIDDEN);
188}
189
190void AConfiguration_setSdkVersion(AConfiguration* config, int32_t sdkVersion) {
191 config->sdkVersion = sdkVersion;
192}
193
194void AConfiguration_setScreenSize(AConfiguration* config, int32_t screenSize) {
195 config->screenLayout = (config->screenLayout&~ResTable_config::MASK_SCREENSIZE)
196 | (screenSize&ResTable_config::MASK_SCREENSIZE);
197}
198
199void AConfiguration_setScreenLong(AConfiguration* config, int32_t screenLong) {
200 config->screenLayout = (config->screenLayout&~ResTable_config::MASK_SCREENLONG)
201 | ((screenLong<<ResTable_config::SHIFT_SCREENLONG)&ResTable_config::MASK_SCREENLONG);
202}
203
Adam Lesinski2738c962015-05-14 14:25:36 -0700204void AConfiguration_setScreenRound(AConfiguration* config, int32_t screenRound) {
205 config->screenLayout2 = (config->screenLayout2&~ResTable_config::MASK_SCREENROUND)
206 | (screenRound&ResTable_config::MASK_SCREENROUND);
207}
208
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700209void AConfiguration_setUiModeType(AConfiguration* config, int32_t uiModeType) {
210 config->uiMode = (config->uiMode&~ResTable_config::MASK_UI_MODE_TYPE)
211 | (uiModeType&ResTable_config::MASK_UI_MODE_TYPE);
212}
213
214void AConfiguration_setUiModeNight(AConfiguration* config, int32_t uiModeNight) {
215 config->uiMode = (config->uiMode&~ResTable_config::MASK_UI_MODE_NIGHT)
216 | ((uiModeNight<<ResTable_config::SHIFT_UI_MODE_NIGHT)&ResTable_config::MASK_UI_MODE_NIGHT);
217
218}
219
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700220void AConfiguration_setScreenWidthDp(AConfiguration* config, int32_t value) {
221 config->screenWidthDp = value;
222}
223
224void AConfiguration_setScreenHeightDp(AConfiguration* config, int32_t value) {
225 config->screenHeightDp = value;
226}
227
228void AConfiguration_setSmallestScreenWidthDp(AConfiguration* config, int32_t value) {
229 config->smallestScreenWidthDp = value;
230}
231
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700232void AConfiguration_setLayoutDirection(AConfiguration* config, int32_t value) {
233 config->screenLayout = (config->screenLayout&~ResTable_config::MASK_LAYOUTDIR)
234 | ((value<<ResTable_config::SHIFT_LAYOUTDIR)&ResTable_config::MASK_LAYOUTDIR);
235}
236
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -0700237// ----------------------------------------------------------------------
238
239int32_t AConfiguration_diff(AConfiguration* config1, AConfiguration* config2) {
240 return (config1->diff(*config2));
241}
242
243int32_t AConfiguration_match(AConfiguration* base, AConfiguration* requested) {
244 return base->match(*requested);
245}
246
247int32_t AConfiguration_isBetterThan(AConfiguration* base, AConfiguration* test,
248 AConfiguration* requested) {
249 return base->isBetterThan(*test, requested);
250}