OLD | NEW |
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 |
(...skipping 15 matching lines...) Expand all Loading... |
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 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
28 | 28 |
29 import android.content.ContentProvider; | 29 import android.content.ContentProvider; |
30 import android.content.ContentValues; | 30 import android.content.ContentValues; |
31 import android.content.Intent; | 31 import android.content.Intent; |
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.support.annotation.NonNull; |
36 import android.util.Log; | 37 import android.util.Log; |
37 | 38 |
38 public class ContentBlockerContentProvider extends ContentProvider | 39 public class ContentBlockerContentProvider extends ContentProvider |
39 { | 40 { |
40 private static final String TAG = ContentBlockerContentProvider.class.getSimpl
eName(); | 41 private static final String TAG = ContentBlockerContentProvider.class.getSimpl
eName(); |
41 | 42 |
42 @Override | 43 @Override |
43 public Bundle call(String method, String arg, Bundle extras) | 44 public Bundle call(@NonNull String method, String arg, Bundle extras) |
44 { | 45 { |
45 // 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 |
46 // use encryption | 47 // use encryption |
47 return null; | 48 return null; |
48 } | 49 } |
49 | 50 |
50 private void setApplicationActivated() | 51 private void setApplicationActivated() |
51 { | 52 { |
52 final boolean applicationActivated = SharedPrefsUtils.getBoolean( | 53 final boolean applicationActivated = SharedPrefsUtils.getBoolean( |
53 this.getContext(), R.string.key_application_activated, false); | 54 this.getContext(), R.string.key_application_activated, false); |
54 | 55 |
55 if (!applicationActivated) | 56 if (!applicationActivated) |
56 { | 57 { |
57 SharedPrefsUtils.putBoolean(this.getContext(), R.string.key_application_ac
tivated, true); | 58 SharedPrefsUtils.putBoolean(this.getContext(), R.string.key_application_ac
tivated, true); |
58 } | 59 } |
59 } | 60 } |
60 | 61 |
61 @Override | 62 @Override |
62 public ParcelFileDescriptor openFile(final Uri uri, final String mode) | 63 public ParcelFileDescriptor openFile(@NonNull final Uri uri, @NonNull final St
ring mode) |
63 throws FileNotFoundException | 64 throws FileNotFoundException |
64 { | 65 { |
65 try | 66 try |
66 { | 67 { |
67 this.setApplicationActivated(); | 68 this.setApplicationActivated(); |
68 Log.d(TAG, "Writing filters..."); | 69 Log.d(TAG, "Writing filters..."); |
69 final File filterFile = Engine.getOrCreateCachedFilterFile(getContext()); | 70 final File filterFile = Engine.getOrCreateCachedFilterFile(getContext()); |
70 Log.d(TAG, "Delivering filters..."); | 71 Log.d(TAG, "Delivering filters..."); |
71 return ParcelFileDescriptor.open(filterFile, ParcelFileDescriptor.MODE_REA
D_ONLY); | 72 return ParcelFileDescriptor.open(filterFile, ParcelFileDescriptor.MODE_REA
D_ONLY); |
72 } | 73 } |
73 catch (IOException e) | 74 catch (IOException e) |
74 { | 75 { |
75 Log.e(TAG, "File creation failed: " + e.getMessage(), e); | 76 Log.e(TAG, "File creation failed: " + e.getMessage(), e); |
76 return null; | 77 return null; |
77 } | 78 } |
78 } | 79 } |
79 | 80 |
80 @Override | 81 @Override |
81 public boolean onCreate() | 82 public boolean onCreate() |
82 { | 83 { |
83 Log.i(TAG, "onCreate() called"); | 84 Log.i(TAG, "onCreate() called"); |
84 getContext().startService(new Intent(getContext(), EngineService.class)); | 85 getContext().startService(new Intent(getContext(), EngineService.class)); |
85 Log.i(TAG, "Requested service startup"); | 86 Log.i(TAG, "Requested service startup"); |
86 return true; | 87 return true; |
87 } | 88 } |
88 | 89 |
89 @Override | 90 @Override |
90 public Cursor query(final Uri uri, final String[] projection, final String sel
ection, | 91 public Cursor query(@NonNull final Uri uri, final String[] projection, final S
tring selection, |
91 final String[] selectionArgs, final String sortOrder) | 92 final String[] selectionArgs, final String sortOrder) |
92 { | 93 { |
93 return null; | 94 return null; |
94 } | 95 } |
95 | 96 |
96 @Override | 97 @Override |
97 public String getType(final Uri uri) | 98 public String getType(@NonNull final Uri uri) |
98 { | 99 { |
99 return null; | 100 return null; |
100 } | 101 } |
101 | 102 |
102 @Override | 103 @Override |
103 public Uri insert(final Uri uri, final ContentValues values) | 104 public Uri insert(@NonNull final Uri uri, final ContentValues values) |
104 { | 105 { |
105 return null; | 106 return null; |
106 } | 107 } |
107 | 108 |
108 @Override | 109 @Override |
109 public int delete(final Uri uri, final String selection, final String[] select
ionArgs) | 110 public int delete(@NonNull final Uri uri, final String selection, final String
[] selectionArgs) |
110 { | 111 { |
111 return 0; | 112 return 0; |
112 } | 113 } |
113 | 114 |
114 @Override | 115 @Override |
115 public int update(final Uri uri, final ContentValues values, final String sele
ction, | 116 public int update(@NonNull final Uri uri, final ContentValues values, final St
ring selection, |
116 final String[] selectionArgs) | 117 final String[] selectionArgs) |
117 { | 118 { |
118 return 0; | 119 return 0; |
119 } | 120 } |
120 } | 121 } |
OLD | NEW |