mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Removed DatabaseUiExecutor as DatabaseExecutor is now single-threaded.
This commit is contained in:
@@ -1,21 +1,13 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.android.AndroidNotificationManager;
|
||||
import org.briarproject.api.android.DatabaseUiExecutor;
|
||||
import org.briarproject.api.android.ReferenceManager;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
@@ -28,18 +20,9 @@ import com.google.inject.Provides;
|
||||
|
||||
public class AndroidModule extends AbstractModule {
|
||||
|
||||
private final ExecutorService databaseUiExecutor;
|
||||
private final UiCallback uiCallback;
|
||||
|
||||
public AndroidModule() {
|
||||
// The queue is unbounded, so tasks can be dependent
|
||||
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
||||
// Discard tasks that are submitted during shutdown
|
||||
RejectedExecutionHandler policy =
|
||||
new ThreadPoolExecutor.DiscardPolicy();
|
||||
// Use a single thread so DB accesses from the UI don't overlap
|
||||
databaseUiExecutor = new ThreadPoolExecutor(1, 1, 60, SECONDS, queue,
|
||||
policy);
|
||||
// Use a dummy UI callback
|
||||
uiCallback = new UiCallback() {
|
||||
|
||||
@@ -53,10 +36,11 @@ public class AndroidModule extends AbstractModule {
|
||||
|
||||
public void showMessage(String... message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(AndroidExecutor.class).to(AndroidExecutorImpl.class).in(
|
||||
Singleton.class);
|
||||
@@ -65,12 +49,6 @@ public class AndroidModule extends AbstractModule {
|
||||
bind(UiCallback.class).toInstance(uiCallback);
|
||||
}
|
||||
|
||||
@Provides @Singleton @DatabaseUiExecutor
|
||||
Executor getDatabaseUiExecutor(LifecycleManager lifecycleManager) {
|
||||
lifecycleManager.registerForShutdown(databaseUiExecutor);
|
||||
return databaseUiExecutor;
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
DatabaseConfig getDatabaseConfig(final Application app) {
|
||||
final File dir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.briarproject.android.groups.GroupListActivity;
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.api.android.AndroidNotificationManager;
|
||||
import org.briarproject.api.android.DatabaseUiExecutor;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
@@ -51,7 +51,7 @@ Service, EventListener {
|
||||
Logger.getLogger(AndroidNotificationManagerImpl.class.getName());
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final Executor dbUiExecutor;
|
||||
private final Executor dbExecutor;
|
||||
private final Context appContext;
|
||||
private final Map<ContactId, Integer> contactCounts =
|
||||
new HashMap<ContactId, Integer>(); // Locking: this
|
||||
@@ -65,9 +65,9 @@ Service, EventListener {
|
||||
|
||||
@Inject
|
||||
public AndroidNotificationManagerImpl(DatabaseComponent db,
|
||||
@DatabaseUiExecutor Executor dbExecutor, Application app) {
|
||||
@DatabaseExecutor Executor dbExecutor, Application app) {
|
||||
this.db = db;
|
||||
this.dbUiExecutor = dbExecutor;
|
||||
this.dbExecutor = dbExecutor;
|
||||
appContext = app.getApplicationContext();
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ Service, EventListener {
|
||||
}
|
||||
|
||||
private void loadSettings() {
|
||||
dbUiExecutor.execute(new Runnable() {
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
settings = db.getSettings();
|
||||
|
||||
@@ -5,14 +5,18 @@ import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
|
||||
import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY;
|
||||
import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.briarproject.android.BriarService.BriarBinder;
|
||||
import org.briarproject.android.BriarService.BriarServiceConnection;
|
||||
import org.briarproject.api.android.DatabaseUiExecutor;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
|
||||
import roboguice.activity.RoboActivity;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
@@ -35,7 +39,7 @@ public class BriarActivity extends RoboActivity {
|
||||
private boolean bound = false;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||
@Inject @DatabaseExecutor private volatile Executor dbExecutor;
|
||||
@Inject private volatile LifecycleManager lifecycleManager;
|
||||
|
||||
@Override
|
||||
@@ -113,7 +117,7 @@ public class BriarActivity extends RoboActivity {
|
||||
}
|
||||
|
||||
protected void runOnDbThread(final Runnable task) {
|
||||
dbUiExecutor.execute(new Runnable() {
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
lifecycleManager.waitForDatabase();
|
||||
|
||||
@@ -18,9 +18,9 @@ import org.briarproject.R;
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.android.AndroidNotificationManager;
|
||||
import org.briarproject.api.android.DatabaseUiExecutor;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
@@ -56,7 +56,7 @@ public class BriarService extends RoboService implements EventListener {
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile LifecycleManager lifecycleManager;
|
||||
@Inject private volatile AndroidExecutor androidExecutor;
|
||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||
@Inject @DatabaseExecutor private volatile Executor dbExecutor;
|
||||
@Inject private volatile DatabaseComponent db;
|
||||
private volatile boolean started = false;
|
||||
|
||||
@@ -130,6 +130,7 @@ public class BriarService extends RoboService implements EventListener {
|
||||
return START_NOT_STICKY; // Don't restart automatically if killed
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return binder;
|
||||
}
|
||||
@@ -170,7 +171,7 @@ public class BriarService extends RoboService implements EventListener {
|
||||
}
|
||||
|
||||
private void showMessageNotification(final GroupId g, final ContactId c) {
|
||||
dbUiExecutor.execute(new Runnable() {
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
lifecycleManager.waitForDatabase();
|
||||
|
||||
@@ -30,8 +30,8 @@ public class SplashScreenActivity extends RoboSplashActivity {
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(SplashScreenActivity.class.getName());
|
||||
|
||||
// This build expires on 17 May 2014
|
||||
private static final long EXPIRY_DATE = 1400284800 * 1000L;
|
||||
// This build expires on 12 July 2014
|
||||
private static final long EXPIRY_DATE = 1405123200 * 1000L;
|
||||
|
||||
private long now = System.currentTimeMillis();
|
||||
|
||||
@@ -61,6 +61,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
|
||||
setContentView(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startNextActivity() {
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package org.briarproject.api.android;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
/**
|
||||
* Annotation for injecting the executor for accessing the database from the UI.
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target({ FIELD, METHOD, PARAMETER })
|
||||
@Retention(RUNTIME)
|
||||
public @interface DatabaseUiExecutor {}
|
||||
Reference in New Issue
Block a user