• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.cts.deviceandprofileowner;
18 
19 import android.content.ComponentName;
20 
21 import java.util.concurrent.TimeUnit;
22 
23 public class RequiredStrongAuthTimeoutTest extends BaseDeviceAdminTest {
24 
25     private static final long DEFAULT_STRONG_AUTH_TIMEOUT_MS = TimeUnit.HOURS.toMillis(72);
26     private static final long MINIMUM_STRONG_AUTH_TIMEOUT_MS = TimeUnit.HOURS.toMillis(1);
27     private static final long ONE_MINUTE = TimeUnit.MINUTES.toMillis(1);
28     private static final long MIN_PLUS_ONE_MINUTE = MINIMUM_STRONG_AUTH_TIMEOUT_MS + ONE_MINUTE;
29     private static final long MAX_MINUS_ONE_MINUTE = DEFAULT_STRONG_AUTH_TIMEOUT_MS - ONE_MINUTE;
30 
31     private static final ComponentName ADMIN = ADMIN_RECEIVER_COMPONENT;
32 
testSetRequiredStrongAuthTimeout()33     public void testSetRequiredStrongAuthTimeout() throws Exception {
34         // aggregation should be the default if unset by any admin
35         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(null),
36                 DEFAULT_STRONG_AUTH_TIMEOUT_MS);
37 
38         // admin not participating by default
39         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(ADMIN), 0);
40 
41         //clamping from the top
42         mDevicePolicyManager.setRequiredStrongAuthTimeout(ADMIN,
43                 DEFAULT_STRONG_AUTH_TIMEOUT_MS + ONE_MINUTE);
44         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(ADMIN),
45                 DEFAULT_STRONG_AUTH_TIMEOUT_MS);
46         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(null),
47                 DEFAULT_STRONG_AUTH_TIMEOUT_MS);
48 
49         // 0 means the admin is not participating, so default should be returned
50         mDevicePolicyManager.setRequiredStrongAuthTimeout(ADMIN, 0);
51         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(ADMIN), 0);
52         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(null),
53                 DEFAULT_STRONG_AUTH_TIMEOUT_MS);
54 
55         // clamping from the bottom
56         mDevicePolicyManager.setRequiredStrongAuthTimeout(ADMIN,
57                 MINIMUM_STRONG_AUTH_TIMEOUT_MS - ONE_MINUTE);
58         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(ADMIN),
59                 MINIMUM_STRONG_AUTH_TIMEOUT_MS);
60         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(null),
61                 MINIMUM_STRONG_AUTH_TIMEOUT_MS);
62 
63         // values within range
64         mDevicePolicyManager.setRequiredStrongAuthTimeout(ADMIN, MIN_PLUS_ONE_MINUTE);
65         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(ADMIN), MIN_PLUS_ONE_MINUTE);
66         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(null), MIN_PLUS_ONE_MINUTE);
67 
68         mDevicePolicyManager.setRequiredStrongAuthTimeout(ADMIN, MAX_MINUS_ONE_MINUTE);
69         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(ADMIN),
70                 MAX_MINUS_ONE_MINUTE);
71         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(null), MAX_MINUS_ONE_MINUTE);
72 
73         // reset to default
74         mDevicePolicyManager.setRequiredStrongAuthTimeout(ADMIN, 0);
75         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(ADMIN), 0);
76         assertEquals(mDevicePolicyManager.getRequiredStrongAuthTimeout(null),
77                 DEFAULT_STRONG_AUTH_TIMEOUT_MS);
78 
79         // negative value
80         try {
81             mDevicePolicyManager.setRequiredStrongAuthTimeout(ADMIN, -ONE_MINUTE);
82             fail("Didn't throw IllegalArgumentException");
83         } catch (IllegalArgumentException iae) {
84         }
85     }
86 }
87