code: public static void keepWiFiOn(Context context, boolean on) {
      if (wifiLock == null) {
        WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (wm != null) {
          wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, TAG);
          wifiLock.setReferenceCounted(true);
        }
      }
      if (wifiLock != null) { // May be null if wm is null
        if (on) {
          wifiLock.acquire();
          L.d(TAG, "Adquired WiFi lock");
        } else if (wifiLock.isHeld()) {
          wifiLock.release();
          L.d(TAG, "Released WiFi lock");
        }
      }
    }
docs: Register a WiFi lock to WiFi management in the device.
  
  @param context Context to use
  @param on if true the device WiFi radio will keep awake until false is called back. if
  true is passed several times only the first time after a false call will take
  effect, also if false is passed and previously the WiFi radio was not turned on
  (true call) does nothing.