• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.platform.test.annotations.AsbSecurityTest;
21 import android.platform.test.annotations.RequiresDevice;
22 import com.android.tradefed.device.ITestDevice;
23 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
24 import com.android.sts.common.tradefed.testtype.NonRootSecurityTestCase;
25 import java.util.regex.Pattern;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 
31 import static org.hamcrest.core.Is.is;
32 import static org.junit.Assert.assertThat;
33 import static org.junit.Assume.assumeTrue;
34 
35 @RunWith(DeviceJUnit4ClassRunner.class)
36 public class CVE_2021_0591 extends NonRootSecurityTestCase {
37 
38     private static final String TEST_PKG = "android.security.cts.CVE_2021_0591";
39     private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest";
40     private static final String TEST_APP = "CVE-2021-0591.apk";
41 
42     @Before
setUp()43     public void setUp() throws Exception {
44         uninstallPackage(getDevice(), TEST_PKG);
45     }
46 
47     /**
48      * b/179386960
49      */
50     @AppModeFull
51     @AsbSecurityTest(cveBugId = 179386960)
52     @Test
testPocCVE_2021_0591()53     public void testPocCVE_2021_0591() throws Exception {
54         ITestDevice device = getDevice();
55 
56         assumeTrue("Bluetooth is not available on device",
57                 device.hasFeature("android.hardware.bluetooth"));
58 
59         /* Clear the logs in the beginning */
60         AdbUtils.runCommandLine("logcat -c", device);
61         installPackage();
62         try {
63             runDeviceTests(TEST_PKG, TEST_CLASS, "testClick");
64         } catch (AssertionError error) {
65             /* runDeviceTests crashed, do not continue */
66             error.printStackTrace();
67             return;
68         }
69         String screenshotServiceErrorReceiver =
70                 "com.android.systemui.screenshot.ScreenshotServiceErrorReceiver";
71         String logcat =
72                 AdbUtils.runCommandLine("logcat -d BluetoothPermissionActivity *:S", device);
73         Pattern pattern = Pattern.compile(screenshotServiceErrorReceiver, Pattern.MULTILINE);
74         String message = "Device is vulnerable to b/179386960 "
75                 + "hence it is possible to sent a broadcast intent to "
76                 + screenshotServiceErrorReceiver;
77         assertThat(message, pattern.matcher(logcat).find(), is(false));
78     }
79 
installPackage()80     private void installPackage() throws Exception {
81         installPackage(TEST_APP, new String[0]);
82     }
83 }
84