Merge "CTS: De-flake LocationOnScreen tests" into pi-dev
diff --git a/tests/framework/base/windowmanager/Android.mk b/tests/framework/base/windowmanager/Android.mk
index af34c5d..a098701 100644
--- a/tests/framework/base/windowmanager/Android.mk
+++ b/tests/framework/base/windowmanager/Android.mk
@@ -25,6 +25,8 @@
     $(call all-named-files-under,Components.java, alertwindowapp) \
     $(call all-named-files-under,Components.java, alertwindowappsdk25)
 
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
+
 LOCAL_PACKAGE_NAME := CtsWindowManagerDeviceTestCases
 
 LOCAL_JAVA_LIBRARIES := android.test.runner.stubs
diff --git a/tests/framework/base/windowmanager/AndroidManifest.xml b/tests/framework/base/windowmanager/AndroidManifest.xml
index 5f08442..3168dae 100644
--- a/tests/framework/base/windowmanager/AndroidManifest.xml
+++ b/tests/framework/base/windowmanager/AndroidManifest.xml
@@ -34,7 +34,8 @@
         <activity android:name="android.server.wm.AlertWindowsAppOpsTestsActivity"/>
         <activity android:name="android.server.wm.DialogFrameTestActivity" />
         <activity android:name="android.server.wm.DisplayCutoutTests$TestActivity" />
-        <activity android:name="android.server.wm.LocationOnScreenTests$TestActivity" />
+        <activity android:name="android.server.wm.LocationOnScreenTests$TestActivity"
+            android:theme="@style/no_starting_window" />
         <activity android:name="android.server.wm.LocationInWindowTests$TestActivity" />
 
     </application>
diff --git a/tests/framework/base/windowmanager/res/values/styles.xml b/tests/framework/base/windowmanager/res/values/styles.xml
new file mode 100644
index 0000000..4e59d14
--- /dev/null
+++ b/tests/framework/base/windowmanager/res/values/styles.xml
@@ -0,0 +1,21 @@
+<!--
+  ~ Copyright (C) 2018 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<resources>
+    <style name="no_starting_window" parent="@android:style/Theme.DeviceDefault">
+        <item name="android:windowDisablePreview">true</item>
+    </style>
+</resources>
\ No newline at end of file
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/LocationInWindowTests.java b/tests/framework/base/windowmanager/src/android/server/wm/LocationInWindowTests.java
index 206185e..1272237 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/LocationInWindowTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/LocationInWindowTests.java
@@ -36,7 +36,6 @@
 import android.support.test.filters.SmallTest;
 import android.support.test.rule.ActivityTestRule;
 import android.support.test.runner.AndroidJUnit4;
-import android.util.Log;
 import android.view.Gravity;
 import android.view.View;
 import android.view.ViewGroup;
@@ -53,7 +52,6 @@
 import org.junit.rules.ErrorCollector;
 import org.junit.runner.RunWith;
 
-import java.util.Arrays;
 import java.util.function.Supplier;
 
 @RunWith(AndroidJUnit4.class)
@@ -80,18 +78,18 @@
     }
 
     @Test
-    public void testLocationOnDisplay_appWindow() {
+    public void testLocationInWindow_appWindow() {
         runTest(mLayoutParams);
     }
 
     @Test
-    public void testLocationOnDisplay_appWindow_fullscreen() {
+    public void testLocationInWindow_appWindow_fullscreen() {
         mLayoutParams.flags |= LayoutParams.FLAG_FULLSCREEN;
         runTest(mLayoutParams);
     }
 
     @Test
-    public void testLocationOnDisplay_floatingWindow() {
+    public void testLocationInWindow_floatingWindow() {
         mLayoutParams.height = 100;
         mLayoutParams.width = 100;
         mLayoutParams.gravity = Gravity.CENTER;
@@ -100,13 +98,13 @@
     }
 
     @Test
-    public void testLocationOnDisplay_appWindow_displayCutoutNever() {
+    public void testLocationInWindow_appWindow_displayCutoutNever() {
         mLayoutParams.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
         runTest(mLayoutParams);
     }
 
     @Test
-    public void testLocationOnDisplay_appWindow_displayCutoutShortEdges() {
+    public void testLocationInWindow_appWindow_displayCutoutShortEdges() {
         mLayoutParams.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
         runTest(mLayoutParams);
     }
@@ -116,11 +114,11 @@
         PollingCheck.waitFor(() -> getOnMainSync(activity::isEnterAnimationComplete));
 
         runOnMainSync(() -> {
-            assertThatViewGetLocationInWindowAndSurfaceIsCorrect(activity.mView);
+            assertThatViewGetLocationInWindowIsCorrect(activity.mView);
         });
     }
 
-    private void assertThatViewGetLocationInWindowAndSurfaceIsCorrect(View v) {
+    private void assertThatViewGetLocationInWindowIsCorrect(View v) {
         final float[] expected = new float[] {0, 0};
 
         v.getMatrix().mapPoints(expected);
@@ -147,12 +145,6 @@
         return new Point(out[0], out[1]);
     }
 
-    private Point locationInSurfaceAsPoint(View v) {
-        final int[] out = new int[2];
-        v.getLocationInWindow(out);
-        return new Point(out[0], out[1]);
-    }
-
     private <T> void assertThat(String reason, T actual, Matcher<? super T> matcher) {
         mErrorCollector.checkThat(reason, actual, matcher);
     }