Compare commits

..

14 Commits

Author SHA1 Message Date
ameba23
d564fc8713 Add logging on replacing outgoing transport keys 2021-10-04 13:55:03 +02:00
ameba23
41443db817 Bug with checking contactId, improve logging 2021-09-30 15:54:32 +02:00
ameba23
274722d695 Log keys in hex on handshake 2021-09-29 10:15:41 +02:00
ameba23
275c7d261f Fix bug when finding handshake mode keys 2021-09-28 14:45:01 +02:00
ameba23
667f8db4f0 Log keys in hex when failing to recognise tags 2021-09-28 12:47:44 +02:00
ameba23
8398ecdeae Merge branch 'social-backup-poc' into social-backup-handshake-after-recover
* social-backup-poc:
  Rm test which was not present in this branch before cherry pick
  Resolve conflict on cherry pick commit to use ByteBuddyClassImposteriser
  Tell animal sniffer gradle plugin to ignore java.util.Objects
  Improve lost password and setup password dialog for social backup
  When creating social backup, only allow selecting contacts when there are at least 2 contacts in contact list
  Disable help recover account option by default
2021-09-28 08:15:28 +02:00
ameba23
8437aa1b10 If current keys are not in handshake mode, look for handshake mode keys 2021-08-27 10:04:50 +02:00
ameba23
9cf00efa9c Comment out additional logging when restoring account 2021-08-27 10:00:27 +02:00
ameba23
2a45fd3c91 Use new method to get stream context in handshake mode on incoming duplex sync connection 2021-08-27 09:58:08 +02:00
ameba23
f1f16f8474 Additional logging for outgoing duplex sync connection 2021-08-27 09:56:05 +02:00
ameba23
873675d68f Additional logging when reading tag 2021-08-27 09:55:28 +02:00
ameba23
1ffa8ee024 Add a method to get stream context in handshake mode 2021-08-27 09:54:50 +02:00
ameba23
a425a33209 Add a method to get stream context in handshake mode 2021-08-27 09:54:24 +02:00
ameba23
5adbf18851 Add and retrieve Onion private key to/from Tor transport propeties 2021-08-27 09:52:04 +02:00
53 changed files with 724 additions and 774 deletions

View File

@@ -116,4 +116,8 @@ public interface KeyManager {
@Nullable
StreamContext getStreamContext(TransportId t, byte[] tag)
throws DbException;
@Nullable
StreamContext getStreamContextInHandshakeMode(ContactId c, TransportId t)
throws DbException;
}

View File

@@ -47,7 +47,9 @@ abstract class Connection {
TransportId transportId) {
StreamContext ctx;
try {
LOG.info("Reading tag...");
byte[] tag = readTag(reader.getInputStream());
LOG.info("Read tag!");
return keyManager.getStreamContext(transportId, tag);
} catch (IOException | DbException e) {
logException(LOG, WARNING, e);

View File

@@ -130,13 +130,17 @@ class IncomingDuplexSyncConnection extends DuplexSyncConnection
private boolean performHandshake(StreamContext ctxIn, ContactId contactId) {
LOG.info("Performing handshake (Incoming)");
// Allocate the outgoing stream context
StreamContext ctxOut =
allocateStreamContext(contactId, transportId);
if (ctxOut == null) {
StreamContext ctxOut;
try {
ctxOut = keyManager.getStreamContextInHandshakeMode(contactId, transportId);
} catch (DbException e) {
logException(LOG, WARNING, e);
LOG.warning("Could not allocate stream context");
onReadError(true);
return false;
}
try {
InputStream in = streamReaderFactory.createStreamReader(
reader.getInputStream(), ctxIn);
@@ -148,7 +152,7 @@ class IncomingDuplexSyncConnection extends DuplexSyncConnection
handshakeManager.handshake(contactId, in, out);
keyManager.addRotationKeys(contactId, result.getMasterKey(),
TIMESTAMP, result.isAlice(), true);
LOG.info("Rotation keys added");
LOG.info("Rotation keys added - IncomingDuplexSyncConnection");
return true;
} catch (IOException | DbException e) {
logException(LOG, WARNING, e);

View File

@@ -64,6 +64,7 @@ class OutgoingDuplexSyncConnection extends DuplexSyncConnection
LOG.info("Running OutgoingDuplexSyncConnection on transport " +
transportId.getString());
// Allocate a stream context
StreamContext ctx = allocateStreamContext(contactId, transportId);
if (ctx == null) {
LOG.warning("Could not allocate stream context");
@@ -71,6 +72,7 @@ class OutgoingDuplexSyncConnection extends DuplexSyncConnection
return;
}
if (ctx.isHandshakeMode()) {
LOG.info("OutgoingDuplexSyncConnection - context is in handshake mode, performing handshake");
if (!performHandshake(ctx)) {
LOG.warning("Handshake failed");
return;
@@ -155,7 +157,8 @@ class OutgoingDuplexSyncConnection extends DuplexSyncConnection
}
private boolean performHandshake(StreamContext ctxOut) {
LOG.info("Performing handshake (Outgoing)");
LOG.info("Performing handshake (Outgoing) for transport " +
ctxOut.getTransportId().getString());
// Flush the output stream to send the outgoing stream header
StreamWriter out;
try {
@@ -177,7 +180,7 @@ class OutgoingDuplexSyncConnection extends DuplexSyncConnection
}
// Check that the stream comes from the expected contact
ContactId inContactId = ctxIn.getContactId();
if (contactId == null) {
if (inContactId == null) {
LOG.warning("Expected contact tag, got rendezvous tag");
onReadError();
return false;
@@ -196,7 +199,7 @@ class OutgoingDuplexSyncConnection extends DuplexSyncConnection
handshakeManager.handshake(contactId, in, out);
keyManager.addRotationKeys(contactId, result.getMasterKey(),
TIMESTAMP, result.isAlice(), true);
LOG.info("Rotation keys added");
LOG.info("Rotation keys added - OutgoingDuplexSyncConnection");
return true;
} catch (IOException | DbException e) {
logException(LOG, WARNING, e);

View File

@@ -470,6 +470,10 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
if (now - then >= V3_MIGRATION_PERIOD_MS) retireV2HiddenService();
else publishV2HiddenService(port, privKey2);
}
if (isNullOrEmpty(privKey3)) {
TransportProperties p = callback.getLocalProperties();
privKey3 = p.get(HS_PRIVATE_KEY_V3);
}
publishV3HiddenService(port, privKey3);
}
@@ -511,9 +515,11 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
try {
// Use the control connection to set up the hidden service
if (privKey == null) {
LOG.info("Private key is null");
response = controlConnection.addOnion("NEW:ED25519-V3",
portLines, null);
} else {
LOG.info("Private key is not null");
response = controlConnection.addOnion(privKey, portLines);
}
} catch (IOException e) {
@@ -535,12 +541,15 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
if (privKey == null) {
// Publish the hidden service's onion hostname in transport props
TransportProperties p = new TransportProperties();
String now = String.valueOf(clock.currentTimeMillis());
p.put(PROP_ONION_V3, onion3);
p.put(HS_PRIVATE_KEY_V3, response.get(HS_PRIVKEY));
p.put(HS_V3_CREATED, now);
callback.mergeLocalProperties(p);
// Save the hidden service's private key for next time
Settings s = new Settings();
s.put(HS_PRIVATE_KEY_V3, response.get(HS_PRIVKEY));
s.put(HS_V3_CREATED, String.valueOf(clock.currentTimeMillis()));
s.put(HS_V3_CREATED, now);
callback.mergeSettings(s);
}
}

View File

@@ -128,6 +128,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
throws DbException, GeneralSecurityException {
SecretKey staticMasterKey = transportCrypto
.deriveStaticMasterKey(theirPublicKey, ourKeyPair);
LOG.info("Deriving root handshake key " + c.toString() + " " + ourKeyPair.getPublic().toString() + " them: " + theirPublicKey.toString());
SecretKey rootKey =
transportCrypto.deriveHandshakeRootKey(staticMasterKey, false);
boolean alice = transportCrypto.isAlice(theirPublicKey, ourKeyPair);
@@ -135,6 +136,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
for (Entry<TransportId, TransportKeyManager> e : managers.entrySet()) {
TransportId t = e.getKey();
TransportKeyManager m = e.getValue();
LOG.info("Adding handshake keys for transport " + t.getString());
ids.put(t, m.addHandshakeKeys(txn, c, rootKey, alice));
}
return ids;
@@ -205,6 +207,14 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
m.getStreamContext(txn, tag)));
}
@Override
public StreamContext getStreamContextInHandshakeMode(ContactId c, TransportId t)
throws DbException {
return withManager(t, m ->
db.transactionWithNullableResult(false, txn ->
m.getStreamContextInHandshakeMode(txn, c)));
}
@Override
public void eventOccurred(Event e) {
if (e instanceof ContactRemovedEvent) {

View File

@@ -48,4 +48,7 @@ interface TransportKeyManager {
StreamContext getStreamContext(Transaction txn, byte[] tag)
throws DbException;
@Nullable
StreamContext getStreamContextInHandshakeMode(Transaction txn, ContactId c)
throws DbException;
}

View File

@@ -19,6 +19,7 @@ import org.briarproject.bramble.api.transport.StreamContext;
import org.briarproject.bramble.api.transport.TransportKeySet;
import org.briarproject.bramble.api.transport.TransportKeys;
import org.briarproject.bramble.transport.ReorderingWindow.Change;
import org.briarproject.bramble.util.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
@@ -182,9 +183,12 @@ class TransportKeyManagerImpl implements TransportKeyManager {
if (old == null || (old.getKeys().isHandshakeMode() &&
!ks.getKeys().isHandshakeMode()) ||
old.getKeySetId().getInt() < ks.getKeySetId().getInt()) {
LOG.info("Replacing Outgoing keys!");
if (ks.getContactId() == null)
pendingContactOutContexts.put(ks.getPendingContactId(), ks);
else contactOutContexts.put(ks.getContactId(), ks);
} else {
LOG.info("Not replacing Outgoing keys!");
}
}
}
@@ -372,6 +376,9 @@ class TransportKeyManagerImpl implements TransportKeyManager {
MutableTransportKeySet ks = getOutgoingKeySet(c, p);
if (ks == null) return null;
MutableTransportKeys keys = ks.getKeys();
LOG.info("Using keys for outgoing connection - handshake mode: " +
keys.isHandshakeMode());
MutableOutgoingKeys outKeys = keys.getCurrentOutgoingKeys();
if (!outKeys.isActive()) throw new AssertionError();
if (outKeys.getStreamCounter() > MAX_32_BIT_UNSIGNED) return null;
@@ -395,7 +402,18 @@ class TransportKeyManagerImpl implements TransportKeyManager {
try {
// Look up the incoming keys for the tag
TagContext tagCtx = inContexts.remove(new Bytes(tag));
if (tagCtx == null) return null;
if (tagCtx == null) {
LOG.info("Cannot find tag!");
for (MutableTransportKeySet t : keys.values()) {
LOG.info("Header key: " + StringUtils
.toHexString(t.getKeys().getCurrentIncomingKeys()
.getHeaderKey().getBytes()));
LOG.info("Tag key: " + StringUtils.toHexString(
t.getKeys().getCurrentIncomingKeys().getTagKey()
.getBytes()));
}
return null;
}
MutableIncomingKeys inKeys = tagCtx.inKeys;
// Create a stream context
StreamContext ctx = new StreamContext(tagCtx.contactId,
@@ -443,6 +461,51 @@ class TransportKeyManagerImpl implements TransportKeyManager {
}
}
@Override
public StreamContext getStreamContextInHandshakeMode(Transaction txn,
ContactId c)
throws DbException {
lock.lock();
try {
MutableTransportKeySet ks = getOutgoingKeySet(c, null);
if (ks == null) return null;
MutableTransportKeys currentKeys = ks.getKeys();
LOG.info("Current keys handshake mode? " +
currentKeys.isHandshakeMode());
if (currentKeys.isHandshakeMode())
return getStreamContext(txn, c, null);
for (MutableTransportKeySet keySet : this.keys.values()) {
MutableTransportKeys keys = keySet.getKeys();
if (!keys.isHandshakeMode()) continue;
LOG.info("Found handshake mode keys");
MutableOutgoingKeys outKeys = keys.getCurrentOutgoingKeys();
// if (!outKeys.isActive()) throw new AssertionError();
if (outKeys.getStreamCounter() > MAX_32_BIT_UNSIGNED)
return null;
// Create a stream context
LOG.info("Creating handshake mode stream context");
StreamContext ctx = new StreamContext(c, null, transportId,
outKeys.getTagKey(), outKeys.getHeaderKey(),
outKeys.getStreamCounter(), keys.isHandshakeMode());
LOG.info("Tag key: " +
StringUtils.toHexString(outKeys.getTagKey().getBytes()));
LOG.info("Header key: " +
StringUtils.toHexString(outKeys.getHeaderKey().getBytes()));
// Increment the stream counter and write it back to the DB
outKeys.incrementStreamCounter();
db.incrementStreamCounter(txn, transportId,
keySet.getKeySetId());
LOG.info("Returning");
return ctx;
}
LOG.info("Cannot find handshake mode keys");
return null;
} finally {
lock.unlock();
}
}
@DatabaseExecutor
@Wakeful
private void updateKeys(Transaction txn) throws DbException {

View File

@@ -139,7 +139,16 @@
</activity>
<activity
android:name="org.briarproject.briar.android.socialbackup.SocialBackupSetupActivity"
android:name="org.briarproject.briar.android.account.NewOrRecoverActivity"
android:label="@string/activity_name_new_or_recover_account"
android:parentActivityName="org.briarproject.briar.android.login.StartupActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.briarproject.briar.android.login.StartupActivity" />
</activity>
<activity
android:name="org.briarproject.briar.android.socialbackup.DistributedBackupActivity"
android:label="@string/activity_name_distributed_backup"
android:parentActivityName="org.briarproject.briar.android.settings.SettingsActivity">
<meta-data
@@ -159,11 +168,10 @@
<activity
android:name="org.briarproject.briar.android.socialbackup.recover.OwnerReturnShardActivity"
android:label="@string/activity_name_recovery"
android:parentActivityName="org.briarproject.briar.android.account.SetupActivity">
android:parentActivityName="org.briarproject.briar.android.account.NewOrRecoverActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.briarproject.briar.android.account.SetupActivity" />
android:value="org.briarproject.briar.android.account.NewOrRecoverActivity" />
</activity>
<activity

View File

@@ -42,7 +42,6 @@ import org.briarproject.briar.android.privategroup.list.GroupListModule;
import org.briarproject.briar.android.reporting.DevReportModule;
import org.briarproject.briar.android.settings.SettingsModule;
import org.briarproject.briar.android.sharing.SharingModule;
import org.briarproject.briar.android.socialbackup.SocialBackupSetupModule;
import org.briarproject.briar.android.socialbackup.recover.CustodianReturnShardModule;
import org.briarproject.briar.android.socialbackup.recover.OwnerReturnShardModule;
import org.briarproject.briar.android.test.TestAvatarCreatorImpl;
@@ -95,8 +94,7 @@ import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
GroupConversationModule.class,
SharingModule.class,
OwnerReturnShardModule.class,
CustodianReturnShardModule.class,
SocialBackupSetupModule.class
CustodianReturnShardModule.class
})
public class AppModule {

View File

@@ -30,7 +30,6 @@ public class AuthorNameFragment extends SetupFragment {
private TextInputLayout authorNameWrapper;
private TextInputEditText authorNameInput;
private Button nextButton;
private Button recoverButton;
public static AuthorNameFragment newInstance() {
return new AuthorNameFragment();
@@ -55,9 +54,6 @@ public class AuthorNameFragment extends SetupFragment {
authorNameInput.addTextChangedListener(this);
nextButton.setOnClickListener(this);
recoverButton = v.findViewById(R.id.buttonRestoreAccount);
recoverButton.setOnClickListener(e -> viewModel.recoverClicked());
return v;
}
@@ -79,8 +75,6 @@ public class AuthorNameFragment extends SetupFragment {
boolean enabled = authorNameLength > 0 && !error;
authorNameInput.setOnEditorActionListener(enabled ? this : null);
nextButton.setEnabled(enabled);
recoverButton.setEnabled(!enabled);
// recoverButton.setVisibility(enabled ? View.INVISIBLE : View.VISIBLE);
}
@Override

View File

@@ -0,0 +1,60 @@
package org.briarproject.briar.android.account;
import android.content.Intent;
import android.os.Bundle;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BaseActivity;
import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.socialbackup.recover.OwnerReturnShardActivity;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
public class NewOrRecoverActivity extends BaseActivity implements
BaseFragment.BaseFragmentListener, SetupNewAccountChosenListener,
RecoverAccountListener {
@Override
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
// fade-in after splash screen instead of default animation
// TODO the fade in is not working
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
setContentView(R.layout.activity_fragment_container);
NewOrRecoverFragment fragment = NewOrRecoverFragment.newInstance();
showInitialFragment(fragment);
}
@Override
public void setupNewAccountChosen() {
finish();
Intent i = new Intent(this, SetupActivity.class);
i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP |
FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(i);
}
@Override
public void recoverAccountChosen() {
finish();
Intent i = new Intent(this, OwnerReturnShardActivity.class);
i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP |
FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(i);
}
@Override
@Deprecated
public void runOnDbThread(Runnable runnable) {
throw new RuntimeException("Don't use this deprecated method here.");
}
}

View File

@@ -0,0 +1,70 @@
package org.briarproject.briar.android.account;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.fragment.BaseFragment;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class NewOrRecoverFragment extends BaseFragment {
public static final String TAG = NewOrRecoverFragment.class.getName();
protected SetupNewAccountChosenListener setupNewAccountListener;
protected RecoverAccountListener recoverAccountListener;
public static NewOrRecoverFragment newInstance() {
Bundle bundle = new Bundle();
NewOrRecoverFragment fragment = new NewOrRecoverFragment();
fragment.setArguments(bundle);
return fragment;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requireActivity().setTitle(R.string.setup_title);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_new_or_recover,
container, false);
Button newAccountButton = view.findViewById(R.id.buttonSetupNewAccount);
newAccountButton.setOnClickListener(e -> {
setupNewAccountListener.setupNewAccountChosen();
});
Button recoverAccountButton = view.findViewById(R.id.buttonRestoreAccount);
recoverAccountButton.setOnClickListener(e -> {
recoverAccountListener.recoverAccountChosen();
});
return view;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
setupNewAccountListener = (SetupNewAccountChosenListener) context;
recoverAccountListener = (RecoverAccountListener) context;
}
@Override
public String getUniqueTag() {
return TAG;
}
@Override
public void injectFragment(ActivityComponent component) {
component.inject(this);
}
}

View File

@@ -10,7 +10,6 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BaseActivity;
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
import org.briarproject.briar.android.socialbackup.recover.OwnerReturnShardActivity;
import javax.annotation.Nullable;
import javax.inject.Inject;
@@ -26,7 +25,6 @@ import static org.briarproject.briar.android.account.SetupViewModel.State.AUTHOR
import static org.briarproject.briar.android.account.SetupViewModel.State.CREATED;
import static org.briarproject.briar.android.account.SetupViewModel.State.DOZE;
import static org.briarproject.briar.android.account.SetupViewModel.State.FAILED;
import static org.briarproject.briar.android.account.SetupViewModel.State.RECOVER;
import static org.briarproject.briar.android.account.SetupViewModel.State.SET_PASSWORD;
@MethodsNotNullByDefault
@@ -62,8 +60,6 @@ public class SetupActivity extends BaseActivity
showPasswordFragment();
} else if (state == DOZE) {
showDozeFragment();
} else if (state == RECOVER) {
recover();
} else if (state == CREATED || state == FAILED) {
// TODO: Show an error if failed
showApp();
@@ -88,13 +84,6 @@ public class SetupActivity extends BaseActivity
overridePendingTransition(R.anim.screen_new_in, R.anim.screen_old_out);
}
void recover () {
// finish();
Intent i = new Intent(this, OwnerReturnShardActivity.class);
i.addFlags(FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
@Override
@Deprecated
public void runOnDbThread(Runnable runnable) {

View File

@@ -25,14 +25,13 @@ import static org.briarproject.briar.android.account.SetupViewModel.State.AUTHOR
import static org.briarproject.briar.android.account.SetupViewModel.State.CREATED;
import static org.briarproject.briar.android.account.SetupViewModel.State.DOZE;
import static org.briarproject.briar.android.account.SetupViewModel.State.FAILED;
import static org.briarproject.briar.android.account.SetupViewModel.State.RECOVER;
import static org.briarproject.briar.android.account.SetupViewModel.State.SET_PASSWORD;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public
class SetupViewModel extends AndroidViewModel {
enum State {AUTHOR_NAME, SET_PASSWORD, DOZE, CREATED, FAILED, RECOVER}
enum State {AUTHOR_NAME, SET_PASSWORD, DOZE, CREATED, FAILED}
private static final Logger LOG =
getLogger(SetupActivity.class.getName());
@@ -118,9 +117,4 @@ class SetupViewModel extends AndroidViewModel {
}
});
}
public void recoverClicked() {
LOG.info("RECOVER CLICKED ***");
state.postEvent(RECOVER);
}
}

View File

@@ -7,6 +7,8 @@ import org.briarproject.briar.android.AndroidComponent;
import org.briarproject.briar.android.StartupFailureActivity;
import org.briarproject.briar.android.account.AuthorNameFragment;
import org.briarproject.briar.android.account.DozeFragment;
import org.briarproject.briar.android.account.NewOrRecoverActivity;
import org.briarproject.briar.android.account.NewOrRecoverFragment;
import org.briarproject.briar.android.account.SetPasswordFragment;
import org.briarproject.briar.android.account.SetupActivity;
import org.briarproject.briar.android.account.UnlockActivity;
@@ -78,19 +80,20 @@ import org.briarproject.briar.android.sharing.ShareBlogFragment;
import org.briarproject.briar.android.sharing.ShareForumActivity;
import org.briarproject.briar.android.sharing.ShareForumFragment;
import org.briarproject.briar.android.sharing.SharingModule;
import org.briarproject.briar.android.socialbackup.SetupExplainerFragment;
import org.briarproject.briar.android.socialbackup.recover.CustodianRecoveryModeExplainerFragment;
import org.briarproject.briar.android.socialbackup.CustodianSelectorFragment;
import org.briarproject.briar.android.socialbackup.SocialBackupSetupActivity;
import org.briarproject.briar.android.socialbackup.DistributedBackupActivity;
import org.briarproject.briar.android.socialbackup.ExistingBackupFragment;
import org.briarproject.briar.android.socialbackup.recover.CustodianReturnShardActivity;
import org.briarproject.briar.android.socialbackup.recover.CustodianReturnShardErrorFragment;
import org.briarproject.briar.android.socialbackup.recover.CustodianReturnShardFragment;
import org.briarproject.briar.android.socialbackup.recover.CustodianReturnShardSuccessFragment;
import org.briarproject.briar.android.socialbackup.recover.OwnerRecoveryModeErrorFragment;
import org.briarproject.briar.android.socialbackup.recover.OwnerRecoveryModeExplainerFragment;
import org.briarproject.briar.android.socialbackup.recover.OwnerRecoveryModeMainFragment;
import org.briarproject.briar.android.socialbackup.recover.OwnerReturnShardActivity;
import org.briarproject.briar.android.socialbackup.recover.OwnerReturnShardFragment;
import org.briarproject.briar.android.socialbackup.ShardsSentFragment;
import org.briarproject.briar.android.socialbackup.ThresholdSelectorFragment;
import org.briarproject.briar.android.socialbackup.creation.CreateBackupModule;
import org.briarproject.briar.android.socialbackup.recover.OwnerReturnShardSuccessFragment;
@@ -99,6 +102,7 @@ import org.briarproject.briar.android.socialbackup.recover.RestoreAccountDozeFra
import org.briarproject.briar.android.socialbackup.recover.RestoreAccountSetPasswordFragment;
import org.briarproject.briar.android.splash.SplashScreenActivity;
import org.briarproject.briar.android.test.TestDataActivity;
import org.briarproject.briar.api.socialbackup.recovery.RestoreAccount;
import dagger.Component;
@@ -201,6 +205,8 @@ public interface ActivityComponent {
void inject(CrashReportActivity crashReportActivity);
void inject(NewOrRecoverActivity newOrRecoverActivity);
void inject(CustodianReturnShardActivity custodianReturnShardActivity);
void inject(OwnerReturnShardActivity ownerReturnShardActivity);
@@ -269,22 +275,28 @@ public interface ActivityComponent {
void inject(ThresholdSelectorFragment thresholdSelectorFragment);
void inject(SocialBackupSetupActivity distributedBackupActivity);
void inject(DistributedBackupActivity distributedBackupActivity);
void inject(DatabaseComponent databaseComponent);
void inject(CustodianSelectorFragment custodianSelectorFragment);
void inject(ShardsSentFragment shardsSentFragment);
void inject(OwnerRecoveryModeExplainerFragment ownerRecoveryModeExplainerFragment);
void inject(ExistingBackupFragment existingBackupFragment);
void inject(NewOrRecoverFragment newOrRecoverFragment);
void inject(CustodianRecoveryModeExplainerFragment custodianRecoveryModeExplainerFragment);
void inject(CustodianReturnShardFragment custodianReturnShardFragment);
void inject(OwnerReturnShardFragment ownerReturnShardFragment);
void inject(CustodianReturnShardSuccessFragment custodianReturnShardSuccessFragment);
void inject(RestoreAccountSetPasswordFragment restoreAccountSetPasswordFragment);
void inject(RestoreAccountDozeFragment restoreAccountDozeFragment);
@@ -294,6 +306,4 @@ public interface ActivityComponent {
void inject(OwnerRecoveryModeErrorFragment ownerRecoveryModeErrorFragment);
void inject(CustodianReturnShardErrorFragment custodianReturnShardErrorFragment);
void inject(SetupExplainerFragment setupExplainerFragment);
}

View File

@@ -7,6 +7,7 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
import org.briarproject.briar.android.BriarService;
import org.briarproject.briar.android.account.NewOrRecoverActivity;
import org.briarproject.briar.android.account.SetupActivity;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BaseActivity;
@@ -107,7 +108,7 @@ public class StartupActivity extends BaseActivity implements
private void onAccountDeleted() {
setResult(RESULT_CANCELED);
finish();
Intent i = new Intent(this, SetupActivity.class);
Intent i = new Intent(this, NewOrRecoverActivity.class);
i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP |
FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(i);

View File

@@ -158,8 +158,7 @@ public class NavDrawerActivity extends BriarActivity implements
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
// navDrawerViewModel.checkTransportsOnboarding();
navDrawerViewModel.checkSocialBackupOnboarding();
navDrawerViewModel.checkTransportsOnboarding();
}
};
drawerLayout.addDrawerListener(drawerToggle);
@@ -168,12 +167,9 @@ public class NavDrawerActivity extends BriarActivity implements
initializeTransports();
transportsView.setAdapter(transportsAdapter);
// observeOnce(navDrawerViewModel.showTransportsOnboarding(), this, show ->
// observeOnce(torIcon, this, imageView ->
// showTransportsOnboarding(show, imageView)));
observeOnce(navDrawerViewModel.showSocialBackupOnboarding(), this,
this::showSocialBackupOnboarding);
observeOnce(navDrawerViewModel.showTransportsOnboarding(), this, show ->
observeOnce(torIcon, this, imageView ->
showTransportsOnboarding(show, imageView)));
lockManager.isLockable().observe(this, this::setLockVisible);
@@ -472,22 +468,6 @@ public class NavDrawerActivity extends BriarActivity implements
}
}
private void showSocialBackupOnboarding(boolean show) {
if (show) {
new MaterialTapTargetPrompt.Builder(NavDrawerActivity.this,
R.style.OnboardingDialogTheme)
.setTarget(R.id.nav_btn_settings)
.setPrimaryText(R.string.social_backup_onboarding_title)
.setSecondaryText(R.string.social_backup_onboarding_long)
.setFocalRadius((float) 350)
.setFocalPadding((float) 100)
.setBackgroundColour(
ContextCompat.getColor(this, R.color.briar_primary))
.show();
navDrawerViewModel.socialBackupOnboardingShown();
}
}
private static class Transport {
private final TransportId id;

View File

@@ -39,8 +39,6 @@ public class NavDrawerViewModel extends DbViewModel {
private static final String EXPIRY_DATE_WARNING = "expiryDateWarning";
private static final String SHOW_TRANSPORTS_ONBOARDING =
"showTransportsOnboarding";
private static final String SHOW_SOCIAL_BACKUP_ONBOARDING =
"showSocialBackupOnboarding";
private final SettingsManager settingsManager;
@@ -50,8 +48,6 @@ public class NavDrawerViewModel extends DbViewModel {
new MutableLiveData<>();
private final MutableLiveData<Boolean> showTransportsOnboarding =
new MutableLiveData<>();
private final MutableLiveData<Boolean> showSocialBackupOnboarding =
new MutableLiveData<>();
@Inject
NavDrawerViewModel(Application app,
@@ -146,11 +142,6 @@ public class NavDrawerViewModel extends DbViewModel {
return showTransportsOnboarding;
}
@UiThread
LiveData<Boolean> showSocialBackupOnboarding() {
return showSocialBackupOnboarding;
}
@UiThread
void checkTransportsOnboarding() {
if (showTransportsOnboarding.getValue() != null) return;
@@ -180,35 +171,4 @@ public class NavDrawerViewModel extends DbViewModel {
}
});
}
@UiThread
void checkSocialBackupOnboarding() {
if (showSocialBackupOnboarding.getValue() != null) return;
runOnDbThread(() -> {
try {
Settings settings =
settingsManager.getSettings(SETTINGS_NAMESPACE);
boolean show =
settings.getBoolean(SHOW_SOCIAL_BACKUP_ONBOARDING,
true);
showSocialBackupOnboarding.postValue(show);
} catch (DbException e) {
logException(LOG, WARNING, e);
}
});
}
@UiThread
void socialBackupOnboardingShown() {
showSocialBackupOnboarding.setValue(false);
runOnDbThread(() -> {
try {
Settings settings = new Settings();
settings.putBoolean(SHOW_SOCIAL_BACKUP_ONBOARDING, false);
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
} catch (DbException e) {
logException(LOG, WARNING, e);
}
});
}
}

View File

@@ -1,12 +1,10 @@
package org.briarproject.briar.android.settings;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@@ -14,7 +12,6 @@ import org.briarproject.bramble.api.FeatureFlags;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import org.briarproject.briar.android.util.UiUtils;
import org.briarproject.briar.android.view.AuthorView;
@@ -22,15 +19,11 @@ import javax.inject.Inject;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import de.hdodenhof.circleimageview.CircleImageView;
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
import static android.widget.Toast.LENGTH_LONG;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_AVATAR_IMAGE;
import static org.briarproject.briar.android.util.UiUtils.resolveColorAttribute;
public class SettingsActivity extends BriarActivity {

View File

@@ -23,7 +23,6 @@ import java.util.Collection;
import javax.inject.Inject;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;
import static java.util.Objects.requireNonNull;
@@ -33,18 +32,6 @@ public class CustodianSelectorFragment extends ContactSelectorFragment {
public static final String TAG = CustodianSelectorFragment.class.getName();
@Inject
ViewModelProvider.Factory viewModelFactory;
private SocialBackupSetupViewModel viewModel;
@Override
public void injectFragment(ActivityComponent component) {
component.inject(this);
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
.get(SocialBackupSetupViewModel.class);
}
@Inject
CreateBackupController controller;
@@ -57,6 +44,11 @@ public class CustodianSelectorFragment extends ContactSelectorFragment {
return fragment;
}
@Override
public void injectFragment(ActivityComponent component) {
component.inject(this);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -86,19 +78,15 @@ public class CustodianSelectorFragment extends ContactSelectorFragment {
int n = selectedContacts.size();
int min = 2;
int max = 7;
boolean amountIsValid = (n >= min) && (n <= max);
boolean enough = n >= min;
item.setVisible(amountIsValid);
item.setVisible(enough);
if (n == 0) {
Toast.makeText(getContext(), String.format(getString(R.string.select_at_least_n_contacts), min),
Toast.LENGTH_SHORT).show();
} else if (n < min) {
Toast.makeText(getContext(), String.format(getString(R.string.select_at_least_n_more_contacts), min - n),
Toast.LENGTH_SHORT).show();
} else if (n > max) {
Toast.makeText(getContext(), String.format(getString(R.string.select_no_more_than_n_contacts), max),
Toast.LENGTH_SHORT).show();
}
}

View File

@@ -0,0 +1,112 @@
package org.briarproject.briar.android.socialbackup;
import android.os.Bundle;
import android.widget.Toast;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.contactselection.ContactSelectorListener;
import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.api.socialbackup.BackupMetadata;
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
import java.util.Collection;
import java.util.List;
import javax.inject.Inject;
public class DistributedBackupActivity extends BriarActivity implements
BaseFragment.BaseFragmentListener, ContactSelectorListener,
ThresholdDefinedListener,
ShardsSentFragment.ShardsSentDismissedListener {
private Collection<ContactId> custodians;
@Inject
public SocialBackupManager socialBackupManager;
@Inject
public ContactManager contactManager;
@Inject
public DatabaseComponent db;
@Override
public void injectActivity(ActivityComponent component) {
component.inject(this);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_distributed_backup);
try {
db.transaction(false, txn -> {
BackupMetadata backupMetadata =
socialBackupManager.getBackupMetadata(txn);
if (backupMetadata == null) throw new DbException();
ExistingBackupFragment fragment =
ExistingBackupFragment.newInstance(backupMetadata);
showInitialFragment(fragment);
});
} catch (DbException e) {
// Check the number of contacts in the contacts list > 1
try {
if (contactManager.getContacts().size() < 2) {
Toast.makeText(this,
R.string.social_backup_not_enough_contacts,
Toast.LENGTH_LONG).show();
finish();
}
} catch (DbException dbException) {
Toast.makeText(this,
R.string.reading_contacts_error,
Toast.LENGTH_LONG).show();
finish();
}
CustodianSelectorFragment fragment =
CustodianSelectorFragment.newInstance();
showInitialFragment(fragment);
}
}
@Override
public void contactsSelected(Collection<ContactId> contacts) {
Toast.makeText(this,
String.format("Selected %d contacts", contacts.size()),
Toast.LENGTH_SHORT).show();
custodians = contacts;
ThresholdSelectorFragment fragment =
ThresholdSelectorFragment.newInstance(contacts.size());
showNextFragment(fragment);
}
@Override
public void thresholdDefined(int threshold) {
try {
db.transaction(false, txn -> {
socialBackupManager
.createBackup(txn, (List<ContactId>) custodians,
threshold);
ShardsSentFragment fragment = new ShardsSentFragment();
showNextFragment(fragment);
});
} catch (DbException e) {
Toast.makeText(this,
"There was an error when creating the backup",
Toast.LENGTH_LONG).show();
finish();
}
}
@Override
public void shardsSentDismissed() {
finish();
}
}

View File

@@ -2,48 +2,42 @@ package org.briarproject.briar.android.socialbackup;
import android.content.Context;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ImageSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.contact.ContactListAdapter;
import org.briarproject.briar.android.contact.ContactListItem;
import org.briarproject.briar.android.contact.OnContactClickListener;
import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.view.BriarRecyclerView;
import org.briarproject.briar.api.socialbackup.BackupMetadata;
import java.util.Arrays;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
public class ExistingBackupFragment extends BaseFragment implements
OnContactClickListener<ContactListItem> {
public class ExistingBackupFragment extends BaseFragment {
private static final String THRESHOLD = "threshold";
private static final String CUSTODIANS = "custodians";
public static final String TAG = ExistingBackupFragment.class.getName();
private final ContactListAdapter adapter = new ContactListAdapter(this);
private BriarRecyclerView list;
@Inject
ViewModelProvider.Factory viewModelFactory;
private SocialBackupSetupViewModel viewModel;
@Override
public void injectFragment(ActivityComponent component) {
component.inject(this);
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
.get(SocialBackupSetupViewModel.class);
public static ExistingBackupFragment newInstance(
BackupMetadata backupMetadata) {
Bundle bundle = new Bundle();
List<Author> custodians = backupMetadata.getCustodians();
ArrayList custodianNames = new ArrayList();
for (Author custodian : custodians) {
custodianNames.add(custodian.getName());
}
bundle.putStringArrayList(CUSTODIANS, custodianNames);
bundle.putInt(THRESHOLD, backupMetadata.getThreshold());
ExistingBackupFragment fragment = new ExistingBackupFragment();
fragment.setArguments(bundle);
return fragment;
}
@Override
@@ -57,69 +51,43 @@ public class ExistingBackupFragment extends BaseFragment implements
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
ViewGroup container, @Nullable Bundle savedInstanceState) {
// change toolbar text (relevant when navigating back to this fragment)
// requireActivity().setTitle(R.string.social_backup_trusted_contacts);
View view = inflater.inflate(R.layout.fragment_existing_backup,
container, false);
viewModel.loadCustodianList();
list = view.findViewById(R.id.custodianList);
list.setLayoutManager(new LinearLayoutManager(getActivity()));
list.setAdapter(adapter);
list.setEmptyText(R.string.no_contacts);
Bundle args = requireArguments();
ArrayList<String> custodianNames = args.getStringArrayList(CUSTODIANS);
viewModel.getContactListItems().observe(getViewLifecycleOwner(),
result -> result.onError(this::handleException)
.onSuccess(adapter::submitList)
);
StringBuilder custodianNamesString = new StringBuilder();
for (String custodianName : custodianNames) {
custodianNamesString
.append("")
.append(custodianName)
.append("\n");
}
int threshold = viewModel.getThresholdFromExistingBackup();
int numberOfCustodians =
viewModel.getNumberOfCustodiansFromExistingBackup();
TextView mOfn = view.findViewById(R.id.textViewThreshold);
mOfn.setText(String.format(
getString(R.string.existing_backup_explain), threshold));
TextView thresholdRepresentation =
view.findViewById(R.id.textViewThresholdRepresentation);
thresholdRepresentation.setText(
buildThresholdRepresentationString(threshold,
numberOfCustodians));
TextView textViewThreshold = view.findViewById(R.id.textViewThreshold);
textViewThreshold.setText(getString(R.string.existing_backup_explain,
args.getInt(THRESHOLD)));
TextView textViewCustodians =
view.findViewById(R.id.textViewCustodians);
textViewCustodians.setText(custodianNamesString);
return view;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
// listener = (ShardsSentDismissedListener) context;
}
@Override
public String getUniqueTag() {
return TAG;
}
@Override
public void onItemClick(View view, ContactListItem item) {
public void injectFragment(ActivityComponent component) {
component.inject(this);
}
private SpannableStringBuilder buildThresholdRepresentationString(
int threshold, int numberOfCustodians) {
char[] charArray = new char[numberOfCustodians];
Arrays.fill(charArray, ' ');
SpannableStringBuilder string =
new SpannableStringBuilder(new String(charArray));
for (int i = 0; i < numberOfCustodians; i++) {
int drawable = i < threshold
? R.drawable.ic_custodian_required
: R.drawable.ic_custodian_optional;
string.setSpan(new ImageSpan(getContext(), drawable), i,
i + 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
// If we have more than 6, split it on two lines
if (numberOfCustodians > 6) string.insert(4, "\n");
return string;
}
}

View File

@@ -0,0 +1,74 @@
package org.briarproject.briar.android.socialbackup;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.fragment.BaseFragment;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
public class ShardsSentFragment extends BaseFragment {
public static final String TAG = ShardsSentFragment.class.getName();
interface ShardsSentDismissedListener {
@UiThread
void shardsSentDismissed();
}
protected ShardsSentDismissedListener listener;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requireActivity().setTitle(R.string.title_distributed_backup);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_shards_sent,
container, false);
Button button = view.findViewById(R.id.button);
button.setOnClickListener(e -> {
listener.shardsSentDismissed();
});
return view;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
listener = (ShardsSentDismissedListener) context;
}
@Override
public String getUniqueTag() {
return TAG;
}
@Override
public void injectFragment(ActivityComponent component) {
component.inject(this);
}
public void onBackPressed() {
listener.shardsSentDismissed();
}
}

View File

@@ -1,94 +0,0 @@
package org.briarproject.briar.android.socialbackup;
import android.os.Bundle;
import android.widget.Toast;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.contactselection.ContactSelectorListener;
import org.briarproject.briar.android.fragment.BaseFragment;
import java.util.Collection;
import java.util.List;
import javax.inject.Inject;
import androidx.lifecycle.ViewModelProvider;
public class SocialBackupSetupActivity extends BriarActivity implements
BaseFragment.BaseFragmentListener, ContactSelectorListener {
private SocialBackupSetupViewModel viewModel;
@Inject
ViewModelProvider.Factory viewModelFactory;
@Override
public void injectActivity(ActivityComponent component) {
component.inject(this);
viewModel = new ViewModelProvider(this, viewModelFactory)
.get(SocialBackupSetupViewModel.class);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_distributed_backup);
if (viewModel.haveExistingBackup()) {
showInitialFragment(new ExistingBackupFragment());
} else {
try {
if (!viewModel.haveEnoughContacts()) {
Toast.makeText(this,
R.string.social_backup_not_enough_contacts,
Toast.LENGTH_LONG).show();
finish();
}
} catch (DbException dbException) {
Toast.makeText(this,
R.string.reading_contacts_error,
Toast.LENGTH_LONG).show();
finish();
}
showInitialFragment(new SetupExplainerFragment());
}
viewModel.getState()
.observe(this, this::onStateChanged);
}
private void onStateChanged(SocialBackupSetupViewModel.State state) {
switch (state) {
case SUCCESS:
finish();
break;
case FAILURE:
Toast.makeText(this,
"There was an error when creating the backup",
Toast.LENGTH_LONG).show();
finish();
break;
case CHOOSING_CUSTODIANS:
CustodianSelectorFragment fragment =
CustodianSelectorFragment.newInstance();
showNextFragment(fragment);
break;
}
}
@Override
public void contactsSelected(Collection<ContactId> contacts) {
Toast.makeText(this,
String.format("Selected %d contacts", contacts.size()),
Toast.LENGTH_SHORT).show();
viewModel.setCustodians((List<ContactId>) contacts);
ThresholdSelectorFragment fragment =
ThresholdSelectorFragment.newInstance(contacts.size());
showNextFragment(fragment);
}
}

View File

@@ -1,20 +0,0 @@
package org.briarproject.briar.android.socialbackup;
import org.briarproject.briar.android.socialbackup.recover.CustodianReturnShardViewModel;
import org.briarproject.briar.android.viewmodel.ViewModelKey;
import androidx.lifecycle.ViewModel;
import dagger.Binds;
import dagger.Module;
import dagger.multibindings.IntoMap;
@Module
public abstract class SocialBackupSetupModule {
@Binds
@IntoMap
@ViewModelKey(SocialBackupSetupViewModel.class)
abstract ViewModel bindSocialBackupSetupViewModel(
SocialBackupSetupViewModel socialBackupSetupViewModel);
}

View File

@@ -1,147 +0,0 @@
package org.briarproject.briar.android.socialbackup;
import android.app.Application;
import org.briarproject.bramble.api.connection.ConnectionRegistry;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DatabaseExecutor;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.event.EventBus;
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.bramble.api.system.AndroidExecutor;
import org.briarproject.briar.android.contact.ContactsViewModel;
import org.briarproject.briar.api.conversation.ConversationManager;
import org.briarproject.briar.api.identity.AuthorManager;
import org.briarproject.briar.api.socialbackup.BackupMetadata;
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
public class SocialBackupSetupViewModel extends ContactsViewModel {
private final SocialBackupManager socialBackupManager;
private final DatabaseComponent db;
private final ContactManager contactManager;
private BackupMetadata backupMetadata;
private List<ContactId> custodians;
private int threshold;
public enum State {
EXPLAINING,
CHOOSING_CUSTODIANS,
GETTING_THRESHOLD,
SUCCESS,
FAILURE
}
private final MutableLiveData<State> state =
new MutableLiveData<>();
@Inject
public SocialBackupSetupViewModel(
@NonNull Application app,
DatabaseComponent db,
@DatabaseExecutor Executor dbExecutor,
LifecycleManager lifecycleManager,
AuthorManager authorManager,
ConversationManager conversationManager,
ConnectionRegistry connectionRegistry,
EventBus eventBus,
AndroidExecutor androidExecutor,
SocialBackupManager socialBackupManager,
ContactManager contactManager
) {
super(app, dbExecutor, lifecycleManager, db, androidExecutor,
contactManager, authorManager, conversationManager,
connectionRegistry, eventBus);
this.socialBackupManager = socialBackupManager;
this.db = db;
this.contactManager = contactManager;
}
public void loadCustodianList() {
try {
custodians = db.transactionWithResult(true,
socialBackupManager::getCustodianContactIds);
} catch (DbException e) {
custodians = new ArrayList<>();
}
loadContacts();
}
public boolean haveExistingBackup() {
try {
backupMetadata = db.transactionWithNullableResult(true,
socialBackupManager::getBackupMetadata);
} catch (DbException e) {
return false;
}
return (backupMetadata != null);
}
// public BackupMetadata getBackupMetadata() {
// return backupMetadata;
// }
public boolean haveEnoughContacts() throws DbException {
return (contactManager.getContacts().size() > 1);
}
public void setCustodians(List<ContactId> contacts) {
custodians = contacts;
}
public void createBackup() {
try {
db.transaction(false, txn -> {
socialBackupManager
.createBackup(txn, (List<ContactId>) custodians,
threshold);
});
} catch (DbException e) {
state.postValue(State.FAILURE);
}
}
public void setThreshold(int threshold) {
this.threshold = threshold;
createBackup();
}
public void onSuccessDismissed() {
state.postValue(State.SUCCESS);
}
public MutableLiveData<State> getState() {
return state;
}
public void onExplainerDismissed() {
state.postValue(State.CHOOSING_CUSTODIANS);
}
@Override
protected boolean displayContact(ContactId contactId) {
// Check if contact holds a backup piece
return custodians.contains(contactId);
}
public int getThresholdFromExistingBackup() {
return backupMetadata.getThreshold();
}
public int getNumberOfCustodiansFromExistingBackup() {
return backupMetadata.getCustodians().size();
}
}

View File

@@ -0,0 +1,12 @@
package org.briarproject.briar.android.socialbackup;
import org.briarproject.bramble.api.db.DbException;
import androidx.annotation.UiThread;
public interface ThresholdDefinedListener {
@UiThread
void thresholdDefined(int threshold) throws DbException;
}

View File

@@ -2,10 +2,6 @@ package org.briarproject.briar.android.socialbackup;
import android.content.Context;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.ImageSpan;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -15,28 +11,22 @@ import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.TextView;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.login.StrengthMeter;
import org.magmacollective.darkcrystal.secretsharingwrapper.SecretSharingWrapper;
import java.util.Arrays;
import javax.inject.Inject;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.ViewModelProvider;
import static android.view.View.GONE;
public class ThresholdSelectorFragment extends BaseFragment {
public static final String TAG = ThresholdSelectorFragment.class.getName();
private static final String NUMBER_CUSTODIANS = "numberCustodians";
protected ThresholdDefinedListener listener;
private int numberOfCustodians;
private int threshold;
private int recommendedThreshold;
@@ -44,19 +34,6 @@ public class ThresholdSelectorFragment extends BaseFragment {
private TextView thresholdRepresentation;
private TextView message;
private TextView mOfn;
private StrengthMeter strengthMeter;
@Inject
ViewModelProvider.Factory viewModelFactory;
private SocialBackupSetupViewModel viewModel;
@Override
public void injectFragment(ActivityComponent component) {
component.inject(this);
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
.get(SocialBackupSetupViewModel.class);
}
public static ThresholdSelectorFragment newInstance(int numberCustodians) {
Bundle bundle = new Bundle();
@@ -85,21 +62,21 @@ public class ThresholdSelectorFragment extends BaseFragment {
thresholdRepresentation =
view.findViewById(R.id.textViewThresholdRepresentation);
message = view.findViewById(R.id.textViewMessage);
mOfn = view.findViewById(R.id.text_view_m_of_n);
strengthMeter = view.findViewById(R.id.strength_meter);
mOfn = view.findViewById(R.id.textViewmOfn);
if (numberOfCustodians == 2) {
message.setText(R.string.threshold_too_few_custodians);
}
if (numberOfCustodians > 3) {
seekBar.setMax(numberOfCustodians -3);
seekBar.setProgress(threshold - 2);
seekBar.setOnSeekBarChangeListener(new SeekBarListener());
recommendedThreshold =
SecretSharingWrapper.defaultThreshold(numberOfCustodians);
threshold = recommendedThreshold;
seekBar.setProgress(threshold - 2);
strengthMeter.setStrength(1);
} else {
seekBar.setEnabled(false);
seekBar.setVisibility(GONE);
strengthMeter.setVisibility(GONE);
threshold = 2;
seekBar.setMax(numberOfCustodians);
seekBar.setProgress(threshold);
@@ -121,13 +98,20 @@ public class ThresholdSelectorFragment extends BaseFragment {
@Override
public void onAttach(Context context) {
super.onAttach(context);
listener = (ThresholdDefinedListener) context;
}
@Override
public String getUniqueTag() {
return TAG;
}
@Override
public void injectFragment(ActivityComponent component) {
component.inject(this);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.define_threshold_actions, menu);
@@ -138,42 +122,26 @@ public class ThresholdSelectorFragment extends BaseFragment {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_threshold_defined:
viewModel.setThreshold(threshold);
showSuccessDialog();
try {
listener.thresholdDefined(threshold);
} catch (DbException e) {
e.printStackTrace();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void showSuccessDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(),
R.style.BriarDialogTheme);
builder.setTitle(R.string.backup_created);
builder.setMessage(R.string.backup_done_info);
builder.setPositiveButton(R.string.ok,
(dialog, which) -> viewModel.onSuccessDismissed());
builder.setIcon(R.drawable.ic_baseline_done_outline_24);
AlertDialog dialog = builder.create();
dialog.show();
}
private SpannableStringBuilder buildThresholdRepresentationString() {
char[] charArray = new char[numberOfCustodians];
Arrays.fill(charArray, ' ');
SpannableStringBuilder string = new SpannableStringBuilder(new String(charArray));
for (int i = 0; i < numberOfCustodians; i++) {
int drawable = i < threshold
? R.drawable.ic_custodian_required
: R.drawable.ic_custodian_optional;
string.setSpan(new ImageSpan(getContext(), drawable), i,
i+1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
private String buildThresholdRepresentationString() {
String thresholdRepresentationText = "";
for (int i = 0; i < threshold; i++) {
thresholdRepresentationText += getString(R.string.filled_bullet);
}
// If we have more than 6, split it on two lines
if (numberOfCustodians > 6) string.insert(4, "\n");
return string;
for (int i = 0; i < (numberOfCustodians - threshold); i++) {
thresholdRepresentationText += getString(R.string.linear_bullet);
}
return thresholdRepresentationText;
}
private class SeekBarListener implements SeekBar.OnSeekBarChangeListener {
@@ -191,23 +159,12 @@ public class ThresholdSelectorFragment extends BaseFragment {
int sanityLevel = SecretSharingWrapper
.thresholdSanity(threshold, numberOfCustodians);
int text = R.string.threshold_secure;
float strength = 1;
if (threshold == recommendedThreshold) {
if (threshold == recommendedThreshold)
text = R.string.threshold_recommended;
}
if (sanityLevel < -1) {
strength = 0.75f;
text = R.string.threshold_low_insecure;
}
if (sanityLevel < -2) {
strength = 0.5f;
}
if (sanityLevel > 0) {
strength = 0.75f;
text = R.string.threshold_high_insecure;
}
strengthMeter.setStrength(strength);
if (sanityLevel < -1) text = R.string.threshold_low_insecure;
if (sanityLevel > 0) text = R.string.threshold_high_insecure;
message.setText(text);
// TODO change colour of thresholdRepresentation to green/red based on sanityLevel
}
@Override

View File

@@ -32,6 +32,11 @@ public class CustodianRecoveryModeExplainerFragment extends BaseFragment {
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
.get(CustodianReturnShardViewModel.class);
}
// @Override
// public void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// requireActivity().setTitle(R.string.title_help_recover);
// }
@Nullable
@Override

View File

@@ -13,6 +13,7 @@ import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.api.socialbackup.recovery.CustodianTask;
import java.io.IOException;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.inject.Inject;
@@ -20,12 +21,17 @@ import javax.inject.Inject;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
public class CustodianReturnShardActivity extends BriarActivity
implements BaseFragment.BaseFragmentListener {
private CustodianReturnShardViewModel viewModel;
private static final Logger LOG =
getLogger(CustodianReturnShardActivity.class.getName());
private ContactId contactId;
@Inject
ViewModelProvider.Factory viewModelFactory;
@@ -46,7 +52,7 @@ public class CustodianReturnShardActivity extends BriarActivity
Intent intent = getIntent();
int id = intent.getIntExtra(CONTACT_ID, -1);
if (id == -1) throw new IllegalStateException("No ContactId");
ContactId contactId = new ContactId(id);
contactId = new ContactId(id);
try {
viewModel.start(contactId);
@@ -90,8 +96,7 @@ public class CustodianReturnShardActivity extends BriarActivity
"It looks like you are not connected to a Wifi network",
Toast.LENGTH_SHORT).show();
FragmentManager fm = getSupportFragmentManager();
if (fm.findFragmentByTag(CustodianReturnShardFragment.TAG) ==
null) {
if (fm.findFragmentByTag(CustodianReturnShardFragment.TAG) == null) {
BaseFragment f = new CustodianReturnShardErrorFragment();
fm.beginTransaction()
.replace(R.id.fragmentContainer, f, f.getUniqueTag())
@@ -101,15 +106,19 @@ public class CustodianReturnShardActivity extends BriarActivity
}
}
private void onReturnShardStateChanged(CustodianTask.State state) {
if (state instanceof CustodianTask.State.Failure) {
// TODO error fragment here
// TODO handle reason
Toast.makeText(this,
"Backup piece transfer failed",
Toast.LENGTH_SHORT).show();
finish();
}
if (state instanceof CustodianTask.State.Success) {
CustodianReturnShardSuccessFragment fragment = new CustodianReturnShardSuccessFragment();
showNextFragment(fragment);
} else if (state instanceof CustodianTask.State.Failure) {
// TODO error fragment here
// TODO handle reason
Toast.makeText(this,
"Backup piece transfer failed",
Toast.LENGTH_SHORT).show();
finish();
}
}
private void showCameraFragment() {

View File

@@ -5,7 +5,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
@@ -25,7 +24,6 @@ import javax.annotation.Nullable;
import javax.inject.Inject;
import androidx.annotation.UiThread;
import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.ViewModelProvider;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
@@ -55,7 +53,6 @@ public class CustodianReturnShardFragment extends BaseFragment
private LinearLayout cameraOverlay;
private View statusView;
private TextView status;
private ProgressBar bottomSpinner;
public static CustodianReturnShardFragment newInstance() {
Bundle args = new Bundle();
@@ -87,7 +84,6 @@ public class CustodianReturnShardFragment extends BaseFragment
cameraOverlay = view.findViewById(R.id.camera_overlay);
statusView = view.findViewById(R.id.status_container);
status = view.findViewById(R.id.connect_status);
bottomSpinner = view.findViewById(R.id.qr_code_progress_bar);
viewModel.getState().observe(getViewLifecycleOwner(),
this::onReturnShardStateChanged);
@@ -145,6 +141,7 @@ public class CustodianReturnShardFragment extends BaseFragment
@UiThread
private void onReturnShardStateChanged(@Nullable CustodianTask.State state) {
LOG.info("State changed");
// if (state instanceof CustodianTask.State.Connecting) {
// try {
// cameraView.stop();
@@ -166,9 +163,8 @@ public class CustodianReturnShardFragment extends BaseFragment
} else if (state instanceof CustodianTask.State.ReceivingAck) {
status.setText("Receiving Ack");
} else if (state instanceof CustodianTask.State.Success) {
statusView.setVisibility(INVISIBLE);
bottomSpinner.setVisibility(INVISIBLE);
showSuccessDialog();
// TODO
status.setText(R.string.exchanging_contact_details);
} else if (state instanceof CustodianTask.State.Failure) {
// the activity will replace this fragment with an error fragment
statusView.setVisibility(INVISIBLE);
@@ -194,15 +190,4 @@ public class CustodianReturnShardFragment extends BaseFragment
requireActivity().getSupportFragmentManager().popBackStack();
}
private void showSuccessDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(),
R.style.BriarDialogTheme);
builder.setTitle(R.string.custodian_shard_sent);
//builder.setMessage();
builder.setPositiveButton(R.string.ok,
(dialog, which) -> viewModel.onSuccessDismissed());
builder.setIcon(R.drawable.ic_baseline_done_outline_24);
AlertDialog dialog = builder.create();
dialog.show();
}
}

View File

@@ -1,4 +1,4 @@
package org.briarproject.briar.android.socialbackup;
package org.briarproject.briar.android.socialbackup.recover;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -6,6 +6,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.fragment.BaseFragment;
@@ -16,33 +18,37 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;
public class SetupExplainerFragment extends BaseFragment {
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class CustodianReturnShardSuccessFragment extends
BaseFragment {
public static final String TAG =
SetupExplainerFragment.class.getName();
CustodianReturnShardFragment.class.getName();
@Inject
ViewModelProvider.Factory viewModelFactory;
private SocialBackupSetupViewModel viewModel;
private CustodianReturnShardViewModel viewModel;
@Override
public void injectFragment(ActivityComponent component) {
component.inject(this);
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
.get(SocialBackupSetupViewModel.class);
.get(CustodianReturnShardViewModel.class);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
ViewGroup container, @Nullable Bundle savedInstanceState) {
View view =
inflater.inflate(R.layout.fragment_social_backup_setup_explainer,
container, false);
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_recovery_custodian_done,
container, false);
Button button = view.findViewById(R.id.button);
button.setOnClickListener(e -> viewModel.onExplainerDismissed());
button.setOnClickListener(e -> viewModel.onSuccessDismissed());
return view;
}
@@ -51,4 +57,3 @@ public class SetupExplainerFragment extends BaseFragment {
return TAG;
}
}

View File

@@ -53,7 +53,7 @@ public class CustodianReturnShardViewModel extends AndroidViewModel
final QrCodeDecoder qrCodeDecoder;
private boolean qrCodeRead = false;
private WifiManager wifiManager;
private final MutableLiveEvent<Boolean> continueClicked = new MutableLiveEvent<>();
private final MutableLiveEvent<Boolean > continueClicked = new MutableLiveEvent<>();
private final MutableLiveEvent<Boolean> showCameraFragment =
new MutableLiveEvent<>();
private final MutableLiveEvent<Boolean> successDismissed =
@@ -177,6 +177,7 @@ public class CustodianReturnShardViewModel extends AndroidViewModel
successDismissed.setEvent(true);
}
QrCodeDecoder getQrCodeDecoder() {
return qrCodeDecoder;
}

View File

@@ -44,6 +44,13 @@ public class OwnerReturnShardActivity extends BaseActivity
private OwnerReturnShardViewModel viewModel;
// private final ActivityResultLauncher<String[]> permissionLauncher =
// registerForActivityResult(
// new ActivityResultContracts.RequestMultiplePermissions(),
// r ->
// permissionManager.onRequestPermissionResult(r,
// viewModel::showQrCodeFragmentIfAllowed));
@Override
public void injectActivity(ActivityComponent component) {
component.inject(this);
@@ -147,8 +154,7 @@ public class OwnerReturnShardActivity extends BaseActivity
"WARNING: Mismatched backup piece!",
Toast.LENGTH_LONG).show();
}
boolean added = result !=
RestoreAccount.AddReturnShardPayloadResult.DUPLICATE;
boolean added = (result != RestoreAccount.AddReturnShardPayloadResult.DUPLICATE) ? true : false;
Toast.makeText(this,
"Success - got backup piece" + (added ? "" : " duplicate"),
Toast.LENGTH_SHORT).show();

View File

@@ -27,6 +27,7 @@ import androidx.lifecycle.ViewModelProvider;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.widget.LinearLayout.HORIZONTAL;
@@ -157,4 +158,5 @@ public class OwnerReturnShardFragment extends BaseFragment
protected void finish() {
requireActivity().getSupportFragmentManager().popBackStack();
}
}

View File

@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/briar_button_text_positive" android:state_enabled="true"/>
<item android:color="@color/briar_button_text_disabled" />
</selector>

View File

@@ -1,5 +0,0 @@
<vector android:height="48dp" android:tint="#660066"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>

View File

@@ -1,5 +0,0 @@
<vector android:height="48dp" android:tint="#FF00FF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>

View File

@@ -1,7 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="72dp"
android:width="72dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M12,5.5A3.5,3.5 0 0,1 15.5,9A3.5,3.5 0 0,1 12,12.5A3.5,3.5 0 0,1 8.5,9A3.5,3.5 0 0,1 12,5.5M5,8C5.56,8 6.08,8.15 6.53,8.42C6.38,9.85 6.8,11.27 7.66,12.38C7.16,13.34 6.16,14 5,14A3,3 0 0,1 2,11A3,3 0 0,1 5,8M19,8A3,3 0 0,1 22,11A3,3 0 0,1 19,14C17.84,14 16.84,13.34 16.34,12.38C17.2,11.27 17.62,9.85 17.47,8.42C17.92,8.15 18.44,8 19,8M5.5,18.25C5.5,16.18 8.41,14.5 12,14.5C15.59,14.5 18.5,16.18 18.5,18.25V20H5.5V18.25M0,20V18.5C0,17.11 1.89,15.94 4.45,15.6C3.86,16.28 3.5,17.22 3.5,18.25V20H0M24,20H20.5V18.25C20.5,17.22 20.14,16.28 19.55,15.6C22.11,15.94 24,17.11 24,18.5V20Z" />
</vector>

View File

@@ -16,7 +16,6 @@
app:title="@string/setup_title"
app:titleTextColor="@android:color/white" />
<!-- <include layout="@layout/fragment_start" />-->
<include layout="@layout/fragment_new_or_recover" />
<include layout="@layout/fragment_start" />
</LinearLayout>

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
@@ -10,35 +11,25 @@
android:paddingBottom="@dimen/margin_medium"
android:layout_height="match_parent">
<TextView
android:id="@+id/textViewThresholdRepresentation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="64sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textViewThreshold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="placeholder threshold"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewThresholdRepresentation" />
app:layout_constraintTop_toTopOf="parent" />
<org.briarproject.briar.android.view.BriarRecyclerView
android:id="@+id/custodianList"
android:layout_width="match_parent"
<TextView
android:id="@+id/textViewCustodians"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:gravity="center"
android:text="@string/backup_done_info"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textViewThreshold"
app:scrollToEnd="false" />
app:layout_constraintTop_toBottomOf="@+id/textViewThreshold" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -13,38 +13,22 @@
<Button
android:id="@+id/buttonSetupNewAccount"
style="@style/BriarButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/setup_new_account"
android:drawableLeft="@drawable/ic_contacts"
android:text="@string/setup_new_account"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:drawableStart="@drawable/ic_contacts" />
<TextView
android:id="@+id/textViewExplain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:gravity="center"
android:text="@string/custodian_recovery_explainer_extra"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/buttonSetupNewAccount"
tools:layout_editor_absoluteX="16dp" />
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/buttonRestoreAccount2"
style="@style/BriarButton"
android:id="@+id/buttonRestoreAccount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_repeat"
android:text="@string/setup_restore_account"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewExplain"
tools:enabled="true"
android:drawableStart="@drawable/ic_repeat" />
app:layout_constraintTop_toBottomOf="@+id/buttonSetupNewAccount" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -8,52 +8,43 @@
android:paddingLeft="@dimen/margin_large"
android:paddingTop="@dimen/margin_medium"
android:paddingRight="@dimen/margin_large"
android:paddingBottom="@dimen/margin_medium"
tools:ignore="VectorDrawableCompat">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:gravity="center"
android:text="@string/social_backup_setup_explainer_title"
android:textSize="24sp"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="16dp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:srcCompat="@drawable/ic_social_backup_group" />
<TextView
android:id="@+id/textViewExplain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="@string/social_backup_setup_explainer_long"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView"
tools:layout_editor_absoluteX="16dp" />
android:paddingBottom="@dimen/margin_medium">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/social_backup_setup_explainer_button"
android:layout_marginTop="32dp"
android:text="@string/ok"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewExplain" />
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="@string/custodian_shard_sent"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_baseline_done_outline_24" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -45,7 +45,7 @@
app:layout_constraintTop_toBottomOf="@+id/seekBar" />
<TextView
android:id="@+id/text_view_m_of_n"
android:id="@+id/textViewmOfn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
@@ -55,17 +55,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewThresholdRepresentation" />
<org.briarproject.briar.android.login.StrengthMeter
android:id="@+id/strength_meter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:visibility="visible"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_m_of_n"
tools:visibility="visible" />
<TextView
android:id="@+id/textViewMessage"
android:layout_width="wrap_content"
@@ -75,6 +64,6 @@
android:textSize="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/strength_meter" />
app:layout_constraintTop_toBottomOf="@+id/textViewmOfn" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -47,28 +47,14 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_activity_horizontal"
android:enabled="false"
android:text="@string/setup_new_account"
android:text="@string/setup_next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nickname_entry_wrapper"
app:layout_constraintVertical_bias="1.0"
tools:enabled="true" />
<Button
android:id="@+id/buttonRestoreAccount"
style="@style/BriarButtonFlat.Positive.Tiny"
android:textColor="@drawable/button_positive_tiny_disable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_activity_horizontal"
android:text="@string/setup_restore_account"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/next"
app:layout_constraintVertical_bias="1.0"
tools:enabled="true" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/margin_large"
android:paddingTop="@dimen/margin_medium"
android:paddingRight="@dimen/margin_large"
android:paddingBottom="@dimen/margin_medium">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/ok"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/backup_done_info"
android:gravity="center"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_baseline_done_outline_24" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -6,7 +6,6 @@
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:id="@+id/qr_code_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />

View File

@@ -9,7 +9,7 @@
<string name="setup_name_explanation">Your nickname will be shown next to any content you post. You can\'t change it after creating your account.</string>
<string name="setup_next">Next</string>
<string name="setup_password_intro">Choose a Password</string>
<string name="setup_password_explanation">Your Briar account is stored encrypted on your device, not in the cloud. If you forget your password or uninstall Briar, your account will be lost.\n\nTo avoid this, use the \'Social Backup\' feature in settings menu to make a backup.</string>
<string name="setup_password_explanation">Your Briar account is stored encrypted on your device, not in the cloud. If you forget your password or uninstall Briar, you can only recover your account if you have made a social backup.\n\nChoose a long password that\'s hard to guess, such as four random words, or ten random letters, numbers and symbols.</string>
<string name="setup_doze_title">Background Connections</string>
<string name="setup_doze_intro">To receive messages, Briar needs to stay connected in the background.</string>
<string name="setup_doze_explanation">To receive messages, Briar needs to stay connected in the background. Please disable battery optimizations so Briar can stay connected.</string>
@@ -653,30 +653,24 @@
<!-- social backup procedure -->
<string name="select_custodians">Select Trusted Contacts</string>
<string name="select_custodians">Select Trusted Contacts:</string>
<string name="select_at_least_n_contacts">Please select at least %d contacts</string>
<string name="select_at_least_n_more_contacts">Please select at least %d more contacts</string>
<string name="select_no_more_than_n_contacts">Too many! Please select no more than %d contacts</string>
<string name="threshold">Set the minimum number of trusted contacts needed</string>
<string name="threshold">Choose the minimum number of trusted contacts needed to restore your account</string>
<string name="threshold_disabled">Two trusted contacts will be needed to restore your account</string>
<string name="threshold_secure">Secure</string>
<string name="threshold_recommended">Secure - recommended threshold</string>
<string name="threshold_low_insecure">Insecure higher threshold recommended</string>
<string name="threshold_high_insecure">Danger of loss lower threshold recommended</string>
<string name="threshold_defined">Choose Minimum Needed</string>
<string name="threshold_too_few_custodians">Danger of loss - more contacts recommended</string>
<string name="threshold_defined">Choose Threshold</string>
<string name="threshold_m_of_n">%d of %d contacts needed to recover your account</string>
<string name="backup_created">Social Backup created</string>
<string name="backup_done_info">Backup pieces sent to trusted contacts</string>
<string name="social_backup_setup_explainer_title">Backup your Briar identity and contacts list</string>
<string name="social_backup_setup_explainer_long">Choose a set of trusted contacts to send backup pieces to.\n\nYou decide how many of these contacts must help you recover your account.\n\nFor example, you can choose three trusted contacts and that any two of them are needed to recover.</string>
<string name="social_backup_setup_explainer_button">Choose trusted contacts</string>
<string name="social_backup_onboarding_title">Backup your Briar account</string>
<string name="social_backup_onboarding_long">Social backup feature allows you to recover your account with the help of trusted contacts</string>
<string name="backup_created">Backup created 1/6/2020</string>
<!-- recovery from the secret owner's POV -->
@@ -706,7 +700,7 @@
<string name="title_distributed_backup">Social Backup</string>
<string name="title_select_custodians">Select Trusted Contacts</string>
<string name="title_define_threshold">Minimum Needed</string>
<string name="title_define_threshold">Threshold</string>
<string name="title_recovery_mode">Recovery Mode</string>
<string name="title_help_recover">Help recover account</string>
@@ -719,6 +713,10 @@
<string name="setup_new_account">Create new account</string>
<string name="setup_restore_account">Restore account from backup</string>
<!-- Symbols for visualising threshold values for social backup -->
<string name="filled_bullet">\u25CF</string>
<string name="linear_bullet">\u25CB</string>
<!-- activity names -->
<string name="activity_name_distributed_backup">Social Backup</string>
<string name="activity_name_restore_account">Restore Account</string>
@@ -730,11 +728,8 @@
<string name="activity_name_new_or_recover_account">Create new account or recover existing account</string>
<string name="activity_name_recovery">Recover Account</string>
<string name="activity_name_custodian_help_recovery">Help recover account</string>
<string name="existing_backup_explain">Any %d of the following contacts are needed to restore your Briar account, should you lose access to it.</string>
<string name="existing_backup_explain">%d of the following contacts are needed to restore your account:</string>
<string name="social_backup_not_enough_contacts">To make a social backup, you need at least 2 contacts in your contacts list</string>
<string name="reading_contacts_error">There was an error reading your contacts list</string>
<!-- Display existing backup -->
<string name="social_backup_trusted_contacts">Trusted Contacts</string>
</resources>

View File

@@ -96,7 +96,7 @@
app:iconSpaceReserved="false">
<intent
android:targetClass="org.briarproject.briar.android.socialbackup.SocialBackupSetupActivity"
android:targetClass="org.briarproject.briar.android.socialbackup.DistributedBackupActivity"
android:targetPackage="@string/app_package" />
</Preference>

View File

@@ -78,11 +78,4 @@ public interface SocialBackupManager extends
*/
byte[] getReturnShardPayloadBytes(Transaction txn, ContactId contactId)
throws DbException;
/**
* Get a list of the contact ids of your custodians, or an empty
* list if no backup exists.
*/
List<ContactId> getCustodianContactIds(Transaction txn);
}

View File

@@ -612,30 +612,4 @@ class SocialBackupManagerImpl extends ConversationClientImpl
results.entrySet().iterator().next();
return new Pair<>(e.getKey(), e.getValue());
}
public List<ContactId> getCustodianContactIds(Transaction txn) {
ArrayList<ContactId> contactIds = new ArrayList<>();
try {
BackupMetadata b = getBackupMetadata(txn);
if (b == null) throw new DbException();
List<Author> custodians = b.getCustodians();
for (Author custodian : custodians) {
contactIds.add(authorToContactId(txn, custodian));
}
} catch (DbException ignored) {
// Will return an empty list
}
return contactIds;
}
private ContactId authorToContactId(Transaction txn, Author author)
throws DbException {
ArrayList<Contact> contacts =
(ArrayList<Contact>) contactManager.getContacts(txn);
for (Contact c : contacts) {
if (c.getAuthor().equals(author)) return c.getId();
}
throw new DbException();
}
}

View File

@@ -201,6 +201,9 @@ public class RestoreAccountImpl implements RestoreAccount {
transportPropertyManager
.mergeLocalProperties(propertiesEntry.getKey(),
propertiesEntry.getValue());
// for (Map.Entry<String, String> entry : propertiesEntry.getValue().entrySet()) {
// LOG.info(String.format("%s : %s", entry.getKey(), entry.getValue()));
// }
}
}