Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 02d8919

Browse files
author
Yurii Zubrytskyi
committed
[res] Add the grammatical gender qualifier
Bug: 237579711 Test: UTs + build + boot Change-Id: Id0919799a8a364f109ff351974f02e4f151f23cd
1 parent dac535a commit 02d8919

23 files changed

+242
-53
lines changed

core/api/current.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12984,9 +12984,9 @@ package android.content.res {
1298412984
field @NonNull public static final android.os.Parcelable.Creator<android.content.res.Configuration> CREATOR;
1298512985
field public static final int DENSITY_DPI_UNDEFINED = 0; // 0x0
1298612986
field public static final int FONT_WEIGHT_ADJUSTMENT_UNDEFINED = 2147483647; // 0x7fffffff
12987-
field public static final int GRAMMATICAL_GENDER_FEMININE = 3; // 0x3
12988-
field public static final int GRAMMATICAL_GENDER_MASCULINE = 4; // 0x4
12989-
field public static final int GRAMMATICAL_GENDER_NEUTRAL = 2; // 0x2
12987+
field public static final int GRAMMATICAL_GENDER_FEMININE = 2; // 0x2
12988+
field public static final int GRAMMATICAL_GENDER_MASCULINE = 3; // 0x3
12989+
field public static final int GRAMMATICAL_GENDER_NEUTRAL = 1; // 0x1
1299012990
field public static final int GRAMMATICAL_GENDER_NOT_SPECIFIED = 0; // 0x0
1299112991
field public static final int HARDKEYBOARDHIDDEN_NO = 1; // 0x1
1299212992
field public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0; // 0x0

core/java/android/content/pm/ActivityInfo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ public static String launchModeToString(@LaunchMode int launchMode) {
998998
Configuration.NATIVE_CONFIG_DENSITY, // DENSITY
999999
Configuration.NATIVE_CONFIG_LAYOUTDIR, // LAYOUT DIRECTION
10001000
Configuration.NATIVE_CONFIG_COLOR_MODE, // COLOR_MODE
1001+
Configuration.NATIVE_CONFIG_GRAMMATICAL_GENDER,
10011002
};
10021003

10031004
/**
@@ -1267,8 +1268,8 @@ public int getRealConfigChanged() {
12671268
* {@link #CONFIG_LOCALE}, {@link #CONFIG_TOUCHSCREEN},
12681269
* {@link #CONFIG_KEYBOARD}, {@link #CONFIG_NAVIGATION},
12691270
* {@link #CONFIG_ORIENTATION}, {@link #CONFIG_SCREEN_LAYOUT},
1270-
* {@link #CONFIG_DENSITY}, {@link #CONFIG_LAYOUT_DIRECTION} and
1271-
* {@link #CONFIG_COLOR_MODE}.
1271+
* {@link #CONFIG_DENSITY}, {@link #CONFIG_LAYOUT_DIRECTION},
1272+
* {@link #CONFIG_COLOR_MODE}, and {link #CONFIG_GRAMMATICAL_GENDER}.
12721273
* Set from the {@link android.R.attr#configChanges} attribute.
12731274
*/
12741275
public int configChanges;

core/java/android/content/pm/PackageParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ private static void collectCertificates(Package pkg, File apkFile, boolean skipV
14561456

14571457
private static AssetManager newConfiguredAssetManager() {
14581458
AssetManager assetManager = new AssetManager();
1459-
assetManager.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1459+
assetManager.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
14601460
Build.VERSION.RESOURCES_SDK_INT);
14611461
return assetManager;
14621462
}
@@ -9011,7 +9011,7 @@ public AssetManager getBaseAssetManager() throws PackageParserException {
90119011
}
90129012

90139013
AssetManager assets = new AssetManager();
9014-
assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9014+
assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90159015
Build.VERSION.RESOURCES_SDK_INT);
90169016
assets.setApkAssets(apkAssets, false /*invalidateCaches*/);
90179017

@@ -9086,7 +9086,7 @@ private static ApkAssets loadApkAssets(String path, @ParseFlags int flags)
90869086

90879087
private static AssetManager createAssetManagerWithAssets(ApkAssets[] apkAssets) {
90889088
final AssetManager assets = new AssetManager();
9089-
assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9089+
assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90909090
Build.VERSION.RESOURCES_SDK_INT);
90919091
assets.setApkAssets(apkAssets, false /*invalidateCaches*/);
90929092
return assets;

core/java/android/content/res/AssetManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,13 +1461,14 @@ Configuration[] getSizeConfigurations() {
14611461
public void setConfiguration(int mcc, int mnc, @Nullable String locale, int orientation,
14621462
int touchscreen, int density, int keyboard, int keyboardHidden, int navigation,
14631463
int screenWidth, int screenHeight, int smallestScreenWidthDp, int screenWidthDp,
1464-
int screenHeightDp, int screenLayout, int uiMode, int colorMode, int majorVersion) {
1464+
int screenHeightDp, int screenLayout, int uiMode, int colorMode, int grammaticalGender,
1465+
int majorVersion) {
14651466
synchronized (this) {
14661467
ensureValidLocked();
14671468
nativeSetConfiguration(mObject, mcc, mnc, locale, orientation, touchscreen, density,
14681469
keyboard, keyboardHidden, navigation, screenWidth, screenHeight,
14691470
smallestScreenWidthDp, screenWidthDp, screenHeightDp, screenLayout, uiMode,
1470-
colorMode, majorVersion);
1471+
colorMode, grammaticalGender, majorVersion);
14711472
}
14721473
}
14731474

@@ -1557,7 +1558,7 @@ private static native void nativeSetConfiguration(long ptr, int mcc, int mnc,
15571558
@Nullable String locale, int orientation, int touchscreen, int density, int keyboard,
15581559
int keyboardHidden, int navigation, int screenWidth, int screenHeight,
15591560
int smallestScreenWidthDp, int screenWidthDp, int screenHeightDp, int screenLayout,
1560-
int uiMode, int colorMode, int majorVersion);
1561+
int uiMode, int colorMode, int grammaticalGender, int majorVersion);
15611562
private static native @NonNull SparseArray<String> nativeGetAssignedPackageIdentifiers(
15621563
long ptr, boolean includeOverlays, boolean includeLoaders);
15631564

core/java/android/content/res/Configuration.java

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static android.content.ConfigurationProto.DENSITY_DPI;
2121
import static android.content.ConfigurationProto.FONT_SCALE;
2222
import static android.content.ConfigurationProto.FONT_WEIGHT_ADJUSTMENT;
23+
import static android.content.ConfigurationProto.GRAMMATICAL_GENDER;
2324
import static android.content.ConfigurationProto.HARD_KEYBOARD_HIDDEN;
2425
import static android.content.ConfigurationProto.KEYBOARD;
2526
import static android.content.ConfigurationProto.KEYBOARD_HIDDEN;
@@ -167,19 +168,19 @@ public final class Configuration implements Parcelable, Comparable<Configuration
167168
* Constant for grammatical gender: to indicate the terms of address the user
168169
* preferred in an application is neuter.
169170
*/
170-
public static final int GRAMMATICAL_GENDER_NEUTRAL = 2;
171+
public static final int GRAMMATICAL_GENDER_NEUTRAL = 1;
171172

172173
/**
173174
* Constant for grammatical gender: to indicate the terms of address the user
174175
* preferred in an application is feminine.
175176
*/
176-
public static final int GRAMMATICAL_GENDER_FEMININE = 3;
177+
public static final int GRAMMATICAL_GENDER_FEMININE = 2;
177178

178179
/**
179180
* Constant for grammatical gender: to indicate the terms of address the user
180181
* preferred in an application is masculine.
181182
*/
182-
public static final int GRAMMATICAL_GENDER_MASCULINE = 4;
183+
public static final int GRAMMATICAL_GENDER_MASCULINE = 3;
183184

184185
/** Constant for {@link #colorMode}: bits that encode whether the screen is wide gamut. */
185186
public static final int COLOR_MODE_WIDE_COLOR_GAMUT_MASK = 0x3;
@@ -529,15 +530,10 @@ public static String configurationDiffToString(int diff) {
529530
if ((diff & ActivityInfo.CONFIG_FONT_WEIGHT_ADJUSTMENT) != 0) {
530531
list.add("CONFIG_AUTO_BOLD_TEXT");
531532
}
532-
StringBuilder builder = new StringBuilder("{");
533-
for (int i = 0, n = list.size(); i < n; i++) {
534-
builder.append(list.get(i));
535-
if (i != n - 1) {
536-
builder.append(", ");
537-
}
533+
if ((diff & ActivityInfo.CONFIG_GRAMMATICAL_GENDER) != 0) {
534+
list.add("CONFIG_GRAMMATICAL_GENDER");
538535
}
539-
builder.append("}");
540-
return builder.toString();
536+
return "{" + TextUtils.join(", ", list) + "}";
541537
}
542538

543539
/**
@@ -970,6 +966,7 @@ public boolean isLayoutSizeAtLeast(int size) {
970966
NATIVE_CONFIG_SMALLEST_SCREEN_SIZE,
971967
NATIVE_CONFIG_LAYOUTDIR,
972968
NATIVE_CONFIG_COLOR_MODE,
969+
NATIVE_CONFIG_GRAMMATICAL_GENDER,
973970
})
974971
@Retention(RetentionPolicy.SOURCE)
975972
public @interface NativeConfig {}
@@ -1008,6 +1005,9 @@ public boolean isLayoutSizeAtLeast(int size) {
10081005
public static final int NATIVE_CONFIG_LAYOUTDIR = 0x4000;
10091006
/** @hide Native-specific bit mask for COLOR_MODE config ; DO NOT USE UNLESS YOU ARE SURE.*/
10101007
public static final int NATIVE_CONFIG_COLOR_MODE = 0x10000;
1008+
/** @hide Native-specific bit mask for GRAMMATICAL_GENDER config; DO NOT USE UNLESS YOU
1009+
* ARE SURE.*/
1010+
public static final int NATIVE_CONFIG_GRAMMATICAL_GENDER = 0x20000;
10111011

10121012
/**
10131013
* <p>Construct an invalid Configuration. This state is only suitable for constructing a
@@ -1112,6 +1112,14 @@ public String toString() {
11121112
} else {
11131113
sb.append(" ?localeList");
11141114
}
1115+
if (mGrammaticalGender != 0) {
1116+
switch (mGrammaticalGender) {
1117+
case GRAMMATICAL_GENDER_NEUTRAL: sb.append(" neuter"); break;
1118+
case GRAMMATICAL_GENDER_FEMININE: sb.append(" feminine"); break;
1119+
case GRAMMATICAL_GENDER_MASCULINE: sb.append(" masculine"); break;
1120+
case GRAMMATICAL_GENDER_NOT_SPECIFIED: sb.append(" ?grgend"); break;
1121+
}
1122+
}
11151123
int layoutDir = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK);
11161124
switch (layoutDir) {
11171125
case SCREENLAYOUT_LAYOUTDIR_UNDEFINED: sb.append(" ?layoutDir"); break;
@@ -1292,6 +1300,7 @@ public void dumpDebug(ProtoOutputStream protoOutputStream, long fieldId, boolean
12921300
protoOutputStream.write(ORIENTATION, orientation);
12931301
protoOutputStream.write(SCREEN_WIDTH_DP, screenWidthDp);
12941302
protoOutputStream.write(SCREEN_HEIGHT_DP, screenHeightDp);
1303+
protoOutputStream.write(GRAMMATICAL_GENDER, mGrammaticalGender);
12951304
protoOutputStream.end(token);
12961305
}
12971306

@@ -1454,6 +1463,9 @@ public void readFromProto(ProtoInputStream protoInputStream, long fieldId) throw
14541463
case (int) FONT_WEIGHT_ADJUSTMENT:
14551464
fontWeightAdjustment = protoInputStream.readInt(FONT_WEIGHT_ADJUSTMENT);
14561465
break;
1466+
case (int) GRAMMATICAL_GENDER:
1467+
mGrammaticalGender = protoInputStream.readInt(GRAMMATICAL_GENDER);
1468+
break;
14571469
}
14581470
}
14591471
} finally {
@@ -1839,6 +1851,9 @@ public void setTo(@NonNull Configuration delta, @Config int mask,
18391851
if ((mask & ActivityInfo.CONFIG_FONT_WEIGHT_ADJUSTMENT) != 0) {
18401852
fontWeightAdjustment = delta.fontWeightAdjustment;
18411853
}
1854+
if ((mask & ActivityInfo.CONFIG_GRAMMATICAL_GENDER) != 0) {
1855+
mGrammaticalGender = delta.mGrammaticalGender;
1856+
}
18421857
}
18431858

18441859
/**
@@ -1975,7 +1990,7 @@ && getScreenLayoutNoDirection(screenLayout) !=
19751990
changed |= ActivityInfo.CONFIG_FONT_WEIGHT_ADJUSTMENT;
19761991
}
19771992

1978-
if (!publicOnly&& mGrammaticalGender != delta.mGrammaticalGender) {
1993+
if (!publicOnly && mGrammaticalGender != delta.mGrammaticalGender) {
19791994
changed |= ActivityInfo.CONFIG_GRAMMATICAL_GENDER;
19801995
}
19811996
return changed;
@@ -2172,6 +2187,8 @@ public int compareTo(Configuration that) {
21722187
if (n != 0) return n;
21732188
}
21742189

2190+
n = this.mGrammaticalGender - that.mGrammaticalGender;
2191+
if (n != 0) return n;
21752192
n = this.touchscreen - that.touchscreen;
21762193
if (n != 0) return n;
21772194
n = this.keyboard - that.keyboard;
@@ -2205,11 +2222,6 @@ public int compareTo(Configuration that) {
22052222
n = windowConfiguration.compareTo(that.windowConfiguration);
22062223
if (n != 0) return n;
22072224
n = this.fontWeightAdjustment - that.fontWeightAdjustment;
2208-
if (n != 0) return n;
2209-
n = this.mGrammaticalGender - that.mGrammaticalGender;
2210-
if (n != 0) return n;
2211-
2212-
// if (n != 0) return n;
22132225
return n;
22142226
}
22152227

@@ -2482,6 +2494,20 @@ public static String resourceQualifierString(Configuration config, DisplayMetric
24822494
}
24832495
}
24842496

2497+
switch (config.mGrammaticalGender) {
2498+
case Configuration.GRAMMATICAL_GENDER_NEUTRAL:
2499+
parts.add("neuter");
2500+
break;
2501+
case Configuration.GRAMMATICAL_GENDER_FEMININE:
2502+
parts.add("feminine");
2503+
break;
2504+
case Configuration.GRAMMATICAL_GENDER_MASCULINE:
2505+
parts.add("masculine");
2506+
break;
2507+
default:
2508+
break;
2509+
}
2510+
24852511
switch (config.screenLayout & Configuration.SCREENLAYOUT_LAYOUTDIR_MASK) {
24862512
case Configuration.SCREENLAYOUT_LAYOUTDIR_LTR:
24872513
parts.add("ldltr");
@@ -2768,6 +2794,10 @@ public static Configuration generateDelta(
27682794
delta.locale = change.locale;
27692795
}
27702796

2797+
if (base.mGrammaticalGender != change.mGrammaticalGender) {
2798+
delta.mGrammaticalGender = change.mGrammaticalGender;
2799+
}
2800+
27712801
if (base.touchscreen != change.touchscreen) {
27722802
delta.touchscreen = change.touchscreen;
27732803
}
@@ -2881,6 +2911,7 @@ public static Configuration generateDelta(
28812911
private static final String XML_ATTR_DENSITY = "density";
28822912
private static final String XML_ATTR_APP_BOUNDS = "app_bounds";
28832913
private static final String XML_ATTR_FONT_WEIGHT_ADJUSTMENT = "fontWeightAdjustment";
2914+
private static final String XML_ATTR_GRAMMATICAL_GENDER = "grammaticalGender";
28842915

28852916
/**
28862917
* Reads the attributes corresponding to Configuration member fields from the Xml parser.
@@ -2932,6 +2963,8 @@ public static void readXmlAttrs(XmlPullParser parser, Configuration configOut)
29322963
DENSITY_DPI_UNDEFINED);
29332964
configOut.fontWeightAdjustment = XmlUtils.readIntAttribute(parser,
29342965
XML_ATTR_FONT_WEIGHT_ADJUSTMENT, FONT_WEIGHT_ADJUSTMENT_UNDEFINED);
2966+
configOut.mGrammaticalGender = XmlUtils.readIntAttribute(parser,
2967+
XML_ATTR_GRAMMATICAL_GENDER, GRAMMATICAL_GENDER_NOT_SPECIFIED);
29352968

29362969
// For persistence, we don't care about assetsSeq and WindowConfiguration, so do not read it
29372970
// out.

core/java/android/content/res/ResourcesImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ public void updateConfiguration(Configuration config, DisplayMetrics metrics,
466466
mConfiguration.smallestScreenWidthDp,
467467
mConfiguration.screenWidthDp, mConfiguration.screenHeightDp,
468468
mConfiguration.screenLayout, mConfiguration.uiMode,
469-
mConfiguration.colorMode, Build.VERSION.RESOURCES_SDK_INT);
469+
mConfiguration.colorMode, mConfiguration.getGrammaticalGender(),
470+
Build.VERSION.RESOURCES_SDK_INT);
470471

471472
if (DEBUG_CONFIG) {
472473
Slog.i(TAG, "**** Updating config of " + this + ": final config is "

core/jni/android_util_AssetManager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ static void NativeSetConfiguration(JNIEnv* env, jclass /*clazz*/, jlong ptr, jin
324324
jint screen_width, jint screen_height,
325325
jint smallest_screen_width_dp, jint screen_width_dp,
326326
jint screen_height_dp, jint screen_layout, jint ui_mode,
327-
jint color_mode, jint major_version) {
327+
jint color_mode, jint grammatical_gender, jint major_version) {
328328
ATRACE_NAME("AssetManager::SetConfiguration");
329329

330330
ResTable_config configuration;
@@ -345,6 +345,7 @@ static void NativeSetConfiguration(JNIEnv* env, jclass /*clazz*/, jlong ptr, jin
345345
configuration.screenLayout = static_cast<uint8_t>(screen_layout);
346346
configuration.uiMode = static_cast<uint8_t>(ui_mode);
347347
configuration.colorMode = static_cast<uint8_t>(color_mode);
348+
configuration.grammaticalInflection = static_cast<uint8_t>(grammatical_gender);
348349
configuration.sdkVersion = static_cast<uint16_t>(major_version);
349350

350351
if (locale != nullptr) {
@@ -1448,7 +1449,7 @@ static const JNINativeMethod gAssetManagerMethods[] = {
14481449
{"nativeCreate", "()J", (void*)NativeCreate},
14491450
{"nativeDestroy", "(J)V", (void*)NativeDestroy},
14501451
{"nativeSetApkAssets", "(J[Landroid/content/res/ApkAssets;Z)V", (void*)NativeSetApkAssets},
1451-
{"nativeSetConfiguration", "(JIILjava/lang/String;IIIIIIIIIIIIIII)V",
1452+
{"nativeSetConfiguration", "(JIILjava/lang/String;IIIIIIIIIIIIIIII)V",
14521453
(void*)NativeSetConfiguration},
14531454
{"nativeGetAssignedPackageIdentifiers", "(JZZ)Landroid/util/SparseArray;",
14541455
(void*)NativeGetAssignedPackageIdentifiers},

core/proto/android/content/configuration.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ message ConfigurationProto {
5050
optional .android.app.WindowConfigurationProto window_configuration = 19;
5151
optional string locale_list = 20;
5252
optional uint32 font_weight_adjustment = 21;
53+
optional uint32 grammatical_gender = 22;
5354
}
5455

5556
/**

0 commit comments

Comments
 (0)