mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Update progress bar and message progress
This commit is contained in:
@@ -36,7 +36,7 @@ import com.kunzisoft.keepass.database.load.ImporterFactory;
|
|||||||
import com.kunzisoft.keepass.database.save.PwDbOutput;
|
import com.kunzisoft.keepass.database.save.PwDbOutput;
|
||||||
import com.kunzisoft.keepass.icons.IconDrawableFactory;
|
import com.kunzisoft.keepass.icons.IconDrawableFactory;
|
||||||
import com.kunzisoft.keepass.search.SearchDbHelper;
|
import com.kunzisoft.keepass.search.SearchDbHelper;
|
||||||
import com.kunzisoft.keepass.tasks.UpdateStatus;
|
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
|
||||||
import com.kunzisoft.keepass.utils.UriUtil;
|
import com.kunzisoft.keepass.utils.UriUtil;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
@@ -99,19 +99,11 @@ public class Database {
|
|||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadData(Context ctx, InputStream is, String password, InputStream keyInputStream) throws IOException, InvalidDBException {
|
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status) throws IOException, FileNotFoundException, InvalidDBException {
|
||||||
loadData(ctx, is, password, keyInputStream, new UpdateStatus(), !Importer.DEBUG);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadData(Context ctx, Uri uri, String password, Uri keyfile) throws IOException, FileNotFoundException, InvalidDBException {
|
|
||||||
loadData(ctx, uri, password, keyfile, new UpdateStatus(), !Importer.DEBUG);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status) throws IOException, FileNotFoundException, InvalidDBException {
|
|
||||||
loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG);
|
loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
|
public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException {
|
||||||
mUri = uri;
|
mUri = uri;
|
||||||
readOnly = false;
|
readOnly = false;
|
||||||
if (uri.getScheme().equals("file")) {
|
if (uri.getScheme().equals("file")) {
|
||||||
@@ -138,7 +130,7 @@ public class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException {
|
private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException {
|
||||||
InputStream is, kfIs;
|
InputStream is, kfIs;
|
||||||
try {
|
try {
|
||||||
is = UriUtil.getUriInputStream(ctx, uri);
|
is = UriUtil.getUriInputStream(ctx, uri);
|
||||||
@@ -157,14 +149,10 @@ public class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, boolean debug) throws IOException, InvalidDBException {
|
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, boolean debug) throws IOException, InvalidDBException {
|
||||||
loadData(ctx, is, password, kfIs, new UpdateStatus(), debug);
|
loadData(ctx, is, password, kfIs, null, debug, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug) throws IOException, InvalidDBException {
|
private void loadData(Context ctx, InputStream is, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater, boolean debug, long roundsFix) throws IOException, InvalidDBException {
|
||||||
loadData(ctx, is, password, kfIs, status, debug, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug, long roundsFix) throws IOException, InvalidDBException {
|
|
||||||
BufferedInputStream bis = new BufferedInputStream(is);
|
BufferedInputStream bis = new BufferedInputStream(is);
|
||||||
|
|
||||||
if ( ! bis.markSupported() ) {
|
if ( ! bis.markSupported() ) {
|
||||||
@@ -178,7 +166,7 @@ public class Database {
|
|||||||
|
|
||||||
bis.reset(); // Return to the start
|
bis.reset(); // Return to the start
|
||||||
|
|
||||||
pm = imp.openDatabase(bis, password, kfIs, status, roundsFix);
|
pm = imp.openDatabase(bis, password, kfIs, progressTaskUpdater, roundsFix);
|
||||||
if ( pm != null ) {
|
if ( pm != null ) {
|
||||||
try {
|
try {
|
||||||
switch (pm.getVersion()) {
|
switch (pm.getVersion()) {
|
||||||
@@ -222,19 +210,23 @@ public class Database {
|
|||||||
saveData(ctx, mUri);
|
saveData(ctx, mUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
|
private void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
|
||||||
if (uri.getScheme().equals("file")) {
|
if (uri.getScheme().equals("file")) {
|
||||||
String filename = uri.getPath();
|
String filename = uri.getPath();
|
||||||
File tempFile = new File(filename + ".tmp");
|
File tempFile = new File(filename + ".tmp");
|
||||||
FileOutputStream fos = new FileOutputStream(tempFile);
|
|
||||||
//BufferedOutputStream bos = new BufferedOutputStream(fos);
|
|
||||||
|
|
||||||
//PwDbV3Output pmo = new PwDbV3Output(pm, bos, App.getCalendar());
|
FileOutputStream fos = null;
|
||||||
|
try {
|
||||||
|
fos = new FileOutputStream(tempFile);
|
||||||
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
|
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
|
||||||
|
if (pmo != null)
|
||||||
pmo.output();
|
pmo.output();
|
||||||
//bos.flush();
|
} catch (Exception e) {
|
||||||
//bos.close();
|
throw new IOException("Failed to store database.");
|
||||||
|
} finally {
|
||||||
|
if (fos != null)
|
||||||
fos.close();
|
fos.close();
|
||||||
|
}
|
||||||
|
|
||||||
// Force data to disk before continuing
|
// Force data to disk before continuing
|
||||||
try {
|
try {
|
||||||
@@ -250,17 +242,19 @@ public class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OutputStream os;
|
OutputStream os = null;
|
||||||
try {
|
try {
|
||||||
os = ctx.getContentResolver().openOutputStream(uri);
|
os = ctx.getContentResolver().openOutputStream(uri);
|
||||||
|
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
|
||||||
|
if (pmo != null)
|
||||||
|
pmo.output();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IOException("Failed to store database.");
|
throw new IOException("Failed to store database.");
|
||||||
}
|
} finally {
|
||||||
|
if (os != null)
|
||||||
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
|
|
||||||
pmo.output();
|
|
||||||
os.close();
|
os.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mUri = uri;
|
mUri = uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class OnFinishRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Move
|
||||||
protected void displayMessage(Context ctx) {
|
protected void displayMessage(Context ctx) {
|
||||||
if ( mMessage != null && mMessage.length() > 0 ) {
|
if ( mMessage != null && mMessage.length() > 0 ) {
|
||||||
Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show();
|
Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show();
|
||||||
|
|||||||
@@ -19,13 +19,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.database.action;
|
package com.kunzisoft.keepass.database.action;
|
||||||
|
|
||||||
import com.kunzisoft.keepass.tasks.UpdateStatus;
|
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
|
||||||
|
|
||||||
|
|
||||||
public abstract class RunnableOnFinish implements Runnable {
|
public abstract class RunnableOnFinish implements Runnable {
|
||||||
|
|
||||||
public OnFinishRunnable mFinish;
|
public OnFinishRunnable mFinish;
|
||||||
public UpdateStatus mStatus;
|
public ProgressTaskUpdater mStatus;
|
||||||
|
|
||||||
public RunnableOnFinish(OnFinishRunnable finish) {
|
public RunnableOnFinish(OnFinishRunnable finish) {
|
||||||
mFinish = finish;
|
mFinish = finish;
|
||||||
@@ -45,7 +45,7 @@ public abstract class RunnableOnFinish implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(UpdateStatus status) {
|
public void setStatus(ProgressTaskUpdater status) {
|
||||||
mStatus = status;
|
mStatus = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.load;
|
|||||||
|
|
||||||
import com.kunzisoft.keepass.database.PwDatabase;
|
import com.kunzisoft.keepass.database.PwDatabase;
|
||||||
import com.kunzisoft.keepass.database.exception.InvalidDBException;
|
import com.kunzisoft.keepass.database.exception.InvalidDBException;
|
||||||
import com.kunzisoft.keepass.tasks.UpdateStatus;
|
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -33,8 +33,7 @@ public abstract class Importer {
|
|||||||
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream)
|
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream)
|
||||||
throws IOException, InvalidDBException;
|
throws IOException, InvalidDBException;
|
||||||
|
|
||||||
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream, UpdateStatus status, long roundsFix)
|
public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream, ProgressTaskUpdater updater, long roundsFix)
|
||||||
throws IOException, InvalidDBException;
|
throws IOException, InvalidDBException;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ import com.kunzisoft.keepass.database.exception.InvalidPasswordException;
|
|||||||
import com.kunzisoft.keepass.stream.LEDataInputStream;
|
import com.kunzisoft.keepass.stream.LEDataInputStream;
|
||||||
import com.kunzisoft.keepass.stream.LEDataOutputStream;
|
import com.kunzisoft.keepass.stream.LEDataOutputStream;
|
||||||
import com.kunzisoft.keepass.stream.NullOutputStream;
|
import com.kunzisoft.keepass.stream.NullOutputStream;
|
||||||
import com.kunzisoft.keepass.tasks.UpdateStatus;
|
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
|
||||||
import com.kunzisoft.keepass.utils.Types;
|
import com.kunzisoft.keepass.utils.Types;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -124,15 +124,15 @@ public class ImporterV3 extends Importer {
|
|||||||
* @throws InvalidAlgorithmParameterException if error decrypting main file body.
|
* @throws InvalidAlgorithmParameterException if error decrypting main file body.
|
||||||
* @throws ShortBufferException if error decrypting main file body.
|
* @throws ShortBufferException if error decrypting main file body.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs)
|
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs)
|
||||||
throws IOException, InvalidDBException
|
throws IOException, InvalidDBException {
|
||||||
{
|
return openDatabase(inStream, password, kfIs, null, 0);
|
||||||
return openDatabase(inStream, password, kfIs, new UpdateStatus(), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs, UpdateStatus status, long roundsFix)
|
@Override
|
||||||
throws IOException, InvalidDBException
|
public PwDatabaseV3 openDatabase(InputStream inStream, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater, long roundsFix)
|
||||||
{
|
throws IOException, InvalidDBException {
|
||||||
PwDatabaseV3 newManager;
|
PwDatabaseV3 newManager;
|
||||||
|
|
||||||
|
|
||||||
@@ -156,7 +156,8 @@ public class ImporterV3 extends Importer {
|
|||||||
throw new InvalidDBVersionException();
|
throw new InvalidDBVersionException();
|
||||||
}
|
}
|
||||||
|
|
||||||
status.updateMessage(R.string.creating_db_key);
|
if (progressTaskUpdater != null)
|
||||||
|
progressTaskUpdater.updateMessage(R.string.creating_db_key);
|
||||||
newManager = createDB();
|
newManager = createDB();
|
||||||
newManager.setMasterKey(password, kfIs);
|
newManager.setMasterKey(password, kfIs);
|
||||||
|
|
||||||
@@ -177,7 +178,8 @@ public class ImporterV3 extends Importer {
|
|||||||
// Generate transformedMasterKey from masterKey
|
// Generate transformedMasterKey from masterKey
|
||||||
newManager.makeFinalKey(hdr.masterSeed, hdr.transformSeed, newManager.getNumberKeyEncryptionRounds());
|
newManager.makeFinalKey(hdr.masterSeed, hdr.transformSeed, newManager.getNumberKeyEncryptionRounds());
|
||||||
|
|
||||||
status.updateMessage(R.string.decrypting_db);
|
if (progressTaskUpdater != null)
|
||||||
|
progressTaskUpdater.updateMessage(R.string.decrypting_db);
|
||||||
// Initialize Rijndael algorithm
|
// Initialize Rijndael algorithm
|
||||||
Cipher cipher;
|
Cipher cipher;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.load;
|
|||||||
|
|
||||||
import com.kunzisoft.keepass.database.PwDatabaseV3Debug;
|
import com.kunzisoft.keepass.database.PwDatabaseV3Debug;
|
||||||
import com.kunzisoft.keepass.database.exception.InvalidDBException;
|
import com.kunzisoft.keepass.database.exception.InvalidDBException;
|
||||||
import com.kunzisoft.keepass.tasks.UpdateStatus;
|
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -35,7 +35,7 @@ public class ImporterV3Debug extends ImporterV3 {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PwDatabaseV3Debug openDatabase(InputStream inStream, String password,
|
public PwDatabaseV3Debug openDatabase(InputStream inStream, String password,
|
||||||
InputStream keyInputStream, UpdateStatus status, long roundsFix) throws IOException,
|
InputStream keyInputStream, ProgressTaskUpdater status, long roundsFix) throws IOException,
|
||||||
InvalidDBException {
|
InvalidDBException {
|
||||||
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status,
|
return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status,
|
||||||
roundsFix);
|
roundsFix);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.kunzisoft.keepass.database.load;
|
package com.kunzisoft.keepass.database.load;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.R;
|
||||||
import com.kunzisoft.keepass.crypto.CipherFactory;
|
import com.kunzisoft.keepass.crypto.CipherFactory;
|
||||||
import com.kunzisoft.keepass.crypto.PwStreamCipherFactory;
|
import com.kunzisoft.keepass.crypto.PwStreamCipherFactory;
|
||||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine;
|
import com.kunzisoft.keepass.crypto.engine.CipherEngine;
|
||||||
@@ -42,7 +43,7 @@ import com.kunzisoft.keepass.stream.BetterCipherInputStream;
|
|||||||
import com.kunzisoft.keepass.stream.HashedBlockInputStream;
|
import com.kunzisoft.keepass.stream.HashedBlockInputStream;
|
||||||
import com.kunzisoft.keepass.stream.HmacBlockInputStream;
|
import com.kunzisoft.keepass.stream.HmacBlockInputStream;
|
||||||
import com.kunzisoft.keepass.stream.LEDataInputStream;
|
import com.kunzisoft.keepass.stream.LEDataInputStream;
|
||||||
import com.kunzisoft.keepass.tasks.UpdateStatus;
|
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
|
||||||
import com.kunzisoft.keepass.utils.DateUtil;
|
import com.kunzisoft.keepass.utils.DateUtil;
|
||||||
import com.kunzisoft.keepass.utils.EmptyUtils;
|
import com.kunzisoft.keepass.utils.EmptyUtils;
|
||||||
import com.kunzisoft.keepass.utils.MemUtil;
|
import com.kunzisoft.keepass.utils.MemUtil;
|
||||||
@@ -97,13 +98,16 @@ public class ImporterV4 extends Importer {
|
|||||||
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
||||||
InputStream keyInputStream) throws IOException, InvalidDBException {
|
InputStream keyInputStream) throws IOException, InvalidDBException {
|
||||||
|
|
||||||
return openDatabase(inStream, password, keyInputStream, new UpdateStatus(), 0);
|
return openDatabase(inStream, password, keyInputStream, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
public PwDatabaseV4 openDatabase(InputStream inStream, String password,
|
||||||
InputStream keyInputStream, UpdateStatus status, long roundsFix) throws IOException,
|
InputStream keyInputStream, ProgressTaskUpdater progressTaskUpdater, long roundsFix) throws IOException,
|
||||||
InvalidDBException {
|
InvalidDBException {
|
||||||
|
|
||||||
|
if (progressTaskUpdater != null)
|
||||||
|
progressTaskUpdater.updateMessage(R.string.creating_db_key);
|
||||||
db = createDB();
|
db = createDB();
|
||||||
|
|
||||||
PwDbHeaderV4 header = new PwDbHeaderV4(db);
|
PwDbHeaderV4 header = new PwDbHeaderV4(db);
|
||||||
@@ -118,6 +122,8 @@ public class ImporterV4 extends Importer {
|
|||||||
db.setMasterKey(password, keyInputStream);
|
db.setMasterKey(password, keyInputStream);
|
||||||
db.makeFinalKey(header.masterSeed, db.getKdfParameters(), roundsFix);
|
db.makeFinalKey(header.masterSeed, db.getKdfParameters(), roundsFix);
|
||||||
|
|
||||||
|
if (progressTaskUpdater != null)
|
||||||
|
progressTaskUpdater.updateMessage(R.string.decrypting_db);
|
||||||
CipherEngine engine;
|
CipherEngine engine;
|
||||||
Cipher cipher;
|
Cipher cipher;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ import com.kunzisoft.keepass.fingerprint.FingerPrintDialog;
|
|||||||
import com.kunzisoft.keepass.fingerprint.FingerPrintHelper;
|
import com.kunzisoft.keepass.fingerprint.FingerPrintHelper;
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||||
import com.kunzisoft.keepass.stylish.StylishActivity;
|
import com.kunzisoft.keepass.stylish.StylishActivity;
|
||||||
import com.kunzisoft.keepass.tasks.ProgressTask;
|
import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment;
|
||||||
|
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
||||||
import com.kunzisoft.keepass.utils.EmptyUtils;
|
import com.kunzisoft.keepass.utils.EmptyUtils;
|
||||||
import com.kunzisoft.keepass.utils.MenuUtil;
|
import com.kunzisoft.keepass.utils.MenuUtil;
|
||||||
import com.kunzisoft.keepass.utils.UriUtil;
|
import com.kunzisoft.keepass.utils.UriUtil;
|
||||||
@@ -122,6 +123,8 @@ public class PasswordActivity extends StylishActivity
|
|||||||
private CompoundButton checkboxKeyfileView;
|
private CompoundButton checkboxKeyfileView;
|
||||||
private CompoundButton checkboxDefaultDatabaseView;
|
private CompoundButton checkboxDefaultDatabaseView;
|
||||||
|
|
||||||
|
private ProgressTaskDialogFragment loadingDatabaseDialog;
|
||||||
|
|
||||||
private DefaultCheckChange defaultCheckChange;
|
private DefaultCheckChange defaultCheckChange;
|
||||||
private ValidateButtonViewClickListener validateButtonViewClickListener;
|
private ValidateButtonViewClickListener validateButtonViewClickListener;
|
||||||
|
|
||||||
@@ -812,16 +815,74 @@ public class PasswordActivity extends StylishActivity
|
|||||||
// Clear before we load
|
// Clear before we load
|
||||||
Database db = App.getDB();
|
Database db = App.getDB();
|
||||||
db.clear();
|
db.clear();
|
||||||
|
|
||||||
// Clear the shutdown flag
|
// Clear the shutdown flag
|
||||||
App.clearShutdown();
|
App.clearShutdown();
|
||||||
|
|
||||||
|
// Show the progress dialog
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
AfterLoad afterLoad = new AfterLoad(handler, db);
|
AfterLoadingDatabase afterLoad = new AfterLoadingDatabase(handler, db);
|
||||||
|
LoadDBRunnable databaseLoadingTask = new LoadDBRunnable(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad);
|
||||||
|
databaseLoadingTask.setStatus(
|
||||||
|
new UpdateProgressTaskStatus(this,
|
||||||
|
handler,
|
||||||
|
ProgressTaskDialogFragment.start(getSupportFragmentManager(), R.string.loading_database)
|
||||||
|
));
|
||||||
|
Thread t = new Thread(databaseLoadingTask);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
|
||||||
LoadDBRunnable task = new LoadDBRunnable(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad);
|
/**
|
||||||
ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database);
|
* Called after verify and try to opening the database
|
||||||
pt.run();
|
*/
|
||||||
|
private final class AfterLoadingDatabase extends OnFinishRunnable {
|
||||||
|
|
||||||
|
protected Database db;
|
||||||
|
|
||||||
|
AfterLoadingDatabase(
|
||||||
|
Handler handler,
|
||||||
|
Database db) {
|
||||||
|
super(handler);
|
||||||
|
|
||||||
|
this.db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
// Recheck fingerprint if error
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
// Stay with the same mode
|
||||||
|
reInitWithFingerprintMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (db.isPasswordEncodingError()) {
|
||||||
|
PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper();
|
||||||
|
dialog.show(PasswordActivity.this, (dialog1, which) -> launchGroupActivity());
|
||||||
|
} else if (mSuccess) {
|
||||||
|
launchGroupActivity();
|
||||||
|
} else {
|
||||||
|
if ( mMessage != null && mMessage.length() > 0 ) {
|
||||||
|
Toast.makeText(PasswordActivity.this, mMessage, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// To remove progress task
|
||||||
|
ProgressTaskDialogFragment.stop(getSupportFragmentManager());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void launchGroupActivity() {
|
||||||
|
AssistStructure assistStructure = null;
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||||
|
assistStructure = autofillHelper.getAssistStructure();
|
||||||
|
if (assistStructure != null) {
|
||||||
|
GroupActivity.launch(PasswordActivity.this, assistStructure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (assistStructure == null) {
|
||||||
|
GroupActivity.launch(PasswordActivity.this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -863,54 +924,6 @@ public class PasswordActivity extends StylishActivity
|
|||||||
PasswordActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
|
PasswordActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called after verify and try to opening the database
|
|
||||||
*/
|
|
||||||
private final class AfterLoad extends OnFinishRunnable {
|
|
||||||
|
|
||||||
protected Database db;
|
|
||||||
|
|
||||||
AfterLoad(
|
|
||||||
Handler handler,
|
|
||||||
Database db) {
|
|
||||||
super(handler);
|
|
||||||
|
|
||||||
this.db = db;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
// Recheck fingerprint if error
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
||||||
// Stay with the same mode
|
|
||||||
reInitWithFingerprintMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (db.isPasswordEncodingError()) {
|
|
||||||
PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper();
|
|
||||||
dialog.show(PasswordActivity.this, (dialog1, which) -> launchGroupActivity());
|
|
||||||
} else if (mSuccess) {
|
|
||||||
launchGroupActivity();
|
|
||||||
} else {
|
|
||||||
displayMessage(PasswordActivity.this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void launchGroupActivity() {
|
|
||||||
AssistStructure assistStructure = null;
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
|
||||||
assistStructure = autofillHelper.getAssistStructure();
|
|
||||||
if (assistStructure != null) {
|
|
||||||
GroupActivity.launch(PasswordActivity.this, assistStructure);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (assistStructure == null) {
|
|
||||||
GroupActivity.launch(PasswordActivity.this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class UriIntentInitTask extends AsyncTask<Intent, Void, Integer> {
|
private static class UriIntentInitTask extends AsyncTask<Intent, Void, Integer> {
|
||||||
|
|
||||||
static final String KEY_FILENAME = "fileName";
|
static final String KEY_FILENAME = "fileName";
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.tasks;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.R;
|
||||||
|
|
||||||
|
public class ProgressTaskDialogFragment extends DialogFragment implements ProgressTaskUpdater{
|
||||||
|
|
||||||
|
public static final String PROGRESS_TASK_DIALOG_TAG = "progressDialogFragment";
|
||||||
|
|
||||||
|
private static final int UNDEFINED = -1;
|
||||||
|
|
||||||
|
private @StringRes int title = UNDEFINED;
|
||||||
|
private @StringRes int message = UNDEFINED;
|
||||||
|
|
||||||
|
private TextView messageView;
|
||||||
|
private ProgressBar progressView;
|
||||||
|
|
||||||
|
public static ProgressTaskDialogFragment start(FragmentManager fragmentManager, @StringRes int titleId) {
|
||||||
|
// Create an instance of the dialog fragment and show it
|
||||||
|
ProgressTaskDialogFragment dialog = new ProgressTaskDialogFragment();
|
||||||
|
dialog.setTitle(titleId);
|
||||||
|
dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG);
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
assert getActivity() != null;
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
// Get the layout inflater
|
||||||
|
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
|
|
||||||
|
// Inflate and set the layout for the dialog
|
||||||
|
// Pass null as the parent view because its going in the dialog layout
|
||||||
|
@SuppressLint("InflateParams")
|
||||||
|
View root = inflater.inflate(R.layout.progress_dialog, null);
|
||||||
|
builder.setView(root);
|
||||||
|
if (title != UNDEFINED)
|
||||||
|
builder.setTitle(title);
|
||||||
|
|
||||||
|
messageView = root.findViewById(R.id.progress_dialog_message);
|
||||||
|
progressView = root.findViewById(R.id.progress_dialog_bar);
|
||||||
|
|
||||||
|
if (message != UNDEFINED)
|
||||||
|
messageView.setText(message);
|
||||||
|
|
||||||
|
setCancelable(false);
|
||||||
|
lockScreenOrientation();
|
||||||
|
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
super.onDismiss(dialog);
|
||||||
|
unlockScreenOrientation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stop(FragmentManager fragmentManager) {
|
||||||
|
Fragment fragmentTask = fragmentManager.findFragmentByTag(PROGRESS_TASK_DIALOG_TAG);
|
||||||
|
if (fragmentTask != null) {
|
||||||
|
ProgressTaskDialogFragment loadingDatabaseDialog = (ProgressTaskDialogFragment) fragmentTask;
|
||||||
|
loadingDatabaseDialog.dismissAllowingStateLoss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lockScreenOrientation() {
|
||||||
|
if (getActivity() != null) {
|
||||||
|
int currentOrientation = getResources().getConfiguration().orientation;
|
||||||
|
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
|
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
|
} else {
|
||||||
|
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unlockScreenOrientation() {
|
||||||
|
if (getActivity() != null)
|
||||||
|
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(@StringRes int titleId) {
|
||||||
|
this.title = titleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateMessage(int resId) {
|
||||||
|
this.message = resId;
|
||||||
|
if (messageView != null)
|
||||||
|
this.messageView.setText(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.tasks;
|
||||||
|
|
||||||
|
public interface ProgressTaskUpdater {
|
||||||
|
void updateMessage(int resId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.kunzisoft.keepass.tasks;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
|
||||||
|
public class UpdateProgressTaskStatus implements ProgressTaskUpdater {
|
||||||
|
private Context mContext;
|
||||||
|
private ProgressTaskUpdater mProgressTaskUpdater;
|
||||||
|
private Handler mHandler;
|
||||||
|
|
||||||
|
public UpdateProgressTaskStatus(Context context, Handler handler, ProgressTaskUpdater progressTaskUpdater) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mProgressTaskUpdater = progressTaskUpdater;
|
||||||
|
this.mHandler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateMessage(int resId) {
|
||||||
|
if ( mContext != null && mProgressTaskUpdater != null && mHandler != null ) {
|
||||||
|
mHandler.post(new UpdateMessage(resId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class UpdateMessage implements Runnable {
|
||||||
|
private int mResId;
|
||||||
|
|
||||||
|
UpdateMessage(int resId) {
|
||||||
|
mResId = resId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
mProgressTaskUpdater.updateMessage(mResId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,16 +23,12 @@ import android.app.ProgressDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
||||||
public class UpdateStatus {
|
public class UpdateStatus implements ProgressTaskUpdater {
|
||||||
private ProgressDialog mPD;
|
private ProgressDialog mPD;
|
||||||
private Context mCtx;
|
private Context mCtx;
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
|
||||||
public UpdateStatus() {
|
UpdateStatus(Context ctx, Handler handler, ProgressDialog pd) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public UpdateStatus(Context ctx, Handler handler, ProgressDialog pd) {
|
|
||||||
mCtx = ctx;
|
mCtx = ctx;
|
||||||
mPD = pd;
|
mPD = pd;
|
||||||
mHandler = handler;
|
mHandler = handler;
|
||||||
@@ -47,7 +43,7 @@ public class UpdateStatus {
|
|||||||
private class UpdateMessage implements Runnable {
|
private class UpdateMessage implements Runnable {
|
||||||
private int mResId;
|
private int mResId;
|
||||||
|
|
||||||
public UpdateMessage(int resId) {
|
UpdateMessage(int resId) {
|
||||||
mResId = resId;
|
mResId = resId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -190,6 +190,17 @@
|
|||||||
|
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_dialog_bar"
|
||||||
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true"
|
||||||
|
android:max="100"
|
||||||
|
android:backgroundTint="@color/white"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_above="@+id/pass_ok"/>
|
||||||
|
|
||||||
<android.support.v7.widget.AppCompatButton
|
<android.support.v7.widget.AppCompatButton
|
||||||
android:id="@+id/pass_ok"
|
android:id="@+id/pass_ok"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
21
app/src/main/res/layout/progress_dialog.xml
Normal file
21
app/src/main/res/layout/progress_dialog.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/progress_dialog_message"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="20dp"
|
||||||
|
style="@style/KeepassDXStyle.TextAppearance.SmallTitle"/>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_dialog_bar"
|
||||||
|
style="?android:attr/progressBarStyleHorizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true"
|
||||||
|
android:max="100"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user