aboutsummaryrefslogtreecommitdiff
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
parent1bd41a3b92d871445dbdc17e3f86ee1504f23a90 (diff)
downloaddsub-12f49b1f5234c57846a4e3c52cc891c2f1e3f0da.tar.gz
dsub-12f49b1f5234c57846a4e3c52cc891c2f1e3f0da.tar.bz2
dsub-12f49b1f5234c57846a4e3c52cc891c2f1e3f0da.zip
Added Wifi Lock
-rw-r--r--subsonic-android/AndroidManifest.xml4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java8
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java10
3 files changed, 20 insertions, 2 deletions
diff --git a/subsonic-android/AndroidManifest.xml b/subsonic-android/AndroidManifest.xml
index 1ee5425a..5fb34247 100644
--- a/subsonic-android/AndroidManifest.xml
+++ b/subsonic-android/AndroidManifest.xml
@@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="github.daneren2005.dsub"
android:installLocation="auto"
- android:versionCode="12"
- android:versionName="3.4.1">
+ android:versionCode="13"
+ android:versionName="3.4.2">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
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);
+ }
}