Handle new Google drive style content URLs

This commit is contained in:
Brian Pellin
2016-03-03 22:03:22 -06:00
parent e68f3d1984
commit e1f3d31ce7
21 changed files with 209 additions and 133 deletions

View File

@@ -1,5 +1,6 @@
* Add .kdbx Twofish support from drizzt
* Improve password generator randomness
* Handle new Google Drive style links (closes: #74)
KeePassDroid (2.0.4)
* Fix notification icons (closes: #60)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -23,6 +23,7 @@ import java.io.InputStream;
import android.content.Context;
import android.content.res.AssetManager;
import android.net.Uri;
import com.keepassdroid.Database;
import com.keepassdroid.database.PwDatabaseV3Debug;
@@ -54,7 +55,9 @@ public class TestData {
Database Db = new Database();
Db.LoadData(ctx, is, password, keyfile, Importer.DEBUG);
Db.mFilename = filename;
Uri.Builder b = new Uri.Builder();
Db.mUri = b.scheme("file").path(filename).build();
return Db;

View File

@@ -58,6 +58,12 @@
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.kdbx" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.kdbx" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/octet-stream" />
</intent-filter>
</activity>
<activity android:name="com.keepassdroid.GroupActivityV3" android:configChanges="orientation|keyboardHidden"
android:theme="@style/NoTitleBar">

View File

@@ -26,11 +26,13 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.SyncFailedException;
import java.util.HashSet;
import java.util.Set;
import android.content.Context;
import android.net.Uri;
import com.keepassdroid.database.PwDatabase;
import com.keepassdroid.database.PwDatabaseV3;
@@ -49,7 +51,7 @@ import com.keepassdroid.search.SearchDbHelper;
public class Database {
public Set<PwGroup> dirty = new HashSet<PwGroup>();
public PwDatabase pm;
public String mFilename;
public Uri mUri;
public SearchDbHelper searchHelper;
public boolean readOnly = false;
public boolean passwordEncodingError = false;
@@ -70,22 +72,25 @@ public class Database {
LoadData(ctx, is, password, keyfile, new UpdateStatus(), !Importer.DEBUG);
}
public void LoadData(Context ctx, String filename, String password, String keyfile) throws IOException, FileNotFoundException, InvalidDBException {
LoadData(ctx, filename, password, keyfile, new UpdateStatus(), !Importer.DEBUG);
public void LoadData(Context ctx, Uri uri, String password, String keyfile) throws IOException, FileNotFoundException, InvalidDBException {
LoadData(ctx, uri, password, keyfile, new UpdateStatus(), !Importer.DEBUG);
}
public void LoadData(Context ctx, String filename, String password, String keyfile, UpdateStatus status) throws IOException, FileNotFoundException, InvalidDBException {
LoadData(ctx, filename, password, keyfile, status, !Importer.DEBUG);
public void LoadData(Context ctx, Uri uri, String password, String keyfile, UpdateStatus status) throws IOException, FileNotFoundException, InvalidDBException {
LoadData(ctx, uri, password, keyfile, status, !Importer.DEBUG);
}
public void LoadData(Context ctx, String filename, String password, String keyfile, UpdateStatus status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
File file = new File(filename);
FileInputStream fis = new FileInputStream(file);
public void LoadData(Context ctx, Uri uri, String password, String keyfile, UpdateStatus status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
mUri = uri;
readOnly = false;
if (uri.getScheme().equals("file")) {
File file = new File(uri.getPath());
readOnly = !file.canWrite();
}
LoadData(ctx, fis, password, keyfile, status, debug);
InputStream is = ctx.getContentResolver().openInputStream(uri);
readOnly = !file.canWrite();
mFilename = filename;
LoadData(ctx, is, password, keyfile, status, debug);
}
public void LoadData(Context ctx, InputStream is, String password, String keyfile, boolean debug) throws IOException, InvalidDBException {
@@ -138,36 +143,51 @@ public class Database {
}
public void SaveData() throws IOException, PwDbOutputException {
SaveData(mFilename);
public void SaveData(Context ctx) throws IOException, PwDbOutputException {
SaveData(ctx, mUri);
}
public void SaveData(String filename) throws IOException, PwDbOutputException {
File tempFile = new File(filename + ".tmp");
FileOutputStream fos = new FileOutputStream(tempFile);
//BufferedOutputStream bos = new BufferedOutputStream(fos);
public void SaveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
if (uri.getScheme().equals("data")) {
String filename = uri.getPath();
File tempFile = new File(filename + ".tmp");
FileOutputStream fos = new FileOutputStream(tempFile);
//BufferedOutputStream bos = new BufferedOutputStream(fos);
//PwDbV3Output pmo = new PwDbV3Output(pm, bos, App.getCalendar());
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
pmo.output();
//bos.flush();
//bos.close();
fos.close();
//PwDbV3Output pmo = new PwDbV3Output(pm, bos, App.getCalendar());
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
pmo.output();
//bos.flush();
//bos.close();
fos.close();
// Force data to disk before continuing
try {
fos.getFD().sync();
} catch (SyncFailedException e) {
// Ignore if fsync fails. We tried.
// Force data to disk before continuing
try {
fos.getFD().sync();
} catch (SyncFailedException e) {
// Ignore if fsync fails. We tried.
}
File orig = new File(filename);
if (!tempFile.renameTo(orig)) {
throw new IOException("Failed to store database.");
}
}
else {
OutputStream os;
try {
os = ctx.getContentResolver().openOutputStream(uri);
} catch (Exception e) {
throw new IOException("Failed to store database.");
}
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
pmo.output();
os.close();
}
File orig = new File(filename);
if ( ! tempFile.renameTo(orig) ) {
throw new IOException("Failed to store database.");
}
mFilename = filename;
mUri = uri;
}
@@ -176,7 +196,7 @@ public class Database {
drawFactory.clear();
pm = null;
mFilename = null;
mUri = null;
loaded = false;
passwordEncodingError = false;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2015 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -188,9 +188,9 @@ public abstract class EntryEditActivity extends LockCloseHideActivity {
OnFinish onFinish = act.new AfterSave(new Handler());
if ( mIsNew ) {
task = AddEntry.getInstance(App.getDB(), newEntry, onFinish);
task = AddEntry.getInstance(EntryEditActivity.this, App.getDB(), newEntry, onFinish);
} else {
task = new UpdateEntry(App.getDB(), mEntry, newEntry, onFinish);
task = new UpdateEntry(EntryEditActivity.this, App.getDB(), mEntry, newEntry, onFinish);
}
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
pt.run();

View File

@@ -210,7 +210,7 @@ public abstract class GroupActivity extends GroupBaseActivity {
int GroupIconID = data.getExtras().getInt(GroupEditActivity.KEY_ICON_ID);
GroupActivity act = GroupActivity.this;
Handler handler = new Handler();
AddGroup task = AddGroup.getInstance(App.getDB(), GroupName, GroupIconID, mGroup, act.new RefreshTask(handler), false);
AddGroup task = AddGroup.getInstance(this, App.getDB(), GroupName, GroupIconID, mGroup, act.new RefreshTask(handler), false);
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
pt.run();
break;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2013 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -33,6 +33,7 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager;
import android.text.InputType;
import android.view.Menu;
@@ -60,6 +61,7 @@ import com.keepassdroid.fileselect.BrowserDialog;
import com.keepassdroid.intents.Intents;
import com.keepassdroid.settings.AppSettingsActivity;
import com.keepassdroid.utils.Interaction;
import com.keepassdroid.utils.StrUtil;
import com.keepassdroid.utils.Util;
public class PasswordActivity extends LockingActivity {
@@ -76,6 +78,7 @@ public class PasswordActivity extends LockingActivity {
private String mFileName;
private String mKeyFile;
private Uri mUri = null;
private boolean mRememberKeyfile;
SharedPreferences prefs;
@@ -84,10 +87,12 @@ public class PasswordActivity extends LockingActivity {
}
public static void Launch(Activity act, String fileName, String keyFile) throws FileNotFoundException {
/*
File dbFile = new File(fileName);
if ( ! dbFile.exists() ) {
throw new FileNotFoundException();
}
*/
Intent i = new Intent(act, PasswordActivity.class);
i.putExtra(KEY_FILENAME, fileName);
@@ -263,8 +268,21 @@ public class PasswordActivity extends LockingActivity {
// Clear the shutdown flag
App.clearShutdown();
Uri uri;
if (mUri != null) {
uri = mUri;
} else {
uri = Uri.parse(fileName);
String scheme = uri.getScheme();
if (scheme == null || scheme.equals("")) {
Uri.Builder builder = new Uri.Builder();
builder.scheme("file").authority("").path(fileName);
uri = builder.build();
}
}
Handler handler = new Handler();
LoadDB task = new LoadDB(db, PasswordActivity.this, fileName, pass, keyfile, new AfterLoad(handler, db));
LoadDB task = new LoadDB(db, PasswordActivity.this, uri, pass, keyfile, new AfterLoad(handler, db));
ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database);
pt.run();
}
@@ -346,27 +364,32 @@ public class PasswordActivity extends LockingActivity {
Intent i = args[0];
String action = i.getAction();;
if ( action != null && action.equals(VIEW_INTENT) ) {
mFileName = i.getDataString();
Uri incoming = i.getData();
if (incoming.getScheme().equals("file")) {
mFileName = incoming.getPath();
if ( ! mFileName.substring(0, 7).equals("file://") ) {
if (mFileName.length() == 0) {
// No file name
return R.string.FileNotFound;
}
File dbFile = new File(mFileName);
if (!dbFile.exists()) {
// File does not exist
return R.string.FileNotFound;
}
mKeyFile = getKeyFile(mFileName);
}
else if (incoming.getScheme().equals("content")) {
mUri = incoming;
mFileName = mUri.toString();
mKeyFile = getKeyFile(mFileName);
}
else {
return R.string.error_can_not_handle_uri;
}
mFileName = URLDecoder.decode(mFileName.substring(7, mFileName.length()));
if ( mFileName.length() == 0 ) {
// No file name
return R.string.FileNotFound;
}
File dbFile = new File(mFileName);
if ( ! dbFile.exists() ) {
// File does not exist
return R.string.FileNotFound;
}
mKeyFile = getKeyFile(mFileName);
} else {
mFileName = i.getStringExtra(KEY_FILENAME);
mKeyFile = i.getStringExtra(KEY_KEYFILE);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -93,7 +93,7 @@ public class SetPasswordDialog extends CancelDialog {
}
SetPassword sp = new SetPassword(App.getDB(), pass, keyfile, new AfterSave(mFinish, new Handler()));
SetPassword sp = new SetPassword(getContext(), App.getDB(), pass, keyfile, new AfterSave(mFinish, new Handler()));
final ProgressTask pt = new ProgressTask(getContext(), sp, R.string.saving_database);
boolean valid = sp.validatePassword(getContext(), new OnClickListener() {

View File

@@ -19,6 +19,8 @@
*/
package com.keepassdroid.database.edit;
import android.content.Context;
import com.keepassdroid.Database;
import com.keepassdroid.database.PwDatabase;
import com.keepassdroid.database.PwEntry;
@@ -27,16 +29,18 @@ import com.keepassdroid.database.PwGroup;
public class AddEntry extends RunnableOnFinish {
protected Database mDb;
private PwEntry mEntry;
private Context ctx;
public static AddEntry getInstance(Database db, PwEntry entry, OnFinish finish) {
return new AddEntry(db, entry, finish);
public static AddEntry getInstance(Context ctx, Database db, PwEntry entry, OnFinish finish) {
return new AddEntry(ctx, db, entry, finish);
}
protected AddEntry(Database db, PwEntry entry, OnFinish finish) {
protected AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) {
super(finish);
mDb = db;
mEntry = entry;
this.ctx = ctx;
mFinish = new AfterAdd(mFinish);
}
@@ -46,7 +50,7 @@ public class AddEntry extends RunnableOnFinish {
mDb.pm.addEntryTo(mEntry, mEntry.getParent());
// Commit to disk
SaveDB save = new SaveDB(mDb, mFinish);
SaveDB save = new SaveDB(ctx, mDb, mFinish);
save.run();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2013 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -19,6 +19,8 @@
*/
package com.keepassdroid.database.edit;
import android.content.Context;
import com.keepassdroid.Database;
import com.keepassdroid.database.PwDatabase;
import com.keepassdroid.database.PwGroup;
@@ -29,15 +31,16 @@ public class AddGroup extends RunnableOnFinish {
private int mIconID;
private PwGroup mGroup;
private PwGroup mParent;
private Context ctx;
protected boolean mDontSave;
public static AddGroup getInstance(Database db, String name, int iconid, PwGroup parent, OnFinish finish, boolean dontSave) {
return new AddGroup(db, name, iconid, parent, finish, dontSave);
public static AddGroup getInstance(Context ctx, Database db, String name, int iconid, PwGroup parent, OnFinish finish, boolean dontSave) {
return new AddGroup(ctx, db, name, iconid, parent, finish, dontSave);
}
private AddGroup(Database db, String name, int iconid, PwGroup parent, OnFinish finish, boolean dontSave) {
private AddGroup(Context ctx, Database db, String name, int iconid, PwGroup parent, OnFinish finish, boolean dontSave) {
super(finish);
mDb = db;
@@ -45,6 +48,7 @@ public class AddGroup extends RunnableOnFinish {
mIconID = iconid;
mParent = parent;
mDontSave = dontSave;
this.ctx = ctx;
mFinish = new AfterAdd(mFinish);
}
@@ -62,7 +66,7 @@ public class AddGroup extends RunnableOnFinish {
//mParent.sortGroupsByName();
// Commit to disk
SaveDB save = new SaveDB(mDb, mFinish, mDontSave);
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
save.run();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2015 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -20,6 +20,9 @@
package com.keepassdroid.database.edit;
import android.content.Context;
import android.net.Uri;
import com.keepassdroid.Database;
import com.keepassdroid.app.App;
import com.keepassdroid.database.PwDatabase;
@@ -32,12 +35,14 @@ public class CreateDB extends RunnableOnFinish {
private String mFilename;
private boolean mDontSave;
private Context ctx;
public CreateDB(String filename, OnFinish finish, boolean dontSave) {
public CreateDB(Context ctx, String filename, OnFinish finish, boolean dontSave) {
super(finish);
mFilename = filename;
mDontSave = dontSave;
this.ctx = ctx;
}
@Override
@@ -51,11 +56,12 @@ public class CreateDB extends RunnableOnFinish {
// Set Database state
db.pm = pm;
db.mFilename = mFilename;
Uri.Builder b = new Uri.Builder();
db.mUri = b.scheme("path").path(mFilename).build();
db.setLoaded();
// Commit changes
SaveDB save = new SaveDB(db, mFinish, mDontSave);
SaveDB save = new SaveDB(ctx, db, mFinish, mDontSave);
mFinish = null;
save.run();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2013 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -19,6 +19,8 @@
*/
package com.keepassdroid.database.edit;
import android.content.Context;
import com.keepassdroid.Database;
import com.keepassdroid.database.PwDatabase;
import com.keepassdroid.database.PwEntry;
@@ -33,22 +35,19 @@ public class DeleteEntry extends RunnableOnFinish {
private Database mDb;
private PwEntry mEntry;
private boolean mDontSave;
private Context ctx;
public DeleteEntry(Database db, PwEntry entry, OnFinish finish) {
super(finish);
mDb = db;
mEntry = entry;
mDontSave = false;
public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) {
this(ctx, db, entry, finish, false);
}
public DeleteEntry(Database db, PwEntry entry, OnFinish finish, boolean dontSave) {
public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) {
super(finish);
mDb = db;
mEntry = entry;
mDontSave = dontSave;
this.ctx = ctx;
}
@@ -70,7 +69,7 @@ public class DeleteEntry extends RunnableOnFinish {
mFinish = new AfterDelete(mFinish, parent, mEntry, recycle);
// Commit database
SaveDB save = new SaveDB(mDb, mFinish, mDontSave);
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
save.run();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2013 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -68,7 +68,7 @@ public class DeleteGroup extends RunnableOnFinish {
// Remove child entries
List<PwEntry> childEnt = new ArrayList<PwEntry>(mGroup.childEntries);
for ( int i = 0; i < childEnt.size(); i++ ) {
DeleteEntry task = new DeleteEntry(mDb, childEnt.get(i), null, true);
DeleteEntry task = new DeleteEntry(mAct, mDb, childEnt.get(i), null, true);
task.run();
}
@@ -90,7 +90,7 @@ public class DeleteGroup extends RunnableOnFinish {
mDb.pm.getGroups().remove(mGroup);
// Save
SaveDB save = new SaveDB(mDb, mFinish, mDontSave);
SaveDB save = new SaveDB(mAct, mDb, mFinish, mDontSave);
save.run();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2013 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -24,6 +24,7 @@ import java.io.IOException;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import com.android.keepass.R;
@@ -39,19 +40,19 @@ import com.keepassdroid.database.exception.InvalidPasswordException;
import com.keepassdroid.database.exception.KeyFileEmptyException;
public class LoadDB extends RunnableOnFinish {
private String mFileName;
private Uri mUri;
private String mPass;
private String mKey;
private Database mDb;
private Context mCtx;
private boolean mRememberKeyfile;
public LoadDB(Database db, Context ctx, String fileName, String pass, String key, OnFinish finish) {
public LoadDB(Database db, Context ctx, Uri uri, String pass, String key, OnFinish finish) {
super(finish);
mDb = db;
mCtx = ctx;
mFileName = fileName;
mUri = uri;
mPass = pass;
mKey = key;
@@ -62,9 +63,9 @@ public class LoadDB extends RunnableOnFinish {
@Override
public void run() {
try {
mDb.LoadData(mCtx, mFileName, mPass, mKey, mStatus);
mDb.LoadData(mCtx, mUri, mPass, mKey, mStatus);
saveFileData(mFileName, mKey);
saveFileData(mUri, mKey);
} catch (ArcFourException e) {
finish(false, mCtx.getString(R.string.error_arc4));
@@ -104,12 +105,12 @@ public class LoadDB extends RunnableOnFinish {
finish(true);
}
private void saveFileData(String fileName, String key) {
private void saveFileData(Uri uri, String key) {
if ( ! mRememberKeyfile ) {
key = "";
}
App.getFileHistory().createFile(fileName, key);
App.getFileHistory().createFile(uri, key);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -19,6 +19,8 @@
*/
package com.keepassdroid.database.edit;
import android.content.Context;
import java.io.IOException;
import com.keepassdroid.Database;
@@ -27,19 +29,22 @@ import com.keepassdroid.database.exception.PwDbOutputException;
public class SaveDB extends RunnableOnFinish {
private Database mDb;
private boolean mDontSave;
private Context mCtx;
public SaveDB(Database db, OnFinish finish, boolean dontSave) {
public SaveDB(Context ctx, Database db, OnFinish finish, boolean dontSave) {
super(finish);
mDb = db;
mDontSave = dontSave;
mCtx = ctx;
}
public SaveDB(Database db, OnFinish finish) {
public SaveDB(Context ctx, Database db, OnFinish finish) {
super(finish);
mDb = db;
mDontSave = false;
mCtx = ctx;
}
@Override
@@ -47,7 +52,7 @@ public class SaveDB extends RunnableOnFinish {
if ( ! mDontSave ) {
try {
mDb.SaveData();
mDb.SaveData(mCtx);
} catch (IOException e) {
finish(false, e.getMessage());
return;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -35,23 +35,21 @@ public class SetPassword extends RunnableOnFinish {
private String mKeyfile;
private Database mDb;
private boolean mDontSave;
private Context ctx;
public SetPassword(Database db, String password, String keyfile, OnFinish finish) {
super(finish);
public SetPassword(Context ctx, Database db, String password, String keyfile, OnFinish finish) {
this(ctx, db, password, keyfile, finish, false);
mDb = db;
mPassword = password;
mKeyfile = keyfile;
mDontSave = false;
}
public SetPassword(Database db, String password, String keyfile, OnFinish finish, boolean dontSave) {
public SetPassword(Context ctx, Database db, String password, String keyfile, OnFinish finish, boolean dontSave) {
super(finish);
mDb = db;
mPassword = password;
mKeyfile = keyfile;
mDontSave = dontSave;
this.ctx = ctx;
}
public boolean validatePassword(Context ctx, DialogInterface.OnClickListener onclick) {
@@ -86,7 +84,7 @@ public class SetPassword extends RunnableOnFinish {
// Save Database
mFinish = new AfterSave(backupKey, mFinish);
SaveDB save = new SaveDB(mDb, mFinish, mDontSave);
SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
save.run();
}

View File

@@ -19,6 +19,8 @@
*/
package com.keepassdroid.database.edit;
import android.content.Context;
import com.keepassdroid.Database;
import com.keepassdroid.database.PwEntry;
import com.keepassdroid.database.PwGroup;
@@ -27,13 +29,15 @@ public class UpdateEntry extends RunnableOnFinish {
private Database mDb;
private PwEntry mOldE;
private PwEntry mNewE;
private Context ctx;
public UpdateEntry(Database db, PwEntry oldE, PwEntry newE, OnFinish finish) {
public UpdateEntry(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinish finish) {
super(finish);
mDb = db;
mOldE = oldE;
mNewE = newE;
this.ctx = ctx;
// Keep backup of original values in case save fails
PwEntry backup;
@@ -50,7 +54,7 @@ public class UpdateEntry extends RunnableOnFinish {
// Commit to disk
SaveDB save = new SaveDB(mDb, mFinish);
SaveDB save = new SaveDB(ctx, mDb, mFinish);
save.run();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2014 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -167,7 +167,7 @@ public class FileSelectActivity extends ListActivity {
new LaunchGroupActivity(filename));
// Create the new database
CreateDB create = new CreateDB(filename, password, true);
CreateDB create = new CreateDB(FileSelectActivity.this, filename, password, true);
ProgressTask createTask = new ProgressTask(
FileSelectActivity.this, create,
R.string.progress_create);
@@ -237,25 +237,22 @@ public class FileSelectActivity extends ListActivity {
}
private class LaunchGroupActivity extends FileOnFinish {
private String mFilename;
private Uri mUri;
public LaunchGroupActivity(String filename) {
super(null);
mFilename = filename;
Uri.Builder b = new Uri.Builder();
mUri = b.scheme("file").authority("").path(filename).build();
}
@Override
public void run() {
if (mSuccess) {
// Add to recent files
fileHistory.createFile(mFilename, getFilename());
fileHistory.createFile(mUri, getFilename());
GroupActivity.Launch(FileSelectActivity.this);
} else {
File file = new File(mFilename);
file.delete();
}
}
}
@@ -413,7 +410,7 @@ public class FileSelectActivity extends ListActivity {
new AsyncTask<String, Void, Void>() {
protected java.lang.Void doInBackground(String... args) {
String filename = args[0];
fileHistory.deleteFile(filename);
fileHistory.deleteFile(Uri.parse(args[0]));
return null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 Brian Pellin.
* Copyright 2013-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -30,6 +30,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.Cursor;
import android.net.Uri;
import android.preference.PreferenceManager;
public class RecentFileHistory {
@@ -124,15 +125,15 @@ public class RecentFileHistory {
return db.exists();
}
public void createFile(String fileName, String keyFile) {
public void createFile(Uri uri, String keyFile) {
if (!enabled) return;
init();
// Remove any existing instance of the same filename
deleteFile(fileName, false);
deleteFile(uri, false);
databases.add(0, fileName);
databases.add(0, uri.toString());
keyfiles.add(0, keyFile);
trimLists();
@@ -189,15 +190,19 @@ public class RecentFileHistory {
EditorCompat.apply(edit);
}
public void deleteFile(String filename) {
deleteFile(filename, true);
public void deleteFile(Uri uri) {
deleteFile(uri, true);
}
public void deleteFile(String filename, boolean save) {
public void deleteFile(Uri uri, boolean save) {
init();
String uriName = uri.toString();
String fileName = uri.getPath();
for (int i = 0; i < databases.size(); i++) {
if (filename.equals(databases.get(i))) {
String entry = databases.get(i);
if (uriName.equals(entry) || fileName.equals(entry)) {
databases.remove(i);
keyfiles.remove(i);
break;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009 Brian Pellin.
* Copyright 2009-2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
@@ -91,7 +91,7 @@ public class RoundsPreference extends DialogPreference {
}
Handler handler = new Handler();
SaveDB save = new SaveDB(App.getDB(), new AfterSave(getContext(), handler, oldRounds));
SaveDB save = new SaveDB(getContext(), App.getDB(), new AfterSave(getContext(), handler, oldRounds));
ProgressTask pt = new ProgressTask(getContext(), save, R.string.saving_database);
pt.run();

View File

@@ -97,7 +97,7 @@ public class PwEntryView extends ClickView {
private void deleteEntry() {
Handler handler = new Handler();
DeleteEntry task = new DeleteEntry(App.getDB(), mPw, mAct.new RefreshTask(handler));
DeleteEntry task = new DeleteEntry(mAct, App.getDB(), mPw, mAct.new RefreshTask(handler));
ProgressTask pt = new ProgressTask(mAct, task, R.string.saving_database);
pt.run();