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