• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.server.wm.UiDeviceUtils.pressBackButton;
20 import static android.server.wm.prerelease.Components.MAIN_ACTIVITY;
21 
22 import android.platform.test.annotations.Presubmit;
23 
24 import com.android.compatibility.common.util.SystemUtil;
25 
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 
30 /**
31  * Ensure that compatibility dialog is shown when launching an application built
32  * against a prerelease SDK.
33  * <p>Build/Install/Run:
34  *     atest CtsWindowManagerDeviceTestCases:PrereleaseSdkTest
35  */
36 @Presubmit
37 public class PrereleaseSdkTest extends ActivityManagerTestBase {
38 
39     /** @see com.android.server.wm.UnsupportedCompileSdkDialog */
40     private static final String UNSUPPORTED_COMPILE_SDK_DIALOG = "UnsupportedCompileSdkDialog";
41 
42     @Before
43     @Override
setUp()44     public void setUp() throws Exception {
45         super.setUp();
46         SystemUtil.runWithShellPermissionIdentity(
47                 () -> mAm.alwaysShowUnsupportedCompileSdkWarning(MAIN_ACTIVITY));
48     }
49 
50     @After
51     @Override
tearDown()52     public void tearDown() throws Exception {
53         super.tearDown();
54 
55         // Ensure app process is stopped.
56         stopTestPackage(MAIN_ACTIVITY.getPackageName());
57     }
58 
59     @Test
testCompatibilityDialog()60     public void testCompatibilityDialog() throws Exception {
61         // Launch target app.
62         launchActivity(MAIN_ACTIVITY);
63         mAmWmState.assertActivityDisplayed(MAIN_ACTIVITY);
64         mAmWmState.assertWindowDisplayed(UNSUPPORTED_COMPILE_SDK_DIALOG);
65 
66         // Go back to dismiss the warning dialog.
67         pressBackButton();
68 
69         // Go back again to formally stop the app. If we just kill the process, it'll attempt to
70         // resume rather than starting from scratch (as far as ActivityStack is concerned) and it
71         // won't invoke the warning dialog.
72         pressBackButton();
73     }
74 }
75