List of usage examples for android.net.wifi WifiManager createWifiLock
public WifiLock createWifiLock(String tag)
From source file:Main.java
public static void acquireTemporaryWakelocks(Context context, long timeout) { if (wakeLock == null) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "PushSMS"); }//from w w w .j a v a 2 s . c o m wakeLock.acquire(timeout); if (wifiLock == null) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock("PushSMS"); } wifiLock.acquire(); new Handler().postDelayed(new Runnable() { @Override public void run() { wifiLock.release(); } }, timeout); }
From source file:ca.farrelltonsolar.classic.MonitorApplication.java
public void onCreate() { super.onCreate(); MonitorApplication.context = getApplicationContext(); if (Constants.DEVELOPER_MODE) { StrictMode.enableDefaults();//ww w .j a va 2s . c om } InitializeChargeStateLookup(); InitializeChargeStateTitleLookup(); InitializeMessageLookup(); try { configuration = ComplexPreferences.getComplexPreferences(this, null, Context.MODE_PRIVATE); chargeControllers = configuration.getObject("devices", ChargeControllers.class); } catch (Exception ex) { Log.w(getClass().getName(), "getComplexPreferences failed to load"); chargeControllers = null; } if (chargeControllers == null) { // save empty collection chargeControllers = new ChargeControllers(context); } if (chargeControllers.uploadToPVOutput()) { startService(new Intent(this, PVOutputService.class)); // start PVOutputService intent service } this.registerActivityLifecycleCallbacks(this); bindService(new Intent(this, UDPListener.class), UDPListenerServiceConnection, Context.BIND_AUTO_CREATE); WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifi != null) { wifiLock = wifi.createWifiLock("ClassicMonitor"); } Log.d(getClass().getName(), "onCreate complete"); }
From source file:com.hbm.devices.scan.ui.android.DeviceListFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /*/*from w w w . j av a 2 s . c o m*/ * Probably a good idea to update UI only after this method was called. * Then we should have a complete view. In onDestroyView we can stop updating UI. * Probably a better idea is to start/stop updating UI in onResume/onPause. * Has to be clarified if these methods are called when activity goes into background. */ final ScanActivity activity = (ScanActivity) getActivity(); final WifiManager wifi = (WifiManager) activity.getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifi == null) { final Toast failureToast = Toast.makeText(activity, activity.getString(R.string.could_not_get_wifimanager), Toast.LENGTH_SHORT); failureToast.show(); } else { if (wifiLock == null || !wifiLock.isHeld()) { wifiLock = wifi.createWifiLock("wifi lock"); wifiLock.acquire(); } if (mcLock == null || !mcLock.isHeld()) { mcLock = wifi.createMulticastLock("multicast lock"); mcLock.acquire(); } } if (adapter.get() != null) { updateList(); } prefUseFakeMessages = getString(R.string.pref_use_fake_messages); prefFakeMessageType = getString(R.string.pref_fake_message_type); }
From source file:com.irccloud.android.NetworkConnection.java
@SuppressWarnings("deprecation") public NetworkConnection() { String version;//from w w w. j a v a2 s. c o m String network_type = null; try { version = "/" + IRCCloudApplication.getInstance().getPackageManager().getPackageInfo( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), 0).versionName; } catch (Exception e) { version = ""; } try { ConnectivityManager cm = (ConnectivityManager) IRCCloudApplication.getInstance() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null) network_type = ni.getTypeName(); } catch (Exception e) { } try { config = new JSONObject(PreferenceManager .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()) .getString("config", "{}")); } catch (JSONException e) { e.printStackTrace(); config = new JSONObject(); } useragent = "IRCCloud" + version + " (" + android.os.Build.MODEL + "; " + Locale.getDefault().getCountry().toLowerCase() + "; " + "Android " + android.os.Build.VERSION.RELEASE; WindowManager wm = (WindowManager) IRCCloudApplication.getInstance() .getSystemService(Context.WINDOW_SERVICE); useragent += "; " + wm.getDefaultDisplay().getWidth() + "x" + wm.getDefaultDisplay().getHeight(); if (network_type != null) useragent += "; " + network_type; useragent += ")"; WifiManager wfm = (WifiManager) IRCCloudApplication.getInstance().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); wifiLock = wfm.createWifiLock(TAG); kms = new X509ExtendedKeyManager[1]; kms[0] = new X509ExtendedKeyManager() { @Override public String chooseClientAlias(String[] keyTypes, Principal[] issuers, Socket socket) { return SSLAuthAlias; } @Override public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) { throw new UnsupportedOperationException(); } @Override public X509Certificate[] getCertificateChain(String alias) { return SSLAuthCertificateChain; } @Override public String[] getClientAliases(String keyType, Principal[] issuers) { throw new UnsupportedOperationException(); } @Override public String[] getServerAliases(String keyType, Principal[] issuers) { throw new UnsupportedOperationException(); } @Override public PrivateKey getPrivateKey(String alias) { return SSLAuthKey; } }; tms = new TrustManager[1]; tms[0] = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { throw new CertificateException("Not implemented"); } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { try { TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509"); trustManagerFactory.init((KeyStore) null); for (TrustManager trustManager : trustManagerFactory.getTrustManagers()) { if (trustManager instanceof X509TrustManager) { X509TrustManager x509TrustManager = (X509TrustManager) trustManager; x509TrustManager.checkServerTrusted(chain, authType); } } } catch (KeyStoreException e) { throw new CertificateException(e); } catch (NoSuchAlgorithmException e) { throw new CertificateException(e); } if (BuildConfig.SSL_FPS != null && BuildConfig.SSL_FPS.length > 0) { try { MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] sha1 = md.digest(chain[0].getEncoded()); // http://stackoverflow.com/questions/9655181/convert-from-byte-array-to-hex-string-in-java final char[] hexArray = "0123456789ABCDEF".toCharArray(); char[] hexChars = new char[sha1.length * 2]; for (int j = 0; j < sha1.length; j++) { int v = sha1[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } String hexCharsStr = new String(hexChars); boolean matched = false; for (String fp : BuildConfig.SSL_FPS) { if (fp.equals(hexCharsStr)) { matched = true; break; } } if (!matched) throw new CertificateException("Incorrect CN in cert chain"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; WebSocketClient.setTrustManagers(tms); }
From source file:com.max2idea.android.limbo.main.LimboActivity.java
private void acquireLocks() { if (mWakeLock == null) { PowerManager pm = (PowerManager) activity.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, WAKELOCK_KEY); mWakeLock.setReferenceCounted(false); }/*from w w w .j a v a2 s.c o m*/ // Creates a new WifiLock by getting the WifiManager as a service. // This object creates a lock tagged "lock". if (wlock == null) { WifiManager wmanager = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE); wlock = wmanager.createWifiLock("lock"); wlock.setReferenceCounted(false); } if (!mWakeLock.isHeld()) { Log.v(TAG, "Acquire wake lock..."); mWakeLock.acquire(); } if (!wlock.isHeld()) { Log.v(TAG, "Acquire wifi lock..."); wlock.acquire(); } }