android.net.wifi.ScanResult Java Examples

The following examples show how to use android.net.wifi.ScanResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From connectivity-samples with Apache License 2.0 6 votes vote down vote up
private List<ScanResult> find80211mcSupportedAccessPoints(
        @NonNull List<ScanResult> originalList) {
    List<ScanResult> newList = new ArrayList<>();

    for (ScanResult scanResult : originalList) {

        if (scanResult.is80211mcResponder()) {
            newList.add(scanResult);
        }

        if (newList.size() >= RangingRequest.getMaxPeers()) {
            break;
        }
    }
    return newList;
}
 
Example #2
Source File: WiFiNetwork.java    From upcKeygen with GNU General Public License v2.0 6 votes vote down vote up
private WiFiNetwork(Parcel in) {
	ssidName = in.readString();
	if (in.readInt() == 1)
		macAddress = in.readString();
	else
		macAddress = "";
	if (in.readInt() == 1)
		encryption = in.readString();
	else
		encryption = OPEN;
	level = in.readInt();
	mode = in.readInt();
	keygens = new ArrayList<>();
	in.readList(keygens, Keygen.class.getClassLoader());
	if (in.readInt() == 1)
		scanResult = in.readParcelable(ScanResult.class.getClassLoader());
	else
		scanResult = null;
}
 
Example #3
Source File: WifiHelper.java    From BaseProject with MIT License 6 votes vote down vote up
/**
 * 扫描WiFi列表
 */
@RequiresPermission(allOf = {Manifest.permission.CHANGE_WIFI_STATE,
                             Manifest.permission.ACCESS_WIFI_STATE})
public List<ScanResult> getScanResults() {
    List<ScanResult> list = null;
    //开始扫描WiFi
    boolean f = mWifiManager.startScan();
    if (!f) {
        getScanResults();
    } else {
        // 得到扫描结果
        list = mWifiManager.getScanResults();
    }

    return list;
}
 
Example #4
Source File: CacheTest.java    From WiFiAnalyzer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAddCompliesToMaxCacheSize() {
    // setup
    int cacheSize = 2;
    when(configuration.isSizeAvailable()).thenReturn(false);
    List<List<ScanResult>> expected = new ArrayList<>();
    // execute
    for (int i = 0; i < cacheSize; i++) {
        List<ScanResult> scanResults = Collections.emptyList();
        expected.add(scanResults);
        fixture.add(scanResults, wifiInfo);
    }
    // validate
    assertEquals(cacheSize, expected.size());
    assertEquals(expected.get(cacheSize - 1), fixture.getFirst());
    assertEquals(expected.get(cacheSize - 2), fixture.getLast());
}
 
Example #5
Source File: AppNetworkMgr.java    From AndroidWallet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 过滤扫描结果
 *
 * @param context
 * @param bssid
 * @return
 */
public static ScanResult getScanResultsByBSSID(Context context, String bssid) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    ScanResult scanResult = null;
    boolean f = wifiManager.startScan();
    if (!f) {
        getScanResultsByBSSID(context, bssid);
    }
    List<ScanResult> list = wifiManager.getScanResults();
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            scanResult = list.get(i);
            if (scanResult.BSSID.equals(bssid)) {
                break;
            }
        }
    }
    return scanResult;
}
 
Example #6
Source File: WifiManagerModule.java    From react-native-wifi-manager with MIT License 6 votes vote down vote up
@ReactMethod
public void list(Callback successCallback, Callback errorCallback) {
  try {
    WifiManager mWifiManager = (WifiManager) getReactApplicationContext().getSystemService(Context.WIFI_SERVICE);
    List < ScanResult > results = mWifiManager.getScanResults();
    WritableArray wifiArray =  Arguments.createArray();
    for (ScanResult result: results) {
      if(!result.SSID.equals("")){
        wifiArray.pushString(result.SSID);
      }
    }
    successCallback.invoke(wifiArray);
  } catch (IllegalViewOperationException e) {
    errorCallback.invoke(e.getMessage());
  }
}
 
Example #7
Source File: WifiVo.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 扫描 Wifi 信息
 * @param listWifiVos     数据源
 * @param listScanResults 扫描返回的数据
 * @return {@code true} success, {@code false} fail
 */
public static boolean scanWifiVos(final List<WifiVo> listWifiVos, final List<ScanResult> listScanResults) {
    if (listWifiVos == null || listScanResults == null) return false;
    // 清空旧数据
    listWifiVos.clear();
    // 遍历 Wifi 列表数据
    for (int i = 0, len = listScanResults.size(); i < len; i++) {
        // 如果出现异常、或者失败, 则无视当前的索引 Wifi 信息
        try {
            // 获取当前索引的 Wifi 信息
            ScanResult scanResult = listScanResults.get(i);
            // 防止 Wifi 名长度为 0
            if (scanResult.SSID.length() == 0) {
                continue;
            }
            // 保存 Wifi 信息
            listWifiVos.add(createWifiVo(scanResult));
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "scanWifiVos");
        }
    }
    return true;
}
 
Example #8
Source File: WifiInfo.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
private static void scanSuccess(WifiManager wifiManager, WifiBean wifiBean, long startTime, WifiScanListener wifiScanListener) {
    List<ScanResult> results = wifiManager.getScanResults();
    wifiBean.setWifiScanStatus(results.size() != 0);
    JSONArray scanArray = new JSONArray();
    for (ScanResult scanResult : results) {
        WifiBean.WifiResultBean wifiResultBean = new WifiBean.WifiResultBean();
        wifiResultBean.setBSSID(scanResult.BSSID);
        wifiResultBean.setSSID(scanResult.SSID);
        wifiResultBean.setCapabilities(scanResult.capabilities);
        wifiResultBean.setLevel(scanResult.level);
        scanArray.put(wifiResultBean.toJSONObject());
    }
    wifiBean.setWifiScanResult(scanArray);
    wifiBean.setTime(System.currentTimeMillis() - startTime);
    wifiScanListener.onResult(wifiBean.toJSONObject());

}
 
Example #9
Source File: WifiWrapper.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("UseValueOf")
public void onReceive(Context c, Intent intent) {
  
	  List<ScanResult> wifiScanList = mainWifiObj.getScanResults();
	  Log.d("wifi-scanning", "received " + wifiScanList.size());
   StreamElement streamElement = null;
   
   if (wifiScanList.size() == 0){
 	  
 	  streamElement = new StreamElement(w.getFieldList(), w.getFieldType(),
			new Serializable[] { 0.0, mainWifiObj.isWifiEnabled()?1.0:0.0 , 0.0 });
       ((WifiWrapper) w).postStreamElement(streamElement);
   }
   
   for(int i = 0; i < wifiScanList.size(); i++){
      	streamElement = new StreamElement(w.getFieldList(), w.getFieldType(),
		new Serializable[] { converTingBSSID(wifiScanList.get(i).BSSID.substring(0, 8)), converTingBSSID(wifiScanList.get(i).BSSID.substring(8)), wifiScanList.get(i).level });
      ((WifiWrapper) w).postStreamElement(streamElement);
      storage.updateWifiFrequency(wifiScanList.get(i).BSSID);
   }
  // unregisterReceiver(wifiReciever);
  // registerReceiver(wifiReciever, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
   scanning = false;
}
 
Example #10
Source File: WifiHelper.java    From AndroidBasicProject with MIT License 6 votes vote down vote up
/**
 * 连接加密wifi
 * @param scanResult
 * @param password
 * @return
 */
@RequiresPermission(Manifest.permission.CHANGE_WIFI_STATE)
public boolean connection(ScanResult scanResult, String password) {
    WifiConfiguration wifiConfiguration = new WifiConfiguration();
    wifiConfiguration.SSID = "\"" + scanResult.SSID + "\"";
    wifiConfiguration.preSharedKey = "\"" + password + "\"";
    wifiConfiguration.hiddenSSID = true;
    wifiConfiguration.status = WifiConfiguration.Status.ENABLED;
    wifiConfiguration.allowedAuthAlgorithms.set(
            WifiConfiguration.AuthAlgorithm.OPEN);
    wifiConfiguration.allowedGroupCiphers.set(
            WifiConfiguration.GroupCipher.TKIP);
    wifiConfiguration.allowedGroupCiphers.set(
            WifiConfiguration.GroupCipher.CCMP);
    wifiConfiguration.allowedKeyManagement.set(
            getEncryptionType(scanResult));
    wifiConfiguration.allowedPairwiseCiphers.set(
            WifiConfiguration.PairwiseCipher.TKIP);
    wifiConfiguration.allowedPairwiseCiphers.set(
            WifiConfiguration.PairwiseCipher.CCMP);
    wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
    return connection(wifiConfiguration);
}
 
Example #11
Source File: GosMessageHandler.java    From Gizwits-SmartBuld_Android with MIT License 6 votes vote down vote up
public void run() {
	if (mcContext == null) {
		return;
	}
	newDeviceList.clear();
	List<ScanResult> currentWifiScanResult = NetUtils.getCurrentWifiScanResult(mcContext);
	int flog = 0;
	for (ScanResult scanResult : currentWifiScanResult) {
		String ssid = scanResult.SSID;
		// 获取系统的NotificationManager服务
		nm = (NotificationManager) mcContext.getSystemService(Context.NOTIFICATION_SERVICE);
		if (ssid.contains(GosBaseActivity.SoftAP_Start) && ssid.length() > GosBaseActivity.SoftAP_Start.length()
				&& !newDeviceList.toString().contains(ssid)) {
			newDeviceList.add(ssid);
			flog++;
			send(ssid, flog);
		}
	}
	if (mainHandler != null && newDeviceList.size() > 0) {
		mainHandler.sendEmptyMessage(SHOWDIALOG);
	}

	looper.postDelayed(mRunnable, 2000);
}
 
Example #12
Source File: WifiHelper.java    From BaseProject with MIT License 6 votes vote down vote up
/**
 * 连接加密wifi
 */
@RequiresPermission(Manifest.permission.CHANGE_WIFI_STATE) public boolean connection(
        @NonNull ScanResult scanResult, @NonNull String password) {
    WifiConfiguration wifiConfiguration = new WifiConfiguration();
    wifiConfiguration.SSID = "\"" + scanResult.SSID + "\"";
    wifiConfiguration.preSharedKey = "\"" + password + "\"";
    wifiConfiguration.hiddenSSID = true;
    wifiConfiguration.status = WifiConfiguration.Status.ENABLED;
    wifiConfiguration.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
    wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
    wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
    wifiConfiguration.allowedKeyManagement.set(getEncryptionType(scanResult));
    wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
    wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
    wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
    return connection(wifiConfiguration);
}
 
Example #13
Source File: GosChooseDeviceActivity.java    From Gizwits-SmartBuld_Android with MIT License 6 votes vote down vote up
private void initData() {
	list = new ArrayList<ScanResult>();
	list = (ArrayList<ScanResult>) NetUtils.getCurrentWifiScanResult(GosChooseDeviceActivity.this);
	softList = new ArrayList<ScanResult>();
	ScanResult scanResult;
	for (int i = 0; i < list.size(); i++) {
		scanResult = list.get(i);
		if (scanResult.SSID.length() > SoftAP_Start.length()) {
			if (scanResult.SSID.contains(SoftAP_Start)) {
				softList.add(scanResult);
			}
		}
	}
	myadapter = new Myadapter(softList);
	listView.setAdapter(myadapter);

}
 
Example #14
Source File: ConnectorUtils.java    From WifiUtils with Apache License 2.0 6 votes vote down vote up
public static boolean reEnableNetworkIfPossible(@Nullable final WifiManager wifiManager, @Nullable final ScanResult scanResult) {
    if (wifiManager == null) {
        return false;
    }
    @Nullable
    final List<WifiConfiguration> configurations = wifiManager.getConfiguredNetworks();
    if (configurations == null || scanResult == null || configurations.isEmpty()) {
        return false;
    }
    boolean result = false;
    for (WifiConfiguration wifiConfig : configurations)
        if (Objects.equals(scanResult.BSSID, wifiConfig.BSSID) && Objects.equals(scanResult.SSID, trimQuotes(wifiConfig.SSID))) {
            result = wifiManager.enableNetwork(wifiConfig.networkId, true);
            break;
        }
    wifiLog("reEnableNetworkIfPossible " + result);
    return result;
}
 
Example #15
Source File: ConnectorUtils.java    From WifiUtils with Apache License 2.0 6 votes vote down vote up
@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
static boolean cleanPreviousConfiguration(@Nullable final WifiManager wifiManager, @NonNull final ScanResult scanResult) {
    if (wifiManager == null) {
        return false;
    }
    //On Android 6.0 (API level 23) and above if my app did not create the configuration in the first place, it can not remove it either.
    final WifiConfiguration config = ConfigSecurities.getWifiConfiguration(wifiManager, scanResult);
    wifiLog("Attempting to remove previous network config...");
    if (config == null) {
        return true;
    }

    if (wifiManager.removeNetwork(config.networkId)) {
        wifiManager.saveConfiguration();
        return true;
    }
    return false;
}
 
Example #16
Source File: MainActivity.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onScanResultItemClick(ScanResult scanResult) {
    Log.d(TAG, "onScanResultItemClick(): ssid: " + scanResult.SSID);

    Intent intent = new Intent(this, AccessPointRangingResultsActivity.class);
    intent.putExtra(SCAN_RESULT_EXTRA, scanResult);
    startActivity(intent);
}
 
Example #17
Source File: AndroidWifiModule.java    From react-native-android-wifi with ISC License 5 votes vote down vote up
@ReactMethod
public void findAndConnect(String ssid, String password, Callback ssidFound) {
	List < ScanResult > results = wifi.getScanResults();
	boolean connected = false;
	for (ScanResult result: results) {
		String resultString = "" + result.SSID;
		if (ssid.equals(resultString)) {
			connected = connectTo(result, password, ssid);
		}
	}
	ssidFound.invoke(connected);
}
 
Example #18
Source File: g.java    From letv with Apache License 2.0 5 votes vote down vote up
private void a(List<ScanResult> list) {
    if (list != null) {
        if (this.c) {
            if (this.b == null) {
                this.b = new ArrayList();
            }
            int size = this.b.size();
            for (ScanResult scanResult : list) {
                for (int i = 0; i < size; i++) {
                    if (((ScanResult) this.b.get(i)).BSSID.equals(scanResult.BSSID)) {
                        this.b.remove(i);
                        break;
                    }
                }
                this.b.add(scanResult);
            }
            return;
        }
        if (this.b == null) {
            this.b = new ArrayList();
        } else {
            this.b.clear();
        }
        for (ScanResult scanResult2 : list) {
            this.b.add(scanResult2);
        }
    }
}
 
Example #19
Source File: PreferencesStorage.java    From privacypolice with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds all BSSIDs that are currently in range for the specified SSID (prevents nagging)
 * We are assuming the user does not know the BSSID of the AP it wants to trust, anyway, and
 * choose the more useable option.
 * @param SSID the SSID of the network that needs to be allowed at this location
 */
public void addAllowedBSSIDsForLocation(String SSID) {
    List<ScanResult> scanResults = wifiManager.getScanResults();
    for (ScanResult result : scanResults) {
        if (SSID.equals(result.SSID))
            addAllowedBSSID(SSID, result.BSSID);
    }
}
 
Example #20
Source File: GosChooseDeviceWorkWiFiActivity.java    From GOpenSource_AppKit_Android_AS with MIT License 5 votes vote down vote up
@Override
public void onSucceed(int requestCode, List<String> grantPermissions) {
	super.onSucceed(requestCode, grantPermissions);
	AlertDialog.Builder dia = new AlertDialog.Builder(GosChooseDeviceWorkWiFiActivity.this);
	View view = View.inflate(GosChooseDeviceWorkWiFiActivity.this, R.layout.alert_gos_wifi_list, null);
	ListView listview = (ListView) view.findViewById(R.id.wifi_list);
	List<ScanResult> rsList = NetUtils.getCurrentWifiScanResult(this);
	List<String> localList = new ArrayList<String>();
	localList.clear();
	wifiList = new ArrayList<ScanResult>();
	wifiList.clear();
	for (ScanResult sss : rsList) {

		if (sss.SSID.contains(GosConstant.SoftAP_Start)) {
		} else {
			if (localList.toString().contains(sss.SSID)) {
			} else {
				localList.add(sss.SSID);
				wifiList.add(sss);
			}
		}
	}
	WifiListAdapter adapter = new WifiListAdapter(wifiList);
	listview.setAdapter(adapter);
	listview.setOnItemClickListener(this);
	dia.setView(view);
	create = dia.create();
	create.show();

}
 
Example #21
Source File: WiFi.java    From WifiConnecter with Apache License 2.0 5 votes vote down vote up
public static WifiConfiguration getWifiConfiguration(final WifiManager wifiMgr,
                                                        final ScanResult hotsopt, String hotspotSecurity) {
	final String ssid = StringUtils.convertToQuotedString(hotsopt.SSID);
	if(ssid.length() == 0) {
		return null;
	}
	
	final String bssid = hotsopt.BSSID;
	if(bssid == null) {
		return null;
	}
	
	if(hotspotSecurity == null) {
		hotspotSecurity = getScanResultSecurity(hotsopt);
	}
	
	final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();

	for(final WifiConfiguration config : configurations) {
		if(config.SSID == null || !ssid.equals(config.SSID)) {
			continue;
		}
		if(config.BSSID == null || bssid.equals(config.BSSID)) {
			final String configSecurity = getWifiConfigurationSecurity(config);
			if(hotspotSecurity.equals(configSecurity)) {
				return config;
			}
		}
	}
	return null;
}
 
Example #22
Source File: NetworkScoreService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public List<ScanResult> get() {
    WifiScanner wifiScanner = mContext.getSystemService(WifiScanner.class);
    if (wifiScanner != null) {
        return wifiScanner.getSingleScanResults();
    }
    Log.w(TAG, "WifiScanner is null, failed to return scan results.");
    return Collections.emptyList();
}
 
Example #23
Source File: BluetoothDeviceFilterUtils.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
static boolean matchesName(@Nullable Pattern namePattern, ScanResult device) {
    boolean result;
    if (namePattern == null)  {
        result = true;
    } else if (device == null) {
        result = false;
    } else {
        final String name = device.SSID;
        result = name != null && namePattern.matcher(name).find();
    }
    if (DEBUG) debugLogMatchResult(result, device, namePattern);
    return result;
}
 
Example #24
Source File: WiFi.java    From WifiConnecter with Apache License 2.0 5 votes vote down vote up
/**
 * Configure a network, and connect to it.
 * @param wifiMgr
 * @param scanResult
 * @param password Password for secure network or is ignored.
 * @return
 */
public static boolean connectToNewNetwork(final WifiManager wifiMgr, final ScanResult scanResult, final String password) {
       //1.获取wifi加密方式(WEP, WPA, WPA2, WPA_EAP, IEEE8021X)
	final String security = getScanResultSecurity(scanResult);
	
	if(security.equals(OPEN)) {
		final int numOpenNetworksKept = 10;
		checkForExcessOpenNetworkAndSave(wifiMgr, numOpenNetworksKept);
	}
	
	WifiConfiguration config = new WifiConfiguration();
	config.SSID = StringUtils.convertToQuotedString(scanResult.SSID);
	config.BSSID = scanResult.BSSID;
	setupSecurity(config, security, password);
	
	int id = wifiMgr.addNetwork(config);
	if(id == -1) {
		return false;
	}
	
	if(!wifiMgr.saveConfiguration()) {
		return false;
	}
	
	config = getWifiConfiguration(wifiMgr, config, security);
	if(config == null) {
		return false;
	}
	
	return connectToConfiguredNetwork(wifiMgr, config, true);
}
 
Example #25
Source File: Cache.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
void add(@NonNull List<ScanResult> scanResults, WifiInfo wifiInfo) {
    int cacheSize = getCacheSize();
    while (cachedScanResults.size() >= cacheSize) {
        cachedScanResults.pollLast();
    }
    cachedScanResults.addFirst(scanResults);
    cachedWifiInfo = wifiInfo;
}
 
Example #26
Source File: ScanResultsChecker.java    From privacypolice with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks whether we should allow connection to a given SSID, based on the user's preferences
 * It will also ask the user if it is unknown whether the network should be trusted.
 * @param SSID The SSID of the network that should be checked
 * @param scanResults The networks that are currently available
 * @return TRUSTED or UNTRUSTED, based on the user's preferences, or UNKNOWN if the user didn't
 *          specify anything yet
 */
public AccessPointSafety getNetworkSafety(String SSID, List<ScanResult> scanResults) {
    for (ScanResult scanResult : scanResults) {
        if (scanResult.SSID.equals(SSID)) {
            // Check whether the user wants to filter by MAC address
            if (!prefs.getOnlyConnectToKnownAccessPoints()) { // Any MAC address is fair game
                // Enabling now makes sure that we only want to connect when it is in range
                return AccessPointSafety.TRUSTED;
            } else { // Check access point's MAC address
                // Check if the MAC address is in the list of allowed MAC's for this SSID
                Set<String> allowedBSSIDs = prefs.getAllowedBSSIDs(scanResult.SSID);
                if (allowedBSSIDs.contains(scanResult.BSSID)) {
                    return AccessPointSafety.TRUSTED;
                } else {
                    // Not an allowed BSSID
                    if (prefs.getBlockedBSSIDs(scanResult.SSID).contains(scanResult.BSSID)) {
                        // This SSID was explicitly blocked by the user!
                        Log.w("PrivacyPolice", "Spoofed network for " + scanResult.SSID + " detected! (BSSID is " + scanResult.BSSID + ")");
                        return AccessPointSafety.UNTRUSTED;
                    } else {
                        // We don't know yet whether the user wants to allow this network
                        // Ask the user what needs to be done
                        notificationHandler.askNetworkPermission(scanResult.SSID, scanResult.BSSID);
                        return AccessPointSafety.UNKNOWN;
                    }
                }
            }
        }
    }
    return AccessPointSafety.UNTRUSTED; // Network not in range
}
 
Example #27
Source File: WifiNetworkAdapter.java    From android-rttmanager-sample with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    if (position >= wifiNetworks.size()) {
        return;
    }
    final ScanResult result = wifiNetworks.get(position);
    holder.txtSsid.setText(result.SSID);
    holder.txtMcResponder.setText(String.valueOf(result.is80211mcResponder()));
    bind(holder.wifi_network_item, result, clickListener);
}
 
Example #28
Source File: Transformer.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
WiFiWidth getWiFiWidth(@NonNull ScanResult scanResult) {
    try {
        return EnumUtils.find(WiFiWidth.class, getFieldValue(scanResult, Fields.channelWidth), WiFiWidth.MHZ_20);
    } catch (Exception e) {
        return WiFiWidth.MHZ_20;
    }
}
 
Example #29
Source File: CacheTest.java    From WiFiAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAdd() {
    // setup
    when(configuration.isSizeAvailable()).thenReturn(false);
    List<ScanResult> scanResults = Collections.emptyList();
    // execute
    fixture.add(scanResults, wifiInfo);
    // validate
    assertEquals(scanResults, fixture.getFirst());
    assertEquals(wifiInfo, fixture.getWifiInfo());
}
 
Example #30
Source File: WifiHooker.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
public Object onInvoke(Object originService, Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
    if (!GpsMockManager.getInstance().isMocking()) {
        return method.invoke(originService, args);
    }
    return new ArrayList<ScanResult>();
}