improve app stability and refactor to get better logs

This commit is contained in:
Philipp Crocoll
2025-06-24 15:41:11 +02:00
parent 8d1195ac96
commit 0f98668bcd
7 changed files with 46 additions and 21 deletions

View File

@@ -476,8 +476,16 @@ namespace Kp2aAutofillParser
foreach (var field in autofillFields.HintMap.Values.Distinct()) foreach (var field in autofillFields.HintMap.Values.Distinct())
{ {
if (field == null || field.AutofillHints == null)
{
continue;
}
foreach (var hint in field.AutofillHints) foreach (var hint in field.AutofillHints)
{ {
if (hint == null)
{
continue;
}
if (GetPartitionIndex(hint) == partitionIndex) if (GetPartitionIndex(hint) == partitionIndex)
{ {
filteredCollection.Add(field); filteredCollection.Add(field);

View File

@@ -14,9 +14,16 @@ namespace KeePass.Util
{ {
string errorMessage = e.Message; string errorMessage = e.Message;
if (e is Java.Lang.Exception javaException) if (e is Java.Lang.Exception javaException)
{
try
{ {
errorMessage = javaException.LocalizedMessage ?? javaException.Message ?? errorMessage; errorMessage = javaException.LocalizedMessage ?? javaException.Message ?? errorMessage;
} }
finally
{
}
}
return errorMessage; return errorMessage;
} }

View File

@@ -14,7 +14,7 @@ using keepass2android;
namespace keepass2android namespace keepass2android
{ {
[Activity(Label = AppNames.AppName)] [Activity(Label = AppNames.AppName, Theme = "@style/Kp2aTheme_BlueNoActionBar")]
public class AppKilledInfo : Activity, IDialogInterfaceOnDismissListener public class AppKilledInfo : Activity, IDialogInterfaceOnDismissListener
{ {
protected override void OnCreate(Bundle bundle) protected override void OnCreate(Bundle bundle)

View File

@@ -894,10 +894,15 @@ namespace keepass2android
RegisterInfoTextDisplay( RegisterInfoTextDisplay(
"DbReadOnly"); //this ensures that we don't show the general info texts too soon "DbReadOnly"); //this ensures that we don't show the general info texts too soon
FindViewById<TextView>(Resource.Id.dbreadonly_infotext_text).Text = var infotext_view = FindViewById<TextView>(Resource.Id.dbreadonly_infotext_text);
if (infotext_view != null)
{
infotext_view.Text =
(GetString(Resource.String.FileReadOnlyMessagePre) + " " + (GetString(Resource.String.FileReadOnlyMessagePre) + " " +
App.Kp2a.GetResourceString(reason.Result)); App.Kp2a.GetResourceString(reason.Result));
} }
}
} }
UpdateBottomBarElementVisibility(Resource.Id.dbreadonly_infotext, canShow); UpdateBottomBarElementVisibility(Resource.Id.dbreadonly_infotext, canShow);
} }

View File

@@ -1245,7 +1245,7 @@ namespace keepass2android
{ {
var db = TryFindDatabaseForElement(element); var db = TryFindDatabaseForElement(element);
if (db == null) 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; return db;
} }

View File

@@ -15,6 +15,7 @@ using Android.Content.Res;
using Android.Preferences; using Android.Preferences;
using Google.Android.Material.Dialog; using Google.Android.Material.Dialog;
using keepass2android; using keepass2android;
using PluginTOTP;
namespace keepass2android namespace keepass2android
{ {
@@ -637,6 +638,21 @@ namespace keepass2android
} }
if (CopyTotpToClipboard && isTotpEntry) if (CopyTotpToClipboard && isTotpEntry)
{
DoCopyTotpToClipboard(activity, pwEntryOutput, totpPluginAdapter);
}
if (CloseAfterCreate)
{
//give plugins and TOTP time to do their work:
notifyPluginsOnOpenThread.Join(TimeSpan.FromSeconds(1));
//close
activity.CloseAfterTaskComplete();
}
}
private static void DoCopyTotpToClipboard(EntryActivity activity, PwEntryOutput pwEntryOutput,
ITotpPluginAdapter? totpPluginAdapter)
{ {
Dictionary<string, string> entryFields = pwEntryOutput.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString()); Dictionary<string, string> entryFields = pwEntryOutput.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString());
var totpData = totpPluginAdapter.GetTotpData(entryFields, activity, true); var totpData = totpPluginAdapter.GetTotpData(entryFields, activity, true);
@@ -649,17 +665,6 @@ namespace keepass2android
App.Kp2a.ShowMessage(activity, activity.GetString(Resource.String.TotpCopiedToClipboard), App.Kp2a.ShowMessage(activity, activity.GetString(Resource.String.TotpCopiedToClipboard),
MessageSeverity.Info); MessageSeverity.Info);
} }
}
if (CloseAfterCreate)
{
//give plugins and TOTP time to do their work:
notifyPluginsOnOpenThread.Join(TimeSpan.FromSeconds(1));
//close
activity.CloseAfterTaskComplete();
}
} }
} }

View File

@@ -189,7 +189,7 @@ namespace keepass2android.services.AutofillBase
{ {
var intent = Intent; var intent = Intent;
AssistStructure structure = (AssistStructure)intent.GetParcelableExtra(AutofillManager.ExtraAssistStructure); AssistStructure structure = (AssistStructure)intent.GetParcelableExtra(AutofillManager.ExtraAssistStructure);
if (structure == null) if (structure == null || clientFormDataMap == null)
{ {
SetResult(Result.Canceled); SetResult(Result.Canceled);
Finish(); Finish();