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

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

Added DeviceConfig properties for Augmented Autofill service timeouts.

Test: manual verification
Bug: 123100811

Change-Id: I82749b4cea5fe90998efa0798fb6b032a8470086
parent dbd04bb6
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -371,6 +371,24 @@ public final class AutofillManager {
    public static final String DEVICE_CONFIG_AUTOFILL_SMART_SUGGESTION_SUPPORTED_MODES =
            "smart_suggestion_supported_modes";

    /**
     * Sets how long (in ms) the augmented autofill service is bound while idle.
     *
     * <p>Use {@code 0} to keep it permanently bound.
     *
     * @hide
     */
    public static final String DEVICE_CONFIG_AUGMENTED_SERVICE_IDLE_UNBIND_TIMEOUT =
            "augmented_service_idle_unbind_timeout";

    /**
     * Sets how long (in ms) the augmented autofill service request is killed if not replied.
     *
     * @hide
     */
    public static final String DEVICE_CONFIG_AUGMENTED_SERVICE_REQUEST_TIMEOUT =
            "augmented_service_request_timeout";

    /** @hide */
    public static final int RESULT_OK = 0;
    /** @hide */
+43 −22
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import android.view.autofill.IAutoFillManagerClient;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.infra.AbstractRemoteService;
import com.android.internal.os.IResultReceiver;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.Preconditions;
@@ -109,6 +110,8 @@ public final class AutofillManagerService
    private static final char COMPAT_PACKAGE_URL_IDS_BLOCK_BEGIN = '[';
    private static final char COMPAT_PACKAGE_URL_IDS_BLOCK_END = ']';

    private static final int DEFAULT_AUGMENTED_AUTOFILL_REQUEST_TIMEOUT_MILLIS = 5_000;

    /**
     * Maximum number of partitions that can be allowed in a session.
     *
@@ -162,6 +165,11 @@ public final class AutofillManagerService
    @GuardedBy("mLock")
    private int mSupportedSmartSuggestionModes;

    @GuardedBy("mLock")
    int mAugmentedServiceIdleUnbindTimeoutMs;
    @GuardedBy("mLock")
    int mAugmentedServiceRequestTimeoutMs;

    public AutofillManagerService(Context context) {
        super(context,
                new SecureSettingsServiceNameResolver(context, Settings.Secure.AUTOFILL_SERVICE),
@@ -171,12 +179,12 @@ public final class AutofillManagerService

        DeviceConfig.addOnPropertyChangedListener(DeviceConfig.NAMESPACE_AUTOFILL,
                ActivityThread.currentApplication().getMainExecutor(),
                (namespace, name, value) -> setSmartSuggestionModesFromDeviceConfig(value));
                (namespace, key, value) -> onDeviceConfigChange(key, value));

        setLogLevelFromSettings();
        setMaxPartitionsFromSettings();
        setMaxVisibleDatasetsFromSettings();
        setSmartSuggestionModesFromDeviceConfig();
        setDeviceConfigProperties();

        final IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
@@ -227,6 +235,18 @@ public final class AutofillManagerService
        }
    }

    private void onDeviceConfigChange(@NonNull String key, @Nullable String value) {
        switch (key) {
            case AutofillManager.DEVICE_CONFIG_AUTOFILL_SMART_SUGGESTION_SUPPORTED_MODES:
            case AutofillManager.DEVICE_CONFIG_AUGMENTED_SERVICE_IDLE_UNBIND_TIMEOUT:
            case AutofillManager.DEVICE_CONFIG_AUGMENTED_SERVICE_REQUEST_TIMEOUT:
                setDeviceConfigProperties();
                break;
            default:
                Slog.i(mTag, "Ignoring change on " + key);
        }
    }

    @Override // from AbstractMasterSystemService
    protected AutofillManagerServiceImpl newServiceLocked(@UserIdInt int resolvedUserId,
            boolean disabled) {
@@ -457,27 +477,24 @@ public final class AutofillManagerService
        }
    }

    private void setSmartSuggestionModesFromDeviceConfig() {
        final String value = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_AUTOFILL,
                AutofillManager.DEVICE_CONFIG_AUTOFILL_SMART_SUGGESTION_SUPPORTED_MODES);
        setSmartSuggestionModesFromDeviceConfig(value);
    }

    private void setSmartSuggestionModesFromDeviceConfig(@Nullable String value) {
        if (sDebug) Slog.d(TAG, "setSmartSuggestionEmulationFromDeviceConfig(): value=" + value);
        final int flags;
        if (value == null) {
            flags = AutofillManager.FLAG_SMART_SUGGESTION_SYSTEM;
        } else {
            try {
                flags = Integer.parseInt(value);
            } catch (Exception e) {
                Slog.w(TAG, "setSmartSuggestionEmulationFromDeviceConfig(): NAN:" + value);
                return;
            }
        }
    private void setDeviceConfigProperties() {
        synchronized (mLock) {
            mSupportedSmartSuggestionModes = flags;
            mAugmentedServiceIdleUnbindTimeoutMs = Helper.getIntDeviceConfigProperty(
                    AutofillManager.DEVICE_CONFIG_AUGMENTED_SERVICE_IDLE_UNBIND_TIMEOUT,
                    (int) AbstractRemoteService.PERMANENT_BOUND_TIMEOUT_MS);
            mAugmentedServiceRequestTimeoutMs = Helper.getIntDeviceConfigProperty(
                    AutofillManager.DEVICE_CONFIG_AUGMENTED_SERVICE_REQUEST_TIMEOUT,
                    DEFAULT_AUGMENTED_AUTOFILL_REQUEST_TIMEOUT_MILLIS);
            mSupportedSmartSuggestionModes = Helper.getIntDeviceConfigProperty(
                    AutofillManager.DEVICE_CONFIG_AUTOFILL_SMART_SUGGESTION_SUPPORTED_MODES,
                    AutofillManager.FLAG_SMART_SUGGESTION_SYSTEM);
            if (verbose) {
                Slog.v(mTag, "setDeviceConfigProperties(): "
                        + "augmentedIdleTimeout=" + mAugmentedServiceIdleUnbindTimeoutMs
                        + ", augmentedRequestTimeout=" + mAugmentedServiceRequestTimeoutMs
                        + ", smartSuggestionMode="
                        + getSmartSuggestionModeToString(mSupportedSmartSuggestionModes));
            }
        }
    }

@@ -1280,6 +1297,10 @@ public final class AutofillManagerService
                        pw.print("Smart Suggestion modes: ");
                        pw.println(getSmartSuggestionModeToString(mSupportedSmartSuggestionModes));
                    }
                    pw.print("Augmented Service Idle Unbind Timeout: ");
                    pw.println(mAugmentedServiceIdleUnbindTimeoutMs);
                    pw.print("Augmented Service Request Timeout: ");
                    pw.println(mAugmentedServiceRequestTimeoutMs);
                    if (showHistory) {
                        pw.println(); pw.println("Requests history:"); pw.println();
                        mRequestsHistory.reverseDump(fd, pw, args);
+4 −2
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ final class AutofillManagerServiceImpl
    private static final int MAX_SESSION_ID_CREATE_TRIES = 2048;

    /** Minimum interval to prune abandoned sessions */
    private static final int MAX_ABANDONED_SESSION_MILLIS = 30000;
    private static final int MAX_ABANDONED_SESSION_MILLIS = 30_000;

    private final AutoFillUI mUi;
    private final MetricsLogger mMetricsLogger = new MetricsLogger();
@@ -1087,7 +1087,9 @@ final class AutofillManagerServiceImpl
                            }
                            mRemoteAugmentedAutofillService = null;
                        }
                    }, mMaster.isInstantServiceAllowed(), mMaster.verbose);
                    }, mMaster.isInstantServiceAllowed(), mMaster.verbose,
                    mMaster.mAugmentedServiceIdleUnbindTimeoutMs,
                    mMaster.mAugmentedServiceRequestTimeoutMs);
        }

        return mRemoteAugmentedAutofillService;
+17 −0
Original line number Diff line number Diff line
@@ -22,9 +22,11 @@ import android.app.assist.AssistStructure;
import android.app.assist.AssistStructure.ViewNode;
import android.content.ComponentName;
import android.metrics.LogMaker;
import android.provider.DeviceConfig;
import android.service.autofill.Dataset;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.util.Slog;
import android.view.WindowManager;
import android.view.autofill.AutofillId;
@@ -205,6 +207,21 @@ public final class Helper {
        }
    }

    /**
     * Gets the value of a device config property from the Autofill namespace.
     */
    static int getIntDeviceConfigProperty(@NonNull String key, int defaultValue) {
        final String value = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_AUTOFILL, key);
        if (value == null) return defaultValue;

        try {
            return Integer.parseInt(value);
        } catch (Exception e) {
            Log.w(TAG, "error parsing value (" + value + ") of property " + key + ": " + e);
            return defaultValue;
        }
    }

    private interface ViewNodeFilter {
        boolean matches(ViewNode node);
    }
+9 −6
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.os.SystemClock;
import android.service.autofill.augmented.AugmentedAutofillService;
import android.service.autofill.augmented.IAugmentedAutofillService;
import android.service.autofill.augmented.IFillCallback;
import android.text.format.DateUtils;
import android.util.Pair;
import android.util.Slog;
import android.view.autofill.AutofillId;
@@ -48,13 +47,17 @@ final class RemoteAugmentedAutofillService

    private static final String TAG = RemoteAugmentedAutofillService.class.getSimpleName();

    private static final long TIMEOUT_REMOTE_REQUEST_MILLIS = 5 * DateUtils.SECOND_IN_MILLIS;
    private final int mIdleUnbindTimeoutMs;
    private final int mRequestTimeoutMs;

    RemoteAugmentedAutofillService(Context context, ComponentName serviceName,
            int userId, RemoteAugmentedAutofillServiceCallbacks callbacks,
            boolean bindInstantServiceAllowed, boolean verbose) {
            boolean bindInstantServiceAllowed, boolean verbose, int idleUnbindTimeoutMs,
            int requestTimeoutMs) {
        super(context, AugmentedAutofillService.SERVICE_INTERFACE, serviceName, userId, callbacks,
                bindInstantServiceAllowed, verbose);
        mIdleUnbindTimeoutMs = idleUnbindTimeoutMs;
        mRequestTimeoutMs = requestTimeoutMs;

        // Bind right away.
        scheduleBind();
@@ -108,12 +111,12 @@ final class RemoteAugmentedAutofillService

    @Override // from AbstractRemoteService
    protected long getTimeoutIdleBindMillis() {
        return PERMANENT_BOUND_TIMEOUT_MS;
        return mIdleUnbindTimeoutMs;
    }

    @Override // from AbstractRemoteService
    protected long getRemoteRequestMillis() {
        return TIMEOUT_REMOTE_REQUEST_MILLIS;
        return mRequestTimeoutMs;
    }

    /**
@@ -209,7 +212,7 @@ final class RemoteAugmentedAutofillService
        protected void onTimeout(RemoteAugmentedAutofillService remoteService) {
            // TODO(b/122858578): must update the logged AUTOFILL_AUGMENTED_REQUEST with the
            // timeout
            Slog.w(TAG, "PendingAutofillRequest timed out (" + TIMEOUT_REMOTE_REQUEST_MILLIS
            Slog.w(TAG, "PendingAutofillRequest timed out (" + remoteService.mRequestTimeoutMs
                    + "ms) for " + remoteService);
            // NOTE: so far we don't need notify RemoteAugmentedAutofillServiceCallbacks
            finish();
Loading