Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a6a99d2 authored by Abodunrinwa Toki's avatar Abodunrinwa Toki Committed by Android (Google) Code Review
Browse files

Merge "TextClassificationManager: Avoid exposing lock."

parents 80f42edf b89cf026
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -47282,7 +47282,7 @@ package android.view.textclassifier {
  public final class TextClassificationManager {
    method public java.util.List<android.view.textclassifier.TextLanguage> detectLanguages(java.lang.CharSequence);
    method public synchronized android.view.textclassifier.TextClassifier getDefaultTextClassifier();
    method public android.view.textclassifier.TextClassifier getDefaultTextClassifier();
  }
  public final class TextClassificationResult {
+1 −1
Original line number Diff line number Diff line
@@ -50701,7 +50701,7 @@ package android.view.textclassifier {
  public final class TextClassificationManager {
    method public java.util.List<android.view.textclassifier.TextLanguage> detectLanguages(java.lang.CharSequence);
    method public synchronized android.view.textclassifier.TextClassifier getDefaultTextClassifier();
    method public android.view.textclassifier.TextClassifier getDefaultTextClassifier();
  }
  public final class TextClassificationResult {
+1 −1
Original line number Diff line number Diff line
@@ -47595,7 +47595,7 @@ package android.view.textclassifier {
  public final class TextClassificationManager {
    method public java.util.List<android.view.textclassifier.TextLanguage> detectLanguages(java.lang.CharSequence);
    method public synchronized android.view.textclassifier.TextClassifier getDefaultTextClassifier();
    method public android.view.textclassifier.TextClassifier getDefaultTextClassifier();
  }
  public final class TextClassificationResult {
+24 −17
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ public final class TextClassificationManager {

    private static final String LOG_TAG = "TextClassificationManager";

    private final Object mTextClassifierLock = new Object();
    private final Object mLangIdLock = new Object();

    private final Context mContext;
    // TODO: Implement a way to close the file descriptor.
    private ParcelFileDescriptor mFd;
@@ -55,7 +58,8 @@ public final class TextClassificationManager {
    /**
     * Returns the default text classifier.
     */
    public synchronized TextClassifier getDefaultTextClassifier() {
    public TextClassifier getDefaultTextClassifier() {
        synchronized (mTextClassifierLock) {
            if (mDefault == null) {
                try {
                    mFd = ParcelFileDescriptor.open(
@@ -69,6 +73,7 @@ public final class TextClassificationManager {
            }
            return mDefault;
        }
    }

    /**
     * Returns information containing languages that were detected in the provided text.
@@ -95,7 +100,8 @@ public final class TextClassificationManager {
        return Collections.emptyList();
    }

    private synchronized LangId getLanguageDetector() {
    private LangId getLanguageDetector() {
        synchronized (mLangIdLock) {
            if (mLangId == null) {
                // TODO: Use a file descriptor as soon as we start to depend on a model file
                // for language detection.
@@ -104,3 +110,4 @@ public final class TextClassificationManager {
            return mLangId;
        }
    }
}
+8 −4
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ final class TextClassifierImpl implements TextClassifier {

    private static final String LOG_TAG = "TextClassifierImpl";

    private final Object mSmartSelectionLock = new Object();

    private final Context mContext;
    private final ParcelFileDescriptor mFd;
    private SmartSelection mSmartSelection;
@@ -140,12 +142,14 @@ final class TextClassifierImpl implements TextClassifier {
        return TextClassifier.NO_OP.getLinks(text, linkMask);
    }

    private synchronized SmartSelection getSmartSelection() throws FileNotFoundException {
    private SmartSelection getSmartSelection() throws FileNotFoundException {
        synchronized (mSmartSelectionLock) {
            if (mSmartSelection == null) {
                mSmartSelection = new SmartSelection(mFd.getFd());
            }
            return mSmartSelection;
        }
    }

    private TextClassificationResult createClassificationResult(String type, CharSequence text) {
        final Intent intent = IntentFactory.create(type, text.toString());