summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRhed Jao <rhedjao@google.com>2022-09-27 10:51:54 +0800
committerRhed Jao <rhedjao@google.com>2022-09-27 21:44:02 +0800
commit6808b857c5e7366ccd726abddbe5e52920c465a0 (patch)
tree3757c4b0ce02676eee1fc54282e87ed4c64902aa
parent14d7ae6116d0c81dde189d8442b6b23b44151bf8 (diff)
downloadcts-6808b857c5e7366ccd726abddbe5e52920c465a0.tar.gz
[DO NOT MERGE] Test to verify setComponentEnabledSetting with invalid component
Bug: 240936919 Test: atest android.security.cts.PackageManagerTest Change-Id: I983f7512d2a2b2c7b24e5e86c6562e1e43e38d19
-rw-r--r--tests/tests/security/Android.bp1
-rw-r--r--tests/tests/security/AndroidManifest.xml1
-rw-r--r--tests/tests/security/AndroidTest.xml5
-rw-r--r--tests/tests/security/src/android/security/cts/PackageManagerTest.java99
-rw-r--r--tests/tests/security/test-apps/DummyTargetApi15TestApp/Android.bp27
-rw-r--r--tests/tests/security/test-apps/DummyTargetApi15TestApp/AndroidManifest.xml21
6 files changed, 154 insertions, 0 deletions
diff --git a/tests/tests/security/Android.bp b/tests/tests/security/Android.bp
index 4df69907958..ef13480ceaa 100644
--- a/tests/tests/security/Android.bp
+++ b/tests/tests/security/Android.bp
@@ -63,6 +63,7 @@ android_test {
data: [
":CtsUsePermissionApp22_2",
":CtsHelperAppOverlay",
+ ":CtsDummyTargetApi15TestApp",
],
//sdk_version: "current",
platform_apis: true,
diff --git a/tests/tests/security/AndroidManifest.xml b/tests/tests/security/AndroidManifest.xml
index 4c21179fa98..7d1a496d337 100644
--- a/tests/tests/security/AndroidManifest.xml
+++ b/tests/tests/security/AndroidManifest.xml
@@ -28,6 +28,7 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
<!-- For FileIntegrityManager -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
diff --git a/tests/tests/security/AndroidTest.xml b/tests/tests/security/AndroidTest.xml
index a0e8fcf1c82..d8e6f7677a7 100644
--- a/tests/tests/security/AndroidTest.xml
+++ b/tests/tests/security/AndroidTest.xml
@@ -44,7 +44,12 @@
value="pm uninstall --user 0 android.security.cts" />
</target_preparer>
+ <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+ <option name="run-command" value="mkdir -p /data/local/tmp/cts/security" />
+ <option name="teardown-command" value="rm -rf /data/local/tmp/cts"/>
+ </target_preparer>
<target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher">
+ <option name="push" value="CtsDummyTargetApi15TestApp.apk->/data/local/tmp/cts/security/CtsDummyTargetApi15TestApp.apk" />
<option name="push" value="CtsUsePermissionApp22_2.apk->/data/local/tmp/cts/permission3/CtsUsePermissionApp22_2.apk" />
<option name="push" value="CtsHelperAppOverlay.apk->/data/local/tmp/cts/permission3/CtsHelperAppOverlay.apk" />
</target_preparer>
diff --git a/tests/tests/security/src/android/security/cts/PackageManagerTest.java b/tests/tests/security/src/android/security/cts/PackageManagerTest.java
new file mode 100644
index 00000000000..8c27a70a391
--- /dev/null
+++ b/tests/tests/security/src/android/security/cts/PackageManagerTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.security.cts;
+
+import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
+
+import static com.android.compatibility.common.util.ShellUtils.runShellCommand;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.core.Is.is;
+
+import android.Manifest;
+import android.content.ComponentName;
+import android.content.pm.PackageManager;
+import android.platform.test.annotations.AppModeFull;
+import android.platform.test.annotations.AsbSecurityTest;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+
+import com.android.sts.common.util.StsExtraBusinessLogicTestCase;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.File;
+
+@AppModeFull
+@RunWith(AndroidJUnit4.class)
+public class PackageManagerTest extends StsExtraBusinessLogicTestCase {
+ private static final String DUMMY_API15_APK_PATH =
+ "/data/local/tmp/cts/security/CtsDummyTargetApi15TestApp.apk";
+ private static final String DUMMY_API15_PACKAGE_NAME =
+ "android.security.cts.dummy.api15";
+ private static final ComponentName INVALID_COMPONENT_NAME =
+ ComponentName.createRelative(DUMMY_API15_PACKAGE_NAME, ".InvalidClassName");
+
+ private PackageManager mPackageManager;
+
+ @Before
+ public void setUp() {
+ mPackageManager = InstrumentationRegistry.getInstrumentation()
+ .getTargetContext().getPackageManager();
+
+ installPackage(DUMMY_API15_APK_PATH);
+ InstrumentationRegistry
+ .getInstrumentation()
+ .getUiAutomation()
+ .adoptShellPermissionIdentity(Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE);
+ }
+
+ @After
+ public void tearDown() {
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .dropShellPermissionIdentity();
+ uninstallPackage(DUMMY_API15_PACKAGE_NAME);
+ }
+
+ @AsbSecurityTest(cveBugId = 240936919)
+ @Test
+ public void setComponentEnabledSetting_targetPkgIsApi15_withInvalidComponentName() {
+ mPackageManager.setComponentEnabledSetting(
+ INVALID_COMPONENT_NAME, COMPONENT_ENABLED_STATE_ENABLED, 0 /* flags */);
+ assertThat(mPackageManager.getComponentEnabledSetting(INVALID_COMPONENT_NAME),
+ not(is(COMPONENT_ENABLED_STATE_ENABLED)));
+ }
+
+ private static void installPackage(String apkPath) {
+ assertThat(new File(apkPath).exists(), is(true));
+ final StringBuilder cmd = new StringBuilder("pm install ");
+ cmd.append(apkPath);
+ final String result = runShellCommand(cmd.toString()).trim();
+ assertThat(result, containsString("Success"));
+ }
+
+ private static void uninstallPackage(String packageName) {
+ final StringBuilder cmd = new StringBuilder("pm uninstall ");
+ cmd.append(packageName);
+ runShellCommand(cmd.toString());
+ }
+}
diff --git a/tests/tests/security/test-apps/DummyTargetApi15TestApp/Android.bp b/tests/tests/security/test-apps/DummyTargetApi15TestApp/Android.bp
new file mode 100644
index 00000000000..2cfcd55beae
--- /dev/null
+++ b/tests/tests/security/test-apps/DummyTargetApi15TestApp/Android.bp
@@ -0,0 +1,27 @@
+//
+// Copyright (C) 2022 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test_helper_app {
+ name: "CtsDummyTargetApi15TestApp",
+ defaults: ["cts_defaults"],
+ sdk_version: "current",
+ target_sdk_version: "15",
+ min_sdk_version: "15",
+}
diff --git a/tests/tests/security/test-apps/DummyTargetApi15TestApp/AndroidManifest.xml b/tests/tests/security/test-apps/DummyTargetApi15TestApp/AndroidManifest.xml
new file mode 100644
index 00000000000..aa25f1a0713
--- /dev/null
+++ b/tests/tests/security/test-apps/DummyTargetApi15TestApp/AndroidManifest.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2022 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.security.cts.dummy.api15" >
+ <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" />
+ <application android:hasCode="false" android:label="Dummy Test App" />
+</manifest>