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 'ff760448039f4ea2d4a3157e7b2e740374924602':
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();
+ }
}