• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
2// Copyright (C) 2019 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
17package {
18    default_applicable_licenses: ["Android-Apache-2.0"],
19}
20
21java_defaults {
22    name: "TetheringApiLevel",
23    sdk_version: "module_current",
24    min_sdk_version: "30",
25}
26
27java_defaults {
28    name: "TetheringReleaseTargetSdk",
29    target_sdk_version: "33",
30}
31
32java_defaults {
33    name: "TetheringExternalLibs",
34    // Libraries not including Tethering's own framework-tethering (different flavors of that one
35    // are needed depending on the build rule)
36    libs: [
37        "connectivity-internal-api-util",
38        "framework-configinfrastructure",
39        "framework-connectivity.stubs.module_lib",
40        "framework-connectivity-t.stubs.module_lib",
41        "framework-statsd.stubs.module_lib",
42        "framework-wifi",
43        "framework-bluetooth",
44        "unsupportedappusage",
45    ],
46    defaults_visibility: ["//visibility:private"],
47}
48
49java_defaults {
50    name: "TetheringAndroidLibraryDefaults",
51    srcs: [
52        "apishim/**/*.java",
53        "src/**/*.java",
54        ":framework-connectivity-shared-srcs",
55        ":services-tethering-shared-srcs",
56        ":statslog-tethering-java-gen",
57    ],
58    static_libs: [
59        "androidx.annotation_annotation",
60        "connectivity-net-module-utils-bpf",
61        "modules-utils-build",
62        "modules-utils-statemachine",
63        "networkstack-client",
64        // AIDL tetheroffload implementation
65        "android.hardware.tetheroffload-V1-java",
66        // HIDL tetheroffload implementation
67        "android.hardware.tetheroffload.config-V1.0-java",
68        "android.hardware.tetheroffload.control-V1.0-java",
69        "android.hardware.tetheroffload.control-V1.1-java",
70        "android.hidl.manager-V1.2-java",
71        "net-utils-framework-common",
72        "net-utils-device-common",
73        "net-utils-device-common-bpf",
74        "net-utils-device-common-ip",
75        "net-utils-device-common-netlink",
76        "netd-client",
77        "tetheringstatsprotos",
78    ],
79    defaults: ["TetheringExternalLibs"],
80    libs: [
81        "framework-tethering.impl",
82    ],
83    manifest: "AndroidManifestBase.xml",
84    lint: { strict_updatability_linting: true },
85}
86
87// build tethering static library, used to compile both variants of the tethering.
88android_library {
89    name: "TetheringApiCurrentLib",
90    defaults: [
91        "ConnectivityNextEnableDefaults",
92        "TetheringAndroidLibraryDefaults",
93        "TetheringApiLevel",
94        "TetheringReleaseTargetSdk"
95    ],
96    static_libs: [
97        "NetworkStackApiCurrentShims",
98    ],
99    apex_available: ["com.android.tethering"],
100    lint: { strict_updatability_linting: true },
101}
102
103android_library {
104    name: "TetheringApiStableLib",
105    defaults: [
106        "TetheringAndroidLibraryDefaults",
107        "TetheringApiLevel",
108        "TetheringReleaseTargetSdk"
109    ],
110    static_libs: [
111        "NetworkStackApiStableShims",
112    ],
113    apex_available: ["com.android.tethering"],
114    lint: { strict_updatability_linting: true },
115}
116
117// Due to b/143733063, APK can't access a jni lib that is in APEX (but not in the APK).
118cc_library {
119    name: "libcom_android_networkstack_tethering_util_jni",
120    sdk_version: "30",
121    apex_available: [
122        "com.android.tethering",
123    ],
124    min_sdk_version: "30",
125    header_libs: [
126        "bpf_connectivity_headers",
127    ],
128    srcs: [
129        "jni/*.cpp",
130    ],
131    shared_libs: [
132        "liblog",
133        "libnativehelper_compat_libc++",
134    ],
135    static_libs: [
136        "libnet_utils_device_common_bpfjni",
137        "libnetjniutils",
138    ],
139
140    // We cannot use plain "libc++" here to link libc++ dynamically because it results in:
141    //   java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
142    // even if "libc++" is added into jni_libs below. Adding "libc++_shared" into jni_libs doesn't
143    // build because soong complains of:
144    //   module Tethering missing dependencies: libc++_shared
145    //
146    // So, link libc++ statically. This means that we also need to ensure that all the C++ libraries
147    // we depend on do not dynamically link libc++. This is currently the case, because liblog is
148    // C-only and libnativehelper_compat_libc also uses stl: "c++_static".
149    stl: "c++_static",
150
151    cflags: [
152        "-Wall",
153        "-Werror",
154        "-Wno-unused-parameter",
155        "-Wthread-safety",
156    ],
157
158    ldflags: ["-Wl,--exclude-libs=ALL,--error-limit=0"],
159}
160
161// Common defaults for compiling the actual APK.
162java_defaults {
163    name: "TetheringAppDefaults",
164    privileged: true,
165    jni_libs: [
166        "libcom_android_networkstack_tethering_util_jni",
167    ],
168    resource_dirs: [
169        "res",
170    ],
171    // Libs are not actually needed to build here since build rules using these defaults are just
172    // packaging the TetheringApiXLibs in APKs, but they are necessary so that R8 has the right
173    // references to optimize the code. Without these, there will be missing class warnings and code
174    // may be wrongly optimized.
175    // R8 runs after jarjar, so the framework-X libraries need to be the post-jarjar artifacts
176    // (framework-tethering.impl), if they are not just stubs, so that the name of jarjared
177    // classes match.
178    // TODO(b/229727645): ensure R8 fails the build fully if libraries are missing
179    defaults: ["TetheringExternalLibs"],
180    libs: [
181        "framework-tethering.impl",
182    ],
183    jarjar_rules: "jarjar-rules.txt",
184    optimize: {
185        proguard_flags_files: ["proguard.flags"],
186    },
187    lint: { strict_updatability_linting: true },
188}
189
190// Updatable tethering packaged for finalized API
191android_app {
192    name: "Tethering",
193    defaults: ["TetheringAppDefaults", "TetheringApiLevel"],
194    static_libs: ["TetheringApiStableLib"],
195    certificate: "networkstack",
196    manifest: "AndroidManifest.xml",
197    use_embedded_native_libs: true,
198    // The network stack *must* be included to ensure security of the device
199    required: [
200        "NetworkStack",
201        "privapp_allowlist_com.android.tethering",
202    ],
203    apex_available: ["com.android.tethering"],
204    lint: { strict_updatability_linting: true },
205}
206
207android_app {
208    name: "TetheringNext",
209    defaults: [
210        "TetheringAppDefaults",
211        "TetheringApiLevel",
212        "ConnectivityNextEnableDefaults",
213    ],
214    static_libs: ["TetheringApiCurrentLib"],
215    certificate: "networkstack",
216    manifest: "AndroidManifest.xml",
217    use_embedded_native_libs: true,
218    // The network stack *must* be included to ensure security of the device
219    required: [
220        "NetworkStackNext",
221        "privapp_allowlist_com.android.tethering",
222    ],
223    apex_available: ["com.android.tethering"],
224    lint: { strict_updatability_linting: true },
225}
226
227sdk {
228    name: "tethering-module-sdk",
229    apexes: [
230        // Adds exportable dependencies of the APEX to the sdk,
231        // e.g. *classpath_fragments.
232        "com.android.tethering",
233    ],
234    native_shared_libs: [
235        "libnetd_updatable",
236    ],
237}
238
239java_library_static {
240    name: "tetheringstatsprotos",
241    proto: {type: "lite"},
242    srcs: [
243        "src/com/android/networkstack/tethering/metrics/stats.proto",
244    ],
245    static_libs: ["tetheringprotos"],
246    apex_available: ["com.android.tethering"],
247    min_sdk_version: "30",
248}
249
250genrule {
251    name: "statslog-tethering-java-gen",
252    tools: ["stats-log-api-gen"],
253    cmd: "$(location stats-log-api-gen) --java $(out) --module network_tethering" +
254         " --javaPackage com.android.networkstack.tethering.metrics --javaClass TetheringStatsLog",
255    out: ["com/android/networkstack/tethering/metrics/TetheringStatsLog.java"],
256}
257