am d4ea0825: am b1a9e89c: am c0206763: am ae8cc846: am 4f8604a2: am ff760448: am a3a37fd2: am 7a4c8877: am b1a8a3b7: am 589787a2: am 6d2d5623: am e9ea138a: Merge "Revert "Use real screen width/height to calculate aspect ratio"" into jb-dev

* commit 'd4ea082508742355a8a3e4c2dc7256d370a76781':
  Revert "Use real screen width/height to calculate aspect ratio"
diff --git a/tests/tests/dpi/src/android/dpi/cts/AspectRatioTest.java b/tests/tests/dpi/src/android/dpi/cts/AspectRatioTest.java
index 572c3f4..74a9f22 100644
--- a/tests/tests/dpi/src/android/dpi/cts/AspectRatioTest.java
+++ b/tests/tests/dpi/src/android/dpi/cts/AspectRatioTest.java
@@ -40,27 +40,46 @@
     }
 
     /**
-     * Get the full screen size directly (including system bar) to calculate
-     * aspect ratio. With this, the screen orientation doesn't affect the aspect
-     * ratio value anymore. Test that the aspect ratio is within the range.
+     * Get all the aspect rations in different orientations. They could be
+     * different due to the system bar being different sizes. Test that
+     * one of the aspect ratios is within the range.
      */
     public void testAspectRatio() throws Exception {
-        double aspectRatio = getRealAspectRatio(getActivity());
-        if (aspectRatio >= 1.333 && aspectRatio <= 1.86) {
-            return;
+        List<Double> aspectRatios = getAllAspectRatios();
+        for (double aspectRatio : aspectRatios) {
+            if (aspectRatio >= 1.333 && aspectRatio <= 1.86) {
+                return;
+            }
         }
-        fail("Aspect ratio was not between 1.333 and 1.86: " + aspectRatio);
+        fail("Aspect ratios were not between 1.333 and 1.86: " + aspectRatios);
     }
 
-    private double getRealAspectRatio(Context context) {
+    private List<Double> getAllAspectRatios() throws Exception {
+        List<Double> aspectRatios = new ArrayList<Double>();
+        for (int i = 0; i < ORIENTATIONS.length; i++) {
+            Activity activity = startOrientationActivity(ORIENTATIONS[i]);
+            aspectRatios.add(getAspectRatio(activity));
+            tearDown();
+        }
+        return aspectRatios;
+    }
+
+    private double getAspectRatio(Context context) {
         WindowManager windowManager =
                 (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
         Display display = windowManager.getDefaultDisplay();
         DisplayMetrics metrics = new DisplayMetrics();
-        display.getRealMetrics(metrics);
+        display.getMetrics(metrics);
 
         int max = Math.max(metrics.widthPixels, metrics.heightPixels);
         int min = Math.min(metrics.widthPixels, metrics.heightPixels);
         return (double) max / min;
     }
+
+    private Activity startOrientationActivity(int orientation) {
+        Intent intent = new Intent();
+        intent.putExtra(OrientationActivity.EXTRA_ORIENTATION, orientation);
+        setActivityIntent(intent);
+        return getActivity();
+    }
 }