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