Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6709189 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Convert NetworkStack shims from filegroup to libraries.

Currently, the NetworkStack shims are a filegroup containing the
shims for all SDK levels, plus networkstack-module-utils-srcs.
The whole filegroup compiles against either system_current (for
NetworkStackNext and friends) or the latest stable SDK.

This CL changes that to one java_library per SDK level. This
ensures that each shim level (e.g., NetworkStackApi30Shims) can
only use classes that are present in its SDK level. It also
allows a shim implementation to directly subclass the class it is
shimming, and automatically have all the methods (and only the
methods) that the real class has at the shim's SDK level.

This requires a few drive-by changes:
1. Because the shims are no longer a filegroup, they can no
   longer contain networkstack-module-utils-srcs. Move that to
   NetworkStackAndroidLibraryDefaults which already contains
   framework-networkstack-shared-srcs.
2. Change CaptivePortalDataShimImpl from the @NonNull in
   android (which the shims shouldn't depend on) to the @NonNull
   in androidx.
3. Remove the NetworkStackApiStableDependencies target. This is
   no longer necessary because the compat jarjar rules are now
   directly on NetworkStackApiStableShims.

Test: m NetworkStack NetworkStackNext
Test: atest NetworkStackCoverageTests
Test: atest NetworkStackTests NetworkStackNextTests
Test: atest NetworkStackIntegrationTests NetworkStackNextIntegrationTests
Change-Id: Icdac8247efebd763bfb4387ee51e8c09ef8c7fd8
parent ee6648c4
Loading
Loading
Loading
Loading
+99 −37
Original line number Diff line number Diff line
@@ -22,12 +22,12 @@
//                                            /    \
//           +NetworkStackApiStableShims --> /      \ <-- +NetworkStackApiCurrentShims
//           +NetworkStackReleaseApiLevel   /        \    +NetworkStackDevApiLevel
//           +jarjar apistub.api[latest].* /          \   +module src/
//            to apistub.*                /            \
//           +jarjar apishim.api[latest].* /          \
//            to apishim.*                /            \
//                                       /              \
//                                      /                \
//         NetworkStackApiStableDependencies             \
//                                     /                  \               android libs w/ all code
//                   +module src/ --> /                    \              (also used in unit tests)
//                                    / <- +module src/ -> \              (also used in unit tests)
//                                   /                      \                        |
//               NetworkStackApiStableLib               NetworkStackApiCurrentLib <--*
//                          |                                     |
@@ -58,28 +58,104 @@ java_defaults {
    target_sdk_version: "30",
}

// Filegroups for the API shims
filegroup {
    name: "NetworkStackApiCurrentShims",
// Libraries for the API shims
java_defaults {
    name: "NetworkStackShimsDefaults",
    libs: [
        "androidx.annotation_annotation",
        "networkstack-client",
    ],
    min_sdk_version: "29",
}

// Common shim code. This includes the shim interface definitions themselves, and things like
// ShimUtils and UnsupportedApiLevelException. Compiles against system_current because ShimUtils
// needs access to all Build.VERSION_CODES.*, which by definition are only in the newest SDK.
// TODO: consider moving ShimUtils into a library (or removing it in favour of SdkLevel) and compile
// this target against the lowest-supported SDK (currently 29).
java_library {
    name: "NetworkStackShimsCommon",
    defaults: ["NetworkStackShimsDefaults"],
    srcs: ["apishim/common/**/*.java"],
    sdk_version: "system_current",
    visibility: ["//visibility:private"],
}

// Each level of the shims (29, 30, ...) is its own java_library compiled against the corresponding
// system_X SDK. this ensures that each shim can only use SDK classes that exist in its SDK level.
java_library {
    name: "NetworkStackApi29Shims",
    defaults: ["NetworkStackShimsDefaults"],
    srcs: ["apishim/29/**/*.java"],
    libs: [
        "NetworkStackShimsCommon",
    ],
    sdk_version: "system_29",
    visibility: ["//visibility:private"],
}

java_library {
    name: "NetworkStackApi30Shims",
    defaults: ["NetworkStackShimsDefaults"],
    srcs: [
        "apishim/common/**/*.java",
        "apishim/29/**/*.java",
        "apishim/30/**/*.java",
    ],
    libs: [
        "NetworkStackShimsCommon",
        "NetworkStackApi29Shims",
    ],
    sdk_version: "system_30",
    visibility: ["//visibility:private"],
}

// Shims for APIs being added to the current development version of Android. These APIs are not
// stable and have no defined version number. We could call these 10000, but we just pick the next
// integer, so if the next SDK release happens to use that integer, we don't need to rename them.
java_library {
    name: "NetworkStackApi31Shims",
    defaults: ["NetworkStackShimsDefaults"],
    srcs: [
        "apishim/31/**/*.java",
        ":networkstack-module-utils-srcs",
    ],
    libs: [
        "NetworkStackShimsCommon",
        "NetworkStackApi29Shims",
        "NetworkStackApi30Shims",
    ],
    sdk_version: "system_current",
    visibility: ["//visibility:private"],
}

// API stable shims only include the compat package, but it is jarjared to replace the non-compat
// package
filegroup {
// API current uses the API current shims directly.
// The current (in-progress) shims are in the com.android.networkstack.apishim package and are
// called directly by the networkstack code.
java_library {
    name: "NetworkStackApiCurrentShims",
    defaults: ["NetworkStackShimsDefaults"],
    static_libs: [
        "NetworkStackShimsCommon",
        "NetworkStackApi29Shims",
        "NetworkStackApi30Shims",
        "NetworkStackApi31Shims",
    ],
    sdk_version: "system_current",
    visibility: ["//visibility:private"],
}

// API stable uses jarjar to rename the latest stable apishim package from
// com.android.networkstack.apishim.apiXX to com.android.networkstack.apishim, which is called by
// the networkstack code.
java_library {
    name: "NetworkStackApiStableShims",
    srcs: [
        "apishim/common/**/*.java",
        "apishim/29/**/*.java",
        "apishim/30/**/*.java",
        ":networkstack-module-utils-srcs",
    defaults: ["NetworkStackShimsDefaults"],
    static_libs: [
        "NetworkStackShimsCommon",
        "NetworkStackApi29Shims",
        "NetworkStackApi30Shims",
    ],
    jarjar_rules: "apishim/jarjar-rules-compat.txt",
    sdk_version: "system_30",
    visibility: ["//visibility:private"],
}

// Common defaults for android libraries containing network stack code, used to compile variants of
@@ -88,6 +164,7 @@ java_defaults {
    name: "NetworkStackAndroidLibraryDefaults",
    srcs: [
        ":framework-networkstack-shared-srcs",
        ":networkstack-module-utils-srcs",
    ],
    libs: ["unsupportedappusage"],
    static_libs: [
@@ -105,41 +182,26 @@ java_defaults {
    plugins: ["java_api_finder"],
}

// The versions of the android library containing network stack code compiled for each SDK variant
// API current uses the sources of the API current shims directly.
// This allows API current code to be treated identically to code in src/ (it will be moved
// there eventually), and to use the compat shim as fallback on older devices.
// The versions of the android library containing network stack code compiled for each SDK variant.
android_library {
    name: "NetworkStackApiCurrentLib",
    defaults: ["NetworkStackDevApiLevel", "NetworkStackAndroidLibraryDefaults"],
    srcs: [
        ":NetworkStackApiCurrentShims",
        "src/**/*.java",
        ":statslog-networkstack-java-gen"
    ],
    static_libs: ["NetworkStackApiCurrentShims"],
    manifest: "AndroidManifestBase.xml",
}

// For API stable, first build the dependencies using jarjar compat rules, then build the sources
// linking with the dependencies.
java_library {
    name: "NetworkStackApiStableDependencies",
    defaults: ["NetworkStackReleaseApiLevel", "NetworkStackAndroidLibraryDefaults"],
    srcs: [":NetworkStackApiStableShims"],
    jarjar_rules: "apishim/jarjar-rules-compat.txt",
}

android_library {
    name: "NetworkStackApiStableLib",
    defaults: ["NetworkStackReleaseApiLevel"],
    defaults: ["NetworkStackReleaseApiLevel", "NetworkStackAndroidLibraryDefaults"],
    srcs: [
        "src/**/*.java",
        ":statslog-networkstack-java-gen",
    ],
    // API stable uses a jarjared version of the shims
    static_libs: [
        "NetworkStackApiStableDependencies",
    ],
    static_libs: ["NetworkStackApiStableShims"],
    manifest: "AndroidManifestBase.xml",
}

+2 −1
Original line number Diff line number Diff line
@@ -16,12 +16,13 @@

package com.android.networkstack.apishim.common;

import android.annotation.NonNull;
import android.net.CaptivePortalData;
import android.net.INetworkMonitorCallbacks;
import android.net.Uri;
import android.os.RemoteException;

import androidx.annotation.NonNull;

/**
 * Compatibility interface for {@link android.net.CaptivePortalData}.
 */