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

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

Issue 29341398: Issue 4041 - Missing engine startup synchronization causing 'blocker not available' message (Closed)
Patch Set: Created May 13, 2016, 10:42 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
« no previous file with comments | « no previous file | src/org/adblockplus/sbrowser/contentblocker/engine/EngineService.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 21 matching lines...) Expand all
32 import android.net.Uri; 32 import android.net.Uri;
33 import android.os.Bundle; 33 import android.os.Bundle;
34 import android.os.ParcelFileDescriptor; 34 import android.os.ParcelFileDescriptor;
35 import android.preference.PreferenceManager; 35 import android.preference.PreferenceManager;
36 import android.util.Log; 36 import android.util.Log;
37 37
38 public class ContentBlockerContentProvider extends ContentProvider implements 38 public class ContentBlockerContentProvider extends ContentProvider implements
39 EngineService.OnEngineCreatedCallback 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 Engine engine = null; 42 private volatile Engine engine = null;
43 private volatile boolean engineInitDone = false;
43 44
44 @Override 45 @Override
45 public Bundle call(String method, String arg, Bundle extras) 46 public Bundle call(String method, String arg, Bundle extras)
46 { 47 {
47 // As of SBC interface v1.4 we return `null` here to signal that we do not 48 // As of SBC interface v1.4 we return `null` here to signal that we do not
48 // use encryption 49 // use encryption
49 return null; 50 return null;
50 } 51 }
51 52
52 private static boolean getBooleanPref(final SharedPreferences prefs, final Str ing key, 53 private static boolean getBooleanPref(final SharedPreferences prefs, final Str ing key,
(...skipping 20 matching lines...) Expand all
73 prefs.edit() 74 prefs.edit()
74 .putBoolean(key, true) 75 .putBoolean(key, true)
75 .commit(); 76 .commit();
76 } 77 }
77 } 78 }
78 79
79 @Override 80 @Override
80 public ParcelFileDescriptor openFile(final Uri uri, final String mode) 81 public ParcelFileDescriptor openFile(final Uri uri, final String mode)
81 throws FileNotFoundException 82 throws FileNotFoundException
82 { 83 {
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
83 if (this.engine == null) 102 if (this.engine == null)
84 { 103 {
85 Log.e(TAG, "Engine not initialized"); 104 Log.e(TAG, "Engine failed to initialized");
Felix Dahlke 2016/05/13 14:29:09 Nit: "failed to initialize" (minus the last d)
86 throw new FileNotFoundException("Engine not yet initialized"); 105 return null;
87 } 106 }
88 107
89 try 108 try
90 { 109 {
91 this.setApplicationActivated(); 110 this.setApplicationActivated();
92 Log.d(TAG, "Writing filters..."); 111 Log.d(TAG, "Writing filters...");
93 final File filterFile = this.engine.createAndWriteFile(); 112 final File filterFile = this.engine.createAndWriteFile();
94 Log.d(TAG, "Delivering filters..."); 113 Log.d(TAG, "Delivering filters...");
95 return ParcelFileDescriptor.open(filterFile, ParcelFileDescriptor.MODE_REA D_ONLY); 114 return ParcelFileDescriptor.open(filterFile, ParcelFileDescriptor.MODE_REA D_ONLY);
96 } 115 }
97 catch (IOException e) 116 catch (IOException e)
98 { 117 {
99 Log.e(TAG, "File creation failed: " + e.getMessage(), e); 118 Log.e(TAG, "File creation failed: " + e.getMessage(), e);
100 return null; 119 return null;
101 } 120 }
102 } 121 }
103 122
104 @Override 123 @Override
105 public boolean onCreate() 124 public boolean onCreate()
106 { 125 {
107 EngineService.startService(this.getContext().getApplicationContext(), this); 126 Log.i(TAG, "onCreate() called");
127 EngineService.startService(this.getContext().getApplicationContext(), this, false);
128 Log.i(TAG, "Requested service startup");
108 return true; 129 return true;
109 } 130 }
110 131
111 @Override 132 @Override
112 public Cursor query(final Uri uri, final String[] projection, final String sel ection, 133 public Cursor query(final Uri uri, final String[] projection, final String sel ection,
113 final String[] selectionArgs, final String sortOrder) 134 final String[] selectionArgs, final String sortOrder)
114 { 135 {
115 return null; 136 return null;
116 } 137 }
117 138
(...skipping 18 matching lines...) Expand all
136 @Override 157 @Override
137 public int update(final Uri uri, final ContentValues values, final String sele ction, 158 public int update(final Uri uri, final ContentValues values, final String sele ction,
138 final String[] selectionArgs) 159 final String[] selectionArgs)
139 { 160 {
140 return 0; 161 return 0;
141 } 162 }
142 163
143 @Override 164 @Override
144 public void onEngineCreated(Engine engine, boolean success) 165 public void onEngineCreated(Engine engine, boolean success)
145 { 166 {
167 Log.i(TAG, "Service started, success: " + success);
168 this.engineInitDone = true;
146 if (success) 169 if (success)
147 { 170 {
148 this.engine = engine; 171 this.engine = engine;
149 } 172 }
150 } 173 }
151 } 174 }
OLDNEW
« no previous file with comments | « no previous file | src/org/adblockplus/sbrowser/contentblocker/engine/EngineService.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld