Bill Napier | ba5ee4a | 2009-08-13 14:46:56 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.dpi.cts; |
| 18 | |
| 19 | import android.content.Context; |
Bill Napier | ba5ee4a | 2009-08-13 14:46:56 -0700 | [diff] [blame] | 20 | import android.test.AndroidTestCase; |
Brian Muramatsu | f0083a8 | 2010-10-29 08:21:49 -0700 | [diff] [blame] | 21 | import android.util.DisplayMetrics; |
Bill Napier | ba5ee4a | 2009-08-13 14:46:56 -0700 | [diff] [blame] | 22 | import android.view.Display; |
| 23 | import android.view.WindowManager; |
Bill Napier | ba5ee4a | 2009-08-13 14:46:56 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
Brian Muramatsu | f0083a8 | 2010-10-29 08:21:49 -0700 | [diff] [blame] | 26 | * Test for verifying a device's screen configuration. |
Bill Napier | ba5ee4a | 2009-08-13 14:46:56 -0700 | [diff] [blame] | 27 | */ |
| 28 | public class ConfigurationTest extends AndroidTestCase { |
| 29 | |
Brian Muramatsu | f0083a8 | 2010-10-29 08:21:49 -0700 | [diff] [blame] | 30 | 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 Napier | ba5ee4a | 2009-08-13 14:46:56 -0700 | [diff] [blame] | 36 | |
Brian Muramatsu | f0083a8 | 2010-10-29 08:21:49 -0700 | [diff] [blame] | 37 | 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 Napier | ba5ee4a | 2009-08-13 14:46:56 -0700 | [diff] [blame] | 42 | |
Brian Muramatsu | f0083a8 | 2010-10-29 08:21:49 -0700 | [diff] [blame] | 43 | double density = 160.0d * metrics.density; |
| 44 | assertTrue("Screen density must be at least 100 dpi: " + density, density >= 100.0d); |
Bill Napier | ba5ee4a | 2009-08-13 14:46:56 -0700 | [diff] [blame] | 45 | |
Mattias Petersson | 5cc4d40 | 2011-03-14 10:53:11 +0100 | [diff] [blame] | 46 | 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 Napier | ba5ee4a | 2009-08-13 14:46:56 -0700 | [diff] [blame] | 52 | } |
| 53 | } |