1 /* 2 * Copyright (C) 2022 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.ShellCommandHelper.executeShellCommand; 20 import static android.server.wm.UiDeviceUtils.pressBackButton; 21 import static android.server.wm.deprecatedabi.Components.WARNING_DIALOG_ACTIVITY; 22 23 import static org.junit.Assume.assumeTrue; 24 25 import android.content.pm.PackageInfo; 26 import android.content.pm.PackageManager; 27 import android.os.SystemProperties; 28 import android.platform.test.annotations.Presubmit; 29 30 import com.android.compatibility.common.util.ApiTest; 31 import com.android.compatibility.common.util.SystemUtil; 32 33 import org.junit.After; 34 import org.junit.Before; 35 import org.junit.Test; 36 37 import java.util.Arrays; 38 import java.util.List; 39 40 41 /** 42 * Ensure that compatibility dialog is shown when launching an application 43 * targeting a deprecated ABI. 44 * <p>Build/Install/Run: 45 * atest CtsWindowManagerDeviceTestCases:DeprecatedAbiTest 46 */ 47 @Presubmit 48 @ApiTest(apis = {"android.content.pm.PackageInstaller#STATUS_FAILURE_INCOMPATIBLE"}) 49 public class DeprecatedAbiTest extends ActivityManagerTestBase { 50 51 /** @see com.android.server.wm.DeprecatedAbiDialog */ 52 private static final String DEPRECATED_ABI_DIALOG = 53 "DeprecatedAbiDialog"; 54 private static final String TEST_APK_PATH = "/data/local/tmp/cts/CtsDeviceDeprecatedAbiApp.apk"; 55 private static final String TEST_PACKAGE_NAME = "android.server.wm.deprecatedabi"; 56 57 @Before setUp()58 public void setUp() { 59 SystemUtil.runShellCommand("input keyevent KEYCODE_WAKEUP"); 60 SystemUtil.runShellCommand("wm dismiss-keyguard"); 61 SystemUtil.runShellCommand("setprop debug.wm.disable_deprecated_abi_dialog 0"); 62 } 63 64 @After tearDown()65 public void tearDown() { 66 // Ensure app process is stopped. 67 stopTestPackage(WARNING_DIALOG_ACTIVITY.getPackageName()); 68 executeShellCommand("pm uninstall " + TEST_PACKAGE_NAME); 69 // Continue to disable DeprecatedAbi dialog so other tests can pass 70 SystemUtil.runShellCommand("setprop debug.wm.disable_deprecated_abi_dialog 1"); 71 } 72 73 @Test testWarningDialog()74 public void testWarningDialog() throws Exception { 75 // Skip the test if the device only supports 32-bit ABI 76 List<String> deviceAbis = Arrays.asList( 77 SystemProperties.get("ro.product.cpu.abilist").split(",")); 78 assumeTrue(deviceAbis.stream().anyMatch(s->s.contains("64"))); 79 executeShellCommand("pm install " + TEST_APK_PATH); 80 // If app fails to install, the device does not support 32-bit ABI. Skip. 81 assumeTrue(isPackageInstalled(TEST_PACKAGE_NAME)); 82 83 // Launch target app. 84 launchActivity(WARNING_DIALOG_ACTIVITY); 85 mWmState.assertActivityDisplayed(WARNING_DIALOG_ACTIVITY); 86 mWmState.assertWindowDisplayed(DEPRECATED_ABI_DIALOG); 87 88 // Go back to dismiss the warning dialog. 89 pressBackButton(); 90 91 // Go back again to formally stop the app. If we just kill the process, it'll attempt to 92 // resume rather than starting from scratch (as far as ActivityStack is concerned) and it 93 // won't invoke the warning dialog. 94 pressBackButton(); 95 } 96 isPackageInstalled(String packageName)97 private boolean isPackageInstalled(String packageName) { 98 try { 99 PackageInfo pi = mContext.getPackageManager().getPackageInfo(packageName, 0); 100 return pi != null; 101 } catch (PackageManager.NameNotFoundException e) { 102 return false; 103 } 104 } 105 } 106