Remi NGUYEN VAN | ded2315 | 2018-12-07 16:52:24 +0900 | [diff] [blame] | 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 | |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 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 |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 22 | // / \ |
| 23 | // +NetworkStackApiStableShims --> / \ <-- +NetworkStackApiCurrentShims |
| 24 | // +NetworkStackApiStableLevel / \ +NetworkStackApiCurrentLevel |
| 25 | // +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 | // | | |
| 37 | // | <-- +NetworkStackApiStableLevel | <-- +NetworkStackApiCurrentLevel |
| 38 | // | | |
| 39 | // | | |
| 40 | // NetworkStackApiStable NetworkStack, InProcessNetworkStack, <-- APKs |
| 41 | // TestNetworkStack |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 42 | |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 43 | // Common defaults to define SDK level |
Remi NGUYEN VAN | 4036956 | 2019-03-20 16:40:54 +0900 | [diff] [blame] | 44 | java_defaults { |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 45 | name: "NetworkStackApiCurrentLevel", |
Remi NGUYEN VAN | 4036956 | 2019-03-20 16:40:54 +0900 | [diff] [blame] | 46 | sdk_version: "system_current", |
| 47 | min_sdk_version: "28", |
| 48 | } |
| 49 | |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 50 | java_defaults { |
| 51 | name: "NetworkStackApiStableLevel", |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 52 | sdk_version: "system_29", |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 53 | min_sdk_version: "28", |
| 54 | } |
| 55 | |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 56 | // Filegroups for the API shims |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 57 | filegroup { |
| 58 | name: "NetworkStackApiCurrentShims", |
| 59 | srcs: [ |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 60 | "apishim/common/**/*.java", |
| 61 | "apishim/29/**/*.java", |
Remi NGUYEN VAN | f9c9b71 | 2019-11-08 11:37:33 +0000 | [diff] [blame] | 62 | "apishim/30/**/*.java", |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 63 | ":net-module-utils-srcs", |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 64 | ], |
| 65 | } |
| 66 | |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 67 | // API stable shims only include the compat package, but it is jarjared to replace the non-compat |
| 68 | // package |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 69 | filegroup { |
| 70 | name: "NetworkStackApiStableShims", |
| 71 | srcs: [ |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 72 | "apishim/common/**/*.java", |
| 73 | "apishim/29/**/*.java", |
| 74 | ":net-module-utils-srcs", |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 75 | ], |
| 76 | } |
| 77 | |
| 78 | // Common defaults for android libraries containing network stack code, used to compile variants of |
| 79 | // the network stack in the system process and in the network_stack process |
| 80 | java_defaults { |
| 81 | name: "NetworkStackAndroidLibraryDefaults", |
Remi NGUYEN VAN | ded2315 | 2018-12-07 16:52:24 +0900 | [diff] [blame] | 82 | srcs: [ |
Remi NGUYEN VAN | 82b4b42 | 2019-01-20 09:35:10 +0900 | [diff] [blame] | 83 | ":framework-networkstack-shared-srcs", |
Chiachang Wang | 8024227 | 2019-04-11 21:24:28 +0800 | [diff] [blame] | 84 | ":statslog-networkstack-java-gen", |
Remi NGUYEN VAN | ded2315 | 2018-12-07 16:52:24 +0900 | [diff] [blame] | 85 | ], |
Artur Satayev | 0eb158a | 2019-12-10 12:54:01 +0000 | [diff] [blame] | 86 | libs: ["unsupportedappusage"], |
Remi NGUYEN VAN | 057bf20 | 2018-12-04 12:13:09 +0900 | [diff] [blame] | 87 | static_libs: [ |
Niklas Lindgren | 0c90488 | 2018-12-07 11:08:04 +0100 | [diff] [blame] | 88 | "androidx.annotation_annotation", |
Chiachang Wang | 2abb2cc | 2019-12-11 21:20:24 +0800 | [diff] [blame^] | 89 | "netd_aidl_interface-unstable-java", |
Remi NGUYEN VAN | 1fc930c | 2019-08-09 13:23:47 +0900 | [diff] [blame] | 90 | "netlink-client", |
Remi NGUYEN VAN | bbb9703 | 2019-08-08 15:53:54 +0900 | [diff] [blame] | 91 | "networkstack-client", |
Chiachang Wang | 8b5f84a | 2019-02-22 11:13:07 +0800 | [diff] [blame] | 92 | "datastallprotosnano", |
Chiachang Wang | 54663a8 | 2019-03-21 20:40:01 +0800 | [diff] [blame] | 93 | "networkstackprotosnano", |
paulhu | 5982eff | 2019-03-29 19:21:30 +0800 | [diff] [blame] | 94 | "captiveportal-lib", |
Remi NGUYEN VAN | 0a4df5a | 2019-03-08 17:20:49 +0900 | [diff] [blame] | 95 | ], |
Kun Niu | f3b6904 | 2019-07-01 17:03:20 -0700 | [diff] [blame] | 96 | plugins: ["java_api_finder"], |
Remi NGUYEN VAN | 0a4df5a | 2019-03-08 17:20:49 +0900 | [diff] [blame] | 97 | } |
| 98 | |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 99 | // The versions of the android library containing network stack code compiled for each SDK variant |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 100 | // API current uses the sources of the API current shims directly. |
| 101 | // This allows API current code to be treated identically to code in src/ (it will be moved |
| 102 | // there eventually), and to use the compat shim as fallback on older devices. |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 103 | android_library { |
| 104 | name: "NetworkStackApiCurrentLib", |
| 105 | defaults: ["NetworkStackApiCurrentLevel", "NetworkStackAndroidLibraryDefaults"], |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 106 | srcs: [":NetworkStackApiCurrentShims", "src/**/*.java"], |
| 107 | manifest: "AndroidManifestBase.xml", |
| 108 | } |
| 109 | |
| 110 | // For API stable, first build the dependencies using jarjar compat rules, then build the sources |
| 111 | // linking with the dependencies. |
| 112 | java_library { |
| 113 | name: "NetworkStackApiStableDependencies", |
| 114 | defaults: ["NetworkStackApiStableLevel", "NetworkStackAndroidLibraryDefaults"], |
| 115 | srcs: [":NetworkStackApiStableShims"], |
| 116 | jarjar_rules: "apishim/jarjar-rules-compat.txt", |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | android_library { |
| 120 | name: "NetworkStackApiStableLib", |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 121 | defaults: ["NetworkStackApiStableLevel"], |
Remi NGUYEN VAN | 87790c2 | 2019-09-12 14:39:24 +0900 | [diff] [blame] | 122 | srcs: ["src/**/*.java"], |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 123 | // API stable uses a jarjared version of the shims |
| 124 | static_libs: [ |
| 125 | "NetworkStackApiStableDependencies", |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 126 | ], |
Remi NGUYEN VAN | 794a4b5 | 2019-09-06 13:00:33 +0900 | [diff] [blame] | 127 | manifest: "AndroidManifestBase.xml", |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | // Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries |
| 131 | java_defaults { |
| 132 | name: "NetworkStackAppDefaults", |
| 133 | privileged: true, |
| 134 | jni_libs: [ |
| 135 | "libnativehelper_compat_libc++", |
| 136 | "libnetworkstackutilsjni", |
| 137 | ], |
| 138 | // Resources already included in NetworkStackBase |
| 139 | resource_dirs: [], |
| 140 | jarjar_rules: "jarjar-rules-shared.txt", |
| 141 | use_embedded_native_libs: true, |
| 142 | optimize: { |
| 143 | proguard_flags_files: ["proguard.flags"], |
| 144 | }, |
| 145 | } |
| 146 | |
| 147 | // Non-updatable network stack running in the system server process for devices not using the module |
| 148 | android_app { |
| 149 | name: "InProcessNetworkStack", |
| 150 | defaults: [ "NetworkStackAppDefaults", "NetworkStackApiCurrentLevel"], |
| 151 | static_libs: ["NetworkStackApiCurrentLib"], |
| 152 | certificate: "platform", |
| 153 | manifest: "AndroidManifest_InProcess.xml", |
| 154 | // InProcessNetworkStack is a replacement for NetworkStack |
Remi NGUYEN VAN | ec9d8a6 | 2019-11-11 03:52:43 +0000 | [diff] [blame] | 155 | overrides: ["NetworkStack", "NetworkStackNext"], |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 156 | // The permission configuration *must* be included to ensure security of the device |
| 157 | // The InProcessNetworkStack goes together with the PlatformCaptivePortalLogin, which replaces |
| 158 | // the default CaptivePortalLogin. |
| 159 | required: ["PlatformNetworkPermissionConfig", "PlatformCaptivePortalLogin"], |
| 160 | } |
| 161 | |
| 162 | // Updatable network stack packaged as an application |
| 163 | android_app { |
Remi NGUYEN VAN | ec9d8a6 | 2019-11-11 03:52:43 +0000 | [diff] [blame] | 164 | name: "NetworkStackNext", |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 165 | defaults: ["NetworkStackAppDefaults", "NetworkStackApiCurrentLevel"], |
| 166 | static_libs: ["NetworkStackApiCurrentLib"], |
| 167 | certificate: "networkstack", |
| 168 | manifest: "AndroidManifest.xml", |
| 169 | // The permission configuration *must* be included to ensure security of the device |
| 170 | required: ["NetworkPermissionConfig"], |
| 171 | } |
| 172 | |
| 173 | // Updatable network stack for finalized API |
| 174 | android_app { |
Remi NGUYEN VAN | ec9d8a6 | 2019-11-11 03:52:43 +0000 | [diff] [blame] | 175 | name: "NetworkStack", |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 176 | defaults: ["NetworkStackAppDefaults", "NetworkStackApiStableLevel"], |
| 177 | static_libs: ["NetworkStackApiStableLib"], |
| 178 | certificate: "networkstack", |
| 179 | manifest: "AndroidManifest.xml", |
| 180 | // The permission configuration *must* be included to ensure security of the device |
| 181 | required: ["NetworkPermissionConfig"], |
| 182 | } |
| 183 | |
| 184 | // Android library to derive test APKs for integration tests |
| 185 | android_library { |
| 186 | name: "TestNetworkStackLib", |
| 187 | defaults: ["NetworkStackAppDefaults", "NetworkStackApiCurrentLevel"], |
| 188 | static_libs: ["NetworkStackApiCurrentLib"], |
Remi NGUYEN VAN | ae18aed | 2019-10-30 18:20:36 +0900 | [diff] [blame] | 189 | manifest: "AndroidManifestBase.xml", |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 190 | } |
| 191 | |
paulhu | e455e2a | 2019-03-29 17:22:20 +0800 | [diff] [blame] | 192 | cc_library_shared { |
| 193 | name: "libnetworkstackutilsjni", |
| 194 | srcs: [ |
| 195 | "jni/network_stack_utils_jni.cpp" |
| 196 | ], |
Lorenzo Colitti | 88ddd88 | 2019-05-01 11:54:33 +0900 | [diff] [blame] | 197 | sdk_version: "current", |
paulhu | e455e2a | 2019-03-29 17:22:20 +0800 | [diff] [blame] | 198 | shared_libs: [ |
| 199 | "liblog", |
Lorenzo Colitti | 88ddd88 | 2019-05-01 11:54:33 +0900 | [diff] [blame] | 200 | "libnativehelper_compat_libc++", |
paulhu | e455e2a | 2019-03-29 17:22:20 +0800 | [diff] [blame] | 201 | ], |
Lorenzo Colitti | 88ddd88 | 2019-05-01 11:54:33 +0900 | [diff] [blame] | 202 | |
| 203 | // We cannot use plain "libc++" here to link libc++ dynamically because it results in: |
| 204 | // java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found |
| 205 | // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't |
| 206 | // build because soong complains of: |
| 207 | // module NetworkStack missing dependencies: libc++_shared |
| 208 | // |
| 209 | // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries |
| 210 | // we depend on do not dynamically link libc++. This is currently the case, because liblog is |
| 211 | // C-only and libnativehelper_compat_libc also uses stl: "c++_static". |
| 212 | // |
| 213 | // TODO: find a better solution for this in R. |
| 214 | stl: "c++_static", |
paulhu | e455e2a | 2019-03-29 17:22:20 +0800 | [diff] [blame] | 215 | cflags: [ |
| 216 | "-Wall", |
| 217 | "-Werror", |
| 218 | "-Wno-unused-parameter", |
| 219 | ], |
| 220 | } |
| 221 | |
Chiachang Wang | 8024227 | 2019-04-11 21:24:28 +0800 | [diff] [blame] | 222 | genrule { |
| 223 | name: "statslog-networkstack-java-gen", |
| 224 | tools: ["stats-log-api-gen"], |
| 225 | cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" + |
| 226 | " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog", |
| 227 | out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"], |
| 228 | } |
Kun Niu | 8e89dd4 | 2019-07-16 18:33:45 -0700 | [diff] [blame] | 229 | |
| 230 | genrule { |
| 231 | name: "NetworkStackTestAndroidManifest", |
| 232 | srcs: ["AndroidManifest.xml"], |
| 233 | out: ["TestAndroidManifest.xml"], |
| 234 | cmd: "sed 's/versionCode=\".*\"/versionCode=\"300000000\"/' $(in) > $(out)", |
| 235 | } |
| 236 | |
| 237 | android_app { |
| 238 | name: "TestNetworkStack", |
Remi NGUYEN VAN | 9964576 | 2019-07-11 14:33:15 +0900 | [diff] [blame] | 239 | defaults: ["NetworkStackAppDefaults", "NetworkStackApiCurrentLevel"], |
| 240 | static_libs: ["NetworkStackApiCurrentLib"], |
Kun Niu | 8e89dd4 | 2019-07-16 18:33:45 -0700 | [diff] [blame] | 241 | certificate: "networkstack", |
| 242 | manifest: ":NetworkStackTestAndroidManifest", |
Kun Niu | 8e89dd4 | 2019-07-16 18:33:45 -0700 | [diff] [blame] | 243 | // The permission configuration *must* be included to ensure security of the device |
| 244 | required: ["NetworkPermissionConfig"], |
| 245 | } |