fixed bugs

removed some error reporting in cases where the errors are somewhat expected and handled
This commit is contained in:
Philipp Crocoll 2016-01-29 22:09:22 +01:00
parent a2be64d1cb
commit 3b5c28c02a
12 changed files with 70 additions and 37 deletions

View File

@ -165,7 +165,7 @@ namespace keepass2android.Io
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.LogUnexpectedError(e); Kp2aLog.Log(e.ToString());
return false; return false;
} }
@ -239,7 +239,7 @@ namespace keepass2android.Io
} }
else return false; else return false;
} }
else throw new Exception("couldn't move to first result element"); else throw new Exception("couldn't move to first result element: " + (cursor == null) + uri.ToString());
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -103,7 +103,7 @@ namespace keepass2android.Io
return _streamCacheDir + iocAsHexString; return _streamCacheDir + iocAsHexString;
} }
private bool IsCached(IOConnectionInfo ioc) public bool IsCached(IOConnectionInfo ioc)
{ {
return File.Exists(CachedFilePath(ioc)) return File.Exists(CachedFilePath(ioc))
&& File.Exists(VersionFilePath(ioc)) && File.Exists(VersionFilePath(ioc))

View File

@ -135,7 +135,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.LogUnexpectedError(e); Kp2aLog.Log(e.ToString());
} }
} }

View File

@ -122,13 +122,14 @@ namespace keepass2android
Root = pwDatabase.RootGroup; Root = pwDatabase.RootGroup;
PopulateGlobals(Root); PopulateGlobals(Root);
Loaded = true;
KpDatabase = pwDatabase; KpDatabase = pwDatabase;
SearchHelper = new SearchDbHelper(app); SearchHelper = new SearchDbHelper(app);
_databaseFormat = databaseFormat; _databaseFormat = databaseFormat;
CanWrite = databaseFormat.CanWrite && !fileStorage.IsReadOnly(iocInfo); CanWrite = databaseFormat.CanWrite && !fileStorage.IsReadOnly(iocInfo);
Loaded = true;
} }
catch (Exception) catch (Exception)
{ {
@ -203,6 +204,8 @@ namespace keepass2android
public PwGroup Search(SearchParameters searchParams, IDictionary<PwUuid, KeyValuePair<string, string>> resultContexts) public PwGroup Search(SearchParameters searchParams, IDictionary<PwUuid, KeyValuePair<string, string>> resultContexts)
{ {
if (SearchHelper == null)
throw new Exception("SearchHelper is null");
return SearchHelper.Search(this, searchParams, resultContexts); return SearchHelper.Search(this, searchParams, resultContexts);
} }
@ -273,6 +276,8 @@ namespace keepass2android
} }
public void Clear() { public void Clear() {
_loaded = false;
Groups.Clear(); Groups.Clear();
Entries.Clear(); Entries.Clear();
Dirty.Clear(); Dirty.Clear();
@ -280,7 +285,7 @@ namespace keepass2android
Root = null; Root = null;
KpDatabase = null; KpDatabase = null;
_loaded = false;
CanWrite = true; CanWrite = true;
_reloadRequested = false; _reloadRequested = false;
OtpAuxFileIoc = null; OtpAuxFileIoc = null;

View File

@ -83,6 +83,8 @@ namespace keepass2android
} }
catch (Java.Lang.Exception e) catch (Java.Lang.Exception e)
{ {
if (e.Message == "Invalid key!")
throw new InvalidCompositeKeyException();
throw new Exception(e.LocalizedMessage ?? throw new Exception(e.LocalizedMessage ??
e.Message ?? e.Message ??
e.GetType().Name, e); e.GetType().Name, e);

View File

@ -388,7 +388,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.LogUnexpectedError(e); Kp2aLog.Log(e.ToString());
} }
} }

View File

@ -225,6 +225,11 @@ namespace keepass2android
{ {
try try
{ {
if (!_popupMenuItems.ContainsKey(fieldId))
{
Kp2aLog.Log("Did not find field with key " + fieldId);
return;
}
//create a new popup item for the plugin action: //create a new popup item for the plugin action:
var newPopup = new PluginPopupMenuItem(this, pluginPackage, fieldId, popupItemId, displayText, iconId, bundleExtra); var newPopup = new PluginPopupMenuItem(this, pluginPackage, fieldId, popupItemId, displayText, iconId, bundleExtra);
//see if we already have a popup item for this field with the same item id //see if we already have a popup item for this field with the same item id

View File

@ -97,7 +97,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.LogUnexpectedError(e); Kp2aLog.Log(e.ToString());
} }
} }

View File

@ -146,13 +146,12 @@ namespace keepass2android
tv.SetPadding(tv.PaddingLeft,0,tv.PaddingRight,0); tv.SetPadding(tv.PaddingLeft,0,tv.PaddingRight,0);
PwEntry templateEntry = this.GetItem(position); PwEntry templateEntry = this.GetItem(position);
int size = (int)(Util.convertDpToPixel(Util.convertDpToPixel(20, Context), Context));
var bmp = var bmp =
Bitmap.CreateScaledBitmap( Bitmap.CreateScaledBitmap(
Util.DrawableToBitmap(App.Kp2a.GetDb() Util.DrawableToBitmap(App.Kp2a.GetDb()
.DrawableFactory.GetIconDrawable(Context, App.Kp2a.GetDb().KpDatabase, templateEntry.IconId, PwUuid.Zero, false)), .DrawableFactory.GetIconDrawable(Context, App.Kp2a.GetDb().KpDatabase, templateEntry.IconId, PwUuid.Zero, false)),
(int)Util.convertDpToPixel(80, Context), size, size,
(int)Util.convertDpToPixel(80, Context),
true); true);

View File

@ -18,6 +18,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; using System.Xml;
using System.Xml.Serialization; using System.Xml.Serialization;
@ -322,13 +323,17 @@ namespace keepass2android
{ {
if (KeyProviderType == KeyProviders.KeyFile) if (KeyProviderType == KeyProviders.KeyFile)
{ {
//TODO: if the user has not yet selected a keyfile, _keyFileOrProvider is empty which
//gives an (unhandled) exception here
var iocKeyfile = IOConnectionInfo.UnserializeFromString(_keyFileOrProvider);
App.Kp2a.GetFileStorage(iocKeyfile) //if the user has not yet selected a keyfile, _keyFileOrProvider is empty
.PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), iocKeyfile, if (string.IsNullOrEmpty(_keyFileOrProvider) == false)
RequestCodePrepareKeyFile, false); {
var iocKeyfile = IOConnectionInfo.UnserializeFromString(_keyFileOrProvider);
App.Kp2a.GetFileStorage(iocKeyfile)
.PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), iocKeyfile,
RequestCodePrepareKeyFile, false);
}
} }
else else
PerformLoadDatabase(); PerformLoadDatabase();
@ -384,10 +389,7 @@ namespace keepass2android
try try
{ {
ChallengeInfo temp = _challengeProv.Encrypt(_challengeSecret); ChallengeInfo temp = _challengeProv.Encrypt(_challengeSecret);
IFileStorage fileStorage = App.Kp2a.GetOtpAuxFileStorage(_ioConnection); if (!temp.Save(_otpAuxIoc))
IOConnectionInfo iocAux = fileStorage.GetFilePath(fileStorage.GetParentPath(_ioConnection),
fileStorage.GetFilenameWithoutPathAndExt(_ioConnection) + ".xml");
if (!temp.Save(iocAux))
{ {
Toast.MakeText(this, Resource.String.ErrorUpdatingChalAuxFile, ToastLength.Long).Show(); Toast.MakeText(this, Resource.String.ErrorUpdatingChalAuxFile, ToastLength.Long).Show();
return false; return false;
@ -482,7 +484,8 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.LogUnexpectedError(e); //this can happen e.g. if the file storage does not support GetParentPath
Kp2aLog.Log(e.ToString());
//retry with saved ioc //retry with saved ioc
try try
{ {
@ -643,6 +646,7 @@ namespace keepass2android
protected override void LoadFile(IOConnectionInfo iocAux) protected override void LoadFile(IOConnectionInfo iocAux)
{ {
Activity._chalInfo = ChallengeInfo.Load(iocAux); Activity._chalInfo = ChallengeInfo.Load(iocAux);
Activity._otpAuxIoc = iocAux;
} }
@ -925,7 +929,7 @@ namespace keepass2android
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{ {
if (requestCode == FingerprintPermissionRequestCode && grantResults[0] == Permission.Granted) if ((requestCode == FingerprintPermissionRequestCode) && (grantResults.Any()) && (grantResults[0] == Permission.Granted))
{ {
var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn); var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
btn.Click += (sender, args) => btn.Click += (sender, args) =>
@ -1390,20 +1394,29 @@ namespace keepass2android
//avoid password being visible while loading: //avoid password being visible while loading:
_showPassword = false; _showPassword = false;
MakePasswordMaskedOrVisible(); try
{
MakePasswordMaskedOrVisible();
Handler handler = new Handler(); Handler handler = new Handler();
OnFinish onFinish = new AfterLoad(handler, this); OnFinish onFinish = new AfterLoad(handler, this);
_performingLoad = true; _performingLoad = true;
LoadDb task = (KeyProviderType == KeyProviders.Otp) LoadDb task = (KeyProviderType == KeyProviders.Otp)
? new SaveOtpAuxFileAndLoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider, ? new SaveOtpAuxFileAndLoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider,
onFinish, this) onFinish, this)
: new LoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider, onFinish); : new LoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider, onFinish);
_loadDbTask = null; // prevent accidental re-use _loadDbTask = null; // prevent accidental re-use
SetNewDefaultFile(); SetNewDefaultFile();
new ProgressTask(App.Kp2a, this, task).Run();
}
catch (Exception e)
{
Kp2aLog.LogUnexpectedError(new Exception("cannot load database: "+e + ", c: " + (compositeKey != null) + (_ioConnection != null) + (_keyFileOrProvider != null), e));
throw;
}
new ProgressTask(App.Kp2a, this, task).Run();
} }
private bool CreateCompositeKey(out CompositeKey compositeKey, out string errorMessage) private bool CreateCompositeKey(out CompositeKey compositeKey, out string errorMessage)
@ -1703,7 +1716,8 @@ namespace keepass2android
CheckBox cbOfflineMode = (CheckBox)FindViewById(Resource.Id.work_offline); CheckBox cbOfflineMode = (CheckBox)FindViewById(Resource.Id.work_offline);
App.Kp2a.OfflineMode = cbOfflineMode.Checked = App.Kp2a.OfflineModePreference; //this won't overwrite new user settings because every change is directly saved in settings App.Kp2a.OfflineMode = cbOfflineMode.Checked = App.Kp2a.OfflineModePreference; //this won't overwrite new user settings because every change is directly saved in settings
LinearLayout offlineModeContainer = FindViewById<LinearLayout>(Resource.Id.work_offline_container); LinearLayout offlineModeContainer = FindViewById<LinearLayout>(Resource.Id.work_offline_container);
if (App.Kp2a.GetFileStorage(_ioConnection) is IOfflineSwitchable) var cachingFileStorage = App.Kp2a.GetFileStorage(_ioConnection) as CachingFileStorage;
if ((cachingFileStorage != null) && cachingFileStorage.IsCached(_ioConnection))
{ {
offlineModeContainer.Visibility = ViewStates.Visible; offlineModeContainer.Visibility = ViewStates.Visible;
} }

View File

@ -136,6 +136,14 @@ namespace keepass2android
public void BroadcastDatabaseAction(Context ctx, string action) public void BroadcastDatabaseAction(Context ctx, string action)
{ {
Intent i = new Intent(action); Intent i = new Intent(action);
//seems like this can happen. This code is for debugging.
if (App.Kp2a.GetDb().Ioc == null)
{
Kp2aLog.LogUnexpectedError(new Exception("App.Kp2a.GetDb().Ioc is null"));
return;
}
i.PutExtra(Strings.ExtraDatabaseFileDisplayname, App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc).GetDisplayName(App.Kp2a.GetDb().Ioc)); i.PutExtra(Strings.ExtraDatabaseFileDisplayname, App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc).GetDisplayName(App.Kp2a.GetDb().Ioc));
i.PutExtra(Strings.ExtraDatabaseFilepath, App.Kp2a.GetDb().Ioc.Path); i.PutExtra(Strings.ExtraDatabaseFilepath, App.Kp2a.GetDb().Ioc.Path);
foreach (var plugin in new PluginDatabase(ctx).GetPluginsWithAcceptedScope(Strings.ScopeDatabaseActions)) foreach (var plugin in new PluginDatabase(ctx).GetPluginsWithAcceptedScope(Strings.ScopeDatabaseActions))

View File

@ -71,7 +71,7 @@ namespace keepass2android
} }
catch (Exception e) catch (Exception e)
{ {
Kp2aLog.LogUnexpectedError(e); Kp2aLog.Log(e.ToString());
return null; return null;
} }
} }