mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Always check whether context has been destroyed.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package org.briarproject.android.controller;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
public interface ActivityLifecycleController {
|
||||
void onActivityCreate();
|
||||
|
||||
void onActivityCreate(Activity activity);
|
||||
|
||||
void onActivityResume();
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ public class BriarControllerImpl implements BriarController {
|
||||
Logger.getLogger(BriarControllerImpl.class.getName());
|
||||
|
||||
@Inject
|
||||
protected BriarServiceConnection serviceConnection;
|
||||
BriarServiceConnection serviceConnection;
|
||||
@Inject
|
||||
protected DatabaseConfig databaseConfig;
|
||||
DatabaseConfig databaseConfig;
|
||||
@Inject
|
||||
protected Activity activity;
|
||||
Activity activity;
|
||||
|
||||
private boolean bound = false;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class BriarControllerImpl implements BriarController {
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
public void onActivityCreate() {
|
||||
public void onActivityCreate(Activity activity) {
|
||||
if (databaseConfig.getEncryptionKey() != null) startAndBindService();
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class BriarControllerImpl implements BriarController {
|
||||
}.start();
|
||||
}
|
||||
|
||||
protected void unbindService() {
|
||||
private void unbindService() {
|
||||
if (bound) activity.unbindService(serviceConnection);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ import org.briarproject.api.identity.LocalAuthor;
|
||||
|
||||
public interface NavDrawerController extends ActivityLifecycleController {
|
||||
|
||||
void setTransportListener(TransportStateListener transportListener);
|
||||
|
||||
boolean isTransportRunning(TransportId transportId);
|
||||
|
||||
void storeLocalAuthor(LocalAuthor author,
|
||||
|
||||
@@ -30,19 +30,17 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
||||
Logger.getLogger(NavDrawerControllerImpl.class.getName());
|
||||
|
||||
@Inject
|
||||
protected ReferenceManager referenceManager;
|
||||
ReferenceManager referenceManager;
|
||||
@Inject
|
||||
protected PluginManager pluginManager;
|
||||
PluginManager pluginManager;
|
||||
@Inject
|
||||
protected EventBus eventBus;
|
||||
@Inject
|
||||
protected Activity activity;
|
||||
EventBus eventBus;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
protected volatile IdentityManager identityManager;
|
||||
|
||||
private TransportStateListener transportStateListener;
|
||||
private TransportStateListener listener;
|
||||
|
||||
@Inject
|
||||
public NavDrawerControllerImpl() {
|
||||
@@ -50,8 +48,8 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreate() {
|
||||
|
||||
public void onActivityCreate(Activity activity) {
|
||||
listener = (TransportStateListener) activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,21 +86,14 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
||||
|
||||
private void transportStateUpdate(final TransportId id,
|
||||
final boolean enabled) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (transportStateListener != null) {
|
||||
transportStateListener.stateUpdate(id, enabled);
|
||||
}
|
||||
listener.stateUpdate(id, enabled);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransportListener(TransportStateListener transportListener) {
|
||||
this.transportStateListener = transportListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTransportRunning(TransportId transportId) {
|
||||
Plugin plugin = pluginManager.getPlugin(transportId);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package org.briarproject.android.controller;
|
||||
|
||||
import org.briarproject.android.DestroyableContext;
|
||||
import org.briarproject.api.TransportId;
|
||||
|
||||
public interface TransportStateListener {
|
||||
public interface TransportStateListener extends DestroyableContext {
|
||||
|
||||
void stateUpdate(TransportId id, boolean enabled);
|
||||
}
|
||||
|
||||
@@ -2,35 +2,33 @@ package org.briarproject.android.controller.handler;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.android.DestroyableActivity;
|
||||
import org.briarproject.android.DestroyableContext;
|
||||
|
||||
public abstract class UiResultExceptionHandler<R, E extends Exception>
|
||||
implements ResultExceptionHandler<R, E> {
|
||||
|
||||
private final DestroyableActivity listener;
|
||||
private final DestroyableContext listener;
|
||||
|
||||
protected UiResultExceptionHandler(DestroyableActivity listener) {
|
||||
protected UiResultExceptionHandler(DestroyableContext listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final R result) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!listener.hasBeenDestroyed())
|
||||
onResultUi(result);
|
||||
onResultUi(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(final E exception) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!listener.hasBeenDestroyed())
|
||||
onExceptionUi(exception);
|
||||
onExceptionUi(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,24 +2,22 @@ package org.briarproject.android.controller.handler;
|
||||
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.android.DestroyableActivity;
|
||||
import org.briarproject.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
import org.briarproject.android.DestroyableContext;
|
||||
|
||||
public abstract class UiResultHandler<R> implements ResultHandler<R> {
|
||||
|
||||
private final DestroyableActivity listener;
|
||||
private final DestroyableContext listener;
|
||||
|
||||
protected UiResultHandler(DestroyableActivity listener) {
|
||||
protected UiResultHandler(DestroyableContext listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final R result) {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!listener.hasBeenDestroyed())
|
||||
onResultUi(result);
|
||||
onResultUi(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user