blob: a623101fcdde3227aef46b47641c540d8c96abfa [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 Colitti0ef45d42021-03-04 09:35:46 +090068 apex_available: [
69 "com.android.tethering",
70 "//apex_available:platform", // For InProcessNetworkStack and InProcessTethering
71 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +090072 min_sdk_version: "29",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090073}
74
Lorenzo Colittid6709182021-02-22 01:38:39 +090075// Common shim code. This includes the shim interface definitions themselves, and things like
76// ShimUtils and UnsupportedApiLevelException. Compiles against system_current because ShimUtils
77// needs access to all Build.VERSION_CODES.*, which by definition are only in the newest SDK.
78// TODO: consider moving ShimUtils into a library (or removing it in favour of SdkLevel) and compile
79// this target against the lowest-supported SDK (currently 29).
80java_library {
81 name: "NetworkStackShimsCommon",
82 defaults: ["NetworkStackShimsDefaults"],
83 srcs: ["apishim/common/**/*.java"],
84 sdk_version: "system_current",
85 visibility: ["//visibility:private"],
86}
87
88// Each level of the shims (29, 30, ...) is its own java_library compiled against the corresponding
89// system_X SDK. this ensures that each shim can only use SDK classes that exist in its SDK level.
90java_library {
91 name: "NetworkStackApi29Shims",
92 defaults: ["NetworkStackShimsDefaults"],
93 srcs: ["apishim/29/**/*.java"],
94 libs: [
95 "NetworkStackShimsCommon",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +090096 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +090097 sdk_version: "system_29",
98 visibility: ["//visibility:private"],
99}
100
101java_library {
102 name: "NetworkStackApi30Shims",
103 defaults: ["NetworkStackShimsDefaults"],
104 srcs: [
105 "apishim/30/**/*.java",
106 ],
107 libs: [
108 "NetworkStackShimsCommon",
109 "NetworkStackApi29Shims",
110 ],
111 sdk_version: "system_30",
112 visibility: ["//visibility:private"],
113}
114
115// Shims for APIs being added to the current development version of Android. These APIs are not
Lorenzo Colitti52f7eb12021-02-24 17:10:56 +0900116// stable and have no defined version number. These could be called 10000, but they use the next
117// 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 +0900118java_library {
119 name: "NetworkStackApi31Shims",
120 defaults: ["NetworkStackShimsDefaults"],
121 srcs: [
122 "apishim/31/**/*.java",
123 ],
124 libs: [
125 "NetworkStackShimsCommon",
126 "NetworkStackApi29Shims",
127 "NetworkStackApi30Shims",
Chiachang Wangffe87162021-02-26 17:36:52 +0800128 "framework-connectivity",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900129 ],
Chiachang Wangffe87162021-02-26 17:36:52 +0800130 sdk_version: "module_current",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900131 visibility: ["//visibility:private"],
132}
133
134// API current uses the API current shims directly.
135// The current (in-progress) shims are in the com.android.networkstack.apishim package and are
136// called directly by the networkstack code.
137java_library {
138 name: "NetworkStackApiCurrentShims",
139 defaults: ["NetworkStackShimsDefaults"],
140 static_libs: [
141 "NetworkStackShimsCommon",
142 "NetworkStackApi29Shims",
143 "NetworkStackApi30Shims",
144 "NetworkStackApi31Shims",
145 ],
Chiachang Wangffe87162021-02-26 17:36:52 +0800146 sdk_version: "module_current",
Chiachang Wanga331c3a2021-02-26 18:01:18 +0800147 visibility: [
Lorenzo Colitti0ef45d42021-03-04 09:35:46 +0900148 "//packages/modules/Connectivity/Tethering",
Chiachang Wanga331c3a2021-02-26 18:01:18 +0800149 "//packages/modules/Connectivity/tests/cts/net",
150 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +0900151}
152
153// API stable uses jarjar to rename the latest stable apishim package from
154// com.android.networkstack.apishim.apiXX to com.android.networkstack.apishim, which is called by
155// the networkstack code.
156java_library {
157 name: "NetworkStackApiStableShims",
158 defaults: ["NetworkStackShimsDefaults"],
159 static_libs: [
160 "NetworkStackShimsCommon",
161 "NetworkStackApi29Shims",
162 "NetworkStackApi30Shims",
163 ],
164 jarjar_rules: "apishim/jarjar-rules-compat.txt",
165 sdk_version: "system_30",
Chiachang Wanga331c3a2021-02-26 18:01:18 +0800166 visibility: [
Lorenzo Colitti0ef45d42021-03-04 09:35:46 +0900167 "//packages/modules/Connectivity/Tethering",
Chiachang Wanga331c3a2021-02-26 18:01:18 +0800168 "//packages/modules/Connectivity/tests/cts/net",
169 ],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900170}
171
172// Common defaults for android libraries containing network stack code, used to compile variants of
173// the network stack in the system process and in the network_stack process
174java_defaults {
175 name: "NetworkStackAndroidLibraryDefaults",
Remi NGUYEN VANded23152018-12-07 16:52:24 +0900176 srcs: [
Remi NGUYEN VAN82b4b422019-01-20 09:35:10 +0900177 ":framework-networkstack-shared-srcs",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900178 ":networkstack-module-utils-srcs",
Remi NGUYEN VANded23152018-12-07 16:52:24 +0900179 ],
Artur Satayev0eb158a2019-12-10 12:54:01 +0000180 libs: ["unsupportedappusage"],
Remi NGUYEN VAN057bf202018-12-04 12:13:09 +0900181 static_libs: [
Niklas Lindgren0c904882018-12-07 11:08:04 +0100182 "androidx.annotation_annotation",
Jeongik Cha848a5b52021-01-26 22:35:03 +0900183 "netd_aidl_interface-lateststable-java",
Remi NGUYEN VAN1fc930c2019-08-09 13:23:47 +0900184 "netlink-client",
Remi NGUYEN VANbbb97032019-08-08 15:53:54 +0900185 "networkstack-client",
Remi NGUYEN VAN5b00d422020-06-08 15:34:22 +0900186 "net-utils-framework-common",
Remi NGUYEN VAN84ba8152020-06-22 18:50:20 +0900187 // See note on statsprotos when adding/updating proto build rules
Chiachang Wang8b5f84a2019-02-22 11:13:07 +0800188 "datastallprotosnano",
lifrcb15db32020-05-21 20:32:36 +0800189 "statsprotos",
paulhu5982eff2019-03-29 19:21:30 +0800190 "captiveportal-lib",
Chalard Jean6f675212020-06-25 23:41:16 +0900191 "net-utils-device-common",
Remi NGUYEN VAN0a4df5a2019-03-08 17:20:49 +0900192 ],
Kun Niuf3b69042019-07-01 17:03:20 -0700193 plugins: ["java_api_finder"],
Remi NGUYEN VAN0a4df5a2019-03-08 17:20:49 +0900194}
195
Lorenzo Colittid6709182021-02-22 01:38:39 +0900196// The versions of the android library containing network stack code compiled for each SDK variant.
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900197android_library {
198 name: "NetworkStackApiCurrentLib",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900199 defaults: ["NetworkStackDevApiLevel", "NetworkStackAndroidLibraryDefaults"],
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800200 srcs: [
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800201 "src/**/*.java",
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000202 ":statslog-networkstack-java-gen-current"
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800203 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +0900204 static_libs: ["NetworkStackApiCurrentShims"],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900205 manifest: "AndroidManifestBase.xml",
Lorenzo Colitti55672ee2021-03-01 16:10:19 +0900206 visibility: [
207 "//frameworks/base/tests/net/integration",
208 "//packages/modules/Connectivity/Tethering/tests/integration",
209 "//packages/modules/Connectivity/tests/cts/net",
210 "//packages/modules/NetworkStack/tests/unit",
211 "//packages/modules/NetworkStack/tests/integration",
212 ],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900213}
214
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900215android_library {
216 name: "NetworkStackApiStableLib",
Lorenzo Colittid6709182021-02-22 01:38:39 +0900217 defaults: ["NetworkStackReleaseApiLevel", "NetworkStackAndroidLibraryDefaults"],
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800218 srcs: [
219 "src/**/*.java",
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000220 ":statslog-networkstack-java-gen-stable",
Muhammad Qureshiaa428cc2020-01-29 11:15:16 -0800221 ],
Lorenzo Colittid6709182021-02-22 01:38:39 +0900222 static_libs: ["NetworkStackApiStableShims"],
Remi NGUYEN VAN794a4b52019-09-06 13:00:33 +0900223 manifest: "AndroidManifestBase.xml",
Lorenzo Colitti55672ee2021-03-01 16:10:19 +0900224 visibility: [
225 "//frameworks/base/tests/net/integration",
226 "//packages/modules/Connectivity/Tethering/tests/integration",
227 "//packages/modules/Connectivity/tests/cts/net",
228 "//packages/modules/NetworkStack/tests/unit",
229 "//packages/modules/NetworkStack/tests/integration",
230 ],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900231}
232
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900233filegroup {
234 name: "NetworkStackJarJarRules",
235 srcs: ["jarjar-rules-shared.txt"],
236 visibility: [
237 "//packages/modules/NetworkStack/tests/unit",
238 "//packages/modules/NetworkStack/tests/integration",
Baligh Uddin1151e2e2020-10-29 02:12:29 +0000239 "//packages/modules/Connectivity/Tethering/tests/integration",
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900240 ]
241}
242
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900243// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries
244java_defaults {
245 name: "NetworkStackAppDefaults",
246 privileged: true,
247 jni_libs: [
248 "libnativehelper_compat_libc++",
249 "libnetworkstackutilsjni",
250 ],
251 // Resources already included in NetworkStackBase
252 resource_dirs: [],
Lorenzo Colittib891b5e2020-02-05 16:48:09 +0900253 jarjar_rules: ":NetworkStackJarJarRules",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900254 use_embedded_native_libs: true,
255 optimize: {
256 proguard_flags_files: ["proguard.flags"],
257 },
258}
259
260// Non-updatable network stack running in the system server process for devices not using the module
261android_app {
262 name: "InProcessNetworkStack",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900263 defaults: [ "NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900264 static_libs: ["NetworkStackApiCurrentLib"],
265 certificate: "platform",
266 manifest: "AndroidManifest_InProcess.xml",
267 // InProcessNetworkStack is a replacement for NetworkStack
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000268 overrides: ["NetworkStack", "NetworkStackNext"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900269 // The permission configuration *must* be included to ensure security of the device
270 // The InProcessNetworkStack goes together with the PlatformCaptivePortalLogin, which replaces
271 // the default CaptivePortalLogin.
272 required: ["PlatformNetworkPermissionConfig", "PlatformCaptivePortalLogin"],
273}
274
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900275// Pre-merge the AndroidManifest for NetworkStackNext, so that its manifest can be merged on top
276android_library {
277 name: "NetworkStackNextManifestBase",
278 defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
279 static_libs: ["NetworkStackApiCurrentLib"],
280 manifest: "AndroidManifest.xml"
281}
282
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900283// NetworkStack build targeting the current API release, for testing on in-development SDK
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900284android_app {
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000285 name: "NetworkStackNext",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900286 defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900287 static_libs: ["NetworkStackNextManifestBase"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900288 certificate: "networkstack",
Remi NGUYEN VAN255d4912020-02-05 13:42:45 +0900289 manifest: "AndroidManifest_Next.xml",
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900290 // The permission configuration *must* be included to ensure security of the device
291 required: ["NetworkPermissionConfig"],
292}
293
294// Updatable network stack for finalized API
295android_app {
Remi NGUYEN VANec9d8a62019-11-11 03:52:43 +0000296 name: "NetworkStack",
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900297 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900298 static_libs: ["NetworkStackApiStableLib"],
299 certificate: "networkstack",
300 manifest: "AndroidManifest.xml",
301 // The permission configuration *must* be included to ensure security of the device
302 required: ["NetworkPermissionConfig"],
Artur Satayev862a1a12020-04-09 11:35:52 +0100303 updatable: true,
Remi NGUYEN VAN99645762019-07-11 14:33:15 +0900304}
305
paulhue455e2a2019-03-29 17:22:20 +0800306cc_library_shared {
307 name: "libnetworkstackutilsjni",
308 srcs: [
309 "jni/network_stack_utils_jni.cpp"
310 ],
Jooyung Hand3fb9f52020-04-29 02:43:03 +0900311 sdk_version: "29",
312 min_sdk_version: "29",
paulhue455e2a2019-03-29 17:22:20 +0800313 shared_libs: [
314 "liblog",
Lorenzo Colitti88ddd882019-05-01 11:54:33 +0900315 "libnativehelper_compat_libc++",
paulhue455e2a2019-03-29 17:22:20 +0800316 ],
Orion Hodson94561f62020-12-08 09:56:29 +0000317 static_libs: [
318 "libnetjniutils",
319 ],
Lorenzo Colitti88ddd882019-05-01 11:54:33 +0900320
321 // We cannot use plain "libc++" here to link libc++ dynamically because it results in:
322 // java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
323 // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't
324 // build because soong complains of:
325 // module NetworkStack missing dependencies: libc++_shared
326 //
327 // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries
328 // we depend on do not dynamically link libc++. This is currently the case, because liblog is
329 // C-only and libnativehelper_compat_libc also uses stl: "c++_static".
330 //
331 // TODO: find a better solution for this in R.
332 stl: "c++_static",
paulhue455e2a2019-03-29 17:22:20 +0800333 cflags: [
334 "-Wall",
335 "-Werror",
336 "-Wno-unused-parameter",
337 ],
338}
339
Chiachang Wang80242272019-04-11 21:24:28 +0800340genrule {
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000341 name: "statslog-networkstack-java-gen-current",
Chiachang Wang80242272019-04-11 21:24:28 +0800342 tools: ["stats-log-api-gen"],
343 cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
Muhammad Qureshi8e0e9bc2019-12-31 11:26:33 -0800344 " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000345 " --minApiLevel 29",
Chiachang Wang80242272019-04-11 21:24:28 +0800346 out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
347}
Kun Niu8e89dd42019-07-16 18:33:45 -0700348
Muhammad Qureshicd7415e2021-02-11 01:54:48 +0000349genrule {
350 name: "statslog-networkstack-java-gen-stable",
351 tools: ["stats-log-api-gen"],
352 cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
353 " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
354 " --minApiLevel 29 --compileApiLevel 30",
355 out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
356}
357
358
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900359version_code_networkstack_next = "300000000"
360version_code_networkstack_test = "999999999"
361
Kun Niu8e89dd42019-07-16 18:33:45 -0700362genrule {
363 name: "NetworkStackTestAndroidManifest",
364 srcs: ["AndroidManifest.xml"],
365 out: ["TestAndroidManifest.xml"],
Remi NGUYEN VAN16fe4542020-01-16 13:48:38 +0900366 cmd: "sed -E 's/versionCode=\"[0-9]+\"/versionCode=\""
367 + version_code_networkstack_test
368 + "\"/' $(in) > $(out)",
369 visibility: ["//visibility:private"],
370}
371
Kun Niu8e89dd42019-07-16 18:33:45 -0700372android_app {
373 name: "TestNetworkStack",
Remi NGUYEN VAN1d52af02020-12-22 02:08:55 +0000374 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
375 static_libs: ["NetworkStackApiStableLib"],
Kun Niu8e89dd42019-07-16 18:33:45 -0700376 certificate: "networkstack",
377 manifest: ":NetworkStackTestAndroidManifest",
Kun Niu8e89dd42019-07-16 18:33:45 -0700378 // The permission configuration *must* be included to ensure security of the device
379 required: ["NetworkPermissionConfig"],
380}
lifrcb15db32020-05-21 20:32:36 +0800381
Remi NGUYEN VAN84ba8152020-06-22 18:50:20 +0900382// When adding or modifying protos, the jarjar rules and possibly proguard rules need
383// to be updated: proto libraries may pull additional static libraries.
lifrcb15db32020-05-21 20:32:36 +0800384java_library_static {
385 name: "statsprotos",
386 proto: {
387 type: "lite",
388 },
389 srcs: [
390 "src/com/android/networkstack/metrics/stats.proto",
391 ],
392 static_libs: [
393 "networkstackprotos",
394 ],
395 defaults: ["NetworkStackReleaseApiLevel"],
396}