• 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.ConnectivityManager.NetworkCallback;
20 import android.net.NetworkRequest;
21 import android.os.Handler;
22 import android.util.Range;
23 
24 import androidx.annotation.NonNull;
25 
26 import java.util.Collection;
27 
28 /**
29  * Interface used to access API methods in {@link android.net.ConnectivityManager}, with
30  * appropriate fallbacks if the methods are not yet part of the released API.
31  *
32  * <p>This interface makes it easier for callers to use ConnectivityManagerShimImpl, as it's more
33  * obvious what methods must be implemented on each API level, and it abstracts from callers the
34  * need to reference classes that have different implementations (which also does not work well
35  * with IDEs).
36  */
37 public interface ConnectivityManagerShim {
38     /** See android.net.ConnectivityManager#requestBackgroundNetwork */
requestBackgroundNetwork(@onNull NetworkRequest request, @NonNull NetworkCallback networkCallback, @NonNull Handler handler)39     void requestBackgroundNetwork(@NonNull NetworkRequest request,
40             @NonNull NetworkCallback networkCallback, @NonNull Handler handler)
41             throws UnsupportedApiLevelException;
42 
43     /** See android.net.ConnectivityManager#registerSystemDefaultNetworkCallback */
registerSystemDefaultNetworkCallback( @onNull NetworkCallback networkCallback, @NonNull Handler handler)44     void registerSystemDefaultNetworkCallback(
45             @NonNull NetworkCallback networkCallback, @NonNull Handler handler);
46 
47     /** See android.net.ConnectivityManager#registerDefaultNetworkCallbackForUid */
registerDefaultNetworkCallbackForUid( int uid, @NonNull NetworkCallback networkCallback, @NonNull Handler handler)48     default void registerDefaultNetworkCallbackForUid(
49             int uid, @NonNull NetworkCallback networkCallback, @NonNull Handler handler)
50             throws UnsupportedApiLevelException {
51         throw new UnsupportedApiLevelException("Only supported starting from API 31");
52     }
53 
54     /** See android.net.ConnectivityManager#setLegacyLockdownVpnEnabled */
setLegacyLockdownVpnEnabled(boolean enabled)55     default void setLegacyLockdownVpnEnabled(boolean enabled) throws UnsupportedApiLevelException {
56         throw new UnsupportedApiLevelException("Only supported starting from API 31");
57     }
58 
59     /** See android.net.ConnectivityManager#setRequireVpnForUids */
setRequireVpnForUids(boolean requireVpn, Collection<Range<Integer>> ranges)60     default void setRequireVpnForUids(boolean requireVpn, Collection<Range<Integer>> ranges)
61             throws UnsupportedApiLevelException {
62         throw new UnsupportedApiLevelException("Only supported starting from API 31");
63     }
64 }
65