1// Copyright (C) 2022 The Android Open Source Project
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: ["Android-Apache-2.0"],
17}
18
19genrule {
20    name: "statslog-adservices-java-gen",
21    tools: ["stats-log-api-gen"],
22    cmd: "$(location stats-log-api-gen) --java $(out) --module adservices" +
23        " --javaPackage com.android.adservices.service.stats --javaClass AdServicesStatsLog",
24    out: ["com/android/adservices/service/stats/AdServicesStatsLog.java"],
25}
26
27// Converts the text proto Cobalt registry into a binary proto.
28genrule {
29    name: "cobalt-registry-binarypb-gen",
30    srcs: [
31        "resources/cobalt_registry.textpb",
32        ":adservices-cobalt-proto",
33    ],
34    out: ["cobalt_registry.binarypb"],
35    tools: ["aprotoc"],
36    cmd: "$(location aprotoc) --encode=cobalt.CobaltRegistry " +
37        "--proto_path=packages/modules/AdServices/adservices/libraries/cobalt/proto " +
38        "packages/modules/AdServices/adservices/libraries/cobalt/proto/cobalt_registry.proto " +
39        "< $(location resources/cobalt_registry.textpb) > $(out)",
40}
41
42// Outputs a class confirming the Cobalt registry asset is validated, conditioned on
43// the asset binary proto and text proto being the same.
44genrule {
45    name: "cobalt-registry-validated-java",
46    srcs: [
47        ":checked_in_cobalt_registry_binarypb",
48        ":cobalt-registry-binarypb-gen",
49        "resources/CobaltRegistryValidated.java",
50    ],
51    // Compare the generated binary proto to the asset binary proto and fail if they
52    // are different. Additionally, print a message with instructions on how to update
53    // the asset binary proto.
54    cmd: "cp $(location resources/CobaltRegistryValidated.java) $(out) && " +
55        "cmp -s $(location :cobalt-registry-binarypb-gen) $(location :checked_in_cobalt_registry_binarypb) " +
56        "|| (echo -e '\\n\\n################################################################\\n#\\n" +
57        "#  ERROR: Binary registry is out of date.  To update it, run:\\n#\\n" +
58        "#  cp $(location :cobalt-registry-binarypb-gen) " +
59        "packages/modules/AdServices/adservices/apk/assets/cobalt/cobalt_registry.binarypb\\n#\\n" +
60        "################################################################\\n\\n' >&2 && false)",
61    out: ["com/android/adservices/cobalt/CobaltRegistryValidated.java"],
62}
63
64filegroup {
65    name: "adservices-service-core-sources",
66    srcs: [
67        "java/**/*.java",
68    ],
69    path: "java",
70    visibility: [
71        "//packages/modules/AdServices/adservices/tests:__subpackages__",
72        "//package/modules/ExtServices/extservices:__subpackages__",
73    ],
74}
75
76filegroup {
77    name: "adservices-service-core-jni-sources",
78    srcs: [
79        "jni/java/**/*.java",
80    ],
81    path: "jni",
82    visibility: [
83        "//packages/modules/AdServices/adservices:__subpackages__",
84    ],
85}
86
87filegroup {
88    name: "adservices-service-core-flags-constants-sources",
89    srcs: [
90        "java/com/android/adservices/cobalt/CobaltConstants.java",
91        "java/com/android/adservices/service/CommonFlagsConstants.java",
92        "java/com/android/adservices/service/DebugFlagsConstants.java",
93        "java/com/android/adservices/service/FlagsConstants.java",
94    ],
95    path: "java",
96    visibility: [
97        "//packages/modules/AdServices/adservices/tests/test-util",
98    ],
99}
100
101// TODO(b/306522832): move to Shared/ and change packages (to something like
102// c.a.ads.flags), although we'd need to be consider whether to make sure it's
103// used only by adservices itself, not ODP (or SdkSandbox)
104filegroup {
105    name: "adservices-service-common-flags-sources",
106    srcs: [
107        "java/com/android/adservices/service/CommonDebugFlags.java",
108        "java/com/android/adservices/service/CommonFlagsConstants.java",
109        "java/com/android/adservices/service/DeviceConfigFlagsHelper.java",
110    ],
111    path: "java",
112    visibility: [
113        "//packages/modules/AdServices/adservices/service",
114    ],
115}
116
117filegroup {
118    name: "adservices-service-core-phflags-sources",
119    srcs: [
120        ":adservices-service-core-flags-constants-sources",
121        ":adservices-service-common-flags-sources",
122        "java/com/android/adservices/service/Flags.java",
123        "java/com/android/adservices/service/FlagsFactory.java",
124        "java/com/android/adservices/service/PhFlags.java",
125        "java/com/android/adservices/service/DebugFlags.java",
126    ],
127    path: "java",
128    visibility: [
129        "//packages/modules/AdServices/adservices/tests/test-util",
130    ],
131}
132
133android_library {
134    name: "adservices-service-core",
135    sdk_version: "module_current",
136    min_sdk_version: "30",
137    srcs: [
138        ":adservices-service-core-sources",
139        ":adservices-service-core-jni-sources",
140        ":cobalt-registry-validated-java",
141        ":statslog-adservices-java-gen",
142    ],
143    manifest: "AndroidManifest.xml",
144    plugins: [
145        "androidx.appsearch_appsearch-compiler-plugin",
146        "androidx.room_room-compiler-plugin",
147        "auto_oneof_plugin",
148        "auto_value_plugin",
149        "auto_annotation_plugin",
150    ],
151    javacflags: [
152        "-Aroom.schemaLocation=packages/modules/AdServices/adservices/service-core/schemas",
153    ],
154    libs: [
155        "androidx.room_room-runtime",
156        "framework-annotations-lib", // For @SystemApi, etc
157        "framework-adservices.impl",
158        "framework-configinfrastructure",
159        "framework-sdksandbox.impl",
160        "framework-ondevicepersonalization",
161        "framework-statsd.stubs.module_lib", // For WW logging
162        "jsr305",
163        "auto_value_annotations",
164    ],
165    static_libs: [
166        "androidx.concurrent_concurrent-futures",
167        "androidx.annotation_annotation",
168        "androidx.appsearch_appsearch",
169        "androidx.appsearch_appsearch-platform-storage",
170        "cbor-java",
171        "mobile_data_downloader_lib",
172        "modules-utils-preconditions",
173        "tflite_support_classifiers_java",
174        "mobile_data_downloader_lib",
175        "androidx.webkit_webkit",
176        "androidx.javascriptengine_javascriptengine",
177        "adservices-cobalt",
178        "adservices-proto-lite",
179        "adservices-grpclib-lite",
180        "adservices-shared-common",
181        "adservices-shared-error-logging",
182        "adservices-shared-spe",
183        "adservices-shared-storage",
184        "adservices-shared-util",
185        "modules-utils-build",
186    ],
187    jarjar_rules: "jarjar-rules.txt",
188    apex_available: [
189        "com.android.adservices",
190        "com.android.extservices",
191    ],
192    lint: {
193        extra_check_modules: ["AdServicesProdLintChecker"],
194        baseline_filename: "lint-baseline.xml",
195
196    },
197}
198
199cc_library_shared {
200    name: "libhpke_jni",
201    min_sdk_version: "30",
202    sdk_version: "current",
203    stl: "libc++_static",
204    cflags: [
205        "-Werror",
206        "-Wno-unused-parameter",
207        "-Wno-unused-but-set-variable",
208    ],
209    srcs: [
210        "jni/cpp/hpke_jni.cpp",
211        "jni/cpp/ohttp_jni.cpp",
212        "jni/cpp/act_jni.cpp",
213    ],
214    include_dirs: ["packages/modules/AdServices/adservices/service-core/jni/include"],
215    header_libs: ["jni_headers"],
216    shared_libs: [
217        "liblog",
218    ],
219    static_libs: [
220        "libact",
221        "libcrypto_static",
222    ],
223    version_script: "jni/version-script.lds",
224    apex_available: [
225        "//apex_available:platform",
226        "com.android.adservices",
227        "com.android.extservices",
228    ],
229    visibility: [
230        "//packages/modules/AdServices:__subpackages__",
231        "//packages/modules/ExtServices:__subpackages__",
232    ],
233}
234
235// Schemas needs to be bundled via this android_library since service-core unit tests for schema
236// migration will need this.
237android_library {
238    name: "adservices-service-core-schema",
239    sdk_version: "module_current",
240    min_sdk_version: "30",
241    asset_dirs: [
242        "schemas",
243    ],
244    // Must use EmptyManifest.xml since this will be used by the service-core tests. If we use the
245    // normal "AndroidManifest.xml", we may introduce potential error like redeclare permissions.
246    // See b/228270294 for the error about duplicated permissions.
247    manifest: "EmptyManifest.xml",
248    lint: {
249        baseline_filename: "lint-baseline2.xml",
250    },
251}
252