• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.devicepolicy.cts;
18 
19 import static com.android.bedstead.enterprise.EnterpriseDeviceStateExtensionsKt.dpc;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import com.android.bedstead.harrier.BedsteadJUnit4;
24 import com.android.bedstead.harrier.DeviceState;
25 import com.android.bedstead.multiuser.annotations.RequireRunOnAdditionalUser;
26 import com.android.bedstead.multiuser.annotations.RequireRunOnSystemUser;
27 import com.android.bedstead.harrier.annotations.RequireStorageEncryptionSupported;
28 import com.android.bedstead.harrier.annotations.RequireStorageEncryptionUnsupported;
29 import com.android.bedstead.enterprise.annotations.CanSetPolicyTest;
30 import com.android.bedstead.harrier.policies.StorageEncryption;
31 
32 import org.junit.ClassRule;
33 import org.junit.Rule;
34 import org.junit.runner.RunWith;
35 
36 @RunWith(BedsteadJUnit4.class)
37 public final class StorageEncryptionTest {
38 
39     @ClassRule @Rule
40     public static final DeviceState sDeviceState = new DeviceState();
41 
42     private static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
43     private static final int ENCRYPTION_STATUS_INACTIVE = 1;
44     private static final int ENCRYPTION_STATUS_ACTIVE = 3;
45 
46     @CanSetPolicyTest(policy = StorageEncryption.class)
47     @RequireRunOnSystemUser
48     @RequireStorageEncryptionSupported
setStorageEncryption_runOnSystemUser_enable_isEnabled()49     public void setStorageEncryption_runOnSystemUser_enable_isEnabled() {
50         try {
51             assertThat(dpc(sDeviceState).devicePolicyManager().setStorageEncryption(
52                     dpc(sDeviceState).componentName(), /* encrypt= */ true))
53                     .isEqualTo(ENCRYPTION_STATUS_ACTIVE);
54 
55             assertThat(dpc(sDeviceState).devicePolicyManager().getStorageEncryption(
56                     dpc(sDeviceState).componentName())).isTrue();
57         } finally {
58             dpc(sDeviceState).devicePolicyManager().setStorageEncryption(
59                     dpc(sDeviceState).componentName(), /* encrypt= */ false);
60         }
61     }
62 
63     @CanSetPolicyTest(policy = StorageEncryption.class)
64     @RequireRunOnAdditionalUser
setStorageEncryption_runOnNonSystemUser_enable_isNotSupported()65     public void setStorageEncryption_runOnNonSystemUser_enable_isNotSupported() {
66         try {
67             assertThat(dpc(sDeviceState).devicePolicyManager().setStorageEncryption(
68                     dpc(sDeviceState).componentName(), /* encrypt= */ true))
69                     .isEqualTo(ENCRYPTION_STATUS_UNSUPPORTED);
70 
71             assertThat(dpc(sDeviceState).devicePolicyManager().getStorageEncryption(
72                     dpc(sDeviceState).componentName())).isFalse();
73         } finally {
74             dpc(sDeviceState).devicePolicyManager().setStorageEncryption(
75                     dpc(sDeviceState).componentName(), /* encrypt= */ false);
76         }
77     }
78 
79     @CanSetPolicyTest(policy = StorageEncryption.class)
80     @RequireRunOnSystemUser
81     @RequireStorageEncryptionSupported
setStorageEncryption_runOnSystemUser_disable_isDisabled()82     public void setStorageEncryption_runOnSystemUser_disable_isDisabled() {
83         assertThat(dpc(sDeviceState).devicePolicyManager().setStorageEncryption(
84                 dpc(sDeviceState).componentName(), /* encrypt= */ false))
85                 .isEqualTo(ENCRYPTION_STATUS_INACTIVE);
86 
87         assertThat(dpc(sDeviceState).devicePolicyManager().getStorageEncryption(
88                 dpc(sDeviceState).componentName())).isFalse();
89     }
90 
91     @CanSetPolicyTest(policy = StorageEncryption.class)
92     @RequireRunOnSystemUser
93     @RequireStorageEncryptionUnsupported
setStorageEncryption_runOnSystemUser_isNotSupported_isDisabled()94     public void setStorageEncryption_runOnSystemUser_isNotSupported_isDisabled() {
95         assertThat(dpc(sDeviceState).devicePolicyManager().getStorageEncryption(
96                 dpc(sDeviceState).componentName())).isFalse();
97     }
98 
99     @CanSetPolicyTest(policy = StorageEncryption.class)
100     @RequireRunOnAdditionalUser
setStorageEncryption_runOnNonSystemUser_disable_isNotSupported()101     public void setStorageEncryption_runOnNonSystemUser_disable_isNotSupported() {
102         assertThat(dpc(sDeviceState).devicePolicyManager().setStorageEncryption(
103                 dpc(sDeviceState).componentName(), /* encrypt= */ false))
104                 .isEqualTo(ENCRYPTION_STATUS_UNSUPPORTED);
105 
106         assertThat(dpc(sDeviceState).devicePolicyManager().getStorageEncryption(
107                 dpc(sDeviceState).componentName())).isFalse();
108     }
109 
110 }
111