mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
CustodianHelpRecoverActivity passes a ReturnShardPayload
This commit is contained in:
@@ -11,6 +11,9 @@ import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.android.socialbackup.recover.ReturnShardActivity;
|
||||
import org.briarproject.briar.api.socialbackup.MessageEncoder;
|
||||
import org.briarproject.briar.api.socialbackup.ReturnShardPayload;
|
||||
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -24,9 +27,16 @@ public class CustodianHelpRecoverActivity extends BriarActivity implements
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
public static final String RETURN_SHARD_PAYLOAD = "ReturnShardPayload";
|
||||
|
||||
private ContactId contactId;
|
||||
|
||||
@Inject
|
||||
public SocialBackupManager socialBackupManager;
|
||||
|
||||
@Inject
|
||||
private MessageEncoder messageEncoder;
|
||||
|
||||
@Inject
|
||||
public DatabaseComponent db;
|
||||
|
||||
@@ -38,7 +48,7 @@ public class CustodianHelpRecoverActivity extends BriarActivity implements
|
||||
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);
|
||||
|
||||
// check if we have a shard for this secret owner
|
||||
try {
|
||||
@@ -61,7 +71,22 @@ public class CustodianHelpRecoverActivity extends BriarActivity implements
|
||||
|
||||
@Override
|
||||
public void scanQrButtonClicked() {
|
||||
// TODO scan qr code
|
||||
finish();
|
||||
try {
|
||||
db.transaction(false, txn -> {
|
||||
ReturnShardPayload returnShardPayload = socialBackupManager
|
||||
.getReturnShardPayload(txn, contactId);
|
||||
byte[] returnShardPayloadBytes = messageEncoder
|
||||
.encodeReturnShardPayload(returnShardPayload);
|
||||
|
||||
Intent i = new Intent(this, ReturnShardActivity.class);
|
||||
i.putExtra(RETURN_SHARD_PAYLOAD, returnShardPayloadBytes);
|
||||
startActivity(i);
|
||||
});
|
||||
} catch (DbException e) {
|
||||
Toast.makeText(this,
|
||||
"Error reading social backup from storage",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
@@ -16,6 +19,9 @@ import org.briarproject.briar.android.contact.add.nearby.AddNearbyContactFragmen
|
||||
import org.briarproject.briar.android.contact.add.nearby.AddNearbyContactPermissionManager;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.android.util.RequestBluetoothDiscoverable;
|
||||
import org.briarproject.briar.api.socialbackup.MessageEncoder;
|
||||
import org.briarproject.briar.api.socialbackup.MessageParser;
|
||||
import org.briarproject.briar.api.socialbackup.ReturnShardPayload;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -31,6 +37,7 @@ import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
import static android.widget.Toast.LENGTH_LONG;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.briar.android.socialbackup.CustodianHelpRecoverActivity.RETURN_SHARD_PAYLOAD;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -43,6 +50,12 @@ public class ReturnShardActivity extends BaseActivity
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
|
||||
@Inject
|
||||
MessageParser messageParser;
|
||||
|
||||
@Inject
|
||||
ClientHelper clientHelper;
|
||||
|
||||
private ReturnShardViewModel viewModel;
|
||||
private AddNearbyContactPermissionManager permissionManager;
|
||||
|
||||
@@ -69,6 +82,20 @@ public class ReturnShardActivity extends BaseActivity
|
||||
public void onCreate(@Nullable Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
byte[] returnShardPayloadBytes = getIntent().getByteArrayExtra(RETURN_SHARD_PAYLOAD);
|
||||
if (returnShardPayloadBytes != null) {
|
||||
try {
|
||||
ReturnShardPayload returnShardPayload = messageParser
|
||||
.parseReturnShardPayload(clientHelper.toList(returnShardPayloadBytes));
|
||||
viewModel.setSending(true);
|
||||
viewModel.setReturnShardPayload(returnShardPayload);
|
||||
} catch (FormatException e) {
|
||||
Toast.makeText(this,
|
||||
"Error reading social backup",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
setContentView(R.layout.activity_fragment_container);
|
||||
if (state == null) {
|
||||
showInitialFragment(getExplainerFragment());
|
||||
|
||||
@@ -48,6 +48,9 @@ import org.briarproject.briar.android.contact.add.nearby.QrCodeDecoder;
|
||||
import org.briarproject.briar.android.contact.add.nearby.QrCodeUtils;
|
||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||
import org.briarproject.briar.api.socialbackup.ReturnShardPayload;
|
||||
import org.briarproject.briar.api.socialbackup.SocialBackupExchangeManager;
|
||||
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -116,6 +119,9 @@ class ReturnShardViewModel extends AndroidViewModel
|
||||
@SuppressWarnings("CharsetObjectCanBeUsed") // Requires minSdkVersion >= 19
|
||||
private static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
|
||||
|
||||
private boolean sending;
|
||||
private ReturnShardPayload returnShardPayload;
|
||||
|
||||
private final EventBus eventBus;
|
||||
private final AndroidExecutor androidExecutor;
|
||||
private final Executor ioExecutor;
|
||||
@@ -123,7 +129,8 @@ class ReturnShardViewModel extends AndroidViewModel
|
||||
private final PayloadEncoder payloadEncoder;
|
||||
private final PayloadParser payloadParser;
|
||||
private final Provider<KeyAgreementTask> keyAgreementTaskProvider;
|
||||
private final ContactExchangeManager contactExchangeManager;
|
||||
private final SocialBackupExchangeManager socialBackupExchangeManager;
|
||||
private final SocialBackupManager socialBackupManager;
|
||||
private final ConnectionManager connectionManager;
|
||||
|
||||
private final MutableLiveEvent<Boolean> checkPermissions =
|
||||
@@ -176,7 +183,8 @@ class ReturnShardViewModel extends AndroidViewModel
|
||||
PayloadEncoder payloadEncoder,
|
||||
PayloadParser payloadParser,
|
||||
Provider<KeyAgreementTask> keyAgreementTaskProvider,
|
||||
ContactExchangeManager contactExchangeManager,
|
||||
SocialBackupExchangeManager socialBackupExchangeManager,
|
||||
SocialBackupManager socialBackupManager,
|
||||
ConnectionManager connectionManager) {
|
||||
super(app);
|
||||
this.eventBus = eventBus;
|
||||
@@ -186,7 +194,8 @@ class ReturnShardViewModel extends AndroidViewModel
|
||||
this.payloadEncoder = payloadEncoder;
|
||||
this.payloadParser = payloadParser;
|
||||
this.keyAgreementTaskProvider = keyAgreementTaskProvider;
|
||||
this.contactExchangeManager = contactExchangeManager;
|
||||
this.socialBackupExchangeManager = socialBackupExchangeManager;
|
||||
this.socialBackupManager = socialBackupManager;
|
||||
this.connectionManager = connectionManager;
|
||||
bt = BluetoothAdapter.getDefaultAdapter();
|
||||
wifiPlugin = pluginManager.getPlugin(LanTcpConstants.ID);
|
||||
@@ -437,8 +446,11 @@ class ReturnShardViewModel extends AndroidViewModel
|
||||
boolean alice = result.wasAlice();
|
||||
ioExecutor.execute(() -> {
|
||||
try {
|
||||
Contact contact = contactExchangeManager.exchangeContacts(conn,
|
||||
masterKey, alice, true);
|
||||
if (sending) {
|
||||
socialBackupExchangeManager.sendReturnShard(conn, masterKey, alice, returnShardPayload);
|
||||
} else {
|
||||
ReturnShardPayload returnShardPayload = socialBackupExchangeManager.receiveReturnShard(conn, masterKey, alice);
|
||||
}
|
||||
// Reuse the connection as a transport connection
|
||||
connectionManager
|
||||
.manageOutgoingConnection(contact.getId(), t, conn);
|
||||
@@ -523,4 +535,11 @@ class ReturnShardViewModel extends AndroidViewModel
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setSending(boolean sending) {
|
||||
this.sending = sending;
|
||||
}
|
||||
|
||||
public void setReturnShardPayload(ReturnShardPayload returnShardPayload) {
|
||||
this.returnShardPayload = returnShardPayload;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user