LEFT | RIGHT |
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); | |
29 | 28 |
30 @Override | 29 @Override |
31 public void onReceive(final Context context, final Intent intent) | 30 public void onReceive(final Context context, final Intent intent) |
32 { | 31 { |
33 final String action = intent.getAction(); | 32 final String action = intent.getAction(); |
34 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
s(context); | 33 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference
s(context); |
35 boolean enabled = prefs.getBoolean(context.getString(R.string.pref_enabled),
false); | 34 boolean enabled = prefs.getBoolean(context.getString(R.string.pref_enabled),
false); |
36 boolean proxyenabled = prefs.getBoolean(context.getString(R.string.pref_prox
yenabled), true); | 35 boolean proxyenabled = prefs.getBoolean(context.getString(R.string.pref_prox
yenabled), true); |
37 final boolean autoconfigured = prefs.getBoolean(context.getString(R.string.p
ref_proxyautoconfigured), false); | 36 final boolean autoconfigured = prefs.getBoolean(context.getString(R.string.p
ref_proxyautoconfigured), false); |
38 if (Intent.ACTION_PACKAGE_REPLACED.equals(action)) | 37 if (Intent.ACTION_PACKAGE_REPLACED.equals(action)) |
39 { | 38 { |
40 final String pkg = context.getApplicationInfo().packageName; | 39 final String pkg = context.getApplicationInfo().packageName; |
41 final boolean us = pkg.equals(intent.getData().getSchemeSpecificPart()); | 40 final boolean us = pkg.equals(intent.getData().getSchemeSpecificPart()); |
42 enabled &= us; | 41 enabled &= us; |
43 proxyenabled &= us; | 42 proxyenabled &= us; |
44 } | 43 } |
45 if (Intent.ACTION_BOOT_COMPLETED.equals(action)) | 44 if (Intent.ACTION_BOOT_COMPLETED.equals(action)) |
46 { | 45 { |
47 final boolean startAtBoot = prefs.getBoolean(context.getString(R.string.pr
ef_startatboot), | 46 final boolean startAtBoot = prefs.getBoolean(context.getString(R.string.pr
ef_startatboot), context.getResources().getBoolean(R.bool.def_startatboot)); |
48 context.getResources().getBoolean(R.bool.def_startatboot)); | |
49 enabled &= startAtBoot; | 47 enabled &= startAtBoot; |
50 proxyenabled &= startAtBoot; | 48 proxyenabled &= startAtBoot; |
51 } | 49 } |
52 if (enabled) | 50 if (enabled) |
53 { | 51 { |
54 final AdblockPlus application = AdblockPlus.getApplication(); | 52 final AdblockPlus application = AdblockPlus.getApplication(); |
55 application.setFilteringEnabled(true); | 53 application.setFilteringEnabled(true); |
56 application.startEngine(); | 54 application.startEngine(); |
57 } | 55 } |
58 if (enabled || (proxyenabled && !autoconfigured)) | 56 if (enabled || (proxyenabled && !autoconfigured)) |
59 { | |
60 context.startService(new Intent(context, ProxyService.class)); | 57 context.startService(new Intent(context, ProxyService.class)); |
61 } | |
62 } | 58 } |
| 59 |
63 } | 60 } |
LEFT | RIGHT |