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

Commit cfa0d49b authored by Felipe Leme's avatar Felipe Leme
Browse files

Fixed FieldClassificationStrategy that gets data from the package info.

The metadata-based approach does not work with AAPT2.

Fixes: 80422287
Test: atest FieldsClassificationTest
Test: m -j update-api ExtServices

Change-Id: Ib7b626e77518e7eb4fcb88d85129cb67ed090c28
parent 2e8c7670
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -4524,9 +4524,11 @@ package android.service.autofill {
  public abstract class AutofillFieldClassificationService extends android.app.Service {
    method public android.os.IBinder onBind(android.content.Intent);
    method public float[][] onGetScores(java.lang.String, android.os.Bundle, java.util.List<android.view.autofill.AutofillValue>, java.util.List<java.lang.String>);
    field public static final java.lang.String RESOURCE_AVAILABLE_ALGORITHMS = "autofill_field_classification_available_algorithms";
    field public static final java.lang.String RESOURCE_DEFAULT_ALGORITHM = "autofill_field_classification_default_algorithm";
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.autofill.AutofillFieldClassificationService";
    field public static final java.lang.String SERVICE_META_DATA_KEY_AVAILABLE_ALGORITHMS = "android.autofill.field_classification.available_algorithms";
    field public static final java.lang.String SERVICE_META_DATA_KEY_DEFAULT_ALGORITHM = "android.autofill.field_classification.default_algorithm";
    field public static final deprecated java.lang.String SERVICE_META_DATA_KEY_AVAILABLE_ALGORITHMS = "android.autofill.field_classification.available_algorithms";
    field public static final deprecated java.lang.String SERVICE_META_DATA_KEY_DEFAULT_ALGORITHM = "android.autofill.field_classification.default_algorithm";
  }

}
+20 −0
Original line number Diff line number Diff line
@@ -65,16 +65,36 @@ public abstract class AutofillFieldClassificationService extends Service {
    /**
     * Manifest metadata key for the resource string containing the name of the default field
     * classification algorithm.
     *
     * @deprecated Use {@link #RESOURCE_DEFAULT_ALGORITHM} instead.
     */
    @Deprecated
    public static final String SERVICE_META_DATA_KEY_DEFAULT_ALGORITHM =
            "android.autofill.field_classification.default_algorithm";

    /**
     * Manifest metadata key for the resource string array containing the names of all field
     * classification algorithms provided by the service.
     *
     * @deprecated Use {@link #RESOURCE_AVAILABLE_ALGORITHMS} instead.
     */
    @Deprecated
    public static final String SERVICE_META_DATA_KEY_AVAILABLE_ALGORITHMS =
            "android.autofill.field_classification.available_algorithms";

    /**
     * Name of the resource string containing the name of the default field
     * classification algorithm.
     */
    public static final String RESOURCE_DEFAULT_ALGORITHM =
            "autofill_field_classification_default_algorithm";

   /**
    * Name of the resource string array containing the names of all field
    * classification algorithms provided by the service.
    */
    public static final String RESOURCE_AVAILABLE_ALGORITHMS =
            "autofill_field_classification_available_algorithms";

    /** {@hide} **/
    public static final String EXTRA_SCORES = "scores";
+3 −2
Original line number Diff line number Diff line
@@ -1397,7 +1397,8 @@ public final class AutofillManager {
        final SyncResultReceiver receiver = new SyncResultReceiver();
        try {
            mService.getAvailableFieldClassificationAlgorithms(receiver);
            final String[] algorithms = receiver.getObjectResult(SyncResultReceiver.TYPE_STRING);
            final String[] algorithms = receiver
                    .getObjectResult(SyncResultReceiver.TYPE_STRING_ARRAY);
            return algorithms != null ? Arrays.asList(algorithms) : Collections.emptyList();
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
@@ -2898,7 +2899,7 @@ public final class AutofillManager {
                case TYPE_STRING:
                    return (T) mBundle.getString(EXTRA);
                case TYPE_STRING_ARRAY:
                    return (T) mBundle.getString(EXTRA);
                    return (T) mBundle.getStringArray(EXTRA);
                case TYPE_PARCELABLE:
                    return (T) mBundle.getParcelable(EXTRA);
                default:
+0 −6
Original line number Diff line number Diff line
@@ -55,12 +55,6 @@
            <intent-filter>
                <action android:name="android.service.autofill.AutofillFieldClassificationService" />
            </intent-filter>
            <meta-data
                android:name="android.autofill.field_classification.default_algorithm"
                android:resource="@string/autofill_field_classification_default_algorithm" />
            <meta-data
                android:name="android.autofill.field_classification.available_algorithms"
                android:resource="@array/autofill_field_classification_available_algorithms" />
        </service>

        <library android:name="android.ext.services"/>
+7 −6
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@ package com.android.server.autofill;

import static com.android.server.autofill.Helper.sDebug;
import static com.android.server.autofill.Helper.sVerbose;
import static android.service.autofill.AutofillFieldClassificationService.SERVICE_META_DATA_KEY_AVAILABLE_ALGORITHMS;
import static android.service.autofill.AutofillFieldClassificationService.SERVICE_META_DATA_KEY_DEFAULT_ALGORITHM;
import static android.service.autofill.AutofillFieldClassificationService.RESOURCE_AVAILABLE_ALGORITHMS;
import static android.service.autofill.AutofillFieldClassificationService.RESOURCE_DEFAULT_ALGORITHM;

import android.Manifest;
import android.annotation.MainThread;
@@ -226,7 +226,7 @@ final class FieldClassificationStrategy {
     */
    @Nullable
    String[] getAvailableAlgorithms() {
        return getMetadataValue(SERVICE_META_DATA_KEY_AVAILABLE_ALGORITHMS,
        return getMetadataValue(RESOURCE_AVAILABLE_ALGORITHMS, "array",
                (res, id) -> res.getStringArray(id));
    }

@@ -235,11 +235,12 @@ final class FieldClassificationStrategy {
     */
    @Nullable
    String getDefaultAlgorithm() {
        return getMetadataValue(SERVICE_META_DATA_KEY_DEFAULT_ALGORITHM, (res, id) -> res.getString(id));
        return getMetadataValue(RESOURCE_DEFAULT_ALGORITHM, "string",
                (res, id) -> res.getString(id));
    }

    @Nullable
    private <T> T getMetadataValue(String field, MetadataParser<T> parser) {
    private <T> T getMetadataValue(String field, String type, MetadataParser<T> parser) {
        final ServiceInfo serviceInfo = getServiceInfo();
        if (serviceInfo == null) return null;

@@ -253,7 +254,7 @@ final class FieldClassificationStrategy {
            return null;
        }

        final int resourceId = serviceInfo.metaData.getInt(field);
        final int resourceId = res.getIdentifier(field, type, serviceInfo.packageName);
        return parser.get(res, resourceId);
    }