mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-22 09:12:17 -05:00
fixed bugs
removed some error reporting in cases where the errors are somewhat expected and handled
This commit is contained in:
parent
a2be64d1cb
commit
3b5c28c02a
@ -165,7 +165,7 @@ namespace keepass2android.Io
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Kp2aLog.LogUnexpectedError(e);
|
||||
Kp2aLog.Log(e.ToString());
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -239,7 +239,7 @@ namespace keepass2android.Io
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
@ -103,7 +103,7 @@ namespace keepass2android.Io
|
||||
return _streamCacheDir + iocAsHexString;
|
||||
}
|
||||
|
||||
private bool IsCached(IOConnectionInfo ioc)
|
||||
public bool IsCached(IOConnectionInfo ioc)
|
||||
{
|
||||
return File.Exists(CachedFilePath(ioc))
|
||||
&& File.Exists(VersionFilePath(ioc))
|
||||
|
@ -135,7 +135,7 @@ namespace keepass2android
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Kp2aLog.LogUnexpectedError(e);
|
||||
Kp2aLog.Log(e.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -122,13 +122,14 @@ namespace keepass2android
|
||||
Root = pwDatabase.RootGroup;
|
||||
PopulateGlobals(Root);
|
||||
|
||||
Loaded = true;
|
||||
|
||||
KpDatabase = pwDatabase;
|
||||
SearchHelper = new SearchDbHelper(app);
|
||||
|
||||
_databaseFormat = databaseFormat;
|
||||
|
||||
CanWrite = databaseFormat.CanWrite && !fileStorage.IsReadOnly(iocInfo);
|
||||
Loaded = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@ -203,6 +204,8 @@ namespace keepass2android
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -273,6 +276,8 @@ namespace keepass2android
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
_loaded = false;
|
||||
|
||||
Groups.Clear();
|
||||
Entries.Clear();
|
||||
Dirty.Clear();
|
||||
@ -280,7 +285,7 @@ namespace keepass2android
|
||||
|
||||
Root = null;
|
||||
KpDatabase = null;
|
||||
_loaded = false;
|
||||
|
||||
CanWrite = true;
|
||||
_reloadRequested = false;
|
||||
OtpAuxFileIoc = null;
|
||||
|
@ -83,6 +83,8 @@ namespace keepass2android
|
||||
}
|
||||
catch (Java.Lang.Exception e)
|
||||
{
|
||||
if (e.Message == "Invalid key!")
|
||||
throw new InvalidCompositeKeyException();
|
||||
throw new Exception(e.LocalizedMessage ??
|
||||
e.Message ??
|
||||
e.GetType().Name, e);
|
||||
|
@ -388,7 +388,7 @@ namespace keepass2android
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Kp2aLog.LogUnexpectedError(e);
|
||||
Kp2aLog.Log(e.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -225,6 +225,11 @@ namespace keepass2android
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_popupMenuItems.ContainsKey(fieldId))
|
||||
{
|
||||
Kp2aLog.Log("Did not find field with key " + fieldId);
|
||||
return;
|
||||
}
|
||||
//create a new popup item for the plugin action:
|
||||
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
|
||||
|
@ -97,7 +97,7 @@ namespace keepass2android
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Kp2aLog.LogUnexpectedError(e);
|
||||
Kp2aLog.Log(e.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -146,13 +146,12 @@ namespace keepass2android
|
||||
tv.SetPadding(tv.PaddingLeft,0,tv.PaddingRight,0);
|
||||
|
||||
PwEntry templateEntry = this.GetItem(position);
|
||||
|
||||
int size = (int)(Util.convertDpToPixel(Util.convertDpToPixel(20, Context), Context));
|
||||
var bmp =
|
||||
Bitmap.CreateScaledBitmap(
|
||||
Util.DrawableToBitmap(App.Kp2a.GetDb()
|
||||
.DrawableFactory.GetIconDrawable(Context, App.Kp2a.GetDb().KpDatabase, templateEntry.IconId, PwUuid.Zero, false)),
|
||||
(int)Util.convertDpToPixel(80, Context),
|
||||
(int)Util.convertDpToPixel(80, Context),
|
||||
size, size,
|
||||
true);
|
||||
|
||||
|
||||
|
@ -18,6 +18,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
@ -322,13 +323,17 @@ namespace keepass2android
|
||||
{
|
||||
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)
|
||||
.PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), iocKeyfile,
|
||||
RequestCodePrepareKeyFile, false);
|
||||
//if the user has not yet selected a keyfile, _keyFileOrProvider is empty
|
||||
if (string.IsNullOrEmpty(_keyFileOrProvider) == false)
|
||||
{
|
||||
var iocKeyfile = IOConnectionInfo.UnserializeFromString(_keyFileOrProvider);
|
||||
|
||||
App.Kp2a.GetFileStorage(iocKeyfile)
|
||||
.PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), iocKeyfile,
|
||||
RequestCodePrepareKeyFile, false);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
PerformLoadDatabase();
|
||||
@ -384,10 +389,7 @@ namespace keepass2android
|
||||
try
|
||||
{
|
||||
ChallengeInfo temp = _challengeProv.Encrypt(_challengeSecret);
|
||||
IFileStorage fileStorage = App.Kp2a.GetOtpAuxFileStorage(_ioConnection);
|
||||
IOConnectionInfo iocAux = fileStorage.GetFilePath(fileStorage.GetParentPath(_ioConnection),
|
||||
fileStorage.GetFilenameWithoutPathAndExt(_ioConnection) + ".xml");
|
||||
if (!temp.Save(iocAux))
|
||||
if (!temp.Save(_otpAuxIoc))
|
||||
{
|
||||
Toast.MakeText(this, Resource.String.ErrorUpdatingChalAuxFile, ToastLength.Long).Show();
|
||||
return false;
|
||||
@ -482,7 +484,8 @@ namespace keepass2android
|
||||
}
|
||||
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
|
||||
try
|
||||
{
|
||||
@ -643,6 +646,7 @@ namespace keepass2android
|
||||
protected override void LoadFile(IOConnectionInfo 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)
|
||||
{
|
||||
if (requestCode == FingerprintPermissionRequestCode && grantResults[0] == Permission.Granted)
|
||||
if ((requestCode == FingerprintPermissionRequestCode) && (grantResults.Any()) && (grantResults[0] == Permission.Granted))
|
||||
{
|
||||
var btn = FindViewById<ImageButton>(Resource.Id.fingerprintbtn);
|
||||
btn.Click += (sender, args) =>
|
||||
@ -1390,20 +1394,29 @@ namespace keepass2android
|
||||
|
||||
//avoid password being visible while loading:
|
||||
_showPassword = false;
|
||||
MakePasswordMaskedOrVisible();
|
||||
try
|
||||
{
|
||||
MakePasswordMaskedOrVisible();
|
||||
|
||||
Handler handler = new Handler();
|
||||
OnFinish onFinish = new AfterLoad(handler, this);
|
||||
_performingLoad = true;
|
||||
LoadDb task = (KeyProviderType == KeyProviders.Otp)
|
||||
? new SaveOtpAuxFileAndLoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider,
|
||||
onFinish, this)
|
||||
: new LoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider, onFinish);
|
||||
_loadDbTask = null; // prevent accidental re-use
|
||||
Handler handler = new Handler();
|
||||
OnFinish onFinish = new AfterLoad(handler, this);
|
||||
_performingLoad = true;
|
||||
LoadDb task = (KeyProviderType == KeyProviders.Otp)
|
||||
? new SaveOtpAuxFileAndLoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider,
|
||||
onFinish, this)
|
||||
: new LoadDb(App.Kp2a, _ioConnection, _loadDbTask, compositeKey, _keyFileOrProvider, onFinish);
|
||||
_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)
|
||||
@ -1703,7 +1716,8 @@ namespace keepass2android
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
@ -136,6 +136,14 @@ namespace keepass2android
|
||||
public void BroadcastDatabaseAction(Context ctx, string 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.ExtraDatabaseFilepath, App.Kp2a.GetDb().Ioc.Path);
|
||||
foreach (var plugin in new PluginDatabase(ctx).GetPluginsWithAcceptedScope(Strings.ScopeDatabaseActions))
|
||||
|
@ -71,7 +71,7 @@ namespace keepass2android
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Kp2aLog.LogUnexpectedError(e);
|
||||
Kp2aLog.Log(e.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user