aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-10-19 21:07:43 -0700
committerScott Jackson <daneren2005@gmail.com>2012-10-19 21:07:43 -0700
commit12f49b1f5234c57846a4e3c52cc891c2f1e3f0da (patch)
tree62e30f000e2ba8d22e0fa044e8ea39d8cf3bb73c /subsonic-android/src
parent1bd41a3b92d871445dbdc17e3f86ee1504f23a90 (diff)
downloaddsub-12f49b1f5234c57846a4e3c52cc891c2f1e3f0da.tar.gz
dsub-12f49b1f5234c57846a4e3c52cc891c2f1e3f0da.tar.bz2
dsub-12f49b1f5234c57846a4e3c52cc891c2f1e3f0da.zip
Added Wifi Lock
Diffstat (limited to 'subsonic-android/src')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java8
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java10
2 files changed, 18 insertions, 0 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java
index 20200607..b2a6de57 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import android.content.Context;
+import android.net.wifi.WifiManager;
import android.os.PowerManager;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -194,6 +195,7 @@ public class DownloadFile {
InputStream in = null;
FileOutputStream out = null;
PowerManager.WakeLock wakeLock = null;
+ WifiManager.WifiLock wifiLock = null;
try {
if (Util.isScreenLitOnDownload(context)) {
@@ -202,6 +204,9 @@ public class DownloadFile {
wakeLock.acquire();
Log.i(TAG, "Acquired wake lock " + wakeLock);
}
+
+ wifiLock = Util.createWifiLock(context, toString());
+ wifiLock.acquire();
if (saveFile.exists()) {
Log.i(TAG, saveFile + " already exists. Skipping.");
@@ -261,6 +266,9 @@ public class DownloadFile {
wakeLock.release();
Log.i(TAG, "Released wake lock " + wakeLock);
}
+ if (wifiLock != null) {
+ wifiLock.release();
+ }
new CacheCleaner(context, DownloadServiceImpl.getInstance()).clean();
}
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index cf3b6ca4..42297971 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -37,6 +37,7 @@ import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
+import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
@@ -892,4 +893,13 @@ public final class Util {
findNotificationTextColors((ViewGroup) group.getChildAt(i), title, content);
}
}
+
+ 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);
+ }
}