1 /*
2  * Copyright (C) 2021 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.security.cts;
18 
19 import android.platform.test.annotations.AppModeFull;
20 import android.util.Log;
21 import android.platform.test.annotations.AsbSecurityTest;
22 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
23 import com.android.sts.common.tradefed.testtype.NonRootSecurityTestCase;
24 import com.android.tradefed.log.LogUtil.CLog;
25 import org.junit.After;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import static org.junit.Assert.*;
31 
32 @RunWith(DeviceJUnit4ClassRunner.class)
33 public class CVE_2021_0921 extends NonRootSecurityTestCase {
34     private static final String TEST_PKG = "android.security.cts.CVE_2021_0921";
35     private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest";
36     private static final String TEST_APP = "CVE-2021-0921.apk";
37 
38     @Before
setUp()39     public void setUp() throws Exception {
40         uninstallPackage(getDevice(), TEST_PKG);
41     }
42 
43     @Test
44     @AsbSecurityTest(cveBugId = 195962697)
45     @AppModeFull
testRunDeviceTest()46     public void testRunDeviceTest() throws Exception {
47 
48         CLog.i("testRunDeviceTest() start");
49         installPackage();
50 
51         //ensure the screen is woken up.
52         //KEYCODE_WAKEUP wakes up the screen
53         //KEYCODE_MENU called twice unlocks the screen (if locked)
54         getDevice().executeShellCommand("input keyevent KEYCODE_WAKEUP");
55         getDevice().executeShellCommand("input keyevent KEYCODE_MENU");
56         getDevice().executeShellCommand("input keyevent KEYCODE_HOME");
57         getDevice().executeShellCommand("input keyevent KEYCODE_MENU");
58 
59         //run the test
60         runDeviceTests(TEST_PKG, TEST_CLASS, "test");
61         CLog.i("testRunDeviceTest() end");
62     }
63 
installPackage()64     private void installPackage() throws Exception {
65         installPackage(TEST_APP, new String[0]);
66     }
67 }
68 
69