Search in sources :

Example 46 with ScanResult

use of android.net.wifi.ScanResult in project routerkeygenAndroid by routerkeygen.

the class NetworksListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    RelativeLayout root = (RelativeLayout) inflater.inflate(R.layout.fragment_networks_list, container, false);
    listview = (ListView) root.findViewById(R.id.networks_list);
    wifiListAdapter = new WifiListAdapter(getActivity());
    listview.setAdapter(wifiListAdapter);
    noNetworksMessage = root.findViewById(R.id.message_group);
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(NETWORKS_FOUND)) {
            Parcelable[] storedNetworksFound = savedInstanceState.getParcelableArray(NETWORKS_FOUND);
            networksFound = new ScanResult[storedNetworksFound.length];
            for (int i = 0; i < storedNetworksFound.length; ++i) networksFound[i] = (ScanResult) storedNetworksFound[i];
            onScanFinished(networksFound);
        }
        if (savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
            setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
        }
    }
    registerForContextMenu(listview);
    return root;
}
Also used : ScanResult(android.net.wifi.ScanResult) RelativeLayout(android.widget.RelativeLayout) Parcelable(android.os.Parcelable)

Example 47 with ScanResult

use of android.net.wifi.ScanResult in project AisenWeiBo by wangdan.

the class SinaSDK method locationMobileGetLocation.

/**
	 * 根据移动基站WIFI等数据获取当前位置信息
	 * 
	 * @return
	 * @throws TaskException
	 */
public SinaLocationMap locationMobileGetLocation() throws TaskException {
    Map<String, Object> requestMap = new HashMap<String, Object>();
    // 请求版本信息
    requestMap.put("version", "2.0");
    // 请求地址信息
    requestMap.put("host", "api.weibo.com");
    // 请求类型
    requestMap.put("radio_type", "gsm");
    // 是否需要返回详细地址,可选,默认:false
    requestMap.put("request_address", "true");
    // 返回坐标是否偏移处理,偏移后坐标适合在新浪地图上使用(http://map.sina.com.cn),
    // 不适用于百度地图(各地图偏移量不同,请谨慎处理);可选,默认:false
    requestMap.put("decode_pos", "true");
    TelephonyManager mTelNet = (TelephonyManager) GlobalContext.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation location = null;
    if (mTelNet != null)
        location = (GsmCellLocation) mTelNet.getCellLocation();
    if (location != null) {
        String operator = mTelNet.getNetworkOperator();
        int mcc = Integer.parseInt(operator.substring(0, 3));
        int mnc = Integer.parseInt(operator.substring(3));
        List<NeighboringCellInfo> cellInfoList = mTelNet.getNeighboringCellInfo();
        ArrayList<Map<String, Object>> cellMapList = new ArrayList<Map<String, Object>>();
        for (NeighboringCellInfo cellInfo : cellInfoList) {
            // 基站信息
            Map<String, Object> cellMap = new HashMap<String, Object>();
            // 基站号
            cellMap.put("cell_id", location.getCid());
            // 小区号
            cellMap.put("location_area_code", cellInfo.getLac());
            // 地区代码
            cellMap.put("mobile_country_code", mcc);
            // 运营商号
            cellMap.put("mobile_network_code", mnc);
            // 信号强度
            cellMap.put("signal_strength", cellInfo.getRssi());
            cellMapList.add(cellMap);
        }
        if (cellMapList.size() > 0)
            requestMap.put("cell_towers", cellMapList);
    }
    WifiManager wm = (WifiManager) GlobalContext.getInstance().getSystemService(Context.WIFI_SERVICE);
    List<ScanResult> scanResultList = wm.getScanResults();
    if (scanResultList != null && scanResultList.size() > 0) {
        ArrayList<Map<String, Object>> wifiMapList = new ArrayList<Map<String, Object>>();
        for (ScanResult scanResult : scanResultList) {
            // WIFI信息
            Map<String, Object> wifiMap = new HashMap<String, Object>();
            wifiMapList.add(wifiMap);
            wifiMap.put("mac_address", scanResult.BSSID);
            wifiMap.put("mac_name", scanResult.SSID);
            // 信号强度
            wifiMap.put("signal_strength", scanResult.level);
        }
        if (wifiMapList.size() > 0)
            requestMap.put("wifi_towers", wifiMapList);
    }
    HttpConfig config = getHttpConfig();
    Params params = new Params();
    params.addParameter("json", JSON.toJSONString(requestMap));
    return doPost(config, getSetting("locationMobileGetLocation"), null, params, null, SinaLocationMap.class);
}
Also used : WifiManager(android.net.wifi.WifiManager) ScanResult(android.net.wifi.ScanResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Params(org.aisen.android.network.http.Params) NeighboringCellInfo(android.telephony.NeighboringCellInfo) TelephonyManager(android.telephony.TelephonyManager) JSONObject(com.alibaba.fastjson.JSONObject) HttpConfig(org.aisen.android.network.http.HttpConfig) GsmCellLocation(android.telephony.gsm.GsmCellLocation) Map(java.util.Map) SinaLocationMap(org.aisen.weibo.sina.sinasdk.bean.SinaLocationMap) HashMap(java.util.HashMap)

Example 48 with ScanResult

use of android.net.wifi.ScanResult in project android_frameworks_base by ParanoidAndroid.

the class WifiNotificationController method checkAndSetNotification.

private synchronized void checkAndSetNotification(NetworkInfo networkInfo, List<ScanResult> scanResults) {
    // don't bother doing any of the following
    if (!mNotificationEnabled)
        return;
    if (networkInfo == null)
        return;
    if (mWifiState != WifiManager.WIFI_STATE_ENABLED)
        return;
    NetworkInfo.State state = networkInfo.getState();
    if ((state == NetworkInfo.State.DISCONNECTED) || (state == NetworkInfo.State.UNKNOWN)) {
        if (scanResults != null) {
            int numOpenNetworks = 0;
            for (int i = scanResults.size() - 1; i >= 0; i--) {
                ScanResult scanResult = scanResults.get(i);
                //that is available for an STA to connect
                if (scanResult.capabilities != null && scanResult.capabilities.equals("[ESS]")) {
                    numOpenNetworks++;
                }
            }
            if (numOpenNetworks > 0) {
                if (++mNumScansSinceNetworkStateChange >= NUM_SCANS_BEFORE_ACTUALLY_SCANNING) {
                    /*
                         * We've scanned continuously at least
                         * NUM_SCANS_BEFORE_NOTIFICATION times. The user
                         * probably does not have a remembered network in range,
                         * since otherwise supplicant would have tried to
                         * associate and thus resetting this counter.
                         */
                    setNotificationVisible(true, numOpenNetworks, false, 0);
                }
                return;
            }
        }
    }
    // No open networks in range, remove the notification
    setNotificationVisible(false, 0, false, 0);
}
Also used : ScanResult(android.net.wifi.ScanResult) NetworkInfo(android.net.NetworkInfo)

Example 49 with ScanResult

use of android.net.wifi.ScanResult in project platform_frameworks_base by android.

the class WifiTracker method updateAccessPoints.

private void updateAccessPoints() {
    // Swap the current access points into a cached list.
    List<AccessPoint> cachedAccessPoints = getAccessPoints();
    ArrayList<AccessPoint> accessPoints = new ArrayList<>();
    // Clear out the configs so we don't think something is saved when it isn't.
    for (AccessPoint accessPoint : cachedAccessPoints) {
        accessPoint.clearConfig();
    }
    /** Lookup table to more quickly update AccessPoints by only considering objects with the
         * correct SSID.  Maps SSID -> List of AccessPoints with the given SSID.  */
    Multimap<String, AccessPoint> apMap = new Multimap<String, AccessPoint>();
    WifiConfiguration connectionConfig = null;
    if (mLastInfo != null) {
        connectionConfig = getWifiConfigurationForNetworkId(mLastInfo.getNetworkId());
    }
    final Collection<ScanResult> results = fetchScanResults();
    final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
    if (configs != null) {
        mSavedNetworksExist = configs.size() != 0;
        for (WifiConfiguration config : configs) {
            if (config.selfAdded && config.numAssociation == 0) {
                continue;
            }
            AccessPoint accessPoint = getCachedOrCreate(config, cachedAccessPoints);
            if (mLastInfo != null && mLastNetworkInfo != null) {
                accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo);
            }
            if (mIncludeSaved) {
                // If saved network not present in scan result then set its Rssi to MAX_VALUE
                boolean apFound = false;
                for (ScanResult result : results) {
                    if (result.SSID.equals(accessPoint.getSsidStr())) {
                        apFound = true;
                        break;
                    }
                }
                if (!apFound) {
                    accessPoint.setRssi(Integer.MAX_VALUE);
                }
                accessPoints.add(accessPoint);
                apMap.put(accessPoint.getSsidStr(), accessPoint);
            } else {
                // If we aren't using saved networks, drop them into the cache so that
                // we have access to their saved info.
                cachedAccessPoints.add(accessPoint);
            }
        }
    }
    if (results != null) {
        for (ScanResult result : results) {
            // Ignore hidden and ad-hoc networks.
            if (result.SSID == null || result.SSID.length() == 0 || result.capabilities.contains("[IBSS]")) {
                continue;
            }
            boolean found = false;
            for (AccessPoint accessPoint : apMap.getAll(result.SSID)) {
                if (accessPoint.update(result)) {
                    found = true;
                    break;
                }
            }
            if (!found && mIncludeScans) {
                AccessPoint accessPoint = getCachedOrCreate(result, cachedAccessPoints);
                if (mLastInfo != null && mLastNetworkInfo != null) {
                    accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo);
                }
                if (result.isPasspointNetwork()) {
                    // Retrieve a WifiConfiguration for a Passpoint provider that matches
                    // the given ScanResult.  This is used for showing that a given AP
                    // (ScanResult) is available via a Passpoint provider (provider friendly
                    // name).
                    WifiConfiguration config = mWifiManager.getMatchingWifiConfig(result);
                    if (config != null) {
                        accessPoint.update(config);
                    }
                }
                accessPoints.add(accessPoint);
                apMap.put(accessPoint.getSsidStr(), accessPoint);
            }
        }
    }
    // Pre-sort accessPoints to speed preference insertion
    Collections.sort(accessPoints);
    // Log accesspoints that were deleted
    if (DBG)
        Log.d(TAG, "------ Dumping SSIDs that were not seen on this scan ------");
    for (AccessPoint prevAccessPoint : mAccessPoints) {
        if (prevAccessPoint.getSsid() == null)
            continue;
        String prevSsid = prevAccessPoint.getSsidStr();
        boolean found = false;
        for (AccessPoint newAccessPoint : accessPoints) {
            if (newAccessPoint.getSsid() != null && newAccessPoint.getSsid().equals(prevSsid)) {
                found = true;
                break;
            }
        }
        if (!found)
            if (DBG)
                Log.d(TAG, "Did not find " + prevSsid + " in this scan");
    }
    if (DBG)
        Log.d(TAG, "---- Done dumping SSIDs that were not seen on this scan ----");
    mAccessPoints = accessPoints;
    mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED);
}
Also used : ScanResult(android.net.wifi.ScanResult) WifiConfiguration(android.net.wifi.WifiConfiguration) ArrayList(java.util.ArrayList)

Example 50 with ScanResult

use of android.net.wifi.ScanResult in project platform_frameworks_base by android.

the class WifiTrackerTest method testNonEphemeralConnected.

public void testNonEphemeralConnected() {
    mWifiTracker = new WifiTracker(mContext, mWifiListener, mLooper, false, true, true, mWifiManager, mMainLooper);
    mWifiTracker.mScanner = mWifiTracker.new Scanner();
    List<WifiConfiguration> wifiConfigs = new ArrayList<WifiConfiguration>();
    List<ScanResult> scanResults = new ArrayList<ScanResult>();
    generateTestNetworks(wifiConfigs, scanResults, false);
    // Tell WifiTracker we are connected now.
    sendConnected();
    // Send all of the configs and scan results to the tracker.
    Mockito.when(mWifiManager.getConfiguredNetworks()).thenReturn(wifiConfigs);
    Mockito.when(mWifiManager.getScanResults()).thenReturn(scanResults);
    // Do this twice to catch a bug that was happening in the caching, making things ephemeral.
    sendScanResultsAndProcess(true);
    List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
    assertEquals("Expected number of results", NUM_NETWORKS - 1, accessPoints.size());
    assertFalse("Connection is not ephemeral", accessPoints.get(0).isEphemeral());
    assertTrue("Connected to wifi", accessPoints.get(0).isActive());
}
Also used : Scanner(com.android.settingslib.wifi.WifiTracker.Scanner) ScanResult(android.net.wifi.ScanResult) WifiConfiguration(android.net.wifi.WifiConfiguration) ArrayList(java.util.ArrayList)

Aggregations

ScanResult (android.net.wifi.ScanResult)75 WifiConfiguration (android.net.wifi.WifiConfiguration)27 ArrayList (java.util.ArrayList)27 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 WifiManager (android.net.wifi.WifiManager)7 WifiInfo (android.net.wifi.WifiInfo)6 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Bundle (android.os.Bundle)5 SpannableString (android.text.SpannableString)5 DhcpInfo (android.net.DhcpInfo)1 NetworkInfo (android.net.NetworkInfo)1 Parcelable (android.os.Parcelable)1 NeighboringCellInfo (android.telephony.NeighboringCellInfo)1 TelephonyManager (android.telephony.TelephonyManager)1 GsmCellLocation (android.telephony.gsm.GsmCellLocation)1 ImageView (android.widget.ImageView)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1