Direct Streetmode & credentials for disabling it (#469)

- Add wallet menu item to enter streetmode directly
- Add credentials check to leave streetmode (someone-snatches-your-phone-scenario)
- Recheck credentials for showing secrets after entering streetmode
This commit is contained in:
m2049r 2018-11-13 19:08:51 +01:00 committed by GitHub
parent 29583fa40d
commit 5bfb920979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 29 deletions

View File

@ -162,7 +162,7 @@ public class LoginActivity extends BaseActivity
}
@Override
public boolean onWalletSelected(String walletName, String daemon) {
public boolean onWalletSelected(String walletName, String daemon, boolean streetmode) {
if (daemon.length() == 0) {
Toast.makeText(this, getString(R.string.prompt_daemon_missing), Toast.LENGTH_SHORT).show();
return false;
@ -170,7 +170,7 @@ public class LoginActivity extends BaseActivity
if (checkServiceRunning()) return false;
try {
WalletNode aWalletNode = new WalletNode(walletName, daemon, WalletManager.getInstance().getNetworkType());
new AsyncOpenWallet().execute(aWalletNode);
new AsyncOpenWallet(streetmode).execute(aWalletNode);
} catch (IllegalArgumentException ex) {
Timber.e(ex.getLocalizedMessage());
Toast.makeText(this, ex.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
@ -580,12 +580,14 @@ public class LoginActivity extends BaseActivity
}
}
void startWallet(String walletName, String walletPassword, boolean fingerprintUsed) {
void startWallet(String walletName, String walletPassword,
boolean fingerprintUsed, boolean streetmode) {
Timber.d("startWallet()");
Intent intent = new Intent(getApplicationContext(), WalletActivity.class);
intent.putExtra(WalletActivity.REQUEST_ID, walletName);
intent.putExtra(WalletActivity.REQUEST_PW, walletPassword);
intent.putExtra(WalletActivity.REQUEST_FINGERPRINT_USED, fingerprintUsed);
intent.putExtra(WalletActivity.REQUEST_STREETMODE, streetmode);
startActivity(intent);
}
@ -1098,7 +1100,12 @@ public class LoginActivity extends BaseActivity
final static int INVALID = 2;
final static int IOEX = 3;
WalletNode walletNode;
private WalletNode walletNode;
private final boolean streetmode;
public AsyncOpenWallet(boolean streetmode) {
this.streetmode = streetmode;
}
@Override
protected void onPreExecute() {
@ -1147,7 +1154,7 @@ public class LoginActivity extends BaseActivity
case OK:
Timber.d("selected wallet is .%s.", walletNode.getName());
// now it's getting real, onValidateFields if wallet exists
promptAndStart(walletNode);
promptAndStart(walletNode, streetmode);
break;
case TIMEOUT:
Toast.makeText(LoginActivity.this, getString(R.string.status_wallet_connect_timeout), Toast.LENGTH_LONG).show();
@ -1184,7 +1191,7 @@ public class LoginActivity extends BaseActivity
return false;
}
void promptAndStart(WalletNode walletNode) {
void promptAndStart(WalletNode walletNode, final boolean streetmode) {
File walletFile = Helper.getWalletFile(this, walletNode.getName());
if (WalletManager.getInstance().walletExists(walletFile)) {
WalletManager.getInstance().setDaemon(walletNode);
@ -1193,7 +1200,7 @@ public class LoginActivity extends BaseActivity
@Override
public void action(String walletName, String password, boolean fingerprintUsed) {
if (checkDevice(walletName, password))
startWallet(walletName, password, fingerprintUsed);
startWallet(walletName, password, fingerprintUsed, streetmode);
}
});

View File

@ -81,7 +81,7 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
File getStorageRoot();
boolean onWalletSelected(String wallet, String daemon);
boolean onWalletSelected(String wallet, String daemon, boolean streetmode);
void onWalletDetails(String wallet);
@ -238,8 +238,11 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
Toast.makeText(getActivity(), getString(R.string.prompt_wrong_net), Toast.LENGTH_LONG).show();
return;
}
openWalet(infoItem.name, false);
}
if (activityCallback.onWalletSelected(infoItem.name, getDaemon())) {
private void openWalet(String name, boolean streetmode) {
if (activityCallback.onWalletSelected(name, getDaemon(), streetmode)) {
savePrefs();
}
}
@ -247,6 +250,9 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
@Override
public boolean onContextInteraction(MenuItem item, WalletManager.WalletInfo listItem) {
switch (item.getItemId()) {
case R.id.action_streetmode:
openWalet(listItem.name, true);
break;
case R.id.action_info:
showInfo(listItem.name);
break;

View File

@ -80,6 +80,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
public static final String REQUEST_ID = "id";
public static final String REQUEST_PW = "pw";
public static final String REQUEST_FINGERPRINT_USED = "fingerprint";
public static final String REQUEST_STREETMODE = "streetmode";
private NavigationView accountsView;
private DrawerLayout drawer;
@ -87,6 +88,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
private Toolbar toolbar;
private boolean needVerifyIdentity;
private boolean requestStreetMode = false;
private String password;
@ -135,13 +137,13 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
return streetMode > 0;
}
public void toggleStreetMode() {
if (streetMode == 0) {
private void enableStreetMode(boolean enable) {
if (enable) {
needVerifyIdentity = true;
streetMode = getWallet().getDaemonBlockChainHeight();
} else {
streetMode = 0;
}
Timber.e("streetMode=" + streetMode);
updateAccountsBalance();
forceUpdate();
}
@ -178,6 +180,8 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
acquireWakeLock();
String walletId = extras.getString(REQUEST_ID);
needVerifyIdentity = extras.getBoolean(REQUEST_FINGERPRINT_USED);
// we can set the streetmode height AFTER opening the wallet
requestStreetMode = extras.getBoolean(REQUEST_STREETMODE);
password = extras.getString(REQUEST_PW);
connectWalletService(walletId, password);
} else {
@ -259,19 +263,66 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
onAccountRename();
return true;
case R.id.action_streetmode:
toggleStreetMode();
if (isStreetMode()) {
toolbar.setBackgroundResource(R.drawable.backgound_toolbar_streetmode);
if (isStreetMode()) { // disable streetmode
onDisableStreetMode();
} else {
showNet();
onEnableStreetMode();
}
invalidateOptionsMenu();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void updateStreetMode() {
if (isStreetMode()) {
toolbar.setBackgroundResource(R.drawable.backgound_toolbar_streetmode);
} else {
showNet();
}
invalidateOptionsMenu();
}
private void onEnableStreetMode() {
enableStreetMode(true);
updateStreetMode();
}
private void onDisableStreetMode() {
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
Helper.promptPassword(WalletActivity.this, getWallet().getName(), true, new Helper.PasswordAction() {
@Override
public void action(String walletName, String password, boolean fingerprintUsed) {
runOnUiThread(new Runnable() {
@Override
public void run() {
enableStreetMode(false);
updateStreetMode();
}
});
}
});
break;
case DialogInterface.BUTTON_NEGATIVE:
// do nothing
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.details_alert_message))
.setPositiveButton(getString(R.string.details_alert_yes), dialogClickListener)
.setNegativeButton(getString(R.string.details_alert_no), dialogClickListener)
.show();
}
public void onWalletChangePassword() {
try {
GenerateReviewFragment detailsFragment = (GenerateReviewFragment)
@ -595,6 +646,8 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
haveWallet = true;
invalidateOptionsMenu();
enableStreetMode(requestStreetMode);
final WalletFragment walletFragment = (WalletFragment)
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
runOnUiThread(new Runnable() {
@ -1173,16 +1226,4 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
Toast.LENGTH_SHORT).show();
}
}
// @Override
// public void invalidateOptionsMenu() {
// super.invalidateOptionsMenu();
// if (isStreetMode()) {
// item.setIcon(R.drawable.gunther_csi_24dp);
// toolbar.setBackgroundResource(R.drawable.backgound_toolbar_streetmode);
// } else {
// item.setIcon(R.drawable.gunther_24dp);
// showNet();
// }
// }
}

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_streetmode"
android:orderInCategory="50"
android:title="@string/menu_streetmode" />
<item
android:id="@+id/action_receive"
android:orderInCategory="100"