Improve content uri file not found errors.

This commit is contained in:
Brian Pellin
2016-03-14 21:43:49 -05:00
parent c99a01ddb1
commit 9c6a9a8a82
5 changed files with 72 additions and 4 deletions

View File

@@ -38,6 +38,7 @@ import android.net.Uri;
import com.keepassdroid.database.PwDatabase;
import com.keepassdroid.database.PwDatabaseV3;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.database.exception.ContentFileNotFoundException;
import com.keepassdroid.database.exception.InvalidDBException;
import com.keepassdroid.database.exception.PwDbOutputException;
import com.keepassdroid.database.load.Importer;
@@ -93,11 +94,15 @@ public class Database {
InputStream is, kfIs;
try {
is = UriUtil.getUriInputStream(ctx, uri);
kfIs = UriUtil.getUriInputStream(ctx, keyfile);
} catch (Exception e) {
throw new FileNotFoundException();
throw ContentFileNotFoundException.getInstance(uri);
}
try {
kfIs = UriUtil.getUriInputStream(ctx, keyfile);
} catch (Exception e) {
throw ContentFileNotFoundException.getInstance(keyfile);
}
LoadData(ctx, is, password, kfIs, status, debug);
}

View File

@@ -31,6 +31,7 @@ import com.android.keepass.R;
import com.keepassdroid.Database;
import com.keepassdroid.app.App;
import com.keepassdroid.database.exception.ArcFourException;
import com.keepassdroid.database.exception.ContentFileNotFoundException;
import com.keepassdroid.database.exception.InvalidAlgorithmException;
import com.keepassdroid.database.exception.InvalidDBException;
import com.keepassdroid.database.exception.InvalidDBSignatureException;
@@ -73,6 +74,9 @@ public class LoadDB extends RunnableOnFinish {
} catch (InvalidPasswordException e) {
finish(false, mCtx.getString(R.string.InvalidPassword));
return;
} catch (ContentFileNotFoundException e) {
finish(false, mCtx.getString(R.string.file_not_found_content));
return;
} catch (FileNotFoundException e) {
finish(false, mCtx.getString(R.string.FileNotFound));
return;

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2016 Brian Pellin.
*
* This file is part of KeePassDroid.
*
* KeePassDroid 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 2 of the License, or
* (at your option) any later version.
*
* KeePassDroid 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 KeePassDroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.keepassdroid.database.exception;
import android.net.Uri;
import com.keepassdroid.utils.EmptyUtils;
import java.io.FileNotFoundException;
/**
* Created by bpellin on 3/14/16.
*/
public class ContentFileNotFoundException extends FileNotFoundException {
public static FileNotFoundException getInstance(Uri uri) {
if (uri == null) { return new FileNotFoundException(); }
String scheme = uri.getScheme();
if (!EmptyUtils.isNullOrEmpty(scheme) && scheme.equalsIgnoreCase("content")) {
return new ContentFileNotFoundException();
}
return new FileNotFoundException();
}
public ContentFileNotFoundException() {
super();
}
}

View File

@@ -53,6 +53,7 @@ import com.keepassdroid.app.App;
import com.keepassdroid.compat.StorageAF;
import com.keepassdroid.database.edit.CreateDB;
import com.keepassdroid.database.edit.FileOnFinish;
import com.keepassdroid.database.exception.ContentFileNotFoundException;
import com.keepassdroid.intents.Intents;
import com.keepassdroid.settings.AppSettingsActivity;
import com.keepassdroid.utils.EmptyUtils;
@@ -101,7 +102,12 @@ public class FileSelectActivity extends ListActivity {
try {
PasswordActivity.Launch(FileSelectActivity.this, fileName);
} catch (FileNotFoundException e) {
}
catch (ContentFileNotFoundException e) {
Toast.makeText(FileSelectActivity.this,
R.string.file_not_found_content, Toast.LENGTH_LONG).show();
}
catch (FileNotFoundException e) {
Toast.makeText(FileSelectActivity.this,
R.string.FileNotFound, Toast.LENGTH_LONG).show();
}
@@ -321,7 +327,12 @@ public class FileSelectActivity extends ListActivity {
protected void onPostExecute(Void v) {
try {
PasswordActivity.Launch(FileSelectActivity.this, fileName, keyFile);
} catch (FileNotFoundException e) {
}
catch (ContentFileNotFoundException e) {
Toast.makeText(FileSelectActivity.this, R.string.file_not_found_content, Toast.LENGTH_LONG)
.show();
}
catch (FileNotFoundException e) {
Toast.makeText(FileSelectActivity.this, R.string.FileNotFound, Toast.LENGTH_LONG)
.show();
}

View File

@@ -100,6 +100,7 @@
<string name="field_name">Field Name</string>
<string name="field_value">Field value</string>
<string name="FileNotFound">File not found.</string>
<string name="file_not_found_content">File not found. Try reopening from your content provider.</string>
<string name="file_browser">File Browser</string>
<string name="generate_password">Generate Password</string>
<string name="group">Group</string>