From 266752317b7752394e39618f6fe1ad2829e919d8 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 19 Jun 2017 09:45:48 -0700 Subject: Fixed updateAutofillValue() when mText is not set. updateAutofillValue() was crashing some apps when the mText was not set at the time it was called. One solution would be to not set mText at all - since the Autofill Service should rely only on getAutofillValue() - but that could break existing services. Hence, a safer solution is to set that field if it's null. Test: existing CtsAutoFillServiceTestCases tests pass Test: manual verification using Fly Delta app Fixes: 62751039 Change-Id: I91a8e0ed5db4148f5eb5729b8e254aa3531f15e4 --- core/java/android/app/assist/AssistStructure.java | 3 +++ core/java/android/service/autofill/AutofillService.java | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/java/android/app/assist/AssistStructure.java b/core/java/android/app/assist/AssistStructure.java index 266fa7e24b2c..4e8277c388de 100644 --- a/core/java/android/app/assist/AssistStructure.java +++ b/core/java/android/app/assist/AssistStructure.java @@ -1051,6 +1051,9 @@ public class AssistStructure implements Parcelable { public void updateAutofillValue(AutofillValue value) { mAutofillValue = value; if (value.isText()) { + if (mText == null) { + mText = new ViewNodeText(); + } mText.mText = value.getTextValue(); } } diff --git a/core/java/android/service/autofill/AutofillService.java b/core/java/android/service/autofill/AutofillService.java index 9df315b7deab..a90ee93d9852 100644 --- a/core/java/android/service/autofill/AutofillService.java +++ b/core/java/android/service/autofill/AutofillService.java @@ -25,7 +25,6 @@ import android.app.Activity; import android.app.Service; import android.app.assist.AssistStructure; import android.content.Intent; -import android.os.Bundle; import android.os.CancellationSignal; import android.os.IBinder; import android.os.ICancellationSignal; @@ -35,9 +34,6 @@ import android.view.autofill.AutofillManager; import com.android.internal.os.SomeArgs; -import java.util.ArrayList; -import java.util.List; - /** * Top-level service of the current autofill service for a given user. * @@ -192,6 +188,11 @@ public abstract class AutofillService extends Service { * {@link SaveCallback#onSuccess()} or {@link SaveCallback#onFailure(CharSequence)}) * to notify the result of the request. * + *

NOTE: to retrieve the actual value of the field, the service should call + * {@link android.app.assist.AssistStructure.ViewNode#getAutofillValue()}; if it calls + * {@link android.app.assist.AssistStructure.ViewNode#getText()} or other methods, there is no + * guarantee such method will return the most recent value of the field. + * * @param request the {@link SaveRequest request} to handle. * See {@link FillResponse} for examples of multiple-sections requests. * @param callback object used to notify the result of the request. -- cgit v1.2.3-59-g8ed1b