Esempio n. 1
0
  private void refresh() {
    WifiInfo info = getNetwork(getContext());

    if (info == null) {
      _views.setSsid(getContext().getString(R.string.wifi_is_disabled));
      _views.setSignal(EMPTYSTRING);
      _views.setLinkspeed(EMPTYSTRING);
      _views.setStatus(EMPTYSTRING);
      _views.setIcon(R.drawable.icon);
    } else if (info.getRssi() == -200) {
      _views.setSsid(EMPTYSTRING);
      _views.setSignal(EMPTYSTRING);
      _views.setLinkspeed(EMPTYSTRING);
      _views.setIcon(R.drawable.icon);
    } else {
      _views.setSsid(StringUtil.removeQuotes(info.getSSID()));
      _views.setSignal(String.valueOf(info.getRssi()) + DBM);
      _views.setLinkspeed(String.valueOf(info.getLinkSpeed()) + MB);
      _views.setStatus(info.getSupplicantState().name());
      _views.setIcon(
          NotifUtil.getIconfromSignal(
              WifiManager.calculateSignalLevel(info.getRssi(), 5), NotifUtil.ICON_SET_LARGE));
    }

    drawhandler.sendEmptyMessageDelayed(REFRESH, REFRESH_DELAY);
  }
Esempio n. 2
0
  public BaseContent(
      final Floating floating, final WifiManager wifiManager, final ScanResult scanResult) {
    super();
    mWifiManager = wifiManager;
    mFloating = floating;
    mScanResult = scanResult;
    mScanResultSecurity = Wifi.ConfigSec.getScanResultSecurity(mScanResult);
    mIsOpenNetwork = Wifi.ConfigSec.isOpenNetwork(mScanResultSecurity);

    mView = View.inflate(mFloating, R.layout.base_content, null);
    ((TextView) mView.findViewById(R.id.SignalStrength_TextView))
        .setText(
            SIGNAL_LEVEL[WifiManager.calculateSignalLevel(mScanResult.level, SIGNAL_LEVEL.length)]);
    final String rawSecurity = Wifi.ConfigSec.getDisplaySecirityString(mScanResult);
    final String readableSecurity =
        Wifi.ConfigSec.isOpenNetwork(rawSecurity)
            ? mFloating.getString(R.string.wifi_security_open)
            : rawSecurity;
    ((TextView) mView.findViewById(R.id.Security_TextView)).setText(readableSecurity);
    ((CheckBox) mView.findViewById(R.id.ShowPassword_CheckBox)).setOnCheckedChangeListener(this);

    mNumOpenNetworksKept =
        Settings.Secure.getInt(
            floating.getContentResolver(), Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, 10);
  }
  private void scanResults(LinkedList<ScanResult> results) {
    @SuppressLint("UseSparseArrays")
    HashMap<Integer, Integer> frequencyCount = new HashMap<>();

    for (ScanResult result : results) {
      WifiManager.calculateSignalLevel(result.level, 100);

      if (frequencyCount.get(result.frequency) == 0) {
        int count = frequencyCount.get(result.frequency);
        frequencyCount.put(result.frequency, ++count);
      } else {
        frequencyCount.put(result.frequency, 1);
      }

      RobotLog.d("Network on: " + wifiChannelMap.get(result.frequency));
    }
    RobotLog.d("Done displaying networks!");

    LinkedList<Map.Entry<Integer, Integer>> frequencies =
        new LinkedList<>(frequencyCount.entrySet());
    Collections.sort(
        frequencies,
        new Comparator<Map.Entry<Integer, Integer>>() {
          @Override
          public int compare(Map.Entry<Integer, Integer> lhs, Map.Entry<Integer, Integer> rhs) {
            if (lhs.equals(rhs)) {
              return 0;
            }

            if (lhs.getValue() > rhs.getValue()) {
              return 1;
            } else if (lhs.getValue() < rhs.getValue()) {
              return -1;
            } else {
              return 0;
            }
          }
        });

    if (frequencies.size() > 0) {
      int location = frequencies.size() - 1;
      mostCommon =
          wifiChannelMap.containsKey(frequencies.get(location).getKey())
              ? wifiChannelMap.get(frequencies.get(location).getKey())
              : "5 GHz";
    }

    if (frequencies.size() > 1) {
      int location = frequencies.size() - 2;
      secondMostCommon =
          wifiChannelMap.containsKey(frequencies.get(location).getKey())
              ? wifiChannelMap.get(frequencies.get(location).getKey())
              : "5 GHz";
    }

    recChannel = recommendedChannel();
  }
 public void bind(ScanResult scanResult) {
   ssid.setText(scanResult.SSID);
   bssid.setText(scanResult.BSSID);
   freq.setText(
       String.format(
           "%dMHz / CH: %d",
           scanResult.frequency, convertFrequencyToChannel(scanResult.frequency)));
   level.setText(
       String.format(
           "%ddB / Level: %d",
           scanResult.level, WifiManager.calculateSignalLevel(scanResult.level, 10)));
   manuf.setText(
       VendorDbAdapter.getVendor(
           Integer.parseInt(scanResult.BSSID.substring(0, 8).replace(":", ""), 16)));
 }
Esempio n. 5
0
 public int getBars() {
   return WifiManager.calculateSignalLevel(level, 5);
 }
  private void refreshWifiInfo() {
    WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
    DhcpInfo dhcpInfo = mWifiManager.getDhcpInfo();

    Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
    String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
    wifiMacAddressPref.setSummary(
        !TextUtils.isEmpty(macAddress)
            ? macAddress
            : getActivity().getString(R.string.status_unavailable));

    Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);
    String ipAddress = Utils.getWifiIpAddresses(getActivity());
    wifiIpAddressPref.setSummary(
        ipAddress == null ? getActivity().getString(R.string.status_unavailable) : ipAddress);
    Preference wifiGateWayPref = findPreference(KEY_GATEWAY_ADDRESS);
    String netGateWayAddress = dhcpInfo.getGateWayValue();
    wifiGateWayPref.setSummary(
        netGateWayAddress == null
            ? getActivity().getString(R.string.status_unavailable)
            : netGateWayAddress);

    Preference wifiNetMaskPref = findPreference(KEY_NETMASK_ADDRESS);
    String netMaskAddress = dhcpInfo.getNetMaskValue();
    wifiNetMaskPref.setSummary(
        netMaskAddress == null
            ? getActivity().getString(R.string.status_unavailable)
            : netMaskAddress);

    Preference wifiDNS1Pref = findPreference(KEY_DNS1_ADDRESS);
    String netDNS1Address = dhcpInfo.getDNS1Value();
    wifiDNS1Pref.setSummary(
        netDNS1Address == null
            ? getActivity().getString(R.string.status_unavailable)
            : netDNS1Address);

    Preference wifiDNS2Pref = findPreference(KEY_DNS2_ADDRESS);
    String netDNS2Address = dhcpInfo.getDNS2Value();
    wifiDNS2Pref.setSummary(
        netDNS2Address == null
            ? getActivity().getString(R.string.status_unavailable)
            : netDNS2Address);

    Preference wifiRssiPref = findPreference(KEY_RSSI);
    // String netRssi = wifiInfo.getRssi()+"";
    String netRssi = mWifiManager.calculateSignalLevel(wifiInfo.getRssi(), 4) + "";
    wifiRssiPref.setSummary(
        netRssi == null ? getActivity().getString(R.string.status_unavailable) : netRssi);

    Preference wifiChNumPref = findPreference(KEY_CHANNELNUM);
    String chNum = wifiInfo.getChannelNumber(wifiInfo.getFrequency()) + "";
    wifiChNumPref.setSummary(
        chNum == null ? getActivity().getString(R.string.status_unavailable) : chNum);

    Preference wifiChFreqPref = findPreference(KEY_CHANNELFREQ);
    String chFreq = wifiInfo.getFrequency() + "";
    wifiChFreqPref.setSummary(
        chFreq == null ? getActivity().getString(R.string.status_unavailable) : chFreq);

    /*Preference wifiBssidPref = findPreference(KEY_BSSID);
          String bssid = wifiInfo.getBSSID();
          wifiBssidPref.setSummary(bssid == null ?
                  getActivity().getString(R.string.status_unavailable) : bssid);
    Preference wifiSsidPref = findPreference(KEY_SSID);
          String ssid = wifiInfo.getSSID();
          wifiSsidPref.setSummary(ssid == null ?
                  getActivity().getString(R.string.status_unavailable) : ssid);
    Preference wifiNetIdPref = findPreference(KEY_NETWORKID);
          String netId = wifiInfo.getNetworkId()+"";
          wifiNetIdPref.setSummary(netId == null ?
                  getActivity().getString(R.string.status_unavailable) : netId);

    Preference wifiPairwisePref = findPreference(KEY_PAIRWISE_CIPHER);
          String pairwise = wifiInfo.getPairwiseCipher();
          wifiPairwisePref.setSummary(pairwise == null ?
                  getActivity().getString(R.string.status_unavailable) : pairwise);
    Preference wifiGroupPref = findPreference(KEY_GROUP_CIPHER);
          String group = wifiInfo.getGroupCipher();
          wifiGroupPref.setSummary(group == null ?
                  getActivity().getString(R.string.status_unavailable) : group);
    Preference wifiMgmtPref = findPreference(KEY_KEY_MGMT);
          String mgmt = wifiInfo.getKeyMgmt();
          wifiMgmtPref.setSummary(mgmt == null ?
                  getActivity().getString(R.string.status_unavailable) : mgmt);
    Preference wifiCurrentRatePref = findPreference(KEY_CURRENT_RATE);
          String currentRate = wifiInfo.getLinkSpeed()+"";
          wifiCurrentRatePref.setSummary(currentRate == null ?
                  getActivity().getString(R.string.status_unavailable) : currentRate);
    Preference wifiCapsPref = findPreference(KEY_PROTOCOL_CAPS);
          String caps = wifiInfo.getGroupCipher();
          wifiCapsPref.setSummary(caps == null ?
                  getActivity().getString(R.string.status_unavailable) : caps);
    Preference wifiWapstatePref = findPreference(KEY_WPA_STATE);
          String wapState = wifiInfo.getWpaState();
          wifiWapstatePref.setSummary(wapState == null ?
                  getActivity().getString(R.string.status_unavailable) : wapState);*/
  }
 /**
  * Wifi強度を取得する
  *
  * @param numLevels 強度の段階数
  * @return int 強度
  */
 public int getRssiLevel(int numLevels) {
   WifiInfo info = mWifiManager.getConnectionInfo();
   return WifiManager.calculateSignalLevel(info.getRssi(), numLevels);
 }
 int getLevel() {
   if (mRssi == Integer.MAX_VALUE) {
     return -1;
   }
   return WifiManager.calculateSignalLevel(mRssi, 4);
 }