From 101ea3e4e55c08b11f54d50d20fb8bfc9cb5a393 Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Mon, 24 Jul 2023 10:37:52 -0700 Subject: [PATCH 1/2] Restoring starting capturing existing activity. ag/24138143 made the rule to produce empty captures in many cases. ag/24138143 aimed to fix a leak that was caused by a local var alreadyOpenActivity still referring the activity when the leak check executes. Fixing that by moving the variable to a method startCapturingExistingActivity. Bug: 291638593 Test: local, presubmit Flag: N/A Change-Id: I281202488c6c85e2e2c5b5b3300e26d808167104 --- .../com/android/quickstep/FallbackRecentsTest.java | 3 ++- .../launcher3/ui/AbstractLauncherUiTest.java | 3 ++- .../android/launcher3/util/rule/ViewCaptureRule.kt | 14 +++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index bc90db0fc1..a67d787842 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -116,7 +116,8 @@ public class FallbackRecentsTest { Utilities.enableRunningInTestHarnessForTests(); } - final ViewCaptureRule viewCaptureRule = new ViewCaptureRule(); + final ViewCaptureRule viewCaptureRule = new ViewCaptureRule( + RecentsActivity.ACTIVITY_TRACKER::getCreatedActivity); mOrderSensitiveRules = RuleChain .outerRule(new SamplerRule()) .around(new NavigationModeSwitchRule(mLauncher)) diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index f061fab105..d22a353707 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -201,7 +201,8 @@ public abstract class AbstractLauncherUiTest { } protected TestRule getRulesInsideActivityMonitor() { - final ViewCaptureRule viewCaptureRule = new ViewCaptureRule(); + final ViewCaptureRule viewCaptureRule = new ViewCaptureRule( + Launcher.ACTIVITY_TRACKER::getCreatedActivity); final RuleChain inner = RuleChain .outerRule(new PortraitLandscapeRunner(this)) .around(new FailureWatcher(mLauncher, viewCaptureRule::getViewCaptureData)) diff --git a/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt b/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt index 1ca4434b82..ab2410a531 100644 --- a/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt +++ b/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt @@ -25,6 +25,7 @@ import com.android.app.viewcapture.ViewCapture.MAIN_EXECUTOR import com.android.app.viewcapture.data.ExportedData import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter import com.android.launcher3.util.viewcapture_analysis.ViewCaptureAnalyzer +import java.util.function.Supplier import org.junit.rules.TestRule import org.junit.runner.Description import org.junit.runners.model.Statement @@ -35,7 +36,7 @@ import org.junit.runners.model.Statement * * This rule will not work in OOP tests that don't have access to the activity under test. */ -class ViewCaptureRule : TestRule { +class ViewCaptureRule(var alreadyOpenActivitySupplier: Supplier) : TestRule { private val viewCapture = SimpleViewCapture("test-view-capture") var viewCaptureData: ExportedData? = null private set @@ -46,6 +47,8 @@ class ViewCaptureRule : TestRule { viewCaptureData = null val windowListenerCloseables = mutableListOf() + startCapturingExistingActivity(windowListenerCloseables) + val lifecycleCallbacks = object : ActivityLifecycleCallbacksAdapter { override fun onActivityCreated(activity: Activity, bundle: Bundle?) { @@ -79,6 +82,15 @@ class ViewCaptureRule : TestRule { ViewCaptureAnalyzer.assertNoAnomalies(viewCaptureData) } + private fun startCapturingExistingActivity( + windowListenerCloseables: MutableCollection + ) { + val alreadyOpenActivity = alreadyOpenActivitySupplier.get() + if (alreadyOpenActivity != null) { + startCapture(windowListenerCloseables, alreadyOpenActivity) + } + } + private fun startCapture( windowListenerCloseables: MutableCollection, activity: Activity From aa79bd9a072e7bb2acfe28b0876100dfa80c9a4c Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Mon, 24 Jul 2023 10:32:53 -0700 Subject: [PATCH 2/2] Verifying that ViewCapture data is not empty Flag: N/A Test: presubmit Bug: 286251603 Change-Id: I45b6f858cfa13a12203a61ee80ac2e7988360d58 --- .../launcher3/util/rule/ViewCaptureRule.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt b/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt index ab2410a531..b4ad1f3542 100644 --- a/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt +++ b/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt @@ -23,8 +23,10 @@ import androidx.test.core.app.ApplicationProvider import com.android.app.viewcapture.SimpleViewCapture import com.android.app.viewcapture.ViewCapture.MAIN_EXECUTOR import com.android.app.viewcapture.data.ExportedData +import com.android.launcher3.tapl.TestHelpers import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter import com.android.launcher3.util.viewcapture_analysis.ViewCaptureAnalyzer +import org.junit.Assert.assertTrue import java.util.function.Supplier import org.junit.rules.TestRule import org.junit.runner.Description @@ -79,7 +81,7 @@ class ViewCaptureRule(var alreadyOpenActivitySupplier: Supplier) : Te MAIN_EXECUTOR.execute { windowListenerCloseables.onEach(SafeCloseable::close) } } - ViewCaptureAnalyzer.assertNoAnomalies(viewCaptureData) + analyzeViewCapture() } private fun startCapturingExistingActivity( @@ -104,4 +106,17 @@ class ViewCaptureRule(var alreadyOpenActivitySupplier: Supplier) : Te } } } + + private fun analyzeViewCapture() { + // OOP tests don't produce ViewCapture data + if (!TestHelpers.isInLauncherProcess()) return + + ViewCaptureAnalyzer.assertNoAnomalies(viewCaptureData) + + var frameCount = 0 + for (i in 0 until viewCaptureData!!.windowDataCount) { + frameCount += viewCaptureData!!.getWindowData(i).frameDataCount + } + assertTrue("Empty ViewCapture data", frameCount > 0) + } }