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 
     25 import androidx.test.filters.SmallTest;
     26 
     27 import org.junit.Test;
     28 
     29 import java.util.Collections;
     30 
     31 @SmallTest
     32 public class TransferDeviceOwnerIncomingTest extends DeviceAndProfileOwnerTransferIncomingTest {
     33     @Test
     34     public void testTransferPoliciesAreRetainedAfterTransfer() {
     35         assertTrue(mDevicePolicyManager.isAdminActive(mIncomingComponentName));
     36         assertTrue(mDevicePolicyManager.isDeviceOwnerApp(mIncomingComponentName.getPackageName()));
     37         assertTrue(mDevicePolicyManager.getCameraDisabled(mIncomingComponentName));
     38         assertEquals(Collections.singletonList("test.package"),
     39                 mDevicePolicyManager.getKeepUninstalledPackages(mIncomingComponentName));
     40         assertEquals(123, mDevicePolicyManager.getPasswordMinimumLength(mIncomingComponentName));
     41         assertSystemPoliciesEqual(SystemUpdatePolicy.createWindowedInstallPolicy(123, 456),
     42                 mDevicePolicyManager.getSystemUpdatePolicy());
     43         assertThrows(SecurityException.class, () -> {
     44             mDevicePolicyManager.getParentProfileInstance(mIncomingComponentName);
     45         });
     46     }
     47 
     48     private void assertSystemPoliciesEqual(SystemUpdatePolicy policy1, SystemUpdatePolicy policy2) {
     49         assertTrue(policy1.getPolicyType() == policy2.getPolicyType()
     50                 && policy1.getInstallWindowStart() == policy2.getInstallWindowStart()
     51                 && policy1.getInstallWindowEnd() == policy2.getInstallWindowEnd());
     52     }
     53 }
     54