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