blob: a0d70a38e713741d0737523b29c1cfc699ba8070 [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
112// stable and have no defined version number. We could call these 10000, but we just pick the next
113// integer, so if the next SDK release happens to use that integer, we don't need to rename them.
114java_library {
115 name: "NetworkStackApi31Shims",
116 defaults: ["NetworkStackShimsDefaults"],
117 srcs: [
118 "apishim/31/**/*.java",
119 ],
120 libs: [
121 "NetworkStackShimsCommon",
122 "NetworkStackApi29Shims",
123 "NetworkStackApi30Shims",
124 ],
125 sdk_version: "system_current",
126 visibility: ["//visibility:private"],
127}
128
129// API current uses the API current shims directly.
130// The current (in-progress) shims are in the com.android.networkstack.apishim package and are
131// called directly by the networkstack code.
132java_library {
133 name: "NetworkStackApiCurrentShims",
134 defaults: ["NetworkStackShimsDefaults"],
135 static_libs: [
136 "NetworkStackShimsCommon",
137 "NetworkStackApi29Shims",
138 "NetworkStackApi30Shims",
139 "NetworkStackApi31Shims",
140 ],
141 sdk_version: "system_current",
142 visibility: ["//visibility:private"],
143}
144
145// API stable uses jarjar to rename the latest stable apishim package from
146// com.android.networkstack.apishim.apiXX to com.android.networkstack.apishim, which is called by
147// the networkstack code.
148java_library {
149 name: "NetworkStackApiStableShims",
150 defaults: ["NetworkStackShimsDefaults"],
151 static_libs: [
152 "NetworkStackShimsCommon",
153 "NetworkStackApi29Shims",
154 "NetworkStackApi30Shims",
155 ],
156 jarjar_rules: "apishim/jarjar-rules-compat.txt",
157 sdk_version: "system_30",
158 visibility: ["//visibility:private"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900159}
160
161// Common defaults for android libraries containing network stack code, used to compile variants of
162// the network stack in the system process and in the network_stack process
163java_defaults {
164 name: "NetworkStackAndroidLibraryDefaults",
Remi NGUYEN VANded23152018-12-07 16:52:24 +0900165 srcs: [
Remi NGUYEN VAN82b4b422019-01-20 09:35:10 +0900166 ":framework-networkstack-shared-srcs",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900167 ":networkstack-module-utils-srcs",
Remi NGUYEN VANded23152018-12-07 16:52:24 +0900168 ],
Artur Satayev0eb158a2019-12-10 12:54:01 +0000169 libs: ["unsupportedappusage"],
Remi NGUYEN VAN057bf202018-12-04 12:13:09 +0900170 static_libs: [
Niklas Lindgren0c904882018-12-07 11:08:04 +0100171 "androidx.annotation_annotation",
Jeongik Cha848a5b52021-01-26 22:35:03 +0900172 "netd_aidl_interface-lateststable-java",
Remi NGUYEN VAN1fc930c2019-08-09 13:23:47 +0900173 "netlink-client",
Remi NGUYEN VANbbb97032019-08-08 15:53:54 +0900174 "networkstack-client",
Remi NGUYEN VAN5b00d422020-06-08 15:34:22 +0900175 "net-utils-framework-common",
Remi NGUYEN VAN84ba8152020-06-22 18:50:20 +0900176 // See note on statsprotos when adding/updating proto build rules
Chiachang Wang8b5f84a2019-02-22 11:13:07 +0800177 "datastallprotosnano",
lifrcb15db32020-05-21 20:32:36 +0800178 "statsprotos",
paulhu5982eff2019-03-29 19:21:30 +0800179 "captiveportal-lib",
Chalard Jean6f675212020-06-25 23:41:16 +0900180 "net-utils-device-common",
Remi NGUYEN VAN0a4df5a2019-03-08 17:20:49 +0900181 ],
Kun Niuf3b69042019-07-01 17:03:20 -0700182 plugins: ["java_api_finder"],
Remi NGUYEN VAN0a4df5a2019-03-08 17:20:49 +0900183}
184
Lorenzo Colittid6709182021-02-22 01:38:39 +0900185// The versions of the android library containing network stack code compiled for each SDK variant.
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900186android_library {
187 name: "NetworkStackApiCurrentLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900188 defaults: ["NetworkStackDevApiLevel", "NetworkStackAndroidLibraryDefaults"],
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800189 srcs: [
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800190 "src/**/*.java",
Remi NGUYEN VANda5f6bb2021-02-09 08:08:38 +0000191 ":statslog-networkstack-java-gen"
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800192 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +0900193 static_libs: ["NetworkStackApiCurrentShims"],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900194 manifest: "AndroidManifestBase.xml",
195}
196
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900197android_library {
198 name: "NetworkStackApiStableLib",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900199 defaults: ["NetworkStackReleaseApiLevel", "NetworkStackAndroidLibraryDefaults"],
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800200 srcs: [
201 "src/**/*.java",
Remi NGUYEN VANda5f6bb2021-02-09 08:08:38 +0000202 ":statslog-networkstack-java-gen",
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800203 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +0900204 static_libs: ["NetworkStackApiStableShims"],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900205 manifest: "AndroidManifestBase.xml",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900206}
207
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900208filegroup {
209 name: "NetworkStackJarJarRules",
210 srcs: ["jarjar-rules-shared.txt"],
211 visibility: [
212 "//packages/modules/NetworkStack/tests/unit",
213 "//packages/modules/NetworkStack/tests/integration",
paulhua9949882020-04-06 23:33:00 +0800214 "//frameworks/base/packages/Tethering/tests/integration",
Baligh Uddin1151e2e2020-10-29 02:12:29 +0000215 "//packages/modules/Connectivity/Tethering/tests/integration",
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900216 ]
217}
218
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900219// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries
220java_defaults {
221 name: "NetworkStackAppDefaults",
222 privileged: true,
223 jni_libs: [
224 "libnativehelper_compat_libc++",
225 "libnetworkstackutilsjni",
226 ],
227 // Resources already included in NetworkStackBase
228 resource_dirs: [],
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900229 jarjar_rules: ":NetworkStackJarJarRules",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900230 use_embedded_native_libs: true,
231 optimize: {
232 proguard_flags_files: ["proguard.flags"],
233 },
234}
235
236// Non-updatable network stack running in the system server process for devices not using the module
237android_app {
238 name: "InProcessNetworkStack",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900239 defaults: [ "NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900240 static_libs: ["NetworkStackApiCurrentLib"],
241 certificate: "platform",
242 manifest: "AndroidManifest_InProcess.xml",
243 // InProcessNetworkStack is a replacement for NetworkStack
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000244 overrides: ["NetworkStack", "NetworkStackNext"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900245 // The permission configuration *must* be included to ensure security of the device
246 // The InProcessNetworkStack goes together with the PlatformCaptivePortalLogin, which replaces
247 // the default CaptivePortalLogin.
248 required: ["PlatformNetworkPermissionConfig", "PlatformCaptivePortalLogin"],
249}
250
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900251// Pre-merge the AndroidManifest for NetworkStackNext, so that its manifest can be merged on top
252android_library {
253 name: "NetworkStackNextManifestBase",
254 defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
255 static_libs: ["NetworkStackApiCurrentLib"],
256 manifest: "AndroidManifest.xml"
257}
258
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900259// NetworkStack build targeting the current API release, for testing on in-development SDK
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900260android_app {
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000261 name: "NetworkStackNext",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900262 defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900263 static_libs: ["NetworkStackNextManifestBase"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900264 certificate: "networkstack",
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900265 manifest: "AndroidManifest_Next.xml",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900266 // The permission configuration *must* be included to ensure security of the device
267 required: ["NetworkPermissionConfig"],
268}
269
270// Updatable network stack for finalized API
271android_app {
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000272 name: "NetworkStack",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900273 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900274 static_libs: ["NetworkStackApiStableLib"],
275 certificate: "networkstack",
276 manifest: "AndroidManifest.xml",
277 // The permission configuration *must* be included to ensure security of the device
278 required: ["NetworkPermissionConfig"],
Artur Satayev862a1a12020-04-09 11:35:52 +0100279 updatable: true,
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900280}
281
282// Android library to derive test APKs for integration tests
283android_library {
284 name: "TestNetworkStackLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900285 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
286 static_libs: ["NetworkStackApiStableLib"],
Remi NGUYEN VANae18aed2019-10-30 18:20:36 +0900287 manifest: "AndroidManifestBase.xml",
Remi NGUYEN VAN2c18f6b2020-05-25 18:27:59 +0900288 visibility: [
289 "//frameworks/base/tests/net/integration",
290 "//cts/tests/tests/net",
Baligh Uddina472e982020-10-31 04:42:56 +0000291 "//packages/modules/Connectivity/tests/cts/net",
Remi NGUYEN VAN2c18f6b2020-05-25 18:27:59 +0900292 ],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900293}
294
paulhue455e2a2019-03-29 17:22:20 +0800295cc_library_shared {
296 name: "libnetworkstackutilsjni",
297 srcs: [
298 "jni/network_stack_utils_jni.cpp"
299 ],
Jooyung Hand3fb9f52020-04-29 02:43:03 +0900300 sdk_version: "29",
301 min_sdk_version: "29",
paulhue455e2a2019-03-29 17:22:20 +0800302 shared_libs: [
303 "liblog",
Lorenzo Colitti88ddd882019-05-01 11:54:33 +0900304 "libnativehelper_compat_libc++",
paulhue455e2a2019-03-29 17:22:20 +0800305 ],
Orion Hodson94561f62020-12-08 09:56:29 +0000306 static_libs: [
307 "libnetjniutils",
308 ],
Lorenzo Colitti88ddd882019-05-01 11:54:33 +0900309
310 // We cannot use plain "libc++" here to link libc++ dynamically because it results in:
311 // java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
312 // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't
313 // build because soong complains of:
314 // module NetworkStack missing dependencies: libc++_shared
315 //
316 // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries
317 // we depend on do not dynamically link libc++. This is currently the case, because liblog is
318 // C-only and libnativehelper_compat_libc also uses stl: "c++_static".
319 //
320 // TODO: find a better solution for this in R.
321 stl: "c++_static",
paulhue455e2a2019-03-29 17:22:20 +0800322 cflags: [
323 "-Wall",
324 "-Werror",
325 "-Wno-unused-parameter",
326 ],
327}
328
Chiachang Wang80242272019-04-11 21:24:28 +0800329genrule {
Remi NGUYEN VANda5f6bb2021-02-09 08:08:38 +0000330 name: "statslog-networkstack-java-gen",
Chiachang Wang80242272019-04-11 21:24:28 +0800331 tools: ["stats-log-api-gen"],
332 cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
Muhammad Qureshi8e0e9bc2019-12-31 11:26:33 -0800333 " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
Remi NGUYEN VANda5f6bb2021-02-09 08:08:38 +0000334 " --supportQ",
Chiachang Wang80242272019-04-11 21:24:28 +0800335 out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
336}
Kun Niu8e89dd42019-07-16 18:33:45 -0700337
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900338version_code_networkstack_next = "300000000"
339version_code_networkstack_test = "999999999"
340
Kun Niu8e89dd42019-07-16 18:33:45 -0700341genrule {
342 name: "NetworkStackTestAndroidManifest",
343 srcs: ["AndroidManifest.xml"],
344 out: ["TestAndroidManifest.xml"],
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900345 cmd: "sed -E 's/versionCode=\"[0-9]+\"/versionCode=\""
346 + version_code_networkstack_test
347 + "\"/' $(in) > $(out)",
348 visibility: ["//visibility:private"],
349}
350
Kun Niu8e89dd42019-07-16 18:33:45 -0700351android_app {
352 name: "TestNetworkStack",
Remi NGUYEN VAN1d52af02020-12-22 02:08:55 +0000353 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
354 static_libs: ["NetworkStackApiStableLib"],
Kun Niu8e89dd42019-07-16 18:33:45 -0700355 certificate: "networkstack",
356 manifest: ":NetworkStackTestAndroidManifest",
Kun Niu8e89dd42019-07-16 18:33:45 -0700357 // The permission configuration *must* be included to ensure security of the device
358 required: ["NetworkPermissionConfig"],
359}
lifrcb15db32020-05-21 20:32:36 +0800360
Remi NGUYEN VAN84ba8152020-06-22 18:50:20 +0900361// When adding or modifying protos, the jarjar rules and possibly proguard rules need
362// to be updated: proto libraries may pull additional static libraries.
lifrcb15db32020-05-21 20:32:36 +0800363java_library_static {
364 name: "statsprotos",
365 proto: {
366 type: "lite",
367 },
368 srcs: [
369 "src/com/android/networkstack/metrics/stats.proto",
370 ],
371 static_libs: [
372 "networkstackprotos",
373 ],
374 defaults: ["NetworkStackReleaseApiLevel"],
375}