diff options
| author | Felipe Leme <felipeal@google.com> | 2019-01-03 11:07:25 -0800 |
|---|---|---|
| committer | Felipe Leme <felipeal@google.com> | 2019-01-03 13:02:02 -0800 |
| commit | bef744c48c2f73c4075212c2830b76bddce0616a (patch) | |
| tree | ac3d819409b3e0888dba8504af6bd77e2e839fcb /core/java | |
| parent | 46bbbdd57755fb4e60a9a030f72c9736d2ead73d (diff) | |
Ignore ContentCapture events after the activity stopped.
Test: atest CtsContentCaptureServiceTestCases
Bug: 121033016
Change-Id: I016f13748287f77b7c5f0ceb12a5af1bb2b555ea
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/contentcapture/ContentCaptureSession.java | 20 | ||||
| -rw-r--r-- | core/java/android/view/contentcapture/MainContentCaptureSession.java | 5 |
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 |
