blob: 624f35a968a37150144e63003bd18da479da92cc [file] [log] [blame]
Bill Napierba5ee4a2009-08-13 14:46:56 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.dpi.cts;
18
19import android.content.Context;
Bill Napierba5ee4a2009-08-13 14:46:56 -070020import android.test.AndroidTestCase;
Brian Muramatsuf0083a82010-10-29 08:21:49 -070021import android.util.DisplayMetrics;
Bill Napierba5ee4a2009-08-13 14:46:56 -070022import android.view.Display;
23import android.view.WindowManager;
Bill Napierba5ee4a2009-08-13 14:46:56 -070024
25/**
Brian Muramatsuf0083a82010-10-29 08:21:49 -070026 * Test for verifying a device's screen configuration.
Bill Napierba5ee4a2009-08-13 14:46:56 -070027 */
28public class ConfigurationTest extends AndroidTestCase {
29
Brian Muramatsuf0083a82010-10-29 08:21:49 -070030 public void testScreenConfiguration() {
31 WindowManager windowManager =
32 (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
33 Display display = windowManager.getDefaultDisplay();
34 DisplayMetrics metrics = new DisplayMetrics();
35 display.getMetrics(metrics);
Bill Napierba5ee4a2009-08-13 14:46:56 -070036
Brian Muramatsuf0083a82010-10-29 08:21:49 -070037 double xInches = (double) metrics.widthPixels / metrics.xdpi;
38 double yInches = (double) metrics.heightPixels / metrics.ydpi;
39 double diagonalInches = Math.sqrt(Math.pow(xInches, 2) + Math.pow(yInches, 2));
40 assertTrue("Screen diagonal must be at least 2.5 inches: " + diagonalInches,
41 diagonalInches >= 2.5d);
Bill Napierba5ee4a2009-08-13 14:46:56 -070042
Brian Muramatsuf0083a82010-10-29 08:21:49 -070043 double density = 160.0d * metrics.density;
44 assertTrue("Screen density must be at least 100 dpi: " + density, density >= 100.0d);
Bill Napierba5ee4a2009-08-13 14:46:56 -070045
Mattias Petersson5cc4d402011-03-14 10:53:11 +010046 int max = Math.max(metrics.widthPixels, metrics.heightPixels);
47 int min = Math.min(metrics.widthPixels, metrics.heightPixels);
48 boolean format16x9 = Math.floor(max * 9.0d / 16.0d) <= min;
49 boolean format4x3 = Math.ceil(max * 3.0d / 4.0d) >= min;
50 assertTrue("Aspect ratio must be between 4:3 and 16:9. It was " + max + ":" + min,
51 format4x3 && format16x9);
Bill Napierba5ee4a2009-08-13 14:46:56 -070052 }
53}