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"
minSdkVersion 21
targetSdkVersion 25
versionCode 47
versionName "1.2.7-alpha"
versionCode 48
versionName "1.2.8-alpha"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {

View File

@ -799,20 +799,26 @@ public class LoginActivity extends SecureActivity
@Override
protected Boolean doInBackground(Void... params) {
File newWalletFolder = getStorageRoot();
if (!newWalletFolder.isDirectory()) {
Timber.e("Wallet dir " + newWalletFolder.getAbsolutePath() + "is not a directory");
// check if the wallet we want to create already exists
File walletFolder = getStorageRoot();
if (!walletFolder.isDirectory()) {
Timber.e("Wallet dir " + walletFolder.getAbsolutePath() + "is not a directory");
return false;
}
File cacheFile = new File(newWalletFolder, walletName);
File keysFile = new File(newWalletFolder, walletName + ".keys");
File addressFile = new File(newWalletFolder, walletName + ".address.txt");
File cacheFile = new File(walletFolder, walletName);
File keysFile = new File(walletFolder, walletName + ".keys");
File addressFile = new File(walletFolder, walletName + ".address.txt");
if (cacheFile.exists() || keysFile.exists() || addressFile.exists()) {
Timber.e("Some wallet files already exist for %s", cacheFile.getAbsolutePath());
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);
boolean success = walletCreator.createWallet(newWalletFile, walletPassword);
if (success) {
@ -930,10 +936,17 @@ public class LoginActivity extends SecureActivity
@Override
public void onAccept(final String name, final String password) {
File walletFolder = getStorageRoot();
File walletFile = new File(walletFolder, name);
walletFile.delete(); // when recovering wallets, the cache seems corrupt
File newWalletFile = new File(Helper.getNewWalletDir(getApplicationContext()), name);
Timber.d("New Wallet %s", newWalletFile.getAbsolutePath());
newWalletFile.delete(); // when recovering wallets, the cache seems corrupt
// 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;
if (rc) {

View File

@ -56,6 +56,17 @@ public class Helper {
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) {
if (!isExternalStorageWritable()) {
String msg = context.getString(R.string.message_strorage_not_writable);