Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68e4888a authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Enhance component alias test.

- We no longer use the helper APKs. Removed the "apps" directory.

- Now, we create 3 instrumentation test APKs from the same source files.
They all contain aliases and targets aross each other.

And we run all the 3 test APKs.

This allows us to cover various combination, such as:
- Caller in package A -> Alias in package A -> Target in Package A
- Caller in package A -> Alias in package A -> Target in Package B
- Caller in package A -> Alias in package A -> Target in Package C
- Caller in package A -> Alias in package B -> Target in Package A
- Caller in package A -> Alias in package B -> Target in Package B
- Caller in package A -> Alias in package B -> Target in Package C
 ....

BYPASS_INCLUSIVE_LANGUAGE_REASON=legacy command name

Bug: 196254758
Test: atest frameworks/base/tests/componentalias
Change-Id: I8e00bfd1a601395641cc5d715a16db11134e81d7
parent 461c1a11
Loading
Loading
Loading
Loading
+52 −14
Original line number Diff line number Diff line
@@ -16,26 +16,14 @@ package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

android_library {
    name: "ComponentAliasTestsCommon",
    srcs: [
        "common/**/*.java",
    ],
    plugins: [
        "staledataclass-annotation-processor",
    ],
    platform_apis: true, // We use hidden APIs in the test.
}

android_test {
    name: "ComponentAliasTests",
java_defaults {
    name: "ComponentAliasTests_defaults",
    static_libs: [
        "androidx.test.rules",
        "compatibility-device-util-axt",
        "mockito-target-extended-minus-junit4",
        "truth-prebuilt",
        "ub-uiautomator",
        "ComponentAliasTestsCommon",
    ],
    libs: ["android.test.base"],
    srcs: [
@@ -46,3 +34,53 @@ android_test {
    ],
    platform_apis: true, // We use hidden APIs in the test.
}

// We build three APKs from the exact same source files, so these APKs contain the exact same tests.
// And we run the tests on each APK, so that we can test various situations:
// - When the alias is in the same package, target in the same package.
// - When the alias is in the same package, target in another package.
// - When the alias is in another package, which also contains the target.
// - When the alias is in another package, and the target is in yet another package.
// etc etc...

android_test {
    name: "ComponentAliasTests",
    defaults: [
        "ComponentAliasTests_defaults",
    ],
    package_name: "android.content.componentalias.tests",
    manifest: "AndroidManifest.xml",
    additional_manifests: [
        "AndroidManifest_service_aliases.xml",
        "AndroidManifest_service_targets.xml",
    ],
    test_config_template: "AndroidTest-template.xml",
}

android_test {
    name: "ComponentAliasTests1",
    defaults: [
        "ComponentAliasTests_defaults",
    ],
    package_name: "android.content.componentalias.tests.sub1",
    manifest: "AndroidManifest.xml",
    additional_manifests: [
        "AndroidManifest_service_aliases.xml",
        "AndroidManifest_service_targets.xml",
    ],
    test_config_template: "AndroidTest-template.xml",
}

android_test {
    name: "ComponentAliasTests2",
    defaults: [
        "ComponentAliasTests_defaults",
    ],
    package_name: "android.content.componentalias.tests.sub2",
    manifest: "AndroidManifest.xml",
    additional_manifests: [
        "AndroidManifest_service_aliases.xml",
        "AndroidManifest_service_targets.xml",
    ],
    test_config_template: "AndroidTest-template.xml",
}
+16 −33
Original line number Diff line number Diff line
@@ -14,54 +14,37 @@
 * 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.content.componentalias.tests.app" >

    package="android.content.componentalias.tests" >
    <application>
        <!--
            Alias components.
            Note aliases do not have the actual implementation, because they're never called
            directly.
            Note the alias components are essentially just placeholders, so the APKs don't have to
            have the implementation classes.
        -->

        <service android:name=".s.Alias00" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests/android.content.componentalias.tests.s.Target00" />
            <intent-filter><action android:name="android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_ALIAS_00" /></intent-filter>
        </service>
        <service android:name=".s.Alias01" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.app.sub1/android.content.componentalias.tests.app.s.Target01" />
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub1/android.content.componentalias.tests.s.Target01" />
            <intent-filter><action android:name="android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.app.IS_ALIAS_01" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_ALIAS_01" /></intent-filter>
        </service>
        <service android:name=".s.Alias02" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.app.sub2/android.content.componentalias.tests.app.s.Target02" />
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub2/android.content.componentalias.tests.s.Target02" />
            <intent-filter><action android:name="android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.app.IS_ALIAS_02" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_ALIAS_02" /></intent-filter>
        </service>
        <service android:name=".s.Alias03" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.app.sub1/android.content.componentalias.tests.app.s.Target03" />
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub1/android.content.componentalias.tests.s.Target03" />
            <intent-filter><action android:name="android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.app.IS_ALIAS_03" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.IS_ALIAS_03" /></intent-filter>
        </service>
        <service android:name=".s.Alias04" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.app.sub2/android.content.componentalias.tests.app.s.Target04" />
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.sub2/android.content.componentalias.tests.s.Target04" />
            <intent-filter><action android:name="android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.app.IS_ALIAS_04" /></intent-filter>
        </service>
        <service android:name=".s.Alias05" android:exported="true" android:enabled="true" >
            <meta-data android:name="alias_target" android:value="android.content.componentalias.tests.app.sub1/android.content.componentalias.tests.app.s.Target05" />
            <intent-filter><action android:name="android.intent.action.EXPERIMENTAL_IS_ALIAS" /></intent-filter>
            <intent-filter><action android:name="android.content.componentalias.tests.app.IS_ALIAS_05" /></intent-filter>
        </service>

        <!-- Target components -->

        <service android:name=".s.Target01" android:exported="true" android:enabled="true" >
        </service>
        <service android:name=".s.Target02" android:exported="true" android:enabled="true" >
        </service>
        <service android:name=".s.Target03" android:exported="true" android:enabled="true" >
        </service>
        <service android:name=".s.Target04" android:exported="true" android:enabled="true" >
        </service>
        <service android:name=".s.Target05" android:exported="true" android:enabled="true" >
            <intent-filter><action android:name="android.content.componentalias.tests.IS_ALIAS_04" /></intent-filter>
        </service>
    </application>
</manifest>
+3 −7
Original line number Diff line number Diff line
@@ -14,13 +14,11 @@
 * 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.content.componentalias.tests.app" >

    package="android.content.componentalias.tests" >
    <application>
        <!-- Only contain the target components -->

        <service android:name=".s.Target00" android:exported="true" android:enabled="true" >
        </service>
        <service android:name=".s.Target01" android:exported="true" android:enabled="true" >
        </service>
        <service android:name=".s.Target02" android:exported="true" android:enabled="true" >
@@ -29,7 +27,5 @@
        </service>
        <service android:name=".s.Target04" android:exported="true" android:enabled="true" >
        </service>
        <service android:name=".s.Target05" android:exported="true" android:enabled="true" >
        </service>
    </application>
</manifest>
+10 −7
Original line number Diff line number Diff line
@@ -17,18 +17,21 @@
    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true" />
        <option name="test-file-name" value="ComponentAliasTests.apk" />
        <option name="test-file-name" value="ComponentAliasAppMain.apk" />
        <option name="test-file-name" value="ComponentAliasAppSub1.apk" />
        <option name="test-file-name" value="ComponentAliasAppSub2.apk" />
        <option name="test-file-name" value="ComponentAliasTests1.apk" />
        <option name="test-file-name" value="ComponentAliasTests2.apk" />
    </target_preparer>
    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
        <!-- Exempt the helper APKs from the BG restriction, so they can start BG services. -->
        <option name="run-command" value="cmd deviceidle whitelist +android.content.componentalias.tests.app" />
        <option name="run-command" value="cmd deviceidle whitelist +android.content.componentalias.tests.app.sub1" />
        <option name="run-command" value="cmd deviceidle whitelist +android.content.componentalias.tests.app.sub2" />
        <option name="run-command" value="cmd deviceidle whitelist +android.content.componentalias.tests" />
        <option name="run-command" value="cmd deviceidle whitelist +android.content.componentalias.tests.sub1" />
        <option name="run-command" value="cmd deviceidle whitelist +android.content.componentalias.tests.sub2" />

        <option name="teardown-command" value="cmd deviceidle whitelist -android.content.componentalias.tests" />
        <option name="teardown-command" value="cmd deviceidle whitelist -android.content.componentalias.tests.sub1" />
        <option name="teardown-command" value="cmd deviceidle whitelist -android.content.componentalias.tests.sub2" />
    </target_preparer>
    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
        <option name="package" value="android.content.componentalias.tests" />
        <option name="package" value="{PACKAGE}" />
        <option name="runtime-hint" value="2m" />
        <option name="isolated-storage" value="false" />
    </test>
+0 −76
Original line number Diff line number Diff line
// 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.
// Copyright (C) 2018 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"],
}

// We build three helper APKs from the same source.
// - The main APK (ComponentAliasAppMain), which contains both the alias and the target components.
// - The sub APKs (ComponentAliasAppSub*), which only contains the target components.

java_defaults {
    name: "component_alias_app_defaults",
    libs: ["android.test.base"],
    sdk_version: "test_current",
    srcs: [
        "src/**/*.java",
    ],
    static_libs: [
        "compatibility-device-util-axt",
        "androidx.legacy_legacy-support-v4",
        "androidx.test.rules",
        "ComponentAliasTestsCommon",
    ],
}

android_test_helper_app {
    name: "ComponentAliasAppMain",
    defaults: [
        "component_alias_app_defaults",
    ],
    package_name: "android.content.componentalias.tests.app",
    manifest: "AndroidManifest_main.xml",
}

android_test_helper_app {
    name: "ComponentAliasAppSub1",
    defaults: [
        "component_alias_app_defaults",
    ],
    package_name: "android.content.componentalias.tests.app.sub1",
    manifest: "AndroidManifest_sub.xml",
}

android_test_helper_app {
    name: "ComponentAliasAppSub2",
    defaults: [
        "component_alias_app_defaults",
    ],
    package_name: "android.content.componentalias.tests.app.sub2",
    manifest: "AndroidManifest_sub.xml",
}
Loading