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