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

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

Issue 29355386: Issue 4463 - Content blocker unavailable error message (Closed)
Patch Set: Adjusting indentation Created Oct. 7, 2016, 2:38 a.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
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 27
28 import android.content.ContentProvider; 28 import android.content.ContentProvider;
29 import android.content.ContentValues; 29 import android.content.ContentValues;
30 import android.content.Intent;
30 import android.content.SharedPreferences; 31 import android.content.SharedPreferences;
31 import android.database.Cursor; 32 import android.database.Cursor;
32 import android.net.Uri; 33 import android.net.Uri;
33 import android.os.Bundle; 34 import android.os.Bundle;
34 import android.os.ParcelFileDescriptor; 35 import android.os.ParcelFileDescriptor;
35 import android.preference.PreferenceManager; 36 import android.preference.PreferenceManager;
36 import android.util.Log; 37 import android.util.Log;
37 38
38 public class ContentBlockerContentProvider extends ContentProvider implements 39 public class ContentBlockerContentProvider extends ContentProvider
39 EngineService.OnEngineCreatedCallback
40 { 40 {
41 private static final String TAG = ContentBlockerContentProvider.class.getSimpl eName(); 41 private static final String TAG = ContentBlockerContentProvider.class.getSimpl eName();
42 private volatile Engine engine = null;
43 private volatile boolean engineInitDone = false;
44 42
45 @Override 43 @Override
46 public Bundle call(String method, String arg, Bundle extras) 44 public Bundle call(String method, String arg, Bundle extras)
47 { 45 {
48 // 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
49 // use encryption 47 // use encryption
50 return null; 48 return null;
51 } 49 }
52 50
53 private static boolean getBooleanPref(final SharedPreferences prefs, final Str ing key, 51 private static boolean getBooleanPref(final SharedPreferences prefs, final Str ing key,
(...skipping 20 matching lines...) Expand all
74 prefs.edit() 72 prefs.edit()
75 .putBoolean(key, true) 73 .putBoolean(key, true)
76 .commit(); 74 .commit();
77 } 75 }
78 } 76 }
79 77
80 @Override 78 @Override
81 public ParcelFileDescriptor openFile(final Uri uri, final String mode) 79 public ParcelFileDescriptor openFile(final Uri uri, final String mode)
82 throws FileNotFoundException 80 throws FileNotFoundException
83 { 81 {
84 if (!this.engineInitDone)
85 {
86 Log.i(TAG, "Engine not ready yet, waiting...");
87 while (!this.engineInitDone)
88 {
89 try
90 {
91 Thread.sleep(10);
92 }
93 catch (InterruptedException e)
94 {
95 Log.e(TAG, "Interrupted: " + e.getMessage(), e);
96 return null;
97 }
98 }
99 Log.i(TAG, "Engine ready");
100 }
101
102 if (this.engine == null)
103 {
104 Log.e(TAG, "Engine failed to initialize");
105 return null;
106 }
107
108 try 82 try
109 { 83 {
110 this.setApplicationActivated(); 84 this.setApplicationActivated();
111 Log.d(TAG, "Writing filters..."); 85 Log.d(TAG, "Writing filters...");
112 final File filterFile = this.engine.createAndWriteFile(); 86 final File filterFile = Engine.getOrCreateCachedFilterFile(getContext());
113 Log.d(TAG, "Delivering filters..."); 87 Log.d(TAG, "Delivering filters...");
114 return ParcelFileDescriptor.open(filterFile, ParcelFileDescriptor.MODE_REA D_ONLY); 88 return ParcelFileDescriptor.open(filterFile, ParcelFileDescriptor.MODE_REA D_ONLY);
115 } 89 }
116 catch (IOException e) 90 catch (IOException e)
117 { 91 {
118 Log.e(TAG, "File creation failed: " + e.getMessage(), e); 92 Log.e(TAG, "File creation failed: " + e.getMessage(), e);
119 return null; 93 return null;
120 } 94 }
121 } 95 }
122 96
123 @Override 97 @Override
124 public boolean onCreate() 98 public boolean onCreate()
125 { 99 {
126 Log.i(TAG, "onCreate() called"); 100 Log.i(TAG, "onCreate() called");
127 EngineService.startService(this.getContext().getApplicationContext(), this, false); 101 getContext().startService(new Intent(getContext(), EngineService.class));
128 Log.i(TAG, "Requested service startup"); 102 Log.i(TAG, "Requested service startup");
129 return true; 103 return true;
130 } 104 }
131 105
132 @Override 106 @Override
133 public Cursor query(final Uri uri, final String[] projection, final String sel ection, 107 public Cursor query(final Uri uri, final String[] projection, final String sel ection,
134 final String[] selectionArgs, final String sortOrder) 108 final String[] selectionArgs, final String sortOrder)
135 { 109 {
136 return null; 110 return null;
137 } 111 }
(...skipping 15 matching lines...) Expand all
153 { 127 {
154 return 0; 128 return 0;
155 } 129 }
156 130
157 @Override 131 @Override
158 public int update(final Uri uri, final ContentValues values, final String sele ction, 132 public int update(final Uri uri, final ContentValues values, final String sele ction,
159 final String[] selectionArgs) 133 final String[] selectionArgs)
160 { 134 {
161 return 0; 135 return 0;
162 } 136 }
163
164 @Override
165 public void onEngineCreated(Engine engine, boolean success)
166 {
167 Log.i(TAG, "Service started, success: " + success);
168 this.engineInitDone = true;
169 if (success)
170 {
171 this.engine = engine;
172 }
173 }
174 } 137 }
OLDNEW
« no previous file with comments | « res/values/sysstrings.xml ('k') | src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld