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.pm.ApplicationInfo;
20 import android.content.pm.PackageManager;
21 import android.content.pm.PackageManager.NameNotFoundException;
22 import android.test.AndroidTestCase;
23 
24 
25 /**
26  * This the base class for verifying that the correct defaults are
27  * loaded for the following manifest attributes:
28  *
29  * android:smallScreens
30  * android:normalScreens
31  * android:largeScreens
32  * android:resizable
33  * android:anyDensity
34  *
35  * The default value depends on the sdk version declared in the
36  * manifest of the package.  sdk version <=3 defaults all values to
37  * false.  It is true otherwise.
38  */
39 public abstract class DefaultManifestAttributesTest extends AndroidTestCase {
40     // Allow subclass to change the package name in seTUp
41     protected String packageName;
42 
43     // Calculated during setUp
44     private boolean expectedResult;
45     private ApplicationInfo appInfo;
46 
getAppInfo()47     protected ApplicationInfo getAppInfo() {
48         return appInfo;
49     }
50 
getPackageName()51     protected abstract String getPackageName();
52 
setUp()53     protected void setUp() {
54         packageName = getPackageName();
55 
56         PackageManager pm = getContext().getPackageManager();
57         try {
58             appInfo = pm.getApplicationInfo(packageName, 0);
59 
60             // Setup expected info based on sdk version in ai
61             if (appInfo.targetSdkVersion <= 3) {
62                 expectedResult = false;
63             } else {
64                 expectedResult = true;
65             }
66         } catch (NameNotFoundException e) {
67             fail("Should be able to find application info for this package");
68         }
69     }
70 
testSmallScreenDefault()71     public void testSmallScreenDefault() {
72         assertEquals(expectedResult,
73                      (getAppInfo().flags & ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0);
74     }
75 
testNormalScreenDefault()76     public void testNormalScreenDefault() {
77         // Normal screens are always supported regardless of SDK
78         // version.
79         assertEquals(true,
80                     (getAppInfo().flags & ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0);
81     }
82 
testLargeScreenDefault()83     public void testLargeScreenDefault() {
84         assertEquals(expectedResult,
85                     (getAppInfo().flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0);
86     }
87 
testResizableDefault()88     public void testResizableDefault() {
89         assertEquals(expectedResult,
90                     (getAppInfo().flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0);
91     }
92 
testAnyDensityDefault()93     public void testAnyDensityDefault() {
94         assertEquals(expectedResult,
95                     (getAppInfo().flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0);
96     }
97 }
98