Java Code Examples for android.net.wifi.WifiManager#WifiLock

The following examples show how to use android.net.wifi.WifiManager#WifiLock . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidEnvironment.java    From personaldnsfilter with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void releaseAllWakeLocks() {
    Object[] locks;
    while (!wakeLooks.isEmpty()) {
        try {
            locks = (Object[]) wakeLooks.pop();
        } catch (Exception e) {
            Logger.getLogger().logException(e);
            return;
        }
        WifiManager.WifiLock wifiLock = (WifiManager.WifiLock) locks[0];
        PowerManager.WakeLock wakeLock = (PowerManager.WakeLock) locks[1];
        wifiLock.release();
        wakeLock.release();
        Logger.getLogger().logLine("Released WIFI lock and partial wake lock!");
    }
}
 
Example 2
Source File: Downloader.java    From AntennaPodSP with MIT License 6 votes vote down vote up
public final Downloader call() {
    WifiManager wifiManager = (WifiManager) PodcastApp.getInstance().getSystemService(Context.WIFI_SERVICE);
    WifiManager.WifiLock wifiLock = null;
    if (wifiManager != null) {
        wifiLock = wifiManager.createWifiLock(TAG);
        wifiLock.acquire();
    }

    download();

    if (wifiLock != null) {
        wifiLock.release();
    }

    if (result == null) {
        throw new IllegalStateException(
                "Downloader hasn't created DownloadStatus object");
    }
    finished = true;
    return this;
}
 
Example 3
Source File: AndroidEnvironment.java    From personaldnsfilter with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void releaseWakeLock() {
    Object[] locks;
    try {
        locks = (Object[]) wakeLooks.pop();
    } catch (Exception e) {
        Logger.getLogger().logException(e);
        return;
    }
    WifiManager.WifiLock wifiLock = (WifiManager.WifiLock) locks[0];
    PowerManager.WakeLock wakeLock = (PowerManager.WakeLock) locks[1];
    wifiLock.release();
    wakeLock.release();
    Logger.getLogger().logLine("Released WIFI lock and partial wake lock!");
}
 
Example 4
Source File: AndroidRouter.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
protected WifiManager.WifiLock createWiFiLock() {
    int wifiMode = WifiManager.WIFI_MODE_FULL;
    try {
        // TODO: What's this?
        Field f = WifiManager.class.getField("WIFI_MODE_FULL_HIGH_PERF");
        wifiMode = f.getInt(null);
    } catch (Exception e) {
        // Ignore
    }
    WifiManager.WifiLock wifiLock =
        wifiManager.createWifiLock(wifiMode, getClass().getSimpleName());
    log.info("Created WiFi lock, mode: " + wifiMode);
    return wifiLock;
}
 
Example 5
Source File: PlaybackModule.java    From Melophile with Apache License 2.0 5 votes vote down vote up
@PlayerScope
@Provides
Playback playback(Context context) {
  AudioManager audioManager = AudioManager.class.cast(context.getSystemService(Context.AUDIO_SERVICE));
  WifiManager.WifiLock wifiManager = ((WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE))
          .createWifiLock(WifiManager.WIFI_MODE_FULL, "uAmp_lock");
  if (Permission.checkForVersion(Build.VERSION_CODES.LOLLIPOP)) {
    return new MediaPlayback21(context, audioManager, wifiManager);
  }
  return new MediaPlayback(context, audioManager, wifiManager);
}
 
Example 6
Source File: BasePlayback.java    From Melophile with Apache License 2.0 5 votes vote down vote up
public BasePlayback(Context context,
                    AudioManager audioManager,
                    WifiManager.WifiLock wifiLock) {
  this.context = checkNotNull(context);
  this.wifiLock = checkNotNull(wifiLock);
  this.audioManager = checkNotNull(audioManager);
}
 
Example 7
Source File: AndroidRouter.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected WifiManager.WifiLock createWiFiLock() {
    int wifiMode = WifiManager.WIFI_MODE_FULL;
    try {
        // TODO: What's this?
        Field f = WifiManager.class.getField("WIFI_MODE_FULL_HIGH_PERF");
        wifiMode = f.getInt(null);
    } catch (Exception e) {
        // Ignore
    }
    WifiManager.WifiLock wifiLock =
        wifiManager.createWifiLock(wifiMode, getClass().getSimpleName());
    log.info("Created WiFi lock, mode: " + wifiMode);
    return wifiLock;
}
 
Example 8
Source File: Util.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
public static WifiManager.WifiLock createWifiLock(Context context, String tag) {
	WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
	int lockType = WifiManager.WIFI_MODE_FULL;
	if (Build.VERSION.SDK_INT >= 12) {
		lockType = 3;
	}
	return wm.createWifiLock(lockType, tag);
}
 
Example 9
Source File: MediaPlayback.java    From Melophile with Apache License 2.0 4 votes vote down vote up
@Inject
public MediaPlayback(Context context,
                     AudioManager audioManager,
                     WifiManager.WifiLock wifiLock) {
  super(context, audioManager, wifiLock);
}
 
Example 10
Source File: MediaPlayback21.java    From Melophile with Apache License 2.0 4 votes vote down vote up
@Inject
public MediaPlayback21(Context context,
                       AudioManager audioManager,
                       WifiManager.WifiLock wifiLock) {
  super(context, audioManager, wifiLock);
}
 
Example 11
Source File: Util.java    From Audinaut with GNU General Public License v3.0 4 votes vote down vote up
public static WifiManager.WifiLock createWifiLock(Context context, String tag) {
    WifiManager wm = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    return wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, tag);
}