OLD | NEW |
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 android.content.BroadcastReceiver; | 20 import android.content.BroadcastReceiver; |
21 import android.content.Context; | 21 import android.content.Context; |
22 import android.content.Intent; | 22 import android.content.Intent; |
23 import android.content.SharedPreferences; | 23 import android.content.SharedPreferences; |
24 import android.preference.PreferenceManager; | 24 import android.preference.PreferenceManager; |
25 | 25 |
26 public class Starter extends BroadcastReceiver | 26 public class Starter extends BroadcastReceiver |
27 { | 27 { |
| 28 private final static String TAG = Utils.getTag(BroadcastReceiver.class); |
28 | 29 |
29 @Override | 30 @Override |
30 public void onReceive(Context context, Intent intent) | 31 public void onReceive(final Context context, final Intent intent) |
31 { | 32 { |
32 String action = intent.getAction(); | 33 final String action = intent.getAction(); |
33 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(cont
ext); | 34 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
s(context); |
34 boolean enabled = prefs.getBoolean(context.getString(R.string.pref_enabled),
false); | 35 boolean enabled = prefs.getBoolean(context.getString(R.string.pref_enabled),
false); |
35 boolean proxyenabled = prefs.getBoolean(context.getString(R.string.pref_prox
yenabled), true); | 36 boolean proxyenabled = prefs.getBoolean(context.getString(R.string.pref_prox
yenabled), true); |
36 boolean autoconfigured = prefs.getBoolean(context.getString(R.string.pref_pr
oxyautoconfigured), false); | 37 final boolean autoconfigured = prefs.getBoolean(context.getString(R.string.p
ref_proxyautoconfigured), false); |
37 if (Intent.ACTION_PACKAGE_REPLACED.equals(action)) | 38 if (Intent.ACTION_PACKAGE_REPLACED.equals(action)) |
38 { | 39 { |
39 String pkg = context.getApplicationInfo().packageName; | 40 final String pkg = context.getApplicationInfo().packageName; |
40 boolean us = pkg.equals(intent.getData().getSchemeSpecificPart()); | 41 final boolean us = pkg.equals(intent.getData().getSchemeSpecificPart()); |
41 enabled &= us; | 42 enabled &= us; |
42 proxyenabled &= us; | 43 proxyenabled &= us; |
43 } | 44 } |
44 if (Intent.ACTION_BOOT_COMPLETED.equals(action)) | 45 if (Intent.ACTION_BOOT_COMPLETED.equals(action)) |
45 { | 46 { |
46 boolean startAtBoot = prefs.getBoolean(context.getString(R.string.pref_sta
rtatboot), context.getResources().getBoolean(R.bool.def_startatboot)); | 47 final boolean startAtBoot = prefs.getBoolean(context.getString(R.string.pr
ef_startatboot), |
| 48 context.getResources().getBoolean(R.bool.def_startatboot)); |
47 enabled &= startAtBoot; | 49 enabled &= startAtBoot; |
48 proxyenabled &= startAtBoot; | 50 proxyenabled &= startAtBoot; |
49 } | 51 } |
50 if (enabled) | 52 if (enabled) |
51 { | 53 { |
52 AdblockPlus application = AdblockPlus.getApplication(); | 54 final AdblockPlus application = AdblockPlus.getApplication(); |
53 application.setFilteringEnabled(true); | 55 application.setFilteringEnabled(true); |
54 application.startEngine(); | 56 application.startEngine(); |
55 } | 57 } |
56 if (enabled || (proxyenabled && !autoconfigured)) | 58 if (enabled || (proxyenabled && !autoconfigured)) |
| 59 { |
57 context.startService(new Intent(context, ProxyService.class)); | 60 context.startService(new Intent(context, ProxyService.class)); |
| 61 } |
58 } | 62 } |
59 | |
60 } | 63 } |
OLD | NEW |