mirror of
https://github.com/m2049r/xmrwallet
synced 2025-09-12 23:40:51 +02:00
Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7fc2dc3ba1 | ||
![]() |
43204d64ef | ||
![]() |
1433143a39 | ||
![]() |
a9a78393a9 | ||
![]() |
fe7ab31050 | ||
![]() |
bf5ed793b3 | ||
![]() |
679bae5f42 | ||
![]() |
e3ccda910e | ||
![]() |
ae75a34977 | ||
![]() |
03efedf35c | ||
![]() |
403dbdf14f | ||
![]() |
0bf3c6f099 | ||
![]() |
1b0ac1c481 | ||
![]() |
dc95539fc1 | ||
![]() |
023fb9e215 | ||
![]() |
92728026c7 | ||
![]() |
8fd9598c6c | ||
![]() |
6633261ba2 | ||
![]() |
dc8c8634cb | ||
![]() |
dcf9b6db15 | ||
![]() |
654d63c32e | ||
![]() |
caf91fccfd | ||
![]() |
41f1f3dec0 | ||
![]() |
bb66d1f68d | ||
![]() |
310548b031 | ||
![]() |
ad7737475f | ||
![]() |
b2d07a65b7 | ||
![]() |
5dfcaae5b9 | ||
![]() |
3c91fc060c | ||
![]() |
f8f113faab | ||
![]() |
268a00cb3e | ||
![]() |
878500ae71 | ||
![]() |
a0debb0f7e | ||
![]() |
3a71e8d352 | ||
![]() |
af68c5e51f | ||
![]() |
5a2b48a087 |
@@ -7,8 +7,8 @@ android {
|
|||||||
applicationId "com.m2049r.xmrwallet"
|
applicationId "com.m2049r.xmrwallet"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 99
|
versionCode 113
|
||||||
versionName "1.5.9 'Maximum Nacho'"
|
versionName "1.6.3 'Nano S'"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
@@ -45,8 +45,17 @@ android {
|
|||||||
// Map for the version code that gives each ABI a value.
|
// Map for the version code that gives each ABI a value.
|
||||||
def abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, 'x86': 3, 'x86_64': 4]
|
def abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2, 'x86': 3, 'x86_64': 4]
|
||||||
|
|
||||||
|
// Enumerate translated locales
|
||||||
|
def availableLocales = ["en"]
|
||||||
|
new File("app/src/main/res/").eachFileMatch(~/^values-.*/) { file ->
|
||||||
|
def languageTag = file.name.substring(7).replace("-r", "-")
|
||||||
|
availableLocales.add(languageTag)
|
||||||
|
}
|
||||||
|
|
||||||
// APKs for the same app that all have the same version information.
|
// APKs for the same app that all have the same version information.
|
||||||
android.applicationVariants.all { variant ->
|
android.applicationVariants.all { variant ->
|
||||||
|
// Update string resource: available_locales
|
||||||
|
variant.resValue("string", "available_locales", availableLocales.join(","))
|
||||||
// Assigns a different version code for each output APK.
|
// Assigns a different version code for each output APK.
|
||||||
variant.outputs.all {
|
variant.outputs.all {
|
||||||
output ->
|
output ->
|
||||||
|
@@ -8,13 +8,14 @@
|
|||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||||
|
<uses-permission android:name="android.permission.NFC" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:name=".XmrWalletApplication"
|
||||||
|
android:allowBackup="false"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:name=".XmrWalletApplication"
|
|
||||||
android:theme="@style/MyMaterialTheme">
|
android:theme="@style/MyMaterialTheme">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
@@ -28,11 +29,19 @@
|
|||||||
android:name=".LoginActivity"
|
android:name=".LoginActivity"
|
||||||
android:configChanges="orientation|keyboardHidden"
|
android:configChanges="orientation|keyboardHidden"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
android:launchMode="singleTop"
|
||||||
android:screenOrientation="portrait">
|
android:screenOrientation="portrait">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
|
||||||
|
android:resource="@xml/usb_device_filter" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
@@ -40,7 +49,5 @@
|
|||||||
android:description="@string/service_description"
|
android:description="@string/service_description"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="Monero Wallet Service" />
|
android:label="Monero Wallet Service" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@@ -38,6 +38,7 @@ static jclass class_ArrayList;
|
|||||||
static jclass class_WalletListener;
|
static jclass class_WalletListener;
|
||||||
static jclass class_TransactionInfo;
|
static jclass class_TransactionInfo;
|
||||||
static jclass class_Transfer;
|
static jclass class_Transfer;
|
||||||
|
static jclass class_Ledger;
|
||||||
|
|
||||||
std::mutex _listenerMutex;
|
std::mutex _listenerMutex;
|
||||||
|
|
||||||
@@ -58,6 +59,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
|
|||||||
jenv->FindClass("com/m2049r/xmrwallet/model/Transfer")));
|
jenv->FindClass("com/m2049r/xmrwallet/model/Transfer")));
|
||||||
class_WalletListener = static_cast<jclass>(jenv->NewGlobalRef(
|
class_WalletListener = static_cast<jclass>(jenv->NewGlobalRef(
|
||||||
jenv->FindClass("com/m2049r/xmrwallet/model/WalletListener")));
|
jenv->FindClass("com/m2049r/xmrwallet/model/WalletListener")));
|
||||||
|
class_Ledger = static_cast<jclass>(jenv->NewGlobalRef(
|
||||||
|
jenv->FindClass("com/m2049r/xmrwallet/ledger/Ledger")));
|
||||||
return JNI_VERSION_1_6;
|
return JNI_VERSION_1_6;
|
||||||
}
|
}
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -353,6 +356,39 @@ Java_com_m2049r_xmrwallet_model_WalletManager_createWalletFromKeysJ(JNIEnv *env,
|
|||||||
return reinterpret_cast<jlong>(wallet);
|
return reinterpret_cast<jlong>(wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// virtual void setSubaddressLookahead(uint32_t major, uint32_t minor) = 0;
|
||||||
|
|
||||||
|
JNIEXPORT jlong JNICALL
|
||||||
|
Java_com_m2049r_xmrwallet_model_WalletManager_createWalletFromDeviceJ(JNIEnv *env, jobject instance,
|
||||||
|
jstring path,
|
||||||
|
jstring password,
|
||||||
|
jint networkType,
|
||||||
|
jstring deviceName,
|
||||||
|
jlong restoreHeight,
|
||||||
|
jstring subaddressLookahead) {
|
||||||
|
const char *_path = env->GetStringUTFChars(path, NULL);
|
||||||
|
const char *_password = env->GetStringUTFChars(password, NULL);
|
||||||
|
Monero::NetworkType _networkType = static_cast<Monero::NetworkType>(networkType);
|
||||||
|
const char *_deviceName = env->GetStringUTFChars(deviceName, NULL);
|
||||||
|
const char *_subaddressLookahead = env->GetStringUTFChars(subaddressLookahead, NULL);
|
||||||
|
|
||||||
|
Bitmonero::Wallet *wallet =
|
||||||
|
Bitmonero::WalletManagerFactory::getWalletManager()->createWalletFromDevice(
|
||||||
|
std::string(_path),
|
||||||
|
std::string(_password),
|
||||||
|
_networkType,
|
||||||
|
std::string(_deviceName),
|
||||||
|
(uint64_t) restoreHeight,
|
||||||
|
std::string(_subaddressLookahead));
|
||||||
|
|
||||||
|
env->ReleaseStringUTFChars(path, _path);
|
||||||
|
env->ReleaseStringUTFChars(password, _password);
|
||||||
|
env->ReleaseStringUTFChars(deviceName, _deviceName);
|
||||||
|
env->ReleaseStringUTFChars(subaddressLookahead, _subaddressLookahead);
|
||||||
|
return reinterpret_cast<jlong>(wallet);
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL
|
JNIEXPORT jboolean JNICALL
|
||||||
Java_com_m2049r_xmrwallet_model_WalletManager_walletExists(JNIEnv *env, jobject instance,
|
Java_com_m2049r_xmrwallet_model_WalletManager_walletExists(JNIEnv *env, jobject instance,
|
||||||
jstring path) {
|
jstring path) {
|
||||||
@@ -378,6 +414,20 @@ Java_com_m2049r_xmrwallet_model_WalletManager_verifyWalletPassword(JNIEnv *env,
|
|||||||
return static_cast<jboolean>(passwordOk);
|
return static_cast<jboolean>(passwordOk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//virtual int queryWalletHardware(const std::string &keys_file_name, const std::string &password) const = 0;
|
||||||
|
JNIEXPORT jint JNICALL
|
||||||
|
Java_com_m2049r_xmrwallet_model_WalletManager_queryWalletHardware(JNIEnv *env, jobject instance,
|
||||||
|
jstring keys_file_name,
|
||||||
|
jstring password) {
|
||||||
|
const char *_keys_file_name = env->GetStringUTFChars(keys_file_name, NULL);
|
||||||
|
const char *_password = env->GetStringUTFChars(password, NULL);
|
||||||
|
int hardwareId =
|
||||||
|
Bitmonero::WalletManagerFactory::getWalletManager()->
|
||||||
|
queryWalletHardware(std::string(_keys_file_name), std::string(_password));
|
||||||
|
env->ReleaseStringUTFChars(keys_file_name, _keys_file_name);
|
||||||
|
env->ReleaseStringUTFChars(password, _password);
|
||||||
|
return static_cast<jint>(hardwareId);
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jobject JNICALL
|
JNIEXPORT jobject JNICALL
|
||||||
Java_com_m2049r_xmrwallet_model_WalletManager_findWallets(JNIEnv *env, jobject instance,
|
Java_com_m2049r_xmrwallet_model_WalletManager_findWallets(JNIEnv *env, jobject instance,
|
||||||
@@ -637,6 +687,13 @@ Java_com_m2049r_xmrwallet_model_Wallet_initJ(JNIEnv *env, jobject instance,
|
|||||||
|
|
||||||
// virtual bool createWatchOnly(const std::string &path, const std::string &password, const std::string &language) const = 0;
|
// virtual bool createWatchOnly(const std::string &path, const std::string &password, const std::string &language) const = 0;
|
||||||
// virtual void setRefreshFromBlockHeight(uint64_t refresh_from_block_height) = 0;
|
// virtual void setRefreshFromBlockHeight(uint64_t refresh_from_block_height) = 0;
|
||||||
|
|
||||||
|
JNIEXPORT jlong JNICALL
|
||||||
|
Java_com_m2049r_xmrwallet_model_Wallet_getRestoreHeight(JNIEnv *env, jobject instance) {
|
||||||
|
Bitmonero::Wallet *wallet = getHandle<Bitmonero::Wallet>(env, instance);
|
||||||
|
return wallet->getRefreshFromBlockHeight();
|
||||||
|
}
|
||||||
|
|
||||||
// virtual void setRecoveringFromSeed(bool recoveringFromSeed) = 0;
|
// virtual void setRecoveringFromSeed(bool recoveringFromSeed) = 0;
|
||||||
// virtual bool connectToDaemon() = 0;
|
// virtual bool connectToDaemon() = 0;
|
||||||
|
|
||||||
@@ -712,6 +769,13 @@ Java_com_m2049r_xmrwallet_model_Wallet_isSynchronized(JNIEnv *env, jobject insta
|
|||||||
return static_cast<jboolean>(wallet->synchronized());
|
return static_cast<jboolean>(wallet->synchronized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL
|
||||||
|
Java_com_m2049r_xmrwallet_model_Wallet_isKeyOnDevice(JNIEnv *env, jobject instance) {
|
||||||
|
Bitmonero::Wallet *wallet = getHandle<Bitmonero::Wallet>(env, instance);
|
||||||
|
bool key_on_device = wallet->isKeyOnDevice();
|
||||||
|
return static_cast<jboolean>(key_on_device);
|
||||||
|
}
|
||||||
|
|
||||||
//void cn_slow_hash(const void *data, size_t length, char *hash); // from crypto/hash-ops.h
|
//void cn_slow_hash(const void *data, size_t length, char *hash); // from crypto/hash-ops.h
|
||||||
JNIEXPORT jbyteArray JNICALL
|
JNIEXPORT jbyteArray JNICALL
|
||||||
Java_com_m2049r_xmrwallet_util_KeyStoreHelper_slowHash(JNIEnv *env, jobject clazz,
|
Java_com_m2049r_xmrwallet_util_KeyStoreHelper_slowHash(JNIEnv *env, jobject clazz,
|
||||||
@@ -1309,6 +1373,96 @@ Java_com_m2049r_xmrwallet_model_WalletManager_setLogLevel(JNIEnv *env, jobject i
|
|||||||
Bitmonero::WalletManagerFactory::setLogLevel(level);
|
Bitmonero::WalletManagerFactory::setLogLevel(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Ledger Stuff
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "monerujo_ledger.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief LedgerExchange - exchange data with Ledger Device
|
||||||
|
* @param pbSendBuffer - buffer for data to send
|
||||||
|
* @param cbSendLength - length of send buffer
|
||||||
|
* @param pbRecvBuffer - buffer for received data
|
||||||
|
* @param pcbRecvLength - pointer to size of receive buffer
|
||||||
|
* gets set with length of received data on successful return
|
||||||
|
* @return SCARD_S_SUCCESS - success
|
||||||
|
* SCARD_E_NO_READERS_AVAILABLE - no device connected / found
|
||||||
|
* SCARD_E_INSUFFICIENT_BUFFER - pbRecvBuffer is too small for the response
|
||||||
|
*/
|
||||||
|
LONG LedgerExchange(
|
||||||
|
LPCBYTE pbSendBuffer,
|
||||||
|
DWORD cbSendLength,
|
||||||
|
LPBYTE pbRecvBuffer,
|
||||||
|
LPDWORD pcbRecvLength) {
|
||||||
|
LOGD("LedgerExchange");
|
||||||
|
JNIEnv *jenv;
|
||||||
|
int envStat = attachJVM(&jenv);
|
||||||
|
if (envStat == JNI_ERR) return -1;
|
||||||
|
|
||||||
|
jmethodID exchangeMethod = jenv->GetStaticMethodID(class_Ledger, "Exchange", "([B)[B");
|
||||||
|
|
||||||
|
jsize sendLen = static_cast<jsize>(cbSendLength);
|
||||||
|
jbyteArray dataSend = jenv->NewByteArray(sendLen);
|
||||||
|
jenv->SetByteArrayRegion(dataSend, 0, sendLen, (jbyte *) pbSendBuffer);
|
||||||
|
jbyteArray dataRecv = (jbyteArray) jenv->CallStaticObjectMethod(class_Ledger, exchangeMethod,
|
||||||
|
dataSend);
|
||||||
|
jenv->DeleteLocalRef(dataSend);
|
||||||
|
if (dataRecv == nullptr) {
|
||||||
|
detachJVM(jenv, envStat);
|
||||||
|
LOGD("LedgerExchange SCARD_E_NO_READERS_AVAILABLE");
|
||||||
|
return SCARD_E_NO_READERS_AVAILABLE;
|
||||||
|
}
|
||||||
|
jsize len = jenv->GetArrayLength(dataRecv);
|
||||||
|
LOGD("LedgerExchange SCARD_S_SUCCESS %ld/%d", cbSendLength, len);
|
||||||
|
if (len <= *pcbRecvLength) {
|
||||||
|
*pcbRecvLength = static_cast<DWORD>(len);
|
||||||
|
jenv->GetByteArrayRegion(dataRecv, 0, len, (jbyte *) pbRecvBuffer);
|
||||||
|
jenv->DeleteLocalRef(dataRecv);
|
||||||
|
detachJVM(jenv, envStat);
|
||||||
|
return SCARD_S_SUCCESS;
|
||||||
|
} else {
|
||||||
|
jenv->DeleteLocalRef(dataRecv);
|
||||||
|
detachJVM(jenv, envStat);
|
||||||
|
LOGE("LedgerExchange SCARD_E_INSUFFICIENT_BUFFER");
|
||||||
|
return SCARD_E_INSUFFICIENT_BUFFER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief LedgerFind - find Ledger Device and return it's name
|
||||||
|
* @param buffer - buffer for name of found device
|
||||||
|
* @param len - length of buffer
|
||||||
|
* @return 0 - success
|
||||||
|
* -1 - no device connected / found
|
||||||
|
* -2 - JVM not found
|
||||||
|
*/
|
||||||
|
int LedgerFind(char *buffer, size_t len) {
|
||||||
|
LOGD("LedgerName");
|
||||||
|
JNIEnv *jenv;
|
||||||
|
int envStat = attachJVM(&jenv);
|
||||||
|
if (envStat == JNI_ERR) return -2;
|
||||||
|
|
||||||
|
jmethodID nameMethod = jenv->GetStaticMethodID(class_Ledger, "Name", "()Ljava/lang/String;");
|
||||||
|
jstring name = (jstring) jenv->CallStaticObjectMethod(class_Ledger, nameMethod);
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
if (name != nullptr) {
|
||||||
|
const char *_name = jenv->GetStringUTFChars(name, NULL);
|
||||||
|
strncpy(buffer, _name, len);
|
||||||
|
jenv->ReleaseStringUTFChars(name, _name);
|
||||||
|
buffer[len - 1] = 0; // terminate in case _name is bigger
|
||||||
|
ret = 0;
|
||||||
|
LOGD("LedgerName is %s", buffer);
|
||||||
|
} else {
|
||||||
|
buffer[0] = 0;
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
detachJVM(jenv, envStat);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
46
app/src/main/cpp/monerujo_ledger.h
Normal file
46
app/src/main/cpp/monerujo_ledger.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018 m2049r
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRWALLET_LEDGER_H
|
||||||
|
#define XMRWALLET_LEDGER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SCARD_S_SUCCESS ((LONG)0x00000000) /**< No error was encountered. */
|
||||||
|
#define SCARD_E_INSUFFICIENT_BUFFER ((LONG)0x80100008) /**< The data buffer to receive returned data is too small for the returned data. */
|
||||||
|
#define SCARD_E_NO_READERS_AVAILABLE ((LONG)0x8010002E) /**< Cannot find a smart card reader. */
|
||||||
|
|
||||||
|
typedef long LONG;
|
||||||
|
typedef unsigned long DWORD;
|
||||||
|
typedef DWORD *LPDWORD;
|
||||||
|
typedef unsigned char BYTE;
|
||||||
|
typedef BYTE *LPBYTE;
|
||||||
|
typedef const BYTE *LPCBYTE;
|
||||||
|
|
||||||
|
typedef char CHAR;
|
||||||
|
typedef CHAR *LPSTR;
|
||||||
|
|
||||||
|
int LedgerFind(char *buffer, size_t len);
|
||||||
|
LONG LedgerExchange(LPCBYTE pbSendBuffer, DWORD cbSendLength, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //XMRWALLET_LEDGER_H
|
53
app/src/main/java/com/btchip/BTChipException.java
Normal file
53
app/src/main/java/com/btchip/BTChipException.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
*******************************************************************************
|
||||||
|
* BTChip Bitcoin Hardware Wallet Java API
|
||||||
|
* (c) 2014 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.btchip;
|
||||||
|
|
||||||
|
public class BTChipException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 5512803003827126405L;
|
||||||
|
|
||||||
|
public BTChipException(String reason) {
|
||||||
|
super(reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BTChipException(String reason, Throwable cause) {
|
||||||
|
super(reason, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BTChipException(String reason, int sw) {
|
||||||
|
super(reason);
|
||||||
|
this.sw = sw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSW() {
|
||||||
|
return sw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
if (sw == 0) {
|
||||||
|
return "BTChip Exception : " + getMessage();
|
||||||
|
} else {
|
||||||
|
return "BTChip Exception : " + getMessage() + " " + Integer.toHexString(sw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int sw;
|
||||||
|
|
||||||
|
}
|
31
app/src/main/java/com/btchip/comm/BTChipTransport.java
Normal file
31
app/src/main/java/com/btchip/comm/BTChipTransport.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
*******************************************************************************
|
||||||
|
* BTChip Bitcoin Hardware Wallet Java API
|
||||||
|
* (c) 2014 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn
|
||||||
|
* (c) 2018 m2049r
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.btchip.comm;
|
||||||
|
|
||||||
|
import com.btchip.BTChipException;
|
||||||
|
|
||||||
|
public interface BTChipTransport {
|
||||||
|
public byte[] exchange(byte[] command);
|
||||||
|
|
||||||
|
public void close();
|
||||||
|
|
||||||
|
public void setDebug(boolean debugFlag);
|
||||||
|
}
|
126
app/src/main/java/com/btchip/comm/LedgerHelper.java
Normal file
126
app/src/main/java/com/btchip/comm/LedgerHelper.java
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
*******************************************************************************
|
||||||
|
* BTChip Bitcoin Hardware Wallet Java API
|
||||||
|
* (c) 2014 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn
|
||||||
|
* (c) 2018 m2049r
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.btchip.comm;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
|
public class LedgerHelper {
|
||||||
|
|
||||||
|
private static final int TAG_APDU = 0x05;
|
||||||
|
|
||||||
|
public static byte[] wrapCommandAPDU(int channel, byte[] command, int packetSize) {
|
||||||
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
|
if (packetSize < 3) {
|
||||||
|
throw new IllegalArgumentException("Can't handle Ledger framing with less than 3 bytes for the report");
|
||||||
|
}
|
||||||
|
int sequenceIdx = 0;
|
||||||
|
int offset = 0;
|
||||||
|
output.write(channel >> 8);
|
||||||
|
output.write(channel);
|
||||||
|
output.write(TAG_APDU);
|
||||||
|
output.write(sequenceIdx >> 8);
|
||||||
|
output.write(sequenceIdx);
|
||||||
|
sequenceIdx++;
|
||||||
|
output.write(command.length >> 8);
|
||||||
|
output.write(command.length);
|
||||||
|
int blockSize = (command.length > packetSize - 7 ? packetSize - 7 : command.length);
|
||||||
|
output.write(command, offset, blockSize);
|
||||||
|
offset += blockSize;
|
||||||
|
while (offset != command.length) {
|
||||||
|
output.write(channel >> 8);
|
||||||
|
output.write(channel);
|
||||||
|
output.write(TAG_APDU);
|
||||||
|
output.write(sequenceIdx >> 8);
|
||||||
|
output.write(sequenceIdx);
|
||||||
|
sequenceIdx++;
|
||||||
|
blockSize = (command.length - offset > packetSize - 5 ? packetSize - 5 : command.length - offset);
|
||||||
|
output.write(command, offset, blockSize);
|
||||||
|
offset += blockSize;
|
||||||
|
}
|
||||||
|
if ((output.size() % packetSize) != 0) {
|
||||||
|
byte[] padding = new byte[packetSize - (output.size() % packetSize)];
|
||||||
|
output.write(padding, 0, padding.length);
|
||||||
|
}
|
||||||
|
return output.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] unwrapResponseAPDU(int channel, byte[] data, int packetSize) {
|
||||||
|
ByteArrayOutputStream response = new ByteArrayOutputStream();
|
||||||
|
int offset = 0;
|
||||||
|
int responseLength;
|
||||||
|
int sequenceIdx = 0;
|
||||||
|
if ((data == null) || (data.length < 7 + 5)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (data[offset++] != (channel >> 8)) {
|
||||||
|
throw new IllegalArgumentException("Invalid channel");
|
||||||
|
}
|
||||||
|
if (data[offset++] != (channel & 0xff)) {
|
||||||
|
throw new IllegalArgumentException("Invalid channel");
|
||||||
|
}
|
||||||
|
if (data[offset++] != TAG_APDU) {
|
||||||
|
throw new IllegalArgumentException("Invalid tag");
|
||||||
|
}
|
||||||
|
if (data[offset++] != 0x00) {
|
||||||
|
throw new IllegalArgumentException("Invalid sequence");
|
||||||
|
}
|
||||||
|
if (data[offset++] != 0x00) {
|
||||||
|
throw new IllegalArgumentException("Invalid sequence");
|
||||||
|
}
|
||||||
|
responseLength = ((data[offset++] & 0xff) << 8);
|
||||||
|
responseLength |= (data[offset++] & 0xff);
|
||||||
|
if (data.length < 7 + responseLength) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int blockSize = (responseLength > packetSize - 7 ? packetSize - 7 : responseLength);
|
||||||
|
response.write(data, offset, blockSize);
|
||||||
|
offset += blockSize;
|
||||||
|
while (response.size() != responseLength) {
|
||||||
|
sequenceIdx++;
|
||||||
|
if (offset == data.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (data[offset++] != (channel >> 8)) {
|
||||||
|
throw new IllegalArgumentException("Invalid channel");
|
||||||
|
}
|
||||||
|
if (data[offset++] != (channel & 0xff)) {
|
||||||
|
throw new IllegalArgumentException("Invalid channel");
|
||||||
|
}
|
||||||
|
if (data[offset++] != TAG_APDU) {
|
||||||
|
throw new IllegalArgumentException("Invalid tag");
|
||||||
|
}
|
||||||
|
if (data[offset++] != (sequenceIdx >> 8)) {
|
||||||
|
throw new IllegalArgumentException("Invalid sequence");
|
||||||
|
}
|
||||||
|
if (data[offset++] != (sequenceIdx & 0xff)) {
|
||||||
|
throw new IllegalArgumentException("Invalid sequence");
|
||||||
|
}
|
||||||
|
blockSize = (responseLength - response.size() > packetSize - 5 ? packetSize - 5 : responseLength - response.size());
|
||||||
|
if (blockSize > data.length - offset) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
response.write(data, offset, blockSize);
|
||||||
|
offset += blockSize;
|
||||||
|
}
|
||||||
|
return response.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,145 @@
|
|||||||
|
/*
|
||||||
|
*******************************************************************************
|
||||||
|
* BTChip Bitcoin Hardware Wallet Java API
|
||||||
|
* (c) 2014 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn
|
||||||
|
* (c) 2018 m2049r
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.btchip.comm.android;
|
||||||
|
|
||||||
|
import android.hardware.usb.UsbConstants;
|
||||||
|
import android.hardware.usb.UsbDevice;
|
||||||
|
import android.hardware.usb.UsbDeviceConnection;
|
||||||
|
import android.hardware.usb.UsbEndpoint;
|
||||||
|
import android.hardware.usb.UsbInterface;
|
||||||
|
import android.hardware.usb.UsbManager;
|
||||||
|
import android.hardware.usb.UsbRequest;
|
||||||
|
|
||||||
|
import com.btchip.BTChipException;
|
||||||
|
import com.btchip.comm.BTChipTransport;
|
||||||
|
import com.btchip.comm.LedgerHelper;
|
||||||
|
import com.btchip.utils.Dump;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
public class BTChipTransportAndroidHID implements BTChipTransport {
|
||||||
|
|
||||||
|
public static UsbDevice getDevice(UsbManager manager) {
|
||||||
|
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
|
||||||
|
for (UsbDevice device : deviceList.values()) {
|
||||||
|
Timber.d("%04X:%04X %s, %s", device.getVendorId(), device.getProductId(), device.getManufacturerName(), device.getProductName());
|
||||||
|
if ((device.getVendorId() == VID) && (device.getProductId() == PID_HID)) {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BTChipTransport open(UsbManager manager, UsbDevice device) throws IOException {
|
||||||
|
UsbDeviceConnection connection = manager.openDevice(device);
|
||||||
|
if (connection == null) throw new IOException("Device not connected");
|
||||||
|
// Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html)
|
||||||
|
// Important if enumerating, rather than being awaken by the intent notification
|
||||||
|
UsbInterface dongleInterface = device.getInterface(0);
|
||||||
|
UsbEndpoint in = null;
|
||||||
|
UsbEndpoint out = null;
|
||||||
|
for (int i = 0; i < dongleInterface.getEndpointCount(); i++) {
|
||||||
|
UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i);
|
||||||
|
if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
|
||||||
|
in = tmpEndpoint;
|
||||||
|
} else {
|
||||||
|
out = tmpEndpoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connection.claimInterface(dongleInterface, true);
|
||||||
|
return new BTChipTransportAndroidHID(connection, dongleInterface, in, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int VID = 0x2C97;
|
||||||
|
private static final int PID_HID = 0x0001;
|
||||||
|
|
||||||
|
private UsbDeviceConnection connection;
|
||||||
|
private UsbInterface dongleInterface;
|
||||||
|
private UsbEndpoint in;
|
||||||
|
private UsbEndpoint out;
|
||||||
|
private byte transferBuffer[];
|
||||||
|
private boolean debug;
|
||||||
|
|
||||||
|
public BTChipTransportAndroidHID(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out) {
|
||||||
|
this.connection = connection;
|
||||||
|
this.dongleInterface = dongleInterface;
|
||||||
|
this.in = in;
|
||||||
|
this.out = out;
|
||||||
|
transferBuffer = new byte[HID_BUFFER_SIZE];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] exchange(byte[] command) {
|
||||||
|
ByteArrayOutputStream response = new ByteArrayOutputStream();
|
||||||
|
byte[] responseData = null;
|
||||||
|
int offset = 0;
|
||||||
|
if (debug) {
|
||||||
|
Timber.d("=> %s", Dump.dump(command));
|
||||||
|
}
|
||||||
|
command = LedgerHelper.wrapCommandAPDU(LEDGER_DEFAULT_CHANNEL, command, HID_BUFFER_SIZE);
|
||||||
|
UsbRequest requestOut = new UsbRequest();
|
||||||
|
requestOut.initialize(connection, out);
|
||||||
|
while (offset != command.length) {
|
||||||
|
int blockSize = (command.length - offset > HID_BUFFER_SIZE ? HID_BUFFER_SIZE : command.length - offset);
|
||||||
|
System.arraycopy(command, offset, transferBuffer, 0, blockSize);
|
||||||
|
requestOut.queue(ByteBuffer.wrap(transferBuffer), HID_BUFFER_SIZE);
|
||||||
|
connection.requestWait();
|
||||||
|
offset += blockSize;
|
||||||
|
}
|
||||||
|
requestOut.close();
|
||||||
|
ByteBuffer responseBuffer = ByteBuffer.allocate(HID_BUFFER_SIZE);
|
||||||
|
UsbRequest requestIn = new UsbRequest();
|
||||||
|
requestIn.initialize(connection, in);
|
||||||
|
while ((responseData = LedgerHelper.unwrapResponseAPDU(LEDGER_DEFAULT_CHANNEL, response.toByteArray(), HID_BUFFER_SIZE)) == null) {
|
||||||
|
responseBuffer.clear();
|
||||||
|
requestIn.queue(responseBuffer, HID_BUFFER_SIZE);
|
||||||
|
connection.requestWait();
|
||||||
|
responseBuffer.rewind();
|
||||||
|
responseBuffer.get(transferBuffer, 0, HID_BUFFER_SIZE);
|
||||||
|
response.write(transferBuffer, 0, HID_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
requestIn.close();
|
||||||
|
if (debug) {
|
||||||
|
Timber.d("<= %s", Dump.dump(responseData));
|
||||||
|
}
|
||||||
|
return responseData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
connection.releaseInterface(dongleInterface);
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDebug(boolean debugFlag) {
|
||||||
|
this.debug = debugFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int HID_BUFFER_SIZE = 64;
|
||||||
|
private static final int LEDGER_DEFAULT_CHANNEL = 1;
|
||||||
|
private static final int SW1_DATA_AVAILABLE = 0x61;
|
||||||
|
}
|
62
app/src/main/java/com/btchip/utils/Dump.java
Normal file
62
app/src/main/java/com/btchip/utils/Dump.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
*******************************************************************************
|
||||||
|
* BTChip Bitcoin Hardware Wallet Java API
|
||||||
|
* (c) 2014 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.btchip.utils;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
|
public class Dump {
|
||||||
|
|
||||||
|
public static String dump(byte[] buffer, int offset, int length) {
|
||||||
|
String result = "";
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
String temp = Integer.toHexString((buffer[offset + i]) & 0xff);
|
||||||
|
if (temp.length() < 2) {
|
||||||
|
temp = "0" + temp;
|
||||||
|
}
|
||||||
|
result += temp;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String dump(byte[] buffer) {
|
||||||
|
return dump(buffer, 0, buffer.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] hexToBin(String src) {
|
||||||
|
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||||
|
int i = 0;
|
||||||
|
while (i < src.length()) {
|
||||||
|
char x = src.charAt(i);
|
||||||
|
if (!((x >= '0' && x <= '9') || (x >= 'A' && x <= 'F') || (x >= 'a' && x <= 'f'))) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
result.write(Integer.valueOf("" + src.charAt(i) + src.charAt(i + 1), 16));
|
||||||
|
i += 2;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
294
app/src/main/java/com/m2049r/xmrwallet/BaseActivity.java
Normal file
294
app/src/main/java/com/m2049r/xmrwallet/BaseActivity.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -61,6 +61,7 @@ public class GenerateFragment extends Fragment {
|
|||||||
static final String TYPE_NEW = "new";
|
static final String TYPE_NEW = "new";
|
||||||
static final String TYPE_KEY = "key";
|
static final String TYPE_KEY = "key";
|
||||||
static final String TYPE_SEED = "seed";
|
static final String TYPE_SEED = "seed";
|
||||||
|
static final String TYPE_LEDGER = "ledger";
|
||||||
static final String TYPE_VIEWONLY = "view";
|
static final String TYPE_VIEWONLY = "view";
|
||||||
|
|
||||||
private TextInputLayout etWalletName;
|
private TextInputLayout etWalletName;
|
||||||
@@ -190,6 +191,17 @@ public class GenerateFragment extends Fragment {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (type.equals(TYPE_LEDGER)) {
|
||||||
|
etWalletPassword.getEditText().setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||||
|
etWalletPassword.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
|
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
|
||||||
|
etWalletRestoreHeight.requestFocus();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (type.equals(TYPE_SEED)) {
|
} else if (type.equals(TYPE_SEED)) {
|
||||||
etWalletPassword.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
etWalletPassword.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
@@ -391,16 +403,24 @@ public class GenerateFragment extends Fragment {
|
|||||||
// is it a date?
|
// is it a date?
|
||||||
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
parser.setLenient(false);
|
parser.setLenient(false);
|
||||||
parser.parse(restoreHeight);
|
height = RestoreHeight.getInstance().getHeight(parser.parse(restoreHeight));
|
||||||
height = RestoreHeight.getInstance().getHeight(restoreHeight);
|
} catch (ParseException ex) {
|
||||||
} catch (ParseException exPE) {
|
}
|
||||||
|
if (height <= 0)
|
||||||
|
try {
|
||||||
|
// is it a date without dashes?
|
||||||
|
SimpleDateFormat parser = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
parser.setLenient(false);
|
||||||
|
height = RestoreHeight.getInstance().getHeight(parser.parse(restoreHeight));
|
||||||
|
} catch (ParseException ex) {
|
||||||
|
}
|
||||||
|
if (height <= 0)
|
||||||
try {
|
try {
|
||||||
// or is it a height?
|
// or is it a height?
|
||||||
height = Long.parseLong(restoreHeight);
|
height = Long.parseLong(restoreHeight);
|
||||||
} catch (NumberFormatException exNFE) {
|
} catch (NumberFormatException ex) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Timber.d("Using Restore Height = %d", height);
|
Timber.d("Using Restore Height = %d", height);
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
@@ -477,6 +497,12 @@ public class GenerateFragment extends Fragment {
|
|||||||
KeyStoreHelper.saveWalletUserPass(getActivity(), name, password);
|
KeyStoreHelper.saveWalletUserPass(getActivity(), name, password);
|
||||||
}
|
}
|
||||||
activityCallback.onGenerate(name, crazyPass, seed, height);
|
activityCallback.onGenerate(name, crazyPass, seed, height);
|
||||||
|
} else if (type.equals(TYPE_LEDGER)) {
|
||||||
|
bGenerate.setEnabled(false);
|
||||||
|
if (fingerprintAuthAllowed) {
|
||||||
|
KeyStoreHelper.saveWalletUserPass(getActivity(), name, password);
|
||||||
|
}
|
||||||
|
activityCallback.onGenerateLedger(name, crazyPass, height);
|
||||||
} else if (type.equals(TYPE_KEY) || type.equals(TYPE_VIEWONLY)) {
|
} else if (type.equals(TYPE_KEY) || type.equals(TYPE_VIEWONLY)) {
|
||||||
if (checkAddress() && checkViewKey() && checkSpendKey()) {
|
if (checkAddress() && checkViewKey() && checkSpendKey()) {
|
||||||
bGenerate.setEnabled(false);
|
bGenerate.setEnabled(false);
|
||||||
@@ -515,6 +541,8 @@ public class GenerateFragment extends Fragment {
|
|||||||
return getString(R.string.generate_wallet_type_new);
|
return getString(R.string.generate_wallet_type_new);
|
||||||
case TYPE_SEED:
|
case TYPE_SEED:
|
||||||
return getString(R.string.generate_wallet_type_seed);
|
return getString(R.string.generate_wallet_type_seed);
|
||||||
|
case TYPE_LEDGER:
|
||||||
|
return getString(R.string.generate_wallet_type_ledger);
|
||||||
case TYPE_VIEWONLY:
|
case TYPE_VIEWONLY:
|
||||||
return getString(R.string.generate_wallet_type_view);
|
return getString(R.string.generate_wallet_type_view);
|
||||||
default:
|
default:
|
||||||
@@ -532,6 +560,8 @@ public class GenerateFragment extends Fragment {
|
|||||||
|
|
||||||
void onGenerate(String name, String password, String address, String viewKey, String spendKey, long height);
|
void onGenerate(String name, String password, String address, String viewKey, String spendKey, long height);
|
||||||
|
|
||||||
|
void onGenerateLedger(String name, String password, long height);
|
||||||
|
|
||||||
void setTitle(String title);
|
void setTitle(String title);
|
||||||
|
|
||||||
void setToolbarButton(int type);
|
void setToolbarButton(int type);
|
||||||
@@ -567,6 +597,9 @@ public class GenerateFragment extends Fragment {
|
|||||||
case TYPE_SEED:
|
case TYPE_SEED:
|
||||||
inflater.inflate(R.menu.create_wallet_seed, menu);
|
inflater.inflate(R.menu.create_wallet_seed, menu);
|
||||||
break;
|
break;
|
||||||
|
case TYPE_LEDGER:
|
||||||
|
inflater.inflate(R.menu.create_wallet_ledger, menu);
|
||||||
|
break;
|
||||||
case TYPE_VIEWONLY:
|
case TYPE_VIEWONLY:
|
||||||
inflater.inflate(R.menu.create_wallet_view, menu);
|
inflater.inflate(R.menu.create_wallet_view, menu);
|
||||||
break;
|
break;
|
||||||
|
@@ -43,6 +43,8 @@ import android.widget.Switch;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.m2049r.xmrwallet.ledger.Ledger;
|
||||||
|
import com.m2049r.xmrwallet.ledger.LedgerProgressDialog;
|
||||||
import com.m2049r.xmrwallet.model.NetworkType;
|
import com.m2049r.xmrwallet.model.NetworkType;
|
||||||
import com.m2049r.xmrwallet.model.Wallet;
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
@@ -52,8 +54,6 @@ import com.m2049r.xmrwallet.util.KeyStoreHelper;
|
|||||||
import com.m2049r.xmrwallet.util.MoneroThreadPoolExecutor;
|
import com.m2049r.xmrwallet.util.MoneroThreadPoolExecutor;
|
||||||
import com.m2049r.xmrwallet.widget.Toolbar;
|
import com.m2049r.xmrwallet.widget.Toolbar;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class GenerateReviewFragment extends Fragment {
|
public class GenerateReviewFragment extends Fragment {
|
||||||
@@ -76,6 +76,9 @@ public class GenerateReviewFragment extends Fragment {
|
|||||||
private ImageButton bCopyAddress;
|
private ImageButton bCopyAddress;
|
||||||
private LinearLayout llAdvancedInfo;
|
private LinearLayout llAdvancedInfo;
|
||||||
private LinearLayout llPassword;
|
private LinearLayout llPassword;
|
||||||
|
private LinearLayout llMnemonic;
|
||||||
|
private LinearLayout llSpendKey;
|
||||||
|
private LinearLayout llViewKey;
|
||||||
private Button bAdvancedInfo;
|
private Button bAdvancedInfo;
|
||||||
private Button bAccept;
|
private Button bAccept;
|
||||||
|
|
||||||
@@ -99,6 +102,9 @@ public class GenerateReviewFragment extends Fragment {
|
|||||||
bAdvancedInfo = (Button) view.findViewById(R.id.bAdvancedInfo);
|
bAdvancedInfo = (Button) view.findViewById(R.id.bAdvancedInfo);
|
||||||
llAdvancedInfo = (LinearLayout) view.findViewById(R.id.llAdvancedInfo);
|
llAdvancedInfo = (LinearLayout) view.findViewById(R.id.llAdvancedInfo);
|
||||||
llPassword = (LinearLayout) view.findViewById(R.id.llPassword);
|
llPassword = (LinearLayout) view.findViewById(R.id.llPassword);
|
||||||
|
llMnemonic = (LinearLayout) view.findViewById(R.id.llMnemonic);
|
||||||
|
llSpendKey = (LinearLayout) view.findViewById(R.id.llSpendKey);
|
||||||
|
llViewKey = (LinearLayout) view.findViewById(R.id.llViewKey);
|
||||||
|
|
||||||
bAccept = (Button) view.findViewById(R.id.bAccept);
|
bAccept = (Button) view.findViewById(R.id.bAccept);
|
||||||
|
|
||||||
@@ -142,7 +148,6 @@ public class GenerateReviewFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void showDetails() {
|
void showDetails() {
|
||||||
showProgress();
|
|
||||||
tvWalletPassword.setText(null);
|
tvWalletPassword.setText(null);
|
||||||
new AsyncShow().executeOnExecutor(MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR, walletPath);
|
new AsyncShow().executeOnExecutor(MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR, walletPath);
|
||||||
}
|
}
|
||||||
@@ -188,6 +193,20 @@ public class GenerateReviewFragment extends Fragment {
|
|||||||
boolean isWatchOnly;
|
boolean isWatchOnly;
|
||||||
Wallet.Status status;
|
Wallet.Status status;
|
||||||
|
|
||||||
|
boolean dialogOpened = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
super.onPreExecute();
|
||||||
|
showProgress();
|
||||||
|
if ((walletPath != null)
|
||||||
|
&& (WalletManager.getInstance().queryWalletHardware(walletPath + ".keys", getPassword()) == 1)
|
||||||
|
&& (progressCallback != null)) {
|
||||||
|
progressCallback.showLedgerProgressDialog(LedgerProgressDialog.TYPE_RESTORE);
|
||||||
|
dialogOpened = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(String... params) {
|
protected Boolean doInBackground(String... params) {
|
||||||
if (params.length != 1) return false;
|
if (params.length != 1) return false;
|
||||||
@@ -212,7 +231,11 @@ public class GenerateReviewFragment extends Fragment {
|
|||||||
|
|
||||||
address = wallet.getAddress();
|
address = wallet.getAddress();
|
||||||
seed = wallet.getSeed();
|
seed = wallet.getSeed();
|
||||||
|
if (wallet.isKeyOnDevice()) {
|
||||||
|
viewKey = Ledger.Key();
|
||||||
|
} else {
|
||||||
viewKey = wallet.getSecretViewKey();
|
viewKey = wallet.getSecretViewKey();
|
||||||
|
}
|
||||||
spendKey = isWatchOnly ? getActivity().getString(R.string.label_watchonly) : wallet.getSecretSpendKey();
|
spendKey = isWatchOnly ? getActivity().getString(R.string.label_watchonly) : wallet.getSecretSpendKey();
|
||||||
isWatchOnly = wallet.isWatchOnly();
|
isWatchOnly = wallet.isWatchOnly();
|
||||||
if (closeWallet) wallet.close();
|
if (closeWallet) wallet.close();
|
||||||
@@ -222,6 +245,8 @@ public class GenerateReviewFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Boolean result) {
|
protected void onPostExecute(Boolean result) {
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
|
if (dialogOpened)
|
||||||
|
progressCallback.dismissProgressDialog();
|
||||||
if (!isAdded()) return; // never mind
|
if (!isAdded()) return; // never mind
|
||||||
walletName = name;
|
walletName = name;
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -232,10 +257,22 @@ public class GenerateReviewFragment extends Fragment {
|
|||||||
llPassword.setVisibility(View.VISIBLE);
|
llPassword.setVisibility(View.VISIBLE);
|
||||||
tvWalletPassword.setText(getPassword());
|
tvWalletPassword.setText(getPassword());
|
||||||
tvWalletAddress.setText(address);
|
tvWalletAddress.setText(address);
|
||||||
|
if (!seed.isEmpty()) {
|
||||||
|
llMnemonic.setVisibility(View.VISIBLE);
|
||||||
tvWalletMnemonic.setText(seed);
|
tvWalletMnemonic.setText(seed);
|
||||||
|
}
|
||||||
|
boolean showAdvanced = false;
|
||||||
|
if (isKeyValid(viewKey)) {
|
||||||
|
llViewKey.setVisibility(View.VISIBLE);
|
||||||
tvWalletViewKey.setText(viewKey);
|
tvWalletViewKey.setText(viewKey);
|
||||||
|
showAdvanced = true;
|
||||||
|
}
|
||||||
|
if (isKeyValid(spendKey)) {
|
||||||
|
llSpendKey.setVisibility(View.VISIBLE);
|
||||||
tvWalletSpendKey.setText(spendKey);
|
tvWalletSpendKey.setText(spendKey);
|
||||||
bAdvancedInfo.setVisibility(View.VISIBLE);
|
showAdvanced = true;
|
||||||
|
}
|
||||||
|
if (showAdvanced) bAdvancedInfo.setVisibility(View.VISIBLE);
|
||||||
bCopyAddress.setClickable(true);
|
bCopyAddress.setClickable(true);
|
||||||
bCopyAddress.setImageResource(R.drawable.ic_content_copy_black_24dp);
|
bCopyAddress.setImageResource(R.drawable.ic_content_copy_black_24dp);
|
||||||
activityCallback.setTitle(name, getString(R.string.details_title));
|
activityCallback.setTitle(name, getString(R.string.details_title));
|
||||||
@@ -267,6 +304,8 @@ public class GenerateReviewFragment extends Fragment {
|
|||||||
public interface ProgressListener {
|
public interface ProgressListener {
|
||||||
void showProgressDialog(int msgId);
|
void showProgressDialog(int msgId);
|
||||||
|
|
||||||
|
void showLedgerProgressDialog(int mode);
|
||||||
|
|
||||||
void dismissProgressDialog();
|
void dismissProgressDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -577,4 +616,10 @@ public class GenerateReviewFragment extends Fragment {
|
|||||||
return openDialog;
|
return openDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isKeyValid(String key) {
|
||||||
|
return (key != null) && (key.length() == 64)
|
||||||
|
&& !key.equals("0000000000000000000000000000000000000000000000000000000000000000")
|
||||||
|
&& !key.toLowerCase().equals("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||||
|
// ledger implmenetation returns the spend key as f's
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -103,6 +103,7 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
|||||||
|
|
||||||
void setNetworkType(NetworkType networkType);
|
void setNetworkType(NetworkType networkType);
|
||||||
|
|
||||||
|
boolean hasLedger();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -145,11 +146,13 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
|||||||
fabView = (FloatingActionButton) view.findViewById(R.id.fabView);
|
fabView = (FloatingActionButton) view.findViewById(R.id.fabView);
|
||||||
fabKey = (FloatingActionButton) view.findViewById(R.id.fabKey);
|
fabKey = (FloatingActionButton) view.findViewById(R.id.fabKey);
|
||||||
fabSeed = (FloatingActionButton) view.findViewById(R.id.fabSeed);
|
fabSeed = (FloatingActionButton) view.findViewById(R.id.fabSeed);
|
||||||
|
fabLedger = (FloatingActionButton) view.findViewById(R.id.fabLedger);
|
||||||
|
|
||||||
fabNewL = (RelativeLayout) view.findViewById(R.id.fabNewL);
|
fabNewL = (RelativeLayout) view.findViewById(R.id.fabNewL);
|
||||||
fabViewL = (RelativeLayout) view.findViewById(R.id.fabViewL);
|
fabViewL = (RelativeLayout) view.findViewById(R.id.fabViewL);
|
||||||
fabKeyL = (RelativeLayout) view.findViewById(R.id.fabKeyL);
|
fabKeyL = (RelativeLayout) view.findViewById(R.id.fabKeyL);
|
||||||
fabSeedL = (RelativeLayout) view.findViewById(R.id.fabSeedL);
|
fabSeedL = (RelativeLayout) view.findViewById(R.id.fabSeedL);
|
||||||
|
fabLedgerL = (RelativeLayout) view.findViewById(R.id.fabLedgerL);
|
||||||
|
|
||||||
fab_pulse = AnimationUtils.loadAnimation(getContext(), R.anim.fab_pulse);
|
fab_pulse = AnimationUtils.loadAnimation(getContext(), R.anim.fab_pulse);
|
||||||
fab_open_screen = AnimationUtils.loadAnimation(getContext(), R.anim.fab_open_screen);
|
fab_open_screen = AnimationUtils.loadAnimation(getContext(), R.anim.fab_open_screen);
|
||||||
@@ -163,6 +166,7 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
|||||||
fabView.setOnClickListener(this);
|
fabView.setOnClickListener(this);
|
||||||
fabKey.setOnClickListener(this);
|
fabKey.setOnClickListener(this);
|
||||||
fabSeed.setOnClickListener(this);
|
fabSeed.setOnClickListener(this);
|
||||||
|
fabLedger.setOnClickListener(this);
|
||||||
fabScreen.setOnClickListener(this);
|
fabScreen.setOnClickListener(this);
|
||||||
|
|
||||||
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
|
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
|
||||||
@@ -426,9 +430,9 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFabOpen = false;
|
private boolean isFabOpen = false;
|
||||||
private FloatingActionButton fab, fabNew, fabView, fabKey, fabSeed;
|
private FloatingActionButton fab, fabNew, fabView, fabKey, fabSeed, fabLedger;
|
||||||
private FrameLayout fabScreen;
|
private FrameLayout fabScreen;
|
||||||
private RelativeLayout fabNewL, fabViewL, fabKeyL, fabSeedL;
|
private RelativeLayout fabNewL, fabViewL, fabKeyL, fabSeedL, fabLedgerL;
|
||||||
private Animation fab_open, fab_close, rotate_forward, rotate_backward, fab_open_screen, fab_close_screen;
|
private Animation fab_open, fab_close, rotate_forward, rotate_backward, fab_open_screen, fab_close_screen;
|
||||||
private Animation fab_pulse;
|
private Animation fab_pulse;
|
||||||
|
|
||||||
@@ -437,11 +441,14 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void animateFAB() {
|
public void animateFAB() {
|
||||||
if (isFabOpen) {
|
if (isFabOpen) { // close the fab
|
||||||
fabScreen.setVisibility(View.INVISIBLE);
|
|
||||||
fabScreen.setClickable(false);
|
fabScreen.setClickable(false);
|
||||||
fabScreen.startAnimation(fab_close_screen);
|
fabScreen.startAnimation(fab_close_screen);
|
||||||
fab.startAnimation(rotate_backward);
|
fab.startAnimation(rotate_backward);
|
||||||
|
if (fabLedgerL.getVisibility() == View.VISIBLE) {
|
||||||
|
fabLedgerL.startAnimation(fab_close);
|
||||||
|
fabLedger.setClickable(false);
|
||||||
|
} else {
|
||||||
fabNewL.startAnimation(fab_close);
|
fabNewL.startAnimation(fab_close);
|
||||||
fabNew.setClickable(false);
|
fabNew.setClickable(false);
|
||||||
fabViewL.startAnimation(fab_close);
|
fabViewL.startAnimation(fab_close);
|
||||||
@@ -450,11 +457,28 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
|||||||
fabKey.setClickable(false);
|
fabKey.setClickable(false);
|
||||||
fabSeedL.startAnimation(fab_close);
|
fabSeedL.startAnimation(fab_close);
|
||||||
fabSeed.setClickable(false);
|
fabSeed.setClickable(false);
|
||||||
|
}
|
||||||
isFabOpen = false;
|
isFabOpen = false;
|
||||||
} else {
|
} else { // open the fab
|
||||||
fabScreen.setClickable(true);
|
fabScreen.setClickable(true);
|
||||||
fabScreen.startAnimation(fab_open_screen);
|
fabScreen.startAnimation(fab_open_screen);
|
||||||
fab.startAnimation(rotate_forward);
|
fab.startAnimation(rotate_forward);
|
||||||
|
if (activityCallback.hasLedger()) {
|
||||||
|
fabLedgerL.setVisibility(View.VISIBLE);
|
||||||
|
fabNewL.setVisibility(View.GONE);
|
||||||
|
fabViewL.setVisibility(View.GONE);
|
||||||
|
fabKeyL.setVisibility(View.GONE);
|
||||||
|
fabSeedL.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
fabLedgerL.startAnimation(fab_open);
|
||||||
|
fabLedger.setClickable(true);
|
||||||
|
} else {
|
||||||
|
fabLedgerL.setVisibility(View.GONE);
|
||||||
|
fabNewL.setVisibility(View.VISIBLE);
|
||||||
|
fabViewL.setVisibility(View.VISIBLE);
|
||||||
|
fabKeyL.setVisibility(View.VISIBLE);
|
||||||
|
fabSeedL.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
fabNewL.startAnimation(fab_open);
|
fabNewL.startAnimation(fab_open);
|
||||||
fabNew.setClickable(true);
|
fabNew.setClickable(true);
|
||||||
fabViewL.startAnimation(fab_open);
|
fabViewL.startAnimation(fab_open);
|
||||||
@@ -463,6 +487,7 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
|||||||
fabKey.setClickable(true);
|
fabKey.setClickable(true);
|
||||||
fabSeedL.startAnimation(fab_open);
|
fabSeedL.startAnimation(fab_open);
|
||||||
fabSeed.setClickable(true);
|
fabSeed.setClickable(true);
|
||||||
|
}
|
||||||
isFabOpen = true;
|
isFabOpen = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,6 +495,7 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
int id = v.getId();
|
int id = v.getId();
|
||||||
|
Timber.d("onClick %d/%d", id, R.id.fabLedger);
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case R.id.fab:
|
case R.id.fab:
|
||||||
animateFAB();
|
animateFAB();
|
||||||
@@ -491,6 +517,11 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
|||||||
animateFAB();
|
animateFAB();
|
||||||
activityCallback.onAddWallet(GenerateFragment.TYPE_SEED);
|
activityCallback.onAddWallet(GenerateFragment.TYPE_SEED);
|
||||||
break;
|
break;
|
||||||
|
case R.id.fabLedger:
|
||||||
|
Timber.d("FAB_LEDGER");
|
||||||
|
animateFAB();
|
||||||
|
activityCallback.onAddWallet(GenerateFragment.TYPE_LEDGER);
|
||||||
|
break;
|
||||||
case R.id.fabScreen:
|
case R.id.fabScreen:
|
||||||
animateFAB();
|
animateFAB();
|
||||||
break;
|
break;
|
||||||
|
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 m2049r
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.m2049r.xmrwallet;
|
||||||
|
|
||||||
|
import com.m2049r.xmrwallet.data.BarcodeData;
|
||||||
|
|
||||||
|
public interface OnUriScannedListener {
|
||||||
|
boolean onUriScanned(BarcodeData barcodeData);
|
||||||
|
}
|
@@ -20,6 +20,8 @@ import android.content.Context;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.nfc.NfcAdapter;
|
||||||
|
import android.nfc.NfcManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.TextInputLayout;
|
import android.support.design.widget.TextInputLayout;
|
||||||
@@ -47,6 +49,7 @@ import com.google.zxing.common.BitMatrix;
|
|||||||
import com.google.zxing.qrcode.QRCodeWriter;
|
import com.google.zxing.qrcode.QRCodeWriter;
|
||||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||||
import com.m2049r.xmrwallet.data.BarcodeData;
|
import com.m2049r.xmrwallet.data.BarcodeData;
|
||||||
|
import com.m2049r.xmrwallet.ledger.LedgerProgressDialog;
|
||||||
import com.m2049r.xmrwallet.model.Wallet;
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
import com.m2049r.xmrwallet.util.Helper;
|
import com.m2049r.xmrwallet.util.Helper;
|
||||||
@@ -62,7 +65,6 @@ import timber.log.Timber;
|
|||||||
public class ReceiveFragment extends Fragment {
|
public class ReceiveFragment extends Fragment {
|
||||||
|
|
||||||
private ProgressBar pbProgress;
|
private ProgressBar pbProgress;
|
||||||
private View llAddress;
|
|
||||||
private TextView tvAddressLabel;
|
private TextView tvAddressLabel;
|
||||||
private TextView tvAddress;
|
private TextView tvAddress;
|
||||||
private TextInputLayout etPaymentId;
|
private TextInputLayout etPaymentId;
|
||||||
@@ -93,7 +95,6 @@ public class ReceiveFragment extends Fragment {
|
|||||||
View view = inflater.inflate(R.layout.fragment_receive, container, false);
|
View view = inflater.inflate(R.layout.fragment_receive, container, false);
|
||||||
|
|
||||||
pbProgress = (ProgressBar) view.findViewById(R.id.pbProgress);
|
pbProgress = (ProgressBar) view.findViewById(R.id.pbProgress);
|
||||||
llAddress = view.findViewById(R.id.llAddress);
|
|
||||||
tvAddressLabel = (TextView) view.findViewById(R.id.tvAddressLabel);
|
tvAddressLabel = (TextView) view.findViewById(R.id.tvAddressLabel);
|
||||||
tvAddress = (TextView) view.findViewById(R.id.tvAddress);
|
tvAddress = (TextView) view.findViewById(R.id.tvAddress);
|
||||||
etPaymentId = (TextInputLayout) view.findViewById(R.id.etPaymentId);
|
etPaymentId = (TextInputLayout) view.findViewById(R.id.etPaymentId);
|
||||||
@@ -177,23 +178,9 @@ public class ReceiveFragment extends Fragment {
|
|||||||
enableSubaddressButton(false);
|
enableSubaddressButton(false);
|
||||||
enableCopyAddress(false);
|
enableCopyAddress(false);
|
||||||
|
|
||||||
final Runnable resetSize = new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
tvAddress.animate().setDuration(125).scaleX(1).scaleY(1).start();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final Runnable newAddress = new Runnable() {
|
final Runnable newAddress = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
tvAddressLabel.setText(getString(R.string.generate_address_label_sub,
|
getNewSubaddress();
|
||||||
wallet.getNumSubaddresses() - 1));
|
|
||||||
tvAddress.setText(wallet.getNewSubaddress());
|
|
||||||
storeWallet();
|
|
||||||
generateQr();
|
|
||||||
enableCopyAddress(true);
|
|
||||||
tvAddress.animate().alpha(1).setDuration(125)
|
|
||||||
.scaleX(1.2f).scaleY(1.2f)
|
|
||||||
.withEndAction(resetSize).start();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -241,6 +228,12 @@ public class ReceiveFragment extends Fragment {
|
|||||||
throw new IllegalStateException("no wallet info");
|
throw new IllegalStateException("no wallet info");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
View tvNfc = view.findViewById(R.id.tvNfc);
|
||||||
|
NfcManager manager = (NfcManager) getContext().getSystemService(Context.NFC_SERVICE);
|
||||||
|
if ((manager != null) && (manager.getDefaultAdapter() != null))
|
||||||
|
tvNfc.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +265,7 @@ public class ReceiveFragment extends Fragment {
|
|||||||
void setQR(Bitmap qr) {
|
void setQR(Bitmap qr) {
|
||||||
qrCode.setImageBitmap(qr);
|
qrCode.setImageBitmap(qr);
|
||||||
qrValid = true;
|
qrValid = true;
|
||||||
tvQrCode.setVisibility(View.INVISIBLE);
|
tvQrCode.setVisibility(View.GONE);
|
||||||
Helper.hideKeyboard(getActivity());
|
Helper.hideKeyboard(getActivity());
|
||||||
etDummy.requestFocus();
|
etDummy.requestFocus();
|
||||||
}
|
}
|
||||||
@@ -315,18 +308,39 @@ public class ReceiveFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadAndShow(String walletPath, String password) {
|
private void loadAndShow(String walletPath, String password) {
|
||||||
new AsyncShow().executeOnExecutor(MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR,
|
new AsyncShow(walletPath, password).executeOnExecutor(MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR);
|
||||||
walletPath, password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AsyncShow extends AsyncTask<String, Void, Boolean> {
|
GenerateReviewFragment.ProgressListener progressCallback = null;
|
||||||
String password;
|
|
||||||
|
private class AsyncShow extends AsyncTask<Void, Void, Boolean> {
|
||||||
|
final private String walletPath;
|
||||||
|
final private String password;
|
||||||
|
|
||||||
|
|
||||||
|
AsyncShow(String walletPath, String passsword) {
|
||||||
|
super();
|
||||||
|
this.walletPath = walletPath;
|
||||||
|
this.password = passsword;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean dialogOpened = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(String... params) {
|
protected void onPreExecute() {
|
||||||
if (params.length != 2) return false;
|
super.onPreExecute();
|
||||||
String walletPath = params[0];
|
showProgress();
|
||||||
password = params[1];
|
if ((walletPath != null)
|
||||||
|
&& (WalletManager.getInstance().queryWalletHardware(walletPath + ".keys", password) == 1)
|
||||||
|
&& (progressCallback != null)) {
|
||||||
|
progressCallback.showLedgerProgressDialog(LedgerProgressDialog.TYPE_RESTORE);
|
||||||
|
dialogOpened = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(Void... params) {
|
||||||
|
if (params.length != 0) return false;
|
||||||
wallet = WalletManager.getInstance().openWallet(walletPath, password);
|
wallet = WalletManager.getInstance().openWallet(walletPath, password);
|
||||||
isMyWallet = true;
|
isMyWallet = true;
|
||||||
return true;
|
return true;
|
||||||
@@ -335,6 +349,8 @@ public class ReceiveFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Boolean result) {
|
protected void onPostExecute(Boolean result) {
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
|
if (dialogOpened)
|
||||||
|
progressCallback.dismissProgressDialog();
|
||||||
if (!isAdded()) return; // never mind
|
if (!isAdded()) return; // never mind
|
||||||
if (result) {
|
if (result) {
|
||||||
show();
|
show();
|
||||||
@@ -365,7 +381,6 @@ public class ReceiveFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean checkPaymentId() {
|
private boolean checkPaymentId() {
|
||||||
String paymentId = etPaymentId.getEditText().getText().toString();
|
String paymentId = etPaymentId.getEditText().getText().toString();
|
||||||
boolean ok = paymentId.isEmpty() || Wallet.isPaymentIdValid(paymentId);
|
boolean ok = paymentId.isEmpty() || Wallet.isPaymentIdValid(paymentId);
|
||||||
@@ -378,6 +393,15 @@ public class ReceiveFragment extends Fragment {
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BarcodeData getBarcodeData() {
|
||||||
|
if (qrValid)
|
||||||
|
return bcData;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BarcodeData bcData = null;
|
||||||
|
|
||||||
private void generateQr() {
|
private void generateQr() {
|
||||||
Timber.d("GENQR");
|
Timber.d("GENQR");
|
||||||
String address = tvAddress.getText().toString();
|
String address = tvAddress.getText().toString();
|
||||||
@@ -389,27 +413,9 @@ public class ReceiveFragment extends Fragment {
|
|||||||
Timber.d("CLEARQR");
|
Timber.d("CLEARQR");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
StringBuffer sb = new StringBuffer();
|
bcData = new BarcodeData(BarcodeData.Asset.XMR, address, paymentId, xmrAmount);
|
||||||
sb.append(BarcodeData.XMR_SCHEME).append(address);
|
|
||||||
boolean first = true;
|
|
||||||
if (!paymentId.isEmpty()) {
|
|
||||||
if (first) {
|
|
||||||
sb.append("?");
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
sb.append(BarcodeData.XMR_PAYMENTID).append('=').append(paymentId);
|
|
||||||
}
|
|
||||||
if (!xmrAmount.isEmpty()) {
|
|
||||||
if (first) {
|
|
||||||
sb.append("?");
|
|
||||||
} else {
|
|
||||||
sb.append("&");
|
|
||||||
}
|
|
||||||
sb.append(BarcodeData.XMR_AMOUNT).append('=').append(xmrAmount);
|
|
||||||
}
|
|
||||||
String text = sb.toString();
|
|
||||||
int size = Math.min(qrCode.getHeight(), qrCode.getWidth());
|
int size = Math.min(qrCode.getHeight(), qrCode.getWidth());
|
||||||
Bitmap qr = generate(text, size, size);
|
Bitmap qr = generate(bcData.getUriString(), size, size);
|
||||||
if (qr != null) {
|
if (qr != null) {
|
||||||
setQR(qr);
|
setQR(qr);
|
||||||
Timber.d("SETQR");
|
Timber.d("SETQR");
|
||||||
@@ -495,6 +501,10 @@ public class ReceiveFragment extends Fragment {
|
|||||||
throw new ClassCastException(context.toString()
|
throw new ClassCastException(context.toString()
|
||||||
+ " must implement Listener");
|
+ " must implement Listener");
|
||||||
}
|
}
|
||||||
|
if (context instanceof GenerateReviewFragment.ProgressListener) {
|
||||||
|
this.progressCallback = (GenerateReviewFragment.ProgressListener) context;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -513,4 +523,51 @@ public class ReceiveFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getNewSubaddress() {
|
||||||
|
new AsyncSubaddress().executeOnExecutor(MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class AsyncSubaddress extends AsyncTask<Void, Void, Boolean> {
|
||||||
|
private String newSubaddress;
|
||||||
|
|
||||||
|
boolean dialogOpened = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
super.onPreExecute();
|
||||||
|
if (wallet.isKeyOnDevice() && (progressCallback != null)) {
|
||||||
|
progressCallback.showLedgerProgressDialog(LedgerProgressDialog.TYPE_SUBADDRESS);
|
||||||
|
dialogOpened = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(Void... params) {
|
||||||
|
if (params.length != 0) return false;
|
||||||
|
newSubaddress = wallet.getNewSubaddress();
|
||||||
|
storeWallet();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Boolean result) {
|
||||||
|
super.onPostExecute(result);
|
||||||
|
if (dialogOpened)
|
||||||
|
progressCallback.dismissProgressDialog();
|
||||||
|
tvAddress.setText(newSubaddress);
|
||||||
|
tvAddressLabel.setText(getString(R.string.generate_address_label_sub,
|
||||||
|
wallet.getNumSubaddresses() - 1));
|
||||||
|
generateQr();
|
||||||
|
enableCopyAddress(true);
|
||||||
|
final Runnable resetSize = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
tvAddress.animate().setDuration(125).scaleX(1).scaleY(1).start();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tvAddress.animate().alpha(1).setDuration(125)
|
||||||
|
.scaleX(1.2f).scaleY(1.2f)
|
||||||
|
.withEndAction(resetSize).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,13 +16,12 @@
|
|||||||
|
|
||||||
package com.m2049r.xmrwallet;
|
package com.m2049r.xmrwallet;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.util.Helper;
|
import com.m2049r.xmrwallet.util.LocaleHelper;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import static android.view.WindowManager.LayoutParams;
|
import static android.view.WindowManager.LayoutParams;
|
||||||
|
|
||||||
@@ -36,4 +35,9 @@ public abstract class SecureActivity extends AppCompatActivity {
|
|||||||
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
|
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void attachBaseContext(Context context) {
|
||||||
|
super.attachBaseContext(LocaleHelper.setLocale(context, LocaleHelper.getLocale(context)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,9 +24,9 @@ import android.content.Intent;
|
|||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.NavigationView;
|
import android.support.design.widget.NavigationView;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
@@ -51,12 +51,14 @@ import com.m2049r.xmrwallet.dialog.CreditsFragment;
|
|||||||
import com.m2049r.xmrwallet.dialog.HelpFragment;
|
import com.m2049r.xmrwallet.dialog.HelpFragment;
|
||||||
import com.m2049r.xmrwallet.fragment.send.SendAddressWizardFragment;
|
import com.m2049r.xmrwallet.fragment.send.SendAddressWizardFragment;
|
||||||
import com.m2049r.xmrwallet.fragment.send.SendFragment;
|
import com.m2049r.xmrwallet.fragment.send.SendFragment;
|
||||||
|
import com.m2049r.xmrwallet.ledger.LedgerProgressDialog;
|
||||||
import com.m2049r.xmrwallet.model.PendingTransaction;
|
import com.m2049r.xmrwallet.model.PendingTransaction;
|
||||||
import com.m2049r.xmrwallet.model.TransactionInfo;
|
import com.m2049r.xmrwallet.model.TransactionInfo;
|
||||||
import com.m2049r.xmrwallet.model.Wallet;
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
import com.m2049r.xmrwallet.service.WalletService;
|
import com.m2049r.xmrwallet.service.WalletService;
|
||||||
import com.m2049r.xmrwallet.util.Helper;
|
import com.m2049r.xmrwallet.util.Helper;
|
||||||
|
import com.m2049r.xmrwallet.util.MoneroThreadPoolExecutor;
|
||||||
import com.m2049r.xmrwallet.util.UserNotes;
|
import com.m2049r.xmrwallet.util.UserNotes;
|
||||||
import com.m2049r.xmrwallet.widget.Toolbar;
|
import com.m2049r.xmrwallet.widget.Toolbar;
|
||||||
|
|
||||||
@@ -65,7 +67,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class WalletActivity extends SecureActivity implements WalletFragment.Listener,
|
public class WalletActivity extends BaseActivity implements WalletFragment.Listener,
|
||||||
WalletService.Observer, SendFragment.Listener, TxFragment.Listener,
|
WalletService.Observer, SendFragment.Listener, TxFragment.Listener,
|
||||||
GenerateReviewFragment.ListenerWithWallet,
|
GenerateReviewFragment.ListenerWithWallet,
|
||||||
GenerateReviewFragment.Listener,
|
GenerateReviewFragment.Listener,
|
||||||
@@ -397,28 +399,6 @@ public class WalletActivity extends SecureActivity implements WalletFragment.Lis
|
|||||||
Timber.d("onResume()");
|
Timber.d("onResume()");
|
||||||
}
|
}
|
||||||
|
|
||||||
private PowerManager.WakeLock wl = null;
|
|
||||||
|
|
||||||
void acquireWakeLock() {
|
|
||||||
if ((wl != null) && wl.isHeld()) return;
|
|
||||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
||||||
this.wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, getString(R.string.app_name));
|
|
||||||
try {
|
|
||||||
wl.acquire();
|
|
||||||
Timber.d("WakeLock acquired");
|
|
||||||
} catch (SecurityException ex) {
|
|
||||||
Timber.w("WakeLock NOT acquired: %s", ex.getLocalizedMessage());
|
|
||||||
wl = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void releaseWakeLock() {
|
|
||||||
if ((wl == null) || !wl.isHeld()) return;
|
|
||||||
wl.release();
|
|
||||||
wl = null;
|
|
||||||
Timber.d("WakeLock released");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveWallet() {
|
public void saveWallet() {
|
||||||
if (mIsBound) { // no point in talking to unbound service
|
if (mIsBound) { // no point in talking to unbound service
|
||||||
Intent intent = new Intent(getApplicationContext(), WalletService.class);
|
Intent intent = new Intent(getApplicationContext(), WalletService.class);
|
||||||
@@ -503,7 +483,7 @@ public class WalletActivity extends SecureActivity implements WalletFragment.Lis
|
|||||||
getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName());
|
getSupportFragmentManager().findFragmentByTag(WalletFragment.class.getName());
|
||||||
if (wallet.isSynchronized()) {
|
if (wallet.isSynchronized()) {
|
||||||
Timber.d("onRefreshed() synced");
|
Timber.d("onRefreshed() synced");
|
||||||
releaseWakeLock(); // the idea is to stay awake until synced
|
releaseWakeLock(RELEASE_WAKE_LOCK_DELAY); // the idea is to stay awake until synced
|
||||||
if (!synced) { // first sync
|
if (!synced) { // first sync
|
||||||
onProgress(-1);
|
onProgress(-1);
|
||||||
saveWallet(); // save on first sync
|
saveWallet(); // save on first sync
|
||||||
@@ -544,10 +524,21 @@ public class WalletActivity extends SecureActivity implements WalletFragment.Lis
|
|||||||
|
|
||||||
boolean haveWallet = false;
|
boolean haveWallet = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWalletOpen(final int hardware) {
|
||||||
|
if (hardware > 0)
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
showLedgerProgressDialog(LedgerProgressDialog.TYPE_RESTORE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWalletStarted(final boolean success) {
|
public void onWalletStarted(final boolean success) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
dismissProgressDialog();
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Toast.makeText(WalletActivity.this, getString(R.string.status_wallet_connect_failed), Toast.LENGTH_LONG).show();
|
Toast.makeText(WalletActivity.this, getString(R.string.status_wallet_connect_failed), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
@@ -578,6 +569,7 @@ public class WalletActivity extends SecureActivity implements WalletFragment.Lis
|
|||||||
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
|
getSupportFragmentManager().findFragmentById(R.id.fragment_container);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
dismissProgressDialog();
|
||||||
PendingTransaction.Status status = pendingTransaction.getStatus();
|
PendingTransaction.Status status = pendingTransaction.getStatus();
|
||||||
if (status != PendingTransaction.Status.Status_Ok) {
|
if (status != PendingTransaction.Status.Status_Ok) {
|
||||||
String errorText = pendingTransaction.getErrorString();
|
String errorText = pendingTransaction.getErrorString();
|
||||||
@@ -733,6 +725,8 @@ public class WalletActivity extends SecureActivity implements WalletFragment.Lis
|
|||||||
intent.putExtra(WalletService.REQUEST_CMD_TX_TAG, tag);
|
intent.putExtra(WalletService.REQUEST_CMD_TX_TAG, tag);
|
||||||
startService(intent);
|
startService(intent);
|
||||||
Timber.d("CREATE TX request sent");
|
Timber.d("CREATE TX request sent");
|
||||||
|
if (getWallet().isKeyOnDevice())
|
||||||
|
showLedgerProgressDialog(LedgerProgressDialog.TYPE_SEND);
|
||||||
} else {
|
} else {
|
||||||
Timber.e("Service not bound");
|
Timber.e("Service not bound");
|
||||||
}
|
}
|
||||||
@@ -846,26 +840,39 @@ public class WalletActivity extends SecureActivity implements WalletFragment.Lis
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BarcodeData scannedData = null;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onScanned(String qrCode) {
|
public boolean onScanned(String qrCode) {
|
||||||
// #gurke
|
// #gurke
|
||||||
BarcodeData bcData = BarcodeData.fromQrCode(qrCode);
|
BarcodeData bcData = BarcodeData.fromQrCode(qrCode);
|
||||||
if (bcData != null) {
|
if (bcData != null) {
|
||||||
this.scannedData = bcData;
|
|
||||||
popFragmentStack(null);
|
popFragmentStack(null);
|
||||||
|
Timber.d("AAA");
|
||||||
|
onUriScanned(bcData);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OnUriScannedListener onUriScannedListener = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BarcodeData popScannedData() {
|
public void setOnUriScannedListener(OnUriScannedListener onUriScannedListener) {
|
||||||
BarcodeData data = scannedData;
|
this.onUriScannedListener = onUriScannedListener;
|
||||||
scannedData = null;
|
}
|
||||||
return data;
|
|
||||||
|
@Override
|
||||||
|
void onUriScanned(BarcodeData barcodeData) {
|
||||||
|
super.onUriScanned(barcodeData);
|
||||||
|
boolean processed = false;
|
||||||
|
if (onUriScannedListener != null) {
|
||||||
|
processed = onUriScannedListener.onUriScanned(barcodeData);
|
||||||
|
}
|
||||||
|
if (!processed || (onUriScannedListener == null)) {
|
||||||
|
Toast.makeText(this, getString(R.string.nfc_tag_read_what), Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, getString(R.string.nfc_tag_read_success), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1049,12 +1056,7 @@ public class WalletActivity extends SecureActivity implements WalletFragment.Lis
|
|||||||
final int id = item.getItemId();
|
final int id = item.getItemId();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case R.id.account_new:
|
case R.id.account_new:
|
||||||
getWallet().addAccount();
|
addAccount();
|
||||||
int newIdx = getWallet().getNumAccounts() - 1;
|
|
||||||
getWallet().setAccountIndex(newIdx);
|
|
||||||
Toast.makeText(this,
|
|
||||||
getString(R.string.accounts_new, newIdx),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Timber.d("NavigationDrawer ID=%d", id);
|
Timber.d("NavigationDrawer ID=%d", id);
|
||||||
@@ -1063,9 +1065,49 @@ public class WalletActivity extends SecureActivity implements WalletFragment.Lis
|
|||||||
Timber.d("found @%d", accountIdx);
|
Timber.d("found @%d", accountIdx);
|
||||||
getWallet().setAccountIndex(accountIdx);
|
getWallet().setAccountIndex(accountIdx);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
drawer.closeDrawer(GravityCompat.START);
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addAccount() {
|
||||||
|
new AsyncAddAccount().executeOnExecutor(MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class AsyncAddAccount extends AsyncTask<Void, Void, Boolean> {
|
||||||
|
boolean dialogOpened = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
super.onPreExecute();
|
||||||
|
if (getWallet().isKeyOnDevice()) {
|
||||||
|
showLedgerProgressDialog(LedgerProgressDialog.TYPE_ACCOUNT);
|
||||||
|
dialogOpened = true;
|
||||||
|
} else {
|
||||||
|
showProgressDialog(R.string.accounts_progress_new);
|
||||||
|
dialogOpened = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(Void... params) {
|
||||||
|
if (params.length != 0) return false;
|
||||||
|
getWallet().addAccount();
|
||||||
|
getWallet().setAccountIndex(getWallet().getNumAccounts() - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Boolean result) {
|
||||||
|
super.onPostExecute(result);
|
||||||
|
forceUpdate();
|
||||||
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
|
if (dialogOpened)
|
||||||
|
dismissProgressDialog();
|
||||||
|
Toast.makeText(WalletActivity.this,
|
||||||
|
getString(R.string.accounts_new, getWallet().getNumAccounts() - 1),
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -271,7 +271,7 @@ public class WalletFragment extends Fragment
|
|||||||
bSend.setVisibility(View.VISIBLE);
|
bSend.setVisibility(View.VISIBLE);
|
||||||
bSend.setEnabled(true);
|
bSend.setEnabled(true);
|
||||||
}
|
}
|
||||||
enableAccountsList(true);
|
if (isVisible()) enableAccountsList(true); //otherwise it is enabled in onResume()
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean walletLoaded = false;
|
boolean walletLoaded = false;
|
||||||
|
@@ -18,8 +18,10 @@ package com.m2049r.xmrwallet;
|
|||||||
|
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.util.Helper;
|
import com.m2049r.xmrwallet.util.LocaleHelper;
|
||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
@@ -32,4 +34,16 @@ public class XmrWalletApplication extends Application {
|
|||||||
Timber.plant(new Timber.DebugTree());
|
Timber.plant(new Timber.DebugTree());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void attachBaseContext(Context context) {
|
||||||
|
super.attachBaseContext(LocaleHelper.setLocale(context, LocaleHelper.getLocale(context)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfigurationChanged(Configuration configuration) {
|
||||||
|
super.onConfigurationChanged(configuration);
|
||||||
|
LocaleHelper.updateSystemDefaultLocale(configuration.locale);
|
||||||
|
LocaleHelper.setLocale(XmrWalletApplication.this, LocaleHelper.getLocale(XmrWalletApplication.this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,9 +18,7 @@ package com.m2049r.xmrwallet.data;
|
|||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.model.NetworkType;
|
|
||||||
import com.m2049r.xmrwallet.model.Wallet;
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
|
||||||
import com.m2049r.xmrwallet.util.BitcoinAddressValidator;
|
import com.m2049r.xmrwallet.util.BitcoinAddressValidator;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -45,6 +43,11 @@ public class BarcodeData {
|
|||||||
public String paymentId = null;
|
public String paymentId = null;
|
||||||
public String amount = null;
|
public String amount = null;
|
||||||
|
|
||||||
|
public BarcodeData(String uri) {
|
||||||
|
this.asset = asset;
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
public BarcodeData(Asset asset, String address) {
|
public BarcodeData(Asset asset, String address) {
|
||||||
this.asset = asset;
|
this.asset = asset;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
@@ -63,6 +66,31 @@ public class BarcodeData {
|
|||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Uri getUri() {
|
||||||
|
return Uri.parse(getUriString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUriString() {
|
||||||
|
if (asset != Asset.XMR) throw new IllegalStateException("We can only do XMR stuff!");
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(BarcodeData.XMR_SCHEME).append(address);
|
||||||
|
boolean first = true;
|
||||||
|
if ((paymentId != null) && !paymentId.isEmpty()) {
|
||||||
|
sb.append("?");
|
||||||
|
first = false;
|
||||||
|
sb.append(BarcodeData.XMR_PAYMENTID).append('=').append(paymentId);
|
||||||
|
}
|
||||||
|
if (!amount.isEmpty()) {
|
||||||
|
if (first) {
|
||||||
|
sb.append("?");
|
||||||
|
} else {
|
||||||
|
sb.append("&");
|
||||||
|
}
|
||||||
|
sb.append(BarcodeData.XMR_AMOUNT).append('=').append(amount);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
static public BarcodeData fromQrCode(String qrCode) {
|
static public BarcodeData fromQrCode(String qrCode) {
|
||||||
// check for monero uri
|
// check for monero uri
|
||||||
BarcodeData bcData = parseMoneroUri(qrCode);
|
BarcodeData bcData = parseMoneroUri(qrCode);
|
||||||
|
@@ -0,0 +1,130 @@
|
|||||||
|
package com.m2049r.xmrwallet.dialog;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007 The Android Open Source Project
|
||||||
|
* Copyright (C) 2018 m2049r
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.m2049r.xmrwallet.R;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
public class ProgressDialog extends AlertDialog {
|
||||||
|
|
||||||
|
private ProgressBar pbBar;
|
||||||
|
|
||||||
|
private TextView tvMessage;
|
||||||
|
|
||||||
|
private TextView tvProgress;
|
||||||
|
|
||||||
|
private View rlProgressBar, pbCircle;
|
||||||
|
|
||||||
|
static private final String PROGRESS_FORMAT = "%1d/%2d";
|
||||||
|
|
||||||
|
private CharSequence message;
|
||||||
|
private int maxValue, progressValue;
|
||||||
|
private boolean indeterminate = true;
|
||||||
|
|
||||||
|
public ProgressDialog(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
final View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_ledger_progress, null);
|
||||||
|
pbCircle = view.findViewById(R.id.pbCircle);
|
||||||
|
tvMessage = (TextView) view.findViewById(R.id.tvMessage);
|
||||||
|
rlProgressBar = view.findViewById(R.id.rlProgressBar);
|
||||||
|
pbBar = (ProgressBar) view.findViewById(R.id.pbBar);
|
||||||
|
tvProgress = (TextView) view.findViewById(R.id.tvProgress);
|
||||||
|
setView(view);
|
||||||
|
//setTitle("blabla");
|
||||||
|
//super.setMessage("bubbu");
|
||||||
|
// view.invalidate();
|
||||||
|
setIndeterminate(indeterminate);
|
||||||
|
if (maxValue > 0) {
|
||||||
|
setMax(maxValue);
|
||||||
|
}
|
||||||
|
if (progressValue > 0) {
|
||||||
|
setProgress(progressValue);
|
||||||
|
}
|
||||||
|
if (message != null) {
|
||||||
|
Timber.d("msg=%s", message);
|
||||||
|
setMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgress(int value, int max) {
|
||||||
|
progressValue = value;
|
||||||
|
maxValue = max;
|
||||||
|
if (pbBar != null) {
|
||||||
|
pbBar.setProgress(value);
|
||||||
|
pbBar.setMax(max);
|
||||||
|
tvProgress.setText(String.format(Locale.getDefault(), PROGRESS_FORMAT, value, maxValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgress(int value) {
|
||||||
|
progressValue = value;
|
||||||
|
if (pbBar != null) {
|
||||||
|
pbBar.setProgress(value);
|
||||||
|
tvProgress.setText(String.format(Locale.getDefault(), PROGRESS_FORMAT, value, maxValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMax(int max) {
|
||||||
|
maxValue = max;
|
||||||
|
if (pbBar != null) {
|
||||||
|
pbBar.setMax(max);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndeterminate(boolean indeterminate) {
|
||||||
|
if (this.indeterminate != indeterminate) {
|
||||||
|
if (rlProgressBar != null) {
|
||||||
|
if (indeterminate) {
|
||||||
|
pbCircle.setVisibility(View.VISIBLE);
|
||||||
|
rlProgressBar.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
pbCircle.setVisibility(View.GONE);
|
||||||
|
rlProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.indeterminate = indeterminate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMessage(CharSequence message) {
|
||||||
|
this.message = message;
|
||||||
|
if (tvMessage != null) {
|
||||||
|
tvMessage.setText(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -17,6 +17,7 @@
|
|||||||
package com.m2049r.xmrwallet.fragment.send;
|
package com.m2049r.xmrwallet.fragment.send;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.nfc.NfcManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.TextInputLayout;
|
import android.support.design.widget.TextInputLayout;
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
@@ -64,6 +65,8 @@ public class SendAddressWizardFragment extends SendWizardFragment {
|
|||||||
public interface Listener {
|
public interface Listener {
|
||||||
void setBarcodeData(BarcodeData data);
|
void setBarcodeData(BarcodeData data);
|
||||||
|
|
||||||
|
BarcodeData getBarcodeData();
|
||||||
|
|
||||||
void setMode(SendFragment.Mode mode);
|
void setMode(SendFragment.Mode mode);
|
||||||
|
|
||||||
TxData getTxData();
|
TxData getTxData();
|
||||||
@@ -83,8 +86,6 @@ public class SendAddressWizardFragment extends SendWizardFragment {
|
|||||||
|
|
||||||
public interface OnScanListener {
|
public interface OnScanListener {
|
||||||
void onScan();
|
void onScan();
|
||||||
|
|
||||||
BarcodeData popScannedData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -206,6 +207,11 @@ public class SendAddressWizardFragment extends SendWizardFragment {
|
|||||||
etDummy.requestFocus();
|
etDummy.requestFocus();
|
||||||
Helper.hideKeyboard(getActivity());
|
Helper.hideKeyboard(getActivity());
|
||||||
|
|
||||||
|
View tvNfc = view.findViewById(R.id.tvNfc);
|
||||||
|
NfcManager manager = (NfcManager) getContext().getSystemService(Context.NFC_SERVICE);
|
||||||
|
if ((manager != null) && (manager.getDefaultAdapter() != null))
|
||||||
|
tvNfc.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,11 +304,20 @@ public class SendAddressWizardFragment extends SendWizardFragment {
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
Timber.d("onResume");
|
Timber.d("onResume");
|
||||||
BarcodeData data = onScanListener.popScannedData();
|
processScannedData();
|
||||||
sendListener.setBarcodeData(data);
|
}
|
||||||
if (data != null) {
|
|
||||||
|
public void processScannedData(BarcodeData barcodeData) {
|
||||||
|
sendListener.setBarcodeData(barcodeData);
|
||||||
|
if (isResumed())
|
||||||
|
processScannedData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processScannedData() {
|
||||||
|
BarcodeData barcodeData = sendListener.getBarcodeData();
|
||||||
|
if (barcodeData != null) {
|
||||||
Timber.d("GOT DATA");
|
Timber.d("GOT DATA");
|
||||||
String scannedAddress = data.address;
|
String scannedAddress = barcodeData.address;
|
||||||
if (scannedAddress != null) {
|
if (scannedAddress != null) {
|
||||||
etAddress.getEditText().setText(scannedAddress);
|
etAddress.getEditText().setText(scannedAddress);
|
||||||
checkAddress();
|
checkAddress();
|
||||||
@@ -310,7 +325,7 @@ public class SendAddressWizardFragment extends SendWizardFragment {
|
|||||||
etAddress.getEditText().getText().clear();
|
etAddress.getEditText().getText().clear();
|
||||||
etAddress.setError(null);
|
etAddress.setError(null);
|
||||||
}
|
}
|
||||||
String scannedPaymenId = data.paymentId;
|
String scannedPaymenId = barcodeData.paymentId;
|
||||||
if (scannedPaymenId != null) {
|
if (scannedPaymenId != null) {
|
||||||
etPaymentId.getEditText().setText(scannedPaymenId);
|
etPaymentId.getEditText().setText(scannedPaymenId);
|
||||||
checkPaymentId();
|
checkPaymentId();
|
||||||
@@ -318,7 +333,8 @@ public class SendAddressWizardFragment extends SendWizardFragment {
|
|||||||
etPaymentId.getEditText().getText().clear();
|
etPaymentId.getEditText().getText().clear();
|
||||||
etPaymentId.setError(null);
|
etPaymentId.setError(null);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
Timber.d("barcodeData=null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -37,16 +37,15 @@ import android.widget.EditText;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.OnBackPressedListener;
|
import com.m2049r.xmrwallet.OnBackPressedListener;
|
||||||
|
import com.m2049r.xmrwallet.OnUriScannedListener;
|
||||||
import com.m2049r.xmrwallet.R;
|
import com.m2049r.xmrwallet.R;
|
||||||
import com.m2049r.xmrwallet.data.BarcodeData;
|
import com.m2049r.xmrwallet.data.BarcodeData;
|
||||||
import com.m2049r.xmrwallet.data.PendingTx;
|
import com.m2049r.xmrwallet.data.PendingTx;
|
||||||
import com.m2049r.xmrwallet.data.TxData;
|
import com.m2049r.xmrwallet.data.TxData;
|
||||||
import com.m2049r.xmrwallet.data.TxDataBtc;
|
import com.m2049r.xmrwallet.data.TxDataBtc;
|
||||||
import com.m2049r.xmrwallet.dialog.HelpFragment;
|
|
||||||
import com.m2049r.xmrwallet.layout.SpendViewPager;
|
import com.m2049r.xmrwallet.layout.SpendViewPager;
|
||||||
import com.m2049r.xmrwallet.model.PendingTransaction;
|
import com.m2049r.xmrwallet.model.PendingTransaction;
|
||||||
import com.m2049r.xmrwallet.util.Helper;
|
import com.m2049r.xmrwallet.util.Helper;
|
||||||
import com.m2049r.xmrwallet.util.NodeList;
|
|
||||||
import com.m2049r.xmrwallet.util.Notice;
|
import com.m2049r.xmrwallet.util.Notice;
|
||||||
import com.m2049r.xmrwallet.util.UserNotes;
|
import com.m2049r.xmrwallet.util.UserNotes;
|
||||||
import com.m2049r.xmrwallet.widget.DotBar;
|
import com.m2049r.xmrwallet.widget.DotBar;
|
||||||
@@ -62,7 +61,7 @@ public class SendFragment extends Fragment
|
|||||||
SendSettingsWizardFragment.Listener,
|
SendSettingsWizardFragment.Listener,
|
||||||
SendConfirmWizardFragment.Listener,
|
SendConfirmWizardFragment.Listener,
|
||||||
SendSuccessWizardFragment.Listener,
|
SendSuccessWizardFragment.Listener,
|
||||||
OnBackPressedListener {
|
OnBackPressedListener, OnUriScannedListener {
|
||||||
|
|
||||||
private Listener activityCallback;
|
private Listener activityCallback;
|
||||||
|
|
||||||
@@ -86,6 +85,8 @@ public class SendFragment extends Fragment
|
|||||||
void setTitle(String title);
|
void setTitle(String title);
|
||||||
|
|
||||||
void setSubtitle(String subtitle);
|
void setSubtitle(String subtitle);
|
||||||
|
|
||||||
|
void setOnUriScannedListener(OnUriScannedListener onUriScannedListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EditText etDummy;
|
private EditText etDummy;
|
||||||
@@ -99,10 +100,6 @@ public class SendFragment extends Fragment
|
|||||||
|
|
||||||
private Button bDone;
|
private Button bDone;
|
||||||
|
|
||||||
private View llXmrToEnabled;
|
|
||||||
private View ibXmrToInfoClose;
|
|
||||||
|
|
||||||
|
|
||||||
static private int MAX_FALLBACK = Integer.MAX_VALUE;
|
static private int MAX_FALLBACK = Integer.MAX_VALUE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -226,13 +223,20 @@ public class SendFragment extends Fragment
|
|||||||
Timber.d("onAttach %s", context);
|
Timber.d("onAttach %s", context);
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof Listener) {
|
if (context instanceof Listener) {
|
||||||
this.activityCallback = (Listener) context;
|
activityCallback = (Listener) context;
|
||||||
|
activityCallback.setOnUriScannedListener(this);
|
||||||
} else {
|
} else {
|
||||||
throw new ClassCastException(context.toString()
|
throw new ClassCastException(context.toString()
|
||||||
+ " must implement Listener");
|
+ " must implement Listener");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
activityCallback.setOnUriScannedListener(null);
|
||||||
|
super.onDetach();
|
||||||
|
}
|
||||||
|
|
||||||
private SpendViewPager spendViewPager;
|
private SpendViewPager spendViewPager;
|
||||||
private SpendPagerAdapter pagerAdapter;
|
private SpendPagerAdapter pagerAdapter;
|
||||||
|
|
||||||
@@ -247,6 +251,18 @@ public class SendFragment extends Fragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onUriScanned(BarcodeData barcodeData) {
|
||||||
|
if (spendViewPager.getCurrentItem() == SpendPagerAdapter.POS_ADDRESS) {
|
||||||
|
final SendWizardFragment fragment = pagerAdapter.getFragment(SpendPagerAdapter.POS_ADDRESS);
|
||||||
|
if (fragment instanceof SendAddressWizardFragment) {
|
||||||
|
((SendAddressWizardFragment) fragment).processScannedData(barcodeData);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
enum Mode {
|
enum Mode {
|
||||||
XMR, BTC
|
XMR, BTC
|
||||||
}
|
}
|
||||||
@@ -414,8 +430,14 @@ public class SendFragment extends Fragment
|
|||||||
barcodeData = data;
|
barcodeData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BarcodeData getBarcodeData() {
|
||||||
|
return barcodeData;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BarcodeData popBarcodeData() {
|
public BarcodeData popBarcodeData() {
|
||||||
|
Timber.d("POPPED");
|
||||||
BarcodeData data = barcodeData;
|
BarcodeData data = barcodeData;
|
||||||
barcodeData = null;
|
barcodeData = null;
|
||||||
return data;
|
return data;
|
||||||
|
142
app/src/main/java/com/m2049r/xmrwallet/ledger/Instruction.java
Normal file
142
app/src/main/java/com/m2049r/xmrwallet/ledger/Instruction.java
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 m2049r
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.m2049r.xmrwallet.ledger;
|
||||||
|
|
||||||
|
public enum Instruction {
|
||||||
|
INS_NONE(0x00),
|
||||||
|
INS_RESET(0x02),
|
||||||
|
INS_GET_KEY(0x20),
|
||||||
|
INS_PUT_KEY(0x22),
|
||||||
|
INS_GET_CHACHA8_PREKEY(0x24),
|
||||||
|
INS_VERIFY_KEY(0x26),
|
||||||
|
|
||||||
|
INS_SECRET_KEY_TO_PUBLIC_KEY(0x30),
|
||||||
|
INS_GEN_KEY_DERIVATION(0x32),
|
||||||
|
INS_DERIVATION_TO_SCALAR(0x34),
|
||||||
|
INS_DERIVE_PUBLIC_KEY(0x36),
|
||||||
|
INS_DERIVE_SECRET_KEY(0x38),
|
||||||
|
INS_GEN_KEY_IMAGE(0x3A),
|
||||||
|
INS_SECRET_KEY_ADD(0x3C),
|
||||||
|
INS_SECRET_KEY_SUB(0x3E),
|
||||||
|
INS_GENERATE_KEYPAIR(0x40),
|
||||||
|
INS_SECRET_SCAL_MUL_KEY(0x42),
|
||||||
|
INS_SECRET_SCAL_MUL_BASE(0x44),
|
||||||
|
|
||||||
|
INS_DERIVE_SUBADDRESS_PUBLIC_KEY(0x46),
|
||||||
|
INS_GET_SUBADDRESS(0x48),
|
||||||
|
INS_GET_SUBADDRESS_SPEND_PUBLIC_KEY(0x4A),
|
||||||
|
INS_GET_SUBADDRESS_SECRET_KEY(0x4C),
|
||||||
|
|
||||||
|
INS_OPEN_TX(0x70),
|
||||||
|
INS_SET_SIGNATURE_MODE(0x72),
|
||||||
|
INS_GET_ADDITIONAL_KEY(0x74),
|
||||||
|
INS_STEALTH(0x76),
|
||||||
|
INS_BLIND(0x78),
|
||||||
|
INS_UNBLIND(0x7A),
|
||||||
|
INS_VALIDATE(0x7C),
|
||||||
|
INS_MLSAG(0x7E),
|
||||||
|
INS_CLOSE_TX(0x80),
|
||||||
|
|
||||||
|
INS_GET_RESPONSE(0xc0),
|
||||||
|
|
||||||
|
INS_UNDEFINED(0xff);;
|
||||||
|
|
||||||
|
public static Instruction fromByte(byte n) {
|
||||||
|
switch (n & 0xFF) {
|
||||||
|
case 0x00:
|
||||||
|
return INS_NONE;
|
||||||
|
case 0x02:
|
||||||
|
return INS_RESET;
|
||||||
|
|
||||||
|
case 0x20:
|
||||||
|
return INS_GET_KEY;
|
||||||
|
case 0x22:
|
||||||
|
return INS_PUT_KEY;
|
||||||
|
case 0x24:
|
||||||
|
return INS_GET_CHACHA8_PREKEY;
|
||||||
|
case 0x26:
|
||||||
|
return INS_VERIFY_KEY;
|
||||||
|
|
||||||
|
case 0x30:
|
||||||
|
return INS_SECRET_KEY_TO_PUBLIC_KEY;
|
||||||
|
case 0x32:
|
||||||
|
return INS_GEN_KEY_DERIVATION;
|
||||||
|
case 0x34:
|
||||||
|
return INS_DERIVATION_TO_SCALAR;
|
||||||
|
case 0x36:
|
||||||
|
return INS_DERIVE_PUBLIC_KEY;
|
||||||
|
case 0x38:
|
||||||
|
return INS_DERIVE_SECRET_KEY;
|
||||||
|
case 0x3A:
|
||||||
|
return INS_GEN_KEY_IMAGE;
|
||||||
|
case 0x3C:
|
||||||
|
return INS_SECRET_KEY_ADD;
|
||||||
|
case 0x3E:
|
||||||
|
return INS_SECRET_KEY_SUB;
|
||||||
|
case 0x40:
|
||||||
|
return INS_GENERATE_KEYPAIR;
|
||||||
|
case 0x42:
|
||||||
|
return INS_SECRET_SCAL_MUL_KEY;
|
||||||
|
case 0x44:
|
||||||
|
return INS_SECRET_SCAL_MUL_BASE;
|
||||||
|
|
||||||
|
case 0x46:
|
||||||
|
return INS_DERIVE_SUBADDRESS_PUBLIC_KEY;
|
||||||
|
case 0x48:
|
||||||
|
return INS_GET_SUBADDRESS;
|
||||||
|
case 0x4A:
|
||||||
|
return INS_GET_SUBADDRESS_SPEND_PUBLIC_KEY;
|
||||||
|
case 0x4C:
|
||||||
|
return INS_GET_SUBADDRESS_SECRET_KEY;
|
||||||
|
|
||||||
|
case 0x70:
|
||||||
|
return INS_OPEN_TX;
|
||||||
|
case 0x72:
|
||||||
|
return INS_SET_SIGNATURE_MODE;
|
||||||
|
case 0x74:
|
||||||
|
return INS_GET_ADDITIONAL_KEY;
|
||||||
|
case 0x76:
|
||||||
|
return INS_STEALTH;
|
||||||
|
case 0x78:
|
||||||
|
return INS_BLIND;
|
||||||
|
case 0x7A:
|
||||||
|
return INS_UNBLIND;
|
||||||
|
case 0x7C:
|
||||||
|
return INS_VALIDATE;
|
||||||
|
case 0x7E:
|
||||||
|
return INS_MLSAG;
|
||||||
|
case 0x80:
|
||||||
|
return INS_CLOSE_TX;
|
||||||
|
|
||||||
|
case 0xc0:
|
||||||
|
return INS_GET_RESPONSE;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return INS_UNDEFINED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
Instruction(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
272
app/src/main/java/com/m2049r/xmrwallet/ledger/Ledger.java
Normal file
272
app/src/main/java/com/m2049r/xmrwallet/ledger/Ledger.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,162 @@
|
|||||||
|
package com.m2049r.xmrwallet.ledger;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
|
import com.m2049r.xmrwallet.R;
|
||||||
|
import com.m2049r.xmrwallet.dialog.ProgressDialog;
|
||||||
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
|
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
public class LedgerProgressDialog extends ProgressDialog implements Ledger.Listener {
|
||||||
|
|
||||||
|
static public final int TYPE_DEBUG = 0;
|
||||||
|
static public final int TYPE_RESTORE = 1;
|
||||||
|
static public final int TYPE_SUBADDRESS = 2;
|
||||||
|
static public final int TYPE_ACCOUNT = 3;
|
||||||
|
static public final int TYPE_SEND = 4;
|
||||||
|
|
||||||
|
private final int type;
|
||||||
|
private Handler uiHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
public LedgerProgressDialog(Context context, int type) {
|
||||||
|
super(context);
|
||||||
|
this.type = type;
|
||||||
|
setCancelable(false);
|
||||||
|
if (type == TYPE_SEND)
|
||||||
|
setMessage(context.getString(R.string.info_prepare_tx));
|
||||||
|
else
|
||||||
|
setMessage(context.getString(R.string.progress_ledger_progress));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
// prevent back button
|
||||||
|
}
|
||||||
|
|
||||||
|
private int firstSubaddress = Integer.MAX_VALUE;
|
||||||
|
|
||||||
|
private boolean validate = false;
|
||||||
|
private boolean validated = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInstructionSend(final Instruction ins, final byte[] apdu) {
|
||||||
|
Timber.d("LedgerProgressDialog SEND %s", ins);
|
||||||
|
uiHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (type > TYPE_DEBUG) {
|
||||||
|
validate = false;
|
||||||
|
switch (ins) {
|
||||||
|
case INS_RESET: // ledger may ask for confirmation - maybe a bug?
|
||||||
|
case INS_GET_KEY: // ledger asks for confirmation to send keys
|
||||||
|
setIndeterminate(true);
|
||||||
|
setMessage(getContext().getString(R.string.progress_ledger_confirm));
|
||||||
|
break;
|
||||||
|
case INS_GET_SUBADDRESS_SPEND_PUBLIC_KEY: // lookahead
|
||||||
|
//00 4a 00 00 09 00 01000000 30000000
|
||||||
|
// 0 1 2 3 4 5 6 7 8 9 a b c d
|
||||||
|
int account = bytesToInteger(apdu, 6);
|
||||||
|
int subaddress = bytesToInteger(apdu, 10);
|
||||||
|
Timber.d("fetching subaddress (%d, %d)", account, subaddress);
|
||||||
|
switch (type) {
|
||||||
|
case TYPE_RESTORE:
|
||||||
|
setProgress(account * Ledger.LOOKAHEAD_SUBADDRESSES + subaddress + 1,
|
||||||
|
Ledger.LOOKAHEAD_ACCOUNTS * Ledger.LOOKAHEAD_SUBADDRESSES);
|
||||||
|
setIndeterminate(false);
|
||||||
|
break;
|
||||||
|
case TYPE_ACCOUNT:
|
||||||
|
final int requestedSubaddress = account * Ledger.LOOKAHEAD_SUBADDRESSES + subaddress;
|
||||||
|
if (firstSubaddress > requestedSubaddress) {
|
||||||
|
firstSubaddress = requestedSubaddress;
|
||||||
|
}
|
||||||
|
setProgress(requestedSubaddress - firstSubaddress + 1,
|
||||||
|
Ledger.LOOKAHEAD_ACCOUNTS * Ledger.LOOKAHEAD_SUBADDRESSES);
|
||||||
|
setIndeterminate(false);
|
||||||
|
break;
|
||||||
|
case TYPE_SUBADDRESS:
|
||||||
|
if (firstSubaddress > subaddress) {
|
||||||
|
firstSubaddress = subaddress;
|
||||||
|
}
|
||||||
|
setProgress(subaddress - firstSubaddress + 1, Ledger.LOOKAHEAD_SUBADDRESSES);
|
||||||
|
setIndeterminate(false);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
setIndeterminate(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
setMessage(getContext().getString(R.string.progress_ledger_lookahead));
|
||||||
|
break;
|
||||||
|
case INS_VERIFY_KEY:
|
||||||
|
setIndeterminate(true);
|
||||||
|
setMessage(getContext().getString(R.string.progress_ledger_verify));
|
||||||
|
break;
|
||||||
|
case INS_OPEN_TX:
|
||||||
|
setIndeterminate(true);
|
||||||
|
setMessage(getContext().getString(R.string.progress_ledger_opentx));
|
||||||
|
break;
|
||||||
|
case INS_MLSAG:
|
||||||
|
if (validated) {
|
||||||
|
setIndeterminate(true);
|
||||||
|
setMessage(getContext().getString(R.string.progress_ledger_mlsag));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case INS_VALIDATE:
|
||||||
|
if ((apdu[2] != 1) || (apdu[3] != 1)) break;
|
||||||
|
validate = true;
|
||||||
|
uiHandler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (validate) {
|
||||||
|
setIndeterminate(true);
|
||||||
|
setMessage(getContext().getString(R.string.progress_ledger_confirm));
|
||||||
|
validated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 250);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// ignore others and maintain state
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setMessage(ins.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInstructionReceive(final Instruction ins, final byte[] data) {
|
||||||
|
Timber.d("LedgerProgressDialog RECV %s", ins);
|
||||||
|
uiHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (type > TYPE_DEBUG) {
|
||||||
|
switch (ins) {
|
||||||
|
case INS_GET_SUBADDRESS_SPEND_PUBLIC_KEY: // lookahead
|
||||||
|
case INS_VERIFY_KEY:
|
||||||
|
case INS_GET_CHACHA8_PREKEY:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (type != TYPE_SEND)
|
||||||
|
setMessage(getContext().getString(R.string.progress_ledger_progress));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setMessage("Returned from " + ins.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: we use ints in Java but the are signed; accounts & subaddresses are unsigned ...
|
||||||
|
private int bytesToInteger(byte[] bytes, int offset) {
|
||||||
|
int result = 0;
|
||||||
|
for (int i = 3; i >= 0; i--) {
|
||||||
|
result <<= 8;
|
||||||
|
result |= (bytes[offset + i] & 0xFF);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@@ -150,6 +150,9 @@ public class Wallet {
|
|||||||
|
|
||||||
// virtual bool createWatchOnly(const std::string &path, const std::string &password, const std::string &language) const = 0;
|
// virtual bool createWatchOnly(const std::string &path, const std::string &password, const std::string &language) const = 0;
|
||||||
// virtual void setRefreshFromBlockHeight(uint64_t refresh_from_block_height) = 0;
|
// virtual void setRefreshFromBlockHeight(uint64_t refresh_from_block_height) = 0;
|
||||||
|
|
||||||
|
public native long getRestoreHeight();
|
||||||
|
|
||||||
// virtual void setRecoveringFromSeed(bool recoveringFromSeed) = 0;
|
// virtual void setRecoveringFromSeed(bool recoveringFromSeed) = 0;
|
||||||
// virtual bool connectToDaemon() = 0;
|
// virtual bool connectToDaemon() = 0;
|
||||||
|
|
||||||
@@ -389,4 +392,5 @@ public class Wallet {
|
|||||||
return getSubaddress(accountIndex, getNumSubaddresses(accountIndex) - 1);
|
return getSubaddress(accountIndex, getNumSubaddresses(accountIndex) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public native boolean isKeyOnDevice();
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.m2049r.xmrwallet.model;
|
package com.m2049r.xmrwallet.model;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.data.WalletNode;
|
import com.m2049r.xmrwallet.data.WalletNode;
|
||||||
|
import com.m2049r.xmrwallet.ledger.Ledger;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -129,6 +130,23 @@ public class WalletManager {
|
|||||||
String viewKeyString,
|
String viewKeyString,
|
||||||
String spendKeyString);
|
String spendKeyString);
|
||||||
|
|
||||||
|
public Wallet createWalletFromDevice(File aFile, String password, long restoreHeight,
|
||||||
|
String deviceName) {
|
||||||
|
long walletHandle = createWalletFromDeviceJ(aFile.getAbsolutePath(), password,
|
||||||
|
getNetworkType().getValue(), deviceName, restoreHeight,
|
||||||
|
Ledger.SUBADDRESS_LOOKAHEAD);
|
||||||
|
Wallet wallet = new Wallet(walletHandle);
|
||||||
|
manageWallet(wallet);
|
||||||
|
return wallet;
|
||||||
|
}
|
||||||
|
|
||||||
|
private native long createWalletFromDeviceJ(String path, String password,
|
||||||
|
int networkType,
|
||||||
|
String deviceName,
|
||||||
|
long restoreHeight,
|
||||||
|
String subaddressLookahead);
|
||||||
|
|
||||||
|
|
||||||
public native boolean closeJ(Wallet wallet);
|
public native boolean closeJ(Wallet wallet);
|
||||||
|
|
||||||
public boolean close(Wallet wallet) {
|
public boolean close(Wallet wallet) {
|
||||||
@@ -150,6 +168,12 @@ public class WalletManager {
|
|||||||
|
|
||||||
public native boolean verifyWalletPassword(String keys_file_name, String password, boolean watch_only);
|
public native boolean verifyWalletPassword(String keys_file_name, String password, boolean watch_only);
|
||||||
|
|
||||||
|
public boolean verifyWalletPasswordOnly(String keys_file_name, String password) {
|
||||||
|
return queryWalletHardware(keys_file_name, password) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public native int queryWalletHardware(String keys_file_name, String password);
|
||||||
|
|
||||||
//public native List<String> findWallets(String path); // this does not work - some error in boost
|
//public native List<String> findWallets(String path); // this does not work - some error in boost
|
||||||
|
|
||||||
public class WalletInfo implements Comparable<WalletInfo> {
|
public class WalletInfo implements Comparable<WalletInfo> {
|
||||||
|
@@ -19,6 +19,7 @@ package com.m2049r.xmrwallet.service;
|
|||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -36,6 +37,7 @@ import com.m2049r.xmrwallet.model.Wallet;
|
|||||||
import com.m2049r.xmrwallet.model.WalletListener;
|
import com.m2049r.xmrwallet.model.WalletListener;
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
import com.m2049r.xmrwallet.util.Helper;
|
import com.m2049r.xmrwallet.util.Helper;
|
||||||
|
import com.m2049r.xmrwallet.util.LocaleHelper;
|
||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
@@ -219,6 +221,8 @@ public class WalletService extends Service {
|
|||||||
void onSetNotes(boolean success);
|
void onSetNotes(boolean success);
|
||||||
|
|
||||||
void onWalletStarted(boolean success);
|
void onWalletStarted(boolean success);
|
||||||
|
|
||||||
|
void onWalletOpen(int hardware);
|
||||||
}
|
}
|
||||||
|
|
||||||
String progressText = null;
|
String progressText = null;
|
||||||
@@ -418,6 +422,11 @@ public class WalletService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void attachBaseContext(Context context) {
|
||||||
|
super.attachBaseContext(LocaleHelper.setLocale(context, LocaleHelper.getLocale(context)));
|
||||||
|
}
|
||||||
|
|
||||||
public class WalletServiceBinder extends Binder {
|
public class WalletServiceBinder extends Binder {
|
||||||
public WalletService getService() {
|
public WalletService getService() {
|
||||||
return WalletService.this;
|
return WalletService.this;
|
||||||
@@ -528,6 +537,8 @@ public class WalletService extends Service {
|
|||||||
showProgress(30);
|
showProgress(30);
|
||||||
if (walletMgr.walletExists(path)) {
|
if (walletMgr.walletExists(path)) {
|
||||||
Timber.d("open wallet %s", path);
|
Timber.d("open wallet %s", path);
|
||||||
|
int hw = WalletManager.getInstance().queryWalletHardware(path + ".keys", walletPassword);
|
||||||
|
if (observer != null) observer.onWalletOpen(hw);
|
||||||
wallet = walletMgr.openWallet(path, walletPassword);
|
wallet = walletMgr.openWallet(path, walletPassword);
|
||||||
showProgress(60);
|
showProgress(60);
|
||||||
Timber.d("wallet opened");
|
Timber.d("wallet opened");
|
||||||
|
@@ -349,33 +349,33 @@ public class Helper {
|
|||||||
String walletPath = new File(getWalletRoot(context), walletName + ".keys").getAbsolutePath();
|
String walletPath = new File(getWalletRoot(context), walletName + ".keys").getAbsolutePath();
|
||||||
|
|
||||||
// try with entered password (which could be a legacy password or a CrAzYpass)
|
// try with entered password (which could be a legacy password or a CrAzYpass)
|
||||||
if (WalletManager.getInstance().verifyWalletPassword(walletPath, password, true)) {
|
if (WalletManager.getInstance().verifyWalletPasswordOnly(walletPath, password)) {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe this is a malformed CrAzYpass?
|
// maybe this is a malformed CrAzYpass?
|
||||||
String possibleCrazyPass = CrazyPassEncoder.reformat(password);
|
String possibleCrazyPass = CrazyPassEncoder.reformat(password);
|
||||||
if (possibleCrazyPass != null) { // looks like a CrAzYpass
|
if (possibleCrazyPass != null) { // looks like a CrAzYpass
|
||||||
if (WalletManager.getInstance().verifyWalletPassword(walletPath, possibleCrazyPass, true)) {
|
if (WalletManager.getInstance().verifyWalletPasswordOnly(walletPath, possibleCrazyPass)) {
|
||||||
return possibleCrazyPass;
|
return possibleCrazyPass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate & try with CrAzYpass
|
// generate & try with CrAzYpass
|
||||||
String crazyPass = KeyStoreHelper.getCrazyPass(context, password);
|
String crazyPass = KeyStoreHelper.getCrazyPass(context, password);
|
||||||
if (WalletManager.getInstance().verifyWalletPassword(walletPath, crazyPass, true)) {
|
if (WalletManager.getInstance().verifyWalletPasswordOnly(walletPath, crazyPass)) {
|
||||||
return crazyPass;
|
return crazyPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
// or maybe it is a broken CrAzYpass? (of which we have two variants)
|
// or maybe it is a broken CrAzYpass? (of which we have two variants)
|
||||||
String brokenCrazyPass2 = KeyStoreHelper.getBrokenCrazyPass(context, password, 2);
|
String brokenCrazyPass2 = KeyStoreHelper.getBrokenCrazyPass(context, password, 2);
|
||||||
if ((brokenCrazyPass2 != null)
|
if ((brokenCrazyPass2 != null)
|
||||||
&& WalletManager.getInstance().verifyWalletPassword(walletPath, brokenCrazyPass2, true)) {
|
&& WalletManager.getInstance().verifyWalletPasswordOnly(walletPath, brokenCrazyPass2)) {
|
||||||
return brokenCrazyPass2;
|
return brokenCrazyPass2;
|
||||||
}
|
}
|
||||||
String brokenCrazyPass1 = KeyStoreHelper.getBrokenCrazyPass(context, password, 1);
|
String brokenCrazyPass1 = KeyStoreHelper.getBrokenCrazyPass(context, password, 1);
|
||||||
if ((brokenCrazyPass1 != null)
|
if ((brokenCrazyPass1 != null)
|
||||||
&& WalletManager.getInstance().verifyWalletPassword(walletPath, brokenCrazyPass1, true)) {
|
&& WalletManager.getInstance().verifyWalletPasswordOnly(walletPath, brokenCrazyPass1)) {
|
||||||
return brokenCrazyPass1;
|
return brokenCrazyPass1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,6 +407,7 @@ public class Helper {
|
|||||||
final CancellationSignal cancelSignal = new CancellationSignal();
|
final CancellationSignal cancelSignal = new CancellationSignal();
|
||||||
|
|
||||||
final AtomicBoolean incorrectSavedPass = new AtomicBoolean(false);
|
final AtomicBoolean incorrectSavedPass = new AtomicBoolean(false);
|
||||||
|
|
||||||
class LoginWalletTask extends AsyncTask<Void, Void, Boolean> {
|
class LoginWalletTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
private String pass;
|
private String pass;
|
||||||
private boolean fingerprintUsed;
|
private boolean fingerprintUsed;
|
||||||
@@ -508,6 +509,12 @@ public class Helper {
|
|||||||
tvOpenPrompt.setText(errString);
|
tvOpenPrompt.setText(errString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
|
||||||
|
tvOpenPrompt.setCompoundDrawablesRelativeWithIntrinsicBounds(icError, null, null, null);
|
||||||
|
tvOpenPrompt.setText(helpString);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
|
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
|
||||||
try {
|
try {
|
||||||
@@ -588,6 +595,5 @@ public class Helper {
|
|||||||
|
|
||||||
static public ExchangeApi getExchangeApi() {
|
static public ExchangeApi getExchangeApi() {
|
||||||
return new com.m2049r.xmrwallet.service.exchange.coinmarketcap.ExchangeApiImpl(OkHttpClientSingleton.getOkHttpClient());
|
return new com.m2049r.xmrwallet.service.exchange.coinmarketcap.ExchangeApiImpl(OkHttpClientSingleton.getOkHttpClient());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,81 @@
|
|||||||
|
package com.m2049r.xmrwallet.util;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import com.m2049r.xmrwallet.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class LocaleHelper {
|
||||||
|
private static final String PREFERRED_LOCALE_KEY = "preferred_locale";
|
||||||
|
private static Locale SYSTEM_DEFAULT_LOCALE = Locale.getDefault();
|
||||||
|
|
||||||
|
public static ArrayList<Locale> getAvailableLocales(Context context) {
|
||||||
|
ArrayList<Locale> locales = new ArrayList<>();
|
||||||
|
String[] availableLocales = context.getString(R.string.available_locales).split(",");
|
||||||
|
|
||||||
|
for (String localeName : availableLocales) {
|
||||||
|
locales.add(Locale.forLanguageTag(localeName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return locales;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDisplayName(Locale locale, boolean sentenceCase) {
|
||||||
|
String displayName = locale.getDisplayName(locale);
|
||||||
|
|
||||||
|
if (sentenceCase) {
|
||||||
|
displayName = toSentenceCase(displayName, locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getLocale(Context context) {
|
||||||
|
return getPreferredLocale(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Context setLocale(Context context, String locale) {
|
||||||
|
setPreferredLocale(context, locale);
|
||||||
|
|
||||||
|
Locale newLocale = (locale.isEmpty()) ? SYSTEM_DEFAULT_LOCALE : Locale.forLanguageTag(locale);
|
||||||
|
Configuration configuration = context.getResources().getConfiguration();
|
||||||
|
|
||||||
|
Locale.setDefault(newLocale);
|
||||||
|
|
||||||
|
configuration.setLocale(newLocale);
|
||||||
|
configuration.setLayoutDirection(newLocale);
|
||||||
|
|
||||||
|
return context.createConfigurationContext(configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateSystemDefaultLocale(Locale locale) {
|
||||||
|
SYSTEM_DEFAULT_LOCALE = locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String toSentenceCase(String str, Locale locale) {
|
||||||
|
if (str.isEmpty()) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
int firstCodePointLen = str.offsetByCodePoints(0, 1);
|
||||||
|
return str.substring(0, firstCodePointLen).toUpperCase(locale)
|
||||||
|
+ str.substring(firstCodePointLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getPreferredLocale(Context context) {
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.getString(PREFERRED_LOCALE_KEY, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ApplySharedPref")
|
||||||
|
private static void setPreferredLocale(Context context, String locale) {
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
||||||
|
.putString(PREFERRED_LOCALE_KEY, locale).commit();
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user