Browse Source

respect allowinternetconnection in connection string

chat
Aditya Kulkarni 5 years ago
parent
commit
268827456a
  1. 6
      app/src/main/java/com/adityapk/zcash/zqwandroid/ConnectionManager.kt
  2. 36
      app/src/main/java/com/adityapk/zcash/zqwandroid/DataModel.kt
  3. 6
      app/src/main/java/com/adityapk/zcash/zqwandroid/MainActivity.kt
  4. 2
      app/src/main/java/com/adityapk/zcash/zqwandroid/QrReaderActivity.kt

6
app/src/main/java/com/adityapk/zcash/zqwandroid/ConnectionManager.kt

@ -158,15 +158,15 @@ object ConnectionManager {
DataModel.connStatus = DataModel.ConnectionStatus.DISCONNECTED
// If the connection is direct, and there is no need to connect to
val allowInternetConnect = true
if (t is ConnectException && (m_directConn && !allowInternetConnect)) {
if (t is ConnectException && (m_directConn && !DataModel.getAllowInternet())) {
sendErrorSignal(t.localizedMessage, true)
sendRefreshSignal(false)
}
// If this was a direct connection and there was a failure to connect, retry connecting
// without the direct connection (i.e., through wormhole)
if (m_directConn && allowInternetConnect) {
if (m_directConn && DataModel.getAllowInternet()) {
makeConnection(false)
} else {
// Not a direct connection (or we're not allowed to connect to internet) and there was a failure.

36
app/src/main/java/com/adityapk/zcash/zqwandroid/DataModel.kt

@ -254,17 +254,6 @@ object DataModel {
return nonce
}
fun getSecret() : ByteArray? {
val settings = ZQWApp.appContext!!.getSharedPreferences("Secret", 0)
val secretHex = settings.getString("secret", "")
if (secretHex.isNullOrEmpty()) {
return null
}
return secretHex.hexStringToByteArray(Sodium.crypto_secretbox_keybytes())
}
fun getWormholeCode() : String? {
if (getSecret() == null)
return null
@ -293,5 +282,30 @@ object DataModel {
editor.apply()
}
fun getSecret() : ByteArray? {
val settings = ZQWApp.appContext!!.getSharedPreferences("Secret", 0)
val secretHex = settings.getString("secret", "")
if (secretHex.isNullOrEmpty()) {
return null
}
return secretHex.hexStringToByteArray(Sodium.crypto_secretbox_keybytes())
}
fun setAllowInternet(allow: Boolean) {
val settings = ZQWApp.appContext!!.getSharedPreferences("Secret", 0)
val editor = settings.edit()
editor.putBoolean("allowinternet", allow)
editor.apply()
}
fun getAllowInternet(): Boolean {
val settings = ZQWApp.appContext!!.getSharedPreferences("Secret", 0)
return settings.getBoolean("allowinternet", false)
}
private const val TAG = "DataModel"
}

6
app/src/main/java/com/adityapk/zcash/zqwandroid/MainActivity.kt

@ -298,17 +298,19 @@ class MainActivity : AppCompatActivity(), TransactionItemFragment.OnFragmentInte
}
val conComponents = data?.dataString?.split(",")
if (conComponents?.size != 2) {
if (conComponents?.size ?: 0 < 2 || conComponents?.size ?: 0 > 3) {
Toast.makeText(applicationContext,
"${data?.dataString} is not a valid connection string", Toast.LENGTH_SHORT).show()
return
}
val conString = conComponents[0]
val conString = conComponents!![0]
val secretHex = conComponents[1]
val allowInternetConnections = if (conComponents.size == 3) conComponents[2] == "1" else false
DataModel.setSecretHex(secretHex)
DataModel.setConnString(conString, applicationContext)
DataModel.setAllowInternet(allowInternetConnections)
ConnectionManager.refreshAllData()
}

2
app/src/main/java/com/adityapk/zcash/zqwandroid/QrReaderActivity.kt

@ -168,7 +168,7 @@ class QrReaderActivity : AppCompatActivity() {
return
}
if (code == REQUEST_ADDRESS && !DataModel.isValidAddress(StringBuilder(barcodeInfo ?: "").toString())) {
if (code == REQUEST_ADDRESS && !DataModel.isValidAddress(StringBuilder(barcodeInfo).toString())) {
Log.i(TAG, "Not an address")
var err = barcodeInfo
if (err.length > 48) {

Loading…
Cancel
Save