Index: src/org/adblockplus/android/updater/UpdaterService.java |
diff --git a/src/org/adblockplus/android/updater/UpdaterService.java b/src/org/adblockplus/android/updater/UpdaterService.java |
index b462d2f925edea19406a580a96e934382834320b..a8760af764202003c8ba0245b6af6521d6d55bab 100644 |
--- a/src/org/adblockplus/android/updater/UpdaterService.java |
+++ b/src/org/adblockplus/android/updater/UpdaterService.java |
@@ -26,6 +26,7 @@ import java.net.URL; |
import java.net.URLConnection; |
import org.adblockplus.android.R; |
+import org.adblockplus.android.Utils; |
import android.app.Notification; |
import android.app.NotificationManager; |
@@ -43,7 +44,7 @@ import android.util.Log; |
*/ |
public class UpdaterService extends Service |
{ |
- private final static String TAG = "UpdaterService"; |
+ private static final String TAG = Utils.getTag(UpdaterService.class); |
private File updateDir; |
@@ -55,8 +56,9 @@ public class UpdaterService extends Service |
updateDir = new File(Environment.getExternalStorageDirectory().getPath(), "downloads"); |
} |
+ @SuppressWarnings("deprecation") |
Felix Dahlke
2014/04/28 07:29:01
As before, not a fan. Also below.
|
@Override |
- public void onStart(Intent intent, int startId) |
+ public void onStart(final Intent intent, final int startId) |
{ |
super.onStart(intent, startId); |
@@ -74,20 +76,20 @@ public class UpdaterService extends Service |
} |
@Override |
- public IBinder onBind(Intent intent) |
+ public IBinder onBind(final Intent intent) |
{ |
return null; |
} |
private class DownloadTask extends AsyncTask<String, Integer, String> |
{ |
- private Context context; |
- private Notification notification; |
- private PendingIntent contentIntent; |
- private NotificationManager notificationManager; |
- private int notificationId = R.string.app_name + 2; |
+ private final Context context; |
+ private final Notification notification; |
+ private final PendingIntent contentIntent; |
+ private final NotificationManager notificationManager; |
+ private final int notificationId = R.string.app_name + 2; |
- public DownloadTask(Context context) |
+ public DownloadTask(final Context context) |
{ |
this.context = context; |
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); |
@@ -95,6 +97,7 @@ public class UpdaterService extends Service |
contentIntent = PendingIntent.getActivity(context, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT); |
} |
+ @SuppressWarnings("deprecation") |
@Override |
protected void onPreExecute() |
{ |
@@ -106,20 +109,20 @@ public class UpdaterService extends Service |
} |
@Override |
- protected String doInBackground(String... sUrl) |
+ protected String doInBackground(final String... sUrl) |
{ |
try |
{ |
// Create connection |
- URL url = new URL(sUrl[0]); |
+ final URL url = new URL(sUrl[0]); |
Log.e(TAG, "D: " + sUrl[0]); |
- URLConnection connection = url.openConnection(); |
+ final URLConnection connection = url.openConnection(); |
connection.connect(); |
- int fileLength = connection.getContentLength(); |
+ final int fileLength = connection.getContentLength(); |
Log.e(TAG, "S: " + fileLength); |
// Check if file already exists |
- File updateFile = new File(updateDir, "AdblockPlus-update.apk"); |
+ final File updateFile = new File(updateDir, "AdblockPlus-update.apk"); |
if (updateFile.exists()) |
{ |
// if (updateFile.length() == fileLength) |
@@ -129,10 +132,10 @@ public class UpdaterService extends Service |
} |
// Download the file |
- InputStream input = new BufferedInputStream(url.openStream()); |
- OutputStream output = new FileOutputStream(updateFile); |
+ final InputStream input = new BufferedInputStream(url.openStream()); |
+ final OutputStream output = new FileOutputStream(updateFile); |
- byte data[] = new byte[1024]; |
+ final byte data[] = new byte[1024]; |
long total = 0; |
int count; |
int progress = 0; |
@@ -141,7 +144,7 @@ public class UpdaterService extends Service |
total += count; |
output.write(data, 0, count); |
- int p = (int) (total * 100 / fileLength); |
+ final int p = (int) (total * 100 / fileLength); |
if (p != progress) |
{ |
publishProgress(p); |
@@ -154,34 +157,36 @@ public class UpdaterService extends Service |
input.close(); |
return updateFile.getAbsolutePath(); |
} |
- catch (Exception e) |
+ catch (final Exception e) |
{ |
Log.e(TAG, "Download error", e); |
return null; |
} |
} |
+ @SuppressWarnings("deprecation") |
@Override |
- protected void onProgressUpdate(Integer... progress) |
+ protected void onProgressUpdate(final Integer... progress) |
{ |
notification.setLatestEventInfo(context, getString(R.string.app_name), String.format(getString(R.string.msg_update_downloading), progress[0]), contentIntent); |
notificationManager.notify(notificationId, notification); |
} |
+ @SuppressWarnings("deprecation") |
@Override |
- protected void onPostExecute(String result) |
+ protected void onPostExecute(final String result) |
{ |
notificationManager.cancel(notificationId); |
if (result != null) |
{ |
- Notification notification = new Notification(); |
+ final Notification notification = new Notification(); |
notification.icon = R.drawable.ic_stat_download; |
notification.when = System.currentTimeMillis(); |
notification.flags |= Notification.FLAG_AUTO_CANCEL; |
- Intent intent = new Intent(context, UpdaterActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
+ final Intent intent = new Intent(context, UpdaterActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
intent.setAction("update"); |
intent.putExtra("path", result); |
- PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); |
+ final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); |
notification.setLatestEventInfo(context, context.getText(R.string.app_name), context.getString(R.string.msg_update_ready), contentIntent); |
notificationManager.notify(R.string.app_name + 1, notification); |
} |