blob: 090629fe77cb9614a6ac9bf42703ae4acce50ee8 [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 Shahbd0ce4d2019-09-10 15:51:37 -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;
Romain Guye89d0bb2017-06-20 12:23:42 -070069
Adam Lesinski7f61e962014-09-02 16:43:52 -070070import java.io.IOException;
Alan Viveretteac85f902016-03-11 15:15:51 -050071import java.lang.annotation.Retention;
72import java.lang.annotation.RetentionPolicy;
Adam Lesinski2c749d22014-06-04 13:00:29 -070073import java.util.ArrayList;
Varun Shah95fabaf2019-05-01 12:45:37 -070074import java.util.IllformedLocaleException;
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -070075import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076import java.util.Locale;
77
78/**
79 * This class describes all device configuration information that can
80 * impact the resources the application retrieves. This includes both
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -070081 * user-specified configuration options (locale list and scaling) as well
Scott Main63848e32011-04-20 22:20:46 -070082 * as device configurations (such as input modes, screen size and screen orientation).
83 * <p>You can acquire this object from {@link Resources}, using {@link
84 * Resources#getConfiguration}. Thus, from an activity, you can get it by chaining the request
85 * with {@link android.app.Activity#getResources}:</p>
86 * <pre>Configuration config = getResources().getConfiguration();</pre>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 */
88public final class Configuration implements Parcelable, Comparable<Configuration> {
Dianne Hackborn756220b2012-08-14 16:45:30 -070089 /** @hide */
90 public static final Configuration EMPTY = new Configuration();
91
Varun Shah95fabaf2019-05-01 12:45:37 -070092 private static final String TAG = "Configuration";
93
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 /**
95 * Current user preference for the scaling factor for fonts, relative
96 * to the base density scaling.
97 */
98 public float fontScale;
99
100 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700101 * IMSI MCC (Mobile Country Code), corresponding to
102 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#MccQualifier">mcc</a>
103 * resource qualifier. 0 if undefined.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 */
105 public int mcc;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700108 * IMSI MNC (Mobile Network Code), corresponding to
109 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#MccQualifier">mnc</a>
Mattias Petersson1d766b52011-10-07 09:33:52 +0200110 * resource qualifier. 0 if undefined. Note that the actual MNC may be 0; in order to check
111 * for this use the {@link #MNC_ZERO} symbol.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 */
113 public int mnc;
Mattias Petersson1d766b52011-10-07 09:33:52 +0200114
115 /**
116 * Constant used to to represent MNC (Mobile Network Code) zero.
117 * 0 cannot be used, since it is used to represent an undefined MNC.
118 */
119 public static final int MNC_ZERO = 0xffff;
120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700122 * Current user preference for the locale, corresponding to
123 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#LocaleQualifier">locale</a>
124 * resource qualifier.
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700125 *
126 * @deprecated Do not set or read this directly. Use {@link #getLocales()} and
Raph Levienb1638702016-04-27 11:02:12 -0700127 * {@link #setLocales(LocaleList)}. If only the primary locale is needed,
128 * <code>getLocales().get(0)</code> is now the preferred accessor.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 */
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700130 @Deprecated public Locale locale;
131
132 private LocaleList mLocaleList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133
134 /**
Andy Stadlerf8a7cea2009-04-10 16:24:47 -0700135 * Locale should persist on setting. This is hidden because it is really
136 * questionable whether this is the right way to expose the functionality.
137 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100139 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 public boolean userSetLocale;
141
Romain Guyc9ba5592017-01-18 16:34:42 -0800142
Romain Guy48327452017-01-23 17:03:35 -0800143 /** Constant for {@link #colorMode}: bits that encode whether the screen is wide gamut. */
144 public static final int COLOR_MODE_WIDE_COLOR_GAMUT_MASK = 0x3;
Romain Guyc9ba5592017-01-18 16:34:42 -0800145 /**
Romain Guy48327452017-01-23 17:03:35 -0800146 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800147 * indicating that it is unknown whether or not the screen is wide gamut.
148 */
Romain Guy48327452017-01-23 17:03:35 -0800149 public static final int COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED = 0x0;
Romain Guyc9ba5592017-01-18 16:34:42 -0800150 /**
Romain Guy48327452017-01-23 17:03:35 -0800151 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800152 * indicating that the screen is not wide gamut.
153 * <p>Corresponds to the <code>-nowidecg</code> resource qualifier.</p>
154 */
Romain Guy48327452017-01-23 17:03:35 -0800155 public static final int COLOR_MODE_WIDE_COLOR_GAMUT_NO = 0x1;
Romain Guyc9ba5592017-01-18 16:34:42 -0800156 /**
Romain Guy48327452017-01-23 17:03:35 -0800157 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800158 * indicating that the screen is wide gamut.
159 * <p>Corresponds to the <code>-widecg</code> resource qualifier.</p>
160 */
Romain Guy48327452017-01-23 17:03:35 -0800161 public static final int COLOR_MODE_WIDE_COLOR_GAMUT_YES = 0x2;
Romain Guyc9ba5592017-01-18 16:34:42 -0800162
Romain Guyb3f69262017-04-13 20:06:41 -0700163 /** Constant for {@link #colorMode}: bits that encode the dynamic range of the screen. */
Romain Guy48327452017-01-23 17:03:35 -0800164 public static final int COLOR_MODE_HDR_MASK = 0xc;
165 /** Constant for {@link #colorMode}: bits shift to get the screen dynamic range. */
166 public static final int COLOR_MODE_HDR_SHIFT = 2;
Romain Guyc9ba5592017-01-18 16:34:42 -0800167 /**
Romain Guy48327452017-01-23 17:03:35 -0800168 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_HDR_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800169 * indicating that it is unknown whether or not the screen is HDR.
170 */
Romain Guy48327452017-01-23 17:03:35 -0800171 public static final int COLOR_MODE_HDR_UNDEFINED = 0x0;
Romain Guyc9ba5592017-01-18 16:34:42 -0800172 /**
Romain Guy48327452017-01-23 17:03:35 -0800173 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_HDR_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800174 * indicating that the screen is not HDR (low/standard dynamic range).
175 * <p>Corresponds to the <code>-lowdr</code> resource qualifier.</p>
176 */
Romain Guy48327452017-01-23 17:03:35 -0800177 public static final int COLOR_MODE_HDR_NO = 0x1 << COLOR_MODE_HDR_SHIFT;
Romain Guyc9ba5592017-01-18 16:34:42 -0800178 /**
Romain Guy48327452017-01-23 17:03:35 -0800179 * Constant for {@link #colorMode}: a {@link #COLOR_MODE_HDR_MASK} value
Romain Guyc9ba5592017-01-18 16:34:42 -0800180 * indicating that the screen is HDR (dynamic range).
181 * <p>Corresponds to the <code>-highdr</code> resource qualifier.</p>
182 */
Romain Guy48327452017-01-23 17:03:35 -0800183 public static final int COLOR_MODE_HDR_YES = 0x2 << COLOR_MODE_HDR_SHIFT;
Romain Guyc9ba5592017-01-18 16:34:42 -0800184
Romain Guy48327452017-01-23 17:03:35 -0800185 /** Constant for {@link #colorMode}: a value indicating that the color mode is undefined */
Romain Guyc9ba5592017-01-18 16:34:42 -0800186 @SuppressWarnings("PointlessBitwiseExpression")
Romain Guy48327452017-01-23 17:03:35 -0800187 public static final int COLOR_MODE_UNDEFINED = COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED |
188 COLOR_MODE_HDR_UNDEFINED;
Romain Guyc9ba5592017-01-18 16:34:42 -0800189
190 /**
Romain Guyb3f69262017-04-13 20:06:41 -0700191 * Bit mask of color capabilities of the screen. Currently there are two fields:
Romain Guy48327452017-01-23 17:03:35 -0800192 * <p>The {@link #COLOR_MODE_WIDE_COLOR_GAMUT_MASK} bits define the color gamut of
Romain Guyc9ba5592017-01-18 16:34:42 -0800193 * the screen. They may be one of
Romain Guy48327452017-01-23 17:03:35 -0800194 * {@link #COLOR_MODE_WIDE_COLOR_GAMUT_NO} or {@link #COLOR_MODE_WIDE_COLOR_GAMUT_YES}.</p>
Romain Guyc9ba5592017-01-18 16:34:42 -0800195 *
Romain Guy48327452017-01-23 17:03:35 -0800196 * <p>The {@link #COLOR_MODE_HDR_MASK} defines the dynamic range of the screen. They may be
197 * one of {@link #COLOR_MODE_HDR_NO} or {@link #COLOR_MODE_HDR_YES}.</p>
Romain Guyc9ba5592017-01-18 16:34:42 -0800198 *
199 * <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
200 * Multiple Screens</a> for more information.</p>
201 */
Romain Guy48327452017-01-23 17:03:35 -0800202 public int colorMode;
Romain Guyc9ba5592017-01-18 16:34:42 -0800203
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700204 /** Constant for {@link #screenLayout}: bits that encode the size. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700205 public static final int SCREENLAYOUT_SIZE_MASK = 0x0f;
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700206 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
207 * value indicating that no size has been set. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700208 public static final int SCREENLAYOUT_SIZE_UNDEFINED = 0x00;
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700209 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700210 * value indicating the screen is at least approximately 320x426 dp units,
211 * corresponds to the
212 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">small</a>
213 * resource qualifier.
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700214 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
215 * Multiple Screens</a> for more information. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700216 public static final int SCREENLAYOUT_SIZE_SMALL = 0x01;
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700217 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700218 * value indicating the screen is at least approximately 320x470 dp units,
219 * corresponds to the
220 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">normal</a>
221 * resource qualifier.
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700222 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
223 * Multiple Screens</a> for more information. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700224 public static final int SCREENLAYOUT_SIZE_NORMAL = 0x02;
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700225 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700226 * value indicating the screen is at least approximately 480x640 dp units,
227 * corresponds to the
228 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">large</a>
229 * resource qualifier.
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700230 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
231 * Multiple Screens</a> for more information. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700232 public static final int SCREENLAYOUT_SIZE_LARGE = 0x03;
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700233 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_SIZE_MASK}
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700234 * value indicating the screen is at least approximately 720x960 dp units,
235 * corresponds to the
236 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenSizeQualifier">xlarge</a>
237 * resource qualifier.
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700238 * See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
239 * Multiple Screens</a> for more information.*/
Dianne Hackborn14cee9f2010-04-23 17:51:26 -0700240 public static final int SCREENLAYOUT_SIZE_XLARGE = 0x04;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700241
242 /** Constant for {@link #screenLayout}: bits that encode the aspect ratio. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700243 public static final int SCREENLAYOUT_LONG_MASK = 0x30;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700244 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK}
245 * value indicating that no size has been set. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700246 public static final int SCREENLAYOUT_LONG_UNDEFINED = 0x00;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700247 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK}
248 * value that corresponds to the
249 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenAspectQualifier">notlong</a>
250 * resource qualifier. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700251 public static final int SCREENLAYOUT_LONG_NO = 0x10;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700252 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LONG_MASK}
253 * value that corresponds to the
254 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenAspectQualifier">long</a>
255 * resource qualifier. */
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700256 public static final int SCREENLAYOUT_LONG_YES = 0x20;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700257
258 /** Constant for {@link #screenLayout}: bits that encode the layout direction. */
259 public static final int SCREENLAYOUT_LAYOUTDIR_MASK = 0xC0;
260 /** Constant for {@link #screenLayout}: bits shift to get the layout direction. */
261 public static final int SCREENLAYOUT_LAYOUTDIR_SHIFT = 6;
262 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK}
263 * value indicating that no layout dir has been set. */
264 public static final int SCREENLAYOUT_LAYOUTDIR_UNDEFINED = 0x00;
265 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK}
266 * value indicating that a layout dir has been set to LTR. */
267 public static final int SCREENLAYOUT_LAYOUTDIR_LTR = 0x01 << SCREENLAYOUT_LAYOUTDIR_SHIFT;
268 /** Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_LAYOUTDIR_MASK}
269 * value indicating that a layout dir has been set to RTL. */
270 public static final int SCREENLAYOUT_LAYOUTDIR_RTL = 0x02 << SCREENLAYOUT_LAYOUTDIR_SHIFT;
271
Adam Powell49e7ff92015-05-14 16:18:53 -0700272 /** Constant for {@link #screenLayout}: bits that encode roundness of the screen. */
273 public static final int SCREENLAYOUT_ROUND_MASK = 0x300;
274 /** @hide Constant for {@link #screenLayout}: bit shift to get to screen roundness bits */
275 public static final int SCREENLAYOUT_ROUND_SHIFT = 8;
276 /**
277 * Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating
278 * that it is unknown whether or not the screen has a round shape.
279 */
280 public static final int SCREENLAYOUT_ROUND_UNDEFINED = 0x00;
281 /**
282 * Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating
283 * that the screen does not have a rounded shape.
284 */
285 public static final int SCREENLAYOUT_ROUND_NO = 0x1 << SCREENLAYOUT_ROUND_SHIFT;
286 /**
287 * Constant for {@link #screenLayout}: a {@link #SCREENLAYOUT_ROUND_MASK} value indicating
288 * that the screen has a rounded shape. Corners may not be visible to the user;
289 * developers should pay special attention to the {@link android.view.WindowInsets} delivered
290 * to views for more information about ensuring content is not obscured.
291 *
292 * <p>Corresponds to the <code>-round</code> resource qualifier.</p>
293 */
294 public static final int SCREENLAYOUT_ROUND_YES = 0x2 << SCREENLAYOUT_ROUND_SHIFT;
295
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700296 /** Constant for {@link #screenLayout}: a value indicating that screenLayout is undefined */
297 public static final int SCREENLAYOUT_UNDEFINED = SCREENLAYOUT_SIZE_UNDEFINED |
Adam Powell49e7ff92015-05-14 16:18:53 -0700298 SCREENLAYOUT_LONG_UNDEFINED | SCREENLAYOUT_LAYOUTDIR_UNDEFINED |
299 SCREENLAYOUT_ROUND_UNDEFINED;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700300
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700301 /**
302 * Special flag we generate to indicate that the screen layout requires
303 * us to use a compatibility mode for apps that are not modern layout
304 * aware.
305 * @hide
306 */
307 public static final int SCREENLAYOUT_COMPAT_NEEDED = 0x10000000;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700308
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700309 /**
Andrii Kulianf12fce12016-05-27 17:30:16 -0700310 * Bit mask of overall layout of the screen. Currently there are four
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700311 * fields:
312 * <p>The {@link #SCREENLAYOUT_SIZE_MASK} bits define the overall size
313 * of the screen. They may be one of
314 * {@link #SCREENLAYOUT_SIZE_SMALL}, {@link #SCREENLAYOUT_SIZE_NORMAL},
Adam Powell49e7ff92015-05-14 16:18:53 -0700315 * {@link #SCREENLAYOUT_SIZE_LARGE}, or {@link #SCREENLAYOUT_SIZE_XLARGE}.</p>
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700316 *
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700317 * <p>The {@link #SCREENLAYOUT_LONG_MASK} defines whether the screen
318 * is wider/taller than normal. They may be one of
Adam Powell49e7ff92015-05-14 16:18:53 -0700319 * {@link #SCREENLAYOUT_LONG_NO} or {@link #SCREENLAYOUT_LONG_YES}.</p>
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700320 *
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700321 * <p>The {@link #SCREENLAYOUT_LAYOUTDIR_MASK} defines whether the screen layout
322 * is either LTR or RTL. They may be one of
Adam Powell49e7ff92015-05-14 16:18:53 -0700323 * {@link #SCREENLAYOUT_LAYOUTDIR_LTR} or {@link #SCREENLAYOUT_LAYOUTDIR_RTL}.</p>
324 *
325 * <p>The {@link #SCREENLAYOUT_ROUND_MASK} defines whether the screen has a rounded
326 * shape. They may be one of {@link #SCREENLAYOUT_ROUND_NO} or {@link #SCREENLAYOUT_ROUND_YES}.
327 * </p>
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700328 *
Dianne Hackborn2f98f262011-03-28 18:28:35 -0700329 * <p>See <a href="{@docRoot}guide/practices/screens_support.html">Supporting
Adam Powell49e7ff92015-05-14 16:18:53 -0700330 * Multiple Screens</a> for more information.</p>
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700331 */
332 public int screenLayout;
Dianne Hackbornfe37f8f2012-09-30 12:24:33 -0700333
Bryce Lee7566d762017-03-30 09:34:15 -0700334 /**
Wale Ogunwale822e5122017-07-26 06:02:24 -0700335 * Configuration relating to the windowing state of the object associated with this
336 * Configuration. Contents of this field are not intended to affect resources, but need to be
337 * communicated and propagated at the same time as the rest of Configuration.
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700338 * @hide
Bryce Lee7566d762017-03-30 09:34:15 -0700339 */
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700340 @TestApi
Wale Ogunwale822e5122017-07-26 06:02:24 -0700341 public final WindowConfiguration windowConfiguration = new WindowConfiguration();
Bryce Lee7566d762017-03-30 09:34:15 -0700342
Dianne Hackbornfe37f8f2012-09-30 12:24:33 -0700343 /** @hide */
344 static public int resetScreenLayout(int curLayout) {
345 return (curLayout&~(SCREENLAYOUT_LONG_MASK | SCREENLAYOUT_SIZE_MASK
346 | SCREENLAYOUT_COMPAT_NEEDED))
347 | (SCREENLAYOUT_LONG_YES | SCREENLAYOUT_SIZE_XLARGE);
348 }
349
350 /** @hide */
351 static public int reduceScreenLayout(int curLayout, int longSizeDp, int shortSizeDp) {
352 int screenLayoutSize;
353 boolean screenLayoutLong;
354 boolean screenLayoutCompatNeeded;
355
356 // These semi-magic numbers define our compatibility modes for
357 // applications with different screens. These are guarantees to
358 // app developers about the space they can expect for a particular
359 // configuration. DO NOT CHANGE!
360 if (longSizeDp < 470) {
361 // This is shorter than an HVGA normal density screen (which
362 // is 480 pixels on its long side).
363 screenLayoutSize = SCREENLAYOUT_SIZE_SMALL;
364 screenLayoutLong = false;
365 screenLayoutCompatNeeded = false;
366 } else {
367 // What size is this screen screen?
368 if (longSizeDp >= 960 && shortSizeDp >= 720) {
369 // 1.5xVGA or larger screens at medium density are the point
370 // at which we consider it to be an extra large screen.
371 screenLayoutSize = SCREENLAYOUT_SIZE_XLARGE;
372 } else if (longSizeDp >= 640 && shortSizeDp >= 480) {
373 // VGA or larger screens at medium density are the point
374 // at which we consider it to be a large screen.
375 screenLayoutSize = SCREENLAYOUT_SIZE_LARGE;
376 } else {
377 screenLayoutSize = SCREENLAYOUT_SIZE_NORMAL;
378 }
379
380 // If this screen is wider than normal HVGA, or taller
381 // than FWVGA, then for old apps we want to run in size
382 // compatibility mode.
383 if (shortSizeDp > 321 || longSizeDp > 570) {
384 screenLayoutCompatNeeded = true;
385 } else {
386 screenLayoutCompatNeeded = false;
387 }
388
389 // Is this a long screen?
390 if (((longSizeDp*3)/5) >= (shortSizeDp-1)) {
391 // Anything wider than WVGA (5:3) is considering to be long.
392 screenLayoutLong = true;
393 } else {
394 screenLayoutLong = false;
395 }
396 }
397
398 // Now reduce the last screenLayout to not be better than what we
399 // have found.
400 if (!screenLayoutLong) {
401 curLayout = (curLayout&~SCREENLAYOUT_LONG_MASK) | SCREENLAYOUT_LONG_NO;
402 }
403 if (screenLayoutCompatNeeded) {
404 curLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
405 }
406 int curSize = curLayout&SCREENLAYOUT_SIZE_MASK;
407 if (screenLayoutSize < curSize) {
408 curLayout = (curLayout&~SCREENLAYOUT_SIZE_MASK) | screenLayoutSize;
409 }
410 return curLayout;
411 }
412
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700413 /** @hide */
414 public static String configurationDiffToString(int diff) {
415 ArrayList<String> list = new ArrayList<>();
416 if ((diff & ActivityInfo.CONFIG_MCC) != 0) {
417 list.add("CONFIG_MCC");
418 }
419 if ((diff & ActivityInfo.CONFIG_MNC) != 0) {
420 list.add("CONFIG_MNC");
421 }
422 if ((diff & ActivityInfo.CONFIG_LOCALE) != 0) {
423 list.add("CONFIG_LOCALE");
424 }
425 if ((diff & ActivityInfo.CONFIG_TOUCHSCREEN) != 0) {
426 list.add("CONFIG_TOUCHSCREEN");
427 }
428 if ((diff & ActivityInfo.CONFIG_KEYBOARD) != 0) {
429 list.add("CONFIG_KEYBOARD");
430 }
431 if ((diff & ActivityInfo.CONFIG_KEYBOARD_HIDDEN) != 0) {
432 list.add("CONFIG_KEYBOARD_HIDDEN");
433 }
434 if ((diff & ActivityInfo.CONFIG_NAVIGATION) != 0) {
435 list.add("CONFIG_NAVIGATION");
436 }
437 if ((diff & ActivityInfo.CONFIG_ORIENTATION) != 0) {
438 list.add("CONFIG_ORIENTATION");
439 }
440 if ((diff & ActivityInfo.CONFIG_SCREEN_LAYOUT) != 0) {
441 list.add("CONFIG_SCREEN_LAYOUT");
442 }
Romain Guy48327452017-01-23 17:03:35 -0800443 if ((diff & ActivityInfo.CONFIG_COLOR_MODE) != 0) {
444 list.add("CONFIG_COLOR_MODE");
Romain Guyc9ba5592017-01-18 16:34:42 -0800445 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700446 if ((diff & ActivityInfo.CONFIG_UI_MODE) != 0) {
447 list.add("CONFIG_UI_MODE");
448 }
449 if ((diff & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) {
450 list.add("CONFIG_SCREEN_SIZE");
451 }
452 if ((diff & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
453 list.add("CONFIG_SMALLEST_SCREEN_SIZE");
454 }
455 if ((diff & ActivityInfo.CONFIG_LAYOUT_DIRECTION) != 0) {
456 list.add("CONFIG_LAYOUT_DIRECTION");
457 }
458 if ((diff & ActivityInfo.CONFIG_FONT_SCALE) != 0) {
459 list.add("CONFIG_FONT_SCALE");
460 }
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +0100461 if ((diff & ActivityInfo.CONFIG_ASSETS_PATHS) != 0) {
462 list.add("CONFIG_ASSETS_PATHS");
463 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700464 StringBuilder builder = new StringBuilder("{");
465 for (int i = 0, n = list.size(); i < n; i++) {
466 builder.append(list.get(i));
467 if (i != n - 1) {
468 builder.append(", ");
469 }
470 }
471 builder.append("}");
472 return builder.toString();
473 }
474
Dianne Hackborn711e62a2010-11-29 16:38:22 -0800475 /**
476 * Check if the Configuration's current {@link #screenLayout} is at
477 * least the given size.
478 *
479 * @param size The desired size, either {@link #SCREENLAYOUT_SIZE_SMALL},
480 * {@link #SCREENLAYOUT_SIZE_NORMAL}, {@link #SCREENLAYOUT_SIZE_LARGE}, or
481 * {@link #SCREENLAYOUT_SIZE_XLARGE}.
482 * @return Returns true if the current screen layout size is at least
483 * the given size.
484 */
485 public boolean isLayoutSizeAtLeast(int size) {
486 int cur = screenLayout&SCREENLAYOUT_SIZE_MASK;
487 if (cur == SCREENLAYOUT_SIZE_UNDEFINED) return false;
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -0800488 return cur >= size;
Dianne Hackborn711e62a2010-11-29 16:38:22 -0800489 }
490
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700491 /** Constant for {@link #touchscreen}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 public static final int TOUCHSCREEN_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700493 /** Constant for {@link #touchscreen}, value corresponding to the
494 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#TouchscreenQualifier">notouch</a>
495 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 public static final int TOUCHSCREEN_NOTOUCH = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700497 /** @deprecated Not currently supported or used. */
498 @Deprecated public static final int TOUCHSCREEN_STYLUS = 2;
499 /** Constant for {@link #touchscreen}, value corresponding to the
500 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#TouchscreenQualifier">finger</a>
501 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 public static final int TOUCHSCREEN_FINGER = 3;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 /**
505 * The kind of touch screen attached to the device.
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700506 * One of: {@link #TOUCHSCREEN_NOTOUCH}, {@link #TOUCHSCREEN_FINGER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 */
508 public int touchscreen;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700509
510 /** Constant for {@link #keyboard}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 public static final int KEYBOARD_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700512 /** Constant for {@link #keyboard}, value corresponding to the
513 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">nokeys</a>
514 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 public static final int KEYBOARD_NOKEYS = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700516 /** Constant for {@link #keyboard}, value corresponding to the
517 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">qwerty</a>
518 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 public static final int KEYBOARD_QWERTY = 2;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700520 /** Constant for {@link #keyboard}, value corresponding to the
521 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ImeQualifier">12key</a>
522 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 public static final int KEYBOARD_12KEY = 3;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 /**
526 * The kind of keyboard attached to the device.
Kenny Root507f8ed2009-06-09 11:21:11 -0500527 * One of: {@link #KEYBOARD_NOKEYS}, {@link #KEYBOARD_QWERTY},
528 * {@link #KEYBOARD_12KEY}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 */
530 public int keyboard;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700531
532 /** Constant for {@link #keyboardHidden}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 public static final int KEYBOARDHIDDEN_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700534 /** Constant for {@link #keyboardHidden}, value corresponding to the
535 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keysexposed</a>
536 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 public static final int KEYBOARDHIDDEN_NO = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700538 /** Constant for {@link #keyboardHidden}, value corresponding to the
539 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#KeyboardAvailQualifier">keyshidden</a>
540 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 public static final int KEYBOARDHIDDEN_YES = 2;
542 /** Constant matching actual resource implementation. {@hide} */
543 public static final int KEYBOARDHIDDEN_SOFT = 3;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 /**
546 * A flag indicating whether any keyboard is available. Unlike
547 * {@link #hardKeyboardHidden}, this also takes into account a soft
548 * keyboard, so if the hard keyboard is hidden but there is soft
549 * keyboard available, it will be set to NO. Value is one of:
550 * {@link #KEYBOARDHIDDEN_NO}, {@link #KEYBOARDHIDDEN_YES}.
551 */
552 public int keyboardHidden;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700553
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700554 /** Constant for {@link #hardKeyboardHidden}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700556 /** Constant for {@link #hardKeyboardHidden}, value corresponding to the
557 * physical keyboard being exposed. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 public static final int HARDKEYBOARDHIDDEN_NO = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700559 /** Constant for {@link #hardKeyboardHidden}, value corresponding to the
560 * physical keyboard being hidden. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 public static final int HARDKEYBOARDHIDDEN_YES = 2;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 /**
564 * A flag indicating whether the hard keyboard has been hidden. This will
565 * be set on a device with a mechanism to hide the keyboard from the
566 * user, when that mechanism is closed. One of:
567 * {@link #HARDKEYBOARDHIDDEN_NO}, {@link #HARDKEYBOARDHIDDEN_YES}.
568 */
569 public int hardKeyboardHidden;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700570
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700571 /** Constant for {@link #navigation}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 public static final int NAVIGATION_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700573 /** Constant for {@link #navigation}, value corresponding to the
574 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">nonav</a>
575 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 public static final int NAVIGATION_NONAV = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700577 /** Constant for {@link #navigation}, value corresponding to the
578 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">dpad</a>
579 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 public static final int NAVIGATION_DPAD = 2;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700581 /** Constant for {@link #navigation}, value corresponding to the
582 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">trackball</a>
583 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 public static final int NAVIGATION_TRACKBALL = 3;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700585 /** Constant for {@link #navigation}, value corresponding to the
586 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavigationQualifier">wheel</a>
587 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 public static final int NAVIGATION_WHEEL = 4;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 /**
591 * The kind of navigation method available on the device.
Kenny Root507f8ed2009-06-09 11:21:11 -0500592 * One of: {@link #NAVIGATION_NONAV}, {@link #NAVIGATION_DPAD},
593 * {@link #NAVIGATION_TRACKBALL}, {@link #NAVIGATION_WHEEL}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 */
595 public int navigation;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700596
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700597 /** Constant for {@link #navigationHidden}: a value indicating that no value has been set. */
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700598 public static final int NAVIGATIONHIDDEN_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700599 /** Constant for {@link #navigationHidden}, value corresponding to the
600 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavAvailQualifier">navexposed</a>
601 * resource qualifier. */
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700602 public static final int NAVIGATIONHIDDEN_NO = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700603 /** Constant for {@link #navigationHidden}, value corresponding to the
604 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NavAvailQualifier">navhidden</a>
605 * resource qualifier. */
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700606 public static final int NAVIGATIONHIDDEN_YES = 2;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700607
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700608 /**
609 * A flag indicating whether any 5-way or DPAD navigation available.
610 * This will be set on a device with a mechanism to hide the navigation
611 * controls from the user, when that mechanism is closed. One of:
612 * {@link #NAVIGATIONHIDDEN_NO}, {@link #NAVIGATIONHIDDEN_YES}.
613 */
614 public int navigationHidden;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700615
Vadim Caen600e4902019-10-17 13:02:24 +0200616 /** @hide **/
617 @IntDef(prefix = {"ORIENTATION_"}, value = {
618 ORIENTATION_UNDEFINED,
619 ORIENTATION_PORTRAIT,
620 ORIENTATION_LANDSCAPE,
621 ORIENTATION_SQUARE
622 })
623 public @interface Orientation {
624 }
625
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700626 /** Constant for {@link #orientation}: a value indicating that no value has been set. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 public static final int ORIENTATION_UNDEFINED = 0;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700628 /** Constant for {@link #orientation}, value corresponding to the
629 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#OrientationQualifier">port</a>
630 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 public static final int ORIENTATION_PORTRAIT = 1;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700632 /** Constant for {@link #orientation}, value corresponding to the
633 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#OrientationQualifier">land</a>
634 * resource qualifier. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 public static final int ORIENTATION_LANDSCAPE = 2;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700636 /** @deprecated Not currently supported or used. */
637 @Deprecated public static final int ORIENTATION_SQUARE = 3;
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 /**
640 * Overall orientation of the screen. May be one of
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700641 * {@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 */
Vadim Caen600e4902019-10-17 13:02:24 +0200643 @Orientation
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 public int orientation;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100645
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700646 /** Constant for {@link #uiMode}: bits that encode the mode type. */
Tobias Haamel27b28b32010-02-09 23:09:17 +0100647 public static final int UI_MODE_TYPE_MASK = 0x0f;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700648 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
649 * value indicating that no mode type has been set. */
Dianne Hackbornef05e072010-03-01 17:43:39 -0800650 public static final int UI_MODE_TYPE_UNDEFINED = 0x00;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700651 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
652 * value that corresponds to
653 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">no
654 * UI mode</a> resource qualifier specified. */
Dianne Hackbornef05e072010-03-01 17:43:39 -0800655 public static final int UI_MODE_TYPE_NORMAL = 0x01;
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">desk</a>
659 * resource qualifier. */
Dianne Hackborn7299c412010-03-04 18:41:49 -0800660 public static final int UI_MODE_TYPE_DESK = 0x02;
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">car</a>
664 * resource qualifier. */
Dianne Hackborn7299c412010-03-04 18:41:49 -0800665 public static final int UI_MODE_TYPE_CAR = 0x03;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700666 /** 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">television</a>
669 * resource qualifier. */
Dianne Hackborne360bb62011-05-20 16:11:04 -0700670 public static final int UI_MODE_TYPE_TELEVISION = 0x04;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700671 /** 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">appliance</a>
674 * resource qualifier. */
Joe Onorato44fcb832011-12-14 20:59:30 -0800675 public static final int UI_MODE_TYPE_APPLIANCE = 0x05;
John Spurlock6c191292014-04-03 16:37:27 -0400676 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
677 * value that corresponds to the
678 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">watch</a>
679 * resource qualifier. */
680 public static final int UI_MODE_TYPE_WATCH = 0x06;
Zak Cohen1a6acdb2016-12-12 15:21:21 -0800681 /** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
682 * value that corresponds to the
683 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">vrheadset</a>
684 * resource qualifier. */
685 public static final int UI_MODE_TYPE_VR_HEADSET = 0x07;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100686
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700687 /** Constant for {@link #uiMode}: bits that encode the night mode. */
Tobias Haamel27b28b32010-02-09 23:09:17 +0100688 public static final int UI_MODE_NIGHT_MASK = 0x30;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700689 /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK}
690 * value indicating that no mode type has been set. */
Tobias Haamel27b28b32010-02-09 23:09:17 +0100691 public static final int UI_MODE_NIGHT_UNDEFINED = 0x00;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700692 /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK}
693 * value that corresponds to the
694 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NightQualifier">notnight</a>
695 * resource qualifier. */
Tobias Haamel27b28b32010-02-09 23:09:17 +0100696 public static final int UI_MODE_NIGHT_NO = 0x10;
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700697 /** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK}
698 * value that corresponds to the
699 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#NightQualifier">night</a>
700 * resource qualifier. */
Tobias Haamel27b28b32010-02-09 23:09:17 +0100701 public static final int UI_MODE_NIGHT_YES = 0x20;
702
703 /**
704 * Bit mask of the ui mode. Currently there are two fields:
705 * <p>The {@link #UI_MODE_TYPE_MASK} bits define the overall ui mode of the
Dianne Hackborn7299c412010-03-04 18:41:49 -0800706 * device. They may be one of {@link #UI_MODE_TYPE_UNDEFINED},
707 * {@link #UI_MODE_TYPE_NORMAL}, {@link #UI_MODE_TYPE_DESK},
John Spurlock6c191292014-04-03 16:37:27 -0400708 * {@link #UI_MODE_TYPE_CAR}, {@link #UI_MODE_TYPE_TELEVISION},
Zak Cohen1a6acdb2016-12-12 15:21:21 -0800709 * {@link #UI_MODE_TYPE_APPLIANCE}, {@link #UI_MODE_TYPE_WATCH},
710 * or {@link #UI_MODE_TYPE_VR_HEADSET}.
Tobias Haamel27b28b32010-02-09 23:09:17 +0100711 *
712 * <p>The {@link #UI_MODE_NIGHT_MASK} defines whether the screen
Dianne Hackborn7299c412010-03-04 18:41:49 -0800713 * is in a special mode. They may be one of {@link #UI_MODE_NIGHT_UNDEFINED},
Tobias Haamel27b28b32010-02-09 23:09:17 +0100714 * {@link #UI_MODE_NIGHT_NO} or {@link #UI_MODE_NIGHT_YES}.
Tobias Haamel27b28b32010-02-09 23:09:17 +0100715 */
716 public int uiMode;
717
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700718 /**
719 * Default value for {@link #screenWidthDp} indicating that no width
720 * has been specified.
721 */
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700722 public static final int SCREEN_WIDTH_DP_UNDEFINED = 0;
723
724 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700725 * The current width of the available screen space, in dp units,
726 * corresponding to
727 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenWidthQualifier">screen
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700728 * width</a> resource qualifier. Set to
729 * {@link #SCREEN_WIDTH_DP_UNDEFINED} if no width is specified.
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700730 */
731 public int screenWidthDp;
732
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700733 /**
734 * Default value for {@link #screenHeightDp} indicating that no width
735 * has been specified.
736 */
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700737 public static final int SCREEN_HEIGHT_DP_UNDEFINED = 0;
738
739 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700740 * The current height of the available screen space, in dp units,
741 * corresponding to
742 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#ScreenHeightQualifier">screen
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700743 * height</a> resource qualifier. Set to
744 * {@link #SCREEN_HEIGHT_DP_UNDEFINED} if no height is specified.
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700745 */
746 public int screenHeightDp;
747
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700748 /**
749 * Default value for {@link #smallestScreenWidthDp} indicating that no width
750 * has been specified.
751 */
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700752 public static final int SMALLEST_SCREEN_WIDTH_DP_UNDEFINED = 0;
753
754 /**
Dianne Hackborn0cf2c8a2012-05-17 17:29:49 -0700755 * The smallest screen size an application will see in normal operation,
756 * corresponding to
757 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#SmallestScreenWidthQualifier">smallest
758 * screen width</a> resource qualifier.
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700759 * This is the smallest value of both screenWidthDp and screenHeightDp
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700760 * in both portrait and landscape. Set to
761 * {@link #SMALLEST_SCREEN_WIDTH_DP_UNDEFINED} if no width is specified.
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700762 */
763 public int smallestScreenWidthDp;
764
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700765 /**
766 * Default value for {@link #densityDpi} indicating that no width
767 * has been specified.
768 */
769 public static final int DENSITY_DPI_UNDEFINED = 0;
770
771 /**
Adam Lesinski31245b42014-08-22 19:10:56 -0700772 * Value for {@link #densityDpi} for resources that scale to any density (vector drawables).
773 * {@hide}
774 */
775 public static final int DENSITY_DPI_ANY = 0xfffe;
776
777 /**
778 * Value for {@link #densityDpi} for resources that are not meant to be scaled.
779 * {@hide}
780 */
781 public static final int DENSITY_DPI_NONE = 0xffff;
782
783 /**
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700784 * The target screen density being rendered to,
785 * corresponding to
786 * <a href="{@docRoot}guide/topics/resources/providing-resources.html#DensityQualifier">density</a>
787 * resource qualifier. Set to
788 * {@link #DENSITY_DPI_UNDEFINED} if no density is specified.
789 */
790 public int densityDpi;
791
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700792 /** @hide Hack to get this information from WM to app running in compat mode. */
793 public int compatScreenWidthDp;
794 /** @hide Hack to get this information from WM to app running in compat mode. */
795 public int compatScreenHeightDp;
796 /** @hide Hack to get this information from WM to app running in compat mode. */
797 public int compatSmallestScreenWidthDp;
798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 /**
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +0100800 * An undefined assetsSeq. This will not override an existing assetsSeq.
801 * @hide
802 */
803 public static final int ASSETS_SEQ_UNDEFINED = 0;
804
805 /**
806 * Internal counter that allows us to piggyback off the configuration change mechanism to
807 * signal to apps that the the assets for an Application have changed. A difference in these
808 * between two Configurations will yield a diff flag of
809 * {@link ActivityInfo#CONFIG_ASSETS_PATHS}.
810 * @hide
811 */
Artur Satayevf0b7d0b2019-11-04 11:16:45 +0000812 @UnsupportedAppUsage
Riddle Hsue716d722019-01-09 15:56:46 +0800813 @TestApi
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +0100814 public int assetsSeq;
815
816 /**
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800817 * @hide Internal book-keeping.
818 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100819 @UnsupportedAppUsage
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800820 public int seq;
Dianne Hackborn1d0b1772013-09-06 14:02:54 -0700821
Alan Viveretteac85f902016-03-11 15:15:51 -0500822 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700823 @IntDef(flag = true, prefix = { "NATIVE_CONFIG_" }, value = {
824 NATIVE_CONFIG_MCC,
825 NATIVE_CONFIG_MNC,
826 NATIVE_CONFIG_LOCALE,
827 NATIVE_CONFIG_TOUCHSCREEN,
828 NATIVE_CONFIG_KEYBOARD,
829 NATIVE_CONFIG_KEYBOARD_HIDDEN,
830 NATIVE_CONFIG_NAVIGATION,
831 NATIVE_CONFIG_ORIENTATION,
832 NATIVE_CONFIG_DENSITY,
833 NATIVE_CONFIG_SCREEN_SIZE,
834 NATIVE_CONFIG_VERSION,
835 NATIVE_CONFIG_SCREEN_LAYOUT,
836 NATIVE_CONFIG_UI_MODE,
837 NATIVE_CONFIG_SMALLEST_SCREEN_SIZE,
838 NATIVE_CONFIG_LAYOUTDIR,
839 NATIVE_CONFIG_COLOR_MODE,
840 })
Alan Viveretteac85f902016-03-11 15:15:51 -0500841 @Retention(RetentionPolicy.SOURCE)
842 public @interface NativeConfig {}
843
Dianne Hackborn1d0b1772013-09-06 14:02:54 -0700844 /** @hide Native-specific bit mask for MCC config; DO NOT USE UNLESS YOU ARE SURE. */
845 public static final int NATIVE_CONFIG_MCC = 0x0001;
846 /** @hide Native-specific bit mask for MNC config; DO NOT USE UNLESS YOU ARE SURE. */
847 public static final int NATIVE_CONFIG_MNC = 0x0002;
848 /** @hide Native-specific bit mask for LOCALE config; DO NOT USE UNLESS YOU ARE SURE. */
849 public static final int NATIVE_CONFIG_LOCALE = 0x0004;
850 /** @hide Native-specific bit mask for TOUCHSCREEN config; DO NOT USE UNLESS YOU ARE SURE. */
851 public static final int NATIVE_CONFIG_TOUCHSCREEN = 0x0008;
852 /** @hide Native-specific bit mask for KEYBOARD config; DO NOT USE UNLESS YOU ARE SURE. */
853 public static final int NATIVE_CONFIG_KEYBOARD = 0x0010;
854 /** @hide Native-specific bit mask for KEYBOARD_HIDDEN config; DO NOT USE UNLESS YOU
855 * ARE SURE. */
856 public static final int NATIVE_CONFIG_KEYBOARD_HIDDEN = 0x0020;
857 /** @hide Native-specific bit mask for NAVIGATION config; DO NOT USE UNLESS YOU ARE SURE. */
858 public static final int NATIVE_CONFIG_NAVIGATION = 0x0040;
859 /** @hide Native-specific bit mask for ORIENTATION config; DO NOT USE UNLESS YOU ARE SURE. */
860 public static final int NATIVE_CONFIG_ORIENTATION = 0x0080;
861 /** @hide Native-specific bit mask for DENSITY config; DO NOT USE UNLESS YOU ARE SURE. */
862 public static final int NATIVE_CONFIG_DENSITY = 0x0100;
863 /** @hide Native-specific bit mask for SCREEN_SIZE config; DO NOT USE UNLESS YOU ARE SURE. */
864 public static final int NATIVE_CONFIG_SCREEN_SIZE = 0x0200;
865 /** @hide Native-specific bit mask for VERSION config; DO NOT USE UNLESS YOU ARE SURE. */
866 public static final int NATIVE_CONFIG_VERSION = 0x0400;
867 /** @hide Native-specific bit mask for SCREEN_LAYOUT config; DO NOT USE UNLESS YOU ARE SURE. */
868 public static final int NATIVE_CONFIG_SCREEN_LAYOUT = 0x0800;
869 /** @hide Native-specific bit mask for UI_MODE config; DO NOT USE UNLESS YOU ARE SURE. */
870 public static final int NATIVE_CONFIG_UI_MODE = 0x1000;
871 /** @hide Native-specific bit mask for SMALLEST_SCREEN_SIZE config; DO NOT USE UNLESS YOU
872 * ARE SURE. */
873 public static final int NATIVE_CONFIG_SMALLEST_SCREEN_SIZE = 0x2000;
874 /** @hide Native-specific bit mask for LAYOUTDIR config ; DO NOT USE UNLESS YOU ARE SURE.*/
875 public static final int NATIVE_CONFIG_LAYOUTDIR = 0x4000;
Romain Guy48327452017-01-23 17:03:35 -0800876 /** @hide Native-specific bit mask for COLOR_MODE config ; DO NOT USE UNLESS YOU ARE SURE.*/
877 public static final int NATIVE_CONFIG_COLOR_MODE = 0x10000;
Dianne Hackborn1d0b1772013-09-06 14:02:54 -0700878
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800879 /**
Adam Lesinskibad43fc2016-07-19 13:35:01 -0700880 * <p>Construct an invalid Configuration. This state is only suitable for constructing a
881 * Configuration delta that will be applied to some valid Configuration object. In order to
882 * create a valid standalone Configuration, you must call {@link #setToDefaults}. </p>
883 *
884 * <p>Example:</p>
885 * <pre class="prettyprint">
886 * Configuration validConfig = new Configuration();
887 * validConfig.setToDefaults();
888 *
889 * Configuration deltaOnlyConfig = new Configuration();
890 * deltaOnlyConfig.orientation = Configuration.ORIENTATION_LANDSCAPE;
891 *
892 * validConfig.updateFrom(deltaOnlyConfig);
893 * </pre>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 */
895 public Configuration() {
Adam Lesinskibad43fc2016-07-19 13:35:01 -0700896 unset();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 }
898
899 /**
900 * Makes a deep copy suitable for modification.
901 */
902 public Configuration(Configuration o) {
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700903 setTo(o);
904 }
905
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700906 /* This brings mLocaleList in sync with locale in case a user of the older API who doesn't know
907 * about setLocales() has changed locale directly. */
908 private void fixUpLocaleList() {
909 if ((locale == null && !mLocaleList.isEmpty()) ||
Roozbeh Pournaderfee44842016-02-04 15:24:24 -0800910 (locale != null && !locale.equals(mLocaleList.get(0)))) {
Raph Levien10ea92a2016-05-02 12:56:01 -0700911 mLocaleList = locale == null ? LocaleList.getEmptyLocaleList() : new LocaleList(locale);
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700912 }
913 }
914
Chet Haased30149e2017-01-13 12:55:16 -0800915 /**
916 * Sets the fields in this object to those in the given Configuration.
917 *
918 * @param o The Configuration object used to set the values of this Configuration's fields.
919 */
Dianne Hackborn694f79b2010-03-17 19:44:59 -0700920 public void setTo(Configuration o) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 fontScale = o.fontScale;
922 mcc = o.mcc;
923 mnc = o.mnc;
Roozbeh Pournader8a412e02015-12-02 18:39:50 -0800924 locale = o.locale == null ? null : (Locale) o.locale.clone();
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700925 o.fixUpLocaleList();
926 mLocaleList = o.mLocaleList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 userSetLocale = o.userSetLocale;
928 touchscreen = o.touchscreen;
929 keyboard = o.keyboard;
930 keyboardHidden = o.keyboardHidden;
931 hardKeyboardHidden = o.hardKeyboardHidden;
932 navigation = o.navigation;
Dianne Hackborn93e462b2009-09-15 22:50:40 -0700933 navigationHidden = o.navigationHidden;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800934 orientation = o.orientation;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700935 screenLayout = o.screenLayout;
Romain Guy48327452017-01-23 17:03:35 -0800936 colorMode = o.colorMode;
Tobias Haamel27b28b32010-02-09 23:09:17 +0100937 uiMode = o.uiMode;
Dianne Hackbornebff8f92011-05-12 18:07:47 -0700938 screenWidthDp = o.screenWidthDp;
939 screenHeightDp = o.screenHeightDp;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700940 smallestScreenWidthDp = o.smallestScreenWidthDp;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700941 densityDpi = o.densityDpi;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700942 compatScreenWidthDp = o.compatScreenWidthDp;
943 compatScreenHeightDp = o.compatScreenHeightDp;
944 compatSmallestScreenWidthDp = o.compatSmallestScreenWidthDp;
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +0100945 assetsSeq = o.assetsSeq;
Dianne Hackborne36d6e22010-02-17 19:46:25 -0800946 seq = o.seq;
Wale Ogunwale822e5122017-07-26 06:02:24 -0700947 windowConfiguration.setTo(o.windowConfiguration);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -0700949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 public String toString() {
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700951 StringBuilder sb = new StringBuilder(128);
Dianne Hackborn29735682011-04-21 17:26:39 -0700952 sb.append("{");
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700953 sb.append(fontScale);
Dianne Hackborn5be8de32011-05-24 18:11:57 -0700954 sb.append(" ");
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700955 if (mcc != 0) {
956 sb.append(mcc);
957 sb.append("mcc");
958 } else {
959 sb.append("?mcc");
960 }
961 if (mnc != 0) {
962 sb.append(mnc);
963 sb.append("mnc");
964 } else {
965 sb.append("?mnc");
966 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700967 fixUpLocaleList();
968 if (!mLocaleList.isEmpty()) {
Dianne Hackborn9a849832011-04-07 15:11:57 -0700969 sb.append(" ");
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700970 sb.append(mLocaleList);
Dianne Hackborn9a849832011-04-07 15:11:57 -0700971 } else {
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -0700972 sb.append(" ?localeList");
Daniel Sandler7d6bddc2010-07-22 16:11:55 -0400973 }
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700974 int layoutDir = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK);
975 switch (layoutDir) {
976 case SCREENLAYOUT_LAYOUTDIR_UNDEFINED: sb.append(" ?layoutDir"); break;
Fabrice Di Meglio8a802db2012-09-05 13:12:02 -0700977 case SCREENLAYOUT_LAYOUTDIR_LTR: sb.append(" ldltr"); break;
978 case SCREENLAYOUT_LAYOUTDIR_RTL: sb.append(" ldrtl"); break;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -0700979 default: sb.append(" layoutDir=");
980 sb.append(layoutDir >> SCREENLAYOUT_LAYOUTDIR_SHIFT); break;
Fabrice Di Meglio7a736fb2011-06-09 20:20:36 -0700981 }
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700982 if (smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
983 sb.append(" sw"); sb.append(smallestScreenWidthDp); sb.append("dp");
984 } else {
Dianne Hackborn2f0b1752011-05-31 17:59:49 -0700985 sb.append(" ?swdp");
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700986 }
987 if (screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
988 sb.append(" w"); sb.append(screenWidthDp); sb.append("dp");
989 } else {
Dianne Hackborn2f0b1752011-05-31 17:59:49 -0700990 sb.append(" ?wdp");
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700991 }
992 if (screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
993 sb.append(" h"); sb.append(screenHeightDp); sb.append("dp");
994 } else {
Dianne Hackborn2f0b1752011-05-31 17:59:49 -0700995 sb.append(" ?hdp");
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700996 }
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700997 if (densityDpi != DENSITY_DPI_UNDEFINED) {
998 sb.append(" "); sb.append(densityDpi); sb.append("dpi");
999 } else {
1000 sb.append(" ?density");
1001 }
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001002 switch ((screenLayout&SCREENLAYOUT_SIZE_MASK)) {
1003 case SCREENLAYOUT_SIZE_UNDEFINED: sb.append(" ?lsize"); break;
1004 case SCREENLAYOUT_SIZE_SMALL: sb.append(" smll"); break;
1005 case SCREENLAYOUT_SIZE_NORMAL: sb.append(" nrml"); break;
1006 case SCREENLAYOUT_SIZE_LARGE: sb.append(" lrg"); break;
1007 case SCREENLAYOUT_SIZE_XLARGE: sb.append(" xlrg"); break;
1008 default: sb.append(" layoutSize=");
1009 sb.append(screenLayout&SCREENLAYOUT_SIZE_MASK); break;
1010 }
1011 switch ((screenLayout&SCREENLAYOUT_LONG_MASK)) {
1012 case SCREENLAYOUT_LONG_UNDEFINED: sb.append(" ?long"); break;
1013 case SCREENLAYOUT_LONG_NO: /* not-long is not interesting to print */ break;
1014 case SCREENLAYOUT_LONG_YES: sb.append(" long"); break;
1015 default: sb.append(" layoutLong=");
1016 sb.append(screenLayout&SCREENLAYOUT_LONG_MASK); break;
1017 }
Romain Guy48327452017-01-23 17:03:35 -08001018 switch ((colorMode &COLOR_MODE_HDR_MASK)) {
1019 case COLOR_MODE_HDR_UNDEFINED: sb.append(" ?ldr"); break; // most likely not HDR
1020 case COLOR_MODE_HDR_NO: /* ldr is not interesting to print */ break;
1021 case COLOR_MODE_HDR_YES: sb.append(" hdr"); break;
Romain Guyc9ba5592017-01-18 16:34:42 -08001022 default: sb.append(" dynamicRange=");
Romain Guy48327452017-01-23 17:03:35 -08001023 sb.append(colorMode &COLOR_MODE_HDR_MASK); break;
Romain Guyc9ba5592017-01-18 16:34:42 -08001024 }
Romain Guy48327452017-01-23 17:03:35 -08001025 switch ((colorMode &COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) {
1026 case COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED: sb.append(" ?wideColorGamut"); break;
1027 case COLOR_MODE_WIDE_COLOR_GAMUT_NO: /* not wide is not interesting to print */ break;
1028 case COLOR_MODE_WIDE_COLOR_GAMUT_YES: sb.append(" widecg"); break;
Romain Guyc9ba5592017-01-18 16:34:42 -08001029 default: sb.append(" wideColorGamut=");
Romain Guy48327452017-01-23 17:03:35 -08001030 sb.append(colorMode &COLOR_MODE_WIDE_COLOR_GAMUT_MASK); break;
Romain Guyc9ba5592017-01-18 16:34:42 -08001031 }
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001032 switch (orientation) {
1033 case ORIENTATION_UNDEFINED: sb.append(" ?orien"); break;
1034 case ORIENTATION_LANDSCAPE: sb.append(" land"); break;
1035 case ORIENTATION_PORTRAIT: sb.append(" port"); break;
1036 default: sb.append(" orien="); sb.append(orientation); break;
1037 }
1038 switch ((uiMode&UI_MODE_TYPE_MASK)) {
1039 case UI_MODE_TYPE_UNDEFINED: sb.append(" ?uimode"); break;
1040 case UI_MODE_TYPE_NORMAL: /* normal is not interesting to print */ break;
1041 case UI_MODE_TYPE_DESK: sb.append(" desk"); break;
1042 case UI_MODE_TYPE_CAR: sb.append(" car"); break;
Dianne Hackborne360bb62011-05-20 16:11:04 -07001043 case UI_MODE_TYPE_TELEVISION: sb.append(" television"); break;
Joe Onorato44fcb832011-12-14 20:59:30 -08001044 case UI_MODE_TYPE_APPLIANCE: sb.append(" appliance"); break;
John Spurlock6c191292014-04-03 16:37:27 -04001045 case UI_MODE_TYPE_WATCH: sb.append(" watch"); break;
Zak Cohen1a6acdb2016-12-12 15:21:21 -08001046 case UI_MODE_TYPE_VR_HEADSET: sb.append(" vrheadset"); break;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001047 default: sb.append(" uimode="); sb.append(uiMode&UI_MODE_TYPE_MASK); break;
1048 }
1049 switch ((uiMode&UI_MODE_NIGHT_MASK)) {
1050 case UI_MODE_NIGHT_UNDEFINED: sb.append(" ?night"); break;
1051 case UI_MODE_NIGHT_NO: /* not-night is not interesting to print */ break;
1052 case UI_MODE_NIGHT_YES: sb.append(" night"); break;
1053 default: sb.append(" night="); sb.append(uiMode&UI_MODE_NIGHT_MASK); break;
1054 }
Dianne Hackborn9a849832011-04-07 15:11:57 -07001055 switch (touchscreen) {
1056 case TOUCHSCREEN_UNDEFINED: sb.append(" ?touch"); break;
1057 case TOUCHSCREEN_NOTOUCH: sb.append(" -touch"); break;
1058 case TOUCHSCREEN_STYLUS: sb.append(" stylus"); break;
1059 case TOUCHSCREEN_FINGER: sb.append(" finger"); break;
1060 default: sb.append(" touch="); sb.append(touchscreen); break;
1061 }
1062 switch (keyboard) {
1063 case KEYBOARD_UNDEFINED: sb.append(" ?keyb"); break;
1064 case KEYBOARD_NOKEYS: sb.append(" -keyb"); break;
1065 case KEYBOARD_QWERTY: sb.append(" qwerty"); break;
1066 case KEYBOARD_12KEY: sb.append(" 12key"); break;
1067 default: sb.append(" keys="); sb.append(keyboard); break;
1068 }
1069 switch (keyboardHidden) {
1070 case KEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break;
1071 case KEYBOARDHIDDEN_NO: sb.append("/v"); break;
1072 case KEYBOARDHIDDEN_YES: sb.append("/h"); break;
1073 case KEYBOARDHIDDEN_SOFT: sb.append("/s"); break;
1074 default: sb.append("/"); sb.append(keyboardHidden); break;
1075 }
1076 switch (hardKeyboardHidden) {
1077 case HARDKEYBOARDHIDDEN_UNDEFINED: sb.append("/?"); break;
1078 case HARDKEYBOARDHIDDEN_NO: sb.append("/v"); break;
1079 case HARDKEYBOARDHIDDEN_YES: sb.append("/h"); break;
1080 default: sb.append("/"); sb.append(hardKeyboardHidden); break;
1081 }
1082 switch (navigation) {
1083 case NAVIGATION_UNDEFINED: sb.append(" ?nav"); break;
1084 case NAVIGATION_NONAV: sb.append(" -nav"); break;
1085 case NAVIGATION_DPAD: sb.append(" dpad"); break;
1086 case NAVIGATION_TRACKBALL: sb.append(" tball"); break;
1087 case NAVIGATION_WHEEL: sb.append(" wheel"); break;
1088 default: sb.append(" nav="); sb.append(navigation); break;
1089 }
1090 switch (navigationHidden) {
1091 case NAVIGATIONHIDDEN_UNDEFINED: sb.append("/?"); break;
1092 case NAVIGATIONHIDDEN_NO: sb.append("/v"); break;
1093 case NAVIGATIONHIDDEN_YES: sb.append("/h"); break;
1094 default: sb.append("/"); sb.append(navigationHidden); break;
1095 }
Wale Ogunwale822e5122017-07-26 06:02:24 -07001096 sb.append(" winConfig="); sb.append(windowConfiguration);
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001097 if (assetsSeq != 0) {
1098 sb.append(" as.").append(assetsSeq);
1099 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001100 if (seq != 0) {
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001101 sb.append(" s.").append(seq);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001102 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001103 sb.append('}');
1104 return sb.toString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 }
1106
1107 /**
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001108 * Write to a protocol buffer output stream.
1109 * Protocol buffer message definition at {@link android.content.ConfigurationProto}
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001110 * Has the option to ignore fields that don't need to be persisted to disk.
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001111 *
1112 * @param protoOutputStream Stream to write the Configuration object to.
1113 * @param fieldId Field Id of the Configuration as defined in the parent message
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001114 * @param persisted Note if this proto will be persisted to disk
Nataniel Borges023ecb52019-01-16 14:15:43 -08001115 * @param critical If true, reduce amount of data written.
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001116 * @hide
1117 */
Jeffrey Huangcb782852019-12-05 11:28:11 -08001118 public void dumpDebug(ProtoOutputStream protoOutputStream, long fieldId, boolean persisted,
Nataniel Borges023ecb52019-01-16 14:15:43 -08001119 boolean critical) {
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001120 final long token = protoOutputStream.start(fieldId);
Nataniel Borges023ecb52019-01-16 14:15:43 -08001121 if (!critical) {
1122 protoOutputStream.write(FONT_SCALE, fontScale);
1123 protoOutputStream.write(MCC, mcc);
1124 protoOutputStream.write(MNC, mnc);
1125 if (mLocaleList != null) {
Varun Shahbd0ce4d2019-09-10 15:51:37 -04001126 protoOutputStream.write(LOCALE_LIST, mLocaleList.toLanguageTags());
Nataniel Borges023ecb52019-01-16 14:15:43 -08001127 }
1128 protoOutputStream.write(SCREEN_LAYOUT, screenLayout);
1129 protoOutputStream.write(COLOR_MODE, colorMode);
1130 protoOutputStream.write(TOUCHSCREEN, touchscreen);
1131 protoOutputStream.write(KEYBOARD, keyboard);
1132 protoOutputStream.write(KEYBOARD_HIDDEN, keyboardHidden);
1133 protoOutputStream.write(HARD_KEYBOARD_HIDDEN, hardKeyboardHidden);
1134 protoOutputStream.write(NAVIGATION, navigation);
1135 protoOutputStream.write(NAVIGATION_HIDDEN, navigationHidden);
1136 protoOutputStream.write(UI_MODE, uiMode);
1137 protoOutputStream.write(SMALLEST_SCREEN_WIDTH_DP, smallestScreenWidthDp);
1138 protoOutputStream.write(DENSITY_DPI, densityDpi);
1139 // For persistence, we do not care about window configuration
1140 if (!persisted && windowConfiguration != null) {
Jeffrey Huangcb782852019-12-05 11:28:11 -08001141 windowConfiguration.dumpDebug(protoOutputStream, WINDOW_CONFIGURATION);
Nataniel Borges023ecb52019-01-16 14:15:43 -08001142 }
Kweku Adams15afdeb2018-09-04 11:54:46 -07001143 }
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001144 protoOutputStream.write(ORIENTATION, orientation);
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001145 protoOutputStream.write(SCREEN_WIDTH_DP, screenWidthDp);
1146 protoOutputStream.write(SCREEN_HEIGHT_DP, screenHeightDp);
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001147 protoOutputStream.end(token);
1148 }
1149
1150 /**
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001151 * Write to a protocol buffer output stream.
1152 * Protocol buffer message definition at {@link android.content.ConfigurationProto}
1153 *
1154 * @param protoOutputStream Stream to write the Configuration object to.
1155 * @param fieldId Field Id of the Configuration as defined in the parent message
1156 * @hide
1157 */
Jeffrey Huangcb782852019-12-05 11:28:11 -08001158 public void dumpDebug(ProtoOutputStream protoOutputStream, long fieldId) {
1159 dumpDebug(protoOutputStream, fieldId, false /* persisted */, false /* critical */);
Nataniel Borges023ecb52019-01-16 14:15:43 -08001160 }
1161
1162 /**
1163 * Write to a protocol buffer output stream.
1164 * Protocol buffer message definition at {@link android.content.ConfigurationProto}
1165 *
1166 * @param protoOutputStream Stream to write the Configuration object to.
1167 * @param fieldId Field Id of the Configuration as defined in the parent message
1168 * @param critical If true, reduce amount of data written.
1169 * @hide
1170 */
Jeffrey Huangcb782852019-12-05 11:28:11 -08001171 public void dumpDebug(ProtoOutputStream protoOutputStream, long fieldId, boolean critical) {
1172 dumpDebug(protoOutputStream, fieldId, false /* persisted */, critical);
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001173 }
1174
1175 /**
1176 * Read from a protocol buffer output stream.
1177 * Protocol buffer message definition at {@link android.content.ConfigurationProto}
1178 *
1179 * @param protoInputStream Stream to read the Configuration object from.
1180 * @param fieldId Field Id of the Configuration as defined in the parent message
1181 * @hide
1182 */
1183 public void readFromProto(ProtoInputStream protoInputStream, long fieldId) throws IOException {
1184 final long token = protoInputStream.start(fieldId);
1185 final List<Locale> list = new ArrayList();
1186 try {
1187 while (protoInputStream.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
1188 switch (protoInputStream.getFieldNumber()) {
1189 case (int) FONT_SCALE:
1190 fontScale = protoInputStream.readFloat(FONT_SCALE);
1191 break;
1192 case (int) MCC:
1193 mcc = protoInputStream.readInt(MCC);
1194 break;
1195 case (int) MNC:
1196 mnc = protoInputStream.readInt(MNC);
1197 break;
1198 case (int) LOCALES:
1199 // Parse the Locale here to handle all the repeated Locales
1200 // The LocaleList will be created when the message is completed
1201 final long localeToken = protoInputStream.start(LOCALES);
1202 String language = "";
1203 String country = "";
1204 String variant = "";
Varun Shah95fabaf2019-05-01 12:45:37 -07001205 String script = "";
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001206 try {
1207 while (protoInputStream.nextField()
1208 != ProtoInputStream.NO_MORE_FIELDS) {
1209 switch (protoInputStream.getFieldNumber()) {
1210 case (int) LocaleProto.LANGUAGE:
1211 language = protoInputStream.readString(
1212 LocaleProto.LANGUAGE);
1213 break;
1214 case (int) LocaleProto.COUNTRY:
1215 country = protoInputStream.readString(LocaleProto.COUNTRY);
1216 break;
1217 case (int) LocaleProto.VARIANT:
1218 variant = protoInputStream.readString(LocaleProto.VARIANT);
1219 break;
Varun Shah95fabaf2019-05-01 12:45:37 -07001220 case (int) LocaleProto.SCRIPT:
1221 script = protoInputStream.readString(LocaleProto.SCRIPT);
1222 break;
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001223 }
1224 }
1225 } catch (WireTypeMismatchException wtme) {
1226 // rethrow for caller deal with
1227 throw wtme;
1228 } finally {
1229 protoInputStream.end(localeToken);
Varun Shah95fabaf2019-05-01 12:45:37 -07001230 try {
1231 final Locale locale = new Locale.Builder()
1232 .setLanguage(language)
1233 .setRegion(country)
1234 .setVariant(variant)
1235 .setScript(script)
1236 .build();
Varun Shah5d9031d2019-09-04 12:04:02 -07001237 // Log a WTF here if a repeated locale is found to avoid throwing an
1238 // exception in system server when LocaleList is created below
1239 final int inListIndex = list.indexOf(locale);
1240 if (inListIndex != -1) {
1241 Slog.wtf(TAG, "Repeated locale (" + list.get(inListIndex) + ")"
1242 + " found when trying to add: " + locale.toString());
1243 } else {
1244 list.add(locale);
1245 }
Varun Shah95fabaf2019-05-01 12:45:37 -07001246 } catch (IllformedLocaleException e) {
1247 Slog.e(TAG, "readFromProto error building locale with: "
1248 + "language-" + language + ";country-" + country
1249 + ";variant-" + variant + ";script-" + script);
1250 }
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001251 }
1252 break;
1253 case (int) SCREEN_LAYOUT:
1254 screenLayout = protoInputStream.readInt(SCREEN_LAYOUT);
1255 break;
1256 case (int) COLOR_MODE:
1257 colorMode = protoInputStream.readInt(COLOR_MODE);
1258 break;
1259 case (int) TOUCHSCREEN:
1260 touchscreen = protoInputStream.readInt(TOUCHSCREEN);
1261 break;
1262 case (int) KEYBOARD:
1263 keyboard = protoInputStream.readInt(KEYBOARD);
1264 break;
1265 case (int) KEYBOARD_HIDDEN:
1266 keyboardHidden = protoInputStream.readInt(KEYBOARD_HIDDEN);
1267 break;
1268 case (int) HARD_KEYBOARD_HIDDEN:
1269 hardKeyboardHidden = protoInputStream.readInt(HARD_KEYBOARD_HIDDEN);
1270 break;
1271 case (int) NAVIGATION:
1272 navigation = protoInputStream.readInt(NAVIGATION);
1273 break;
1274 case (int) NAVIGATION_HIDDEN:
1275 navigationHidden = protoInputStream.readInt(NAVIGATION_HIDDEN);
1276 break;
1277 case (int) ORIENTATION:
1278 orientation = protoInputStream.readInt(ORIENTATION);
1279 break;
1280 case (int) UI_MODE:
1281 uiMode = protoInputStream.readInt(UI_MODE);
1282 break;
1283 case (int) SCREEN_WIDTH_DP:
1284 screenWidthDp = protoInputStream.readInt(SCREEN_WIDTH_DP);
1285 break;
1286 case (int) SCREEN_HEIGHT_DP:
1287 screenHeightDp = protoInputStream.readInt(SCREEN_HEIGHT_DP);
1288 break;
1289 case (int) SMALLEST_SCREEN_WIDTH_DP:
1290 smallestScreenWidthDp = protoInputStream.readInt(SMALLEST_SCREEN_WIDTH_DP);
1291 break;
1292 case (int) DENSITY_DPI:
1293 densityDpi = protoInputStream.readInt(DENSITY_DPI);
1294 break;
1295 case (int) WINDOW_CONFIGURATION:
1296 windowConfiguration.readFromProto(protoInputStream, WINDOW_CONFIGURATION);
1297 break;
Varun Shahbd0ce4d2019-09-10 15:51:37 -04001298 case (int) LOCALE_LIST:
1299 try {
1300 setLocales(LocaleList.forLanguageTags(protoInputStream.readString(
1301 LOCALE_LIST)));
1302 } catch (Exception e) {
1303 Slog.e(TAG, "error parsing locale list in configuration.", e);
1304 }
1305 break;
Michael Wachenschwanzc8c26362018-09-07 14:59:25 -07001306 }
1307 }
1308 } finally {
1309 // Let caller handle any exceptions
1310 if (list.size() > 0) {
1311 //Create the LocaleList from the collected Locales
1312 setLocales(new LocaleList(list.toArray(new Locale[list.size()])));
1313 }
1314 protoInputStream.end(token);
1315 }
1316 }
1317
1318 /**
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -08001319 * Write full {@link android.content.ResourcesConfigurationProto} to protocol buffer output
1320 * stream.
1321 *
1322 * @param protoOutputStream Stream to write the Configuration object to.
1323 * @param fieldId Field Id of the Configuration as defined in the parent message
1324 * @param metrics Current display information
1325 * @hide
1326 */
1327 public void writeResConfigToProto(ProtoOutputStream protoOutputStream, long fieldId,
1328 DisplayMetrics metrics) {
1329 final int width, height;
1330 if (metrics.widthPixels >= metrics.heightPixels) {
1331 width = metrics.widthPixels;
1332 height = metrics.heightPixels;
1333 } else {
1334 //noinspection SuspiciousNameCombination
1335 width = metrics.heightPixels;
1336 //noinspection SuspiciousNameCombination
1337 height = metrics.widthPixels;
1338 }
1339
1340 final long token = protoOutputStream.start(fieldId);
Jeffrey Huangcb782852019-12-05 11:28:11 -08001341 dumpDebug(protoOutputStream, CONFIGURATION);
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -08001342 protoOutputStream.write(SDK_VERSION, Build.VERSION.RESOURCES_SDK_INT);
1343 protoOutputStream.write(SCREEN_WIDTH_PX, width);
1344 protoOutputStream.write(SCREEN_HEIGHT_PX, height);
1345 protoOutputStream.end(token);
1346 }
1347
1348 /**
Michael Wright19859762017-09-18 20:57:58 +01001349 * Convert the UI mode to a human readable format.
1350 * @hide
1351 */
1352 public static String uiModeToString(int uiMode) {
1353 switch (uiMode) {
1354 case UI_MODE_TYPE_UNDEFINED:
1355 return "UI_MODE_TYPE_UNDEFINED";
1356 case UI_MODE_TYPE_NORMAL:
1357 return "UI_MODE_TYPE_NORMAL";
1358 case UI_MODE_TYPE_DESK:
1359 return "UI_MODE_TYPE_DESK";
1360 case UI_MODE_TYPE_CAR:
1361 return "UI_MODE_TYPE_CAR";
1362 case UI_MODE_TYPE_TELEVISION:
1363 return "UI_MODE_TYPE_TELEVISION";
1364 case UI_MODE_TYPE_APPLIANCE:
1365 return "UI_MODE_TYPE_APPLIANCE";
1366 case UI_MODE_TYPE_WATCH:
1367 return "UI_MODE_TYPE_WATCH";
1368 case UI_MODE_TYPE_VR_HEADSET:
1369 return "UI_MODE_TYPE_VR_HEADSET";
1370 default:
1371 return Integer.toString(uiMode);
1372 }
1373 }
1374
1375 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 * Set this object to the system defaults.
1377 */
1378 public void setToDefaults() {
1379 fontScale = 1;
1380 mcc = mnc = 0;
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001381 mLocaleList = LocaleList.getEmptyLocaleList();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001382 locale = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 userSetLocale = false;
1384 touchscreen = TOUCHSCREEN_UNDEFINED;
1385 keyboard = KEYBOARD_UNDEFINED;
1386 keyboardHidden = KEYBOARDHIDDEN_UNDEFINED;
1387 hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED;
1388 navigation = NAVIGATION_UNDEFINED;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001389 navigationHidden = NAVIGATIONHIDDEN_UNDEFINED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 orientation = ORIENTATION_UNDEFINED;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001391 screenLayout = SCREENLAYOUT_UNDEFINED;
Romain Guy48327452017-01-23 17:03:35 -08001392 colorMode = COLOR_MODE_UNDEFINED;
Dianne Hackborn7299c412010-03-04 18:41:49 -08001393 uiMode = UI_MODE_TYPE_UNDEFINED;
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001394 screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
1395 screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
1396 smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001397 densityDpi = DENSITY_DPI_UNDEFINED;
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001398 assetsSeq = ASSETS_SEQ_UNDEFINED;
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001399 seq = 0;
Wale Ogunwale822e5122017-07-26 06:02:24 -07001400 windowConfiguration.setToDefaults();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 }
1402
Adam Lesinskibad43fc2016-07-19 13:35:01 -07001403 /**
1404 * Set this object to completely undefined.
1405 * @hide
1406 */
1407 public void unset() {
1408 setToDefaults();
1409 fontScale = 0;
1410 }
1411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001412 /** {@hide} */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001413 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 @Deprecated public void makeDefault() {
1415 setToDefaults();
1416 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -07001417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001418 /**
Alan Viveretteac85f902016-03-11 15:15:51 -05001419 * Copies the fields from delta into this Configuration object, keeping
1420 * track of which ones have changed. Any undefined fields in {@code delta}
1421 * are ignored and not copied in to the current Configuration.
1422 *
1423 * @return a bit mask of the changed fields, as per {@link #diff}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 */
Alan Viveretteac85f902016-03-11 15:15:51 -05001425 public @Config int updateFrom(@NonNull Configuration delta) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 int changed = 0;
1427 if (delta.fontScale > 0 && fontScale != delta.fontScale) {
1428 changed |= ActivityInfo.CONFIG_FONT_SCALE;
1429 fontScale = delta.fontScale;
1430 }
1431 if (delta.mcc != 0 && mcc != delta.mcc) {
1432 changed |= ActivityInfo.CONFIG_MCC;
1433 mcc = delta.mcc;
1434 }
1435 if (delta.mnc != 0 && mnc != delta.mnc) {
1436 changed |= ActivityInfo.CONFIG_MNC;
1437 mnc = delta.mnc;
1438 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001439 fixUpLocaleList();
1440 delta.fixUpLocaleList();
1441 if (!delta.mLocaleList.isEmpty() && !mLocaleList.equals(delta.mLocaleList)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 changed |= ActivityInfo.CONFIG_LOCALE;
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001443 mLocaleList = delta.mLocaleList;
1444 // delta.locale can't be null, since delta.mLocaleList is not empty.
1445 if (!delta.locale.equals(locale)) {
1446 locale = (Locale) delta.locale.clone();
1447 // If locale has changed, then layout direction is also changed ...
1448 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
1449 // ... and we need to update the layout direction (represented by the first
1450 // 2 most significant bits in screenLayout).
1451 setLayoutDirection(locale);
1452 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 }
Craig Mautner31678b52013-08-12 17:56:34 -07001454 final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;
1455 if (deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED &&
1456 deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {
1457 screenLayout = (screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK) | deltaScreenLayoutDir;
Amith Yamasanid8415f42013-08-07 20:15:10 -07001458 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
Amith Yamasanid8415f42013-08-07 20:15:10 -07001459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001460 if (delta.userSetLocale && (!userSetLocale || ((changed & ActivityInfo.CONFIG_LOCALE) != 0)))
1461 {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001462 changed |= ActivityInfo.CONFIG_LOCALE;
Amith Yamasanid8415f42013-08-07 20:15:10 -07001463 userSetLocale = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 }
1465 if (delta.touchscreen != TOUCHSCREEN_UNDEFINED
1466 && touchscreen != delta.touchscreen) {
1467 changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
1468 touchscreen = delta.touchscreen;
1469 }
1470 if (delta.keyboard != KEYBOARD_UNDEFINED
1471 && keyboard != delta.keyboard) {
1472 changed |= ActivityInfo.CONFIG_KEYBOARD;
1473 keyboard = delta.keyboard;
1474 }
1475 if (delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED
1476 && keyboardHidden != delta.keyboardHidden) {
1477 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1478 keyboardHidden = delta.keyboardHidden;
1479 }
1480 if (delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED
1481 && hardKeyboardHidden != delta.hardKeyboardHidden) {
1482 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1483 hardKeyboardHidden = delta.hardKeyboardHidden;
1484 }
1485 if (delta.navigation != NAVIGATION_UNDEFINED
1486 && navigation != delta.navigation) {
1487 changed |= ActivityInfo.CONFIG_NAVIGATION;
1488 navigation = delta.navigation;
1489 }
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001490 if (delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED
1491 && navigationHidden != delta.navigationHidden) {
1492 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1493 navigationHidden = delta.navigationHidden;
1494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 if (delta.orientation != ORIENTATION_UNDEFINED
1496 && orientation != delta.orientation) {
1497 changed |= ActivityInfo.CONFIG_ORIENTATION;
1498 orientation = delta.orientation;
1499 }
Robert Carrdf259d32016-12-05 20:33:10 -08001500 if (((delta.screenLayout & SCREENLAYOUT_SIZE_MASK) != SCREENLAYOUT_SIZE_UNDEFINED)
1501 && (delta.screenLayout & SCREENLAYOUT_SIZE_MASK)
1502 != (screenLayout & SCREENLAYOUT_SIZE_MASK)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001503 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
Robert Carrdf259d32016-12-05 20:33:10 -08001504 screenLayout = (screenLayout & ~SCREENLAYOUT_SIZE_MASK)
1505 | (delta.screenLayout & SCREENLAYOUT_SIZE_MASK);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001506 }
Robert Carrdf259d32016-12-05 20:33:10 -08001507 if (((delta.screenLayout & SCREENLAYOUT_LONG_MASK) != SCREENLAYOUT_LONG_UNDEFINED)
1508 && (delta.screenLayout & SCREENLAYOUT_LONG_MASK)
1509 != (screenLayout & SCREENLAYOUT_LONG_MASK)) {
1510 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
1511 screenLayout = (screenLayout & ~SCREENLAYOUT_LONG_MASK)
1512 | (delta.screenLayout & SCREENLAYOUT_LONG_MASK);
1513 }
1514 if (((delta.screenLayout & SCREENLAYOUT_ROUND_MASK) != SCREENLAYOUT_ROUND_UNDEFINED)
1515 && (delta.screenLayout & SCREENLAYOUT_ROUND_MASK)
1516 != (screenLayout & SCREENLAYOUT_ROUND_MASK)) {
1517 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
1518 screenLayout = (screenLayout & ~SCREENLAYOUT_ROUND_MASK)
1519 | (delta.screenLayout & SCREENLAYOUT_ROUND_MASK);
1520 }
1521 if ((delta.screenLayout & SCREENLAYOUT_COMPAT_NEEDED)
1522 != (screenLayout & SCREENLAYOUT_COMPAT_NEEDED)
1523 && delta.screenLayout != 0) {
1524 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
1525 screenLayout = (screenLayout & ~SCREENLAYOUT_COMPAT_NEEDED)
1526 | (delta.screenLayout & SCREENLAYOUT_COMPAT_NEEDED);
1527 }
1528
Romain Guy48327452017-01-23 17:03:35 -08001529 if (((delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) !=
1530 COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED)
1531 && (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)
1532 != (colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) {
1533 changed |= ActivityInfo.CONFIG_COLOR_MODE;
1534 colorMode = (colorMode & ~COLOR_MODE_WIDE_COLOR_GAMUT_MASK)
1535 | (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK);
Romain Guyc9ba5592017-01-18 16:34:42 -08001536 }
1537
Romain Guy48327452017-01-23 17:03:35 -08001538 if (((delta.colorMode & COLOR_MODE_HDR_MASK) != COLOR_MODE_HDR_UNDEFINED)
1539 && (delta.colorMode & COLOR_MODE_HDR_MASK)
1540 != (colorMode & COLOR_MODE_HDR_MASK)) {
1541 changed |= ActivityInfo.CONFIG_COLOR_MODE;
1542 colorMode = (colorMode & ~COLOR_MODE_HDR_MASK)
1543 | (delta.colorMode & COLOR_MODE_HDR_MASK);
Romain Guyc9ba5592017-01-18 16:34:42 -08001544 }
1545
Dianne Hackborn7299c412010-03-04 18:41:49 -08001546 if (delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED)
Tobias Haamel27b28b32010-02-09 23:09:17 +01001547 && uiMode != delta.uiMode) {
1548 changed |= ActivityInfo.CONFIG_UI_MODE;
Dianne Hackborn7299c412010-03-04 18:41:49 -08001549 if ((delta.uiMode&UI_MODE_TYPE_MASK) != UI_MODE_TYPE_UNDEFINED) {
1550 uiMode = (uiMode&~UI_MODE_TYPE_MASK)
1551 | (delta.uiMode&UI_MODE_TYPE_MASK);
1552 }
1553 if ((delta.uiMode&UI_MODE_NIGHT_MASK) != UI_MODE_NIGHT_UNDEFINED) {
1554 uiMode = (uiMode&~UI_MODE_NIGHT_MASK)
1555 | (delta.uiMode&UI_MODE_NIGHT_MASK);
1556 }
Tobias Haamel27b28b32010-02-09 23:09:17 +01001557 }
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001558 if (delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED
1559 && screenWidthDp != delta.screenWidthDp) {
1560 changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
1561 screenWidthDp = delta.screenWidthDp;
1562 }
1563 if (delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED
1564 && screenHeightDp != delta.screenHeightDp) {
1565 changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
1566 screenHeightDp = delta.screenHeightDp;
1567 }
Danny Baumanne7123a62013-05-15 10:21:40 +02001568 if (delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED
1569 && smallestScreenWidthDp != delta.smallestScreenWidthDp) {
1570 changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001571 smallestScreenWidthDp = delta.smallestScreenWidthDp;
1572 }
Danny Baumanne7123a62013-05-15 10:21:40 +02001573 if (delta.densityDpi != DENSITY_DPI_UNDEFINED &&
1574 densityDpi != delta.densityDpi) {
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001575 changed |= ActivityInfo.CONFIG_DENSITY;
1576 densityDpi = delta.densityDpi;
1577 }
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001578 if (delta.compatScreenWidthDp != SCREEN_WIDTH_DP_UNDEFINED) {
1579 compatScreenWidthDp = delta.compatScreenWidthDp;
1580 }
1581 if (delta.compatScreenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED) {
1582 compatScreenHeightDp = delta.compatScreenHeightDp;
1583 }
1584 if (delta.compatSmallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
1585 compatSmallestScreenWidthDp = delta.compatSmallestScreenWidthDp;
1586 }
Adam Lesinski4eb41292017-07-06 12:06:13 -07001587 if (delta.assetsSeq != ASSETS_SEQ_UNDEFINED && delta.assetsSeq != assetsSeq) {
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001588 changed |= ActivityInfo.CONFIG_ASSETS_PATHS;
1589 assetsSeq = delta.assetsSeq;
1590 }
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001591 if (delta.seq != 0) {
1592 seq = delta.seq;
1593 }
Wale Ogunwale822e5122017-07-26 06:02:24 -07001594 if (windowConfiguration.updateFrom(delta.windowConfiguration) != 0) {
1595 changed |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
1596 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -07001597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 return changed;
1599 }
1600
1601 /**
Evan Roskyddedfd42019-10-04 13:38:38 -07001602 * Copies the fields specified by mask from delta into this Configuration object. This will
1603 * copy anything allowed by the mask (including undefined values).
1604 * @hide
1605 */
1606 public void setTo(@NonNull Configuration delta, @Config int mask,
1607 @WindowConfiguration.WindowConfig int windowMask) {
1608 if ((mask & ActivityInfo.CONFIG_FONT_SCALE) != 0) {
1609 fontScale = delta.fontScale;
1610 }
1611 if ((mask & ActivityInfo.CONFIG_MCC) != 0) {
1612 mcc = delta.mcc;
1613 }
1614 if ((mask & ActivityInfo.CONFIG_MNC) != 0) {
1615 mnc = delta.mnc;
1616 }
1617 if ((mask & ActivityInfo.CONFIG_LOCALE) != 0) {
1618 mLocaleList = delta.mLocaleList;
1619 if (!mLocaleList.isEmpty()) {
1620 locale = (Locale) delta.locale.clone();
1621 }
1622 }
1623 if ((mask & ActivityInfo.CONFIG_LAYOUT_DIRECTION) != 0) {
1624 final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;
1625 screenLayout = (screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK) | deltaScreenLayoutDir;
1626 }
1627 if ((mask & ActivityInfo.CONFIG_LOCALE) != 0) {
1628 userSetLocale = delta.userSetLocale;
1629 }
1630 if ((mask & ActivityInfo.CONFIG_TOUCHSCREEN) != 0) {
1631 touchscreen = delta.touchscreen;
1632 }
1633 if ((mask & ActivityInfo.CONFIG_KEYBOARD) != 0) {
1634 keyboard = delta.keyboard;
1635 }
1636 if ((mask & ActivityInfo.CONFIG_KEYBOARD_HIDDEN) != 0) {
1637 keyboardHidden = delta.keyboardHidden;
1638 hardKeyboardHidden = delta.hardKeyboardHidden;
1639 navigationHidden = delta.navigationHidden;
1640 }
1641 if ((mask & ActivityInfo.CONFIG_NAVIGATION) != 0) {
1642 navigation = delta.navigation;
1643 }
1644 if ((mask & ActivityInfo.CONFIG_ORIENTATION) != 0) {
1645 orientation = delta.orientation;
1646 }
1647 if ((mask & ActivityInfo.CONFIG_SCREEN_LAYOUT) != 0) {
1648 // Not enough granularity for each component unfortunately.
1649 screenLayout = screenLayout | (delta.screenLayout & ~SCREENLAYOUT_LAYOUTDIR_MASK);
1650 }
1651 if ((mask & ActivityInfo.CONFIG_COLOR_MODE) != 0) {
1652 colorMode = delta.colorMode;
1653 }
1654 if ((mask & ActivityInfo.CONFIG_UI_MODE) != 0) {
1655 uiMode = delta.uiMode;
1656 }
1657 if ((mask & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) {
1658 screenWidthDp = delta.screenWidthDp;
1659 screenHeightDp = delta.screenHeightDp;
1660 }
1661 if ((mask & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
1662 smallestScreenWidthDp = delta.smallestScreenWidthDp;
1663 }
1664 if ((mask & ActivityInfo.CONFIG_DENSITY) != 0) {
1665 densityDpi = delta.densityDpi;
1666 }
1667 if ((mask & ActivityInfo.CONFIG_ASSETS_PATHS) != 0) {
1668 assetsSeq = delta.assetsSeq;
1669 }
1670 if ((mask & ActivityInfo.CONFIG_WINDOW_CONFIGURATION) != 0) {
1671 windowConfiguration.setTo(delta.windowConfiguration, windowMask);
1672 }
1673 }
1674
1675 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001676 * Return a bit mask of the differences between this Configuration
1677 * object and the given one. Does not change the values of either. Any
1678 * undefined fields in <var>delta</var> are ignored.
1679 * @return Returns a bit mask indicating which configuration
1680 * values has changed, containing any combination of
1681 * {@link android.content.pm.ActivityInfo#CONFIG_FONT_SCALE
1682 * PackageManager.ActivityInfo.CONFIG_FONT_SCALE},
1683 * {@link android.content.pm.ActivityInfo#CONFIG_MCC
1684 * PackageManager.ActivityInfo.CONFIG_MCC},
1685 * {@link android.content.pm.ActivityInfo#CONFIG_MNC
1686 * PackageManager.ActivityInfo.CONFIG_MNC},
1687 * {@link android.content.pm.ActivityInfo#CONFIG_LOCALE
1688 * PackageManager.ActivityInfo.CONFIG_LOCALE},
1689 * {@link android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN
1690 * PackageManager.ActivityInfo.CONFIG_TOUCHSCREEN},
1691 * {@link android.content.pm.ActivityInfo#CONFIG_KEYBOARD
1692 * PackageManager.ActivityInfo.CONFIG_KEYBOARD},
1693 * {@link android.content.pm.ActivityInfo#CONFIG_NAVIGATION
Dianne Hackborn723738c2009-06-25 19:48:04 -07001694 * PackageManager.ActivityInfo.CONFIG_NAVIGATION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 * {@link android.content.pm.ActivityInfo#CONFIG_ORIENTATION
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001696 * PackageManager.ActivityInfo.CONFIG_ORIENTATION},
Dianne Hackborn723738c2009-06-25 19:48:04 -07001697 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001698 * PackageManager.ActivityInfo.CONFIG_SCREEN_LAYOUT}, or
1699 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001700 * PackageManager.ActivityInfo.CONFIG_SCREEN_SIZE}, or
1701 * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE
1702 * PackageManager.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE}.
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001703 * {@link android.content.pm.ActivityInfo#CONFIG_LAYOUT_DIRECTION
1704 * PackageManager.ActivityInfo.CONFIG_LAYOUT_DIRECTION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 */
1706 public int diff(Configuration delta) {
Bryce Lee658d9842017-07-28 08:33:36 -07001707 return diff(delta, false /* compareUndefined */, false /* publicOnly */);
1708 }
1709
1710 /**
1711 * Returns the diff against the provided {@link Configuration} excluding values that would
1712 * publicly be equivalent, such as appBounds.
1713 * @param delta {@link Configuration} to compare to.
1714 *
1715 * TODO(b/36812336): Remove once appBounds has been moved out of Configuration.
1716 * {@hide}
1717 */
1718 public int diffPublicOnly(Configuration delta) {
1719 return diff(delta, false /* compareUndefined */, true /* publicOnly */);
Andrii Kulianb10330d2016-09-16 13:51:46 -07001720 }
1721
1722 /**
1723 * Variation of {@link #diff(Configuration)} with an option to skip checks for undefined values.
1724 *
1725 * @hide
1726 */
Bryce Lee658d9842017-07-28 08:33:36 -07001727 public int diff(Configuration delta, boolean compareUndefined, boolean publicOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 int changed = 0;
Andrii Kulianb10330d2016-09-16 13:51:46 -07001729 if ((compareUndefined || delta.fontScale > 0) && fontScale != delta.fontScale) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 changed |= ActivityInfo.CONFIG_FONT_SCALE;
1731 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001732 if ((compareUndefined || delta.mcc != 0) && mcc != delta.mcc) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001733 changed |= ActivityInfo.CONFIG_MCC;
1734 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001735 if ((compareUndefined || delta.mnc != 0) && mnc != delta.mnc) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 changed |= ActivityInfo.CONFIG_MNC;
1737 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001738 fixUpLocaleList();
1739 delta.fixUpLocaleList();
Andrii Kulianb10330d2016-09-16 13:51:46 -07001740 if ((compareUndefined || !delta.mLocaleList.isEmpty())
1741 && !mLocaleList.equals(delta.mLocaleList)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001742 changed |= ActivityInfo.CONFIG_LOCALE;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001743 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001744 }
Craig Mautner31678b52013-08-12 17:56:34 -07001745 final int deltaScreenLayoutDir = delta.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;
Andrii Kulianb10330d2016-09-16 13:51:46 -07001746 if ((compareUndefined || deltaScreenLayoutDir != SCREENLAYOUT_LAYOUTDIR_UNDEFINED)
1747 && deltaScreenLayoutDir != (screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {
Amith Yamasanid8415f42013-08-07 20:15:10 -07001748 changed |= ActivityInfo.CONFIG_LAYOUT_DIRECTION;
1749 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001750 if ((compareUndefined || delta.touchscreen != TOUCHSCREEN_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001751 && touchscreen != delta.touchscreen) {
1752 changed |= ActivityInfo.CONFIG_TOUCHSCREEN;
1753 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001754 if ((compareUndefined || delta.keyboard != KEYBOARD_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001755 && keyboard != delta.keyboard) {
1756 changed |= ActivityInfo.CONFIG_KEYBOARD;
1757 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001758 if ((compareUndefined || delta.keyboardHidden != KEYBOARDHIDDEN_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001759 && keyboardHidden != delta.keyboardHidden) {
1760 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1761 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001762 if ((compareUndefined || delta.hardKeyboardHidden != HARDKEYBOARDHIDDEN_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001763 && hardKeyboardHidden != delta.hardKeyboardHidden) {
1764 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1765 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001766 if ((compareUndefined || delta.navigation != NAVIGATION_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001767 && navigation != delta.navigation) {
1768 changed |= ActivityInfo.CONFIG_NAVIGATION;
1769 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001770 if ((compareUndefined || delta.navigationHidden != NAVIGATIONHIDDEN_UNDEFINED)
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001771 && navigationHidden != delta.navigationHidden) {
1772 changed |= ActivityInfo.CONFIG_KEYBOARD_HIDDEN;
1773 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001774 if ((compareUndefined || delta.orientation != ORIENTATION_UNDEFINED)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 && orientation != delta.orientation) {
1776 changed |= ActivityInfo.CONFIG_ORIENTATION;
1777 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001778 if ((compareUndefined || getScreenLayoutNoDirection(delta.screenLayout) !=
1779 (SCREENLAYOUT_SIZE_UNDEFINED | SCREENLAYOUT_LONG_UNDEFINED))
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001780 && getScreenLayoutNoDirection(screenLayout) !=
Andrii Kulianb10330d2016-09-16 13:51:46 -07001781 getScreenLayoutNoDirection(delta.screenLayout)) {
Dianne Hackborn723738c2009-06-25 19:48:04 -07001782 changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
1783 }
Romain Guyc9ba5592017-01-18 16:34:42 -08001784 if ((compareUndefined ||
Romain Guy48327452017-01-23 17:03:35 -08001785 (delta.colorMode & COLOR_MODE_HDR_MASK) != COLOR_MODE_HDR_UNDEFINED)
1786 && (colorMode & COLOR_MODE_HDR_MASK) !=
1787 (delta.colorMode & COLOR_MODE_HDR_MASK)) {
1788 changed |= ActivityInfo.CONFIG_COLOR_MODE;
Romain Guyc9ba5592017-01-18 16:34:42 -08001789 }
1790 if ((compareUndefined ||
Romain Guy48327452017-01-23 17:03:35 -08001791 (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) !=
1792 COLOR_MODE_WIDE_COLOR_GAMUT_UNDEFINED)
1793 && (colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) !=
1794 (delta.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) {
1795 changed |= ActivityInfo.CONFIG_COLOR_MODE;
Romain Guyc9ba5592017-01-18 16:34:42 -08001796 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001797 if ((compareUndefined || delta.uiMode != (UI_MODE_TYPE_UNDEFINED|UI_MODE_NIGHT_UNDEFINED))
Tobias Haamel27b28b32010-02-09 23:09:17 +01001798 && uiMode != delta.uiMode) {
1799 changed |= ActivityInfo.CONFIG_UI_MODE;
1800 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001801 if ((compareUndefined || delta.screenWidthDp != SCREEN_WIDTH_DP_UNDEFINED)
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001802 && screenWidthDp != delta.screenWidthDp) {
1803 changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
1804 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001805 if ((compareUndefined || delta.screenHeightDp != SCREEN_HEIGHT_DP_UNDEFINED)
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001806 && screenHeightDp != delta.screenHeightDp) {
1807 changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
1808 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001809 if ((compareUndefined || delta.smallestScreenWidthDp != SMALLEST_SCREEN_WIDTH_DP_UNDEFINED)
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001810 && smallestScreenWidthDp != delta.smallestScreenWidthDp) {
1811 changed |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
1812 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001813 if ((compareUndefined || delta.densityDpi != DENSITY_DPI_UNDEFINED)
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001814 && densityDpi != delta.densityDpi) {
1815 changed |= ActivityInfo.CONFIG_DENSITY;
1816 }
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001817 if ((compareUndefined || delta.assetsSeq != ASSETS_SEQ_UNDEFINED)
1818 && assetsSeq != delta.assetsSeq) {
1819 changed |= ActivityInfo.CONFIG_ASSETS_PATHS;
1820 }
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07001821
Wale Ogunwale822e5122017-07-26 06:02:24 -07001822 // WindowConfiguration differences aren't considered public...
1823 if (!publicOnly
1824 && windowConfiguration.diff(delta.windowConfiguration, compareUndefined) != 0) {
1825 changed |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
Bryce Lee7566d762017-03-30 09:34:15 -07001826 }
1827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001828 return changed;
1829 }
1830
1831 /**
Alan Viveretteac85f902016-03-11 15:15:51 -05001832 * Determines if a new resource needs to be loaded from the bit set of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 * configuration changes returned by {@link #updateFrom(Configuration)}.
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -07001834 *
Alan Viveretteac85f902016-03-11 15:15:51 -05001835 * @param configChanges the mask of changes configurations as returned by
1836 * {@link #updateFrom(Configuration)}
1837 * @param interestingChanges the configuration changes that the resource
1838 * can handle as given in
1839 * {@link android.util.TypedValue#changingConfigurations}
1840 * @return {@code true} if the resource needs to be loaded, {@code false}
1841 * otherwise
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001842 */
Alan Viveretteac85f902016-03-11 15:15:51 -05001843 public static boolean needNewResources(@Config int configChanges,
1844 @Config int interestingChanges) {
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001845 // CONFIG_ASSETS_PATHS and CONFIG_FONT_SCALE are higher level configuration changes that
1846 // all resources are subject to change with.
1847 interestingChanges = interestingChanges | ActivityInfo.CONFIG_ASSETS_PATHS
1848 | ActivityInfo.CONFIG_FONT_SCALE;
1849 return (configChanges & interestingChanges) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001850 }
Amith Yamasanid8415f42013-08-07 20:15:10 -07001851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 /**
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001853 * @hide Return true if the sequence of 'other' is better than this. Assumes
1854 * that 'this' is your current sequence and 'other' is a new one you have
1855 * received some how and want to compare with what you have.
1856 */
1857 public boolean isOtherSeqNewer(Configuration other) {
1858 if (other == null) {
1859 // Sanity check.
1860 return false;
1861 }
1862 if (other.seq == 0) {
1863 // If the other sequence is not specified, then we must assume
1864 // it is newer since we don't know any better.
1865 return true;
1866 }
1867 if (seq == 0) {
1868 // If this sequence is not specified, then we also consider the
1869 // other is better. Yes we have a preference for other. Sue us.
1870 return true;
1871 }
1872 int diff = other.seq - seq;
1873 if (diff > 0x10000) {
1874 // If there has been a sufficiently large jump, assume the
1875 // sequence has wrapped around.
1876 return false;
1877 }
1878 return diff > 0;
1879 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -07001880
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001881 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882 * Parcelable methods
1883 */
1884 public int describeContents() {
1885 return 0;
1886 }
1887
1888 public void writeToParcel(Parcel dest, int flags) {
1889 dest.writeFloat(fontScale);
1890 dest.writeInt(mcc);
1891 dest.writeInt(mnc);
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001892
1893 fixUpLocaleList();
Siyamed Sinir27ddd8a2018-02-27 13:07:22 -08001894 dest.writeParcelable(mLocaleList, flags);
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001895
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896 if(userSetLocale) {
1897 dest.writeInt(1);
1898 } else {
1899 dest.writeInt(0);
1900 }
1901 dest.writeInt(touchscreen);
1902 dest.writeInt(keyboard);
1903 dest.writeInt(keyboardHidden);
1904 dest.writeInt(hardKeyboardHidden);
1905 dest.writeInt(navigation);
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001906 dest.writeInt(navigationHidden);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001907 dest.writeInt(orientation);
Dianne Hackborn723738c2009-06-25 19:48:04 -07001908 dest.writeInt(screenLayout);
Romain Guy48327452017-01-23 17:03:35 -08001909 dest.writeInt(colorMode);
Tobias Haamel27b28b32010-02-09 23:09:17 +01001910 dest.writeInt(uiMode);
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001911 dest.writeInt(screenWidthDp);
1912 dest.writeInt(screenHeightDp);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001913 dest.writeInt(smallestScreenWidthDp);
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001914 dest.writeInt(densityDpi);
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001915 dest.writeInt(compatScreenWidthDp);
1916 dest.writeInt(compatScreenHeightDp);
1917 dest.writeInt(compatSmallestScreenWidthDp);
Wale Ogunwale822e5122017-07-26 06:02:24 -07001918 dest.writeValue(windowConfiguration);
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001919 dest.writeInt(assetsSeq);
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001920 dest.writeInt(seq);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 }
1922
Dianne Hackborn694f79b2010-03-17 19:44:59 -07001923 public void readFromParcel(Parcel source) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 fontScale = source.readFloat();
1925 mcc = source.readInt();
1926 mnc = source.readInt();
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001927
Siyamed Sinir27ddd8a2018-02-27 13:07:22 -08001928 mLocaleList = source.readParcelable(LocaleList.class.getClassLoader());
Roozbeh Pournaderfee44842016-02-04 15:24:24 -08001929 locale = mLocaleList.get(0);
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001931 userSetLocale = (source.readInt()==1);
1932 touchscreen = source.readInt();
1933 keyboard = source.readInt();
1934 keyboardHidden = source.readInt();
1935 hardKeyboardHidden = source.readInt();
1936 navigation = source.readInt();
Dianne Hackborn93e462b2009-09-15 22:50:40 -07001937 navigationHidden = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 orientation = source.readInt();
Dianne Hackborn723738c2009-06-25 19:48:04 -07001939 screenLayout = source.readInt();
Romain Guy48327452017-01-23 17:03:35 -08001940 colorMode = source.readInt();
Tobias Haamel27b28b32010-02-09 23:09:17 +01001941 uiMode = source.readInt();
Dianne Hackbornebff8f92011-05-12 18:07:47 -07001942 screenWidthDp = source.readInt();
1943 screenHeightDp = source.readInt();
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001944 smallestScreenWidthDp = source.readInt();
Dianne Hackborn908aecc2012-07-31 16:37:34 -07001945 densityDpi = source.readInt();
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001946 compatScreenWidthDp = source.readInt();
1947 compatScreenHeightDp = source.readInt();
1948 compatSmallestScreenWidthDp = source.readInt();
Wale Ogunwale822e5122017-07-26 06:02:24 -07001949 windowConfiguration.setTo((WindowConfiguration) source.readValue(null));
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01001950 assetsSeq = source.readInt();
Dianne Hackborne36d6e22010-02-17 19:46:25 -08001951 seq = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 }
Filip Gruszczynskibc5a6c52015-09-22 13:13:24 -07001953
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001954 public static final @android.annotation.NonNull Parcelable.Creator<Configuration> CREATOR
Dianne Hackborn694f79b2010-03-17 19:44:59 -07001955 = new Parcelable.Creator<Configuration>() {
1956 public Configuration createFromParcel(Parcel source) {
1957 return new Configuration(source);
1958 }
1959
1960 public Configuration[] newArray(int size) {
1961 return new Configuration[size];
1962 }
1963 };
1964
1965 /**
1966 * Construct this Configuration object, reading from the Parcel.
1967 */
1968 private Configuration(Parcel source) {
1969 readFromParcel(source);
1970 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971
1972 public int compareTo(Configuration that) {
1973 int n;
1974 float a = this.fontScale;
1975 float b = that.fontScale;
1976 if (a < b) return -1;
1977 if (a > b) return 1;
1978 n = this.mcc - that.mcc;
1979 if (n != 0) return n;
1980 n = this.mnc - that.mnc;
1981 if (n != 0) return n;
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001982
1983 fixUpLocaleList();
1984 that.fixUpLocaleList();
1985 // for backward compatibility, we consider an empty locale list to be greater
1986 // than any non-empty locale list.
1987 if (this.mLocaleList.isEmpty()) {
1988 if (!that.mLocaleList.isEmpty()) return 1;
1989 } else if (that.mLocaleList.isEmpty()) {
Dianne Hackborna8397032010-03-12 10:52:22 -08001990 return -1;
1991 } else {
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07001992 final int minSize = Math.min(this.mLocaleList.size(), that.mLocaleList.size());
1993 for (int i = 0; i < minSize; ++i) {
1994 final Locale thisLocale = this.mLocaleList.get(i);
1995 final Locale thatLocale = that.mLocaleList.get(i);
1996 n = thisLocale.getLanguage().compareTo(thatLocale.getLanguage());
1997 if (n != 0) return n;
1998 n = thisLocale.getCountry().compareTo(thatLocale.getCountry());
1999 if (n != 0) return n;
2000 n = thisLocale.getVariant().compareTo(thatLocale.getVariant());
2001 if (n != 0) return n;
2002 n = thisLocale.toLanguageTag().compareTo(thatLocale.toLanguageTag());
2003 if (n != 0) return n;
2004 }
2005 n = this.mLocaleList.size() - that.mLocaleList.size();
Dianne Hackborna8397032010-03-12 10:52:22 -08002006 if (n != 0) return n;
2007 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 n = this.touchscreen - that.touchscreen;
2010 if (n != 0) return n;
2011 n = this.keyboard - that.keyboard;
2012 if (n != 0) return n;
2013 n = this.keyboardHidden - that.keyboardHidden;
2014 if (n != 0) return n;
2015 n = this.hardKeyboardHidden - that.hardKeyboardHidden;
2016 if (n != 0) return n;
2017 n = this.navigation - that.navigation;
2018 if (n != 0) return n;
Dianne Hackborn93e462b2009-09-15 22:50:40 -07002019 n = this.navigationHidden - that.navigationHidden;
2020 if (n != 0) return n;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002021 n = this.orientation - that.orientation;
Dianne Hackborn723738c2009-06-25 19:48:04 -07002022 if (n != 0) return n;
Romain Guy48327452017-01-23 17:03:35 -08002023 n = this.colorMode - that.colorMode;
Romain Guyc9ba5592017-01-18 16:34:42 -08002024 if (n != 0) return n;
Dianne Hackborn723738c2009-06-25 19:48:04 -07002025 n = this.screenLayout - that.screenLayout;
Tobias Haamel27b28b32010-02-09 23:09:17 +01002026 if (n != 0) return n;
2027 n = this.uiMode - that.uiMode;
Dianne Hackbornebff8f92011-05-12 18:07:47 -07002028 if (n != 0) return n;
2029 n = this.screenWidthDp - that.screenWidthDp;
2030 if (n != 0) return n;
2031 n = this.screenHeightDp - that.screenHeightDp;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002032 if (n != 0) return n;
2033 n = this.smallestScreenWidthDp - that.smallestScreenWidthDp;
Dianne Hackborn908aecc2012-07-31 16:37:34 -07002034 if (n != 0) return n;
2035 n = this.densityDpi - that.densityDpi;
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01002036 if (n != 0) return n;
2037 n = this.assetsSeq - that.assetsSeq;
Bryce Leec5fe0ee2017-06-30 09:03:09 -07002038 if (n != 0) return n;
Wale Ogunwale822e5122017-07-26 06:02:24 -07002039 n = windowConfiguration.compareTo(that.windowConfiguration);
2040 if (n != 0) return n;
Bryce Leec5fe0ee2017-06-30 09:03:09 -07002041
2042 // if (n != 0) return n;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 return n;
2044 }
2045
2046 public boolean equals(Configuration that) {
2047 if (that == null) return false;
2048 if (that == this) return true;
2049 return this.compareTo(that) == 0;
2050 }
2051
2052 public boolean equals(Object that) {
2053 try {
2054 return equals((Configuration)that);
2055 } catch (ClassCastException e) {
2056 }
2057 return false;
2058 }
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 public int hashCode() {
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002061 int result = 17;
2062 result = 31 * result + Float.floatToIntBits(fontScale);
2063 result = 31 * result + mcc;
2064 result = 31 * result + mnc;
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002065 result = 31 * result + mLocaleList.hashCode();
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002066 result = 31 * result + touchscreen;
2067 result = 31 * result + keyboard;
2068 result = 31 * result + keyboardHidden;
2069 result = 31 * result + hardKeyboardHidden;
2070 result = 31 * result + navigation;
2071 result = 31 * result + navigationHidden;
2072 result = 31 * result + orientation;
2073 result = 31 * result + screenLayout;
Romain Guy48327452017-01-23 17:03:35 -08002074 result = 31 * result + colorMode;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002075 result = 31 * result + uiMode;
Dianne Hackbornebff8f92011-05-12 18:07:47 -07002076 result = 31 * result + screenWidthDp;
2077 result = 31 * result + screenHeightDp;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002078 result = 31 * result + smallestScreenWidthDp;
Dianne Hackborn908aecc2012-07-31 16:37:34 -07002079 result = 31 * result + densityDpi;
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01002080 result = 31 * result + assetsSeq;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002081 return result;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002082 }
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002083
2084 /**
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002085 * Get the locale list. This is the preferred way for getting the locales (instead of using
2086 * the direct accessor to {@link #locale}, which would only provide the primary locale).
2087 *
2088 * @return The locale list.
2089 */
Adam Lesinskib61e4052016-05-19 18:23:05 -07002090 public @NonNull LocaleList getLocales() {
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002091 fixUpLocaleList();
2092 return mLocaleList;
2093 }
2094
2095 /**
2096 * Set the locale list. This is the preferred way for setting up the locales (instead of using
2097 * the direct accessor or {@link #setLocale(Locale)}). This will also set the layout direction
2098 * according to the first locale in the list.
2099 *
2100 * Note that the layout direction will always come from the first locale in the locale list,
2101 * even if the locale is not supported by the resources (the resources may only support
2102 * another locale further down the list which has a different direction).
2103 *
2104 * @param locales The locale list. If null, an empty LocaleList will be assigned.
2105 */
2106 public void setLocales(@Nullable LocaleList locales) {
2107 mLocaleList = locales == null ? LocaleList.getEmptyLocaleList() : locales;
Roozbeh Pournaderfee44842016-02-04 15:24:24 -08002108 locale = mLocaleList.get(0);
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002109 setLayoutDirection(locale);
2110 }
2111
2112 /**
2113 * Set the locale list to a list of just one locale. This will also set the layout direction
2114 * according to the locale.
2115 *
2116 * Note that after this is run, calling <code>.equals()</code> on the input locale and the
2117 * {@link #locale} attribute would return <code>true</code> if they are not null, but there is
2118 * no guarantee that they would be the same object.
2119 *
2120 * See also the note about layout direction in {@link #setLocales(LocaleList)}.
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002121 *
2122 * @param loc The locale. Can be null.
2123 */
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002124 public void setLocale(@Nullable Locale loc) {
Raph Levien10ea92a2016-05-02 12:56:01 -07002125 setLocales(loc == null ? LocaleList.getEmptyLocaleList() : new LocaleList(loc));
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002126 }
2127
2128 /**
Seigo Nonakabd5cac62016-05-13 15:11:37 +09002129 * @hide
2130 *
2131 * Clears the locale without changing layout direction.
2132 */
2133 public void clearLocales() {
2134 mLocaleList = LocaleList.getEmptyLocaleList();
2135 locale = null;
2136 }
2137
2138 /**
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002139 * Return the layout direction. Will be either {@link View#LAYOUT_DIRECTION_LTR} or
2140 * {@link View#LAYOUT_DIRECTION_RTL}.
2141 *
Dianne Hackbornf1ae2692013-04-19 14:09:37 -07002142 * @return Returns {@link View#LAYOUT_DIRECTION_RTL} if the configuration
2143 * is {@link #SCREENLAYOUT_LAYOUTDIR_RTL}, otherwise {@link View#LAYOUT_DIRECTION_LTR}.
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002144 */
2145 public int getLayoutDirection() {
Dianne Hackbornf1ae2692013-04-19 14:09:37 -07002146 return (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK) == SCREENLAYOUT_LAYOUTDIR_RTL
2147 ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002148 }
2149
2150 /**
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002151 * Set the layout direction from a Locale.
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002152 *
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002153 * @param loc The Locale. If null will set the layout direction to
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002154 * {@link View#LAYOUT_DIRECTION_LTR}. If not null will set it to the layout direction
2155 * corresponding to the Locale.
2156 *
John Spurlockbc4cf002015-03-24 21:51:20 -04002157 * @see View#LAYOUT_DIRECTION_LTR
2158 * @see View#LAYOUT_DIRECTION_RTL
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002159 */
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002160 public void setLayoutDirection(Locale loc) {
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002161 // There is a "1" difference between the configuration values for
2162 // layout direction and View constants for layout direction, just add "1".
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002163 final int layoutDirection = 1 + TextUtils.getLayoutDirectionFromLocale(loc);
Fabrice Di Meglio5f797992012-06-15 20:16:41 -07002164 screenLayout = (screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK)|
2165 (layoutDirection << SCREENLAYOUT_LAYOUTDIR_SHIFT);
2166 }
2167
2168 private static int getScreenLayoutNoDirection(int screenLayout) {
2169 return screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK;
2170 }
Adam Lesinski2c749d22014-06-04 13:00:29 -07002171
2172 /**
Adam Powell49e7ff92015-05-14 16:18:53 -07002173 * Return whether the screen has a round shape. Apps may choose to change styling based
2174 * on this property, such as the alignment or layout of text or informational icons.
2175 *
2176 * @return true if the screen is rounded, false otherwise
2177 */
2178 public boolean isScreenRound() {
2179 return (screenLayout & SCREENLAYOUT_ROUND_MASK) == SCREENLAYOUT_ROUND_YES;
2180 }
2181
2182 /**
Romain Guye89d0bb2017-06-20 12:23:42 -07002183 * Return whether the screen has a wide color gamut and wide color gamut rendering
2184 * is supported by this device.
Romain Guyc9ba5592017-01-18 16:34:42 -08002185 *
Chia-I Wu53e86ba2018-05-02 10:13:22 -07002186 * When true, it implies the screen is colorspace aware but not
2187 * necessarily color-managed. The final colors may still be changed by the
2188 * screen depending on user settings.
2189 *
Romain Guye89d0bb2017-06-20 12:23:42 -07002190 * @return true if the screen has a wide color gamut and wide color gamut rendering
2191 * is supported, false otherwise
Romain Guyc9ba5592017-01-18 16:34:42 -08002192 */
2193 public boolean isScreenWideColorGamut() {
Romain Guy48327452017-01-23 17:03:35 -08002194 return (colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) == COLOR_MODE_WIDE_COLOR_GAMUT_YES;
Romain Guyc9ba5592017-01-18 16:34:42 -08002195 }
2196
2197 /**
2198 * Return whether the screen has a high dynamic range.
2199 *
2200 * @return true if the screen has a high dynamic range, false otherwise
2201 */
2202 public boolean isScreenHdr() {
Romain Guy48327452017-01-23 17:03:35 -08002203 return (colorMode & COLOR_MODE_HDR_MASK) == COLOR_MODE_HDR_YES;
Romain Guyc9ba5592017-01-18 16:34:42 -08002204 }
2205
2206 /**
Adam Lesinski2c749d22014-06-04 13:00:29 -07002207 *
2208 * @hide
2209 */
Roozbeh Pournader47f71a62015-11-07 11:55:38 -08002210 public static String localesToResourceQualifier(LocaleList locs) {
Roozbeh Pournader309ebd62016-06-17 22:13:12 -07002211 final StringBuilder sb = new StringBuilder();
Roozbeh Pournader47f71a62015-11-07 11:55:38 -08002212 for (int i = 0; i < locs.size(); i++) {
Roozbeh Pournader309ebd62016-06-17 22:13:12 -07002213 final Locale loc = locs.get(i);
2214 final int l = loc.getLanguage().length();
2215 if (l == 0) {
2216 continue;
2217 }
2218 final int s = loc.getScript().length();
2219 final int c = loc.getCountry().length();
2220 final int v = loc.getVariant().length();
2221 // We ignore locale extensions, since they are not supported by AAPT
2222
2223 if (sb.length() != 0) {
2224 sb.append(",");
2225 }
2226 if (l == 2 && s == 0 && (c == 0 || c == 2) && v == 0) {
2227 // Traditional locale format: xx or xx-rYY
Roozbeh Pournader47f71a62015-11-07 11:55:38 -08002228 sb.append(loc.getLanguage());
Roozbeh Pournader309ebd62016-06-17 22:13:12 -07002229 if (c == 2) {
Roozbeh Pournader47f71a62015-11-07 11:55:38 -08002230 sb.append("-r").append(loc.getCountry());
Roozbeh Pournader309ebd62016-06-17 22:13:12 -07002231 }
2232 } else {
2233 sb.append("b+");
2234 sb.append(loc.getLanguage());
2235 if (s != 0) {
2236 sb.append("+");
2237 sb.append(loc.getScript());
2238 }
2239 if (c != 0) {
2240 sb.append("+");
2241 sb.append(loc.getCountry());
2242 }
2243 if (v != 0) {
2244 sb.append("+");
2245 sb.append(loc.getVariant());
Adam Lesinski2c749d22014-06-04 13:00:29 -07002246 }
2247 }
2248 }
2249 return sb.toString();
2250 }
2251
2252
2253 /**
2254 * Returns a string representation of the configuration that can be parsed
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -08002255 * by build tools (like AAPT), without display metrics included
Adam Lesinski2c749d22014-06-04 13:00:29 -07002256 *
Adam Lesinski2c749d22014-06-04 13:00:29 -07002257 * @hide
2258 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002259 @UnsupportedAppUsage
Adam Lesinski2c749d22014-06-04 13:00:29 -07002260 public static String resourceQualifierString(Configuration config) {
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -08002261 return resourceQualifierString(config, null);
2262 }
2263
2264 /**
2265 * Returns a string representation of the configuration that can be parsed
2266 * by build tools (like AAPT).
2267 *
2268 * @hide
2269 */
2270 public static String resourceQualifierString(Configuration config, DisplayMetrics metrics) {
Adam Lesinski2c749d22014-06-04 13:00:29 -07002271 ArrayList<String> parts = new ArrayList<String>();
2272
2273 if (config.mcc != 0) {
Adam Lesinski90865622014-10-16 18:18:10 -07002274 parts.add("mcc" + config.mcc);
Adam Lesinski2c749d22014-06-04 13:00:29 -07002275 if (config.mnc != 0) {
Adam Lesinski90865622014-10-16 18:18:10 -07002276 parts.add("mnc" + config.mnc);
Adam Lesinski2c749d22014-06-04 13:00:29 -07002277 }
2278 }
2279
Roozbeh Pournader47f71a62015-11-07 11:55:38 -08002280 if (!config.mLocaleList.isEmpty()) {
Roozbeh Pournader417bbe02015-11-09 17:09:15 -08002281 final String resourceQualifier = localesToResourceQualifier(config.mLocaleList);
2282 if (!resourceQualifier.isEmpty()) {
2283 parts.add(resourceQualifier);
2284 }
Adam Lesinski2c749d22014-06-04 13:00:29 -07002285 }
2286
2287 switch (config.screenLayout & Configuration.SCREENLAYOUT_LAYOUTDIR_MASK) {
2288 case Configuration.SCREENLAYOUT_LAYOUTDIR_LTR:
2289 parts.add("ldltr");
2290 break;
2291 case Configuration.SCREENLAYOUT_LAYOUTDIR_RTL:
2292 parts.add("ldrtl");
2293 break;
2294 default:
2295 break;
2296 }
2297
2298 if (config.smallestScreenWidthDp != 0) {
2299 parts.add("sw" + config.smallestScreenWidthDp + "dp");
2300 }
2301
2302 if (config.screenWidthDp != 0) {
2303 parts.add("w" + config.screenWidthDp + "dp");
2304 }
2305
2306 if (config.screenHeightDp != 0) {
2307 parts.add("h" + config.screenHeightDp + "dp");
2308 }
2309
2310 switch (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) {
2311 case Configuration.SCREENLAYOUT_SIZE_SMALL:
2312 parts.add("small");
2313 break;
2314 case Configuration.SCREENLAYOUT_SIZE_NORMAL:
2315 parts.add("normal");
2316 break;
2317 case Configuration.SCREENLAYOUT_SIZE_LARGE:
2318 parts.add("large");
2319 break;
2320 case Configuration.SCREENLAYOUT_SIZE_XLARGE:
2321 parts.add("xlarge");
2322 break;
2323 default:
2324 break;
2325 }
2326
2327 switch (config.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) {
2328 case Configuration.SCREENLAYOUT_LONG_YES:
2329 parts.add("long");
2330 break;
2331 case Configuration.SCREENLAYOUT_LONG_NO:
2332 parts.add("notlong");
2333 break;
2334 default:
2335 break;
2336 }
2337
Adam Powell49e7ff92015-05-14 16:18:53 -07002338 switch (config.screenLayout & Configuration.SCREENLAYOUT_ROUND_MASK) {
2339 case Configuration.SCREENLAYOUT_ROUND_YES:
2340 parts.add("round");
2341 break;
2342 case Configuration.SCREENLAYOUT_ROUND_NO:
2343 parts.add("notround");
2344 break;
2345 default:
2346 break;
2347 }
2348
Romain Guy48327452017-01-23 17:03:35 -08002349 switch (config.colorMode & Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_MASK) {
2350 case Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES:
Romain Guyc9ba5592017-01-18 16:34:42 -08002351 parts.add("widecg");
2352 break;
Romain Guy48327452017-01-23 17:03:35 -08002353 case Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO:
Romain Guyc9ba5592017-01-18 16:34:42 -08002354 parts.add("nowidecg");
2355 break;
2356 default:
2357 break;
2358 }
2359
Chia-I Wu0d8acf52018-05-09 12:08:05 -07002360 switch (config.colorMode & Configuration.COLOR_MODE_HDR_MASK) {
2361 case Configuration.COLOR_MODE_HDR_YES:
2362 parts.add("highdr");
2363 break;
2364 case Configuration.COLOR_MODE_HDR_NO:
2365 parts.add("lowdr");
2366 break;
2367 default:
2368 break;
2369 }
2370
Adam Lesinski2c749d22014-06-04 13:00:29 -07002371 switch (config.orientation) {
2372 case Configuration.ORIENTATION_LANDSCAPE:
2373 parts.add("land");
2374 break;
2375 case Configuration.ORIENTATION_PORTRAIT:
2376 parts.add("port");
2377 break;
2378 default:
2379 break;
2380 }
2381
2382 switch (config.uiMode & Configuration.UI_MODE_TYPE_MASK) {
2383 case Configuration.UI_MODE_TYPE_APPLIANCE:
2384 parts.add("appliance");
2385 break;
2386 case Configuration.UI_MODE_TYPE_DESK:
2387 parts.add("desk");
2388 break;
2389 case Configuration.UI_MODE_TYPE_TELEVISION:
2390 parts.add("television");
2391 break;
2392 case Configuration.UI_MODE_TYPE_CAR:
2393 parts.add("car");
2394 break;
2395 case Configuration.UI_MODE_TYPE_WATCH:
2396 parts.add("watch");
2397 break;
Zak Cohen1a6acdb2016-12-12 15:21:21 -08002398 case Configuration.UI_MODE_TYPE_VR_HEADSET:
2399 parts.add("vrheadset");
2400 break;
Adam Lesinski2c749d22014-06-04 13:00:29 -07002401 default:
2402 break;
2403 }
2404
2405 switch (config.uiMode & Configuration.UI_MODE_NIGHT_MASK) {
2406 case Configuration.UI_MODE_NIGHT_YES:
2407 parts.add("night");
2408 break;
2409 case Configuration.UI_MODE_NIGHT_NO:
2410 parts.add("notnight");
2411 break;
2412 default:
2413 break;
2414 }
2415
2416 switch (config.densityDpi) {
Adam Lesinski31245b42014-08-22 19:10:56 -07002417 case DENSITY_DPI_UNDEFINED:
Adam Lesinski2c749d22014-06-04 13:00:29 -07002418 break;
2419 case 120:
2420 parts.add("ldpi");
2421 break;
2422 case 160:
2423 parts.add("mdpi");
2424 break;
2425 case 213:
2426 parts.add("tvdpi");
2427 break;
2428 case 240:
2429 parts.add("hdpi");
2430 break;
2431 case 320:
2432 parts.add("xhdpi");
2433 break;
Adam Lesinskiebc3e4c2014-08-21 12:21:45 -07002434 case 480:
2435 parts.add("xxhdpi");
2436 break;
2437 case 640:
2438 parts.add("xxxhdpi");
2439 break;
Adam Lesinski31245b42014-08-22 19:10:56 -07002440 case DENSITY_DPI_ANY:
2441 parts.add("anydpi");
2442 break;
2443 case DENSITY_DPI_NONE:
2444 parts.add("nodpi");
Christian Williamsb709f3c2017-11-02 17:19:27 -07002445 break;
Adam Lesinski2c749d22014-06-04 13:00:29 -07002446 default:
2447 parts.add(config.densityDpi + "dpi");
2448 break;
2449 }
2450
2451 switch (config.touchscreen) {
2452 case Configuration.TOUCHSCREEN_NOTOUCH:
2453 parts.add("notouch");
2454 break;
2455 case Configuration.TOUCHSCREEN_FINGER:
2456 parts.add("finger");
2457 break;
2458 default:
2459 break;
2460 }
2461
2462 switch (config.keyboardHidden) {
2463 case Configuration.KEYBOARDHIDDEN_NO:
2464 parts.add("keysexposed");
2465 break;
2466 case Configuration.KEYBOARDHIDDEN_YES:
2467 parts.add("keyshidden");
2468 break;
2469 case Configuration.KEYBOARDHIDDEN_SOFT:
2470 parts.add("keyssoft");
2471 break;
2472 default:
2473 break;
2474 }
2475
2476 switch (config.keyboard) {
2477 case Configuration.KEYBOARD_NOKEYS:
2478 parts.add("nokeys");
2479 break;
2480 case Configuration.KEYBOARD_QWERTY:
2481 parts.add("qwerty");
2482 break;
2483 case Configuration.KEYBOARD_12KEY:
2484 parts.add("12key");
2485 break;
2486 default:
2487 break;
2488 }
2489
2490 switch (config.navigationHidden) {
2491 case Configuration.NAVIGATIONHIDDEN_NO:
2492 parts.add("navexposed");
2493 break;
2494 case Configuration.NAVIGATIONHIDDEN_YES:
2495 parts.add("navhidden");
2496 break;
2497 default:
2498 break;
2499 }
2500
2501 switch (config.navigation) {
2502 case Configuration.NAVIGATION_NONAV:
2503 parts.add("nonav");
2504 break;
2505 case Configuration.NAVIGATION_DPAD:
2506 parts.add("dpad");
2507 break;
2508 case Configuration.NAVIGATION_TRACKBALL:
2509 parts.add("trackball");
2510 break;
2511 case Configuration.NAVIGATION_WHEEL:
2512 parts.add("wheel");
2513 break;
2514 default:
2515 break;
2516 }
2517
Dianne Hackbornbf5ba6b2018-02-20 10:31:02 -08002518 if (metrics != null) {
2519 final int width, height;
2520 if (metrics.widthPixels >= metrics.heightPixels) {
2521 width = metrics.widthPixels;
2522 height = metrics.heightPixels;
2523 } else {
2524 //noinspection SuspiciousNameCombination
2525 width = metrics.heightPixels;
2526 //noinspection SuspiciousNameCombination
2527 height = metrics.widthPixels;
2528 }
2529 parts.add(width + "x" + height);
2530 }
2531
Adam Lesinskiebc3e4c2014-08-21 12:21:45 -07002532 parts.add("v" + Build.VERSION.RESOURCES_SDK_INT);
Adam Lesinski2c749d22014-06-04 13:00:29 -07002533 return TextUtils.join("-", parts);
2534 }
Adam Lesinski7f61e962014-09-02 16:43:52 -07002535
2536 /**
2537 * Generate a delta Configuration between <code>base</code> and <code>change</code>. The
2538 * resulting delta can be used with {@link #updateFrom(Configuration)}.
2539 * <p />
2540 * Caveat: If the any of the Configuration's members becomes undefined, then
2541 * {@link #updateFrom(Configuration)} will treat it as a no-op and not update that member.
2542 *
2543 * This is fine for device configurations as no member is ever undefined.
2544 * {@hide}
2545 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002546 @UnsupportedAppUsage
Adam Lesinski7f61e962014-09-02 16:43:52 -07002547 public static Configuration generateDelta(Configuration base, Configuration change) {
2548 final Configuration delta = new Configuration();
2549 if (base.fontScale != change.fontScale) {
2550 delta.fontScale = change.fontScale;
2551 }
2552
2553 if (base.mcc != change.mcc) {
2554 delta.mcc = change.mcc;
2555 }
2556
2557 if (base.mnc != change.mnc) {
2558 delta.mnc = change.mnc;
2559 }
2560
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002561 base.fixUpLocaleList();
2562 change.fixUpLocaleList();
2563 if (!base.mLocaleList.equals(change.mLocaleList)) {
2564 delta.mLocaleList = change.mLocaleList;
Adam Lesinski7f61e962014-09-02 16:43:52 -07002565 delta.locale = change.locale;
2566 }
2567
2568 if (base.touchscreen != change.touchscreen) {
2569 delta.touchscreen = change.touchscreen;
2570 }
2571
2572 if (base.keyboard != change.keyboard) {
2573 delta.keyboard = change.keyboard;
2574 }
2575
2576 if (base.keyboardHidden != change.keyboardHidden) {
2577 delta.keyboardHidden = change.keyboardHidden;
2578 }
2579
2580 if (base.navigation != change.navigation) {
2581 delta.navigation = change.navigation;
2582 }
2583
2584 if (base.navigationHidden != change.navigationHidden) {
2585 delta.navigationHidden = change.navigationHidden;
2586 }
2587
2588 if (base.orientation != change.orientation) {
2589 delta.orientation = change.orientation;
2590 }
2591
2592 if ((base.screenLayout & SCREENLAYOUT_SIZE_MASK) !=
2593 (change.screenLayout & SCREENLAYOUT_SIZE_MASK)) {
2594 delta.screenLayout |= change.screenLayout & SCREENLAYOUT_SIZE_MASK;
2595 }
2596
2597 if ((base.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK) !=
2598 (change.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK)) {
2599 delta.screenLayout |= change.screenLayout & SCREENLAYOUT_LAYOUTDIR_MASK;
2600 }
2601
2602 if ((base.screenLayout & SCREENLAYOUT_LONG_MASK) !=
2603 (change.screenLayout & SCREENLAYOUT_LONG_MASK)) {
2604 delta.screenLayout |= change.screenLayout & SCREENLAYOUT_LONG_MASK;
2605 }
2606
Adam Powell49e7ff92015-05-14 16:18:53 -07002607 if ((base.screenLayout & SCREENLAYOUT_ROUND_MASK) !=
2608 (change.screenLayout & SCREENLAYOUT_ROUND_MASK)) {
2609 delta.screenLayout |= change.screenLayout & SCREENLAYOUT_ROUND_MASK;
2610 }
2611
Romain Guy48327452017-01-23 17:03:35 -08002612 if ((base.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK) !=
2613 (change.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK)) {
2614 delta.colorMode |= change.colorMode & COLOR_MODE_WIDE_COLOR_GAMUT_MASK;
Romain Guyc9ba5592017-01-18 16:34:42 -08002615 }
2616
Romain Guy48327452017-01-23 17:03:35 -08002617 if ((base.colorMode & COLOR_MODE_HDR_MASK) !=
2618 (change.colorMode & COLOR_MODE_HDR_MASK)) {
2619 delta.colorMode |= change.colorMode & COLOR_MODE_HDR_MASK;
Romain Guyc9ba5592017-01-18 16:34:42 -08002620 }
2621
Adam Lesinski7f61e962014-09-02 16:43:52 -07002622 if ((base.uiMode & UI_MODE_TYPE_MASK) != (change.uiMode & UI_MODE_TYPE_MASK)) {
2623 delta.uiMode |= change.uiMode & UI_MODE_TYPE_MASK;
2624 }
2625
2626 if ((base.uiMode & UI_MODE_NIGHT_MASK) != (change.uiMode & UI_MODE_NIGHT_MASK)) {
2627 delta.uiMode |= change.uiMode & UI_MODE_NIGHT_MASK;
2628 }
2629
2630 if (base.screenWidthDp != change.screenWidthDp) {
2631 delta.screenWidthDp = change.screenWidthDp;
2632 }
2633
2634 if (base.screenHeightDp != change.screenHeightDp) {
2635 delta.screenHeightDp = change.screenHeightDp;
2636 }
2637
2638 if (base.smallestScreenWidthDp != change.smallestScreenWidthDp) {
2639 delta.smallestScreenWidthDp = change.smallestScreenWidthDp;
2640 }
2641
2642 if (base.densityDpi != change.densityDpi) {
2643 delta.densityDpi = change.densityDpi;
2644 }
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01002645
2646 if (base.assetsSeq != change.assetsSeq) {
2647 delta.assetsSeq = change.assetsSeq;
2648 }
Wale Ogunwale822e5122017-07-26 06:02:24 -07002649
2650 if (!base.windowConfiguration.equals(change.windowConfiguration)) {
2651 delta.windowConfiguration.setTo(change.windowConfiguration);
2652 }
Adam Lesinski7f61e962014-09-02 16:43:52 -07002653 return delta;
2654 }
2655
2656 private static final String XML_ATTR_FONT_SCALE = "fs";
2657 private static final String XML_ATTR_MCC = "mcc";
2658 private static final String XML_ATTR_MNC = "mnc";
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002659 private static final String XML_ATTR_LOCALES = "locales";
Adam Lesinski7f61e962014-09-02 16:43:52 -07002660 private static final String XML_ATTR_TOUCHSCREEN = "touch";
2661 private static final String XML_ATTR_KEYBOARD = "key";
2662 private static final String XML_ATTR_KEYBOARD_HIDDEN = "keyHid";
2663 private static final String XML_ATTR_HARD_KEYBOARD_HIDDEN = "hardKeyHid";
2664 private static final String XML_ATTR_NAVIGATION = "nav";
2665 private static final String XML_ATTR_NAVIGATION_HIDDEN = "navHid";
2666 private static final String XML_ATTR_ORIENTATION = "ori";
Bryce Leec1f2f2a2017-06-22 15:29:42 -07002667 private static final String XML_ATTR_ROTATION = "rot";
Adam Lesinski7f61e962014-09-02 16:43:52 -07002668 private static final String XML_ATTR_SCREEN_LAYOUT = "scrLay";
Romain Guy48327452017-01-23 17:03:35 -08002669 private static final String XML_ATTR_COLOR_MODE = "clrMod";
Adam Lesinski7f61e962014-09-02 16:43:52 -07002670 private static final String XML_ATTR_UI_MODE = "ui";
2671 private static final String XML_ATTR_SCREEN_WIDTH = "width";
2672 private static final String XML_ATTR_SCREEN_HEIGHT = "height";
2673 private static final String XML_ATTR_SMALLEST_WIDTH = "sw";
2674 private static final String XML_ATTR_DENSITY = "density";
Bryce Lee7566d762017-03-30 09:34:15 -07002675 private static final String XML_ATTR_APP_BOUNDS = "app_bounds";
Adam Lesinski7f61e962014-09-02 16:43:52 -07002676
2677 /**
2678 * Reads the attributes corresponding to Configuration member fields from the Xml parser.
2679 * The parser is expected to be on a tag which has Configuration attributes.
2680 *
2681 * @param parser The Xml parser from which to read attributes.
2682 * @param configOut The Configuration to populate from the Xml attributes.
2683 * {@hide}
2684 */
2685 public static void readXmlAttrs(XmlPullParser parser, Configuration configOut)
2686 throws XmlPullParserException, IOException {
2687 configOut.fontScale = Float.intBitsToFloat(
2688 XmlUtils.readIntAttribute(parser, XML_ATTR_FONT_SCALE, 0));
2689 configOut.mcc = XmlUtils.readIntAttribute(parser, XML_ATTR_MCC, 0);
2690 configOut.mnc = XmlUtils.readIntAttribute(parser, XML_ATTR_MNC, 0);
2691
Roozbeh Pournaderb46fdd42015-08-19 14:56:22 -07002692 final String localesStr = XmlUtils.readStringAttribute(parser, XML_ATTR_LOCALES);
2693 configOut.mLocaleList = LocaleList.forLanguageTags(localesStr);
Roozbeh Pournaderfee44842016-02-04 15:24:24 -08002694 configOut.locale = configOut.mLocaleList.get(0);
Adam Lesinski7f61e962014-09-02 16:43:52 -07002695
2696 configOut.touchscreen = XmlUtils.readIntAttribute(parser, XML_ATTR_TOUCHSCREEN,
2697 TOUCHSCREEN_UNDEFINED);
2698 configOut.keyboard = XmlUtils.readIntAttribute(parser, XML_ATTR_KEYBOARD,
2699 KEYBOARD_UNDEFINED);
2700 configOut.keyboardHidden = XmlUtils.readIntAttribute(parser, XML_ATTR_KEYBOARD_HIDDEN,
2701 KEYBOARDHIDDEN_UNDEFINED);
2702 configOut.hardKeyboardHidden =
2703 XmlUtils.readIntAttribute(parser, XML_ATTR_HARD_KEYBOARD_HIDDEN,
2704 HARDKEYBOARDHIDDEN_UNDEFINED);
2705 configOut.navigation = XmlUtils.readIntAttribute(parser, XML_ATTR_NAVIGATION,
2706 NAVIGATION_UNDEFINED);
2707 configOut.navigationHidden = XmlUtils.readIntAttribute(parser, XML_ATTR_NAVIGATION_HIDDEN,
2708 NAVIGATIONHIDDEN_UNDEFINED);
2709 configOut.orientation = XmlUtils.readIntAttribute(parser, XML_ATTR_ORIENTATION,
2710 ORIENTATION_UNDEFINED);
2711 configOut.screenLayout = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_LAYOUT,
2712 SCREENLAYOUT_UNDEFINED);
Romain Guy48327452017-01-23 17:03:35 -08002713 configOut.colorMode = XmlUtils.readIntAttribute(parser, XML_ATTR_COLOR_MODE,
2714 COLOR_MODE_UNDEFINED);
Adam Lesinski7f61e962014-09-02 16:43:52 -07002715 configOut.uiMode = XmlUtils.readIntAttribute(parser, XML_ATTR_UI_MODE, 0);
2716 configOut.screenWidthDp = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_WIDTH,
2717 SCREEN_WIDTH_DP_UNDEFINED);
2718 configOut.screenHeightDp = XmlUtils.readIntAttribute(parser, XML_ATTR_SCREEN_HEIGHT,
2719 SCREEN_HEIGHT_DP_UNDEFINED);
2720 configOut.smallestScreenWidthDp =
2721 XmlUtils.readIntAttribute(parser, XML_ATTR_SMALLEST_WIDTH,
2722 SMALLEST_SCREEN_WIDTH_DP_UNDEFINED);
2723 configOut.densityDpi = XmlUtils.readIntAttribute(parser, XML_ATTR_DENSITY,
2724 DENSITY_DPI_UNDEFINED);
Mårten Kongstad49a4a1d2017-01-12 08:36:37 +01002725
Wale Ogunwale822e5122017-07-26 06:02:24 -07002726 // For persistence, we don't care about assetsSeq and WindowConfiguration, so do not read it
2727 // out.
Adam Lesinski7f61e962014-09-02 16:43:52 -07002728 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002729}