Acquire Wi-Fi lock before downloading. Should fix issue #110 and #243

- Adds the WAKE_LOCK permission
This commit is contained in:
daniel oeh 2014-02-12 00:20:02 +01:00
parent 969170f0e8
commit 967e322913
2 changed files with 16 additions and 0 deletions

View File

@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk
android:minSdkVersion="10"

View File

@ -1,5 +1,8 @@
package de.danoeh.antennapod.service.download;
import android.content.Context;
import android.net.wifi.WifiManager;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
import java.util.concurrent.Callable;
@ -26,7 +29,19 @@ public abstract class Downloader implements Callable<Downloader> {
protected abstract void download();
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");