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

Commit af1e95a1 authored by Chiachang Wang's avatar Chiachang Wang
Browse files

Support NetworkRequest.Builder with an existing request in shim

New constructor in NetworkRequest.Builder that takes an existing
network request is exposed for supporting the usage outside the
module. This API should be tested. Add the new method into shims
to allow building and testing against older sdk version without
this new API.

Bug: 172183305
Test: make NetworkStackApiStableLib NetworkStackApiCurrentLib
Change-Id: I61227e5dc7d48b1ff71d52b5ec9d9644fe33ffab
parent f47788f7
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.util.Range;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.android.networkstack.apishim.common.NetworkRequestShim;
import com.android.networkstack.apishim.common.ShimUtils;
@@ -53,4 +54,10 @@ public class NetworkRequestShimImpl
            @Nullable Set<Range<Integer>> uids) {
        builder.setUids(uids);
    }

    @RequiresApi(Build.VERSION_CODES.S)
    @Override
    public NetworkRequest.Builder newBuilder(@NonNull NetworkRequest request) {
        return new NetworkRequest.Builder(request);
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -35,4 +35,14 @@ public interface NetworkRequestShim {
     */
    void setUids(@NonNull NetworkRequest.Builder builder,
            @Nullable Set<Range<Integer>> uids) throws UnsupportedApiLevelException;

    /**
     * See android.net.NetworkRequest.Builder(NetworkRequest).
     * @throws UnsupportedApiLevelException if API is not available in the API level.
     */
    default NetworkRequest.Builder newBuilder(@NonNull NetworkRequest request)
            throws UnsupportedApiLevelException {
        // Not supported before API 31.
        throw new UnsupportedApiLevelException("Not supported before API 31.");
    }
}