blob: 0af38a4ee08a8d89c1bc9d77da09cc56c4555cdb [file] [log] [blame]
Kenny Guyda652442015-01-26 14:49:13 +00001/*
2 * Copyright (C) 2014 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
17package com.android.cts.devicepolicy;
18
19import com.android.ddmlib.Log.LogLevel;
20import com.android.tradefed.device.DeviceNotAvailableException;
21import com.android.tradefed.log.LogUtil.CLog;
22
23/**
24 * Set of tests for LauncherApps attempting to access a non-profiles
25 * apps.
26 */
27public class LauncherAppsMultiUserTest extends BaseLauncherAppsTest {
28
29 private int mSecondaryUserId;
30 private int mSecondaryUserSerialNumber;
31
32 private boolean mMultiUserSupported;
33
34 @Override
35 protected void setUp() throws Exception {
36 super.setUp();
37 // We need multi user to be supported in order to create a secondary user
38 // and api level 21 to support LauncherApps
39 mMultiUserSupported = getMaxNumberOfUsersSupported() > 1 && getDevice().getApiLevel() >= 21;
40
41 if (mMultiUserSupported) {
42 removeTestUsers();
43 installTestApps();
44 // Create a secondary user.
45 mSecondaryUserId = createUser();
46 mSecondaryUserSerialNumber = getUserSerialNumber(mSecondaryUserId);
47 startUser(mSecondaryUserId);
48 }
49 }
50
51 @Override
52 protected void tearDown() throws Exception {
53 if (mMultiUserSupported) {
54 removeUser(mSecondaryUserId);
55 uninstallTestApps();
56 }
57 super.tearDown();
58 }
59
60 public void testGetActivitiesForNonProfileFails() throws Exception {
61 if (!mMultiUserSupported) {
62 return;
63 }
64 installApp(SIMPLE_APP_APK);
65 try {
66 assertTrue(runDeviceTests(LAUNCHER_TESTS_PKG,
67 LAUNCHER_TESTS_CLASS,
68 "testGetActivitiesForUserFails",
69 0, "-e testUser " + mSecondaryUserSerialNumber));
70 } finally {
71 getDevice().uninstallPackage(SIMPLE_APP_PKG);
72 }
73 }
74
75 public void testNoLauncherCallbackPackageAddedSecondaryUser() throws Exception {
76 if (!mMultiUserSupported) {
77 return;
78 }
79 startCallbackService();
80 installApp(SIMPLE_APP_APK);
81 try {
82 assertTrue(runDeviceTests(LAUNCHER_TESTS_PKG,
83 LAUNCHER_TESTS_CLASS,
84 "testNoCallbackForUser",
85 0, "-e testUser " + mSecondaryUserSerialNumber));
86 } finally {
87 getDevice().uninstallPackage(SIMPLE_APP_PKG);
88 }
89 }
90}