mirror of
https://github.com/wownero/wownerujo.git
synced 2026-11-13 03:33:57 +01:00
new api & queryWalletDevice
This commit is contained in:
@@ -416,17 +416,20 @@ Java_com_m2049r_xmrwallet_model_WalletManager_verifyWalletPassword(JNIEnv *env,
|
||||
|
||||
//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) {
|
||||
Java_com_m2049r_xmrwallet_model_WalletManager_queryWalletDeviceJ(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));
|
||||
Bitmonero::Wallet::Device device_type;
|
||||
bool ok = Bitmonero::WalletManagerFactory::getWalletManager()->
|
||||
queryWalletDevice(device_type, 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);
|
||||
if (ok)
|
||||
return static_cast<jint>(device_type);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
|
||||
@@ -200,7 +200,8 @@ public class GenerateReviewFragment extends Fragment {
|
||||
super.onPreExecute();
|
||||
showProgress();
|
||||
if ((walletPath != null)
|
||||
&& (WalletManager.getInstance().queryWalletHardware(walletPath + ".keys", getPassword()) == 1)
|
||||
&& (WalletManager.getInstance().queryWalletDevice(walletPath + ".keys", getPassword())
|
||||
== Wallet.Device.Device_Ledger)
|
||||
&& (progressCallback != null)) {
|
||||
progressCallback.showLedgerProgressDialog(LedgerProgressDialog.TYPE_RESTORE);
|
||||
dialogOpened = true;
|
||||
|
||||
@@ -1171,18 +1171,25 @@ public class LoginActivity extends BaseActivity
|
||||
String keyPath = new File(Helper.getWalletRoot(LoginActivity.this),
|
||||
walletName + ".keys").getAbsolutePath();
|
||||
// check if we need connected hardware
|
||||
int hw = WalletManager.getInstance().queryWalletHardware(keyPath, password);
|
||||
if ((hw == 1) && (!hasLedger())) {
|
||||
toast(R.string.open_wallet_ledger_missing);
|
||||
} else {
|
||||
// hw could be < 0 meaning the password is wrong - this gets dealt with later
|
||||
startWallet(walletName, password, fingerprintUsed);
|
||||
Wallet.Device device =
|
||||
WalletManager.getInstance().queryWalletDevice(keyPath, password);
|
||||
switch (device) {
|
||||
case Device_Ledger:
|
||||
if (!hasLedger()) {
|
||||
toast(R.string.open_wallet_ledger_missing);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// device could be undefined meaning the password is wrong
|
||||
// this gets dealt with later
|
||||
startWallet(walletName, password, fingerprintUsed);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else { // this cannot really happen as we prefilter choices
|
||||
Toast.makeText(this, getString(R.string.bad_wallet), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// USB Stuff - (Ledger)
|
||||
|
||||
@@ -320,7 +320,8 @@ public class ReceiveFragment extends Fragment {
|
||||
super.onPreExecute();
|
||||
showProgress();
|
||||
if ((walletPath != null)
|
||||
&& (WalletManager.getInstance().queryWalletHardware(walletPath + ".keys", password) == 1)
|
||||
&& (WalletManager.getInstance().queryWalletDevice(walletPath + ".keys", password)
|
||||
== Wallet.Device.Device_Ledger)
|
||||
&& (progressCallback != null)) {
|
||||
progressCallback.showLedgerProgressDialog(LedgerProgressDialog.TYPE_RESTORE);
|
||||
dialogOpened = true;
|
||||
|
||||
@@ -516,13 +516,15 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
||||
boolean haveWallet = false;
|
||||
|
||||
@Override
|
||||
public void onWalletOpen(final int hardware) {
|
||||
if (hardware > 0)
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
showLedgerProgressDialog(LedgerProgressDialog.TYPE_RESTORE);
|
||||
}
|
||||
});
|
||||
public void onWalletOpen(final Wallet.Device device) {
|
||||
switch (device) {
|
||||
case Device_Ledger:
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
showLedgerProgressDialog(LedgerProgressDialog.TYPE_RESTORE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -60,6 +60,12 @@ public class Wallet {
|
||||
this.accountIndex = accountIndex;
|
||||
}
|
||||
|
||||
public enum Device {
|
||||
Device_Undefined,
|
||||
Device_Software,
|
||||
Device_Ledger
|
||||
};
|
||||
|
||||
public enum Status {
|
||||
Status_Ok,
|
||||
Status_Error,
|
||||
|
||||
@@ -178,10 +178,15 @@ public class WalletManager {
|
||||
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;
|
||||
return queryWalletDevice(keys_file_name, password) != Wallet.Device.Device_Undefined;
|
||||
}
|
||||
|
||||
public native int queryWalletHardware(String keys_file_name, String password);
|
||||
public Wallet.Device queryWalletDevice(String keys_file_name, String password) {
|
||||
int device = queryWalletDeviceJ(keys_file_name, password);
|
||||
return Wallet.Device.values()[device + 1]; // mapping is monero+1=android
|
||||
}
|
||||
|
||||
private native int queryWalletDeviceJ(String keys_file_name, String password);
|
||||
|
||||
//public native List<String> findWallets(String path); // this does not work - some error in boost
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ public class WalletService extends Service {
|
||||
|
||||
void onWalletStarted(boolean success);
|
||||
|
||||
void onWalletOpen(int hardware);
|
||||
void onWalletOpen(Wallet.Device device);
|
||||
}
|
||||
|
||||
String progressText = null;
|
||||
@@ -550,8 +550,8 @@ public class WalletService extends Service {
|
||||
showProgress(30);
|
||||
if (walletMgr.walletExists(path)) {
|
||||
Timber.d("open wallet %s", path);
|
||||
int hw = WalletManager.getInstance().queryWalletHardware(path + ".keys", walletPassword);
|
||||
if (observer != null) observer.onWalletOpen(hw);
|
||||
Wallet.Device device = WalletManager.getInstance().queryWalletDevice(path + ".keys", walletPassword);
|
||||
if (observer != null) observer.onWalletOpen(device);
|
||||
wallet = walletMgr.openWallet(path, walletPassword);
|
||||
showProgress(60);
|
||||
Timber.d("wallet opened");
|
||||
|
||||
Reference in New Issue
Block a user