| /* |
| * Copyright (C) 2018 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License |
| */ |
| |
| package android.appsecurity.cts; |
| |
| import android.platform.test.annotations.AppModeFull; |
| import android.platform.test.annotations.Presubmit; |
| |
| import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; |
| |
| import org.junit.After; |
| import org.junit.Before; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| /** |
| * Tests the visibility of installed applications. |
| */ |
| @Presubmit |
| @RunWith(DeviceJUnit4ClassRunner.class) |
| public class ApplicationVisibilityTest extends BaseAppSecurityTest { |
| |
| private static final String TINY_APK = "CtsPkgInstallTinyApp.apk"; |
| private static final String TINY_PKG = "android.appsecurity.cts.tinyapp"; |
| |
| private static final String TEST_WITH_PERMISSION_APK = |
| "CtsApplicationVisibilityCrossUserApp.apk"; |
| private static final String TEST_WITH_PERMISSION_PKG = |
| "com.android.cts.applicationvisibility"; |
| |
| private int[] mUsers; |
| private String mOldVerifierValue; |
| |
| @Before |
| public void setUpPackage() throws Exception { |
| mUsers = Utils.prepareMultipleUsers(getDevice(), 2); |
| mOldVerifierValue = |
| getDevice().executeShellCommand("settings get global package_verifier_enable"); |
| getDevice().executeShellCommand("settings put global package_verifier_enable 0"); |
| } |
| |
| @After |
| public void tearDown() throws Exception { |
| getDevice().uninstallPackage(TEST_WITH_PERMISSION_PKG); |
| getDevice().uninstallPackage(TINY_PKG); |
| getDevice().executeShellCommand("settings put global package_verifier_enable " |
| + mOldVerifierValue); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot be granted INTERACT_ACROSS_USERS") |
| public void testPackageListCrossUserGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testPackageVisibility_currentUser", |
| testUserId); |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testPackageVisibility_anyUserCrossUserGrant", |
| testUserId); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot see any other application") |
| public void testPackageListCrossUserNoGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testPackageVisibility_currentUser", |
| testUserId); |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testPackageVisibility_anyUserCrossUserNoGrant", |
| testUserId); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot be granted INTERACT_ACROSS_USERS") |
| public void testPackageListOtherUserCrossUserGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| final Map<String, String> testArgs = new HashMap<>(); |
| testArgs.put("testUser", Integer.toString(installUserId)); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testPackageVisibility_otherUserGrant", |
| testUserId, |
| testArgs); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot see any other application") |
| public void testPackageListOtherUserCrossUserNoGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| final Map<String, String> testArgs = new HashMap<>(); |
| testArgs.put("testUser", Integer.toString(installUserId)); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testPackageVisibility_otherUserNoGrant", |
| testUserId, |
| testArgs); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot be granted INTERACT_ACROSS_USERS") |
| public void testApplicationListCrossUserGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testApplicationVisibility_currentUser", |
| testUserId); |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testApplicationVisibility_anyUserCrossUserGrant", |
| testUserId); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot see any other application") |
| public void testApplicationListCrossUserNoGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testApplicationVisibility_currentUser", |
| testUserId); |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testApplicationVisibility_anyUserCrossUserNoGrant", |
| testUserId); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot be granted INTERACT_ACROSS_USERS") |
| public void testApplicationListOtherUserCrossUserGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| final Map<String, String> testArgs = new HashMap<>(); |
| testArgs.put("testUser", Integer.toString(installUserId)); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testApplicationVisibility_otherUserGrant", |
| testUserId, |
| testArgs); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot see any other application") |
| public void testApplicationListOtherUserCrossUserNoGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| final Map<String, String> testArgs = new HashMap<>(); |
| testArgs.put("testUser", Integer.toString(installUserId)); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testApplicationVisibility_otherUserNoGrant", |
| testUserId, |
| testArgs); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot be granted INTERACT_ACROSS_USERS") |
| public void testGetPackagesForUidCrossUserGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackagesForUidVisibility_currentUser", |
| testUserId); |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackagesForUidVisibility_anotherUserCrossUserGrant", |
| testUserId); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot see any other application") |
| public void testGetPackagesForUidCrossUserNoGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackagesForUidVisibility_currentUser", |
| testUserId); |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackagesForUidVisibility_anotherUserCrossUserNoGrant", |
| testUserId); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot be granted INTERACT_ACROSS_USERS") |
| public void testGetPackageUidCrossUserGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| final Map<String, String> testArgs = new HashMap<>(); |
| testArgs.put("testUser", Integer.toString(installUserId)); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| // Also install TEST_WITH_PERMISSION_APK in installUSerId for creating across user context |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackageUidVisibility_currentUser", |
| testUserId); |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackageUidVisibility_anotherUserCrossUserGrant", |
| testUserId, |
| testArgs); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot see any other application") |
| public void testGetPackageUidCrossUserNoGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| final Map<String, String> testArgs = new HashMap<>(); |
| testArgs.put("testUser", Integer.toString(installUserId)); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| // Also install TEST_WITH_PERMISSION_APK in installUSerId for creating across user context |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackageUidVisibility_currentUser", |
| testUserId); |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackageUidVisibility_anotherUserCrossUserNoGrant", |
| testUserId, |
| testArgs); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot be granted INTERACT_ACROSS_USERS") |
| public void testGetPackageGidsCrossUserGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| final Map<String, String> testArgs = new HashMap<>(); |
| testArgs.put("testUser", Integer.toString(installUserId)); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| // Also install TEST_WITH_PERMISSION_APK in installUSerId for creating across user context |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackageGidsVisibility_currentUser", |
| testUserId); |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackageGidsVisibility_anotherUserCrossUserGrant", |
| testUserId, |
| testArgs); |
| } |
| |
| @Test |
| @AppModeFull(reason = "instant applications cannot see any other application") |
| public void testGetPackageGidsCrossUserNoGrant() throws Exception { |
| if (!mSupportsMultiUser) { |
| return; |
| } |
| |
| final int installUserId = getInstallUserId(); |
| final int testUserId = getTestUserId(); |
| final Map<String, String> testArgs = new HashMap<>(); |
| testArgs.put("testUser", Integer.toString(installUserId)); |
| |
| installTestAppForUser(TINY_APK, installUserId); |
| // Also install TEST_WITH_PERMISSION_APK in installUSerId for creating across user context |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, installUserId); |
| installTestAppForUser(TEST_WITH_PERMISSION_APK, testUserId); |
| |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackageGidsVisibility_currentUser", |
| testUserId); |
| Utils.runDeviceTests( |
| getDevice(), |
| TEST_WITH_PERMISSION_PKG, |
| ".ApplicationVisibilityCrossUserTest", |
| "testGetPackageGidsVisibility_anotherUserCrossUserNoGrant", |
| testUserId, |
| testArgs); |
| } |
| |
| private int getInstallUserId() { |
| return mUsers[0]; |
| } |
| |
| private int getTestUserId() { |
| return mUsers[1]; |
| } |
| } |