Move TextClassifier.getLocalTextClassifier() API.

In the future, we think the TextClassifier is going to run in an
external process. This CL moves the getLocalTextClassifier() API so
that we don't have to guarantee this to apps.
OEMs implementing TextClassifierServices however will want access to
this API so this CL effectively moves the the API from where apps
typically look for a TC (we prefer apps to call getTextClassifier()
instead) to where TCS implementations are most likely to be accessing
such APIs. The method is also renamed appropriately to what it will be
long term (i.e. the default TC implementation rather than as the local
TC).

Bug: 123681286
Test: atest core/tests/coretests/src/android/view/textclassifier
Test: atest cts/tests/tests/view/src/android/view/textclassifier/cts
Test: adb shell am instrument -w -e class android.textclassifier.TextClassifierPerfTest com.android.perftests.core/androidx.test.runner.AndroidJUnitRunner
Change-Id: I685e2b5263ffddbe301256fc2ed0d6254c3357ed
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 6f2751d..d99cdd5a 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -54189,7 +54189,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 0df3b74..50f5d280 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -6646,7 +6646,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()) {