// Copyright (C) 2019 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 {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_base_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_team: "trendy_team_mainline_modularization",
    default_applicable_licenses: ["frameworks_base_license"],
}

android_test {
    name: "RollbackTest",
    manifest: "RollbackTest/AndroidManifest.xml",
    platform_apis: true,
    srcs: ["RollbackTest/src/**/*.java"],
    static_libs: [
        "androidx.test.rules",
        "cts-install-lib",
        "cts-rollback-lib",
    ],
    test_suites: ["general-tests"],
    test_config: "RollbackTest.xml",
    java_resources: [
        ":com.android.apex.apkrollback.test_v2",
        ":com.android.apex.apkrollback.test_v2Crashing",
        ":test.rebootless_apex_v2",
    ],
}

java_test_host {
    name: "StagedRollbackTest",
    srcs: ["StagedRollbackTest/src/**/*.java"],
    libs: ["tradefed"],
    static_libs: [
        "RollbackTestLib",
        "compatibility-tradefed",
        "frameworks-base-hostutils",
        "testng",
    ],
    test_suites: ["general-tests"],
    test_config: "StagedRollbackTest.xml",
    device_common_data: [
        ":RollbackTest",
        ":com.android.apex.apkrollback.test_v1",
        ":test.rebootless_apex_v1",
    ],
}

java_test_host {
    name: "NetworkStagedRollbackTest",
    srcs: ["NetworkStagedRollbackTest/src/**/*.java"],
    libs: ["tradefed"],
    static_libs: [
        "RollbackTestLib",
        "frameworks-base-hostutils",
    ],
    test_suites: ["general-tests"],
    test_config: "NetworkStagedRollbackTest.xml",
    device_common_data: [":RollbackTest"],
}

java_test_host {
    name: "MultiUserRollbackTest",
    srcs: ["MultiUserRollbackTest/src/**/*.java"],
    libs: ["tradefed"],
    static_libs: [
        "frameworks-base-hostutils",
    ],
    test_suites: ["general-tests"],
    test_config: "MultiUserRollbackTest.xml",
    device_common_data: [":RollbackTest"],
}

java_library_host {
    name: "RollbackTestLib",
    srcs: ["lib/src/**/*.java"],
    libs: ["tradefed"],
}

genrule {
    name: "com.android.apex.apkrollback.test.pem",
    out: ["com.android.apex.apkrollback.test.pem"],
    cmd: "openssl genrsa -out $(out) 4096",
}

genrule {
    name: "com.android.apex.apkrollback.test.pubkey",
    srcs: [":com.android.apex.apkrollback.test.pem"],
    out: ["com.android.apex.apkrollback.test.pubkey"],
    tools: ["avbtool"],
    cmd: "$(location avbtool) extract_public_key --key $(in) --output $(out)",
}

apex_key {
    name: "com.android.apex.apkrollback.test.key",
    private_key: ":com.android.apex.apkrollback.test.pem",
    public_key: ":com.android.apex.apkrollback.test.pubkey",
    installable: false,
}

apex {
    name: "com.android.apex.apkrollback.test_v1",
    manifest: "testdata/manifest_v1.json",
    androidManifest: "testdata/AndroidManifest.xml",
    file_contexts: ":apex.test-file_contexts",
    key: "com.android.apex.apkrollback.test.key",
    apps: ["TestAppAv1"],
    installable: false,
    updatable: false,
}

apex {
    name: "com.android.apex.apkrollback.test_v2",
    manifest: "testdata/manifest_v2.json",
    androidManifest: "testdata/AndroidManifest.xml",
    file_contexts: ":apex.test-file_contexts",
    key: "com.android.apex.apkrollback.test.key",
    apps: ["TestAppAv2"],
    installable: false,
    updatable: false,
}

apex {
    name: "com.android.apex.apkrollback.test_v2Crashing",
    manifest: "testdata/manifest_v2.json",
    androidManifest: "testdata/AndroidManifest.xml",
    file_contexts: ":apex.test-file_contexts",
    key: "com.android.apex.apkrollback.test.key",
    apps: ["TestAppACrashingV2"],
    installable: false,
    updatable: false,
}
