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 tearDown()51 public void tearDown() { 52 // Ensure app process is stopped. 53 stopTestPackage(MAIN_ACTIVITY.getPackageName()); 54 } 55 56 @Test testCompatibilityDialog()57 public void testCompatibilityDialog() throws Exception { 58 // Launch target app. 59 launchActivity(MAIN_ACTIVITY); 60 mWmState.assertActivityDisplayed(MAIN_ACTIVITY); 61 mWmState.assertWindowDisplayed(UNSUPPORTED_COMPILE_SDK_DIALOG); 62 63 // Go back to dismiss the warning dialog. 64 pressBackButton(); 65 66 // Go back again to formally stop the app. If we just kill the process, it'll attempt to 67 // resume rather than starting from scratch (as far as ActivityStack is concerned) and it 68 // won't invoke the warning dialog. 69 pressBackButton(); 70 } 71 } 72