Make more use of DbViewModel#handleException()

This commit is contained in:
Sebastian Kürten
2021-04-12 15:50:34 +02:00
parent 2ddb7b5b64
commit 419247074f
18 changed files with 52 additions and 65 deletions

View File

@@ -1,6 +1,10 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="MissingOverrideAnnotation" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreObjectMethods" value="true" />
<option name="ignoreAnonymousClassMethods" value="false" />
</inspection_tool>
<inspection_tool class="WeakerAccess" enabled="true" level="WARNING" enabled_by_default="true">
<option name="SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS" value="true" />
<option name="SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES" value="true" />

View File

@@ -57,6 +57,7 @@ public class Author implements Nameable {
/**
* Returns the author's name.
*/
@Override
public String getName() {
return name;
}

View File

@@ -146,10 +146,12 @@ abstract class PowerView extends ConstraintLayout {
static final Parcelable.Creator<SavedState> CREATOR
= new Parcelable.Creator<SavedState>() {
@Override
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}
@Override
public SavedState[] newArray(int size) {
return new SavedState[size];
}

View File

@@ -51,6 +51,7 @@ public class UnlockActivity extends BaseActivity {
component.inject(this);
}
@Override
public void onCreate(@Nullable Bundle state) {
super.onCreate(state);
overridePendingTransition(0, 0);

View File

@@ -19,23 +19,15 @@ import org.briarproject.briar.api.conversation.ConversationManager;
import org.briarproject.briar.api.identity.AuthorManager;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.inject.Inject;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logException;
@NotNullByDefault
class ContactListViewModel extends ContactsViewModel {
private static final Logger LOG =
getLogger(ContactListViewModel.class.getName());
private final AndroidNotificationManager notificationManager;
private final MutableLiveData<Boolean> hasPendingContacts =
@@ -76,7 +68,7 @@ class ContactListViewModel extends ContactsViewModel {
!contactManager.getPendingContacts().isEmpty();
hasPendingContacts.postValue(hasPending);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -70,7 +70,7 @@ public class AddContactViewModel extends DbViewModel {
try {
handshakeLink.postValue(contactManager.getHandshakeLink());
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
// the UI should stay disabled in this case,
// leaving the user unable to proceed
}

View File

@@ -26,25 +26,18 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.inject.Inject;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.api.contact.PendingContactState.OFFLINE;
import static org.briarproject.bramble.util.LogUtils.logException;
@NotNullByDefault
public class PendingContactListViewModel extends DbViewModel
implements EventListener {
private final Logger LOG =
getLogger(PendingContactListViewModel.class.getName());
private final ContactManager contactManager;
private final RendezvousPoller rendezvousPoller;
private final EventBus eventBus;
@@ -106,7 +99,7 @@ public class PendingContactListViewModel extends DbViewModel
pendingContacts.postValue(items);
hasInternetConnection.postValue(online);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -120,7 +113,7 @@ public class PendingContactListViewModel extends DbViewModel
try {
contactManager.removePendingContact(id);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -237,7 +237,7 @@ public class ConversationViewModel extends DbViewModel
} catch (NoSuchContactException e) {
contactDeleted.postValue(true);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -249,7 +249,7 @@ public class ConversationViewModel extends DbViewModel
conversationManager.setReadFlag(g, m, true);
logDuration(LOG, "Marking read", start);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -261,7 +261,7 @@ public class ConversationViewModel extends DbViewModel
alias.isEmpty() ? null : alias);
loadContact(contactId);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -402,7 +402,7 @@ public class ConversationViewModel extends DbViewModel
autoDeleteManager.setAutoDeleteTimer(txn, c, timer));
autoDeleteTimer.postValue(timer);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -453,7 +453,7 @@ public class ConversationViewModel extends DbViewModel
try {
checkFeaturesAndOnboarding(contactId);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -40,10 +40,8 @@ import androidx.annotation.UiThread;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.LogUtils.now;
import static org.briarproject.briar.api.forum.ForumManager.CLIENT_ID;
@@ -126,7 +124,7 @@ class ForumListViewModel extends DbViewModel implements EventListener {
}
}
public void loadForums() {
void loadForums() {
loadFromDb(this::loadForums, forumItems::setValue);
}
@@ -169,7 +167,7 @@ class ForumListViewModel extends DbViewModel implements EventListener {
logDuration(LOG, "Loading available", start);
numInvitations.postValue(available);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -50,10 +50,8 @@ import androidx.lifecycle.MutableLiveData;
import static android.widget.Toast.LENGTH_SHORT;
import static java.lang.Math.max;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.LogUtils.now;
@MethodsNotNullByDefault
@@ -116,6 +114,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
}
}
@Override
protected void clearNotifications() {
notificationManager.clearForumPostNotification(groupId);
}
@@ -127,7 +126,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
Forum f = forumManager.getForum(groupId);
forum.postValue(f);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
return forum;
@@ -167,7 +166,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
clock.currentTimeMillis());
createMessage(text, timestamp, parentId, author);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -191,7 +190,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
ForumPostItem item = new ForumPostItem(header, text);
addItem(item, true);
});
}, e -> logException(LOG, WARNING, e));
}, this::handleException);
}
@Override
@@ -200,11 +199,12 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
try {
forumManager.setReadFlag(groupId, item.getId(), true);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@Override
public void loadSharingContacts() {
runOnDbThread(true, txn -> {
Collection<Contact> contacts =
@@ -212,7 +212,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
Collection<ContactId> contactIds = new ArrayList<>(contacts.size());
for (Contact c : contacts) contactIds.add(c.getId());
txn.attach(() -> sharingController.addAll(contactIds));
}, e -> logException(LOG, WARNING, e));
}, this::handleException);
}
void deleteForum() {
@@ -220,12 +220,13 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
try {
Forum f = forumManager.getForum(groupId);
forumManager.removeForum(f);
androidExecutor.runOnUiThread(() -> Toast
.makeText(getApplication(), R.string.forum_left_toast,
LENGTH_SHORT).show());
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
Toast.makeText(getApplication(), R.string.forum_left_toast,
LENGTH_SHORT).show();
}
}

View File

@@ -154,7 +154,7 @@ class IntroductionViewModel extends ContactsViewModel {
introductionInfo.postValue(
new IntroductionInfo(c1, c2, possible));
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -94,7 +94,7 @@ public class NavDrawerViewModel extends DbViewModel {
}
}
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -109,7 +109,7 @@ public class NavDrawerViewModel extends DbViewModel {
settings.putInt(EXPIRY_DATE_WARNING, date);
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -156,7 +156,7 @@ public class NavDrawerViewModel extends DbViewModel {
settings.getBoolean(SHOW_TRANSPORTS_ONBOARDING, true);
showTransportsOnboarding.postValue(show);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -170,7 +170,7 @@ public class NavDrawerViewModel extends DbViewModel {
settings.putBoolean(SHOW_TRANSPORTS_ONBOARDING, false);
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -45,12 +45,10 @@ import static android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED;
import static android.bluetooth.BluetoothAdapter.EXTRA_STATE;
import static android.bluetooth.BluetoothAdapter.STATE_ON;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.api.plugin.Plugin.PREF_PLUGIN_ENABLE;
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.LogUtils.now;
@NotNullByDefault
@@ -197,7 +195,7 @@ public class PluginViewModel extends DbViewModel implements EventListener {
BluetoothConstants.DEFAULT_PREF_PLUGIN_ENABLE);
btEnabledSetting.postValue(bt);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -228,7 +226,7 @@ public class PluginViewModel extends DbViewModel implements EventListener {
settingsManager.mergeSettings(s, namespace);
logDuration(LOG, "Merging settings", start);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -51,10 +51,8 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import static java.lang.Math.max;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.LogUtils.now;
@MethodsNotNullByDefault
@@ -140,6 +138,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
loadPrivateGroup(groupId);
}
@Override
protected void clearNotifications() {
notificationManager.clearGroupMessageNotification(groupId);
}
@@ -152,7 +151,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
Author author = identityManager.getLocalAuthor();
isCreator.postValue(g.getCreator().equals(author));
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -210,7 +209,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
timestamp = max(clock.currentTimeMillis(), timestamp + 1);
createMessage(text, timestamp, parentId, author, previousMsgId);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -235,7 +234,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
txn.attach(() ->
addItem(buildItem(header, text), true)
);
}, e -> logException(LOG, WARNING, e));
}, this::handleException);
}
@Override
@@ -244,11 +243,12 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
try {
privateGroupManager.setReadFlag(groupId, item.getId(), true);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@Override
public void loadSharingContacts() {
runOnDbThread(true, txn -> {
Collection<GroupMember> members =
@@ -259,7 +259,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
contactIds.add(m.getContactId());
}
txn.attach(() -> sharingController.addAll(contactIds));
}, e -> logException(LOG, WARNING, e));
}, this::handleException);
}
void deletePrivateGroup() {
@@ -267,7 +267,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
try {
privateGroupManager.removePrivateGroup(groupId);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -48,10 +48,8 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.LogUtils.now;
import static org.briarproject.briar.api.privategroup.PrivateGroupManager.CLIENT_ID;
@@ -202,7 +200,7 @@ class GroupListViewModel extends DbViewModel implements EventListener {
groupManager.removePrivateGroup(g);
logDuration(LOG, "Removing group", start);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -213,7 +211,7 @@ class GroupListViewModel extends DbViewModel implements EventListener {
int i = groupInvitationManager.getInvitations().size();
numInvitations.postValue(i);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -152,7 +152,7 @@ class SettingsViewModel extends DbViewModel implements EventListener {
settingsManager.getSettings(TOR_NAMESPACE));
logDuration(LOG, "Loading settings", start);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -169,7 +169,7 @@ class SettingsViewModel extends DbViewModel implements EventListener {
ownIdentityInfo.postValue(
new OwnIdentityInfo(localAuthor, authorInfo));
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -41,9 +41,7 @@ import androidx.lifecycle.MutableLiveData;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logException;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
@@ -160,7 +158,7 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
storedMessageId);
}
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}
@@ -223,7 +221,7 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
try {
messageTracker.storeMessageId(groupId, messageId);
} catch (DbException e) {
logException(LOG, WARNING, e);
handleException(e);
}
});
}

View File

@@ -84,6 +84,7 @@ class IntroducerSession extends Session<IntroducerState> {
this(sessionId, groupId, author, -1, null, null);
}
@Override
public SessionId getSessionId() {
return sessionId;
}