• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 static com.android.sts.common.CommandUtil.runAndCheck;
20 
21 import static com.google.common.truth.TruthJUnit.assume;
22 
23 import static org.junit.Assume.assumeNoException;
24 
25 import android.platform.test.annotations.AsbSecurityTest;
26 
27 import com.android.sts.common.UserUtils.SecondaryUser;
28 import com.android.sts.common.tradefed.testtype.NonRootSecurityTestCase;
29 import com.android.tradefed.device.ITestDevice;
30 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
31 import com.android.tradefed.testtype.junit4.DeviceTestRunOptions;
32 
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 
36 @RunWith(DeviceJUnit4ClassRunner.class)
37 public class CVE_2024_0053 extends NonRootSecurityTestCase {
38 
39     @AsbSecurityTest(cveBugId = 281525042)
40     @Test
testPocCVE_2024_0053()41     public void testPocCVE_2024_0053() {
42         ITestDevice device = null;
43         try {
44             device = getDevice();
45 
46             // Get userId of primary user
47             int primaryUserId = device.getCurrentUser();
48             try (AutoCloseable asSecondaryUser =
49                     new SecondaryUser(device).name("cve_2024_0053_user").doSwitch().withUser()) {
50 
51                 // Capture Screenshot
52                 runAndCheck(device, "input keyevent KEYCODE_SYSRQ");
53 
54                 // Switch back to primary user
55                 assume().withMessage("Failed to switch user back to primary user")
56                         .that(device.switchUser(primaryUserId))
57                         .isTrue();
58 
59                 // Install application in primary user
60                 installPackage("CVE-2024-0053.apk");
61 
62                 // Run DeviceTest
63                 final String testPkg = "android.security.cts.CVE_2024_0053";
64                 runDeviceTests(
65                         new DeviceTestRunOptions(testPkg)
66                                 .setDevice(getDevice())
67                                 .setTestClassName(testPkg + ".DeviceTest")
68                                 .setTestMethodName("testPocCVE_2024_0053")
69                                 .setDisableHiddenApiCheck(true));
70             }
71         } catch (Exception e) {
72             assumeNoException(e);
73         } finally {
74             try {
75                 // To exit the test gracefully
76                 runAndCheck(device, "input keyevent KEYCODE_HOME");
77             } catch (Exception e) {
78                 // Ignore all exceptions
79             }
80         }
81     }
82 }
83