From 68f793679ec0840746cf7ca9490cb3dfd8096689 Mon Sep 17 00:00:00 2001 From: TYM Tsai Date: Wed, 14 Jul 2021 08:41:06 +0800 Subject: [PATCH] Make parents important for Content Capture A view is important for content capture, its parents are also important for content capture. So sets the cache of its parents become important for content capture and send out its parent's appeared event. Bug: 180059047 Test: manual 1.new conversation and receive new message 2.switch between different conversations check sent events for fullly view hierarchy Test: atest CtsContentCaptureServiceTestCases Change-Id: I700989650dd36555841d65d74e532f001e419416 --- core/java/android/view/View.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index d68e08526483d..af1acdc069aa4 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -10131,6 +10131,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, setNotifiedContentCaptureAppeared(); if (ai != null) { + makeParentImportantAndNotifyAppearedEventIfNeed(); ai.delayNotifyContentCaptureEvent(session, this, appeared); } else { if (DEBUG_CONTENT_CAPTURE) { @@ -10158,6 +10159,22 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } + private void makeParentImportantAndNotifyAppearedEventIfNeed() { + // If view sent the appeared event to Content Capture, Content Capture also + // would like to receive its parents' appeared events. So checks its parents + // whether the appeared event is sent or not. If not, send the appeared event. + final ViewParent parent = getParent(); + if (parent instanceof View) { + View p = ((View) parent); + if (p.getNotifiedContentCaptureAppeared()) { + return; + } + // Set important for content capture in the cache. + p.mPrivateFlags4 |= PFLAG4_CONTENT_CAPTURE_IMPORTANCE_MASK; + p.notifyAppearedOrDisappearedForContentCaptureIfNeeded(/* appeared */ true); + } + } + private void setNotifiedContentCaptureAppeared() { mPrivateFlags4 |= PFLAG4_NOTIFIED_CONTENT_CAPTURE_APPEARED; mPrivateFlags4 &= ~PFLAG4_NOTIFIED_CONTENT_CAPTURE_DISAPPEARED;