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 com.android.cts.devicepolicy; 18 19 import java.util.Collections; 20 21 /** 22 * Set of tests for the limit app icon hiding feature. 23 */ 24 public class LimitAppIconHidingTest extends BaseLauncherAppsTest { 25 26 private static final String LAUNCHER_TESTS_NO_LAUNCHABLE_ACTIVITY_APK = 27 "CtsNoLaunchableActivityApp.apk"; 28 private static final String LAUNCHER_TESTS_NO_COMPONENT_APK = 29 "CtsNoComponentApp.apk"; 30 private static final String LAUNCHER_TESTS_NO_PERMISSION_APK = 31 "CtsNoPermissionApp.apk"; 32 33 private boolean mHasLauncherApps; 34 private String mSerialNumber; 35 private int mCurrentUserId; 36 37 @Override 38 protected void setUp() throws Exception { 39 super.setUp(); 40 mHasLauncherApps = getDevice().getApiLevel() >= 21; 41 42 if (mHasLauncherApps) { 43 mCurrentUserId = getDevice().getCurrentUser(); 44 mSerialNumber = Integer.toString(getUserSerialNumber(mCurrentUserId)); 45 uninstallTestApps(); 46 installTestApps(mCurrentUserId); 47 } 48 } 49 50 @Override 51 protected void tearDown() throws Exception { 52 if (mHasLauncherApps) { 53 uninstallTestApps(); 54 } 55 super.tearDown(); 56 } 57 58 @Override 59 protected void installTestApps(int userId) throws Exception { 60 super.installTestApps(mCurrentUserId); 61 installAppAsUser(LAUNCHER_TESTS_NO_LAUNCHABLE_ACTIVITY_APK, mCurrentUserId); 62 installAppAsUser(LAUNCHER_TESTS_NO_COMPONENT_APK, mCurrentUserId); 63 installAppAsUser(LAUNCHER_TESTS_NO_PERMISSION_APK, mCurrentUserId); 64 } 65 66 @Override 67 protected void uninstallTestApps() throws Exception { 68 super.uninstallTestApps(); 69 getDevice().uninstallPackage(LAUNCHER_TESTS_NO_PERMISSION_APK); 70 getDevice().uninstallPackage(LAUNCHER_TESTS_NO_COMPONENT_APK); 71 getDevice().uninstallPackage(LAUNCHER_TESTS_NO_LAUNCHABLE_ACTIVITY_APK); 72 } 73 74 public void testNoLaunchableActivityAppHasAppDetailsActivityInjected() throws Exception { 75 if (!mHasLauncherApps) { 76 return; 77 } 78 runDeviceTestsAsUser(LAUNCHER_TESTS_PKG, 79 LAUNCHER_TESTS_CLASS, "testNoLaunchableActivityAppHasAppDetailsActivityInjected", 80 mCurrentUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber)); 81 } 82 83 public void testNoSystemAppHasSyntheticAppDetailsActivityInjected() throws Exception { 84 if (!mHasLauncherApps) { 85 return; 86 } 87 runDeviceTestsAsUser(LAUNCHER_TESTS_PKG, 88 LAUNCHER_TESTS_CLASS, "testNoSystemAppHasSyntheticAppDetailsActivityInjected", 89 mCurrentUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber)); 90 } 91 92 public void testNoComponentAppNotInjected() throws Exception { 93 if (!mHasLauncherApps) { 94 return; 95 } 96 runDeviceTestsAsUser(LAUNCHER_TESTS_PKG, 97 LAUNCHER_TESTS_CLASS, "testNoComponentAppNotInjected", 98 mCurrentUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber)); 99 } 100 101 public void testNoPermissionAppNotInjected() throws Exception { 102 if (!mHasLauncherApps) { 103 return; 104 } 105 runDeviceTestsAsUser(LAUNCHER_TESTS_PKG, 106 LAUNCHER_TESTS_CLASS, "testNoPermissionAppNotInjected", 107 mCurrentUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber)); 108 } 109 110 public void testGetSetSyntheticAppDetailsActivityEnabled() throws Exception { 111 if (!mHasLauncherApps) { 112 return; 113 } 114 runDeviceTestsAsUser(LAUNCHER_TESTS_PKG, 115 LAUNCHER_TESTS_CLASS, "testGetSetSyntheticAppDetailsActivityEnabled", 116 mCurrentUserId, Collections.singletonMap(PARAM_TEST_USER, mSerialNumber)); 117 } 118 } 119