• 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_applicable_licenses: ["Android-Apache-2.0"],
46}
47
48// In some branches, this may be module_current instead of module_33 if the SDK prebuilts are not
49// yet dropped there, meaning module_33 cannot be used yet.
50module_33_version = "module_33"
51
52// TODO: remove this default and replace with ConnectivityNextEnableDefaults. This will need to be
53// done separately in each branch due to merge conflicts.
54// Defaults to enable/disable java targets that depend on
55// NetworkStackNext, which uses development APIs. "enabled" may
56// have a different value depending on the branch.
57java_defaults {
58    name: "NetworkStackNextEnableDefaults",
59    enabled: true,
60}
61// This is a placeholder comment to avoid merge conflicts
62// as the above target may have different "enabled" values
63// depending on the branch
64
65java_defaults {
66    name: "NetworkStackDevApiLevel",
67    min_sdk_version: "29",
68    sdk_version: "module_current",
69    libs: [
70        "framework-connectivity",
71        "framework-connectivity-t",
72        "framework-statsd",
73        "framework-wifi",
74    ]
75}
76
77java_defaults {
78    name: "NetworkStackReleaseApiLevel",
79    sdk_version: module_33_version,
80    min_sdk_version: "29",
81    target_sdk_version: "33",
82    libs: [
83        "framework-connectivity",
84        "framework-connectivity-t",
85        "framework-statsd",
86        "framework-wifi",
87    ]
88}
89
90// Libraries for the API shims
91java_defaults {
92    name: "NetworkStackShimsDefaults",
93    libs: [
94        "androidx.annotation_annotation",
95        "networkstack-aidl-latest",
96    ],
97    static_libs : [
98        "modules-utils-build_system"
99    ],
100    apex_available: [
101        "com.android.tethering",
102        "//apex_available:platform",  // For InProcessNetworkStack and InProcessTethering
103    ],
104    min_sdk_version: "29",
105}
106
107// Common shim code. This includes the shim interface definitions themselves, and things like
108// ShimUtils and UnsupportedApiLevelException. Compiles against system_current because ShimUtils
109// needs access to all Build.VERSION_CODES.*, which by definition are only in the newest SDK.
110// TODO: consider moving ShimUtils into a library (or removing it in favour of SdkLevel) and compile
111// this target against the lowest-supported SDK (currently 29).
112java_library {
113    name: "NetworkStackShimsCommon",
114    defaults: ["NetworkStackShimsDefaults"],
115    srcs: ["apishim/common/**/*.java"],
116    sdk_version: "system_current",
117    visibility: ["//visibility:private"],
118}
119
120// Each level of the shims (29, 30, ...) is its own java_library compiled against the corresponding
121// system_X SDK. this ensures that each shim can only use SDK classes that exist in its SDK level.
122java_library {
123    name: "NetworkStackApi29Shims",
124    defaults: ["NetworkStackShimsDefaults"],
125    srcs: ["apishim/29/**/*.java"],
126    libs: [
127        "NetworkStackShimsCommon",
128    ],
129    sdk_version: "system_29",
130    visibility: ["//visibility:private"],
131}
132
133java_library {
134    name: "NetworkStackApi30Shims",
135    defaults: ["NetworkStackShimsDefaults"],
136    srcs: [
137        "apishim/30/**/*.java",
138    ],
139    libs: [
140        "NetworkStackShimsCommon",
141        "NetworkStackApi29Shims",
142    ],
143    sdk_version: "system_30",
144    visibility: ["//visibility:private"],
145    lint: {
146        strict_updatability_linting: true,
147    },
148}
149
150java_library {
151    name: "NetworkStackApi31Shims",
152    defaults: ["NetworkStackShimsDefaults"],
153    srcs: [
154        "apishim/31/**/*.java",
155    ],
156    libs: [
157        "NetworkStackShimsCommon",
158        "NetworkStackApi29Shims",
159        "NetworkStackApi30Shims",
160        "framework-connectivity",
161    ],
162    sdk_version: "module_31",
163    visibility: ["//visibility:private"],
164}
165
166java_library {
167    name: "NetworkStackApi33Shims",
168    defaults: ["NetworkStackShimsDefaults", "ConnectivityNextEnableDefaults"],
169    srcs: [
170        "apishim/33/**/*.java",
171    ],
172    static_libs: [
173        "net-utils-framework-common",
174    ],
175    libs: [
176        "NetworkStackShimsCommon",
177        "NetworkStackApi29Shims",
178        "NetworkStackApi30Shims",
179        "NetworkStackApi31Shims",
180        "framework-bluetooth",
181        "framework-connectivity",
182        "framework-connectivity-t.stubs.module_lib",
183        "framework-tethering",
184    ],
185    sdk_version: module_33_version,
186    visibility: ["//visibility:private"],
187}
188
189// Shims for APIs being added to the current development version of Android. These APIs are not
190// stable and have no defined version number. These could be called 10000, but they use the next
191// integer so if the next SDK release happens to use that integer, we don't need to rename them.
192java_library {
193    name: "NetworkStackApi34Shims",
194    defaults: ["NetworkStackShimsDefaults", "ConnectivityNextEnableDefaults"],
195    srcs: [
196        "apishim/34/**/*.java",
197    ],
198    static_libs: [
199        "net-utils-framework-common",
200    ],
201    libs: [
202        "NetworkStackShimsCommon",
203        "NetworkStackApi29Shims",
204        "NetworkStackApi30Shims",
205        "NetworkStackApi31Shims",
206        "NetworkStackApi33Shims",
207        "framework-bluetooth",
208        "framework-connectivity",
209        "framework-connectivity-t.stubs.module_lib",
210        "framework-tethering",
211    ],
212    sdk_version: "module_current",
213    visibility: ["//visibility:private"],
214}
215
216// API current uses the API current shims directly.
217// The current (in-progress) shims are in the com.android.networkstack.apishim package and are
218// called directly by the networkstack code.
219java_library {
220    name: "NetworkStackApiCurrentShims",
221    defaults: [
222        "NetworkStackShimsDefaults",
223        "NetworkStackDevApiLevel",
224        "ConnectivityNextEnableDefaults",
225    ],
226    static_libs: [
227        "NetworkStackShimsCommon",
228        "NetworkStackApi29Shims",
229        "NetworkStackApi30Shims",
230        "NetworkStackApi31Shims",
231        "NetworkStackApi33Shims",
232        "NetworkStackApi34Shims",
233    ],
234    visibility: [
235        "//packages/modules/Connectivity/Tethering",
236        "//packages/modules/Connectivity/service",
237        "//packages/modules/Connectivity/service-t",
238        "//packages/modules/Connectivity/tests/cts/net",
239        "//packages/modules/Connectivity/tests/cts/hostside/app",
240    ],
241}
242
243// API stable uses jarjar to rename the latest stable apishim package from
244// com.android.networkstack.apishim.apiXX to com.android.networkstack.apishim, which is called by
245// the networkstack code.
246java_library {
247    name: "NetworkStackApiStableShims",
248    defaults: ["NetworkStackShimsDefaults", "NetworkStackReleaseApiLevel"],
249    static_libs: [
250        "NetworkStackShimsCommon",
251        "NetworkStackApi29Shims",
252        "NetworkStackApi30Shims",
253        "NetworkStackApi31Shims",
254        "NetworkStackApi33Shims",
255    ],
256    jarjar_rules: "apishim/jarjar-rules-compat.txt",
257    visibility: [
258        "//packages/modules/Connectivity/Tethering",
259        "//packages/modules/Connectivity/service",
260        "//packages/modules/Connectivity/service-t",
261        "//packages/modules/Connectivity/tests/cts:__subpackages__",
262    ],
263}
264
265// Common defaults for android libraries containing network stack code, used to compile variants of
266// the network stack in the system process and in the network_stack process
267java_defaults {
268    name: "NetworkStackAndroidLibraryDefaults",
269    srcs: [
270        ":framework-networkstack-shared-srcs",
271        ":networkstack-module-utils-srcs",
272    ],
273    libs: ["unsupportedappusage"],
274    static_libs: [
275        "androidx.annotation_annotation",
276        "modules-utils-build_system",
277        "modules-utils-preconditions",
278        "modules-utils-statemachine",
279        "netd_aidl_interface-lateststable-java",
280        "networkstack-client",
281        "net-utils-framework-common",
282        // See note on statsprotos when adding/updating proto build rules
283        "datastallprotosnano",
284        "statsprotos",
285        "captiveportal-lib",
286        "net-utils-device-common",
287        "net-utils-device-common-netlink",
288    ],
289    plugins: ["java_api_finder"],
290}
291
292// The versions of the android library containing network stack code compiled for each SDK variant.
293android_library {
294    name: "NetworkStackApiCurrentLib",
295    defaults: [
296        "NetworkStackDevApiLevel",
297        "NetworkStackAndroidLibraryDefaults",
298        "ConnectivityNextEnableDefaults",
299    ],
300    srcs: [
301        "src/**/*.java",
302        ":statslog-networkstack-java-gen-current"
303    ],
304    static_libs: ["NetworkStackApiCurrentShims"],
305    manifest: "AndroidManifestBase.xml",
306    visibility: [
307        "//frameworks/base/tests/net/integration",
308        "//packages/modules/Connectivity/Tethering/tests/integration",
309        "//packages/modules/Connectivity/tests/cts/net",
310        "//packages/modules/NetworkStack/tests/unit",
311        "//packages/modules/NetworkStack/tests/integration",
312    ],
313    lint: { strict_updatability_linting: true },
314}
315
316android_library {
317    name: "NetworkStackApiStableLib",
318    defaults: ["NetworkStackReleaseApiLevel", "NetworkStackAndroidLibraryDefaults"],
319    srcs: [
320        "src/**/*.java",
321        ":statslog-networkstack-java-gen-stable",
322    ],
323    static_libs: ["NetworkStackApiStableShims"],
324    manifest: "AndroidManifestBase.xml",
325    visibility: [
326        "//frameworks/base/packages/Connectivity/tests/integration",
327        "//frameworks/base/tests/net/integration",
328        "//packages/modules/Connectivity/Tethering/tests/integration",
329        "//packages/modules/Connectivity/tests/cts/net",
330        "//packages/modules/Connectivity/tests/integration",
331        "//packages/modules/NetworkStack/tests/unit",
332        "//packages/modules/NetworkStack/tests/integration",
333    ],
334    lint: { strict_updatability_linting: true },
335}
336
337filegroup {
338    name: "NetworkStackJarJarRules",
339    srcs: ["jarjar-rules-shared.txt"],
340    visibility: [
341        "//packages/modules/NetworkStack/tests/unit",
342        "//packages/modules/NetworkStack/tests/integration",
343        "//packages/modules/Connectivity/tests:__subpackages__",
344        "//packages/modules/Connectivity/Tethering/tests/integration",
345    ]
346}
347
348// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries
349java_defaults {
350    name: "NetworkStackAppDefaults",
351    privileged: true,
352    jni_libs: [
353        "libnativehelper_compat_libc++",
354        "libnetworkstackutilsjni",
355    ],
356    // Resources already included in NetworkStackBase
357    resource_dirs: [],
358    jarjar_rules: ":NetworkStackJarJarRules",
359    use_embedded_native_libs: true,
360    optimize: {
361        proguard_flags_files: ["proguard.flags"],
362    },
363}
364
365// Non-updatable network stack running in the system server process for devices not using the module
366android_app {
367    name: "InProcessNetworkStack",
368    defaults: [
369        "NetworkStackAppDefaults",
370        "NetworkStackDevApiLevel",
371        "ConnectivityNextEnableDefaults",
372    ],
373    static_libs: ["NetworkStackApiCurrentLib"],
374    certificate: "platform",
375    manifest: "AndroidManifest_InProcess.xml",
376    // InProcessNetworkStack is a replacement for NetworkStack
377    overrides: ["NetworkStack", "NetworkStackNext"],
378    // The InProcessNetworkStack goes together with the PlatformCaptivePortalLogin, which replaces
379    // the default CaptivePortalLogin.
380    required: [
381        "PlatformCaptivePortalLogin",
382    ],
383}
384
385// Pre-merge the AndroidManifest for NetworkStackNext, so that its manifest can be merged on top
386android_library {
387    name: "NetworkStackNextManifestBase",
388    defaults: [
389        "NetworkStackAppDefaults",
390        "NetworkStackDevApiLevel",
391        "ConnectivityNextEnableDefaults",
392    ],
393    static_libs: ["NetworkStackApiCurrentLib"],
394    manifest: "AndroidManifest.xml"
395}
396
397// NetworkStack build targeting the current API release, for testing on in-development SDK
398android_app {
399    name: "NetworkStackNext",
400    defaults: [
401        "NetworkStackAppDefaults",
402        "NetworkStackDevApiLevel",
403        "ConnectivityNextEnableDefaults",
404    ],
405    static_libs: ["NetworkStackNextManifestBase"],
406    certificate: "networkstack",
407    manifest: "AndroidManifest_Next.xml",
408    required: [
409        "privapp_whitelist_com.android.networkstack",
410    ],
411    lint: { strict_updatability_linting: true },
412}
413
414// Updatable network stack for finalized API
415android_app {
416    name: "NetworkStack",
417    defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
418    static_libs: ["NetworkStackApiStableLib"],
419    certificate: "networkstack",
420    manifest: "AndroidManifest.xml",
421    required: [
422        "privapp_whitelist_com.android.networkstack",
423    ],
424    updatable: true,
425    lint: { strict_updatability_linting: true },
426}
427
428cc_library_shared {
429    name: "libnetworkstackutilsjni",
430    srcs: [
431        "jni/network_stack_utils_jni.cpp"
432    ],
433    sdk_version: "29",
434    min_sdk_version: "29",
435    shared_libs: [
436        "liblog",
437        "libnativehelper_compat_libc++",
438    ],
439    static_libs: [
440        "libnetjniutils",
441    ],
442
443    // We cannot use plain "libc++" here to link libc++ dynamically because it results in:
444    //   java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
445    // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't
446    // build because soong complains of:
447    //   module NetworkStack missing dependencies: libc++_shared
448    //
449    // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries
450    // we depend on do not dynamically link libc++. This is currently the case, because liblog is
451    // C-only and libnativehelper_compat_libc also uses stl: "c++_static".
452    //
453    // TODO: find a better solution for this in R.
454    stl: "c++_static",
455    cflags: [
456        "-Wall",
457        "-Werror",
458        "-Wno-unused-parameter",
459    ],
460}
461
462genrule {
463    name: "statslog-networkstack-java-gen-current",
464    tools: ["stats-log-api-gen"],
465    cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
466         " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
467         " --minApiLevel 29",
468    out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
469}
470
471genrule {
472    name: "statslog-networkstack-java-gen-stable",
473    tools: ["stats-log-api-gen"],
474    cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
475         " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
476         " --minApiLevel 29 --compileApiLevel 30",
477    out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
478}
479
480
481version_code_networkstack_next = "300000000"
482version_code_networkstack_test = "999999999"
483
484genrule {
485    name: "NetworkStackTestAndroidManifest",
486    srcs: ["AndroidManifest.xml"],
487    out: ["TestAndroidManifest.xml"],
488    cmd: "sed -E 's/versionCode=\"[0-9]+\"/versionCode=\""
489        + version_code_networkstack_test
490        + "\"/' $(in) > $(out)",
491    visibility: ["//visibility:private"],
492}
493
494android_app {
495    name: "TestNetworkStack",
496    defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
497    static_libs: ["NetworkStackApiStableLib"],
498    certificate: "networkstack",
499    manifest: ":NetworkStackTestAndroidManifest",
500    required: [
501        "privapp_whitelist_com.android.networkstack",
502    ],
503}
504
505// When adding or modifying protos, the jarjar rules and possibly proguard rules need
506// to be updated: proto libraries may pull additional static libraries.
507java_library_static {
508    name: "statsprotos",
509    proto: {
510        type: "lite",
511    },
512    srcs: [
513        "src/com/android/networkstack/metrics/stats.proto",
514    ],
515    static_libs: [
516        "networkstackprotos",
517    ],
518    defaults: ["NetworkStackReleaseApiLevel"],
519}
520