blob: 17b57c90cca5e92541ad56f66e1e54d4f60dc120 [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
Remi NGUYEN VAN40369562019-03-20 16:40:54 +090044java_defaults {
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +090045 name: "NetworkStackDevApiLevel",
Remi NGUYEN VAN5b3ea2f2020-11-24 02:43:44 +000046 min_sdk_version: "29",
Remi NGUYEN VAN40369562019-03-20 16:40:54 +090047 sdk_version: "system_current",
Remi NGUYEN VAN40369562019-03-20 16:40:54 +090048}
49
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090050java_defaults {
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +090051 name: "NetworkStackReleaseApiLevel",
Remi NGUYEN VAN38dc8342020-05-18 18:09:28 +090052 sdk_version: "system_30",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +090053 min_sdk_version: "29",
Remi NGUYEN VAN67933142020-05-07 18:53:35 +090054 target_sdk_version: "30",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090055}
56
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090057// Filegroups for the API shims
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090058filegroup {
59 name: "NetworkStackApiCurrentShims",
60 srcs: [
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090061 "apishim/common/**/*.java",
62 "apishim/29/**/*.java",
Remi NGUYEN VANf9c9b712019-11-08 11:37:33 +000063 "apishim/30/**/*.java",
Remi NGUYEN VAN67933142020-05-07 18:53:35 +090064 "apishim/31/**/*.java",
Remi NGUYEN VAN44e8ebf2020-02-15 04:36:06 +090065 ":networkstack-module-utils-srcs",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090066 ],
67}
68
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090069// API stable shims only include the compat package, but it is jarjared to replace the non-compat
70// package
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090071filegroup {
72 name: "NetworkStackApiStableShims",
73 srcs: [
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +090074 "apishim/common/**/*.java",
75 "apishim/29/**/*.java",
Remi NGUYEN VAN67933142020-05-07 18:53:35 +090076 "apishim/30/**/*.java",
Remi NGUYEN VAN44e8ebf2020-02-15 04:36:06 +090077 ":networkstack-module-utils-srcs",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090078 ],
79}
80
81// Common defaults for android libraries containing network stack code, used to compile variants of
82// the network stack in the system process and in the network_stack process
83java_defaults {
84 name: "NetworkStackAndroidLibraryDefaults",
Remi NGUYEN VANded23152018-12-07 16:52:24 +090085 srcs: [
Remi NGUYEN VAN82b4b422019-01-20 09:35:10 +090086 ":framework-networkstack-shared-srcs",
Remi NGUYEN VANded23152018-12-07 16:52:24 +090087 ],
Artur Satayev0eb158a2019-12-10 12:54:01 +000088 libs: ["unsupportedappusage"],
Remi NGUYEN VAN057bf202018-12-04 12:13:09 +090089 static_libs: [
Niklas Lindgren0c904882018-12-07 11:08:04 +010090 "androidx.annotation_annotation",
Hungming Chenb5b6e692020-05-29 20:09:23 +080091 "netd_aidl_interface-unstable-java",
Remi NGUYEN VAN1fc930c2019-08-09 13:23:47 +090092 "netlink-client",
Remi NGUYEN VANbbb97032019-08-08 15:53:54 +090093 "networkstack-client",
Remi NGUYEN VAN5b00d422020-06-08 15:34:22 +090094 "net-utils-framework-common",
Remi NGUYEN VAN84ba8152020-06-22 18:50:20 +090095 // See note on statsprotos when adding/updating proto build rules
Chiachang Wang8b5f84a2019-02-22 11:13:07 +080096 "datastallprotosnano",
lifrcb15db32020-05-21 20:32:36 +080097 "statsprotos",
paulhu5982eff2019-03-29 19:21:30 +080098 "captiveportal-lib",
Chalard Jean6f675212020-06-25 23:41:16 +090099 "net-utils-device-common",
Remi NGUYEN VAN0a4df5a2019-03-08 17:20:49 +0900100 ],
Kun Niuf3b69042019-07-01 17:03:20 -0700101 plugins: ["java_api_finder"],
Remi NGUYEN VAN0a4df5a2019-03-08 17:20:49 +0900102}
103
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900104// The versions of the android library containing network stack code compiled for each SDK variant
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900105// API current uses the sources of the API current shims directly.
106// This allows API current code to be treated identically to code in src/ (it will be moved
107// there eventually), and to use the compat shim as fallback on older devices.
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900108android_library {
109 name: "NetworkStackApiCurrentLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900110 defaults: ["NetworkStackDevApiLevel", "NetworkStackAndroidLibraryDefaults"],
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800111 srcs: [
112 ":NetworkStackApiCurrentShims",
113 "src/**/*.java",
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000114 ":statslog-networkstack-java-gen-current"
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800115 ],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900116 manifest: "AndroidManifestBase.xml",
117}
118
119// For API stable, first build the dependencies using jarjar compat rules, then build the sources
120// linking with the dependencies.
121java_library {
122 name: "NetworkStackApiStableDependencies",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900123 defaults: ["NetworkStackReleaseApiLevel", "NetworkStackAndroidLibraryDefaults"],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900124 srcs: [":NetworkStackApiStableShims"],
125 jarjar_rules: "apishim/jarjar-rules-compat.txt",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900126}
127
128android_library {
129 name: "NetworkStackApiStableLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900130 defaults: ["NetworkStackReleaseApiLevel"],
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800131 srcs: [
132 "src/**/*.java",
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000133 ":statslog-networkstack-java-gen-stable",
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800134 ],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900135 // API stable uses a jarjared version of the shims
136 static_libs: [
137 "NetworkStackApiStableDependencies",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900138 ],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900139 manifest: "AndroidManifestBase.xml",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900140}
141
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900142filegroup {
143 name: "NetworkStackJarJarRules",
144 srcs: ["jarjar-rules-shared.txt"],
145 visibility: [
146 "//packages/modules/NetworkStack/tests/unit",
147 "//packages/modules/NetworkStack/tests/integration",
paulhua9949882020-04-06 23:33:00 +0800148 "//frameworks/base/packages/Tethering/tests/integration",
Baligh Uddin1151e2e2020-10-29 02:12:29 +0000149 "//packages/modules/Connectivity/Tethering/tests/integration",
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900150 ]
151}
152
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900153// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries
154java_defaults {
155 name: "NetworkStackAppDefaults",
156 privileged: true,
157 jni_libs: [
158 "libnativehelper_compat_libc++",
159 "libnetworkstackutilsjni",
160 ],
161 // Resources already included in NetworkStackBase
162 resource_dirs: [],
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900163 jarjar_rules: ":NetworkStackJarJarRules",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900164 use_embedded_native_libs: true,
165 optimize: {
166 proguard_flags_files: ["proguard.flags"],
167 },
168}
169
170// Non-updatable network stack running in the system server process for devices not using the module
171android_app {
172 name: "InProcessNetworkStack",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900173 defaults: [ "NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900174 static_libs: ["NetworkStackApiCurrentLib"],
175 certificate: "platform",
176 manifest: "AndroidManifest_InProcess.xml",
177 // InProcessNetworkStack is a replacement for NetworkStack
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000178 overrides: ["NetworkStack", "NetworkStackNext"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900179 // The permission configuration *must* be included to ensure security of the device
180 // The InProcessNetworkStack goes together with the PlatformCaptivePortalLogin, which replaces
181 // the default CaptivePortalLogin.
182 required: ["PlatformNetworkPermissionConfig", "PlatformCaptivePortalLogin"],
183}
184
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900185// Pre-merge the AndroidManifest for NetworkStackNext, so that its manifest can be merged on top
186android_library {
187 name: "NetworkStackNextManifestBase",
188 defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
189 static_libs: ["NetworkStackApiCurrentLib"],
190 manifest: "AndroidManifest.xml"
191}
192
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900193// NetworkStack build targeting the current API release, for testing on in-development SDK
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900194android_app {
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000195 name: "NetworkStackNext",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900196 defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900197 static_libs: ["NetworkStackNextManifestBase"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900198 certificate: "networkstack",
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900199 manifest: "AndroidManifest_Next.xml",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900200 // The permission configuration *must* be included to ensure security of the device
201 required: ["NetworkPermissionConfig"],
202}
203
204// Updatable network stack for finalized API
205android_app {
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000206 name: "NetworkStack",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900207 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900208 static_libs: ["NetworkStackApiStableLib"],
209 certificate: "networkstack",
210 manifest: "AndroidManifest.xml",
211 // The permission configuration *must* be included to ensure security of the device
212 required: ["NetworkPermissionConfig"],
Artur Satayev862a1a12020-04-09 11:35:52 +0100213 updatable: true,
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900214}
215
216// Android library to derive test APKs for integration tests
217android_library {
218 name: "TestNetworkStackLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900219 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
220 static_libs: ["NetworkStackApiStableLib"],
Remi NGUYEN VANae18aed2019-10-30 18:20:36 +0900221 manifest: "AndroidManifestBase.xml",
Remi NGUYEN VAN2c18f6b2020-05-25 18:27:59 +0900222 visibility: [
223 "//frameworks/base/tests/net/integration",
224 "//cts/tests/tests/net",
Baligh Uddina472e982020-10-31 04:42:56 +0000225 "//packages/modules/Connectivity/tests/cts/net",
Remi NGUYEN VAN2c18f6b2020-05-25 18:27:59 +0900226 ],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900227}
228
paulhue455e2a2019-03-29 17:22:20 +0800229cc_library_shared {
230 name: "libnetworkstackutilsjni",
231 srcs: [
232 "jni/network_stack_utils_jni.cpp"
233 ],
Jooyung Hand3fb9f52020-04-29 02:43:03 +0900234 sdk_version: "29",
235 min_sdk_version: "29",
paulhue455e2a2019-03-29 17:22:20 +0800236 shared_libs: [
237 "liblog",
Lorenzo Colitti88ddd882019-05-01 11:54:33 +0900238 "libnativehelper_compat_libc++",
paulhue455e2a2019-03-29 17:22:20 +0800239 ],
Orion Hodson94561f62020-12-08 09:56:29 +0000240 static_libs: [
241 "libnetjniutils",
242 ],
Lorenzo Colitti88ddd882019-05-01 11:54:33 +0900243
244 // We cannot use plain "libc++" here to link libc++ dynamically because it results in:
245 // java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
246 // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't
247 // build because soong complains of:
248 // module NetworkStack missing dependencies: libc++_shared
249 //
250 // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries
251 // we depend on do not dynamically link libc++. This is currently the case, because liblog is
252 // C-only and libnativehelper_compat_libc also uses stl: "c++_static".
253 //
254 // TODO: find a better solution for this in R.
255 stl: "c++_static",
paulhue455e2a2019-03-29 17:22:20 +0800256 cflags: [
257 "-Wall",
258 "-Werror",
259 "-Wno-unused-parameter",
260 ],
261}
262
Chiachang Wang80242272019-04-11 21:24:28 +0800263genrule {
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000264 name: "statslog-networkstack-java-gen-current",
Chiachang Wang80242272019-04-11 21:24:28 +0800265 tools: ["stats-log-api-gen"],
266 cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
Muhammad Qureshi8e0e9bc2019-12-31 11:26:33 -0800267 " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000268 " --minApiLevel 29",
Chiachang Wang80242272019-04-11 21:24:28 +0800269 out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
270}
Kun Niu8e89dd42019-07-16 18:33:45 -0700271
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000272genrule {
273 name: "statslog-networkstack-java-gen-stable",
274 tools: ["stats-log-api-gen"],
275 cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
276 " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
277 " --minApiLevel 29 --compileApiLevel 30",
278 out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
279}
280
281
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900282version_code_networkstack_next = "300000000"
283version_code_networkstack_test = "999999999"
284
Kun Niu8e89dd42019-07-16 18:33:45 -0700285genrule {
286 name: "NetworkStackTestAndroidManifest",
287 srcs: ["AndroidManifest.xml"],
288 out: ["TestAndroidManifest.xml"],
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900289 cmd: "sed -E 's/versionCode=\"[0-9]+\"/versionCode=\""
290 + version_code_networkstack_test
291 + "\"/' $(in) > $(out)",
292 visibility: ["//visibility:private"],
293}
294
Kun Niu8e89dd42019-07-16 18:33:45 -0700295android_app {
296 name: "TestNetworkStack",
Remi NGUYEN VAN1d52af02020-12-22 02:08:55 +0000297 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
298 static_libs: ["NetworkStackApiStableLib"],
Kun Niu8e89dd42019-07-16 18:33:45 -0700299 certificate: "networkstack",
300 manifest: ":NetworkStackTestAndroidManifest",
Kun Niu8e89dd42019-07-16 18:33:45 -0700301 // The permission configuration *must* be included to ensure security of the device
302 required: ["NetworkPermissionConfig"],
303}
lifrcb15db32020-05-21 20:32:36 +0800304
Remi NGUYEN VAN84ba8152020-06-22 18:50:20 +0900305// When adding or modifying protos, the jarjar rules and possibly proguard rules need
306// to be updated: proto libraries may pull additional static libraries.
lifrcb15db32020-05-21 20:32:36 +0800307java_library_static {
308 name: "statsprotos",
309 proto: {
310 type: "lite",
311 },
312 srcs: [
313 "src/com/android/networkstack/metrics/stats.proto",
314 ],
315 static_libs: [
316 "networkstackprotos",
317 ],
318 defaults: ["NetworkStackReleaseApiLevel"],
319}