Commit ed66a470 authored by akwizgran's avatar akwizgran

Merge branch '1643-controller-leaks' into 'master'

Fix controller memory leaks

Closes #1643

See merge request !1184
parents 405c2433 034e76dd
Pipeline #3900 passed with stage
in 10 minutes and 26 seconds
......@@ -35,9 +35,6 @@ interface BaseController {
void repeatPost(BlogPostItem item, @Nullable String comment,
ExceptionHandler<DbException> handler);
@UiThread
void setBlogListener(BlogListener listener);
@NotNullByDefault
interface BlogListener {
......
......@@ -55,8 +55,6 @@ abstract class BaseControllerImpl extends DbControllerImpl
private final Map<MessageId, BlogPostHeader> headerCache =
new ConcurrentHashMap<>();
private volatile BlogListener listener;
BaseControllerImpl(@DatabaseExecutor Executor dbExecutor,
LifecycleManager lifecycleManager, EventBus eventBus,
AndroidNotificationManager notificationManager,
......@@ -71,7 +69,6 @@ abstract class BaseControllerImpl extends DbControllerImpl
@Override
@CallSuper
public void onStart() {
if (listener == null) throw new IllegalStateException();
eventBus.addListener(this);
}
......@@ -81,11 +78,6 @@ abstract class BaseControllerImpl extends DbControllerImpl
eventBus.removeListener(this);
}
@Override
public void setBlogListener(BlogListener listener) {
this.listener = listener;
}
@Override
public void loadBlogPosts(GroupId groupId,
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler) {
......@@ -211,7 +203,6 @@ abstract class BaseControllerImpl extends DbControllerImpl
text = HtmlUtils.clean(blogManager.getPostText(m), ARTICLE);
textCache.put(m, text);
}
//noinspection ConstantConditions
return text;
}
......
......@@ -9,6 +9,7 @@ import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
import java.util.Collection;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
@NotNullByDefault
......@@ -17,7 +18,7 @@ public interface BlogController extends BaseController {
void setGroupId(GroupId g);
@UiThread
void setBlogSharingListener(BlogSharingListener listener);
void setBlogSharingListener(@Nullable BlogSharingListener listener);
void loadBlogPosts(
ResultExceptionHandler<Collection<BlogPostItem>, DbException> handler);
......
......@@ -35,6 +35,8 @@ import java.util.logging.Logger;
import javax.inject.Inject;
import androidx.annotation.Nullable;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
......@@ -51,6 +53,7 @@ class BlogControllerImpl extends BaseControllerImpl
private final BlogSharingManager blogSharingManager;
// UI thread
@Nullable
private BlogSharingListener listener;
private volatile GroupId groupId = null;
......@@ -93,14 +96,14 @@ class BlogControllerImpl extends BaseControllerImpl
}
@Override
public void setBlogSharingListener(BlogSharingListener listener) {
super.setBlogListener(listener);
public void setBlogSharingListener(@Nullable BlogSharingListener listener) {
this.listener = listener;
}
@Override
public void eventOccurred(Event e) {
if (groupId == null) throw new IllegalStateException();
if (groupId == null || listener == null)
throw new IllegalStateException();
if (e instanceof BlogPostAddedEvent) {
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
if (b.getGroupId().equals(groupId)) {
......
......@@ -33,9 +33,9 @@ import org.briarproject.briar.api.blog.BlogPostHeader;
import java.util.Collection;
import javax.annotation.Nullable;
import javax.inject.Inject;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
......@@ -138,6 +138,12 @@ public class BlogFragment extends BaseFragment
list.stopPeriodicUpdate();
}
@Override
public void onDestroy() {
super.onDestroy();
blogController.setBlogSharingListener(null);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
......
......@@ -43,7 +43,6 @@ public class BlogPostFragment extends BasePostFragment implements BlogListener {
@Override
public void injectFragment(ActivityComponent component) {
component.inject(this);
blogController.setBlogListener(this);
}
@Override
......
......@@ -7,6 +7,7 @@ import org.briarproject.briar.api.blog.Blog;
import java.util.Collection;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
@NotNullByDefault
......@@ -18,7 +19,7 @@ public interface FeedController extends BaseController {
void loadPersonalBlog(ResultExceptionHandler<Blog, DbException> handler);
@UiThread
void setFeedListener(FeedListener listener);
void setFeedListener(@Nullable FeedListener listener);
@NotNullByDefault
interface FeedListener extends BlogListener {
......
......@@ -26,6 +26,8 @@ import java.util.logging.Logger;
import javax.inject.Inject;
import androidx.annotation.Nullable;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
......@@ -40,6 +42,7 @@ class FeedControllerImpl extends BaseControllerImpl implements FeedController {
Logger.getLogger(FeedControllerImpl.class.getName());
// UI thread
@Nullable
private FeedListener listener;
@Inject
......@@ -66,13 +69,13 @@ class FeedControllerImpl extends BaseControllerImpl implements FeedController {
}
@Override
public void setFeedListener(FeedListener listener) {
super.setBlogListener(listener);
public void setFeedListener(@Nullable FeedListener listener) {
this.listener = listener;
}
@Override
public void eventOccurred(Event e) {
if (listener == null) throw new IllegalStateException();
if (e instanceof BlogPostAddedEvent) {
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
LOG.info("Blog post added");
......
......@@ -26,9 +26,9 @@ import org.briarproject.briar.api.blog.BlogPostHeader;
import java.util.Collection;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.inject.Inject;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.recyclerview.widget.LinearLayoutManager;
......@@ -131,6 +131,12 @@ public class FeedFragment extends BaseFragment implements
// TODO save list position in database/preferences?
}
@Override
public void onDestroy() {
super.onDestroy();
feedController.setFeedListener(null);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
......
......@@ -10,6 +10,8 @@ import org.briarproject.briar.api.privategroup.GroupMessageHeader;
import java.util.Collection;
import javax.annotation.Nullable;
import androidx.annotation.UiThread;
@NotNullByDefault
......@@ -19,7 +21,7 @@ interface GroupListController extends DbController {
* The listener must be set right after the controller was injected
*/
@UiThread
void setGroupListListener(GroupListListener listener);
void setGroupListListener(@Nullable GroupListListener listener);
@UiThread
void onStart();
......
......@@ -39,6 +39,7 @@ import java.util.logging.Logger;
import javax.inject.Inject;
import androidx.annotation.CallSuper;
import androidx.annotation.Nullable;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logDuration;
......@@ -61,6 +62,7 @@ class GroupListControllerImpl extends DbControllerImpl
private final EventBus eventBus;
// UI thread
@Nullable
private GroupListListener listener;
@Inject
......@@ -78,7 +80,7 @@ class GroupListControllerImpl extends DbControllerImpl
}
@Override
public void setGroupListListener(GroupListListener listener) {
public void setGroupListListener(@Nullable GroupListListener listener) {
this.listener = listener;
}
......@@ -99,6 +101,7 @@ class GroupListControllerImpl extends DbControllerImpl
@Override
@CallSuper
public void eventOccurred(Event e) {
if (listener == null) throw new IllegalStateException();
if (e instanceof GroupMessageAddedEvent) {
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
LOG.info("Private group message added");
......
......@@ -109,6 +109,12 @@ public class GroupListFragment extends BaseFragment implements
list.showProgressBar();
}
@Override
public void onDestroy() {
super.onDestroy();
controller.setGroupListListener(null);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.groups_list_actions, menu);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment