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

Commit d2dff29f authored by Calvin Pan's avatar Calvin Pan Committed by Android (Google) Code Review
Browse files

Merge changes from topic "configuration_gender"

* changes:
  Fix test case fail
  Add a new field in Configuration and persist the field
  Add a system service for grammatical gender
parents d403e908 5128bb95
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -5650,6 +5650,11 @@ package android.app {
    field public static final int MODE_UNKNOWN = 0; // 0x0
  }
  public class GrammaticalInflectionManager {
    method public int getApplicationGrammaticalGender();
    method public void setRequestedApplicationGrammaticalGender(int);
  }
  public class Instrumentation {
    ctor public Instrumentation();
    method public android.os.TestLooperManager acquireLooperManager(android.os.Looper);
@@ -10005,6 +10010,7 @@ package android.content {
    field public static final String FILE_INTEGRITY_SERVICE = "file_integrity";
    field public static final String FINGERPRINT_SERVICE = "fingerprint";
    field public static final String GAME_SERVICE = "game";
    field public static final String GRAMMATICAL_INFLECTION_SERVICE = "grammatical_inflection";
    field public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
    field public static final String HEALTHCONNECT_SERVICE = "healthconnect";
    field public static final String INPUT_METHOD_SERVICE = "input_method";
@@ -11261,6 +11267,7 @@ package android.content.pm {
    field public static final int CONFIG_DENSITY = 4096; // 0x1000
    field public static final int CONFIG_FONT_SCALE = 1073741824; // 0x40000000
    field public static final int CONFIG_FONT_WEIGHT_ADJUSTMENT = 268435456; // 0x10000000
    field public static final int CONFIG_GRAMMATICAL_GENDER = 32768; // 0x8000
    field public static final int CONFIG_KEYBOARD = 16; // 0x10
    field public static final int CONFIG_KEYBOARD_HIDDEN = 32; // 0x20
    field public static final int CONFIG_LAYOUT_DIRECTION = 8192; // 0x2000
@@ -12875,6 +12882,7 @@ package android.content.res {
    method public int diff(android.content.res.Configuration);
    method public boolean equals(android.content.res.Configuration);
    method @NonNull public static android.content.res.Configuration generateDelta(@NonNull android.content.res.Configuration, @NonNull android.content.res.Configuration);
    method public int getGrammaticalGender();
    method public int getLayoutDirection();
    method @NonNull public android.os.LocaleList getLocales();
    method public boolean isLayoutSizeAtLeast(int);
@@ -12904,6 +12912,10 @@ package android.content.res {
    field @NonNull public static final android.os.Parcelable.Creator<android.content.res.Configuration> CREATOR;
    field public static final int DENSITY_DPI_UNDEFINED = 0; // 0x0
    field public static final int FONT_WEIGHT_ADJUSTMENT_UNDEFINED = 2147483647; // 0x7fffffff
    field public static final int GRAMMATICAL_GENDER_FEMININE = 3; // 0x3
    field public static final int GRAMMATICAL_GENDER_MASCULINE = 4; // 0x4
    field public static final int GRAMMATICAL_GENDER_NEUTRAL = 2; // 0x2
    field public static final int GRAMMATICAL_GENDER_NOT_SPECIFIED = 0; // 0x0
    field public static final int HARDKEYBOARDHIDDEN_NO = 1; // 0x1
    field public static final int HARDKEYBOARDHIDDEN_UNDEFINED = 0; // 0x0
    field public static final int HARDKEYBOARDHIDDEN_YES = 2; // 0x2
+93 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app;

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

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

/**
 * This class allow applications to control granular grammatical inflection settings (such as
 * per-app grammatical gender).
 */
@SystemService(Context.GRAMMATICAL_INFLECTION_SERVICE)
public class GrammaticalInflectionManager {
    private static final Set<Integer> VALID_GENDER_VALUES = new HashSet<>(Arrays.asList(
            Configuration.GRAMMATICAL_GENDER_NOT_SPECIFIED,
            Configuration.GRAMMATICAL_GENDER_NEUTRAL,
            Configuration.GRAMMATICAL_GENDER_FEMININE,
            Configuration.GRAMMATICAL_GENDER_MASCULINE));

    private final Context mContext;
    private final IGrammaticalInflectionManager mService;

    /** @hide Instantiated by ContextImpl */
    public GrammaticalInflectionManager(Context context, IGrammaticalInflectionManager service) {
        mContext = context;
        mService = service;
    }

    /**
     * Returns the current grammatical gender for the calling app. A new value can be requested via
     * {@link #setRequestedApplicationGrammaticalGender(int)} and will be updated with a new
     * configuration change. The method always returns the value received with the last received
     * configuration change.
     *
     * @return the value of grammatical gender
     * @see Configuration#getGrammaticalGender
     */
    @Configuration.GrammaticalGender
    public int getApplicationGrammaticalGender() {
        return mContext.getApplicationContext()
                .getResources()
                .getConfiguration()
                .getGrammaticalGender();
    }

    /**
     * Sets the current grammatical gender for the calling app (keyed by package name and user ID
     * retrieved from the calling pid).
     *
     * <p><b>Note:</b> Changes to app grammatical gender will result in a configuration change (and
     * potentially an Activity re-creation) being applied to the specified application. For more
     * information, see the <a
     * href="https://developer.android.com/guide/topics/resources/runtime-changes">section on
     * handling configuration changes</a>. The set grammatical gender are persisted across
     * application restarts; they are backed up if the user has enabled Backup & Restore.`
     *
     * @param grammaticalGender the terms of address the user preferred in an application.
     * @see Configuration#getGrammaticalGender
     */
    public void setRequestedApplicationGrammaticalGender(
            @Configuration.GrammaticalGender int grammaticalGender) {
        if (!VALID_GENDER_VALUES.contains(grammaticalGender)) {
            throw new IllegalArgumentException("Unknown grammatical gender");
        }

        try {
            mService.setRequestedApplicationGrammaticalGender(
                    mContext.getPackageName(), mContext.getUserId(), grammaticalGender);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
+19 −0
Original line number Diff line number Diff line
package android.app;


/**
 * Internal interface used to control app-specific gender.
 *
 * <p>Use the {@link android.app.GrammarInflectionManager} class rather than going through
 * this Binder interface directly. See {@link android.app.GrammarInflectionManager} for
 * more complete documentation.
 *
 * @hide
 */
 interface IGrammaticalInflectionManager {

     /**
      * Sets a specified app’s app-specific grammatical gender.
      */
     void setRequestedApplicationGrammaticalGender(String appPackageName, int userId, int gender);
 }
 No newline at end of file
+13 −0
Original line number Diff line number Diff line
@@ -1547,6 +1547,7 @@ public final class SystemServiceRegistry {
                                IAmbientContextManager.Stub.asInterface(iBinder);
                        return new AmbientContextManager(ctx.getOuterContext(), manager);
                    }});

        registerService(Context.WEARABLE_SENSING_SERVICE, WearableSensingManager.class,
                new CachedServiceFetcher<WearableSensingManager>() {
                    @Override
@@ -1559,6 +1560,18 @@ public final class SystemServiceRegistry {
                        return new WearableSensingManager(ctx.getOuterContext(), manager);
                    }});

        registerService(Context.GRAMMATICAL_INFLECTION_SERVICE, GrammaticalInflectionManager.class,
                new CachedServiceFetcher<GrammaticalInflectionManager>() {
                    @Override
                    public GrammaticalInflectionManager createService(ContextImpl ctx)
                            throws ServiceNotFoundException {
                        return new GrammaticalInflectionManager(ctx,
                                IGrammaticalInflectionManager.Stub.asInterface(
                                        ServiceManager.getServiceOrThrow(
                                                Context.GRAMMATICAL_INFLECTION_SERVICE)));
                    }});


        sInitializing = true;
        try {
            // Note: the following functions need to be @SystemApis, once they become mainline
+11 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.app.Activity;
import android.app.ActivityManager;
import android.app.BroadcastOptions;
import android.app.GameManager;
import android.app.GrammaticalInflectionManager;
import android.app.IApplicationThread;
import android.app.IServiceConnection;
import android.app.VrManager;
@@ -3973,6 +3974,8 @@ public abstract class Context {
            CREDENTIAL_SERVICE,
            DEVICE_LOCK_SERVICE,
            VIRTUALIZATION_SERVICE,
            GRAMMATICAL_INFLECTION_SERVICE,

    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ServiceName {}
@@ -6168,6 +6171,14 @@ public abstract class Context {
    @SystemApi
    public static final String VIRTUALIZATION_SERVICE = "virtualization";

    /**
     * Use with {@link #getSystemService(String)} to retrieve a
     * {@link GrammaticalInflectionManager}.
     *
     * @see #getSystemService(String)
     */
    public static final String GRAMMATICAL_INFLECTION_SERVICE = "grammatical_inflection";

    /**
     * Determine whether the given permission is allowed for a particular
     * process and user ID running in the system.
Loading