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