LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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.sbrowser.contentblocker; | 18 package org.adblockplus.sbrowser.contentblocker; |
19 | 19 |
20 import java.io.File; | 20 import java.io.File; |
21 import java.io.FileNotFoundException; | 21 import java.io.FileNotFoundException; |
22 import java.io.IOException; | 22 import java.io.IOException; |
23 | 23 |
24 import org.adblockplus.adblockplussbrowser.R; | 24 import org.adblockplus.adblockplussbrowser.R; |
25 import org.adblockplus.sbrowser.contentblocker.engine.Engine; | 25 import org.adblockplus.sbrowser.contentblocker.engine.Engine; |
26 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; | 26 import org.adblockplus.sbrowser.contentblocker.engine.EngineService; |
| 27 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
27 | 28 |
28 import android.content.ContentProvider; | 29 import android.content.ContentProvider; |
29 import android.content.ContentValues; | 30 import android.content.ContentValues; |
30 import android.content.Intent; | 31 import android.content.Intent; |
31 import android.content.SharedPreferences; | |
32 import android.database.Cursor; | 32 import android.database.Cursor; |
33 import android.net.Uri; | 33 import android.net.Uri; |
34 import android.os.Bundle; | 34 import android.os.Bundle; |
35 import android.os.ParcelFileDescriptor; | 35 import android.os.ParcelFileDescriptor; |
36 import android.preference.PreferenceManager; | |
37 import android.support.annotation.NonNull; | 36 import android.support.annotation.NonNull; |
38 import android.util.Log; | 37 import android.util.Log; |
39 | 38 |
40 public class ContentBlockerContentProvider extends ContentProvider | 39 public class ContentBlockerContentProvider extends ContentProvider |
41 { | 40 { |
42 private static final String TAG = ContentBlockerContentProvider.class.getSimpl
eName(); | 41 private static final String TAG = ContentBlockerContentProvider.class.getSimpl
eName(); |
43 | 42 |
44 @Override | 43 @Override |
45 public Bundle call(@NonNull String method, String arg, Bundle extras) | 44 public Bundle call(@NonNull String method, String arg, Bundle extras) |
46 { | 45 { |
47 // As of SBC interface v1.4 we return `null` here to signal that we do not | 46 // As of SBC interface v1.4 we return `null` here to signal that we do not |
48 // use encryption | 47 // use encryption |
49 return null; | 48 return null; |
50 } | 49 } |
51 | 50 |
52 private static boolean getBooleanPref(final SharedPreferences prefs, final Str
ing key, | |
53 final boolean defValue) | |
54 { | |
55 try | |
56 { | |
57 return prefs.getBoolean(key, defValue); | |
58 } | |
59 catch (final Throwable t) | |
60 { | |
61 return defValue; | |
62 } | |
63 } | |
64 | |
65 private void setApplicationActivated() | 51 private void setApplicationActivated() |
66 { | 52 { |
67 final SharedPreferences prefs = PreferenceManager | 53 final boolean applicationActivated = SharedPrefsUtils.getBoolean( |
68 .getDefaultSharedPreferences(this.getContext().getApplicationContext()); | 54 this.getContext(), R.string.key_application_activated, false); |
69 final String key = this.getContext().getString(R.string.key_application_acti
vated); | 55 |
70 final boolean applicationActived = getBooleanPref(prefs, key, false); | 56 if (!applicationActivated) |
71 if (!applicationActived) | |
72 { | 57 { |
73 prefs.edit() | 58 SharedPrefsUtils.putBoolean(this.getContext(), R.string.key_application_ac
tivated, true); |
74 .putBoolean(key, true) | |
75 .commit(); | |
76 } | 59 } |
77 } | 60 } |
78 | 61 |
79 @Override | 62 @Override |
80 public ParcelFileDescriptor openFile(@NonNull final Uri uri, @NonNull final St
ring mode) | 63 public ParcelFileDescriptor openFile(@NonNull final Uri uri, @NonNull final St
ring mode) |
81 throws FileNotFoundException | 64 throws FileNotFoundException |
82 { | 65 { |
83 try | 66 try |
84 { | 67 { |
85 this.setApplicationActivated(); | 68 this.setApplicationActivated(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 return 0; | 112 return 0; |
130 } | 113 } |
131 | 114 |
132 @Override | 115 @Override |
133 public int update(@NonNull final Uri uri, final ContentValues values, final St
ring selection, | 116 public int update(@NonNull final Uri uri, final ContentValues values, final St
ring selection, |
134 final String[] selectionArgs) | 117 final String[] selectionArgs) |
135 { | 118 { |
136 return 0; | 119 return 0; |
137 } | 120 } |
138 } | 121 } |
LEFT | RIGHT |