• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
2// Copyright (C) 2018 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
17// The network stack can be compiled using system_current (non-finalized) SDK, or finalized system_X
18// SDK. There is also a variant that uses system_current SDK and runs in the system process
19// (InProcessNetworkStack). The following structure is used to create the build rules:
20//
21//                          NetworkStackAndroidLibraryDefaults <-- common defaults for android libs
22//                                            /    \
23//           +NetworkStackApiStableShims --> /      \ <-- +NetworkStackApiCurrentShims
24//           +NetworkStackReleaseApiLevel   /        \    +NetworkStackDevApiLevel
25//           +jarjar apishim.api[latest].* /          \
26//            to apishim.*                /            \
27//                                       /              \
28//                                      /                \
29//                                     /                  \               android libs w/ all code
30//                                    / <- +module src/ -> \              (also used in unit tests)
31//                                   /                      \                        |
32//               NetworkStackApiStableLib               NetworkStackApiCurrentLib <--*
33//                          |                                     |
34//                          | <--   +NetworkStackAppDefaults  --> |
35//                          |          (APK build params)         |
36//                          |                                     |
37//                          | <-- +NetworkStackReleaseApiLevel    | <-- +NetworkStackDevApiLevel
38//                          |                                     |
39//                          |                                     |
40//                NetworkStackApiStable          NetworkStack, InProcessNetworkStack, <-- APKs
41//                                                         TestNetworkStack
42
43// Common defaults to define SDK level
44package {
45    default_team: "trendy_team_fwk_core_networking",
46    default_applicable_licenses: ["Android-Apache-2.0"],
47}
48
49// TODO: remove this default and replace with ConnectivityNextEnableDefaults. This will need to be
50// done separately in each branch due to merge conflicts.
51// Defaults to enable/disable java targets that depend on
52// NetworkStackNext, which uses development APIs. "enabled" may
53// have a different value depending on the branch.
54java_defaults {
55    name: "NetworkStackNextEnableDefaults",
56    enabled: true,
57}
58
59// This is a placeholder comment to avoid merge conflicts
60// as the above target may have different "enabled" values
61// depending on the branch
62
63java_defaults {
64    name: "NetworkStackDevApiLevel",
65    min_sdk_version: "30",
66    sdk_version: "module_current",
67    libs: [
68        "framework-configinfrastructure",
69        "framework-connectivity",
70        "framework-connectivity-t",
71        "framework-statsd",
72        "framework-wifi",
73    ],
74}
75
76// Common defaults for NetworkStack integration tests, root tests and coverage tests
77// to keep tests always running against the same target sdk version with NetworkStack.
78java_defaults {
79    name: "NetworkStackReleaseTargetSdk",
80    min_sdk_version: "30",
81    target_sdk_version: "35",
82}
83
84java_defaults {
85    name: "NetworkStackReleaseApiLevel",
86    defaults: ["NetworkStackReleaseTargetSdk"],
87    sdk_version: "module_current",
88    libs: [
89        "framework-configinfrastructure",
90        "framework-connectivity.stubs.module_lib",
91        "framework-connectivity-t",
92        "framework-statsd",
93        "framework-wifi",
94    ],
95}
96
97// Libraries for the API shims
98java_defaults {
99    name: "NetworkStackShimsDefaults",
100    libs: [
101        "androidx.annotation_annotation",
102        "networkstack-aidl-latest",
103    ],
104    static_libs: [
105        "modules-utils-build_system",
106    ],
107    apex_available: [
108        "com.android.tethering",
109        "//apex_available:platform", // For InProcessNetworkStack
110    ],
111    min_sdk_version: "30",
112}
113
114// Common shim code. This includes the shim interface definitions themselves, and things like
115// ShimUtils and UnsupportedApiLevelException. Compiles against system_current because ShimUtils
116// needs access to all Build.VERSION_CODES.*, which by definition are only in the newest SDK.
117// TODO: consider moving ShimUtils into a library (or removing it in favour of SdkLevel) and compile
118// this target against the lowest-supported SDK (currently 30).
119java_library {
120    name: "NetworkStackShimsCommon",
121    defaults: ["NetworkStackShimsDefaults"],
122    srcs: ["apishim/common/**/*.java"],
123    sdk_version: "system_current",
124    visibility: ["//visibility:private"],
125}
126
127// Each level of the shims (29, 30, ...) is its own java_library compiled against the corresponding
128// system_X SDK. this ensures that each shim can only use SDK classes that exist in its SDK level.
129java_library {
130    name: "NetworkStackApi29Shims",
131    defaults: ["NetworkStackShimsDefaults"],
132    srcs: ["apishim/29/**/*.java"],
133    libs: [
134        "NetworkStackShimsCommon",
135    ],
136    sdk_version: "system_29",
137    visibility: ["//visibility:private"],
138}
139
140java_library {
141    name: "NetworkStackApi30Shims",
142    defaults: ["NetworkStackShimsDefaults"],
143    srcs: [
144        "apishim/30/**/*.java",
145    ],
146    libs: [
147        "NetworkStackShimsCommon",
148        "NetworkStackApi29Shims",
149    ],
150    sdk_version: "system_30",
151    visibility: ["//visibility:private"],
152    lint: {
153        strict_updatability_linting: true,
154
155    },
156}
157
158java_library {
159    name: "NetworkStackApi31Shims",
160    defaults: ["NetworkStackShimsDefaults"],
161    srcs: [
162        "apishim/31/**/*.java",
163    ],
164    static_libs: [
165        // Libs building against module API can only be linked against when building against
166        // module API (so NetworkStackApi30Shims or NetworkStackApi29Shims can't use it, since they
167        // use system_30 and system_29 respectively).
168        "net-utils-framework-common",
169    ],
170    libs: [
171        "NetworkStackShimsCommon",
172        "NetworkStackApi29Shims",
173        "NetworkStackApi30Shims",
174        "framework-connectivity",
175        "framework-wifi",
176    ],
177    sdk_version: "module_31",
178    visibility: ["//visibility:private"],
179}
180
181java_library {
182    name: "NetworkStackApi33Shims",
183    defaults: ["NetworkStackShimsDefaults"],
184    srcs: [
185        "apishim/33/**/*.java",
186    ],
187    libs: [
188        "NetworkStackShimsCommon",
189        "NetworkStackApi29Shims",
190        "NetworkStackApi30Shims",
191        "NetworkStackApi31Shims",
192        "framework-bluetooth",
193        "framework-connectivity",
194        "framework-connectivity-t.stubs.module_lib",
195        "framework-tethering",
196        "framework-wifi",
197    ],
198    sdk_version: "module_33",
199    visibility: ["//visibility:private"],
200}
201
202java_library {
203    name: "NetworkStackApi34Shims",
204    defaults: ["NetworkStackShimsDefaults"],
205    srcs: [
206        "apishim/34/**/*.java",
207    ],
208    libs: [
209        "NetworkStackShimsCommon",
210        "NetworkStackApi29Shims",
211        "NetworkStackApi30Shims",
212        "NetworkStackApi31Shims",
213        "NetworkStackApi33Shims",
214        "framework-bluetooth",
215        "framework-connectivity",
216        "framework-connectivity-t.stubs.module_lib",
217        "framework-tethering",
218        "framework-wifi",
219    ],
220    sdk_version: "module_34",
221    visibility: ["//visibility:private"],
222}
223
224// Shims for APIs being added to the current development version of Android. These APIs are not
225// stable and have no defined version number. These could be called 10000, but they use the next
226// integer so if the next SDK release happens to use that integer, we don't need to rename them.
227// Jarjar rules are generated based on the stable shims, which do not contain this library. As a
228// result, no static_lib that needs jarjar should be used here. In general, static_libs should not
229// be used in this library at all; instead they can be in one of the earlier, shim libraries which
230// are part of the stable shims and scanned when generating jarjar rules.
231java_library {
232    name: "NetworkStackApi35Shims",
233    defaults: [
234        "NetworkStackShimsDefaults",
235        "ConnectivityNextEnableDefaults",
236    ],
237    srcs: [
238        "apishim/35/**/*.java",
239    ],
240    libs: [
241        "NetworkStackShimsCommon",
242        "NetworkStackApi29Shims",
243        "NetworkStackApi30Shims",
244        "NetworkStackApi31Shims",
245        "NetworkStackApi33Shims",
246        "NetworkStackApi34Shims",
247        "framework-bluetooth",
248        "framework-connectivity",
249        "framework-connectivity-t.stubs.module_lib",
250        "framework-tethering",
251        "framework-wifi",
252        "android.net.ipsec.ike.stubs.module_lib",
253    ],
254    sdk_version: "module_current",
255    visibility: ["//visibility:private"],
256}
257
258// API current uses the API current shims directly.
259// The current (in-progress) shims are in the com.android.networkstack.apishim package and are
260// called directly by the networkstack code.
261java_library {
262    name: "NetworkStackApiCurrentShims",
263    defaults: [
264        "NetworkStackShimsDefaults",
265        "NetworkStackDevApiLevel",
266        "ConnectivityNextEnableDefaults",
267    ],
268    static_libs: [
269        "NetworkStackShimsCommon",
270        "NetworkStackApi29Shims",
271        "NetworkStackApi30Shims",
272        "NetworkStackApi31Shims",
273        "NetworkStackApi33Shims",
274        "NetworkStackApi34Shims",
275        "NetworkStackApi35Shims",
276    ],
277    visibility: [
278        "//packages/modules/Connectivity/Tethering",
279        "//packages/modules/Connectivity/service",
280        "//packages/modules/Connectivity/service-t",
281        "//packages/modules/Connectivity/tests:__subpackages__",
282    ],
283}
284
285// API stable uses jarjar to rename the latest stable apishim package from
286// com.android.networkstack.apishim.apiXX to com.android.networkstack.apishim, which is called by
287// the networkstack code.
288java_library {
289    name: "NetworkStackApiStableShims",
290    defaults: [
291        "NetworkStackShimsDefaults",
292        "NetworkStackReleaseApiLevel",
293    ],
294    static_libs: [
295        "NetworkStackShimsCommon",
296        "NetworkStackApi29Shims",
297        "NetworkStackApi30Shims",
298        "NetworkStackApi31Shims",
299        "NetworkStackApi33Shims",
300        "NetworkStackApi34Shims",
301    ],
302    jarjar_rules: "apishim/jarjar-rules-compat.txt",
303    visibility: [
304        "//packages/modules/Connectivity/Tethering",
305        "//packages/modules/Connectivity/service",
306        "//packages/modules/Connectivity/service-t",
307        "//packages/modules/Connectivity/tests:__subpackages__",
308    ],
309}
310
311// Common defaults for android libraries containing network stack code, used to compile variants of
312// the network stack in the system process and in the network_stack process
313java_defaults {
314    name: "NetworkStackAndroidLibraryDefaults",
315    srcs: [
316        ":framework-networkstack-shared-srcs",
317    ],
318    libs: [
319        "error_prone_annotations",
320        "unsupportedappusage",
321    ],
322    static_libs: [
323        "androidx.annotation_annotation",
324        "modules-utils-build_system",
325        "modules-utils-preconditions",
326        "modules-utils-shell-command-handler",
327        "modules-utils-statemachine",
328        "netd_aidl_interface-lateststable-java",
329        "networkstack-client",
330        "net-utils-framework-common",
331        // See note on statsprotos when adding/updating proto build rules
332        "datastallprotosnano",
333        "statsprotos",
334        "captiveportal-lib",
335        "net-utils-device-common-ip",
336        "net-utils-device-common-netlink",
337        "net-utils-device-common-struct",
338        "net-utils-device-common-struct-base",
339    ],
340}
341
342// The versions of the android library containing network stack code compiled for each SDK variant.
343android_library {
344    name: "NetworkStackApiCurrentLib",
345    defaults: [
346        "NetworkStackDevApiLevel",
347        "NetworkStackAndroidLibraryDefaults",
348        "ConnectivityNextEnableDefaults",
349    ],
350    srcs: [
351        "src/**/*.java",
352        ":statslog-networkstack-java-gen-current",
353    ],
354    static_libs: [
355        "NetworkStackApiCurrentShims",
356    ],
357    manifest: "AndroidManifestBase.xml",
358    visibility: [
359        "//frameworks/base/tests/net/integration",
360        "//packages/modules/Connectivity/Tethering/tests/integration",
361        "//packages/modules/NetworkStack/tests/unit",
362        "//packages/modules/NetworkStack/tests/integration",
363    ],
364}
365
366android_library {
367    name: "NetworkStackApiStableLib",
368    defaults: [
369        "NetworkStackReleaseApiLevel",
370        "NetworkStackAndroidLibraryDefaults",
371    ],
372    srcs: [
373        "src/**/*.java",
374        ":statslog-networkstack-java-gen-stable",
375    ],
376    static_libs: [
377        "NetworkStackApiStableShims",
378    ],
379    manifest: "AndroidManifestBase.xml",
380    visibility: [
381        "//packages/modules/Connectivity/Tethering/tests/integration",
382        "//packages/modules/Connectivity/tests/integration",
383        "//packages/modules/NetworkStack/tests/unit",
384        "//packages/modules/NetworkStack/tests/integration",
385    ],
386}
387
388java_library {
389    name: "DhcpPacketLib",
390    defaults: ["NetworkStackReleaseApiLevel"],
391    srcs: [
392        "src/android/net/DhcpResults.java",
393        "src/android/net/dhcp/Dhcp*Packet.java",
394    ],
395    libs: [
396        "androidx.annotation_annotation",
397        "framework-annotations-lib",
398    ],
399    static_libs: [
400        "modules-utils-build",
401        "net-utils-framework-common",
402        "networkstack-client",
403        "net-utils-device-common",
404    ],
405    // If this library is ever used outside of tests, it should not use "Dhcp*Packet", and specify
406    // its contents explicitly.
407    visibility: [
408        "//packages/modules/Connectivity/Tethering/tests/integration",
409        "//packages/modules/Connectivity/tests/cts/net",
410    ],
411}
412
413java_library {
414    name: "ApfGeneratorLib",
415    defaults: ["NetworkStackReleaseApiLevel"],
416    srcs: [
417        "src/android/net/apf/ApfConstants.java",
418        "src/android/net/apf/ApfCounterTracker.java",
419        "src/android/net/apf/ApfV4Generator.java",
420        "src/android/net/apf/ApfV4GeneratorBase.java",
421        "src/android/net/apf/ApfV6Generator.java",
422        "src/android/net/apf/ApfV6GeneratorBase.java",
423        "src/android/net/apf/BaseApfGenerator.java",
424    ],
425    libs: [
426        "androidx.annotation_annotation",
427        "framework-annotations-lib",
428    ],
429    static_libs: [
430        "net-utils-framework-common",
431    ],
432    visibility: [
433        "//packages/modules/Connectivity/tests/cts/net",
434    ],
435}
436
437java_genrule {
438    name: "NetworkStackJarJarRules",
439    tool_files: [
440        // com.android.networkstack.apishim is already in the target package that is not jarjared,
441        // so it does not matter whether ApiStable or ApiCurrent is used to generate the jarjar
442        // rules. Use ApiStable to be based on most stable release configuration and be buildable
443        // in all branches.
444        ":NetworkStackApiStableLib{.jar}",
445        "jarjar-excludes.txt",
446    ],
447    tools: [
448        "jarjar-rules-generator",
449    ],
450    out: ["NetworkStackJarJarRules.txt"],
451    cmd: "$(location jarjar-rules-generator) " +
452        "$(location :NetworkStackApiStableLib{.jar}) " +
453        "--prefix com.android.networkstack " +
454        "--excludes $(location jarjar-excludes.txt) " +
455        "--output $(out)",
456    visibility: [
457        "//packages/modules/NetworkStack/tests/unit",
458        "//packages/modules/NetworkStack/tests/integration",
459        "//packages/modules/Connectivity/tests:__subpackages__",
460        "//packages/modules/Connectivity/Tethering/tests/integration",
461    ],
462}
463
464// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries
465java_defaults {
466    name: "NetworkStackAppDefaults",
467    privileged: true,
468    jni_libs: [
469        "libnativehelper_compat_libc++",
470        "libnetworkstackutilsjni",
471    ],
472    // Resources already included in NetworkStackBase
473    resource_dirs: [],
474    jarjar_rules: ":NetworkStackJarJarRules",
475    use_embedded_native_libs: true,
476    optimize: {
477        ignore_warnings: false,
478        proguard_flags_files: ["proguard.flags"],
479    },
480}
481
482// Non-updatable network stack running in the system server process for devices not using the module
483android_app {
484    name: "InProcessNetworkStack",
485    defaults: [
486        "NetworkStackAppDefaults",
487        "NetworkStackDevApiLevel",
488        "ConnectivityNextEnableDefaults",
489    ],
490    static_libs: ["NetworkStackApiCurrentLib"],
491    certificate: "platform",
492    manifest: "AndroidManifest_InProcess.xml",
493    // InProcessNetworkStack is a replacement for NetworkStack
494    overrides: [
495        "NetworkStack",
496        "NetworkStackNext",
497    ],
498    // The InProcessNetworkStack goes together with the PlatformCaptivePortalLogin, which replaces
499    // the default CaptivePortalLogin.
500    required: [
501        "PlatformCaptivePortalLogin",
502    ],
503}
504
505// Pre-merge the AndroidManifest for NetworkStackNext, so that its manifest can be merged on top
506android_library {
507    name: "NetworkStackNextManifestBase",
508    defaults: [
509        "NetworkStackAppDefaults",
510        "NetworkStackDevApiLevel",
511        "ConnectivityNextEnableDefaults",
512    ],
513    static_libs: ["NetworkStackApiCurrentLib"],
514    manifest: "AndroidManifest.xml",
515}
516
517// NetworkStack build targeting the current API release, for testing on in-development SDK
518android_app {
519    name: "NetworkStackNext",
520    defaults: [
521        "NetworkStackAppDefaults",
522        "NetworkStackDevApiLevel",
523        "ConnectivityNextEnableDefaults",
524    ],
525    static_libs: ["NetworkStackNextManifestBase"],
526    certificate: "networkstack",
527    manifest: "AndroidManifest_Next.xml",
528    required: [
529        "privapp_whitelist_com.android.networkstack",
530    ],
531    updatable: true,
532}
533
534// Updatable network stack for finalized API
535android_app {
536    name: "NetworkStack",
537    defaults: [
538        "NetworkStackAppDefaults",
539        "NetworkStackReleaseApiLevel",
540    ],
541    static_libs: ["NetworkStackApiStableLib"],
542    certificate: "networkstack",
543    manifest: "AndroidManifest.xml",
544    required: [
545        "privapp_whitelist_com.android.networkstack",
546    ],
547    updatable: true,
548}
549
550cc_library_shared {
551    name: "libnetworkstackutilsjni",
552    srcs: [
553        "jni/network_stack_utils_jni.cpp",
554    ],
555    header_libs: [
556        "bpf_headers",
557    ],
558    sdk_version: "30",
559    min_sdk_version: "30",
560    shared_libs: [
561        "liblog",
562        "libnativehelper_compat_libc++",
563    ],
564    static_libs: [
565        "libnetjniutils",
566    ],
567
568    // We cannot use plain "libc++" here to link libc++ dynamically because it results in:
569    //   java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
570    // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't
571    // build because soong complains of:
572    //   module NetworkStack missing dependencies: libc++_shared
573    //
574    // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries
575    // we depend on do not dynamically link libc++. This is currently the case, because liblog is
576    // C-only and libnativehelper_compat_libc also uses stl: "c++_static".
577    //
578    // TODO: find a better solution for this in R.
579    stl: "c++_static",
580    cflags: [
581        "-Wall",
582        "-Werror",
583        "-Wno-unused-parameter",
584    ],
585}
586
587genrule {
588    name: "statslog-networkstack-java-gen-current",
589    tools: ["stats-log-api-gen"],
590    cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
591        " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
592        " --minApiLevel 30",
593    out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
594}
595
596genrule {
597    name: "statslog-networkstack-java-gen-stable",
598    tools: ["stats-log-api-gen"],
599    cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
600        " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
601        " --minApiLevel 30",
602    out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
603}
604
605version_code_networkstack_next = "300000000"
606version_code_networkstack_test = "999999999"
607
608genrule {
609    name: "NetworkStackTestAndroidManifest",
610    srcs: ["AndroidManifest.xml"],
611    out: ["TestAndroidManifest.xml"],
612    cmd: "sed -E 's/versionCode=\"[0-9]+\"/versionCode=\"" +
613        version_code_networkstack_test +
614        "\"/' $(in) > $(out)",
615    visibility: ["//visibility:private"],
616}
617
618android_app {
619    name: "TestNetworkStack",
620    defaults: [
621        "NetworkStackAppDefaults",
622        "NetworkStackReleaseApiLevel",
623    ],
624    static_libs: ["NetworkStackApiStableLib"],
625    certificate: "networkstack",
626    manifest: ":NetworkStackTestAndroidManifest",
627    required: [
628        "privapp_whitelist_com.android.networkstack",
629    ],
630}
631
632// When adding or modifying protos, the jarjar rules and possibly proguard rules need
633// to be updated: proto libraries may pull additional static libraries.
634java_library_static {
635    name: "statsprotos",
636    proto: {
637        type: "lite",
638    },
639    srcs: [
640        "src/com/android/networkstack/metrics/stats.proto",
641    ],
642    static_libs: [
643        "networkstackprotos",
644    ],
645    defaults: ["NetworkStackReleaseApiLevel"],
646}
647