1 package org.robolectric.shadows; 2 3 import static android.os.Build.VERSION_CODES.P; 4 5 import android.net.wifi.ScanResult; 6 import android.os.Build; 7 import java.util.List; 8 import org.robolectric.shadow.api.Shadow; 9 10 public class ShadowScanResult { 11 /** 12 * @deprecated use ScanResult() instead 13 */ 14 @Deprecated newInstance( String SSID, String BSSID, String caps, int level, int frequency)15 public static ScanResult newInstance( 16 String SSID, String BSSID, String caps, int level, int frequency) { 17 return newInstance(SSID, BSSID, caps, level, frequency, false); 18 } 19 20 /** 21 * @deprecated use ScanResult() instead 22 */ 23 @Deprecated newInstance( String SSID, String BSSID, String caps, int level, int frequency, boolean is80211McRTTResponder)24 public static ScanResult newInstance( 25 String SSID, 26 String BSSID, 27 String caps, 28 int level, 29 int frequency, 30 boolean is80211McRTTResponder) { 31 ScanResult scanResult; 32 if (Build.VERSION.SDK_INT >= 30) { 33 // ScanResult() was introduced as public API in 30 34 scanResult = new ScanResult(); 35 } else { 36 scanResult = Shadow.newInstanceOf(ScanResult.class); 37 } 38 scanResult.SSID = SSID; 39 scanResult.BSSID = BSSID; 40 scanResult.capabilities = caps; 41 scanResult.level = level; 42 scanResult.frequency = frequency; 43 if (Build.VERSION.SDK_INT >= P) { 44 if (is80211McRTTResponder) { 45 scanResult.setFlag(ScanResult.FLAG_80211mc_RESPONDER); 46 } else { 47 scanResult.setFlag(0); 48 } 49 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 50 scanResult.informationElements = new ScanResult.InformationElement[0]; 51 } 52 } 53 return scanResult; 54 } 55 newInstance( String ssid, String bssid, String caps, int level, int frequency, boolean is80211McRttResponder, List<ScanResult.InformationElement> informationElements)56 public static ScanResult newInstance( 57 String ssid, 58 String bssid, 59 String caps, 60 int level, 61 int frequency, 62 boolean is80211McRttResponder, 63 List<ScanResult.InformationElement> informationElements) { 64 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { 65 ScanResult scanResult = new ScanResult(); 66 scanResult.SSID = ssid; 67 scanResult.BSSID = bssid; 68 scanResult.capabilities = caps; 69 scanResult.level = level; 70 scanResult.frequency = frequency; 71 scanResult.informationElements = 72 informationElements.toArray(new ScanResult.InformationElement[0]); 73 if (is80211McRttResponder) { 74 scanResult.setFlag(ScanResult.FLAG_80211mc_RESPONDER); 75 } else { 76 scanResult.setFlag(0); 77 } 78 79 return scanResult; 80 } else { 81 throw new UnsupportedOperationException( 82 "InformationElement not available on API " + Build.VERSION.SDK_INT); 83 } 84 } 85 } 86