diff options
| author | 2018-01-17 15:12:17 -0800 | |
|---|---|---|
| committer | 2018-01-18 10:48:17 -0800 | |
| commit | afe65dc28a087cf3089593a8dd825136c9f37f9e (patch) | |
| tree | 5d0e9000ce65422c1414c23f5b496d8f12e18b47 | |
| parent | bc055b0ef1c11337b8ec5f681097e7b51e84b9c4 (diff) | |
Implemented shell cmd to get field classification score.
Bug: 70939974
Test: adb shell cmd autofill get fc_score half kale
Change-Id: Idd5d79500e915f61920865f7b721eddfb580d319
| -rw-r--r-- | services/autofill/java/com/android/server/autofill/AutofillManagerService.java | 14 | ||||
| -rw-r--r-- | services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java | 56 |
2 files changed, 57 insertions, 13 deletions
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java index 03708375b311..6d845f9a9d3a 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java @@ -52,6 +52,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.os.UserManagerInternal; import android.provider.Settings; +import android.service.autofill.AutofillFieldClassificationService.Scores; import android.service.autofill.FillEventHistory; import android.service.autofill.UserData; import android.util.LocalLog; @@ -79,6 +80,7 @@ import com.android.server.autofill.ui.AutoFillUI; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -444,7 +446,17 @@ public final class AutofillManagerService extends SystemService { } } - // TODO(b/70291841): add command to get field classification score + // Called by Shell command. + public void getScore(@Nullable String algorithmName, @NonNull String value1, + @NonNull String value2, @NonNull RemoteCallback callback) { + mContext.enforceCallingPermission(MANAGE_AUTO_FILL, TAG); + + final FieldClassificationStrategy strategy = + new FieldClassificationStrategy(mContext, UserHandle.USER_CURRENT); + + strategy.getScores(callback, algorithmName, null, + Arrays.asList(AutofillValue.forText(value1)), new String[] { value2 }); + } private void setDebugLocked(boolean debug) { com.android.server.autofill.Helper.sDebug = debug; diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java index f3de557ec540..24b9fbd59935 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceShellCommand.java @@ -16,11 +16,15 @@ package com.android.server.autofill; +import static android.service.autofill.AutofillFieldClassificationService.EXTRA_SCORES; + import static com.android.server.autofill.AutofillManagerService.RECEIVER_BUNDLE_EXTRA_SESSIONS; import android.os.Bundle; +import android.os.RemoteCallback; import android.os.ShellCommand; import android.os.UserHandle; +import android.service.autofill.AutofillFieldClassificationService.Scores; import android.view.autofill.AutofillManager; import com.android.internal.os.IResultReceiver; @@ -80,13 +84,16 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand { pw.println(" Sets the maximum number of partitions per session."); pw.println(""); pw.println(" list sessions [--user USER_ID]"); - pw.println(" List all pending sessions."); + pw.println(" Lists all pending sessions."); pw.println(""); pw.println(" destroy sessions [--user USER_ID]"); - pw.println(" Destroy all pending sessions."); + pw.println(" Destroys all pending sessions."); pw.println(""); pw.println(" reset"); - pw.println(" Reset all pending sessions and cached service connections."); + pw.println(" Resets all pending sessions and cached service connections."); + pw.println(""); + pw.println(" get fc_score [--algorithm ALGORITHM] value1 value2"); + pw.println(" Gets the field classification score for 2 fields."); pw.println(""); } } @@ -98,6 +105,8 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand { return getLogLevel(pw); case "max_partitions": return getMaxPartitions(pw); + case "fc_score": + return getFieldClassificationScore(pw); default: pw.println("Invalid set: " + what); return -1; @@ -164,6 +173,35 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand { return 0; } + private int getFieldClassificationScore(PrintWriter pw) { + final String nextArg = getNextArgRequired(); + final String algorithm, value1; + if ("--algorithm".equals(nextArg)) { + algorithm = getNextArgRequired(); + value1 = getNextArgRequired(); + } else { + algorithm = null; + value1 = nextArg; + } + final String value2 = getNextArgRequired(); + + final CountDownLatch latch = new CountDownLatch(1); + mService.getScore(algorithm, value1, value2, new RemoteCallback((result) -> { + final Scores scores = result.getParcelable(EXTRA_SCORES); + if (scores == null) { + pw.println("no score"); + } else { + pw.print("algorithm: "); + pw.print(scores.getAlgorithmName()); + pw.print(" score: "); + pw.println(scores.getScores()[0][0]); + } + latch.countDown(); + })); + + return waitForLatch(pw, latch); + } + private int requestDestroy(PrintWriter pw) { if (!isNextArgSessions(pw)) { return -1; @@ -210,19 +248,13 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand { return true; } - private boolean isNextArgLogLevel(PrintWriter pw, String cmd) { - final String type = getNextArgRequired(); - if (!type.equals("log_level")) { - pw.println("Error: invalid " + cmd + " type: " + type); - return false; - } - return true; - } - private int requestSessionCommon(PrintWriter pw, CountDownLatch latch, Runnable command) { command.run(); + return waitForLatch(pw, latch); + } + private int waitForLatch(PrintWriter pw, CountDownLatch latch) { try { final boolean received = latch.await(5, TimeUnit.SECONDS); if (!received) { |