From 029f10100cced4a0dd6b07b26b0ffd670881aa47 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Mon, 22 Jan 2018 11:53:44 -0800 Subject: [PATCH] Changed onGetScores() to return null instead of throwing exception. Callers (Session and AFMShellCommand) already handle null (in fact, the signature declares it as @Nullable), so there's no point on throwing a runtime exception... Bug: 70939974 Test: 'adb shell cmd autofill get fc_score half kale' when service APK was not implementing it. Change-Id: I37da6cd13c40545626332c272759e797b5a25924 --- .../autofill/AutofillFieldClassificationService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/java/android/service/autofill/AutofillFieldClassificationService.java b/core/java/android/service/autofill/AutofillFieldClassificationService.java index 4e4caf04579f0..df63a91790d88 100644 --- a/core/java/android/service/autofill/AutofillFieldClassificationService.java +++ b/core/java/android/service/autofill/AutofillFieldClassificationService.java @@ -99,7 +99,9 @@ public abstract class AutofillFieldClassificationService extends Service { final String[] userDataValues = (String[]) args.arg5; final float[][] scores = onGetScores(algorithmName, algorithmArgs, actualValues, Arrays.asList(userDataValues)); - data.putParcelable(EXTRA_SCORES, new Scores(scores)); + if (scores != null) { + data.putParcelable(EXTRA_SCORES, new Scores(scores)); + } break; default: Log.w(TAG, "Handling unknown message: " + action); @@ -148,7 +150,8 @@ public abstract class AutofillFieldClassificationService extends Service { public float[][] onGetScores(@Nullable String algorithm, @Nullable Bundle args, @NonNull List actualValues, @NonNull List userDataValues) { - throw new UnsupportedOperationException("Must be implemented by external service"); + Log.e(TAG, "service implementation (" + getClass() + " does not implement onGetScore()"); + return null; } private final class AutofillFieldClassificationServiceWrapper @@ -182,7 +185,7 @@ public abstract class AutofillFieldClassificationService extends Service { } } - private Scores(float[][] scores) { + private Scores(float[][] scores) { this.scores = scores; }