Add end-to-end testing of extension-sdk attribute
So far the behavior of this tag has only been verified in the
PackageManager unit tests. Add an end-to-end test as well.
Test: atest SdkExtensionsHostTest
Change-Id: I318354c6e674b8767c15493a1b630a86e79a0eab
diff --git a/tests/e2e/Android.bp b/tests/e2e/Android.bp
index cc73e20..47400e3 100644
--- a/tests/e2e/Android.bp
+++ b/tests/e2e/Android.bp
@@ -26,6 +26,8 @@
],
data: [
":sdkextensions_e2e_test_app",
+ ":sdkextensions_e2e_test_app_req_r12",
+ ":sdkextensions_e2e_test_app_req_r45",
":test_com.android.media",
":test_com.android.sdkext",
],
diff --git a/tests/e2e/apps-with-reqs/Android.bp b/tests/e2e/apps-with-reqs/Android.bp
new file mode 100644
index 0000000..2e8671c
--- /dev/null
+++ b/tests/e2e/apps-with-reqs/Android.bp
@@ -0,0 +1,25 @@
+// Copyright (C) 2021 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.
+
+android_app {
+ name: "sdkextensions_e2e_test_app_req_r12",
+ sdk_version: "current",
+ manifest: "AndroidManifest-r12.xml"
+}
+
+android_app {
+ name: "sdkextensions_e2e_test_app_req_r45",
+ sdk_version: "current",
+ manifest: "AndroidManifest-r45.xml"
+}
diff --git a/tests/e2e/apps-with-reqs/AndroidManifest-r12.xml b/tests/e2e/apps-with-reqs/AndroidManifest-r12.xml
new file mode 100644
index 0000000..92aff31
--- /dev/null
+++ b/tests/e2e/apps-with-reqs/AndroidManifest-r12.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 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="com.android.tests.apex.sdkextensions.r12">
+
+ <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="29">
+ <extension-sdk android:sdkVersion="30" android:minExtensionVersion="12" />
+ </uses-sdk>
+
+ <application android:hasCode="false"></application>
+</manifest>
diff --git a/tests/e2e/apps-with-reqs/AndroidManifest-r45.xml b/tests/e2e/apps-with-reqs/AndroidManifest-r45.xml
new file mode 100644
index 0000000..ff5eb0e
--- /dev/null
+++ b/tests/e2e/apps-with-reqs/AndroidManifest-r45.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 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="com.android.tests.apex.sdkextensions.r45">
+
+ <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="29">
+ <extension-sdk android:sdkVersion="30" android:minExtensionVersion="45" />
+ </uses-sdk>
+
+ <application android:hasCode="false"></application>
+</manifest>
diff --git a/tests/e2e/test-src/com/android/tests/apex/sdkextensions/SdkExtensionsHostTest.java b/tests/e2e/test-src/com/android/tests/apex/sdkextensions/SdkExtensionsHostTest.java
index ecee769..324a7a7 100644
--- a/tests/e2e/test-src/com/android/tests/apex/sdkextensions/SdkExtensionsHostTest.java
+++ b/tests/e2e/test-src/com/android/tests/apex/sdkextensions/SdkExtensionsHostTest.java
@@ -48,6 +48,10 @@
private static final String APP_FILENAME = "sdkextensions_e2e_test_app.apk";
private static final String APP_PACKAGE = "com.android.tests.apex.sdkextensions";
+ private static final String APP_R12_FILENAME = "sdkextensions_e2e_test_app_req_r12.apk";
+ private static final String APP_R12_PACKAGE = "com.android.tests.apex.sdkextensions.r12";
+ private static final String APP_R45_FILENAME = "sdkextensions_e2e_test_app_req_r45.apk";
+ private static final String APP_R45_PACKAGE = "com.android.tests.apex.sdkextensions.r45";
private static final String MEDIA_FILENAME = "test_com.android.media.apex";
private static final String SDKEXTENSIONS_FILENAME = "test_com.android.sdkext.apex";
@@ -109,6 +113,15 @@
assertVersion45();
}
+ private boolean canInstallApp(String filename, String packageName) throws Exception {
+ File appFile = mInstallUtils.getTestFile(filename);
+ String installResult = getDevice().installPackage(appFile, true);
+ if (installResult == null) {
+ assertNull(getDevice().uninstallPackage(packageName));
+ }
+ return installResult == null;
+ }
+
private int getExtensionVersionR() throws Exception {
int appValue = Integer.parseInt(broadcast("GET_SDK_VERSION"));
int syspropValue = getExtensionVersionRFromSysprop();
@@ -135,16 +148,24 @@
private void assertVersion0() throws Exception {
assertEquals(0, getExtensionVersionR());
assertEquals("true", broadcast("MAKE_CALLS_0"));
+ File testAppFile = mInstallUtils.getTestFile(APP_FILENAME);
+ String installResult = getDevice().installPackage(testAppFile, true);
+ assertFalse(canInstallApp(APP_R12_FILENAME, APP_R12_PACKAGE));
+ assertFalse(canInstallApp(APP_R45_FILENAME, APP_R45_PACKAGE));
}
private void assertVersion12() throws Exception {
assertEquals(12, getExtensionVersionR());
assertEquals("true", broadcast("MAKE_CALLS_45")); // sdkext 45 APIs are available in 12 too.
+ assertTrue(canInstallApp(APP_R12_FILENAME, APP_R12_PACKAGE));
+ assertFalse(canInstallApp(APP_R45_FILENAME, APP_R45_PACKAGE));
}
private void assertVersion45() throws Exception {
assertEquals(45, getExtensionVersionR());
assertEquals("true", broadcast("MAKE_CALLS_45"));
+ assertTrue(canInstallApp(APP_R12_FILENAME, APP_R12_PACKAGE));
+ assertTrue(canInstallApp(APP_R45_FILENAME, APP_R45_PACKAGE));
}
private static String getBroadcastCommand(String action) {