1 /*
2  * Copyright (C) 2017 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.settings.vpn2;
18 
19 import android.net.ConnectivityManager;
20 import android.net.ConnectivityManager.NetworkCallback;
21 import android.net.Network;
22 import android.net.NetworkRequest;
23 import android.os.Handler;
24 import android.net.ProxyInfo;
25 
26 /**
27  * This interface replicates a subset of the android.net.ConnectivityManager (CM). The interface
28  * exists so that we can use a thin wrapper around the CM in production code and a mock in tests.
29  * We cannot directly mock or shadow the CM, because some of the methods we rely on are marked as
30  * hidden and are thus invisible to Robolectric.
31  */
32 public interface ConnectivityManagerWrapper {
33 
34     /**
35      * Returns the real ConnectivityManager object wrapped by this wrapper.
36      */
getConnectivityManager()37     public ConnectivityManager getConnectivityManager();
38 
39     /**
40      * Calls {@code ConnectivityManager.getAlwaysOnVpnPackageForUser()}.
41      *
42      * @see android.net.ConnectivityManager#getAlwaysOnVpnPackageForUser
43      */
getAlwaysOnVpnPackageForUser(int userId)44    String getAlwaysOnVpnPackageForUser(int userId);
45 
46     /**
47      * Calls {@code ConnectivityManager.getGlobalProxy()}.
48      *
49      * @see android.net.ConnectivityManager#getGlobalProxy
50      */
getGlobalProxy()51    ProxyInfo getGlobalProxy();
52 
53     /**
54      * Calls {@code ConnectivityManager.registerNetworkCallback()}.
55      *
56      * This is part of the ConnectivityManager public API in SDK 26 or above, but is not yet visible
57      * to the robolectric tests, which currently build with SDK 23.
58      * TODO: delete this once the robolectric tests build with SDK 26 or above.
59      *
60      * @see android.net.ConnectivityManager#registerNetworkCallback(NetworkRequest,NetworkCallback,Handler)
61      */
registerNetworkCallback(NetworkRequest request, NetworkCallback callback, Handler handler)62     public void registerNetworkCallback(NetworkRequest request, NetworkCallback callback,
63             Handler handler);
64 
65     /**
66      * Calls {@code ConnectivityManager.startCaptivePortalApp()}.
67      *
68      * This is part of the ConnectivityManager public API in SDK 26 or above, but is not yet visible
69      * to the robolectric tests, which currently build with SDK 23.
70      * TODO: delete this once the robolectric tests build with SDK 26 or above.
71      *
72      * @see android.net.ConnectivityManager#startCaptivePortalApp(Network)
73      */
startCaptivePortalApp(Network network)74     public void startCaptivePortalApp(Network network);
75 }
76