summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chang Li <licha@google.com> 2020-11-25 17:02:31 +0000
committer Chang Li <licha@google.com> 2020-11-27 23:30:13 +0000
commit3650ad14f86d03173149a11961d24a789d97ce54 (patch)
tree30463ee84bbdddb405b5235245915856cb5e580f
parent95290b2266b67edfb4a715505f9c35069f346ec1 (diff)
Always swallow the IllegalStateException from AsyncTask.
Because we use suppliers for TextClassifier, the mTextClassificationHelper::isTextClassifierDestroyed actually always returns false. Always swallows the exception temporarily to unblock other teams. We may want to keep a reference of the TCSession in the AsyncTask and check it ideally (b/174300371). Bug: 174300371 Fix: 172627102 Test: atest AccessibilityTextTraversalTest.java Change-Id: I5988db992956d666e24e608cd99d4fc87fd6820b
-rw-r--r--core/java/android/widget/SelectionActionModeHelper.java29
1 files changed, 6 insertions, 23 deletions
diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java
index a034a7c2dc7e..e08ccfddc4c5 100644
--- a/core/java/android/widget/SelectionActionModeHelper.java
+++ b/core/java/android/widget/SelectionActionModeHelper.java
@@ -156,8 +156,7 @@ public final class SelectionActionModeHelper {
mSmartSelectSprite != null
? this::startSelectionActionModeWithSmartSelectAnimation
: this::startSelectionActionMode,
- mTextClassificationHelper::getOriginalSelection,
- mTextClassificationHelper::isTextClassifierDestroyed)
+ mTextClassificationHelper::getOriginalSelection)
.execute();
}
}
@@ -179,8 +178,7 @@ public final class SelectionActionModeHelper {
mTextClassificationHelper.getTimeoutDuration(),
mTextClassificationHelper::classifyText,
this::startLinkActionMode,
- mTextClassificationHelper::getOriginalSelection,
- mTextClassificationHelper::isTextClassifierDestroyed)
+ mTextClassificationHelper::getOriginalSelection)
.execute();
}
}
@@ -196,8 +194,7 @@ public final class SelectionActionModeHelper {
mTextClassificationHelper.getTimeoutDuration(),
mTextClassificationHelper::classifyText,
this::invalidateActionMode,
- mTextClassificationHelper::getOriginalSelection,
- mTextClassificationHelper::isTextClassifierDestroyed)
+ mTextClassificationHelper::getOriginalSelection)
.execute();
}
}
@@ -995,7 +992,6 @@ public final class SelectionActionModeHelper {
private final Supplier<SelectionResult> mSelectionResultSupplier;
private final Consumer<SelectionResult> mSelectionResultCallback;
private final Supplier<SelectionResult> mTimeOutResultSupplier;
- private final Supplier<Boolean> mIsTextClassifierDestroyedSupplier;
private final TextView mTextView;
private final String mOriginalText;
@@ -1010,16 +1006,13 @@ public final class SelectionActionModeHelper {
@NonNull TextView textView, int timeOut,
@NonNull Supplier<SelectionResult> selectionResultSupplier,
@NonNull Consumer<SelectionResult> selectionResultCallback,
- @NonNull Supplier<SelectionResult> timeOutResultSupplier,
- @NonNull Supplier<Boolean> isTextClassifierDestroyedSupplier) {
+ @NonNull Supplier<SelectionResult> timeOutResultSupplier) {
super(textView != null ? textView.getHandler() : null);
mTextView = Objects.requireNonNull(textView);
mTimeOutDuration = timeOut;
mSelectionResultSupplier = Objects.requireNonNull(selectionResultSupplier);
mSelectionResultCallback = Objects.requireNonNull(selectionResultCallback);
mTimeOutResultSupplier = Objects.requireNonNull(timeOutResultSupplier);
- mIsTextClassifierDestroyedSupplier =
- Objects.requireNonNull(isTextClassifierDestroyedSupplier);
// Make a copy of the original text.
mOriginalText = getText(mTextView).toString();
}
@@ -1033,14 +1026,8 @@ public final class SelectionActionModeHelper {
try {
result = mSelectionResultSupplier.get();
} catch (IllegalStateException e) {
- // Swallows the exception if the text classifier session is destroyed
- if (mIsTextClassifierDestroyedSupplier.get()) {
- Log.w(LOG_TAG,
- "TextClassificationAsyncTask failed because TextClassifier destroyed",
- e);
- } else {
- throw e;
- }
+ // TODO(b/174300371): Only swallows the exception if the TCSession is destroyed
+ Log.w(LOG_TAG, "TextClassificationAsyncTask failed.", e);
}
mTextView.removeCallbacks(onTimeOut);
return result;
@@ -1173,10 +1160,6 @@ public final class SelectionActionModeHelper {
}
}
- public boolean isTextClassifierDestroyed() {
- return mTextClassifier.get().isDestroyed();
- }
-
private boolean isDarkLaunchEnabled() {
return TextClassificationManager.getSettings(mContext).isModelDarkLaunchEnabled();
}