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.server.wm.UiDeviceUtils.pressBackButton;
20 import static android.server.wm.deprecatedsdk.Components.MAIN_ACTIVITY;
21 
22 import android.platform.test.annotations.Presubmit;
23 
24 import org.junit.After;
25 import org.junit.Test;
26 
27 /**
28  * Ensure that compatibility dialog is shown when launching an application
29  * targeting a deprecated version of SDK.
30  * <p>Build/Install/Run:
31  *     atest CtsWindowManagerDeviceTestCases:DeprecatedTargetSdkTest
32  */
33 @Presubmit
34 public class DeprecatedTargetSdkTest extends ActivityManagerTestBase {
35 
36     /** @see com.android.server.wm.DeprecatedTargetSdkVersionDialog */
37     private static final String DEPRECATED_TARGET_SDK_VERSION_DIALOG =
38             "DeprecatedTargetSdkVersionDialog";
39 
40     @After
tearDown()41     public void tearDown() {
42         // Ensure app process is stopped.
43         stopTestPackage(MAIN_ACTIVITY.getPackageName());
44     }
45 
46     @Test
testCompatibilityDialog()47     public void testCompatibilityDialog() throws Exception {
48         // Launch target app.
49         launchActivity(MAIN_ACTIVITY);
50         mWmState.assertActivityDisplayed(MAIN_ACTIVITY);
51         mWmState.assertWindowDisplayed(DEPRECATED_TARGET_SDK_VERSION_DIALOG);
52 
53         // Go back to dismiss the warning dialog.
54         pressBackButton();
55 
56         // Go back again to formally stop the app. If we just kill the process, it'll attempt to
57         // resume rather than starting from scratch (as far as ActivityStack is concerned) and it
58         // won't invoke the warning dialog.
59         pressBackButton();
60     }
61 }
62