summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Haoran Zhang <haoranzhang@google.com> 2023-02-06 22:41:07 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-02-06 22:41:07 +0000
commit475712da99116ea06c384aa2e3dce312fc42b687 (patch)
tree8db0077b9243da7e4ef18506f5907638824306c7
parentaff8cdd439c7f70718851e8971e0c395943d8f16 (diff)
parent44999c7c8e2499bc74779be310e7e1194518a3a7 (diff)
Merge "After this change, when user enters a screen, an assist structure will be generated and sent along a field classification request to pcc classification service."
-rw-r--r--core/java/android/view/autofill/AutofillManager.java17
-rw-r--r--services/autofill/java/com/android/server/autofill/Session.java121
2 files changed, 138 insertions, 0 deletions
diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java
index b5764c50ccc2..bdc7333f2751 100644
--- a/core/java/android/view/autofill/AutofillManager.java
+++ b/core/java/android/view/autofill/AutofillManager.java
@@ -19,6 +19,7 @@ package android.view.autofill;
import static android.service.autofill.FillRequest.FLAG_IME_SHOWING;
import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST;
import static android.service.autofill.FillRequest.FLAG_PASSWORD_INPUT_TYPE;
+import static android.service.autofill.FillRequest.FLAG_PCC_DETECTION;
import static android.service.autofill.FillRequest.FLAG_RESET_FILL_DIALOG_STATE;
import static android.service.autofill.FillRequest.FLAG_SUPPORTS_FILL_DIALOG;
import static android.service.autofill.FillRequest.FLAG_VIEW_NOT_FOCUSED;
@@ -1312,6 +1313,22 @@ public final class AutofillManager {
return;
}
+ // Start session with PCC flag to get assist structure and send field classification request
+ // to PCC classification service.
+ if (AutofillFeatureFlags.isAutofillPccClassificationEnabled()) {
+ synchronized (mLock) {
+ final boolean clientAdded = tryAddServiceClientIfNeededLocked();
+ if (clientAdded){
+ startSessionLocked(/* id= */ AutofillId.NO_AUTOFILL_ID,
+ /* bounds= */ null, /* value= */ null, /* flags= */ FLAG_PCC_DETECTION);
+ } else {
+ if (sVerbose) {
+ Log.v(TAG, "not starting session: no service client");
+ }
+ }
+ }
+ }
+
if (mIsFillDialogEnabled
|| ArrayUtils.containsAny(autofillHints, mFillDialogEnabledHints)) {
if (sDebug) {
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 939047fdb622..2b529bfe5e32 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -24,6 +24,7 @@ import static android.service.autofill.FillEventHistory.Event.UI_TYPE_MENU;
import static android.service.autofill.FillEventHistory.Event.UI_TYPE_UNKNOWN;
import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST;
import static android.service.autofill.FillRequest.FLAG_PASSWORD_INPUT_TYPE;
+import static android.service.autofill.FillRequest.FLAG_PCC_DETECTION;
import static android.service.autofill.FillRequest.FLAG_RESET_FILL_DIALOG_STATE;
import static android.service.autofill.FillRequest.FLAG_SUPPORTS_FILL_DIALOG;
import static android.service.autofill.FillRequest.FLAG_VIEW_NOT_FOCUSED;
@@ -384,6 +385,11 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
*/
private final AssistDataReceiverImpl mAssistReceiver = new AssistDataReceiverImpl();
+ /**
+ * Receiver of assist data for pcc purpose
+ */
+ private final PccAssistDataReceiverImpl mPccAssistReceiver = new PccAssistDataReceiverImpl();
+
@Nullable
private ClientSuggestionsSession mClientSuggestionsSession;
@@ -698,6 +704,89 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
}
}
+ /**
+ * Assist Data Receiver for PCC
+ */
+ private final class PccAssistDataReceiverImpl extends IAssistDataReceiver.Stub {
+ // TODO: Uncomment lines below after field classification service definition merged
+ // @GuardedBy("mLock")
+ // private FieldClassificationRequest mPendingFieldClassifitacionRequest;
+ // @GuardedBy("mLock")
+ // private FieldClassificationRequest mLastFieldClassifitacionRequest;
+
+ @GuardedBy("mLock")
+ void maybeRequestFieldClassificationFromServiceLocked() {
+ // TODO: Uncomment lines below after field classification service definition merged
+ // if (mPendingFieldClassifitacionRequest == null) {
+ // return;
+ // }
+ // mLastFieldClassifitacionRequest = mPendingFieldClassifitacionRequest;
+ //
+ // mRemoteFieldClassificationService.onFieldClassificationRequest(
+ // mPendingFieldClassifitacionRequest);
+ //
+ // mPendingFieldClassifitacionRequest = null;
+ }
+
+ @Override
+ public void onHandleAssistData(Bundle resultData) throws RemoteException {
+ // TODO: add a check if pcc field classification service is present
+ final AssistStructure structure = resultData.getParcelable(ASSIST_KEY_STRUCTURE,
+ android.app.assist.AssistStructure.class);
+ if (structure == null) {
+ Slog.e(TAG, "No assist structure for pcc detection - "
+ + "app might have crashed providing it");
+ return;
+ }
+
+ final Bundle receiverExtras = resultData.getBundle(ASSIST_KEY_RECEIVER_EXTRAS);
+ if (receiverExtras == null) {
+ Slog.e(TAG, "No receiver extras for pcc detection - "
+ + "app might have crashed providing it");
+ return;
+ }
+
+ final int requestId = receiverExtras.getInt(EXTRA_REQUEST_ID);
+
+ if (sVerbose) {
+ Slog.v(TAG, "New structure for requestId " + requestId + ": " + structure);
+ }
+
+ synchronized (mLock) {
+ // TODO(b/35708678): Must fetch the data so it's available later on handleSave(),
+ // even if the activity is gone by then, but structure .ensureData() gives a
+ // ONE_WAY warning because system_service could block on app calls. We need to
+ // change AssistStructure so it provides a "one-way" writeToParcel() method that
+ // sends all the data
+ try {
+ structure.ensureDataForAutofill();
+ } catch (RuntimeException e) {
+ wtf(e, "Exception lazy loading assist structure for %s: %s",
+ structure.getActivityComponent(), e);
+ return;
+ }
+
+ final ArrayList<AutofillId> ids = Helper.getAutofillIds(structure,
+ /* autofillableOnly= */false);
+ for (int i = 0; i < ids.size(); i++) {
+ ids.get(i).setSessionId(Session.this.id);
+ }
+
+ // TODO: Uncomment lines below after field classification service definition merged
+ // FieldClassificationRequest request = new FieldClassificationRequest(structure);
+ //
+ // mPendingFieldClassifitacionRequest = request;
+ //
+ // maybeRequestFieldClassificationFromServiceLocked();
+ }
+ }
+
+ @Override
+ public void onHandleAssistScreenshot(Bitmap screenshot) {
+ // Do nothing
+ }
+ }
+
/** Creates {@link PendingIntent} for autofill service to send a delayed fill. */
private PendingIntent createPendingIntent(int requestId) {
Slog.d(TAG, "createPendingIntent for request " + requestId);
@@ -1062,6 +1151,32 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
}
@GuardedBy("mLock")
+ private void requestAssistStructureForPccLocked(int flags) {
+ // Get request id
+ int requestId;
+ // TODO(b/158623971): Update this to prevent possible overflow
+ do {
+ requestId = sIdCounter.getAndIncrement();
+ } while (requestId == INVALID_REQUEST_ID);
+
+ // Call requestAutofilLData
+ try {
+ final Bundle receiverExtras = new Bundle();
+ receiverExtras.putInt(EXTRA_REQUEST_ID, requestId);
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ if (!ActivityTaskManager.getService().requestAutofillData(mPccAssistReceiver,
+ receiverExtras, mActivityToken, flags)) {
+ Slog.w(TAG, "failed to request autofill data for pcc: " + mActivityToken);
+ }
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ } catch (RemoteException e) {
+ }
+ }
+
+ @GuardedBy("mLock")
private void requestAssistStructureLocked(int requestId, int flags) {
try {
final Bundle receiverExtras = new Bundle();
@@ -3095,6 +3210,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
mSessionFlags.mFillDialogDisabled = false;
}
+ /* request assist structure for pcc */
+ if ((flags & FLAG_PCC_DETECTION) != 0) {
+ requestAssistStructureForPccLocked(flags);
+ return;
+ }
+
switch(action) {
case ACTION_START_SESSION:
// View is triggering autofill.