blob: 83bcd9127df87fd731dadf897f539955e7398184 [file] [log] [blame]
Remi NGUYEN VANded23152018-12-07 16:52:24 +09001//
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
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090017// 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
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090022// / \
23// +NetworkStackApiStableShims --> / \ <-- +NetworkStackApiCurrentShims
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +090024// +NetworkStackReleaseApiLevel / \ +NetworkStackDevApiLevel
Lorenzo Colittid6709182021-02-22 01:38:39 +090025// +jarjar apishim.api[latest].* / \
26// to apishim.* / \
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090027// / \
Lorenzo Colittid6709182021-02-22 01:38:39 +090028// / \
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090029// / \ android libs w/ all code
Lorenzo Colittid6709182021-02-22 01:38:39 +090030// / <- +module src/ -> \ (also used in unit tests)
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090031// / \ |
32// NetworkStackApiStableLib NetworkStackApiCurrentLib <--*
33// | |
34// | <-- +NetworkStackAppDefaults --> |
35// | (APK build params) |
36// | |
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +090037// | <-- +NetworkStackReleaseApiLevel | <-- +NetworkStackDevApiLevel
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090038// | |
39// | |
40// NetworkStackApiStable NetworkStack, InProcessNetworkStack, <-- APKs
41// TestNetworkStack
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090042
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090043// Common defaults to define SDK level
Bob Badourdd486972021-02-12 15:05:06 -080044package {
45 default_applicable_licenses: ["Android-Apache-2.0"],
46}
47
Remi NGUYEN VAN40369562019-03-20 16:40:54 +090048java_defaults {
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +090049 name: "NetworkStackDevApiLevel",
Remi NGUYEN VAN5b3ea2f2020-11-24 02:43:44 +000050 min_sdk_version: "29",
Remi NGUYEN VAN40369562019-03-20 16:40:54 +090051 sdk_version: "system_current",
Remi NGUYEN VAN40369562019-03-20 16:40:54 +090052}
53
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090054java_defaults {
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +090055 name: "NetworkStackReleaseApiLevel",
Remi NGUYEN VAN38dc8342020-05-18 18:09:28 +090056 sdk_version: "system_30",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +090057 min_sdk_version: "29",
Remi NGUYEN VAN67933142020-05-07 18:53:35 +090058 target_sdk_version: "30",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090059}
60
Lorenzo Colittid6709182021-02-22 01:38:39 +090061// Libraries for the API shims
62java_defaults {
63 name: "NetworkStackShimsDefaults",
64 libs: [
65 "androidx.annotation_annotation",
66 "networkstack-client",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090067 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +090068 min_sdk_version: "29",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090069}
70
Lorenzo Colittid6709182021-02-22 01:38:39 +090071// Common shim code. This includes the shim interface definitions themselves, and things like
72// ShimUtils and UnsupportedApiLevelException. Compiles against system_current because ShimUtils
73// needs access to all Build.VERSION_CODES.*, which by definition are only in the newest SDK.
74// TODO: consider moving ShimUtils into a library (or removing it in favour of SdkLevel) and compile
75// this target against the lowest-supported SDK (currently 29).
76java_library {
77 name: "NetworkStackShimsCommon",
78 defaults: ["NetworkStackShimsDefaults"],
79 srcs: ["apishim/common/**/*.java"],
80 sdk_version: "system_current",
81 visibility: ["//visibility:private"],
82}
83
84// Each level of the shims (29, 30, ...) is its own java_library compiled against the corresponding
85// system_X SDK. this ensures that each shim can only use SDK classes that exist in its SDK level.
86java_library {
87 name: "NetworkStackApi29Shims",
88 defaults: ["NetworkStackShimsDefaults"],
89 srcs: ["apishim/29/**/*.java"],
90 libs: [
91 "NetworkStackShimsCommon",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090092 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +090093 sdk_version: "system_29",
94 visibility: ["//visibility:private"],
95}
96
97java_library {
98 name: "NetworkStackApi30Shims",
99 defaults: ["NetworkStackShimsDefaults"],
100 srcs: [
101 "apishim/30/**/*.java",
102 ],
103 libs: [
104 "NetworkStackShimsCommon",
105 "NetworkStackApi29Shims",
106 ],
107 sdk_version: "system_30",
108 visibility: ["//visibility:private"],
109}
110
111// Shims for APIs being added to the current development version of Android. These APIs are not
Lorenzo Colitti52f7eb12021-02-24 17:10:56 +0900112// stable and have no defined version number. These could be called 10000, but they use the next
113// integer so if the next SDK release happens to use that integer, we don't need to rename them.
Lorenzo Colittid6709182021-02-22 01:38:39 +0900114java_library {
115 name: "NetworkStackApi31Shims",
116 defaults: ["NetworkStackShimsDefaults"],
117 srcs: [
118 "apishim/31/**/*.java",
119 ],
120 libs: [
121 "NetworkStackShimsCommon",
122 "NetworkStackApi29Shims",
123 "NetworkStackApi30Shims",
Chiachang Wangffe87162021-02-26 17:36:52 +0800124 "framework-connectivity",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900125 ],
Chiachang Wangffe87162021-02-26 17:36:52 +0800126 sdk_version: "module_current",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900127 visibility: ["//visibility:private"],
128}
129
130// API current uses the API current shims directly.
131// The current (in-progress) shims are in the com.android.networkstack.apishim package and are
132// called directly by the networkstack code.
133java_library {
134 name: "NetworkStackApiCurrentShims",
135 defaults: ["NetworkStackShimsDefaults"],
136 static_libs: [
137 "NetworkStackShimsCommon",
138 "NetworkStackApi29Shims",
139 "NetworkStackApi30Shims",
140 "NetworkStackApi31Shims",
141 ],
Chiachang Wangffe87162021-02-26 17:36:52 +0800142 sdk_version: "module_current",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900143 visibility: ["//visibility:private"],
144}
145
146// API stable uses jarjar to rename the latest stable apishim package from
147// com.android.networkstack.apishim.apiXX to com.android.networkstack.apishim, which is called by
148// the networkstack code.
149java_library {
150 name: "NetworkStackApiStableShims",
151 defaults: ["NetworkStackShimsDefaults"],
152 static_libs: [
153 "NetworkStackShimsCommon",
154 "NetworkStackApi29Shims",
155 "NetworkStackApi30Shims",
156 ],
157 jarjar_rules: "apishim/jarjar-rules-compat.txt",
158 sdk_version: "system_30",
159 visibility: ["//visibility:private"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900160}
161
162// Common defaults for android libraries containing network stack code, used to compile variants of
163// the network stack in the system process and in the network_stack process
164java_defaults {
165 name: "NetworkStackAndroidLibraryDefaults",
Remi NGUYEN VANded23152018-12-07 16:52:24 +0900166 srcs: [
Remi NGUYEN VAN82b4b422019-01-20 09:35:10 +0900167 ":framework-networkstack-shared-srcs",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900168 ":networkstack-module-utils-srcs",
Remi NGUYEN VANded23152018-12-07 16:52:24 +0900169 ],
Artur Satayev0eb158a2019-12-10 12:54:01 +0000170 libs: ["unsupportedappusage"],
Remi NGUYEN VAN057bf202018-12-04 12:13:09 +0900171 static_libs: [
Niklas Lindgren0c904882018-12-07 11:08:04 +0100172 "androidx.annotation_annotation",
Jeongik Cha848a5b52021-01-26 22:35:03 +0900173 "netd_aidl_interface-lateststable-java",
Remi NGUYEN VAN1fc930c2019-08-09 13:23:47 +0900174 "netlink-client",
Remi NGUYEN VANbbb97032019-08-08 15:53:54 +0900175 "networkstack-client",
Remi NGUYEN VAN5b00d422020-06-08 15:34:22 +0900176 "net-utils-framework-common",
Remi NGUYEN VAN84ba8152020-06-22 18:50:20 +0900177 // See note on statsprotos when adding/updating proto build rules
Chiachang Wang8b5f84a2019-02-22 11:13:07 +0800178 "datastallprotosnano",
lifrcb15db32020-05-21 20:32:36 +0800179 "statsprotos",
paulhu5982eff2019-03-29 19:21:30 +0800180 "captiveportal-lib",
Chalard Jean6f675212020-06-25 23:41:16 +0900181 "net-utils-device-common",
Remi NGUYEN VAN0a4df5a2019-03-08 17:20:49 +0900182 ],
Kun Niuf3b69042019-07-01 17:03:20 -0700183 plugins: ["java_api_finder"],
Remi NGUYEN VAN0a4df5a2019-03-08 17:20:49 +0900184}
185
Lorenzo Colittid6709182021-02-22 01:38:39 +0900186// The versions of the android library containing network stack code compiled for each SDK variant.
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900187android_library {
188 name: "NetworkStackApiCurrentLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900189 defaults: ["NetworkStackDevApiLevel", "NetworkStackAndroidLibraryDefaults"],
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800190 srcs: [
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800191 "src/**/*.java",
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000192 ":statslog-networkstack-java-gen-current"
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800193 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +0900194 static_libs: ["NetworkStackApiCurrentShims"],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900195 manifest: "AndroidManifestBase.xml",
196}
197
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900198android_library {
199 name: "NetworkStackApiStableLib",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900200 defaults: ["NetworkStackReleaseApiLevel", "NetworkStackAndroidLibraryDefaults"],
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800201 srcs: [
202 "src/**/*.java",
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000203 ":statslog-networkstack-java-gen-stable",
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800204 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +0900205 static_libs: ["NetworkStackApiStableShims"],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900206 manifest: "AndroidManifestBase.xml",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900207}
208
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900209filegroup {
210 name: "NetworkStackJarJarRules",
211 srcs: ["jarjar-rules-shared.txt"],
212 visibility: [
213 "//packages/modules/NetworkStack/tests/unit",
214 "//packages/modules/NetworkStack/tests/integration",
paulhua9949882020-04-06 23:33:00 +0800215 "//frameworks/base/packages/Tethering/tests/integration",
Baligh Uddin1151e2e2020-10-29 02:12:29 +0000216 "//packages/modules/Connectivity/Tethering/tests/integration",
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900217 ]
218}
219
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900220// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries
221java_defaults {
222 name: "NetworkStackAppDefaults",
223 privileged: true,
224 jni_libs: [
225 "libnativehelper_compat_libc++",
226 "libnetworkstackutilsjni",
227 ],
228 // Resources already included in NetworkStackBase
229 resource_dirs: [],
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900230 jarjar_rules: ":NetworkStackJarJarRules",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900231 use_embedded_native_libs: true,
232 optimize: {
233 proguard_flags_files: ["proguard.flags"],
234 },
235}
236
237// Non-updatable network stack running in the system server process for devices not using the module
238android_app {
239 name: "InProcessNetworkStack",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900240 defaults: [ "NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900241 static_libs: ["NetworkStackApiCurrentLib"],
242 certificate: "platform",
243 manifest: "AndroidManifest_InProcess.xml",
244 // InProcessNetworkStack is a replacement for NetworkStack
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000245 overrides: ["NetworkStack", "NetworkStackNext"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900246 // The permission configuration *must* be included to ensure security of the device
247 // The InProcessNetworkStack goes together with the PlatformCaptivePortalLogin, which replaces
248 // the default CaptivePortalLogin.
249 required: ["PlatformNetworkPermissionConfig", "PlatformCaptivePortalLogin"],
250}
251
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900252// Pre-merge the AndroidManifest for NetworkStackNext, so that its manifest can be merged on top
253android_library {
254 name: "NetworkStackNextManifestBase",
255 defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
256 static_libs: ["NetworkStackApiCurrentLib"],
257 manifest: "AndroidManifest.xml"
258}
259
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900260// NetworkStack build targeting the current API release, for testing on in-development SDK
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900261android_app {
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000262 name: "NetworkStackNext",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900263 defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900264 static_libs: ["NetworkStackNextManifestBase"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900265 certificate: "networkstack",
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900266 manifest: "AndroidManifest_Next.xml",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900267 // The permission configuration *must* be included to ensure security of the device
268 required: ["NetworkPermissionConfig"],
269}
270
271// Updatable network stack for finalized API
272android_app {
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000273 name: "NetworkStack",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900274 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900275 static_libs: ["NetworkStackApiStableLib"],
276 certificate: "networkstack",
277 manifest: "AndroidManifest.xml",
278 // The permission configuration *must* be included to ensure security of the device
279 required: ["NetworkPermissionConfig"],
Artur Satayev862a1a12020-04-09 11:35:52 +0100280 updatable: true,
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900281}
282
283// Android library to derive test APKs for integration tests
284android_library {
285 name: "TestNetworkStackLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900286 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
287 static_libs: ["NetworkStackApiStableLib"],
Remi NGUYEN VANae18aed2019-10-30 18:20:36 +0900288 manifest: "AndroidManifestBase.xml",
Remi NGUYEN VAN2c18f6b2020-05-25 18:27:59 +0900289 visibility: [
290 "//frameworks/base/tests/net/integration",
291 "//cts/tests/tests/net",
Baligh Uddina472e982020-10-31 04:42:56 +0000292 "//packages/modules/Connectivity/tests/cts/net",
Remi NGUYEN VAN2c18f6b2020-05-25 18:27:59 +0900293 ],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900294}
295
paulhue455e2a2019-03-29 17:22:20 +0800296cc_library_shared {
297 name: "libnetworkstackutilsjni",
298 srcs: [
299 "jni/network_stack_utils_jni.cpp"
300 ],
Jooyung Hand3fb9f52020-04-29 02:43:03 +0900301 sdk_version: "29",
302 min_sdk_version: "29",
paulhue455e2a2019-03-29 17:22:20 +0800303 shared_libs: [
304 "liblog",
Lorenzo Colitti88ddd882019-05-01 11:54:33 +0900305 "libnativehelper_compat_libc++",
paulhue455e2a2019-03-29 17:22:20 +0800306 ],
Orion Hodson94561f62020-12-08 09:56:29 +0000307 static_libs: [
308 "libnetjniutils",
309 ],
Lorenzo Colitti88ddd882019-05-01 11:54:33 +0900310
311 // We cannot use plain "libc++" here to link libc++ dynamically because it results in:
312 // java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
313 // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't
314 // build because soong complains of:
315 // module NetworkStack missing dependencies: libc++_shared
316 //
317 // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries
318 // we depend on do not dynamically link libc++. This is currently the case, because liblog is
319 // C-only and libnativehelper_compat_libc also uses stl: "c++_static".
320 //
321 // TODO: find a better solution for this in R.
322 stl: "c++_static",
paulhue455e2a2019-03-29 17:22:20 +0800323 cflags: [
324 "-Wall",
325 "-Werror",
326 "-Wno-unused-parameter",
327 ],
328}
329
Chiachang Wang80242272019-04-11 21:24:28 +0800330genrule {
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000331 name: "statslog-networkstack-java-gen-current",
Chiachang Wang80242272019-04-11 21:24:28 +0800332 tools: ["stats-log-api-gen"],
333 cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
Muhammad Qureshi8e0e9bc2019-12-31 11:26:33 -0800334 " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000335 " --minApiLevel 29",
Chiachang Wang80242272019-04-11 21:24:28 +0800336 out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
337}
Kun Niu8e89dd42019-07-16 18:33:45 -0700338
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000339genrule {
340 name: "statslog-networkstack-java-gen-stable",
341 tools: ["stats-log-api-gen"],
342 cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
343 " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
344 " --minApiLevel 29 --compileApiLevel 30",
345 out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
346}
347
348
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900349version_code_networkstack_next = "300000000"
350version_code_networkstack_test = "999999999"
351
Kun Niu8e89dd42019-07-16 18:33:45 -0700352genrule {
353 name: "NetworkStackTestAndroidManifest",
354 srcs: ["AndroidManifest.xml"],
355 out: ["TestAndroidManifest.xml"],
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900356 cmd: "sed -E 's/versionCode=\"[0-9]+\"/versionCode=\""
357 + version_code_networkstack_test
358 + "\"/' $(in) > $(out)",
359 visibility: ["//visibility:private"],
360}
361
Kun Niu8e89dd42019-07-16 18:33:45 -0700362android_app {
363 name: "TestNetworkStack",
Remi NGUYEN VAN1d52af02020-12-22 02:08:55 +0000364 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
365 static_libs: ["NetworkStackApiStableLib"],
Kun Niu8e89dd42019-07-16 18:33:45 -0700366 certificate: "networkstack",
367 manifest: ":NetworkStackTestAndroidManifest",
Kun Niu8e89dd42019-07-16 18:33:45 -0700368 // The permission configuration *must* be included to ensure security of the device
369 required: ["NetworkPermissionConfig"],
370}
lifrcb15db32020-05-21 20:32:36 +0800371
Remi NGUYEN VAN84ba8152020-06-22 18:50:20 +0900372// When adding or modifying protos, the jarjar rules and possibly proguard rules need
373// to be updated: proto libraries may pull additional static libraries.
lifrcb15db32020-05-21 20:32:36 +0800374java_library_static {
375 name: "statsprotos",
376 proto: {
377 type: "lite",
378 },
379 srcs: [
380 "src/com/android/networkstack/metrics/stats.proto",
381 ],
382 static_libs: [
383 "networkstackprotos",
384 ],
385 defaults: ["NetworkStackReleaseApiLevel"],
386}