Added a step to first verify the user's Security Lock before trying to send a transaction in SendTransactionFragment.

This commit is contained in:
Severiano Jaramillo 2019-02-16 17:48:50 -06:00
parent a10a8cd836
commit b0811ab2c8
2 changed files with 56 additions and 21 deletions

View file

@ -21,7 +21,6 @@ import com.google.android.material.snackbar.Snackbar
import com.google.common.primitives.UnsignedLong import com.google.common.primitives.UnsignedLong
import com.google.zxing.BarcodeFormat import com.google.zxing.BarcodeFormat
import com.google.zxing.Result import com.google.zxing.Result
import com.jakewharton.rxbinding3.material.dismisses
import com.jakewharton.rxbinding3.widget.textChanges import com.jakewharton.rxbinding3.widget.textChanges
import cy.agorise.bitsybitshareswallet.R import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.adapters.BalancesDetailsAdapter import cy.agorise.bitsybitshareswallet.adapters.BalancesDetailsAdapter
@ -55,7 +54,8 @@ import java.util.Locale
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.crypto.AEADBadTagException import javax.crypto.AEADBadTagException
class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHandler { class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHandler,
BaseSecurityLockDialog.OnPINPatternEnteredListener {
companion object { companion object {
private const val TAG = "SendTransactionFragment" private const val TAG = "SendTransactionFragment"
@ -68,6 +68,9 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
private const val RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS = 2 private const val RESPONSE_GET_DYNAMIC_GLOBAL_PARAMETERS = 2
private const val RESPONSE_GET_REQUIRED_FEES = 3 private const val RESPONSE_GET_REQUIRED_FEES = 3
private const val RESPONSE_BROADCAST_TRANSACTION = 4 private const val RESPONSE_BROADCAST_TRANSACTION = 4
// Constant used to perform security locked requests
private const val ACTION_SEND_TRANSFER = 1
} }
// Navigation AAC Safe Args // Navigation AAC Safe Args
@ -168,7 +171,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
spAsset.onItemSelectedListener = assetItemSelectedListener spAsset.onItemSelectedListener = assetItemSelectedListener
fabSendTransaction.setOnClickListener { startSendTransferOperation() } fabSendTransaction.setOnClickListener { verifySecurityLockSendTransfer() }
fabSendTransaction.disable(R.color.lightGray) fabSendTransaction.disable(R.color.lightGray)
authorityRepository = AuthorityRepository(context!!) authorityRepository = AuthorityRepository(context!!)
@ -458,6 +461,45 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
} }
} }
private fun verifySecurityLockSendTransfer() {
val securityLockSelected = PreferenceManager.getDefaultSharedPreferences(context)
.getInt(Constants.KEY_SECURITY_LOCK_SELECTED, 0)
// Security Lock Options
// 0 -> PIN
// 1 -> Pattern
// 2 -> None
// Args used for both PIN and Pattern options
val args = Bundle()
args.putInt(BaseSecurityLockDialog.KEY_STEP_SECURITY_LOCK,
BaseSecurityLockDialog.STEP_SECURITY_LOCK_VERIFY)
args.putInt(BaseSecurityLockDialog.KEY_ACTION_IDENTIFIER, ACTION_SEND_TRANSFER)
when (securityLockSelected) {
0 -> { /* PIN */
val pinFrag = PINSecurityLockDialog()
pinFrag.arguments = args
pinFrag.show(childFragmentManager, "pin_security_lock_tag")
}
1 -> { /* Pattern */
val patternFrag = PatternSecurityLockDialog()
patternFrag.arguments = args
patternFrag.show(childFragmentManager, "pattern_security_lock_tag")
}
else -> { /* None */
startSendTransferOperation()
}
}
}
override fun onPINPatternEntered(actionIdentifier: Int) {
if (actionIdentifier == ACTION_SEND_TRANSFER) {
startSendTransferOperation()
}
}
override fun onPINPatternChanged() { /* Do nothing */ }
/** Starts the Send Transfer operation procedure, creating a [TransferOperation] and sending a call to the /** Starts the Send Transfer operation procedure, creating a [TransferOperation] and sending a call to the
* NetworkService to obtain the [DynamicGlobalProperties] object needed to successfully send a Transfer */ * NetworkService to obtain the [DynamicGlobalProperties] object needed to successfully send a Transfer */
private fun startSendTransferOperation() { private fun startSendTransferOperation() {

View file

@ -41,6 +41,7 @@ class SettingsFragment : Fragment(), ServiceConnection, BaseSecurityLockDialog.O
companion object { companion object {
private const val TAG = "SettingsFragment" private const val TAG = "SettingsFragment"
// Constants used to perform security locked requests
private const val ACTION_CHANGE_SECURITY_LOCK = 1 private const val ACTION_CHANGE_SECURITY_LOCK = 1
private const val ACTION_SHOW_BRAINKEY = 2 private const val ACTION_SHOW_BRAINKEY = 2
} }
@ -213,14 +214,7 @@ class SettingsFragment : Fragment(), ServiceConnection, BaseSecurityLockDialog.O
} }
private fun onSecurityLockTextSelected() { private fun onSecurityLockTextSelected() {
val securityLockSelected = PreferenceManager.getDefaultSharedPreferences(context) if (!verifySecurityLock(ACTION_CHANGE_SECURITY_LOCK))
.getInt(Constants.KEY_SECURITY_LOCK_SELECTED, 0)
// Security Lock Options
// 0 -> PIN
// 1 -> Pattern
// 2 -> None
if (!verifySecurityLock(securityLockSelected, ACTION_CHANGE_SECURITY_LOCK))
showChooseSecurityLockDialog() showChooseSecurityLockDialog()
} }
@ -228,11 +222,17 @@ class SettingsFragment : Fragment(), ServiceConnection, BaseSecurityLockDialog.O
* Encapsulated the logic required to do actions possibly locked by the Security Lock. If PIN/Pattern is selected * Encapsulated the logic required to do actions possibly locked by the Security Lock. If PIN/Pattern is selected
* then it prompts for it. * then it prompts for it.
* *
* @param securityLockSelected Current Security Lock option selected
* @param actionIdentifier Identifier used to know why a verify security lock was launched * @param actionIdentifier Identifier used to know why a verify security lock was launched
* @return true if the action was handled, false otherwise * @return true if the action was handled, false otherwise
*/ */
private fun verifySecurityLock(securityLockSelected: Int, actionIdentifier: Int): Boolean { private fun verifySecurityLock(actionIdentifier: Int): Boolean {
val securityLockSelected = PreferenceManager.getDefaultSharedPreferences(context)
.getInt(Constants.KEY_SECURITY_LOCK_SELECTED, 0)
// Security Lock Options
// 0 -> PIN
// 1 -> Pattern
// 2 -> None
// Args used for both PIN and Pattern options // Args used for both PIN and Pattern options
val args = Bundle() val args = Bundle()
args.putInt(BaseSecurityLockDialog.KEY_STEP_SECURITY_LOCK, args.putInt(BaseSecurityLockDialog.KEY_STEP_SECURITY_LOCK,
@ -317,14 +317,7 @@ class SettingsFragment : Fragment(), ServiceConnection, BaseSecurityLockDialog.O
} }
private fun onShowBrainKeyButtonSelected() { private fun onShowBrainKeyButtonSelected() {
val securityLockSelected = PreferenceManager.getDefaultSharedPreferences(context) if (!verifySecurityLock(ACTION_SHOW_BRAINKEY))
.getInt(Constants.KEY_SECURITY_LOCK_SELECTED, 0)
// Security Lock Options
// 0 -> PIN
// 1 -> Pattern
// 2 -> None
if (!verifySecurityLock(securityLockSelected, ACTION_SHOW_BRAINKEY))
getBrainkey() getBrainkey()
} }