From 31ff1351f1608d84e8e45313c4b661117d9b4b96 Mon Sep 17 00:00:00 2001 From: Tony Mak Date: Tue, 22 Jan 2019 21:26:05 +0000 Subject: [PATCH] Make getLocalTextClassifier public As suggested by security review, the javadoc should mention that the requests will be sent to a textclassifier package if system textclassifier is in use. Make getLocalTextClassifier public so that developers can use it instead if they want to keep the data local. BUG: 119631517 Test: atest TextClassificationManagerTest.java Change-Id: I703c0a26c501c6eacf7c9efc7c21aca835e99fdb --- api/current.txt | 1 + .../TextClassificationManager.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/api/current.txt b/api/current.txt index 7dac82ca94874..a31179a1ace12 100644 --- a/api/current.txt +++ b/api/current.txt @@ -53336,6 +53336,7 @@ package android.view.textclassifier { public final class TextClassificationManager { method @NonNull public android.view.textclassifier.TextClassifier createTextClassificationSession(@NonNull android.view.textclassifier.TextClassificationContext); + method @NonNull public android.view.textclassifier.TextClassifier getLocalTextClassifier(); method @NonNull public android.view.textclassifier.TextClassifier getTextClassifier(); method public void setTextClassificationSessionFactory(@Nullable android.view.textclassifier.TextClassificationSessionFactory); method public void setTextClassifier(@Nullable android.view.textclassifier.TextClassifier); diff --git a/core/java/android/view/textclassifier/TextClassificationManager.java b/core/java/android/view/textclassifier/TextClassificationManager.java index ed862064be67c..10c7adef28fd7 100644 --- a/core/java/android/view/textclassifier/TextClassificationManager.java +++ b/core/java/android/view/textclassifier/TextClassificationManager.java @@ -73,9 +73,16 @@ public final class TextClassificationManager { /** * Returns the text classifier that was set via {@link #setTextClassifier(TextClassifier)}. * If this is null, this method returns a default text classifier (i.e. either the system text - * classifier if one exists, or a local text classifier running in this app.) + * classifier if one exists, or a local text classifier running in this process.) + *

+ * Note that if system textclassifier is in use, requests will be sent to a textclassifier + * package provided from OEM. If you want to make sure the requests are handled in your own + * process, you should consider {@link #getLocalTextClassifier()} instead. However, the local + * textclassifier may return inferior results to those returned by the system + * textclassifier. * * @see #setTextClassifier(TextClassifier) + * @see #getLocalTextClassifier() */ @NonNull public TextClassifier getTextClassifier() { @@ -215,7 +222,13 @@ public final class TextClassificationManager { return TextClassifier.NO_OP; } - private TextClassifier getLocalTextClassifier() { + /** + * Returns a local textclassifier, which is running in this process. + * + * @see #getTextClassifier() + */ + @NonNull + public TextClassifier getLocalTextClassifier() { synchronized (mLock) { if (mLocalTextClassifier == null) { if (getSettings().isLocalTextClassifierEnabled()) {