From b4e23c2cbc922c9349dba7bfc4e329fad9a65bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 11 Sep 2015 15:48:21 -0700 Subject: [PATCH] Make most fields in AsyncDownloader final --- .../net/AsyncDownloaderFromAndroid.java | 23 +++++++++++-------- .../src/org/fdroid/fdroid/net/Downloader.java | 3 +-- .../org/fdroid/fdroid/net/IconDownloader.java | 3 +-- .../fdroid/net/WifiStateChangeService.java | 3 ++- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloaderFromAndroid.java b/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloaderFromAndroid.java index ca4c78feb..8350fb226 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloaderFromAndroid.java +++ b/F-Droid/src/org/fdroid/fdroid/net/AsyncDownloaderFromAndroid.java @@ -31,12 +31,11 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader { private final Context context; private final DownloadManager dm; private final LocalBroadcastManager localBroadcastManager; - private File localFile; - private String remoteAddress; - private String downloadTitle; - private String uniqueDownloadId; - private Listener listener; - private Thread progressThread; + private final File localFile; + private final String remoteAddress; + private final String downloadTitle; + private final String uniqueDownloadId; + private final Listener listener; private boolean isCancelled; private long downloadManagerId = -1; @@ -50,7 +49,6 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader { */ public AsyncDownloaderFromAndroid(Context context, Listener listener, String downloadTitle, String downloadId, String remoteAddress, File localFile) { this.context = context; - this.downloadTitle = downloadTitle; this.uniqueDownloadId = downloadId; this.remoteAddress = remoteAddress; this.listener = listener; @@ -58,6 +56,8 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader { if (TextUtils.isEmpty(downloadTitle)) { this.downloadTitle = remoteAddress; + } else { + this.downloadTitle = downloadTitle; } dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); @@ -101,11 +101,14 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader { context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); - progressThread = new Thread() { + Thread progressThread = new Thread() { @Override public void run() { while (!isCancelled && isDownloading(context, uniqueDownloadId) >= 0) { - try { Thread.sleep(1000); } catch (Exception e) {} + try { + Thread.sleep(1000); + } catch (Exception e) { + } sendProgress(getBytesRead(), getTotalBytes()); } } @@ -313,7 +316,7 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader { /** * Broadcast receiver to listen for ACTION_DOWNLOAD_COMPLETE broadcasts */ - BroadcastReceiver receiver = new BroadcastReceiver() { + final BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) { diff --git a/F-Droid/src/org/fdroid/fdroid/net/Downloader.java b/F-Droid/src/org/fdroid/fdroid/net/Downloader.java index 78d3c42a7..48a3b0237 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/Downloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/Downloader.java @@ -156,8 +156,7 @@ public abstract class Downloader { sendProgress(bytesRead, totalBytes); while (bytesRead < totalBytes) { - int count = -1; - + int count; if (input.available()>0) { int readLength = Math.min(input.available(), buffer.length); diff --git a/F-Droid/src/org/fdroid/fdroid/net/IconDownloader.java b/F-Droid/src/org/fdroid/fdroid/net/IconDownloader.java index 6ed2458e0..6df702e42 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/IconDownloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/IconDownloader.java @@ -38,8 +38,7 @@ public class IconDownloader extends BaseImageDownloader { ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = downloader.getInputStream(); - int b = -1; - + int b; while ((b = is.read())!=-1) baos.write(b); diff --git a/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java b/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java index 5fc0b0033..0459b3bff 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java +++ b/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java @@ -197,7 +197,8 @@ public class WifiStateChangeService extends Service { InetAddress inetAddress = inetAddresses.nextElement(); if (inetAddress.isLoopbackAddress() || inetAddress instanceof Inet6Address) { continue; - } else if (netIf.getDisplayName().contains("wlan0") + } + if (netIf.getDisplayName().contains("wlan0") || netIf.getDisplayName().contains("eth0") || netIf.getDisplayName().contains("ap0")) { FDroidApp.ipAddressString = inetAddress.getHostAddress();