• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 
17 package com.android.networkstack.apishim.common;
18 
19 import android.net.NetworkRequest;
20 import android.util.Range;
21 
22 import androidx.annotation.NonNull;
23 import androidx.annotation.Nullable;
24 
25 import java.util.Set;
26 
27 /**
28  * Interface used to access API methods in {@link android.net.NetworkRequest}, with
29  * appropriate fallbacks if the methods are not yet part of the released API.
30  */
31 public interface NetworkRequestShim {
32     /**
33      * See android.net.NetworkRequest.Builder#setUids.
34      * Set the {@code uids} into {@code builder}.
35      */
setUids(@onNull NetworkRequest.Builder builder, @Nullable Set<Range<Integer>> uids)36     void setUids(@NonNull NetworkRequest.Builder builder,
37             @Nullable Set<Range<Integer>> uids) throws UnsupportedApiLevelException;
38 
39     /**
40      * See android.net.NetworkRequest.Builder#setIncludeOtherUidNetworks.
41      */
setIncludeOtherUidNetworks(NetworkRequest.Builder builder, boolean include)42     default NetworkRequest.Builder setIncludeOtherUidNetworks(NetworkRequest.Builder builder,
43             boolean include) throws UnsupportedApiLevelException {
44         throw new UnsupportedApiLevelException("Not supported before API 31.");
45     }
46 
47     /**
48      * See android.net.NetworkRequest.Builder(NetworkRequest).
49      * @throws UnsupportedApiLevelException if API is not available in the API level.
50      */
newBuilder(@onNull NetworkRequest request)51     default NetworkRequest.Builder newBuilder(@NonNull NetworkRequest request)
52             throws UnsupportedApiLevelException {
53         // Not supported before API 31.
54         throw new UnsupportedApiLevelException("Not supported before API 31.");
55     }
56 }
57