Add check to retrieve grammatical gender value from system properties

after reboot and introduce an internal constant in Configuration to fix bugs
that block updating grammatical gender value.

Bug: b/272626712
Test: Verified affected tests passed.
Change-Id: Ia1ee69608380e64529d7a2f1dd920bb73ce80528
This commit is contained in:
Brandon Liu
2023-06-21 22:33:13 +00:00
parent 50e3809a53
commit dc7c982eab
2 changed files with 35 additions and 7 deletions

View File

@@ -154,7 +154,6 @@ public final class Configuration implements Parcelable, Comparable<Configuration
/**
* Current user preference for the grammatical gender.
*/
@GrammaticalGender
private int mGrammaticalGender;
/** @hide */
@@ -166,6 +165,13 @@ public final class Configuration implements Parcelable, Comparable<Configuration
})
public @interface GrammaticalGender {}
/**
* Constant for grammatical gender: to indicate that the grammatical gender is undefined.
* Only for internal usage.
* @hide
*/
public static final int GRAMMATICAL_GENDER_UNDEFINED = -1;
/**
* Constant for grammatical gender: to indicate the user has not specified the terms
* of address for the application.
@@ -1120,12 +1126,12 @@ public final class Configuration implements Parcelable, Comparable<Configuration
} else {
sb.append(" ?localeList");
}
if (mGrammaticalGender != 0) {
if (mGrammaticalGender > 0) {
switch (mGrammaticalGender) {
case GRAMMATICAL_GENDER_NEUTRAL: sb.append(" neuter"); break;
case GRAMMATICAL_GENDER_FEMININE: sb.append(" feminine"); break;
case GRAMMATICAL_GENDER_MASCULINE: sb.append(" masculine"); break;
case GRAMMATICAL_GENDER_NOT_SPECIFIED: sb.append(" ?grgend"); break;
default: sb.append(" ?grgend"); break;
}
}
int layoutDir = (screenLayout&SCREENLAYOUT_LAYOUTDIR_MASK);
@@ -1570,7 +1576,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
seq = 0;
windowConfiguration.setToDefaults();
fontWeightAdjustment = FONT_WEIGHT_ADJUSTMENT_UNDEFINED;
mGrammaticalGender = GRAMMATICAL_GENDER_NOT_SPECIFIED;
mGrammaticalGender = GRAMMATICAL_GENDER_UNDEFINED;
}
/**
@@ -1773,7 +1779,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
changed |= ActivityInfo.CONFIG_FONT_WEIGHT_ADJUSTMENT;
fontWeightAdjustment = delta.fontWeightAdjustment;
}
if (delta.mGrammaticalGender != mGrammaticalGender) {
if (delta.mGrammaticalGender != GRAMMATICAL_GENDER_UNDEFINED
&& delta.mGrammaticalGender != mGrammaticalGender) {
changed |= ActivityInfo.CONFIG_GRAMMATICAL_GENDER;
mGrammaticalGender = delta.mGrammaticalGender;
}
@@ -1998,7 +2005,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
changed |= ActivityInfo.CONFIG_FONT_WEIGHT_ADJUSTMENT;
}
if (mGrammaticalGender != delta.mGrammaticalGender) {
if ((compareUndefined || delta.mGrammaticalGender != GRAMMATICAL_GENDER_UNDEFINED)
&& mGrammaticalGender != delta.mGrammaticalGender) {
changed |= ActivityInfo.CONFIG_GRAMMATICAL_GENDER;
}
return changed;
@@ -2284,6 +2292,17 @@ public final class Configuration implements Parcelable, Comparable<Configuration
*/
@GrammaticalGender
public int getGrammaticalGender() {
return mGrammaticalGender == GRAMMATICAL_GENDER_UNDEFINED
? GRAMMATICAL_GENDER_NOT_SPECIFIED : mGrammaticalGender;
}
/**
* Internal getter of grammatical gender, to get the raw value of grammatical gender,
* which include {@link #GRAMMATICAL_GENDER_UNDEFINED}.
* @hide
*/
public int getGrammaticalGenderRaw() {
return mGrammaticalGender;
}
@@ -2972,7 +2991,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
configOut.fontWeightAdjustment = XmlUtils.readIntAttribute(parser,
XML_ATTR_FONT_WEIGHT_ADJUSTMENT, FONT_WEIGHT_ADJUSTMENT_UNDEFINED);
configOut.mGrammaticalGender = XmlUtils.readIntAttribute(parser,
XML_ATTR_GRAMMATICAL_GENDER, GRAMMATICAL_GENDER_NOT_SPECIFIED);
XML_ATTR_GRAMMATICAL_GENDER, GRAMMATICAL_GENDER_UNDEFINED);
// For persistence, we don't care about assetsSeq and WindowConfiguration, so do not read it
// out.

View File

@@ -311,6 +311,7 @@ import java.util.Set;
* {@hide}
*/
public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
private static final String GRAMMATICAL_GENDER_PROPERTY = "persist.sys.grammatical_gender";
private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityTaskManagerService" : TAG_ATM;
static final String TAG_ROOT_TASK = TAG + POSTFIX_ROOT_TASK;
static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
@@ -928,6 +929,14 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
configuration.setLayoutDirection(configuration.locale);
}
// Retrieve the grammatical gender from system property, set it into configuration which
// will get updated later if the grammatical gender raw value of current configuration is
// {@link Configuration#GRAMMATICAL_GENDER_UNDEFINED}.
if (configuration.getGrammaticalGenderRaw() == Configuration.GRAMMATICAL_GENDER_UNDEFINED) {
configuration.setGrammaticalGender(SystemProperties.getInt(GRAMMATICAL_GENDER_PROPERTY,
Configuration.GRAMMATICAL_GENDER_UNDEFINED));
}
synchronized (mGlobalLock) {
mForceResizableActivities = forceResizable;
mDevEnableNonResizableMultiWindow = devEnableNonResizableMultiWindow;