1 /*
2  * Copyright (C) 2018 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.server.wm;
18 
19 import static android.content.pm.PackageManager.FEATURE_WATCH;
20 
21 import static androidx.test.InstrumentationRegistry.getInstrumentation;
22 
23 import static org.junit.Assert.assertThat;
24 
25 import android.app.Activity;
26 import android.platform.test.annotations.Presubmit;
27 
28 import androidx.test.rule.ActivityTestRule;
29 
30 import org.junit.Rule;
31 import org.junit.Test;
32 
33 /**
34  * Build/Install/Run:
35  *  atest CtsWindowManagerSdk28TestCases:AspectRatioSdk28Tests
36  */
37 @Presubmit
38 public class AspectRatioSdk28Tests extends AspectRatioTestsBase {
39 
40     // The minimum supported device aspect ratio for pre-Q devices.
41     private static final float MIN_DEVICE_ASPECT_RATIO = 1.333f;
42 
43     // The minimum supported device aspect ratio for watches.
44     private static final float MIN_WATCH_DEVICE_ASPECT_RATIO = 1.0f;
45 
46 
47     // Test target activity that has targetSdk="28" and resizeableActivity="false".
48     public static class Sdk28MinAspectRatioActivity extends Activity {
49     }
50 
51     @Rule
52     public ActivityTestRule<?> mSdk28MinAspectRatioActivity = new ActivityTestRule<>(
53             Sdk28MinAspectRatioActivity.class, false /* initialTouchMode */,
54             false /* launchActivity */);
55 
56     @Test
testMaxAspectRatioPreQActivity()57     public void testMaxAspectRatioPreQActivity() {
58         boolean isWatch = getInstrumentation().getContext().getPackageManager()
59                 .hasSystemFeature(FEATURE_WATCH);
60         float minAspectRatio = isWatch ? MIN_WATCH_DEVICE_ASPECT_RATIO : MIN_DEVICE_ASPECT_RATIO;
61 
62         runAspectRatioTest(mSdk28MinAspectRatioActivity, (actual, displayId, size) -> {
63             assertThat(actual, greaterThanOrEqualToInexact(minAspectRatio));
64         });
65     }
66 }
67