1 /* 2 * Copyright (C) 2022 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 org.junit.Assume.assumeNoException; 20 import static org.junit.Assume.assumeTrue; 21 22 import android.platform.test.annotations.AsbSecurityTest; 23 24 import com.android.sts.common.tradefed.testtype.NonRootSecurityTestCase; 25 import com.android.tradefed.device.ITestDevice; 26 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 27 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 @RunWith(DeviceJUnit4ClassRunner.class) 32 public class CVE_2022_20223 extends NonRootSecurityTestCase { 33 34 @AsbSecurityTest(cveBugId = 223578534) 35 @Test testPocCVE_2022_20223()36 public void testPocCVE_2022_20223() { 37 ITestDevice device = getDevice(); 38 final String testPkg = "android.security.cts.CVE_2022_20223"; 39 int userId = -1; 40 try { 41 // Wake up the screen 42 AdbUtils.runCommandLine("input keyevent KEYCODE_WAKEUP", device); 43 AdbUtils.runCommandLine("input keyevent KEYCODE_MENU", device); 44 AdbUtils.runCommandLine("input keyevent KEYCODE_HOME", device); 45 46 // Create restricted user 47 String commandOutput = AdbUtils.runCommandLine( 48 "pm create-user --restricted CVE_2022_20223_RestrictedUser", device); 49 50 // Extract user id of the restricted user 51 String[] tokens = commandOutput.split("\\s+"); 52 assumeTrue(tokens.length > 0); 53 assumeTrue(tokens[0].equals("Success:")); 54 userId = Integer.parseInt(tokens[tokens.length - 1]); 55 56 // Install PoC application 57 installPackage("CVE-2022-20223.apk"); 58 59 runDeviceTests(testPkg, testPkg + ".DeviceTest", "testAppRestrictionsFragment"); 60 } catch (Exception e) { 61 assumeNoException(e); 62 } finally { 63 try { 64 // Back to home screen after test 65 AdbUtils.runCommandLine("input keyevent KEYCODE_HOME", device); 66 if (userId != -1) { 67 // Remove restricted user 68 AdbUtils.runCommandLine("pm remove-user " + userId, device); 69 } 70 } catch (Exception e) { 71 assumeNoException(e); 72 } 73 } 74 } 75 } 76