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

Unified Diff: src/org/adblockplus/sbrowser/contentblocker/ContentBlockerContentProvider.java

Issue 29355386: Issue 4463 - Content blocker unavailable error message (Closed)
Patch Set: Created Sept. 30, 2016, 2:44 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/org/adblockplus/sbrowser/contentblocker/ContentBlockerContentProvider.java
===================================================================
--- a/src/org/adblockplus/sbrowser/contentblocker/ContentBlockerContentProvider.java
+++ b/src/org/adblockplus/sbrowser/contentblocker/ContentBlockerContentProvider.java
@@ -22,30 +22,28 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import org.adblockplus.adblockplussbrowser.R;
import org.adblockplus.sbrowser.contentblocker.engine.Engine;
import org.adblockplus.sbrowser.contentblocker.engine.EngineService;
import android.content.ContentProvider;
import android.content.ContentValues;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager;
import android.util.Log;
-public class ContentBlockerContentProvider extends ContentProvider implements
- EngineService.OnEngineCreatedCallback
+public class ContentBlockerContentProvider extends ContentProvider
{
private static final String TAG = ContentBlockerContentProvider.class.getSimpleName();
- private volatile Engine engine = null;
- private volatile boolean engineInitDone = false;
@Override
public Bundle call(String method, String arg, Bundle extras)
{
// As of SBC interface v1.4 we return `null` here to signal that we do not
// use encryption
return null;
}
@@ -76,60 +74,36 @@ public class ContentBlockerContentProvid
.commit();
}
}
@Override
public ParcelFileDescriptor openFile(final Uri uri, final String mode)
throws FileNotFoundException
{
- if (!this.engineInitDone)
- {
- Log.i(TAG, "Engine not ready yet, waiting...");
- while (!this.engineInitDone)
- {
- try
- {
- Thread.sleep(10);
- }
- catch (InterruptedException e)
- {
- Log.e(TAG, "Interrupted: " + e.getMessage(), e);
- return null;
- }
- }
- Log.i(TAG, "Engine ready");
- }
-
- if (this.engine == null)
- {
- Log.e(TAG, "Engine failed to initialize");
- return null;
- }
-
try
{
this.setApplicationActivated();
Log.d(TAG, "Writing filters...");
- final File filterFile = this.engine.createAndWriteFile();
+ final File filterFile = Engine.getOrCreateCachedFilterFile(getContext());
Log.d(TAG, "Delivering filters...");
return ParcelFileDescriptor.open(filterFile, ParcelFileDescriptor.MODE_READ_ONLY);
}
catch (IOException e)
{
Log.e(TAG, "File creation failed: " + e.getMessage(), e);
return null;
}
}
@Override
public boolean onCreate()
{
Log.i(TAG, "onCreate() called");
- EngineService.startService(this.getContext().getApplicationContext(), this, false);
+ getContext().startService(new Intent(getContext(), EngineService.class));
Log.i(TAG, "Requested service startup");
return true;
}
@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
final String[] selectionArgs, final String sortOrder)
{
@@ -155,20 +129,9 @@ public class ContentBlockerContentProvid
}
@Override
public int update(final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs)
{
return 0;
}
-
- @Override
- public void onEngineCreated(Engine engine, boolean success)
- {
- Log.i(TAG, "Service started, success: " + success);
- this.engineInitDone = true;
- if (success)
- {
- this.engine = engine;
- }
- }
}

Powered by Google App Engine
This is Rietveld