1// 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 17// 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 22// / \ 23// +NetworkStackApiStableShims --> / \ <-- +NetworkStackApiCurrentShims 24// +NetworkStackReleaseApiLevel / \ +NetworkStackDevApiLevel 25// +jarjar apishim.api[latest].* / \ 26// to apishim.* / \ 27// / \ 28// / \ 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// | | 37// | <-- +NetworkStackReleaseApiLevel | <-- +NetworkStackDevApiLevel 38// | | 39// | | 40// NetworkStackApiStable NetworkStack, InProcessNetworkStack, <-- APKs 41// TestNetworkStack 42 43// Common defaults to define SDK level 44package { 45 default_applicable_licenses: ["Android-Apache-2.0"], 46} 47 48// In some branches, this may be module_current instead of module_34 if the SDK prebuilts are not 49// yet dropped there, meaning module_34 cannot be used yet. 50module_34_version = "module_34" 51 52// TODO: remove this default and replace with ConnectivityNextEnableDefaults. This will need to be 53// done separately in each branch due to merge conflicts. 54// Defaults to enable/disable java targets that depend on 55// NetworkStackNext, which uses development APIs. "enabled" may 56// have a different value depending on the branch. 57java_defaults { 58 name: "NetworkStackNextEnableDefaults", 59 enabled: true, 60} 61// This is a placeholder comment to avoid merge conflicts 62// as the above target may have different "enabled" values 63// depending on the branch 64 65java_defaults { 66 name: "NetworkStackDevApiLevel", 67 min_sdk_version: "29", 68 sdk_version: "module_current", 69 libs: [ 70 "framework-configinfrastructure", 71 "framework-connectivity", 72 "framework-connectivity-t", 73 "framework-statsd", 74 "framework-wifi", 75 ] 76} 77 78// Common defaults for NetworkStack integration tests, root tests and coverage tests 79// to keep tests always running against the same target sdk version with NetworkStack. 80java_defaults { 81 name: "NetworkStackReleaseTargetSdk", 82 min_sdk_version: "29", 83 target_sdk_version: "34", 84} 85 86java_defaults { 87 name: "NetworkStackReleaseApiLevel", 88 defaults:["NetworkStackReleaseTargetSdk"], 89 sdk_version: module_34_version, 90 libs: [ 91 "framework-configinfrastructure", 92 "framework-connectivity", 93 "framework-connectivity-t", 94 "framework-statsd", 95 "framework-wifi", 96 ] 97} 98 99// Libraries for the API shims 100java_defaults { 101 name: "NetworkStackShimsDefaults", 102 libs: [ 103 "androidx.annotation_annotation", 104 "networkstack-aidl-latest", 105 ], 106 static_libs : [ 107 "modules-utils-build_system" 108 ], 109 apex_available: [ 110 "com.android.tethering", 111 "//apex_available:platform", // For InProcessNetworkStack and InProcessTethering 112 ], 113 min_sdk_version: "29", 114} 115 116// Common shim code. This includes the shim interface definitions themselves, and things like 117// ShimUtils and UnsupportedApiLevelException. Compiles against system_current because ShimUtils 118// needs access to all Build.VERSION_CODES.*, which by definition are only in the newest SDK. 119// TODO: consider moving ShimUtils into a library (or removing it in favour of SdkLevel) and compile 120// this target against the lowest-supported SDK (currently 29). 121java_library { 122 name: "NetworkStackShimsCommon", 123 defaults: ["NetworkStackShimsDefaults"], 124 srcs: ["apishim/common/**/*.java"], 125 sdk_version: "system_current", 126 visibility: ["//visibility:private"], 127} 128 129// Each level of the shims (29, 30, ...) is its own java_library compiled against the corresponding 130// system_X SDK. this ensures that each shim can only use SDK classes that exist in its SDK level. 131java_library { 132 name: "NetworkStackApi29Shims", 133 defaults: ["NetworkStackShimsDefaults"], 134 srcs: ["apishim/29/**/*.java"], 135 libs: [ 136 "NetworkStackShimsCommon", 137 ], 138 sdk_version: "system_29", 139 visibility: ["//visibility:private"], 140} 141 142java_library { 143 name: "NetworkStackApi30Shims", 144 defaults: ["NetworkStackShimsDefaults"], 145 srcs: [ 146 "apishim/30/**/*.java", 147 ], 148 libs: [ 149 "NetworkStackShimsCommon", 150 "NetworkStackApi29Shims", 151 ], 152 sdk_version: "system_30", 153 visibility: ["//visibility:private"], 154 lint: { 155 strict_updatability_linting: true, 156 }, 157} 158 159java_library { 160 name: "NetworkStackApi31Shims", 161 defaults: ["NetworkStackShimsDefaults"], 162 srcs: [ 163 "apishim/31/**/*.java", 164 ], 165 static_libs: [ 166 // Libs building against module API can only be linked against when building against 167 // module API (so NetworkStackApi30Shims or NetworkStackApi29Shims can't use it, since they 168 // use system_30 and system_29 respectively). 169 "net-utils-framework-common", 170 ], 171 libs: [ 172 "NetworkStackShimsCommon", 173 "NetworkStackApi29Shims", 174 "NetworkStackApi30Shims", 175 "framework-connectivity", 176 ], 177 sdk_version: "module_31", 178 visibility: ["//visibility:private"], 179} 180 181java_library { 182 name: "NetworkStackApi33Shims", 183 defaults: ["NetworkStackShimsDefaults"], 184 srcs: [ 185 "apishim/33/**/*.java", 186 ], 187 libs: [ 188 "NetworkStackShimsCommon", 189 "NetworkStackApi29Shims", 190 "NetworkStackApi30Shims", 191 "NetworkStackApi31Shims", 192 "framework-bluetooth", 193 "framework-connectivity", 194 "framework-connectivity-t.stubs.module_lib", 195 "framework-tethering", 196 "android.net.ipsec.ike.stubs.module_lib", 197 ], 198 sdk_version: "module_33", 199 visibility: ["//visibility:private"], 200} 201 202java_library { 203 name: "NetworkStackApi34Shims", 204 defaults: ["NetworkStackShimsDefaults"], 205 srcs: [ 206 "apishim/34/**/*.java", 207 ], 208 libs: [ 209 "NetworkStackShimsCommon", 210 "NetworkStackApi29Shims", 211 "NetworkStackApi30Shims", 212 "NetworkStackApi31Shims", 213 "NetworkStackApi33Shims", 214 "framework-bluetooth", 215 "framework-connectivity", 216 "framework-connectivity-t.stubs.module_lib", 217 "framework-tethering", 218 "android.net.ipsec.ike.stubs.module_lib" 219 ], 220 sdk_version: module_34_version, 221 visibility: ["//visibility:private"], 222} 223 224// Shims for APIs being added to the current development version of Android. These APIs are not 225// stable and have no defined version number. These could be called 10000, but they use the next 226// integer so if the next SDK release happens to use that integer, we don't need to rename them. 227// Jarjar rules are generated based on the stable shims, which do not contain this library. As a 228// result, no static_lib that needs jarjar should be used here. In general, static_libs should not 229// be used in this library at all; instead they can be in one of the earlier, shim libraries which 230// are part of the stable shims and scanned when generating jarjar rules. 231java_library { 232 name: "NetworkStackApi35Shims", 233 defaults: ["NetworkStackShimsDefaults", "ConnectivityNextEnableDefaults"], 234 srcs: [ 235 "apishim/35/**/*.java", 236 ], 237 libs: [ 238 "NetworkStackShimsCommon", 239 "NetworkStackApi29Shims", 240 "NetworkStackApi30Shims", 241 "NetworkStackApi31Shims", 242 "NetworkStackApi33Shims", 243 "NetworkStackApi34Shims", 244 "framework-bluetooth", 245 "framework-connectivity", 246 "framework-connectivity-t.stubs.module_lib", 247 "framework-tethering", 248 "android.net.ipsec.ike.stubs.module_lib" 249 ], 250 sdk_version: "module_current", 251 visibility: ["//visibility:private"], 252} 253 254// API current uses the API current shims directly. 255// The current (in-progress) shims are in the com.android.networkstack.apishim package and are 256// called directly by the networkstack code. 257java_library { 258 name: "NetworkStackApiCurrentShims", 259 defaults: [ 260 "NetworkStackShimsDefaults", 261 "NetworkStackDevApiLevel", 262 "ConnectivityNextEnableDefaults", 263 ], 264 static_libs: [ 265 "NetworkStackShimsCommon", 266 "NetworkStackApi29Shims", 267 "NetworkStackApi30Shims", 268 "NetworkStackApi31Shims", 269 "NetworkStackApi33Shims", 270 "NetworkStackApi34Shims", 271 "NetworkStackApi35Shims", 272 ], 273 visibility: [ 274 "//packages/modules/Connectivity/Tethering", 275 "//packages/modules/Connectivity/service", 276 "//packages/modules/Connectivity/service-t", 277 "//packages/modules/Connectivity/tests:__subpackages__", 278 ], 279} 280 281// API stable uses jarjar to rename the latest stable apishim package from 282// com.android.networkstack.apishim.apiXX to com.android.networkstack.apishim, which is called by 283// the networkstack code. 284java_library { 285 name: "NetworkStackApiStableShims", 286 defaults: ["NetworkStackShimsDefaults", "NetworkStackReleaseApiLevel"], 287 static_libs: [ 288 "NetworkStackShimsCommon", 289 "NetworkStackApi29Shims", 290 "NetworkStackApi30Shims", 291 "NetworkStackApi31Shims", 292 "NetworkStackApi33Shims", 293 "NetworkStackApi34Shims", 294 ], 295 jarjar_rules: "apishim/jarjar-rules-compat.txt", 296 visibility: [ 297 "//packages/modules/Connectivity/Tethering", 298 "//packages/modules/Connectivity/service", 299 "//packages/modules/Connectivity/service-t", 300 "//packages/modules/Connectivity/tests:__subpackages__", 301 ], 302} 303 304// Common defaults for android libraries containing network stack code, used to compile variants of 305// the network stack in the system process and in the network_stack process 306java_defaults { 307 name: "NetworkStackAndroidLibraryDefaults", 308 srcs: [ 309 ":framework-networkstack-shared-srcs", 310 ], 311 libs: ["unsupportedappusage"], 312 static_libs: [ 313 "androidx.annotation_annotation", 314 "modules-utils-build_system", 315 "modules-utils-preconditions", 316 "modules-utils-statemachine", 317 "netd_aidl_interface-lateststable-java", 318 "networkstack-client", 319 "net-utils-framework-common", 320 // See note on statsprotos when adding/updating proto build rules 321 "datastallprotosnano", 322 "statsprotos", 323 "captiveportal-lib", 324 "net-utils-device-common", 325 "net-utils-device-common-ip", 326 "net-utils-device-common-netlink", 327 ], 328} 329 330// The versions of the android library containing network stack code compiled for each SDK variant. 331android_library { 332 name: "NetworkStackApiCurrentLib", 333 defaults: [ 334 "NetworkStackDevApiLevel", 335 "NetworkStackAndroidLibraryDefaults", 336 "ConnectivityNextEnableDefaults", 337 ], 338 srcs: [ 339 "src/**/*.java", 340 ":statslog-networkstack-java-gen-current" 341 ], 342 static_libs: ["NetworkStackApiCurrentShims"], 343 manifest: "AndroidManifestBase.xml", 344 visibility: [ 345 "//frameworks/base/tests/net/integration", 346 "//packages/modules/Connectivity/Tethering/tests/integration", 347 "//packages/modules/NetworkStack/tests/unit", 348 "//packages/modules/NetworkStack/tests/integration", 349 ], 350 lint: { strict_updatability_linting: true }, 351} 352 353android_library { 354 name: "NetworkStackApiStableLib", 355 defaults: ["NetworkStackReleaseApiLevel", "NetworkStackAndroidLibraryDefaults"], 356 srcs: [ 357 "src/**/*.java", 358 ":statslog-networkstack-java-gen-stable", 359 ], 360 static_libs: ["NetworkStackApiStableShims"], 361 manifest: "AndroidManifestBase.xml", 362 visibility: [ 363 "//frameworks/base/packages/Connectivity/tests/integration", 364 "//frameworks/base/tests/net/integration", 365 "//packages/modules/Connectivity/Tethering/tests/integration", 366 "//packages/modules/Connectivity/tests/integration", 367 "//packages/modules/NetworkStack/tests/unit", 368 "//packages/modules/NetworkStack/tests/integration", 369 ], 370 lint: { strict_updatability_linting: true }, 371} 372 373java_library { 374 name: "DhcpPacketLib", 375 defaults: ["NetworkStackReleaseApiLevel"], 376 srcs: [ 377 "src/android/net/DhcpResults.java", 378 "src/android/net/dhcp/Dhcp*Packet.java", 379 ], 380 libs: [ 381 "androidx.annotation_annotation", 382 "framework-annotations-lib", 383 ], 384 static_libs: [ 385 "modules-utils-build", 386 "net-utils-framework-common", 387 "networkstack-client", 388 ], 389 // If this library is ever used outside of tests, it should not use "Dhcp*Packet", and specify 390 // its contents explicitly. 391 visibility: ["//packages/modules/Connectivity/tests/cts/net"], 392} 393 394java_genrule { 395 name: "NetworkStackJarJarRules", 396 tool_files: [ 397 // com.android.networkstack.apishim is already in the target package that is not jarjared, 398 // so it does not matter whether ApiStable or ApiCurrent is used to generate the jarjar 399 // rules. Use ApiStable to be based on most stable release configuration and be buildable 400 // in all branches. 401 ":NetworkStackApiStableLib{.jar}", 402 "jarjar-excludes.txt", 403 ], 404 tools: [ 405 "jarjar-rules-generator", 406 ], 407 out: ["NetworkStackJarJarRules.txt"], 408 cmd: "$(location jarjar-rules-generator) " + 409 "$(location :NetworkStackApiStableLib{.jar}) " + 410 "--prefix com.android.networkstack " + 411 "--excludes $(location jarjar-excludes.txt) " + 412 "--output $(out)", 413 visibility: [ 414 "//packages/modules/NetworkStack/tests/unit", 415 "//packages/modules/NetworkStack/tests/integration", 416 "//packages/modules/Connectivity/tests:__subpackages__", 417 "//packages/modules/Connectivity/Tethering/tests/integration", 418 ], 419} 420 421// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries 422java_defaults { 423 name: "NetworkStackAppDefaults", 424 privileged: true, 425 jni_libs: [ 426 "libnativehelper_compat_libc++", 427 "libnetworkstackutilsjni", 428 ], 429 // Resources already included in NetworkStackBase 430 resource_dirs: [], 431 jarjar_rules: ":NetworkStackJarJarRules", 432 use_embedded_native_libs: true, 433 optimize: { 434 ignore_warnings: false, 435 proguard_flags_files: ["proguard.flags"], 436 }, 437} 438 439// Non-updatable network stack running in the system server process for devices not using the module 440android_app { 441 name: "InProcessNetworkStack", 442 defaults: [ 443 "NetworkStackAppDefaults", 444 "NetworkStackDevApiLevel", 445 "ConnectivityNextEnableDefaults", 446 ], 447 static_libs: ["NetworkStackApiCurrentLib"], 448 certificate: "platform", 449 manifest: "AndroidManifest_InProcess.xml", 450 // InProcessNetworkStack is a replacement for NetworkStack 451 overrides: ["NetworkStack", "NetworkStackNext"], 452 // The InProcessNetworkStack goes together with the PlatformCaptivePortalLogin, which replaces 453 // the default CaptivePortalLogin. 454 required: [ 455 "PlatformCaptivePortalLogin", 456 ], 457} 458 459// Pre-merge the AndroidManifest for NetworkStackNext, so that its manifest can be merged on top 460android_library { 461 name: "NetworkStackNextManifestBase", 462 defaults: [ 463 "NetworkStackAppDefaults", 464 "NetworkStackDevApiLevel", 465 "ConnectivityNextEnableDefaults", 466 ], 467 static_libs: ["NetworkStackApiCurrentLib"], 468 manifest: "AndroidManifest.xml" 469} 470 471// NetworkStack build targeting the current API release, for testing on in-development SDK 472android_app { 473 name: "NetworkStackNext", 474 defaults: [ 475 "NetworkStackAppDefaults", 476 "NetworkStackDevApiLevel", 477 "ConnectivityNextEnableDefaults", 478 ], 479 static_libs: ["NetworkStackNextManifestBase"], 480 certificate: "networkstack", 481 manifest: "AndroidManifest_Next.xml", 482 required: [ 483 "privapp_whitelist_com.android.networkstack", 484 ], 485 updatable: true, 486 lint: { strict_updatability_linting: true }, 487} 488 489// Updatable network stack for finalized API 490android_app { 491 name: "NetworkStack", 492 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"], 493 static_libs: ["NetworkStackApiStableLib"], 494 certificate: "networkstack", 495 manifest: "AndroidManifest.xml", 496 required: [ 497 "privapp_whitelist_com.android.networkstack", 498 ], 499 updatable: true, 500 lint: { strict_updatability_linting: true }, 501} 502 503cc_library_shared { 504 name: "libnetworkstackutilsjni", 505 srcs: [ 506 "jni/network_stack_utils_jni.cpp" 507 ], 508 sdk_version: "29", 509 min_sdk_version: "29", 510 shared_libs: [ 511 "liblog", 512 "libnativehelper_compat_libc++", 513 ], 514 static_libs: [ 515 "libnetjniutils", 516 ], 517 518 // We cannot use plain "libc++" here to link libc++ dynamically because it results in: 519 // java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found 520 // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't 521 // build because soong complains of: 522 // module NetworkStack missing dependencies: libc++_shared 523 // 524 // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries 525 // we depend on do not dynamically link libc++. This is currently the case, because liblog is 526 // C-only and libnativehelper_compat_libc also uses stl: "c++_static". 527 // 528 // TODO: find a better solution for this in R. 529 stl: "c++_static", 530 cflags: [ 531 "-Wall", 532 "-Werror", 533 "-Wno-unused-parameter", 534 ], 535} 536 537genrule { 538 name: "statslog-networkstack-java-gen-current", 539 tools: ["stats-log-api-gen"], 540 cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" + 541 " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" + 542 " --minApiLevel 29", 543 out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"], 544} 545 546genrule { 547 name: "statslog-networkstack-java-gen-stable", 548 tools: ["stats-log-api-gen"], 549 cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" + 550 " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" + 551 " --minApiLevel 29 --compileApiLevel 30", 552 out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"], 553} 554 555 556version_code_networkstack_next = "300000000" 557version_code_networkstack_test = "999999999" 558 559genrule { 560 name: "NetworkStackTestAndroidManifest", 561 srcs: ["AndroidManifest.xml"], 562 out: ["TestAndroidManifest.xml"], 563 cmd: "sed -E 's/versionCode=\"[0-9]+\"/versionCode=\"" 564 + version_code_networkstack_test 565 + "\"/' $(in) > $(out)", 566 visibility: ["//visibility:private"], 567} 568 569android_app { 570 name: "TestNetworkStack", 571 defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"], 572 static_libs: ["NetworkStackApiStableLib"], 573 certificate: "networkstack", 574 manifest: ":NetworkStackTestAndroidManifest", 575 required: [ 576 "privapp_whitelist_com.android.networkstack", 577 ], 578} 579 580// When adding or modifying protos, the jarjar rules and possibly proguard rules need 581// to be updated: proto libraries may pull additional static libraries. 582java_library_static { 583 name: "statsprotos", 584 proto: { 585 type: "lite", 586 }, 587 srcs: [ 588 "src/com/android/networkstack/metrics/stats.proto", 589 ], 590 static_libs: [ 591 "networkstackprotos", 592 ], 593 defaults: ["NetworkStackReleaseApiLevel"], 594} 595