blob: 46044242aef0d41a640109e67650508a8a121a18 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.content.res;
18
Dianne Hackborn337e01a2018-02-27 17:16:37 -080019import static android.content.ConfigurationProto.COLOR_MODE;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070020import static android.content.ConfigurationProto.DENSITY_DPI;
21import static android.content.ConfigurationProto.FONT_SCALE;
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -080022import static android.content.ConfigurationProto.HARD_KEYBOARD_HIDDEN;
Dianne Hackborn337e01a2018-02-27 17:16:37 -080023import static android.content.ConfigurationProto.KEYBOARD;
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -080024import static android.content.ConfigurationProto.KEYBOARD_HIDDEN;
25import static android.content.ConfigurationProto.LOCALES;
Varun Shahb53b3442019-09-10 14:41:00 -040026import static android.content.ConfigurationProto.LOCALE_LIST;
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -080027import static android.content.ConfigurationProto.MCC;
28import static android.content.ConfigurationProto.MNC;
29import static android.content.ConfigurationProto.NAVIGATION;
30import static android.content.ConfigurationProto.NAVIGATION_HIDDEN;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070031import static android.content.ConfigurationProto.ORIENTATION;
32import static android.content.ConfigurationProto.SCREEN_HEIGHT_DP;
33import static android.content.ConfigurationProto.SCREEN_LAYOUT;
34import static android.content.ConfigurationProto.SCREEN_WIDTH_DP;
35import static android.content.ConfigurationProto.SMALLEST_SCREEN_WIDTH_DP;
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -080036import static android.content.ConfigurationProto.TOUCHSCREEN;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070037import static android.content.ConfigurationProto.UI_MODE;
38import static android.content.ConfigurationProto.WINDOW_CONFIGURATION;
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -080039import static android.content.ResourcesConfigurationProto.CONFIGURATION;
40import static android.content.ResourcesConfigurationProto.SCREEN_HEIGHT_PX;
41import static android.content.ResourcesConfigurationProto.SCREEN_WIDTH_PX;
42import static android.content.ResourcesConfigurationProto.SDK_VERSION;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070043
Alan Viveretteac85f902016-03-11 15:15:51 -050044import android.annotation.IntDef;
45import android.annotation.NonNull;
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -070046import android.annotation.Nullable;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070047import android.annotation.TestApi;
Mathew Inwood5c0d3542018-08-14 13:54:31 +010048import android.annotation.UnsupportedAppUsage;
Wale Ogunwale822e5122017-07-26 06:02:24 -070049import android.app.WindowConfiguration;
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -070050import android.content.LocaleProto;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.content.pm.ActivityInfo;
Alan Viveretteac85f902016-03-11 15:15:51 -050052import android.content.pm.ActivityInfo.Config;
Adam Lesinski2c749d22014-06-04 13:00:29 -070053import android.os.Build;
Yohei Yukawa23cbe852016-05-17 16:42:58 -070054import android.os.LocaleList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.os.Parcel;
56import android.os.Parcelable;
Fabrice Di Megliod3d9f3f2012-09-18 12:55:32 -070057import android.text.TextUtils;
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -080058import android.util.DisplayMetrics;
Varun Shah95fabaf2019-05-01 12:45:37 -070059import android.util.Slog;
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -070060import android.util.proto.ProtoInputStream;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070061import android.util.proto.ProtoOutputStream;
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -070062import android.util.proto.WireTypeMismatchException;
Fabrice Di Meglio3fb824b2012-02-28 17:58:31 -080063import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064
Romain Guye89d0bb2017-06-20 12:23:42 -070065import com.android.internal.util.XmlUtils;
66
67import org.xmlpull.v1.XmlPullParser;
68import org.xmlpull.v1.XmlPullParserException;
69import org.xmlpull.v1.XmlSerializer;
70
Adam Lesinski7f61e962014-09-02 16:43:52 -070071import java.io.IOException;
Alan Viveretteac85f902016-03-11 15:15:51 -050072import java.lang.annotation.Retention;
73import java.lang.annotation.RetentionPolicy;
Adam Lesinski2c749d22014-06-04 13:00:29 -070074import java.util.ArrayList;
Varun Shah95fabaf2019-05-01 12:45:37 -070075import java.util.IllformedLocaleException;
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -070076import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077import java.util.Locale;
78
79/**
80 * This class describes all device configuration information that can
81 * impact the resources the application retrieves. This includes both
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -070082 * user-specified configuration options (locale list and scaling) as well
Scott Main63848e32011-04-20 22:20:46 -070083 * as device configurations (such as input modes, screen size and screen orientation).
84 * <p>You can acquire this object from {@link Resources}, using {@link
85 * Resources#getConfiguration}. Thus, from an activity, you can get it by chaining the request
86 * with {@link android.app.Activity#getResources}:</p>
87 * <pre>Configuration config = getResources().getConfiguration();</pre>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 */
89public final class Configuration implements Parcelable, Comparable<Configuration> {
Dianne Hackborn756220b2012-08-14 16:45:30 -070090 /** @hide */
91 public static final Configuration EMPTY = new Configuration();
92
Varun Shah95fabaf2019-05-01 12:45:37 -070093 private static final String TAG = "Configuration";
94
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 /**
96 * Current user preference for the scaling factor for fonts, relative
97 * to the base density scaling.
98 */
99 public float fontScale;
100
101 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700102 * IMSI MCC (Mobile Country Code), corresponding to
103 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#MccQualifier">mcc</a>
104 * resource qualifier. 0 if undefined.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 */
106 public int mcc;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700109 * IMSI MNC (Mobile Network Code), corresponding to
110 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#MccQualifier">mnc</a>
Mattias Petersson1d766b52011-10-07 09:33:52 +0200111 * resource qualifier. 0 if undefined. Note that the actual MNC may be 0; in order to check
112 * for this use the {@link #MNC_ZERO} symbol.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 */
114 public int mnc;
Mattias Petersson1d766b52011-10-07 09:33:52 +0200115
116 /**
117 * Constant used to to represent MNC (Mobile Network Code) zero.
118 * 0 cannot be used, since it is used to represent an undefined MNC.
119 */
120 public static final int MNC_ZERO = 0xffff;
121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700123 * Current user preference for the locale, corresponding to
124 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#LocaleQualifier">locale</a>
125 * resource qualifier.
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700126 *
127 * @deprecated Do not set or read this directly. Use {@link #getLocales()} and
Raph Levienb1638702016-04-27 11:02:12 -0700128 * {@link #setLocales(LocaleList)}. If only the primary locale is needed,
129 * <code>getLocales().get(0)</code> is now the preferred accessor.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 */
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700131 @Deprecated public Locale locale;
132
133 private LocaleList mLocaleList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134
135 /**
Andy Stadlerf8a7cea2009-04-10 16:24:47 -0700136 * Locale should persist on setting. This is hidden because it is really
137 * questionable whether this is the right way to expose the functionality.
138 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100140 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 public boolean userSetLocale;
142
Romain Guyc9ba5592017-01-18 16:34:42 -0800143
Romain Guy48327452017-01-23 17:03:35 -0800144 /** Constant for {@link #colorMode}: bits that encode whether the screen is wide gamut. */
145 public static final int COLOR_MODE_WIDE_COLOR_GAMUT_MASK = 0x3;
Romain Guyc9ba5592017-01-18 16:34:42 -0800146 /**
Romain Guy48327452017-01-23 17:03:35 -0800147 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800148 * indicating that it is unknown whether or not the screen is wide gamut.
149 */
Romain Guy48327452017-01-23 17:03:35 -0800150 public static final int COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED = 0x0;
Romain Guyc9ba5592017-01-18 16:34:42 -0800151 /**
Romain Guy48327452017-01-23 17:03:35 -0800152 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800153 * indicating that the screen is not wide gamut.
154 * <p>Corresponds to the <code>-nowidecg</code> resource qualifier.</p>
155 */
Romain Guy48327452017-01-23 17:03:35 -0800156 public static final int COLOR_MODE_WIDE_COLOR_GAMUT_NO = 0x1;
Romain Guyc9ba5592017-01-18 16:34:42 -0800157 /**
Romain Guy48327452017-01-23 17:03:35 -0800158 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800159 * indicating that the screen is wide gamut.
160 * <p>Corresponds to the <code>-widecg</code> resource qualifier.</p>
161 */
Romain Guy48327452017-01-23 17:03:35 -0800162 public static final int COLOR_MODE_WIDE_COLOR_GAMUT_YES = 0x2;
Romain Guyc9ba5592017-01-18 16:34:42 -0800163
Romain Guyb3f69262017-04-13 20:06:41 -0700164 /** Constant for {@link #colorMode}: bits that encode the dynamic range of the screen. */
Romain Guy48327452017-01-23 17:03:35 -0800165 public static final int COLOR_MODE_HDR_MASK = 0xc;
166 /** Constant for {@link #colorMode}: bits shift to get the screen dynamic range. */
167 public static final int COLOR_MODE_HDR_SHIFT = 2;
Romain Guyc9ba5592017-01-18 16:34:42 -0800168 /**
Romain Guy48327452017-01-23 17:03:35 -0800169 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_HDR_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800170 * indicating that it is unknown whether or not the screen is HDR.
171 */
Romain Guy48327452017-01-23 17:03:35 -0800172 public static final int COLOR_MODE_HDR_UNDEFINED = 0x0;
Romain Guyc9ba5592017-01-18 16:34:42 -0800173 /**
Romain Guy48327452017-01-23 17:03:35 -0800174 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_HDR_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800175 * indicating that the screen is not HDR (low/standard dynamic range).
176 * <p>Corresponds to the <code>-lowdr</code> resource qualifier.</p>
177 */
Romain Guy48327452017-01-23 17:03:35 -0800178 public static final int COLOR_MODE_HDR_NO = 0x1 << COLOR_MODE_HDR_SHIFT;
Romain Guyc9ba5592017-01-18 16:34:42 -0800179 /**
Romain Guy48327452017-01-23 17:03:35 -0800180 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_HDR_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800181 * indicating that the screen is HDR (dynamic range).
182 * <p>Corresponds to the <code>-highdr</code> resource qualifier.</p>
183 */
Romain Guy48327452017-01-23 17:03:35 -0800184 public static final int COLOR_MODE_HDR_YES = 0x2 << COLOR_MODE_HDR_SHIFT;
Romain Guyc9ba5592017-01-18 16:34:42 -0800185
Romain Guy48327452017-01-23 17:03:35 -0800186 /** Constant for {@link #colorMode}: a value indicating that the color mode is undefined */
Romain Guyc9ba5592017-01-18 16:34:42 -0800187 @SuppressWarnings("PointlessBitwiseExpression")
Romain Guy48327452017-01-23 17:03:35 -0800188 public static final int COLOR_MODE_UNDEFINED = COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED |
189 COLOR_MODE_HDR_UNDEFINED;
Romain Guyc9ba5592017-01-18 16:34:42 -0800190
191 /**
Romain Guyb3f69262017-04-13 20:06:41 -0700192 * Bit mask of color capabilities of the screen. Currently there are two fields:
Romain Guy48327452017-01-23 17:03:35 -0800193 * <p>The {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} bits define the color gamut of
Romain Guyc9ba5592017-01-18 16:34:42 -0800194 * the screen. They may be one of
Romain Guy48327452017-01-23 17:03:35 -0800195 * {@link #COLOR_MODE_WIDE_COLOR_GAMUT_NO} or {@link #COLOR_MODE_WIDE_COLOR_GAMUT_YES}.</p>
Romain Guyc9ba5592017-01-18 16:34:42 -0800196 *
Romain Guy48327452017-01-23 17:03:35 -0800197 * <p>The {@link #COLOR_MODE_HDR_MASK} defines the dynamic range of the screen. They may be
198 * one of {@link #COLOR_MODE_HDR_NO} or {@link #COLOR_MODE_HDR_YES}.</p>
Romain Guyc9ba5592017-01-18 16:34:42 -0800199 *
200 * <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
201 * Multiple Screens</a> for more information.</p>
202 */
Romain Guy48327452017-01-23 17:03:35 -0800203 public int colorMode;
Romain Guyc9ba5592017-01-18 16:34:42 -0800204
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700205 /** Constant for {@link #screenLayout}: bits that encode the size. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700206 public static final int SCREENLAYOUT_SIZE_MASK = 0x0f;
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700207 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
208 * value indicating that no size has been set. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700209 public static final int SCREENLAYOUT_SIZE_UNDEFINED = 0x00;
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700210 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700211 * value indicating the screen is at least approximately 320x426 dp units,
212 * corresponds to the
213 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">small</a>
214 * resource qualifier.
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700215 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
216 * Multiple Screens</a> for more information. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700217 public static final int SCREENLAYOUT_SIZE_SMALL = 0x01;
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700218 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700219 * value indicating the screen is at least approximately 320x470 dp units,
220 * corresponds to the
221 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">normal</a>
222 * resource qualifier.
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700223 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
224 * Multiple Screens</a> for more information. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700225 public static final int SCREENLAYOUT_SIZE_NORMAL = 0x02;
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700226 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700227 * value indicating the screen is at least approximately 480x640 dp units,
228 * corresponds to the
229 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">large</a>
230 * resource qualifier.
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700231 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
232 * Multiple Screens</a> for more information. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700233 public static final int SCREENLAYOUT_SIZE_LARGE = 0x03;
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700234 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700235 * value indicating the screen is at least approximately 720x960 dp units,
236 * corresponds to the
237 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">xlarge</a>
238 * resource qualifier.
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700239 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
240 * Multiple Screens</a> for more information.*/
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700241 public static final int SCREENLAYOUT_SIZE_XLARGE = 0x04;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700242
243 /** Constant for {@link #screenLayout}: bits that encode the aspect ratio. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700244 public static final int SCREENLAYOUT_LONG_MASK = 0x30;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700245 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK}
246 * value indicating that no size has been set. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700247 public static final int SCREENLAYOUT_LONG_UNDEFINED = 0x00;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700248 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK}
249 * value that corresponds to the
250 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenAspectQualifier">notlong</a>
251 * resource qualifier. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700252 public static final int SCREENLAYOUT_LONG_NO = 0x10;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700253 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK}
254 * value that corresponds to the
255 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenAspectQualifier">long</a>
256 * resource qualifier. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700257 public static final int SCREENLAYOUT_LONG_YES = 0x20;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700258
259 /** Constant for {@link #screenLayout}: bits that encode the layout direction. */
260 public static final int SCREENLAYOUT_LAYOUTDIR_MASK = 0xC0;
261 /** Constant for {@link #screenLayout}: bits shift to get the layout direction. */
262 public static final int SCREENLAYOUT_LAYOUTDIR_SHIFT = 6;
263 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK}
264 * value indicating that no layout dir has been set. */
265 public static final int SCREENLAYOUT_LAYOUTDIR_UNDEFINED = 0x00;
266 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK}
267 * value indicating that a layout dir has been set to LTR. */
268 public static final int SCREENLAYOUT_LAYOUTDIR_LTR = 0x01 << SCREENLAYOUT_LAYOUTDIR_SHIFT;
269 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK}
270 * value indicating that a layout dir has been set to RTL. */
271 public static final int SCREENLAYOUT_LAYOUTDIR_RTL = 0x02 << SCREENLAYOUT_LAYOUTDIR_SHIFT;
272
Adam Powell49e7ff92015-05-14 16:18:53 -0700273 /** Constant for {@link #screenLayout}: bits that encode roundness of the screen. */
274 public static final int SCREENLAYOUT_ROUND_MASK = 0x300;
275 /** @hide Constant for {@link #screenLayout}: bit shift to get to screen roundness bits */
276 public static final int SCREENLAYOUT_ROUND_SHIFT = 8;
277 /**
278 * Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating
279 * that it is unknown whether or not the screen has a round shape.
280 */
281 public static final int SCREENLAYOUT_ROUND_UNDEFINED = 0x00;
282 /**
283 * Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating
284 * that the screen does not have a rounded shape.
285 */
286 public static final int SCREENLAYOUT_ROUND_NO = 0x1 << SCREENLAYOUT_ROUND_SHIFT;
287 /**
288 * Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating
289 * that the screen has a rounded shape. Corners may not be visible to the user;
290 * developers should pay special attention to the {@link android.view.WindowInsets} delivered
291 * to views for more information about ensuring content is not obscured.
292 *
293 * <p>Corresponds to the <code>-round</code> resource qualifier.</p>
294 */
295 public static final int SCREENLAYOUT_ROUND_YES = 0x2 << SCREENLAYOUT_ROUND_SHIFT;
296
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700297 /** Constant for {@link #screenLayout}: a value indicating that screenLayout is undefined */
298 public static final int SCREENLAYOUT_UNDEFINED = SCREENLAYOUT_SIZE_UNDEFINED |
Adam Powell49e7ff92015-05-14 16:18:53 -0700299 SCREENLAYOUT_LONG_UNDEFINED | SCREENLAYOUT_LAYOUTDIR_UNDEFINED |
300 SCREENLAYOUT_ROUND_UNDEFINED;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700301
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700302 /**
303 * Special flag we generate to indicate that the screen layout requires
304 * us to use a compatibility mode for apps that are not modern layout
305 * aware.
306 * @hide
307 */
308 public static final int SCREENLAYOUT_COMPAT_NEEDED = 0x10000000;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700309
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700310 /**
Andrii Kulianf12fce12016-05-27 17:30:16 -0700311 * Bit mask of overall layout of the screen. Currently there are four
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700312 * fields:
313 * <p>The {@link #SCREENLAYOUT_SIZE_MASK} bits define the overall size
314 * of the screen. They may be one of
315 * {@link #SCREENLAYOUT_SIZE_SMALL}, {@link #SCREENLAYOUT_SIZE_NORMAL},
Adam Powell49e7ff92015-05-14 16:18:53 -0700316 * {@link #SCREENLAYOUT_SIZE_LARGE}, or {@link #SCREENLAYOUT_SIZE_XLARGE}.</p>
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700317 *
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700318 * <p>The {@link #SCREENLAYOUT_LONG_MASK} defines whether the screen
319 * is wider/taller than normal. They may be one of
Adam Powell49e7ff92015-05-14 16:18:53 -0700320 * {@link #SCREENLAYOUT_LONG_NO} or {@link #SCREENLAYOUT_LONG_YES}.</p>
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700321 *
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700322 * <p>The {@link #SCREENLAYOUT_LAYOUTDIR_MASK} defines whether the screen layout
323 * is either LTR or RTL. They may be one of
Adam Powell49e7ff92015-05-14 16:18:53 -0700324 * {@link #SCREENLAYOUT_LAYOUTDIR_LTR} or {@link #SCREENLAYOUT_LAYOUTDIR_RTL}.</p>
325 *
326 * <p>The {@link #SCREENLAYOUT_ROUND_MASK} defines whether the screen has a rounded
327 * shape. They may be one of {@link #SCREENLAYOUT_ROUND_NO} or {@link #SCREENLAYOUT_ROUND_YES}.
328 * </p>
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700329 *
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700330 * <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
Adam Powell49e7ff92015-05-14 16:18:53 -0700331 * Multiple Screens</a> for more information.</p>
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700332 */
333 public int screenLayout;
Dianne Hackbornfe37f8f2012-09-30 12:24:33 -0700334
Bryce Lee7566d762017-03-30 09:34:15 -0700335 /**
Wale Ogunwale822e5122017-07-26 06:02:24 -0700336 * Configuration relating to the windowing state of the object associated with this
337 * Configuration. Contents of this field are not intended to affect resources, but need to be
338 * communicated and propagated at the same time as the rest of Configuration.
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700339 * @hide
Bryce Lee7566d762017-03-30 09:34:15 -0700340 */
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700341 @TestApi
Wale Ogunwale822e5122017-07-26 06:02:24 -0700342 public final WindowConfiguration windowConfiguration = new WindowConfiguration();
Bryce Lee7566d762017-03-30 09:34:15 -0700343
Dianne Hackbornfe37f8f2012-09-30 12:24:33 -0700344 /** @hide */
345 static public int resetScreenLayout(int curLayout) {
346 return (curLayout&~(SCREENLAYOUT_LONG_MASK | SCREENLAYOUT_SIZE_MASK
347 | SCREENLAYOUT_COMPAT_NEEDED))
348 | (SCREENLAYOUT_LONG_YES | SCREENLAYOUT_SIZE_XLARGE);
349 }
350
351 /** @hide */
352 static public int reduceScreenLayout(int curLayout, int longSizeDp, int shortSizeDp) {
353 int screenLayoutSize;
354 boolean screenLayoutLong;
355 boolean screenLayoutCompatNeeded;
356
357 // These semi-magic numbers define our compatibility modes for
358 // applications with different screens. These are guarantees to
359 // app developers about the space they can expect for a particular
360 // configuration. DO NOT CHANGE!
361 if (longSizeDp < 470) {
362 // This is shorter than an HVGA normal density screen (which
363 // is 480 pixels on its long side).
364 screenLayoutSize = SCREENLAYOUT_SIZE_SMALL;
365 screenLayoutLong = false;
366 screenLayoutCompatNeeded = false;
367 } else {
368 // What size is this screen screen?
369 if (longSizeDp >= 960 && shortSizeDp >= 720) {
370 // 1.5xVGA or larger screens at medium density are the point
371 // at which we consider it to be an extra large screen.
372 screenLayoutSize = SCREENLAYOUT_SIZE_XLARGE;
373 } else if (longSizeDp >= 640 && shortSizeDp >= 480) {
374 // VGA or larger screens at medium density are the point
375 // at which we consider it to be a large screen.
376 screenLayoutSize = SCREENLAYOUT_SIZE_LARGE;
377 } else {
378 screenLayoutSize = SCREENLAYOUT_SIZE_NORMAL;
379 }
380
381 // If this screen is wider than normal HVGA, or taller
382 // than FWVGA, then for old apps we want to run in size
383 // compatibility mode.
384 if (shortSizeDp > 321 || longSizeDp > 570) {
385 screenLayoutCompatNeeded = true;
386 } else {
387 screenLayoutCompatNeeded = false;
388 }
389
390 // Is this a long screen?
391 if (((longSizeDp*3)/5) >= (shortSizeDp-1)) {
392 // Anything wider than WVGA (5:3) is considering to be long.
393 screenLayoutLong = true;
394 } else {
395 screenLayoutLong = false;
396 }
397 }
398
399 // Now reduce the last screenLayout to not be better than what we
400 // have found.
401 if (!screenLayoutLong) {
402 curLayout = (curLayout&~SCREENLAYOUT_LONG_MASK) | SCREENLAYOUT_LONG_NO;
403 }
404 if (screenLayoutCompatNeeded) {
405 curLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
406 }
407 int curSize = curLayout&SCREENLAYOUT_SIZE_MASK;
408 if (screenLayoutSize < curSize) {
409 curLayout = (curLayout&~SCREENLAYOUT_SIZE_MASK) | screenLayoutSize;
410 }
411 return curLayout;
412 }
413
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700414 /** @hide */
415 public static String configurationDiffToString(int diff) {
416 ArrayList<String> list = new ArrayList<>();
417 if ((diff & ActivityInfo.CONFIG_MCC) != 0) {
418 list.add("CONFIG_MCC");
419 }
420 if ((diff & ActivityInfo.CONFIG_MNC) != 0) {
421 list.add("CONFIG_MNC");
422 }
423 if ((diff & ActivityInfo.CONFIG_LOCALE) != 0) {
424 list.add("CONFIG_LOCALE");
425 }
426 if ((diff & ActivityInfo.CONFIG_TOUCHSCREEN) != 0) {
427 list.add("CONFIG_TOUCHSCREEN");
428 }
429 if ((diff & ActivityInfo.CONFIG_KEYBOARD) != 0) {
430 list.add("CONFIG_KEYBOARD");
431 }
432 if ((diff & ActivityInfo.CONFIG_KEYBOARD_HIDDEN) != 0) {
433 list.add("CONFIG_KEYBOARD_HIDDEN");
434 }
435 if ((diff & ActivityInfo.CONFIG_NAVIGATION) != 0) {
436 list.add("CONFIG_NAVIGATION");
437 }
438 if ((diff & ActivityInfo.CONFIG_ORIENTATION) != 0) {
439 list.add("CONFIG_ORIENTATION");
440 }
441 if ((diff & ActivityInfo.CONFIG_SCREEN_LAYOUT) != 0) {
442 list.add("CONFIG_SCREEN_LAYOUT");
443 }
Romain Guy48327452017-01-23 17:03:35 -0800444 if ((diff & ActivityInfo.CONFIG_COLOR_MODE) != 0) {
445 list.add("CONFIG_COLOR_MODE");
Romain Guyc9ba5592017-01-18 16:34:42 -0800446 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700447 if ((diff & ActivityInfo.CONFIG_UI_MODE) != 0) {
448 list.add("CONFIG_UI_MODE");
449 }
450 if ((diff & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) {
451 list.add("CONFIG_SCREEN_SIZE");
452 }
453 if ((diff & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
454 list.add("CONFIG_SMALLEST_SCREEN_SIZE");
455 }
456 if ((diff & ActivityInfo.CONFIG_LAYOUT_DIRECTION) != 0) {
457 list.add("CONFIG_LAYOUT_DIRECTION");
458 }
459 if ((diff & ActivityInfo.CONFIG_FONT_SCALE) != 0) {
460 list.add("CONFIG_FONT_SCALE");
461 }
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +0100462 if ((diff & ActivityInfo.CONFIG_ASSETS_PATHS) != 0) {
463 list.add("CONFIG_ASSETS_PATHS");
464 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700465 StringBuilder builder = new StringBuilder("{");
466 for (int i = 0, n = list.size(); i < n; i++) {
467 builder.append(list.get(i));
468 if (i != n - 1) {
469 builder.append(", ");
470 }
471 }
472 builder.append("}");
473 return builder.toString();
474 }
475
Dianne Hackborn711e62a2010-11-29 16:38:22 -0800476 /**
477 * Check if the Configuration's current {@link #screenLayout} is at
478 * least the given size.
479 *
480 * @param size The desired size, either {@link #SCREENLAYOUT_SIZE_SMALL},
481 * {@link #SCREENLAYOUT_SIZE_NORMAL}, {@link #SCREENLAYOUT_SIZE_LARGE}, or
482 * {@link #SCREENLAYOUT_SIZE_XLARGE}.
483 * @return Returns true if the current screen layout size is at least
484 * the given size.
485 */
486 public boolean isLayoutSizeAtLeast(int size) {
487 int cur = screenLayout&SCREENLAYOUT_SIZE_MASK;
488 if (cur == SCREENLAYOUT_SIZE_UNDEFINED) return false;
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -0800489 return cur >= size;
Dianne Hackborn711e62a2010-11-29 16:38:22 -0800490 }
491
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700492 /** Constant for {@link #touchscreen}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 public static final int TOUCHSCREEN_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700494 /** Constant for {@link #touchscreen}, value corresponding to the
495 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#TouchscreenQualifier">notouch</a>
496 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 public static final int TOUCHSCREEN_NOTOUCH = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700498 /** @deprecated Not currently supported or used. */
499 @Deprecated public static final int TOUCHSCREEN_STYLUS = 2;
500 /** Constant for {@link #touchscreen}, value corresponding to the
501 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#TouchscreenQualifier">finger</a>
502 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 public static final int TOUCHSCREEN_FINGER = 3;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 /**
506 * The kind of touch screen attached to the device.
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700507 * One of: {@link #TOUCHSCREEN_NOTOUCH}, {@link #TOUCHSCREEN_FINGER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 */
509 public int touchscreen;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700510
511 /** Constant for {@link #keyboard}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 public static final int KEYBOARD_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700513 /** Constant for {@link #keyboard}, value corresponding to the
514 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">nokeys</a>
515 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 public static final int KEYBOARD_NOKEYS = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700517 /** Constant for {@link #keyboard}, value corresponding to the
518 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">qwerty</a>
519 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 public static final int KEYBOARD_QWERTY = 2;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700521 /** Constant for {@link #keyboard}, value corresponding to the
522 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">12key</a>
523 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 public static final int KEYBOARD_12KEY = 3;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 /**
527 * The kind of keyboard attached to the device.
Kenny Root507f8ed2009-06-09 11:21:11 -0500528 * One of: {@link #KEYBOARD_NOKEYS}, {@link #KEYBOARD_QWERTY},
529 * {@link #KEYBOARD_12KEY}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 */
531 public int keyboard;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700532
533 /** Constant for {@link #keyboardHidden}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 public static final int KEYBOARDHIDDEN_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700535 /** Constant for {@link #keyboardHidden}, value corresponding to the
536 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keysexposed</a>
537 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 public static final int KEYBOARDHIDDEN_NO = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700539 /** Constant for {@link #keyboardHidden}, value corresponding to the
540 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keyshidden</a>
541 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 public static final int KEYBOARDHIDDEN_YES = 2;
543 /** Constant matching actual resource implementation. {@hide} */
544 public static final int KEYBOARDHIDDEN_SOFT = 3;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 /**
547 * A flag indicating whether any keyboard is available. Unlike
548 * {@link #hardKeyboardHidden}, this also takes into account a soft
549 * keyboard, so if the hard keyboard is hidden but there is soft
550 * keyboard available, it will be set to NO. Value is one of:
551 * {@link #KEYBOARDHIDDEN_NO}, {@link #KEYBOARDHIDDEN_YES}.
552 */
553 public int keyboardHidden;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700554
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700555 /** Constant for {@link #hardKeyboardHidden}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700557 /** Constant for {@link #hardKeyboardHidden}, value corresponding to the
558 * physical keyboard being exposed. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 public static final int HARDKEYBOARDHIDDEN_NO = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700560 /** Constant for {@link #hardKeyboardHidden}, value corresponding to the
561 * physical keyboard being hidden. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 public static final int HARDKEYBOARDHIDDEN_YES = 2;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 /**
565 * A flag indicating whether the hard keyboard has been hidden. This will
566 * be set on a device with a mechanism to hide the keyboard from the
567 * user, when that mechanism is closed. One of:
568 * {@link #HARDKEYBOARDHIDDEN_NO}, {@link #HARDKEYBOARDHIDDEN_YES}.
569 */
570 public int hardKeyboardHidden;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700571
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700572 /** Constant for {@link #navigation}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 public static final int NAVIGATION_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700574 /** Constant for {@link #navigation}, value corresponding to the
575 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">nonav</a>
576 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 public static final int NAVIGATION_NONAV = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700578 /** Constant for {@link #navigation}, value corresponding to the
579 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">dpad</a>
580 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 public static final int NAVIGATION_DPAD = 2;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700582 /** Constant for {@link #navigation}, value corresponding to the
583 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">trackball</a>
584 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 public static final int NAVIGATION_TRACKBALL = 3;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700586 /** Constant for {@link #navigation}, value corresponding to the
587 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">wheel</a>
588 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 public static final int NAVIGATION_WHEEL = 4;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 /**
592 * The kind of navigation method available on the device.
Kenny Root507f8ed2009-06-09 11:21:11 -0500593 * One of: {@link #NAVIGATION_NONAV}, {@link #NAVIGATION_DPAD},
594 * {@link #NAVIGATION_TRACKBALL}, {@link #NAVIGATION_WHEEL}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 */
596 public int navigation;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700597
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700598 /** Constant for {@link #navigationHidden}: a value indicating that no value has been set. */
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700599 public static final int NAVIGATIONHIDDEN_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700600 /** Constant for {@link #navigationHidden}, value corresponding to the
601 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavAvailQualifier">navexposed</a>
602 * resource qualifier. */
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700603 public static final int NAVIGATIONHIDDEN_NO = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700604 /** Constant for {@link #navigationHidden}, value corresponding to the
605 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavAvailQualifier">navhidden</a>
606 * resource qualifier. */
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700607 public static final int NAVIGATIONHIDDEN_YES = 2;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700608
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700609 /**
610 * A flag indicating whether any 5-way or DPAD navigation available.
611 * This will be set on a device with a mechanism to hide the navigation
612 * controls from the user, when that mechanism is closed. One of:
613 * {@link #NAVIGATIONHIDDEN_NO}, {@link #NAVIGATIONHIDDEN_YES}.
614 */
615 public int navigationHidden;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700616
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700617 /** Constant for {@link #orientation}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 public static final int ORIENTATION_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700619 /** Constant for {@link #orientation}, value corresponding to the
620 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#OrientationQualifier">port</a>
621 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 public static final int ORIENTATION_PORTRAIT = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700623 /** Constant for {@link #orientation}, value corresponding to the
624 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#OrientationQualifier">land</a>
625 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 public static final int ORIENTATION_LANDSCAPE = 2;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700627 /** @deprecated Not currently supported or used. */
628 @Deprecated public static final int ORIENTATION_SQUARE = 3;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700629
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 /**
631 * Overall orientation of the screen. May be one of
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700632 * {@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 */
634 public int orientation;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100635
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700636 /** Constant for {@link #uiMode}: bits that encode the mode type. */
Tobias Haamel27b28b32010-02-09 23:09:17 +0100637 public static final int UI_MODE_TYPE_MASK = 0x0f;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700638 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
639 * value indicating that no mode type has been set. */
Dianne Hackbornef05e072010-03-01 17:43:39 -0800640 public static final int UI_MODE_TYPE_UNDEFINED = 0x00;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700641 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
642 * value that corresponds to
643 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">no
644 * UI mode</a> resource qualifier specified. */
Dianne Hackbornef05e072010-03-01 17:43:39 -0800645 public static final int UI_MODE_TYPE_NORMAL = 0x01;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700646 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
647 * value that corresponds to the
648 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">desk</a>
649 * resource qualifier. */
Dianne Hackborn7299c412010-03-04 18:41:49 -0800650 public static final int UI_MODE_TYPE_DESK = 0x02;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700651 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
652 * value that corresponds to the
653 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">car</a>
654 * resource qualifier. */
Dianne Hackborn7299c412010-03-04 18:41:49 -0800655 public static final int UI_MODE_TYPE_CAR = 0x03;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700656 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
657 * value that corresponds to the
658 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">television</a>
659 * resource qualifier. */
Dianne Hackborne360bb62011-05-20 16:11:04 -0700660 public static final int UI_MODE_TYPE_TELEVISION = 0x04;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700661 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
662 * value that corresponds to the
663 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">appliance</a>
664 * resource qualifier. */
Joe Onorato44fcb832011-12-14 20:59:30 -0800665 public static final int UI_MODE_TYPE_APPLIANCE = 0x05;
John Spurlock6c191292014-04-03 16:37:27 -0400666 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
667 * value that corresponds to the
668 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">watch</a>
669 * resource qualifier. */
670 public static final int UI_MODE_TYPE_WATCH = 0x06;
Zak Cohen1a6acdb2016-12-12 15:21:21 -0800671 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
672 * value that corresponds to the
673 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">vrheadset</a>
674 * resource qualifier. */
675 public static final int UI_MODE_TYPE_VR_HEADSET = 0x07;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100676
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700677 /** Constant for {@link #uiMode}: bits that encode the night mode. */
Tobias Haamel27b28b32010-02-09 23:09:17 +0100678 public static final int UI_MODE_NIGHT_MASK = 0x30;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700679 /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK}
680 * value indicating that no mode type has been set. */
Tobias Haamel27b28b32010-02-09 23:09:17 +0100681 public static final int UI_MODE_NIGHT_UNDEFINED = 0x00;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700682 /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK}
683 * value that corresponds to the
684 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NightQualifier">notnight</a>
685 * resource qualifier. */
Tobias Haamel27b28b32010-02-09 23:09:17 +0100686 public static final int UI_MODE_NIGHT_NO = 0x10;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700687 /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK}
688 * value that corresponds to the
689 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NightQualifier">night</a>
690 * resource qualifier. */
Tobias Haamel27b28b32010-02-09 23:09:17 +0100691 public static final int UI_MODE_NIGHT_YES = 0x20;
692
693 /**
694 * Bit mask of the ui mode. Currently there are two fields:
695 * <p>The {@link #UI_MODE_TYPE_MASK} bits define the overall ui mode of the
Dianne Hackborn7299c412010-03-04 18:41:49 -0800696 * device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED},
697 * {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK},
John Spurlock6c191292014-04-03 16:37:27 -0400698 * {@link #UI_MODE_TYPE_CAR}, {@link #UI_MODE_TYPE_TELEVISION},
Zak Cohen1a6acdb2016-12-12 15:21:21 -0800699 * {@link #UI_MODE_TYPE_APPLIANCE}, {@link #UI_MODE_TYPE_WATCH},
700 * or {@link #UI_MODE_TYPE_VR_HEADSET}.
Tobias Haamel27b28b32010-02-09 23:09:17 +0100701 *
702 * <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen
Dianne Hackborn7299c412010-03-04 18:41:49 -0800703 * is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED},
Tobias Haamel27b28b32010-02-09 23:09:17 +0100704 * {@link #UI_MODE_NIGHT_NO} or {@link #UI_MODE_NIGHT_YES}.
Tobias Haamel27b28b32010-02-09 23:09:17 +0100705 */
706 public int uiMode;
707
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700708 /**
709 * Default value for {@link #screenWidthDp} indicating that no width
710 * has been specified.
711 */
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700712 public static final int SCREEN_WIDTH_DP_UNDEFINED = 0;
713
714 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700715 * The current width of the available screen space, in dp units,
716 * corresponding to
717 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenWidthQualifier">screen
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700718 * width</a> resource qualifier. Set to
719 * {@link #SCREEN_WIDTH_DP_UNDEFINED} if no width is specified.
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700720 */
721 public int screenWidthDp;
722
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700723 /**
724 * Default value for {@link #screenHeightDp} indicating that no width
725 * has been specified.
726 */
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700727 public static final int SCREEN_HEIGHT_DP_UNDEFINED = 0;
728
729 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700730 * The current height of the available screen space, in dp units,
731 * corresponding to
732 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenHeightQualifier">screen
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700733 * height</a> resource qualifier. Set to
734 * {@link #SCREEN_HEIGHT_DP_UNDEFINED} if no height is specified.
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700735 */
736 public int screenHeightDp;
737
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700738 /**
739 * Default value for {@link #smallestScreenWidthDp} indicating that no width
740 * has been specified.
741 */
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700742 public static final int SMALLEST_SCREEN_WIDTH_DP_UNDEFINED = 0;
743
744 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700745 * The smallest screen size an application will see in normal operation,
746 * corresponding to
747 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#SmallestScreenWidthQualifier">smallest
748 * screen width</a> resource qualifier.
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700749 * This is the smallest value of both screenWidthDp and screenHeightDp
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700750 * in both portrait and landscape. Set to
751 * {@link #SMALLEST_SCREEN_WIDTH_DP_UNDEFINED} if no width is specified.
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700752 */
753 public int smallestScreenWidthDp;
754
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700755 /**
756 * Default value for {@link #densityDpi} indicating that no width
757 * has been specified.
758 */
759 public static final int DENSITY_DPI_UNDEFINED = 0;
760
761 /**
Adam Lesinski31245b42014-08-22 19:10:56 -0700762 * Value for {@link #densityDpi} for resources that scale to any density (vector drawables).
763 * {@hide}
764 */
765 public static final int DENSITY_DPI_ANY = 0xfffe;
766
767 /**
768 * Value for {@link #densityDpi} for resources that are not meant to be scaled.
769 * {@hide}
770 */
771 public static final int DENSITY_DPI_NONE = 0xffff;
772
773 /**
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700774 * The target screen density being rendered to,
775 * corresponding to
776 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#DensityQualifier">density</a>
777 * resource qualifier. Set to
778 * {@link #DENSITY_DPI_UNDEFINED} if no density is specified.
779 */
780 public int densityDpi;
781
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700782 /** @hide Hack to get this information from WM to app running in compat mode. */
783 public int compatScreenWidthDp;
784 /** @hide Hack to get this information from WM to app running in compat mode. */
785 public int compatScreenHeightDp;
786 /** @hide Hack to get this information from WM to app running in compat mode. */
787 public int compatSmallestScreenWidthDp;
788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 /**
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +0100790 * An undefined assetsSeq. This will not override an existing assetsSeq.
791 * @hide
792 */
793 public static final int ASSETS_SEQ_UNDEFINED = 0;
794
795 /**
796 * Internal counter that allows us to piggyback off the configuration change mechanism to
797 * signal to apps that the the assets for an Application have changed. A difference in these
798 * between two Configurations will yield a diff flag of
799 * {@link ActivityInfo#CONFIG_ASSETS_PATHS}.
800 * @hide
801 */
Artur Satayev5a525852019-10-31 15:15:50 +0000802 @UnsupportedAppUsage
Riddle Hsue716d722019-01-09 15:56:46 +0800803 @TestApi
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +0100804 public int assetsSeq;
805
806 /**
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800807 * @hide Internal book-keeping.
808 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100809 @UnsupportedAppUsage
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800810 public int seq;
Dianne Hackborn1d0b1772013-09-06 14:02:54 -0700811
Alan Viveretteac85f902016-03-11 15:15:51 -0500812 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700813 @IntDef(flag = true, prefix = { "NATIVE_CONFIG_" }, value = {
814 NATIVE_CONFIG_MCC,
815 NATIVE_CONFIG_MNC,
816 NATIVE_CONFIG_LOCALE,
817 NATIVE_CONFIG_TOUCHSCREEN,
818 NATIVE_CONFIG_KEYBOARD,
819 NATIVE_CONFIG_KEYBOARD_HIDDEN,
820 NATIVE_CONFIG_NAVIGATION,
821 NATIVE_CONFIG_ORIENTATION,
822 NATIVE_CONFIG_DENSITY,
823 NATIVE_CONFIG_SCREEN_SIZE,
824 NATIVE_CONFIG_VERSION,
825 NATIVE_CONFIG_SCREEN_LAYOUT,
826 NATIVE_CONFIG_UI_MODE,
827 NATIVE_CONFIG_SMALLEST_SCREEN_SIZE,
828 NATIVE_CONFIG_LAYOUTDIR,
829 NATIVE_CONFIG_COLOR_MODE,
830 })
Alan Viveretteac85f902016-03-11 15:15:51 -0500831 @Retention(RetentionPolicy.SOURCE)
832 public @interface NativeConfig {}
833
Dianne Hackborn1d0b1772013-09-06 14:02:54 -0700834 /** @hide Native-specific bit mask for MCC config; DO NOT USE UNLESS YOU ARE SURE. */
835 public static final int NATIVE_CONFIG_MCC = 0x0001;
836 /** @hide Native-specific bit mask for MNC config; DO NOT USE UNLESS YOU ARE SURE. */
837 public static final int NATIVE_CONFIG_MNC = 0x0002;
838 /** @hide Native-specific bit mask for LOCALE config; DO NOT USE UNLESS YOU ARE SURE. */
839 public static final int NATIVE_CONFIG_LOCALE = 0x0004;
840 /** @hide Native-specific bit mask for TOUCHSCREEN config; DO NOT USE UNLESS YOU ARE SURE. */
841 public static final int NATIVE_CONFIG_TOUCHSCREEN = 0x0008;
842 /** @hide Native-specific bit mask for KEYBOARD config; DO NOT USE UNLESS YOU ARE SURE. */
843 public static final int NATIVE_CONFIG_KEYBOARD = 0x0010;
844 /** @hide Native-specific bit mask for KEYBOARD_HIDDEN config; DO NOT USE UNLESS YOU
845 * ARE SURE. */
846 public static final int NATIVE_CONFIG_KEYBOARD_HIDDEN = 0x0020;
847 /** @hide Native-specific bit mask for NAVIGATION config; DO NOT USE UNLESS YOU ARE SURE. */
848 public static final int NATIVE_CONFIG_NAVIGATION = 0x0040;
849 /** @hide Native-specific bit mask for ORIENTATION config; DO NOT USE UNLESS YOU ARE SURE. */
850 public static final int NATIVE_CONFIG_ORIENTATION = 0x0080;
851 /** @hide Native-specific bit mask for DENSITY config; DO NOT USE UNLESS YOU ARE SURE. */
852 public static final int NATIVE_CONFIG_DENSITY = 0x0100;
853 /** @hide Native-specific bit mask for SCREEN_SIZE config; DO NOT USE UNLESS YOU ARE SURE. */
854 public static final int NATIVE_CONFIG_SCREEN_SIZE = 0x0200;
855 /** @hide Native-specific bit mask for VERSION config; DO NOT USE UNLESS YOU ARE SURE. */
856 public static final int NATIVE_CONFIG_VERSION = 0x0400;
857 /** @hide Native-specific bit mask for SCREEN_LAYOUT config; DO NOT USE UNLESS YOU ARE SURE. */
858 public static final int NATIVE_CONFIG_SCREEN_LAYOUT = 0x0800;
859 /** @hide Native-specific bit mask for UI_MODE config; DO NOT USE UNLESS YOU ARE SURE. */
860 public static final int NATIVE_CONFIG_UI_MODE = 0x1000;
861 /** @hide Native-specific bit mask for SMALLEST_SCREEN_SIZE config; DO NOT USE UNLESS YOU
862 * ARE SURE. */
863 public static final int NATIVE_CONFIG_SMALLEST_SCREEN_SIZE = 0x2000;
864 /** @hide Native-specific bit mask for LAYOUTDIR config ; DO NOT USE UNLESS YOU ARE SURE.*/
865 public static final int NATIVE_CONFIG_LAYOUTDIR = 0x4000;
Romain Guy48327452017-01-23 17:03:35 -0800866 /** @hide Native-specific bit mask for COLOR_MODE config ; DO NOT USE UNLESS YOU ARE SURE.*/
867 public static final int NATIVE_CONFIG_COLOR_MODE = 0x10000;
Dianne Hackborn1d0b1772013-09-06 14:02:54 -0700868
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800869 /**
Adam Lesinskibad43fc2016-07-19 13:35:01 -0700870 * <p>Construct an invalid Configuration. This state is only suitable for constructing a
871 * Configuration delta that will be applied to some valid Configuration object. In order to
872 * create a valid standalone Configuration, you must call {@link #setToDefaults}. </p>
873 *
874 * <p>Example:</p>
875 * <pre class="prettyprint">
876 * Configuration validConfig = new Configuration();
877 * validConfig.setToDefaults();
878 *
879 * Configuration deltaOnlyConfig = new Configuration();
880 * deltaOnlyConfig.orientation = Configuration.ORIENTATION_LANDSCAPE;
881 *
882 * validConfig.updateFrom(deltaOnlyConfig);
883 * </pre>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 */
885 public Configuration() {
Adam Lesinskibad43fc2016-07-19 13:35:01 -0700886 unset();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 }
888
889 /**
890 * Makes a deep copy suitable for modification.
891 */
892 public Configuration(Configuration o) {
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700893 setTo(o);
894 }
895
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700896 /* This brings mLocaleList in sync with locale in case a user of the older API who doesn't know
897 * about setLocales() has changed locale directly. */
898 private void fixUpLocaleList() {
899 if ((locale == null && !mLocaleList.isEmpty()) ||
Roozbeh Pournaderfee44842016-02-04 15:24:24 -0800900 (locale != null && !locale.equals(mLocaleList.get(0)))) {
Raph Levien10ea92a2016-05-02 12:56:01 -0700901 mLocaleList = locale == null ? LocaleList.getEmptyLocaleList() : new LocaleList(locale);
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700902 }
903 }
904
Chet Haased30149e2017-01-13 12:55:16 -0800905 /**
906 * Sets the fields in this object to those in the given Configuration.
907 *
908 * @param o The Configuration object used to set the values of this Configuration's fields.
909 */
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700910 public void setTo(Configuration o) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 fontScale = o.fontScale;
912 mcc = o.mcc;
913 mnc = o.mnc;
Roozbeh Pournader8a412e02015-12-02 18:39:50 -0800914 locale = o.locale == null ? null : (Locale) o.locale.clone();
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700915 o.fixUpLocaleList();
916 mLocaleList = o.mLocaleList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 userSetLocale = o.userSetLocale;
918 touchscreen = o.touchscreen;
919 keyboard = o.keyboard;
920 keyboardHidden = o.keyboardHidden;
921 hardKeyboardHidden = o.hardKeyboardHidden;
922 navigation = o.navigation;
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700923 navigationHidden = o.navigationHidden;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 orientation = o.orientation;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700925 screenLayout = o.screenLayout;
Romain Guy48327452017-01-23 17:03:35 -0800926 colorMode = o.colorMode;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100927 uiMode = o.uiMode;
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700928 screenWidthDp = o.screenWidthDp;
929 screenHeightDp = o.screenHeightDp;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700930 smallestScreenWidthDp = o.smallestScreenWidthDp;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700931 densityDpi = o.densityDpi;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700932 compatScreenWidthDp = o.compatScreenWidthDp;
933 compatScreenHeightDp = o.compatScreenHeightDp;
934 compatSmallestScreenWidthDp = o.compatSmallestScreenWidthDp;
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +0100935 assetsSeq = o.assetsSeq;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800936 seq = o.seq;
Wale Ogunwale822e5122017-07-26 06:02:24 -0700937 windowConfiguration.setTo(o.windowConfiguration);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700939
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700941 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn29735682011-04-21 17:26:39 -0700942 sb.append("{");
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700943 sb.append(fontScale);
Dianne Hackborn5be8de32011-05-24 18:11:57 -0700944 sb.append(" ");
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700945 if (mcc != 0) {
946 sb.append(mcc);
947 sb.append("mcc");
948 } else {
949 sb.append("?mcc");
950 }
951 if (mnc != 0) {
952 sb.append(mnc);
953 sb.append("mnc");
954 } else {
955 sb.append("?mnc");
956 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700957 fixUpLocaleList();
958 if (!mLocaleList.isEmpty()) {
Dianne Hackborn9a849832011-04-07 15:11:57 -0700959 sb.append(" ");
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700960 sb.append(mLocaleList);
Dianne Hackborn9a849832011-04-07 15:11:57 -0700961 } else {
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700962 sb.append(" ?localeList");
Daniel Sandler7d6bddc2010-07-22 16:11:55 -0400963 }
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700964 int layoutDir = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK);
965 switch (layoutDir) {
966 case SCREENLAYOUT_LAYOUTDIR_UNDEFINED: sb.append(" ?layoutDir"); break;
Fabrice Di Meglio8a802db2012-09-05 13:12:02 -0700967 case SCREENLAYOUT_LAYOUTDIR_LTR: sb.append(" ldltr"); break;
968 case SCREENLAYOUT_LAYOUTDIR_RTL: sb.append(" ldrtl"); break;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700969 default: sb.append(" layoutDir=");
970 sb.append(layoutDir >> SCREENLAYOUT_LAYOUTDIR_SHIFT); break;
Fabrice Di Meglio7a736fb2011-06-09 20:20:36 -0700971 }
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700972 if (smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
973 sb.append(" sw"); sb.append(smallestScreenWidthDp); sb.append("dp");
974 } else {
Dianne Hackborn2f0b1752011-05-31 17:59:49 -0700975 sb.append(" ?swdp");
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700976 }
977 if (screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
978 sb.append(" w"); sb.append(screenWidthDp); sb.append("dp");
979 } else {
Dianne Hackborn2f0b1752011-05-31 17:59:49 -0700980 sb.append(" ?wdp");
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700981 }
982 if (screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
983 sb.append(" h"); sb.append(screenHeightDp); sb.append("dp");
984 } else {
Dianne Hackborn2f0b1752011-05-31 17:59:49 -0700985 sb.append(" ?hdp");
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700986 }
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700987 if (densityDpi != DENSITY_DPI_UNDEFINED) {
988 sb.append(" "); sb.append(densityDpi); sb.append("dpi");
989 } else {
990 sb.append(" ?density");
991 }
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700992 switch ((screenLayout&SCREENLAYOUT_SIZE_MASK)) {
993 case SCREENLAYOUT_SIZE_UNDEFINED: sb.append(" ?lsize"); break;
994 case SCREENLAYOUT_SIZE_SMALL: sb.append(" smll"); break;
995 case SCREENLAYOUT_SIZE_NORMAL: sb.append(" nrml"); break;
996 case SCREENLAYOUT_SIZE_LARGE: sb.append(" lrg"); break;
997 case SCREENLAYOUT_SIZE_XLARGE: sb.append(" xlrg"); break;
998 default: sb.append(" layoutSize=");
999 sb.append(screenLayout&SCREENLAYOUT_SIZE_MASK); break;
1000 }
1001 switch ((screenLayout&SCREENLAYOUT_LONG_MASK)) {
1002 case SCREENLAYOUT_LONG_UNDEFINED: sb.append(" ?long"); break;
1003 case SCREENLAYOUT_LONG_NO: /* not-long is not interesting to print */ break;
1004 case SCREENLAYOUT_LONG_YES: sb.append(" long"); break;
1005 default: sb.append(" layoutLong=");
1006 sb.append(screenLayout&SCREENLAYOUT_LONG_MASK); break;
1007 }
Romain Guy48327452017-01-23 17:03:35 -08001008 switch ((colorMode &COLOR_MODE_HDR_MASK)) {
1009 case COLOR_MODE_HDR_UNDEFINED: sb.append(" ?ldr"); break; // most likely not HDR
1010 case COLOR_MODE_HDR_NO: /* ldr is not interesting to print */ break;
1011 case COLOR_MODE_HDR_YES: sb.append(" hdr"); break;
Romain Guyc9ba5592017-01-18 16:34:42 -08001012 default: sb.append(" dynamicRange=");
Romain Guy48327452017-01-23 17:03:35 -08001013 sb.append(colorMode &COLOR_MODE_HDR_MASK); break;
Romain Guyc9ba5592017-01-18 16:34:42 -08001014 }
Romain Guy48327452017-01-23 17:03:35 -08001015 switch ((colorMode &COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) {
1016 case COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED: sb.append(" ?wideColorGamut"); break;
1017 case COLOR_MODE_WIDE_COLOR_GAMUT_NO: /* not wide is not interesting to print */ break;
1018 case COLOR_MODE_WIDE_COLOR_GAMUT_YES: sb.append(" widecg"); break;
Romain Guyc9ba5592017-01-18 16:34:42 -08001019 default: sb.append(" wideColorGamut=");
Romain Guy48327452017-01-23 17:03:35 -08001020 sb.append(colorMode &COLOR_MODE_WIDE_COLOR_GAMUT_MASK); break;
Romain Guyc9ba5592017-01-18 16:34:42 -08001021 }
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001022 switch (orientation) {
1023 case ORIENTATION_UNDEFINED: sb.append(" ?orien"); break;
1024 case ORIENTATION_LANDSCAPE: sb.append(" land"); break;
1025 case ORIENTATION_PORTRAIT: sb.append(" port"); break;
1026 default: sb.append(" orien="); sb.append(orientation); break;
1027 }
1028 switch ((uiMode&UI_MODE_TYPE_MASK)) {
1029 case UI_MODE_TYPE_UNDEFINED: sb.append(" ?uimode"); break;
1030 case UI_MODE_TYPE_NORMAL: /* normal is not interesting to print */ break;
1031 case UI_MODE_TYPE_DESK: sb.append(" desk"); break;
1032 case UI_MODE_TYPE_CAR: sb.append(" car"); break;
Dianne Hackborne360bb62011-05-20 16:11:04 -07001033 case UI_MODE_TYPE_TELEVISION: sb.append(" television"); break;
Joe Onorato44fcb832011-12-14 20:59:30 -08001034 case UI_MODE_TYPE_APPLIANCE: sb.append(" appliance"); break;
John Spurlock6c191292014-04-03 16:37:27 -04001035 case UI_MODE_TYPE_WATCH: sb.append(" watch"); break;
Zak Cohen1a6acdb2016-12-12 15:21:21 -08001036 case UI_MODE_TYPE_VR_HEADSET: sb.append(" vrheadset"); break;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001037 default: sb.append(" uimode="); sb.append(uiMode&UI_MODE_TYPE_MASK); break;
1038 }
1039 switch ((uiMode&UI_MODE_NIGHT_MASK)) {
1040 case UI_MODE_NIGHT_UNDEFINED: sb.append(" ?night"); break;
1041 case UI_MODE_NIGHT_NO: /* not-night is not interesting to print */ break;
1042 case UI_MODE_NIGHT_YES: sb.append(" night"); break;
1043 default: sb.append(" night="); sb.append(uiMode&UI_MODE_NIGHT_MASK); break;
1044 }
Dianne Hackborn9a849832011-04-07 15:11:57 -07001045 switch (touchscreen) {
1046 case TOUCHSCREEN_UNDEFINED: sb.append(" ?touch"); break;
1047 case TOUCHSCREEN_NOTOUCH: sb.append(" -touch"); break;
1048 case TOUCHSCREEN_STYLUS: sb.append(" stylus"); break;
1049 case TOUCHSCREEN_FINGER: sb.append(" finger"); break;
1050 default: sb.append(" touch="); sb.append(touchscreen); break;
1051 }
1052 switch (keyboard) {
1053 case KEYBOARD_UNDEFINED: sb.append(" ?keyb"); break;
1054 case KEYBOARD_NOKEYS: sb.append(" -keyb"); break;
1055 case KEYBOARD_QWERTY: sb.append(" qwerty"); break;
1056 case KEYBOARD_12KEY: sb.append(" 12key"); break;
1057 default: sb.append(" keys="); sb.append(keyboard); break;
1058 }
1059 switch (keyboardHidden) {
1060 case KEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break;
1061 case KEYBOARDHIDDEN_NO: sb.append("/v"); break;
1062 case KEYBOARDHIDDEN_YES: sb.append("/h"); break;
1063 case KEYBOARDHIDDEN_SOFT: sb.append("/s"); break;
1064 default: sb.append("/"); sb.append(keyboardHidden); break;
1065 }
1066 switch (hardKeyboardHidden) {
1067 case HARDKEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break;
1068 case HARDKEYBOARDHIDDEN_NO: sb.append("/v"); break;
1069 case HARDKEYBOARDHIDDEN_YES: sb.append("/h"); break;
1070 default: sb.append("/"); sb.append(hardKeyboardHidden); break;
1071 }
1072 switch (navigation) {
1073 case NAVIGATION_UNDEFINED: sb.append(" ?nav"); break;
1074 case NAVIGATION_NONAV: sb.append(" -nav"); break;
1075 case NAVIGATION_DPAD: sb.append(" dpad"); break;
1076 case NAVIGATION_TRACKBALL: sb.append(" tball"); break;
1077 case NAVIGATION_WHEEL: sb.append(" wheel"); break;
1078 default: sb.append(" nav="); sb.append(navigation); break;
1079 }
1080 switch (navigationHidden) {
1081 case NAVIGATIONHIDDEN_UNDEFINED: sb.append("/?"); break;
1082 case NAVIGATIONHIDDEN_NO: sb.append("/v"); break;
1083 case NAVIGATIONHIDDEN_YES: sb.append("/h"); break;
1084 default: sb.append("/"); sb.append(navigationHidden); break;
1085 }
Wale Ogunwale822e5122017-07-26 06:02:24 -07001086 sb.append(" winConfig="); sb.append(windowConfiguration);
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001087 if (assetsSeq != 0) {
1088 sb.append(" as.").append(assetsSeq);
1089 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001090 if (seq != 0) {
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001091 sb.append(" s.").append(seq);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001092 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001093 sb.append('}');
1094 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 }
1096
1097 /**
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001098 * Write to a protocol buffer output stream.
1099 * Protocol buffer message definition at {@link android.content.ConfigurationProto}
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001100 * Has the option to ignore fields that don't need to be persisted to disk.
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001101 *
1102 * @param protoOutputStream Stream to write the Configuration object to.
1103 * @param fieldId Field Id of the Configuration as defined in the parent message
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001104 * @param persisted Note if this proto will be persisted to disk
Nataniel Borges023ecb52019-01-16 14:15:43 -08001105 * @param critical If true, reduce amount of data written.
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001106 * @hide
1107 */
Nataniel Borges023ecb52019-01-16 14:15:43 -08001108 public void writeToProto(ProtoOutputStream protoOutputStream, long fieldId, boolean persisted,
1109 boolean critical) {
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001110 final long token = protoOutputStream.start(fieldId);
Nataniel Borges023ecb52019-01-16 14:15:43 -08001111 if (!critical) {
1112 protoOutputStream.write(FONT_SCALE, fontScale);
1113 protoOutputStream.write(MCC, mcc);
1114 protoOutputStream.write(MNC, mnc);
1115 if (mLocaleList != null) {
Varun Shahb53b3442019-09-10 14:41:00 -04001116 protoOutputStream.write(LOCALE_LIST, mLocaleList.toLanguageTags());
Nataniel Borges023ecb52019-01-16 14:15:43 -08001117 }
1118 protoOutputStream.write(SCREEN_LAYOUT, screenLayout);
1119 protoOutputStream.write(COLOR_MODE, colorMode);
1120 protoOutputStream.write(TOUCHSCREEN, touchscreen);
1121 protoOutputStream.write(KEYBOARD, keyboard);
1122 protoOutputStream.write(KEYBOARD_HIDDEN, keyboardHidden);
1123 protoOutputStream.write(HARD_KEYBOARD_HIDDEN, hardKeyboardHidden);
1124 protoOutputStream.write(NAVIGATION, navigation);
1125 protoOutputStream.write(NAVIGATION_HIDDEN, navigationHidden);
1126 protoOutputStream.write(UI_MODE, uiMode);
1127 protoOutputStream.write(SMALLEST_SCREEN_WIDTH_DP, smallestScreenWidthDp);
1128 protoOutputStream.write(DENSITY_DPI, densityDpi);
1129 // For persistence, we do not care about window configuration
1130 if (!persisted && windowConfiguration != null) {
1131 windowConfiguration.writeToProto(protoOutputStream, WINDOW_CONFIGURATION);
1132 }
Kweku Adams15afdeb2018-09-04 11:54:46 -07001133 }
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001134 protoOutputStream.write(ORIENTATION, orientation);
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001135 protoOutputStream.write(SCREEN_WIDTH_DP, screenWidthDp);
1136 protoOutputStream.write(SCREEN_HEIGHT_DP, screenHeightDp);
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001137 protoOutputStream.end(token);
1138 }
1139
1140 /**
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001141 * Write to a protocol buffer output stream.
1142 * Protocol buffer message definition at {@link android.content.ConfigurationProto}
1143 *
1144 * @param protoOutputStream Stream to write the Configuration object to.
1145 * @param fieldId Field Id of the Configuration as defined in the parent message
1146 * @hide
1147 */
1148 public void writeToProto(ProtoOutputStream protoOutputStream, long fieldId) {
Nataniel Borges023ecb52019-01-16 14:15:43 -08001149 writeToProto(protoOutputStream, fieldId, false /* persisted */, false /* critical */);
1150 }
1151
1152 /**
1153 * Write to a protocol buffer output stream.
1154 * Protocol buffer message definition at {@link android.content.ConfigurationProto}
1155 *
1156 * @param protoOutputStream Stream to write the Configuration object to.
1157 * @param fieldId Field Id of the Configuration as defined in the parent message
1158 * @param critical If true, reduce amount of data written.
1159 * @hide
1160 */
1161 public void writeToProto(ProtoOutputStream protoOutputStream, long fieldId, boolean critical) {
1162 writeToProto(protoOutputStream, fieldId, false /* persisted */, critical);
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001163 }
1164
1165 /**
1166 * Read from a protocol buffer output stream.
1167 * Protocol buffer message definition at {@link android.content.ConfigurationProto}
1168 *
1169 * @param protoInputStream Stream to read the Configuration object from.
1170 * @param fieldId Field Id of the Configuration as defined in the parent message
1171 * @hide
1172 */
1173 public void readFromProto(ProtoInputStream protoInputStream, long fieldId) throws IOException {
1174 final long token = protoInputStream.start(fieldId);
1175 final List<Locale> list = new ArrayList();
1176 try {
1177 while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
1178 switch (protoInputStream.getFieldNumber()) {
1179 case (int) FONT_SCALE:
1180 fontScale = protoInputStream.readFloat(FONT_SCALE);
1181 break;
1182 case (int) MCC:
1183 mcc = protoInputStream.readInt(MCC);
1184 break;
1185 case (int) MNC:
1186 mnc = protoInputStream.readInt(MNC);
1187 break;
1188 case (int) LOCALES:
1189 // Parse the Locale here to handle all the repeated Locales
1190 // The LocaleList will be created when the message is completed
1191 final long localeToken = protoInputStream.start(LOCALES);
1192 String language = "";
1193 String country = "";
1194 String variant = "";
Varun Shah95fabaf2019-05-01 12:45:37 -07001195 String script = "";
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001196 try {
1197 while (protoInputStream.nextField()
1198 != ProtoInputStream.NO_MORE_FIELDS) {
1199 switch (protoInputStream.getFieldNumber()) {
1200 case (int) LocaleProto.LANGUAGE:
1201 language = protoInputStream.readString(
1202 LocaleProto.LANGUAGE);
1203 break;
1204 case (int) LocaleProto.COUNTRY:
1205 country = protoInputStream.readString(LocaleProto.COUNTRY);
1206 break;
1207 case (int) LocaleProto.VARIANT:
1208 variant = protoInputStream.readString(LocaleProto.VARIANT);
1209 break;
Varun Shah95fabaf2019-05-01 12:45:37 -07001210 case (int) LocaleProto.SCRIPT:
1211 script = protoInputStream.readString(LocaleProto.SCRIPT);
1212 break;
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001213 }
1214 }
1215 } catch (WireTypeMismatchException wtme) {
1216 // rethrow for caller deal with
1217 throw wtme;
1218 } finally {
1219 protoInputStream.end(localeToken);
Varun Shah95fabaf2019-05-01 12:45:37 -07001220 try {
1221 final Locale locale = new Locale.Builder()
1222 .setLanguage(language)
1223 .setRegion(country)
1224 .setVariant(variant)
1225 .setScript(script)
1226 .build();
1227 list.add(locale);
1228 } catch (IllformedLocaleException e) {
1229 Slog.e(TAG, "readFromProto error building locale with: "
1230 + "language-" + language + ";country-" + country
1231 + ";variant-" + variant + ";script-" + script);
1232 }
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001233 }
1234 break;
1235 case (int) SCREEN_LAYOUT:
1236 screenLayout = protoInputStream.readInt(SCREEN_LAYOUT);
1237 break;
1238 case (int) COLOR_MODE:
1239 colorMode = protoInputStream.readInt(COLOR_MODE);
1240 break;
1241 case (int) TOUCHSCREEN:
1242 touchscreen = protoInputStream.readInt(TOUCHSCREEN);
1243 break;
1244 case (int) KEYBOARD:
1245 keyboard = protoInputStream.readInt(KEYBOARD);
1246 break;
1247 case (int) KEYBOARD_HIDDEN:
1248 keyboardHidden = protoInputStream.readInt(KEYBOARD_HIDDEN);
1249 break;
1250 case (int) HARD_KEYBOARD_HIDDEN:
1251 hardKeyboardHidden = protoInputStream.readInt(HARD_KEYBOARD_HIDDEN);
1252 break;
1253 case (int) NAVIGATION:
1254 navigation = protoInputStream.readInt(NAVIGATION);
1255 break;
1256 case (int) NAVIGATION_HIDDEN:
1257 navigationHidden = protoInputStream.readInt(NAVIGATION_HIDDEN);
1258 break;
1259 case (int) ORIENTATION:
1260 orientation = protoInputStream.readInt(ORIENTATION);
1261 break;
1262 case (int) UI_MODE:
1263 uiMode = protoInputStream.readInt(UI_MODE);
1264 break;
1265 case (int) SCREEN_WIDTH_DP:
1266 screenWidthDp = protoInputStream.readInt(SCREEN_WIDTH_DP);
1267 break;
1268 case (int) SCREEN_HEIGHT_DP:
1269 screenHeightDp = protoInputStream.readInt(SCREEN_HEIGHT_DP);
1270 break;
1271 case (int) SMALLEST_SCREEN_WIDTH_DP:
1272 smallestScreenWidthDp = protoInputStream.readInt(SMALLEST_SCREEN_WIDTH_DP);
1273 break;
1274 case (int) DENSITY_DPI:
1275 densityDpi = protoInputStream.readInt(DENSITY_DPI);
1276 break;
1277 case (int) WINDOW_CONFIGURATION:
1278 windowConfiguration.readFromProto(protoInputStream, WINDOW_CONFIGURATION);
1279 break;
Varun Shahb53b3442019-09-10 14:41:00 -04001280 case (int) LOCALE_LIST:
1281 try {
1282 setLocales(LocaleList.forLanguageTags(protoInputStream.readString(
1283 LOCALE_LIST)));
1284 } catch (Exception e) {
1285 Slog.e(TAG, "error parsing locale list in configuration.", e);
1286 }
1287 break;
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001288 }
1289 }
1290 } finally {
1291 // Let caller handle any exceptions
1292 if (list.size() > 0) {
1293 //Create the LocaleList from the collected Locales
1294 setLocales(new LocaleList(list.toArray(new Locale[list.size()])));
1295 }
1296 protoInputStream.end(token);
1297 }
1298 }
1299
1300 /**
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -08001301 * Write full {@link android.content.ResourcesConfigurationProto} to protocol buffer output
1302 * stream.
1303 *
1304 * @param protoOutputStream Stream to write the Configuration object to.
1305 * @param fieldId Field Id of the Configuration as defined in the parent message
1306 * @param metrics Current display information
1307 * @hide
1308 */
1309 public void writeResConfigToProto(ProtoOutputStream protoOutputStream, long fieldId,
1310 DisplayMetrics metrics) {
1311 final int width, height;
1312 if (metrics.widthPixels >= metrics.heightPixels) {
1313 width = metrics.widthPixels;
1314 height = metrics.heightPixels;
1315 } else {
1316 //noinspection SuspiciousNameCombination
1317 width = metrics.heightPixels;
1318 //noinspection SuspiciousNameCombination
1319 height = metrics.widthPixels;
1320 }
1321
1322 final long token = protoOutputStream.start(fieldId);
1323 writeToProto(protoOutputStream, CONFIGURATION);
1324 protoOutputStream.write(SDK_VERSION, Build.VERSION.RESOURCES_SDK_INT);
1325 protoOutputStream.write(SCREEN_WIDTH_PX, width);
1326 protoOutputStream.write(SCREEN_HEIGHT_PX, height);
1327 protoOutputStream.end(token);
1328 }
1329
1330 /**
Michael Wright19859762017-09-18 20:57:58 +01001331 * Convert the UI mode to a human readable format.
1332 * @hide
1333 */
1334 public static String uiModeToString(int uiMode) {
1335 switch (uiMode) {
1336 case UI_MODE_TYPE_UNDEFINED:
1337 return "UI_MODE_TYPE_UNDEFINED";
1338 case UI_MODE_TYPE_NORMAL:
1339 return "UI_MODE_TYPE_NORMAL";
1340 case UI_MODE_TYPE_DESK:
1341 return "UI_MODE_TYPE_DESK";
1342 case UI_MODE_TYPE_CAR:
1343 return "UI_MODE_TYPE_CAR";
1344 case UI_MODE_TYPE_TELEVISION:
1345 return "UI_MODE_TYPE_TELEVISION";
1346 case UI_MODE_TYPE_APPLIANCE:
1347 return "UI_MODE_TYPE_APPLIANCE";
1348 case UI_MODE_TYPE_WATCH:
1349 return "UI_MODE_TYPE_WATCH";
1350 case UI_MODE_TYPE_VR_HEADSET:
1351 return "UI_MODE_TYPE_VR_HEADSET";
1352 default:
1353 return Integer.toString(uiMode);
1354 }
1355 }
1356
1357 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 * Set this object to the system defaults.
1359 */
1360 public void setToDefaults() {
1361 fontScale = 1;
1362 mcc = mnc = 0;
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001363 mLocaleList = LocaleList.getEmptyLocaleList();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001364 locale = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 userSetLocale = false;
1366 touchscreen = TOUCHSCREEN_UNDEFINED;
1367 keyboard = KEYBOARD_UNDEFINED;
1368 keyboardHidden = KEYBOARDHIDDEN_UNDEFINED;
1369 hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED;
1370 navigation = NAVIGATION_UNDEFINED;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001371 navigationHidden = NAVIGATIONHIDDEN_UNDEFINED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001372 orientation = ORIENTATION_UNDEFINED;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001373 screenLayout = SCREENLAYOUT_UNDEFINED;
Romain Guy48327452017-01-23 17:03:35 -08001374 colorMode = COLOR_MODE_UNDEFINED;
Dianne Hackborn7299c412010-03-04 18:41:49 -08001375 uiMode = UI_MODE_TYPE_UNDEFINED;
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001376 screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
1377 screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
1378 smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001379 densityDpi = DENSITY_DPI_UNDEFINED;
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001380 assetsSeq = ASSETS_SEQ_UNDEFINED;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001381 seq = 0;
Wale Ogunwale822e5122017-07-26 06:02:24 -07001382 windowConfiguration.setToDefaults();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 }
1384
Adam Lesinskibad43fc2016-07-19 13:35:01 -07001385 /**
1386 * Set this object to completely undefined.
1387 * @hide
1388 */
1389 public void unset() {
1390 setToDefaults();
1391 fontScale = 0;
1392 }
1393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 /** {@hide} */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001395 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 @Deprecated public void makeDefault() {
1397 setToDefaults();
1398 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -07001399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400 /**
Alan Viveretteac85f902016-03-11 15:15:51 -05001401 * Copies the fields from delta into this Configuration object, keeping
1402 * track of which ones have changed. Any undefined fields in {@code delta}
1403 * are ignored and not copied in to the current Configuration.
1404 *
1405 * @return a bit mask of the changed fields, as per {@link #diff}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 */
Alan Viveretteac85f902016-03-11 15:15:51 -05001407 public @Config int updateFrom(@NonNull Configuration delta) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 int changed = 0;
1409 if (delta.fontScale > 0 && fontScale != delta.fontScale) {
1410 changed |= ActivityInfo.CONFIG_FONT_SCALE;
1411 fontScale = delta.fontScale;
1412 }
1413 if (delta.mcc != 0 && mcc != delta.mcc) {
1414 changed |= ActivityInfo.CONFIG_MCC;
1415 mcc = delta.mcc;
1416 }
1417 if (delta.mnc != 0 && mnc != delta.mnc) {
1418 changed |= ActivityInfo.CONFIG_MNC;
1419 mnc = delta.mnc;
1420 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001421 fixUpLocaleList();
1422 delta.fixUpLocaleList();
1423 if (!delta.mLocaleList.isEmpty() && !mLocaleList.equals(delta.mLocaleList)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 changed |= ActivityInfo.CONFIG_LOCALE;
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001425 mLocaleList = delta.mLocaleList;
1426 // delta.locale can't be null, since delta.mLocaleList is not empty.
1427 if (!delta.locale.equals(locale)) {
1428 locale = (Locale) delta.locale.clone();
1429 // If locale has changed, then layout direction is also changed ...
1430 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
1431 // ... and we need to update the layout direction (represented by the first
1432 // 2 most significant bits in screenLayout).
1433 setLayoutDirection(locale);
1434 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 }
Craig Mautner31678b52013-08-12 17:56:34 -07001436 final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;
1437 if (deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED &&
1438 deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {
1439 screenLayout = (screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK) | deltaScreenLayoutDir;
Amith Yamasanid8415f42013-08-07 20:15:10 -07001440 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
Amith Yamasanid8415f42013-08-07 20:15:10 -07001441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0)))
1443 {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 changed |= ActivityInfo.CONFIG_LOCALE;
Amith Yamasanid8415f42013-08-07 20:15:10 -07001445 userSetLocale = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 }
1447 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
1448 && touchscreen != delta.touchscreen) {
1449 changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
1450 touchscreen = delta.touchscreen;
1451 }
1452 if (delta.keyboard != KEYBOARD_UNDEFINED
1453 && keyboard != delta.keyboard) {
1454 changed |= ActivityInfo.CONFIG_KEYBOARD;
1455 keyboard = delta.keyboard;
1456 }
1457 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
1458 && keyboardHidden != delta.keyboardHidden) {
1459 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1460 keyboardHidden = delta.keyboardHidden;
1461 }
1462 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
1463 && hardKeyboardHidden != delta.hardKeyboardHidden) {
1464 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1465 hardKeyboardHidden = delta.hardKeyboardHidden;
1466 }
1467 if (delta.navigation != NAVIGATION_UNDEFINED
1468 && navigation != delta.navigation) {
1469 changed |= ActivityInfo.CONFIG_NAVIGATION;
1470 navigation = delta.navigation;
1471 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001472 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
1473 && navigationHidden != delta.navigationHidden) {
1474 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1475 navigationHidden = delta.navigationHidden;
1476 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 if (delta.orientation != ORIENTATION_UNDEFINED
1478 && orientation != delta.orientation) {
1479 changed |= ActivityInfo.CONFIG_ORIENTATION;
1480 orientation = delta.orientation;
1481 }
Robert Carrdf259d32016-12-05 20:33:10 -08001482 if (((delta.screenLayout & SCREENLAYOUT_SIZE_MASK) != SCREENLAYOUT_SIZE_UNDEFINED)
1483 && (delta.screenLayout & SCREENLAYOUT_SIZE_MASK)
1484 != (screenLayout & SCREENLAYOUT_SIZE_MASK)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001485 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
Robert Carrdf259d32016-12-05 20:33:10 -08001486 screenLayout = (screenLayout & ~SCREENLAYOUT_SIZE_MASK)
1487 | (delta.screenLayout & SCREENLAYOUT_SIZE_MASK);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001488 }
Robert Carrdf259d32016-12-05 20:33:10 -08001489 if (((delta.screenLayout & SCREENLAYOUT_LONG_MASK) != SCREENLAYOUT_LONG_UNDEFINED)
1490 && (delta.screenLayout & SCREENLAYOUT_LONG_MASK)
1491 != (screenLayout & SCREENLAYOUT_LONG_MASK)) {
1492 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
1493 screenLayout = (screenLayout & ~SCREENLAYOUT_LONG_MASK)
1494 | (delta.screenLayout & SCREENLAYOUT_LONG_MASK);
1495 }
1496 if (((delta.screenLayout & SCREENLAYOUT_ROUND_MASK) != SCREENLAYOUT_ROUND_UNDEFINED)
1497 && (delta.screenLayout & SCREENLAYOUT_ROUND_MASK)
1498 != (screenLayout & SCREENLAYOUT_ROUND_MASK)) {
1499 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
1500 screenLayout = (screenLayout & ~SCREENLAYOUT_ROUND_MASK)
1501 | (delta.screenLayout & SCREENLAYOUT_ROUND_MASK);
1502 }
1503 if ((delta.screenLayout & SCREENLAYOUT_COMPAT_NEEDED)
1504 != (screenLayout & SCREENLAYOUT_COMPAT_NEEDED)
1505 && delta.screenLayout != 0) {
1506 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
1507 screenLayout = (screenLayout & ~SCREENLAYOUT_COMPAT_NEEDED)
1508 | (delta.screenLayout & SCREENLAYOUT_COMPAT_NEEDED);
1509 }
1510
Romain Guy48327452017-01-23 17:03:35 -08001511 if (((delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) !=
1512 COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED)
1513 && (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)
1514 != (colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) {
1515 changed |= ActivityInfo.CONFIG_COLOR_MODE;
1516 colorMode = (colorMode & ~COLOR_MODE_WIDE_COLOR_GAMUT_MASK)
1517 | (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK);
Romain Guyc9ba5592017-01-18 16:34:42 -08001518 }
1519
Romain Guy48327452017-01-23 17:03:35 -08001520 if (((delta.colorMode & COLOR_MODE_HDR_MASK) != COLOR_MODE_HDR_UNDEFINED)
1521 && (delta.colorMode & COLOR_MODE_HDR_MASK)
1522 != (colorMode & COLOR_MODE_HDR_MASK)) {
1523 changed |= ActivityInfo.CONFIG_COLOR_MODE;
1524 colorMode = (colorMode & ~COLOR_MODE_HDR_MASK)
1525 | (delta.colorMode & COLOR_MODE_HDR_MASK);
Romain Guyc9ba5592017-01-18 16:34:42 -08001526 }
1527
Dianne Hackborn7299c412010-03-04 18:41:49 -08001528 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
Tobias Haamel27b28b32010-02-09 23:09:17 +01001529 && uiMode != delta.uiMode) {
1530 changed |= ActivityInfo.CONFIG_UI_MODE;
Dianne Hackborn7299c412010-03-04 18:41:49 -08001531 if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) {
1532 uiMode = (uiMode&~UI_MODE_TYPE_MASK)
1533 | (delta.uiMode&UI_MODE_TYPE_MASK);
1534 }
1535 if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) {
1536 uiMode = (uiMode&~UI_MODE_NIGHT_MASK)
1537 | (delta.uiMode&UI_MODE_NIGHT_MASK);
1538 }
Tobias Haamel27b28b32010-02-09 23:09:17 +01001539 }
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001540 if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
1541 && screenWidthDp != delta.screenWidthDp) {
1542 changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
1543 screenWidthDp = delta.screenWidthDp;
1544 }
1545 if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
1546 && screenHeightDp != delta.screenHeightDp) {
1547 changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
1548 screenHeightDp = delta.screenHeightDp;
1549 }
Danny Baumanne7123a62013-05-15 10:21:40 +02001550 if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED
1551 && smallestScreenWidthDp != delta.smallestScreenWidthDp) {
1552 changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001553 smallestScreenWidthDp = delta.smallestScreenWidthDp;
1554 }
Danny Baumanne7123a62013-05-15 10:21:40 +02001555 if (delta.densityDpi != DENSITY_DPI_UNDEFINED &&
1556 densityDpi != delta.densityDpi) {
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001557 changed |= ActivityInfo.CONFIG_DENSITY;
1558 densityDpi = delta.densityDpi;
1559 }
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001560 if (delta.compatScreenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
1561 compatScreenWidthDp = delta.compatScreenWidthDp;
1562 }
1563 if (delta.compatScreenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
1564 compatScreenHeightDp = delta.compatScreenHeightDp;
1565 }
1566 if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
1567 compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp;
1568 }
Adam Lesinski4eb41292017-07-06 12:06:13 -07001569 if (delta.assetsSeq != ASSETS_SEQ_UNDEFINED && delta.assetsSeq != assetsSeq) {
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001570 changed |= ActivityInfo.CONFIG_ASSETS_PATHS;
1571 assetsSeq = delta.assetsSeq;
1572 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001573 if (delta.seq != 0) {
1574 seq = delta.seq;
1575 }
Wale Ogunwale822e5122017-07-26 06:02:24 -07001576 if (windowConfiguration.updateFrom(delta.windowConfiguration) != 0) {
1577 changed |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
1578 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -07001579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 return changed;
1581 }
1582
1583 /**
1584 * Return a bit mask of the differences between this Configuration
1585 * object and the given one. Does not change the values of either. Any
1586 * undefined fields in <var>delta</var> are ignored.
1587 * @return Returns a bit mask indicating which configuration
1588 * values has changed, containing any combination of
1589 * {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE
1590 * PackageManager.ActivityInfo.CONFIG_FONT_SCALE},
1591 * {@link android.content.pm.ActivityInfo#CONFIG_MCC
1592 * PackageManager.ActivityInfo.CONFIG_MCC},
1593 * {@link android.content.pm.ActivityInfo#CONFIG_MNC
1594 * PackageManager.ActivityInfo.CONFIG_MNC},
1595 * {@link android.content.pm.ActivityInfo#CONFIG_LOCALE
1596 * PackageManager.ActivityInfo.CONFIG_LOCALE},
1597 * {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN
1598 * PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN},
1599 * {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD
1600 * PackageManager.ActivityInfo.CONFIG_KEYBOARD},
1601 * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION
Dianne Hackborn723738c2009-06-25 19:48:04 -07001602 * PackageManager.ActivityInfo.CONFIG_NAVIGATION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001604 * PackageManager.ActivityInfo.CONFIG_ORIENTATION},
Dianne Hackborn723738c2009-06-25 19:48:04 -07001605 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001606 * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or
1607 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001608 * PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}, or
1609 * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE
1610 * PackageManager.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE}.
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001611 * {@link android.content.pm.ActivityInfo#CONFIG_LAYOUT_DIRECTION
1612 * PackageManager.ActivityInfo.CONFIG_LAYOUT_DIRECTION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 */
1614 public int diff(Configuration delta) {
Bryce Lee658d9842017-07-28 08:33:36 -07001615 return diff(delta, false /* compareUndefined */, false /* publicOnly */);
1616 }
1617
1618 /**
1619 * Returns the diff against the provided {@link Configuration} excluding values that would
1620 * publicly be equivalent, such as appBounds.
1621 * @param delta {@link Configuration} to compare to.
1622 *
1623 * TODO(b/36812336): Remove once appBounds has been moved out of Configuration.
1624 * {@hide}
1625 */
1626 public int diffPublicOnly(Configuration delta) {
1627 return diff(delta, false /* compareUndefined */, true /* publicOnly */);
Andrii Kulianb10330d2016-09-16 13:51:46 -07001628 }
1629
1630 /**
1631 * Variation of {@link #diff(Configuration)} with an option to skip checks for undefined values.
1632 *
1633 * @hide
1634 */
Bryce Lee658d9842017-07-28 08:33:36 -07001635 public int diff(Configuration delta, boolean compareUndefined, boolean publicOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 int changed = 0;
Andrii Kulianb10330d2016-09-16 13:51:46 -07001637 if ((compareUndefined || delta.fontScale > 0) && fontScale != delta.fontScale) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001638 changed |= ActivityInfo.CONFIG_FONT_SCALE;
1639 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001640 if ((compareUndefined || delta.mcc != 0) && mcc != delta.mcc) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 changed |= ActivityInfo.CONFIG_MCC;
1642 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001643 if ((compareUndefined || delta.mnc != 0) && mnc != delta.mnc) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001644 changed |= ActivityInfo.CONFIG_MNC;
1645 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001646 fixUpLocaleList();
1647 delta.fixUpLocaleList();
Andrii Kulianb10330d2016-09-16 13:51:46 -07001648 if ((compareUndefined || !delta.mLocaleList.isEmpty())
1649 && !mLocaleList.equals(delta.mLocaleList)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 changed |= ActivityInfo.CONFIG_LOCALE;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001651 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 }
Craig Mautner31678b52013-08-12 17:56:34 -07001653 final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;
Andrii Kulianb10330d2016-09-16 13:51:46 -07001654 if ((compareUndefined || deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED)
1655 && deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {
Amith Yamasanid8415f42013-08-07 20:15:10 -07001656 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
1657 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001658 if ((compareUndefined || delta.touchscreen != TOUCHSCREEN_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 && touchscreen != delta.touchscreen) {
1660 changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
1661 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001662 if ((compareUndefined || delta.keyboard != KEYBOARD_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 && keyboard != delta.keyboard) {
1664 changed |= ActivityInfo.CONFIG_KEYBOARD;
1665 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001666 if ((compareUndefined || delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001667 && keyboardHidden != delta.keyboardHidden) {
1668 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1669 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001670 if ((compareUndefined || delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001671 && hardKeyboardHidden != delta.hardKeyboardHidden) {
1672 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1673 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001674 if ((compareUndefined || delta.navigation != NAVIGATION_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 && navigation != delta.navigation) {
1676 changed |= ActivityInfo.CONFIG_NAVIGATION;
1677 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001678 if ((compareUndefined || delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED)
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001679 && navigationHidden != delta.navigationHidden) {
1680 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1681 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001682 if ((compareUndefined || delta.orientation != ORIENTATION_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001683 && orientation != delta.orientation) {
1684 changed |= ActivityInfo.CONFIG_ORIENTATION;
1685 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001686 if ((compareUndefined || getScreenLayoutNoDirection(delta.screenLayout) !=
1687 (SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED))
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001688 && getScreenLayoutNoDirection(screenLayout) !=
Andrii Kulianb10330d2016-09-16 13:51:46 -07001689 getScreenLayoutNoDirection(delta.screenLayout)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001690 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
1691 }
Romain Guyc9ba5592017-01-18 16:34:42 -08001692 if ((compareUndefined ||
Romain Guy48327452017-01-23 17:03:35 -08001693 (delta.colorMode & COLOR_MODE_HDR_MASK) != COLOR_MODE_HDR_UNDEFINED)
1694 && (colorMode & COLOR_MODE_HDR_MASK) !=
1695 (delta.colorMode & COLOR_MODE_HDR_MASK)) {
1696 changed |= ActivityInfo.CONFIG_COLOR_MODE;
Romain Guyc9ba5592017-01-18 16:34:42 -08001697 }
1698 if ((compareUndefined ||
Romain Guy48327452017-01-23 17:03:35 -08001699 (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) !=
1700 COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED)
1701 && (colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) !=
1702 (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) {
1703 changed |= ActivityInfo.CONFIG_COLOR_MODE;
Romain Guyc9ba5592017-01-18 16:34:42 -08001704 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001705 if ((compareUndefined || delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED))
Tobias Haamel27b28b32010-02-09 23:09:17 +01001706 && uiMode != delta.uiMode) {
1707 changed |= ActivityInfo.CONFIG_UI_MODE;
1708 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001709 if ((compareUndefined || delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED)
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001710 && screenWidthDp != delta.screenWidthDp) {
1711 changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
1712 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001713 if ((compareUndefined || delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED)
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001714 && screenHeightDp != delta.screenHeightDp) {
1715 changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
1716 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001717 if ((compareUndefined || delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED)
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001718 && smallestScreenWidthDp != delta.smallestScreenWidthDp) {
1719 changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
1720 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001721 if ((compareUndefined || delta.densityDpi != DENSITY_DPI_UNDEFINED)
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001722 && densityDpi != delta.densityDpi) {
1723 changed |= ActivityInfo.CONFIG_DENSITY;
1724 }
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001725 if ((compareUndefined || delta.assetsSeq != ASSETS_SEQ_UNDEFINED)
1726 && assetsSeq != delta.assetsSeq) {
1727 changed |= ActivityInfo.CONFIG_ASSETS_PATHS;
1728 }
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001729
Wale Ogunwale822e5122017-07-26 06:02:24 -07001730 // WindowConfiguration differences aren't considered public...
1731 if (!publicOnly
1732 && windowConfiguration.diff(delta.windowConfiguration, compareUndefined) != 0) {
1733 changed |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
Bryce Lee7566d762017-03-30 09:34:15 -07001734 }
1735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 return changed;
1737 }
1738
1739 /**
Alan Viveretteac85f902016-03-11 15:15:51 -05001740 * Determines if a new resource needs to be loaded from the bit set of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001741 * configuration changes returned by {@link #updateFrom(Configuration)}.
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -07001742 *
Alan Viveretteac85f902016-03-11 15:15:51 -05001743 * @param configChanges the mask of changes configurations as returned by
1744 * {@link #updateFrom(Configuration)}
1745 * @param interestingChanges the configuration changes that the resource
1746 * can handle as given in
1747 * {@link android.util.TypedValue#changingConfigurations}
1748 * @return {@code true} if the resource needs to be loaded, {@code false}
1749 * otherwise
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001750 */
Alan Viveretteac85f902016-03-11 15:15:51 -05001751 public static boolean needNewResources(@Config int configChanges,
1752 @Config int interestingChanges) {
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001753 // CONFIG_ASSETS_PATHS and CONFIG_FONT_SCALE are higher level configuration changes that
1754 // all resources are subject to change with.
1755 interestingChanges = interestingChanges | ActivityInfo.CONFIG_ASSETS_PATHS
1756 | ActivityInfo.CONFIG_FONT_SCALE;
1757 return (configChanges & interestingChanges) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001758 }
Amith Yamasanid8415f42013-08-07 20:15:10 -07001759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001760 /**
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001761 * @hide Return true if the sequence of 'other' is better than this. Assumes
1762 * that 'this' is your current sequence and 'other' is a new one you have
1763 * received some how and want to compare with what you have.
1764 */
1765 public boolean isOtherSeqNewer(Configuration other) {
1766 if (other == null) {
1767 // Sanity check.
1768 return false;
1769 }
1770 if (other.seq == 0) {
1771 // If the other sequence is not specified, then we must assume
1772 // it is newer since we don't know any better.
1773 return true;
1774 }
1775 if (seq == 0) {
1776 // If this sequence is not specified, then we also consider the
1777 // other is better. Yes we have a preference for other. Sue us.
1778 return true;
1779 }
1780 int diff = other.seq - seq;
1781 if (diff > 0x10000) {
1782 // If there has been a sufficiently large jump, assume the
1783 // sequence has wrapped around.
1784 return false;
1785 }
1786 return diff > 0;
1787 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -07001788
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001789 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790 * Parcelable methods
1791 */
1792 public int describeContents() {
1793 return 0;
1794 }
1795
1796 public void writeToParcel(Parcel dest, int flags) {
1797 dest.writeFloat(fontScale);
1798 dest.writeInt(mcc);
1799 dest.writeInt(mnc);
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001800
1801 fixUpLocaleList();
Siyamed Sinir27ddd8a2018-02-27 13:07:22 -08001802 dest.writeParcelable(mLocaleList, flags);
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001804 if(userSetLocale) {
1805 dest.writeInt(1);
1806 } else {
1807 dest.writeInt(0);
1808 }
1809 dest.writeInt(touchscreen);
1810 dest.writeInt(keyboard);
1811 dest.writeInt(keyboardHidden);
1812 dest.writeInt(hardKeyboardHidden);
1813 dest.writeInt(navigation);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001814 dest.writeInt(navigationHidden);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 dest.writeInt(orientation);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001816 dest.writeInt(screenLayout);
Romain Guy48327452017-01-23 17:03:35 -08001817 dest.writeInt(colorMode);
Tobias Haamel27b28b32010-02-09 23:09:17 +01001818 dest.writeInt(uiMode);
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001819 dest.writeInt(screenWidthDp);
1820 dest.writeInt(screenHeightDp);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001821 dest.writeInt(smallestScreenWidthDp);
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001822 dest.writeInt(densityDpi);
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001823 dest.writeInt(compatScreenWidthDp);
1824 dest.writeInt(compatScreenHeightDp);
1825 dest.writeInt(compatSmallestScreenWidthDp);
Wale Ogunwale822e5122017-07-26 06:02:24 -07001826 dest.writeValue(windowConfiguration);
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001827 dest.writeInt(assetsSeq);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001828 dest.writeInt(seq);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 }
1830
Dianne Hackborn694f79b2010-03-17 19:44:59 -07001831 public void readFromParcel(Parcel source) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001832 fontScale = source.readFloat();
1833 mcc = source.readInt();
1834 mnc = source.readInt();
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001835
Siyamed Sinir27ddd8a2018-02-27 13:07:22 -08001836 mLocaleList = source.readParcelable(LocaleList.class.getClassLoader());
Roozbeh Pournaderfee44842016-02-04 15:24:24 -08001837 locale = mLocaleList.get(0);
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 userSetLocale = (source.readInt()==1);
1840 touchscreen = source.readInt();
1841 keyboard = source.readInt();
1842 keyboardHidden = source.readInt();
1843 hardKeyboardHidden = source.readInt();
1844 navigation = source.readInt();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001845 navigationHidden = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 orientation = source.readInt();
Dianne Hackborn723738c2009-06-25 19:48:04 -07001847 screenLayout = source.readInt();
Romain Guy48327452017-01-23 17:03:35 -08001848 colorMode = source.readInt();
Tobias Haamel27b28b32010-02-09 23:09:17 +01001849 uiMode = source.readInt();
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001850 screenWidthDp = source.readInt();
1851 screenHeightDp = source.readInt();
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001852 smallestScreenWidthDp = source.readInt();
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001853 densityDpi = source.readInt();
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001854 compatScreenWidthDp = source.readInt();
1855 compatScreenHeightDp = source.readInt();
1856 compatSmallestScreenWidthDp = source.readInt();
Wale Ogunwale822e5122017-07-26 06:02:24 -07001857 windowConfiguration.setTo((WindowConfiguration) source.readValue(null));
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001858 assetsSeq = source.readInt();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001859 seq = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -07001861
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001862 public static final @android.annotation.NonNull Parcelable.Creator<Configuration> CREATOR
Dianne Hackborn694f79b2010-03-17 19:44:59 -07001863 = new Parcelable.Creator<Configuration>() {
1864 public Configuration createFromParcel(Parcel source) {
1865 return new Configuration(source);
1866 }
1867
1868 public Configuration[] newArray(int size) {
1869 return new Configuration[size];
1870 }
1871 };
1872
1873 /**
1874 * Construct this Configuration object, reading from the Parcel.
1875 */
1876 private Configuration(Parcel source) {
1877 readFromParcel(source);
1878 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879
1880 public int compareTo(Configuration that) {
1881 int n;
1882 float a = this.fontScale;
1883 float b = that.fontScale;
1884 if (a < b) return -1;
1885 if (a > b) return 1;
1886 n = this.mcc - that.mcc;
1887 if (n != 0) return n;
1888 n = this.mnc - that.mnc;
1889 if (n != 0) return n;
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001890
1891 fixUpLocaleList();
1892 that.fixUpLocaleList();
1893 // for backward compatibility, we consider an empty locale list to be greater
1894 // than any non-empty locale list.
1895 if (this.mLocaleList.isEmpty()) {
1896 if (!that.mLocaleList.isEmpty()) return 1;
1897 } else if (that.mLocaleList.isEmpty()) {
Dianne Hackborna8397032010-03-12 10:52:22 -08001898 return -1;
1899 } else {
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001900 final int minSize = Math.min(this.mLocaleList.size(), that.mLocaleList.size());
1901 for (int i = 0; i < minSize; ++i) {
1902 final Locale thisLocale = this.mLocaleList.get(i);
1903 final Locale thatLocale = that.mLocaleList.get(i);
1904 n = thisLocale.getLanguage().compareTo(thatLocale.getLanguage());
1905 if (n != 0) return n;
1906 n = thisLocale.getCountry().compareTo(thatLocale.getCountry());
1907 if (n != 0) return n;
1908 n = thisLocale.getVariant().compareTo(thatLocale.getVariant());
1909 if (n != 0) return n;
1910 n = thisLocale.toLanguageTag().compareTo(thatLocale.toLanguageTag());
1911 if (n != 0) return n;
1912 }
1913 n = this.mLocaleList.size() - that.mLocaleList.size();
Dianne Hackborna8397032010-03-12 10:52:22 -08001914 if (n != 0) return n;
1915 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001917 n = this.touchscreen - that.touchscreen;
1918 if (n != 0) return n;
1919 n = this.keyboard - that.keyboard;
1920 if (n != 0) return n;
1921 n = this.keyboardHidden - that.keyboardHidden;
1922 if (n != 0) return n;
1923 n = this.hardKeyboardHidden - that.hardKeyboardHidden;
1924 if (n != 0) return n;
1925 n = this.navigation - that.navigation;
1926 if (n != 0) return n;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001927 n = this.navigationHidden - that.navigationHidden;
1928 if (n != 0) return n;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 n = this.orientation - that.orientation;
Dianne Hackborn723738c2009-06-25 19:48:04 -07001930 if (n != 0) return n;
Romain Guy48327452017-01-23 17:03:35 -08001931 n = this.colorMode - that.colorMode;
Romain Guyc9ba5592017-01-18 16:34:42 -08001932 if (n != 0) return n;
Dianne Hackborn723738c2009-06-25 19:48:04 -07001933 n = this.screenLayout - that.screenLayout;
Tobias Haamel27b28b32010-02-09 23:09:17 +01001934 if (n != 0) return n;
1935 n = this.uiMode - that.uiMode;
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001936 if (n != 0) return n;
1937 n = this.screenWidthDp - that.screenWidthDp;
1938 if (n != 0) return n;
1939 n = this.screenHeightDp - that.screenHeightDp;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001940 if (n != 0) return n;
1941 n = this.smallestScreenWidthDp - that.smallestScreenWidthDp;
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001942 if (n != 0) return n;
1943 n = this.densityDpi - that.densityDpi;
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001944 if (n != 0) return n;
1945 n = this.assetsSeq - that.assetsSeq;
Bryce Leec5fe0ee2017-06-30 09:03:09 -07001946 if (n != 0) return n;
Wale Ogunwale822e5122017-07-26 06:02:24 -07001947 n = windowConfiguration.compareTo(that.windowConfiguration);
1948 if (n != 0) return n;
Bryce Leec5fe0ee2017-06-30 09:03:09 -07001949
1950 // if (n != 0) return n;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 return n;
1952 }
1953
1954 public boolean equals(Configuration that) {
1955 if (that == null) return false;
1956 if (that == this) return true;
1957 return this.compareTo(that) == 0;
1958 }
1959
1960 public boolean equals(Object that) {
1961 try {
1962 return equals((Configuration)that);
1963 } catch (ClassCastException e) {
1964 }
1965 return false;
1966 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 public int hashCode() {
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001969 int result = 17;
1970 result = 31 * result + Float.floatToIntBits(fontScale);
1971 result = 31 * result + mcc;
1972 result = 31 * result + mnc;
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001973 result = 31 * result + mLocaleList.hashCode();
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001974 result = 31 * result + touchscreen;
1975 result = 31 * result + keyboard;
1976 result = 31 * result + keyboardHidden;
1977 result = 31 * result + hardKeyboardHidden;
1978 result = 31 * result + navigation;
1979 result = 31 * result + navigationHidden;
1980 result = 31 * result + orientation;
1981 result = 31 * result + screenLayout;
Romain Guy48327452017-01-23 17:03:35 -08001982 result = 31 * result + colorMode;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001983 result = 31 * result + uiMode;
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001984 result = 31 * result + screenWidthDp;
1985 result = 31 * result + screenHeightDp;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001986 result = 31 * result + smallestScreenWidthDp;
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001987 result = 31 * result + densityDpi;
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001988 result = 31 * result + assetsSeq;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001989 return result;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001990 }
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001991
1992 /**
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001993 * Get the locale list. This is the preferred way for getting the locales (instead of using
1994 * the direct accessor to {@link #locale}, which would only provide the primary locale).
1995 *
1996 * @return The locale list.
1997 */
Adam Lesinskib61e4052016-05-19 18:23:05 -07001998 public @NonNull LocaleList getLocales() {
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001999 fixUpLocaleList();
2000 return mLocaleList;
2001 }
2002
2003 /**
2004 * Set the locale list. This is the preferred way for setting up the locales (instead of using
2005 * the direct accessor or {@link #setLocale(Locale)}). This will also set the layout direction
2006 * according to the first locale in the list.
2007 *
2008 * Note that the layout direction will always come from the first locale in the locale list,
2009 * even if the locale is not supported by the resources (the resources may only support
2010 * another locale further down the list which has a different direction).
2011 *
2012 * @param locales The locale list. If null, an empty LocaleList will be assigned.
2013 */
2014 public void setLocales(@Nullable LocaleList locales) {
2015 mLocaleList = locales == null ? LocaleList.getEmptyLocaleList() : locales;
Roozbeh Pournaderfee44842016-02-04 15:24:24 -08002016 locale = mLocaleList.get(0);
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002017 setLayoutDirection(locale);
2018 }
2019
2020 /**
2021 * Set the locale list to a list of just one locale. This will also set the layout direction
2022 * according to the locale.
2023 *
2024 * Note that after this is run, calling <code>.equals()</code> on the input locale and the
2025 * {@link #locale} attribute would return <code>true</code> if they are not null, but there is
2026 * no guarantee that they would be the same object.
2027 *
2028 * See also the note about layout direction in {@link #setLocales(LocaleList)}.
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002029 *
2030 * @param loc The locale. Can be null.
2031 */
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002032 public void setLocale(@Nullable Locale loc) {
Raph Levien10ea92a2016-05-02 12:56:01 -07002033 setLocales(loc == null ? LocaleList.getEmptyLocaleList() : new LocaleList(loc));
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002034 }
2035
2036 /**
Seigo Nonakabd5cac62016-05-13 15:11:37 +09002037 * @hide
2038 *
2039 * Clears the locale without changing layout direction.
2040 */
2041 public void clearLocales() {
2042 mLocaleList = LocaleList.getEmptyLocaleList();
2043 locale = null;
2044 }
2045
2046 /**
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002047 * Return the layout direction. Will be either {@link View#LAYOUT_DIRECTION_LTR} or
2048 * {@link View#LAYOUT_DIRECTION_RTL}.
2049 *
Dianne Hackbornf1ae2692013-04-19 14:09:37 -07002050 * @return Returns {@link View#LAYOUT_DIRECTION_RTL} if the configuration
2051 * is {@link #SCREENLAYOUT_LAYOUTDIR_RTL}, otherwise {@link View#LAYOUT_DIRECTION_LTR}.
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002052 */
2053 public int getLayoutDirection() {
Dianne Hackbornf1ae2692013-04-19 14:09:37 -07002054 return (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == SCREENLAYOUT_LAYOUTDIR_RTL
2055 ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002056 }
2057
2058 /**
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002059 * Set the layout direction from a Locale.
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002060 *
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002061 * @param loc The Locale. If null will set the layout direction to
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002062 * {@link View#LAYOUT_DIRECTION_LTR}. If not null will set it to the layout direction
2063 * corresponding to the Locale.
2064 *
John Spurlockbc4cf002015-03-24 21:51:20 -04002065 * @see View#LAYOUT_DIRECTION_LTR
2066 * @see View#LAYOUT_DIRECTION_RTL
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002067 */
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002068 public void setLayoutDirection(Locale loc) {
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002069 // There is a "1" difference between the configuration values for
2070 // layout direction and View constants for layout direction, just add "1".
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002071 final int layoutDirection = 1 + TextUtils.getLayoutDirectionFromLocale(loc);
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002072 screenLayout = (screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK)|
2073 (layoutDirection << SCREENLAYOUT_LAYOUTDIR_SHIFT);
2074 }
2075
2076 private static int getScreenLayoutNoDirection(int screenLayout) {
2077 return screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK;
2078 }
Adam Lesinski2c749d22014-06-04 13:00:29 -07002079
2080 /**
Adam Powell49e7ff92015-05-14 16:18:53 -07002081 * Return whether the screen has a round shape. Apps may choose to change styling based
2082 * on this property, such as the alignment or layout of text or informational icons.
2083 *
2084 * @return true if the screen is rounded, false otherwise
2085 */
2086 public boolean isScreenRound() {
2087 return (screenLayout & SCREENLAYOUT_ROUND_MASK) == SCREENLAYOUT_ROUND_YES;
2088 }
2089
2090 /**
Romain Guye89d0bb2017-06-20 12:23:42 -07002091 * Return whether the screen has a wide color gamut and wide color gamut rendering
2092 * is supported by this device.
Romain Guyc9ba5592017-01-18 16:34:42 -08002093 *
Chia-I Wu53e86ba2018-05-02 10:13:22 -07002094 * When true, it implies the screen is colorspace aware but not
2095 * necessarily color-managed. The final colors may still be changed by the
2096 * screen depending on user settings.
2097 *
Romain Guye89d0bb2017-06-20 12:23:42 -07002098 * @return true if the screen has a wide color gamut and wide color gamut rendering
2099 * is supported, false otherwise
Romain Guyc9ba5592017-01-18 16:34:42 -08002100 */
2101 public boolean isScreenWideColorGamut() {
Romain Guy48327452017-01-23 17:03:35 -08002102 return (colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) == COLOR_MODE_WIDE_COLOR_GAMUT_YES;
Romain Guyc9ba5592017-01-18 16:34:42 -08002103 }
2104
2105 /**
2106 * Return whether the screen has a high dynamic range.
2107 *
2108 * @return true if the screen has a high dynamic range, false otherwise
2109 */
2110 public boolean isScreenHdr() {
Romain Guy48327452017-01-23 17:03:35 -08002111 return (colorMode & COLOR_MODE_HDR_MASK) == COLOR_MODE_HDR_YES;
Romain Guyc9ba5592017-01-18 16:34:42 -08002112 }
2113
2114 /**
Adam Lesinski2c749d22014-06-04 13:00:29 -07002115 *
2116 * @hide
2117 */
Roozbeh Pournader47f71a62015-11-07 11:55:38 -08002118 public static String localesToResourceQualifier(LocaleList locs) {
Roozbeh Pournader309ebd62016-06-17 22:13:12 -07002119 final StringBuilder sb = new StringBuilder();
Roozbeh Pournader47f71a62015-11-07 11:55:38 -08002120 for (int i = 0; i < locs.size(); i++) {
Roozbeh Pournader309ebd62016-06-17 22:13:12 -07002121 final Locale loc = locs.get(i);
2122 final int l = loc.getLanguage().length();
2123 if (l == 0) {
2124 continue;
2125 }
2126 final int s = loc.getScript().length();
2127 final int c = loc.getCountry().length();
2128 final int v = loc.getVariant().length();
2129 // We ignore locale extensions, since they are not supported by AAPT
2130
2131 if (sb.length() != 0) {
2132 sb.append(",");
2133 }
2134 if (l == 2 && s == 0 && (c == 0 || c == 2) && v == 0) {
2135 // Traditional locale format: xx or xx-rYY
Roozbeh Pournader47f71a62015-11-07 11:55:38 -08002136 sb.append(loc.getLanguage());
Roozbeh Pournader309ebd62016-06-17 22:13:12 -07002137 if (c == 2) {
Roozbeh Pournader47f71a62015-11-07 11:55:38 -08002138 sb.append("-r").append(loc.getCountry());
Roozbeh Pournader309ebd62016-06-17 22:13:12 -07002139 }
2140 } else {
2141 sb.append("b+");
2142 sb.append(loc.getLanguage());
2143 if (s != 0) {
2144 sb.append("+");
2145 sb.append(loc.getScript());
2146 }
2147 if (c != 0) {
2148 sb.append("+");
2149 sb.append(loc.getCountry());
2150 }
2151 if (v != 0) {
2152 sb.append("+");
2153 sb.append(loc.getVariant());
Adam Lesinski2c749d22014-06-04 13:00:29 -07002154 }
2155 }
2156 }
2157 return sb.toString();
2158 }
2159
2160
2161 /**
2162 * Returns a string representation of the configuration that can be parsed
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -08002163 * by build tools (like AAPT), without display metrics included
Adam Lesinski2c749d22014-06-04 13:00:29 -07002164 *
Adam Lesinski2c749d22014-06-04 13:00:29 -07002165 * @hide
2166 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002167 @UnsupportedAppUsage
Adam Lesinski2c749d22014-06-04 13:00:29 -07002168 public static String resourceQualifierString(Configuration config) {
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -08002169 return resourceQualifierString(config, null);
2170 }
2171
2172 /**
2173 * Returns a string representation of the configuration that can be parsed
2174 * by build tools (like AAPT).
2175 *
2176 * @hide
2177 */
2178 public static String resourceQualifierString(Configuration config, DisplayMetrics metrics) {
Adam Lesinski2c749d22014-06-04 13:00:29 -07002179 ArrayList<String> parts = new ArrayList<String>();
2180
2181 if (config.mcc != 0) {
Adam Lesinski90865622014-10-16 18:18:10 -07002182 parts.add("mcc" + config.mcc);
Adam Lesinski2c749d22014-06-04 13:00:29 -07002183 if (config.mnc != 0) {
Adam Lesinski90865622014-10-16 18:18:10 -07002184 parts.add("mnc" + config.mnc);
Adam Lesinski2c749d22014-06-04 13:00:29 -07002185 }
2186 }
2187
Roozbeh Pournader47f71a62015-11-07 11:55:38 -08002188 if (!config.mLocaleList.isEmpty()) {
Roozbeh Pournader417bbe02015-11-09 17:09:15 -08002189 final String resourceQualifier = localesToResourceQualifier(config.mLocaleList);
2190 if (!resourceQualifier.isEmpty()) {
2191 parts.add(resourceQualifier);
2192 }
Adam Lesinski2c749d22014-06-04 13:00:29 -07002193 }
2194
2195 switch (config.screenLayout & Configuration.SCREENLAYOUT_LAYOUTDIR_MASK) {
2196 case Configuration.SCREENLAYOUT_LAYOUTDIR_LTR:
2197 parts.add("ldltr");
2198 break;
2199 case Configuration.SCREENLAYOUT_LAYOUTDIR_RTL:
2200 parts.add("ldrtl");
2201 break;
2202 default:
2203 break;
2204 }
2205
2206 if (config.smallestScreenWidthDp != 0) {
2207 parts.add("sw" + config.smallestScreenWidthDp + "dp");
2208 }
2209
2210 if (config.screenWidthDp != 0) {
2211 parts.add("w" + config.screenWidthDp + "dp");
2212 }
2213
2214 if (config.screenHeightDp != 0) {
2215 parts.add("h" + config.screenHeightDp + "dp");
2216 }
2217
2218 switch (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) {
2219 case Configuration.SCREENLAYOUT_SIZE_SMALL:
2220 parts.add("small");
2221 break;
2222 case Configuration.SCREENLAYOUT_SIZE_NORMAL:
2223 parts.add("normal");
2224 break;
2225 case Configuration.SCREENLAYOUT_SIZE_LARGE:
2226 parts.add("large");
2227 break;
2228 case Configuration.SCREENLAYOUT_SIZE_XLARGE:
2229 parts.add("xlarge");
2230 break;
2231 default:
2232 break;
2233 }
2234
2235 switch (config.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) {
2236 case Configuration.SCREENLAYOUT_LONG_YES:
2237 parts.add("long");
2238 break;
2239 case Configuration.SCREENLAYOUT_LONG_NO:
2240 parts.add("notlong");
2241 break;
2242 default:
2243 break;
2244 }
2245
Adam Powell49e7ff92015-05-14 16:18:53 -07002246 switch (config.screenLayout & Configuration.SCREENLAYOUT_ROUND_MASK) {
2247 case Configuration.SCREENLAYOUT_ROUND_YES:
2248 parts.add("round");
2249 break;
2250 case Configuration.SCREENLAYOUT_ROUND_NO:
2251 parts.add("notround");
2252 break;
2253 default:
2254 break;
2255 }
2256
Romain Guy48327452017-01-23 17:03:35 -08002257 switch (config.colorMode & Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_MASK) {
2258 case Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES:
Romain Guyc9ba5592017-01-18 16:34:42 -08002259 parts.add("widecg");
2260 break;
Romain Guy48327452017-01-23 17:03:35 -08002261 case Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO:
Romain Guyc9ba5592017-01-18 16:34:42 -08002262 parts.add("nowidecg");
2263 break;
2264 default:
2265 break;
2266 }
2267
Chia-I Wu0d8acf52018-05-09 12:08:05 -07002268 switch (config.colorMode & Configuration.COLOR_MODE_HDR_MASK) {
2269 case Configuration.COLOR_MODE_HDR_YES:
2270 parts.add("highdr");
2271 break;
2272 case Configuration.COLOR_MODE_HDR_NO:
2273 parts.add("lowdr");
2274 break;
2275 default:
2276 break;
2277 }
2278
Adam Lesinski2c749d22014-06-04 13:00:29 -07002279 switch (config.orientation) {
2280 case Configuration.ORIENTATION_LANDSCAPE:
2281 parts.add("land");
2282 break;
2283 case Configuration.ORIENTATION_PORTRAIT:
2284 parts.add("port");
2285 break;
2286 default:
2287 break;
2288 }
2289
2290 switch (config.uiMode & Configuration.UI_MODE_TYPE_MASK) {
2291 case Configuration.UI_MODE_TYPE_APPLIANCE:
2292 parts.add("appliance");
2293 break;
2294 case Configuration.UI_MODE_TYPE_DESK:
2295 parts.add("desk");
2296 break;
2297 case Configuration.UI_MODE_TYPE_TELEVISION:
2298 parts.add("television");
2299 break;
2300 case Configuration.UI_MODE_TYPE_CAR:
2301 parts.add("car");
2302 break;
2303 case Configuration.UI_MODE_TYPE_WATCH:
2304 parts.add("watch");
2305 break;
Zak Cohen1a6acdb2016-12-12 15:21:21 -08002306 case Configuration.UI_MODE_TYPE_VR_HEADSET:
2307 parts.add("vrheadset");
2308 break;
Adam Lesinski2c749d22014-06-04 13:00:29 -07002309 default:
2310 break;
2311 }
2312
2313 switch (config.uiMode & Configuration.UI_MODE_NIGHT_MASK) {
2314 case Configuration.UI_MODE_NIGHT_YES:
2315 parts.add("night");
2316 break;
2317 case Configuration.UI_MODE_NIGHT_NO:
2318 parts.add("notnight");
2319 break;
2320 default:
2321 break;
2322 }
2323
2324 switch (config.densityDpi) {
Adam Lesinski31245b42014-08-22 19:10:56 -07002325 case DENSITY_DPI_UNDEFINED:
Adam Lesinski2c749d22014-06-04 13:00:29 -07002326 break;
2327 case 120:
2328 parts.add("ldpi");
2329 break;
2330 case 160:
2331 parts.add("mdpi");
2332 break;
2333 case 213:
2334 parts.add("tvdpi");
2335 break;
2336 case 240:
2337 parts.add("hdpi");
2338 break;
2339 case 320:
2340 parts.add("xhdpi");
2341 break;
Adam Lesinskiebc3e4c2014-08-21 12:21:45 -07002342 case 480:
2343 parts.add("xxhdpi");
2344 break;
2345 case 640:
2346 parts.add("xxxhdpi");
2347 break;
Adam Lesinski31245b42014-08-22 19:10:56 -07002348 case DENSITY_DPI_ANY:
2349 parts.add("anydpi");
2350 break;
2351 case DENSITY_DPI_NONE:
2352 parts.add("nodpi");
Christian Williamsb709f3c2017-11-02 17:19:27 -07002353 break;
Adam Lesinski2c749d22014-06-04 13:00:29 -07002354 default:
2355 parts.add(config.densityDpi + "dpi");
2356 break;
2357 }
2358
2359 switch (config.touchscreen) {
2360 case Configuration.TOUCHSCREEN_NOTOUCH:
2361 parts.add("notouch");
2362 break;
2363 case Configuration.TOUCHSCREEN_FINGER:
2364 parts.add("finger");
2365 break;
2366 default:
2367 break;
2368 }
2369
2370 switch (config.keyboardHidden) {
2371 case Configuration.KEYBOARDHIDDEN_NO:
2372 parts.add("keysexposed");
2373 break;
2374 case Configuration.KEYBOARDHIDDEN_YES:
2375 parts.add("keyshidden");
2376 break;
2377 case Configuration.KEYBOARDHIDDEN_SOFT:
2378 parts.add("keyssoft");
2379 break;
2380 default:
2381 break;
2382 }
2383
2384 switch (config.keyboard) {
2385 case Configuration.KEYBOARD_NOKEYS:
2386 parts.add("nokeys");
2387 break;
2388 case Configuration.KEYBOARD_QWERTY:
2389 parts.add("qwerty");
2390 break;
2391 case Configuration.KEYBOARD_12KEY:
2392 parts.add("12key");
2393 break;
2394 default:
2395 break;
2396 }
2397
2398 switch (config.navigationHidden) {
2399 case Configuration.NAVIGATIONHIDDEN_NO:
2400 parts.add("navexposed");
2401 break;
2402 case Configuration.NAVIGATIONHIDDEN_YES:
2403 parts.add("navhidden");
2404 break;
2405 default:
2406 break;
2407 }
2408
2409 switch (config.navigation) {
2410 case Configuration.NAVIGATION_NONAV:
2411 parts.add("nonav");
2412 break;
2413 case Configuration.NAVIGATION_DPAD:
2414 parts.add("dpad");
2415 break;
2416 case Configuration.NAVIGATION_TRACKBALL:
2417 parts.add("trackball");
2418 break;
2419 case Configuration.NAVIGATION_WHEEL:
2420 parts.add("wheel");
2421 break;
2422 default:
2423 break;
2424 }
2425
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -08002426 if (metrics != null) {
2427 final int width, height;
2428 if (metrics.widthPixels >= metrics.heightPixels) {
2429 width = metrics.widthPixels;
2430 height = metrics.heightPixels;
2431 } else {
2432 //noinspection SuspiciousNameCombination
2433 width = metrics.heightPixels;
2434 //noinspection SuspiciousNameCombination
2435 height = metrics.widthPixels;
2436 }
2437 parts.add(width + "x" + height);
2438 }
2439
Adam Lesinskiebc3e4c2014-08-21 12:21:45 -07002440 parts.add("v" + Build.VERSION.RESOURCES_SDK_INT);
Adam Lesinski2c749d22014-06-04 13:00:29 -07002441 return TextUtils.join("-", parts);
2442 }
Adam Lesinski7f61e962014-09-02 16:43:52 -07002443
2444 /**
2445 * Generate a delta Configuration between <code>base</code> and <code>change</code>. The
2446 * resulting delta can be used with {@link #updateFrom(Configuration)}.
2447 * <p />
2448 * Caveat: If the any of the Configuration's members becomes undefined, then
2449 * {@link #updateFrom(Configuration)} will treat it as a no-op and not update that member.
2450 *
2451 * This is fine for device configurations as no member is ever undefined.
2452 * {@hide}
2453 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002454 @UnsupportedAppUsage
Adam Lesinski7f61e962014-09-02 16:43:52 -07002455 public static Configuration generateDelta(Configuration base, Configuration change) {
2456 final Configuration delta = new Configuration();
2457 if (base.fontScale != change.fontScale) {
2458 delta.fontScale = change.fontScale;
2459 }
2460
2461 if (base.mcc != change.mcc) {
2462 delta.mcc = change.mcc;
2463 }
2464
2465 if (base.mnc != change.mnc) {
2466 delta.mnc = change.mnc;
2467 }
2468
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002469 base.fixUpLocaleList();
2470 change.fixUpLocaleList();
2471 if (!base.mLocaleList.equals(change.mLocaleList)) {
2472 delta.mLocaleList = change.mLocaleList;
Adam Lesinski7f61e962014-09-02 16:43:52 -07002473 delta.locale = change.locale;
2474 }
2475
2476 if (base.touchscreen != change.touchscreen) {
2477 delta.touchscreen = change.touchscreen;
2478 }
2479
2480 if (base.keyboard != change.keyboard) {
2481 delta.keyboard = change.keyboard;
2482 }
2483
2484 if (base.keyboardHidden != change.keyboardHidden) {
2485 delta.keyboardHidden = change.keyboardHidden;
2486 }
2487
2488 if (base.navigation != change.navigation) {
2489 delta.navigation = change.navigation;
2490 }
2491
2492 if (base.navigationHidden != change.navigationHidden) {
2493 delta.navigationHidden = change.navigationHidden;
2494 }
2495
2496 if (base.orientation != change.orientation) {
2497 delta.orientation = change.orientation;
2498 }
2499
2500 if ((base.screenLayout & SCREENLAYOUT_SIZE_MASK) !=
2501 (change.screenLayout & SCREENLAYOUT_SIZE_MASK)) {
2502 delta.screenLayout |= change.screenLayout & SCREENLAYOUT_SIZE_MASK;
2503 }
2504
2505 if ((base.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK) !=
2506 (change.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {
2507 delta.screenLayout |= change.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;
2508 }
2509
2510 if ((base.screenLayout & SCREENLAYOUT_LONG_MASK) !=
2511 (change.screenLayout & SCREENLAYOUT_LONG_MASK)) {
2512 delta.screenLayout |= change.screenLayout & SCREENLAYOUT_LONG_MASK;
2513 }
2514
Adam Powell49e7ff92015-05-14 16:18:53 -07002515 if ((base.screenLayout & SCREENLAYOUT_ROUND_MASK) !=
2516 (change.screenLayout & SCREENLAYOUT_ROUND_MASK)) {
2517 delta.screenLayout |= change.screenLayout & SCREENLAYOUT_ROUND_MASK;
2518 }
2519
Romain Guy48327452017-01-23 17:03:35 -08002520 if ((base.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) !=
2521 (change.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) {
2522 delta.colorMode |= change.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK;
Romain Guyc9ba5592017-01-18 16:34:42 -08002523 }
2524
Romain Guy48327452017-01-23 17:03:35 -08002525 if ((base.colorMode & COLOR_MODE_HDR_MASK) !=
2526 (change.colorMode & COLOR_MODE_HDR_MASK)) {
2527 delta.colorMode |= change.colorMode & COLOR_MODE_HDR_MASK;
Romain Guyc9ba5592017-01-18 16:34:42 -08002528 }
2529
Adam Lesinski7f61e962014-09-02 16:43:52 -07002530 if ((base.uiMode & UI_MODE_TYPE_MASK) != (change.uiMode & UI_MODE_TYPE_MASK)) {
2531 delta.uiMode |= change.uiMode & UI_MODE_TYPE_MASK;
2532 }
2533
2534 if ((base.uiMode & UI_MODE_NIGHT_MASK) != (change.uiMode & UI_MODE_NIGHT_MASK)) {
2535 delta.uiMode |= change.uiMode & UI_MODE_NIGHT_MASK;
2536 }
2537
2538 if (base.screenWidthDp != change.screenWidthDp) {
2539 delta.screenWidthDp = change.screenWidthDp;
2540 }
2541
2542 if (base.screenHeightDp != change.screenHeightDp) {
2543 delta.screenHeightDp = change.screenHeightDp;
2544 }
2545
2546 if (base.smallestScreenWidthDp != change.smallestScreenWidthDp) {
2547 delta.smallestScreenWidthDp = change.smallestScreenWidthDp;
2548 }
2549
2550 if (base.densityDpi != change.densityDpi) {
2551 delta.densityDpi = change.densityDpi;
2552 }
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01002553
2554 if (base.assetsSeq != change.assetsSeq) {
2555 delta.assetsSeq = change.assetsSeq;
2556 }
Wale Ogunwale822e5122017-07-26 06:02:24 -07002557
2558 if (!base.windowConfiguration.equals(change.windowConfiguration)) {
2559 delta.windowConfiguration.setTo(change.windowConfiguration);
2560 }
Adam Lesinski7f61e962014-09-02 16:43:52 -07002561 return delta;
2562 }
2563
2564 private static final String XML_ATTR_FONT_SCALE = "fs";
2565 private static final String XML_ATTR_MCC = "mcc";
2566 private static final String XML_ATTR_MNC = "mnc";
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002567 private static final String XML_ATTR_LOCALES = "locales";
Adam Lesinski7f61e962014-09-02 16:43:52 -07002568 private static final String XML_ATTR_TOUCHSCREEN = "touch";
2569 private static final String XML_ATTR_KEYBOARD = "key";
2570 private static final String XML_ATTR_KEYBOARD_HIDDEN = "keyHid";
2571 private static final String XML_ATTR_HARD_KEYBOARD_HIDDEN = "hardKeyHid";
2572 private static final String XML_ATTR_NAVIGATION = "nav";
2573 private static final String XML_ATTR_NAVIGATION_HIDDEN = "navHid";
2574 private static final String XML_ATTR_ORIENTATION = "ori";
Bryce Leec1f2f2a2017-06-22 15:29:42 -07002575 private static final String XML_ATTR_ROTATION = "rot";
Adam Lesinski7f61e962014-09-02 16:43:52 -07002576 private static final String XML_ATTR_SCREEN_LAYOUT = "scrLay";
Romain Guy48327452017-01-23 17:03:35 -08002577 private static final String XML_ATTR_COLOR_MODE = "clrMod";
Adam Lesinski7f61e962014-09-02 16:43:52 -07002578 private static final String XML_ATTR_UI_MODE = "ui";
2579 private static final String XML_ATTR_SCREEN_WIDTH = "width";
2580 private static final String XML_ATTR_SCREEN_HEIGHT = "height";
2581 private static final String XML_ATTR_SMALLEST_WIDTH = "sw";
2582 private static final String XML_ATTR_DENSITY = "density";
Bryce Lee7566d762017-03-30 09:34:15 -07002583 private static final String XML_ATTR_APP_BOUNDS = "app_bounds";
Adam Lesinski7f61e962014-09-02 16:43:52 -07002584
2585 /**
2586 * Reads the attributes corresponding to Configuration member fields from the Xml parser.
2587 * The parser is expected to be on a tag which has Configuration attributes.
2588 *
2589 * @param parser The Xml parser from which to read attributes.
2590 * @param configOut The Configuration to populate from the Xml attributes.
2591 * {@hide}
2592 */
2593 public static void readXmlAttrs(XmlPullParser parser, Configuration configOut)
2594 throws XmlPullParserException, IOException {
2595 configOut.fontScale = Float.intBitsToFloat(
2596 XmlUtils.readIntAttribute(parser, XML_ATTR_FONT_SCALE, 0));
2597 configOut.mcc = XmlUtils.readIntAttribute(parser, XML_ATTR_MCC, 0);
2598 configOut.mnc = XmlUtils.readIntAttribute(parser, XML_ATTR_MNC, 0);
2599
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002600 final String localesStr = XmlUtils.readStringAttribute(parser, XML_ATTR_LOCALES);
2601 configOut.mLocaleList = LocaleList.forLanguageTags(localesStr);
Roozbeh Pournaderfee44842016-02-04 15:24:24 -08002602 configOut.locale = configOut.mLocaleList.get(0);
Adam Lesinski7f61e962014-09-02 16:43:52 -07002603
2604 configOut.touchscreen = XmlUtils.readIntAttribute(parser, XML_ATTR_TOUCHSCREEN,
2605 TOUCHSCREEN_UNDEFINED);
2606 configOut.keyboard = XmlUtils.readIntAttribute(parser, XML_ATTR_KEYBOARD,
2607 KEYBOARD_UNDEFINED);
2608 configOut.keyboardHidden = XmlUtils.readIntAttribute(parser, XML_ATTR_KEYBOARD_HIDDEN,
2609 KEYBOARDHIDDEN_UNDEFINED);
2610 configOut.hardKeyboardHidden =
2611 XmlUtils.readIntAttribute(parser, XML_ATTR_HARD_KEYBOARD_HIDDEN,
2612 HARDKEYBOARDHIDDEN_UNDEFINED);
2613 configOut.navigation = XmlUtils.readIntAttribute(parser, XML_ATTR_NAVIGATION,
2614 NAVIGATION_UNDEFINED);
2615 configOut.navigationHidden = XmlUtils.readIntAttribute(parser, XML_ATTR_NAVIGATION_HIDDEN,
2616 NAVIGATIONHIDDEN_UNDEFINED);
2617 configOut.orientation = XmlUtils.readIntAttribute(parser, XML_ATTR_ORIENTATION,
2618 ORIENTATION_UNDEFINED);
2619 configOut.screenLayout = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_LAYOUT,
2620 SCREENLAYOUT_UNDEFINED);
Romain Guy48327452017-01-23 17:03:35 -08002621 configOut.colorMode = XmlUtils.readIntAttribute(parser, XML_ATTR_COLOR_MODE,
2622 COLOR_MODE_UNDEFINED);
Adam Lesinski7f61e962014-09-02 16:43:52 -07002623 configOut.uiMode = XmlUtils.readIntAttribute(parser, XML_ATTR_UI_MODE, 0);
2624 configOut.screenWidthDp = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_WIDTH,
2625 SCREEN_WIDTH_DP_UNDEFINED);
2626 configOut.screenHeightDp = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_HEIGHT,
2627 SCREEN_HEIGHT_DP_UNDEFINED);
2628 configOut.smallestScreenWidthDp =
2629 XmlUtils.readIntAttribute(parser, XML_ATTR_SMALLEST_WIDTH,
2630 SMALLEST_SCREEN_WIDTH_DP_UNDEFINED);
2631 configOut.densityDpi = XmlUtils.readIntAttribute(parser, XML_ATTR_DENSITY,
2632 DENSITY_DPI_UNDEFINED);
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01002633
Wale Ogunwale822e5122017-07-26 06:02:24 -07002634 // For persistence, we don't care about assetsSeq and WindowConfiguration, so do not read it
2635 // out.
Adam Lesinski7f61e962014-09-02 16:43:52 -07002636 }
2637
2638
2639 /**
2640 * Writes the Configuration's member fields as attributes into the XmlSerializer.
2641 * The serializer is expected to have already started a tag so that attributes can be
2642 * immediately written.
2643 *
2644 * @param xml The serializer to which to write the attributes.
2645 * @param config The Configuration whose member fields to write.
2646 * {@hide}
2647 */
2648 public static void writeXmlAttrs(XmlSerializer xml, Configuration config) throws IOException {
2649 XmlUtils.writeIntAttribute(xml, XML_ATTR_FONT_SCALE,
2650 Float.floatToIntBits(config.fontScale));
2651 if (config.mcc != 0) {
2652 XmlUtils.writeIntAttribute(xml, XML_ATTR_MCC, config.mcc);
2653 }
2654 if (config.mnc != 0) {
2655 XmlUtils.writeIntAttribute(xml, XML_ATTR_MNC, config.mnc);
2656 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002657 config.fixUpLocaleList();
2658 if (!config.mLocaleList.isEmpty()) {
2659 XmlUtils.writeStringAttribute(xml, XML_ATTR_LOCALES, config.mLocaleList.toLanguageTags());
Adam Lesinski7f61e962014-09-02 16:43:52 -07002660 }
2661 if (config.touchscreen != TOUCHSCREEN_UNDEFINED) {
2662 XmlUtils.writeIntAttribute(xml, XML_ATTR_TOUCHSCREEN, config.touchscreen);
2663 }
2664 if (config.keyboard != KEYBOARD_UNDEFINED) {
2665 XmlUtils.writeIntAttribute(xml, XML_ATTR_KEYBOARD, config.keyboard);
2666 }
2667 if (config.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED) {
2668 XmlUtils.writeIntAttribute(xml, XML_ATTR_KEYBOARD_HIDDEN, config.keyboardHidden);
2669 }
2670 if (config.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED) {
2671 XmlUtils.writeIntAttribute(xml, XML_ATTR_HARD_KEYBOARD_HIDDEN,
2672 config.hardKeyboardHidden);
2673 }
2674 if (config.navigation != NAVIGATION_UNDEFINED) {
2675 XmlUtils.writeIntAttribute(xml, XML_ATTR_NAVIGATION, config.navigation);
2676 }
2677 if (config.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED) {
2678 XmlUtils.writeIntAttribute(xml, XML_ATTR_NAVIGATION_HIDDEN, config.navigationHidden);
2679 }
2680 if (config.orientation != ORIENTATION_UNDEFINED) {
2681 XmlUtils.writeIntAttribute(xml, XML_ATTR_ORIENTATION, config.orientation);
2682 }
2683 if (config.screenLayout != SCREENLAYOUT_UNDEFINED) {
2684 XmlUtils.writeIntAttribute(xml, XML_ATTR_SCREEN_LAYOUT, config.screenLayout);
2685 }
Romain Guy48327452017-01-23 17:03:35 -08002686 if (config.colorMode != COLOR_MODE_UNDEFINED) {
2687 XmlUtils.writeIntAttribute(xml, XML_ATTR_COLOR_MODE, config.colorMode);
Romain Guyc9ba5592017-01-18 16:34:42 -08002688 }
Adam Lesinski7f61e962014-09-02 16:43:52 -07002689 if (config.uiMode != 0) {
2690 XmlUtils.writeIntAttribute(xml, XML_ATTR_UI_MODE, config.uiMode);
2691 }
2692 if (config.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
2693 XmlUtils.writeIntAttribute(xml, XML_ATTR_SCREEN_WIDTH, config.screenWidthDp);
2694 }
2695 if (config.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
2696 XmlUtils.writeIntAttribute(xml, XML_ATTR_SCREEN_HEIGHT, config.screenHeightDp);
2697 }
2698 if (config.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
2699 XmlUtils.writeIntAttribute(xml, XML_ATTR_SMALLEST_WIDTH, config.smallestScreenWidthDp);
2700 }
2701 if (config.densityDpi != DENSITY_DPI_UNDEFINED) {
2702 XmlUtils.writeIntAttribute(xml, XML_ATTR_DENSITY, config.densityDpi);
2703 }
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01002704
Wale Ogunwale822e5122017-07-26 06:02:24 -07002705 // For persistence, we do not care about assetsSeq and window configuration, so do not write
2706 // it out.
Adam Lesinski7f61e962014-09-02 16:43:52 -07002707 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002708}