Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/org/adblockplus/android/updater/UpdaterService.java

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Left Patch Set: Fixed leftover first-batch review issues. Created April 16, 2014, 5:51 p.m.
Right Patch Set: Even more review issues fixed. Created April 28, 2014, 10:18 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 private File updateDir; 49 private File updateDir;
50 50
51 @Override 51 @Override
52 public void onCreate() 52 public void onCreate()
53 { 53 {
54 super.onCreate(); 54 super.onCreate();
55 // Use common Android path for downloads 55 // Use common Android path for downloads
56 updateDir = new File(Environment.getExternalStorageDirectory().getPath(), "d ownloads"); 56 updateDir = new File(Environment.getExternalStorageDirectory().getPath(), "d ownloads");
57 } 57 }
58 58
59 @SuppressWarnings("deprecation")
60 @Override 59 @Override
61 public void onStart(final Intent intent, final int startId) 60 public void onStart(final Intent intent, final int startId)
62 { 61 {
63 super.onStart(intent, startId); 62 super.onStart(intent, startId);
64 63
65 // Stop if media not available 64 // Stop if media not available
66 if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ) 65 if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) )
67 { 66 {
68 stopSelf(); 67 stopSelf();
69 return; 68 return;
(...skipping 20 matching lines...) Expand all
90 private final int notificationId = R.string.app_name + 2; 89 private final int notificationId = R.string.app_name + 2;
91 90
92 public DownloadTask(final Context context) 91 public DownloadTask(final Context context)
93 { 92 {
94 this.context = context; 93 this.context = context;
95 notificationManager = (NotificationManager) context.getSystemService(Conte xt.NOTIFICATION_SERVICE); 94 notificationManager = (NotificationManager) context.getSystemService(Conte xt.NOTIFICATION_SERVICE);
96 notification = new Notification(); 95 notification = new Notification();
97 contentIntent = PendingIntent.getActivity(context, 0, new Intent(), Pendin gIntent.FLAG_UPDATE_CURRENT); 96 contentIntent = PendingIntent.getActivity(context, 0, new Intent(), Pendin gIntent.FLAG_UPDATE_CURRENT);
98 } 97 }
99 98
100 @SuppressWarnings("deprecation")
101 @Override 99 @Override
102 protected void onPreExecute() 100 protected void onPreExecute()
103 { 101 {
104 notification.flags |= Notification.FLAG_ONGOING_EVENT; 102 notification.flags |= Notification.FLAG_ONGOING_EVENT;
105 notification.when = 0; 103 notification.when = 0;
106 notification.icon = R.drawable.ic_stat_download; 104 notification.icon = R.drawable.ic_stat_download;
107 notification.setLatestEventInfo(context, getString(R.string.app_name), Str ing.format(getString(R.string.msg_update_downloading), 0), contentIntent); 105 notification.setLatestEventInfo(context, getString(R.string.app_name), Str ing.format(getString(R.string.msg_update_downloading), 0), contentIntent);
108 notificationManager.notify(notificationId, notification); 106 notificationManager.notify(notificationId, notification);
109 } 107 }
110 108
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 input.close(); 155 input.close();
158 return updateFile.getAbsolutePath(); 156 return updateFile.getAbsolutePath();
159 } 157 }
160 catch (final Exception e) 158 catch (final Exception e)
161 { 159 {
162 Log.e(TAG, "Download error", e); 160 Log.e(TAG, "Download error", e);
163 return null; 161 return null;
164 } 162 }
165 } 163 }
166 164
167 @SuppressWarnings("deprecation")
168 @Override 165 @Override
169 protected void onProgressUpdate(final Integer... progress) 166 protected void onProgressUpdate(final Integer... progress)
170 { 167 {
171 notification.setLatestEventInfo(context, getString(R.string.app_name), Str ing.format(getString(R.string.msg_update_downloading), progress[0]), contentInte nt); 168 notification.setLatestEventInfo(context, getString(R.string.app_name), Str ing.format(getString(R.string.msg_update_downloading), progress[0]), contentInte nt);
172 notificationManager.notify(notificationId, notification); 169 notificationManager.notify(notificationId, notification);
173 } 170 }
174 171
175 @SuppressWarnings("deprecation")
176 @Override 172 @Override
177 protected void onPostExecute(final String result) 173 protected void onPostExecute(final String result)
178 { 174 {
179 notificationManager.cancel(notificationId); 175 notificationManager.cancel(notificationId);
180 if (result != null) 176 if (result != null)
181 { 177 {
182 final Notification notification = new Notification(); 178 final Notification notification = new Notification();
183 notification.icon = R.drawable.ic_stat_download; 179 notification.icon = R.drawable.ic_stat_download;
184 notification.when = System.currentTimeMillis(); 180 notification.when = System.currentTimeMillis();
185 notification.flags |= Notification.FLAG_AUTO_CANCEL; 181 notification.flags |= Notification.FLAG_AUTO_CANCEL;
186 final Intent intent = new Intent(context, UpdaterActivity.class).addFlag s(Intent.FLAG_ACTIVITY_NEW_TASK); 182 final Intent intent = new Intent(context, UpdaterActivity.class).addFlag s(Intent.FLAG_ACTIVITY_NEW_TASK);
187 intent.setAction("update"); 183 intent.setAction("update");
188 intent.putExtra("path", result); 184 intent.putExtra("path", result);
189 final PendingIntent contentIntent = PendingIntent.getActivity(context, 0 , intent, PendingIntent.FLAG_UPDATE_CURRENT); 185 final PendingIntent contentIntent = PendingIntent.getActivity(context, 0 , intent, PendingIntent.FLAG_UPDATE_CURRENT);
190 notification.setLatestEventInfo(context, context.getText(R.string.app_na me), context.getString(R.string.msg_update_ready), contentIntent); 186 notification.setLatestEventInfo(context, context.getText(R.string.app_na me), context.getString(R.string.msg_update_ready), contentIntent);
191 notificationManager.notify(R.string.app_name + 1, notification); 187 notificationManager.notify(R.string.app_name + 1, notification);
192 } 188 }
193 } 189 }
194 } 190 }
195 } 191 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld