From 0f98668bcdc017b3075e708637bb990f68554ba6 Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Tue, 24 Jun 2025 15:41:11 +0200 Subject: [PATCH] improve app stability and refactor to get better logs --- src/Kp2aAutofillParser/AutofillParser.cs | 8 +++++ src/Kp2aBusinessLogic/Utils/ExceptionUtil.cs | 9 ++++- src/keepass2android-app/AppKilledInfo.cs | 2 +- src/keepass2android-app/GroupBaseActivity.cs | 11 +++++-- src/keepass2android-app/app/App.cs | 2 +- src/keepass2android-app/app/AppTask.cs | 33 +++++++++++-------- .../ChooseForAutofillActivityBase.cs | 2 +- 7 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/Kp2aAutofillParser/AutofillParser.cs b/src/Kp2aAutofillParser/AutofillParser.cs index 3271b6b7..9464021c 100644 --- a/src/Kp2aAutofillParser/AutofillParser.cs +++ b/src/Kp2aAutofillParser/AutofillParser.cs @@ -476,8 +476,16 @@ namespace Kp2aAutofillParser foreach (var field in autofillFields.HintMap.Values.Distinct()) { + if (field == null || field.AutofillHints == null) + { + continue; + } foreach (var hint in field.AutofillHints) { + if (hint == null) + { + continue; + } if (GetPartitionIndex(hint) == partitionIndex) { filteredCollection.Add(field); diff --git a/src/Kp2aBusinessLogic/Utils/ExceptionUtil.cs b/src/Kp2aBusinessLogic/Utils/ExceptionUtil.cs index dc303b97..07905f2f 100644 --- a/src/Kp2aBusinessLogic/Utils/ExceptionUtil.cs +++ b/src/Kp2aBusinessLogic/Utils/ExceptionUtil.cs @@ -15,7 +15,14 @@ namespace KeePass.Util string errorMessage = e.Message; if (e is Java.Lang.Exception javaException) { - errorMessage = javaException.LocalizedMessage ?? javaException.Message ?? errorMessage; + try + { + errorMessage = javaException.LocalizedMessage ?? javaException.Message ?? errorMessage; + } + finally + { + + } } return errorMessage; diff --git a/src/keepass2android-app/AppKilledInfo.cs b/src/keepass2android-app/AppKilledInfo.cs index 6d017bee..36b14a8a 100644 --- a/src/keepass2android-app/AppKilledInfo.cs +++ b/src/keepass2android-app/AppKilledInfo.cs @@ -14,7 +14,7 @@ using keepass2android; namespace keepass2android { - [Activity(Label = AppNames.AppName)] + [Activity(Label = AppNames.AppName, Theme = "@style/Kp2aTheme_BlueNoActionBar")] public class AppKilledInfo : Activity, IDialogInterfaceOnDismissListener { protected override void OnCreate(Bundle bundle) diff --git a/src/keepass2android-app/GroupBaseActivity.cs b/src/keepass2android-app/GroupBaseActivity.cs index 8f43e58d..12c22d3f 100644 --- a/src/keepass2android-app/GroupBaseActivity.cs +++ b/src/keepass2android-app/GroupBaseActivity.cs @@ -894,9 +894,14 @@ namespace keepass2android RegisterInfoTextDisplay( "DbReadOnly"); //this ensures that we don't show the general info texts too soon - FindViewById(Resource.Id.dbreadonly_infotext_text).Text = - (GetString(Resource.String.FileReadOnlyMessagePre) + " " + - App.Kp2a.GetResourceString(reason.Result)); + var infotext_view = FindViewById(Resource.Id.dbreadonly_infotext_text); + if (infotext_view != null) + { + infotext_view.Text = + (GetString(Resource.String.FileReadOnlyMessagePre) + " " + + App.Kp2a.GetResourceString(reason.Result)); + } + } } UpdateBottomBarElementVisibility(Resource.Id.dbreadonly_infotext, canShow); diff --git a/src/keepass2android-app/app/App.cs b/src/keepass2android-app/app/App.cs index 80324987..9bb54877 100644 --- a/src/keepass2android-app/app/App.cs +++ b/src/keepass2android-app/app/App.cs @@ -1245,7 +1245,7 @@ namespace keepass2android { var db = TryFindDatabaseForElement(element); if (db == null) - throw new Exception("Database element not found!"); + throw new Exception($"Database element {element.Uuid} not found in any of {OpenDatabases.Count()} databases!"); return db; } diff --git a/src/keepass2android-app/app/AppTask.cs b/src/keepass2android-app/app/AppTask.cs index 7cb617bd..4679c99b 100644 --- a/src/keepass2android-app/app/AppTask.cs +++ b/src/keepass2android-app/app/AppTask.cs @@ -15,6 +15,7 @@ using Android.Content.Res; using Android.Preferences; using Google.Android.Material.Dialog; using keepass2android; +using PluginTOTP; namespace keepass2android { @@ -638,19 +639,7 @@ namespace keepass2android if (CopyTotpToClipboard && isTotpEntry) { - Dictionary entryFields = pwEntryOutput.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString()); - var totpData= totpPluginAdapter.GetTotpData(entryFields, activity, true); - if (totpData.IsTotpEntry) - { - TOTPProvider prov = new TOTPProvider(totpData); - string totp = prov.GenerateByByte(totpData.TotpSecret); - CopyToClipboardService.CopyValueToClipboardWithTimeout(activity, totp, true); - - App.Kp2a.ShowMessage(activity, activity.GetString(Resource.String.TotpCopiedToClipboard), - MessageSeverity.Info); - } - - + DoCopyTotpToClipboard(activity, pwEntryOutput, totpPluginAdapter); } if (CloseAfterCreate) @@ -661,7 +650,23 @@ namespace keepass2android activity.CloseAfterTaskComplete(); } } - } + + private static void DoCopyTotpToClipboard(EntryActivity activity, PwEntryOutput pwEntryOutput, + ITotpPluginAdapter? totpPluginAdapter) + { + Dictionary entryFields = pwEntryOutput.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString()); + var totpData = totpPluginAdapter.GetTotpData(entryFields, activity, true); + if (totpData.IsTotpEntry) + { + TOTPProvider prov = new TOTPProvider(totpData); + string totp = prov.GenerateByByte(totpData.TotpSecret); + CopyToClipboardService.CopyValueToClipboardWithTimeout(activity, totp, true); + + App.Kp2a.ShowMessage(activity, activity.GetString(Resource.String.TotpCopiedToClipboard), + MessageSeverity.Info); + } + } + } /// diff --git a/src/keepass2android-app/services/AutofillBase/ChooseForAutofillActivityBase.cs b/src/keepass2android-app/services/AutofillBase/ChooseForAutofillActivityBase.cs index f80a441e..092284c7 100644 --- a/src/keepass2android-app/services/AutofillBase/ChooseForAutofillActivityBase.cs +++ b/src/keepass2android-app/services/AutofillBase/ChooseForAutofillActivityBase.cs @@ -189,7 +189,7 @@ namespace keepass2android.services.AutofillBase { var intent = Intent; AssistStructure structure = (AssistStructure)intent.GetParcelableExtra(AutofillManager.ExtraAssistStructure); - if (structure == null) + if (structure == null || clientFormDataMap == null) { SetResult(Result.Canceled); Finish();