1// Copyright 2021 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package {
16    default_applicable_licenses: [
17        "Android-Apache-2.0",
18    ],
19}
20
21java_library {
22    name: "adservices-test-scenarios",
23    platform_apis: true,
24    static_libs: [
25        "adservices-assets",
26        "adservices-clients",
27        "mockwebserver",
28        "platform-test-annotations",
29        "adservices-test-fixtures",
30        "adservices-test-utility",
31        "adservices-ui-cts-root-test-lib",
32        "adservices-profile-text-protos-genrule",
33        "adservices-concurrent-profile-text-protos-genrule",
34        "longevity-device-lib",
35        "concurrent-longevity-device-lib",
36    ],
37    libs: [
38        "framework-adservices-lib",
39        "androidx.test.rules",
40        "androidx.test.runner",
41        "app-helpers-handheld-interfaces",
42        "guava",
43        "gson",
44        "platform-test-rules",
45        "health-testing-utils",
46        "microbenchmark-device-lib",
47        "ub-uiautomator",
48        "common-platform-scenarios",
49        "launcher-aosp-tapl",
50        "platform-test-options",
51        "hamcrest-library",
52        "androidx.media_media",
53        "modules-utils-testable-device-config",
54        "adservices-profile-text-protos-genrule",
55        "adservices-concurrent-profile-text-protos-genrule",
56        "adservices-collectors-helper",
57    ],
58
59    srcs: ["src/**/*.java"],
60    lint: {
61        extra_check_modules: ["AdServicesTestLintChecker"],
62        test: false, // TODO(b/343741206): remove when checks will run on android_test
63    },
64}
65
66java_genrule {
67    name: "adservices-profile-text-protos-genrule",
68    host_supported: true,
69    tools: ["aprotoc"],
70    srcs: [
71        ":profile-proto-def",
72        "assets/topics_profile.textpb",
73    ],
74    out: ["google-profiles.jar"],
75    /*
76     * Loops over all *.textpb files under res/ and serializes them into binary protos with ".pb"
77     * extension using aprotoc. The generated *.pb files are put under an assets/ directory, which
78     * gets packed into a .jar file and ends being under the assets/ directory in the apk package,
79     * which can then be read by the app's asset manager.
80     *
81     * If a profile fails to parse, an error is thrown and the build will fail.
82     */
83    cmd: "out_dir=$$(dirname $(out)) && assets_dir=\"assets\" && mkdir -p $$out_dir/$$assets_dir " +
84        "&& src_protos=($(locations assets/topics_profile.textpb)) && red='\x1b[0;31m' " +
85        "&& no_color='\x1b[0m' && for file in $${src_protos[@]} ; do fname=$$(basename $$file) " +
86        "&& if ! ($(location aprotoc) --encode=longevity.profile.Configuration " +
87        "$(location :profile-proto-def) < $$file > " +
88        "$$out_dir/$$assets_dir/$${fname//.textpb/.pb}) ; then " +
89        "echo \"$${red}Failed to parse profile $$file. See above for errors.$${no_color}\" " +
90        "&& exit 1 ; fi ; done && jar cf $(out) -C $$(dirname $(out)) $$assets_dir",
91}
92
93java_genrule {
94    name: "adservices-concurrent-profile-text-protos-genrule",
95    host_supported: true,
96    tools: ["aprotoc"],
97    srcs: [
98        ":concurrent-profile-proto-def",
99        "assets/concurrent-configs/*.textpb",
100    ],
101    out: ["google-profiles.jar"],
102    /*
103     * Loops over all *.textpb files under res/ and serializes them into binary protos with ".pb"
104     * extension using aprotoc. The generated *.pb files are put under an assets/ directory, which
105     * gets packed into a .jar file and ends being under the assets/ directory in the apk package,
106     * which can then be read by the app's asset manager.
107     *
108     * If a profile fails to parse, an error is thrown and the build will fail.
109     */
110    cmd: "out_dir=$$(dirname $(out)) && assets_dir=\"assets\" && mkdir -p $$out_dir/$$assets_dir " +
111        "&& src_protos=($(locations assets/concurrent-configs/*.textpb)) && red='\x1b[0;31m' " +
112        "&& no_color='\x1b[0m' && for file in $${src_protos[@]} ; do fname=$$(basename $$file) " +
113        "&& if ! ($(location aprotoc) --encode=adservices.longevity.profile.concurrent.Configuration " +
114        "$(location :concurrent-profile-proto-def) < $$file > " +
115        "$$out_dir/$$assets_dir/$${fname//.textpb/.pb}) ; then " +
116        "echo \"$${red}Failed to parse profile $$file. See above for errors.$${no_color}\" " +
117        "&& exit 1 ; fi ; done && jar cf $(out) -C $$(dirname $(out)) $$assets_dir",
118}
119