diff --git a/javatests/com/android/modules/apkinapex/Android.bp b/javatests/com/android/modules/apkinapex/Android.bp new file mode 100644 index 0000000..39f1915 --- /dev/null +++ b/javatests/com/android/modules/apkinapex/Android.bp @@ -0,0 +1,37 @@ +/* + * 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"], +} + +java_test_host { + name: "ApkInApexTest", + srcs: [ + "ApkInApexTest.java" + ], + libs: ["tradefed"], + java_resources: [ + ":test_com.android.modules.apkinapex", + ], + static_libs: [ + "compatibility-host-util", + "cts-install-lib-host", + "frameworks-base-hostutils", + "modules-utils-build-testing", + "truth-prebuilt", + ], +} diff --git a/javatests/com/android/modules/apkinapex/ApkInApexTest.java b/javatests/com/android/modules/apkinapex/ApkInApexTest.java new file mode 100644 index 0000000..7d688ac --- /dev/null +++ b/javatests/com/android/modules/apkinapex/ApkInApexTest.java @@ -0,0 +1,80 @@ +/* + * 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 com.android.modules.apkinapex; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assume.assumeTrue; +import static org.junit.Assert.assertThrows; + +import com.android.modules.utils.build.testing.DeviceSdkLevel; +import com.android.tradefed.device.DeviceNotAvailableException; +import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; +import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.internal.util.test.SystemPreparer; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.RuleChain; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; + +import android.cts.install.lib.host.InstallUtilsHost; + +/** + * Collection of tests to test functionality of APKs in apexes. + * + *
This test installs an apex which contains APKs and then performs the tests.
+ */
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class ApkInApexTest extends BaseHostJUnit4Test {
+
+ private final InstallUtilsHost mHostUtils = new InstallUtilsHost(this);
+ private final TemporaryFolder mTemporaryFolder = new TemporaryFolder();
+ private final SystemPreparer mPreparer = new SystemPreparer(mTemporaryFolder, this::getDevice);
+
+ @Rule
+ public final RuleChain ruleChain = RuleChain.outerRule(mTemporaryFolder).around(mPreparer);
+
+ @Test
+ public void installApexAndRunTests() throws Exception {
+ if (!getDevice().isAdbRoot()) {
+ getDevice().enableAdbRoot();
+ }
+ assumeTrue("Device does not support updating APEX", mHostUtils.isApexUpdateSupported());
+ assumeTrue("Device requires root", getDevice().isAdbRoot());
+ DeviceSdkLevel deviceSdkLevel = new DeviceSdkLevel(getDevice());
+ assumeTrue("Test requires atLeastT", deviceSdkLevel.isDeviceAtLeastT());
+
+ String apex = "test_com.android.modules.apkinapex.apex";
+ mPreparer.pushResourceFile(apex, "/system/apex/" + apex);
+ mPreparer.reboot();
+
+ assertValidApkInApexInstalled();
+ assertApkInApexWithMinSdkVersionWithFutureCodenameFailed();
+ }
+
+ private void assertValidApkInApexInstalled() throws DeviceNotAvailableException {
+ String result = getDevice().executeShellCommand("pm list packages "
+ + "com.android.modules.apkinapex.apps.installable");
+ assertThat(result).isNotEmpty();
+ }
+ private void assertApkInApexWithMinSdkVersionWithFutureCodenameFailed() throws DeviceNotAvailableException {
+ String result = getDevice().executeShellCommand("pm list packages "
+ + "com.android.modules.apkinapex.apps.futureminsdk");
+ assertThat(result).isEmpty();
+ }
+}
diff --git a/javatests/com/android/modules/apkinapex/apex/Android.bp b/javatests/com/android/modules/apkinapex/apex/Android.bp
index 3301d46..29c2a2c 100644
--- a/javatests/com/android/modules/apkinapex/apex/Android.bp
+++ b/javatests/com/android/modules/apkinapex/apex/Android.bp
@@ -30,8 +30,12 @@ android_app_certificate {
apex_test {
name: "test_com.android.modules.apkinapex",
manifest: "manifest.json",
- file_contexts: ":apex.test-file_contexts", // Default, please edit, see go/android-apex-howto
+ file_contexts: ":apex.test-file_contexts",
key: "test_com.android.modules.apkinapex.key",
certificate: ":test_com.android.modules.apkinapex.certificate",
updatable: false,
+ apps: [
+ "com.android.modules.apkinapex.apps.installable",
+ "com.android.modules.apkinapex.apps.futureminsdk",
+ ],
}
diff --git a/javatests/com/android/modules/apkinapex/apps/Android.bp b/javatests/com/android/modules/apkinapex/apps/Android.bp
new file mode 100644
index 0000000..c538cef
--- /dev/null
+++ b/javatests/com/android/modules/apkinapex/apps/Android.bp
@@ -0,0 +1,36 @@
+// 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: "com.android.modules.apkinapex.apps.futureminsdk",
+ target_sdk_version: "Tiramisu",
+
+ // min sdk is overridden in the AndroidManifest.xml - but it is required to have a value here
+ // so the build system uses the value from the manifest!
+ min_sdk_version: "23",
+ apex_available: [ "test_com.android.modules.apkinapex" ],
+ manifest: "FutureMinSdkAndroidManifest.xml"
+}
+
+android_test_helper_app {
+ name: "com.android.modules.apkinapex.apps.installable",
+ target_sdk_version: "Tiramisu",
+ min_sdk_version: "23",
+ apex_available: [ "test_com.android.modules.apkinapex" ],
+ manifest: "InstallableAndroidManifest.xml"
+}
diff --git a/javatests/com/android/modules/apkinapex/apps/FutureMinSdkAndroidManifest.xml b/javatests/com/android/modules/apkinapex/apps/FutureMinSdkAndroidManifest.xml
new file mode 100644
index 0000000..0dd97db
--- /dev/null
+++ b/javatests/com/android/modules/apkinapex/apps/FutureMinSdkAndroidManifest.xml
@@ -0,0 +1,24 @@
+
+
+