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

Side by Side Diff: src/org/adblockplus/android/AdblockPlus.java

Issue 5153282527854592: Issue 98 - Use the libadblockplus update mechanism (Closed)
Patch Set: Only append the revision to the version for devbuilds Created Sept. 26, 2014, 2:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.android; 18 package org.adblockplus.android;
19 19
20 import java.io.BufferedReader; 20 import java.io.BufferedReader;
21 import java.io.File; 21 import java.io.File;
22 import java.io.FileNotFoundException; 22 import java.io.FileNotFoundException;
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.io.InputStream; 24 import java.io.InputStream;
25 import java.io.InputStreamReader; 25 import java.io.InputStreamReader;
26 import java.util.Calendar;
27 import java.util.List; 26 import java.util.List;
28 import java.util.TimeZone;
29 import java.util.regex.Pattern; 27 import java.util.regex.Pattern;
30 28
31 import org.adblockplus.android.updater.AlarmReceiver;
32 import org.adblockplus.libadblockplus.FilterEngine.ContentType; 29 import org.adblockplus.libadblockplus.FilterEngine.ContentType;
33 import org.apache.commons.lang.StringUtils; 30 import org.apache.commons.lang.StringUtils;
34 31
35 import android.app.ActivityManager; 32 import android.app.ActivityManager;
36 import android.app.ActivityManager.RunningServiceInfo; 33 import android.app.ActivityManager.RunningServiceInfo;
37 import android.app.AlarmManager;
38 import android.app.Application; 34 import android.app.Application;
39 import android.app.PendingIntent;
40 import android.content.Context; 35 import android.content.Context;
41 import android.content.Intent; 36 import android.content.Intent;
42 import android.content.SharedPreferences; 37 import android.content.SharedPreferences;
43 import android.content.SharedPreferences.Editor; 38 import android.content.SharedPreferences.Editor;
44 import android.content.pm.PackageInfo; 39 import android.content.pm.PackageInfo;
45 import android.content.pm.PackageManager; 40 import android.content.pm.PackageManager;
46 import android.content.pm.PackageManager.NameNotFoundException; 41 import android.content.pm.PackageManager.NameNotFoundException;
47 import android.net.ConnectivityManager; 42 import android.net.ConnectivityManager;
48 import android.net.NetworkInfo; 43 import android.net.NetworkInfo;
49 import android.net.Uri; 44 import android.net.Uri;
50 import android.os.Build; 45 import android.os.Build;
51 import android.preference.PreferenceManager; 46 import android.preference.PreferenceManager;
52 import android.provider.Settings; 47 import android.provider.Settings;
53 import android.util.Log; 48 import android.util.Log;
54 49
55 public class AdblockPlus extends Application 50 public class AdblockPlus extends Application
56 { 51 {
57 private static final String TAG = Utils.getTag(AdblockPlus.class); 52 private static final String TAG = Utils.getTag(AdblockPlus.class);
58 53
59 private static final Pattern RE_JS = Pattern.compile("\\.js$", Pattern.CASE_IN SENSITIVE); 54 private static final Pattern RE_JS = Pattern.compile("\\.js$", Pattern.CASE_IN SENSITIVE);
60 private static final Pattern RE_CSS = Pattern.compile("\\.css$", Pattern.CASE_ INSENSITIVE); 55 private static final Pattern RE_CSS = Pattern.compile("\\.css$", Pattern.CASE_ INSENSITIVE);
61 private static final Pattern RE_IMAGE = Pattern.compile("\\.(?:gif|png|jpe?g|b mp|ico)$", Pattern.CASE_INSENSITIVE); 56 private static final Pattern RE_IMAGE = Pattern.compile("\\.(?:gif|png|jpe?g|b mp|ico)$", Pattern.CASE_INSENSITIVE);
62 private static final Pattern RE_FONT = Pattern.compile("\\.(?:ttf|woff)$", Pat tern.CASE_INSENSITIVE); 57 private static final Pattern RE_FONT = Pattern.compile("\\.(?:ttf|woff)$", Pat tern.CASE_INSENSITIVE);
63 private static final Pattern RE_HTML = Pattern.compile("\\.html?$", Pattern.CA SE_INSENSITIVE); 58 private static final Pattern RE_HTML = Pattern.compile("\\.html?$", Pattern.CA SE_INSENSITIVE);
64 59
65 /** 60 /**
66 * Update notification id.
67 */
68 public static final int UPDATE_NOTIFICATION_ID = R.string.app_name + 1;
69 /**
70 * Broadcasted when filtering is enabled or disabled. 61 * Broadcasted when filtering is enabled or disabled.
71 */ 62 */
72 public static final String BROADCAST_FILTERING_CHANGE = "org.adblockplus.andro id.filtering.status"; 63 public static final String BROADCAST_FILTERING_CHANGE = "org.adblockplus.andro id.filtering.status";
73 /** 64 /**
74 * Broadcasted when subscription status changes. 65 * Broadcasted when subscription status changes.
75 */ 66 */
76 public static final String BROADCAST_SUBSCRIPTION_STATUS = "org.adblockplus.an droid.subscription.status"; 67 public static final String BROADCAST_SUBSCRIPTION_STATUS = "org.adblockplus.an droid.subscription.status";
77 /** 68 /**
78 * Cached list of recommended subscriptions. 69 * Cached list of recommended subscriptions.
79 */ 70 */
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 408 }
418 409
419 /** 410 /**
420 * Initiates immediate interactive check for available update. 411 * Initiates immediate interactive check for available update.
421 */ 412 */
422 public void checkUpdates() 413 public void checkUpdates()
423 { 414 {
424 abpEngine.checkForUpdates(); 415 abpEngine.checkForUpdates();
425 } 416 }
426 417
427 /**
428 * Sets Alarm to call updater after specified number of minutes or after one
429 * day if
430 * minutes are set to 0.
431 *
432 * @param minutes
433 * number of minutes to wait
434 */
435 public void scheduleUpdater(final int minutes)
436 {
437 final Calendar updateTime = Calendar.getInstance();
438
439 if (minutes == 0)
440 {
441 // Start update checks at 10:00 GMT...
442 updateTime.setTimeZone(TimeZone.getTimeZone("GMT"));
443 updateTime.set(Calendar.HOUR_OF_DAY, 10);
444 updateTime.set(Calendar.MINUTE, 0);
445 // ...next day
446 updateTime.add(Calendar.HOUR_OF_DAY, 24);
447 // Spread out the “mass downloading” for 6 hours
448 updateTime.add(Calendar.MINUTE, (int) (Math.random() * 60 * 6));
449 }
450 else
451 {
452 updateTime.add(Calendar.MINUTE, minutes);
453 }
454
455 final Intent updater = new Intent(this, AlarmReceiver.class);
456 final PendingIntent recurringUpdate = PendingIntent.getBroadcast(this, 0, up dater, PendingIntent.FLAG_CANCEL_CURRENT);
457 // Set non-waking alarm
458 final AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SE RVICE);
459 alarms.set(AlarmManager.RTC, updateTime.getTimeInMillis(), recurringUpdate);
460 }
461
462 @Override 418 @Override
463 public void onCreate() 419 public void onCreate()
464 { 420 {
465 super.onCreate(); 421 super.onCreate();
466 instance = this; 422 instance = this;
467 423
468 // Check for crash report 424 // Check for crash report
469 try 425 try
470 { 426 {
471 final InputStreamReader reportFile = new InputStreamReader(openFileInput(C rashHandler.REPORT_FILE)); 427 final InputStreamReader reportFile = new InputStreamReader(openFileInput(C rashHandler.REPORT_FILE));
(...skipping 20 matching lines...) Expand all
492 { 448 {
493 // ignore 449 // ignore
494 } 450 }
495 catch (final IOException e) 451 catch (final IOException e)
496 { 452 {
497 Log.e(TAG, e.getMessage(), e); 453 Log.e(TAG, e.getMessage(), e);
498 } 454 }
499 455
500 // Set crash handler 456 // Set crash handler
501 Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this)); 457 Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this));
502
503 // Initiate update check
504 scheduleUpdater(0);
505 } 458 }
506 } 459 }
OLDNEW
« no previous file with comments | « src/org/adblockplus/android/ABPEngine.java ('k') | src/org/adblockplus/android/AndroidUpdateAvailableCallback.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld