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."

This commit is contained in:
Haoran Zhang
2023-02-06 22:41:07 +00:00
committed by Android (Google) Code Review
2 changed files with 138 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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);
@@ -1061,6 +1150,32 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
return (flags & FLAG_SUPPORTS_FILL_DIALOG) != 0;
}
@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 {
@@ -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.