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 com.android.tests.sdksandbox.host; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 22 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 23 24 import org.junit.After; 25 import org.junit.Before; 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 29 import java.util.HashSet; 30 31 @RunWith(DeviceJUnit4ClassRunner.class) 32 public final class SdkSandboxHostTest extends BaseHostJUnit4Test { 33 34 private boolean mMultiuserSupported; 35 36 private int mInitialUserId; 37 private HashSet<Integer> mOriginalUsers; 38 39 @Before setUp()40 public void setUp() throws Exception { 41 assertThat(getBuild()).isNotNull(); // ensure build has been set before test is run 42 43 mMultiuserSupported = getDevice().isMultiUserSupported(); 44 mInitialUserId = getDevice().getCurrentUser(); 45 mOriginalUsers = new HashSet<>(getDevice().listUsers()); 46 } 47 48 @After teardown()49 public void teardown() throws Exception { 50 removeTestUsers(); 51 } 52 53 @Test testSdkSandboxPackageInstallatedForAllUsers()54 public void testSdkSandboxPackageInstallatedForAllUsers() throws Exception { 55 // Test installation for new users 56 if (mMultiuserSupported) { 57 final int testUser = getDevice().createUser("Test User"); 58 } 59 60 for (Integer userId : getDevice().listUsers()) { 61 // TODO(b/204991850): add below code after package install is handled 62 // assertTrue(getDevice().isPackageInstalled(SUPPLEMENTAL_PROCESS_PKG, 63 // Integer.toString(userId))); 64 } 65 } 66 removeTestUsers()67 private void removeTestUsers() throws Exception { 68 if (!mMultiuserSupported) { 69 return; 70 } 71 72 getDevice().switchUser(mInitialUserId); 73 for (Integer userId : getDevice().listUsers()) { 74 if (!mOriginalUsers.contains(userId)) { 75 getDevice().removeUser(userId); 76 } 77 } 78 } 79 } 80