From ef0af93c7c42df3cb64694a6a1e87467fa352238 Mon Sep 17 00:00:00 2001 From: Simranjit Kohli Date: Sun, 7 May 2023 12:21:07 -0700 Subject: [PATCH] [Autofill PCC]: Optimize PCC Detection calling PCC Detection feature should only be enabled if both conditions are satisfied. 1. flag:pcc_classification_enabled is enabled 2. Device has config: config_defaultFieldClassificationService defined. In the absence of either of the above, PCC feature should be turned off. Test: atest CtsAutoFillServiceTestCases The above 'atest CtsAutoFillServiceTestCases' was ran in two cases 1. config_defaultFieldClassificationService not present on device. 2. config_defaultFieldClassificationService defined on the device. Also, ran through Autofill usecase manually. Bug: 279610519 Merged-In: I92f509b150586f7ad35580240a2981c1d31f10a9 Change-Id: I92f509b150586f7ad35580240a2981c1d31f10a9 --- .../server/autofill/AutofillManagerService.java | 10 ++++++++-- .../autofill/AutofillManagerServiceImpl.java | 17 +++++++++++++++++ .../AutofillManagerServiceShellCommand.java | 11 +++++++++++ .../com/android/server/autofill/Session.java | 6 +++--- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java index af5b196fe93db..fc758cba617f5 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java @@ -760,6 +760,12 @@ public final class AutofillManagerService return false; } + // Called by Shell command + String getFieldDetectionServiceName(@UserIdInt int userId) { + enforceCallingPermissionForManagement(); + return mFieldClassificationResolver.readServiceName(userId); + } + // Called by Shell command boolean setTemporaryDetectionService(@UserIdInt int userId, @NonNull String serviceName, int durationMs) { @@ -903,9 +909,9 @@ public final class AutofillManagerService } /** - * Whether the Autofill PCC Classification feature is enabled. + * Whether the Autofill PCC Classification feature flag is enabled. */ - public boolean isPccClassificationEnabled() { + public boolean isPccClassificationFlagEnabled() { synchronized (mFlagLock) { return mPccClassificationEnabled; } diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java index d5dcdaf3c7b04..63a607c8d0d47 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java @@ -1730,6 +1730,23 @@ final class AutofillManagerServiceImpl return mRemoteFieldClassificationService; } + + public boolean isPccClassificationEnabled() { + boolean result = isPccClassificationEnabledInternal(); + if (sVerbose) { + Slog.v(TAG, "pccEnabled: " + result); + } + return result; + } + + public boolean isPccClassificationEnabledInternal() { + boolean flagEnabled = mMaster.isPccClassificationFlagEnabled(); + if (!flagEnabled) return false; + synchronized (mLock) { + return getRemoteFieldClassificationServiceLocked() != null; + } + } + /** * Called when the {@link AutofillManagerService#mFieldClassificationResolver} * changed (among other places). diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java index 62a29705f62e9..4aeb4a4f84096 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java @@ -26,6 +26,7 @@ import android.os.RemoteCallback; import android.os.ShellCommand; import android.os.UserHandle; import android.service.autofill.AutofillFieldClassificationService.Scores; +import android.text.TextUtils; import android.view.autofill.AutofillManager; import com.android.internal.os.IResultReceiver; @@ -154,6 +155,8 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand { return getBindInstantService(pw); case "default-augmented-service-enabled": return getDefaultAugmentedServiceEnabled(pw); + case "field-detection-service-enabled": + return isFieldDetectionServiceEnabled(pw); case "saved-password-count": return getSavedPasswordCount(pw); default: @@ -343,6 +346,14 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand { return 0; } + private int isFieldDetectionServiceEnabled(PrintWriter pw) { + final int userId = getNextIntArgRequired(); + String name = mService.getFieldDetectionServiceName(userId); + boolean enabled = !TextUtils.isEmpty(name); + pw.println(enabled); + return 0; + } + private int setTemporaryAugmentedService(PrintWriter pw) { final int userId = getNextIntArgRequired(); final String serviceName = getNextArg(); diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index fb94af65513fb..2233f52ff2dae 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -798,7 +798,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState * Returns empty list if PCC is off or no types available */ private List getTypeHintsForProvider() { - if (!mService.getMaster().isPccClassificationEnabled()) { + if (!mService.isPccClassificationEnabled()) { return Collections.EMPTY_LIST; } final String typeHints = mService.getMaster().getPccProviderHints(); @@ -1200,7 +1200,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState // structure is taken. This causes only one fill request per burst of focus changes. cancelCurrentRequestLocked(); - if (mService.getMaster().isPccClassificationEnabled() + if (mService.isPccClassificationEnabled() && mClassificationState.mHintsToAutofillIdMap == null) { if (sVerbose) { Slog.v(TAG, "triggering field classification"); @@ -1631,7 +1631,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState Slog.d(TAG, "DBG: computeDatasetsForProviderAndUpdateContainer: " + autofillProviderContainer); } - if (!mService.getMaster().isPccClassificationEnabled()) { + if (!mService.isPccClassificationEnabled()) { if (sVerbose) { Slog.v(TAG, "PCC classification is disabled"); }