Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2015 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 android.packageinstaller.admin.cts;
     18 
     19 /**
     20  * This class tests silent package install and uninstall by a device owner.
     21  */
     22 public class SilentPackageInstallTest extends BasePackageInstallTest {
     23     public void testSilentInstallUninstall() throws Exception {
     24         if (!mHasFeature) {
     25             return;
     26         }
     27         // install the app
     28         assertInstallPackage();
     29 
     30         // uninstall the app again
     31         assertTrue(tryUninstallPackage());
     32         assertFalse(isPackageInstalled(TEST_APP_PKG));
     33     }
     34 
     35     public void testUninstallBlocked() throws Exception {
     36         if (!mHasFeature) {
     37             return;
     38         }
     39         // install the app
     40         assertInstallPackage();
     41 
     42         mDevicePolicyManager.setUninstallBlocked(getWho(), TEST_APP_PKG, true);
     43         assertTrue(mDevicePolicyManager.isUninstallBlocked(getWho(), TEST_APP_PKG));
     44         assertTrue(mDevicePolicyManager.isUninstallBlocked(null, TEST_APP_PKG));
     45         assertFalse(tryUninstallPackage());
     46         assertTrue(isPackageInstalled(TEST_APP_PKG));
     47 
     48         mDevicePolicyManager.setUninstallBlocked(getWho(), TEST_APP_PKG, false);
     49         assertFalse(mDevicePolicyManager.isUninstallBlocked(getWho(), TEST_APP_PKG));
     50         assertFalse(mDevicePolicyManager.isUninstallBlocked(null, TEST_APP_PKG));
     51         assertTrue(tryUninstallPackage());
     52         assertFalse(isPackageInstalled(TEST_APP_PKG));
     53     }
     54 }
     55