• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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//                          | <-- +NetworkStackReleaseApiLevel    | <-- +NetworkStackDevApiLevel
38//                          |                                     |
39//                          |                                     |
40//                NetworkStackApiStable          NetworkStack, InProcessNetworkStack, <-- APKs
41//                                                         TestNetworkStack
42
43// Common defaults to define SDK level
44java_defaults {
45    name: "NetworkStackDevApiLevel",
46    sdk_version: "system_current",
47}
48
49java_defaults {
50    name: "NetworkStackReleaseApiLevel",
51    sdk_version: "system_30",
52    min_sdk_version: "29",
53    target_sdk_version: "30",
54}
55
56// Filegroups for the API shims
57filegroup {
58    name: "NetworkStackApiCurrentShims",
59    srcs: [
60        "apishim/common/**/*.java",
61        "apishim/29/**/*.java",
62        "apishim/30/**/*.java",
63        "apishim/31/**/*.java",
64        ":networkstack-module-utils-srcs",
65    ],
66}
67
68// API stable shims only include the compat package, but it is jarjared to replace the non-compat
69// package
70filegroup {
71    name: "NetworkStackApiStableShims",
72    srcs: [
73        "apishim/common/**/*.java",
74        "apishim/29/**/*.java",
75        "apishim/30/**/*.java",
76        ":networkstack-module-utils-srcs",
77    ],
78}
79
80// Common defaults for android libraries containing network stack code, used to compile variants of
81// the network stack in the system process and in the network_stack process
82java_defaults {
83    name: "NetworkStackAndroidLibraryDefaults",
84    srcs: [
85        ":framework-networkstack-shared-srcs",
86    ],
87    libs: ["unsupportedappusage"],
88    static_libs: [
89        "androidx.annotation_annotation",
90        "netd_aidl_interface-java",
91        "netlink-client",
92        "networkstack-client",
93        "net-utils-framework-common",
94        // See note on statsprotos when adding/updating proto build rules
95        "datastallprotosnano",
96        "statsprotos",
97        "captiveportal-lib",
98    ],
99    plugins: ["java_api_finder"],
100}
101
102// The versions of the android library containing network stack code compiled for each SDK variant
103// API current uses the sources of the API current shims directly.
104// This allows API current code to be treated identically to code in src/ (it will be moved
105// there eventually), and to use the compat shim as fallback on older devices.
106android_library {
107    name: "NetworkStackApiCurrentLib",
108    defaults: ["NetworkStackDevApiLevel", "NetworkStackAndroidLibraryDefaults"],
109    srcs: [
110        ":NetworkStackApiCurrentShims",
111        "src/**/*.java",
112        ":statslog-networkstack-java-gen"
113    ],
114    manifest: "AndroidManifestBase.xml",
115}
116
117// For API stable, first build the dependencies using jarjar compat rules, then build the sources
118// linking with the dependencies.
119java_library {
120    name: "NetworkStackApiStableDependencies",
121    defaults: ["NetworkStackReleaseApiLevel", "NetworkStackAndroidLibraryDefaults"],
122    srcs: [":NetworkStackApiStableShims"],
123    jarjar_rules: "apishim/jarjar-rules-compat.txt",
124}
125
126android_library {
127    name: "NetworkStackApiStableLib",
128    defaults: ["NetworkStackReleaseApiLevel"],
129    srcs: [
130        "src/**/*.java",
131        ":statslog-networkstack-java-gen",
132    ],
133    // API stable uses a jarjared version of the shims
134    static_libs: [
135        "NetworkStackApiStableDependencies",
136    ],
137    manifest: "AndroidManifestBase.xml",
138}
139
140filegroup {
141    name: "NetworkStackJarJarRules",
142    srcs: ["jarjar-rules-shared.txt"],
143    visibility: [
144        "//packages/modules/NetworkStack/tests/unit",
145        "//packages/modules/NetworkStack/tests/integration",
146        "//frameworks/base/packages/Tethering/tests/integration",
147    ]
148}
149
150// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries
151java_defaults {
152    name: "NetworkStackAppDefaults",
153    privileged: true,
154    jni_libs: [
155        "libnativehelper_compat_libc++",
156        "libnetworkstackutilsjni",
157    ],
158    // Resources already included in NetworkStackBase
159    resource_dirs: [],
160    jarjar_rules: ":NetworkStackJarJarRules",
161    use_embedded_native_libs: true,
162    optimize: {
163        proguard_flags_files: ["proguard.flags"],
164    },
165}
166
167// Non-updatable network stack running in the system server process for devices not using the module
168android_app {
169    name: "InProcessNetworkStack",
170    defaults: [ "NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
171    static_libs: ["NetworkStackApiCurrentLib"],
172    certificate: "platform",
173    manifest: "AndroidManifest_InProcess.xml",
174    // InProcessNetworkStack is a replacement for NetworkStack
175    overrides: ["NetworkStack", "NetworkStackNext"],
176    // The permission configuration *must* be included to ensure security of the device
177    // The InProcessNetworkStack goes together with the PlatformCaptivePortalLogin, which replaces
178    // the default CaptivePortalLogin.
179    required: ["PlatformNetworkPermissionConfig", "PlatformCaptivePortalLogin"],
180}
181
182// Pre-merge the AndroidManifest for NetworkStackNext, so that its manifest can be merged on top
183android_library {
184    name: "NetworkStackNextManifestBase",
185    defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
186    static_libs: ["NetworkStackApiCurrentLib"],
187    manifest: "AndroidManifest.xml"
188}
189
190// NetworkStack build targeting the current API release, for testing on in-development SDK
191android_app {
192    name: "NetworkStackNext",
193    defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
194    static_libs: ["NetworkStackNextManifestBase"],
195    certificate: "networkstack",
196    manifest: "AndroidManifest_Next.xml",
197    // The permission configuration *must* be included to ensure security of the device
198    required: ["NetworkPermissionConfig"],
199}
200
201// Updatable network stack for finalized API
202android_app {
203    name: "NetworkStack",
204    defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
205    static_libs: ["NetworkStackApiStableLib"],
206    certificate: "networkstack",
207    manifest: "AndroidManifest.xml",
208    // The permission configuration *must* be included to ensure security of the device
209    required: ["NetworkPermissionConfig"],
210    updatable: true,
211}
212
213// Android library to derive test APKs for integration tests
214android_library {
215    name: "TestNetworkStackLib",
216    defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
217    static_libs: ["NetworkStackApiStableLib"],
218    manifest: "AndroidManifestBase.xml",
219    visibility: [
220        "//frameworks/base/tests/net/integration",
221        "//cts/tests/tests/net",
222    ],
223}
224
225cc_library_shared {
226    name: "libnetworkstackutilsjni",
227    srcs: [
228        "jni/network_stack_utils_jni.cpp"
229    ],
230    sdk_version: "29",
231    min_sdk_version: "29",
232    shared_libs: [
233        "liblog",
234        "libnativehelper_compat_libc++",
235    ],
236
237    // We cannot use plain "libc++" here to link libc++ dynamically because it results in:
238    //   java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
239    // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't
240    // build because soong complains of:
241    //   module NetworkStack missing dependencies: libc++_shared
242    //
243    // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries
244    // we depend on do not dynamically link libc++. This is currently the case, because liblog is
245    // C-only and libnativehelper_compat_libc also uses stl: "c++_static".
246    //
247    // TODO: find a better solution for this in R.
248    stl: "c++_static",
249    cflags: [
250        "-Wall",
251        "-Werror",
252        "-Wno-unused-parameter",
253    ],
254}
255
256genrule {
257    name: "statslog-networkstack-java-gen",
258    tools: ["stats-log-api-gen"],
259    cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
260         " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
261         " --supportQ",
262    out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
263}
264
265version_code_networkstack_next = "300000000"
266version_code_networkstack_test = "999999999"
267
268genrule {
269    name: "NetworkStackTestAndroidManifest",
270    srcs: ["AndroidManifest.xml"],
271    out: ["TestAndroidManifest.xml"],
272    cmd: "sed -E 's/versionCode=\"[0-9]+\"/versionCode=\""
273        + version_code_networkstack_test
274        + "\"/' $(in) > $(out)",
275    visibility: ["//visibility:private"],
276}
277
278android_app {
279    name: "TestNetworkStack",
280    defaults: ["NetworkStackAppDefaults", "NetworkStackDevApiLevel"],
281    static_libs: ["NetworkStackApiCurrentLib"],
282    certificate: "networkstack",
283    manifest: ":NetworkStackTestAndroidManifest",
284    // The permission configuration *must* be included to ensure security of the device
285    required: ["NetworkPermissionConfig"],
286}
287
288// When adding or modifying protos, the jarjar rules and possibly proguard rules need
289// to be updated: proto libraries may pull additional static libraries.
290java_library_static {
291    name: "statsprotos",
292    proto: {
293        type: "lite",
294    },
295    srcs: [
296        "src/com/android/networkstack/metrics/stats.proto",
297    ],
298    static_libs: [
299        "networkstackprotos",
300    ],
301    defaults: ["NetworkStackReleaseApiLevel"],
302}
303