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

Side by Side Diff: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/ContentBlockerContentProvider.java

Issue 29603697: Issue 5931 - Create tests for util package (Closed)
Patch Set: Created Nov. 10, 2017, 2:23 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
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 package org.adblockplus.sbrowser.contentblocker;
19
20 import java.io.File;
21 import java.io.FileNotFoundException;
22 import java.io.IOException;
23
24 import org.adblockplus.adblockplussbrowser.R;
25 import org.adblockplus.sbrowser.contentblocker.engine.Engine;
26 import org.adblockplus.sbrowser.contentblocker.engine.EngineService;
27 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils;
28
29 import android.content.ContentProvider;
30 import android.content.ContentValues;
31 import android.content.Intent;
32 import android.database.Cursor;
33 import android.net.Uri;
34 import android.os.Bundle;
35 import android.os.ParcelFileDescriptor;
36 import android.support.annotation.NonNull;
37 import android.util.Log;
38
39 public class ContentBlockerContentProvider extends ContentProvider
40 {
41 private static final String TAG = ContentBlockerContentProvider.class.getSimpl eName();
42
43 @Override
44 public Bundle call(@NonNull String method, String arg, Bundle extras)
45 {
46 // As of SBC interface v1.4 we return `null` here to signal that we do not
47 // use encryption
48 return null;
49 }
50
51 private void setApplicationActivated()
52 {
53 final boolean applicationActivated = SharedPrefsUtils.getBoolean(
54 this.getContext(), R.string.key_application_activated, false);
55
56 if (!applicationActivated)
57 {
58 SharedPrefsUtils.putBoolean(this.getContext(), R.string.key_application_ac tivated, true);
59 }
60 }
61
62 @Override
63 public ParcelFileDescriptor openFile(@NonNull final Uri uri, @NonNull final St ring mode)
64 throws FileNotFoundException
65 {
66 try
67 {
68 this.setApplicationActivated();
69 Log.d(TAG, "Writing filters...");
70 final File filterFile = Engine.getOrCreateCachedFilterFile(getContext());
71 Log.d(TAG, "Delivering filters...");
72 return ParcelFileDescriptor.open(filterFile, ParcelFileDescriptor.MODE_REA D_ONLY);
73 }
74 catch (IOException e)
75 {
76 Log.e(TAG, "File creation failed: " + e.getMessage(), e);
77 return null;
78 }
79 }
80
81 @Override
82 public boolean onCreate()
83 {
84 Log.i(TAG, "onCreate() called");
85 getContext().startService(new Intent(getContext(), EngineService.class));
86 Log.i(TAG, "Requested service startup");
87 return true;
88 }
89
90 @Override
91 public Cursor query(@NonNull final Uri uri, final String[] projection, final S tring selection,
92 final String[] selectionArgs, final String sortOrder)
93 {
94 return null;
95 }
96
97 @Override
98 public String getType(@NonNull final Uri uri)
99 {
100 return null;
101 }
102
103 @Override
104 public Uri insert(@NonNull final Uri uri, final ContentValues values)
105 {
106 return null;
107 }
108
109 @Override
110 public int delete(@NonNull final Uri uri, final String selection, final String [] selectionArgs)
111 {
112 return 0;
113 }
114
115 @Override
116 public int update(@NonNull final Uri uri, final ContentValues values, final St ring selection,
117 final String[] selectionArgs)
118 {
119 return 0;
120 }
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld