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
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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<Activity?>) : 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<SafeCloseable>()
|
||||
|
||||
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<SafeCloseable>
|
||||
) {
|
||||
val alreadyOpenActivity = alreadyOpenActivitySupplier.get()
|
||||
if (alreadyOpenActivity != null) {
|
||||
startCapture(windowListenerCloseables, alreadyOpenActivity)
|
||||
}
|
||||
}
|
||||
|
||||
private fun startCapture(
|
||||
windowListenerCloseables: MutableCollection<SafeCloseable>,
|
||||
activity: Activity
|
||||
|
||||
Reference in New Issue
Block a user