From 12f49b1f5234c57846a4e3c52cc891c2f1e3f0da Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 19 Oct 2012 21:07:43 -0700 Subject: Added Wifi Lock --- .../src/github/daneren2005/dsub/service/DownloadFile.java | 8 ++++++++ subsonic-android/src/github/daneren2005/dsub/util/Util.java | 10 ++++++++++ 2 files changed, 18 insertions(+) (limited to 'subsonic-android/src') 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); + } } -- cgit v1.2.3