only display custodian help recover explainer screen if you are a custodian

This commit is contained in:
ameba23
2021-03-22 17:03:22 +01:00
parent 365fa58928
commit 2486a60fea
2 changed files with 165 additions and 127 deletions

View File

@@ -1,11 +1,22 @@
package org.briarproject.briar.android.socialbackup; package org.briarproject.briar.android.socialbackup;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent; import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity; import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.fragment.BaseFragment; import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.api.socialbackup.BackupMetadata;
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
import javax.inject.Inject;
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
public class CustodianHelpRecoverActivity extends BriarActivity implements public class CustodianHelpRecoverActivity extends BriarActivity implements
BaseFragment.BaseFragmentListener, CustodianScanQrButtonListener { BaseFragment.BaseFragmentListener, CustodianScanQrButtonListener {
@@ -14,15 +25,39 @@ public class CustodianHelpRecoverActivity extends BriarActivity implements
component.inject(this); component.inject(this);
} }
@Inject
public SocialBackupManager socialBackupManager;
@Inject
public DatabaseComponent db;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recover); // TODO change this setContentView(R.layout.activity_recover); // TODO change this
// TODO check if we have a shard for this secret owner
// if not we should not even display the menu item Intent intent = getIntent();
int id = intent.getIntExtra(CONTACT_ID, -1);
if (id == -1) throw new IllegalStateException("No ContactId");
ContactId contactId = new ContactId(id);
// check if we have a shard for this secret owner
try {
db.transaction(false, txn -> {
if (!socialBackupManager.amCustodian(txn, contactId)) {
throw new DbException();
}
CustodianRecoveryModeExplainerFragment fragment = CustodianRecoveryModeExplainerFragment fragment =
new CustodianRecoveryModeExplainerFragment(); new CustodianRecoveryModeExplainerFragment();
showInitialFragment(fragment); showInitialFragment(fragment);
});
} catch (DbException e) {
// TODO improve this
Toast.makeText(this,
"You do not hold a backup shard from this contact",
Toast.LENGTH_SHORT).show();
finish();
}
} }
@Override @Override

View File

@@ -8,22 +8,17 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.briar.R; import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent; import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.contactselection.ContactSelectorListener;
import org.briarproject.briar.android.fragment.BaseFragment; import org.briarproject.briar.android.fragment.BaseFragment;
import org.magmacollective.darkcrystal.secretsharingwrapper.SecretSharingWrapper; import org.magmacollective.darkcrystal.secretsharingwrapper.SecretSharingWrapper;
import static java.util.Objects.requireNonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class ThresholdSelectorFragment extends BaseFragment { public class ThresholdSelectorFragment extends BaseFragment {
@@ -57,20 +52,24 @@ public class ThresholdSelectorFragment extends BaseFragment {
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_select_threshold, View view = inflater.inflate(R.layout.fragment_select_threshold,
container, false); container, false);
Bundle args = requireArguments(); Bundle args = requireArguments();
numberOfCustodians = args.getInt(NUMBER_CUSTODIANS); numberOfCustodians = args.getInt(NUMBER_CUSTODIANS);
seekBar = view.findViewById(R.id.seekBar); seekBar = view.findViewById(R.id.seekBar);
thresholdRepresentation = view.findViewById(R.id.textViewThresholdRepresentation); thresholdRepresentation =
view.findViewById(R.id.textViewThresholdRepresentation);
message = view.findViewById(R.id.textViewMessage); message = view.findViewById(R.id.textViewMessage);
mOfn = view.findViewById(R.id.textViewmOfn); mOfn = view.findViewById(R.id.textViewmOfn);
int max = numberOfCustodians - 3; int max = numberOfCustodians - 3;
seekBar.setMax(max); seekBar.setMax(max);
seekBar.setOnSeekBarChangeListener(new SeekBarListener()); seekBar.setOnSeekBarChangeListener(new SeekBarListener());
recommendedThreshold = SecretSharingWrapper.defaultThreshold(numberOfCustodians); recommendedThreshold =
SecretSharingWrapper.defaultThreshold(numberOfCustodians);
threshold = recommendedThreshold; threshold = recommendedThreshold;
seekBar.setProgress(threshold - 2); seekBar.setProgress(threshold - 2);
@@ -81,7 +80,9 @@ public class ThresholdSelectorFragment extends BaseFragment {
} }
private void setmOfnText() { private void setmOfnText() {
mOfn.setText(String.format("%d of %d contacts needed to recover your account", threshold, numberOfCustodians)); mOfn.setText(String.format(
"%d of %d contacts needed to recover your account", threshold,
numberOfCustodians));
} }
@Override @Override
@@ -122,7 +123,7 @@ public class ThresholdSelectorFragment extends BaseFragment {
} }
} }
private String buildThresholdRepresentationString () { private String buildThresholdRepresentationString() {
String thresholdRepresentationText = ""; String thresholdRepresentationText = "";
for (int i = 0; i < threshold; i++) { for (int i = 0; i < threshold; i++) {
thresholdRepresentationText += getString(R.string.filled_bullet); thresholdRepresentationText += getString(R.string.filled_bullet);
@@ -145,9 +146,11 @@ public class ThresholdSelectorFragment extends BaseFragment {
); );
setmOfnText(); setmOfnText();
int sanityLevel = SecretSharingWrapper.thresholdSanity(threshold, numberOfCustodians); int sanityLevel = SecretSharingWrapper
.thresholdSanity(threshold, numberOfCustodians);
int text = R.string.threshold_secure; int text = R.string.threshold_secure;
if (threshold == recommendedThreshold) text = R.string.threshold_recommended; if (threshold == recommendedThreshold)
text = R.string.threshold_recommended;
if (sanityLevel < -1) text = R.string.threshold_low_insecure; if (sanityLevel < -1) text = R.string.threshold_low_insecure;
if (sanityLevel > 0) text = R.string.threshold_high_insecure; if (sanityLevel > 0) text = R.string.threshold_high_insecure;
message.setText(text); message.setText(text);