mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Merge branch social-backup-poc
This commit is contained in:
@@ -298,11 +298,13 @@ class ConversationVisitor implements
|
||||
@Override
|
||||
public ConversationItem visitShardMessage(ShardMessageHeader r) {
|
||||
if (r.isLocal()) {
|
||||
String text = ctx.getString(R.string.social_backup_shard_sent);
|
||||
String text = ctx.getString(R.string.social_backup_shard_sent,
|
||||
contactName.getValue());
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text = ctx.getString(R.string.social_backup_shard_received);
|
||||
String text = ctx.getString(R.string.social_backup_shard_received,
|
||||
contactName.getValue());
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_in, text, r);
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package org.briarproject.briar.android.socialbackup;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
public interface CustodianScanQrButtonListener {
|
||||
@UiThread
|
||||
void scanQrButtonClicked();
|
||||
}
|
||||
@@ -80,7 +80,10 @@ public class DistributedBackupActivity extends BriarActivity implements
|
||||
showNextFragment(fragment);
|
||||
});
|
||||
} catch (DbException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this,
|
||||
"There was an error when creating the backup",
|
||||
Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,15 +30,16 @@ public class ExistingBackupFragment extends BaseFragment {
|
||||
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);
|
||||
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
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -53,15 +54,22 @@ public class ExistingBackupFragment extends BaseFragment {
|
||||
View view = inflater.inflate(R.layout.fragment_existing_backup,
|
||||
container, false);
|
||||
Bundle args = requireArguments();
|
||||
ArrayList<String> custodianNames = args.getStringArrayList(CUSTODIANS);
|
||||
String custodianNamesString = "";
|
||||
for (String custodianName : custodianNames) {
|
||||
custodianNamesString += custodianName + ", ";
|
||||
}
|
||||
TextView textViewThreshold = view.findViewById(R.id.textViewThreshold);
|
||||
textViewThreshold.setText(String.format("%d of %d contacts needed to restore account", args.getInt(THRESHOLD), custodianNames.size()));
|
||||
TextView textViewCustodians = view.findViewById(R.id.textViewCustodians);
|
||||
textViewCustodians.setText(custodianNamesString);
|
||||
ArrayList<String> custodianNames = args.getStringArrayList(CUSTODIANS);
|
||||
|
||||
StringBuilder custodianNamesString = new StringBuilder();
|
||||
for (String custodianName : custodianNames) {
|
||||
custodianNamesString
|
||||
.append("• ")
|
||||
.append(custodianName)
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,4 +67,8 @@ public class ShardsSentFragment extends BaseFragment {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
public void onBackPressed() {
|
||||
listener.shardsSentDismissed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -723,12 +723,13 @@
|
||||
<string name="activity_name_restore_account">Restore Account</string>
|
||||
|
||||
<!-- conversation -->
|
||||
<string name="social_backup_shard_received">You have received a social backup shard.</string>
|
||||
<string name="social_backup_shard_sent">You have sent a social backup shard.</string>
|
||||
<string name="social_backup_shard_received">%1$s has sent you a social backup shard.</string>
|
||||
<string name="social_backup_shard_sent">You have sent a social backup shard to %1$s.</string>
|
||||
|
||||
<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">%d of the following contacts are needed to restore your account:</string>
|
||||
|
||||
<!-- Remote Wipe -->
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.briarproject.briar.api.socialbackup;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
@@ -50,15 +49,33 @@ public interface SocialBackupManager extends
|
||||
void createBackup(Transaction txn, List<ContactId> custodianIds,
|
||||
int threshold) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns a collection of social backup message headers
|
||||
*/
|
||||
@Override
|
||||
Collection<ConversationMessageHeader> getMessageHeaders(
|
||||
Transaction txn, ContactId contactId) throws DbException;
|
||||
|
||||
/**
|
||||
* Determines whether you hold a shard belonging to a given contact
|
||||
*/
|
||||
boolean amCustodian(Transaction txn, ContactId contactId);
|
||||
|
||||
ReturnShardPayload getReturnShardPayload(Transaction txn, ContactId contactId)
|
||||
/**
|
||||
* Retrieves the shard and encrypted backup you hold for a given contact
|
||||
*
|
||||
* @throws DbException if you are not a custodian for the given contact
|
||||
*/
|
||||
ReturnShardPayload getReturnShardPayload(Transaction txn,
|
||||
ContactId contactId)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Retrieves the shard and encrypted backup you hold for a given contact
|
||||
* encoded with BDF
|
||||
*
|
||||
* @throws DbException if you are not a custodian for the given contact
|
||||
*/
|
||||
byte[] getReturnShardPayloadBytes(Transaction txn, ContactId contactId)
|
||||
throws DbException;
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
// Create the encrypted backup payload
|
||||
SecretKey secret = crypto.generateSecretKey();
|
||||
List<org.briarproject.briar.api.socialbackup.ContactData> contactData = loadContactData(txn);
|
||||
List<ContactData> contactData = loadContactData(txn);
|
||||
BackupPayload payload =
|
||||
createBackupPayload(txn, secret, contactData, 0);
|
||||
// Create the shards
|
||||
@@ -423,7 +423,7 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
||||
contactData, version);
|
||||
}
|
||||
|
||||
private List<org.briarproject.briar.api.socialbackup.ContactData> loadContactData(Transaction txn)
|
||||
private List<ContactData> loadContactData(Transaction txn)
|
||||
throws DbException {
|
||||
Collection<Contact> contacts = contactManager.getContacts(txn);
|
||||
List<org.briarproject.briar.api.socialbackup.ContactData> contactData = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user