Create e2e test for apk-in-apex with a future minSdkVersion

Apk in apex should not be installed.

Test: atest ApkInApexTest

Test: (test the test:) manually change AndroidManifest.xml of the app and set
the min sdk version to 30. Repeat the test and the test should fail (because
with min sdk version 30, the app should be installable).

Bug: 208239394

Ignore-AOSP-First: feature not in AOSP yet

Change-Id: I7caa31fe366b74d74f1d8e9e53d6ddd241a70751
This commit is contained in:
Pedro Loureiro
2022-04-12 13:15:21 +00:00
parent 7545c47c27
commit dc0f07a271
6 changed files with 201 additions and 1 deletions

View File

@@ -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",
],
}

View File

@@ -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.
*
* <p>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();
}
}

View File

@@ -30,8 +30,12 @@ android_app_certificate {
apex_test { apex_test {
name: "test_com.android.modules.apkinapex", name: "test_com.android.modules.apkinapex",
manifest: "manifest.json", 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", key: "test_com.android.modules.apkinapex.key",
certificate: ":test_com.android.modules.apkinapex.certificate", certificate: ":test_com.android.modules.apkinapex.certificate",
updatable: false, updatable: false,
apps: [
"com.android.modules.apkinapex.apps.installable",
"com.android.modules.apkinapex.apps.futureminsdk",
],
} }

View File

@@ -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"
}

View File

@@ -0,0 +1,24 @@
<?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="com.android.modules.apkinapex.apps.futureminsdk">
<!-- on purpose we use a non-existing minSdkVersion to simulate a future API codename that
was not known when this device was compiled -->
<uses-sdk
android:minSdkVersion="FutureSdkCodename"
/>
</manifest>

View File

@@ -0,0 +1,19 @@
<?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="com.android.modules.apkinapex.apps.installable">
</manifest>