Fixed bug with turnScreenOn window flag.

The test
ActivityManagerActivityVisibilityTests#testTurnScreenOnActivity_withRelayout
was failing due to issues with how the turnScreenOn flag was handled.
This change centralizes the logic about when to turn the screen on. The
check for whether the screen should be turned on will happen on each
relayout but is guarded by a flag set in resume. This way the screen can only
have the chance to turn on if a resume was just called.

Change-Id: I0a6e4a11de92fa41c8a49cbfd1b78bd8b38a1b4a
Fixes: 68091612
Test: WindowStateTests
Test: ActivityManagerActivityVisibilityTests
diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java
index 6a4710b..a49522a 100644
--- a/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java
+++ b/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java
@@ -40,6 +40,10 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.verify;
 
 /**
  * Tests for the {@link WindowState} class.
@@ -237,11 +241,11 @@
     }
 
     private void testPrepareWindowToDisplayDuringRelayout(boolean wasVisible) {
+        reset(mPowerManagerWrapper);
         final WindowState root = createWindow(null, TYPE_APPLICATION, "root");
         root.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
-        root.mTurnOnScreen = false;
 
         root.prepareWindowToDisplayDuringRelayout(wasVisible /*wasVisible*/);
-        assertTrue(root.mTurnOnScreen);
+        verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString());
     }
 }