Home | History | Annotate | Download | only in transferowner
      1 /*
      2  * Copyright (C) 2017 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 package com.android.cts.transferowner;
     17 
     18 import static junit.framework.Assert.assertTrue;
     19 
     20 import static org.junit.Assert.assertEquals;
     21 import static org.testng.Assert.assertThrows;
     22 
     23 import android.app.admin.SystemUpdatePolicy;
     24 import android.support.test.filters.SmallTest;
     25 
     26 import org.junit.Test;
     27 
     28 import java.util.Collections;
     29 
     30 @SmallTest
     31 public class TransferDeviceOwnerIncomingTest extends DeviceAndProfileOwnerTransferIncomingTest {
     32     @Test
     33     public void testTransferPoliciesAreRetainedAfterTransfer() {
     34         assertTrue(mDevicePolicyManager.isAdminActive(mIncomingComponentName));
     35         assertTrue(mDevicePolicyManager.isDeviceOwnerApp(mIncomingComponentName.getPackageName()));
     36         assertTrue(mDevicePolicyManager.getCameraDisabled(mIncomingComponentName));
     37         assertEquals(Collections.singletonList("test.package"),
     38                 mDevicePolicyManager.getKeepUninstalledPackages(mIncomingComponentName));
     39         assertEquals(123, mDevicePolicyManager.getPasswordMinimumLength(mIncomingComponentName));
     40         assertSystemPoliciesEqual(SystemUpdatePolicy.createWindowedInstallPolicy(123, 456),
     41                 mDevicePolicyManager.getSystemUpdatePolicy());
     42         assertThrows(SecurityException.class, () -> {
     43             mDevicePolicyManager.getParentProfileInstance(mIncomingComponentName);
     44         });
     45     }
     46 
     47     private void assertSystemPoliciesEqual(SystemUpdatePolicy policy1, SystemUpdatePolicy policy2) {
     48         assertTrue(policy1.getPolicyType() == policy2.getPolicyType()
     49                 && policy1.getInstallWindowStart() == policy2.getInstallWindowStart()
     50                 && policy1.getInstallWindowEnd() == policy2.getInstallWindowEnd());
     51     }
     52 }
     53