Merge "Move TextClassifier.getLocalTextClassifier() API."
diff --git a/apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java b/apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java
index c506aec..c5d89b2 100644
--- a/apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java
+++ b/apct-tests/perftests/core/src/android/textclassifier/TextClassifierPerfTest.java
@@ -64,7 +64,7 @@
Context context = InstrumentationRegistry.getTargetContext();
TextClassificationManager textClassificationManager =
context.getSystemService(TextClassificationManager.class);
- mTextClassifier = textClassificationManager.getLocalTextClassifier();
+ mTextClassifier = textClassificationManager.getTextClassifier(TextClassifier.LOCAL);
}
@Test
diff --git a/api/current.txt b/api/current.txt
index 833b87b..2b560a4 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -54238,7 +54238,6 @@
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/api/system-current.txt b/api/system-current.txt
index 5c89b05..ea03472 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -6718,7 +6718,8 @@
public abstract class TextClassifierService extends android.app.Service {
ctor public TextClassifierService();
- method public final android.view.textclassifier.TextClassifier getLocalTextClassifier();
+ method public static android.view.textclassifier.TextClassifier getDefaultTextClassifierImplementation(@NonNull android.content.Context);
+ method @Deprecated public final android.view.textclassifier.TextClassifier getLocalTextClassifier();
method @Nullable public final android.os.IBinder onBind(android.content.Intent);
method public abstract void onClassifyText(@Nullable android.view.textclassifier.TextClassificationSessionId, @NonNull android.view.textclassifier.TextClassification.Request, @NonNull android.os.CancellationSignal, @NonNull android.service.textclassifier.TextClassifierService.Callback<android.view.textclassifier.TextClassification>);
method public void onCreateTextClassificationSession(@NonNull android.view.textclassifier.TextClassificationContext, @NonNull android.view.textclassifier.TextClassificationSessionId);
diff --git a/core/java/android/service/textclassifier/TextClassifierService.java b/core/java/android/service/textclassifier/TextClassifierService.java
index 2221d6e..235b8e8 100644
--- a/core/java/android/service/textclassifier/TextClassifierService.java
+++ b/core/java/android/service/textclassifier/TextClassifierService.java
@@ -420,9 +420,21 @@
/**
* Returns a TextClassifier that runs in this service's process.
* If the local TextClassifier is disabled, this returns {@link TextClassifier#NO_OP}.
+ *
+ * @deprecated Use {@link #getDefaultTextClassifierImplementation(Context)} instead.
*/
+ @Deprecated
public final TextClassifier getLocalTextClassifier() {
- final TextClassificationManager tcm = getSystemService(TextClassificationManager.class);
+ // Deprecated: In the future, we may not guarantee that this runs in the service's process.
+ return getDefaultTextClassifierImplementation(this);
+ }
+
+ /**
+ * Returns the platform's default TextClassifier implementation.
+ */
+ public static TextClassifier getDefaultTextClassifierImplementation(@NonNull Context context) {
+ final TextClassificationManager tcm =
+ context.getSystemService(TextClassificationManager.class);
if (tcm != null) {
return tcm.getTextClassifier(TextClassifier.LOCAL);
}
diff --git a/core/java/android/view/textclassifier/TextClassificationManager.java b/core/java/android/view/textclassifier/TextClassificationManager.java
index 10c7ade..d047c55 100644
--- a/core/java/android/view/textclassifier/TextClassificationManager.java
+++ b/core/java/android/view/textclassifier/TextClassificationManager.java
@@ -75,14 +75,10 @@
* 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 process.)
* <p>
- * 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.
+ * Note that requests to the TextClassifier may be handled in an OEM-provided process rather
+ * than in the calling app's process.
*
* @see #setTextClassifier(TextClassifier)
- * @see #getLocalTextClassifier()
*/
@NonNull
public TextClassifier getTextClassifier() {
@@ -224,11 +220,9 @@
/**
* Returns a local textclassifier, which is running in this process.
- *
- * @see #getTextClassifier()
*/
@NonNull
- public TextClassifier getLocalTextClassifier() {
+ private TextClassifier getLocalTextClassifier() {
synchronized (mLock) {
if (mLocalTextClassifier == null) {
if (getSettings().isLocalTextClassifierEnabled()) {