Commit 570bb890 authored by pokkst's avatar pokkst

If wallet is encrypted, then prompt for password when disabling. Disabling...

If wallet is encrypted, then prompt for password when disabling. Disabling encryption now requires password before disabling.

Compile FINAL v1.10 .aab
parent 0b7f6cb3
No preview for this file type
......@@ -32,6 +32,12 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.PromptPasswordActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing"
android:launchMode="singleTop">
</activity>
<activity android:name=".activity.VerifySignatureActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
......
package app.crescentcash.src.activity
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import app.crescentcash.src.R
import app.crescentcash.src.manager.UIManager
import app.crescentcash.src.manager.WalletManager
import app.crescentcash.src.utils.Constants
class PromptPasswordActivity : AppCompatActivity() {
lateinit var unlockPassword: EditText
lateinit var unlockBtn: Button
var confirmed: Boolean = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
UIManager.determineTheme(this)
this.setContentView(R.layout.prompt_pass)
this.findViews()
this.prepareViews()
this.initListeners()
}
private fun prepareViews() {
}
private fun findViews() {
unlockPassword = this.findViewById(R.id.unlockPassword)
unlockBtn = this.findViewById(R.id.unlockBtn)
}
private fun initListeners() {
this.unlockBtn.setOnClickListener {
if (!TextUtils.isEmpty(unlockPassword.text)) {
val password = unlockPassword.text.toString()
val scrypt = WalletManager.wallet.keyCrypter
val key = scrypt!!.deriveKey(password)
if (WalletManager.wallet.checkAESKey(key)) {
confirmed = true
finish()
} else {
UIManager.showToastMessage(this, "Invalid password.")
}
} else {
UIManager.showToastMessage(this, "Please enter your password.")
}
}
}
override fun finish() {
val resultIntent = Intent()
resultIntent.putExtra(Constants.CONFIRM_PASS_RESULT, confirmed)
this.setResult(Constants.REQUEST_CODE_PROMPT_PASS_STREET, resultIntent)
super.finish()
}
companion object
}
......@@ -38,6 +38,7 @@ class SettingsActivity : AppCompatActivity() {
lateinit var useTorSwitch: Switch
private lateinit var copyXpubBtn: ImageView
lateinit var streetModeSwitch: Switch
private var onEncryptCheckedListener: CompoundButton.OnCheckedChangeListener? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -94,20 +95,22 @@ class SettingsActivity : AppCompatActivity() {
val intent = Intent(Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE)
LocalBroadcastManager.getInstance(this@SettingsActivity).sendBroadcast(intent)
}
this.encryptWalletSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
onEncryptCheckedListener = CompoundButton.OnCheckedChangeListener { buttonView, isChecked ->
if (isChecked) {
val encryptWalletActivity = Intent(this, EncryptWalletActivity::class.java)
startActivityForResult(encryptWalletActivity, Constants.REQUEST_CODE_ENCRYPT_WALLET)
} else {
if (WalletManager.aesKey != null) {
WalletManager.wallet.decrypt(WalletManager.aesKey)
WalletManager.aesKey = null
val promptPasswordActivity = Intent(this, PromptPasswordActivity::class.java)
promptPasswordActivity.putExtra(Constants.INTENT_PASS_PROMPT_TYPE, "decrypt")
startActivityForResult(promptPasswordActivity, Constants.REQUEST_CODE_PROMPT_PASS_DECRYPT)
}
}
WalletManager.encrypted = isChecked
PrefsUtil.prefs.edit().putBoolean("useEncryption", WalletManager.encrypted).apply()
}
this.encryptWalletSwitch.setOnCheckedChangeListener(onEncryptCheckedListener)
this.useTorSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
WalletManager.useTor = isChecked
......@@ -118,10 +121,23 @@ class SettingsActivity : AppCompatActivity() {
PrefsUtil.prefs.edit().putBoolean("useTor", WalletManager.useTor).apply()
}
this.streetModeSwitch.setOnCheckedChangeListener { buttonView, isChecked ->
UIManager.streetModeEnabled = isChecked
PrefsUtil.prefs.edit().putBoolean("streetMode", UIManager.streetModeEnabled).apply()
val intent = Intent(Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE)
LocalBroadcastManager.getInstance(this@SettingsActivity).sendBroadcast(intent)
if(isChecked) {
UIManager.streetModeEnabled = isChecked
PrefsUtil.prefs.edit().putBoolean("streetMode", UIManager.streetModeEnabled).apply()
val intent = Intent(Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE)
LocalBroadcastManager.getInstance(this@SettingsActivity).sendBroadcast(intent)
} else {
if(WalletManager.encrypted) {
val promptPasswordActivity = Intent(this, PromptPasswordActivity::class.java)
promptPasswordActivity.putExtra(Constants.INTENT_PASS_PROMPT_TYPE, "streetMode")
startActivityForResult(promptPasswordActivity, Constants.REQUEST_CODE_PROMPT_PASS_STREET)
} else {
UIManager.streetModeEnabled = isChecked
PrefsUtil.prefs.edit().putBoolean("streetMode", UIManager.streetModeEnabled).apply()
val intent = Intent(Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE)
LocalBroadcastManager.getInstance(this@SettingsActivity).sendBroadcast(intent)
}
}
}
val decimalFormatter = DecimalFormat("#.########", DecimalFormatSymbols(Locale.US))
......@@ -260,13 +276,34 @@ class SettingsActivity : AppCompatActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == Constants.REQUEST_CODE_ENCRYPT_WALLET) {
if (data != null) {
if (data != null) {
if (requestCode == Constants.REQUEST_CODE_ENCRYPT_WALLET) {
this.encryptWalletSwitch.setOnCheckedChangeListener(null)
val encryptData = data.getBooleanExtra(Constants.ENCRYPTED_RESULT, false)
if (!encryptData) {
WalletManager.encrypted = false
WalletManager.encrypted = encryptData
PrefsUtil.prefs.edit().putBoolean("useEncryption", WalletManager.encrypted).apply()
this.encryptWalletSwitch.isChecked = encryptData
this.encryptWalletSwitch.setOnCheckedChangeListener(onEncryptCheckedListener)
} else {
val promptPassData = data.getBooleanExtra(Constants.CONFIRM_PASS_RESULT, false)
if(requestCode == Constants.REQUEST_CODE_PROMPT_PASS_STREET) {
UIManager.streetModeEnabled = !promptPassData
PrefsUtil.prefs.edit().putBoolean("streetMode", UIManager.streetModeEnabled).apply()
val intent = Intent(Constants.ACTION_UPDATE_HOME_SCREEN_BALANCE)
LocalBroadcastManager.getInstance(this@SettingsActivity).sendBroadcast(intent)
this.streetModeSwitch.isChecked = !promptPassData
} else if(requestCode == Constants.REQUEST_CODE_PROMPT_PASS_DECRYPT) {
this.encryptWalletSwitch.setOnCheckedChangeListener(null)
WalletManager.encrypted = !promptPassData
PrefsUtil.prefs.edit().putBoolean("useEncryption", WalletManager.encrypted).apply()
this.encryptWalletSwitch.isChecked = false
this.encryptWalletSwitch.isChecked = !promptPassData
if(!WalletManager.encrypted) {
WalletManager.wallet.decrypt(WalletManager.aesKey)
WalletManager.aesKey = null
}
this.encryptWalletSwitch.setOnCheckedChangeListener(onEncryptCheckedListener)
}
}
}
......
......@@ -14,13 +14,17 @@ object Constants {
var REQUEST_CODE_SIG_VERIFY_ADDRESS_SCAN = 2260
var REQUEST_CODE_SIG_VERIFY_SIGNATURE_SCAN = 2265
var REQUEST_CODE_ENCRYPT_WALLET = 2270
var REQUEST_CODE_PROMPT_PASS_STREET = 2275
var REQUEST_CODE_PROMPT_PASS_DECRYPT = 2280
var QR_SCAN_RESULT = "SCAN_RESULT"
var DONATION_ADDRESS = "bitcoincash:qptnypuugy29lttleggl7l0vpls0vg295q9nsavw6g"
var INTENT_BALANCE_DATA = "balance"
var INTENT_CASH_ACCOUNT_DATA = "cashAccount"
var INTENT_TOKEN_TICKER_DATA = "tokenTicker"
var INTENT_TRANSACTION_POSITION_DATA = "transactionPos"
var INTENT_PASS_PROMPT_TYPE = "promptType"
var ENCRYPTED_RESULT = "ENCRYPT_RESULT"
var CONFIRM_PASS_RESULT = "CONFIRM_PASS_RESULT"
var ACTION_CLEAR_SEND = "SendActivity.CLEAR_SEND"
var ACTION_UPDATE_HOME_SCREEN_BALANCE = "MainActivity.UPDATE_HOME_SCREEN_BALANCE"
var ACTION_UPDATE_HOME_SCREEN_THEME = "MainActivity.UPDATE_HOME_SCREEN_THEME"
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/unlockScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/backgroundColor"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:text="Enter Password"
android:textColor="?attr/textColor"
android:textSize="40sp"
android:textStyle="bold" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#353535"
android:minHeight="10dp" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp" />
<EditText
android:id="@+id/unlockPassword"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:background="@drawable/circle_button"
android:backgroundTint="?attr/textboxOnWhite"
android:hint="Enter wallet password"
android:inputType="textPassword"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:singleLine="true"
android:textColor="?attr/textColor"
android:textColorHint="?attr/textHintOnWhite"
android:textCursorDrawable="@null"
android:textSize="14sp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="30dp" />
<Button
android:id="@+id/unlockBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="100dp"
android:layout_marginEnd="100dp"
android:background="@drawable/bch_wallet_button"
android:gravity="center"
android:text="Confirm"
android:textAllCaps="false"
android:textColor="?attr/buttonTextOnWhite" />
</LinearLayout>
</FrameLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment