Create new wallets in app-private storage (#151)

* new version

* create new wallet in app-private storage
This commit is contained in:
m2049r 2017-12-07 19:55:01 +01:00 committed by GitHub
parent 51876f788f
commit ac78ecb298
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 11 deletions

View File

@ -8,8 +8,8 @@ android {
applicationId "com.m2049r.xmrwallet" applicationId "com.m2049r.xmrwallet"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 25 targetSdkVersion 25
versionCode 47 versionCode 48
versionName "1.2.7-alpha" versionName "1.2.8-alpha"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild { externalNativeBuild {
cmake { cmake {

View File

@ -799,20 +799,26 @@ public class LoginActivity extends SecureActivity
@Override @Override
protected Boolean doInBackground(Void... params) { protected Boolean doInBackground(Void... params) {
File newWalletFolder = getStorageRoot(); // check if the wallet we want to create already exists
if (!newWalletFolder.isDirectory()) { File walletFolder = getStorageRoot();
Timber.e("Wallet dir " + newWalletFolder.getAbsolutePath() + "is not a directory"); if (!walletFolder.isDirectory()) {
Timber.e("Wallet dir " + walletFolder.getAbsolutePath() + "is not a directory");
return false; return false;
} }
File cacheFile = new File(newWalletFolder, walletName); File cacheFile = new File(walletFolder, walletName);
File keysFile = new File(newWalletFolder, walletName + ".keys"); File keysFile = new File(walletFolder, walletName + ".keys");
File addressFile = new File(newWalletFolder, walletName + ".address.txt"); File addressFile = new File(walletFolder, walletName + ".address.txt");
if (cacheFile.exists() || keysFile.exists() || addressFile.exists()) { if (cacheFile.exists() || keysFile.exists() || addressFile.exists()) {
Timber.e("Some wallet files already exist for %s", cacheFile.getAbsolutePath()); Timber.e("Some wallet files already exist for %s", cacheFile.getAbsolutePath());
return false; return false;
} }
File newWalletFolder = Helper.getNewWalletDir(getApplicationContext());
if (!newWalletFolder.isDirectory()) {
Timber.e("New Wallet dir " + newWalletFolder.getAbsolutePath() + "is not a directory");
return false;
}
newWalletFile = new File(newWalletFolder, walletName); newWalletFile = new File(newWalletFolder, walletName);
boolean success = walletCreator.createWallet(newWalletFile, walletPassword); boolean success = walletCreator.createWallet(newWalletFile, walletPassword);
if (success) { if (success) {
@ -930,10 +936,17 @@ public class LoginActivity extends SecureActivity
@Override @Override
public void onAccept(final String name, final String password) { public void onAccept(final String name, final String password) {
File walletFolder = getStorageRoot(); File newWalletFile = new File(Helper.getNewWalletDir(getApplicationContext()), name);
File walletFile = new File(walletFolder, name); Timber.d("New Wallet %s", newWalletFile.getAbsolutePath());
walletFile.delete(); // when recovering wallets, the cache seems corrupt newWalletFile.delete(); // when recovering wallets, the cache seems corrupt
// TODO: figure out why this is so? Only for a private testnet? // TODO: figure out why this is so? Only for a private testnet?
// now copy the new wallet to the wallet folder
File walletFile = new File(getStorageRoot(), name);
Timber.d("Wallet %s", walletFile.getAbsolutePath());
copyWallet(newWalletFile, walletFile, false, true);
deleteWallet(newWalletFile); // delete it no matter what (can't recover from this anyway)
boolean rc = testWallet(walletFile.getAbsolutePath(), password) == Wallet.Status.Status_Ok; boolean rc = testWallet(walletFile.getAbsolutePath(), password) == Wallet.Status.Status_Ok;
if (rc) { if (rc) {

View File

@ -56,6 +56,17 @@ public class Helper {
static public int DISPLAY_DIGITS_INFO = 5; static public int DISPLAY_DIGITS_INFO = 5;
static public File getNewWalletDir(Context context) {
File newWalletDir = context.getDir("new", Context.MODE_PRIVATE);
Timber.d("new wallet directory is %s", newWalletDir.getAbsolutePath());
if (!newWalletDir.exists() || !newWalletDir.isDirectory()) {
String msg = newWalletDir.getAbsolutePath() + " is not a directory!";
Timber.e(msg);
throw new IllegalStateException(msg);
}
return newWalletDir;
}
static public File getStorageRoot(Context context) { static public File getStorageRoot(Context context) {
if (!isExternalStorageWritable()) { if (!isExternalStorageWritable()) {
String msg = context.getString(R.string.message_strorage_not_writable); String msg = context.getString(R.string.message_strorage_not_writable);