• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.deviceowner;
18 
19 import java.lang.Character;
20 
21 public class LockScreenInfoTest extends BaseDeviceOwnerTest {
22 
23     @Override
tearDown()24     public void tearDown() throws Exception {
25         mDevicePolicyManager.setDeviceOwnerLockScreenInfo(getWho(), null);
26         super.tearDown();
27     }
28 
testSetAndGetLockInfo()29     public void testSetAndGetLockInfo() {
30         setLockInfo("testSetAndGet");
31     }
32 
testClearLockInfo()33     public void testClearLockInfo() {
34         setLockInfo("testClear");
35         setLockInfo(null);
36 
37     }
38 
testEmptyStringClearsLockInfo()39     public void testEmptyStringClearsLockInfo() {
40         final String message = "";
41         mDevicePolicyManager.setDeviceOwnerLockScreenInfo(getWho(), message);
42         assertNull(mDevicePolicyManager.getDeviceOwnerLockScreenInfo());
43     }
44 
testWhitespaceOnly()45     public void testWhitespaceOnly() {
46         setLockInfo("\t");
47     }
48 
testUnicode()49     public void testUnicode() {
50         final String smiley = new String(Character.toChars(0x1F601));
51         final String phone = new String(Character.toChars(0x1F4F1));
52         setLockInfo(smiley + phone + "\t" + phone + smiley);
53     }
54 
testNullInString()55     public void testNullInString() {
56         setLockInfo("does \0 this \1 work?");
57     }
58 
testReasonablyLongString()59     public void testReasonablyLongString() {
60         final int messageLength = 128;
61         setLockInfo(new String(new char[messageLength]).replace('\0', 'Z'));
62     }
63 
testSetLockInfoWithNullAdminFails()64     public void testSetLockInfoWithNullAdminFails() {
65         final String message = "nulladmin";
66 
67         // Set message
68         try {
69             mDevicePolicyManager.setDeviceOwnerLockScreenInfo(null, message);
70             fail("Exception should have been thrown for null admin ComponentName");
71         } catch (NullPointerException expected) {
72         }
73     }
74 
75     /**
76      * Sets device owner lock screen info on behalf of the current device owner admin.
77      *
78      * @throws AssertionError if the setting did not take effect.
79      */
setLockInfo(String message)80     private void setLockInfo(String message) {
81         mDevicePolicyManager.setDeviceOwnerLockScreenInfo(getWho(), message);
82         assertEquals(message, mDevicePolicyManager.getDeviceOwnerLockScreenInfo());
83     }
84 }
85