Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit abb2ea62 authored by Zoey Chen's avatar Zoey Chen
Browse files

[Terms of Address] New hiden APIs, setSystemGrammaticalGender and getSystemGrammaticalGender

Change-Id: I1b35078cbc5f581b6b13daa8afcb6eee1aa2a15f
Test: adb shell device_config put grammatical_gender android.app.system_terms_of_address_enabled true
Bug: 295826542
Bug: 297798866
parent b05b0b65
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -334,7 +334,7 @@ java_aconfig_library {
aconfig_declarations {
    name: "android.app.flags-aconfig",
    package: "android.app",
    srcs: ["core/java/android/app/activity_manager.aconfig"],
    srcs: ["core/java/android/app/*.aconfig"],
}

java_aconfig_library {
+1 −0
Original line number Diff line number Diff line
@@ -5952,6 +5952,7 @@ package android.app {
  public class GrammaticalInflectionManager {
    method public int getApplicationGrammaticalGender();
    method @FlaggedApi("android.app.system_terms_of_address_enabled") public int getSystemGrammaticalGender();
    method public void setRequestedApplicationGrammaticalGender(int);
  }
+50 −3
Original line number Diff line number Diff line
@@ -16,12 +16,15 @@

package android.app;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.SystemService;
import android.content.Context;
import android.content.res.Configuration;
import android.os.RemoteException;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

@@ -31,11 +34,15 @@ import java.util.Set;
 */
@SystemService(Context.GRAMMATICAL_INFLECTION_SERVICE)
public class GrammaticalInflectionManager {
    private static final Set<Integer> VALID_GENDER_VALUES = new HashSet<>(Arrays.asList(

    /** @hide */
    @NonNull
    public static final Set<Integer> VALID_GRAMMATICAL_GENDER_VALUES =
        Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
            Configuration.GRAMMATICAL_GENDER_NOT_SPECIFIED,
            Configuration.GRAMMATICAL_GENDER_NEUTRAL,
            Configuration.GRAMMATICAL_GENDER_FEMININE,
            Configuration.GRAMMATICAL_GENDER_MASCULINE));
            Configuration.GRAMMATICAL_GENDER_MASCULINE)));

    private final Context mContext;
    private final IGrammaticalInflectionManager mService;
@@ -79,7 +86,7 @@ public class GrammaticalInflectionManager {
     */
    public void setRequestedApplicationGrammaticalGender(
            @Configuration.GrammaticalGender int grammaticalGender) {
        if (!VALID_GENDER_VALUES.contains(grammaticalGender)) {
        if (!VALID_GRAMMATICAL_GENDER_VALUES.contains(grammaticalGender)) {
            throw new IllegalArgumentException("Unknown grammatical gender");
        }

@@ -90,4 +97,44 @@ public class GrammaticalInflectionManager {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Sets the current grammatical gender for all privileged applications. The value will be
     * stored in an encrypted file at {@link android.os.Environment#getDataSystemCeDirectory(int)
     *
     * @param grammaticalGender the terms of address the user preferred in system.
     *
     * @see Configuration#getGrammaticalGender
     * @hide
     */
    public void setSystemWideGrammaticalGender(
            @Configuration.GrammaticalGender int grammaticalGender) {
        if (!VALID_GRAMMATICAL_GENDER_VALUES.contains(grammaticalGender)) {
            throw new IllegalArgumentException("Unknown grammatical gender");
        }

        try {
            mService.setSystemWideGrammaticalGender(mContext.getUserId(), grammaticalGender);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Get the current grammatical gender of privileged application from the encrypted file,
     * which is stored under {@link android.os.Environment#getDataSystemCeDirectory(int)}.
     *
     * @return the value of grammatical gender
     *
     * @see Configuration#getGrammaticalGender
     */
    @FlaggedApi(Flags.FLAG_SYSTEM_TERMS_OF_ADDRESS_ENABLED)
    @Configuration.GrammaticalGender
    public int getSystemGrammaticalGender() {
        try {
            return mService.getSystemGrammaticalGender(mContext.getUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
+11 −1
Original line number Diff line number Diff line
@@ -16,4 +16,14 @@ package android.app;
      * Sets a specified app’s app-specific grammatical gender.
      */
     void setRequestedApplicationGrammaticalGender(String appPackageName, int userId, int gender);

     /**
      * Sets the grammatical gender to system.
      */
     void setSystemWideGrammaticalGender(int userId, int gender);

     /**
      * Gets the grammatical gender from system.
      */
     int getSystemGrammaticalGender(int userId);
 }
+3 −0
Original line number Diff line number Diff line
@@ -54,6 +54,9 @@ per-file IBackupAgent.aidl = file:/services/backup/OWNERS
per-file Broadcast* = file:/BROADCASTS_OWNERS
per-file ReceiverInfo* = file:/BROADCASTS_OWNERS

# GrammaticalInflectionManager
per-file *GrammaticalInflection* = file:/services/core/java/com/android/server/grammaticalinflection/OWNERS

# KeyguardManager
per-file KeyguardManager.java = file:/services/core/java/com/android/server/locksettings/OWNERS

Loading