summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-01-04 00:35:37 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-01-04 00:35:37 +0000
commit358acd5854467c015886ffbcaca0af5413127366 (patch)
treedd453e2d956697c01fecc8baab95ba4b82cebda6 /core/java/android
parent2e425c6fb733ba0092b1c7fa4efa618229b78cc7 (diff)
parentbef744c48c2f73c4075212c2830b76bddce0616a (diff)
Merge "Ignore ContentCapture events after the activity stopped."
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/view/contentcapture/ContentCaptureSession.java20
-rw-r--r--core/java/android/view/contentcapture/MainContentCaptureSession.java5
2 files changed, 18 insertions, 7 deletions
diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java
index 9f666a40bef3..fb6cacf44b45 100644
--- a/core/java/android/view/contentcapture/ContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/ContentCaptureSession.java
@@ -34,6 +34,7 @@ import dalvik.system.CloseGuard;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* Session used to notify a system-provided Content Capture service about events associated with
@@ -90,6 +91,12 @@ public abstract class ContentCaptureSession implements AutoCloseable {
private final CloseGuard mCloseGuard = CloseGuard.get();
+ /**
+ * Guard use to ignore events after it's destroyed.
+ */
+ @NonNull
+ private final AtomicBoolean mDestroyed = new AtomicBoolean();
+
/** @hide */
@Nullable
protected final String mId = UUID.randomUUID().toString();
@@ -157,10 +164,10 @@ public abstract class ContentCaptureSession implements AutoCloseable {
* <p>Once destroyed, any new notification will be dropped.
*/
public final void destroy() {
- //TODO(b/111276913): mark it as destroyed so other methods are ignored (and test on CTS)
-
- //TODO(b/111276913): probably shouldn't check for it
- if (!isContentCaptureEnabled()) return;
+ if (!mDestroyed.compareAndSet(false, true)) {
+ Log.e(mTag, "destroy(): already destroyed");
+ return;
+ }
mCloseGuard.close();
@@ -298,10 +305,13 @@ public abstract class ContentCaptureSession implements AutoCloseable {
return new ViewNode.ViewStructureImpl(parentId, virtualId);
}
- abstract boolean isContentCaptureEnabled();
+ boolean isContentCaptureEnabled() {
+ return !mDestroyed.get();
+ }
@CallSuper
void dump(@NonNull String prefix, @NonNull PrintWriter pw) {
+ pw.print(prefix); pw.print("destroyed: "); pw.println(mDestroyed.get());
if (mChildren != null && !mChildren.isEmpty()) {
final String prefix2 = prefix + " ";
final int numberChildren = mChildren.size();
diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java
index 92e0187f5b0f..12c50ce3e13d 100644
--- a/core/java/android/view/contentcapture/MainContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java
@@ -219,7 +219,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
/**
* Callback from {@code system_server} after call to
* {@link IContentCaptureManager#startSession(int, IBinder, ComponentName, String,
- * ContentCaptureContext, int, IResultReceiver)}.
+ * int, IResultReceiver)}.
*
* @param resultCode session state
* @param binder handle to {@code IContentCaptureDirectManager}
@@ -425,7 +425,8 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
@Override
boolean isContentCaptureEnabled() {
- return mSystemServerInterface != null && !mDisabled.get();
+ return super.isContentCaptureEnabled() && mSystemServerInterface != null
+ && !mDisabled.get();
}
// TODO(b/121033016): refactor "notifyXXXX" methods below to a common "Buffer" object that is