• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.testutils.shadow;
18 
19 import static org.robolectric.RuntimeEnvironment.application;
20 
21 import android.net.wifi.WifiConfiguration;
22 import android.net.wifi.WifiManager;
23 import android.net.wifi.hotspot2.PasspointConfiguration;
24 
25 import org.robolectric.annotation.HiddenApi;
26 import org.robolectric.annotation.Implementation;
27 import org.robolectric.annotation.Implements;
28 import org.robolectric.shadow.api.Shadow;
29 
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.List;
33 
34 @Implements(value = WifiManager.class)
35 public class ShadowWifiManager extends org.robolectric.shadows.ShadowWifiManager {
36 
37     private List<PasspointConfiguration> mPasspointConfiguration;
38 
39     public WifiConfiguration savedWifiConfig;
40     private WifiConfiguration mSavedApConfig;
41 
42     @Implementation
getWifiApConfiguration()43     protected WifiConfiguration getWifiApConfiguration() {
44         return mSavedApConfig;
45     }
46 
47     @Implementation
setWifiApConfiguration(WifiConfiguration wifiConfig)48     protected boolean setWifiApConfiguration(WifiConfiguration wifiConfig) {
49         mSavedApConfig = wifiConfig;
50         return true;
51     }
52 
53     @HiddenApi // @SystemApi
54     @Implementation
connect(WifiConfiguration config, WifiManager.ActionListener listener)55     protected void connect(WifiConfiguration config, WifiManager.ActionListener listener) {
56         savedWifiConfig = config;
57     }
58 
59     @HiddenApi
60     @Implementation
save(WifiConfiguration config, WifiManager.ActionListener listener)61     protected void save(WifiConfiguration config, WifiManager.ActionListener listener) {
62         savedWifiConfig = config;
63     }
64 
65     @Implementation
getPasspointConfigurations()66     protected List<PasspointConfiguration> getPasspointConfigurations() {
67         return mPasspointConfiguration == null ? Collections.emptyList() : mPasspointConfiguration;
68     }
69 
70     @Implementation
addOrUpdatePasspointConfiguration(PasspointConfiguration config)71     protected void addOrUpdatePasspointConfiguration(PasspointConfiguration config) {
72         if (mPasspointConfiguration == null) {
73             mPasspointConfiguration = new ArrayList<>();
74         }
75         mPasspointConfiguration.add(config);
76     }
77 
78     @Implementation
isDualModeSupported()79     protected boolean isDualModeSupported() {
80         return false;
81     }
82 
get()83     public static ShadowWifiManager get() {
84         return Shadow.extract(application.getSystemService(WifiManager.class));
85     }
86 }
87