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

@@ -15,7 +15,14 @@ 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)
{ {
errorMessage = javaException.LocalizedMessage ?? javaException.Message ?? errorMessage; try
{
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,9 +894,14 @@ 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);
(GetString(Resource.String.FileReadOnlyMessagePre) + " " + if (infotext_view != null)
App.Kp2a.GetResourceString(reason.Result)); {
infotext_view.Text =
(GetString(Resource.String.FileReadOnlyMessagePre) + " " +
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
{ {
@@ -638,19 +639,7 @@ namespace keepass2android
if (CopyTotpToClipboard && isTotpEntry) if (CopyTotpToClipboard && isTotpEntry)
{ {
Dictionary<string, string> entryFields = pwEntryOutput.OutputStrings.ToDictionary(pair => StrUtil.SafeXmlString(pair.Key), pair => pair.Value.ReadString()); DoCopyTotpToClipboard(activity, pwEntryOutput, totpPluginAdapter);
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);
}
} }
if (CloseAfterCreate) if (CloseAfterCreate)
@@ -661,7 +650,23 @@ namespace keepass2android
activity.CloseAfterTaskComplete(); 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());
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);
}
}
}
/// <summary> /// <summary>

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();