List of usage examples for android.net.wifi WifiInfo getSupplicantState
public SupplicantState getSupplicantState()
From source file:com.tvs.signaltracker.STService.java
private void UpdateWiFi() { SupplicantState supState;//from ww w .ja va2 s . c om WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); supState = wifiInfo.getSupplicantState(); CommonHandler.WifiConnected = (supState == SupplicantState.COMPLETED); }
From source file:org.wahtod.wififixer.ui.StatusFragment.java
private void refresh() { WifiInfo info = getNetwork(getContext()); if (info == null) { _views.setSsid(getContext().getString(R.string.wifi_is_disabled)); _views.setSignal(EMPTYSTRING);/*from ww w . ja v a2 s . c om*/ _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); }
From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java
public boolean setUpNetwork(String sIniFile) { boolean bRet = false; int lcv = 0;/*from w w w . ja v a2 s . c om*/ int lcv2 = 0; WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiConfiguration wc = new WifiConfiguration(); DoCommand tmpdc = new DoCommand(getApplication()); String ssid = tmpdc.GetIniData("Network Settings", "SSID", sIniFile); String auth = tmpdc.GetIniData("Network Settings", "AUTH", sIniFile); String encr = tmpdc.GetIniData("Network Settings", "ENCR", sIniFile); String key = tmpdc.GetIniData("Network Settings", "KEY", sIniFile); String eap = tmpdc.GetIniData("Network Settings", "EAP", sIniFile); String adhoc = tmpdc.GetIniData("Network Settings", "ADHOC", sIniFile); Toast.makeText(getApplication().getApplicationContext(), "Starting and configuring network", Toast.LENGTH_LONG).show(); /* ContentResolver cr = getContentResolver(); int nRet; try { nRet = Settings.System.getInt(cr, Settings.System.WIFI_USE_STATIC_IP); String foo2 = "" + nRet; } catch (SettingNotFoundException e1) { e1.printStackTrace(); } */ /* wc.SSID = "\"Mozilla-Build\""; wc.preSharedKey = "\"MozillaBuildQA500\""; wc.hiddenSSID = true; wc.status = WifiConfiguration.Status.ENABLED; wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN); */ wc.SSID = "\"" + ssid + "\""; // wc.SSID = "\"Mozilla-G\""; // wc.SSID = "\"Mozilla\""; if (auth.contentEquals("wpa2")) { wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN); wc.preSharedKey = null; } if (encr.contentEquals("aes")) { wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); } if (eap.contentEquals("peap")) { wc.eap.setValue("PEAP"); wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X); } wc.status = WifiConfiguration.Status.ENABLED; if (!wifi.isWifiEnabled()) wifi.setWifiEnabled(true); while (wifi.getWifiState() != WifiManager.WIFI_STATE_ENABLED) { Thread.yield(); if (++lcv > 10000) return (bRet); } wl = wifi.createWifiLock(WifiManager.WIFI_MODE_FULL, "SUTAgent"); if (wl != null) wl.acquire(); WifiConfiguration foo = null; int nNetworkID = -1; List<WifiConfiguration> connsLst = wifi.getConfiguredNetworks(); int nConns = connsLst.size(); for (int i = 0; i < nConns; i++) { foo = connsLst.get(i); if (foo.SSID.equalsIgnoreCase(wc.SSID)) { nNetworkID = foo.networkId; wc.networkId = foo.networkId; break; } } int res; if (nNetworkID != -1) { res = wifi.updateNetwork(wc); } else { res = wifi.addNetwork(wc); } Log.d("WifiPreference", "add Network returned " + res); boolean b = wifi.enableNetwork(res, true); Log.d("WifiPreference", "enableNetwork returned " + b); wifi.saveConfiguration(); WifiInfo wi = wifi.getConnectionInfo(); SupplicantState ss = wi.getSupplicantState(); lcv = 0; lcv2 = 0; while (ss.compareTo(SupplicantState.COMPLETED) != 0) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } if (wi != null) wi = null; if (ss != null) ss = null; wi = wifi.getConnectionInfo(); ss = wi.getSupplicantState(); if (++lcv > 60) { if (++lcv2 > 5) { Toast.makeText(getApplication().getApplicationContext(), "Unable to start and configure network", Toast.LENGTH_LONG).show(); return (bRet); } else { Toast.makeText(getApplication().getApplicationContext(), "Resetting wifi interface", Toast.LENGTH_LONG).show(); if (wl != null) wl.release(); wifi.setWifiEnabled(false); while (wifi.getWifiState() != WifiManager.WIFI_STATE_DISABLED) { Thread.yield(); } wifi.setWifiEnabled(true); while (wifi.getWifiState() != WifiManager.WIFI_STATE_ENABLED) { Thread.yield(); } b = wifi.enableNetwork(res, true); Log.d("WifiPreference", "enableNetwork returned " + b); if (wl != null) wl.acquire(); lcv = 0; } } } lcv = 0; while (getLocalIpAddress() == null) { if (++lcv > 10000) return (bRet); } Toast.makeText(getApplication().getApplicationContext(), "Network started and configured", Toast.LENGTH_LONG).show(); bRet = true; return (bRet); }
From source file:org.sipdroid.sipua.ui.Receiver.java
@Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); if (!Sipdroid.on(context)) return;/*from w w w.j a v a2 s. c o m*/ if (!Sipdroid.release) Log.i("SipUA:", intentAction); if (mContext == null) mContext = context; if (intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) { on_vpn(false); engine(context).register(); } else if (intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION) || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_AVAILABLE) || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE) || intentAction.equals(Intent.ACTION_PACKAGE_REPLACED)) { engine(context).register(); } else if (intentAction.equals(ACTION_VPN_CONNECTIVITY) && intent.hasExtra("connection_state")) { String state = intent.getSerializableExtra("connection_state").toString(); if (state != null && on_vpn() != state.equals("CONNECTED")) { on_vpn(state.equals("CONNECTED")); for (SipProvider sip_provider : engine(context).sip_providers) if (sip_provider != null) sip_provider.haltConnections(); engine(context).register(); } } else if (intentAction.equals(ACTION_DATA_STATE_CHANGED)) { engine(context).registerMore(); } else if (intentAction.equals(ACTION_PHONE_STATE_CHANGED) && !intent.getBooleanExtra(context.getString(R.string.app_name), false)) { stopRingtone(); pstn_state = intent.getStringExtra("state"); pstn_time = SystemClock.elapsedRealtime(); if (pstn_state.equals("IDLE") && call_state != UserAgent.UA_STATE_IDLE) broadcastCallStateChanged(null, null); if (!pstn_state.equals("IDLE") && call_state == UserAgent.UA_STATE_INCALL) mHandler.sendEmptyMessageDelayed(MSG_HOLD, 5000); else if (!pstn_state.equals("IDLE") && (call_state == UserAgent.UA_STATE_INCOMING_CALL || call_state == UserAgent.UA_STATE_OUTGOING_CALL)) mHandler.sendEmptyMessageDelayed(MSG_HANGUP, 5000); else if (pstn_state.equals("IDLE")) { mHandler.removeMessages(MSG_HOLD); mHandler.removeMessages(MSG_HANGUP); if (call_state == UserAgent.UA_STATE_HOLD) mHandler.sendEmptyMessageDelayed(MSG_HOLD, 1000); } } else if (intentAction.equals(ACTION_DOCK_EVENT)) { docked = intent.getIntExtra(EXTRA_DOCK_STATE, -1) & 7; if (call_state == UserAgent.UA_STATE_INCALL) engine(mContext).speaker(speakermode()); } else if (intentAction.equals(ACTION_SCO_AUDIO_STATE_CHANGED)) { bluetooth = intent.getIntExtra(EXTRA_SCO_AUDIO_STATE, -1); progress(); RtpStreamSender.changed = true; } else if (intentAction.equals(Intent.ACTION_HEADSET_PLUG)) { headset = intent.getIntExtra("state", -1); if (call_state == UserAgent.UA_STATE_INCALL) engine(mContext).speaker(speakermode()); } else if (intentAction.equals(Intent.ACTION_SCREEN_ON)) { if (!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) alarm(0, OwnWifi.class); } else if (intentAction.equals(Intent.ACTION_USER_PRESENT)) { mHandler.sendEmptyMessageDelayed(MSG_ENABLE, 3000); } else if (intentAction.equals(Intent.ACTION_SCREEN_OFF)) { if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); if (wm.getWifiState() != WifiManager.WIFI_STATE_ENABLED || wi == null || wi.getSupplicantState() != SupplicantState.COMPLETED || wi.getIpAddress() == 0) alarm(2 * 60, OwnWifi.class); else alarm(15 * 60, OwnWifi.class); } if (SipdroidEngine.pwl != null) for (PowerManager.WakeLock pwl : SipdroidEngine.pwl) if (pwl != null && pwl.isHeld()) { pwl.release(); pwl.acquire(); } } else if (intentAction.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) mHandler.sendEmptyMessageDelayed(MSG_SCAN, 3000); } else if (intentAction.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { if (SystemClock.uptimeMillis() > lastscan + 45000 && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); String activeSSID = null; if (wi != null) activeSSID = wi.getSSID(); if (activeSSID != null && (activeSSID.length() == 0 || activeSSID.equals("0x"))) activeSSID = null; List<ScanResult> mScanResults = wm.getScanResults(); List<WifiConfiguration> configurations = wm.getConfiguredNetworks(); if (configurations != null) { WifiConfiguration bestconfig = null, maxconfig = null, activeconfig = null; for (final WifiConfiguration config : configurations) { if (maxconfig == null || config.priority > maxconfig.priority) { maxconfig = config; } if (config.SSID != null && (config.SSID.equals("\"" + activeSSID + "\"") || config.SSID.equals(activeSSID))) activeconfig = config; } ScanResult bestscan = null, activescan = null; if (mScanResults != null) for (final ScanResult scan : mScanResults) { for (final WifiConfiguration config : configurations) { if (config.SSID != null && config.SSID.equals("\"" + scan.SSID + "\"")) { if (bestscan == null || scan.level > bestscan.level) { bestscan = scan; bestconfig = config; } if (config == activeconfig) activescan = scan; } } } if (activescan != null) System.out.println("debug wifi asu(active)" + asu(activescan)); if (bestconfig != null && (activeconfig == null || bestconfig.priority != activeconfig.priority) && asu(bestscan) > asu(activescan) * 1.5 && /* (activeSSID == null || activescan != null) && */ asu(bestscan) > 22) { if (!Sipdroid.release) Log.i("SipUA:", "changing to " + bestconfig.SSID); if (activeSSID == null || !activeSSID.equals(bestscan.SSID)) wm.disconnect(); bestconfig.priority = maxconfig.priority + 1; wm.updateNetwork(bestconfig); wm.enableNetwork(bestconfig.networkId, true); wm.saveConfiguration(); if (activeSSID == null || !activeSSID.equals(bestscan.SSID)) wm.reconnect(); lastscan = SystemClock.uptimeMillis(); } else if (activescan != null && asu(activescan) < 15) { wm.disconnect(); wm.disableNetwork(activeconfig.networkId); wm.saveConfiguration(); } } } } }
From source file:com.example.aaron.test.MyGLSurfaceView.java
public void tick() { antispam = antispam + 1;/*w w w .ja v a 2 s.c o m*/ count = 0; WifiInfo wifiInfo = getWifi(context1); NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); mRenderer.textListSINFO.get(1).setText("Strength: " + wifiInfo.getRssi()); if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) { mRenderer.textListSINFO.get(2).setText("Network: " + wifiInfo.getSSID()); } if (mRenderer.voronoiDeploymentToggle.active == true) { mRenderer.textListSINFO.get(3).setText("Deployment: Multi-agent Voronoi"); } else if (pFlag == 1) { mRenderer.textListSINFO.get(3).setText("Go to Goal"); } for (int i = 0; i < 50; i++) { if (tList[i].getState() == 1) { count++; if (count > 1) { mRenderer.textListARINFO.get(0).setText("Multiple Robots Selected"); mRenderer.textListARINFO.get(2).setText(" X:"); mRenderer.textListARINFO.get(3).setText(" Y:"); mRenderer.textListARINFO.get(4).setText(" Z:"); } else { mRenderer.textListARINFO.get(0).setText(tList[i].getIdentification()); mRenderer.textListARINFO.get(2).setText(" X:" + truncateDecimal(tList[i].getX(), 3)); mRenderer.textListARINFO.get(3).setText(" Y:" + truncateDecimal(tList[i].getY(), 3)); mRenderer.textListARINFO.get(4).setText(" Z:" + truncateDecimal(tList[i].getZ(), 3)); } } } if (count == 0) { mRenderer.textListARINFO.get(0).setText("No Robots Selected"); mRenderer.textListARINFO.get(2).setText(" X:"); mRenderer.textListARINFO.get(3).setText(" Y:"); mRenderer.textListARINFO.get(4).setText(" Z:"); } mRenderer.getUniqueVertices(); mRenderer.toMapPoints(); mRenderer.calculateAdjacencyMatrix(); mRenderer.calculateAdjacencyMatrixGoal(); if (!mRenderer.obstacleMapPoints.isEmpty()) { mRenderer.Dijkstra(); } }
From source file:at.alladin.rmbt.android.util.InformationCollector.java
private void getWiFiInfo() { initNetwork();/*from ww w .ja va 2 s . co m*/ if (wifiManager != null) { final WifiInfo wifiInfo = wifiManager.getConnectionInfo(); fullInfo.setProperty("WIFI_SSID", String.valueOf(Helperfunctions.removeQuotationsInCurrentSSIDForJellyBean(wifiInfo.getSSID()))); /* * fullInfo.setProperty("WIFI_LINKSPEED", * String.valueOf(wifiInfo.getLinkSpeed())); */ fullInfo.setProperty("WIFI_BSSID", String.valueOf(wifiInfo.getBSSID())); fullInfo.setProperty("WIFI_NETWORK_ID", String.valueOf(wifiInfo.getNetworkId())); /* * fullInfo.setProperty("WIFI_RSSI", * String.valueOf(wifiInfo.getRssi())); */ final SupplicantState wifiState = wifiInfo.getSupplicantState(); fullInfo.setProperty("WIFI_SUPPLICANT_STATE", String.valueOf(wifiState.name())); final DetailedState wifiDetail = WifiInfo.getDetailedStateOf(wifiState); fullInfo.setProperty("WIFI_SUPPLICANT_STATE_DETAIL", String.valueOf(wifiDetail.name())); if (getNetwork() == NETWORK_WIFI) { final int rssi = wifiInfo.getRssi(); if (rssi != -1 && rssi >= ACCEPT_WIFI_RSSI_MIN) { int linkSpeed = wifiInfo.getLinkSpeed(); if (linkSpeed < 0) { linkSpeed = 0; } final SignalItem signalItem = SignalItem.getWifiSignalItem(linkSpeed, rssi); if (this.collectInformation) { signals.add(signalItem); } lastSignalItem.set(signalItem); signal.set(rssi); signalType.set(SINGAL_TYPE_WLAN); // Log.i(DEBUG_TAG, "Signals1: " + signals.toString()); } } } }
From source file:com.csipsimple.service.SipService.java
/** * Ask to take the control of the wifi and the partial wake lock if * configured//from w ww. ja va 2 s .c om */ private synchronized void acquireResources() { if (holdResources) { return; } // Add a wake lock for CPU if necessary if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.USE_PARTIAL_WAKE_LOCK)) { PowerManager pman = (PowerManager) getSystemService(Context.POWER_SERVICE); if (wakeLock == null) { wakeLock = pman.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.csipsimple.SipService"); wakeLock.setReferenceCounted(false); } // Extra check if set reference counted is false ??? if (!wakeLock.isHeld()) { wakeLock.acquire(); } } // Add a lock for WIFI if necessary WifiManager wman = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifiLock == null) { int mode = WifiManager.WIFI_MODE_FULL; if (Compatibility.isCompatible(9) && prefsWrapper.getPreferenceBooleanValue(SipConfigManager.LOCK_WIFI_PERFS)) { mode = 0x3; // WIFI_MODE_FULL_HIGH_PERF } wifiLock = wman.createWifiLock(mode, "com.csipsimple.SipService"); wifiLock.setReferenceCounted(false); } if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.LOCK_WIFI) && !wifiLock.isHeld()) { WifiInfo winfo = wman.getConnectionInfo(); if (winfo != null) { DetailedState dstate = WifiInfo.getDetailedStateOf(winfo.getSupplicantState()); // We assume that if obtaining ip addr, we are almost connected // so can keep wifi lock if (dstate == DetailedState.OBTAINING_IPADDR || dstate == DetailedState.CONNECTED) { if (!wifiLock.isHeld()) { wifiLock.acquire(); } } } } holdResources = true; }
From source file:ua.mkh.settings.full.MainActivity.java
private void ButtonTextWifi() { TextView textwifi = (TextView) findViewById(R.id.textwifi); if (wifi.isWifiEnabled()) { textwifi.setText(R.string.on);// www . j a va2 s . c om } else { textwifi.setText(R.string.off); } WifiManager manager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); if (manager.isWifiEnabled()) { WifiInfo wifiInfo = manager.getConnectionInfo(); if (wifiInfo != null) { DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); if (state == DetailedState.CONNECTED || state == DetailedState.OBTAINING_IPADDR) { String wi = wifiInfo.getSSID().replace('"', ' '); textwifi.setText(wi); } } } }