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

Commit ce8888a1 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by android-build-merger
Browse files

Merge "Compile NetworkStackApiStable as system_29" am: 8292962a am: 1522fdc2 am: 0bc45381

am: 19ad75d1

Change-Id: Ifa2944f466239ddd6a26359d25ccf2431835550d
parents 07e4516c 19ad75d1
Loading
Loading
Loading
Loading
+51 −26
Original line number Diff line number Diff line
@@ -22,16 +22,22 @@
//                                            /    \
//           +NetworkStackApiStableShims --> /      \ <-- +NetworkStackApiCurrentShims
//           +NetworkStackApiStableLevel    /        \    +NetworkStackApiCurrentLevel
//           +jarjar apistub.api[latest].* /          \   +module src/
//            to apistub.*                /            \
//                                       /              \
//           NetworkStackApiStableLib         NetworkStackApiCurrentLib <-- android libs w/ all code
//                     |                                     |             (also used in unit tests)
//         NetworkStackApiStableDependencies             \
//                                     /                  \               android libs w/ all code
//                   +module src/ --> /                    \              (also used in unit tests)
//                                   /                      \                        |
//               NetworkStackApiStableLib               NetworkStackApiCurrentLib <--*
//                          |                                     |
//                          | <--   +NetworkStackAppDefaults  --> |
//                          |          (APK build params)         |
//                          |                                     |
//                          | <-- +NetworkStackApiStableLevel     | <-- +NetworkStackApiCurrentLevel
//                          |                                     |
//                          |                                     |
//           NetworkStackApiStable          NetworkStack, InProcessNetworkStack, <-- output APKs
//                NetworkStackApiStable          NetworkStack, InProcessNetworkStack, <-- APKs
//                                                         TestNetworkStack

// Common defaults to define SDK level
@@ -43,22 +49,29 @@ java_defaults {

java_defaults {
    name: "NetworkStackApiStableLevel",
    sdk_version: "system_current", // TODO: change to system_29
    sdk_version: "system_29",
    min_sdk_version: "28",
}

// Java libraries for the API shims
// Filegroups for the API shims
filegroup {
    name: "NetworkStackApiCurrentShims",
    srcs: [
        "apishim/current/**/*.java"
        "apishim/common/**/*.java",
        "apishim/29/**/*.java",
        "apishim/current/**/*.java",
        ":net-module-utils-srcs",
    ],
}

// API stable shims only include the compat package, but it is jarjared to replace the non-compat
// package
filegroup {
    name: "NetworkStackApiStableShims",
    srcs: [
        "apishim/29/**/*.java"
        "apishim/common/**/*.java",
        "apishim/29/**/*.java",
        ":net-module-utils-srcs",
    ],
}

@@ -67,7 +80,6 @@ filegroup {
java_defaults {
    name: "NetworkStackAndroidLibraryDefaults",
    srcs: [
        "src/**/*.java",
        ":framework-networkstack-shared-srcs",
        ":services-networkstack-shared-srcs",
        ":statslog-networkstack-java-gen",
@@ -80,25 +92,38 @@ java_defaults {
        "networkstackprotosnano",
        "captiveportal-lib",
    ],
    manifest: "AndroidManifestBase.xml",
    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.
android_library {
    name: "NetworkStackApiCurrentLib",
    defaults: ["NetworkStackApiCurrentLevel", "NetworkStackAndroidLibraryDefaults"],
    srcs: [
        ":NetworkStackApiCurrentShims",
    ],
    srcs: [":NetworkStackApiCurrentShims", "src/**/*.java"],
    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: ["NetworkStackApiStableLevel", "NetworkStackAndroidLibraryDefaults"],
    srcs: [":NetworkStackApiStableShims"],
    jarjar_rules: "apishim/jarjar-rules-compat.txt",
}

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

// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries
+15 −1
Original line number Diff line number Diff line
@@ -14,18 +14,32 @@
 * limitations under the License.
 */

package com.android.networkstack.apishim;
package com.android.networkstack.apishim.api29;

import android.net.util.SocketUtils;

import androidx.annotation.NonNull;

import com.android.networkstack.apishim.SocketUtilsShim;

import java.net.SocketAddress;

/**
 * Implementation of SocketUtilsShim for API 29.
 */
public class SocketUtilsShimImpl implements SocketUtilsShim {
    protected SocketUtilsShimImpl() {}

    /**
     * Get a new instance of {@link SocketUtilsShim}.
     *
     * Use com.android.networkstack.apishim.SocketUtilsShim#newInstance()
     * (non-API29 version) instead, to use the correct shims depending on build SDK.
     */
    public static SocketUtilsShim newInstance() {
        return new SocketUtilsShimImpl();
    }

    @NonNull
    @Override
    public SocketAddress makePacketSocketAddress(
+15 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.networkstack.apishim;

import android.net.util.SocketUtils;
import android.os.Build;

import androidx.annotation.NonNull;

@@ -25,7 +26,20 @@ import java.net.SocketAddress;
/**
 * Implementation of {@link SocketUtilsShim} for API 30.
 */
public class SocketUtilsShimImpl implements SocketUtilsShim {
public class SocketUtilsShimImpl
        extends com.android.networkstack.apishim.api29.SocketUtilsShimImpl {
    protected SocketUtilsShimImpl() {}

    /**
     * Get a new instance of {@link SocketUtilsShim}.
     */
    public static SocketUtilsShim newInstance() {
        if (!ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) {
            return com.android.networkstack.apishim.api29.SocketUtilsShimImpl.newInstance();
        }
        return new SocketUtilsShimImpl();
    }

    @NonNull
    @Override
    public SocketAddress makePacketSocketAddress(
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.networkstack.apishim;

import android.os.Build;

/**
 * Utility class for API shims.
 */
public final class ShimUtils {
    /**
     * Check whether the device release or development API level is strictly higher than the passed
     * in level.
     *
     * On a development build (codename != REL), the device will have the same API level as the
     * last stable release, even though some additional APIs may be available. In this method the
     * device API level is considered to be higher if the device supports a stable SDK with a higher
     * version number, or if the device supports a development version of a SDK that has a higher
     * version number.
     *
     * @return True if the device supports an SDK that has or will have a higher version number,
     *         even if still in development.
     */
    public static boolean isReleaseOrDevelopmentApiAbove(int apiLevel) {
        // In-development API n+1 will have SDK_INT == n and CODENAME != REL.
        // Stable API n has SDK_INT == n and CODENAME == REL.
        final int devApiLevel = Build.VERSION.SDK_INT
                + ("REL".equals(Build.VERSION.CODENAME) ? 0 : 1);
        return devApiLevel > apiLevel;
    }
}
+0 −12
Original line number Diff line number Diff line
@@ -29,18 +29,6 @@ import java.net.SocketAddress;
 * reference classes that have different implementations (which also does not work well with IDEs).
 */
public interface SocketUtilsShim {
    /**
     * Create a new instance of SocketUtilsShim.
     */
    @NonNull
    static SocketUtilsShim newInstance() {
        // TODO: when the R API is finalized, rename the API 29 shim to SocketUtilsCompat, and
        // return it here instead of SocketUtilsShimImpl for devices with Build.VERSION <= 29.
        // For now, the switch between implementations is done at build time (swapping the java file
        // with another), since production modules should not be built with a non-finalized API.
        return new SocketUtilsShimImpl();
    }

    /**
     * @see android.net.util.SocketUtils#makePacketSocketAddress(int, int, byte[])
     */
Loading