From bb50f3cd8e8faca4e4aa14a444017fdf7dbd9af6 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 19 Jul 2023 15:57:29 -0700 Subject: [PATCH] Fixing ViewCaptureRule not unregistered if activity is destroyed Bug: 291638593 Test: Presubmit Flag: N/A Change-Id: I86daf9fac210340b037d376d882ac5872c596ae4 --- .../src/com/android/quickstep/FallbackRecentsTest.java | 3 +-- .../android/launcher3/ui/AbstractLauncherUiTest.java | 3 +-- .../com/android/launcher3/util/rule/ViewCaptureRule.kt | 10 +--------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index a67d787842..bc90db0fc1 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -116,8 +116,7 @@ public class FallbackRecentsTest { Utilities.enableRunningInTestHarnessForTests(); } - final ViewCaptureRule viewCaptureRule = new ViewCaptureRule( - RecentsActivity.ACTIVITY_TRACKER::getCreatedActivity); + final ViewCaptureRule viewCaptureRule = new ViewCaptureRule(); 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 d22a353707..f061fab105 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -201,8 +201,7 @@ public abstract class AbstractLauncherUiTest { } protected TestRule getRulesInsideActivityMonitor() { - final ViewCaptureRule viewCaptureRule = new ViewCaptureRule( - Launcher.ACTIVITY_TRACKER::getCreatedActivity); + final ViewCaptureRule viewCaptureRule = new ViewCaptureRule(); 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 b2a2f7f64a..1ca4434b82 100644 --- a/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt +++ b/tests/src/com/android/launcher3/util/rule/ViewCaptureRule.kt @@ -25,7 +25,6 @@ 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 @@ -36,7 +35,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(var alreadyOpenActivitySupplier: Supplier) : TestRule { +class ViewCaptureRule : TestRule { private val viewCapture = SimpleViewCapture("test-view-capture") var viewCaptureData: ExportedData? = null private set @@ -47,20 +46,13 @@ class ViewCaptureRule(var alreadyOpenActivitySupplier: Supplier) : Te viewCaptureData = null val windowListenerCloseables = mutableListOf() - val alreadyOpenActivity = alreadyOpenActivitySupplier.get() - if (alreadyOpenActivity != null) { - startCapture(windowListenerCloseables, alreadyOpenActivity) - } - val lifecycleCallbacks = object : ActivityLifecycleCallbacksAdapter { override fun onActivityCreated(activity: Activity, bundle: Bundle?) { - super.onActivityCreated(activity, bundle) startCapture(windowListenerCloseables, activity) } override fun onActivityDestroyed(activity: Activity) { - super.onActivityDestroyed(activity) viewCapture.stopCapture(activity.window.decorView) } }