mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 14:49:53 +01:00
Merge branch social-backup-poc
This commit is contained in:
@@ -298,11 +298,13 @@ class ConversationVisitor implements
|
|||||||
@Override
|
@Override
|
||||||
public ConversationItem visitShardMessage(ShardMessageHeader r) {
|
public ConversationItem visitShardMessage(ShardMessageHeader r) {
|
||||||
if (r.isLocal()) {
|
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(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text, r);
|
R.layout.list_item_conversation_notice_out, text, r);
|
||||||
} else {
|
} 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(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_in, text, r);
|
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);
|
showNextFragment(fragment);
|
||||||
});
|
});
|
||||||
} catch (DbException e) {
|
} 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();
|
Bundle bundle = new Bundle();
|
||||||
List<Author> custodians = backupMetadata.getCustodians();
|
List<Author> custodians = backupMetadata.getCustodians();
|
||||||
ArrayList custodianNames = new ArrayList();
|
ArrayList custodianNames = new ArrayList();
|
||||||
for (Author custodian : custodians) {
|
for (Author custodian : custodians) {
|
||||||
custodianNames.add(custodian.getName());
|
custodianNames.add(custodian.getName());
|
||||||
}
|
}
|
||||||
bundle.putStringArrayList(CUSTODIANS, custodianNames);
|
bundle.putStringArrayList(CUSTODIANS, custodianNames);
|
||||||
bundle.putInt(THRESHOLD, backupMetadata.getThreshold());
|
bundle.putInt(THRESHOLD, backupMetadata.getThreshold());
|
||||||
ExistingBackupFragment fragment = new ExistingBackupFragment();
|
ExistingBackupFragment fragment = new ExistingBackupFragment();
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -53,15 +54,22 @@ public class ExistingBackupFragment extends BaseFragment {
|
|||||||
View view = inflater.inflate(R.layout.fragment_existing_backup,
|
View view = inflater.inflate(R.layout.fragment_existing_backup,
|
||||||
container, false);
|
container, false);
|
||||||
Bundle args = requireArguments();
|
Bundle args = requireArguments();
|
||||||
ArrayList<String> custodianNames = args.getStringArrayList(CUSTODIANS);
|
ArrayList<String> custodianNames = args.getStringArrayList(CUSTODIANS);
|
||||||
String custodianNamesString = "";
|
|
||||||
for (String custodianName : custodianNames) {
|
StringBuilder custodianNamesString = new StringBuilder();
|
||||||
custodianNamesString += custodianName + ", ";
|
for (String custodianName : custodianNames) {
|
||||||
}
|
custodianNamesString
|
||||||
TextView textViewThreshold = view.findViewById(R.id.textViewThreshold);
|
.append("• ")
|
||||||
textViewThreshold.setText(String.format("%d of %d contacts needed to restore account", args.getInt(THRESHOLD), custodianNames.size()));
|
.append(custodianName)
|
||||||
TextView textViewCustodians = view.findViewById(R.id.textViewCustodians);
|
.append("\n");
|
||||||
textViewCustodians.setText(custodianNamesString);
|
}
|
||||||
|
|
||||||
|
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;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,4 +67,8 @@ public class ShardsSentFragment extends BaseFragment {
|
|||||||
component.inject(this);
|
component.inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onBackPressed() {
|
||||||
|
listener.shardsSentDismissed();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -723,12 +723,13 @@
|
|||||||
<string name="activity_name_restore_account">Restore Account</string>
|
<string name="activity_name_restore_account">Restore Account</string>
|
||||||
|
|
||||||
<!-- conversation -->
|
<!-- conversation -->
|
||||||
<string name="social_backup_shard_received">You have received 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.</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_new_or_recover_account">Create new account or recover existing account</string>
|
||||||
<string name="activity_name_recovery">Recover Account</string>
|
<string name="activity_name_recovery">Recover Account</string>
|
||||||
<string name="activity_name_custodian_help_recovery">Help 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 -->
|
<!-- Remote Wipe -->
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.briar.api.socialbackup;
|
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.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
@@ -50,15 +49,33 @@ public interface SocialBackupManager extends
|
|||||||
void createBackup(Transaction txn, List<ContactId> custodianIds,
|
void createBackup(Transaction txn, List<ContactId> custodianIds,
|
||||||
int threshold) throws DbException;
|
int threshold) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a collection of social backup message headers
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
Collection<ConversationMessageHeader> getMessageHeaders(
|
Collection<ConversationMessageHeader> getMessageHeaders(
|
||||||
Transaction txn, ContactId contactId) throws DbException;
|
Transaction txn, ContactId contactId) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether you hold a shard belonging to a given contact
|
||||||
|
*/
|
||||||
boolean amCustodian(Transaction txn, ContactId contactId);
|
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;
|
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)
|
byte[] getReturnShardPayloadBytes(Transaction txn, ContactId contactId)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
}
|
}
|
||||||
// Create the encrypted backup payload
|
// Create the encrypted backup payload
|
||||||
SecretKey secret = crypto.generateSecretKey();
|
SecretKey secret = crypto.generateSecretKey();
|
||||||
List<org.briarproject.briar.api.socialbackup.ContactData> contactData = loadContactData(txn);
|
List<ContactData> contactData = loadContactData(txn);
|
||||||
BackupPayload payload =
|
BackupPayload payload =
|
||||||
createBackupPayload(txn, secret, contactData, 0);
|
createBackupPayload(txn, secret, contactData, 0);
|
||||||
// Create the shards
|
// Create the shards
|
||||||
@@ -423,7 +423,7 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
contactData, version);
|
contactData, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<org.briarproject.briar.api.socialbackup.ContactData> loadContactData(Transaction txn)
|
private List<ContactData> loadContactData(Transaction txn)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
Collection<Contact> contacts = contactManager.getContacts(txn);
|
Collection<Contact> contacts = contactManager.getContacts(txn);
|
||||||
List<org.briarproject.briar.api.socialbackup.ContactData> contactData = new ArrayList<>();
|
List<org.briarproject.briar.api.socialbackup.ContactData> contactData = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user