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