blob: fc28e1a7e1388696729ef4a70dcb7dfbbb86b97d [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
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090025// +jarjar apistub.api[latest].* / \ +module src/
26// to apistub.* / \
27// / \
28// NetworkStackApiStableDependencies \
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// | |
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
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090061// Filegroups for the API shims
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090062filegroup {
63 name: "NetworkStackApiCurrentShims",
64 srcs: [
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090065 "apishim/common/**/*.java",
66 "apishim/29/**/*.java",
Remi NGUYEN VANf9c9b712019-11-08 11:37:33 +000067 "apishim/30/**/*.java",
Remi NGUYEN VAN67933142020-05-07 18:53:35 +090068 "apishim/31/**/*.java",
Remi NGUYEN VAN44e8ebf2020-02-15 04:36:06 +090069 ":networkstack-module-utils-srcs",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090070 ],
71}
72
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090073// API stable shims only include the compat package, but it is jarjared to replace the non-compat
74// package
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090075filegroup {
76 name: "NetworkStackApiStableShims",
77 srcs: [
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090078 "apishim/common/**/*.java",
79 "apishim/29/**/*.java",
Remi NGUYEN VAN67933142020-05-07 18:53:35 +090080 "apishim/30/**/*.java",
Remi NGUYEN VAN44e8ebf2020-02-15 04:36:06 +090081 ":networkstack-module-utils-srcs",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090082 ],
83}
84
85// Common defaults for android libraries containing network stack code, used to compile variants of
86// the network stack in the system process and in the network_stack process
87java_defaults {
88 name: "NetworkStackAndroidLibraryDefaults",
Remi NGUYEN VANded23152018-12-07 16:52:24 +090089 srcs: [
Remi NGUYEN VAN82b4b422019-01-20 09:35:10 +090090 ":framework-networkstack-shared-srcs",
Remi NGUYEN VANded23152018-12-07 16:52:24 +090091 ],
Artur Satayev0eb158a2019-12-10 12:54:01 +000092 libs: ["unsupportedappusage"],
Remi NGUYEN VAN057bf202018-12-04 12:13:09 +090093 static_libs: [
Niklas Lindgren0c904882018-12-07 11:08:04 +010094 "androidx.annotation_annotation",
Hungming Chenb5b6e692020-05-29 20:09:23 +080095 "netd_aidl_interface-unstable-java",
Remi NGUYEN VAN1fc930c2019-08-09 13:23:47 +090096 "netlink-client",
Remi NGUYEN VANbbb97032019-08-08 15:53:54 +090097 "networkstack-client",
Remi NGUYEN VAN5b00d422020-06-08 15:34:22 +090098 "net-utils-framework-common",
Remi NGUYEN VAN84ba8152020-06-22 18:50:20 +090099 // See note on statsprotos when adding/updating proto build rules
Chiachang Wang8b5f84a2019-02-22 11:13:07 +0800100 "datastallprotosnano",
lifrcb15db32020-05-21 20:32:36 +0800101 "statsprotos",
paulhu5982eff2019-03-29 19:21:30 +0800102 "captiveportal-lib",
Chalard Jean6f675212020-06-25 23:41:16 +0900103 "net-utils-device-common",
Remi NGUYEN VAN0a4df5a2019-03-08 17:20:49 +0900104 ],
Kun Niuf3b69042019-07-01 17:03:20 -0700105 plugins: ["java_api_finder"],
Remi NGUYEN VAN0a4df5a2019-03-08 17:20:49 +0900106}
107
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900108// The versions of the android library containing network stack code compiled for each SDK variant
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900109// API current uses the sources of the API current shims directly.
110// This allows API current code to be treated identically to code in src/ (it will be moved
111// there eventually), and to use the compat shim as fallback on older devices.
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900112android_library {
113 name: "NetworkStackApiCurrentLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900114 defaults: ["NetworkStackDevApiLevel", "NetworkStackAndroidLibraryDefaults"],
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800115 srcs: [
116 ":NetworkStackApiCurrentShims",
117 "src/**/*.java",
Remi NGUYEN VANda5f6bb2021-02-09 08:08:38 +0000118 ":statslog-networkstack-java-gen"
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800119 ],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900120 manifest: "AndroidManifestBase.xml",
121}
122
123// For API stable, first build the dependencies using jarjar compat rules, then build the sources
124// linking with the dependencies.
125java_library {
126 name: "NetworkStackApiStableDependencies",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900127 defaults: ["NetworkStackReleaseApiLevel", "NetworkStackAndroidLibraryDefaults"],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900128 srcs: [":NetworkStackApiStableShims"],
129 jarjar_rules: "apishim/jarjar-rules-compat.txt",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900130}
131
132android_library {
133 name: "NetworkStackApiStableLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900134 defaults: ["NetworkStackReleaseApiLevel"],
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800135 srcs: [
136 "src/**/*.java",
Remi NGUYEN VANda5f6bb2021-02-09 08:08:38 +0000137 ":statslog-networkstack-java-gen",
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800138 ],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900139 // API stable uses a jarjared version of the shims
140 static_libs: [
141 "NetworkStackApiStableDependencies",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900142 ],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900143 manifest: "AndroidManifestBase.xml",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900144}
145
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900146filegroup {
147 name: "NetworkStackJarJarRules",
148 srcs: ["jarjar-rules-shared.txt"],
149 visibility: [
150 "//packages/modules/NetworkStack/tests/unit",
151 "//packages/modules/NetworkStack/tests/integration",
paulhua9949882020-04-06 23:33:00 +0800152 "//frameworks/base/packages/Tethering/tests/integration",
Baligh Uddin1151e2e2020-10-29 02:12:29 +0000153 "//packages/modules/Connectivity/Tethering/tests/integration",
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900154 ]
155}
156
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900157// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries
158java_defaults {
159 name: "NetworkStackAppDefaults",
160 privileged: true,
161 jni_libs: [
162 "libnativehelper_compat_libc++",
163 "libnetworkstackutilsjni",
164 ],
165 // Resources already included in NetworkStackBase
166 resource_dirs: [],
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900167 jarjar_rules: ":NetworkStackJarJarRules",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900168 use_embedded_native_libs: true,
169 optimize: {
170 proguard_flags_files: ["proguard.flags"],
171 },
172}
173
174// Non-updatable network stack running in the system server process for devices not using the module
175android_app {
176 name: "InProcessNetworkStack",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900177 defaults: [ "NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900178 static_libs: ["NetworkStackApiCurrentLib"],
179 certificate: "platform",
180 manifest: "AndroidManifest_InProcess.xml",
181 // InProcessNetworkStack is a replacement for NetworkStack
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000182 overrides: ["NetworkStack", "NetworkStackNext"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900183 // The permission configuration *must* be included to ensure security of the device
184 // The InProcessNetworkStack goes together with the PlatformCaptivePortalLogin, which replaces
185 // the default CaptivePortalLogin.
186 required: ["PlatformNetworkPermissionConfig", "PlatformCaptivePortalLogin"],
187}
188
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900189// Pre-merge the AndroidManifest for NetworkStackNext, so that its manifest can be merged on top
190android_library {
191 name: "NetworkStackNextManifestBase",
192 defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
193 static_libs: ["NetworkStackApiCurrentLib"],
194 manifest: "AndroidManifest.xml"
195}
196
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900197// NetworkStack build targeting the current API release, for testing on in-development SDK
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900198android_app {
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000199 name: "NetworkStackNext",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900200 defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900201 static_libs: ["NetworkStackNextManifestBase"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900202 certificate: "networkstack",
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900203 manifest: "AndroidManifest_Next.xml",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900204 // The permission configuration *must* be included to ensure security of the device
205 required: ["NetworkPermissionConfig"],
206}
207
208// Updatable network stack for finalized API
209android_app {
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000210 name: "NetworkStack",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900211 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900212 static_libs: ["NetworkStackApiStableLib"],
213 certificate: "networkstack",
214 manifest: "AndroidManifest.xml",
215 // The permission configuration *must* be included to ensure security of the device
216 required: ["NetworkPermissionConfig"],
Artur Satayev862a1a12020-04-09 11:35:52 +0100217 updatable: true,
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900218}
219
220// Android library to derive test APKs for integration tests
221android_library {
222 name: "TestNetworkStackLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900223 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
224 static_libs: ["NetworkStackApiStableLib"],
Remi NGUYEN VANae18aed2019-10-30 18:20:36 +0900225 manifest: "AndroidManifestBase.xml",
Remi NGUYEN VAN2c18f6b2020-05-25 18:27:59 +0900226 visibility: [
227 "//frameworks/base/tests/net/integration",
228 "//cts/tests/tests/net",
Baligh Uddina472e982020-10-31 04:42:56 +0000229 "//packages/modules/Connectivity/tests/cts/net",
Remi NGUYEN VAN2c18f6b2020-05-25 18:27:59 +0900230 ],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900231}
232
paulhue455e2a2019-03-29 17:22:20 +0800233cc_library_shared {
234 name: "libnetworkstackutilsjni",
235 srcs: [
236 "jni/network_stack_utils_jni.cpp"
237 ],
Jooyung Hand3fb9f52020-04-29 02:43:03 +0900238 sdk_version: "29",
239 min_sdk_version: "29",
paulhue455e2a2019-03-29 17:22:20 +0800240 shared_libs: [
241 "liblog",
Lorenzo Colitti88ddd882019-05-01 11:54:33 +0900242 "libnativehelper_compat_libc++",
paulhue455e2a2019-03-29 17:22:20 +0800243 ],
Orion Hodson94561f62020-12-08 09:56:29 +0000244 static_libs: [
245 "libnetjniutils",
246 ],
Lorenzo Colitti88ddd882019-05-01 11:54:33 +0900247
248 // We cannot use plain "libc++" here to link libc++ dynamically because it results in:
249 // java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
250 // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't
251 // build because soong complains of:
252 // module NetworkStack missing dependencies: libc++_shared
253 //
254 // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries
255 // we depend on do not dynamically link libc++. This is currently the case, because liblog is
256 // C-only and libnativehelper_compat_libc also uses stl: "c++_static".
257 //
258 // TODO: find a better solution for this in R.
259 stl: "c++_static",
paulhue455e2a2019-03-29 17:22:20 +0800260 cflags: [
261 "-Wall",
262 "-Werror",
263 "-Wno-unused-parameter",
264 ],
265}
266
Chiachang Wang80242272019-04-11 21:24:28 +0800267genrule {
Remi NGUYEN VANda5f6bb2021-02-09 08:08:38 +0000268 name: "statslog-networkstack-java-gen",
Chiachang Wang80242272019-04-11 21:24:28 +0800269 tools: ["stats-log-api-gen"],
270 cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
Muhammad Qureshi8e0e9bc2019-12-31 11:26:33 -0800271 " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
Remi NGUYEN VANda5f6bb2021-02-09 08:08:38 +0000272 " --supportQ",
Chiachang Wang80242272019-04-11 21:24:28 +0800273 out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
274}
Kun Niu8e89dd42019-07-16 18:33:45 -0700275
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900276version_code_networkstack_next = "300000000"
277version_code_networkstack_test = "999999999"
278
Kun Niu8e89dd42019-07-16 18:33:45 -0700279genrule {
280 name: "NetworkStackTestAndroidManifest",
281 srcs: ["AndroidManifest.xml"],
282 out: ["TestAndroidManifest.xml"],
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900283 cmd: "sed -E 's/versionCode=\"[0-9]+\"/versionCode=\""
284 + version_code_networkstack_test
285 + "\"/' $(in) > $(out)",
286 visibility: ["//visibility:private"],
287}
288
Kun Niu8e89dd42019-07-16 18:33:45 -0700289android_app {
290 name: "TestNetworkStack",
Remi NGUYEN VAN1d52af02020-12-22 02:08:55 +0000291 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
292 static_libs: ["NetworkStackApiStableLib"],
Kun Niu8e89dd42019-07-16 18:33:45 -0700293 certificate: "networkstack",
294 manifest: ":NetworkStackTestAndroidManifest",
Kun Niu8e89dd42019-07-16 18:33:45 -0700295 // The permission configuration *must* be included to ensure security of the device
296 required: ["NetworkPermissionConfig"],
297}
lifrcb15db32020-05-21 20:32:36 +0800298
Remi NGUYEN VAN84ba8152020-06-22 18:50:20 +0900299// When adding or modifying protos, the jarjar rules and possibly proguard rules need
300// to be updated: proto libraries may pull additional static libraries.
lifrcb15db32020-05-21 20:32:36 +0800301java_library_static {
302 name: "statsprotos",
303 proto: {
304 type: "lite",
305 },
306 srcs: [
307 "src/com/android/networkstack/metrics/stats.proto",
308 ],
309 static_libs: [
310 "networkstackprotos",
311 ],
312 defaults: ["NetworkStackReleaseApiLevel"],
313}