1//
2// Copyright (C) 2020 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17package {
18    default_team: "trendy_team_fwk_core_networking",
19    // See: http://go/android-license-faq
20    default_applicable_licenses: ["Android-Apache-2.0"],
21}
22
23service_remoteauth_pre_jarjar_lib = "service-remoteauth-pre-jarjar"
24
25// The above variables may have different values
26// depending on the branch, and this comment helps
27// separate them from the rest of the file to avoid merge conflicts
28
29aidl_interface {
30    name: "connectivity_native_aidl_interface",
31    local_include_dir: "binder",
32    srcs: [
33        "binder/android/net/connectivity/aidl/*.aidl",
34    ],
35    backend: {
36        java: {
37            apex_available: [
38                "com.android.tethering",
39            ],
40            min_sdk_version: "30",
41        },
42        ndk: {
43            apex_available: [
44                "com.android.tethering",
45            ],
46            min_sdk_version: "30",
47        },
48    },
49    versions: ["1"],
50
51}
52
53cc_library_static {
54    name: "connectivity_native_aidl_interface-lateststable-ndk",
55    min_sdk_version: "30",
56    whole_static_libs: [
57        "connectivity_native_aidl_interface-V1-ndk",
58    ],
59    apex_available: [
60        "com.android.tethering",
61    ],
62}
63
64java_library {
65    name: "connectivity_native_aidl_interface-lateststable-java",
66    sdk_version: "system_current",
67    min_sdk_version: "30",
68    static_libs: [
69        "connectivity_native_aidl_interface-V1-java",
70    ],
71    apex_available: [
72        "com.android.tethering",
73    ],
74}
75
76// The library name match the service-connectivity jarjar rules that put the JNI utils in the
77// android.net.connectivity.com.android.net.module.util package.
78cc_library_shared {
79    name: "libandroid_net_connectivity_com_android_net_module_util_jni",
80    min_sdk_version: "30",
81    cflags: [
82        "-Wall",
83        "-Werror",
84        "-Wno-unused-parameter",
85        "-Wthread-safety",
86    ],
87    srcs: [
88        "jni/com_android_net_module_util/onload.cpp",
89    ],
90    static_libs: [
91        "libnet_utils_device_common_bpfjni",
92        "libnet_utils_device_common_bpfutils",
93    ],
94    shared_libs: [
95        "liblog",
96        "libnativehelper",
97    ],
98    apex_available: [
99        "com.android.tethering",
100    ],
101}
102
103cc_library_shared {
104    name: "libservice-connectivity",
105    min_sdk_version: "30",
106    cflags: [
107        "-Wall",
108        "-Werror",
109        "-Wno-unused-parameter",
110        "-Wthread-safety",
111    ],
112    srcs: [
113        ":services.connectivity-netstats-jni-sources",
114        "jni/com_android_server_connectivity_ClatCoordinator.cpp",
115        "jni/com_android_server_ServiceManagerWrapper.cpp",
116        "jni/com_android_server_TestNetworkService.cpp",
117        "jni/onload.cpp",
118    ],
119    header_libs: [
120        "bpf_connectivity_headers",
121    ],
122    static_libs: [
123        "libclat",
124        "libip_checksum",
125        "libmodules-utils-build",
126        "libnetjniutils",
127        "libnet_utils_device_common_bpfjni",
128        "libnet_utils_device_common_timerfdjni",
129        "netd_aidl_interface-lateststable-ndk",
130    ],
131    shared_libs: [
132        "libbase",
133        "libbinder_ndk",
134        "libcutils",
135        "libnetdutils",
136        "liblog",
137        "libnativehelper",
138        "libnetworkstats",
139    ],
140    apex_available: [
141        "com.android.tethering",
142    ],
143}
144
145java_library {
146    name: "service-connectivity-pre-jarjar",
147    sdk_version: "system_server_current",
148    min_sdk_version: "30",
149    // NetworkStackApiShimSettingsForCurrentBranch provides the latest available shims depending on
150    // the branch to "service-connectivity".
151    // There are Tethering.apk and TetheringNext.apk variants for the tethering APEX,
152    // which use NetworkStackApiStableShims and NetworkStackApiCurrentShims respectively.
153    // Note that there can be no service-connectivity-next because it would need to be configured in
154    // default_art_config.mk which doesn't support conditionals, hence this scheme of using a
155    // variable here.
156    defaults: ["NetworkStackApiShimSettingsForCurrentBranch"],
157    srcs: [
158        "src/**/*.java",
159        ":framework-connectivity-shared-srcs",
160        ":services-connectivity-shared-srcs",
161        ":statslog-connectivity-java-gen",
162    ],
163    libs: [
164        "framework-annotations-lib",
165        "framework-configinfrastructure.stubs.module_lib",
166        "framework-connectivity-pre-jarjar",
167        // The framework-connectivity-t library is only available on T+ platforms
168        // so any calls to it must be protected with a check to ensure that it is
169        // available. The linter will detect any unprotected calls through an API
170        // but not direct calls to the implementation. So, this depends on the
171        // module lib stubs directly to ensure the linter will work correctly
172        // as depending on framework-connectivity-t would cause it to be compiled
173        // against the implementation because the two libraries are in the same
174        // APEX.
175        "framework-connectivity-t.stubs.module_lib",
176        // TODO: figure out why just using "framework-tethering" uses the stubs, even though both
177        // service-connectivity and framework-tethering are in the same APEX.
178        "framework-tethering.impl",
179        "framework-wifi.stubs.module_lib",
180        "unsupportedappusage",
181        "ServiceConnectivityResources",
182        "framework-statsd.stubs.module_lib",
183        "framework-permission.stubs.module_lib",
184        "framework-permission-s.stubs.module_lib",
185    ],
186    static_libs: [
187        // Do not add libs here if they are already included
188        // in framework-connectivity
189        "androidx.annotation_annotation",
190        "connectivity-net-module-utils-bpf",
191        "connectivity_native_aidl_interface-lateststable-java",
192        "dnsresolver_aidl_interface-V15-java",
193        "modules-utils-shell-command-handler",
194        "net-utils-service-connectivity",
195        "netd-client",
196        "networkstack-client",
197        "PlatformProperties",
198        "service-connectivity-protos",
199        "service-connectivity-stats-protos",
200    ],
201    apex_available: [
202        "com.android.tethering",
203    ],
204    lint: {
205        baseline_filename: "lint-baseline.xml",
206
207    },
208    visibility: [
209        "//packages/modules/Connectivity/service-t",
210        "//packages/modules/Connectivity/networksecurity:__subpackages__",
211        "//packages/modules/Connectivity/tests:__subpackages__",
212        "//packages/modules/Connectivity/thread/service:__subpackages__",
213        "//packages/modules/Connectivity/thread/tests:__subpackages__",
214    ],
215}
216
217java_library {
218    name: "service-connectivity-protos",
219    sdk_version: "system_current",
220    min_sdk_version: "30",
221    proto: {
222        type: "nano",
223    },
224    srcs: [
225        ":system-messages-proto-src",
226    ],
227    libs: ["libprotobuf-java-nano"],
228    apex_available: [
229        "com.android.tethering",
230    ],
231    lint: {
232        strict_updatability_linting: true,
233
234    },
235}
236
237java_defaults {
238    name: "service-connectivity-defaults",
239    sdk_version: "system_server_current",
240    min_sdk_version: "30",
241    defaults: [
242        "standalone-system-server-module-optimize-defaults",
243    ],
244    // This library combines system server jars that have access to different bootclasspath jars.
245    // Lower SDK service jars must not depend on higher SDK jars as that would let them
246    // transitively depend on the wrong bootclasspath jars. Sources also cannot be added here as
247    // they would depend on bootclasspath jars that may not be available.
248    static_libs: [
249        "service-connectivity-pre-jarjar",
250        "service-connectivity-tiramisu-pre-jarjar",
251        "service-nearby-pre-jarjar",
252        "service-networksecurity-pre-jarjar",
253        service_remoteauth_pre_jarjar_lib,
254        "service-thread-pre-jarjar",
255    ],
256    // The below libraries are not actually needed to build since no source is compiled
257    // (only combining prebuilt static_libs), but they are necessary so that R8 has the right
258    // references to optimize the code. Without these, there will be missing class warnings and
259    // code may be wrongly optimized.
260    // R8 runs after jarjar, so the framework-X libraries need to be the post-jarjar artifacts
261    // (.impl), if they are not just stubs, so that the name of jarjared classes match.
262    libs: [
263        "androidx.annotation_annotation",
264        "framework-annotations-lib",
265        "framework-connectivity.impl",
266        "framework-connectivity-t.impl",
267        "framework-tethering.impl",
268        "framework-wifi.stubs.module_lib",
269        "libprotobuf-java-nano",
270        "framework-permission.stubs.module_lib",
271        "framework-permission-s.stubs.module_lib",
272    ],
273    jarjar_rules: ":connectivity-jarjar-rules",
274    apex_available: [
275        "com.android.tethering",
276    ],
277    optimize: {
278        proguard_flags_files: ["proguard.flags"],
279    },
280}
281
282// A special library created strictly for use by the tests as they need the
283// implementation library but that is not available when building from prebuilts.
284// Using a library with a different name to what is used by the prebuilts ensures
285// that this will never depend on the prebuilt.
286// Switching service-connectivity to a java_sdk_library would also have worked as
287// that has built in support for managing this but that is too big a change at this
288// point.
289java_library {
290    name: "service-connectivity-for-tests",
291    defaults: ["service-connectivity-defaults"],
292}
293
294java_library {
295    name: "service-connectivity",
296    defaults: ["service-connectivity-defaults"],
297    installable: true,
298}
299
300java_library_static {
301    name: "service-connectivity-stats-protos",
302    sdk_version: "system_current",
303    min_sdk_version: "30",
304    proto: {
305        type: "lite",
306    },
307    srcs: [
308        "src/com/android/metrics/stats.proto",
309    ],
310    static_libs: ["ConnectivityServiceprotos"],
311    apex_available: ["com.android.tethering"],
312}
313
314java_genrule {
315    name: "connectivity-jarjar-rules",
316    defaults: ["jarjar-rules-combine-defaults"],
317    srcs: [
318        ":framework-connectivity-jarjar-rules",
319        ":service-connectivity-jarjar-gen",
320        ":service-nearby-jarjar-gen",
321        ":service-networksecurity-jarjar-gen",
322        ":service-remoteauth-jarjar-gen",
323        ":service-thread-jarjar-gen",
324    ],
325    out: ["connectivity-jarjar-rules.txt"],
326    visibility: ["//packages/modules/Connectivity:__subpackages__"],
327}
328
329// TODO: This filegroup temporary exposes for NetworkStats. It should be
330// removed right after NetworkStats moves into mainline module.
331filegroup {
332    name: "traffic-controller-utils",
333    srcs: ["src/com/android/server/BpfNetMaps.java"],
334    visibility: ["//packages/modules/Connectivity:__subpackages__"],
335}
336
337java_genrule {
338    name: "service-connectivity-jarjar-gen",
339    tool_files: [
340        ":service-connectivity-pre-jarjar{.jar}",
341        ":service-connectivity-tiramisu-pre-jarjar{.jar}",
342        "jarjar-excludes.txt",
343    ],
344    tools: [
345        "jarjar-rules-generator",
346    ],
347    out: ["service_connectivity_jarjar_rules.txt"],
348    cmd: "$(location jarjar-rules-generator) " +
349        "$(location :service-connectivity-pre-jarjar{.jar}) " +
350        "$(location :service-connectivity-tiramisu-pre-jarjar{.jar}) " +
351        "--prefix android.net.connectivity " +
352        "--excludes $(location jarjar-excludes.txt) " +
353        "--output $(out)",
354    visibility: ["//visibility:private"],
355}
356
357java_genrule {
358    name: "service-nearby-jarjar-gen",
359    tool_files: [
360        ":service-nearby-pre-jarjar{.jar}",
361        "jarjar-excludes.txt",
362    ],
363    tools: [
364        "jarjar-rules-generator",
365    ],
366    out: ["service_nearby_jarjar_rules.txt"],
367    cmd: "$(location jarjar-rules-generator) " +
368        "$(location :service-nearby-pre-jarjar{.jar}) " +
369        "--prefix com.android.server.nearby " +
370        "--excludes $(location jarjar-excludes.txt) " +
371        "--output $(out)",
372    visibility: ["//visibility:private"],
373}
374
375java_genrule {
376    name: "service-remoteauth-jarjar-gen",
377    tool_files: [
378        ":" + service_remoteauth_pre_jarjar_lib + "{.jar}",
379        "jarjar-excludes.txt",
380    ],
381    tools: [
382        "jarjar-rules-generator",
383    ],
384    out: ["service_remoteauth_jarjar_rules.txt"],
385    cmd: "$(location jarjar-rules-generator) " +
386        "$(location :" + service_remoteauth_pre_jarjar_lib + "{.jar}) " +
387        "--prefix com.android.server.remoteauth " +
388        "--excludes $(location jarjar-excludes.txt) " +
389        "--output $(out)",
390    visibility: ["//visibility:private"],
391}
392
393java_genrule {
394    name: "service-thread-jarjar-gen",
395    tool_files: [
396        ":service-thread-pre-jarjar{.jar}",
397        "jarjar-excludes.txt",
398    ],
399    tools: [
400        "jarjar-rules-generator",
401    ],
402    out: ["service_thread_jarjar_rules.txt"],
403    cmd: "$(location jarjar-rules-generator) " +
404        "$(location :service-thread-pre-jarjar{.jar}) " +
405        "--prefix com.android.server.thread " +
406        "--excludes $(location jarjar-excludes.txt) " +
407        "--output $(out)",
408    visibility: ["//visibility:private"],
409}
410
411java_genrule {
412    name: "service-networksecurity-jarjar-gen",
413    tool_files: [
414        ":service-networksecurity-pre-jarjar{.jar}",
415        "jarjar-excludes.txt",
416    ],
417    tools: [
418        "jarjar-rules-generator",
419    ],
420    out: ["service_ct_jarjar_rules.txt"],
421    cmd: "$(location jarjar-rules-generator) " +
422        "$(location :service-networksecurity-pre-jarjar{.jar}) " +
423        "--prefix com.android.server.net.ct " +
424        "--excludes $(location jarjar-excludes.txt) " +
425        "--output $(out)",
426    visibility: ["//visibility:private"],
427}
428
429genrule {
430    name: "statslog-connectivity-java-gen",
431    tools: ["stats-log-api-gen"],
432    cmd: "$(location stats-log-api-gen) --java $(out) --module connectivity --javaPackage com.android.server --javaClass ConnectivityStatsLog",
433    out: ["com/android/server/ConnectivityStatsLog.java"],
434}
435