Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c870133b authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Fix leakage of unit test on large screen/foldable device

The device type may have additional registrations, so just
clean up them on tearDown.

Fix: 295867194
Fix: 295892211
Test: atest SystemServicesTestRuleTest#testRule_ranSuccessfully
Change-Id: Ie6e841fef7a4754c6a7d700163a2ed23a8df6d5f
parent 6c65ee52
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -384,7 +384,16 @@ public class SystemServicesTestRule implements TestRule {
    }

    private void tearDown() {
        mWmService.mRoot.forAllDisplayPolicies(DisplayPolicy::release);
        for (int i = mWmService.mRoot.getChildCount() - 1; i >= 0; i--) {
            final DisplayContent dc = mWmService.mRoot.getChildAt(i);
            // Unregister SettingsObserver.
            dc.getDisplayPolicy().release();
            // Unregister SensorEventListener (foldable device may register for hinge angle).
            dc.getDisplayRotation().onDisplayRemoved();
            if (dc.mDisplayRotationCompatPolicy != null) {
                dc.mDisplayRotationCompatPolicy.dispose();
            }
        }

        // Unregister display listener from root to avoid issues with subsequent tests.
        mContext.getSystemService(DisplayManager.class)